Skip to content

Commit

Permalink
GH-445 Add settings to control question feedback
Browse files Browse the repository at this point in the history
Adds some checkboxes to the quiz settings to control whether to add
detailed question feedback and how it will be displayed.

It is possible to enable/disable display of the correct response and to
show or hide an indicator about the correctness of the given response.
  • Loading branch information
davidszkiba committed Oct 18, 2024
1 parent 09ee632 commit ad3d89e
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 16 deletions.
2 changes: 1 addition & 1 deletion amd/build/graphicalsummary.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/graphicalsummary.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions amd/src/graphicalsummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ import {addIconToContainerWithPromise} from 'core/loadingicon';
*/
export const init = async () => {
const urlParams = new URLSearchParams(window.location.search);
const attemptid = urlParams.get('attempt');
const instanceid = urlParams.get('instance');
const attemptid = urlParams.get('attempt') ?? urlParams.get('attemptid');
const rows = document.querySelectorAll('tr>td>.clickable');
rows.forEach(row => {
row.addEventListener('click', async function() {
// Show loader icon until we have the question.
let iconPromise = addIconToContainerWithPromise(row);
const slot = this.getAttribute('data-slot');
const questiondata = await fetchQuestionData(slot, attemptid, instanceid);
const questiondata = await fetchQuestionData(slot, attemptid);
// Hide the loader icon by resolving it.
iconPromise.resolve();
const modal = await ModalFactory.create({
Expand All @@ -53,16 +52,14 @@ export const init = async () => {
/**
* @param {integer} slot Question slot
* @param {integer} attemptid The attempt ID
* @param {integer} instanceid The instance ID
* @return string
*/
const fetchQuestionData = async (slot, attemptid, instanceid) => {
const fetchQuestionData = async (slot, attemptid) => {
let data = await Ajax.call([{
methodname: 'local_catquiz_render_question_with_response',
args: {
slot: slot,
attemptid: attemptid,
instanceid: instanceid,
}
}])[0];
return {
Expand Down
34 changes: 27 additions & 7 deletions classes/external/render_question_with_response.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
use external_api;
use external_value;
use external_single_structure;
use local_catquiz\catquiz_test;
use local_catquiz\testenvironment;
use qbank_previewquestion\question_preview_options;
use question_bank;
use question_display_options;
Expand Down Expand Up @@ -61,7 +63,6 @@ public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'slot' => new external_value(PARAM_INT, 'Slot'),
'attemptid' => new external_value(PARAM_INT, 'Attempt ID'),
'instanceid' => new external_value(PARAM_INT, 'Instance ID'),
]
);
}
Expand All @@ -71,19 +72,17 @@ public static function execute_parameters(): external_function_parameters {
*
* @param int $slot
* @param int $attemptid
* @param int $instanceid
* @param string $label
*
* @return array
*/
public static function execute(int $slot, int $attemptid, int $instanceid): array {
public static function execute(int $slot, int $attemptid): array {
self::validate_parameters(self::execute_parameters(), [
'slot' => $slot,
'attemptid' => $attemptid,
'instanceid' => $instanceid,
]);

$questionhtml = self::render_question($slot, $attemptid, $instanceid);
$questionhtml = self::render_question($slot, $attemptid);

return [
'questionhtml' => $questionhtml['body'],
Expand All @@ -101,20 +100,41 @@ public static function execute_returns(): external_single_structure {
]);
}

private static function render_question(int $slot, int $attemptid, int $instanceid): array {
private static function render_question(int $slot, int $attemptid): array {
global $DB, $PAGE;
$attempt = $DB->get_record('adaptivequiz_attempt', ['id' => $attemptid]);
$instanceid = $attempt->instance;
require_login();
$cm = get_coursemodule_from_instance('adaptivequiz', $instanceid);
$context = context_module::instance($cm->id);
$PAGE->set_context($context);
// Get the question attempt.
$uniqueid = $DB->get_field('adaptivequiz_attempt', 'uniqueid', ['id' => $attemptid]);
$uniqueid = $attempt->uniqueid;
$quba = question_engine::load_questions_usage_by_activity($uniqueid);

// Get the question settings for this quiz.
$data = (object)['componentid' => $instanceid, 'component' => 'mod_adaptivequiz'];
$testenvironment = new testenvironment($data);
$testsettings = $testenvironment->return_settings();

// Render the question.
$displayoptions = new question_display_options();
$displayoptions->readonly = true; // Set to false if you want the question to be interactive.
$displayoptions->marks = question_display_options::MARK_AND_MAX;
// Show an indicator if the given response was correct or wrong.
$showresponse = boolval($testsettings->catquiz_questionfeedbacksettings->catquiz_showquestionresponse)
? question_display_options::VISIBLE
: question_display_options::HIDDEN;
$showrightanswer = boolval($testsettings->catquiz_questionfeedbacksettings->catquiz_showquestioncorrectresponse)
? question_display_options::VISIBLE
: question_display_options::HIDDEN;
$showfeedback = boolval($testsettings->catquiz_questionfeedbacksettings->catquiz_showquestionfeedback)
? question_display_options::VISIBLE
: question_display_options::HIDDEN;
$displayoptions->correctness = $showresponse;
$displayoptions->rightanswer = $showrightanswer;
$displayoptions->generalfeedback = $showfeedback;
$displayoptions->feedback = $showfeedback;

$html = $quba->render_question($slot, $displayoptions);

Expand Down
8 changes: 7 additions & 1 deletion classes/teststrategy/feedbackgenerator/graphicalsummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ public function get_studentfeedback(array $feedbackdata): array {
);
}
if (isset($feedbackdata['graphicalsummary_data'])) {
$table = $this->render_table($feedbackdata['graphicalsummary_data']);
$showquestions = boolval(
$this
->get_progress()
->get_quiz_settings()
->catquiz_showquestion
);
$table = $this->render_table($feedbackdata['graphicalsummary_data'], $showquestions);
}
$globalscale = catscale::return_catscale_object($this->get_progress()->get_quiz_settings()->catquiz_catscales);
$globalscalename = $globalscale->name;
Expand Down
31 changes: 31 additions & 0 deletions classes/teststrategy/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,37 @@ public static function instance_form_definition(MoodleQuickForm &$mform, array &
$mform->setType('catquiz_maxtimeperitem', PARAM_INT);
$mform->hideIf('catquiz_timelimitgroup', 'catquiz_includetimelimit', 'neq', 1);


$elements[] = $mform->addElement(
'advcheckbox',
'catquiz_showquestion',
get_string('questionfeedbackshow', 'local_catquiz')
);
$feedbackgroup = [
$mform->createElement(
'advcheckbox',
'catquiz_showquestionresponse',
get_string('questionfeedbackshowresponse', 'local_catquiz')
),
$mform->createElement(
'advcheckbox',
'catquiz_showquestioncorrectresponse',
get_string('questionfeedbackshowcorrectresponse', 'local_catquiz')
),
$mform->createElement(
'advcheckbox',
'catquiz_showquestionfeedback',
get_string('questionfeedbackshowfeedback', 'local_catquiz')
),
];
$elements[] = $mform->addGroup(
$feedbackgroup,
'catquiz_questionfeedbacksettings',
get_string('questionfeedbacksettings', 'local_catquiz')
);
$mform->hideIf('catquiz_questionfeedbacksettings', 'catquiz_showquestion', 'neq', 1);


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

Expand Down
5 changes: 5 additions & 0 deletions lang/de/local_catquiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@
$string['progress'] = 'Entwicklung Fähigkeits-Wert in „{$a}“';
$string['questioncategories'] = 'Fragekategorien';
$string['questioncontextattempts'] = '# Testversuche im ausgewählten Einsatz-Kontext';
$string['questionfeedbacksettings'] = 'Einstellungen zu Frage-Rückmeldungen';
$string['questionfeedbackshow'] = 'Rückmeldung über gegebene Antworten anzeigen';
$string['questionfeedbackshowcorrectresponse'] = 'Korrekte Antwort anzeigen';
$string['questionfeedbackshowfeedback'] = 'Fragefeedback anzeigen';
$string['questionfeedbackshowresponse'] = 'Indikator zur Korrektheit der gegebenen Antwort anzeigen';
$string['questionpreview'] = 'Fragevorschau';
$string['questionresults'] = 'Fragen Auswertung';
$string['questions'] = 'Fragen';
Expand Down
5 changes: 5 additions & 0 deletions lang/en/local_catquiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@
$string['progress'] = 'Progress of your ability score in “{$a}”';
$string['questioncategories'] = 'Question category';
$string['questioncontextattempts'] = '# Attempts in selected context';
$string['questionfeedbacksettings'] = 'Feedback settings for given responses';
$string['questionfeedbackshow'] = 'Show feedback for given responses';
$string['questionfeedbackshowcorrectresponse'] = 'Display correct response';
$string['questionfeedbackshowfeedback'] = 'Display question feedback';
$string['questionfeedbackshowresponse'] = 'Indicate correctness of the given response';
$string['questionpreview'] = 'Question preview';
$string['questionresults'] = 'Question results';
$string['questions'] = 'Questions';
Expand Down

0 comments on commit ad3d89e

Please sign in to comment.