PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/php/lib/cas_user_request.class.php

https://bitbucket.org/chamilo/chamilo-app-cas-user-dev/
PHP | 221 lines | 172 code | 39 blank | 10 comment | 3 complexity | b602afcf96965c89f392553c00b8a8f2 MD5 | raw file
  1. <?php
  2. namespace application\cas_user;
  3. use common\libraries\Text;
  4. use common\libraries\Theme;
  5. use common\libraries\DataClass;
  6. use user\UserDataManager;
  7. use user\User;
  8. /**
  9. * @author Hans De Bisschop
  10. */
  11. require_once dirname(__FILE__) . '/cas_account.class.php';
  12. class CasUserRequest extends DataClass
  13. {
  14. const CLASS_NAME = __CLASS__;
  15. const TABLE_NAME = 'request';
  16. /**
  17. * CasUserRequest properties
  18. */
  19. const PROPERTY_ID = 'id';
  20. const PROPERTY_FIRST_NAME = 'first_name';
  21. const PROPERTY_LAST_NAME = 'last_name';
  22. const PROPERTY_EMAIL = 'email';
  23. const PROPERTY_AFFILIATION = 'affiliation';
  24. const PROPERTY_MOTIVATION = 'motivation';
  25. const PROPERTY_REQUESTER_ID = 'requester_id';
  26. const PROPERTY_REQUEST_DATE = 'requested';
  27. const PROPERTY_VALID_FROM = 'valid_from';
  28. const PROPERTY_VALID_UNTIL = 'valid_until';
  29. const PROPERTY_STATUS = 'status';
  30. const STATUS_PENDING = 1;
  31. const STATUS_ACCEPTED = 2;
  32. const STATUS_REJECTED = 3;
  33. /**
  34. * Get the default properties
  35. * @return array The property names.
  36. */
  37. static function get_default_property_names($extended_property_names = array())
  38. {
  39. return parent :: get_default_property_names(array(self :: PROPERTY_FIRST_NAME, self :: PROPERTY_LAST_NAME,
  40. self :: PROPERTY_EMAIL, self :: PROPERTY_AFFILIATION, self :: PROPERTY_MOTIVATION,
  41. self :: PROPERTY_REQUESTER_ID, self :: PROPERTY_REQUEST_DATE, self :: PROPERTY_STATUS,
  42. self :: PROPERTY_VALID_FROM, self :: PROPERTY_VALID_UNTIL));
  43. }
  44. function get_data_manager()
  45. {
  46. return CasUserDataManager :: get_instance();
  47. }
  48. function get_id()
  49. {
  50. return $this->get_default_property(self :: PROPERTY_ID);
  51. }
  52. public function get_first_name()
  53. {
  54. return $this->get_default_property(self :: PROPERTY_FIRST_NAME);
  55. }
  56. public function get_last_name()
  57. {
  58. return $this->get_default_property(self :: PROPERTY_LAST_NAME);
  59. }
  60. public function get_email()
  61. {
  62. return $this->get_default_property(self :: PROPERTY_EMAIL);
  63. }
  64. public function get_affiliation()
  65. {
  66. return $this->get_default_property(self :: PROPERTY_AFFILIATION);
  67. }
  68. public function get_motivation()
  69. {
  70. return $this->get_default_property(self :: PROPERTY_MOTIVATION);
  71. }
  72. public function get_requester_id()
  73. {
  74. return $this->get_default_property(self :: PROPERTY_REQUESTER_ID);
  75. }
  76. public function get_request_date()
  77. {
  78. return $this->get_default_property(self :: PROPERTY_REQUEST_DATE);
  79. }
  80. public function get_valid_from()
  81. {
  82. return $this->get_default_property(self :: PROPERTY_VALID_FROM);
  83. }
  84. public function get_valid_until()
  85. {
  86. return $this->get_default_property(self :: PROPERTY_VALID_UNTIL);
  87. }
  88. public function get_status()
  89. {
  90. return $this->get_default_property(self :: PROPERTY_STATUS);
  91. }
  92. function set_id($id)
  93. {
  94. $this->set_default_property(self :: PROPERTY_ID, $id);
  95. }
  96. public function set_first_name($first_name)
  97. {
  98. $this->set_default_property(self :: PROPERTY_FIRST_NAME, $first_name);
  99. }
  100. public function set_last_name($last_name)
  101. {
  102. $this->set_default_property(self :: PROPERTY_LAST_NAME, $last_name);
  103. }
  104. public function set_email($email)
  105. {
  106. $this->set_default_property(self :: PROPERTY_EMAIL, $email);
  107. }
  108. public function set_affiliation($affiliation)
  109. {
  110. $this->set_default_property(self :: PROPERTY_AFFILIATION, $affiliation);
  111. }
  112. public function set_motivation($motivation)
  113. {
  114. $this->set_default_property(self :: PROPERTY_MOTIVATION, $motivation);
  115. }
  116. public function set_requester_id($requester_id)
  117. {
  118. $this->set_default_property(self :: PROPERTY_REQUESTER_ID, $requester_id);
  119. }
  120. public function set_request_date($request_date)
  121. {
  122. $this->set_default_property(self :: PROPERTY_REQUEST_DATE, $request_date);
  123. }
  124. public function set_valid_from($valid_from)
  125. {
  126. $this->set_default_property(self :: PROPERTY_VALID_FROM, $valid_from);
  127. }
  128. public function set_valid_until($valid_until)
  129. {
  130. $this->set_default_property(self :: PROPERTY_VALID_UNTIL, $valid_until);
  131. }
  132. public function set_status($status)
  133. {
  134. $this->set_default_property(self :: PROPERTY_STATUS, $status);
  135. }
  136. static function get_table_name()
  137. {
  138. return self :: TABLE_NAME;
  139. }
  140. function get_status_icon()
  141. {
  142. switch ($this->get_status())
  143. {
  144. case self :: STATUS_ACCEPTED :
  145. $path = Theme :: get_image_path() . 'status_accepted.png';
  146. break;
  147. case self :: STATUS_PENDING :
  148. $path = Theme :: get_image_path() . 'status_pending.png';
  149. break;
  150. case self :: STATUS_REJECTED :
  151. $path = Theme :: get_image_path() . 'status_rejected.png';
  152. break;
  153. }
  154. return '<img src="' . $path . '" />';
  155. }
  156. function is_pending()
  157. {
  158. return $this->get_status() == self :: STATUS_PENDING;
  159. }
  160. function is_rejected()
  161. {
  162. return $this->get_status() == self :: STATUS_REJECTED;
  163. }
  164. function get_requester_user()
  165. {
  166. $user = UserDataManager :: get_instance()->retrieve_user($this->get_requester_id());
  167. return ($user instanceof User ? $user : '');
  168. }
  169. function generate_cas_account()
  170. {
  171. $cas_account = new CasAccount();
  172. $cas_account->set_first_name($this->get_first_name());
  173. $cas_account->set_last_name($this->get_last_name());
  174. $cas_account->set_email($this->get_email());
  175. $cas_account->set_affiliation($this->get_affiliation());
  176. $cas_account->set_group('-');
  177. $cas_account->set_password(md5(Text :: generate_password()));
  178. $cas_account->set_status(CasAccount :: STATUS_ENABLED);
  179. return $cas_account->create();
  180. }
  181. }
  182. ?>