From 349d379616893e4de971a1476a11249f48f0d07a Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 24 Oct 2017 13:31:02 +0800 Subject: [PATCH] MDL-60561 calendar: Increase event limit for calendar It's quite common to have more than 50 events in a calendar month, but we do not want to change the default value when the API is called in other ways. --- .../classes/local/event/data_access/event_vault.php | 4 ++-- calendar/lib.php | 13 +++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/calendar/classes/local/event/data_access/event_vault.php b/calendar/classes/local/event/data_access/event_vault.php index 9111f3918c0..246cd9f66a0 100644 --- a/calendar/classes/local/event/data_access/event_vault.php +++ b/calendar/classes/local/event/data_access/event_vault.php @@ -102,8 +102,8 @@ class event_vault implements event_vault_interface { $ignorehidden = true, callable $filter = null ) { - if ($limitnum < 1 || $limitnum > 50) { - throw new limit_invalid_parameter_exception("Limit must be between 1 and 50 (inclusive)"); + if ($limitnum < 1 || $limitnum > 200) { + throw new limit_invalid_parameter_exception("Limit must be between 1 and 200 (inclusive)"); } $fromquery = function($field, $timefrom, $lastseenmethod, $afterevent, $withduration) { diff --git a/calendar/lib.php b/calendar/lib.php index ef5a16f598d..d495d5d4937 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -3066,6 +3066,7 @@ function calendar_get_view(\calendar_information $calendar, $view, $includenavig $calendardate = $type->timestamp_to_date_array($calendar->time); $date = new \DateTime('now', core_date::get_user_timezone_object(99)); + $eventlimit = 200; if ($view === 'day') { $tstart = $type->convert_to_timestamp($calendardate['year'], $calendardate['mon'], $calendardate['mday']); @@ -3085,7 +3086,7 @@ function calendar_get_view(\calendar_information $calendar, $view, $includenavig if (isset($CFG->calendar_maxevents)) { $defaultmaxevents = intval($CFG->calendar_maxevents); } - $maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents); + $eventlimit = get_user_preferences('calendar_maxevents', $defaultmaxevents); $tstart = $type->convert_to_timestamp($calendardate['year'], $calendardate['mon'], $calendardate['mday'], $calendardate['hours']); @@ -3128,14 +3129,6 @@ function calendar_get_view(\calendar_information $calendar, $view, $includenavig return $param; }, [$calendar->users, $calendar->groups, $calendar->courses, $calendar->categories]); - // We need to make sure user calendar preferences are respected. - // If max upcoming events is not set then use default value of 40 events. - if (isset($maxevents)) { - $limit = $maxevents; - } else { - $limit = 40; - } - $events = \core_calendar\local\api::get_events( $tstart, $tend, @@ -3143,7 +3136,7 @@ function calendar_get_view(\calendar_information $calendar, $view, $includenavig null, null, null, - $limit, + $eventlimit, null, $userparam, $groupparam, -- 2.43.0