Skip to content

Commit

Permalink
MDL-82775 mod_h5pactivity: Return total attempts in get_user_attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
dpalou committed Oct 22, 2024
1 parent ecfcf00 commit 965932f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .upgradenotes/MDL-82775-2024082908150378.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions mod/h5pactivity/classes/external/get_user_attempts.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public static function execute(int $h5pactivityid, $sortorder = 'id ASC', ?int $
$result = (object)[
'activityid' => $instance->id,
'usersattempts' => $usersattempts,
'totalattempts' => $manager->count_attempts(),
'warnings' => $warnings,
];

Expand Down Expand Up @@ -255,6 +256,7 @@ public static function execute_returns(): external_single_structure {
'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');
}
Expand Down
3 changes: 3 additions & 0 deletions mod/h5pactivity/tests/external/get_user_attempts_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ public function test_execute_multipleusers(string $loginuser, array $participant
$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;
} else {
$params = ['cmid' => $cm->id, 'userid' => $user->id];
for ($i = 1; $i <= $attemptcount; $i++) {
$generator->create_content($activity, $params);
$totalattempts++;
}
$countattempts[$user->id] = $attemptcount;
$attemptcount++;
Expand All @@ -107,6 +109,7 @@ public function test_execute_multipleusers(string $loginuser, array $participant
$result
);

$this->assertEquals($totalattempts, $result['totalattempts']);
$this->assertCount(count($warnings), $result['warnings']);
// Teacher is excluded.
$this->assertCount(count($resultusers), $result['usersattempts']);
Expand Down

0 comments on commit 965932f

Please sign in to comment.