Commit d523cbcb authored by Andrew Nicols's avatar Andrew Nicols
Browse files

MDL-60558 calendar: Upcoming should support categories

parent 5c9acb81
......@@ -61,7 +61,7 @@ class block_calendar_upcoming extends block_base {
$courses = [$course->id => $course];
}
$calendar = new calendar_information(0, 0, 0, time());
$calendar->set_sources($course, $courses);
$calendar->set_sources($course, $courses, $this->page->category);
list($data, $template) = calendar_get_view($calendar, 'upcoming_mini');
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -164,13 +164,15 @@ define(['jquery', 'core/ajax'], function($, Ajax) {
*
* @method getCalendarUpcomingData
* @param {Number} courseid The course id.
* @param {Number} categoryid The category id.
* @return {promise} Resolved with the month view data.
*/
var getCalendarUpcomingData = function(courseid) {
var getCalendarUpcomingData = function(courseid, categoryid) {
var request = {
methodname: 'core_calendar_get_calendar_upcoming_view',
args: {
courseid: courseid,
categoryid: categoryid,
}
};
......
......@@ -305,18 +305,23 @@ define([
*
* @param {object} root The container element.
* @param {Number} courseId The course id.
* @param {Number} categoryId The id of the category whose events are shown
* @return {promise}
*/
var reloadCurrentUpcoming = function(root, courseId) {
var reloadCurrentUpcoming = function(root, courseId, categoryId) {
startLoading(root);
var target = root.find(CalendarSelectors.wrapper);
if (!courseId) {
if (typeof courseId === 'undefined') {
courseId = root.find(CalendarSelectors.wrapper).data('courseid');
}
return CalendarRepository.getCalendarUpcomingData(courseId)
if (typeof categoryId === 'undefined') {
categoryId = root.find(CalendarSelectors.wrapper).data('categoryid');
}
return CalendarRepository.getCalendarUpcomingData(courseId, categoryId)
.then(function(context) {
return Templates.render(root.attr('data-template'), context);
})
......
......@@ -82,6 +82,11 @@ class calendar_upcoming_exporter extends exporter {
'courseid' => [
'type' => PARAM_INT,
],
'categoryid' => [
'type' => PARAM_INT,
'optional' => true,
'default' => 0,
],
];
}
......@@ -127,6 +132,11 @@ class calendar_upcoming_exporter extends exporter {
}
$return['filter_selector'] = $this->get_course_filter_selector($output);
$return['courseid'] = $this->calendar->courseid;
if ($this->calendar->categoryid) {
$return['categoryid'] = $this->calendar->categoryid;
}
return $return;
}
......
......@@ -1154,12 +1154,26 @@ class core_calendar_external extends external_api {
// Parameter validation.
self::validate_parameters(self::get_calendar_upcoming_view_parameters(), [
'courseid' => $courseid,
'categoryid' => $categoryid,
]);
$PAGE->set_url('/calendar/');
$category = null;
if ($courseid != SITEID && !empty($courseid)) {
// Course ID must be valid and existing.
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$courses = [$course->id => $course];
} else if (!empty($categoryid)) {
$course = get_site();
$courses = calendar_get_default_courses();
$category = \coursecat::get($categoryid);
$ids += $category->get_parents();
$categories = \coursecat::get_many($ids);
$courses = array_filter($courses, function($course) use ($categories) {
return array_search($course->category, $categories) !== false;
});
$category = $category->get_db_record();
} else {
$course = get_site();
$courses = calendar_get_default_courses();
......@@ -1169,7 +1183,7 @@ class core_calendar_external extends external_api {
self::validate_context($context);
$calendar = new calendar_information(0, 0, 0, time());
$calendar->set_sources($course, $courses);
$calendar->set_sources($course, $courses, $category);
list($data, $template) = calendar_get_view($calendar, 'upcoming');
......@@ -1185,6 +1199,7 @@ class core_calendar_external extends external_api {
return new external_function_parameters(
[
'courseid' => new external_value(PARAM_INT, 'Course being viewed', VALUE_DEFAULT, SITEID, NULL_ALLOWED),
'categoryid' => new external_value(PARAM_INT, 'Category being viewed', VALUE_DEFAULT, null, NULL_ALLOWED),
]
);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment