Skip to content

Commit db931ae

Browse files
committed
WIP6
1 parent e93b9de commit db931ae

File tree

5 files changed

+155
-69
lines changed

5 files changed

+155
-69
lines changed

classes/feedback_form.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
defined('MOODLE_INTERNAL') || die();
2020

2121
require_once($CFG->libdir . '/formslib.php');
22-
require_once($CFG->dirroot.'/mod/questionnaire/lib.php');
22+
require_once($CFG->dirroot . '/mod/questionnaire/lib.php');
2323

2424
/**
2525
* Print the form to manage feedback settings.
@@ -30,7 +30,6 @@
3030
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
3131
*/
3232
class feedback_form extends \moodleform {
33-
3433
/**
3534
* Defition of the form.
3635
*/
@@ -60,9 +59,13 @@ public function definition() {
6059
$charttypes = [null => get_string('none'),
6160
'bipolar' => get_string('chart:bipolar', 'questionnaire'),
6261
'vprogress' => get_string('chart:vprogress', 'questionnaire')];
63-
$chartgroup[] = $mform->createElement('select', 'chart_type_global',
62+
$chartgroup[] = $mform->createElement(
63+
'select',
64+
'chart_type_global',
6465
get_string('chart:type', 'questionnaire') . ' (' .
65-
get_string('feedbackglobal', 'questionnaire') . ')', $charttypes);
66+
get_string('feedbackglobal', 'questionnaire') . ')',
67+
$charttypes
68+
);
6669
if ($questionnaire->survey->feedbacksections == 1) {
6770
$mform->setDefault('chart_type_global', $questionnaire->survey->chart_type);
6871
}
@@ -73,9 +76,13 @@ public function definition() {
7376
'bipolar' => get_string('chart:bipolar', 'questionnaire'),
7477
'hbar' => get_string('chart:hbar', 'questionnaire'),
7578
'rose' => get_string('chart:rose', 'questionnaire')];
76-
$chartgroup[] = $mform->createElement('select', 'chart_type_two_sections',
79+
$chartgroup[] = $mform->createElement(
80+
'select',
81+
'chart_type_two_sections',
7782
get_string('chart:type', 'questionnaire') . ' (' .
78-
get_string('feedbackbysection', 'questionnaire') . ')', $charttypes);
83+
get_string('feedbackbysection', 'questionnaire') . ')',
84+
$charttypes
85+
);
7986
if ($questionnaire->survey->feedbacksections > 1) {
8087
$mform->setDefault('chart_type_two_sections', $questionnaire->survey->chart_type);
8188
}
@@ -86,18 +93,27 @@ public function definition() {
8693
'hbar' => get_string('chart:hbar', 'questionnaire'),
8794
'radar' => get_string('chart:radar', 'questionnaire'),
8895
'rose' => get_string('chart:rose', 'questionnaire')];
89-
$chartgroup[] = $mform->createElement('select', 'chart_type_sections',
96+
$chartgroup[] = $mform->createElement(
97+
'select',
98+
'chart_type_sections',
9099
get_string('chart:type', 'questionnaire') . ' (' .
91-
get_string('feedbackbysection', 'questionnaire') . ')', $charttypes);
100+
get_string('feedbackbysection', 'questionnaire') . ')',
101+
$charttypes
102+
);
92103
if ($questionnaire->survey->feedbacksections > 1) {
93104
$mform->setDefault('chart_type_sections', $questionnaire->survey->chart_type);
94105
}
95106
$mform->disabledIf('chart_type_sections', 'feedbacksections', 'eq', 0);
96107
$mform->disabledIf('chart_type_sections', 'feedbacksections', 'eq', 1);
97108
$mform->disabledIf('chart_type_sections', 'feedbacksections', 'eq', 2);
98109

99-
$mform->addGroup($chartgroup, 'chartgroup',
100-
get_string('chart:type', 'questionnaire'), null, false);
110+
$mform->addGroup(
111+
$chartgroup,
112+
'chartgroup',
113+
get_string('chart:type', 'questionnaire'),
114+
null,
115+
false
116+
);
101117
$mform->addHelpButton('chartgroup', 'chart:type', 'questionnaire');
102118
}
103119
$editoroptions = ['maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext' => true];

classes/feedback_section_form.php

Lines changed: 100 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
defined('MOODLE_INTERNAL') || die();
2020

2121
require_once($CFG->libdir . '/formslib.php');
22-
require_once($CFG->dirroot.'/mod/questionnaire/lib.php');
22+
require_once($CFG->dirroot . '/mod/questionnaire/lib.php');
2323

2424
/**
2525
* Print the form to add or edit a questionnaire-instance
@@ -55,15 +55,22 @@ public function definition() {
5555
if ($survey->feedbacksections > 1) {
5656
$mform->addElement('header', 'feedbacksectionsheader', get_string('feedbacksections', 'questionnaire'));
5757
$sselectgroup = [];
58-
$sselect = $mform->createElement('select', 'navigatesections', get_string('navigatetosection', 'questionnaire'),
59-
$this->_customdata->sectionselect);
58+
$sselect = $mform->createElement(
59+
'select',
60+
'navigatesections',
61+
get_string('navigatetosection', 'questionnaire'),
62+
$this->_customdata->sectionselect
63+
);
6064
$sselect->setSelected($feedbacksection->id);
6165
$sselectgroup[] = $sselect;
6266
$sselectgroup[] = $mform->createElement('submit', 'gotosection', get_string('navigatetosection', 'questionnaire'));
6367
$mform->addGroup($sselectgroup, '');
6468
$addnewsectionarray = [];
65-
$addnewsectionarray[] = $mform->createElement('text', 'newsectionlabel',
66-
get_string('feedbacksectionlabel', 'questionnaire'));
69+
$addnewsectionarray[] = $mform->createElement(
70+
'text',
71+
'newsectionlabel',
72+
get_string('feedbacksectionlabel', 'questionnaire')
73+
);
6774
$mform->setType('newsectionlabel', PARAM_TEXT);
6875
$addnewsectionarray[] = $mform->createElement('submit', 'addnewsection', get_string('addnewsection', 'questionnaire'));
6976
$mform->addGroup($addnewsectionarray, '', get_string('feedbacksectionlabel', 'questionnaire'));
@@ -80,24 +87,36 @@ public function definition() {
8087
}
8188

8289
$mform->addElement('header', 'contenthdr', $feedbackheading);
83-
$mform->addElement('text', 'sectionlabel', get_string('feedbacksectionlabel', 'questionnaire'),
84-
['size' => '50', 'maxlength' => '50']);
90+
$mform->addElement(
91+
'text',
92+
'sectionlabel',
93+
get_string('feedbacksectionlabel', 'questionnaire'),
94+
['size' => '50', 'maxlength' => '50']
95+
);
8596
$mform->setType('sectionlabel', PARAM_TEXT);
8697
$mform->addRule('sectionlabel', null, 'required', null, 'client');
8798
$mform->addHelpButton('sectionlabel', 'feedbacksectionlabel', 'questionnaire');
8899

89100
$editoroptions = ['maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext' => true];
90-
$mform->addElement('editor', 'sectionheading', get_string('feedbacksectionheadingtext', 'questionnaire'),
91-
null, $editoroptions);
101+
$mform->addElement(
102+
'editor',
103+
'sectionheading',
104+
get_string('feedbacksectionheadingtext', 'questionnaire'),
105+
null,
106+
$editoroptions
107+
);
92108
$mform->setType('sectionheading', PARAM_RAW);
93109
$mform->setDefault('feedbacknotes', $questionnaire->survey->feedbacknotes);
94110
$mform->addHelpButton('sectionheading', 'feedbackheading', 'questionnaire');
95111

96112
if ($questionnaire->survey->feedbacksections > 0) {
97113
// Sections.
98114
if ($survey->feedbacksections > 1) {
99-
$mform->addElement('header', 'fbsection_' . $feedbacksection->id,
100-
get_string('feedbacksectionquestions', 'questionnaire', $label));
115+
$mform->addElement(
116+
'header',
117+
'fbsection_' . $feedbacksection->id,
118+
get_string('feedbacksectionquestions', 'questionnaire', $label)
119+
);
101120
$qvalid = $validquestions;
102121
if (!empty($feedbacksection->scorecalculation)) {
103122
$rsrc = $questionnaire->renderer->image_url('t/delete');
@@ -112,7 +131,7 @@ public function definition() {
112131
'name="weight[' . $qid . ']" min="0.0" max="1.0" step="0.01" ' .
113132
'value="' . $score . '">';
114133
} else {
115-
$weight = '<input type="hidden" id="weight' . $counter . '" name="weight[' . $qid . ']" '.
134+
$weight = '<input type="hidden" id="weight' . $counter . '" name="weight[' . $qid . ']" ' .
116135
'value="' . $score . '">';
117136
}
118137
$questionactions[] = $mform->createElement('html', $weight);
@@ -127,8 +146,12 @@ public function definition() {
127146
if (!empty($qvalid)) {
128147
// Merge arrays maintaining keys.
129148
$qselect = [];
130-
$qselect[] = $mform->createElement('select', 'addquestionselect',
131-
get_string('addquestiontosection', 'questionnaire'), $qvalid);
149+
$qselect[] = $mform->createElement(
150+
'select',
151+
'addquestionselect',
152+
get_string('addquestiontosection', 'questionnaire'),
153+
$qvalid
154+
);
132155
$qselect[] = $mform->createElement('submit', 'addquestion', get_string('addquestion', 'questionnaire'));
133156
$mform->addGroup($qselect, '', get_string('addquestiontosection', 'questionnaire'));
134157
}
@@ -145,27 +168,56 @@ public function definition() {
145168
$repeatarray = [];
146169
$repeatedoptions = [];
147170

148-
$repeatarray[] = $mform->createElement('editor', 'feedbacktext', get_string('feedback', 'questionnaire'), null,
149-
['maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $questionnaire->context]);
150171
$repeatarray[] = $mform->createElement(
151-
'text', 'feedbackboundaries', get_string('feedbackscoreboundary', 'questionnaire'), ['size' => 10]);
172+
'editor',
173+
'feedbacktext',
174+
get_string('feedback', 'questionnaire'),
175+
null,
176+
['maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $questionnaire->context]
177+
);
178+
$repeatarray[] = $mform->createElement(
179+
'text',
180+
'feedbackboundaries',
181+
get_string('feedbackscoreboundary', 'questionnaire'),
182+
['size' => 10]
183+
);
152184
$repeatedoptions['feedbacklabel']['type'] = PARAM_RAW;
153185
$repeatedoptions['feedbacktext']['type'] = PARAM_RAW;
154186
$repeatedoptions['feedbackboundaries']['type'] = PARAM_RAW;
155187

156188
$numfeedbacks = max(count($this->_feedbacks) * 1, 3);
157189

158-
$nextel = $this->repeat_elements($repeatarray, $numfeedbacks - 1, $repeatedoptions, 'boundary_repeats',
159-
'boundary_add_fields', 2, get_string('feedbackaddmorefeedbacks', 'questionnaire'), true);
190+
$nextel = $this->repeat_elements(
191+
$repeatarray,
192+
$numfeedbacks - 1,
193+
$repeatedoptions,
194+
'boundary_repeats',
195+
'boundary_add_fields',
196+
2,
197+
get_string('feedbackaddmorefeedbacks', 'questionnaire'),
198+
true
199+
);
160200

161201
// Put some extra elements in before the button.
162202
$mform->insertElementBefore(
163-
$mform->createElement('editor', "feedbacktext[$nextel]", get_string('feedback', 'questionnaire'), null,
164-
['maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $questionnaire->context]),
165-
'boundary_add_fields');
203+
$mform->createElement(
204+
'editor',
205+
"feedbacktext[$nextel]",
206+
get_string('feedback', 'questionnaire'),
207+
null,
208+
['maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $questionnaire->context]
209+
),
210+
'boundary_add_fields'
211+
);
166212
$mform->insertElementBefore(
167-
$mform->createElement('static', 'scoreboundarystatic2', get_string('feedbackscoreboundary', 'questionnaire'), '0%'),
168-
'boundary_add_fields');
213+
$mform->createElement(
214+
'static',
215+
'scoreboundarystatic2',
216+
get_string('feedbackscoreboundary', 'questionnaire'),
217+
'0%'
218+
),
219+
'boundary_add_fields'
220+
);
169221

170222
// Hidden fields.
171223
$mform->addElement('hidden', 'id', 0);
@@ -190,22 +242,22 @@ public function data_preprocessing(&$toform) {
190242
if (count($this->_feedbacks)) {
191243
$key = 0;
192244
foreach ($this->_feedbacks as $feedback) {
193-
$draftid = file_get_submitted_draft_itemid('feedbacktext['.$key.']');
194-
$toform['feedbacktext['.$key.']']['text'] = file_prepare_draft_area(
195-
$draftid, // Draftid.
196-
$this->context->id, // Context.
197-
'mod_questionnaire', // Component.
198-
'feedback', // Filarea.
199-
!empty($feedback->id) ? (int)$feedback->id : null, // Itemid.
245+
$draftid = file_get_submitted_draft_itemid('feedbacktext[' . $key . ']');
246+
$toform['feedbacktext[' . $key . ']']['text'] = file_prepare_draft_area(
247+
$draftid,
248+
$this->context->id,
249+
'mod_questionnaire', // Component.
250+
'feedback',
251+
!empty($feedback->id) ? (int)$feedback->id : null,
200252
null,
201-
$feedback->feedbacktext // Text.
253+
$feedback->feedbacktext
202254
);
203-
$toform['feedbacktext['.$key.']']['format'] = 1;
204-
$toform['feedbacklabel['.$key.']'] = $feedback->feedbacklabel;
205-
$toform['feedbacktext['.$key.']']['itemid'] = $draftid;
255+
$toform['feedbacktext[' . $key . ']']['format'] = 1;
256+
$toform['feedbacklabel[' . $key . ']'] = $feedback->feedbacklabel;
257+
$toform['feedbacktext[' . $key . ']']['itemid'] = $draftid;
206258

207259
if ($feedback->minscore > 0) {
208-
$toform['feedbackboundaries['.$key.']'] = (100.0 * $feedback->minscore / 100 ) . '%';
260+
$toform['feedbackboundaries[' . $key . ']'] = (100.0 * $feedback->minscore / 100 ) . '%';
209261
}
210262
$key++;
211263
}
@@ -236,8 +288,10 @@ public function validation($data, $files) {
236288
if (is_numeric($boundary) && $boundary <= 0) {
237289
$errors["feedbackboundaries[$i]"] = get_string('feedbackerrorboundaryoutofrange', 'questionnaire', $i + 1);
238290
}
239-
if (is_numeric($boundary) && $i > 0 &&
240-
$boundary >= $data['feedbackboundaries'][$i - 1]) {
291+
if (
292+
is_numeric($boundary) && $i > 0 &&
293+
$boundary >= $data['feedbackboundaries'][$i - 1]
294+
) {
241295
$errors["feedbackboundaries[$i]"] = get_string('feedbackerrororder', 'questionnaire', $i + 1);
242296
}
243297
$data['feedbackboundaries'][$i] = $boundary;
@@ -248,15 +302,19 @@ public function validation($data, $files) {
248302
// Check there is nothing in the remaining unused fields.
249303
if (!empty($data['feedbackboundaries'])) {
250304
for ($i = $numboundaries; $i < count($data['feedbackboundaries']); $i += 1) {
251-
if (!empty($data['feedbackboundaries'][$i] ) &&
252-
trim($data['feedbackboundaries'][$i] ) != '') {
305+
if (
306+
!empty($data['feedbackboundaries'][$i] ) &&
307+
trim($data['feedbackboundaries'][$i] ) != ''
308+
) {
253309
$errors["feedbackboundaries[$i]"] = get_string('feedbackerrorjunkinboundary', 'questionnaire', $i + 1);
254310
}
255311
}
256312
}
257313
for ($i = $numboundaries + 1; $i < count($data['feedbacktext']); $i += 1) {
258-
if (!empty($data['feedbacktext'][$i]['text']) &&
259-
trim($data['feedbacktext'][$i]['text'] ) != '') {
314+
if (
315+
!empty($data['feedbacktext'][$i]['text']) &&
316+
trim($data['feedbacktext'][$i]['text'] ) != ''
317+
) {
260318
$errors["feedbacktext[$i]"] = get_string('feedbackerrorjunkinfeedback', 'questionnaire', $i + 1);
261319
}
262320
}

classes/privacy/provider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3232
*/
3333
class provider implements
34-
\core_privacy\local\metadata\provider,
3534
\core_privacy\local\request\core_userlist_provider,
35+
\core_privacy\local\metadata\provider,
3636
\core_privacy\local\request\plugin\provider {
3737
/**
3838
* Returns meta data about this system.

0 commit comments

Comments
 (0)