PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/php/lib/agreement_manager/component/moment_viewer.class.php

https://bitbucket.org/chamilo/chamilo-app-internship-organizer-dev/
PHP | 193 lines | 147 code | 45 blank | 1 comment | 5 complexity | 3be3a477eff72c5c96d09937bf4d7034 MD5 | raw file
  1. <?php
  2. namespace application\internship_organizer;
  3. use common\libraries\OrCondition;
  4. use common\libraries\PatternMatchCondition;
  5. use common\libraries\WebApplication;
  6. use common\libraries\Utilities;
  7. use common\libraries\DatetimeUtilities;
  8. use common\libraries\Translation;
  9. use common\libraries\Theme;
  10. use common\libraries\ActionBarRenderer;
  11. use common\libraries\DynamicTabsRenderer;
  12. use common\libraries\EqualityCondition;
  13. use common\libraries\AndCondition;
  14. use common\libraries\DynamicContentTab;
  15. use common\libraries\ToolbarItem;
  16. use common\libraries\InCondition;
  17. use common\libraries\BreadcrumbTrail;
  18. use common\libraries\Breadcrumb;
  19. use common\libraries\Request;
  20. use common\libraries\ActionBarSearchForm;
  21. use repository\RepositoryDataManager;
  22. use repository\ContentObject;
  23. use repository\content_object\document\Document;
  24. use repository\content_object\survey\Survey;
  25. use user\UserDataManager;
  26. use user\User;
  27. require_once WebApplication :: get_application_class_lib_path('internship_organizer') . 'agreement_manager/agreement_manager.class.php';
  28. require_once WebApplication :: get_application_class_lib_path('internship_organizer') . 'publisher/publication_table/publication_table.class.php';
  29. require_once WebApplication :: get_application_class_lib_path('internship_organizer') . 'agreement_manager/component/viewer.class.php';
  30. class InternshipOrganizerAgreementManagerMomentViewerComponent extends InternshipOrganizerAgreementManager
  31. {
  32. const TAB_PUBLICATIONS = 1;
  33. const TAB_EVALUATIONS = 2;
  34. private $action_bar;
  35. private $moment;
  36. function run()
  37. {
  38. $moment_id = $_GET[self :: PARAM_MOMENT_ID];
  39. if (! InternshipOrganizerRights :: is_allowed_in_internship_organizers_subtree(InternshipOrganizerRights :: RIGHT_VIEW, $moment_id, InternshipOrganizerRights :: TYPE_MOMENT))
  40. {
  41. $this->display_header($trail);
  42. $this->display_error_message(Translation :: get('NotAllowed'));
  43. $this->display_footer();
  44. exit();
  45. }
  46. $this->moment = $this->retrieve_moment($moment_id);
  47. $agreement_id = $this->moment->get_agreement_id();
  48. $agreement = $this->retrieve_agreement($agreement_id);
  49. $users_ids = $agreement->get_user_ids(InternshipOrganizerUserType :: STUDENT);
  50. $user = UserDataManager :: get_instance()->retrieve_user($users_ids[0]);
  51. $location = $agreement->get_location();
  52. $region = $location->get_region();
  53. $trail = BreadcrumbTrail :: get_instance();
  54. $this->action_bar = $this->get_action_bar();
  55. $this->display_header($trail);
  56. echo $this->action_bar->as_html();
  57. echo '<div id="action_bar_browser">';
  58. echo '<div class="clear"></div><div class="content_object" style="background-image: url(' . Theme :: get_common_image_path() . 'place_location.png);">';
  59. echo '<div class="title">' . Translation :: get('Details') . '</div>';
  60. echo '<br /><b>' . Translation :: get('Student') . '</b>: ' . $user->get_fullname();
  61. echo '<br /><br /><b>' . Translation :: get('Name') . '</b>: ' . $this->moment->get_name();
  62. echo '<br /><b>' . Translation :: get('Description') . '</b>: ' . $this->moment->get_description();
  63. echo '<br /><br /><b>' . Translation :: get('Begin') . '</b>: ' . DatetimeUtilities :: format_locale_date(null, $this->moment->get_begin());
  64. echo '<br /><b>' . Translation :: get('End') . '</b>: ' . DatetimeUtilities :: format_locale_date(null, $this->moment->get_end());
  65. echo '<br /><br /><b>' . Translation :: get(InternshipOrganizerLocation :: PROPERTY_TELEPHONE) . '</b>: ' . $location->get_telephone();
  66. echo '<br /><b>' . Translation :: get(InternshipOrganizerLocation :: PROPERTY_ADDRESS) . '</b>: ' . $location->get_address();
  67. echo '<br /><b>' . Translation :: get(InternshipOrganizerRegion :: PROPERTY_CITY_NAME) . '</b>: ' . $region->get_zip_code() . ' ' . $region->get_city_name();
  68. echo '<div class="clear">&nbsp;</div>';
  69. echo '</div>';
  70. echo '<div>';
  71. echo $this->get_tabs();
  72. echo '</div>';
  73. echo '</div>';
  74. $this->display_footer();
  75. }
  76. function get_tabs()
  77. {
  78. $html = array();
  79. $html[] = '<div>';
  80. $renderer_name = Utilities :: get_classname_from_object($this, true);
  81. $tabs = new DynamicTabsRenderer($renderer_name);
  82. $parameters = $this->get_parameters();
  83. $parameters[self :: PARAM_MOMENT_ID] = $this->moment->get_id();
  84. $parameters[ActionBarSearchForm :: PARAM_SIMPLE_SEARCH_QUERY] = $this->action_bar->get_query();
  85. // Publications table tab
  86. $parameters[DynamicTabsRenderer :: PARAM_SELECTED_TAB] = self :: TAB_PUBLICATIONS;
  87. $table = new InternshipOrganizerPublicationTable($this, $parameters, $this->get_publications_condition(array(
  88. Document :: get_type_name())));
  89. $tabs->add_tab(new DynamicContentTab(self :: TAB_PUBLICATIONS, Translation :: get('InternshipOrganizerPublications'), Theme :: get_image_path(__NAMESPACE__) . 'place_mini_publication.png', $table->as_html()));
  90. $parameters[DynamicTabsRenderer :: PARAM_SELECTED_TAB] = self :: TAB_EVALUATIONS;
  91. $table = new InternshipOrganizerPublicationTable($this, $parameters, $this->get_publications_condition(array(
  92. Survey :: get_type_name())));
  93. $tabs->add_tab(new DynamicContentTab(self :: TAB_EVALUATIONS, Translation :: get('InternshipOrganizerEvaluations'), Theme :: get_image_path(__NAMESPACE__) . 'place_mini_evaluation.png', $table->as_html()));
  94. $html[] = $tabs->render();
  95. $html[] = '</div>';
  96. $html[] = '<div class="clear"></div>';
  97. return implode($html, "\n");
  98. }
  99. function get_action_bar()
  100. {
  101. $action_bar = new ActionBarRenderer(ActionBarRenderer :: TYPE_HORIZONTAL);
  102. $action_bar->set_search_url($this->get_url(array(self :: PARAM_MOMENT_ID => $this->moment->get_id())));
  103. if (InternshipOrganizerRights :: is_allowed_in_internship_organizers_subtree(InternshipOrganizerRights :: RIGHT_PUBLISH, $this->moment->get_id(), InternshipOrganizerRights :: TYPE_MOMENT))
  104. {
  105. $action_bar->add_common_action(new ToolbarItem(Translation :: get('Publish'), Theme :: get_common_image_path() . 'action_publish.png', $this->get_moment_publish_url($this->moment), ToolbarItem :: DISPLAY_ICON_AND_LABEL));
  106. }
  107. return $action_bar;
  108. }
  109. function get_publications_condition($types = array(''))
  110. {
  111. $conditions = array();
  112. $conditions[] = new EqualityCondition(InternshipOrganizerPublication :: PROPERTY_PUBLICATION_PLACE, InternshipOrganizerPublicationPlace :: MOMENT);
  113. $conditions[] = new EqualityCondition(InternshipOrganizerPublication :: PROPERTY_PLACE_ID, $this->moment->get_id());
  114. $conditions[] = new InCondition(InternshipOrganizerPublication :: PROPERTY_CONTENT_OBJECT_TYPE, $types);
  115. $query = $this->action_bar->get_query();
  116. if (isset($query) && $query != '')
  117. {
  118. $publication_alias = InternshipOrganizerDataManager :: get_instance()->get_alias(InternshipOrganizerPublication :: get_table_name());
  119. $user_alias = UserDataManager :: get_instance()->get_alias(User :: get_table_name());
  120. $object_alias = RepositoryDataManager :: get_instance()->get_alias(ContentObject :: get_table_name());
  121. $search_conditions = array();
  122. $search_conditions[] = new PatternMatchCondition(User :: PROPERTY_FIRSTNAME, '*' . $query . '*', $user_alias, true);
  123. $search_conditions[] = new PatternMatchCondition(User :: PROPERTY_LASTNAME, '*' . $query . '*', $user_alias, true);
  124. $search_conditions[] = new PatternMatchCondition(InternshipOrganizerPublication :: PROPERTY_NAME, '*' . $query . '*', $publication_alias, true);
  125. $search_conditions[] = new PatternMatchCondition(InternshipOrganizerPublication :: PROPERTY_DESCRIPTION, '*' . $query . '*', $publication_alias, true);
  126. $search_conditions[] = new PatternMatchCondition(ContentObject :: PROPERTY_TITLE, '*' . $query . '*', $object_alias, true);
  127. $search_conditions[] = new PatternMatchCondition(ContentObject :: PROPERTY_DESCRIPTION, '*' . $query . '*', $object_alias, true);
  128. $conditions[] = new OrCondition($search_conditions);
  129. }
  130. return new AndCondition($conditions);
  131. }
  132. function add_additional_breadcrumbs(BreadcrumbTrail $breadcrumbtrail)
  133. {
  134. $breadcrumbtrail->add(new Breadcrumb($this->get_url(array(
  135. self :: PARAM_ACTION => self :: ACTION_BROWSE_AGREEMENT)), Translation :: get('BrowseInternshipOrganizerAgreements')));
  136. $moment_id = Request :: get(self :: PARAM_MOMENT_ID);
  137. $moment = $this->retrieve_moment($moment_id);
  138. $agreement_id = $moment->get_agreement_id();
  139. $breadcrumbtrail->add(new Breadcrumb($this->get_url(array(
  140. self :: PARAM_ACTION => self :: ACTION_VIEW_AGREEMENT, self :: PARAM_AGREEMENT_ID => $agreement_id,
  141. DynamicTabsRenderer :: PARAM_SELECTED_TAB => InternshipOrganizerAgreementManagerViewerComponent :: TAB_MOMENTS)), Translation :: get('ViewInternshipOrganizerAgreement')));
  142. }
  143. function get_additional_parameters()
  144. {
  145. return array(self :: PARAM_AGREEMENT_ID, self :: PARAM_MOMENT_ID);
  146. }
  147. }
  148. ?>