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