X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=application%2Fship-simu%2Fmain%2Fpersonell%2Fclass_SimulatorPersonell.php;h=6c1e08407835b26f42d0a0f8a83356dcd2499706;hp=1d148ddb69d85809946e214177370e006cf6ea8a;hb=6ea93981ed22f96c996122c3e0e2171a39927b1c;hpb=87c949b6948ffa6fa7aa3c1701888b20f86de6ce diff --git a/application/ship-simu/main/personell/class_SimulatorPersonell.php b/application/ship-simu/main/personell/class_SimulatorPersonell.php index 1d148dd..6c1e084 100644 --- a/application/ship-simu/main/personell/class_SimulatorPersonell.php +++ b/application/ship-simu/main/personell/class_SimulatorPersonell.php @@ -4,9 +4,9 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @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 + * @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 @@ -19,7 +19,7 @@ * 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 . + * along with this program. If not, see . */ class SimulatorPersonell extends BasePersonell { // Personell list @@ -32,26 +32,13 @@ class SimulatorPersonell extends BasePersonell { private $cacheCond = null; /** - * Private constructor + * Protected constructor * * @return void */ - private function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); - - if (((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) $this->getDebugInstance()->output(sprintf("[%s:] Konstruktor erreicht.
\n", - $this->__toString() - )); - - // Set description - $this->setPartDescr("Simulationspersonal"); - - // Create unique ID - $this->createUniqueID(); - - // Clean-up a little - $this->removeSystemArray(); + parent::__construct(__CLASS__); } /** @@ -86,7 +73,7 @@ class SimulatorPersonell extends BasePersonell { $personellInstance = new SimulatorPersonell(); // Debug message - if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $personellInstance->getDebugInstance()->output(sprintf("[%s:%d] Es werden %d Personal bereitgestellt.
\n", + if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $personellInstance->debugOutput(sprintf("[%s:%d] Es werden %d Personal bereitgestellt.", __CLASS__, __LINE__, $amountPersonell @@ -101,7 +88,7 @@ class SimulatorPersonell extends BasePersonell { } // Debug message - if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $personellInstance->getDebugInstance()->output(sprintf("[%s:%d] %d Personal bereitgestellt.
\n", + if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $personellInstance->debugOutput(sprintf("[%s:%d] %d Personal bereitgestellt.", __CLASS__, __LINE__, $amountPersonell @@ -126,32 +113,27 @@ class SimulatorPersonell extends BasePersonell { * Create a SimulatorPersonell object by loading the specified personell * list from an existing database backend * - * @param $idNumber The ID number (only right part) of the list - * @return $personellInstance An instance of - * @throws InvalidIDFormatException If the given id number - * $idNumber is invalid - * @throws NullPointerException If a null pointer (instance) - * has been returned. - * @throws NoObjectException If a non-object has been - * returned - * @throws MissingMethodException If a required method is missing - * @throws MissingSimulatorIDException If an ID number was not found + * @param $idNumber The ID number (only right part) of the list + * @return $personellInstance An instance of this class + * @throws InvalidIDFormatException If the given id number + * $idNumber is invalid + * @throws MissingSimulatorIdException If an ID number was not found */ public final static function createSimulatorPersonellByID ($idNumber) { + // Use the direct ID number + $tempID = $idNumber; + // Add the class name if it was not found if (count(explode("@", $idNumber)) < 2) { // Add class name in front of the incomplete ID number $tempID = sprintf("%s@%s", __CLASS__, $idNumber); - } else { - // Use the direct ID number - $tempID = $idNumber; - } + } // END - if // Validate the ID number if (!preg_match(sprintf("/%s\@([a-f0-9]){32}/i", __CLASS__), $tempID)) { // Invalid format throw new InvalidIDFormatException(new SimulatorPersonell(), self::EXCEPTION_ID_IS_INVALID_FORMAT); - } + } // END - if // Get instance $personellInstance = new SimulatorPersonell(false); @@ -159,23 +141,11 @@ class SimulatorPersonell extends BasePersonell { // Get database instance $dbInstance = $personellInstance->getDatabaseInstance(); - // Is this a valid database instance? - if (is_null($dbInstance)) { - // No class returned - throw new NullPointerException($personellInstance, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_object($dbInstance)) { - // Not an object! ;-( - throw new NoObjectException($dbInstance, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!method_exists($dbInstance, 'isUniqueIdUsed')) { - // Required method not found - throw new MissingMethodException(array($dbInstance, 'isUniqueIdUsed'), self::EXCEPTION_MISSING_METHOD); - } - // Is the unique ID already used? Then it must be there! if (!$dbInstance->isUniqueIdUsed($tempID)) { // Entry not found! - throw new MissingSimulatorIDException(array($personellInstance, $idNumber), self::EXCEPTION_SIMULATOR_ID_INVALID); - } + throw new MissingSimulatorIdException(array($personellInstance, $idNumber), self::EXCEPTION_SIMULATOR_ID_INVALID); + } // END - if // Load the personell list and add it to this object $personellInstance->loadPersonellList($tempID); @@ -197,30 +167,25 @@ class SimulatorPersonell extends BasePersonell { // Create personell list public function createPersonellList () { - if (is_null($this->personellList)) { - if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Personell-Liste erstellt.
\n", - __CLASS__, - __LINE__ - )); - $this->personellList = new FrameworkArrayObject(); - } else { + // Is the list already created? + if ($this->personelllList instanceof FrameworkArrayObject) { + // Throw an exception throw new PersonellListAlreadyCreatedException($this, self::EXCEPTION_DIMENSION_ARRAY_INVALID); - } + } // END - if + + // Initialize the array + $this->personellList = new FrameworkArrayObject("FakedPersonellList"); } // Remove the personell list - private function removePersonellList () { - if (defined('DEBUG_PERSONELL')) $this->getDebugInstance()->output(sprintf("[%s:%d] Personell-Liste entfernt.
\n", - __CLASS__, - __LINE__ - )); + private final function removePersonellList () { unset($this->personellList); } // Add new personell object to our list public function addRandomPersonell () { // Gender list... - $genders = array('M', 'F'); + $genders = array("M", "F"); // Create new personell members $personellInstance = new SimulatorPersonell(); @@ -255,7 +220,7 @@ class SimulatorPersonell extends BasePersonell { // The same (last) conditions? if (($serialized == $this->cacheCond) && (!is_null($this->cacheCond))) { - if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Gecachte Liste wird verwendet.
\n", + if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Gecachte Liste wird verwendet.", __CLASS__, __LINE__ )); @@ -265,7 +230,7 @@ class SimulatorPersonell extends BasePersonell { } // Output debug message - if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Personalliste wird nach Kriterien durchsucht...
\n", + if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Personalliste wird nach Kriterien durchsucht...", __CLASS__, __LINE__ )); @@ -274,7 +239,7 @@ class SimulatorPersonell extends BasePersonell { $this->setCacheCond($serialized); // Create cached list - $this->setAllCacheList(new FrameworkArrayObject()); + $this->setAllCacheList(new FrameworkArrayObject('FakedCacheList')); // Search all unemployed personells for ($idx = $this->personellList->getIterator(); $idx->valid(); $idx->next()) { @@ -304,11 +269,6 @@ class SimulatorPersonell extends BasePersonell { * @return $count Amount of unemployed personell */ public final function getAllUnemployed () { - if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Es werden alle erwerbslosen Personen gesucht.
\n", - __CLASS__, - __LINE__ - )); - // Get a temporary list $list = $this->getSpecialPersonellList(false); @@ -322,11 +282,6 @@ class SimulatorPersonell extends BasePersonell { * @return void */ private function removeCache () { - if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Cache-Attribute entfernt.
\n", - __CLASS__, - __LINE__ - )); - // Remove cache data unset($this->cacheList); unset($this->cacheCond); @@ -358,10 +313,6 @@ class SimulatorPersonell extends BasePersonell { * @return void */ public function resetCache () { - if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Cache-Liste zurückgesetzt.
\n", - __CLASS__, - __LINE__ - )); $this->setAllCacheList(null); $this->setCacheCond(""); } @@ -370,10 +321,11 @@ class SimulatorPersonell extends BasePersonell { * Getter for surname. If no surname is set then default surnames are set * for male and female personells. * - * @return $surname The personell' surname + * @return $surname The personell' surname */ public final function getSurname () { $surname = parent::getSurname(); + // Make sure every one has a surname... if (empty($surname)) { if ($this->isMale()) { @@ -386,27 +338,10 @@ class SimulatorPersonell extends BasePersonell { // Set typical family name parent::setFamily("Smith"); - } - return $surname; - } - - /** - * Saves only the personell list to the database - * - * @return void - */ - public function saveObjectToDatabase () { - // Get the database - $dbInstance = $this->getDatabaseInstance(); - - // Prepare the limitation object. We just need the personellList array object. - $limitInstance = ObjectLimits::createObjectLimits(array("personellList")); - - // Limitate the saving amount - $dbInstance->limitObject($limitInstance); + } // END - if - // Save this object - $dbInstance->saveObject($this); + // Return surname + return $surname; } /** @@ -421,62 +356,20 @@ class SimulatorPersonell extends BasePersonell { /** * Loads the mostly pre-cached personell list * - * @param $idNumber The ID number we shall use for looking up + * @param $idNumber The ID number we shall use for looking up * the right data. * @return void * @throws ContainerItemIsNullException If a container item is null * @throws ContainerItemIsNoArrayException If a container item is - * not an array + * not an array * @throws ContainerMaybeDamagedException If the container item - * is missing the indexes - * 'name' and/or 'value' - * @see SerializationContainer A special container class which - * helps storing only some attributes - * of a class. + * is missing the indexes + * 'name' and/or 'value' + * @deprecated */ public function loadPersonellList ($idNumber) { - // Get database instance - $dbInstance = $this->getDatabaseInstance(); - - // Get the serialization container within the personell list from - // the database layer - $containerInstance = $dbInstance->getObjectFromCachedData($idNumber); - - // Iterate through the whole container - for ($idx = $containerInstance->getIterator(); $idx->valid(); $idx->next()) { - // Get current item from container - $item = $idx->current(); - - // Validate it a bit - if (is_null($item)) { - // Is null - throw new ContainerItemIsNullException($this, self::EXCEPTION_CONTAINER_ITEM_IS_NULL); - } elseif (!is_array($item)) { - // Is not an array - throw new ContainerItemIsNoArrayException($this, self::EXCEPTION_ITEM_IS_NO_ARRAY); - } elseif ((!isset($item['name'])) || (!isset($item['value']))) { - // Missing elements - throw new ContainerMaybeDamagedException($this, self::EXCEPTION_CONTAINER_MAYBE_DAMAGED); - } - - // Okay, now we can get the item and generate a valid command for eval(). - // We need to convert the first letter to lower-case but keep all others intact - $eval = sprintf("\$this->%s = \$item['value'];", - strtolower(substr($item['name'], 0, 1)) - . - substr($item['name'], 1) - ); - - // Debug message - if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruierte PHP-Anweisung:
%s

\n", - __CLASS__, - __LINE__, - htmlentities($eval) - )); - - // Run the command - @eval($eval); - } + // Cleared because old code + $this->partialStub("Cleared because old lost code was used."); } }