3 * A general class for personell
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class BasePersonell extends BaseFrameworkSystem implements Personellizer {
25 // Maximum/minimum age
26 private $MIN_AGE = 21;
27 private $MAX_AGE = 40;
30 private $gender = ""; // M=Male, F=Female, empty=uninitialized
32 // Year/month/day of birth
33 private $yearBirth = 0;
34 private $monthBirth = 0;
35 private $dayBirth = 0;
37 // Surname/family name
38 private $surname = "";
42 private $employed = false;
45 private $married = false;
48 private $salary = 0.00;
51 private function __construct ($class) {
52 // Call parent constructor
53 parent::constructor($class);
56 if ((defined('DEBUG_PERSONELL')) && (defined('DEBUG_CONSTRUCT'))) $this->getDebugInstance()->output("[PersonellBase:] Konstruktor erreicht.<br />\n");
59 $this->setPartDescr("Personal");
62 // Calls the constructor
63 public function constructor ($class) {
64 $this->__construct($class);
67 // Remove min/max ages
68 public final function removeMinMaxAge () {
69 if (defined('DEBUG_PERSONELL')) $this->getDebugInstance()->output(sprintf("[%s:%d] Minimum-/Maximum-Alter entfernt.<br />\n",
73 unset($this->MIN_AGE);
74 unset($this->MAX_AGE);
77 // Generates a birthday based on MAX_AGE/MIN_AGE and the current date
78 public final function createBirthday () {
79 // Is the birthday already set?
80 if ($this->isDateValid($this->yearBirth, $this->monthBirth, $this->dayBirth)) return false;
83 $currYear = date("Y", time());
85 // Generate random year/month/day
86 $year = mt_rand(($currYear - $this->MIN_AGE), ($currYear - $this->MAX_AGE));
89 while (!$this->isDateValid($year, $month, $day)) {
90 $month = mt_rand(1, 12);
99 $day = mt_rand(1, 31);
106 $day = mt_rand(1, 30);
110 if ($year % 4 == 0) {
112 $day = mt_rand(1, 29);
115 $day = mt_rand(1, 28);
121 // Set the new birthday
122 $this->setBirthday($year, $month, $day);
125 // Is the current day valid?
126 public final function isDateValid ($year, $month, $day) {
128 $stamp = mktime(0, 0, 0, $month, $day, $year);
130 // Get year/month/day back
131 $y = date("Y", $stamp);
132 $m = date("m", $stamp);
133 $d = date("d", $stamp);
136 return (($y == $year) && ($m == $month) && ($d == $day));
140 public final function isEmployed () {
141 return $this->employed;
145 public final function isMarried () {
146 return $this->married;
150 public final function isMale () {
151 return ($this->gender == "M");
155 public final function isFemale () {
156 return ($this->gender == "F");
159 // Setter for surname
160 public final function setSurname ($surname) {
161 $this->surname = (string) $surname;
164 // Getter for surname
165 public function getSurname () {
166 return $this->surname;
169 // Setter for family name
170 public final function setFamily ($family) {
171 $this->family = (string) $family;
174 // Getter for family name
175 public final function getFamily () {
176 return $this->family;
180 public final function setGender ($gender) {
181 // Set random gender here
182 if (($gender == "M") || ($gender == "F") || ((empty($gender)) && ($this->getSurname() == ""))) {
183 $this->gender = $gender;
185 throw new WrongGenderSpecifiedException($gender, self::EXCEPTION_GENDER_IS_WRONG);
190 public final function getGender () {
191 return $this->gender;
194 // Setter for employment status
195 public final function setEmployed ($employed) {
196 $this->employed = (boolean) $employed;
199 // Setter for marriage status
200 public final function setMarried ($married) {
201 $this->married = (boolean) $married;
205 public final function getSalary () {
206 return $this->salary;
210 public final function increaseSalary ($add) {
211 $this->salary += (float) abs($add);
215 public final function decreaseSalary ($sub) {
216 $this->salary -= (float) abs($sub);
219 // Setter for birthday
220 public final function setBirthday ($year, $month, $day) {
221 $this->yearBirth = (int) abs($year);
222 $this->monthBirth = (int) abs($month);
223 $this->dayBirth = (int) abs($day);
227 public final function removeGender () {
228 unset($this->gender);
232 public final function removeNames () {
233 unset($this->surname);
234 unset($this->family);
237 // Remove complete birthday
238 public final function removeBirthday () {
239 unset($this->yearBirth);
240 unset($this->monthBirth);
241 unset($this->dayBirth);
245 public final function removeSalary () {
246 unset($this->salary);
249 // Remove employment status
250 public final function removeEmployed () {
251 unset($this->employed);
254 // Remove marrital status
255 public final function removeMarried () {
256 unset($this->married);