<?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
}
// 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ündet.<br />\n",
__CLASS__,
// Auftragsliste erstellen
$companyInstance->createContractList();
- // Etwas aufraeumen
+ // Clean up a little
$companyInstance->removeWidth();
$companyInstance->removeHeight();
$companyInstance->removeLength();
}
// 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;
}
}
// 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ündet worden.<br />\n",
__CLASS__,
__LINE__,
}
// Getter for founder instance
- public function getFounderInstance () {
+ public final function getFounderInstance () {
return $this->founderInstance;
}
$employeeInstance->getSurname(),
$employeeInstance->getFamily(),
$this->getCompanyName(),
- $employeeInstance->getPartDescr(),
+ $employeeInstance->getObjectDescription(),
$this->formatCurrency($employeeInstance->getSalary())
));
$this->employeeList->append($employeeInstance);
// Element holen
$employee = $iterator->current();
} else {
- // Should normally not happen... :(
+ // Should normally not happen... :(
throw new StructuresOutOfBoundsException($idx, self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
}
}
// 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?
}
// Getter for total employees
- public function getTotalEmployee () {
+ public final function getTotalEmployee () {
// Count all...
$total = $this->employeeList->count();
}
// 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ür die Reederei <strong>%s</strong> werden die Anzahl der Werften in allen Häfen ermittelt.<br />\n",
__CLASS__,
__LINE__,
// 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
__CLASS__,
__LINE__,
$this->getCompanyName(),
- $shipInstance->getPartDescr()
+ $shipInstance->getObjectDescription()
));
// Iterate shipyard list
}
// 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üft den Bauauftrag der <strong>%s</strong>.<br />\n",
__CLASS__,
__LINE__,
__LINE__,
$this->getCompanyName(),
$contractInstance->getShipName(),
- $shipInstance->getPartDescr()
+ $shipInstance->getObjectDescription()
));
// Now check if the ship type is in any list and return the result
// 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!
}
}
// 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ü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();
}
// 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
__CLASS__,
__LINE__,
$this->getCompanyName(),
- $contractInstance->getShipInstance()->getPartDescr(),
+ $contractInstance->getShipInstance()->getObjectDescription(),
$contractInstance->getShipInstance()->getShipName()
));
} else {
__CLASS__,
__LINE__,
$this->getCompanyName(),
- $contractInstance->getShipInstance()->getPartDescr(),
+ $contractInstance->getShipInstance()->getObjectDescription(),
$contractInstance->getShipInstance()->getShipName(),
$partnerInstance->getCompanyName()
));
}
// 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();
// 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]