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