]> git.mxchange.org Git - shipsimu.git/blobdiff - application/ship-simu/main/companies/class_ShippingCompany.php
Fake class names added, insertDataSet() stub added, dataset criteria added
[shipsimu.git] / application / ship-simu / main / companies / class_ShippingCompany.php
index 54b3e285cd0c246ae684e56506ced4b45d525592..f7616b32a8545dcce9eaa53896ab2fa34b6e68a7 100644 (file)
@@ -1,48 +1,80 @@
 <?php
-
-// Die Reederei-Klasse
+/**
+ * A shipping company may be founded with this class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
 class ShippingCompany extends BaseSimulator implements Customer, ContractPartner {
-       // Firmenname
+       /**
+        * Full name of this company
+        */
        private $companyName     = "Namenlose Reederei";
 
-       // Firmenkuerzel
+       /**
+        * Shorted name of this company
+        */
        private $shortName       = "";
 
-       // Reederei-Gruender
+       /**
+        * Instance of the founder
+        */
        private $founderInstance = null;
 
-       // Angestellten-Liste
+       /**
+        * Employed people by this company
+        */
        private $employeeList    = null;
 
-       // Zugewiesener Hafen
+       /**
+        * Headquarter harbor instance
+        */
        private $hqInstance      = null;
 
-       // Werftenliste
+       /**
+        * List of all assigned shipyards
+        */
        private $shipyardList   = null;
 
-       // Der Reederei gehoerenden Schiffe
+       /**
+        * List of owned ships
+        */
        private $ownedShips      = null;
 
-       // Bauauftraege als Kunde
+       /**
+        * Work constracts this company is currently working on
+        */
        private $contractList    = null;
 
