1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
// This page prints a particular instance of questionnaire.
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Manage feedback settings.
|
|
|
21 |
*
|
|
|
22 |
* @package mod_questionnaire
|
|
|
23 |
* @copyright 2016 onward Mike Churchward (mike.churchward@poetgroup.org)
|
|
|
24 |
* @author Joseph Rezeau
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
require_once("../../config.php");
|
|
|
29 |
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
|
|
|
30 |
|
|
|
31 |
$id = required_param('id', PARAM_INT); // Course module ID.
|
|
|
32 |
$currentgroupid = optional_param('group', 0, PARAM_INT); // Groupid.
|
|
|
33 |
$action = optional_param('action', '', PARAM_ALPHA);
|
|
|
34 |
|
|
|
35 |
if (! $cm = get_coursemodule_from_id('questionnaire', $id)) {
|
|
|
36 |
throw new \moodle_exception('invalidcoursemodule', 'mod_questionnaire');
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
if (! $course = $DB->get_record("course", ["id" => $cm->course])) {
|
|
|
40 |
throw new \moodle_exception('coursemisconf', 'mod_questionnaire');
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
if (! $questionnaire = $DB->get_record("questionnaire", ["id" => $cm->instance])) {
|
|
|
44 |
throw new \moodle_exception('invalidcoursemodule', 'mod_questionnaire');
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
// Needed here for forced language courses.
|
|
|
48 |
require_course_login($course, true, $cm);
|
|
|
49 |
$context = context_module::instance($cm->id);
|
|
|
50 |
|
|
|
51 |
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/questionnaire/feedback.php', ['id' => $id]));
|
|
|
52 |
$PAGE->set_context($context);
|
|
|
53 |
if (!isset($SESSION->questionnaire)) {
|
|
|
54 |
$SESSION->questionnaire = new stdClass();
|
|
|
55 |
}
|
|
|
56 |
$questionnaire = new questionnaire($course, $cm, 0, $questionnaire);
|
|
|
57 |
|
|
|
58 |
// Add renderer and page objects to the questionnaire object for display use.
|
|
|
59 |
$questionnaire->add_renderer($PAGE->get_renderer('mod_questionnaire'));
|
|
|
60 |
$questionnaire->add_page(new \mod_questionnaire\output\feedbackpage());
|
|
|
61 |
|
|
|
62 |
$SESSION->questionnaire->current_tab = 'feedback';
|
|
|
63 |
|
|
|
64 |
if (!$questionnaire->capabilities->editquestions) {
|
|
|
65 |
throw new \moodle_exception('nopermissions', 'mod_questionnaire');
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
$feedbackform = new \mod_questionnaire\feedback_form('feedback.php');
|
|
|
69 |
$sdata = clone($questionnaire->survey);
|
|
|
70 |
$sdata->sid = $questionnaire->survey->id;
|
|
|
71 |
$sdata->id = $cm->id;
|
|
|
72 |
|
|
|
73 |
$draftideditor = file_get_submitted_draft_itemid('feedbacknotes');
|
|
|
74 |
$currentinfo = file_prepare_draft_area($draftideditor, $context->id, 'mod_questionnaire', 'feedbacknotes',
|
|
|
75 |
$sdata->sid, ['subdirs' => true], $questionnaire->survey->feedbacknotes);
|
|
|
76 |
$sdata->feedbacknotes = ['text' => $currentinfo, 'format' => FORMAT_HTML, 'itemid' => $draftideditor];
|
|
|
77 |
|
|
|
78 |
$feedbackform->set_data($sdata);
|
|
|
79 |
|
|
|
80 |
if ($feedbackform->is_cancelled()) {
|
|
|
81 |
redirect(new moodle_url('/mod/questionnaire/view.php', ['id' => $questionnaire->cm->id]));
|
|
|
82 |
}
|
|
|
83 |
// Confirm that feedback can be used for this questionnaire...
|
|
|
84 |
// Get all questions that are valid feedback questions.
|
|
|
85 |
$validquestions = false;
|
|
|
86 |
foreach ($questionnaire->questions as $question) {
|
|
|
87 |
if ($question->valid_feedback()) {
|
|
|
88 |
$validquestions = true;
|
|
|
89 |
break;
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
if ($settings = $feedbackform->get_data()) {
|
|
|
94 |
if (isset($settings->feedbacksettingsbutton1) || isset($settings->feedbacksettingsbutton2) || isset($settings->buttongroup)) {
|
|
|
95 |
if (isset ($settings->feedbackscores)) {
|
|
|
96 |
$sdata->feedbackscores = $settings->feedbackscores;
|
|
|
97 |
} else {
|
|
|
98 |
$sdata->feedbackscores = 0;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
if (isset ($settings->feedbacknotes)) {
|
|
|
102 |
$sdata->fbnotesitemid = $settings->feedbacknotes['itemid'];
|
|
|
103 |
$sdata->fbnotesformat = $settings->feedbacknotes['format'];
|
|
|
104 |
$sdata->feedbacknotes = $settings->feedbacknotes['text'];
|
|
|
105 |
$sdata->feedbacknotes = file_save_draft_area_files($sdata->fbnotesitemid, $context->id, 'mod_questionnaire',
|
|
|
106 |
'feedbacknotes', $sdata->id, ['subdirs' => true], $sdata->feedbacknotes);
|
|
|
107 |
} else {
|
|
|
108 |
$sdata->feedbacknotes = '';
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
if ($settings->feedbacksections > 0) {
|
|
|
112 |
$sdata->feedbacksections = $settings->feedbacksections;
|
|
|
113 |
$usergraph = get_config('questionnaire', 'usergraph');
|
|
|
114 |
if ($usergraph) {
|
|
|
115 |
if ($settings->feedbacksections == 1) {
|
|
|
116 |
$sdata->chart_type = $settings->chart_type_global;
|
|
|
117 |
} else if ($settings->feedbacksections == 2) {
|
|
|
118 |
$sdata->chart_type = $settings->chart_type_two_sections;
|
|
|
119 |
} else if ($settings->feedbacksections > 2) {
|
|
|
120 |
$sdata->chart_type = $settings->chart_type_sections;
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
} else {
|
|
|
124 |
$sdata->feedbacksections = 0;
|
|
|
125 |
}
|
|
|
126 |
$sdata->courseid = $settings->courseid;
|
|
|
127 |
if (!($sid = $questionnaire->survey_update($sdata))) {
|
|
|
128 |
throw new \moodle_exception('couldnotcreatenewsurvey', 'mod_questionnaire');
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
// Handle the edit feedback sections action.
|
|
|
133 |
if (isset($settings->buttongroup['feedbackeditbutton'])) {
|
|
|
134 |
// Create a single section for Global Feedback if not existent.
|
|
|
135 |
if (!($firstsection = $DB->get_field('questionnaire_fb_sections', 'MIN(section)', ['surveyid' => $questionnaire->sid]))) {
|
|
|
136 |
$firstsection = 0;
|
|
|
137 |
}
|
|
|
138 |
if (($sdata->feedbacksections > 0) && ($firstsection == 0)) {
|
|
|
139 |
if ($sdata->feedbacksections == 1) {
|
|
|
140 |
$sectionlabel = get_string('feedbackglobal', 'questionnaire');
|
|
|
141 |
} else {
|
|
|
142 |
$sectionlabel = get_string('feedbackdefaultlabel', 'questionnaire');
|
|
|
143 |
}
|
|
|
144 |
$feedbacksection = mod_questionnaire\feedback\section::new_section($questionnaire->sid, $sectionlabel);
|
|
|
145 |
}
|
|
|
146 |
redirect(new moodle_url('/mod/questionnaire/fbsections.php', ['id' => $cm->id, 'section' => $firstsection]));
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
// Print the page header.
|
|
|
151 |
$PAGE->set_title(get_string('editingfeedback', 'questionnaire'));
|
|
|
152 |
$PAGE->set_heading(format_string($course->fullname));
|
|
|
153 |
$PAGE->navbar->add(get_string('editingfeedback', 'questionnaire'));
|
|
|
154 |
echo $questionnaire->renderer->header();
|
|
|
155 |
require('tabs.php');
|
|
|
156 |
if (!$validquestions) {
|
|
|
157 |
$questionnaire->page->add_to_page('formarea', get_string('feedbackoptions_help', 'questionnaire'));
|
|
|
158 |
} else {
|
|
|
159 |
$questionnaire->page->add_to_page('formarea', $feedbackform->render());
|
|
|
160 |
}
|
|
|
161 |
echo $questionnaire->renderer->render($questionnaire->page);
|
|
|
162 |
echo $questionnaire->renderer->footer($course);
|