agenda_list.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.calendar
  5. */
  6. require_once __DIR__.'/../inc/global.inc.php';
  7. $interbreadcrumb[] = [
  8. 'url' => api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php',
  9. 'name' => get_lang('Agenda'),
  10. ];
  11. $currentCourseId = api_get_course_int_id();
  12. $currentGroupdId = api_get_group_id();
  13. if (!empty($currentGroupdId)) {
  14. $groupProperties = GroupManager::get_group_properties($currentGroupdId);
  15. $currentGroupdId = $groupProperties['iid'];
  16. $interbreadcrumb[] = [
  17. "url" => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(),
  18. "name" => get_lang('Groups'),
  19. ];
  20. $interbreadcrumb[] = [
  21. "url" => api_get_path(WEB_CODE_PATH)."group/group_space.php?".api_get_cidreq(),
  22. "name" => get_lang('GroupSpace').' '.$groupProperties['name'],
  23. ];
  24. }
  25. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
  26. $agenda = new Agenda($type);
  27. $events = $agenda->getEvents(
  28. null,
  29. null,
  30. $currentCourseId,
  31. $currentGroupdId,
  32. null,
  33. 'array'
  34. );
  35. $this_section = SECTION_MYAGENDA;
  36. if (!empty($currentCourseId) && $currentCourseId != -1) {
  37. // Agenda is inside a course tool
  38. $url = api_get_self().'?'.api_get_cidreq();
  39. $this_section = SECTION_COURSES;
  40. // Order by start date
  41. usort($events, function ($a, $b) {
  42. $t1 = strtotime($a['start']);
  43. $t2 = strtotime($b['start']);
  44. return $t1 > $t2;
  45. });
  46. } else {
  47. // Agenda is out of the course tool (e.g personal agenda)
  48. // Little hack to sort the events by start date in personal agenda (Agenda events List view - See #8014)
  49. usort($events, function ($a, $b) {
  50. $t1 = strtotime($a['start']);
  51. $t2 = strtotime($b['start']);
  52. return $t1 - $t2;
  53. });
  54. $url = false;
  55. if (!empty($events)) {
  56. foreach ($events as &$event) {
  57. $courseId = isset($event['course_id']) ? $event['course_id'] : '';
  58. $event['url'] = api_get_self().'?cid='.$courseId.'&type='.$event['type'];
  59. }
  60. }
  61. }
  62. $actions = $agenda->displayActions('list');
  63. $tpl = new Template(get_lang('Events'));
  64. $tpl->assign('agenda_events', $events);
  65. $tpl->assign('url', $url);
  66. $tpl->assign('show_action', in_array($type, ['course', 'session']));
  67. $tpl->assign('agenda_actions', $actions);
  68. $tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit());
  69. if (api_is_allowed_to_edit()) {
  70. if (isset($_GET['action']) && $_GET['action'] == 'change_visibility') {
  71. $courseInfo = api_get_course_info();
  72. $courseCondition = '';
  73. // This happens when list agenda is not inside a course
  74. if (($type == 'course' || $type == 'session' && !empty($courseInfo))) {
  75. // For course and session event types
  76. // Just needs course ID
  77. $agenda->changeVisibility($_GET['id'], $_GET['visibility'], $courseInfo);
  78. } else {
  79. $courseCondition = '&'.api_get_cidreq();
  80. }
  81. header('Location: '.api_get_self().'?type='.$agenda->type.$courseCondition);
  82. exit;
  83. }
  84. }
  85. $templateName = $tpl->get_template('agenda/event_list.tpl');
  86. $content = $tpl->fetch($templateName);
  87. $tpl->assign('content', $content);
  88. $tpl->display_one_col_template();