Merge branch 'MDL-57395-master' of git://github.com/jleyva/moodle

This commit is contained in:
Dan Poltawski 2017-01-02 11:46:44 +00:00
commit 6dbe175454
4 changed files with 107 additions and 1 deletions

View File

@ -3147,4 +3147,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();
}
}

View File

@ -2150,6 +2150,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');
@ -2168,6 +2174,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;

View File

@ -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',

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2016122800.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2017010200.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.