Skip to content

Commit

Permalink
MDL-74332 mod_survey: Critical incidents dont require summary and scales
Browse files Browse the repository at this point in the history
Do not show summary and scales for the survey with critical
incidents. So critical incidents survey would have questions
and participants only under response reports.
Also corrected the heading for the Questions page.
  • Loading branch information
sharidas committed Apr 4, 2022
1 parent b5f5188 commit bfb4c27
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 31 deletions.
52 changes: 26 additions & 26 deletions mod/survey/classes/output/actionbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,36 @@ public function __construct(int $id, string $action, moodle_url $currenturl) {
* @return url_select url_select object.
*/
private function create_select_menu(): url_select {
$summarylink = new moodle_url('/mod/survey/report.php', ['id' => $this->id, 'action' => 'summary']);
$scaleslink = new moodle_url('/mod/survey/report.php', ['id' => $this->id, 'action' => 'scales']);
$questionslink = new moodle_url('/mod/survey/report.php', ['id' => $this->id, 'action' => 'questions']);
$participantslink = new moodle_url('/mod/survey/report.php', ['id' => $this->id, 'action' => 'students']);
$menu = [];
$actions = $this->get_available_reports();

$menu = [
$summarylink->out(false) => get_string('summary', 'survey'),
$scaleslink->out(false) => get_string('scales', 'survey'),
$questionslink->out(false) => get_string('questions', 'survey'),
$participantslink->out(false) => get_string('participants'),
];
foreach ($actions as $action => $straction) {
$url = new moodle_url($this->currenturl, ['id' => $this->id, 'action' => $action]);
$menu[$url->out(false)] = $straction;
}
return new url_select($menu, $this->currenturl->out(false), null, 'surveyresponseselect');
}

/**
* Generate available reports list
*
* @return array The list of available action => action string.
*/
private function get_available_reports(): array {
global $DB;

$cm = get_coursemodule_from_id('survey', $this->id);
$survey = $DB->get_record("survey", ["id" => $cm->instance]);

switch ($this->action) {
case 'summary':
$activeurl = $summarylink;
break;
case 'scales':
$activeurl = $scaleslink;
break;
case 'questions':
$activeurl = $questionslink;
break;
case 'students':
$activeurl = $participantslink;
break;
default:
$activeurl = $this->currenturl;
$actions = [];
if ($survey && ($survey->template != SURVEY_CIQ)) {
$actions['summary'] = get_string('summary', 'survey');
$actions['scales'] = get_string('scales', 'survey');
}
$actions['questions'] = get_string('questions', 'survey');
$actions['students'] = get_string('participants');

return new url_select($menu, $activeurl->out(false), null, 'surveyresponseselect');
return $actions;
}

/**
Expand Down
1 change: 1 addition & 0 deletions mod/survey/lang/en/deprecated.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
clicktocontinue,mod_survey
viewsurveyresponses,mod_survey
allquestions,mod_survey
2 changes: 1 addition & 1 deletion mod/survey/lang/en/survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
$string['actual'] = 'Actual';
$string['actualclass'] = 'Class actual';
$string['actualstudent'] = '{$a} actual';
$string['allquestions'] = 'All questions in order, all students';
$string['allscales'] = 'All scales, all students';
$string['alreadysubmitted'] = 'You have already submitted this survey';
$string['analysisof'] = 'Analysis of {$a}';
Expand Down Expand Up @@ -286,3 +285,4 @@
// Deprecated since Moodle 4.0.
$string['clicktocontinue'] = 'Click here to continue';
$string['viewsurveyresponses'] = 'View {$a} survey responses';
$string['allquestions'] = 'All questions in order, all students';
11 changes: 9 additions & 2 deletions mod/survey/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,16 @@ function survey_supports($feature) {
* @param navigation_node $surveynode
*/
function survey_extend_settings_navigation(settings_navigation $settings, navigation_node $surveynode) {
global $DB;
if (has_capability('mod/survey:readresponses', $settings->get_page()->cm->context)) {
$url = new moodle_url('/mod/survey/report.php', array('id' => $settings->get_page()->cm->id,
'action' => 'summary'));
$cm = get_coursemodule_from_id('survey', $settings->get_page()->cm->id);
$survey = $DB->get_record("survey", ["id" => $cm->instance]);
$url = new moodle_url('/mod/survey/report.php', ['id' => $settings->get_page()->cm->id]);
if ($survey && ($survey->template != SURVEY_CIQ)) {
$url->param('action', 'summary');
} else {
$url->param('action', 'questions');
}
$surveynode->add(get_string("responsereports", "survey"), $url);
}
}
Expand Down
14 changes: 12 additions & 2 deletions mod/survey/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
$strquestions = get_string("questions", "survey");
$strdownload = get_string("download", "survey");
$strallscales = get_string("allscales", "survey");
$strallquestions = get_string("allquestions", "survey");
$strselectedquestions = get_string("selectedquestions", "survey");
$strseemoredetail = get_string("seemoredetail", "survey");
$strnotes = get_string("notes", "survey");
Expand Down Expand Up @@ -148,6 +147,10 @@
switch ($action) {

case "summary":
// If survey type is Critical incidents then we don't show summary report.
if ($survey->template == SURVEY_CIQ) {
throw new moodle_exception('cannotviewreport');
}
echo $OUTPUT->heading($strsummary, 3);

if ($groupsactivitymenu) {
Expand All @@ -164,6 +167,10 @@
break;

case "scales":
// If survey type is Critical incidents then we don't show scales report.
if ($survey->template == SURVEY_CIQ) {
throw new moodle_exception('cannotviewreport');
}
echo $OUTPUT->heading($strscales, 3);

if ($groupsactivitymenu) {
Expand Down Expand Up @@ -218,7 +225,7 @@
$questions = $DB->get_records_list("survey_questions", "id", explode(',',$survey->questions));
$questionorder = explode(",", $survey->questions);

echo $OUTPUT->heading($strallquestions, 3);
echo $OUTPUT->heading($strquestions, 3);
}

if ($groupsactivitymenu) {
Expand Down Expand Up @@ -506,5 +513,8 @@

break;

default:
throw new moodle_exception('cannotviewreport');

}
echo $OUTPUT->footer();
54 changes: 54 additions & 0 deletions mod/survey/tests/behat/survey_critical_incidents.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
@mod @mod_survey @javascript
Feature: A teacher navigates to response reports of students
If survey activity is configured for critical students
Only questions and particiats pages should be visible under response reports

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 1 | student2@example.com |
And the following "courses" exist:
| fullname | shortname | category | enablecompletion |
| Course 1 | C1 | 0 | 1 |
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 | intro | course | idnumber | section |
| survey | Test survey name | Test survey description | C1 | survey1 | 1 |

Scenario: Only questions and participants page should be available under response reports as teacher
Given I am on the "Test survey name" "survey activity" page logged in as teacher1
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Survey type | Critical incidents |
And I press "Save and return to course"
And I log out
And I am on the "Test survey name" "survey activity" page logged in as student1
And I set the field "At what moment in class were you most engaged as a learner?" to "most engaged as student1"
And I set the field "At what moment in class were you most distanced as a learner?" to "most distanced as student1"
And I set the field "What action from anyone in the forums did you find most affirming or helpful?" to "most helpful student1"
And I set the field "What action from anyone in the forums did you find most puzzling or confusing?" to "most confusing student1"
And I set the field "What event surprised you most?" to "most surprised student1"
And I press "Submit"
And I press "Continue"
And I log out
And I am on the "Test survey name" "survey activity" page logged in as student2
And I set the field "At what moment in class were you most engaged as a learner?" to "most engaged as student2"
And I set the field "At what moment in class were you most distanced as a learner?" to "most distanced as student2"
And I set the field "What action from anyone in the forums did you find most affirming or helpful?" to "most helpful student2"
And I set the field "What action from anyone in the forums did you find most puzzling or confusing?" to "most confusing student2"
And I set the field "What event surprised you most?" to "most surprised student1"
And I press "Submit"
And I press "Continue"
And I log out
When I am on the "Test survey name" "survey activity" page logged in as teacher1
And I navigate to "Response reports" in current page administration
Then I should not see "Summary"
And I should not see "Scales"
And I should see "Questions"
And I should see "Participants"

0 comments on commit bfb4c27

Please sign in to comment.