From 34c80542f5bfee51d1666c8adcb1b4b1009b42b7 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/submission/quiz.php | 33 +++++++++++++++++++----- lang/en/local_sitsgradepush.php | 26 ++++++++++++++++--- styles.css | 10 +++---- templates/assessmentgrades.mustache | 12 ++++----- templates/module_delivery_table.mustache | 28 ++++++++++---------- templates/select_source_page.mustache | 7 +++-- 7 files changed, 77 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/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..19b708f 100644 --- a/lang/en/local_sitsgradepush.php +++ b/lang/en/local_sitsgradepush.php @@ -67,11 +67,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. -$string['dashboard:header'] = 'SITS Marks Transfer Dashboard'; +// 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'; @@ -103,7 +121,7 @@ $string['error:duplicatedtask'] = 'There is already a transfer task in queue / processing for this assessment mapping.'; $string['error:tasknotfound'] = 'Transfer task not found.'; $string['error:multiplemappingsnotsupported'] = 'Multiple assessment component mappings is not supported by {$a}'; -$string['error:studentnotfound'] = 'Student with idnumber {$a->idnumber} not found for component grade {$a->componentgrade}'; +$string['error:studentnotfound'] = 'Student with idnumber {$a->idnumber} not found for component marks {$a->componentgrade}'; $string['error:coursemodulenotfound'] = 'Course module not found. ID: {$a}'; $string['error:duplicatemapping'] = 'Cannot map multiple assessment components with same module delivery to an activity. Mapcode: {$a}'; $string['error:nomoduledeliveryfound'] = 'No module delivery found.'; 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 @@
-
+
-
+
-
+