Commit 01ed53df authored by Damyon Wiese's avatar Damyon Wiese
Browse files

MDL-59973 calendar: Only load required fields

When loading courses for the course filter on the calendar, we only need the id and shortname.
parent 1b7d75f1
...@@ -2138,9 +2138,10 @@ function calendar_delete_event_allowed($event) { ...@@ -2138,9 +2138,10 @@ function calendar_delete_event_allowed($event) {
* course to display. * course to display.
* *
* @param int $courseid (optional) If passed, an additional course can be returned for admins (the current course). * @param int $courseid (optional) If passed, an additional course can be returned for admins (the current course).
* @param string $fields Comma separated list of course fields to return.
* @return array $courses Array of courses to display * @return array $courses Array of courses to display
*/ */
function calendar_get_default_courses($courseid = null) { function calendar_get_default_courses($courseid = null, $fields = '*') {
global $CFG, $DB; global $CFG, $DB;
if (!isloggedin()) { if (!isloggedin()) {
...@@ -2148,9 +2149,15 @@ function calendar_get_default_courses($courseid = null) { ...@@ -2148,9 +2149,15 @@ function calendar_get_default_courses($courseid = null) {
} }
if (has_capability('moodle/calendar:manageentries', context_system::instance()) && !empty($CFG->calendar_adminseesall)) { if (has_capability('moodle/calendar:manageentries', context_system::instance()) && !empty($CFG->calendar_adminseesall)) {
$courses = get_courses('all', 'c.shortname', 'c.*'); // Add a c. prefix to every field as expected by get_courses function.
$fieldlist = explode(',', $fields);
$prefixedfields = array_map(function($value) {
return 'c.' . trim($value);
}, $fieldlist);
$courses = get_courses('all', 'c.shortname', implode(',', $prefixedfields));
} else { } else {
$courses = enrol_get_my_courses(); $courses = enrol_get_my_courses($fields);
} }
if ($courseid && $courseid != SITEID) { if ($courseid && $courseid != SITEID) {
......
...@@ -247,7 +247,7 @@ class core_calendar_renderer extends plugin_renderer_base { ...@@ -247,7 +247,7 @@ class core_calendar_renderer extends plugin_renderer_base {
return ''; return '';
} }
$courses = calendar_get_default_courses($courseid); $courses = calendar_get_default_courses($courseid, 'id, shortname');
unset($courses[SITEID]); unset($courses[SITEID]);
......
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