+++ /dev/null
-<?php
-/**
- * The general simulator personell class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 SimulatorPersonell extends BasePersonell {
- // Personell list
- private $personellList = null;
-
- // A cache for lists
- private $cacheList = null;
-
- // A string for cached conditions
- private $cacheCond = null;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Magic wake-up method called when unserialize() is called. This is
- * neccessary because in this case a personell does not need to know the
- * min/max ages range and system classes. This would anyway use more RAM
- * what is not required.
- *
- * @return void
- */
- public function __wakeup () {
- // Tidy up a little
- $this->removePersonellList();
- $this->removeMinMaxAge();
- $this->removeCache();
- }
-
- /**
- * Generate a specified amount of personell and return the prepared instance
- *
- * @param $amountPersonell Number of personell we shall
- * generate
- * @return $personellInstance An instance of this object with a
- * list of personells
- */
- public static final function createSimulatorPersonell ($amountPersonell) {
- // Make sure only integer can pass
- $amountPersonell = (int) $amountPersonell;
-
- // Get a new instance
- $personellInstance = new SimulatorPersonell();
-
- // Debug message
- if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $personellInstance->debugOutput(sprintf("[%s:%d] Es werden <strong>%d</strong> Personal bereitgestellt.",
- __CLASS__,
- __LINE__,
- $amountPersonell
- ));
-
- // Initialize the personell list
- $personellInstance->createPersonellList();
-
- // Create requested amount of personell
- for ($idx = 0; $idx < $amountPersonell; $idx++) {
- $personellInstance->addRandomPersonell();
- }
-
- // Debug message
- if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $personellInstance->debugOutput(sprintf("[%s:%d] <strong>%d</strong> Personal bereitgestellt.",
- __CLASS__,
- __LINE__,
- $amountPersonell
- ));
-
- // Tidy up a little
- $personellInstance->removeGender();
- $personellInstance->removeNames();
- $personellInstance->removeBirthday();
- $personellInstance->removeSalary();
- $personellInstance->removeEmployed();
- $personellInstance->removeMarried();
- //$personellInstance->removeCache();
-
- // Instanz zurueckgeben
- return $personellInstance;
- }
-
- /**
- * 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 this class
- * @throws InvalidIDFormatException If the given id number
- * $idNumber is invalid
- * @throws MissingSimulatorIdException If an ID number was not found
- * @deprecated
- */
- public static final function createSimulatorPersonellByID ($idNumber) {
- // Get instance
- $personellInstance = new SimulatorPersonell(false);
- $personellInstance->makeDeprecated();
- }
-
- // Create personell list
- public function createPersonellList () {
- // 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 final function removePersonellList () {
- unset($this->personellList);
- }
-
- // Add new personell object to our list
- public function addRandomPersonell () {
- // Gender list...
- $genders = array("M", "F");
-
- // Create new personell members
- $personellInstance = new SimulatorPersonell();
-
- // Set a randomized gender
- $personellInstance->setGender($genders[mt_rand(0, 1)]);
-
- // Set a randomized birthday (maximum age required, see const MAX_AGE)
- $personellInstance->createBirthday();
-
- // Married? Same values means: married
- if (mt_rand(0, 5) == mt_rand(0, 5)) $personellInstance->setMarried(true);
-
- // Tidy up a little
- $personellInstance->removePersonellList();
- $personellInstance->removeMinMaxAge();
- $personellInstance->removeCache();
-
- // Add new member to the list
- $this->personellList->append($personellInstance);
- }
-
- /**
- * Get a specifyable list of our people, null or empty string will be ignored!
- *
- * @return $cacheList A list of cached personells
- */
- function getSpecialPersonellList ($isEmployed = null, $isMarried = null, $hasGender = "") {
- // Serialize the conditions for checking if we can take the cache
- $serialized = serialize(array($isEmployed, $isMarried, $hasGender));
-
- // The same (last) conditions?
- if (($serialized == $this->cacheCond) && (!is_null($this->cacheCond))) {
- if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Gecachte Liste wird verwendet.",
- __CLASS__,
- __LINE__
- ));
-
- // Return cached list
- return $this->cacheList;
- }
-
- // Output debug message
- if ((defined('DEBUG_PERSONELL')) || (defined('DEBUG_ALL'))) $this->debugOutput(sprintf("[%s:%d] Personalliste wird nach Kriterien durchsucht...",
- __CLASS__,
- __LINE__
- ));
-
- // Remember the conditions
- $this->setCacheCond($serialized);
-
- // Create cached list
- $this->setAllCacheList(new FrameworkArrayObject('FakedCacheList'));
-
- // Search all unemployed personells
- for ($idx = $this->personellList->getIterator(); $idx->valid(); $idx->next()) {
- // Element holen
- $el = $idx->current();
-
- // Check currenylt all single conditions (combined conditions are not yet supported)
- if ((!is_null($isEmployed)) && ($el->isEmployed() == $isEmployed)) {
- // Add this one (employed status asked)
- $this->cacheList->append($el);
- } elseif ((!is_null($isMarried)) && ($el->isMarried() == $isMarried)) {
- // Add this one (marrital status asked)
- $this->cacheList->append($el);
- } elseif ((!empty($hasGender)) && ($el->getGender() == $hasGender)) {
- // Add this one (specified gender)
- $this->cacheList->append($el);
- }
- }
-
- // Return the completed list
- return $this->cacheList;
- }
-
- /**
- * Get amount of unemployed personell
- *
- * @return $count Amount of unemployed personell
- */
- public final function getAllUnemployed () {
- // Get a temporary list
- $list = $this->getSpecialPersonellList(false);
-
- // Anzahl zurueckliefern
- return $list->count();
- }
-
- /**
- * Remove cache things
- *
- * @return void
- */
- private function removeCache () {
- // Remove cache data
- unset($this->cacheList);
- unset($this->cacheCond);
- }
-
- /**
- * Setter for cache list
- *
- * @param $cacheList The new cache list to set or null for initialization/reset
- * @return void
- */
- private final function setAllCacheList (FrameworkArrayObject $cacheList = null) {
- $this->cacheList = $cacheList;
- }
-
- /**
- * Setter for cache conditions
- *
- * @param $cacheCond The new cache conditions to set
- * @return void
- */
- private final function setCacheCond ($cacheCond) {
- $this->cacheCond = (string) $cacheCond;
- }
-
- /**
- * Reset cache list
- *
- * @return void
- */
- public function resetCache () {
- $this->setAllCacheList(null);
- $this->setCacheCond("");
- }
-
- /**
- * Getter for surname. If no surname is set then default surnames are set
- * for male and female personells.
- *
- * @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()) {
- // Typical male name
- $surname = "John";
- } else {
- // Typical female name
- $surname = "Jennifer";
- }
-
- // Set typical family name
- parent::setFamily("Smith");
- } // END - if
-
- // Return surname
- return $surname;
- }
-
- /**
- * Getter for personell list
- *
- * @return $personellList The list of all personells
- */
- public final function getPersonellList () {
- return $this->personellList;
- }
-
- /**
- * Loads the mostly pre-cached personell list
- *
- * @param $idNumber The ID number we shall use for looking up
- * the right data.
- * @return void
- * @deprecated
- */
- public function loadPersonellList ($idNumber) {
- $this->makeDeprecated();
- }
-}
-
-// [EOF]
-?>