mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-73040 timeline: Update core_calendar_get_action_events_by_course API
This API now accepts an optional parameter 'searchvalue' to search the events
This commit is contained in:
parent
d135a1200a
commit
7d3d855193
@ -498,7 +498,8 @@ class core_calendar_external extends external_api {
|
||||
'timesortfrom' => new external_value(PARAM_INT, 'Time sort from', VALUE_DEFAULT, null),
|
||||
'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),
|
||||
'searchvalue' => new external_value(PARAM_TEXT, 'The value a user wishes to search against', VALUE_DEFAULT, null)
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -512,10 +513,11 @@ class core_calendar_external extends external_api {
|
||||
* @param null|int $timesortto Events before this time (inclusive)
|
||||
* @param null|int $aftereventid Get events with ids greater than this one
|
||||
* @param int $limitnum Limit the number of results to this value
|
||||
* @param string|null $searchvalue The value a user wishes to search against
|
||||
* @return array
|
||||
*/
|
||||
public static function get_calendar_action_events_by_course(
|
||||
$courseid, $timesortfrom = null, $timesortto = null, $aftereventid = 0, $limitnum = 20) {
|
||||
$courseid, $timesortfrom = null, $timesortto = null, $aftereventid = 0, $limitnum = 20, ?string $searchvalue = null) {
|
||||
|
||||
global $PAGE, $USER;
|
||||
|
||||
@ -528,6 +530,7 @@ class core_calendar_external extends external_api {
|
||||
'timesortto' => $timesortto,
|
||||
'aftereventid' => $aftereventid,
|
||||
'limitnum' => $limitnum,
|
||||
'searchvalue' => $searchvalue
|
||||
]
|
||||
);
|
||||
$context = \context_user::instance($USER->id);
|
||||
@ -551,7 +554,8 @@ class core_calendar_external extends external_api {
|
||||
$params['timesortfrom'],
|
||||
$params['timesortto'],
|
||||
$params['aftereventid'],
|
||||
$params['limitnum']
|
||||
$params['limitnum'],
|
||||
$params['searchvalue']
|
||||
);
|
||||
|
||||
$exportercache = new events_related_objects_cache($events, $courses);
|
||||
|
@ -1352,6 +1352,71 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_calendar_action_events_by_course with search feature
|
||||
*/
|
||||
public function test_get_calendar_action_events_by_course_with_search() {
|
||||
// Generate data.
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
|
||||
$instance = $generator->create_instance(['course' => $course->id]);
|
||||
|
||||
// Enrol.
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id);
|
||||
$this->resetAfterTest(true);
|
||||
$this->setUser($user);
|
||||
|
||||
for ($i = 1; $i < 5; $i++) {
|
||||
$this->create_calendar_event(
|
||||
sprintf('Event %d', $i),
|
||||
$user->id,
|
||||
'user',
|
||||
0,
|
||||
1,
|
||||
[
|
||||
'type' => CALENDAR_EVENT_TYPE_ACTION,
|
||||
'courseid' => $course->id,
|
||||
'timesort' => $i,
|
||||
'modulename' => 'assign',
|
||||
'instance' => $instance->id,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// No result found for fake search.
|
||||
$result = core_calendar_external::get_calendar_action_events_by_course($course->id, null, null, 0, 20, 'Fake search');
|
||||
$result = external_api::clean_returnvalue(
|
||||
core_calendar_external::get_calendar_action_events_by_course_returns(),
|
||||
$result
|
||||
);
|
||||
$result = $result['events'];
|
||||
$this->assertEmpty($result);
|
||||
|
||||
// Search for event name called 'Event 1'.
|
||||
$result = core_calendar_external::get_calendar_action_events_by_course($course->id, null, null, 0, 20, 'Event 1');
|
||||
$result = external_api::clean_returnvalue(
|
||||
core_calendar_external::get_calendar_action_events_by_course_returns(),
|
||||
$result
|
||||
);
|
||||
$result = $result['events'];
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals('Event 1', $result[0]['name']);
|
||||
|
||||
// Search for activity type called 'assign'.
|
||||
$result = core_calendar_external::get_calendar_action_events_by_course($course->id, null, null, 0, 20, 'assign');
|
||||
$result = external_api::clean_returnvalue(
|
||||
core_calendar_external::get_calendar_action_events_by_course_returns(),
|
||||
$result
|
||||
);
|
||||
$result = $result['events'];
|
||||
$this->assertCount(4, $result);
|
||||
$this->assertEquals('Event 1', $result[0]['name']);
|
||||
$this->assertEquals('Event 2', $result[1]['name']);
|
||||
$this->assertEquals('Event 3', $result[2]['name']);
|
||||
$this->assertEquals('Event 4', $result[3]['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that get_action_events_by_courses will return a list of events for each
|
||||
* course you provided as long as the user is enrolled in the course.
|
||||
|
@ -5,6 +5,7 @@ information provided here is intended especially for developers.
|
||||
* The following external functions now accepts an optional parameter 'searchvalue' to search the events:
|
||||
- core_calendar_external::get_calendar_action_events_by_timesort
|
||||
- core_calendar_external::get_calendar_action_events_by_courses
|
||||
- core_calendar_external::get_calendar_action_events_by_course
|
||||
* Added core_calendar_delete_subscription, which allows to delete the calendar subscription.
|
||||
* The following functions have been deprecated because they were no longer used:
|
||||
- calendar_process_subscription_row()
|
||||
|
Loading…
x
Reference in New Issue
Block a user