PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/php/lib/agreement_manager/component/viewer.class.php

https://bitbucket.org/chamilo/chamilo-app-internship-organizer-dev/
PHP | 401 lines | 283 code | 79 blank | 39 comment | 25 complexity | 88bd0378393d1519c55a7f4b0522a630 MD5 | raw file
  1. <?php
  2. namespace application\internship_organizer;
  3. use common\libraries\OrCondition;
  4. use common\libraries\PatternMatchCondition;
  5. use common\libraries\Translation;
  6. use common\libraries\WebApplication;
  7. use common\libraries\Utilities;
  8. use common\libraries\Theme;
  9. use common\libraries\ActionBarRenderer;
  10. use common\libraries\DynamicTabsRenderer;
  11. use common\libraries\EqualityCondition;
  12. use common\libraries\AndCondition;
  13. use common\libraries\DynamicContentTab;
  14. use common\libraries\ToolbarItem;
  15. use common\libraries\InCondition;
  16. use common\libraries\BreadcrumbTrail;
  17. use common\libraries\Breadcrumb;
  18. use common\libraries\ActionBarSearchForm;
  19. use repository\RepositoryDataManager;
  20. use repository\ContentObject;
  21. use repository\content_object\document\Document;
  22. use repository\content_object\survey\Survey;
  23. use user\UserDataManager;
  24. use user\User;
  25. require_once WebApplication :: get_application_class_lib_path('internship_organizer') . 'agreement_manager/agreement_manager.class.php';
  26. require_once WebApplication :: get_application_class_lib_path('internship_organizer') . 'agreement_manager/component/moment_browser/browser_table.class.php';
  27. require_once WebApplication :: get_application_class_lib_path('internship_organizer') . 'agreement_manager/component/rel_location_browser/rel_location_browser_table.class.php';
  28. require_once WebApplication :: get_application_class_lib_path('internship_organizer') . 'agreement_manager/component/user_browser/user_browser_table.class.php';
  29. require_once WebApplication :: get_application_class_lib_path('internship_organizer') . 'agreement_manager/component/rel_mentor_browser/rel_mentor_browser_table.class.php';
  30. require_once WebApplication :: get_application_class_lib_path('internship_organizer') . 'publisher/publication_table/publication_table.class.php';
  31. class InternshipOrganizerAgreementManagerViewerComponent extends InternshipOrganizerAgreementManager
  32. {
  33. const TAB_LOCATIONS = 1;
  34. const TAB_MOMENTS = 2;
  35. const TAB_COORDINATOR = 3;
  36. const TAB_COACH = 4;
  37. const TAB_MENTOR = 5;
  38. const TAB_PUBLICATIONS = 6;
  39. const TAB_EVALUATIONS = 7;
  40. private $action_bar;
  41. private $agreement;
  42. private $student;
  43. private $selected_tab;
  44. function run()
  45. {
  46. if (! InternshipOrganizerRights :: is_allowed_in_internship_organizers_subtree(InternshipOrganizerRights :: RIGHT_VIEW, InternshipOrganizerRights :: LOCATION_AGREEMENT, InternshipOrganizerRights :: TYPE_COMPONENT))
  47. {
  48. $this->display_header();
  49. $this->display_error_message(Translation :: get('NotAllowed'));
  50. $this->display_footer();
  51. exit();
  52. }
  53. $agreement_id = $_GET[self :: PARAM_AGREEMENT_ID];
  54. $this->agreement = $this->retrieve_agreement($agreement_id);
  55. $this->action_bar = $this->get_action_bar();
  56. $this->display_header();
  57. echo $this->action_bar->as_html();
  58. echo '<div id="action_bar_browser">';
  59. echo '<div class="clear"></div><div class="content_object" style="background-image: url(' . Theme :: get_common_image_path() . 'place_location.png);">';
  60. echo '<div class="title">' . Translation :: get('Details') . '</div>';
  61. echo '<b>' . Translation :: get('Description') . '</b>: ' . $this->agreement->get_description() . '<br /> ';
  62. $student = $this->get_student();
  63. echo '<div class="title">' . Translation :: get('Student') . '</div>';
  64. echo '<b>' . Translation :: get('Firstname') . '</b>: ' . $student->get_firstname();
  65. echo '<br /><b>' . Translation :: get('Lastname') . '</b>: ' . $student->get_lastname();
  66. echo '<br /><b>' . Translation :: get('InternshipOrganizerEmail') . '</b>: ' . $student->get_email();
  67. echo '<div class="clear">&nbsp;</div>';
  68. echo '</div>';
  69. echo '<div>';
  70. echo $this->get_tabs();
  71. echo '</div>';
  72. echo '</div>';
  73. $this->display_footer();
  74. }
  75. function get_tabs()
  76. {
  77. $html = array();
  78. $html[] = '<div>';
  79. $renderer_name = Utilities :: get_classname_from_object($this, true);
  80. $tabs = new DynamicTabsRenderer($renderer_name);
  81. //coordinators and coaches are added/checked when the agreement is created and so are always present
  82. $parameters = $this->get_parameters();
  83. $parameters[InternshipOrganizerAgreementManager :: PARAM_AGREEMENT_ID] = $this->agreement->get_id();
  84. $parameters[ActionBarSearchForm :: PARAM_SIMPLE_SEARCH_QUERY] = $this->action_bar->get_query();
  85. $parameters[DynamicTabsRenderer :: PARAM_SELECTED_TAB] = self :: TAB_COORDINATOR;
  86. $table = new InternshipOrganizerAgreementUserBrowserTable($this, $parameters, $this->get_type_users_condition(InternshipOrganizerUserType :: COORDINATOR));
  87. $tabs->add_tab(new DynamicContentTab(self :: TAB_COORDINATOR, Translation :: get('InternshipOrganizerCoordinators'), Theme :: get_image_path(__NAMESPACE__) . 'place_mini_coordinator.png', $table->as_html()));
  88. $parameters[DynamicTabsRenderer :: PARAM_SELECTED_TAB] = self :: TAB_COACH;
  89. $table = new InternshipOrganizerAgreementUserBrowserTable($this, $parameters, $this->get_type_users_condition(InternshipOrganizerUserType :: COACH));
  90. $tabs->add_tab(new DynamicContentTab(self :: TAB_COACH, Translation :: get('InternshipOrganizerCoaches'), Theme :: get_image_path(__NAMESPACE__) . 'place_mini_coach.png', $table->as_html()));
  91. // Publications table tab
  92. $parameters[DynamicTabsRenderer :: PARAM_SELECTED_TAB] = self :: TAB_PUBLICATIONS;
  93. $table = new InternshipOrganizerPublicationTable($this, $parameters, $this->get_publications_condition(array(
  94. Document :: get_type_name())));
  95. $tabs->add_tab(new DynamicContentTab(self :: TAB_PUBLICATIONS, Translation :: get('InternshipOrganizerPublications'), Theme :: get_image_path(__NAMESPACE__) . 'place_mini_publication.png', $table->as_html()));
  96. // Evaluations table tab
  97. $parameters[DynamicTabsRenderer :: PARAM_SELECTED_TAB] = self :: TAB_EVALUATIONS;
  98. $table = new InternshipOrganizerPublicationTable($this, $parameters, $this->get_publications_condition(array(
  99. Survey :: get_type_name())));
  100. $tabs->add_tab(new DynamicContentTab(self :: TAB_EVALUATIONS, Translation :: get('InternshipOrganizerEvaluations'), Theme :: get_image_path(__NAMESPACE__) . 'place_mini_evaluation.png', $table->as_html()));
  101. $count = $this->count_agreement_rel_locations($this->get_location_condition(InternshipOrganizerAgreementRelLocation :: APPROVED));
  102. if ($count == 1)
  103. {
  104. //the agreement is aproved for the chosen organisation/location
  105. $parameters[DynamicTabsRenderer :: PARAM_SELECTED_TAB] = self :: TAB_LOCATIONS;
  106. $table = new InternshipOrganizerAgreementRelLocationBrowserTable($this, $parameters, $this->get_location_condition(InternshipOrganizerAgreementRelLocation :: APPROVED));
  107. $tabs->add_tab(new DynamicContentTab(self :: TAB_LOCATIONS, Translation :: get('InternshipOrganizerLocations'), Theme :: get_image_path(__NAMESPACE__) . 'place_mini_location.png', $table->as_html()));
  108. $parameters[DynamicTabsRenderer :: PARAM_SELECTED_TAB] = self :: TAB_MENTOR;
  109. $table = new InternshipOrganizerAgreementRelMentorBrowserTable($this, $parameters, $this->get_mentor_condition());
  110. $tabs->add_tab(new DynamicContentTab(self :: TAB_MENTOR, Translation :: get('InternshipOrganizerMentors'), Theme :: get_image_path(__NAMESPACE__) . 'place_mini_mentor.png', $table->as_html()));
  111. $condition = new EqualityCondition(InternshipOrganizerAgreementRelMentor :: PROPERTY_AGREEMENT_ID, $this->agreement->get_id());
  112. $mentor_count = InternshipOrganizerDataManager :: get_instance()->count_agreement_rel_mentors($condition);
  113. if ($mentor_count > 0)
  114. {
  115. //the mentors are connencted so it is possible to create moments and view publications
  116. $parameters[DynamicTabsRenderer :: PARAM_SELECTED_TAB] = self :: TAB_MOMENTS;
  117. $table = new InternshipOrganizerMomentBrowserTable($this, $parameters, $this->get_moment_condition());
  118. $tabs->add_tab(new DynamicContentTab(self :: TAB_MOMENTS, Translation :: get('InternshipOrganizerMoments'), Theme :: get_image_path(__NAMESPACE__) . 'place_mini_moment.png', $table->as_html()));
  119. }
  120. }
  121. else
  122. {
  123. $parameters[DynamicTabsRenderer :: PARAM_SELECTED_TAB] = self :: TAB_LOCATIONS;
  124. $table = new InternshipOrganizerAgreementRelLocationBrowserTable($this, $parameters, $this->get_location_condition(InternshipOrganizerAgreementRelLocation :: TO_APPROVE));
  125. $tabs->add_tab(new DynamicContentTab(self :: TAB_LOCATIONS, Translation :: get('InternshipOrganizerLocations'), Theme :: get_image_path(__NAMESPACE__) . 'place_mini_location.png', $table->as_html()));
  126. }
  127. $html[] = $tabs->render();
  128. $html[] = '</div>';
  129. $html[] = '<div class="clear"></div>';
  130. return implode($html, "\n");
  131. }
  132. function get_action_bar()
  133. {
  134. $action_bar = new ActionBarRenderer(ActionBarRenderer :: TYPE_HORIZONTAL);
  135. $conditions = array();
  136. $agreement_id = $this->agreement->get_id();
  137. $conditions[] = new EqualityCondition(InternshipOrganizerAgreementRelLocation :: PROPERTY_AGREEMENT_ID, $agreement_id);
  138. $conditions[] = new EqualityCondition(InternshipOrganizerAgreementRelLocation :: PROPERTY_LOCATION_TYPE, InternshipOrganizerAgreementRelLocation :: APPROVED);
  139. $condition = new AndCondition($conditions);
  140. $location_count = $this->count_agreement_rel_locations($condition);
  141. if (InternshipOrganizerRights :: is_allowed_in_internship_organizers_subtree(InternshipOrganizerRights :: RIGHT_PUBLISH, $agreement_id, InternshipOrganizerRights :: TYPE_AGREEMENT))
  142. {
  143. $action_bar->add_common_action(new ToolbarItem(Translation :: get('Publish'), Theme :: get_common_image_path() . 'action_publish.png', $this->get_agreement_publish_url($this->agreement), ToolbarItem :: DISPLAY_ICON_AND_LABEL));
  144. }
  145. if ($location_count == 1)
  146. {
  147. $condition = new EqualityCondition(InternshipOrganizerAgreementRelMentor :: PROPERTY_AGREEMENT_ID, $this->agreement->get_id());
  148. $mentor_count = InternshipOrganizerDataManager :: get_instance()->count_agreement_rel_mentors($condition);
  149. if ($mentor_count > 0)
  150. {
  151. //all actions that you can do on a approved agreement
  152. if (InternshipOrganizerRights :: is_allowed_in_internship_organizers_subtree(InternshipOrganizerRights :: RIGHT_PUBLISH, $this->agreement->get_id(), InternshipOrganizerRights :: TYPE_AGREEMENT))
  153. {
  154. $action_bar->add_common_action(new ToolbarItem(Translation :: get('PublishInMoments'), Theme :: get_common_image_path() . 'action_publish.png', $this->get_moments_publish_url($this->agreement), ToolbarItem :: DISPLAY_ICON_AND_LABEL));
  155. }
  156. if (InternshipOrganizerRights :: is_allowed_in_internship_organizers_subtree(InternshipOrganizerRights :: ADD_MOMENT_RIGHT, $this->agreement->get_id(), InternshipOrganizerRights :: TYPE_AGREEMENT))
  157. {
  158. $action_bar->add_common_action(new ToolbarItem(Translation :: get('CreateInternshipOrganizerMoment'), Theme :: get_common_image_path() . 'action_add.png', $this->get_create_moment_url($this->agreement), ToolbarItem :: DISPLAY_ICON_AND_LABEL));
  159. }
  160. }
  161. else
  162. {
  163. if (InternshipOrganizerRights :: is_allowed_in_internship_organizers_subtree(InternshipOrganizerRights :: ADD_MENTOR_RIGHT, $this->agreement->get_id(), InternshipOrganizerRights :: TYPE_AGREEMENT))
  164. {
  165. //first mentors have to be added before moments can be created
  166. $action_bar->add_tool_action(new ToolbarItem(Translation :: get('AddInternshipOrganizerMentor'), Theme :: get_common_image_path() . 'action_add.png', $this->get_agreement_subscribe_mentor_url($this->agreement), ToolbarItem :: DISPLAY_ICON_AND_LABEL));
  167. }
  168. }
  169. }
  170. else
  171. {
  172. if (InternshipOrganizerRights :: is_allowed_in_internship_organizers_subtree(InternshipOrganizerRights :: ADD_LOCATION_RIGHT, $this->agreement->get_id(), InternshipOrganizerRights :: TYPE_AGREEMENT))
  173. {
  174. //add locations
  175. $action_bar->add_common_action(new ToolbarItem(Translation :: get('SubscribeInternshipOrganizerAgreementLocation'), Theme :: get_common_image_path() . 'action_add.png', $this->get_subscribe_location_url($this->agreement), ToolbarItem :: DISPLAY_ICON_AND_LABEL));
  176. }
  177. }
  178. $action_bar->set_search_url($this->get_url(array(
  179. InternshipOrganizerAgreementManager :: PARAM_AGREEMENT_ID => $this->agreement->get_id())));
  180. return $action_bar;
  181. }
  182. function get_moment_condition()
  183. {
  184. $query = $this->action_bar->get_query();
  185. $conditions = array();
  186. $agreement_id = $this->agreement->get_id();
  187. $conditions[] = new EqualityCondition(InternshipOrganizerMoment :: PROPERTY_AGREEMENT_ID, $agreement_id);
  188. if (isset($query) && $query != '')
  189. {
  190. $search_conditions = array();
  191. $search_conditions[] = new PatternMatchCondition(InternshipOrganizerMoment :: PROPERTY_NAME, '*' . $query . '*');
  192. $search_conditions[] = new PatternMatchCondition(InternshipOrganizerMoment :: PROPERTY_DESCRIPTION, '*' . $query . '*');
  193. $conditions[] = new OrCondition($search_conditions);
  194. }
  195. return new AndCondition($conditions);
  196. }
  197. function get_mentor_condition()
  198. {
  199. $query = $this->action_bar->get_query();
  200. $conditions = array();
  201. $agreement_id = $this->agreement->get_id();
  202. $conditions[] = new EqualityCondition(InternshipOrganizerAgreementRelMentor :: PROPERTY_AGREEMENT_ID, $agreement_id);
  203. // if (isset($query) && $query != '')
  204. // {
  205. // $search_conditions = array();
  206. // $search_conditions[] = new PatternMatchCondition(InternshipOrganizerMentor :: PROPERTY_FIRSTNAME, '*' . $query . '*');
  207. // $search_conditions[] = new PatternMatchCondition(InternshipOrganizerMentor :: PROPERTY_LASTNAME, '*' . $query . '*');
  208. // $search_conditions[] = new PatternMatchCondition(InternshipOrganizerMentor :: PROPERTY_TITLE, '*' . $query . '*');
  209. // $search_conditions[] = new PatternMatchCondition(InternshipOrganizerMentor :: PROPERTY_TELEPHONE, '*' . $query . '*');
  210. //
  211. // $mentors = InternshipOrganizerDataManager :: get_instance()->retrieve_mentors($search_conditions);
  212. //
  213. // $mentor_ids = array();
  214. // while ($mentor = $mentors->next_result())
  215. // {
  216. // $mentor_ids[] = $mentor->get_id();
  217. // }
  218. //
  219. // if (count($mentor_ids))
  220. // {
  221. //
  222. // $rel_mentor_condition = new InCondition(InternshipOrganizerAgreementRelMentor :: PROPERTY_MENTOR_ID, $mentor_ids);
  223. //
  224. // }
  225. // else
  226. // {
  227. // $rel_mentor_condition = new EqualityCondition(InternshipOrganizerAgreementRelMentor :: PROPERTY_MENTOR_ID, 0);
  228. //
  229. // }
  230. //
  231. // $conditions[] = $rel_mentor_condition;
  232. // }
  233. return new AndCondition($conditions);
  234. }
  235. function get_location_condition($location_type)
  236. {
  237. $conditions = array();
  238. $agreement_id = $this->agreement->get_id();
  239. $agreement_rel_location_alias = InternshipOrganizerDataManager :: get_instance()->get_alias(InternshipOrganizerAgreementRelLocation :: get_table_name());
  240. $conditions[] = new EqualityCondition(InternshipOrganizerAgreementRelLocation :: PROPERTY_AGREEMENT_ID, $agreement_id, $agreement_rel_location_alias, true);
  241. $conditions[] = new EqualityCondition(InternshipOrganizerAgreementRelLocation :: PROPERTY_LOCATION_TYPE, $location_type, $agreement_rel_location_alias, true);
  242. $query = $this->action_bar->get_query();
  243. if (isset($query) && $query != '')
  244. {
  245. $region_alias = InternshipOrganizerDataManager :: get_instance()->get_alias(InternshipOrganizerRegion :: get_table_name());
  246. $organisation_alias = InternshipOrganizerDataManager :: get_instance()->get_alias(InternshipOrganizerOrganisation :: get_table_name());
  247. $location_alias = InternshipOrganizerDataManager :: get_instance()->get_alias(InternshipOrganizerLocation :: get_table_name());
  248. $search_conditions = array();
  249. $search_conditions[] = new PatternMatchCondition(InternshipOrganizerLocation :: PROPERTY_ADDRESS, '*' . $query . '*', $location_alias, true);
  250. $search_conditions[] = new PatternMatchCondition(InternshipOrganizerLocation :: PROPERTY_DESCRIPTION, '*' . $query . '*', $location_alias, true);
  251. $search_conditions[] = new PatternMatchCondition(InternshipOrganizerLocation :: PROPERTY_EMAIL, '*' . $query . '*', $location_alias, true);
  252. $search_conditions[] = new PatternMatchCondition(InternshipOrganizerLocation :: PROPERTY_NAME, '*' . $query . '*', $location_alias, true);
  253. $search_conditions[] = new PatternMatchCondition(InternshipOrganizerLocation :: PROPERTY_TELEPHONE, '*' . $query . '*', $location_alias, true);
  254. $conditions[] = new OrCondition($search_conditions);
  255. }
  256. return new AndCondition($conditions);
  257. }
  258. function get_type_users_condition($user_type)
  259. {
  260. $query = $this->action_bar->get_query();
  261. $conditions = array();
  262. $user_ids = $this->agreement->get_user_ids($user_type);
  263. if (count($user_ids))
  264. {
  265. $conditions[] = new InCondition(User :: PROPERTY_ID, $user_ids);
  266. }
  267. else
  268. {
  269. $conditions[] = new EqualityCondition(User :: PROPERTY_ID, 0);
  270. }
  271. if (isset($query) && $query != '')
  272. {
  273. $user_alias = UserDataManager :: get_instance()->get_alias(User :: get_table_name());
  274. $search_conditions = array();
  275. $search_conditions[] = new PatternMatchCondition(User :: PROPERTY_FIRSTNAME, '*' . $query . '*', $user_alias, true);
  276. $search_conditions[] = new PatternMatchCondition(User :: PROPERTY_LASTNAME, '*' . $query . '*', $user_alias, true);
  277. // $search_conditions[] = new PatternMatchCondition(User :: PROPERTY_USERNAME, '*' . $query . '*');
  278. $conditions[] = new OrCondition($search_conditions);
  279. }
  280. return new AndCondition($conditions);
  281. }
  282. function get_student()
  283. {
  284. $student_id = $this->agreement->get_user_ids(InternshipOrganizerUserType :: STUDENT);
  285. $dm = UserDataManager :: get_instance();
  286. $student = $dm->retrieve_user($student_id[0]);
  287. return $student;
  288. }
  289. function get_publications_condition($types = array(''))
  290. {
  291. $conditions = array();
  292. $conditions[] = new EqualityCondition(InternshipOrganizerPublication :: PROPERTY_PUBLICATION_PLACE, InternshipOrganizerPublicationPlace :: AGREEMENT);
  293. $conditions[] = new EqualityCondition(InternshipOrganizerPublication :: PROPERTY_PLACE_ID, $this->agreement->get_id());
  294. $conditions[] = new InCondition(InternshipOrganizerPublication :: PROPERTY_CONTENT_OBJECT_TYPE, $types);
  295. $query = $this->action_bar->get_query();
  296. if (isset($query) && $query != '')
  297. {
  298. $publication_alias = InternshipOrganizerDataManager :: get_instance()->get_alias(InternshipOrganizerPublication :: get_table_name());
  299. $user_alias = UserDataManager :: get_instance()->get_alias(User :: get_table_name());
  300. $object_alias = RepositoryDataManager :: get_instance()->get_alias(ContentObject :: get_table_name());
  301. $search_conditions = array();
  302. $search_conditions[] = new PatternMatchCondition(User :: PROPERTY_FIRSTNAME, '*' . $query . '*', $user_alias, true);
  303. $search_conditions[] = new PatternMatchCondition(User :: PROPERTY_LASTNAME, '*' . $query . '*', $user_alias, true);
  304. $search_conditions[] = new PatternMatchCondition(InternshipOrganizerPublication :: PROPERTY_NAME, '*' . $query . '*', $publication_alias, true);
  305. $search_conditions[] = new PatternMatchCondition(InternshipOrganizerPublication :: PROPERTY_DESCRIPTION, '*' . $query . '*', $publication_alias, true);
  306. $search_conditions[] = new PatternMatchCondition(ContentObject :: PROPERTY_TITLE, '*' . $query . '*', $object_alias, true);
  307. $search_conditions[] = new PatternMatchCondition(ContentObject :: PROPERTY_DESCRIPTION, '*' . $query . '*', $object_alias, true);
  308. $conditions[] = new OrCondition($search_conditions);
  309. }
  310. return new AndCondition($conditions);
  311. }
  312. function add_additional_breadcrumbs(BreadcrumbTrail $breadcrumbtrail)
  313. {
  314. $breadcrumbtrail->add(new Breadcrumb($this->get_url(array(
  315. self :: PARAM_ACTION => self :: ACTION_BROWSE_AGREEMENT)), Translation :: get('BrowseInternshipOrganizerAgreements')));
  316. }
  317. function get_additional_parameters()
  318. {
  319. return array(self :: PARAM_AGREEMENT_ID);
  320. }
  321. }
  322. ?>