class_SimulatorPersonell.php

Go to the documentation of this file.
00001 <?php
00024 class SimulatorPersonell extends BasePersonell {
00025         // Personell list
00026         private $personellList = null;
00027 
00028         // A cache for lists
00029         private $cacheList = null;
00030 
00031         // A string for cached conditions
00032         private $cacheCond = null;
00033 
00039         protected function __construct () {
00040                 // Call parent constructor
00041                 parent::__construct(__CLASS__);
00042         }
00043 
00052         public function __wakeup () {
00053                 // Tidy up a little
00054                 $this->removePersonellList();
00055                 $this->removeMinMaxAge();
00056                 $this->removeCache();
00057                 $this->removeSystemArray();
00058         }
00059 
00068         public final static function createSimulatorPersonell ($amountPersonell) {
00069                 // Make sure only integer can pass
00070                 $amountPersonell = (int) $amountPersonell;
00071 
00072                 // Get a new instance
00073                 $personellInstance = new SimulatorPersonell();
00074 
00075                 // Debug message
00076                 if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $personellInstance->debugOutput(sprintf("[%s:%d] Es werden <strong>%d</strong> Personal bereitgestellt.",
00077                         __CLASS__,
00078                         __LINE__,
00079                         $amountPersonell
00080                 ));
00081 
00082                 // Initialize the personell list
00083                 $personellInstance->createPersonellList();
00084 
00085                 // Create requested amount of personell
00086                 for ($idx = 0; $idx < $amountPersonell; $idx++) {
00087                         $personellInstance->addRandomPersonell();
00088                 }
00089 
00090                 // Debug message
00091                 if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $personellInstance->debugOutput(sprintf("[%s:%d] <strong>%d</strong> Personal bereitgestellt.",
00092                         __CLASS__,
00093                         __LINE__,
00094                         $amountPersonell
00095                 ));
00096 
00097                 // Tidy up a little
00098                 $personellInstance->removeGender();
00099                 $personellInstance->removeNames();
00100                 $personellInstance->removeBirthday();
00101                 $personellInstance->removeSalary();
00102                 $personellInstance->removeEmployed();
00103                 $personellInstance->removeMarried();
00104                 $personellInstance->removeNumberFormaters();
00105                 //$personellInstance->removeCache();
00106                 $personellInstance->removeSystemArray();
00107 
00108                 // Instanz zurueckgeben
00109                 return $personellInstance;
00110         }
00111 
00123         public final static function createSimulatorPersonellByID ($idNumber) {
00124                 // Get instance
00125                 $personellInstance = new SimulatorPersonell(false);
00126                 $personellInstance->makeDeprecated();
00127         }
00128 
00129         // Create personell list
00130         public function createPersonellList () {
00131                 // Is the list already created?
00132                 if ($this->personelllList instanceof FrameworkArrayObject) {
00133                         // Throw an exception
00134                         throw new PersonellListAlreadyCreatedException($this, self::EXCEPTION_DIMENSION_ARRAY_INVALID);
00135                 } // END - if
00136 
00137                 // Initialize the array
00138                 $this->personellList = new FrameworkArrayObject("FakedPersonellList");
00139         }
00140 
00141         // Remove the personell list
00142         private final function removePersonellList () {
00143                 unset($this->personellList);
00144         }
00145 
00146         // Add new personell object to our list
00147         public function addRandomPersonell () {
00148                 // Gender list...
00149                 $genders = array("M", "F");
00150 
00151                 // Create new personell members
00152                 $personellInstance = new SimulatorPersonell();
00153 
00154                 // Set a randomized gender
00155                 $personellInstance->setGender($genders[mt_rand(0, 1)]);
00156 
00157                 // Set a randomized birthday (maximum age required, see const MAX_AGE)
00158                 $personellInstance->createBirthday();
00159 
00160                 // Married? Same values means: married
00161                 if (mt_rand(0, 5) == mt_rand(0, 5)) $personellInstance->setMarried(true);
00162 
00163                 // Tidy up a little
00164                 $personellInstance->removePersonellList();
00165                 $personellInstance->removeMinMaxAge();
00166                 $personellInstance->removeCache();
00167                 $personellInstance->removeSystemArray();
00168 
00169                 // Add new member to the list
00170                 $this->personellList->append($personellInstance);
00171         }
00172 
00178         function getSpecialPersonellList ($isEmployed = null, $isMarried = null, $hasGender = "") {
00179                 // Serialize the conditions for checking if we can take the cache
00180                 $serialized = serialize(array($isEmployed, $isMarried, $hasGender));
00181 
00182                 // The same (last) conditions?
00183                 if (($serialized == $this->cacheCond) && (!is_null($this->cacheCond))) {
00184                         if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Gecachte Liste wird verwendet.",
00185                                 __CLASS__,
00186                                 __LINE__
00187                         ));
00188 
00189                         // Return cached list
00190                         return $this->cacheList;
00191                 }
00192 
00193                 // Output debug message
00194                 if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Personalliste wird nach Kriterien durchsucht...",
00195                         __CLASS__,
00196                         __LINE__
00197                 ));
00198 
00199                 // Remember the conditions
00200                 $this->setCacheCond($serialized);
00201 
00202                 // Create cached list
00203                 $this->setAllCacheList(new FrameworkArrayObject('FakedCacheList'));
00204 
00205                 // Search all unemployed personells
00206                 for ($idx = $this->personellList->getIterator(); $idx->valid(); $idx->next()) {
00207                         // Element holen
00208                         $el = $idx->current();
00209 
00210                         // Check currenylt all single conditions (combined conditions are not yet supported)
00211                         if ((!is_null($isEmployed)) && ($el->isEmployed() == $isEmployed)) {
00212                                 // Add this one (employed status asked)
00213                                 $this->cacheList->append($el);
00214                         } elseif ((!is_null($isMarried)) && ($el->isMarried() == $isMarried)) {
00215                                 // Add this one (marrital status asked)
00216                                 $this->cacheList->append($el);
00217                         } elseif ((!empty($hasGender)) && ($el->getGender() == $hasGender)) {
00218                                 // Add this one (specified gender)
00219                                 $this->cacheList->append($el);
00220                         }
00221                 }
00222 
00223                 // Return the completed list
00224                 return $this->cacheList;
00225         }
00226 
00232         public final function getAllUnemployed () {
00233                 // Get a temporary list
00234                 $list = $this->getSpecialPersonellList(false);
00235 
00236                 // Anzahl zurueckliefern
00237                 return $list->count();
00238         }
00239 
00245         private function removeCache () {
00246                 // Remove cache data
00247                 unset($this->cacheList);
00248                 unset($this->cacheCond);
00249         }
00250 
00257         private final function setAllCacheList (FrameworkArrayObject $cacheList = null) {
00258                 $this->cacheList = $cacheList;
00259         }
00260 
00267         private final function setCacheCond ($cacheCond) {
00268                 $this->cacheCond = (string) $cacheCond;
00269         }
00270 
00276         public function resetCache () {
00277                 $this->setAllCacheList(null);
00278                 $this->setCacheCond("");
00279         }
00280 
00287         public final function getSurname () {
00288                 $surname = parent::getSurname();
00289 
00290                 // Make sure every one has a surname...
00291                 if (empty($surname)) {
00292                         if ($this->isMale()) {
00293                                 // Typical male name
00294                                 $surname = "John";
00295                         } else {
00296                                 // Typical female name
00297                                 $surname = "Jennifer";
00298                         }
00299 
00300                         // Set typical family name
00301                         parent::setFamily("Smith");
00302                 } // END - if
00303 
00304                 // Return surname
00305                 return $surname;
00306         }
00307 
00313         public final function getPersonellList () {
00314                 return $this->personellList;
00315         }
00316 
00325         public function loadPersonellList ($idNumber) {
00326                 $this->makeDeprecated();
00327         }
00328 }
00329 
00330 // [EOF]
00331 ?>

Generated on Mon Dec 8 01:06:44 2008 for Ship-Simulator by  doxygen 1.5.6