X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=application%2Fship-simu%2Fmain%2Fcompanies%2Fclass_ShippingCompany.php;h=24603fd86b1309381305e1b132eb44c6c1f5e6b2;hb=5bf79580029c4f6ee71e6c9e7890169e4b344def;hp=841be84d0134d40f7d4ea03483c837367d7ff16b;hpb=e433812994d5f9a15d2be01b271c3a46bda729ae;p=shipsimu.git diff --git a/application/ship-simu/main/companies/class_ShippingCompany.php b/application/ship-simu/main/companies/class_ShippingCompany.php index 841be84..24603fd 100644 --- a/application/ship-simu/main/companies/class_ShippingCompany.php +++ b/application/ship-simu/main/companies/class_ShippingCompany.php @@ -73,15 +73,6 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); - - // Set description - $this->setObjectDescription("A shipping company class"); - - // Generate unique ID number - $this->generateUniqueId(); - - // Clean up a little - $this->removeSystemArray(); } /** @@ -90,14 +81,15 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner * * @param $userInstance A user class * @return $companyInstance Prepared company instance + * @todo Add functionality if user participates in a company */ - public final static function createShippingCompany (BaseUser $userInstance) { + public final static function createShippingCompany (ManageableAccount $userInstance) { // Get new instance $companyInstance = new ShippingCompany(); // Does the given user owns a company? if ($companyInstance->ifUserParticipatesInCompany($userInstance)) { - // Then do some nastly caching here but don't throw an exception + // Then do some nasty 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 @@ -115,12 +107,12 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner * @param $userInstance An instance of a user class * @return $participates Wether the user participates at lease in one company */ - protected function ifUserParticipatesInCompany (BaseUser $userInstance) { + protected function ifUserParticipatesInCompany (ManageableAccount $userInstance) { // By default no user owns any company... ;) $participates = false; // Get a company database wrapper class - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class'); + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class', array($this)); // Ask the wrapper if this user participates $participates = $wrapperInstance->ifUserParticipatesInCompany($userInstance); @@ -142,6 +134,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner * Checks wether the current user in registry is the company founder * * @return $isFounder Wether the current user is the company founder + * @todo Check if user is company founder */ public function ifUserIsFounder () { // Default is not the founder @@ -164,6 +157,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner * Checks wether the current user in registry is the company owner * * @return $isOwner Wether the current user is the company owner + * @todo Check if user is company owner */ public function ifUserIsOwner () { // Default is not the owner @@ -204,9 +198,9 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner return $isEmployee; } - //---------------------------------------------------------------------------- - // From here is very old code which needs to be translated and changed heavily - //---------------------------------------------------------------------------- + //------------------------------------------------------------------------------\ + // Below here is very old code which needs to be translated and changed heavily | + //------------------------------------------------------------------------------/ /** * Intialize all lists @@ -251,7 +245,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner // Reedereien Werften bauen lassen public function createShipyardInHarbor($shipyardName, Harbor $harborInstance) { - if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s baut im %s eine Werft %s.", + if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Reederei %s baut im %s eine Werft %s.", __CLASS__, __LINE__, $this->getCompanyName(), @@ -296,7 +290,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner $amount = (int) $amount; // Debug-Meldung ausgeben - if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s stellt per Zufall %d neue Mitarbeiter ein.", + if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Reederei %s stellt per Zufall %d neue Mitarbeiter ein.", __CLASS__, __LINE__, $this->getCompanyName(), @@ -331,26 +325,25 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner $iterator->seek($pos); // Is the current position valid? - if ($iterator->valid()) { - // Element holen - $employee = $iterator->current(); - } else { + if ($iterator->valid() === false) { // Should normally not happen... :( throw new StructuresOutOfBoundsException($idx, self::EXCEPTION_INDEX_OUT_OF_BOUNDS); - } - } + } // END - if + + // Get current element + $employee = $iterator->current(); + } // END - while // A dummy just for the description and real class $dummy = CompanyEmployee::createCompanyEmployee("", "", "M", 1970, 1, 1, $employee->isMarried(), 0); // Make this person employed and give him some money to work $employee->setEmployed(true); - $employee->setObjectDescription($dummy->getObjectDescription()); $employee->setRealClass($dummy->__toString()); $employee->increaseSalary((mt_rand(7, 14) * 100)); // Are 700 to 1400 EUR for the begin okay? // Debug message - if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s stellt den/die Angestellte(n) %s %s ein.", + if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Reederei %s stellt den/die Angestellte(n) %s %s ein.", __CLASS__, __LINE__, $this->getCompanyName(), @@ -366,7 +359,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner $personellInstance->resetCache(); // Debug-Meldung ausgeben - if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s hat per Zufall %d neue Mitarbeiter eingestellt.", + if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Reederei %s hat per Zufall %d neue Mitarbeiter eingestellt.", __CLASS__, __LINE__, $this->getCompanyName(), @@ -376,7 +369,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner // Distribute all personells on all shipyards public function distributeAllPersonellOnShipyards () { - if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s verteilt alle ihre %d Mitarbeiter auf alle %d Werft(en).", + if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Reederei %s verteilt alle ihre %d Mitarbeiter auf alle %d Werft(en).", __CLASS__, __LINE__, $this->getCompanyName(), @@ -396,10 +389,10 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner // Iterate through all employees for ($idx = $this->employeeList->getIterator(); $idx->valid(); $idx->next()) { // Is the shipyard iterator still okay? - if (!$shipyardIter->valid()) { + if ($shipyardIter->valid() === false) { // Rewind to first position $shipyardIter->seek(0); - } + } // END - if // Get Shipyard object $shipyard = $shipyardIter->current(); @@ -411,7 +404,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner } elseif (!is_object($shipyard)) { // Not an object! ;-( throw new NoObjectException($shipyard, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!$shipyard->isClass("Shipyard")) { + } elseif ($shipyard->isClass("Shipyard") === false) { // Nope, so throw exception throw new ClassMismatchException(array($shipyard->__toString(), "Shipyard"), self::EXCEPTION_CLASSES_NOT_MATCHING); } @@ -430,7 +423,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner $total = $this->employeeList->count(); // Debug message - if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s hat %d Mitarbeiter.", + if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Reederei %s hat %d Mitarbeiter.", __CLASS__, __LINE__, $this->getCompanyName(), @@ -443,7 +436,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner // Getter for total shipyards public final function getTotalShipyards () { - if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Für die Reederei %s werden die Anzahl der Werften in allen Häfen ermittelt.", + if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Für die Reederei %s werden die Anzahl der Werften in allen Häfen ermittelt.", __CLASS__, __LINE__, $this->getCompanyName() @@ -459,7 +452,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner $total = $this->shipyardList->count(); // Debug message - if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s hat %d Werft(en).", + if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Reederei %s hat %d Werft(en).", __CLASS__, __LINE__, $this->getCompanyName(), @@ -487,14 +480,6 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner $shipType )); - // Debug message - if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s baut in allen Werften bald Schiffe vom Typ %s.", - __CLASS__, - __LINE__, - $this->getCompanyName(), - $shipInstance->getObjectDescription() - )); - // Iterate shipyard list for ($idx = $this->shipyardList->getIterator(); $idx->valid(); $idx->next()) { // Get current element @@ -507,25 +492,18 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner } elseif (!is_object($shipyard)) { // Not an object! ;-( throw new NoObjectException($shipyard, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!$shipyard->isClass("Shipyard")) { + } elseif ($shipyard->isClass("Shipyard") === false) { // Class is not a shipyard throw new ClassMismatchException(array($shipyard->__toString(), "Shipyard"), self::EXCEPTION_CLASSES_NOT_MATCHING); } // Add the new ship type to the shipyard $shipyard->addNewConstructableShipType($shipType); - } + } // END - for } // Validate the requested ship type with the company if they can construct it public function validateWorksContractShipType (SignableContract $contractInstance) { - if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s prüft den Bauauftrag der %s.", - __CLASS__, - __LINE__, - $this->getCompanyName(), - $contractInstance->getShipName() - )); - // First get the ship type $shipInstance = $contractInstance->getShipInstance(); @@ -541,16 +519,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner // Get it's real class name $shipType = $shipInstance->__toString(); - // Debug message - if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s prüft, ob die %s (Typ:%s) gebaut werden kann.", - __CLASS__, - __LINE__, - $this->getCompanyName(), - $contractInstance->getShipName(), - $shipInstance->getObjectDescription() - )); - - // Now check if the ship type is in any list and return the result + // Now check if ship type is in any list and return the result return ($this->isShipTypeConstructable($shipType)); } @@ -560,7 +529,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner $shipType = (string) $shipType; // Debug message - if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s fragt alle Werften ab, ob diese Schiffe vom Typ %s bauen können.", + if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Reederei %s fragt alle Werften ab, ob diese Schiffe vom Typ %s bauen können.", __CLASS__, __LINE__, $this->getCompanyName(), @@ -582,20 +551,20 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner } elseif (!is_object($shipyard)) { // Not an object! ;-( throw new NoObjectException($shipyard, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!$shipyard->isClass("Shipyard")) { + } elseif ($shipyard->isClass("Shipyard") === false) { // Class is not a shipyard throw new ClassMismatchException(array($shipyard->__toString(), "Shipyard"), self::EXCEPTION_CLASSES_NOT_MATCHING); } - // Validate if the first found shipyard can construct the requested type + // Validate if first found shipyard can construct the requested type $result = $shipyard->isShipTypeConstructable($shipType); // Does this shipyard construct the requested ship type? if ($result) break; // Then abort the search! - } + } // END - for // Debug message - if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s hat die Suche nach einer Werft beendet, die Schiffe vom Typ %s bauen kann.", + if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Reederei %s hat die Suche nach einer Werft beendet, die Schiffe vom Typ %s bauen kann.", __CLASS__, __LINE__, $this->getCompanyName(), @@ -608,13 +577,6 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner // As a customer the shipping company can add new contracts public function addNewWorksContract (SignableContract $contractInstance) { - if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s erstellt einen Bauauftrag für ein %s mit dem Namen %s.", - __CLASS__, - __LINE__, - $this->getCompanyName(), - $contractInstance->getShipInstance()->getObjectDescription(), - $contractInstance->getShipInstance()->getShipName() - )); $this->contractList->append($contractInstance); } @@ -638,15 +600,15 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner // Sign a contract with an other party which must also implement Customer public function signContract (SignableContract $contractInstance, ContractPartner $partnerInstance) { // Check wether the other party is our contract partner - if (!$partnerInstance->isContractPartner($contractInstance)) { + if ($partnerInstance->isContractPartner($contractInstance) === false) { // Invalid contract partner! throw new InvalidContractPartnerException($partnerInstance, self::EXCEPTION_CONTRACT_PARTNER_INVALID); - } + } // END - if // Determine if company "signs" own contract (must be done) or with an other party if ($this->equals($partnerInstance)) { // With itself - if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s erteilt an sich selbst einen Bauauftrag für das %s "%s".", + if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Reederei %s erteilt an sich selbst einen Bauauftrag für das %s "%s".", __CLASS__, __LINE__, $this->getCompanyName(), @@ -655,7 +617,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner )); } else { // Other external company - if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei %s unterzeichnet einen Bauauftrag für das %s "%s" mit der %s.", + if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Die Reederei %s unterzeichnet einen Bauauftrag für das %s "%s" mit der %s.", __CLASS__, __LINE__, $this->getCompanyName(), @@ -690,7 +652,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner } elseif (!is_object($contractInstance)) { // Not an object! ;-( throw new NoObjectException($contractInstance, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!$contractInstance->isClass('WorksContract')) { + } elseif ($contractInstance->isClass("WorksContract") === false) { // Is not a merchant throw new ClassMismatchException(array($contractInstance->__toString(), "WorksContract"), self::EXCEPTION_CLASSES_NOT_MATCHING); }