* @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 . */ class BasePersonell extends BaseFrameworkSystem implements Personellizer { // Maximum/minimum age private $MIN_AGE = 21; private $MAX_AGE = 40; // Male/female private $gender = ""; // M=Male, F=Female, empty=uninitialized // Year/month/day of birth private $yearBirth = 0; private $monthBirth = 0; private $dayBirth = 0; // Surname/family name private $surname = ""; private $family = ""; // Employed? private $employed = false; // Married? private $married = false; // Her/his salary private $salary = 0.00; // Constructor protected function __construct ($className) { // Call parent constructor parent::__construct($className); // Set description $this->setObjectDescription("Personal"); } // Remove min/max ages public final function removeMinMaxAge () { unset($this->MIN_AGE); unset($this->MAX_AGE); } // Generates a birthday based on MAX_AGE/MIN_AGE and the current date public final function createBirthday () { // Is the birthday already set? if ($this->isDateValid($this->yearBirth, $this->monthBirth, $this->dayBirth)) return false; // Get current year $currYear = date("Y", time()); // Generate random year/month/day $year = mt_rand(($currYear - $this->MIN_AGE), ($currYear - $this->MAX_AGE)); $month = 0; $day = 0; while (!$this->isDateValid($year, $month, $day)) { $month = mt_rand(1, 12); switch ($month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: $day = mt_rand(1, 31); break; case 4: case 6: case 9: case 11: $day = mt_rand(1, 30); break; case 2: // February if ($year % 4 == 0) { // Is a "Schaltjahr" $day = mt_rand(1, 29); } else { // Regular year $day = mt_rand(1, 28); } break; } // switch - END } // while - END // Set the new birthday $this->setBirthday($year, $month, $day); } // Is the current day valid? public final function isDateValid ($year, $month, $day) { // Create timestamp $stamp = mktime(0, 0, 0, $month, $day, $year); // Get year/month/day back $y = date("Y", $stamp); $m = date("m", $stamp); $d = date("d", $stamp); // Compare all return (($y == $year) && ($m == $month) && ($d == $day)); } // Employed? public final function isEmployed () { return $this->employed; } // Married? public final function isMarried () { return $this->married; } // Male? public final function isMale () { return ($this->gender == "M"); } // Female public final function isFemale () { return ($this->gender == "F"); } // Setter for surname public final function setSurname ($surname) { $this->surname = (string) $surname; } // Getter for surname public function getSurname () { return $this->surname; } // Setter for family name public final function setFamily ($family) { $this->family = (string) $family; } // Getter for family name public final function getFamily () { return $this->family; } // Setter for gender public final function setGender ($gender) { // Set random gender here if (($gender == "M") || ($gender == "F") || ((empty($gender)) && ($this->getSurname() == ""))) { $this->gender = $gender; } else { throw new WrongGenderSpecifiedException($gender, self::EXCEPTION_GENDER_IS_WRONG); } } // Getter for gender public final function getGender () { return $this->gender; } // Setter for employment status public final function setEmployed ($employed) { $this->employed = (boolean) $employed; } // Setter for marriage status public final function setMarried ($married) { $this->married = (boolean) $married; } // Getter for salary public final function getSalary () { return $this->salary; } // Increase salary public final function increaseSalary ($add) { $this->salary += (float) abs($add); } // Decrease salary public final function decreaseSalary ($sub) { $this->salary -= (float) abs($sub); } // Setter for birthday public final function setBirthday ($year, $month, $day) { $this->yearBirth = (int) abs($year); $this->monthBirth = (int) abs($month); $this->dayBirth = (int) abs($day); } // Remove gender public final function removeGender () { unset($this->gender); } // Remove both names public final function removeNames () { unset($this->surname); unset($this->family); } // Remove complete birthday public final function removeBirthday () { unset($this->yearBirth); unset($this->monthBirth); unset($this->dayBirth); } // Remove salary public final function removeSalary () { unset($this->salary); } // Remove employment status public final function removeEmployed () { unset($this->employed); } // Remove marrital status public final function removeMarried () { unset($this->married); } } // [EOF] ?>