@@ -202,15 +202,16 @@ private function add_settings_field($stratfieldid, array $value, $strategyid, Mo
202
202
$ mform ->hideIf ($ stratfieldid , 'strategy ' , 'neq ' , $ strategyid );
203
203
}
204
204
205
+
205
206
// Override if you need to setup the form depending on current values.
206
207
public function definition_after_data () {
207
- parent :: definition_after_data ();
208
+
208
209
$ mform = &$ this ->_form ;
209
210
210
211
$ data = $ this ->current ;
211
212
212
213
if ($ this ->is_submitted ()) {
213
- $ subdata = $ this ->get_submitted_data ();
214
+ $ subdata = $ this ->get_data ();
214
215
$ allstrategyoptions = $ subdata ->{self ::STRATEGY_OPTIONS };
215
216
} else if (isset ($ data ->setting )) {
216
217
$ allstrategyoptions = json_decode ($ data ->setting , true );
@@ -245,8 +246,12 @@ public function definition_after_data() {
245
246
}
246
247
$ mform ->removeElement ($ strategyplaceholder );
247
248
}
249
+
250
+ // Call parent function after, in order to have completiontracking working properly.
251
+ parent ::definition_after_data ();
248
252
}
249
253
254
+
250
255
/**
251
256
* Checks that accesstimestart is before accesstimestop
252
257
*/
@@ -321,7 +326,7 @@ public function add_completion_rules() {
321
326
}
322
327
323
328
protected function get_suffixed_name (string $ fieldname ): string {
324
- return 'completion ' . $ fieldname ;
329
+ return 'completion ' . $ fieldname . $ this -> get_suffix () ;
325
330
}
326
331
327
332
/**
@@ -334,4 +339,44 @@ public function completion_rule_enabled($data) {
334
339
return ($ data [$ this ->get_suffixed_name ('vote ' )] == 1 || $ data [$ this ->get_suffixed_name ('allocation ' )] == 1 );
335
340
}
336
341
342
+ /**
343
+ * Allows module to modify data returned by get_moduleinfo_data() or prepare_new_moduleinfo_data() before calling set_data().
344
+ * This method is also called in the bulk activity completion form.
345
+ * Only available on moodleform_mod.
346
+ *
347
+ * @param $default_values
348
+ * @return void
349
+ */
350
+ function data_preprocessing (&$ default_values ){
351
+ if (empty ($ default_values [$ this ->get_suffixed_name ('vote ' )])) {
352
+ $ default_values [$ this ->get_suffixed_name ('vote ' )] = 0 ;
353
+ }
354
+ if (empty ($ default_values [$ this ->get_suffixed_name ('allocation ' )])) {
355
+ $ default_values [$ this ->get_suffixed_name ('allocation ' )] = 0 ;
356
+ }
357
+ }
358
+
359
+ /**
360
+ * Allows module to modify the data returned by form get_data().
361
+ * This method is also called in the bulk activity completion form.
362
+ *
363
+ * Only available on moodleform_mod.
364
+ *
365
+ * @param stdClass $data the form data to be modified.
366
+ */
367
+ public function data_postprocessing ($ data ) {
368
+ parent ::data_postprocessing ($ data );
369
+ // Turn off completion settings if the checkboxes aren't ticked.
370
+ if (!empty ($ data ->completionunlocked )) {
371
+ $ completion = $ data ->{'completion ' . $ this ->get_suffix ()};
372
+ $ autocompletion = !empty ($ completion ) && $ completion == COMPLETION_TRACKING_AUTOMATIC ;
373
+ if (empty ($ data ->{$ this ->get_suffixed_name ('vote ' )}) || !$ autocompletion ) {
374
+ $ data ->{$ this ->get_suffixed_name ('vote ' )} = 0 ;
375
+ }
376
+ if (empty ($ data ->{$ this ->get_suffixed_name ('allocation ' )}) || !$ autocompletion ) {
377
+ $ data ->{$ this ->get_suffixed_name ('allocation ' )} = 0 ;
378
+ }
379
+ }
380
+ }
381
+
337
382
}
0 commit comments