A lot debug messages removed, mailer with stubs added, resend link basicly finished...
[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, this is free software
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                 // Set description
56                 $this->setObjectDescription("Personal");
57         }
58
59         // Remove min/max ages
60         public final function removeMinMaxAge () {
61                 unset($this->MIN_AGE);
62                 unset($this->MAX_AGE);
63         }
64
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;
69
70                 // Get current year
71                 $currYear = date("Y", time());
72
73                 // Generate random year/month/day
74                 $year = mt_rand(($currYear - $this->MIN_AGE), ($currYear - $this->MAX_AGE));
75                 $month = 0;
76                 $day = 0;
77                 while (!$this->isDateValid($year, $month, $day)) {
78                         $month = mt_rand(1, 12);
79                         switch ($month) {
80                         case 1:
81                         case 3:
82                         case 5:
83                         case 7:
84                         case 8:
85                         case 10:
86                         case 12:
87                                 $day   = mt_rand(1, 31);
88                                 break;
89
90                         case 4:
91                         case 6:
92                         case 9:
93                         case 11:
94                                 $day   = mt_rand(1, 30);
95                                 break;
96
97                         case 2: // February
98                                 if ($year % 4 == 0) {
99                                         // Is a "Schaltjahr"
100                                         $day = mt_rand(1, 29);
101                                 } else {
102                                         // Regular year
103                                         $day = mt_rand(1, 28);
104                                 }
105                                 break;
106                         } // switch - END
107                 } // while - END
108
109                 // Set the new birthday
110                 $this->setBirthday($year, $month, $day);
111         }
112
113         // Is the current day valid?
114         public final function isDateValid ($year, $month, $day) {
115                 // Create timestamp
116                 $stamp = mktime(0, 0, 0, $month, $day, $year);
117
118                 // Get year/month/day back
119                 $y = date("Y", $stamp);
120                 $m = date("m", $stamp);
121                 $d = date("d", $stamp);
122
123                 // Compare all
124                 return (($y == $year) && ($m == $month) && ($d == $day));
125         }
126
127         // Employed?
128         public final function isEmployed () {
129                 return $this->employed;
130         }
131
132         // Married?
133         public final function isMarried () {
134                 return $this->married;
135         }
136
137         // Male?
138         public final function isMale () {
139                 return ($this->gender == "M");
140         }
141
142         // Female
143         public final function isFemale () {
144                 return ($this->gender == "F");
145         }
146
147         // Setter for surname
148         public final function setSurname ($surname) {
149                 $this->surname = (string) $surname;
150         }
151
152         // Getter for surname
153         public function getSurname () {
154                 return $this->surname;
155         }
156
157         // Setter for family name
158         public final function setFamily ($family) {
159                 $this->family = (string) $family;
160         }
161
162         // Getter for family name
163         public final function getFamily () {
164                 return $this->family;
165         }
166
167         // Setter for gender
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;
172                 } else {
173                         throw new WrongGenderSpecifiedException($gender, self::EXCEPTION_GENDER_IS_WRONG);
174                 }
175         }
176
177         // Getter for gender
178         public final function getGender () {
179                 return $this->gender;
180         }
181
182         // Setter for employment status
183         public final function setEmployed ($employed) {
184                 $this->employed = (boolean) $employed;
185         }
186
187         // Setter for marriage status
188         public final function setMarried ($married) {
189                 $this->married = (boolean) $married;
190         }
191
192         // Getter for salary
193         public final function getSalary () {
194                 return $this->salary;
195         }
196
197         // Increase salary
198         public final function increaseSalary ($add) {
199                 $this->salary += (float) abs($add);
200         }
201
202         // Decrease salary
203         public final function decreaseSalary ($sub) {
204                 $this->salary -= (float) abs($sub);
205         }
206
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);
212         }
213
214         // Remove gender
215         public final function removeGender () {
216                 unset($this->gender);
217         }
218
219         // Remove both names
220         public final function removeNames () {
221                 unset($this->surname);
222                 unset($this->family);
223         }
224
225         // Remove complete birthday
226         public final function removeBirthday () {
227                 unset($this->yearBirth);
228                 unset($this->monthBirth);
229                 unset($this->dayBirth);
230         }
231
232         // Remove salary
233         public final function removeSalary () {
234                 unset($this->salary);
235         }
236
237         // Remove employment status
238         public final function removeEmployed () {
239                 unset($this->employed);
240         }
241
242         // Remove marrital status
243         public final function removeMarried () {
244                 unset($this->married);
245         }
246 }
247
248 // [EOF]
249 ?>