3 * A general class for personell
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team
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 protected function __construct ($className) {
52 // Call parent constructor
53 parent::__construct($className);
56 // Remove min/max ages
57 public final function removeMinMaxAge () {
58 unset($this->MIN_AGE);
59 unset($this->MAX_AGE);
62 // Generates a birthday based on MAX_AGE/MIN_AGE and the current date
63 public final function createBirthday () {
64 // Is the birthday already set?
65 if ($this->isDateValid($this->yearBirth, $this->monthBirth, $this->dayBirth)) return false;
68 $currYear = date("Y", time());
70 // Generate random year/month/day
71 $year = mt_rand(($currYear - $this->MIN_AGE), ($currYear - $this->MAX_AGE));
74 while ($this->isDateValid($year, $month, $day) === false) {
75 $month = mt_rand(1, 12);
84 $day = mt_rand(1, 31);
91 $day = mt_rand(1, 30);
97 $day = mt_rand(1, 29);
100 $day = mt_rand(1, 28);
106 // Set the new birthday
107 $this->setBirthday($year, $month, $day);
110 // Is the current day valid?
111 public final function isDateValid ($year, $month, $day) {
113 $stamp = mktime(0, 0, 0, $month, $day, $year);
115 // Get year/month/day back
116 $y = date("Y", $stamp);
117 $m = date("m", $stamp);
118 $d = date("d", $stamp);
121 return (($y == $year) && ($m == $month) && ($d == $day));
125 public final function isEmployed () {
126 return $this->employed;
130 public final function isMarried () {
131 return $this->married;
135 public final function isMale () {
136 return ($this->gender == "M");
140 public final function isFemale () {
141 return ($this->gender == "F");
144 // Setter for surname
145 public final function setSurname ($surname) {
146 $this->surname = (string) $surname;
149 // Getter for surname
150 public function getSurname () {
151 return $this->surname;
154 // Setter for family name
155 public final function setFamily ($family) {
156 $this->family = (string) $family;
159 // Getter for family name
160 public final function getFamily () {
161 return $this->family;
165 public final function setGender ($gender) {
166 // Set random gender here
167 if (($gender == "M") || ($gender == "F") || ((empty($gender)) && ($this->getSurname() == ""))) {
168 $this->gender = $gender;
170 throw new WrongGenderSpecifiedException($gender, self::EXCEPTION_GENDER_IS_WRONG);
175 public final function getGender () {
176 return $this->gender;
179 // Setter for employment status
180 public final function setEmployed ($employed) {
181 $this->employed = (boolean) $employed;
184 // Setter for marriage status
185 public final function setMarried ($married) {
186 $this->married = (boolean) $married;
190 public final function getSalary () {
191 return $this->salary;
195 public final function increaseSalary ($add) {
196 $this->salary += (float) abs($add);
200 public final function decreaseSalary ($sub) {
201 $this->salary -= (float) abs($sub);
204 // Setter for birthday
205 public final function setBirthday ($year, $month, $day) {
206 $this->yearBirth = (int) abs($year);
207 $this->monthBirth = (int) abs($month);
208 $this->dayBirth = (int) abs($day);
212 public final function removeGender () {
213 unset($this->gender);
217 public final function removeNames () {
218 unset($this->surname);
219 unset($this->family);
222 // Remove complete birthday
223 public final function removeBirthday () {
224 unset($this->yearBirth);
225 unset($this->monthBirth);
226 unset($this->dayBirth);
230 public final function removeSalary () {
231 unset($this->salary);
234 // Remove employment status
235 public final function removeEmployed () {
236 unset($this->employed);
239 // Remove marrital status
240 public final function removeMarried () {
241 unset($this->married);