-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from PhilippImhof/options
Add options to show/hide the history and the correct answer
- Loading branch information
Showing
6 changed files
with
177 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,18 @@ | |
*/ | ||
|
||
|
||
use mod_quiz\local\reports\attempts_report_options_form; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->libdir.'/formslib.php'); | ||
// This work-around is required until Moodle 4.2 is the lowest version we support. | ||
if (class_exists('\mod_quiz\local\reports\attempts_report_options_form')) { | ||
class_alias('\mod_quiz\local\reports\attempts_report_options_form', '\quiz_archive_settings_form_parent_class_alias'); | ||
} else { | ||
require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_form.php'); | ||
class_alias('\mod_quiz_attempts_report_form', '\quiz_archive_settings_form_parent_class_alias'); | ||
} | ||
|
||
|
||
/** | ||
* Quiz archive report settings form. | ||
|
@@ -34,14 +43,45 @@ | |
* @copyright 2018 Luca Bösch <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class quiz_archive_settings_form extends moodleform { | ||
class quiz_archive_settings_form extends quiz_archive_settings_form_parent_class_alias { | ||
|
||
/** | ||
* Definition of our form. Overriding parent method, because our form is much simpler | ||
* and does not have multiple sections. | ||
* | ||
* @return void | ||
*/ | ||
protected function definition() { | ||
$mform = $this->_form; | ||
|
||
$mform->addElement('header', 'preferencesuser', get_string('reportdisplayoptions', 'quiz')); | ||
|
||
$this->standard_preference_fields($mform); | ||
|
||
$mform->addElement('submit', 'submitbutton', get_string('showreport', 'quiz')); | ||
} | ||
|
||
/** | ||
* Called to define this moodle form. | ||
* Override parent function. Our form currently only has two checkboxes, so their | ||
* data is always valid or could at least be converted to valid values. | ||
* | ||
* @param mixed $data | ||
* @param mixed $files | ||
* @return array | ||
*/ | ||
public function validation($data, $files) { | ||
return []; | ||
} | ||
|
||
/** | ||
* Add the preference fields that we offer. | ||
* | ||
* @param MoodleQuickForm $mform the form | ||
* @return void | ||
*/ | ||
public function definition() { | ||
$mform =& $this->_form; | ||
protected function standard_preference_fields(MoodleQuickForm $mform) { | ||
$mform->addElement('advcheckbox', 'showhistory', get_string('includehistory', 'quiz_archive')); | ||
$mform->addElement('advcheckbox', 'showright', get_string('includecorrectanswer', 'quiz_archive')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,82 +22,32 @@ | |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
use mod_quiz\local\reports\attempts_report_options; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
// This work-around is required until Moodle 4.2 is the lowest version we support. | ||
if (class_exists('\mod_quiz\local\reports\attempts_report_options')) { | ||
class_alias('\mod_quiz\local\reports\attempts_report_options', '\quiz_archive_options_parent_class_alias'); | ||
} else { | ||
require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_options.php'); | ||
class_alias('\mod_quiz_attempts_report_options', '\quiz_archive_options_parent_class_alias'); | ||
} | ||
|
||
/** | ||
* Class to store the options for a {@see quiz_archive_report}. | ||
* | ||
* @package quiz_archive | ||
* @copyright 2018 Luca Bösch <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class quiz_archive_options extends mod_quiz_attempts_report_options { | ||
|
||
/** @var string the report mode. */ | ||
public $mode; | ||
|
||
/** @var object the settings for the quiz being reported on. */ | ||
public $quiz; | ||
|
||
/** @var object the course module objects for the quiz being reported on. */ | ||
public $cm; | ||
|
||
/** @var object the course settings for the course the quiz is in. */ | ||
public $course; | ||
|
||
/** | ||
* @var array form field name => corresponding quiz_attempt:: state constant. | ||
*/ | ||
protected static $statefields = [ | ||
'stateinprogress' => quiz_attempt::IN_PROGRESS, | ||
'stateoverdue' => quiz_attempt::OVERDUE, | ||
'statefinished' => quiz_attempt::FINISHED, | ||
'stateabandoned' => quiz_attempt::ABANDONED, | ||
]; | ||
class quiz_archive_options extends quiz_archive_options_parent_class_alias { | ||
|
||
/** | ||
* @var string quiz_attempts_report::ALL_WITH or quiz_attempts_report::ENROLLED_WITH | ||
* quiz_attempts_report::ENROLLED_WITHOUT or quiz_attempts_report::ENROLLED_ALL | ||
*/ | ||
public $attempts = quiz_attempts_report::ENROLLED_WITH; | ||
/** @var bool whether to show the correct response. */ | ||
public $showright = true; | ||
|
||
/** @var int the currently selected group. 0 if no group is selected. */ | ||
public $group = 0; | ||
|
||
/** | ||
* @var array|null of quiz_attempt::IN_PROGRESS, etc. constants. null means | ||
* no restriction. | ||
*/ | ||
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 | ||
* the final grade for the user. | ||
*/ | ||
public $onlygraded = false; | ||
|
||
/** @var int Number of attempts to show per page. */ | ||
public $pagesize = quiz_attempts_report::DEFAULT_PAGE_SIZE; | ||
|
||
/** @var string whether the data should be downloaded in some format, or '' to display it. */ | ||
public $download = ''; | ||
|
||
/** @var bool whether the current user has permission to see grades. */ | ||
public $usercanseegrades; | ||
|
||
/** @var bool whether the report table should have a column of checkboxes. */ | ||
public $checkboxcolumn = false; | ||
|
||
/** @var bool whether to show the question text columns. */ | ||
public $showqtext = false; | ||
|
||
/** @var bool whether to show the students' response columns. */ | ||
public $showresponses = true; | ||
|
||
/** @var bool whether to show the correct response columns. */ | ||
public $showright = false; | ||
|
||
/** @var bool which try/tries to show responses from. */ | ||
public $whichtries = question_attempt::LAST_TRY; | ||
/** @var bool whether to show the history. */ | ||
public $showhistory = true; | ||
|
||
/** | ||
* Constructor. | ||
|
@@ -111,51 +61,16 @@ public function __construct($mode, $quiz, $cm, $course) { | |
$this->quiz = $quiz; | ||
$this->cm = $cm; | ||
$this->course = $course; | ||
|
||
$this->usercanseegrades = quiz_report_should_show_grades($quiz, context_module::instance($cm->id)); | ||
} | ||
|
||
/** | ||
* Get the URL to show the report with these options. | ||
* @return moodle_url the URL. | ||
*/ | ||
public function get_url() { | ||
return new moodle_url('/mod/quiz/report.php', $this->get_url_params()); | ||
} | ||
|
||
/** | ||
* Get the URL parameters required to show the report with these options. | ||
* @return array URL parameter name => value. | ||
*/ | ||
protected function get_url_params() { | ||
$params = [ | ||
'id' => $this->cm->id, | ||
'mode' => $this->mode, | ||
'attempts' => $this->attempts, | ||
'onlygraded' => $this->onlygraded, | ||
]; | ||
|
||
if ($this->states) { | ||
$params['states'] = implode('-', $this->states); | ||
} | ||
|
||
if (groups_get_activity_groupmode($this->cm, $this->course)) { | ||
$params['group'] = $this->group; | ||
} | ||
return $params; | ||
} | ||
|
||
/** | ||
* Get the current value of the settings to pass to the settings form. | ||
*/ | ||
public function get_initial_form_data() { | ||
$toform = parent::get_initial_form_data(); | ||
$toform->qtext = $this->showqtext; | ||
$toform->resp = $this->showresponses; | ||
$toform->right = $this->showright; | ||
if (quiz_allows_multiple_tries($this->quiz)) { | ||
$toform->whichtries = $this->whichtries; | ||
} | ||
$toform = new stdClass(); | ||
|
||
$toform->showright = $this->showright; | ||
$toform->showhistory = $this->showhistory; | ||
|
||
return $toform; | ||
} | ||
|
@@ -165,74 +80,35 @@ public function get_initial_form_data() { | |
* @param object $fromform The data from $mform->get_data() from the settings form. | ||
*/ | ||
public function setup_from_form_data($fromform) { | ||
parent::setup_from_form_data($fromform); | ||
|
||
$this->showqtext = $fromform->qtext; | ||
$this->showresponses = $fromform->resp; | ||
$this->showright = $fromform->right; | ||
if (quiz_allows_multiple_tries($this->quiz)) { | ||
$this->whichtries = $fromform->whichtries; | ||
} | ||
$this->showright = $fromform->showright; | ||
$this->showhistory = $fromform->showhistory; | ||
} | ||
|
||
/** | ||
* Set the fields of this object from the URL parameters. | ||
*/ | ||
public function setup_from_params() { | ||
parent::setup_from_params(); | ||
|
||
$this->showqtext = optional_param('qtext', $this->showqtext, PARAM_BOOL); | ||
$this->showresponses = optional_param('resp', $this->showresponses, PARAM_BOOL); | ||
$this->showright = optional_param('right', $this->showright, PARAM_BOOL); | ||
if (quiz_allows_multiple_tries($this->quiz)) { | ||
$this->whichtries = optional_param('whichtries', $this->whichtries, PARAM_ALPHA); | ||
} | ||
$this->showright = optional_param('right', $this->showright, PARAM_BOOL); | ||
$this->showhistory = optional_param('history', $this->showhistory, PARAM_BOOL); | ||
} | ||
|
||
/** | ||
* Set the fields of this object from the user's preferences. | ||
* (For those settings that are backed by user-preferences). | ||
* Override parent method, because we do not have settings that are backed by | ||
* user-preferences. | ||
*/ | ||
public function setup_from_user_preferences() { | ||
parent::setup_from_user_preferences(); | ||
|
||
$this->showqtext = get_user_preferences('quiz_report_archive_qtext', $this->showqtext); | ||
$this->showresponses = get_user_preferences('quiz_report_archive_resp', $this->showresponses); | ||
$this->showright = get_user_preferences('quiz_report_archive_right', $this->showright); | ||
if (quiz_allows_multiple_tries($this->quiz)) { | ||
$this->whichtries = get_user_preferences('quiz_report_archive_which_tries', $this->whichtries); | ||
} | ||
} | ||
|
||
/** | ||
* Update the user preferences so they match the settings in this object. | ||
* (For those settings that are backed by user-preferences). | ||
* Override parent method, because we do not have settings that are backed by | ||
* user-preferences. | ||
*/ | ||
public function update_user_preferences() { | ||
parent::update_user_preferences(); | ||
|
||
set_user_preference('quiz_report_archive_qtext', $this->showqtext); | ||
set_user_preference('quiz_report_archive_resp', $this->showresponses); | ||
set_user_preference('quiz_report_archive_right', $this->showright); | ||
if (quiz_allows_multiple_tries($this->quiz)) { | ||
set_user_preference('quiz_report_archive_which_tries', $this->whichtries); | ||
} | ||
} | ||
|
||
/** | ||
* Check the settings, and remove any 'impossible' combinations. | ||
* Override parent method, because our settings cannot be incompatible. | ||
*/ | ||
public function resolve_dependencies() { | ||
parent::resolve_dependencies(); | ||
|
||
if (!$this->showqtext && !$this->showresponses && !$this->showright) { | ||
// We have to show at least something. | ||
$this->showresponses = true; | ||
} | ||
|
||
// 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.