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 protected function __construct ($className) {
52 // Call parent constructor
53 parent::__construct($className);
56 $this->setObjectDescription("Personal");
59 // Remove min/max ages
60 public final function removeMinMaxAge () {
61 unset($this->MIN_AGE);
62 unset($this->MAX_AGE);
65 // Generates a birthday based on MAX_AGE/MIN_AGE and the current date
66 public final function createBirthday () {
67 // Is the birthday already set?
68 if ($this->isDateValid($this->yearBirth, $this->monthBirth, $this->dayBirth)) return false;
71 $currYear = date("Y", time());
73 // Generate random year/month/day
74 $year = mt_rand(($currYear - $this->MIN_AGE), ($currYear - $this->MAX_AGE));
77 while (!$this->isDateValid($year, $month, $day)) {
78 $month = mt_rand(1, 12);
87 $day = mt_rand(1, 31);
94 $day = mt_rand(1, 30);
100 $day = mt_rand(1, 29);
103 $day = mt_rand(1, 28);
109 // Set the new birthday
110 $this->setBirthday($year, $month, $day);
113 // Is the current day valid?
114 public final function isDateValid ($year, $month, $day) {
116 $stamp = mktime(0, 0, 0, $month, $day, $year);
118 // Get year/month/day back
119 $y = date("Y", $stamp);
120 $m = date("m", $stamp);
121 $d = date("d", $stamp);
124 return (($y == $year) && ($m == $month) && ($d == $day));
128 public final function isEmployed () {
129 return $this->employed;
133 public final function isMarried () {
134 return $this->married;
138 public final function isMale () {
139 return ($this->gender == "M");
143 public final function isFemale () {
144 return ($this->gender == "F");
147 // Setter for surname
148 public final function setSurname ($surname) {
149 $this->surname = (string) $surname;
152 // Getter for surname
153 public function getSurname () {
154 return $this->surname;
157 // Setter for family name
158 public final function setFamily ($family) {
159 $this->family = (string) $family;
162 // Getter for family name
163 public final function getFamily () {
164 return $this->family;
168 public final function setGender ($gender) {
169 // Set random gender here
170 if (($gender == "M") || ($gender == "F") || ((empty($gender)) && ($this->getSurname() == ""))) {
171 $this->gender = $gender;
173 throw new WrongGenderSpecifiedException($gender, self::EXCEPTION_GENDER_IS_WRONG);
178 public final function getGender () {
179 return $this->gender;
182 // Setter for employment status
183 public final function setEmployed ($employed) {
184 $this->employed = (boolean) $employed;
187 // Setter for marriage status
188 public final function setMarried ($married) {
189 $this->married = (boolean) $married;
193 public final function getSalary () {
194 return $this->salary;
198 public final function increaseSalary ($add) {
199 $this->salary += (float) abs($add);
203 public final function decreaseSalary ($sub) {
204 $this->salary -= (float) abs($sub);
207 // Setter for birthday
208 public final function setBirthday ($year, $month, $day) {
209 $this->yearBirth = (int) abs($year);
210 $this->monthBirth = (int) abs($month);
211 $this->dayBirth = (int) abs($day);
215 public final function removeGender () {
216 unset($this->gender);
220 public final function removeNames () {
221 unset($this->surname);
222 unset($this->family);
225 // Remove complete birthday
226 public final function removeBirthday () {
227 unset($this->yearBirth);
228 unset($this->monthBirth);
229 unset($this->dayBirth);
233 public final function removeSalary () {
234 unset($this->salary);
237 // Remove employment status
238 public final function removeEmployed () {
239 unset($this->employed);
242 // Remove marrital status
243 public final function removeMarried () {
244 unset($this->married);