mirror of
https://github.com/moodle/moodle.git
synced 2025-04-09 02:12:22 +02:00
Merge branch 'MDL-64063-master' of git://github.com/abgreeve/moodle
This commit is contained in:
commit
819cb2054b
@ -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}});
|
@ -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',
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -557,6 +557,37 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
|
||||
$this->assertEquals('Assignment 1 due date', $usersevents['For user in no groups'][0]->get_name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that if a user is suspended that events related to that course are not shown.
|
||||
* User 1 is suspended. User 2 is active.
|
||||
*/
|
||||
public function test_get_action_events_by_timesort_with_suspended_user() {
|
||||
$this->resetAfterTest();
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$this->setAdminuser();
|
||||
$lesson = $this->getDataGenerator()->create_module('lesson', [
|
||||
'name' => 'Lesson 1',
|
||||
'course' => $course->id,
|
||||
'available' => time(),
|
||||
'deadline' => (time() + (60 * 60 * 24 * 5))
|
||||
]
|
||||
);
|
||||
$this->getDataGenerator()->enrol_user($user1->id, $course->id, null, 'manual', 0, 0, ENROL_USER_SUSPENDED);
|
||||
$this->getDataGenerator()->enrol_user($user2->id, $course->id);
|
||||
|
||||
$factory = new action_event_test_factory();
|
||||
$strategy = new raw_event_retrieval_strategy();
|
||||
$vault = new event_vault($factory, $strategy);
|
||||
|
||||
$user1events = $vault->get_action_events_by_timesort($user1, null, null, null, 20, true);
|
||||
$this->assertEmpty($user1events);
|
||||
$user2events = $vault->get_action_events_by_timesort($user2, null, null, null, 20, true);
|
||||
$this->assertCount(1, $user2events);
|
||||
$this->assertEquals('Lesson 1 closes', $user2events[0]->get_name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that get_action_events_by_course returns events after the
|
||||
* provided timesort value.
|
||||
|
@ -937,6 +937,34 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->assertNull($result['lastid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that it is possible to restrict the calendar events to events where the user is not suspended in the course.
|
||||
*/
|
||||
public function test_get_calendar_action_events_by_timesort_suspended_course() {
|
||||
$this->resetAfterTest();
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$this->setAdminUser();
|
||||
$lesson = $this->getDataGenerator()->create_module('lesson', [
|
||||
'name' => 'Lesson 1',
|
||||
'course' => $course->id,
|
||||
'available' => time(),
|
||||
'deadline' => (time() + (60 * 60 * 24 * 5))
|
||||
]
|
||||
);
|
||||
$this->getDataGenerator()->enrol_user($user1->id, $course->id, null, 'manual', 0, 0, ENROL_USER_SUSPENDED);
|
||||
$this->getDataGenerator()->enrol_user($user2->id, $course->id);
|
||||
|
||||
$this->setUser($user1);
|
||||
$result = core_calendar_external::get_calendar_action_events_by_timesort(0, null, 0, 20, true);
|
||||
$this->assertEmpty($result->events);
|
||||
$this->setUser($user2);
|
||||
$result = core_calendar_external::get_calendar_action_events_by_timesort(0, null, 0, 20, true);
|
||||
$this->assertCount(1, $result->events);
|
||||
$this->assertEquals('Lesson 1 closes', $result->events[0]->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requesting calendar events from a given course and time should return all
|
||||
* events with a sort time at or after the requested time. All events prior
|
||||
|
Loading…
x
Reference in New Issue
Block a user