Commit 879a8f56 authored by Juan Leyva's avatar Juan Leyva
Browse files

MDL-57395 course: New Web Service core_course_get_updates_since

parent c4cf1c60
......@@ -3153,4 +3153,78 @@ class core_course_external extends external_api {
)
);
}
/**
* Returns description of method parameters
*
* @return external_function_parameters
* @since Moodle 3.3
*/
public static function get_updates_since_parameters() {
return new external_function_parameters(
array(
'courseid' => new external_value(PARAM_INT, 'Course id to check'),
'since' => new external_value(PARAM_INT, 'Check updates since this time stamp'),
'filter' => new external_multiple_structure(
new external_value(PARAM_ALPHANUM, 'Area name: configuration, fileareas, completion, ratings, comments,
gradeitems, outcomes'),
'Check only for updates in these areas', VALUE_DEFAULT, array()
)
)
);
}
/**
* Check if there are updates affecting the user for the given course since the given time stamp.
*
* This function is a wrapper of self::check_updates for retrieving all the updates since a given time for all the activities.
*
* @param int $courseid the list of modules to check
* @param int $since check updates since this time stamp
* @param array $filter check only for updates in these areas
* @return array list of updates and warnings
* @throws moodle_exception
* @since Moodle 3.3
*/
public static function get_updates_since($courseid, $since, $filter = array()) {
global $CFG, $DB;
$params = self::validate_parameters(
self::get_updates_since_parameters(),
array(
'courseid' => $courseid,
'since' => $since,
'filter' => $filter,
)
);
$course = get_course($params['courseid']);
$modinfo = get_fast_modinfo($course);
$tocheck = array();
// Retrieve all the visible course modules for the current user.
$cms = $modinfo->get_cms();
foreach ($cms as $cm) {
if (!$cm->uservisible) {
continue;
}
$tocheck[] = array(
'id' => $cm->id,
'contextlevel' => 'module',
'since' => $params['since'],
);
}
return self::check_updates($course->id, $tocheck, $params['filter']);
}
/**
* Returns description of method result value
*
* @return external_description
* @since Moodle 3.3
*/
public static function get_updates_since_returns() {
return self::check_updates_returns();
}
}
......@@ -2139,6 +2139,12 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$this->assertCount(0, $result['instances']);
$this->assertCount(0, $result['warnings']);
// Test with get_updates_since the same data.
$result = core_course_external::get_updates_since($course->id, $since);
$result = external_api::clean_returnvalue(core_course_external::get_updates_since_returns(), $result);
$this->assertCount(0, $result['instances']);
$this->assertCount(0, $result['warnings']);
// Update a module after a second.
$this->waitForSecond();
set_coursemodule_name($modules['forum']['cm']->id, 'New forum name');
......@@ -2157,6 +2163,23 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
}
$this->assertTrue($found);
// Test with get_updates_since the same data.
$result = core_course_external::get_updates_since($course->id, $since);
$result = external_api::clean_returnvalue(core_course_external::get_updates_since_returns(), $result);
$this->assertCount(1, $result['instances']);
$this->assertCount(0, $result['warnings']);
$found = false;
$this->assertCount(1, $result['instances']);
$this->assertCount(0, $result['warnings']);
foreach ($result['instances'] as $module) {
foreach ($module['updates'] as $update) {
if ($module['id'] == $modules['forum']['cm']->id and $update['name'] == 'configuration') {
$found = true;
}
}
}
$this->assertTrue($found);
// Do not retrieve the configuration field.
$filter = array('files');
$found = false;
......
......@@ -344,6 +344,15 @@ $functions = array(
'ajax' => true,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
),
'core_course_get_updates_since' => array(
'classname' => 'core_course_external',
'methodname' => 'get_updates_since',
'classpath' => 'course/externallib.php',
'description' => 'Check if there are updates affecting the user for the given course since the given time stamp.',
'type' => 'read',
'ajax' => true,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
),
'core_enrol_get_course_enrolment_methods' => array(
'classname' => 'core_enrol_external',
'methodname' => 'get_course_enrolment_methods',
......
......@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2016122200.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2016122200.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
......
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