mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 11:46:19 +01:00
MDL-82775 mod_h5pactivity: Return total attempts in get_user_attempts
This commit is contained in:
parent
ecfcf00d92
commit
965932fdcb
7
.upgradenotes/MDL-82775-2024082908150378.yml
Normal file
7
.upgradenotes/MDL-82775-2024082908150378.yml
Normal 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
|
@ -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');
|
||||
}
|
||||
|
@ -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']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user