Commit dfcf8342 authored by Juan Leyva's avatar Juan Leyva
Browse files

MDL-65211 enrol: Return if user is being completion tracked

parent 0920f35e
...@@ -366,6 +366,7 @@ class core_enrol_external extends external_api { ...@@ -366,6 +366,7 @@ class core_enrol_external extends external_api {
$progress = null; $progress = null;
$completed = null; $completed = null;
$completionhascriteria = false; $completionhascriteria = false;
$completionusertracked = false;
// Return only private information if the user should be able to see it. // Return only private information if the user should be able to see it.
if ($sameuser || completion_can_view_data($userid, $course)) { if ($sameuser || completion_can_view_data($userid, $course)) {
...@@ -373,6 +374,7 @@ class core_enrol_external extends external_api { ...@@ -373,6 +374,7 @@ class core_enrol_external extends external_api {
$completion = new completion_info($course); $completion = new completion_info($course);
$completed = $completion->is_course_complete($userid); $completed = $completion->is_course_complete($userid);
$completionhascriteria = $completion->has_criteria(); $completionhascriteria = $completion->has_criteria();
$completionusertracked = $completion->is_tracked_user($userid);
$progress = \core_completion\progress::get_course_progress_percentage($course, $userid); $progress = \core_completion\progress::get_course_progress_percentage($course, $userid);
} }
} }
...@@ -425,6 +427,7 @@ class core_enrol_external extends external_api { ...@@ -425,6 +427,7 @@ class core_enrol_external extends external_api {
'lang' => clean_param($course->lang, PARAM_LANG), 'lang' => clean_param($course->lang, PARAM_LANG),
'enablecompletion' => $course->enablecompletion, 'enablecompletion' => $course->enablecompletion,
'completionhascriteria' => $completionhascriteria, 'completionhascriteria' => $completionhascriteria,
'completionusertracked' => $completionusertracked,
'category' => $course->category, 'category' => $course->category,
'progress' => $progress, 'progress' => $progress,
'completed' => $completed, 'completed' => $completed,
...@@ -470,6 +473,7 @@ class core_enrol_external extends external_api { ...@@ -470,6 +473,7 @@ class core_enrol_external extends external_api {
'enablecompletion' => new external_value(PARAM_BOOL, 'true if completion is enabled, otherwise false', 'enablecompletion' => new external_value(PARAM_BOOL, 'true if completion is enabled, otherwise false',
VALUE_OPTIONAL), VALUE_OPTIONAL),
'completionhascriteria' => new external_value(PARAM_BOOL, 'If completion criteria is set.', VALUE_OPTIONAL), 'completionhascriteria' => new external_value(PARAM_BOOL, 'If completion criteria is set.', VALUE_OPTIONAL),
'completionusertracked' => new external_value(PARAM_BOOL, 'If the user is completion tracked.', VALUE_OPTIONAL),
'category' => new external_value(PARAM_INT, 'course category id', VALUE_OPTIONAL), 'category' => new external_value(PARAM_INT, 'course category id', VALUE_OPTIONAL),
'progress' => new external_value(PARAM_FLOAT, 'Progress percentage', VALUE_OPTIONAL), 'progress' => new external_value(PARAM_FLOAT, 'Progress percentage', VALUE_OPTIONAL),
'completed' => new external_value(PARAM_BOOL, 'Whether the course is completed.', VALUE_OPTIONAL), 'completed' => new external_value(PARAM_BOOL, 'Whether the course is completed.', VALUE_OPTIONAL),
......
...@@ -453,6 +453,7 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase { ...@@ -453,6 +453,7 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase {
$this->assertEquals(100.0, $courseenrol['progress']); $this->assertEquals(100.0, $courseenrol['progress']);
$this->assertEquals(true, $courseenrol['completed']); $this->assertEquals(true, $courseenrol['completed']);
$this->assertTrue($courseenrol['completionhascriteria']); $this->assertTrue($courseenrol['completionhascriteria']);
$this->assertTrue($courseenrol['completionusertracked']);
$this->assertTrue($courseenrol['hidden']); $this->assertTrue($courseenrol['hidden']);
$this->assertTrue($courseenrol['isfavourite']); $this->assertTrue($courseenrol['isfavourite']);
$this->assertEquals(2, $courseenrol['enrolledusercount']); $this->assertEquals(2, $courseenrol['enrolledusercount']);
...@@ -465,6 +466,7 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase { ...@@ -465,6 +466,7 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase {
$this->assertEquals(0, $courseenrol['progress']); $this->assertEquals(0, $courseenrol['progress']);
$this->assertEquals(false, $courseenrol['completed']); $this->assertEquals(false, $courseenrol['completed']);
$this->assertFalse($courseenrol['completionhascriteria']); $this->assertFalse($courseenrol['completionhascriteria']);
$this->assertFalse($courseenrol['completionusertracked']);
$this->assertFalse($courseenrol['hidden']); $this->assertFalse($courseenrol['hidden']);
$this->assertFalse($courseenrol['isfavourite']); $this->assertFalse($courseenrol['isfavourite']);
$this->assertEquals(1, $courseenrol['enrolledusercount']); $this->assertEquals(1, $courseenrol['enrolledusercount']);
...@@ -489,11 +491,13 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase { ...@@ -489,11 +491,13 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase {
$this->assertEquals($timenow, $courseenrol['lastaccess']); $this->assertEquals($timenow, $courseenrol['lastaccess']);
$this->assertEquals(100.0, $courseenrol['progress']); $this->assertEquals(100.0, $courseenrol['progress']);
$this->assertTrue($courseenrol['completionhascriteria']); $this->assertTrue($courseenrol['completionhascriteria']);
$this->assertTrue($courseenrol['completionusertracked']);
$this->assertFalse($courseenrol['isfavourite']); // This always false. $this->assertFalse($courseenrol['isfavourite']); // This always false.
$this->assertFalse($courseenrol['hidden']); // This always false. $this->assertFalse($courseenrol['hidden']); // This always false.
} else { } else {
$this->assertEquals(0, $courseenrol['progress']); $this->assertEquals(0, $courseenrol['progress']);
$this->assertFalse($courseenrol['completionhascriteria']); $this->assertFalse($courseenrol['completionhascriteria']);
$this->assertFalse($courseenrol['completionusertracked']);
$this->assertFalse($courseenrol['isfavourite']); // This always false. $this->assertFalse($courseenrol['isfavourite']); // This always false.
$this->assertFalse($courseenrol['hidden']); // This always false. $this->assertFalse($courseenrol['hidden']); // This always false.
} }
......
...@@ -9,6 +9,8 @@ information provided here is intended especially for developers. ...@@ -9,6 +9,8 @@ information provided here is intended especially for developers.
- totalusers: Number users matching the search. (This element only exists if the function is called with $returnexactcount param set to true). - totalusers: Number users matching the search. (This element only exists if the function is called with $returnexactcount param set to true).
* enrolledusercount is now optional in the return value of get_users_courses() for performance reasons. This is controlled with the new * enrolledusercount is now optional in the return value of get_users_courses() for performance reasons. This is controlled with the new
optional returnusercount parameter (default true). optional returnusercount parameter (default true).
* External function core_enrol_external::get_users_courses now returns a new field "completionusertracked" that indicates if the
given user is being tracked for completion.
=== 3.6 === === 3.6 ===
......
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