Skip to content

Commit

Permalink
Removal of unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
AnupamaSarjoshi committed Oct 13, 2023
1 parent adfd8e7 commit 2ef5321
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 312 deletions.
31 changes: 14 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
# oumatrix #
# Matrix question type

TODO Describe the plugin shortly here.
A matrix question type for Moodle.

TODO Provide more detailed description here.
This question type helps in creating the Single Choice or Multiple Response questions
in multi-row multi-column matrix format.

## Installing via uploaded ZIP file ##

1. Log in to your Moodle site as an admin and go to _Site administration >
Plugins > Install plugins_.
2. Upload the ZIP file with the plugin code. You should only be prompted to add
extra details if your plugin type is not automatically detected.
3. Check the plugin validation report and finish the installation.
## Installation and set-up

## Installing manually ##
### Install from the plugins database

The plugin can be also installed by putting the contents of this directory to
Install from the Moodle plugins database https://moodle.org/plugins/qtype_oumatrix
in the normal way.

{your/moodle/dirroot}/question/type/oumatrix

Afterwards, log in to your Moodle site as an admin and go to _Site administration >
Notifications_ to complete the installation.
### Install using git

Alternatively, you can run
Or you can install using git. Type this commands in the root of your Moodle install

$ php admin/cli/upgrade.php
git clone https://github.com/moodleou/moodle-qtype_oumatrix.git question/type/oumatrix
echo /question/type/oumatrix/ >> .git/info/exclude

