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