-       // Konstruktor
-       private function __construct () {
-               // Eltern-Konstruktor aufrufen
-               parent::constructor(__CLASS__);
-
-               // Debug message
-               if (((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) {
-                       $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
-                               __CLASS__,
-                               __LINE__
-                       ));
-               }
+       /**
+        * Main constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
 
-               // Beschreibung setzen
-               $this->setPartDescr("Reederei");
+               // Set description
+               $this->setObjectDescription("Reederei");
 
-               // Unique-ID erzeugen
+               // Generate unique ID number
                $this->createUniqueID();
 
                // Clean up a little
@@ -50,9 +82,9 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        }
 
        // Reederei gruenden (create wegen Namenskonvention)
-       public static function createShippingCompany ($companyName, Harbor $hqInstance) {
-               // Instanz holen
-               $companyInstance = new ShippingCompany();               
+       public final static function createShippingCompany ($companyName, Harbor $hqInstance) {
+               // Get new instance
+               $companyInstance = new ShippingCompany();
 
                if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $companyInstance->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> wird gegr&uuml;ndet.<br />\n",
                        __CLASS__,
@@ -78,7 +110,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                // Auftragsliste erstellen
                $companyInstance->createContractList();
 
-               // Etwas aufraeumen
+               // Clean up a little
                $companyInstance->removeWidth();
                $companyInstance->removeHeight();
                $companyInstance->removeLength();
@@ -96,7 +128,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                        __LINE__,
                        $this->getCompanyName()
                ));
-               $this->employeeList = new FrameworkArrayObject();
+               $this->employeeList = new FrameworkArrayObject("FakedEmployeeList");
        }
 
        // Werftenliste erstellen
@@ -106,7 +138,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                        __LINE__,
                        $this->getCompanyName()
                ));
-               $this->shipyardList = new FrameworkArrayObject();
+               $this->shipyardList = new FrameworkArrayObject("FakedShipyardList");
        }
 
        // Auftragsliste erstellen
@@ -116,21 +148,21 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                        __LINE__,
                        $this->getCompanyName()
                ));
-               $this->contractList = new FrameworkArrayObject();
+               $this->contractList = new FrameworkArrayObject("FakedContractList");
        }
 
        // Setter-Methode fuer Firmennamen
-       public function setCompanyName ($companyName) {
+       public final function setCompanyName ($companyName) {
                $this->companyName = (string) $companyName;
        }
 
        // Getter-Methode fuer Firmennamen
-       public function getCompanyName () {
+       public final function getCompanyName () {
                return $this->companyName;
        }
 
        // Setter-Methode fuer Firmensitz
-       public function setHQInstance (Harbor $hqInstance) {
+       public final function setHQInstance (Harbor $hqInstance) {
                $this->hqInstance = $hqInstance;
        }
 
@@ -165,7 +197,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        }
 
        // Setter fuer Reederei-Gruender
-       public function setCompanyFounder(CompanyEmployee $founderInstance) {
+       public final function setCompanyFounder(CompanyEmployee $founderInstance) {
                if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> ist von <strong>%s %s</strong> gegr&uuml;ndet worden.<br />\n",
                        __CLASS__,
                        __LINE__,
@@ -177,7 +209,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        }
 
        // Getter for founder instance
-       public function getFounderInstance () {
+       public final function getFounderInstance () {
                return $this->founderInstance;
        }
 
@@ -189,7 +221,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                        $employeeInstance->getSurname(),
                        $employeeInstance->getFamily(),
                        $this->getCompanyName(),
-                       $employeeInstance->getPartDescr(),
+                       $employeeInstance->getObjectDescription(),
                        $this->formatCurrency($employeeInstance->getSalary())
                ));
                $this->employeeList->append($employeeInstance);
@@ -251,7 +283,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                                        // Element holen
                                        $employee = $iterator->current();
                                } else {
-                                       // Should normally not happen... :(
+                                       // Should normally not happen... :(
                                        throw new StructuresOutOfBoundsException($idx, self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
                                }
                        }
@@ -261,7 +293,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
 
                        // Make this person employed and give him some money to work
                        $employee->setEmployed(true);
-                       $employee->setPartDescr($dummy->getPartDescr());
+                       $employee->setObjectDescription($dummy->getObjectDescription());
                        $employee->setRealClass($dummy->__toString());
                        $employee->increaseSalary((mt_rand(7, 14) * 100)); // Are 700 to 1400 EUR for the begin okay?
 
@@ -341,7 +373,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        }
 
        // Getter for total employees
-       public function getTotalEmployee () {
+       public final function getTotalEmployee () {
                // Count all...
                $total = $this->employeeList->count();
 
@@ -358,7 +390,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        }
 
        // Getter for total shipyards
-       public function getTotalShipyards () {
+       public final function getTotalShipyards () {
                if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] F&uuml;r die Reederei <strong>%s</strong> werden die Anzahl der Werften in allen H&auml;fen ermittelt.<br />\n",
                        __CLASS__,
                        __LINE__,
@@ -394,7 +426,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                // Is the class there?
                if (!class_exists($shipType)) {
                        // Throw exception
-                       throw new ClassNotFoundException($shipType, 0);
+                       throw new ClassNotFoundException($shipType, self::EXCEPTION_CLASS_NOT_FOUND);
                }
 
                // Create dummy ship
@@ -408,7 +440,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                        __CLASS__,
                        __LINE__,
                        $this->getCompanyName(),
-                       $shipInstance->getPartDescr()
+                       $shipInstance->getObjectDescription()
                ));
 
                // Iterate shipyard list
@@ -434,7 +466,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        }
 
        // Validate the requested ship type with the company if they can construct it
-       public function validateWorksContractShipType (WorksContract $contractInstance) {
+       public function validateWorksContractShipType (SignableContract $contractInstance) {
                if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> pr&uuml;ft den Bauauftrag der <strong>%s</strong>.<br />\n",
                        __CLASS__,
                        __LINE__,
@@ -463,7 +495,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                        __LINE__,
                        $this->getCompanyName(),
                        $contractInstance->getShipName(),
-                       $shipInstance->getPartDescr()
+                       $shipInstance->getObjectDescription()
                ));
 
                // Now check if the ship type is in any list and return the result
@@ -506,7 +538,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                        // Validate if the first found shipyard can construct the requested type
                        $result = $shipyard->isShipTypeConstructable($shipType);
 
-                       // Does this shipyard construct the requested ship type?
+                       // Does this shipyard construct the requested ship type?
                        if ($result) break; // Then abort the search!
                }
 
@@ -523,24 +555,24 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        }
 
        // As a customer the shipping company can add new contracts
-       public function addNewWorksContract (WorksContract $contractInstance) {
+       public function addNewWorksContract (SignableContract $contractInstance) {
                if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> erstellt einen Bauauftrag f&uuml;r ein <strong>%s</strong> mit dem Namen <strong>%s</strong>.<br />\n",
                        __CLASS__,
                        __LINE__,
                        $this->getCompanyName(),
-                       $contractInstance->getShipInstance()->getPartDescr(),
+                       $contractInstance->getShipInstance()->getObjectDescription(),
                        $contractInstance->getShipInstance()->getShipName()
                ));
                $this->contractList->append($contractInstance);
        }
 
        // As a customer the shippng company can withdraw from a contract
-       public function withdrawFromContract (WorksContract $contractInstance) {
+       public function withdrawFromContract (SignableContract $contractInstance) {
                ApplicationEntryPoint::app_die("WITHDRAW:<pre>".print_r($contractInstance, true)."</pre>");
        }
 
        // Get latest added contract instance
-       public function getLastContractInstance () {
+       public final function getLastContractInstance () {
                // Get iterator
                $iter = $this->contractList->getIterator();
 
@@ -552,12 +584,13 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        }
 
        // Sign a contract with an other party which must also implement Customer
-       public function signContract (WorksContract $contractInstance, ContractPartner $partnerInstance) {
+       public function signContract (SignableContract $contractInstance, ContractPartner $partnerInstance) {
+               // Check wether the other party is our contract partner
                if (!$partnerInstance->isContractPartner($contractInstance)) {
                        // Invalid contract partner!
                        throw new InvalidContractPartnerException($partnerInstance, self::EXCEPTION_CONTRACT_PARTNER_INVALID);
                }
-               
+
                // Determine if company "signs" own contract (must be done) or with an other party
                if ($this->equals($partnerInstance)) {
                        // With itself
@@ -565,7 +598,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                                __CLASS__,
                                __LINE__,
                                $this->getCompanyName(),
-                               $contractInstance->getShipInstance()->getPartDescr(),
+                               $contractInstance->getShipInstance()->getObjectDescription(),
                                $contractInstance->getShipInstance()->getShipName()
                        ));
                } else {
@@ -574,7 +607,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                                __CLASS__,
                                __LINE__,
                                $this->getCompanyName(),
-                               $contractInstance->getShipInstance()->getPartDescr(),
+                               $contractInstance->getShipInstance()->getObjectDescription(),
                                $contractInstance->getShipInstance()->getShipName(),
                                $partnerInstance->getCompanyName()
                        ));
@@ -589,13 +622,13 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        }
 
        // Is this the right contract partner?
-       public function isContractPartner (WorksContract $contractInstance) {
+       public function isContractPartner (SignableContract $contractInstance) {
                // Get contract partner instance and compare it with $this contract partner
                return ($this->equals($contractInstance->getContractPartner()));
        }
 
        // Setter for merchant instance
-       public function setMerchantInstance (Merchant $merchantInstance) {
+       public final function setMerchantInstance (Merchant $merchantInstance) {
                // Get contract
                $contractInstance = $this->getLastContractInstance();
 
@@ -613,23 +646,6 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                // Set the merchant in the contract (for getting prices)
                $contractInstance->setMerchantInstance($merchantInstance);
        }
-
-       /**
-        * Stub!
-        */
-       public function saveObjectToDatabase () {
-               $this->getDebugInstance()->output(sprintf("[%s:] Stub <strong>%s</strong> erreicht.",
-                       $this->__toString(),
-                       __FUNCTION__
-               ));
-       }
-
-       /**
-        * Limits this object with an ObjectLimits instance
-        */
-       public function limitObject (ObjectLimits $limitInstance) {
-               ApplicationEntryPoint::app_die("".__METHOD__." reached! Stub!");
-       }
 }
 
 // [EOF]