MDL-64063 core_calendar: events by time considers enrolment status.

This commit is contained in:
Adrian Greeve 2018-11-19 10:07:39 +08:00
parent 0225ad42ea
commit 644ffbd332
6 changed files with 21 additions and 9 deletions

View File

@ -1 +1 @@
define(["jquery","core/ajax","core/notification"],function(a,b,c){var d=20,e=function(a){a.hasOwnProperty("limit")||(a.limit=d),a.limitnum=a.limit,delete a.limit,a.hasOwnProperty("starttime")&&(a.timesortfrom=a.starttime,delete a.starttime),a.hasOwnProperty("endtime")&&(a.timesortto=a.endtime,delete a.endtime);var e={methodname:"core_calendar_get_action_events_by_course",args:a},f=b.call([e])[0];return f.fail(c.exception),f},f=function(a){a.hasOwnProperty("limit")||(a.limit=10),a.limitnum=a.limit,delete a.limit,a.hasOwnProperty("starttime")&&(a.timesortfrom=a.starttime,delete a.starttime),a.hasOwnProperty("endtime")&&(a.timesortto=a.endtime,delete a.endtime);var d={methodname:"core_calendar_get_action_events_by_courses",args:a},e=b.call([d])[0];return e.fail(c.exception),e},g=function(a){a.hasOwnProperty("limit")||(a.limit=d),a.limitnum=a.limit,delete a.limit,a.hasOwnProperty("starttime")&&(a.timesortfrom=a.starttime,delete a.starttime),a.hasOwnProperty("endtime")&&(a.timesortto=a.endtime,delete a.endtime);var e={methodname:"core_calendar_get_action_events_by_timesort",args:a},f=b.call([e])[0];return f.fail(c.exception),f};return{queryByTime:g,queryByCourse:e,queryByCourses:f}});
define(["jquery","core/ajax","core/notification"],function(a,b,c){var d=20,e=function(a){a.hasOwnProperty("limit")||(a.limit=d),a.limitnum=a.limit,delete a.limit,a.hasOwnProperty("starttime")&&(a.timesortfrom=a.starttime,delete a.starttime),a.hasOwnProperty("endtime")&&(a.timesortto=a.endtime,delete a.endtime);var e={methodname:"core_calendar_get_action_events_by_course",args:a},f=b.call([e])[0];return f.fail(c.exception),f},f=function(a){a.hasOwnProperty("limit")||(a.limit=10),a.limitnum=a.limit,delete a.limit,a.hasOwnProperty("starttime")&&(a.timesortfrom=a.starttime,delete a.starttime),a.hasOwnProperty("endtime")&&(a.timesortto=a.endtime,delete a.endtime);var d={methodname:"core_calendar_get_action_events_by_courses",args:a},e=b.call([d])[0];return e.fail(c.exception),e},g=function(a){a.hasOwnProperty("limit")||(a.limit=d),a.limitnum=a.limit,delete a.limit,a.hasOwnProperty("starttime")&&(a.timesortfrom=a.starttime,delete a.starttime),a.hasOwnProperty("endtime")&&(a.timesortto=a.endtime,delete a.endtime),a.limittononsuspendedevents=!0;var e={methodname:"core_calendar_get_action_events_by_timesort",args:a},f=b.call([e])[0];return f.fail(c.exception),f};return{queryByTime:g,queryByCourse:e,queryByCourses:f}});

View File

@ -145,6 +145,8 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notificat
args.timesortto = args.endtime;
delete args.endtime;
}
// Don't show events related to courses that the user is suspended in.
args.limittononsuspendedevents = true;
var request = {
methodname: 'core_calendar_get_action_events_by_timesort',

View File

@ -118,6 +118,7 @@ class api {
* @param int|null $timesortto The end timesort value (inclusive)
* @param int|null $aftereventid Only return events after this one
* @param int $limitnum Limit results to this amount (between 1 and 50)
* @param bool $lmittononsuspendedevents Limit course events to courses the user is active in (not suspended).
* @return array A list of action_event_interface objects
* @throws \moodle_exception
*/
@ -125,7 +126,8 @@ class api {
$timesortfrom = null,
$timesortto = null,
$aftereventid = null,
$limitnum = 20
$limitnum = 20,
$limittononsuspendedevents = false
) {
global $USER;
@ -144,7 +146,8 @@ class api {
$afterevent = $event;
}
return $vault->get_action_events_by_timesort($USER, $timesortfrom, $timesortto, $afterevent, $limitnum);
return $vault->get_action_events_by_timesort($USER, $timesortfrom, $timesortto, $afterevent, $limitnum,
$limittononsuspendedevents);
}
/**

View File

@ -197,11 +197,12 @@ class event_vault implements event_vault_interface {
$timesortfrom = null,
$timesortto = null,
event_interface $afterevent = null,
$limitnum = 20
$limitnum = 20,
$limittononsuspendedevents = false
) {
$courseids = array_map(function($course) {
return $course->id;
}, enrol_get_all_users_courses($user->id));
}, enrol_get_all_users_courses($user->id, $limittononsuspendedevents));
$groupids = array_reduce($courseids, function($carry, $courseid) use ($user) {
$groupings = groups_get_user_groups($courseid, $user->id);

View File

@ -93,6 +93,7 @@ interface event_vault_interface {
* @param int $timesortto Events with timesort until this value (inclusive)
* @param event_interface $afterevent Only return events after this one
* @param int $limitnum Return at most this number of events
* @param bool $lmittononsuspendedevents Limit course events to courses the user is active in (not suspended).
* @return event_interface
*/
public function get_action_events_by_timesort(
@ -100,7 +101,8 @@ interface event_vault_interface {
$timesortfrom,
$timesortto,
event_interface $afterevent,
$limitnum
$limitnum,
$limittononsuspendedevents
);
/**

View File

@ -404,7 +404,9 @@ class core_calendar_external extends external_api {
'timesortfrom' => new external_value(PARAM_INT, 'Time sort from', VALUE_DEFAULT, 0),
'timesortto' => new external_value(PARAM_INT, 'Time sort to', VALUE_DEFAULT, null),
'aftereventid' => new external_value(PARAM_INT, 'The last seen event id', VALUE_DEFAULT, 0),
'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 20)
'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 20),
'limittononsuspendedevents' => new external_value(PARAM_BOOL,
'Limit the events to courses the user is not suspended in', VALUE_DEFAULT, false)
)
);
}
@ -420,7 +422,7 @@ class core_calendar_external extends external_api {
* @return array
*/
public static function get_calendar_action_events_by_timesort($timesortfrom = 0, $timesortto = null,
$aftereventid = 0, $limitnum = 20) {
$aftereventid = 0, $limitnum = 20, $limittononsuspendedevents = false) {
global $CFG, $PAGE, $USER;
require_once($CFG->dirroot . '/calendar/lib.php');
@ -433,6 +435,7 @@ class core_calendar_external extends external_api {
'timesortto' => $timesortto,
'aftereventid' => $aftereventid,
'limitnum' => $limitnum,
'limittononsuspendedevents' => $limittononsuspendedevents
]
);
$context = \context_user::instance($USER->id);
@ -447,7 +450,8 @@ class core_calendar_external extends external_api {
$params['timesortfrom'],
$params['timesortto'],
$params['aftereventid'],
$params['limitnum']
$params['limitnum'],
$params['limittononsuspendedevents']
);
$exportercache = new events_related_objects_cache($events);