diff --git a/attemptsheet.php b/attemptsheet.php index 96c0b82..7f4a851 100644 --- a/attemptsheet.php +++ b/attemptsheet.php @@ -24,6 +24,7 @@ use quiz_answersheets\report_display_options; use quiz_answersheets\utils; +use mod_quiz\quiz_attempt; require_once(__DIR__ . '/../../../../config.php'); require_once($CFG->dirroot . '/mod/quiz/locallib.php'); @@ -33,8 +34,10 @@ $rightanswer = optional_param('rightanswer', 0, PARAM_BOOL); $attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid); -$reportoptions = new report_display_options('answersheets', $attemptobj->get_quiz(), - $attemptobj->get_cm(), $attemptobj->get_course()); +if (isset($attemptobj)) { + $reportoptions = new report_display_options('answersheets', $attemptobj->get_quiz(), + $attemptobj->get_cm(), $attemptobj->get_course()); +} $reportoptions->setup_from_params(); // Check login. diff --git a/classes/output/renderer.php b/classes/output/renderer.php index f046ee6..1671ef0 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -34,7 +34,7 @@ use question_display_options; use quiz_answersheets\report_display_options; use quiz_answersheets\utils; -use quiz_attempt; +use mod_quiz\quiz_attempt; defined('MOODLE_INTERNAL') || die(); diff --git a/classes/report_display_options.php b/classes/report_display_options.php index 438de58..f0d6033 100644 --- a/classes/report_display_options.php +++ b/classes/report_display_options.php @@ -25,14 +25,12 @@ namespace quiz_answersheets; use context_module; -use quiz_attempts_report; +use mod_quiz\local\reports\attempts_report_options; +use mod_quiz\local\reports\attempts_report; defined('MOODLE_INTERNAL') || die(); -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/attemptsreport.php'); -require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_options.php'); /** * This file defines the options for the quiz answersheets report. @@ -41,7 +39,7 @@ * @copyright 2019 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class report_display_options extends \mod_quiz_attempts_report_options { +class report_display_options extends attempts_report_options { /**@var int Last changed row id */ public $lastchanged; @@ -58,7 +56,7 @@ class report_display_options extends \mod_quiz_attempts_report_options { public function __construct($mode, $quiz, $cm, $course) { parent::__construct($mode, $quiz, $cm, $course); - $this->attempts = quiz_attempts_report::ENROLLED_ALL; + $this->attempts = attempts_report::ENROLLED_ALL; $this->userinfovisibility = self::possible_user_info_visibility_settings($cm); } @@ -68,7 +66,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_capability('mod/quiz:deleteattempts', context_module::instance($this->cm->id)) - && ($this->attempts != quiz_attempts_report::ENROLLED_WITHOUT); + && ($this->attempts != attempts_report::ENROLLED_WITHOUT); } public function setup_from_params() { @@ -97,7 +95,8 @@ public function process_settings_from_form($fromform) { parent::process_settings_from_form($fromform); } - public function get_initial_form_data() { + public function get_initial_form_data(): \cm_info| \stdClass + { $toform = parent::get_initial_form_data(); foreach ($this->userinfovisibility as $name => $show) { @@ -157,7 +156,8 @@ protected function parse_user_info_visibility(string $combined): void { * @param \stdClass $cm the course_module info for this quiz. * @return array setting name => true */ - public static function possible_user_info_visibility_settings(\stdClass $cm): array { + public static function possible_user_info_visibility_settings( \cm_info|\stdClass $cm): array { + $settings = ['fullname' => true]; // TODO Does not support custom user profile fields (MDL-70456). diff --git a/classes/report_settings_form.php b/classes/report_settings_form.php index 2d0c0a2..8ef1bc6 100644 --- a/classes/report_settings_form.php +++ b/classes/report_settings_form.php @@ -25,8 +25,7 @@ namespace quiz_answersheets; defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_form.php'); +use mod_quiz\local\reports\attempts_report_options_form; /** * This file defines the setting form for the quiz answersheets report. @@ -35,9 +34,13 @@ * @copyright 2019 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class report_settings_form extends \mod_quiz_attempts_report_form { +class report_settings_form extends attempts_report_options_form { + + protected $_customdata; + - protected function other_preference_fields(\MoodleQuickForm $mform) { + protected function other_preference_fields(\MoodleQuickForm $mform): void + { $field = report_display_options::possible_user_info_visibility_settings( $this->_customdata['quiz']->cmobject); diff --git a/classes/report_table.php b/classes/report_table.php index c982622..21e1a85 100644 --- a/classes/report_table.php +++ b/classes/report_table.php @@ -26,12 +26,11 @@ use html_writer; use moodle_url; -use quiz_attempt; +use mod_quiz\local\reports\attempts_report_table; +use mod_quiz\quiz_attempt; defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_table.php'); - /** * This file defines the quiz answersheets table for showing last try at question * @@ -39,7 +38,7 @@ * @copyright 2019 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class report_table extends \quiz_attempts_report_table { +class report_table extends attempts_report_table { /** @var report_display_options Option */ protected $options; diff --git a/classes/utils.php b/classes/utils.php index 4f3a42b..e025cac 100644 --- a/classes/utils.php +++ b/classes/utils.php @@ -33,7 +33,7 @@ use qtype_renderer; use question_attempt; use question_display_options; -use quiz_attempt; +use mod_quiz\quiz_attempt; use ReflectionClass; use stdClass; use user_picture; @@ -77,7 +77,7 @@ class utils { * @param report_display_options $reportoptions controls which user info is shown. * @return array List of summary information */ - public static function prepare_summary_attempt_information(quiz_attempt $attemptobj, + public static function prepare_summary_attempt_information(\mod_quiz\quiz_attempt $attemptobj, bool $minimal, report_display_options $reportoptions): array { global $CFG, $DB; @@ -200,7 +200,7 @@ public static function prepare_summary_attempt_information(quiz_attempt $attempt * or just a array of field names. * @return string User detail string */ - public static function get_user_details(stdClass $attemptuser, stdClass $cm, $fieldoptions): string { + public static function get_user_details(stdClass $attemptuser, \stdClass | \cm_info $cm, $fieldoptions): string { $fields = []; if ($fieldoptions instanceof report_display_options) { foreach ($fieldoptions->userinfovisibility as $field => $show) { diff --git a/report.php b/report.php index f7a3143..11a6416 100644 --- a/report.php +++ b/report.php @@ -25,12 +25,11 @@ use quiz_answersheets\report_display_options; use quiz_answersheets\report_table; use quiz_answersheets\utils; - +use mod_quiz\local\reports\attempts_report; +use mod_quiz\quiz_attempt; defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport.php'); - /** * This file defines the export quiz attempts report class. * @@ -38,7 +37,7 @@ * @copyright 2019 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class quiz_answersheets_report extends quiz_attempts_report { +class quiz_answersheets_report extends attempts_report { public function display($quiz, $cm, $course) { global $DB, $PAGE; @@ -455,7 +454,7 @@ protected function attempt_has_any_questions_with_files(int $attemptid, array $q * @param stdClass $cm the course-module settings for the quiz. * @return string suggested filename. */ - protected function generate_zip_filename(stdClass $quiz, stdClass $cm): string { + protected function generate_zip_filename(cm_info|stdClass $quiz, cm_info|stdClass $cm): string { $filename = ''; if ($cm->idnumber) { $filename = $this->clean_filename($cm->idnumber); diff --git a/submitresponses.php b/submitresponses.php index dc01220..b0683b4 100644 --- a/submitresponses.php +++ b/submitresponses.php @@ -24,6 +24,7 @@ use quiz_answersheets\report_display_options; use quiz_answersheets\utils; +use mod_quiz\quiz_attempt; require_once(__DIR__ . '/../../../../config.php'); require_once($CFG->dirroot . '/mod/quiz/locallib.php');