PageRenderTime 34ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/php/lib/period_manager/period_manager.class.php

https://bitbucket.org/chamilo/chamilo-app-internship-organizer-dev/
PHP | 318 lines | 233 code | 60 blank | 25 comment | 2 complexity | 52dad9ae5d901e536c14a6a9c4108066 MD5 | raw file
  1. <?php
  2. namespace application\internship_organizer;
  3. use common\libraries\Application;
  4. use common\libraries\WebApplication;
  5. use common\libraries\SubManager;
  6. require_once WebApplication :: get_application_class_lib_path('internship_organizer') . 'period_manager/component/browser/browser_table.class.php';
  7. require_once WebApplication :: get_application_class_lib_path('internship_organizer') . 'period_menu.class.php';
  8. require_once WebApplication :: get_application_class_lib_path('internship_organizer') . 'period.class.php';
  9. class InternshipOrganizerPeriodManager extends SubManager
  10. {
  11. const PARAM_ACTION = 'action';
  12. const PARAM_PERIOD_ID = 'period_id';
  13. const PARAM_REMOVE_SELECTED = 'delete';
  14. const PARAM_TRUNCATE_SELECTED = 'truncate';
  15. const PARAM_PERIOD_REL_USER_ID = 'period_rel_user_id';
  16. const PARAM_PERIOD_REL_GROUP_ID = 'period_rel_group_id';
  17. const PARAM_PERIOD_REL_CATEGORY_ID = 'period_rel_category_id';
  18. const PARAM_USER_ID = 'user_id';
  19. const PARAM_USER_TYPE = 'user_type';
  20. const PARAM_AGREEMENT_ID = 'agreement_id';
  21. const PARAM_PUBLICATION_ID = 'publication_id';
  22. const ACTION_CREATE_PERIOD = 'creator';
  23. const ACTION_BROWSE_PERIODS = 'browser';
  24. const ACTION_EDIT_PERIOD = 'editor';
  25. const ACTION_EDIT_PERIOD_RIGHTS = 'rights_editor';
  26. const ACTION_DELETE_PERIOD = 'deleter';
  27. const ACTION_VIEW_PERIOD = 'viewer';
  28. const ACTION_PUBLISH_PERIOD = 'publisher';
  29. const ACTION_CREATE_AGREEMENT = 'agreement_creator';
  30. const ACTION_DELETE_AGREEMENT = 'agreement_deleter';
  31. const ACTION_UPDATE_AGREEMENT = 'agreement_editor';
  32. const ACTION_VIEW_AGREEMENT = 'agreement_viewer';
  33. const ACTION_VIEW_PUBLICATION = 'publication_viewer';
  34. const ACTION_DELETE_PUBLICATION = 'publication_deleter';
  35. const ACTION_EDIT_PUBLICATION_RIGHTS = 'publication_rights_editor';
  36. const ACTION_SUBSCRIBE_USER = 'subscribe_user';
  37. const ACTION_SUBSCRIBE_GROUP = 'subscribe_group';
  38. const ACTION_SUBSCRIBE_CATEGORY = 'subscribe_category';
  39. const ACTION_SUBSCRIBE_AGREEMENT_REL_USER = 'subscribe_agreement_rel_user';
  40. const ACTION_UNSUBSCRIBE_USER = 'unsubscribe_user';
  41. const ACTION_UNSUBSCRIBE_GROUP = 'unsubscribe_group';
  42. const ACTION_UNSUBSCRIBE_CATEGORY = 'unsubscribe_category';
  43. const ACTION_UNSUBSCRIBE_AGREEMENT_REL_USER = 'unsubscribe_agreement_rel_user';
  44. const ACTION_REPORTING = 'reporting';
  45. const DEFAULT_ACTION = self :: ACTION_BROWSE_PERIODS;
  46. function __construct($internship_manager)
  47. {
  48. parent :: __construct($internship_manager);
  49. }
  50. function get_application_component_path()
  51. {
  52. return WebApplication :: get_application_class_lib_path('internship_organizer') . 'period_manager/component/';
  53. }
  54. //periods
  55. function retrieve_periods($condition = null, $offset = null, $count = null, $order_property = null)
  56. {
  57. return InternshipOrganizerDataManager :: get_instance()->retrieve_periods($condition, $offset, $count, $order_property);
  58. }
  59. function retrieve_period($id)
  60. {
  61. return InternshipOrganizerDataManager :: get_instance()->retrieve_internship_organizer_period($id);
  62. }
  63. function retrieve_root_period()
  64. {
  65. return InternshipOrganizerDataManager :: get_instance()->retrieve_root_period();
  66. }
  67. function count_periods($conditions = null)
  68. {
  69. return InternshipOrganizerDataManager :: get_instance()->count_periods($conditions);
  70. }
  71. function count_period_rel_users($conditions = null)
  72. {
  73. return InternshipOrganizerDataManager :: get_instance()->count_period_rel_users($conditions);
  74. }
  75. function count_period_rel_groups($conditions = null)
  76. {
  77. return InternshipOrganizerDataManager :: get_instance()->count_period_rel_groups($conditions);
  78. }
  79. function retrieve_groups($condition = null, $offset = null, $count = null, $order_property = null)
  80. {
  81. return InternshipOrganizerDataManager :: get_instance()->retrieve_groups($condition, $offset, $count, $order_property);
  82. }
  83. //url
  84. function get_browse_periods_url($period = null)
  85. {
  86. if ($period != null)
  87. {
  88. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_BROWSE_PERIODS,
  89. self :: PARAM_PERIOD_ID => $period->get_id()));
  90. }
  91. else
  92. {
  93. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_BROWSE_PERIODS));
  94. }
  95. }
  96. function get_period_editing_url($period)
  97. {
  98. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_EDIT_PERIOD,
  99. self :: PARAM_PERIOD_ID => $period->get_id()));
  100. }
  101. function get_period_create_url($parent_period)
  102. {
  103. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_CREATE_PERIOD,
  104. self :: PARAM_PERIOD_ID => $parent_period->get_id()));
  105. }
  106. function get_period_emptying_url($period)
  107. {
  108. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_TRUNCATE_PERIOD,
  109. self :: PARAM_PERIOD_ID => $period->get_id()));
  110. }
  111. function get_period_viewing_url($period)
  112. {
  113. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_VIEW_PERIOD,
  114. self :: PARAM_PERIOD_ID => $period->get_id()));
  115. }
  116. function get_period_delete_url($period)
  117. {
  118. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_DELETE_PERIOD,
  119. self :: PARAM_PERIOD_ID => $period->get_id()));
  120. }
  121. function get_period_reporting_url($period)
  122. {
  123. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_REPORTING,
  124. self :: PARAM_PERIOD_ID => $period->get_id()));
  125. }
  126. function get_period_publish_url($period)
  127. {
  128. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_PUBLISH_PERIOD,
  129. self :: PARAM_PERIOD_ID => $period->get_id()));
  130. }
  131. function get_periods_publish_url()
  132. {
  133. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_PUBLISH_PERIOD));
  134. }
  135. function get_period_subscribe_user_url($period)
  136. {
  137. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_SUBSCRIBE_USER,
  138. self :: PARAM_PERIOD_ID => $period->get_id()));
  139. }
  140. function get_period_subscribe_group_url($period)
  141. {
  142. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_SUBSCRIBE_GROUP,
  143. self :: PARAM_PERIOD_ID => $period->get_id()));
  144. }
  145. function get_period_subscribe_category_url($period)
  146. {
  147. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_SUBSCRIBE_CATEGORY,
  148. self :: PARAM_PERIOD_ID => $period->get_id()));
  149. }
  150. function get_period_unsubscribe_user_url($period_rel_user)
  151. {
  152. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_UNSUBSCRIBE_USER,
  153. self :: PARAM_PERIOD_REL_USER_ID => $period_rel_user->get_period_id() . '|' . $period_rel_user->get_user_id() . '|' . $period_rel_user->get_user_type()));
  154. }
  155. function get_period_unsubscribe_group_url($period_rel_group)
  156. {
  157. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_UNSUBSCRIBE_GROUP,
  158. self :: PARAM_PERIOD_REL_GROUP_ID => $period_rel_group->get_period_id() . '|' . $period_rel_group->get_group_id() . '|' . $period_rel_group->get_user_type()));
  159. }
  160. function get_period_unsubscribe_category_url($category_rel_period)
  161. {
  162. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_UNSUBSCRIBE_CATEGORY,
  163. self :: PARAM_PERIOD_REL_CATEGORY_ID => $category_rel_period->get_category_id() . '|' . $category_rel_period->get_period_id()));
  164. }
  165. function get_period_create_agreement_url($period, $user)
  166. {
  167. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_CREATE_AGREEMENT,
  168. self :: PARAM_USER_ID => $period->get_id() . '|' . $user->get_id()));
  169. }
  170. function get_update_agreement_url($agreement)
  171. {
  172. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_UPDATE_AGREEMENT,
  173. self :: PARAM_AGREEMENT_ID => $agreement->get_id()));
  174. }
  175. function get_delete_agreement_url($agreement)
  176. {
  177. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_DELETE_AGREEMENT,
  178. self :: PARAM_AGREEMENT_ID => $agreement->get_id()));
  179. }
  180. function get_view_agreement_url($agreement)
  181. {
  182. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_VIEW_AGREEMENT,
  183. self :: PARAM_AGREEMENT_ID => $agreement->get_id()));
  184. }
  185. function get_unsubscribe_agreement_rel_user_url($agreement, $user, $user_type)
  186. {
  187. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_UNSUBSCRIBE_AGREEMENT_REL_USER,
  188. self :: PARAM_USER_ID => $agreement->get_id() . '|' . $user->get_id() . '|' . $user_type));
  189. }
  190. function get_subscribe_agreement_rel_user_url($agreement, $user_type)
  191. {
  192. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_SUBSCRIBE_AGREEMENT_REL_USER,
  193. self :: PARAM_AGREEMENT_ID => $agreement->get_id(), self :: PARAM_USER_TYPE => $user_type));
  194. }
  195. function get_rights_editor_url($period)
  196. {
  197. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_EDIT_PERIOD_RIGHTS,
  198. self :: PARAM_PERIOD_ID => $period->get_id()));
  199. }
  200. function get_agreement_rights_editor_url($agreement)
  201. {
  202. return $this->get_url(array(
  203. Application :: PARAM_ACTION => InternshipOrganizerAgreementManager :: SUB_MANAGER_NAME,
  204. InternshipOrganizerAgreementManager :: PARAM_ACTION => InternshipOrganizerAgreementManager :: ACTION_EDIT_AGREEMENT_RIGHTS,
  205. InternshipOrganizerAgreementManager :: PARAM_AGREEMENT_ID => $agreement->get_id()));
  206. }
  207. function get_view_publication_url($publication)
  208. {
  209. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_VIEW_PUBLICATION,
  210. self :: PARAM_PUBLICATION_ID => $publication->get_id()));
  211. }
  212. function get_delete_publication_url($publication)
  213. {
  214. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_DELETE_PUBLICATION,
  215. self :: PARAM_PUBLICATION_ID => $publication->get_id()));
  216. }
  217. function get_publication_rights_editor_url($publication)
  218. {
  219. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_EDIT_PUBLICATION_RIGHTS,
  220. self :: PARAM_PUBLICATION_ID => $publication->get_id()));
  221. }
  222. /**
  223. * Helper function for the SubManager class,
  224. * pending access to class constants via variables in PHP 5.3
  225. * e.g. $name = $class :: DEFAULT_ACTION
  226. *
  227. * DO NOT USE IN THIS SUBMANAGER'S CONTEXT
  228. * Instead use:
  229. * - self :: DEFAULT_ACTION in the context of this class
  230. * - YourSubManager :: DEFAULT_ACTION in all other application classes
  231. */
  232. static function get_default_action()
  233. {
  234. return self :: DEFAULT_ACTION;
  235. }
  236. /**
  237. * Helper function for the SubManager class,
  238. * pending access to class constants via variables in PHP 5.3
  239. * e.g. $name = $class :: PARAM_ACTION
  240. *
  241. * DO NOT USE IN THIS SUBMANAGER'S CONTEXT
  242. * Instead use:
  243. * - self :: PARAM_ACTION in the context of this class
  244. * - YourSubManager :: PARAM_ACTION in all other application classes
  245. */
  246. static function get_action_parameter()
  247. {
  248. return self :: PARAM_ACTION;
  249. }
  250. /**
  251. * @param Application $application
  252. */
  253. static function launch($application)
  254. {
  255. parent :: launch(__CLASS__, $application);
  256. }
  257. }
  258. ?>