]> git.mxchange.org Git - shipsimu.git/blobdiff - application/ship-simu/main/companies/class_ShippingCompany.php
More stubs added, code "made" generic:
[shipsimu.git] / application / ship-simu / main / companies / class_ShippingCompany.php
index d3ab6985dec4c5d08e602f645dcaa330de337044..e3bd59167a0ba6b84edea35b98529d05e8fcabc1 100644 (file)
@@ -38,14 +38,14 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        private $founderInstance = null;
 
        /**
-        * Employed people by this company
+        * Headquarter harbor instance
         */
-       private $employeeList    = null;
+       private $hqInstance      = null;
 
        /**
-        * Headquarter harbor instance
+        * Employed people by this company
         */
-       private $hqInstance      = null;
+       private $employeeList    = null;
 
        /**
         * List of all assigned shipyards
@@ -62,11 +62,6 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
         */
        private $contractList    = null;
 
-       /**
-        * Database result instance
-        */
-       private $resultInstance = null;
-
        // Exception constants
        const EXCEPTION_USER_OWNS_NO_COMPANY = 0x200;
 
@@ -95,21 +90,18 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
         *
         * @param       $userInstance           A user class
         * @return      $companyInstance        Prepared company instance
-        * @throws      NoShippingCompanyOwnedException         If the user owns no shipping companies
         */
        public final static function createShippingCompany (BaseUser $userInstance) {
                // Get new instance
                $companyInstance = new ShippingCompany();
 
                // Does the given user owns a company?
-               if (!$companyInstance->ifUserOwnsShippingCompany($userInstance)) {
-                       // Throw an exception here
-                       throw new NoShippingCompanyOwnedException(array($companyInstance, $userInstance), self::EXCEPTION_USER_OWNS_NO_COMPANY);
+               if ($companyInstance->ifUserParticipatesInCompany($userInstance)) {
+                       // Then do some nastly caching here but don't throw an exception
+                       // because then you will hurt our web helpers... :/
+                       $companyInstance->partialStub("Don't throw exceptions here.");
                } // END - if
 
-               // Set the user instance. We don't care here if he is founder or employee.
-               $companyInstance->setUserInstance($userInstance);
-
                // Init all lists
                $companyInstance->initCompanyLists();
 
@@ -118,34 +110,43 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        }
 
        /**
-        * Checks wether the given user owns a company or not
+        * Checks wether the given user participates in a company
         *
         * @param       $userInstance   An instance of a user class
-        * @return      $ownsCompany    Wether the user owns at least one company
+        * @return      $participates   Wether the user participates at lease in one company
         */
-       protected function ifUserOwnsShippingCompany (BaseUser $userInstance)  {
+       protected function ifUserParticipatesInCompany (BaseUser $userInstance)  {
                // By default no user owns any company... ;)
-               $ownsCompany = false;
+               $participates = false;
 
                // Get a company database wrapper class
                $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class');
 
-               // Get a search criteria class
-               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+               // Ask the wrapper if this user participates
+               $participates = $wrapperInstance->ifUserParticipatesInCompany($userInstance);
 
-               // Add the user primary key as a search criteria
-               $criteriaInstance->addCriteria('company_owner', $userInstance->getPrimaryKey());
-               $criteriaInstance->setLimit(1);
+               // Get the result instance
+               $resultInstance = $wrapperInstance->getResultInstance();
 
-               // Get the result back
-               $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
-               $resultInstance->debugInstance();
+               // Caches the result instance here, if set (we don't the wrapper anymore!)
+               if ($resultInstance instanceof SearchableResult) {
+                       // Set the result instance
+                       $this->setResultInstance($resultInstance);
+               } // END - if
+
+               // Return result
+               return $participates;
        }
 
+       //----------------------------------------------------------------------------
+       // From here is very old code which needs to be translated and changed heavily
+       //----------------------------------------------------------------------------
+
        /**
         * Intialize all lists
         *
         * @return      void
+        * @todo        Maybe we don't need these big lists anymore?! So we can deprecate/remove it
         */
        protected function initCompanyLists () {
                // Employees
@@ -158,10 +159,6 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                $this->contractList = new FrameworkArrayObject("FakedContractList");
        }
 
-       //----------------------------------------------------------------------------
-       // From here is very old code which needs to be translated and changed heavily
-       //----------------------------------------------------------------------------
-
        // Setter-Methode fuer Firmennamen
        public final function setCompanyName ($companyName) {
                $this->companyName = (string) $companyName;