diff --git a/classes/quiz_attemptreport.php b/classes/quiz_attemptreport.php index d50c737..45cabea 100644 --- a/classes/quiz_attemptreport.php +++ b/classes/quiz_attemptreport.php @@ -25,6 +25,9 @@ namespace quiz_markspersection; +use mod_quiz\access_manager; +use mod_quiz\quiz_attempt; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -36,7 +39,7 @@ * @author Marie-Eve Lévesque * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class quiz_attemptreport extends \quiz_attempt { +class quiz_attemptreport extends quiz_attempt { /** @var array Already calculated sections marks, stored in this variable for further use (to avoid recalculation). */ private $sectionmarks = null; @@ -97,7 +100,7 @@ public function get_sectionid($slot) { * @return quiz_attempt the new quiz_attempt object */ public static function create($attemptid) { - return self::create_helper(array('id' => $attemptid)); + return self::create_helper(['id' => $attemptid]); } /** @@ -110,8 +113,8 @@ protected static function create_helper($conditions) { global $DB; $attempt = $DB->get_record('quiz_attempts', $conditions, '*', MUST_EXIST); - $quiz = \quiz_access_manager::load_quiz_and_settings($attempt->quiz); - $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST); + $quiz = access_manager::load_quiz_and_settings($attempt->quiz); + $course = $DB->get_record('course', ['id' => $quiz->course], '*', MUST_EXIST); $cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id, false, MUST_EXIST); // Update quiz with override information. diff --git a/markspersection_form.php b/markspersection_form.php index 8638f2b..54938e9 100644 --- a/markspersection_form.php +++ b/markspersection_form.php @@ -23,9 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_form.php'); +use mod_quiz\local\reports\attempts_report_options_form; /** * Quiz marks per section report settings form. @@ -34,6 +32,6 @@ * @author Marie-Eve Lévesque * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class quiz_markspersection_settings_form extends mod_quiz_attempts_report_form { +class quiz_markspersection_settings_form extends attempts_report_options_form { } diff --git a/markspersection_options.php b/markspersection_options.php index f73f715..58eb8dd 100644 --- a/markspersection_options.php +++ b/markspersection_options.php @@ -23,9 +23,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_options.php'); +use mod_quiz\local\reports\attempts_report; +use mod_quiz\local\reports\attempts_report_options; /** * Class to store the options for a quiz_markspersection_report. @@ -34,7 +33,7 @@ * @author Marie-Eve Lévesque * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class quiz_markspersection_options extends mod_quiz_attempts_report_options { +class quiz_markspersection_options extends attempts_report_options { /** @var bool whether to show only attempt that need regrading. * This variable is necessary to stay compatible with quiz_overview_options even if we do not extend it. */ @@ -53,7 +52,7 @@ public function resolve_dependencies() { // We only want to show the checkbox to delete attempts // if the user has permissions and if the report mode is showing attempts. $this->checkboxcolumn = has_any_capability( - array('mod/quiz:deleteattempts'), context_module::instance($this->cm->id)) - && ($this->attempts != quiz_attempts_report::ENROLLED_WITHOUT); + ['mod/quiz:deleteattempts'], context_module::instance($this->cm->id)) + && ($this->attempts != attempts_report::ENROLLED_WITHOUT); } } diff --git a/markspersection_table.php b/markspersection_table.php index c7b4827..f55f50b 100644 --- a/markspersection_table.php +++ b/markspersection_table.php @@ -24,9 +24,8 @@ */ -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_table.php'); +use mod_quiz\local\reports\attempts_report_table; +use mod_quiz\quiz_settings; use quiz_markspersection\quiz_attemptreport; /** @@ -39,10 +38,10 @@ class quiz_markspersection_table extends quiz_overview_table { /** @var array Array of quiz_attemptreport (kept for further usage, to avoid unnecessary initialisations and calculations). */ - private $attemptreports = array(); + private $attemptreports = []; /** @var array Array of attemps section marks. */ - private $attemptsectionsmarks = array(); + private $attemptsectionsmarks = []; /** @var Array Array of attempts ids in the report. */ private $attemptsids = []; @@ -61,7 +60,7 @@ class quiz_markspersection_table extends quiz_overview_table { public function __construct($quiz, $context, $qmsubselect, $options, \core\dml\sql_join $groupstudentsjoins, \core\dml\sql_join $studentsjoins, $questions, $reporturl) { - quiz_attempts_report_table::__construct('mod-quiz-report-markspersection-report', $quiz , $context, + attempts_report_table::__construct('mod-quiz-report-markspersection-report', $quiz , $context, $qmsubselect, $options, $groupstudentsjoins, $studentsjoins, $questions, $reporturl); } @@ -161,12 +160,12 @@ public function compute_average_row($label, \core\dml\sql_join $usersjoins) { } else { $namekey = 'fullname'; } - $averagerow = array( + $averagerow = [ $namekey => $label, 'sumgrades' => $this->format_average($record), 'feedbacktext' => strip_tags(quiz_report_feedback_for_grade( - $record->grade, $this->quiz->id, $this->context)) - ); + $record->grade, $this->quiz->id, $this->context)), + ]; $qubaids = new qubaid_join("{quiz_attempts} quizaouter JOIN ( SELECT DISTINCT quiza.id @@ -201,7 +200,7 @@ public function compute_average_row($label, \core\dml\sql_join $usersjoins) { * Redefine the parent function with only relevant information (quiz_overview_table has too many). */ protected function submit_buttons() { - quiz_attempts_report_table::submit_buttons(); + attempts_report_table::submit_buttons(); } /** @@ -256,7 +255,7 @@ protected function add_latest_state_join($slot) { // therefore, it is better to use a very simple join, which may include // too many records, than to do a super-accurate join. $qubaids = new qubaid_join("{quiz_attempts} {$alias}quiza", "{$alias}quiza.uniqueid", - "{$alias}quiza.quiz = :{$alias}quizid", array("{$alias}quizid" => $this->sql->params['quizid'])); + "{$alias}quiza.quiz = :{$alias}quizid", ["{$alias}quizid" => $this->sql->params['quizid']]); list($inlineview, $viewparams) = $this->question_attempt_latest_state_view($alias, $qubaids); @@ -286,7 +285,7 @@ public function question_attempt_latest_state_view($alias, qubaid_condition $qub $where = $qubaids->where() . " AND {$alias}qa.questionid IN($questionsidsstr)"; $whereparams = $qubaids->from_where_params(); // The name "marksection" givent to the SUM function is the one to reuse in get_required_latest_state_fields. - return array("( + return ["( SELECT {$alias}qa.questionusageid, SUM({$alias}qas.fraction * {$alias}qa.maxmark) AS marksection, {$alias}qas.userid @@ -294,7 +293,7 @@ public function question_attempt_latest_state_view($alias, qubaid_condition $qub JOIN {question_attempt_steps} {$alias}qas ON {$alias}qas.questionattemptid = {$alias}qa.id WHERE {$where} GROUP BY {$alias}qa.questionusageid, {$alias}qas.userid - ) {$alias}", $whereparams); + ) {$alias}", $whereparams]; } /** @@ -304,12 +303,12 @@ public function question_attempt_latest_state_view($alias, qubaid_condition $qub */ public function get_questions_in_section($sectionid) { $cm = get_coursemodule_from_instance('quiz', $this->quiz->id, $this->quiz->course, false, MUST_EXIST); - $quizobj = new \quiz($this->quiz, $cm, $this->quiz->course); + $quizobj = new quiz_settings($this->quiz, $cm, $this->quiz->course); $structure = $quizobj->get_structure(); $slots = $structure->get_slots_in_section($sectionid); // Get all the questions in the slots of this section. - $questionsinsection = array(); + $questionsinsection = []; foreach ($this->questions as $question) { if (in_array($question->slot, $slots)) { $questionsinsection[] = $question->id; diff --git a/report.php b/report.php index 9268b55..345f49d 100644 --- a/report.php +++ b/report.php @@ -29,6 +29,8 @@ require_once($CFG->dirroot . '/mod/quiz/report/markspersection/markspersection_form.php'); require_once($CFG->dirroot . '/mod/quiz/report/markspersection/markspersection_options.php'); require_once($CFG->dirroot . '/mod/quiz/report/markspersection/markspersection_table.php'); + +use mod_quiz\quiz_settings; use quiz_markspersection\quiz_attemptreport; /** @@ -70,7 +72,7 @@ public function display($quiz, $cm, $course) { // Prepare for downloading, if applicable. $courseshortname = format_string($course->shortname, true, - array('context' => context_course::instance($course->id))); + ['context' => context_course::instance($course->id)]); $table = new quiz_markspersection_table($quiz, $this->context, $this->qmsubselect, $options, $groupstudentsjoins, $studentsjoins, $questions, $options->get_url()); $filename = quiz_report_download_filename(get_string('markspersectionfilename', 'quiz_markspersection'), @@ -109,7 +111,7 @@ public function display($quiz, $cm, $course) { $hasquestions = quiz_has_questions($quiz->id); - $quizobj = quiz::create($quiz->id); + $quizobj = quiz_settings::create($quiz->id); $sections = $quizobj->get_sections(); if (count($sections) <= 1) { $this->print_header_and_tabs($cm, $course, $quiz); @@ -141,8 +143,8 @@ public function display($quiz, $cm, $course) { } // Define table columns. - $columns = array(); - $headers = array(); + $columns = []; + $headers = []; if (!$table->is_downloading() && $options->checkboxcolumn) { $columnname = 'checkbox'; @@ -207,7 +209,7 @@ protected function quiz_no_sections_message($cm, $context) { $output = $OUTPUT->notification(get_string('nosections', 'quiz_markspersection')); if (has_capability('mod/quiz:manage', $context)) { $output .= $OUTPUT->single_button(new moodle_url('/mod/quiz/edit.php', - array('cmid' => $cm->id)), get_string('editquiz', 'quiz'), 'get'); + ['cmid' => $cm->id]), get_string('editquiz', 'quiz'), 'get'); } return $output; diff --git a/tests/report_test.php b/tests/report_test.php index 9b53cdd..d2b94fa 100644 --- a/tests/report_test.php +++ b/tests/report_test.php @@ -28,11 +28,12 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; -require_once($CFG->dirroot . '/mod/quiz/report/default.php'); require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); require_once($CFG->dirroot . '/mod/quiz/report/markspersection/report.php'); -use quiz_markspersection\quiz_attemptreport; +use mod_quiz\local\reports\attempts_report; +use mod_quiz\quiz_attempt; +use mod_quiz\quiz_settings; /** * Tests for the quiz marks per section report. @@ -56,13 +57,13 @@ public function test_get_sections_marks() { // Create 2 quizzes : one without sections and one with sections. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz1 = $quizgenerator->create_instance(array('course' => $course->id, 'questionsperpage' => 0, - 'grade' => 100.0, 'sumgrades' => 2, 'preferredbehaviour' => 'immediatefeedback')); - $quiz2 = $quizgenerator->create_instance(array('course' => $course->id, 'questionsperpage' => 0, - 'grade' => 100.0, 'sumgrades' => 2, 'preferredbehaviour' => 'immediatefeedback')); + $quiz1 = $quizgenerator->create_instance(['course' => $course->id, 'questionsperpage' => 0, + 'grade' => 100.0, 'sumgrades' => 2, 'preferredbehaviour' => 'immediatefeedback']); + $quiz2 = $quizgenerator->create_instance(['course' => $course->id, 'questionsperpage' => 0, + 'grade' => 100.0, 'sumgrades' => 2, 'preferredbehaviour' => 'immediatefeedback']); - $quizobj1 = \quiz::create($quiz1->id, $user->id); - $quizobj2 = \quiz::create($quiz2->id, $user->id); + $quizobj1 = quiz_settings::create($quiz1->id, $user->id); + $quizobj2 = quiz_settings::create($quiz2->id, $user->id); $quba1 = \question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj1->get_context()); $quba1->set_preferred_behaviour($quizobj1->get_quiz()->preferredbehaviour); @@ -105,7 +106,7 @@ public function test_get_sections_marks() { // Case 1 : When there are no sections in the quiz. // Submit answers to create attempt for user. - $attemptobj = $this->submitanswers($quizobj1, $quba1, $user, array(0, 0, 1, 0, 1, 1)); + $attemptobj = $this->submitanswers($quizobj1, $quba1, $user, [0, 0, 1, 0, 1, 1]); // Check the data for the report - there is at least one section. $quizattemptsreport = quiz_attemptreport::create($attemptobj->get_attemptid()); @@ -134,7 +135,7 @@ public function test_get_sections_marks() { $structure->add_section_heading(4, 'Section 4'); // Submit answers to create attempt for user. - $attemptobj = $this->submitanswers($quizobj2, $quba2, $user, array(0, 0, 1, 0, 1, 1, 'My essay.')); + $attemptobj = $this->submitanswers($quizobj2, $quba2, $user, [0, 0, 1, 0, 1, 1, 'My essay.']); // Check the data for the report. $quizattemptsreport = new \quiz_markspersection_report(); @@ -173,11 +174,11 @@ public function test_compute_average_row() { // Create 2 quizzes : one without sections and one with sections. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz1 = $quizgenerator->create_instance(array('course' => $course->id, 'questionsperpage' => 0, - 'grade' => 100.0, 'sumgrades' => 2, 'preferredbehaviour' => 'immediatefeedback')); + $quiz1 = $quizgenerator->create_instance(['course' => $course->id, 'questionsperpage' => 0, + 'grade' => 100.0, 'sumgrades' => 2, 'preferredbehaviour' => 'immediatefeedback']); - $quizobj1 = \quiz::create($quiz1->id, $user->id); - $quizobj2 = \quiz::create($quiz1->id, $user2->id); + $quizobj1 = quiz_settings::create($quiz1->id, $user->id); + $quizobj2 = quiz_settings::create($quiz1->id, $user2->id); $quba1 = \question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj1->get_context()); $quba1->set_preferred_behaviour($quizobj1->get_quiz()->preferredbehaviour); @@ -228,24 +229,24 @@ public function test_compute_average_row() { $section4 = $structure->add_section_heading(4, 'Section 4'); // Submit answers to create attempt for user 1. - $this->submitanswers($quizobj1, $quba1, $user, array(0, 0, 1, 0, 1, 1, 'My essay.')); + $this->submitanswers($quizobj1, $quba1, $user, [0, 0, 1, 0, 1, 1, 'My essay.']); // Submit answers to create attempt for user 2. - $this->submitanswers($quizobj2, $quba2, $user2, array(0, 1, 1)); + $this->submitanswers($quizobj2, $quba2, $user2, [0, 1, 1]); // Check the data for the report. $context = \context_module::instance($cm1->id); $cm = get_coursemodule_from_id('quiz', $cm1->id); $qmsubselect = quiz_report_qm_filter_select($quiz1); $studentsjoins = get_enrolled_with_capabilities_join($context, '', - array('mod/quiz:attempt', 'mod/quiz:reviewmyattempts')); + ['mod/quiz:attempt', 'mod/quiz:reviewmyattempts']); $empty = new \core\dml\sql_join(); // Set the options. $reportoptions = new \quiz_markspersection_options('overview', $quiz1, $cm, null); - $reportoptions->attempts = \quiz_attempts_report::ENROLLED_ALL; + $reportoptions->attempts = attempts_report::ENROLLED_ALL; $reportoptions->onlygraded = true; - $reportoptions->states = array(\quiz_attempt::IN_PROGRESS, \quiz_attempt::OVERDUE, \quiz_attempt::FINISHED); + $reportoptions->states = [quiz_attempt::IN_PROGRESS, quiz_attempt::OVERDUE, quiz_attempt::FINISHED]; // Load the required questions. $questions = quiz_report_get_significant_questions($quiz1); @@ -253,7 +254,7 @@ public function test_compute_average_row() { $table = new \quiz_markspersection_table($quiz1, $context, $qmsubselect, $reportoptions, $empty, $studentsjoins, $questions, null); $table->download = null; - $table->define_columns(array('fullname')); + $table->define_columns(['fullname']); $table->sortable(true, 'uniqueid'); $table->define_baseurl(new \moodle_url('/mod/quiz/report.php')); $table->setup(); @@ -279,7 +280,7 @@ public function test_compute_average_row() { $table = new \quiz_markspersection_table($quiz1, $context, $qmsubselect, $reportoptions, $empty, $studentsjoins, $questions, null); $table->download = null; - $table->define_columns(array('fullname')); + $table->define_columns(['fullname']); $table->sortable(true, 'uniqueid'); $table->define_baseurl(new \moodle_url('/mod/quiz/report.php')); $table->setup(); @@ -307,7 +308,7 @@ public function test_compute_average_row() { * @param \stdClass $user The user record object who submitted this attempt. * @param array $answers The answers submitted by the user. * - * @return \quiz_attempt The attempt object created. + * @return quiz_attempt The attempt object created. */ private function submitanswers($quizobj, $quba1, $user, $answers) { $timenow = time(); @@ -316,13 +317,13 @@ private function submitanswers($quizobj, $quba1, $user, $answers) { quiz_attempt_save_started($quizobj, $quba1, $attempt); // Process some responses from the student 1. - $attemptobj = \quiz_attempt::create($attempt->id); - $tosubmit = array(); + $attemptobj = quiz_attempt::create($attempt->id); + $tosubmit = []; foreach ($answers as $ianswer => $answer) { if (is_numeric($answer)) { - $tosubmit[$ianswer + 1] = array('answer' => $answer); + $tosubmit[$ianswer + 1] = ['answer' => $answer]; } else { - $tosubmit[$ianswer + 1] = array('answer' => $answer, 'answerformat' => FORMAT_PLAIN); + $tosubmit[$ianswer + 1] = ['answer' => $answer, 'answerformat' => FORMAT_PLAIN]; } } $attemptobj->process_submitted_actions($timenow, false, $tosubmit); diff --git a/tests/table_test.php b/tests/table_test.php index abd2021..c507867 100644 --- a/tests/table_test.php +++ b/tests/table_test.php @@ -28,10 +28,13 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; -require_once($CFG->dirroot . '/mod/quiz/report/default.php'); require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); require_once($CFG->dirroot . '/mod/quiz/report/markspersection/report.php'); +use mod_quiz\local\reports\attempts_report; +use mod_quiz\quiz_attempt; +use mod_quiz\quiz_settings; + /** * Tests for the table of quiz marks per section report. * @@ -53,10 +56,10 @@ public function test_get_questions_in_section() { // Create a quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz1 = $quizgenerator->create_instance(array('course' => $course->id, 'questionsperpage' => 0, - 'grade' => 100.0, 'sumgrades' => 2, 'preferredbehaviour' => 'immediatefeedback')); + $quiz1 = $quizgenerator->create_instance(['course' => $course->id, 'questionsperpage' => 0, + 'grade' => 100.0, 'sumgrades' => 2, 'preferredbehaviour' => 'immediatefeedback']); - $quizobj1 = \quiz::create($quiz1->id, $user->id); + $quizobj1 = quiz_settings::create($quiz1->id, $user->id); $context1 = $quizobj1->get_context(); $quba1 = \question_engine::make_questions_usage_by_activity('mod_quiz', $context1); @@ -107,19 +110,19 @@ public function test_get_questions_in_section() { // Now do a minimal set-up of the table class. $qmsubselect = quiz_report_qm_filter_select($quiz1); $studentsjoins = get_enrolled_with_capabilities_join($context1, '', - array('mod/quiz:attempt', 'mod/quiz:reviewmyattempts')); + ['mod/quiz:attempt', 'mod/quiz:reviewmyattempts']); $empty = new \core\dml\sql_join(); // Set the options. $reportoptions = new \quiz_markspersection_options('markspersection', $quiz1, $cm1, null); - $reportoptions->attempts = \quiz_attempts_report::ENROLLED_ALL; + $reportoptions->attempts = attempts_report::ENROLLED_ALL; $reportoptions->onlygraded = true; - $reportoptions->states = array(\quiz_attempt::IN_PROGRESS, \quiz_attempt::OVERDUE, \quiz_attempt::FINISHED); + $reportoptions->states = [quiz_attempt::IN_PROGRESS, quiz_attempt::OVERDUE, quiz_attempt::FINISHED]; // Initialise the table class. $table = new \quiz_markspersection_table($quiz1, $quizobj1->get_context(), $qmsubselect, $reportoptions, $empty, $studentsjoins, - array(1 => $question1, 2 => $question2, 3 => $question3, 4 => $question4, 5 => $question5, 6 => $question6), + [1 => $question1, 2 => $question2, 3 => $question3, 4 => $question4, 5 => $question5, 6 => $question6], null); // Assert the get_questions_in_section function. diff --git a/version.php b/version.php index 02fbe43..90f59c8 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2021110900; -$plugin->requires = 2021051704; +$plugin->version = 2024012500; +$plugin->requires = 2023100400; $plugin->component = 'quiz_markspersection'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '1.0.3 (Build 2021110900)'; +$plugin->release = '1.0.4 (Build 2024012500)';