Merge branch 'wip-MDL-53638-fix' of https://github.com/marinaglancy/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2016-04-28 13:08:42 +02:00 committed by Dan Poltawski
commit eb98b1395d
5 changed files with 171 additions and 20 deletions

View file

@ -117,30 +117,22 @@ class mod_feedback_complete_form extends moodleform {
$mform->closeHeaderBefore('buttonar'); $mform->closeHeaderBefore('buttonar');
} }
if ($this->mode == self::MODE_COMPLETE) {
$this->definition_complete();
} else {
$this->definition_preview();
}
// Set data. // Set data.
$this->set_data(array('gopage' => $this->gopage)); $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 * 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 * 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) { if (!$this->structure instanceof mod_feedback_completion) {
// We should not really be here but just in case. // We should not really be here but just in case.
return; 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. * 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) { foreach ($this->structure->get_items() as $feedbackitem) {
$itemobj = feedback_get_item_class($feedbackitem->typ); $itemobj = feedback_get_item_class($feedbackitem->typ);
$itemobj->complete_form_element($feedbackitem, $this); $itemobj->complete_form_element($feedbackitem, $this);

View file

@ -27,6 +27,9 @@ class feedback_item_info extends feedback_item_base {
/** Mode recording current course category */ /** Mode recording current course category */
const MODE_CATEGORY = 3; 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) { public function build_editform($item, $feedback, $cm) {
global $DB, $CFG; global $DB, $CFG;
require_once('info_form.php'); require_once('info_form.php');
@ -130,7 +133,7 @@ class feedback_item_info extends feedback_item_base {
public function get_printval($item, $value) { public function get_printval($item, $value) {
if (!isset($value->value)) { if (strval($value->value) === '') {
return ''; return '';
} }
return $item->presentation == self::MODE_RESPONSETIME ? return $item->presentation == self::MODE_RESPONSETIME ?
@ -231,6 +234,7 @@ class feedback_item_info extends feedback_item_base {
switch ($item->presentation) { switch ($item->presentation) {
case self::MODE_RESPONSETIME: case self::MODE_RESPONSETIME:
$class = 'info-responsetime'; $class = 'info-responsetime';
$value = $value ? self::CURRENTTIMESTAMP : '';
break; break;
case self::MODE_COURSE: case self::MODE_COURSE:
$class = 'info-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() { public function can_switch_require() {
return false; return false;
} }

View file

@ -336,8 +336,10 @@ class feedback_item_multichoice extends feedback_item_base {
if ($info->subtype === 'c') { if ($info->subtype === 'c') {
// Checkboxes. // Checkboxes.
$objs[] = ['hidden', $inputname.'[0]', 0]; $objs[] = ['hidden', $inputname.'[0]', 0];
$form->set_element_type($inputname.'[0]', PARAM_INT);
foreach ($options as $idx => $label) { foreach ($options as $idx => $label) {
$objs[] = ['advcheckbox', $inputname.'['.$idx.']', '', $label, null, array(0, $idx)]; $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); $element = $form->add_form_group_element($item, 'group_'.$inputname, $name, $objs, $separator, $class);
if ($tmpvalue) { if ($tmpvalue) {

View file

@ -1,5 +1,5 @@
@mod @mod_feedback @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 In order to create feedbacks
As a teacher As a teacher
I need to be able to add different question types 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 "no way" in the "(shorttext)" "table"
And I should see "hello" 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 And I log out
@javascript @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 a:" "table_row"
And I should see "1 (50.00 %)" in the "option b:" "table_row" And I should see "1 (50.00 %)" in the "option b:" "table_row"
And I log out And I log out

View file

@ -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