PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Testing/Version-Three/src/main/resources/php/model/User.php

http://qnet-ua2011.googlecode.com/
PHP | 261 lines | 213 code | 47 blank | 1 comment | 17 complexity | 1e677f55cf85e94bbfcbd8f6151a852e MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. namespace Qnet\Model;
  3. class User {
  4. public static $AGE = "AGE";
  5. public static $GENDER = "GENDER";
  6. public static $MARITAL_STATUS = "MARTIAL_STATUS";
  7. public static $STUDIES = "STUDIES";
  8. public static $LOCATION = "LOCATION";
  9. public static $RELIGION = "RELIGION";
  10. public static $PROPERTIES;
  11. public static $PROPS_LABELS;
  12. public static $FIRST_PROPERTY;
  13. public static function init() {
  14. User::$PROPERTIES = array(User::$AGE => array("Young", "Adult", "Old"),
  15. User::$GENDER => array("Male", "Female"),
  16. User::$MARITAL_STATUS => array("Single", "Married", "Divorced", "Widow"),
  17. User::$STUDIES => array("Primary", "Secondary", "University"),
  18. User::$LOCATION => array("Argentina", "Brazil"),
  19. User::$RELIGION => array("Catholic", "Musulman"));
  20. User::$FIRST_PROPERTY = User::$AGE;
  21. User::$PROPS_LABELS = array(User::$AGE => "Age",
  22. User::$GENDER => "Gender",
  23. User::$MARITAL_STATUS => "Marital status",
  24. User::$STUDIES => "Studies",
  25. User::$LOCATION => "Current country location",
  26. User::$RELIGION => "Religion");
  27. }
  28. public static function indexOfUserValue($property, $user) {
  29. return User::indexOfValue($property, User::getUserValue($property, $user));
  30. }
  31. public static function createPropertyMap($defaultValue) {
  32. $result = array();
  33. foreach(array_keys(User::$PROPERTIES) as $prop) {
  34. $result[$prop] = $defaultValue;
  35. }
  36. return $result;
  37. }
  38. private static function getUserValue($varValue, $user) {
  39. switch($varValue) {
  40. case User::$AGE:
  41. return $user->birth;
  42. case User::$GENDER:
  43. return $user->gender;
  44. case User::$MARITAL_STATUS:
  45. return $user->maritalSt;
  46. case User::$STUDIES:
  47. return $user->studies;
  48. case User::$LOCATION:
  49. return $user->country;
  50. case User::$RELIGION:
  51. return $user->religion;
  52. }
  53. }
  54. public static function readProperties($user, $values) {
  55. if($values[User::$AGE] != null) {
  56. return $user->birth = $values[User::$AGE];
  57. }
  58. $user->gender = $values[User::$GENDER];
  59. $user->maritalSt = $values[User::$MARITAL_STATUS];
  60. $user->studies = $values[User::$STUDIES];
  61. $user->country = $values[User::$LOCATION];
  62. $user->religion = $values[User::$RELIGION];
  63. }
  64. public static function indexOfSelectValue($property, $value) {
  65. return array_search($value, User::$PROPERTIES[$property]);
  66. }
  67. public static function indexOfValue($property, $value) {
  68. if($property == User::$AGE) {
  69. $age = 2010 - intval(substr($value, strrpos($value, '-') + 1));
  70. if($age < 18) return 0;
  71. if($age < 60) return 1;
  72. return 2;
  73. }
  74. return array_search($value, User::$PROPERTIES[$property]);
  75. }
  76. public static function propertyValueAt($property, $ix) {
  77. User::$PROPERTIES[$property][$x];
  78. }
  79. public static function propertyValues($property) {
  80. return User::$PROPERTIES[$property];
  81. }
  82. public static function getPropertyCardinality($property) {
  83. return count(User::$PROPERTIES[$property]);
  84. }
  85. public static function printSimpleOptionsFor($property) {
  86. foreach(User::$PROPERTIES[$property] as $value) {
  87. User::outputOption($property, $value, null, true);
  88. }
  89. }
  90. public static function printOptionsFor($property, $default = null) {
  91. echo '<label class="mylabelstyle">'.User::$PROPS_LABELS[$property].'</label>';
  92. User::_printOptionsFor($property, $default);
  93. }
  94. private static function _printOptionsFor($property, $default) {
  95. if($property == User::$GENDER) {
  96. foreach(User::$PROPERTIES[$property] as $value) {
  97. User::outputOption($property, $value, $default);
  98. }
  99. } else {
  100. echo '<select id="'.$property.'" name="'.$property.'">';
  101. foreach(User::$PROPERTIES[$property] as $value) {
  102. User::outputOption($property, $value, $default);
  103. }
  104. echo '</select>';
  105. }
  106. }
  107. public static function printPropertiesOptions() {
  108. foreach(User::$PROPS_LABELS as $value => $label) {
  109. User::outputCustomOption($value, $label, null);
  110. }
  111. }
  112. private static function outputOption($name, $value, $default, $forceSelect = false) {
  113. if($name == User::$GENDER && !$forceSelect) {
  114. echo '<label for="'.$name.$value.'">'.$value.'</label>';
  115. echo '<input type="radio" name="'.$name.'" value="'.$value.'" id="'.$name.$value.'" ';
  116. User::check($default, $value);
  117. echo ' />';
  118. } else {
  119. User::outputCustomOption($value, $value, $default);
  120. }
  121. }
  122. private static function outputCustomOption($value, $label, $default) {
  123. echo '<option ';
  124. User::sel($default, $value);
  125. echo ' value="'.$value.'">'.$label.'</option>';
  126. }
  127. private static function check($var, $value) {
  128. if($var == $value) {
  129. echo 'checked="checked"';
  130. }
  131. }
  132. private static function sel($var, $value) {
  133. if($var == $value) {
  134. echo 'selected="selected"';
  135. }
  136. }
  137. public $id;
  138. public $name;
  139. public $lastName;
  140. public $mail;
  141. public $password;
  142. public $birth;
  143. public $gender;
  144. public $maritalSt;
  145. public $studies;
  146. public $InstitutionName;
  147. public $country;
  148. public $religion;
  149. public $photo;
  150. public $alive;
  151. //religion , country
  152. public function getId() {
  153. return $this->id;
  154. }
  155. public function setReligion($religion) {
  156. $this->religion = $religion;
  157. }
  158. public function setCountry($country) {
  159. $this->country = $country;
  160. }
  161. public function getReligion() {
  162. return $this->religion;
  163. }
  164. public function getCountry() {
  165. return $this->country;
  166. }
  167. public function setInstitutionName($institutionName) {
  168. $this->InstitutionName = $institutionName;
  169. }
  170. public function getInstitutionName() {
  171. return $this->InstitutionName;
  172. }
  173. public function getLastName() {
  174. return $this->lastName;
  175. }
  176. public function setLastName($lastName) {
  177. $this->lastName = $lastName;
  178. }
  179. public function setId($id) {
  180. $this->id = $id;
  181. }
  182. public function getPassword() {
  183. return $this->password;
  184. }
  185. public function setPassword($password) {
  186. $this->password = $password;
  187. }
  188. function __construct($name, $lastName, $mail, $password, $birth, $gender, $maritalSt, $studies, $InstitutionName, $country, $religion, $photo='img08', $alive = 1) {
  189. $this->name = $name;
  190. $this->lastName = $lastName;
  191. $this->mail = $mail;
  192. $this->password = $password;
  193. $this->birth = $birth;
  194. $this->gender = $gender;
  195. $this->maritalSt = $maritalSt;
  196. $this->studies = $studies;
  197. $this->InstitutionName = $InstitutionName;
  198. $this->country = $country;
  199. $this->religion = $religion;
  200. $this->photo = $photo;
  201. $this->alive = $alive;
  202. }
  203. public function getName() {
  204. return $this->name;
  205. }
  206. public function setAlive($alive) {
  207. $this->alive = $alive;
  208. }
  209. public function getPhoto() {
  210. return $this->photo;
  211. }
  212. }
  213. User::init();
  214. ?>