Merge branch 'MDL-60092-master' of git://github.com/lameze/moodle
This commit is contained in:
@@ -46,107 +46,36 @@ class block_calendar_upcoming extends block_base {
|
||||
$this->content = new stdClass;
|
||||
$this->content->text = '';
|
||||
|
||||
$filtercourse = array();
|
||||
if (empty($this->instance)) { // Overrides: use no course at all.
|
||||
$courseshown = false;
|
||||
$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 {
|
||||
$courseshown = $this->page->course->id;
|
||||
$this->content->footer = '<div class="gotocal"><a href="'.$CFG->wwwroot.
|
||||
'/calendar/view.php?view=upcoming&course='.$courseshown.'">'.
|
||||
get_string('gotocalendar', 'calendar').'</a>...</div>';
|
||||
$context = context_course::instance($courseshown);
|
||||
if (has_any_capability(array('moodle/calendar:manageentries', 'moodle/calendar:manageownentries'), $context)) {
|
||||
$this->content->footer .= '<div class="newevent"><a href="'.$CFG->wwwroot.
|
||||
'/calendar/event.php?action=new&course='.$courseshown.'">'.
|
||||
get_string('newevent', 'calendar').'</a>...</div>';
|
||||
}
|
||||
if ($courseshown == SITEID) {
|
||||
// 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.
|
||||
$filtercourse = calendar_get_default_courses();
|
||||
} else {
|
||||
// Forcibly filter events to include only those from the particular course we are in.
|
||||
$filtercourse = array($courseshown => $this->page->course);
|
||||
}
|
||||
// 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);
|
||||
|
||||
list($courses, $group, $user) = calendar_set_filters($filtercourse);
|
||||
|
||||
$defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
|
||||
if (isset($CFG->calendar_lookahead)) {
|
||||
$defaultlookahead = intval($CFG->calendar_lookahead);
|
||||
}
|
||||
$lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
|
||||
|
||||
$defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS;
|
||||
if (isset($CFG->calendar_maxevents)) {
|
||||
$defaultmaxevents = intval($CFG->calendar_maxevents);
|
||||
}
|
||||
$maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
|
||||
$events = calendar_get_upcoming($courses, $group, $user, $lookahead, $maxevents);
|
||||
|
||||
if (!empty($this->instance)) {
|
||||
$link = 'view.php?view=day&course='.$courseshown.'&';
|
||||
$showcourselink = ($this->page->course->id == SITEID);
|
||||
$this->content->text = self::get_upcoming_content($events, $link, $showcourselink);
|
||||
}
|
||||
list($data, $template) = calendar_get_view($calendar, 'upcoming_mini');
|
||||
$this->content->text .= $renderer->render_from_template($template, $data);
|
||||
|
||||
if (empty($this->content->text)) {
|
||||
$this->content->text = '<div class="post">'. get_string('noupcomingevents', 'calendar').'</div>';
|
||||
}
|
||||
|
||||
$this->content->footer = '<div class="gotocal">
|
||||
<a href="'.$CFG->wwwroot.'/calendar/view.php?view=upcoming&course='.$courseid.'">'.
|
||||
get_string('gotocalendar', 'calendar').'</a>...</div>';
|
||||
|
||||
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('»', '<br />»', $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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -208,6 +208,9 @@ class event_exporter_base extends exporter {
|
||||
'editurl' => [
|
||||
'type' => PARAM_URL
|
||||
],
|
||||
'viewurl' => [
|
||||
'type' => PARAM_URL
|
||||
],
|
||||
'formattedtime' => [
|
||||
'type' => PARAM_RAW,
|
||||
],
|
||||
@@ -280,6 +283,10 @@ class event_exporter_base extends exporter {
|
||||
$editurl = new moodle_url('/calendar/event.php', ['action' => 'edit', 'id' => $event->get_id(),
|
||||
'course' => $courseid]);
|
||||
$values['editurl'] = $editurl->out(false);
|
||||
$viewurl = new moodle_url('/calendar/view.php', ['view' => 'day', 'course' => $courseid,
|
||||
'time' => $timesort]);
|
||||
$viewurl->set_anchor('event_' . $event->get_id());
|
||||
$values['viewurl'] = $viewurl->out(false);
|
||||
$values['formattedtime'] = calendar_format_event_time($legacyevent, time(), null, false,
|
||||
$timesort);
|
||||
|
||||
|
||||
+8
-74
@@ -1318,77 +1318,6 @@ function calendar_get_starting_weekday() {
|
||||
return $calendartype->get_starting_weekday();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the calendar upcoming event.
|
||||
*
|
||||
* @param array $courses array of courses
|
||||
* @param array|int|bool $groups array of groups, group id or boolean for all/no group events
|
||||
* @param array|int|bool $users array of users, user id or boolean for all/no user events
|
||||
* @param int $daysinfuture number of days in the future we 'll look
|
||||
* @param int $maxevents maximum number of events
|
||||
* @param int $fromtime start time
|
||||
* @return array $output array of upcoming events
|
||||
*/
|
||||
function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime=0) {
|
||||
global $COURSE;
|
||||
|
||||
$display = new \stdClass;
|
||||
$display->range = $daysinfuture; // How many days in the future we 'll look.
|
||||
$display->maxevents = $maxevents;
|
||||
|
||||
$output = array();
|
||||
|
||||
$processed = 0;
|
||||
$now = time(); // We 'll need this later.
|
||||
$usermidnighttoday = usergetmidnight($now);
|
||||
|
||||
if ($fromtime) {
|
||||
$display->tstart = $fromtime;
|
||||
} else {
|
||||
$display->tstart = $usermidnighttoday;
|
||||
}
|
||||
|
||||
// This works correctly with respect to the user's DST, but it is accurate
|
||||
// only because $fromtime is always the exact midnight of some day!
|
||||
$display->tend = usergetmidnight($display->tstart + DAYSECS * $display->range + 3 * HOURSECS) - 1;
|
||||
|
||||
// Get the events matching our criteria.
|
||||
$events = calendar_get_legacy_events($display->tstart, $display->tend, $users, $groups, $courses);
|
||||
|
||||
// This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after
|
||||
// possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month
|
||||
// will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra
|
||||
// arguments to this function.
|
||||
$hrefparams = array();
|
||||
if (!empty($courses)) {
|
||||
$courses = array_diff($courses, array(SITEID));
|
||||
if (count($courses) == 1) {
|
||||
$hrefparams['course'] = reset($courses);
|
||||
}
|
||||
}
|
||||
|
||||
if ($events !== false) {
|
||||
foreach ($events as $event) {
|
||||
if (!empty($event->modulename)) {
|
||||
$instances = get_fast_modinfo($event->courseid)->get_instances_of($event->modulename);
|
||||
if (empty($instances[$event->instance]->uservisible)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($processed >= $display->maxevents) {
|
||||
break;
|
||||
}
|
||||
|
||||
$event->time = calendar_format_event_time($event, $now, $hrefparams);
|
||||
$output[] = $event;
|
||||
$processed++;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a HTML link to a course.
|
||||
*
|
||||
@@ -3147,7 +3076,7 @@ function calendar_get_view(\calendar_information $calendar, $view, $includenavig
|
||||
if ($view === 'day') {
|
||||
$tstart = $type->convert_to_timestamp($date['year'], $date['mon'], $date['mday']);
|
||||
$tend = $tstart + DAYSECS - 1;
|
||||
} else if ($view === 'upcoming') {
|
||||
} else if ($view === 'upcoming' || $view === 'upcoming_mini') {
|
||||
if (isset($CFG->calendar_lookahead)) {
|
||||
$defaultlookahead = intval($CFG->calendar_lookahead);
|
||||
} else {
|
||||
@@ -3234,10 +3163,15 @@ function calendar_get_view(\calendar_information $calendar, $view, $includenavig
|
||||
$day = new \core_calendar\external\calendar_day_exporter($calendar, $related);
|
||||
$data = $day->export($renderer);
|
||||
$template = 'core_calendar/calendar_day';
|
||||
} else if ($view == "upcoming") {
|
||||
} else if ($view == "upcoming" || $view == "upcoming_mini") {
|
||||
$upcoming = new \core_calendar\external\calendar_upcoming_exporter($calendar, $related);
|
||||
$data = $upcoming->export($renderer);
|
||||
$template = 'core_calendar/calendar_upcoming';
|
||||
|
||||
if ($view == "upcoming") {
|
||||
$template = 'core_calendar/calendar_upcoming';
|
||||
} else if ($view == "upcoming_mini") {
|
||||
$template = 'core_calendar/upcoming_mini';
|
||||
}
|
||||
}
|
||||
|
||||
return [$data, $template];
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template calendar/upcoming_mini
|
||||
|
||||
Calendar upcoming view for blocks.
|
||||
|
||||
The purpose of this template is to render the upcoming view for blocks.
|
||||
|
||||
Classes required for JS:
|
||||
* none
|
||||
|
||||
Data attributes required for JS:
|
||||
* none
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
}
|
||||
}}
|
||||
<div class="card-text content">
|
||||
{{#events}}
|
||||
<div class="event">
|
||||
<span>{{#icon}}{{#pix}} {{key}}, {{component}}, {{alttext}} {{/pix}}{{/icon}}</span>
|
||||
<a href="{{viewurl}}">{{{name}}}</a>
|
||||
<div class="date">{{{formattedtime}}}</div>
|
||||
</div>
|
||||
<hr>
|
||||
{{/events}}
|
||||
</div>
|
||||
Reference in New Issue
Block a user