From 6c97428ab4608d809f6e324b3c830bb56cc9b14c Mon Sep 17 00:00:00 2001 From: Alex Yeung Date: Tue, 5 Dec 2023 13:31:35 +0000 Subject: [PATCH] CTP-2495 Replace quiz deprecated methods CTP-2889 Tweaks dashboard page CTP-2890 Fix external api phpunit test --- classes/external/map_assessment.php | 2 +- classes/privacy/provider.php | 40 ++++++++++++++++++++- classes/submission/quiz.php | 33 ++++++++++++++---- lang/en/local_sitsgradepush.php | 44 ++++++++++++++++++++++-- styles.css | 10 +++--- templates/assessmentgrades.mustache | 12 +++---- templates/module_delivery_table.mustache | 28 +++++++-------- templates/select_source_page.mustache | 7 ++-- 8 files changed, 135 insertions(+), 41 deletions(-) diff --git a/classes/external/map_assessment.php b/classes/external/map_assessment.php index bba13ea..6e4f633 100644 --- a/classes/external/map_assessment.php +++ b/classes/external/map_assessment.php @@ -41,7 +41,7 @@ public static function execute_parameters() { 'courseid' => new external_value(PARAM_INT, 'Coruse ID', VALUE_REQUIRED), 'coursemoduleid' => new external_value(PARAM_INT, 'Course Module ID', VALUE_REQUIRED), 'mabid' => new external_value(PARAM_INT, 'Assessment Component ID', VALUE_REQUIRED), - 'partid' => new external_value(PARAM_INT, 'Assessment Part ID', VALUE_OPTIONAL), + 'partid' => new external_value(PARAM_INT, 'Assessment Part ID', VALUE_DEFAULT, null), ]); } diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 7b28eef..ceb6055 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -16,6 +16,8 @@ namespace local_sitsgradepush\privacy; +use core_privacy\local\metadata\collection; + /** * Data provider class. * @@ -24,7 +26,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @author Alex Yeung */ -class provider implements \core_privacy\local\metadata\null_provider { +class provider implements + \core_privacy\local\metadata\null_provider, + \core_privacy\local\metadata\provider { /** * Get the language string identifier with the component's language @@ -35,4 +39,38 @@ class provider implements \core_privacy\local\metadata\null_provider { public static function get_reason() : string { return 'privacy:metadata'; } + + /** + * Returns metadata about this plugin. + * + * @param collection $collection The initialised collection to add items to. + * @return collection A listing of user data stored through this system. + */ + public static function get_metadata(collection $collection) : collection { + $collection->add_database_table('local_sitsgradepush_tfr_log', [ + 'type' => 'privacy:metadata:local_sitsgradepush_tfr_log:type', + 'userid' => 'privacy:metadata:local_sitsgradepush_tfr_log:userid', + 'request' => 'privacy:metadata:local_sitsgradepush_tfr_log:request', + 'requestbody' => 'privacy:metadata:local_sitsgradepush_tfr_log:requestbody', + 'response' => 'privacy:metadata:local_sitsgradepush_tfr_log:response', + 'usermodified' => 'privacy:metadata:local_sitsgradepush_tfr_log:usermodified', + ], 'privacy:metadata:local_sitsgradepush_tfr_log'); + + $collection->add_database_table('local_sitsgradepush_err_log', [ + 'message' => 'privacy:metadata:local_sitsgradepush_err_log:message', + 'errortype' => 'privacy:metadata:local_sitsgradepush_err_log:errortype', + 'requesturl' => 'privacy:metadata:local_sitsgradepush_err_log:requesturl', + 'data' => 'privacy:metadata:local_sitsgradepush_err_log:data', + 'response' => 'privacy:metadata:local_sitsgradepush_err_log:response', + 'userid' => 'privacy:metadata:local_sitsgradepush_err_log:userid', + ], 'privacy:metadata:local_sitsgradepush_err_log'); + + $collection->add_database_table('local_sitsgradepush_tasks', [ + 'userid' => 'privacy:metadata:local_sitsgradepush_tasks:userid', + 'status' => 'privacy:metadata:local_sitsgradepush_tasks:status', + 'info' => 'privacy:metadata:local_sitsgradepush_tasks:info', + ], 'privacy:metadata:local_sitsgradepush_tasks'); + + return $collection; + } } diff --git a/classes/submission/quiz.php b/classes/submission/quiz.php index d9d73e6..00f3556 100644 --- a/classes/submission/quiz.php +++ b/classes/submission/quiz.php @@ -78,14 +78,35 @@ private function get_best_attempt() { require_once($CFG->dirroot.'/mod/quiz/locallib.php'); // Get student's quiz attempts. - $attemps = $DB->get_records( - 'quiz_attempts', - ['quiz' => $this->modinstance->id, 'userid' => $this->userid, 'preview' => 0, 'state' => quiz_attempt::FINISHED] - ); + $attempts = quiz_get_user_attempts($this->modinstance->id, $this->userid); // Throw error if no attempt found. - if ($attemps) { - return quiz_calculate_best_attempt($this->modinstance, $attemps); + if (!empty($attempts)) { + switch ($this->modinstance->grademethod) { + // Return the first attempt. + case QUIZ_ATTEMPTFIRST: + return reset($attempts); + + // Return the last attempt. + case QUIZ_ATTEMPTLAST: + case QUIZ_GRADEAVERAGE: + return end($attempts); + + // Return the highest grade attempt. + case QUIZ_GRADEHIGHEST: + default: + $maxattempt = null; + $maxsumgrades = -1; + + foreach ($attempts as $attempt) { + if ($attempt->sumgrades > $maxsumgrades) { + $maxsumgrades = $attempt->sumgrades; + $maxattempt = $attempt; + } + } + + return $maxattempt; + } } return null; diff --git a/lang/en/local_sitsgradepush.php b/lang/en/local_sitsgradepush.php index 84a695c..17cf301 100644 --- a/lang/en/local_sitsgradepush.php +++ b/lang/en/local_sitsgradepush.php @@ -27,7 +27,6 @@ defined('MOODLE_INTERNAL') || die(); $string['pluginname'] = 'SITS Marks Transfer'; -$string['privacy:metadata'] = 'This plugin does not store any personal data.'; $string['settings:apiclientselect'] = 'Select API client'; $string['settings:apiclient'] = 'API client'; $string['settings:apiclient:desc'] = 'Choose which API client to use'; @@ -67,11 +66,29 @@ $string['pushrecordsexist'] = 'Transfer records exist'; $string['pushrecordsnotexist'] = 'No transfer records'; -// Marks Transfer index page. +// Marks transfer activity index page. $string['index:header'] = 'SITS Marks Transfer History'; +$string['index:student'] = 'Student'; +$string['index:porticonumber'] = 'Portico number'; +$string['index:grade'] = 'Grade'; +$string['index:submissiondate'] = 'Submission date'; +$string['index:lastmarktransfer'] = 'Last Mark Transfer'; +$string['index:lastsublogtransfer'] = 'Last Submission Log Transfer'; -// Marks Transfer dashboard page. +// Marks transfer dashboard page. $string['dashboard:header'] = 'SITS Marks Transfer Dashboard'; +$string['dashboard:modcode'] = 'MODULE CODE: {$a}'; +$string['dashboard:academicyear'] = 'ACADEMIC YEAR: {$a}'; +$string['dashboard:level'] = 'LEVEL: {$a}'; +$string['dashboard:mapcode'] = 'MAP CODE: {$a}'; +$string['dashboard:seq'] = 'SEQ'; +$string['dashboard:title'] = 'TITLE'; +$string['dashboard:weight'] = 'WEIGHT'; +$string['dashboard:asttype'] = 'AST TYPE'; +$string['dashboard:source'] = 'SOURCE'; +$string['dashboard:actions'] = 'ACTIONS'; +$string['dashboard:transfermark'] = 'Transfer Mark'; +$string['dashboard:changesource'] = 'Change Source'; // Select source page. $string['selectsource:header'] = 'Select Source'; @@ -130,3 +147,24 @@ $string['task:status:processing'] = 'Transfer task processing'; $string['task:status:completed'] = 'completed'; $string['task:status:failed'] = 'failed'; + +// Privacy strings. +$string['privacy:metadata'] = 'This plugin does not store any personal data.'; +$string['privacy:metadata:local_sitsgradepush_tfr_log'] = 'Stores the marks transfer records.'; +$string['privacy:metadata:local_sitsgradepush_tfr_log:type'] = 'The type of the transfer task.'; +$string['privacy:metadata:local_sitsgradepush_tfr_log:userid'] = 'Whose this transfer task is for.'; +$string['privacy:metadata:local_sitsgradepush_tfr_log:request'] = 'The request\'s URL'; +$string['privacy:metadata:local_sitsgradepush_tfr_log:requestbody'] = 'The request\'s body'; +$string['privacy:metadata:local_sitsgradepush_tfr_log:response'] = 'The response received from SITS'; +$string['privacy:metadata:local_sitsgradepush_tfr_log:usermodified'] = 'The user who requested the transfer task.'; +$string['privacy:metadata:local_sitsgradepush_err_log'] = 'Stores the error logs.'; +$string['privacy:metadata:local_sitsgradepush_err_log:message'] = 'The error message.'; +$string['privacy:metadata:local_sitsgradepush_err_log:errortype'] = 'The error type.'; +$string['privacy:metadata:local_sitsgradepush_err_log:requesturl'] = 'The request\'s URL.'; +$string['privacy:metadata:local_sitsgradepush_err_log:data'] = 'The data sent to SITS.'; +$string['privacy:metadata:local_sitsgradepush_err_log:response'] = 'The response received from SITS.'; +$string['privacy:metadata:local_sitsgradepush_err_log:userid'] = 'The user having the error.'; +$string['privacy:metadata:local_sitsgradepush_tasks'] = 'Stores the transfer tasks.'; +$string['privacy:metadata:local_sitsgradepush_tasks:userid'] = 'The user who requested the transfer task.'; +$string['privacy:metadata:local_sitsgradepush_tasks:status'] = 'The status of the transfer task.'; +$string['privacy:metadata:local_sitsgradepush_tasks:info'] = 'Additional information about the transfer task.'; diff --git a/styles.css b/styles.css index 90046c9..9edce51 100644 --- a/styles.css +++ b/styles.css @@ -24,12 +24,8 @@ width: 5%; } -.sitsgradepush-dasboard .module-delivery-table .assessment-col { - width: 15%; -} - .sitsgradepush-dasboard .module-delivery-table .mark-col { - width: 20%; + width: 35%; } .sitsgradepush-dasboard .module-delivery-table .action-col { @@ -106,3 +102,7 @@ .sitsgradepush-select-source .container { max-width: 90%; } + +.sitsgradepush-select-source .hidden { + display: none; +} diff --git a/templates/assessmentgrades.mustache b/templates/assessmentgrades.mustache index 892ce52..49b3177 100644 --- a/templates/assessmentgrades.mustache +++ b/templates/assessmentgrades.mustache @@ -60,12 +60,12 @@ {{/additionalinfo}} - Student - Portico number - Grade - Submission date - Last grade push - Last submission log push + {{#str}} index:student, local_sitsgradepush {{/str}} + {{#str}} index:porticonumber, local_sitsgradepush {{/str}} + {{#str}} index:grade, local_sitsgradepush {{/str}} + {{#str}} index:submissiondate, local_sitsgradepush {{/str}} + {{#str}} index:lastmarktransfer, local_sitsgradepush {{/str}} + {{#str}} index:lastsublogtransfer, local_sitsgradepush {{/str}} diff --git a/templates/module_delivery_table.mustache b/templates/module_delivery_table.mustache index 2fb510e..af95797 100644 --- a/templates/module_delivery_table.mustache +++ b/templates/module_delivery_table.mustache @@ -77,24 +77,23 @@ - - + - - - - - - + + + + + @@ -103,10 +102,9 @@ -
+
-
MODULE CODE: {{modcode}}
-
ACADEMIC YEAR: {{academicyear}}
-
LEVEL: {{level}} {{graduatetype}}
+
{{#str}} dashboard:modcode, local_sitsgradepush, {{modcode}} {{/str}}
+
{{#str}} dashboard:academicyear, local_sitsgradepush, {{academicyear}} {{/str}}
+
{{#str}} dashboard:level, local_sitsgradepush, {{level}} {{/str}} {{graduatetype}}
MAP CODE: {{mapcode}}{{#str}} dashboard:mapcode, local_sitsgradepush, {{mapcode}} {{/str}}
SEQTITLEWGTAST TYPEMARK TRANSFERACTIONS{{#str}} dashboard:seq, local_sitsgradepush {{/str}}{{#str}} dashboard:title, local_sitsgradepush {{/str}}{{#str}} dashboard:weight, local_sitsgradepush {{/str}}{{#str}} dashboard:source, local_sitsgradepush {{/str}}{{#str}} dashboard:actions, local_sitsgradepush {{/str}}
{{mabseq}} {{mabname}} {{mabperc}}{{astcode}} {{#assessmentmapping}} - {{type}} + {{name}} {{/assessmentmapping}} {{^assessmentmapping}} Select Source
-

{{#str}} selectsource:header, local_sitsgradepush {{/str}}

@@ -43,21 +42,21 @@
-
+
-
+
-
+