Skip to content

Commit

Permalink
GH-779 Overwrite scale feedback with data from template
Browse files Browse the repository at this point in the history
  • Loading branch information
davidszkiba committed Dec 20, 2024
1 parent e252818 commit 2cf93d5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
10 changes: 6 additions & 4 deletions classes/catquiz_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,18 @@ public static function instance_form_definition(MoodleQuickForm &$mform) {
// ... after this function has finished execution. submitted form.
// But the submitted via post, so we can access the variable via the superglobal $POST.

if ($chosentemplate = optional_param('choosetemplate', 0, PARAM_INT)) {
$reloadtemplate = optional_param('reloadtemplate', true, PARAM_BOOL);
$template = null;
if ($reloadtemplate && $chosentemplate = optional_param('choosetemplate', 0, PARAM_INT)) {
// Get parent scale ID from template.
$cattest = (object)[
'id' => $chosentemplate,
'component' => 'mod_adaptivequiz',
];

// Pass on the values as stdClass.
$test = new testenvironment($cattest);
$selectedparentscale = $test->return_as_array()['catscaleid'];
$template = new testenvironment($cattest);
$selectedparentscale = $template->return_as_array()['catscaleid'];
} else {
$selectedparentscale = optional_param('catquiz_catscales', 0, PARAM_INT);
}
Expand All @@ -189,7 +191,7 @@ public static function instance_form_definition(MoodleQuickForm &$mform) {
$mform->addHelpButton('catquiz_passinglevel', 'passinglevel', 'local_catquiz');
$mform->setType('catquiz_passinglevel', PARAM_INT);

info::instance_form_definition($mform, $elements);
info::instance_form_definition($mform, $elements, $template);

return $elements;
}
Expand Down
20 changes: 17 additions & 3 deletions classes/feedback/feedbackclass.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace local_catquiz\feedback;

use local_catquiz\data\dataapi;
use local_catquiz\testenvironment;
use MoodleQuickForm;
use stdClass;

Expand All @@ -41,16 +42,23 @@ class feedbackclass {
* Add Form elements to form.
* @param MoodleQuickForm $mform
* @param array $elements
* @param ?testenvironment $template
*
* @return void
*/
public static function instance_form_definition(MoodleQuickForm &$mform, array &$elements) {
public static function instance_form_definition(MoodleQuickForm &$mform, array &$elements, ?testenvironment $template) {

global $CFG, $PAGE, $OUTPUT;

require_once($CFG->libdir .'/datalib.php');

// Get all Values from the form.
$data = $mform->getSubmitValues();
// If the user just selected a template, get the values from there.
if ($template) {
$data = (array) $template->return_settings();
} else {
// Otherwise: Get all values from the existing form.
$data = $mform->getSubmitValues();
}
$defaultvalues = $mform->_defaultValues;

// phpcs:ignore
Expand All @@ -65,6 +73,9 @@ public static function instance_form_definition(MoodleQuickForm &$mform, array &
];

$selectedparentscale = optional_param('catquiz_catscales', 0, PARAM_INT);
if ($template) {
$selectedparentscale = $template->return_as_array()['catscaleid'];
}

if (!empty($selectedparentscale)) {
$scales = dataapi::get_catscale_and_children($selectedparentscale, true);
Expand Down Expand Up @@ -185,6 +196,9 @@ public static function instance_form_definition(MoodleQuickForm &$mform, array &
if (is_array($feedback)) {
$feedbacktext = $feedback['text'];
}
if (is_object($feedback)) {
$feedbacktext = $feedback->text;
}
$feedbacktext = strip_tags($feedbacktext ?? '');
}

Expand Down
6 changes: 4 additions & 2 deletions classes/teststrategy/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use cache;
use core_component;
use local_catquiz\feedback\feedbackclass;
use local_catquiz\testenvironment;
use local_catquiz\teststrategy\context\contextcreator;
use local_catquiz\teststrategy\preselect_task\firstquestionselector;
use MoodleQuickForm;
Expand Down Expand Up @@ -144,9 +145,10 @@ public static function get_teststrategy(int $id, bool $onlyactive = true) {
*
* @param MoodleQuickForm $mform
* @param array $elements
* @param ?testenvironment $template
* @return void
*/
public static function instance_form_definition(MoodleQuickForm &$mform, array &$elements) {
public static function instance_form_definition(MoodleQuickForm &$mform, array &$elements, ?testenvironment $template) {

$data = $mform->getSubmitValues();
$defaultvalues = $mform->_defaultValues;
Expand Down Expand Up @@ -433,7 +435,7 @@ public static function instance_form_definition(MoodleQuickForm &$mform, array &
);
$mform->hideIf('catquiz_questionfeedbacksettings', 'catquiz_showquestion', 'neq', 1);

feedbackclass::instance_form_definition($mform, $elements);
feedbackclass::instance_form_definition($mform, $elements, $template);
}

/**
Expand Down

0 comments on commit 2cf93d5

Please sign in to comment.