Copyright updated, menu class added for 'home'
[shipsimu.git] / application / ship-simu / main / class_BasePersonell.php
1 <?php
2 /**
3  * A general class for personell
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
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
10  *
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.
15  *
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.
20  *
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/>.
23  */
24 class BasePersonell extends BaseFrameworkSystem implements Personellizer {
25         // Maximum/minimum age
26         private $MIN_AGE = 21;
27         private $MAX_AGE = 40;
28
29         // Male/female
30         private $gender     = ""; // M=Male, F=Female, empty=uninitialized
31
32         // Year/month/day of birth
33         private $yearBirth  = 0;
34         private $monthBirth = 0;
35         private $dayBirth   = 0;
36
37         // Surname/family name
38         private $surname    = "";
39         private $family     = "";
40
41         // Employed?
42         private $employed   = false;
43
44         // Married?
45         private $married    = false;
46
47         // Her/his salary
48         private $salary     = 0.00;
49
50         // Constructor
51         protected function __construct ($className) {
52                 // Call parent constructor
53                 parent::__construct($className);
54
55                 // Tidy up a little
56                 $this->removeSystemArray();
57                 $this->removeNumberFormaters();
58         }
59
60         // Remove min/max ages
61         public final function removeMinMaxAge () {
62                 unset($this->MIN_AGE);
63                 unset($this->MAX_AGE);
64         }
65
66         // Generates a birthday based on MAX_AGE/MIN_AGE and the current date
67         public final function createBirthday () {
68                 // Is the birthday already set?
69                 if ($this->isDateValid($this->yearBirth, $this->monthBirth, $this->dayBirth)) return false;
70
71                 // Get current year
72                 $currYear = date("Y", time());
73
74                 // Generate random year/month/day
75                 $year = mt_rand(($currYear - $this->MIN_AGE), ($currYear - $this->MAX_AGE));
76                 $month = 0;
77                 $day = 0;
78                 while ($this->isDateValid($year, $month, $day) === false) {
79                         $month = mt_rand(1, 12);
80                         switch ($month) {
81                         case 1:
82                         case 3:
83                         case 5:
84                         case 7:
85                         case 8:
86                         case 10:
87                         case 12:
88                                 $day   = mt_rand(1, 31);
89                                 break;
90
91                         case 4:
92                         case 6:
93                         case 9:
94                         case 11:
95                                 $day   = mt_rand(1, 30);
96                                 break;
97
98                         case 2: // February
99                                 if ($year % 4 == 0) {
100                                         // Is a "Schaltjahr"
101                                         $day = mt_rand(1, 29);
102                                 } else {
103                                         // Regular year
104                                         $day = mt_rand(1, 28);
105                                 }
106                                 break;
107                         } // END - switch
108                 } // END - while
109
110                 // Set the new birthday
111                 $this->setBirthday($year, $month, $day);
112         }
113
114         // Is the current day valid?
115         public final function isDateValid ($year, $month, $day) {
116                 // Create timestamp
117                 $stamp = mktime(0, 0, 0, $month, $day, $year);
118
119                 // Get year/month/day back
120                 $y = date("Y", $stamp);
121                 $m = date("m", $stamp);
122                 $d = date("d", $stamp);
123
124                 // Compare all
125                 return (($y == $year) && ($m == $month) && ($d == $day));
126         }
127
128         // Employed?
129         public final function isEmployed () {
130                 return $this->employed;
131         }
132
133         // Married?
134         public final function isMarried () {
135                 return $this->married;
136         }
137
138         // Male?
139         public final function isMale () {
140                 return ($this->gender == "M");
141         }
142
143         // Female
144         public final function isFemale () {
145                 return ($this->gender == "F");
146         }
147
148         // Setter for surname
149         public final function setSurname ($surname) {
150                 $this->surname = (string) $surname;
151         }
152
153         // Getter for surname
154         public function getSurname () {
155                 return $this->surname;
156         }
157
158         // Setter for family name
159         public final function setFamily ($family) {
160                 $this->family = (string) $family;
161         }
162
163         // Getter for family name
164         public final function getFamily () {
165                 return $this->family;
166         }
167
168         // Setter for gender
169         public final function setGender ($gender) {
170                 // Set random gender here
171                 if (($gender == "M") || ($gender == "F") || ((empty($gender)) && ($this->getSurname() == ""))) {
172                         $this->gender = $gender;
173                 } else {
174                         throw new WrongGenderSpecifiedException($gender, self::EXCEPTION_GENDER_IS_WRONG);
175                 }
176         }
177
178         // Getter for gender
179         public final function getGender () {
180                 return $this->gender;
181         }
182
183         // Setter for employment status
184         public final function setEmployed ($employed) {
185                 $this->employed = (boolean) $employed;
186         }
187
188         // Setter for marriage status
189         public final function setMarried ($married) {
190                 $this->married = (boolean) $married;
191         }
192
193         // Getter for salary
194         public final function getSalary () {
195                 return $this->salary;
196         }
197
198         // Increase salary
199         public final function increaseSalary ($add) {
200                 $this->salary += (float) abs($add);
201         }
202
203         // Decrease salary
204         public final function decreaseSalary ($sub) {
205                 $this->salary -= (float) abs($sub);
206         }
207
208         // Setter for birthday
209         public final function setBirthday ($year, $month, $day) {
210                 $this->yearBirth  = (int) abs($year);
211                 $this->monthBirth = (int) abs($month);
212                 $this->dayBirth   = (int) abs($day);
213         }
214
215         // Remove gender
216         public final function removeGender () {
217                 unset($this->gender);
218         }
219
220         // Remove both names
221         public final function removeNames () {
222                 unset($this->surname);
223                 unset($this->family);
224         }
225
226         // Remove complete birthday
227         public final function removeBirthday () {
228                 unset($this->yearBirth);
229                 unset($this->monthBirth);
230                 unset($this->dayBirth);
231         }
232
233         // Remove salary
234         public final function removeSalary () {
235                 unset($this->salary);
236         }
237
238         // Remove employment status
239         public final function removeEmployed () {
240                 unset($this->employed);
241         }
242
243         // Remove marrital status
244         public final function removeMarried () {
245                 unset($this->married);
246         }
247 }
248
249 // [EOF]
250 ?>