first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,106 @@
<?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/>.
namespace qbank_previewquestion\form;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
use moodleform;
use question_display_options;
use question_engine;
use qbank_previewquestion\question_preview_options;
/**
* Settings form for the preview options.
*
* @package qbank_previewquestion
* @copyright 2009 The Open University
* @author 2021 Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class preview_options_form extends moodleform {
public function definition() {
$mform = $this->_form;
$hiddenorvisible = [
question_display_options::HIDDEN => get_string('notshown', 'question'),
question_display_options::VISIBLE => get_string('shown', 'question'),
];
$mform->addElement('header', 'attemptoptionsheader', get_string('previewoptions', 'qbank_previewquestion'));
$mform->setExpanded('attemptoptionsheader', false);
// Add html element with class to display long text in single line.
$mform->addElement('html', \html_writer::div(get_string('theoptionsyouselectonlyaffectthepreview',
'qbank_previewquestion'), "col-md-12 row d-flex col-form-label mb-3"));
$versions = $this->_customdata['versions'];
$versions[question_preview_options::ALWAYS_LATEST] = get_string('alwayslatest', 'qbank_previewquestion');
$currentversion = $this->_customdata['restartversion'];
$select = $mform->addElement('select', 'restartversion', get_string('questionversion', 'qbank_previewquestion'), $versions);
$select->setSelected($currentversion);
$behaviours = question_engine::get_behaviour_options(
$this->_customdata['quba']->get_preferred_behaviour());
$mform->addElement('select', 'behaviour',
get_string('howquestionsbehave', 'question'), $behaviours);
$mform->addHelpButton('behaviour', 'howquestionsbehave', 'question');
$mform->addElement('float', 'maxmark', get_string('markedoutof', 'question'), ['size' => '5']);
if ($this->_customdata['maxvariant'] > 1) {
$variants = range(1, $this->_customdata['maxvariant']);
$mform->addElement('select', 'variant', get_string('questionvariant', 'question'),
array_combine($variants, $variants));
}
$mform->setType('variant', PARAM_INT);
$mform->addElement('submit', 'saverestart',
get_string('restartwiththeseoptions', 'question'));
$mform->addElement('header', 'displayoptionsheader', get_string('displayoptions', 'question'));
$mform->setExpanded('displayoptionsheader', false);
$mform->addElement('select', 'correctness', get_string('whethercorrect', 'question'),
$hiddenorvisible);
$marksoptions = [
question_display_options::HIDDEN => get_string('notshown', 'question'),
question_display_options::MAX_ONLY => get_string('showmaxmarkonly', 'question'),
question_display_options::MARK_AND_MAX => get_string('showmarkandmax', 'question'),
];
$mform->addElement('select', 'marks', get_string('marks', 'question'), $marksoptions);
$mform->addElement('select', 'markdp', get_string('decimalplacesingrades', 'question'),
question_engine::get_dp_options());
$mform->addElement('select', 'feedback',
get_string('specificfeedback', 'question'), $hiddenorvisible);
$mform->addElement('select', 'generalfeedback',
get_string('generalfeedback', 'question'), $hiddenorvisible);
$mform->addElement('select', 'rightanswer',
get_string('rightanswer', 'question'), $hiddenorvisible);
$mform->addElement('select', 'history',
get_string('responsehistory', 'question'), $hiddenorvisible);
$mform->addElement('submit', 'saveupdate',
get_string('updatedisplayoptions', 'question'));
}
}
@@ -0,0 +1,339 @@
<?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/>.
namespace qbank_previewquestion;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/question/editlib.php');
use action_menu;
use comment;
use context_module;
use context;
use core\plugininfo\qbank;
use core_question\local\bank\edit_menu_column;
use core_question\local\bank\view;
use core_question\local\bank\question_edit_contexts;
use moodle_url;
use question_bank;
use question_definition;
use question_display_options;
use question_engine;
use stdClass;
/**
* Class helper contains all the helper functions.
*
* @package qbank_previewquestion
* @copyright 2010 The Open University
* @author 2021 Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class helper {
/**
* Called via pluginfile.php -> question_pluginfile to serve files belonging to
* a question in a question_attempt when that attempt is a preview.
*
* @param stdClass $course course settings object
* @param stdClass $context context object
* @param string $component the name of the component we are serving files for.
* @param string $filearea the name of the file area.
* @param int $qubaid the question_usage this image belongs to.
* @param int $slot the relevant slot within the usage.
* @param array $args the remaining bits of the file path.
* @param bool $forcedownload whether the user must be forced to download the file.
* @param array $fileoptions options for the stored files
* @return void false if file not found, does not return if found - justsend the file
*/
public static function question_preview_question_pluginfile($course, $context, $component,
$filearea, $qubaid, $slot, $args, $forcedownload, $fileoptions): void {
global $USER, $DB, $CFG;
list($context, $course, $cm) = get_context_info_array($context->id);
require_login($course, false, $cm);
$quba = question_engine::load_questions_usage_by_activity($qubaid);
if (!question_has_capability_on($quba->get_question($slot, false), 'use')) {
send_file_not_found();
}
$options = new question_display_options();
$options->feedback = question_display_options::VISIBLE;
$options->numpartscorrect = question_display_options::VISIBLE;
$options->generalfeedback = question_display_options::VISIBLE;
$options->rightanswer = question_display_options::VISIBLE;
$options->manualcomment = question_display_options::VISIBLE;
$options->history = question_display_options::VISIBLE;
if (!$quba->check_file_access($slot, $options, $component,
$filearea, $args, $forcedownload)) {
send_file_not_found();
}
$fs = get_file_storage();
$relativepath = implode('/', $args);
$fullpath = "/{$context->id}/{$component}/{$filearea}/{$relativepath}";
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
send_file_not_found();
}
send_stored_file($file, 0, 0, $forcedownload, $fileoptions);
}
/**
* The the URL to use for actions relating to this preview.
*
* @param int $questionid the question being previewed
* @param int $qubaid the id of the question usage for this preview
* @param question_preview_options $options the options in use
* @param context $context context for the question preview
* @param moodle_url $returnurl url of the page to return to
* @param int|null $restartversion version of the question to use when next restarting the preview.
* @return moodle_url
*/
public static function question_preview_action_url($questionid, $qubaid,
question_preview_options $options, $context, $returnurl = null, $restartversion = null): moodle_url {
$params = [
'id' => $questionid,
'previewid' => $qubaid,
];
if ($context->contextlevel == CONTEXT_MODULE) {
$params['cmid'] = $context->instanceid;
} else if ($context->contextlevel == CONTEXT_COURSE) {
$params['courseid'] = $context->instanceid;
}
if ($returnurl !== null) {
$params['returnurl'] = $returnurl;
}
if ($restartversion !== null) {
$params['restartversion'] = $restartversion;
}
$params = array_merge($params, $options->get_url_params());
return new moodle_url('/question/bank/previewquestion/preview.php', $params);
}
/**
* The the URL to use for actions relating to this preview.
*
* @param int $questionid the question being previewed
* @param context $context the current moodle context
* @param int $previewid optional previewid to sign post saved previewed answers
* @param moodle_url $returnurl url of the page to return to
* @return moodle_url
*/
public static function question_preview_form_url($questionid, $context, $previewid = null, $returnurl = null): moodle_url {
$params = [
'id' => $questionid,
];
if ($context->contextlevel == CONTEXT_MODULE) {
$params['cmid'] = $context->instanceid;
} else if ($context->contextlevel == CONTEXT_COURSE) {
$params['courseid'] = $context->instanceid;
}
if ($previewid) {
$params['previewid'] = $previewid;
}
if ($returnurl !== null) {
$params['returnurl'] = $returnurl;
}
return new moodle_url('/question/bank/previewquestion/preview.php', $params);
}
/**
* Delete the current preview, if any, and redirect to start a new preview.
*
* @param int $previewid id of the preview while restarting it
* @param int $questionid id of the question in preview
* @param object $displayoptions display options for the question in preview
* @param object $context context of the question for preview
* @param moodle_url $returnurl url of the page to return to
* @param int|null $restartversion version of the question to use when next restarting the preview.
* @return void
*/
public static function restart_preview($previewid, $questionid, $displayoptions, $context,
$returnurl = null, $restartversion = null): void {
global $DB;
if ($previewid) {
$transaction = $DB->start_delegated_transaction();
question_engine::delete_questions_usage_by_activity($previewid);
$transaction->allow_commit();
}
redirect(self::question_preview_url($questionid, $displayoptions->behaviour,
$displayoptions->maxmark, $displayoptions, $displayoptions->variant,
$context, $returnurl, $restartversion));
}
/**
* Generate the URL for starting a new preview of a given question with the given options.
*
* @param integer $questionid the question to preview
* @param string $preferredbehaviour the behaviour to use for the preview
* @param float $maxmark the maximum to mark the question out of
* @param question_display_options $displayoptions the display options to use
* @param int $variant the variant of the question to preview. If null, one will
* be picked randomly
* @param object $context context to run the preview in (affects things like
* filter settings, theme, lang, etc.) Defaults to $PAGE->context
* @param moodle_url $returnurl url of the page to return to
* @param int $restartversion The version of the question to use when restarting the preview.
* @return moodle_url the URL
*/
public static function question_preview_url($questionid, $preferredbehaviour = null,
$maxmark = null, $displayoptions = null, $variant = null, $context = null, $returnurl = null,
$restartversion = null): moodle_url {
$params = ['id' => $questionid];
if (!is_null($restartversion)) {
$params['restartversion'] = $restartversion;
}
if (is_null($context)) {
global $PAGE;
$context = $PAGE->context;
}
if ($context->contextlevel == CONTEXT_MODULE) {
$params['cmid'] = $context->instanceid;
} else if ($context->contextlevel == CONTEXT_COURSE) {
$params['courseid'] = $context->instanceid;
}
if (!is_null($preferredbehaviour)) {
$params['behaviour'] = $preferredbehaviour;
}
if (!is_null($maxmark)) {
$params['maxmark'] = format_float($maxmark, -1);
}
if (!is_null($displayoptions)) {
$params['correctness'] = $displayoptions->correctness;
$params['marks'] = $displayoptions->marks;
$params['markdp'] = $displayoptions->markdp;
$params['feedback'] = (bool) $displayoptions->feedback;
$params['generalfeedback'] = (bool) $displayoptions->generalfeedback;
$params['rightanswer'] = (bool) $displayoptions->rightanswer;
$params['history'] = (bool) $displayoptions->history;
}
if (!is_null($returnurl)) {
$params['returnurl'] = $returnurl;
}
if ($variant) {
$params['variant'] = $variant;
}
return new moodle_url('/question/bank/previewquestion/preview.php', $params);
}
/**
* Popup params for the question preview.
*
* @return array that can be passed as $params to the {@see popup_action} constructor.
*/
public static function question_preview_popup_params(): array {
return [
'height' => 600,
'width' => 800,
];
}
/**
* Get the extra elements for preview from qbank plugins.
*
* @param question_definition $question question definition object
* @param int $courseid id of the course
* @return array
*/
public static function get_preview_extra_elements(question_definition $question, int $courseid): array {
$plugins = get_plugin_list_with_function('qbank', 'preview_display');
$comment = '';
$extrahtml = [];
foreach ($plugins as $componentname => $plugin) {
$pluginhtml = component_callback($componentname, 'preview_display', [$question, $courseid]);
if ($componentname === 'qbank_comment') {
$comment = $pluginhtml;
continue;
}
$extrahtml[] = $pluginhtml;
}
return [$comment, $extrahtml];
}
/**
* Checks if question is the latest version.
*
* @param string $version Question version to check
* @param string $questionbankentryid Entry to check against
* @return bool
*/
public static function is_latest(string $version, string $questionbankentryid): bool {
global $DB;
$sql = 'SELECT MAX(version) AS max
FROM {question_versions}
WHERE questionbankentryid = ?';
$latestversion = $DB->get_record_sql($sql, [$questionbankentryid]);
if (isset($latestversion->max)) {
return ($version === $latestversion->max) ? true : false;
}
return false;
}
/**
* Loads question version ids for current question.
*
* @param string $questionbankentryid Question bank entry id
* @return array $questionids Array containing question id as key and version as value.
*/
public static function load_versions(string $questionbankentryid): array {
global $DB;
$questionids = [];
$sql = 'SELECT version, questionid
FROM {question_versions}
WHERE questionbankentryid = ?
ORDER BY version';
$versions = $DB->get_records_sql($sql, [$questionbankentryid]);
foreach ($versions as $key => $version) {
$questionids[$version->questionid] = $key;
}
return $questionids;
}
/**
* Return the question ID from the array of id => version that corresponds to the requested version.
*
* If the requested version is question_preview_options::ALWAYS_LATEST, this will return the latest version.
*
* @param array $versions
* @param int $restartversion
* @return ?int
*/
public static function get_restart_id(array $versions, int $restartversion): ?int {
if ($restartversion === question_preview_options::ALWAYS_LATEST) {
return array_key_last($versions);
} else {
return array_search($restartversion, $versions) ?: null;
}
}
}
@@ -0,0 +1,70 @@
<?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/>.
namespace qbank_previewquestion\output;
use context;
use qbank_previewquestion\helper;
use qbank_previewquestion\question_preview_options;
/**
* Class renderer for rendering preview url
*
* @package qbank_previewquestion
* @copyright 2009 The Open University
* @author 2021 Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends \plugin_renderer_base {
/**
* Render an icon, optionally with the word 'Preview' beside it, to preview a given question.
*
* @param int $questionid the id of the question to be previewed.
* @param context $context the context in which the preview is happening.
* Must be a course or category context.
* @param bool $showlabel if true, show the word 'Preview' after the icon.
* If false, just show the icon.
*/
public function question_preview_link($questionid, context $context, $showlabel) {
if ($showlabel) {
$alt = '';
$label = get_string('preview');
$attributes = [];
} else {
$alt = get_string('preview');
$label = '';
$attributes = ['title' => $alt];
}
$image = $this->pix_icon('t/preview', $alt, '', ['class' => 'iconsmall']);
$link = helper::question_preview_url($questionid, null, null, null, null, $context, null,
question_preview_options::ALWAYS_LATEST);
$action = new \popup_action('click', $link, 'questionpreview', helper::question_preview_popup_params());
return $this->action_link($link, $image . $label, $action, $attributes);
}
/**
* Render the preview page.
*
* @param array $previewdata
*/
public function render_preview_page($previewdata) {
return $this->render_from_template('qbank_previewquestion/preview_question', $previewdata);
}
}
@@ -0,0 +1,34 @@
<?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/>.
namespace qbank_previewquestion;
/**
* Class columns is the entrypoint for the columns.
*
* @package qbank_previewquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class plugin_feature extends \core_question\local\bank\plugin_features_base{
public function get_question_actions($qbank): array {
return [
new preview_action($qbank)
];
}
}
@@ -0,0 +1,69 @@
<?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/>.
namespace qbank_previewquestion;
use core_question\local\bank\question_action_base;
/**
* Question bank columns for the preview action icon.
*
* @package qbank_previewquestion
* @copyright 2009 Tim Hunt
* @author 2021 Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class preview_action extends question_action_base {
/**
* @var string store this lang string for performance.
*/
protected $strpreview;
public function init(): void {
parent::init();
$this->strpreview = get_string('preview');
}
public function get_menu_position(): int {
return 100;
}
protected function get_url_icon_and_label(\stdClass $question): array {
if (!\question_bank::is_qtype_installed($question->qtype)) {
// It sometimes happens that people end up with junk questions
// in their question bank of a type that is no longer installed.
// We cannot do most actions on them, because that leads to errors.
return [null, null, null];
}
if (question_has_capability_on($question, 'use')) {
$context = $this->qbank->get_most_specific_context();
// Default previews to always use the latest question version, unless we are previewing specific versions from the
// question history.
if ($this->qbank->is_listing_specific_versions()) {
$requestedversion = $question->version;
} else {
$requestedversion = question_preview_options::ALWAYS_LATEST;
}
$url = helper::question_preview_url($question->id, null, null,
null, null, $context, $this->qbank->returnurl, $requestedversion);
return [$url, 't/preview', $this->strpreview];
} else {
return [null, null, null];
}
}
}
@@ -0,0 +1,32 @@
<?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/>.
namespace qbank_previewquestion\privacy;
/**
* Privacy Subsystem for qbank_previewquestion implementing null_provider.
*
* @package qbank_previewquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
@@ -0,0 +1,144 @@
<?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/>.
namespace qbank_previewquestion;
use question_display_options;
/**
* Displays question preview options as default and set the options.
*
* Setting default, getting and setting user preferences in question preview options.
*
* @package qbank_previewquestion
* @copyright 2010 The Open University
* @author 2021 Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class question_preview_options extends question_display_options {
/** @var string the behaviour to use for this preview. */
public $behaviour;
/** @var number the maximum mark to use for this preview. */
public $maxmark;
/** @var int the variant of the question to preview. */
public $variant;
/** @var string prefix to append to field names to get user_preference names. */
const OPTIONPREFIX = 'question_preview_options_';
/** @var int Special value for question version ID to indicate that we should always use the latest version */
const ALWAYS_LATEST = 0;
/**
* Constructor.
* @param \stdClass $question
*/
public function __construct($question) {
$this->behaviour = 'deferredfeedback';
$this->maxmark = $question->defaultmark;
$this->variant = null;
$this->correctness = self::VISIBLE;
$this->marks = self::MARK_AND_MAX;
$this->markdp = get_config('quiz', 'decimalpoints');
$this->feedback = self::VISIBLE;
$this->numpartscorrect = $this->feedback;
$this->generalfeedback = self::VISIBLE;
$this->rightanswer = self::VISIBLE;
$this->history = self::HIDDEN;
$this->flags = self::HIDDEN;
$this->manualcomment = self::HIDDEN;
}
/**
* Names of the options we store in the user preferences table.
* @return array
*/
protected function get_user_pref_fields(): array {
return ['behaviour', 'correctness', 'marks', 'markdp', 'feedback', 'generalfeedback', 'rightanswer', 'history'];
}
/**
* Names and param types of the options we read from the request.
* @return array
*/
protected function get_field_types(): array {
return [
'behaviour' => PARAM_ALPHA,
'maxmark' => PARAM_LOCALISEDFLOAT,
'variant' => PARAM_INT,
'correctness' => PARAM_BOOL,
'marks' => PARAM_INT,
'markdp' => PARAM_INT,
'feedback' => PARAM_BOOL,
'generalfeedback' => PARAM_BOOL,
'rightanswer' => PARAM_BOOL,
'history' => PARAM_BOOL,
];
}
/**
* Load the value of the options from the user_preferences table.
*/
public function load_user_defaults(): void {
$defaults = get_config('question_preview');
foreach ($this->get_user_pref_fields() as $field) {
$this->$field = get_user_preferences(
self::OPTIONPREFIX . $field, $defaults->$field);
}
$this->numpartscorrect = $this->feedback;
}
/**
* Save a change to the user's preview options to the database.
* @param object $newoptions
*/
public function save_user_preview_options($newoptions): void {
foreach ($this->get_user_pref_fields() as $field) {
if (isset($newoptions->$field)) {
set_user_preference(self::OPTIONPREFIX . $field, $newoptions->$field);
}
}
}
/**
* Set the value of any fields included in the request.
*/
public function set_from_request(): void {
foreach ($this->get_field_types() as $field => $type) {
$this->$field = optional_param($field, $this->$field, $type);
}
$this->numpartscorrect = $this->feedback;
}
/**
* Parameters needed in the URL when continuing this preview.
*
* @return array URL fragment.
*/
public function get_url_params(): array {
$params = [];
foreach ($this->get_field_types() as $field => $notused) {
if ($field === 'behaviour' || $field === 'maxmark' || is_null($this->$field)) {
continue;
}
$params[$field] = $this->$field;
}
return $params;
}
}