MDL-80392 completion: Fix exporter for Web Services

This commit is contained in:
Juan Leyva 2023-12-20 17:01:12 +01:00
parent 3fc907e3d8
commit 408d7c0c9c
5 changed files with 24 additions and 3 deletions

View File

@ -349,7 +349,9 @@ class core_completion_external extends external_api {
VALUE_DEFAULT,
[]
),
'isoverallcomplete' => new external_value(PARAM_BOOL,
'Whether the overall completion state of this course module should be marked as complete or not.',
VALUE_OPTIONAL),
], 'Activity'
), 'List of activities status'
),

View File

@ -83,9 +83,9 @@ class completion_info_exporter extends \core\external\exporter {
'hascompletion' => $cmcompletion->has_completion(),
'isautomatic' => $cmcompletion->is_automatic(),
'istrackeduser' => $cmcompletion->is_tracked_user(),
'overallstatus' => $cmcompletion->get_overall_completion(),
'uservisible' => $this->cminfo->uservisible,
'details' => $details,
'isoverallcomplete' => $cmcompletion->is_overall_complete(),
];
}
@ -148,6 +148,11 @@ class completion_info_exporter extends \core\external\exporter {
]
]
],
'isoverallcomplete' => [
'type' => PARAM_BOOL,
'description' => 'Whether the overall completion state of this course module should be marked as complete or not.',
'optional' => true,
],
];
}
}

View File

@ -34,6 +34,7 @@ require_once($CFG->dirroot . '/webservice/tests/helpers.php');
* @copyright 2015 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.9
* @coversDefaultClass \core_completion_external
*/
class externallib_test extends externallib_advanced_testcase {
@ -177,6 +178,7 @@ class externallib_test extends externallib_advanced_testcase {
$this->assertTrue($status['uservisible']);
$details = $status['details'];
$this->assertCount(0, $details);
$this->assertTrue($status['isoverallcomplete']);
} else if ($status['cmid'] == $forumautocompletion->cmid) {
$activitiesfound++;
$this->assertEquals(COMPLETION_INCOMPLETE, $status['state']);
@ -190,7 +192,7 @@ class externallib_test extends externallib_advanced_testcase {
$this->assertCount(1, $details);
$this->assertEquals('completionview', $details[0]['rulename']);
$this->assertEquals(0, $details[0]['rulevalue']['status']);
$this->assertFalse($status['isoverallcomplete']);
} else if ($status['cmid'] == $assignautocompletion->cmid) {
$activitiesfound++;
$this->assertEquals(COMPLETION_INCOMPLETE, $status['state']);
@ -200,6 +202,7 @@ class externallib_test extends externallib_advanced_testcase {
$this->assertTrue($status['isautomatic']);
$this->assertTrue($status['istrackeduser']);
$this->assertTrue($status['uservisible']);
$this->assertFalse($status['isoverallcomplete']);
$details = $status['details'];
$this->assertCount(3, $details);
$expecteddetails = [
@ -223,6 +226,7 @@ class externallib_test extends externallib_advanced_testcase {
$this->assertTrue($status['uservisible']);
$details = $status['details'];
$this->assertCount(0, $details);
$this->assertFalse($status['isoverallcomplete']);
}
}
$this->assertEquals(4, $activitiesfound);
@ -250,6 +254,7 @@ class externallib_test extends externallib_advanced_testcase {
$this->assertEquals(COMPLETION_INCOMPLETE, $status['state']);
$this->assertEquals(COMPLETION_TRACKING_MANUAL, $status['tracking']);
$this->assertEquals($teacher->id, $status['overrideby']);
$this->assertFalse($status['isoverallcomplete']);
break;
}
}
@ -273,14 +278,17 @@ class externallib_test extends externallib_advanced_testcase {
$activitiesfound++;
$this->assertEquals(COMPLETION_COMPLETE, $status['state']);
$this->assertEquals(COMPLETION_TRACKING_MANUAL, $status['tracking']);
$this->assertTrue($status['isoverallcomplete']);
} else if (in_array($status['cmid'], [$forumautocompletion->cmid, $assignautocompletion->cmid])) {
$activitiesfound++;
$this->assertEquals(COMPLETION_INCOMPLETE, $status['state']);
$this->assertEquals(COMPLETION_TRACKING_AUTOMATIC, $status['tracking']);
$this->assertFalse($status['isoverallcomplete']);
} else {
$activitiesfound++;
$this->assertEquals(COMPLETION_INCOMPLETE, $status['state']);
$this->assertEquals(COMPLETION_TRACKING_MANUAL, $status['tracking']);
$this->assertFalse($status['isoverallcomplete']);
}
}
$this->assertEquals(5, $activitiesfound);

View File

@ -10,6 +10,8 @@ information provided here is intended especially for developers.
* The following previously deprecated methods have been removed and can no longer be used:
- `completion_info::display_help_icon`
- `completion_info::print_help_icon`
* The \core_completion\completion_info_exporter class has been updated to return a new field "isverallcomplete" to return the result of the
new cm_completion_details::is_overall_complete() method.
=== 4.3 ===
* A trait class, core_completion/form/form_trait has been added to reuse code for adding and validation completion settings to any

View File

@ -1514,6 +1514,7 @@ class externallib_test extends externallib_advanced_testcase {
$this->assertFalse($completiondata['isautomatic']);
$this->assertFalse($completiondata['istrackeduser']);
$this->assertTrue($completiondata['uservisible']);
$this->assertFalse($completiondata['isoverallcomplete']);
// Set activity completed.
core_completion_external::update_activity_completion_status_manually($forumcm->id, true);
@ -1524,6 +1525,7 @@ class externallib_test extends externallib_advanced_testcase {
$result = external_api::clean_returnvalue(core_course_external::get_course_contents_returns(), $result);
$this->assertEquals(COMPLETION_COMPLETE, $result[0]['modules'][0]["completiondata"]['state']);
$this->assertTrue($result[0]['modules'][0]["completiondata"]['isoverallcomplete']);
$this->assertNotEmpty($result[0]['modules'][0]["completiondata"]['timecompleted']);
$this->assertEmpty($result[0]['modules'][0]["completiondata"]['overrideby']);
@ -1545,6 +1547,7 @@ class externallib_test extends externallib_advanced_testcase {
$this->assertFalse($completiondata['isautomatic']);
$this->assertFalse($completiondata['istrackeduser']);
$this->assertTrue($completiondata['uservisible']);
$this->assertFalse($completiondata['isoverallcomplete']);
// Disable completion.
$CFG->enablecompletion = 0;
@ -1595,6 +1598,7 @@ class externallib_test extends externallib_advanced_testcase {
$this->assertFalse($completiondata['istrackeduser']);
$this->assertTrue($completiondata['uservisible']);
$this->assertCount(1, $completiondata['details']);
$this->assertFalse($completiondata['isoverallcomplete']);
}
/**