Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues of answersheets in Moodle 4.2 to 4.4 #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions attemptsheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
18 changes: 9 additions & 9 deletions classes/report_display_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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);
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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).
Expand Down
11 changes: 7 additions & 4 deletions classes/report_settings_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);

Expand Down
7 changes: 3 additions & 4 deletions classes/report_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@

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
*
* @package quiz_answersheets
* @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;
Expand Down
6 changes: 3 additions & 3 deletions classes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 4 additions & 5 deletions report.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,19 @@
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.
*
* @package quiz_answersheets
* @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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions submitresponses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down