From bc73c640717a202fda233ec9ab6c39d968d35ef4 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Thu, 28 Apr 2016 16:42:22 +0800 Subject: [PATCH] MDL-53638 mod_feedback: fix to responsetime in non-anon answer --- mod/feedback/classes/complete_form.php | 24 +-- mod/feedback/item/info/lib.php | 18 ++- mod/feedback/item/multichoice/lib.php | 2 + .../tests/behat/question_types.feature | 6 +- .../behat/question_types_non_anon.feature | 141 ++++++++++++++++++ 5 files changed, 171 insertions(+), 20 deletions(-) create mode 100644 mod/feedback/tests/behat/question_types_non_anon.feature diff --git a/mod/feedback/classes/complete_form.php b/mod/feedback/classes/complete_form.php index a281464b3d8..9573a64f611 100644 --- a/mod/feedback/classes/complete_form.php +++ b/mod/feedback/classes/complete_form.php @@ -117,30 +117,22 @@ class mod_feedback_complete_form extends moodleform { $mform->closeHeaderBefore('buttonar'); } + if ($this->mode == self::MODE_COMPLETE) { + $this->definition_complete(); + } else { + $this->definition_preview(); + } + // Set data. $this->set_data(array('gopage' => $this->gopage)); } - /** - * This method is called after definition(), data submission and set_data(). - * All form setup that is dependent on form values should go in here. - */ - public function definition_after_data() { - parent::definition_after_data(); - - if ($this->mode == self::MODE_COMPLETE) { - $this->definition_after_data_complete(); - } else { - $this->definition_after_data_preview(); - } - } - /** * Called from definition_after_data() in the completion mode * * This will add only items from a current page to the feedback and adjust the buttons */ - protected function definition_after_data_complete() { + protected function definition_complete() { if (!$this->structure instanceof mod_feedback_completion) { // We should not really be here but just in case. return; @@ -174,7 +166,7 @@ class mod_feedback_complete_form extends moodleform { * * This will add all items to the form, including pagebreaks as horizontal rules. */ - protected function definition_after_data_preview() { + protected function definition_preview() { foreach ($this->structure->get_items() as $feedbackitem) { $itemobj = feedback_get_item_class($feedbackitem->typ); $itemobj->complete_form_element($feedbackitem, $this); diff --git a/mod/feedback/item/info/lib.php b/mod/feedback/item/info/lib.php index 10824f24ea9..20cc371a470 100644 --- a/mod/feedback/item/info/lib.php +++ b/mod/feedback/item/info/lib.php @@ -27,6 +27,9 @@ class feedback_item_info extends feedback_item_base { /** Mode recording current course category */ const MODE_CATEGORY = 3; + /** Special constant to keep the current timestamp as value for the form element */ + const CURRENTTIMESTAMP = '__CURRENT__TIMESTAMP__'; + public function build_editform($item, $feedback, $cm) { global $DB, $CFG; require_once('info_form.php'); @@ -130,7 +133,7 @@ class feedback_item_info extends feedback_item_base { public function get_printval($item, $value) { - if (!isset($value->value)) { + if (strval($value->value) === '') { return ''; } return $item->presentation == self::MODE_RESPONSETIME ? @@ -231,6 +234,7 @@ class feedback_item_info extends feedback_item_base { switch ($item->presentation) { case self::MODE_RESPONSETIME: $class = 'info-responsetime'; + $value = $value ? self::CURRENTTIMESTAMP : ''; break; case self::MODE_COURSE: $class = 'info-course'; @@ -256,6 +260,18 @@ class feedback_item_info extends feedback_item_base { } } + /** + * Converts the value from complete_form data to the string value that is stored in the db. + * @param mixed $value element from mod_feedback_complete_form::get_data() with the name $item->typ.'_'.$item->id + * @return string + */ + public function create_value($value) { + if ($value === self::CURRENTTIMESTAMP) { + return strval(time()); + } + return parent::create_value($value); + } + public function can_switch_require() { return false; } diff --git a/mod/feedback/item/multichoice/lib.php b/mod/feedback/item/multichoice/lib.php index b58b30abbf8..bd15d3e10c0 100644 --- a/mod/feedback/item/multichoice/lib.php +++ b/mod/feedback/item/multichoice/lib.php @@ -336,8 +336,10 @@ class feedback_item_multichoice extends feedback_item_base { if ($info->subtype === 'c') { // Checkboxes. $objs[] = ['hidden', $inputname.'[0]', 0]; + $form->set_element_type($inputname.'[0]', PARAM_INT); foreach ($options as $idx => $label) { $objs[] = ['advcheckbox', $inputname.'['.$idx.']', '', $label, null, array(0, $idx)]; + $form->set_element_type($inputname.'['.$idx.']', PARAM_INT); } $element = $form->add_form_group_element($item, 'group_'.$inputname, $name, $objs, $separator, $class); if ($tmpvalue) { diff --git a/mod/feedback/tests/behat/question_types.feature b/mod/feedback/tests/behat/question_types.feature index 4e8235fd516..b7092c8b2cd 100644 --- a/mod/feedback/tests/behat/question_types.feature +++ b/mod/feedback/tests/behat/question_types.feature @@ -1,5 +1,5 @@ @mod @mod_feedback -Feature: Test creating different types of feedback questions +Feature: Test creating different types of feedback questions for anonymous feedback In order to create feedbacks As a teacher I need to be able to add different question types @@ -127,11 +127,11 @@ Feature: Test creating different types of feedback questions And I should see "no way" in the "(shorttext)" "table" And I should see "hello" in the "(shorttext)" "table" - Scenario: Create different types of questions in feedback with javascript disabled + Scenario: Create different types of questions in anonymous feedback with javascript disabled And I log out @javascript - Scenario: Create different types of questions in feedback with javascript enabled + Scenario: Create different types of questions in anonymous feedback with javascript enabled And I should see "1 (50.00 %)" in the "option a:" "table_row" And I should see "1 (50.00 %)" in the "option b:" "table_row" And I log out diff --git a/mod/feedback/tests/behat/question_types_non_anon.feature b/mod/feedback/tests/behat/question_types_non_anon.feature new file mode 100644 index 00000000000..89e6ccb7041 --- /dev/null +++ b/mod/feedback/tests/behat/question_types_non_anon.feature @@ -0,0 +1,141 @@ +@mod @mod_feedback +Feature: Test creating different types of feedback questions for non-anonymous feedback + In order to create feedbacks + As a teacher + I need to be able to add different question types + + Background: + Given the following "users" exist: + | username | firstname | lastname | + | teacher1 | Teacher | 1 | + | student1 | Student | 1 | + | student2 | Student | 2 | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + And the following "activities" exist: + | activity | name | course | idnumber | anonymous | + | feedback | Learning experience | C1 | feedback0 | 2 | + When I log in as "teacher1" + And I follow "Course 1" + And I follow "Learning experience" + And I follow "Edit questions" + And I add a "Information" question to the feedback with: + | Question | this is an information question | + | Label | info | + | Information-Type | Course | + And I add a "Information" question to the feedback with: + | Question | this is a response time question | + | Label | curtime | + | Information-Type | Responsestime | + And I add a "Label" question to the feedback with: + | Contents | label text | + And I add a "Longer text answer" question to the feedback with: + | Question | this is a longer text answer | + | Label | longertext | + And I add a "Multiple choice" question to the feedback with: + | Question | this is a multiple choice 1 | + | Label | multichoice1 | + | Multiple choice type | Multiple choice - single answer | + | Multiple choice values | option a\noption b\noption c | + And I add a "Multiple choice" question to the feedback with: + | Question | this is a multiple choice 2 | + | Label | multichoice2 | + | Multiple choice type | Multiple choice - multiple answers | + | Hide the "Not selected" option | Yes | + | Multiple choice values | option d\noption e\noption f | + And I add a "Multiple choice" question to the feedback with: + | Question | this is a multiple choice 3 | + | Label | multichoice3 | + | Multiple choice type | Multiple choice - single answer allowed (dropdownlist) | + | Multiple choice values | option g\noption h\noption i | + And I add a "Multiple choice (rated)" question to the feedback with: + | Question | this is a multiple choice rated | + | Label | multichoice4 | + | Multiple choice type | Multiple choice - single answer | + | Multiple choice values | 0/option k\n1/option l\n5/option m | + And I add a "Numeric answer" question to the feedback with: + | Question | this is a numeric answer | + | Label | numeric | + | Range from | 0 | + | Range to | 100 | + And I add a "Short text answer" question to the feedback with: + | Question | this is a short text answer | + | Label | shorttext | + | Maximum characters accepted | 200 | + And I log out + And I log in as "student1" + And I follow "Course 1" + And I follow "Learning experience" + And I follow "Answer the questions..." + And I set the following fields to these values: + | this is a longer text answer | my long answer | + | option b | 1 | + | option d | 1 | + | option f | 1 | + | this is a multiple choice 3 | option h | + | option l | 1 | + | this is a numeric answer (0 - 100) | 35 | + | this is a short text answer | hello | + And I press "Submit your answers" + And I log out + And I log in as "student2" + And I follow "Course 1" + And I follow "Learning experience" + And I follow "Answer the questions..." + And I set the following fields to these values: + | this is a longer text answer | lots of feedbacks | + | option a | 1 | + | option d | 1 | + | option e | 1 | + | this is a multiple choice 3 | option i | + | option m | 1 | + | this is a numeric answer (0 - 100) | 71 | + | this is a short text answer | no way | + And I press "Submit your answers" + And I log out + When I log in as "teacher1" + And I follow "Course 1" + And I follow "Learning experience" + And I follow "Analysis" + And I should see "Submitted answers: 2" + And I should see "Questions: 9" + And I log out + And I log in as "teacher1" + And I follow "Course 1" + And I follow "Learning experience" + And I follow "Analysis" + And I should see "C1" in the "(info)" "table" + And I should see "my long answer" in the "(longertext)" "table" + And I should see "lots of feedbacks" in the "(longertext)" "table" + And I should see "2 (100.00 %)" in the "option d:" "table_row" + And I should see "1 (50.00 %)" in the "option e:" "table_row" + And I should see "1 (50.00 %)" in the "option f:" "table_row" + And I should see "0" in the "option g:" "table_row" + And I should not see "%" in the "option g:" "table_row" + And I should see "1 (50.00 %)" in the "option h:" "table_row" + And I should see "1 (50.00 %)" in the "option i:" "table_row" + And I should see "0" in the "(0) option k" "table_row" + And I should not see "%" in the "(0) option k" "table_row" + And I should see "1 (50.00 %)" in the "(1) option l" "table_row" + And I should see "1 (50.00 %)" in the "(5) option m:" "table_row" + And I should see "Average: 3.00" in the "(multichoice4)" "table" + And I should see "35" in the "(numeric)" "table" + And I should see "71" in the "(numeric)" "table" + And I should see "Average: 53.00" in the "(numeric)" "table" + And I should see "no way" in the "(shorttext)" "table" + And I should see "hello" in the "(shorttext)" "table" + + Scenario: Create different types of questions in non-anonymous feedback with javascript disabled + And I log out + + @javascript + Scenario: Create different types of questions in non-anonymous feedback with javascript enabled + And I should see "1 (50.00 %)" in the "option a:" "table_row" + And I should see "1 (50.00 %)" in the "option b:" "table_row" + And I log out