Skip to content

Commit

Permalink
Add privacy/provider class
Browse files Browse the repository at this point in the history
  • Loading branch information
mkassaei committed Oct 18, 2023
1 parent 0ddd290 commit e1606d0
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 16 deletions.
97 changes: 97 additions & 0 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?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/>.

/**
* 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);
}
}
}
14 changes: 8 additions & 6 deletions edit_oumatrix_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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')));

Expand Down
16 changes: 10 additions & 6 deletions lang/en/qtype_oumatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)';
Expand All @@ -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.';
Expand All @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit e1606d0

Please sign in to comment.