to complete the installation from the command line.
Then run the Moodle update process
Site administration > Notifications
8 changes: 4 additions & 4 deletions backup/moodle2/backup_qtype_oumatrix_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ protected function define_question_plugin_structure(): backup_plugin_element {

public static function get_qtype_fileareas() {
return [
'feedback' => 'question_created',
'correctfeedback' => 'question_created',
'partiallycorrectfeedback' => 'question_created',
'incorrectfeedback' => 'question_created',
'feedback' => 'question_created',
'correctfeedback' => 'question_created',
'partiallycorrectfeedback' => 'question_created',
'incorrectfeedback' => 'question_created',
];
}
}
8 changes: 5 additions & 3 deletions backup/moodle2/restore_qtype_oumatrix_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ class restore_qtype_oumatrix_plugin extends restore_qtype_plugin {

/**
* Returns the paths to be handled by the plugin at question level.
*
* @return array The restore path element array.
*/
protected function define_question_plugin_structure(): array {

$paths = [];

// We used get_recommended_name() so this works.
$elements = [
'qtype_oumatrix' => '/oumatrix',
'qtype_oumatrix_column' => '/columns/column',
'qtype_oumatrix_row' => '/rows/row',
'qtype_oumatrix' => '/oumatrix',
'qtype_oumatrix_column' => '/columns/column',
'qtype_oumatrix_row' => '/rows/row',
];

foreach ($elements as $elename => $path) {
Expand Down
35 changes: 0 additions & 35 deletions db/upgradelib.php

This file was deleted.

17 changes: 5 additions & 12 deletions edit_oumatrix_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private function data_preprocessing_columns($question) {
}

/**
* Perform the necessary preprocessing for rows (subquestions) fields.
* Perform the necessary preprocessing for rows (sub-questions) fields.
*
* @param object $question The data being passed to the form.
* @return object The modified data.
Expand Down Expand Up @@ -312,7 +312,7 @@ public function validation($data, $files) {
// 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 => $unused) {
$rowanswerslabel = "rowanswers" . 'a' . ($colkey + 1);
if (isset($data[$rowanswerslabel]) && array_key_exists($rowkey, $data[$rowanswerslabel])) {
$answerfound = true;
Expand All @@ -327,13 +327,6 @@ public function validation($data, $files) {
return $errors;
}

protected function get_hint_fields($withclearwrong = false, $withshownumpartscorrect = false) {
[$repeated, $repeatedoptions] = parent::get_hint_fields($withclearwrong, $withshownumpartscorrect);
$repeatedoptions['hintclearwrong']['disabledif'] = ['single', 'eq', 1];
$repeatedoptions['hintshownumcorrect']['disabledif'] = ['single', 'eq', 1];
return [$repeated, $repeatedoptions];
}

/**
* Add a set of form fields, obtained from get_per_column_fields.
*
Expand All @@ -355,9 +348,9 @@ protected function add_per_column_fields(object $mform, string $label,
}

$this->repeat_elements($this->get_per_column_fields($mform, $label, $repeatedoptions),
$repeatsatstart, $repeatedoptions,
'nocolumns', 'addcolumns', $addoptions,
get_string('addmoreblanks', 'qtype_oumatrix', 'columns'), true);
$repeatsatstart, $repeatedoptions,
'nocolumns', 'addcolumns', $addoptions,
get_string('addmoreblanks', 'qtype_oumatrix', 'columns'), true);
}

protected function get_per_column_fields($mform, $label, $repeatedoptions) {
Expand Down
67 changes: 23 additions & 44 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ abstract public function is_choice_selected($response, $rowkey, $colkey);

abstract public function is_same_response(array $prevresponse, array $newresponse);

abstract public function grade_response(array $response);

public function start_attempt(question_attempt_step $step, $variant) {
$this->roworder = array_keys($this->rows);
if ($this->shuffleanswers) {
Expand All @@ -93,6 +95,10 @@ protected function init_roworder(question_attempt $qa) {
}
}

public function is_gradable_response(array $response) {
return $this->is_complete_response($response);
}

public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) {
if ($component == 'question' && in_array($filearea,
['correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'])) {
Expand All @@ -117,8 +123,6 @@ public function get_validation_error(array $response): string {
return get_string('pleaseananswerallparts', 'qtype_oumatrix');
}

abstract public function grade_response(array $response);

public function validate_can_regrade_with_other_version(question_definition $otherversion): ?string {
$basemessage = parent::validate_can_regrade_with_other_version($otherversion);
if ($basemessage) {
Expand Down Expand Up @@ -158,7 +162,7 @@ public function update_attempt_state_data_for_new_version(
}

/**
* Class that represents a oumatrix question.
* Class that represents a oumatrix question for single choice.
*/
class qtype_oumatrix_single extends qtype_oumatrix_base {

Expand All @@ -176,7 +180,7 @@ public function get_expected_data(): array {

public function is_choice_selected($response, $rowkey, $colkey) {
$responsekey = $this->field($rowkey);
if ($response && array_key_exists($responsekey, $response)) {
if (array_key_exists($responsekey, $response)) {
return (string) $response[$responsekey] == $colkey;
}
return false;
Expand Down Expand Up @@ -210,9 +214,9 @@ public function get_correct_response(): ?array {
$response = [];
foreach ($this->roworder as $key => $rownumber) {
$row = $this->rows[$rownumber];
if ($row->correctanswers != '') {
$response[$this->field($key)] = $this->columns[array_key_first($row->correctanswers)]->number;
}
//if ($row->correctanswers != '') {
$response[$this->field($key)] = $this->columns[array_key_first($row->correctanswers)]->number;
//}
}
return $response;
}
Expand Down Expand Up @@ -245,19 +249,8 @@ public function is_complete_response(array $response): bool {
return true;
}

public function is_gradable_response(array $response): bool {
return true;
}

public function get_validation_error(array $response): string {
if ($this->is_complete_response($response)) {
return '';
}
return get_string('pleaseananswerallparts', 'qtype_oumatrix');
}

public function grade_response(array $response): array {
// Retrieve the number of right and total answers.
// Retrieve the number of right responses and the total number of responses.
[$numrightparts, $total] = $this->get_num_parts_right($response);
$fraction = $numrightparts / $total;
return [$fraction, question_state::graded_state_for_fraction($fraction)];
Expand All @@ -267,8 +260,8 @@ public function get_num_parts_right(array $response): array {
$numright = 0;
foreach ($this->roworder as $key => $rownumber) {
$row = $this->rows[$rownumber];
if (array_key_exists($this->field($key), $response) && $row->correctanswers != '' &&
$response[$this->field($key)] == $this->columns[array_key_first($row->correctanswers)]->number) {
$columnnumber = $this->columns[array_key_first($row->correctanswers)]->number;
if (array_key_exists($this->field($key), $response) && $response[$this->field($key)] == $columnnumber) {
$numright++;
}
}
Expand All @@ -277,15 +270,14 @@ public function get_num_parts_right(array $response): array {
}

/**
* Class that represents a oumatrix question.
* Class that represents a oumatrix question for multiple response.
*/
class qtype_oumatrix_multiple extends qtype_oumatrix_base {

public function get_renderer(moodle_page $page) {
return $page->get_renderer('qtype_oumatrix', 'multiple');
}


public function get_expected_data(): array {
$expected = [];
foreach ($this->rows as $row) {
Expand All @@ -300,7 +292,7 @@ public function get_expected_data(): array {

public function is_choice_selected($response, $rowkey, $colkey) {
$responsekey = $this->field($rowkey, $colkey);
if ($response && array_key_exists($responsekey, $response)) {
if (array_key_exists($responsekey, $response)) {
return (string) $response[$responsekey] == 1;
}
return false;
Expand Down Expand Up @@ -337,12 +329,10 @@ public function get_correct_response(): ?array {
$answers = [];
foreach ($this->roworder as $key => $rownumber) {
$row = $this->rows[$rownumber];
if ($row->correctanswers != '') {
foreach ($row->correctanswers as $colkey => $answer) {
// Get the corresponding column object associated with the column key.
$column = $this->columns[$colkey];
$answers[$this->field($key, $column->number)] = $answer;
}
foreach ($row->correctanswers as $colkey => $answer) {
// Get the corresponding column object associated with the column key.
$column = $this->columns[$colkey];
$answers[$this->field($key, $column->number)] = $answer;
}
}
return $answers;
Expand Down Expand Up @@ -372,8 +362,8 @@ public function summarise_response(array $response): ?string {
public function is_complete_response(array $response): bool {
foreach ($this->rows as $row) {
$inputresponse = false;
foreach ($this->columns as $col) {
$fieldname = $this->field($row->number, $col->number);
foreach ($this->columns as $column) {
$fieldname = $this->field($row->number, $column->number);
if (array_key_exists($fieldname, $response)) {
$inputresponse = true;
}
Expand All @@ -385,19 +375,8 @@ public function is_complete_response(array $response): bool {
return true;
}

public function is_gradable_response(array $response): bool {
return true;
}

public function get_validation_error(array $response): string {
if ($this->is_complete_response($response)) {
return '';
}
return get_string('pleaseananswerallparts', 'qtype_oumatrix');
}

public function grade_response(array $response): array {
// Retrieve a number of right answers and total answers.
// Retrieve the number of right responses and the total number of responses.
if ($this->grademethod == 'allnone') {
[$numrightparts, $total] = $this->get_num_grade_allornone($response);
$fraction = $numrightparts / $total;
Expand Down
Loading

0 comments on commit 2ef5321

Please sign in to comment.