From 90dd4d88829227b1bd51d5e18a181ebd044fbe6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Thu, 9 Nov 2023 14:37:07 +0100 Subject: [PATCH] Adhere to Moodle coding style more closely. --- archive_options.php | 12 +++---- archive_table.php | 8 ++--- report.php | 52 +++++++++++++++--------------- tests/behat/behat_quiz_archive.php | 2 +- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/archive_options.php b/archive_options.php index 3dd85b9..1dc064a 100644 --- a/archive_options.php +++ b/archive_options.php @@ -46,12 +46,12 @@ class quiz_archive_options extends mod_quiz_attempts_report_options { /** * @var array form field name => corresponding quiz_attempt:: state constant. */ - protected static $statefields = array( + protected static $statefields = [ 'stateinprogress' => quiz_attempt::IN_PROGRESS, 'stateoverdue' => quiz_attempt::OVERDUE, 'statefinished' => quiz_attempt::FINISHED, 'stateabandoned' => quiz_attempt::ABANDONED, - ); + ]; /** * @var string quiz_attempts_report::ALL_WITH or quiz_attempts_report::ENROLLED_WITH @@ -66,8 +66,8 @@ class quiz_archive_options extends mod_quiz_attempts_report_options { * @var array|null of quiz_attempt::IN_PROGRESS, etc. constants. null means * no restriction. */ - public $states = array(quiz_attempt::IN_PROGRESS, quiz_attempt::OVERDUE, - quiz_attempt::FINISHED, quiz_attempt::ABANDONED); + public $states = [quiz_attempt::IN_PROGRESS, quiz_attempt::OVERDUE, + quiz_attempt::FINISHED, quiz_attempt::ABANDONED, ]; /** * @var bool whether to show all finished attmepts, or just the one that gave @@ -128,12 +128,12 @@ public function get_url() { * @return array URL parameter name => value. */ protected function get_url_params() { - $params = array( + $params = [ 'id' => $this->cm->id, 'mode' => $this->mode, 'attempts' => $this->attempts, 'onlygraded' => $this->onlygraded, - ); + ]; if ($this->states) { $params['states'] = implode('-', $this->states); diff --git a/archive_table.php b/archive_table.php index f260158..618590a 100644 --- a/archive_table.php +++ b/archive_table.php @@ -44,8 +44,8 @@ class quiz_archive_table extends flexible_table { public function __construct($uniqueid, $quiz) { parent::__construct($uniqueid); - $tablecolumns = array('template', 'action'); - $tableheaders = array(get_string('template', 'feedback'), ''); + $tablecolumns = ['template', 'action']; + $tableheaders = [get_string('template', 'feedback'), '']; $this->set_attribute('class', 'templateslist'); @@ -73,9 +73,9 @@ public function display($templates) { $strdeletefeedback = get_string('delete_template', 'feedback'); foreach ($templates as $template) { - $data = array(); + $data = []; $data[] = format_string($template->name); - $url = new moodle_url($this->baseurl, array('deletetempl' => $template->id, 'sesskey' => sesskey())); + $url = new moodle_url($this->baseurl, ['deletetempl' => $template->id, 'sesskey' => sesskey()]); $deleteaction = new confirm_action(get_string('confirmdeletetemplate', 'feedback')); $data[] = $OUTPUT->action_icon($url, new pix_icon('t/delete', $strdeletefeedback), $deleteaction); $this->add_data($data); diff --git a/report.php b/report.php index c5369d2..8e16ada 100644 --- a/report.php +++ b/report.php @@ -91,7 +91,7 @@ public function display($quiz, $cm, $course) { $questionid = optional_param('qid', null, PARAM_INT); $grade = optional_param('grade', null, PARAM_ALPHA); - if (!in_array($grade, array('all', 'needsgrading', 'autograded', 'manuallygraded'))) { + if (!in_array($grade, ['all', 'needsgrading', 'autograded', 'manuallygraded'])) { $grade = null; } $page = optional_param('page', 0, PARAM_INT); @@ -128,7 +128,7 @@ public function display($quiz, $cm, $course) { */ protected function base_url() { return new moodle_url('/mod/quiz/report.php', - array('id' => $this->cm->id, 'mode' => 'archive')); + ['id' => $this->cm->id, 'mode' => 'archive']); } /** @@ -155,9 +155,9 @@ protected function quizreportgetstudentandattempts($quiz) { $sql = "SELECT DISTINCT quiza.id attemptid, u.id userid, u.firstname, u.lastname FROM {user} u " . "LEFT JOIN {quiz_attempts} quiza " . "ON quiza.userid = u.id WHERE quiza.quiz = :quizid AND quiza.preview = 0 ORDER BY u.lastname ASC, u.firstname ASC"; - $params = array('quizid' => $this->quiz->id); + $params = ['quizid' => $this->quiz->id]; $results = $DB->get_records_sql($sql, $params); - $students = array(); + $students = []; foreach ($results as $result) { array_push($students, array('userid' => $result->userid, 'attemptid' => $result->attemptid)); } @@ -198,17 +198,17 @@ protected function quiz_report_get_student_attempt($attemptid, $userid) { } // Prepare summary information about the whole attempt. - $summarydata = array(); + $summarydata = []; // We want the user information no matter what. - $student = $DB->get_record('user', array('id' => $attemptobj->get_userid())); + $student = $DB->get_record('user', ['id' => $attemptobj->get_userid()]); $userpicture = new user_picture($student); $userpicture->courseid = $attemptobj->get_courseid(); - $summarydata['user'] = array( + $summarydata['user'] = [ 'title' => $userpicture, - 'content' => new action_link(new moodle_url('/user/view.php', array( - 'id' => $student->id, 'course' => $attemptobj->get_courseid())), + 'content' => new action_link(new moodle_url('/user/view.php', [ + 'id' => $student->id, 'course' => $attemptobj->get_courseid(), ]), fullname($student, true)), - ); + ]; // Timing information. $summarydata['startedon'] = array( @@ -216,27 +216,27 @@ protected function quiz_report_get_student_attempt($attemptid, $userid) { 'content' => userdate($attempt->timestart), ); - $summarydata['state'] = array( + $summarydata['state'] = [ 'title' => get_string('attemptstate', 'quiz'), 'content' => quiz_archive_quiz_attempt::state_name($attempt->state), - ); + ]; if ($attempt->state == quiz_archive_quiz_attempt::FINISHED) { - $summarydata['completedon'] = array( + $summarydata['completedon'] = [ 'title' => get_string('completedon', 'quiz'), 'content' => userdate($attempt->timefinish), - ); - $summarydata['timetaken'] = array( + ]; + $summarydata['timetaken'] = [ 'title' => get_string('timetaken', 'quiz'), 'content' => $timetaken, - ); + ]; } if (!empty($overtime)) { - $summarydata['overdue'] = array( + $summarydata['overdue'] = [ 'title' => get_string('overdue', 'quiz'), 'content' => $overtime, - ); + ]; } // Show marks (if the user is allowed to see marks at the moment). @@ -247,10 +247,10 @@ protected function quiz_report_get_student_attempt($attemptid, $userid) { // Cannot display grade. echo ''; } else if (is_null($grade)) { - $summarydata['grade'] = array( + $summarydata['grade'] = [ 'title' => get_string('grade', 'quiz'), 'content' => quiz_format_grade($quiz, $grade), - ); + ]; } else { // Show raw marks only if they are different from the grade (like on the view page). @@ -258,10 +258,10 @@ protected function quiz_report_get_student_attempt($attemptid, $userid) { $a = new stdClass(); $a->grade = quiz_format_grade($quiz, $attempt->sumgrades); $a->maxgrade = quiz_format_grade($quiz, $quiz->sumgrades); - $summarydata['marks'] = array( + $summarydata['marks'] = [ 'title' => get_string('marks', 'quiz'), 'content' => get_string('outofshort', 'quiz', $a), - ); + ]; } // Now the scaled grade. @@ -275,10 +275,10 @@ protected function quiz_report_get_student_attempt($attemptid, $userid) { } else { $formattedgrade = get_string('outof', 'quiz', $a); } - $summarydata['grade'] = array( + $summarydata['grade'] = [ 'title' => get_string('grade', 'quiz'), 'content' => $formattedgrade, - ); + ]; } } @@ -288,10 +288,10 @@ protected function quiz_report_get_student_attempt($attemptid, $userid) { // Feedback if there is any, and the user is allowed to see it now. $feedback = $attemptobj->get_overall_feedback($grade); if ($options->overallfeedback && $feedback) { - $summarydata['feedback'] = array( + $summarydata['feedback'] = [ 'title' => get_string('feedback', 'quiz'), 'content' => $feedback, - ); + ]; } // Summary table end. diff --git a/tests/behat/behat_quiz_archive.php b/tests/behat/behat_quiz_archive.php index d3b90b3..a7c5769 100644 --- a/tests/behat/behat_quiz_archive.php +++ b/tests/behat/behat_quiz_archive.php @@ -112,7 +112,7 @@ public function i_confirm_the_quiz_submission_in_the_modal_dialog() { } else if (version_compare($currentversion, '3.9', ">=")) { $xpath = "//div[contains(@class, 'confirmation-dialogue')]/*/input[contains(@class, 'btn-primary')]"; } - $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element")); + $this->execute("behat_general::i_click_on", [$this->escape($xpath), "xpath_element"]); } }