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

/php/lib/browser/list_renderer/calendar_content_object_publication_list_renderer.class.php

https://bitbucket.org/chamilo/chamilo-app-weblcms/
PHP | 267 lines | 192 code | 46 blank | 29 comment | 15 complexity | 0518d22909cf136be53957155278f19f MD5 | raw file
  1. <?php
  2. namespace application\weblcms;
  3. use common\libraries\NotCondition;
  4. use common\libraries\Toolbar;
  5. use common\libraries\ToolbarItem;
  6. use common\libraries\Theme;
  7. use common\libraries\AndCondition;
  8. use common\libraries\EqualityCondition;
  9. use common\libraries\Request;
  10. use common\libraries\Translation;
  11. use common\libraries\Utilities;
  12. /**
  13. * $Id: week_calendar_content_object_publication_list_renderer.class.php 216 2009-11-13 14:08:06Z kariboe $
  14. * @package application.lib.weblcms.browser.list_renderer
  15. */
  16. require_once dirname(__FILE__) . '/../content_object_publication_list_renderer.class.php';
  17. /**
  18. * Interval between sections in the week view of the calendar.
  19. */
  20. /**
  21. * Renderer to display events in a week calendar
  22. */
  23. class CalendarContentObjectPublicationListRenderer extends ContentObjectPublicationListRenderer
  24. {
  25. const CALENDAR_MONTH_VIEW = 'month';
  26. const CALENDAR_WEEK_VIEW = 'week';
  27. const CALENDAR_DAY_VIEW = 'day';
  28. const CALENDAR_YEAR_VIEW = 'year';
  29. const PARAM_CALENDAR_VIEW = 'view';
  30. /**
  31. * The current time displayed in the calendar
  32. */
  33. private $display_time;
  34. /**
  35. * Sets the current display time.
  36. * @param int $time The current display time.
  37. */
  38. function set_display_time($time)
  39. {
  40. $this->display_time = $time;
  41. }
  42. function get_display_time()
  43. {
  44. return $this->display_time;
  45. }
  46. function get_view()
  47. {
  48. return Request :: get(self :: PARAM_CALENDAR_VIEW);
  49. }
  50. function get_calendar_events($from_time, $to_time, $limit = 0)
  51. {
  52. $publications = $this->get_publications();
  53. $events = array();
  54. foreach ($publications as $index => $publication)
  55. {
  56. if (method_exists($this->get_tool_browser()->get_parent(), 'convert_content_object_publication_to_calendar_event'))
  57. {
  58. $publication = $this->get_tool_browser()->get_parent()->convert_content_object_publication_to_calendar_event($publication, $from_time, $to_time);
  59. }
  60. $object = $publication->get_content_object();
  61. if ($object->repeats())
  62. {
  63. $repeats = $object->get_repeats($from_time, $to_time);
  64. foreach ($repeats as $repeat)
  65. {
  66. $the_publication = clone $publication;
  67. $the_publication->set_content_object($repeat);
  68. $events[$repeat->get_start_date()][] = $the_publication;
  69. }
  70. }
  71. elseif ($from_time <= $object->get_start_date() && $object->get_start_date() <= $to_time || $from_time <= $object->get_end_date() && $object->get_end_date() <= $to_time || $object->get_start_date() <= $from_time && $to_time <= $object->get_end_date())
  72. {
  73. $events[$object->get_start_date()][] = $publication;
  74. }
  75. }
  76. ksort($events);
  77. $calendar_events = array();
  78. foreach($events as $start_time => $time_events)
  79. {
  80. foreach($time_events as $event)
  81. {
  82. $calendar_events[] = $event;
  83. }
  84. }
  85. return $calendar_events;
  86. }
  87. function as_html()
  88. {
  89. $time = Request :: get('time') ? intval(Request :: get('time')) : time();
  90. $this->set_display_time($time);
  91. $mini_month_calendar = ContentObjectPublicationListRenderer :: factory(ContentObjectPublicationListRenderer :: TYPE_MINI_MONTH, $this->get_tool_browser());
  92. $mini_month_calendar->set_display_time($this->get_display_time());
  93. $html[] = '<div class="mini_calendar">';
  94. $html[] = $mini_month_calendar->as_html();
  95. $html[] = '<br />';
  96. $html[] = $this->list_views();
  97. $html[] = $this->render_upcoming_events();
  98. $html[] = '</div>';
  99. //style="margin-left: 0px; float: right; width: 70%;"
  100. $html[] = '<div class="normal_calendar">';
  101. $view = $this->get_view();
  102. switch ($view)
  103. {
  104. case self :: CALENDAR_DAY_VIEW :
  105. $calendar = ContentObjectPublicationListRenderer :: factory(ContentObjectPublicationListRenderer :: TYPE_DAY, $this->get_tool_browser());
  106. break;
  107. case self :: CALENDAR_WEEK_VIEW :
  108. $calendar = ContentObjectPublicationListRenderer :: factory(ContentObjectPublicationListRenderer :: TYPE_WEEK, $this->get_tool_browser());
  109. break;
  110. case self :: CALENDAR_MONTH_VIEW :
  111. $calendar = ContentObjectPublicationListRenderer :: factory(ContentObjectPublicationListRenderer :: TYPE_MONTH, $this->get_tool_browser());
  112. break;
  113. case self :: CALENDAR_YEAR_VIEW :
  114. $calendar = ContentObjectPublicationListRenderer :: factory(ContentObjectPublicationListRenderer :: TYPE_YEAR, $this->get_tool_browser());
  115. break;
  116. default :
  117. $calendar = ContentObjectPublicationListRenderer :: factory(ContentObjectPublicationListRenderer :: TYPE_MONTH, $this->get_tool_browser());
  118. break;
  119. }
  120. $calendar->set_display_time($time);
  121. $html[] = $calendar->as_html();
  122. $html[] = '</div>';
  123. return implode("\n", $html);
  124. }
  125. function get_filter_targets()
  126. {
  127. $course = $this->get_course_id();
  128. $targets = array();
  129. $user_conditions = array();
  130. $user_conditions[] = new EqualityCondition(CourseUserRelation :: PROPERTY_COURSE, $course);
  131. $user_conditions[] = new NotCondition(new EqualityCondition(CourseUserRelation :: PROPERTY_USER, $this->get_user_id()));
  132. $user_condition = new AndCondition($user_conditions);
  133. $user_relations = WeblcmsDataManager :: get_instance()->retrieve_course_user_relations($user_condition);
  134. if ($user_relations->size() > 0)
  135. {
  136. $targets[] = Translation :: get('Users', null ,'user');
  137. $targets[] = '----------';
  138. while ($user_relation = $user_relations->next_result())
  139. {
  140. $user = $user_relation->get_user_object();
  141. $targets['user|' . $user->get_id()] = $user->get_fullname() . ' (' . $user->get_username() . ')';
  142. }
  143. }
  144. $groups = WeblcmsDataManager :: get_instance()->retrieve_course_groups(new EqualityCondition(CourseGroup :: PROPERTY_COURSE_CODE, $course));
  145. if ($groups->size() > 0)
  146. {
  147. if ($user_relations->size() > 0)
  148. {
  149. $targets[] = '';
  150. }
  151. $targets[] = Translation :: get('Groups', null ,'groups');
  152. $targets[] = '----------';
  153. while ($group = $groups->next_result())
  154. {
  155. $targets['group|' . $group->get_id()] = $group->get_name();
  156. }
  157. }
  158. return $targets;
  159. }
  160. function list_views()
  161. {
  162. $toolbar = new Toolbar(Toolbar :: TYPE_VERTICAL);
  163. $toolbar->add_item(new ToolbarItem(Translation :: get('MonthView', null ,Utilities:: COMMON_LIBRARIES), Theme :: get_image_path() . 'tool_calendar_month.png', $this->get_url(array(self :: PARAM_CALENDAR_VIEW => self :: CALENDAR_MONTH_VIEW, 'time' => $this->get_display_time())), ToolbarItem :: DISPLAY_ICON_AND_LABEL));
  164. $toolbar->add_item(new ToolbarItem(Translation :: get('WeekView', null ,Utilities:: COMMON_LIBRARIES), Theme :: get_image_path() . 'tool_calendar_week.png', $this->get_url(array(self :: PARAM_CALENDAR_VIEW => self :: CALENDAR_WEEK_VIEW, 'time' => $this->get_display_time())), ToolbarItem :: DISPLAY_ICON_AND_LABEL));
  165. $toolbar->add_item(new ToolbarItem(Translation :: get('DayView', null ,Utilities:: COMMON_LIBRARIES), Theme :: get_image_path() . 'tool_calendar_day.png', $this->get_url(array(self :: PARAM_CALENDAR_VIEW => self :: CALENDAR_DAY_VIEW, 'time' => $this->get_display_time())), ToolbarItem :: DISPLAY_ICON_AND_LABEL));
  166. $toolbar->add_item(new ToolbarItem(Translation :: get('YearView', null ,Utilities:: COMMON_LIBRARIES), Theme :: get_image_path() . 'tool_calendar_year.png', $this->get_url(array(self :: PARAM_CALENDAR_VIEW => self :: CALENDAR_YEAR_VIEW, 'time' => $this->get_display_time())), ToolbarItem :: DISPLAY_ICON_AND_LABEL));
  167. $toolbar->add_item(new ToolbarItem(Translation :: get('Today', null ,Utilities:: COMMON_LIBRARIES), Theme :: get_image_path() . 'tool_calendar_today.png', $this->get_url(array(self :: PARAM_CALENDAR_VIEW => $this->get_view(), 'time' => time())), ToolbarItem :: DISPLAY_ICON_AND_LABEL));
  168. $html = array();
  169. $html[] = '<div class="content_object" style="padding: 10px;">';
  170. $html[] = '<div class="description">';
  171. /*if ($this->is_allowed(WeblcmsRights :: EDIT_RIGHT))
  172. {
  173. $form = new FormValidator('user_filter', 'post', $this->get_url());
  174. $renderer = $form->defaultRenderer();
  175. $renderer->setElementTemplate('{element}');
  176. $form->addElement('select', 'filter', Translation :: get('FilterTarget'), $this->get_filter_targets());
  177. $form->addElement('submit', 'submit', Translation :: get('Ok', null ,Utilities:: COMMON_LIBRARIES));
  178. $html[] = $form->toHtml();
  179. $html[] = '<br />';
  180. }*/
  181. $html[] = $toolbar->as_html();
  182. $html[] = '</div>';
  183. $html[] = '</div>';
  184. return implode("\n", $html);
  185. }
  186. function render_upcoming_events()
  187. {
  188. $html = array();
  189. $amount_to_show = 5;
  190. $publications = $this->get_calendar_events(time(), strtotime('+1 Year', time()), $amount_to_show);
  191. ksort($publications);
  192. $count = count($publications);
  193. $total = $count < $amount_to_show ? $count : $amount_to_show;
  194. if (count($publications) > 0)
  195. {
  196. $html[] = '<div class="content_object" style="padding: 10px;">';
  197. $html[] = '<div class="title">' . Translation :: get('UpcomingEvents') . '</div>';
  198. $html[] = '<div class="description">';
  199. $i = 0;
  200. foreach ($publications as $publication)
  201. {
  202. $html[] = $this->render_small_publication($publication);
  203. $i ++;
  204. if ($i >= $amount_to_show)
  205. {
  206. break;
  207. }
  208. }
  209. $html[] = '</div>';
  210. $html[] = '</div>';
  211. }
  212. return implode("\n", $html);
  213. }
  214. function render_small_publication($publication)
  215. {
  216. $feedback_url = $this->get_url(array(Tool :: PARAM_PUBLICATION_ID => $publication->get_id(), Tool :: PARAM_ACTION => Tool :: ACTION_VIEW), array(), true);
  217. return '<a href="' . $feedback_url . '">' . date('d/m/y H:i:s -', $publication->get_content_object()->get_start_date()) . ' ' . $publication->get_content_object()->get_title() . '</a><br />';
  218. }
  219. }
  220. ?>