@@ -61,9 +61,9 @@ protected function set_current_settings(): void {
61
61
}
62
62
63
63
/**
64
- * Options shared by all file pickers in the form.
64
+ * Options shared by all file pickers in the form for background image .
65
65
*
66
- * @return array Array of filepicker options.
66
+ * @return array Array of filepicker options for selecting the background image .
67
67
*/
68
68
public static function file_picker_options (): array {
69
69
$ filepickeroptions = [];
@@ -79,11 +79,8 @@ protected function definition_inner($mform): void {
79
79
80
80
$ this ->set_current_settings ();
81
81
82
- // Add hidden form elements, for choices.
83
- for ($ number = 1 ; $ number <= ($ this ->numberoflines * 2 ); $ number ++) {
84
- $ mform ->addElement ('hidden ' , 'c ' . $ number );
85
- $ mform ->setType ('c ' . $ number , PARAM_RAW );
86
- }
82
+ $ mform ->addElement ('advcheckbox ' , 'showmisplaced ' , get_string ('showmisplaced ' , 'qtype_ddmarker ' ));
83
+ $ mform ->setDefault ('showmisplaced ' , $ this ->get_default_value ('showmisplaced ' , 0 ));
87
84
88
85
$ grademethodmenu = [
89
86
'partial ' => get_string ('gradepartialcredit ' , 'qtype_ ' . $ this ->qtype ()),
@@ -113,6 +110,65 @@ protected function definition_inner($mform): void {
113
110
$ this ->add_interactive_settings (true , true );
114
111
}
115
112
113
+ /**
114
+ * Add a set of form fields, obtained from get_per_line_fields.
115
+ *
116
+ * @param MoodleQuickForm $mform the form being built.
117
+ * @param string $label the label to use for each line.
118
+ */
119
+ protected function add_per_line_fields (MoodleQuickForm $ mform , string $ label ) {
120
+ if (isset ($ this ->question ->lines )) {
121
+ $ repeatsatstart = count ($ this ->question ->lines );
122
+ } else {
123
+ $ repeatsatstart = line::LINE_NUMBER_START ;
124
+ }
125
+ $ repeatedoptions = [];
126
+ $ this ->repeat_elements ($ this ->get_per_line_fields ($ mform , $ label , $ repeatedoptions ),
127
+ $ repeatsatstart , $ repeatedoptions ,
128
+ 'numberoflines ' , 'addlines ' , line::LINE_NUMBER_ADD ,
129
+ get_string ('addmoreblanks ' , 'qtype_drawlines ' , 'lines ' ), true );
130
+ }
131
+
132
+ /**
133
+ * Returns a line object with relevant input fields.
134
+ *
135
+ * @param MoodleQuickForm $mform
136
+ * @param string $label
137
+ * @param array $repeatedoptions
138
+ * @return array
139
+ */
140
+ protected function get_per_line_fields (MoodleQuickForm $ mform , string $ label , array &$ repeatedoptions ): array {
141
+
142
+ $ repeated = [];
143
+
144
+ $ repeated [] = $ mform ->createElement ('header ' , 'linexheader ' , $ label );
145
+
146
+ $ repeated [] = $ mform ->createElement ('select ' , 'type ' ,
147
+ get_string ('type ' , 'qtype_ ' . $ this ->qtype ()),
148
+ array_merge (['choose ' => get_string ('choose ' )], line::get_line_types ()));
149
+
150
+ $ repeated [] = $ mform ->createElement ('text ' , 'labelstart ' ,
151
+ get_string ('labelstart ' , 'qtype_ ' . $ this ->qtype ()), ['size ' => 20 ]);
152
+ $ mform ->setType ('labelstart ' , PARAM_RAW_TRIMMED );
153
+
154
+ $ repeated [] = $ mform ->createElement ('text ' , 'labelmiddle ' ,
155
+ get_string ('labelmiddle ' , 'qtype_ ' . $ this ->qtype ()), ['size ' => 20 ]);
156
+ $ mform ->setType ('labelmiddle ' , PARAM_RAW_TRIMMED );
157
+
158
+ $ repeated [] = $ mform ->createElement ('text ' , 'labelend ' ,
159
+ get_string ('labelend ' , 'qtype_ ' . $ this ->qtype ()), ['size ' => 20 ]);
160
+ $ mform ->setType ('labelend ' , PARAM_RAW_TRIMMED );
161
+
162
+ $ repeated [] = $ mform ->createElement ('text ' , 'zonestart ' ,
163
+ get_string ('zonestart ' , 'qtype_ ' . $ this ->qtype ()), ['size ' => 20 ]);
164
+ $ mform ->setType ('zonestart ' , PARAM_RAW_TRIMMED );
165
+
166
+ $ repeated [] = $ mform ->createElement ('text ' , 'zoneend ' ,
167
+ get_string ('zoneend ' , 'qtype_ ' . $ this ->qtype ()), ['size ' => 20 ]);
168
+ $ mform ->setType ('zoneend ' , PARAM_RAW_TRIMMED );
169
+ return $ repeated ;
170
+ }
171
+
116
172
/**
117
173
* Create the form elements required by one hint.
118
174
*
@@ -230,7 +286,7 @@ public function validation($data, $files) {
230
286
if ($ bgimagesize === null ) {
231
287
$ errors ["bgimage " ] = get_string ('formerror_nobgimage ' , 'qtype_ ' . $ this ->qtype ());
232
288
}
233
- $ validlines = 0 ;
289
+ $ hasbothcoordinates = false ;
234
290
// Validate whether the line type error needed to be displayed.
235
291
for ($ i = 0 ; $ i < count ($ data ["type " ]); $ i ++) {
236
292
// Validate line type.
@@ -252,11 +308,11 @@ public function validation($data, $files) {
252
308
if (in_array ($ data ["type " ][$ i ], array_keys (line::get_line_types ())) &&
253
309
line::is_zone_coordinates_valid ($ data ["zonestart " ][$ i ]) &&
254
310
line::is_zone_coordinates_valid ($ data ['zoneend ' ][$ i ])) {
255
- $ validlines = 1 ;
311
+ $ hasbothcoordinates = true ;
256
312
}
257
313
}
258
314
// There should be atleast one valid line.
259
- if (empty ($ errors ) && $ validlines == 0 ) {
315
+ if (empty ($ errors ) && $ hasbothcoordinates == false ) {
260
316
$ errors ["type[0] " ] = get_string ('formerror_notype ' , 'qtype_ ' . $ this ->qtype (), 1 );
261
317
}
262
318
return $ errors ;
@@ -287,65 +343,4 @@ public function get_image_size_in_draft_area($draftitemid) {
287
343
}
288
344
return null ;
289
345
}
290
-
291
- /**
292
- * Add a set of form fields, obtained from get_per_line_fields.
293
- *
294
- * @param MoodleQuickForm $mform the form being built.
295
- * @param string $label the label to use for each line.
296
- */
297
- protected function add_per_line_fields (MoodleQuickForm $ mform , string $ label ) {
298
- if (isset ($ this ->question ->lines )) {
299
- $ repeatsatstart = count ($ this ->question ->lines );
300
- } else {
301
- $ repeatsatstart = line::LINE_NUMBER_START ;
302
- }
303
- $ repeatedoptions = [];
304
- $ this ->repeat_elements ($ this ->get_per_line_fields ($ mform , $ label , $ repeatedoptions ),
305
- $ repeatsatstart , $ repeatedoptions ,
306
- 'numberoflines ' , 'addlines ' , line::LINE_NUMBER_ADD ,
307
- get_string ('addmoreblanks ' , 'qtype_drawlines ' , 'lines ' ), true );
308
- }
309
-
310
- /**
311
- * Returns a line object with relevant input fields.
312
- *
313
- * @param MoodleQuickForm $mform
314
- * @param string $label
315
- * @param array $repeatedoptions
316
- * @return array
317
- */
318
- protected function get_per_line_fields (MoodleQuickForm $ mform , string $ label , array &$ repeatedoptions ): array {
319
-
320
- $ repeated = [];
321
-
322
- $ repeated [] = $ mform ->createElement ('header ' , 'linexheader ' , $ label );
323
- $ mform ->setType ('linexheader ' , PARAM_RAW );
324
-
325
- $ repeated [] = $ mform ->createElement ('select ' , 'type ' ,
326
- get_string ('type ' , 'qtype_ ' . $ this ->qtype ()),
327
- array_merge (['choose ' => get_string ('choose ' )], line::get_line_types ()));
328
- $ mform ->setType ('type ' , PARAM_RAW );
329
-
330
- $ repeated [] = $ mform ->createElement ('text ' , 'labelstart ' ,
331
- get_string ('labelstart ' , 'qtype_ ' . $ this ->qtype ()), ['size ' => 20 ]);
332
- $ mform ->setType ('labelstart ' , PARAM_RAW_TRIMMED );
333
-
334
- $ repeated [] = $ mform ->createElement ('text ' , 'labelmiddle ' ,
335
- get_string ('labelmiddle ' , 'qtype_ ' . $ this ->qtype ()), ['size ' => 20 ]);
336
- $ mform ->setType ('labelmiddle ' , PARAM_RAW_TRIMMED );
337
-
338
- $ repeated [] = $ mform ->createElement ('text ' , 'labelend ' ,
339
- get_string ('labelend ' , 'qtype_ ' . $ this ->qtype ()), ['size ' => 20 ]);
340
- $ mform ->setType ('labelend ' , PARAM_RAW_TRIMMED );
341
-
342
- $ repeated [] = $ mform ->createElement ('text ' , 'zonestart ' ,
343
- get_string ('zonestart ' , 'qtype_ ' . $ this ->qtype ()), ['size ' => 20 ]);
344
- $ mform ->setType ('zonestart ' , PARAM_RAW_TRIMMED );
345
-
346
- $ repeated [] = $ mform ->createElement ('text ' , 'zoneend ' ,
347
- get_string ('zoneend ' , 'qtype_ ' . $ this ->qtype ()), ['size ' => 20 ]);
348
- $ mform ->setType ('zoneend ' , PARAM_RAW_TRIMMED );
349
- return $ repeated ;
350
- }
351
346
}
0 commit comments