MDL-82775 mod_h5pactivity: Return total attempts in get_user_attempts

This commit is contained in:
Dani Palou 2024-08-29 10:12:15 +02:00
parent ecfcf00d92
commit 965932fdcb
3 changed files with 12 additions and 0 deletions

View File

@ -0,0 +1,7 @@
issueNumber: MDL-82775
notes:
mod_h5pactivity:
- message: >-
The external function get_user_attempts now returns the total number of
attempts.
type: changed

View File

@ -149,6 +149,7 @@ class get_user_attempts extends external_api {
$result = (object)[
'activityid' => $instance->id,
'usersattempts' => $usersattempts,
'totalattempts' => $manager->count_attempts(),
'warnings' => $warnings,
];
@ -255,6 +256,7 @@ class get_user_attempts extends external_api {
'usersattempts' => new external_multiple_structure(
self::get_user_attempts_returns(), 'The complete users attempts list'
),
'totalattempts' => new external_value(PARAM_INT, 'Total number of attempts'),
'warnings' => new external_warnings(),
], 'Activity attempts data');
}

View File

@ -80,6 +80,7 @@ class get_user_attempts_test extends externallib_advanced_testcase {
$generator = $this->getDataGenerator()->get_plugin_generator('mod_h5pactivity');
$attemptcount = 1;
$totalattempts = 0;
foreach ($users as $key => $user) {
if (($key == 'noattempts') || ($key == 'noenrolled') || ($key == 'editingteacher')) {
$countattempts[$user->id] = 0;
@ -87,6 +88,7 @@ class get_user_attempts_test extends externallib_advanced_testcase {
$params = ['cmid' => $cm->id, 'userid' => $user->id];
for ($i = 1; $i <= $attemptcount; $i++) {
$generator->create_content($activity, $params);
$totalattempts++;
}
$countattempts[$user->id] = $attemptcount;
$attemptcount++;
@ -107,6 +109,7 @@ class get_user_attempts_test extends externallib_advanced_testcase {
$result
);
$this->assertEquals($totalattempts, $result['totalattempts']);
$this->assertCount(count($warnings), $result['warnings']);
// Teacher is excluded.
$this->assertCount(count($resultusers), $result['usersattempts']);