1919defined ('MOODLE_INTERNAL ' ) || die ();
2020
2121require_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 }
0 commit comments