private $contractList = null;
/**
- * Main constructor
+ * Database result instance
+ */
+ private $resultInstance = null;
+
+ // Exception constants
+ const EXCEPTION_USER_OWNS_NO_COMPANY = 0x200;
+
+ /**
+ * Protected constructor
*
* @return void
*/
parent::__construct(__CLASS__);
// Set description
- $this->setObjectDescription("Reederei");
+ $this->setObjectDescription("A shipping company class");
// Generate unique ID number
$this->generateUniqueId();
$this->removeSystemArray();
}
- // Reederei gruenden (create wegen Namenskonvention)
- public final static function createShippingCompany ($companyName, Harbor $hqInstance) {
+ /**
+ * Creates an instance of this company class or throws an exception if the
+ * given user owns no company.
+ *
+ * @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();
- if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $companyInstance->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> wird gegründet.",
- __CLASS__,
- __LINE__,
- $companyName
- ));
+ // 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);
+ } // END - if
- // Firmennamen setzen
- $companyInstance->setCompanyName($companyName);
+ // Set the user instance. We don't care here if he is founder or employee.
+ $companyInstance->setUserInstance($userInstance);
- // Kuerzel setzen
- $companyInstance->createShortName();
+ // Init all lists
+ $companyInstance->initCompanyLists();
- // Sitz festlegen
- $companyInstance->setHQInstance($hqInstance);
+ // Return instance
+ return $companyInstance;
+ }
- // Werftenliste erstellen
- $companyInstance->createshipyardList();
+ /**
+ * Checks wether the given user owns a company or not
+ *
+ * @param $userInstance An instance of a user class
+ * @return $ownsCompany Wether the user owns at least one company
+ */
+ protected function ifUserOwnsShippingCompany (BaseUser $userInstance) {
+ // By default no user owns any company... ;)
+ $ownsCompany = false;
- // Angestellten-Liste erstellen
- $companyInstance->createEmployeeList();
+ // Get a company database wrapper class
+ $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class');
- // Auftragsliste erstellen
- $companyInstance->createContractList();
+ // Get a search criteria class
+ $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
- // Clean up a little
- $companyInstance->removeWidth();
- $companyInstance->removeHeight();
- $companyInstance->removeLength();
- $companyInstance->removeDraught();
- $companyInstance->removePartInstance();
+ // Add the user primary key as a search criteria
+ $criteriaInstance->addCriteria('company_owner', $userInstance->getPrimaryKey());
+ $criteriaInstance->setLimit(1);
- // Instanz zurueckgeben
- return $companyInstance;
+ // Get the result back
+ $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+ $resultInstance->debugInstance();
}
- // Angestellten-Liste erstellen
- private function createEmployeeList () {
- if ((defined('DEBUG_COMPANY_EMPLOYEE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> erhält eine Angestelltenliste.",
- __CLASS__,
- __LINE__,
- $this->getCompanyName()
- ));
+ /**
+ * Intialize all lists
+ *
+ * @return void
+ */
+ protected function initCompanyLists () {
+ // Employees
$this->employeeList = new FrameworkArrayObject("FakedEmployeeList");
- }
- // Werftenliste erstellen
- public function createShipyardList () {
- if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> erhält eine Werftsliste.",
- __CLASS__,
- __LINE__,
- $this->getCompanyName()
- ));
+ // Ship yards
$this->shipyardList = new FrameworkArrayObject("FakedShipyardList");
- }
- // Auftragsliste erstellen
- public function createContractList () {
- if ((defined('DEBUG_COMPANY')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Reederei <strong>%s</strong> erhält eine Auftragsliste.",
- __CLASS__,
- __LINE__,
- $this->getCompanyName()
- ));
+ // Contracts
$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;
}
// Kuerzel setzen
- private function createShortName () {
+ private function initShortName () {
// Mindestens eine Leerstelle?
$dummy = explode(" ", $this->getCompanyName());
foreach ($dummy as $part) {
$this->shortName .= substr($part, 0, 1);
- }
+ } // END - if
}
// Reedereien Werften bauen lassen