class_BasePersonell.php

Go to the documentation of this file.
00001 <?php
00024 class BasePersonell extends BaseFrameworkSystem implements Personellizer {
00025         // Maximum/minimum age
00026         private $MIN_AGE = 21;
00027         private $MAX_AGE = 40;
00028 
00029         // Male/female
00030         private $gender     = ""; // M=Male, F=Female, empty=uninitialized
00031 
00032         // Year/month/day of birth
00033         private $yearBirth  = 0;
00034         private $monthBirth = 0;
00035         private $dayBirth   = 0;
00036 
00037         // Surname/family name
00038         private $surname    = "";
00039         private $family     = "";
00040 
00041         // Employed?
00042         private $employed   = false;
00043 
00044         // Married?
00045         private $married    = false;
00046 
00047         // Her/his salary
00048         private $salary     = 0.00;
00049 
00050         // Constructor
00051         protected function __construct ($className) {
00052                 // Call parent constructor
00053                 parent::__construct($className);
00054 
00055                 // Tidy up a little
00056                 $this->removeSystemArray();
00057                 $this->removeNumberFormaters();
00058         }
00059 
00060         // Remove min/max ages
00061         public final function removeMinMaxAge () {
00062                 unset($this->MIN_AGE);
00063                 unset($this->MAX_AGE);
00064         }
00065 
00066         // Generates a birthday based on MAX_AGE/MIN_AGE and the current date
00067         public final function createBirthday () {
00068                 // Is the birthday already set?
00069                 if ($this->isDateValid($this->yearBirth, $this->monthBirth, $this->dayBirth)) return false;
00070 
00071                 // Get current year
00072                 $currYear = date("Y", time());
00073 
00074                 // Generate random year/month/day
00075                 $year = mt_rand(($currYear - $this->MIN_AGE), ($currYear - $this->MAX_AGE));
00076                 $month = 0;
00077                 $day = 0;
00078                 while ($this->isDateValid($year, $month, $day) === false) {
00079                         $month = mt_rand(1, 12);
00080                         switch ($month) {
00081                         case 1:
00082                         case 3:
00083                         case 5:
00084                         case 7:
00085                         case 8:
00086                         case 10:
00087                         case 12:
00088                                 $day   = mt_rand(1, 31);
00089                                 break;
00090 
00091                         case 4:
00092                         case 6:
00093                         case 9:
00094                         case 11:
00095                                 $day   = mt_rand(1, 30);
00096                                 break;
00097 
00098                         case 2: // February
00099                                 if ($year % 4 == 0) {
00100                                         // Is a "Schaltjahr"
00101                                         $day = mt_rand(1, 29);
00102                                 } else {
00103                                         // Regular year
00104                                         $day = mt_rand(1, 28);
00105                                 }
00106                                 break;
00107                         } // END - switch
00108                 } // END - while
00109 
00110                 // Set the new birthday
00111                 $this->setBirthday($year, $month, $day);
00112         }
00113 
00114         // Is the current day valid?
00115         public final function isDateValid ($year, $month, $day) {
00116                 // Create timestamp
00117                 $stamp = mktime(0, 0, 0, $month, $day, $year);
00118 
00119                 // Get year/month/day back
00120                 $y = date("Y", $stamp);
00121                 $m = date("m", $stamp);
00122                 $d = date("d", $stamp);
00123 
00124                 // Compare all
00125                 return (($y == $year) && ($m == $month) && ($d == $day));
00126         }
00127 
00128         // Employed?
00129         public final function isEmployed () {
00130                 return $this->employed;
00131         }
00132 
00133         // Married?
00134         public final function isMarried () {
00135                 return $this->married;
00136         }
00137 
00138         // Male?
00139         public final function isMale () {
00140                 return ($this->gender == "M");
00141         }
00142 
00143         // Female
00144         public final function isFemale () {
00145                 return ($this->gender == "F");
00146         }
00147 
00148         // Setter for surname
00149         public final function setSurname ($surname) {
00150                 $this->surname = (string) $surname;
00151         }
00152 
00153         // Getter for surname
00154         public function getSurname () {
00155                 return $this->surname;
00156         }
00157 
00158         // Setter for family name
00159         public final function setFamily ($family) {
00160                 $this->family = (string) $family;
00161         }
00162 
00163         // Getter for family name
00164         public final function getFamily () {
00165                 return $this->family;
00166         }
00167 
00168         // Setter for gender
00169         public final function setGender ($gender) {
00170                 // Set random gender here
00171                 if (($gender == "M") || ($gender == "F") || ((empty($gender)) && ($this->getSurname() == ""))) {
00172                         $this->gender = $gender;
00173                 } else {
00174                         throw new WrongGenderSpecifiedException($gender, self::EXCEPTION_GENDER_IS_WRONG);
00175                 }
00176         }
00177 
00178         // Getter for gender
00179         public final function getGender () {
00180                 return $this->gender;
00181         }
00182 
00183         // Setter for employment status
00184         public final function setEmployed ($employed) {
00185                 $this->employed = (boolean) $employed;
00186         }
00187 
00188         // Setter for marriage status
00189         public final function setMarried ($married) {
00190                 $this->married = (boolean) $married;
00191         }
00192 
00193         // Getter for salary
00194         public final function getSalary () {
00195                 return $this->salary;
00196         }
00197 
00198         // Increase salary
00199         public final function increaseSalary ($add) {
00200                 $this->salary += (float) abs($add);
00201         }
00202 
00203         // Decrease salary
00204         public final function decreaseSalary ($sub) {
00205                 $this->salary -= (float) abs($sub);
00206         }
00207 
00208         // Setter for birthday
00209         public final function setBirthday ($year, $month, $day) {
00210                 $this->yearBirth  = (int) abs($year);
00211                 $this->monthBirth = (int) abs($month);
00212                 $this->dayBirth   = (int) abs($day);
00213         }
00214 
00215         // Remove gender
00216         public final function removeGender () {
00217                 unset($this->gender);
00218         }
00219 
00220         // Remove both names
00221         public final function removeNames () {
00222                 unset($this->surname);
00223                 unset($this->family);
00224         }
00225 
00226         // Remove complete birthday
00227         public final function removeBirthday () {
00228                 unset($this->yearBirth);
00229                 unset($this->monthBirth);
00230                 unset($this->dayBirth);
00231         }
00232 
00233         // Remove salary
00234         public final function removeSalary () {
00235                 unset($this->salary);
00236         }
00237 
00238         // Remove employment status
00239         public final function removeEmployed () {
00240                 unset($this->employed);
00241         }
00242 
00243         // Remove marrital status
00244         public final function removeMarried () {
00245                 unset($this->married);
00246         }
00247 }
00248 
00249 // [EOF]
00250 ?>

Generated on Mon Dec 8 01:06:44 2008 for Ship-Simulator by  doxygen 1.5.6