Skip to content

Commit a2692eb

Browse files
authored
Add Slider question type compatibility with Feedback features for MOO… (#520)
* Add Slider question type compatibility with Feedback features for MOODLE_401_STABLE Signed-off-by: rezeau <[email protected]> * removed trailing spaces in slider_feedback_question_type.feature Signed-off-by: rezeau <[email protected]> --------- Signed-off-by: rezeau <[email protected]>
1 parent 9dec750 commit a2692eb

File tree

4 files changed

+139
-1
lines changed

4 files changed

+139
-1
lines changed

classes/question/slider.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,39 @@ public function response_template() {
6767
return 'mod_questionnaire/response_slider';
6868
}
6969

70+
/**
71+
* True if question type supports feedback options. False by default.
72+
* @return bool
73+
*/
74+
public function supports_feedback() {
75+
return true;
76+
}
77+
78+
/**
79+
* True if the question supports feedback and has valid settings for feedback. Override if the default logic is not enough.
80+
* @return bool
81+
*/
82+
public function valid_feedback() {
83+
$extradata = json_decode($this->extradata);
84+
$minrange = $extradata->minrange;
85+
// Negative scores are not accepted in Feedback.
86+
return $this->supports_feedback() && !empty($this->name) && $minrange >= 0;
87+
}
88+
89+
/**
90+
* Get the maximum score possible for feedback if appropriate. Override if default behaviour is not correct.
91+
* @return int | boolean
92+
*/
93+
public function get_feedback_maxscore() {
94+
if ($this->valid_feedback()) {
95+
$extradata = json_decode($this->extradata);
96+
$maxscore = $extradata->maxrange;
97+
} else {
98+
$maxscore = false;
99+
}
100+
return $maxscore;
101+
}
102+
70103
/**
71104
* Return the context tags for the check question template.
72105
*

classes/responsetype/slider.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,26 @@ public static function response_answers_by_question($rid) {
5151
}
5252
return $answers;
5353
}
54+
55+
/**
56+
* Provide the feedback scores for all requested response id's. This should be provided only by questions that provide feedback.
57+
* @param array $rids
58+
* @return array | boolean
59+
*/
60+
public function get_feedback_scores(array $rids) {
61+
global $DB;
62+
$rsql = '';
63+
$params = [$this->question->id];
64+
if (!empty($rids)) {
65+
list($rsql, $rparams) = $DB->get_in_or_equal($rids);
66+
$params = array_merge($params, $rparams);
67+
$rsql = ' AND response_id ' . $rsql;
68+
}
69+
$sql = 'SELECT response_id as rid, response AS score ' .
70+
'FROM {'.$this->response_table().'} r ' .
71+
'WHERE r.question_id= ? ' . $rsql . ' ' .
72+
'ORDER BY response_id ASC';
73+
return $DB->get_records_sql($sql, $params);
74+
}
75+
5476
}

lang/en/questionnaire.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@
216216
$string['feedbacknotes_help'] = 'Text entered here will be displayed to the respondents at the end of their Feedback Report';
217217
$string['feedbackoptions'] = 'Feedback options';
218218
$string['feedbackoptions_help'] = 'Feedback options are available if your questionnaire contains the following question types and question settings:
219-
Radio buttons; Dropdown box; Yes/No; or Rate (normal or Osgood scale). Those questions must be set as Required, their Question Name field must NOT be empty and the Possible answers choices must contain a value.';
219+
Radio buttons; Dropdown box; Yes/No; Rate (normal or Osgood scale) or Slider. Those questions must be set as Required, their Question Name field must NOT be empty and the Possible answers choices must contain a value.
220+
Slider questions must NOT use a negative value for the Minimum slider range.';
220221
$string['feedbackoptions_link'] = 'mod/questionnaire/personality_test';
221222
$string['feedbackremovequestionfromsection'] = 'This question is part of feedback section [{$a}]';
222223
$string['feedbackremovesection'] = 'Removing this question will completely remove feedback section [{$a}]';
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
@mod @mod_questionnaire
2+
Feature: In questionnaire, slider questions can be defined with scores attributed to specific answers, in order
3+
to provide score dependent feedback.
4+
In order to define a feedback question
5+
As a teacher
6+
I must add a required slider question type.
7+
8+
@javascript
9+
Scenario: Create a questionnaire with a slider question type and verify that feedback options exist.
10+
Given the following "users" exist:
11+
| username | firstname | lastname | email |
12+
| teacher1 | Teacher | 1 | teacher1@example.com |
13+
| student1 | Student | 1 | student1@example.com |
14+
And the following "courses" exist:
15+
| fullname | shortname | category |
16+
| Course 1 | C1 | 0 |
17+
And the following "course enrolments" exist:
18+
| user | course | role |
19+
| teacher1 | C1 | editingteacher |
20+
| student1 | C1 | student |
21+
And the following "activities" exist:
22+
| activity | name | description | course | idnumber | resume | navigate |
23+
| questionnaire | Test questionnaire | Test questionnaire description | C1 | questionnaire0 | 1 | 1 |
24+
And I log in as "teacher1"
25+
And I am on "Course 1" course homepage
26+
And I follow "Test questionnaire"
27+
And I follow "Feedback"
28+
Then I should not see "Display Scores"
29+
And I navigate to "Questions" in current page administration
30+
Then I should see "Add questions"
31+
And I add a "Slider" question and I fill the form with:
32+
| Question Name | Q1 |
33+
| Question Text | Slider question test 1 |
34+
| Left label | Left |
35+
| Right label | Right |
36+
| Centre label | Center |
37+
| Minimum slider range (left) | -5 |
38+
| Maximum slider range (right) | 5 |
39+
| Slider starting value | 0 |
40+
| Slider increment value | 1 |
41+
Then I should see " [Slider] (Q1)"
42+
And I should see "Slider question test"
43+
And I follow "Feedback"
44+
Then I should not see "Display Scores"
45+
And I navigate to "Questions" in current page administration
46+
Then I should see "Add questions"
47+
And I add a "Slider" question and I fill the form with:
48+
| Question Name | Q2 |
49+
| Question Text | Slider question test 2 |
50+
| Left label | Left |
51+
| Right label | Right |
52+
| Centre label | Center |
53+
| Minimum slider range (left) | 0 |
54+
| Maximum slider range (right) | 5 |
55+
| Slider starting value | 0 |
56+
| Slider increment value | 1 |
57+
Then I should see " [Slider] (Q2)"
58+
And I add a "Slider" question and I fill the form with:
59+
| Question Name | Q3 |
60+
| Question Text | Slider question test 3 |
61+
| Left label | Left |
62+
| Right label | Right |
63+
| Centre label | Center |
64+
| Minimum slider range (left) | 0 |
65+
| Maximum slider range (right) | 2 |
66+
| Slider starting value | 0 |
67+
| Slider increment value | 1 |
68+
Then I should see " [Slider] (Q3)"
69+
And I should see "Slider question test"
70+
And I follow "Feedback"
71+
And I should see "Feedback options"
72+
And I should see "Display Scores"
73+
And I set the field "id_feedbacksections" to "Feedback sections"
74+
And I set the field "id_feedbackscores" to "Yes"
75+
And I set the field "id_feedbacknotes" to "These are the main Feedback notes"
76+
And I press "Save settings and edit Feedback Sections"
77+
Then I should see "[New section] section questions"
78+
And I follow "[New section] section questions"
79+
Then I should see "Add question to section"
80+
And I should not see "Q1"
81+
And I should see "Q2"
82+
And I log out

0 commit comments

Comments
 (0)