MDL-73481 qtype_truefalse: optional standard instructions for output.
AMOS BEGIN CPY [privacy:preference:showstandardinstruction,qtype_multichoice],[privacy:preference:showstandardinstruction,qtype_truefalse] CPY [showstandardinstruction,qtype_multichoice],[showstandardinstruction,qtype_truefalse] AMOS END
This commit is contained in:
@@ -53,7 +53,7 @@ class backup_qtype_truefalse_plugin extends backup_qtype_plugin {
|
||||
|
||||
// Now create the qtype own structures.
|
||||
$truefalse = new backup_nested_element('truefalse', array('id'), array(
|
||||
'trueanswer', 'falseanswer'));
|
||||
'trueanswer', 'falseanswer', 'showstandardinstruction'));
|
||||
|
||||
// Now the own qtype tree.
|
||||
$pluginwrapper->add_child($truefalse);
|
||||
|
||||
@@ -14,33 +14,44 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace qtype_truefalse\privacy;
|
||||
|
||||
use core_privacy\local\metadata\collection;
|
||||
use core_privacy\local\request\transform;
|
||||
use core_privacy\local\request\writer;
|
||||
|
||||
/**
|
||||
* Privacy Subsystem implementation for qtype_truefalse.
|
||||
* Privacy Subsystem implementation for qtype_truefalse
|
||||
*
|
||||
* @package qtype_truefalse
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace qtype_truefalse\privacy;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Privacy Subsystem for qtype_truefalse implementing null_provider.
|
||||
*
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class provider implements \core_privacy\local\metadata\null_provider {
|
||||
class provider implements
|
||||
\core_privacy\local\metadata\provider,
|
||||
\core_privacy\local\request\user_preference_provider {
|
||||
|
||||
/**
|
||||
* Get the language string identifier with the component's language
|
||||
* file to explain why this plugin stores no data.
|
||||
* Returns metadata about this system
|
||||
*
|
||||
* @return string
|
||||
* @param collection $collection
|
||||
* @return collection
|
||||
*/
|
||||
public static function get_reason() : string {
|
||||
return 'privacy:metadata';
|
||||
public static function get_metadata(collection $collection): collection {
|
||||
$collection->add_user_preference('qtype_truefalse_showstandardinstruction', 'privacy:preference:showstandardinstruction');
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export plugin user preferences for the given user
|
||||
*
|
||||
* @param int $userid
|
||||
*/
|
||||
public static function export_user_preferences(int $userid): void {
|
||||
$preference = get_user_preferences('qtype_truefalse_showstandardinstruction', null, $userid);
|
||||
if ($preference !== null) {
|
||||
writer::export_user_preference('qtype_truefalse', 'showstandardinstruction', transform::yesno($preference),
|
||||
get_string('privacy:preference:showstandardinstruction', 'qtype_truefalse'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="question/type/truefalse/db" VERSION="20120122" COMMENT="XMLDB file for Moodle question/type/truefalse"
|
||||
<XMLDB PATH="question/type/truefalse/db" VERSION="20220719" COMMENT="XMLDB file for Moodle question/type/truefalse"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@@ -10,6 +10,7 @@
|
||||
<FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Foreign key references question.id."/>
|
||||
<FIELD NAME="trueanswer" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Foreign key references question_answers.id. The 'True' choice."/>
|
||||
<FIELD NAME="falseanswer" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Foreign key references question_answers.id. The 'False' choice."/>
|
||||
<FIELD NAME="showstandardinstruction" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Whether standard instruction ('Select one:') is displayed"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* True/false question type upgrade code
|
||||
*
|
||||
* @package qtype_truefalse
|
||||
* @copyright 2022 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Method to perform upgrade steps between versions
|
||||
*
|
||||
* @param int $oldversion
|
||||
* @return bool
|
||||
*/
|
||||
function xmldb_qtype_truefalse_upgrade(int $oldversion): bool {
|
||||
global $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
if ($oldversion < 2022071900) {
|
||||
|
||||
// Define field showstandardinstruction to be added to question_truefalse.
|
||||
$table = new xmldb_table('question_truefalse');
|
||||
$field = new xmldb_field('showstandardinstruction', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1', 'falseanswer');
|
||||
|
||||
// Conditionally launch add field showstandardinstruction.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Truefalse savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2022071900, 'qtype', 'truefalse');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -48,6 +48,10 @@ class qtype_truefalse_edit_form extends question_edit_form {
|
||||
0 => get_string('false', 'qtype_truefalse'),
|
||||
1 => get_string('true', 'qtype_truefalse')));
|
||||
|
||||
$mform->addElement('selectyesno', 'showstandardinstruction', get_string('showstandardinstruction', 'qtype_truefalse'));
|
||||
$mform->addHelpButton('showstandardinstruction', 'showstandardinstruction', 'qtype_truefalse');
|
||||
$mform->setDefault('showstandardinstruction', $this->get_default_value('showstandardinstruction', 0));
|
||||
|
||||
$mform->addElement('editor', 'feedbacktrue',
|
||||
get_string('feedbacktrue', 'qtype_truefalse'), array('rows' => 10), $this->editoroptions);
|
||||
$mform->setType('feedbacktrue', PARAM_RAW);
|
||||
@@ -111,6 +115,10 @@ class qtype_truefalse_edit_form extends question_edit_form {
|
||||
$question->feedbackfalse['itemid'] = $draftid;
|
||||
}
|
||||
|
||||
if (!empty($question->options)) {
|
||||
$question->showstandardinstruction = !empty($question->options->showstandardinstruction);
|
||||
}
|
||||
|
||||
return $question;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
privacy:metadata,qtype_truefalse
|
||||
@@ -38,4 +38,9 @@ $string['pluginname_link'] = 'question/type/truefalse';
|
||||
$string['pluginnameadding'] = 'Adding a True/False question';
|
||||
$string['pluginnameediting'] = 'Editing a True/False question';
|
||||
$string['pluginnamesummary'] = 'A simple form of multiple choice question with just the two choices \'True\' and \'False\'.';
|
||||
$string['privacy:preference:showstandardinstruction'] = 'Whether showing standard instruction.';
|
||||
$string['showstandardinstruction'] = 'Show standard instructions';
|
||||
$string['showstandardinstruction_help'] = 'Whether to show the instructions "Select one:" before true/false answers.';
|
||||
|
||||
// Deprecated since Moodle 4.1.
|
||||
$string['privacy:metadata'] = 'The True/False question type plugin does not store any personal data.';
|
||||
|
||||
@@ -94,12 +94,14 @@ class qtype_truefalse extends question_type {
|
||||
// But we'll do it anyway, just for robustness.
|
||||
$options->trueanswer = $trueid;
|
||||
$options->falseanswer = $falseid;
|
||||
$options->showstandardinstruction = !empty($question->showstandardinstruction);
|
||||
$DB->update_record('question_truefalse', $options);
|
||||
} else {
|
||||
$options = new stdClass();
|
||||
$options->question = $question->id;
|
||||
$options->trueanswer = $trueid;
|
||||
$options->falseanswer = $falseid;
|
||||
$options->showstandardinstruction = !empty($question->showstandardinstruction);
|
||||
$DB->insert_record('question_truefalse', $options);
|
||||
}
|
||||
|
||||
@@ -108,6 +110,11 @@ class qtype_truefalse extends question_type {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function save_defaults_for_new_questions(stdClass $fromform): void {
|
||||
parent::save_defaults_for_new_questions($fromform);
|
||||
$this->set_default_value('showstandardinstruction', $fromform->showstandardinstruction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the question type specific options for the question.
|
||||
*/
|
||||
@@ -148,6 +155,7 @@ class qtype_truefalse extends question_type {
|
||||
$answers[$questiondata->options->falseanswer]->feedbackformat;
|
||||
$question->trueanswerid = $questiondata->options->trueanswer;
|
||||
$question->falseanswerid = $questiondata->options->falseanswer;
|
||||
$question->showstandardinstruction = $questiondata->options->showstandardinstruction;
|
||||
}
|
||||
|
||||
public function delete_question($questionid, $contextid) {
|
||||
|
||||
@@ -100,8 +100,10 @@ class qtype_truefalse_renderer extends qtype_renderer {
|
||||
array('class' => 'qtext'));
|
||||
|
||||
$result .= html_writer::start_tag('div', array('class' => 'ablock'));
|
||||
$result .= html_writer::tag('div', get_string('selectone', 'qtype_truefalse'),
|
||||
if (!empty($question->showstandardinstruction)) {
|
||||
$result .= html_writer::tag('div', get_string('selectone', 'qtype_truefalse'),
|
||||
array('class' => 'prompt'));
|
||||
}
|
||||
|
||||
$result .= html_writer::start_tag('div', array('class' => 'answer'));
|
||||
$result .= html_writer::tag('div', $radiotrue . ' ' . $truefeedbackimg,
|
||||
|
||||
@@ -27,6 +27,7 @@ Feature: Test creating a True/False question
|
||||
| Feedback for the response 'False'. | Read more about England. |
|
||||
Then I should see "true-false-001"
|
||||
|
||||
@javascript
|
||||
Scenario: Create a True/False question with Correct answer as True
|
||||
When I am on the "Course 1" "core_question > course question bank" page logged in as teacher
|
||||
And I add a "True/False" question filling the form with:
|
||||
@@ -35,6 +36,13 @@ Feature: Test creating a True/False question
|
||||
| Default mark | 1 |
|
||||
| General feedback | London is the capital city of England. |
|
||||
| Correct answer | True |
|
||||
| Show standard instructions | Yes |
|
||||
| Feedback for the response 'True'. | Well done! |
|
||||
| Feedback for the response 'False'. | Read more about England. |
|
||||
Then I should see "true-false-002"
|
||||
# Checking that the next new question form displays user preferences settings.
|
||||
And I press "Create a new question ..."
|
||||
And I set the field "True/False" to "1"
|
||||
And I click on "Add" "button" in the "Choose a question type to add" "dialogue"
|
||||
And the following fields match these values:
|
||||
| Show standard instructions | Yes |
|
||||
|
||||
@@ -66,4 +66,38 @@ class walkthrough_test extends \qbehaviour_walkthrough_test_base {
|
||||
new \question_no_pattern_expectation('/' . preg_quote($tf->falsefeedback, '/') . '/'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \qtype_truefalse_renderer::formulation_and_controls
|
||||
*/
|
||||
public function test_deferredfeedback_feedback_multichoice_single_showstandardinstruction_yes() {
|
||||
|
||||
// Create a true-false question with correct answer false.
|
||||
$tf = \test_question_maker::make_question('truefalse', 'false');
|
||||
$tf->showstandardinstruction = true;
|
||||
|
||||
$this->start_attempt_at_question($tf, 'deferredfeedback', 1);
|
||||
$this->render();
|
||||
|
||||
// Check for 'Show standard instruction'.
|
||||
$standardinstruction = get_string('selectone', 'qtype_truefalse');
|
||||
$this->assertStringContainsString($standardinstruction, $this->currentoutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \qtype_truefalse_renderer::formulation_and_controls
|
||||
*/
|
||||
public function test_deferredfeedback_feedback_multichoice_single_showstandardinstruction_no() {
|
||||
|
||||
// Create a true-false question with correct answer false.
|
||||
$tf = \test_question_maker::make_question('truefalse', 'false');
|
||||
$tf->showstandardinstruction = false;
|
||||
|
||||
$this->start_attempt_at_question($tf, 'deferredfeedback', 1);
|
||||
$this->render();
|
||||
|
||||
// Check for 'Show standard instruction'.
|
||||
$standardinstruction = get_string('selectone', 'qtype_truefalse');
|
||||
$this->assertStringNotContainsString($standardinstruction, $this->currentoutput);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = 'qtype_truefalse';
|
||||
$plugin->version = 2022041900;
|
||||
$plugin->version = 2022071900;
|
||||
|
||||
$plugin->requires = 2022041200;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user