Skip to content

Commit

Permalink
Fix codechecker errors and cleaning up unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
AnupamaSarjoshi committed Oct 11, 2023
1 parent 84d5754 commit 849aeeb
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 396 deletions.
3 changes: 2 additions & 1 deletion backup/moodle2/backup_qtype_oumatrix_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ protected function define_question_plugin_structure(): backup_plugin_element {
// Now create the qtype own structures.
$matrix = new backup_nested_element('oumatrix', ['id'], ['inputtype', 'grademethod', 'shuffleanswers',
'correctfeedback', 'correctfeedbackformat', 'partiallycorrectfeedback', 'partiallycorrectfeedbackformat',
'incorrectfeedback', 'incorrectfeedbackformat', 'shownumcorrect']);
'incorrectfeedback', 'incorrectfeedbackformat', 'shownumcorrect',
]);
$pluginwrapper->add_child($matrix);

// Define the columns.
Expand Down
42 changes: 11 additions & 31 deletions edit_oumatrix_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ protected function definition_inner($mform) {

$answermodemenu = [
'single' => get_string('answermodesingle', 'qtype_oumatrix'),
'multiple' => get_string('answermodemultiple', 'qtype_oumatrix')
'multiple' => get_string('answermodemultiple', 'qtype_oumatrix'),
];
$mform->addElement('select', 'inputtype', get_string('answermode', 'qtype_oumatrix'), $answermodemenu);
$mform->setDefault('inputtype', $this->get_default_value('single',
get_config('qtype_oumatrix', 'inputtype')));

$grademethod = [
'partial' => get_string('gradepartialcredit', 'qtype_oumatrix'),
'allnone' => get_string('gradeallornothing', 'qtype_oumatrix')
'allnone' => get_string('gradeallornothing', 'qtype_oumatrix'),
];
$mform->addElement('select', 'grademethod', get_string('grademethod', 'qtype_oumatrix'), $grademethod);
$mform->addHelpButton('grademethod', 'grademethod', 'qtype_oumatrix');
Expand Down Expand Up @@ -152,6 +152,7 @@ public function data_preprocessing($question) {

/**
* Perform the necessary preprocessing for the options fields.
*
* @param object $question the data being passed to the form.
* @return object $question the modified data.
*/
Expand Down Expand Up @@ -210,15 +211,15 @@ private function data_preprocessing_rows($question) {
$question->rowanswers[$row->number] = $columnvalue;
} else {
$rowanswerslabel = "rowanswers" . $columnvalue;
$question->$rowanswerslabel[$row->number] = $decodedanswers[$column->id];
$question->{$rowanswerslabel}[$row->number] = $decodedanswers[$column->id];
}
}
}
$itemid = (int)$row->id ?? null;
$itemid = (int) $row->id ?? null;

// Prepare the feedback editor to display files in draft area.
$feedback[$key] = [];
$feedbackdraftitemid = file_get_submitted_draft_itemid('feedback['.$key.']');
$feedbackdraftitemid = file_get_submitted_draft_itemid('feedback[' . $key . ']');
$feedback[$key]['text'] = file_prepare_draft_area(
$feedbackdraftitemid,
$this->context->id,
Expand All @@ -245,7 +246,7 @@ public function validation($data, $files) {
// Ignore the blank columns.
$filteredcolscount = count(array_filter($data['columnname']));
if ($filteredcolscount < column::MIN_NUMBER_OF_COLUMNS) {
$errors['columnname[' . $filteredcolscount .']'] = get_string('notenoughanswercols', 'qtype_oumatrix',
$errors['columnname[' . $filteredcolscount . ']'] = get_string('notenoughanswercols', 'qtype_oumatrix',
column::MIN_NUMBER_OF_COLUMNS);
}

Expand Down Expand Up @@ -302,24 +303,24 @@ public function validation($data, $files) {
// Validate if correct answers have been input for oumatrix single choice question.
$nonemptyrows = array_filter($data['rowname']);
if ($data['inputtype'] == 'single') {
foreach ($nonemptyrows as $key => $rowname ) {
foreach ($nonemptyrows as $key => $rowname) {
if (!isset($data['rowanswers']) || !array_key_exists($key, $data['rowanswers'])) {
$errors['rowoptions[' . $key .']'] = get_string('noinputanswer', 'qtype_oumatrix');
$errors['rowoptions[' . $key . ']'] = get_string('noinputanswer', 'qtype_oumatrix');
}
}
} else {
// Validate if correct answers have been input for oumatrix multiple choice question.
foreach ($nonemptyrows as $rowkey => $rowname) {
$answerfound = false;
foreach($data['columnname'] as $colkey => $colname) {
foreach ($data['columnname'] as $colkey => $colname) {
$rowanswerslabel = "rowanswers" . 'a' . ($colkey + 1);
if (isset($data[$rowanswerslabel]) && array_key_exists($rowkey, $data[$rowanswerslabel])) {
$answerfound = true;
break;
}
}
if (!$answerfound) {
$errors['rowoptions[' . $rowkey .']'] = get_string('noinputanswer', 'qtype_oumatrix');
$errors['rowoptions[' . $rowkey . ']'] = get_string('noinputanswer', 'qtype_oumatrix');
}
}
}
Expand All @@ -332,27 +333,6 @@ protected function get_hint_fields($withclearwrong = false, $withshownumpartscor
$repeatedoptions['hintshownumcorrect']['disabledif'] = ['single', 'eq', 1];
return [$repeated, $repeatedoptions];
}
//
///**
// * Perform the necessary preprocessing for the hint fields.
// *
// * @param object $question The data being passed to the form.
// * @param bool $withclearwrong Clear wrong hints.
// * @param bool $withshownumpartscorrect Show number correct.
// * @return object The modified data.
// */
//protected function data_preprocessing_hints($question, $withclearwrong = false, $withshownumpartscorrect = false) {
// if (empty($question->hints)) {
// return $question;
// }
// parent::data_preprocessing_hints($question, $withclearwrong, $withshownumpartscorrect);
//
// $question->hintoptions = [];
// foreach ($question->hints as $hint) {
// $question->hintoptions[] = $hint->options;
// }
// return $question;
//}

/**
* Add a set of form fields, obtained from get_per_column_fields.
Expand Down
2 changes: 1 addition & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @param array $options additional options affecting the file serving
* @return bool
*/
function qtype_oumatrix_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
function qtype_oumatrix_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) {
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_oumatrix', $filearea, $args, $forcedownload, $options);
Expand Down
Loading

0 comments on commit 849aeeb

Please sign in to comment.