Skip to content

Commit

Permalink
Add Slider question type compatibility with Feedback features for MOO… (
Browse files Browse the repository at this point in the history
#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]>
  • Loading branch information
rezeau authored Feb 23, 2024
1 parent 9dec750 commit a2692eb
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 1 deletion.
33 changes: 33 additions & 0 deletions classes/question/slider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,39 @@ public function response_template() {
return 'mod_questionnaire/response_slider';
}

/**
* True if question type supports feedback options. False by default.
* @return bool
*/
public function supports_feedback() {
return true;
}

/**
* True if the question supports feedback and has valid settings for feedback. Override if the default logic is not enough.
* @return bool
*/
public function valid_feedback() {
$extradata = json_decode($this->extradata);
$minrange = $extradata->minrange;
// Negative scores are not accepted in Feedback.
return $this->supports_feedback() && !empty($this->name) && $minrange >= 0;
}

/**
* Get the maximum score possible for feedback if appropriate. Override if default behaviour is not correct.
* @return int | boolean
*/
public function get_feedback_maxscore() {
if ($this->valid_feedback()) {
$extradata = json_decode($this->extradata);
$maxscore = $extradata->maxrange;
} else {
$maxscore = false;
}
return $maxscore;
}

/**
* Return the context tags for the check question template.
*
Expand Down
22 changes: 22 additions & 0 deletions classes/responsetype/slider.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,26 @@ public static function response_answers_by_question($rid) {
}
return $answers;
}

/**
* Provide the feedback scores for all requested response id's. This should be provided only by questions that provide feedback.
* @param array $rids
* @return array | boolean
*/
public function get_feedback_scores(array $rids) {
global $DB;
$rsql = '';
$params = [$this->question->id];
if (!empty($rids)) {
list($rsql, $rparams) = $DB->get_in_or_equal($rids);
$params = array_merge($params, $rparams);
$rsql = ' AND response_id ' . $rsql;
}
$sql = 'SELECT response_id as rid, response AS score ' .
'FROM {'.$this->response_table().'} r ' .
'WHERE r.question_id= ? ' . $rsql . ' ' .
'ORDER BY response_id ASC';
return $DB->get_records_sql($sql, $params);
}

}
3 changes: 2 additions & 1 deletion lang/en/questionnaire.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@
$string['feedbacknotes_help'] = 'Text entered here will be displayed to the respondents at the end of their Feedback Report';
$string['feedbackoptions'] = 'Feedback options';
$string['feedbackoptions_help'] = 'Feedback options are available if your questionnaire contains the following question types and question settings:
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.';
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.
Slider questions must NOT use a negative value for the Minimum slider range.';
$string['feedbackoptions_link'] = 'mod/questionnaire/personality_test';
$string['feedbackremovequestionfromsection'] = 'This question is part of feedback section [{$a}]';
$string['feedbackremovesection'] = 'Removing this question will completely remove feedback section [{$a}]';
Expand Down
82 changes: 82 additions & 0 deletions tests/behat/slider_feedback_question_type.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
@mod @mod_questionnaire
Feature: In questionnaire, slider questions can be defined with scores attributed to specific answers, in order
to provide score dependent feedback.
In order to define a feedback question
As a teacher
I must add a required slider question type.

@javascript
Scenario: Create a questionnaire with a slider question type and verify that feedback options exist.
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | name | description | course | idnumber | resume | navigate |
| questionnaire | Test questionnaire | Test questionnaire description | C1 | questionnaire0 | 1 | 1 |
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Test questionnaire"
And I follow "Feedback"
Then I should not see "Display Scores"
And I navigate to "Questions" in current page administration
Then I should see "Add questions"
And I add a "Slider" question and I fill the form with:
| Question Name | Q1 |
| Question Text | Slider question test 1 |
| Left label | Left |
| Right label | Right |
| Centre label | Center |
| Minimum slider range (left) | -5 |
| Maximum slider range (right) | 5 |
| Slider starting value | 0 |
| Slider increment value | 1 |
Then I should see " [Slider] (Q1)"
And I should see "Slider question test"
And I follow "Feedback"
Then I should not see "Display Scores"
And I navigate to "Questions" in current page administration
Then I should see "Add questions"
And I add a "Slider" question and I fill the form with:
| Question Name | Q2 |
| Question Text | Slider question test 2 |
| Left label | Left |
| Right label | Right |
| Centre label | Center |
| Minimum slider range (left) | 0 |
| Maximum slider range (right) | 5 |
| Slider starting value | 0 |
| Slider increment value | 1 |
Then I should see " [Slider] (Q2)"
And I add a "Slider" question and I fill the form with:
| Question Name | Q3 |
| Question Text | Slider question test 3 |
| Left label | Left |
| Right label | Right |
| Centre label | Center |
| Minimum slider range (left) | 0 |
| Maximum slider range (right) | 2 |
| Slider starting value | 0 |
| Slider increment value | 1 |
Then I should see " [Slider] (Q3)"
And I should see "Slider question test"
And I follow "Feedback"
And I should see "Feedback options"
And I should see "Display Scores"
And I set the field "id_feedbacksections" to "Feedback sections"
And I set the field "id_feedbackscores" to "Yes"
And I set the field "id_feedbacknotes" to "These are the main Feedback notes"
And I press "Save settings and edit Feedback Sections"
Then I should see "[New section] section questions"
And I follow "[New section] section questions"
Then I should see "Add question to section"
And I should not see "Q1"
And I should see "Q2"
And I log out

0 comments on commit a2692eb

Please sign in to comment.