Skip to content

Commit

Permalink
Edit form update
Browse files Browse the repository at this point in the history
  • Loading branch information
AnupamaSarjoshi committed Jun 23, 2023
1 parent 1bc86bf commit bf08b30
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 5 deletions.
5 changes: 4 additions & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="question/type/oumatrix/db" VERSION="20230621" COMMENT="XMLDB file for Moodle question/type/oumatrix">
<XMLDB PATH="question/type/oumatrix/db" VERSION="20230621" COMMENT="XMLDB file for Moodle question/type/oumatrix"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="qtype_oumatrix_options" COMMENT="Options for OU matrix question">
<FIELDS>
Expand Down
97 changes: 97 additions & 0 deletions edit_oumatrix_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,103 @@
*/
class qtype_oumatrix_edit_form extends question_edit_form {

/** @var int Number of rows. */
protected $numrows;
/** @var int Number of columns. */
protected $numcolumns;
/** @var array The grid options. */
protected $gridoptions;

protected $grademethod = ['partialcredit', 'allornothing'];

/**
* Add question-type specific form fields.
*
* @param object $mform the form being built.
*/
protected function definition_inner($mform) {

$qtype = 'qtype_oumatrix';
$answermodemenu = array(
get_string('answersingleno', $qtype),
get_string('answersingleyes', $qtype),
);
$mform->addElement('select', 'single',
get_string('answermode', $qtype), $answermodemenu);
$mform->setDefault('single', $this->get_default_value('single',
get_config($qtype, 'answermode')));

$mform->addElement('selectyesno', 'shuffleanswers', get_string('shuffleanswers', $qtype), '');
$mform->addHelpButton('shuffleanswers', 'shuffleanswers', $qtype);
$mform->setDefault('shuffleanswers', $this->get_default_value('shuffleanswers', 0));

$mform->addElement('select', 'grademethod',
get_string('grademethod', $qtype), self::get_grading_modes());

$mform->addHelpButton('grademethod', 'grademethod', $qtype);
$mform->setDefault('grademethod', $this->get_default_value('grademethod',
get_config($qtype, 'grademethod')));

// Set matrix table options.
$this->gridoptions = range(1, 12);
// Add number of matrix rows.
$mform->addElement('select', 'numrows',
get_string('numberofrows', $qtype), $this->gridoptions, null);
$mform->addRule('numrows', null, 'required', null, 'client');
$mform->setDefault('numrows', 2);

// Add number of matrix columns.
$mform->addElement('select', 'numcolumns',
get_string('numberofcolumns', $qtype), $this->gridoptions, null);
$mform->addRule('numcolumns', null, 'required', null, 'client');
$mform->setDefault('numcolumns', 4);
// Add update field.
$mform->addElement('submit', 'updateform', get_string('updateform', $qtype));
$mform->registerNoSubmitButton('updateform');

$this->set_current_rowcolumn_setting();

$this->add_combined_feedback_fields(true);
$mform->disabledIf('shownumcorrect', 'single', 'eq', 1);

$this->add_interactive_settings(true, true);

}

/**
* Set the matrix grid size.
*
* @return void
*/
protected function set_current_rowcolumn_setting(): void {
$numrowsindex = optional_param('numrows', -1, PARAM_INT);
$numcolumnsindex = optional_param('numcolumns', -1, PARAM_INT);

if ($numrowsindex < 0) {
$numrowsindex = $this->question->options->numrows ?? 2;
}

if ($numcolumnsindex < 0) {
$numcolumnsindex = $this->question->options->numcolumns ?? 2;
}

$this->numrows = $this->gridoptions[$numrowsindex] ?? 2;
$this->numcolumns = $this->gridoptions[$numcolumnsindex] ?? 2;
}

/**
* @return array supported grading methods.
*/
public static function get_grading_modes(): array {
return [
'partialcredit' => get_string('gradepartialcredit', 'qtype_oumatrix'),
'allornothing' => get_string('gradeallornothing', 'qtype_oumatrix')
];
}

protected function add_question_section(): void {

}
/**
* Returns the question type name.
*
Expand Down
19 changes: 17 additions & 2 deletions lang/en/qtype_oumatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,26 @@
* @copyright 2023 The Open University
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


defined('MOODLE_INTERNAL') || die();


$string['answermode'] = 'Answer mode';
$string['answersingleno'] = 'Multiple response';
$string['answersingleyes'] = 'Single choice';
$string['grademethod'] = 'Marking mode';
$string['grademethod_help'] = 'Standard (subpoints): each correct response in the body cells is worth one point, so students score a percentage of the total correct responses.
All or nothing: students must get every response correct, otherwise they score zero.';
$string['gradepartialcredit'] = 'Give partial credit';
$string['gradeallornothing'] = 'All-or-nothing';
$string['numberofcolumns'] = 'Body columns';
$string['numberofrows'] = 'Body rows';
$string['pluginname'] = 'oumatrix';
$string['pluginname_help'] = 'Creating a matrix question requires you to specify column headings (values) to row headings (items). For example, you might ask students to classify an item as animal, vegetable, or mineral using Single Choice. You can use Multiple Response so that several values may apply to an item.';
$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['shuffleanswers'] = 'Shuffle the items?';
$string['shuffleanswers_desc'] = 'Whether options should be randomly shuffled for each attempt by default.';
$string['shuffleanswers_help'] = 'If enabled, the order of the row items is randomly shuffled for each attempt, provided that "Shuffle within questions" in the activity settings is also enabled.';
$string['updateform'] = 'Update the response matrix';
1 change: 1 addition & 0 deletions pix/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
* @copyright 2023 The Open University
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


defined('MOODLE_INTERNAL') || die();


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

/**
Expand Down

0 comments on commit bf08b30

Please sign in to comment.