From 557d8528eb8796c50867b86464c37cfeb6ee9368 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 27 Oct 2017 10:26:20 +0800 Subject: [PATCH] MDL-60587 block_calendar_upcoming: Setup calendar using new helper --- .../block_calendar_upcoming.php | 36 +++++++++---------- .../lang/en/block_calendar_upcoming.php | 1 + 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/blocks/calendar_upcoming/block_calendar_upcoming.php b/blocks/calendar_upcoming/block_calendar_upcoming.php index e0e0267f78d71..5abdbafd9cc7b 100644 --- a/blocks/calendar_upcoming/block_calendar_upcoming.php +++ b/blocks/calendar_upcoming/block_calendar_upcoming.php @@ -45,31 +45,27 @@ public function get_content() { } $this->content = new stdClass; $this->content->text = ''; + $this->content->footer = ''; - $renderer = $this->page->get_renderer('core_calendar'); - $courseid = $this->page->course->id; - $issite = ($courseid == SITEID); - - if ($issite) { - // Being displayed at site level. This will cause the filter to fall back to auto-detecting - // the list of courses it will be grabbing events from. - $course = get_site(); - $courses = calendar_get_default_courses(); - } else { - // Forcibly filter events to include only those from the particular course we are in. - $course = $this->page->course; - $courses = [$course->id => $course]; - } - $calendar = new calendar_information(0, 0, 0, time()); - $calendar->set_sources($course, $courses, $this->page->category); - + $courseid = isset($this->page->course) ? $this->page->course->id : SITEID; + $categoryid = isset($this->page->category) ? $this->page->category->id : null; + $calendar = \calendar_information::create(time(), $courseid, $categoryid); list($data, $template) = calendar_get_view($calendar, 'upcoming_mini'); + $renderer = $this->page->get_renderer('core_calendar'); $this->content->text .= $renderer->render_from_template($template, $data); - $this->content->footer = '
- '. - get_string('gotocalendar', 'calendar').'...
'; + $url = new \moodle_url('/calendar/view.php', ['view' => 'upcoming']); + if ($courseid != SITEID) { + $url->param('course', $this->page->course->id); + } else if (!empty($categoryid)) { + $url->param('category', $this->page->category->id); + } + + $this->content->footer = html_writer::div( + html_writer::link($url, get_string('gotocalendar', 'block_calendar_upcoming')), + 'gotocal' + ); return $this->content; } diff --git a/blocks/calendar_upcoming/lang/en/block_calendar_upcoming.php b/blocks/calendar_upcoming/lang/en/block_calendar_upcoming.php index 2b1423815d665..dc8adc3df95f5 100644 --- a/blocks/calendar_upcoming/lang/en/block_calendar_upcoming.php +++ b/blocks/calendar_upcoming/lang/en/block_calendar_upcoming.php @@ -24,4 +24,5 @@ $string['calendar_upcoming:addinstance'] = 'Add a new upcoming events block'; $string['calendar_upcoming:myaddinstance'] = 'Add a new upcoming events block to Dashboard'; +$string['gotocalendar'] = 'Go to calendar...'; $string['pluginname'] = 'Upcoming events';