From 965932fdcb60779c19d8a434bc50bd03ea9749f3 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 29 Aug 2024 10:12:15 +0200 Subject: [PATCH] MDL-82775 mod_h5pactivity: Return total attempts in get_user_attempts --- .upgradenotes/MDL-82775-2024082908150378.yml | 7 +++++++ mod/h5pactivity/classes/external/get_user_attempts.php | 2 ++ mod/h5pactivity/tests/external/get_user_attempts_test.php | 3 +++ 3 files changed, 12 insertions(+) create mode 100644 .upgradenotes/MDL-82775-2024082908150378.yml diff --git a/.upgradenotes/MDL-82775-2024082908150378.yml b/.upgradenotes/MDL-82775-2024082908150378.yml new file mode 100644 index 0000000000000..a40950f86651e --- /dev/null +++ b/.upgradenotes/MDL-82775-2024082908150378.yml @@ -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 diff --git a/mod/h5pactivity/classes/external/get_user_attempts.php b/mod/h5pactivity/classes/external/get_user_attempts.php index e10163af3ac8e..bd5fe29b9ab0a 100644 --- a/mod/h5pactivity/classes/external/get_user_attempts.php +++ b/mod/h5pactivity/classes/external/get_user_attempts.php @@ -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, ]; @@ -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'); } diff --git a/mod/h5pactivity/tests/external/get_user_attempts_test.php b/mod/h5pactivity/tests/external/get_user_attempts_test.php index 2f0a344d7cb69..985f89b48eb16 100644 --- a/mod/h5pactivity/tests/external/get_user_attempts_test.php +++ b/mod/h5pactivity/tests/external/get_user_attempts_test.php @@ -80,6 +80,7 @@ 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; @@ -87,6 +88,7 @@ public function test_execute_multipleusers(string $loginuser, array $participant $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 @@ 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']);