diff --git a/classes/line.php b/classes/line.php index abf286a..0b85530 100644 --- a/classes/line.php +++ b/classes/line.php @@ -31,16 +31,16 @@ class line { const LINE_NUMBER_ADD = 2; /** @var string linesegment (Line segment ---). */ - const TYPE_LINE_SEGMENT ='linesegment'; + const TYPE_LINE_SEGMENT = 'linesegment'; /** @var string linesinglearrow (Single arrow -→). */ - const TYPE_LINE_SINGLE_ARROW ='linesinglearrow'; + const TYPE_LINE_SINGLE_ARROW = 'linesinglearrow'; /** @var string linedoublearrows (Double arrows ←--→). */ - const TYPE_LINE_DOUBLE_ARROW ='linedoublearrows'; + const TYPE_LINE_DOUBLE_ARROW = 'linedoublearrows'; /** @var string lineinfinite (Infinite line --o--o--). */ - const TYPE_LINE_INFINITE ='lineinfinite'; + const TYPE_LINE_INFINITE = 'lineinfinite'; /** @var string lineinfinite (Infinite line --o--o--). */ @@ -125,11 +125,11 @@ public static function get_line_types(): array { */ public static function is_zone_coordinates_valid(string $zone): bool { preg_match_all(self::VALIDATE_ZONE_COORDINATES, $zone, $matches); - // If the zone is empty return fale + // If the zone is empty return false. if (trim($zone) === '') { return false; } - // if there is no match return false. + // If there is no match return false. foreach ($matches as $i => $match) { if (empty($matches[$i])) { return false; diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 2355c71..b0374d0 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -38,8 +38,7 @@ 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 -{ + \core_privacy\local\request\user_preference_provider { /** * Returns meta data about this system. @@ -47,7 +46,7 @@ class provider implements * @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 { + public static function get_metadata(collection $collection): collection { $collection->add_user_preference('qtype_drawlines_defaultmark', 'privacy:preference:defaultmark'); $collection->add_user_preference('qtype_drawlines_penalty', 'privacy:preference:penalty'); $collection->add_user_preference('qtype_drawlines_grademethod', 'privacy:preference:grademethod'); diff --git a/edit_drawlines_form.php b/edit_drawlines_form.php index 6192677..db6ae7b 100644 --- a/edit_drawlines_form.php +++ b/edit_drawlines_form.php @@ -133,7 +133,7 @@ public function data_preprocessing($question) { self::file_picker_options()); $question->bgimage = $draftitemid; - //$this->js_call(); + // TODO: Require js amd module for fom. return $question; } @@ -210,7 +210,7 @@ public function validation($data, $files) { if (!$bgimagesize === null) { $errors["bgimage"] = get_string('formerror_nobgimage', 'qtype_' . $this->qtype()); } - // Validate whether the line type error needed to be displayed. + // Validate whether the line type error needed to be displayed. for ($i = 0; $i < $this->numberoflines; $i++) { // Validate line type. if (!in_array($data["type"][$i], array_keys(line::get_line_types())) && @@ -315,10 +315,5 @@ protected function get_per_line_fields(MoodleQuickForm $mform, string $label, ar $mform->setType('zoneend', PARAM_RAW_TRIMMED); return $repeated; } - - //public function js_call() { - // global $PAGE; - // $PAGE->requires->js_call_amd('qtype_drawlines/form', 'init'); - //} - + } diff --git a/lang/en/qtype_drawlines.php b/lang/en/qtype_drawlines.php index baa7ded..7a31398 100644 --- a/lang/en/qtype_drawlines.php +++ b/lang/en/qtype_drawlines.php @@ -26,11 +26,11 @@ $string['answer'] = 'Answer'; $string['bgimage'] = 'Background image'; -$string['dropbackground'] = 'Background image for dragging markers onto'; -//$string['coords'] = 'Coordinates'; $string['correctansweris'] = 'The correct answer is: {$a}'; +$string['dropbackground'] = 'Background image for dragging markers onto'; + $string['formerror_nobgimage'] = 'You need to select an image to use as the background for the drag and drop area.'; $string['formerror_notype'] = 'You have to select a type for Line {$a}'; $string['formerror_zonestart'] = 'Start zone coordinates should be in x,y;r format, where x,y are the coordinates of the centre of a circle and r is the radius.'; diff --git a/question.php b/question.php index a2a4f8c..9dc67e0 100644 --- a/question.php +++ b/question.php @@ -130,7 +130,7 @@ public function get_validation_error(array $response) { public function get_num_parts_right(array $response) { $chosenhits = $this->choose_hits($response); $divisor = max(count($this->rightchoices), $this->total_number_of_items_dragged($response)); - return array(count($chosenhits), $divisor); + return [count($chosenhits), $divisor]; } /** @@ -218,7 +218,7 @@ public function get_right_choice_for($place) { public function grade_response(array $response) { list($right, $total) = $this->get_num_parts_right($response); $fraction = $right / $total; - return array($fraction, question_state::graded_state_for_fraction($fraction)); + return [$fraction, question_state::graded_state_for_fraction($fraction)]; } public function compute_final_grade($responses, $totaltries) { diff --git a/questiontype.php b/questiontype.php index c0175b3..85834f0 100644 --- a/questiontype.php +++ b/questiontype.php @@ -103,8 +103,7 @@ public function save_hints($fromform, $withparts = false) { global $DB; $context = $fromform->context; - $oldhints = $DB->get_records('question_hints', - array('questionid' => $fromform->id), 'id ASC'); + $oldhints = $DB->get_records('question_hints', ['questionid' => $fromform->id], 'id ASC'); if (!empty($fromform->hint)) { $numhints = max(array_keys($fromform->hint)) + 1; @@ -166,7 +165,7 @@ public function save_hints($fromform, $withparts = false) { $fs = get_file_storage(); foreach ($oldhints as $oldhint) { $fs->delete_area_files($context->id, 'question', 'hint', $oldhint->id); - $DB->delete_records('question_hints', array('id' => $oldhint->id)); + $DB->delete_records('question_hints', ['id' => $oldhint->id]); } } @@ -178,12 +177,11 @@ protected function make_question_instance($questiondata) { protected function initialise_question_instance(question_definition $question, $questiondata): void { parent::initialise_question_instance($question, $questiondata); $this->initialise_question_lines($question, $questiondata); - //$this->initialise_combined_feedback($question, $questiondata, true); } protected function initialise_question_lines(question_definition $question, stdClass $questiondata): void { foreach ($questiondata->lines as $line) { - $question->lines[$line->number -1] = $this->make_line($line); + $question->lines[$line->number - 1] = $this->make_line($line); } } protected function initialise_combined_feedback(question_definition $question, $questiondata, $withparts = false) { @@ -208,7 +206,6 @@ public function delete_question($questionid, $contextid) { $DB->delete_records('qtype_drawlines_options', ['questionid' => $questionid]); $DB->delete_records('qtype_drawlines_lines', ['questionid' => $questionid]); // TODO: user the answer table for storing drag items. - //$DB->delete_records('qtype_drawlines_drags', ['questionid' => $questionid]); parent::delete_question($questionid, $contextid); } diff --git a/tests/helper.php b/tests/helper.php index 83b97be..e372933 100644 --- a/tests/helper.php +++ b/tests/helper.php @@ -85,7 +85,7 @@ public function get_drawlines_question_data_mkmap_twolines(): stdClass { 'labelend' => '', 'zonestart' => '100,100;10', 'zoneend' => '322,213;10', - ] + ], ]; $qdata->hints = [ 1 => (object) [ diff --git a/tests/questiontype_test.php b/tests/questiontype_test.php index d24abdf..1a08c6d 100644 --- a/tests/questiontype_test.php +++ b/tests/questiontype_test.php @@ -45,15 +45,15 @@ protected function tearDown(): void { $this->qtype = null; } - public function test_name() { + public function test_name(): void { $this->assertEquals($this->qtype->name(), 'drawlines'); } - public function test_can_analyse_responses() { + public function test_can_analyse_responses(): void { $this->assertTrue($this->qtype->can_analyse_responses()); } - public function test_make_line() { + public function test_make_line(): void { $this->resetAfterTest(); $line = new stdClass(); @@ -75,10 +75,7 @@ public function test_make_line() { } } - /** - * Test to make sure that loading of question options works, including in an error case. - */ - public function test_get_question_options() { + public function test_get_question_options(): void { global $DB; $this->resetAfterTest(true); @@ -102,16 +99,16 @@ public function test_get_question_options() { $this->assertEquals($formdata->shownumcorrect, $options->shownumcorrect); foreach ($question->lines as $line) { - $this->assertEquals($line->type, $formdata->type[$line->number -1]); - $this->assertEquals($line->labelstart, $formdata->labelstart[$line->number -1]); - $this->assertEquals($line->labelmiddle, $formdata->labelmiddle[$line->number -1]); - $this->assertEquals($line->labelend, $formdata->labelend[$line->number -1]); - $this->assertEquals($line->zonestart, $formdata->zonestart[$line->number -1]); - $this->assertEquals($line->zoneend, $formdata->zoneend[$line->number -1]); + $this->assertEquals($line->type, $formdata->type[$line->number - 1]); + $this->assertEquals($line->labelstart, $formdata->labelstart[$line->number - 1]); + $this->assertEquals($line->labelmiddle, $formdata->labelmiddle[$line->number - 1]); + $this->assertEquals($line->labelend, $formdata->labelend[$line->number - 1]); + $this->assertEquals($line->zonestart, $formdata->zonestart[$line->number - 1]); + $this->assertEquals($line->zoneend, $formdata->zoneend[$line->number - 1]); }; } - public function test_save_lines() { + public function test_save_lines(): void { global $DB; $this->resetAfterTest(true);