diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php new file mode 100644 index 0000000..e8dd890 --- /dev/null +++ b/classes/privacy/provider.php @@ -0,0 +1,97 @@ +. + +/** + * Privacy Subsystem implementation for qtype_oumatrix. + * + * @package qtype_oumatrix + * @copyright 2023 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace qtype_oumatrix\privacy; + +use core_privacy\local\metadata\collection; +use core_privacy\local\request\transform; +use core_privacy\local\request\writer; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for qtype_oumatrix implementing user_preference_provider. + * + * @copyright 2023 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements + // This component has data. + // We need to return default options that have been set a user preferences. + \core_privacy\local\metadata\provider, + \core_privacy\local\request\user_preference_provider +{ + + /** + * Returns meta data about this system. + * + * @param collection $collection The initialised collection to add items to. + * @return collection A listing of user data stored through this system. + */ + public static function get_metadata(collection $collection) : collection { + $collection->add_user_preference('qtype_oumatrix_defaultmark', 'privacy:preference:defaultmark'); + $collection->add_user_preference('qtype_oumatrix_penalty', 'privacy:preference:penalty'); + $collection->add_user_preference('qtype_oumatrix_inputtype', 'privacy:preference:inputtype'); + $collection->add_user_preference('qtype_oumatrix_grademethod', 'privacy:preference:grademethod'); + $collection->add_user_preference('qtype_oumatrix_shuffleanswers', 'privacy:preference:shuffleanswers'); + return $collection; + } + + /** + * Export all user preferences for the plugin. + * + * @param int $userid The userid of the user whose data is to be exported. + */ + public static function export_user_preferences(int $userid) { + $preference = get_user_preferences('qtype_oumatrix_defaultmark', null, $userid); + if (null !== $preference) { + $desc = get_string('privacy:preference:defaultmark', 'qtype_oumatrix'); + writer::export_user_preference('qtype_oumatrix', 'defaultmark', $preference, $desc); + } + + $preference = get_user_preferences('qtype_oumatrix_penalty', null, $userid); + if (null !== $preference) { + $desc = get_string('privacy:preference:penalty', 'qtype_oumatrix'); + writer::export_user_preference('qtype_oumatrix', 'penalty', transform::percentage($preference), $desc); + } + + $preference = get_user_preferences('qtype_oumatrix_inputtype', null, $userid); + if (null !== $preference) { + $desc = get_string('privacy:preference:inputtype', 'qtype_oumatrix'); + writer::export_user_preference('qtype_oumatrix', 'inputtype', transform::yesno($preference), $desc); + } + + $preference = get_user_preferences('qtype_oumatrix_grademethod', null, $userid); + if (null !== $preference) { + $desc = get_string('privacy:preference:grademethod', 'qtype_oumatrix'); + writer::export_user_preference('qtype_oumatrix', 'grademethod', transform::yesno($preference), $desc); + } + + $preference = get_user_preferences('qtype_oumatrix_shuffleanswers', null, $userid); + if (null !== $preference) { + $desc = get_string('privacy:preference:shuffleanswers', 'qtype_oumatrix'); + writer::export_user_preference('qtype_oumatrix', 'shuffleanswers', transform::yesno($preference), $desc); + } + } +} \ No newline at end of file diff --git a/edit_oumatrix_form.php b/edit_oumatrix_form.php index 8c06aea..6054e2e 100644 --- a/edit_oumatrix_form.php +++ b/edit_oumatrix_form.php @@ -41,7 +41,10 @@ class qtype_oumatrix_edit_form extends question_edit_form { /** @var int Number of columns. */ private $numcolumns; - /** @var string answermode of rows. */ + /** @var int Number of rows. */ + private $numrows; + + /** @var string inputtype of rows. */ private $inputtype; /** @@ -67,12 +70,11 @@ protected function definition_inner($mform) { // Set the number of columns and rows. $this->set_current_settings(); - - $answermodemenu = [ - 'single' => get_string('answermodesingle', 'qtype_oumatrix'), - 'multiple' => get_string('answermodemultiple', 'qtype_oumatrix'), + $inputtypemenu = [ + 'single' => get_string('inputtypesingle', 'qtype_oumatrix'), + 'multiple' => get_string('inputtypemultiple', 'qtype_oumatrix'), ]; - $mform->addElement('select', 'inputtype', get_string('answermode', 'qtype_oumatrix'), $answermodemenu); + $mform->addElement('select', 'inputtype', get_string('inputtype', 'qtype_oumatrix'), $inputtypemenu); $mform->setDefault('inputtype', $this->get_default_value('inputtype', get_config('qtype_oumatrix', 'inputtype'))); diff --git a/lang/en/qtype_oumatrix.php b/lang/en/qtype_oumatrix.php index 411d500..b532593 100644 --- a/lang/en/qtype_oumatrix.php +++ b/lang/en/qtype_oumatrix.php @@ -26,12 +26,6 @@ defined('MOODLE_INTERNAL') || die(); $string['a'] = 'A{$a}'; $string['addmoreblanks'] = 'Blanks for {no} more {$a}'; -$string['answermode'] = 'One or multiple answers?'; -$string['answermodesingle'] = 'Single'; -$string['answermodemultiple'] = 'Multiple'; -$string['answermode_desc'] = 'Answer mode can be either \'Single choice\' or \'Multiple response\' for each row in the matrix table.'; -$string['answermodemultiple'] = 'Multiple response'; -$string['answermodesingle'] = 'Single choice'; $string['blankcolumnsnotallowed'] = 'Empty column name is not allowed.'; $string['column'] = 'Column {$a}'; $string['columnshdr'] = 'Matrix columns (answers)'; @@ -48,6 +42,10 @@ All or nothing: students must get every response correct, otherwise they score zero.'; $string['gradepartialcredit'] = 'Give partial credit'; $string['gradeallornothing'] = 'All-or-nothing'; +$string['inputtype'] = 'One or multiple answers?'; +$string['inputtype_desc'] = 'One or multiple answers? can be either \'Single choice\' or \'Multiple response\' for each row in the matrix table.'; +$string['inputtypemultiple'] = 'Multiple response'; +$string['inputtypesingle'] = 'Single choice'; $string['noinputanswer'] = 'Each sub-question should have at least one correct answer.'; $string['notenoughanswercols'] = 'You must have at least {$a} answer columns.'; $string['notenoughquestionrows'] = 'You must have at least {$a} sub-questions.'; @@ -57,6 +55,12 @@ $string['pluginnameadding'] = 'Adding a Matrix question'; $string['pluginnameediting'] = 'Editing a Matrix question'; $string['pluginnamesummary'] = 'A multi-row table that can use single choice or multiple response inputs.'; +$string['privacy:metadata'] = 'Matrix question type plugin allows question authors to set default options as user preferences.'; +$string['privacy:preference:defaultmark'] = 'The default mark set for a given question.'; +$string['privacy:preference:penalty'] = 'The penalty for each incorrect try when questions are run using the \'Interactive with multiple tries\' or \'Adaptive mode\' behaviour.'; +$string['privacy:preference:inputtype'] = 'Whether the \'One or multiple answers?\' should be \'Single choice\' or \'Multiple response\'.'; +$string['privacy:preference:grademethod'] = 'Whether the Grading type should be \'All-or-nothing\' or \'Give partial credit\' for \'Multiple response\'. This option is diabled for \'Single choice\'.'; +$string['privacy:preference:shuffleanswers'] = 'Whether the answers should be automatically shuffled.'; $string['row'] = 'Row {$a}'; $string['rowshdr'] = 'Matrix rows (sub-questions)'; $string['rowanswerlist'] = 'Select answers'; diff --git a/settings.php b/settings.php index 8b216ca..9da5a4e 100644 --- a/settings.php +++ b/settings.php @@ -26,12 +26,12 @@ if ($ADMIN->fulltree) { $inputtype = [ - 'single' => get_string('answermodesingle', 'qtype_oumatrix'), - 'multiple' => get_string('answermodemultiple', 'qtype_oumatrix'), + 'single' => get_string('inputtypesingle', 'qtype_oumatrix'), + 'multiple' => get_string('inputtypemultiple', 'qtype_oumatrix'), ]; $settings->add(new admin_setting_configselect('qtype_oumatrix/inputtype', - new lang_string('answermode', 'qtype_oumatrix'), - new lang_string('answermode_desc', 'qtype_oumatrix'), 'single', $inputtype)); + new lang_string('inputtype', 'qtype_oumatrix'), + new lang_string('inputtype_desc', 'qtype_oumatrix'), 'single', $inputtype)); $grademethod = [ 'partial' => get_string('gradepartialcredit', 'qtype_oumatrix'),