Skip to content

Commit

Permalink
Fix Moodle Code Checker errors and warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
lbailey-ucsf committed Dec 27, 2024
1 parent fd615cf commit 6bee8c3
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 13 deletions.
12 changes: 10 additions & 2 deletions classes/hook_callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@

use core\hook\output\before_standard_top_of_body_html_generation;

/**
* Hook callback implementations for the Quiz Anonymization plugin
*
* @package local_quizanon
* @copyright 2024 UCSF Education IT
* @author Leon U. Bailey <leon.bailey@ucsf.edu>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class hook_callbacks {
/**
* Hook callback for before standard top of body HTML generation.
Expand All @@ -36,6 +44,6 @@ class hook_callbacks {
* @param \core\hook\output\before_standard_top_of_body_html_generation $hook
*/
public static function before_standard_top_of_body_html(before_standard_top_of_body_html_generation $hook): void {
local_quizanon_before_standard_top_of_body_html();
local_quizanon_before_standard_top_of_body_html();
}
}
}
17 changes: 16 additions & 1 deletion db/hooks.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Hooks configuration for the Quiz Anonymization plugin
*
Expand All @@ -15,5 +30,5 @@
'hook' => \core\hook\output\before_standard_top_of_body_html_generation::class,
'callback' => '\local_quizanon\hook_callbacks::before_standard_top_of_body_html',
'priority' => 0,
],
],
];
8 changes: 4 additions & 4 deletions report.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
if (!$cm = get_coursemodule_from_id('quiz', $id)) {
throw new \moodle_exception('invalidcoursemodule');
}
if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
if (!$course = $DB->get_record('course', ['id' => $cm->course])) {
throw new \moodle_exception('coursemisconf');
}
if (!$quiz = $DB->get_record('quiz', array('id' => $cm->instance))) {
if (!$quiz = $DB->get_record('quiz', ['id' => $cm->instance])) {
throw new \moodle_exception('invalidcoursemodule');
}

} else {
if (!$quiz = $DB->get_record('quiz', array('id' => $q))) {
if (!$quiz = $DB->get_record('quiz', ['id' => $q]))) {
throw new \moodle_exception('invalidquizid', 'quiz');
}
if (!$course = $DB->get_record('course', array('id' => $quiz->course))) {
if (!$course = $DB->get_record('course', ['id' => $quiz->course])) {
throw new \moodle_exception('invalidcourseid');
}
if (!$cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
Expand Down
7 changes: 6 additions & 1 deletion report/grading/gradingsettings_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ protected function definition() {
$mform->addElement('submit', 'submitbutton', get_string('changeoptions', 'quiz_grading'));

$mform->addElement('header', 'searchoption', get_string('search'));
$mform->addElement('text', 'anonsearch', get_string('searchanonymousid', 'local_quizanon'), ['size' => 6, 'maxlength' => 6]);
$mform->addElement(
'text',
'anonsearch',
get_string('searchanonymousid', 'local_quizanon'),
['size' => 6, 'maxlength' => 6]
);
$mform->setType('anonsearch', PARAM_ALPHANUM);
}
}
7 changes: 6 additions & 1 deletion report/overview/overview_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ public function print_initials_bar() {

if ((!empty($ifirst) || !empty($ilast) || $this->use_initials)) {
$prefixfirst = $this->request[TABLE_VAR_IFIRST];
echo $OUTPUT->initials_bar($ifirst, 'firstinitial', get_string('usercode', 'local_quizanon'), $prefixfirst, $this->baseurl);
echo $OUTPUT->initials_bar(
$ifirst,
'firstinitial',
get_string('usercode', 'local_quizanon'),
$prefixfirst,
$this->baseurl);
}
}
}
8 changes: 7 additions & 1 deletion report/responses/last_responses_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ public function print_initials_bar() {

if ((!empty($ifirst) || !empty($ilast) || $this->use_initials)) {
$prefixfirst = $this->request[TABLE_VAR_IFIRST];
echo $OUTPUT->initials_bar($ifirst, 'firstinitial', get_string('usercode', 'local_quizanon'), $prefixfirst, $this->baseurl);
echo $OUTPUT->initials_bar(
$ifirst,
'firstinitial',
get_string('usercode', 'local_quizanon'),
$prefixfirst,
$this->baseurl
);
}
}
}
6 changes: 3 additions & 3 deletions tests/behat/behat_local_quizanon.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class behat_local_quizanon extends behat_question_base {
*/
public function quizanonpluginisenable($quizname) {
global $DB;
$quiz = $DB->get_record('quiz', array('name' => $quizname), '*', MUST_EXIST);
$quiz = $DB->get_record('quiz', ['name' => $quizname], '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('quiz', $quiz->id);
$roles = [];
$record = $DB->get_record('local_quizanon', ['quizid' => $cm->id]);
Expand All @@ -68,7 +68,7 @@ public function quizanonpluginisenable($quizname) {
*/
public function roleisexcludedfromquizanon($role, $quizname) {
global $DB;
$quiz = $DB->get_record('quiz', array('name' => $quizname), '*', MUST_EXIST);
$quiz = $DB->get_record('quiz', ['name' => $quizname], '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('quiz', $quiz->id);
$roles = [];
$getroleid = $DB->get_record('role', ['shortname' => $role]);
Expand All @@ -91,7 +91,7 @@ public function roleisexcludedfromquizanon($role, $quizname) {
*/
public function quizanonpluginisdisabled($quizname) {
global $DB;
$quiz = $DB->get_record('quiz', array('name' => $quizname), '*', MUST_EXIST);
$quiz = $DB->get_record('quiz', ['name' => $quizname], '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('quiz', $quiz->id);
if (!$quiz) {

Expand Down

0 comments on commit 6bee8c3

Please sign in to comment.