Skip to content

Commit

Permalink
MDL-60763 core_calendar: Revert removal of calendar_get_upcoming
Browse files Browse the repository at this point in the history
This reverts part of commit 522b84b.
  • Loading branch information
andrewnicols committed Nov 10, 2017
1 parent 6996fba commit 9dead25
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions blocks/calendar_upcoming/block_calendar_upcoming.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,52 @@ public function get_content() {

return $this->content;
}

/**
* Get the upcoming event block content.
*
* @param array $events list of events
* @param \moodle_url|string $linkhref link to event referer
* @param boolean $showcourselink whether links to courses should be shown
* @return string|null $content html block content
*/
public static function get_upcoming_content($events, $linkhref = null, $showcourselink = false) {
$content = '';
$lines = count($events);

if (!$lines) {
return $content;
}

for ($i = 0; $i < $lines; ++$i) {
if (!isset($events[$i]->time)) {
continue;
}
$events[$i] = calendar_add_event_metadata($events[$i]);
$content .= '<div class="event"><span class="icon c0">' . $events[$i]->icon . '</span>';
if (!empty($events[$i]->referer)) {
// That's an activity event, so let's provide the hyperlink.
$content .= $events[$i]->referer;
} else {
if (!empty($linkhref)) {
$href = calendar_get_link_href(new \moodle_url(CALENDAR_URL . $linkhref), 0, 0, 0,
$events[$i]->timestart);
$href->set_anchor('event_' . $events[$i]->id);
$content .= \html_writer::link($href, $events[$i]->name);
} else {
$content .= $events[$i]->name;
}
}
$events[$i]->time = str_replace('&raquo;', '<br />&raquo;', $events[$i]->time);
if ($showcourselink && !empty($events[$i]->courselink)) {
$content .= \html_writer::div($events[$i]->courselink, 'course');
}
$content .= '<div class="date">' . $events[$i]->time . '</div></div>';
if ($i < $lines - 1) {
$content .= '<hr />';
}
}

return $content;
}
}

0 comments on commit 9dead25

Please sign in to comment.