Skip to content

Commit

Permalink
MDL-60558 calendar: Upcoming should support categories
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Nov 2, 2017
1 parent 5c9acb8 commit d523cbc
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion blocks/calendar_upcoming/block_calendar_upcoming.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function get_content() {
$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');

Expand Down
2 changes: 1 addition & 1 deletion calendar/amd/build/repository.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calendar/amd/build/view_manager.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion calendar/amd/src/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
};

Expand Down
11 changes: 8 additions & 3 deletions calendar/amd/src/view_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down
10 changes: 10 additions & 0 deletions calendar/classes/external/calendar_upcoming_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ protected static function define_other_properties() {
'courseid' => [
'type' => PARAM_INT,
],
'categoryid' => [
'type' => PARAM_INT,
'optional' => true,
'default' => 0,
],
];
}

Expand Down Expand Up @@ -127,6 +132,11 @@ protected function get_other_values(renderer_base $output) {
}
$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;
}

Expand Down
17 changes: 16 additions & 1 deletion calendar/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1154,12 +1154,26 @@ public static function get_calendar_upcoming_view($courseid) {
// 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();
Expand All @@ -1169,7 +1183,7 @@ public static function get_calendar_upcoming_view($courseid) {
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');

Expand All @@ -1185,6 +1199,7 @@ public static function get_calendar_upcoming_view_parameters() {
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),
]
);
}
Expand Down

0 comments on commit d523cbc

Please sign in to comment.