-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmod_form.php
More file actions
678 lines (602 loc) · 28.3 KB
/
mod_form.php
File metadata and controls
678 lines (602 loc) · 28.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the forms to create and edit an instance of the diary module.
*
* @package mod_diary
* @copyright 2019 AL Rachels ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
use mod_diary\local\diarystats;
require_once($CFG->dirroot . '/course/moodleform_mod.php');
require_once($CFG->dirroot . '/rating/lib.php');
/**
* Diary settings form.
*
* @package mod_diary
* @copyright 2019 AL Rachels ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_diary_mod_form extends moodleform_mod {
/** Threshold above which Count of ratings + Point warning applies. */
/** @var int */
const COUNT_RATINGS_POINT_WARNING_THRESHOLD = 10;
/** Settings for adding repeated form elements. */
/** @var int */
const NUM_ITEMS_DEFAULT = 0;
/** @var int */
const NUM_ITEMS_MIN = 0;
/** @var int */
const NUM_ITEMS_ADD = 1;
/** Number of rows in TEXTAREA elements. */
/** @var int */
const TEXTAREA_ROWS = 3;
/**
* diary is plugin name without leading "mod_".
*/
public function mod() {
return substr($this->plugin_name(), 4);
}
/**
* Plugin name is class name without trailing "mod_form"
*/
public function plugin_name() {
return substr(get_class($this), 0, -9);
}
/**
* Fetch a constant from the plugin class.
*
* @param string $name
*/
protected function plugin_constant($name) {
$plugin = $this->plugin_name();
return constant($plugin . '::' . $name);
}
/**
* Define the diary activity settings form.
*
* @return void
*/
public function definition() {
global $COURSE, $PAGE, $CFG;
// Cache the plugin name.
$plugin = 'mod_diary';
$diaryconfig = get_config('mod_diary');
// 20210706 Add Javascript to expand/contract text input fields. NOT sure if this is needed.
$params = [];
$PAGE->requires->js_call_amd("$plugin/form", 'init', $params);
// 20210706 Cache options for form elements to input text.
$shorttextoptions = ['size' => 3, 'style' => 'width: auto'];
$mediumtextoptions = ['size' => 5, 'style' => 'width: auto'];
$longtextoptions = ['size' => 10, 'style' => 'width: auto'];
// 20210706 Cache options for show/hide elements.
// 20220115 NOT in use yet.
$showhideoptions = diarystats::get_showhide_options($plugin);
// 20210706 Cache options for form elements to select a rating.
$ratingoptions = diarystats::get_rating_options($plugin);
$mform = &$this->_form;
$mform->addElement('header', 'general', get_string('general', 'form'));
$mform->addElement('text', 'name', get_string('diaryname', 'diary'), ['size' => '64']);
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client');
$this->standard_intro_elements(get_string('diarydescription', 'diary'));
// 20210706 Add the availability header.
$name = 'availibilityhdr';
$label = get_string('availability');
$mform->addElement('header', $name, $label);
$mform->setExpanded($name, true);
// 20200915 Moved check so daysavailable is hidden unless using weekly format.
if ($COURSE->format == 'weeks') {
$options = [];
$options[0] = get_string('alwaysopen', 'diary');
for ($i = 1; $i <= 13; $i++) {
$options[$i] = get_string('numdays', '', $i);
}
for ($i = 2; $i <= 16; $i++) {
$days = $i * 7;
$options[$days] = get_string('numweeks', '', $i);
}
$options[365] = get_string('numweeks', '', 52);
$mform->addElement('select', 'days', get_string('daysavailable', 'diary'), $options);
$mform->addHelpButton('days', 'daysavailable', 'diary');
$mform->setDefault('days', '7');
} else {
$mform->setDefault('days', '0');
}
$mform->addElement(
'date_time_selector',
'timeopen',
get_string('diaryopentime', 'diary'),
[
'optional' => true,
'step' => 1,
]
);
$mform->addHelpButton('timeopen', 'diaryopentime', 'diary');
$mform->addElement(
'date_time_selector',
'timeclose',
get_string('diaryclosetime', 'diary'),
[
'optional' => true,
'step' => 1,
]
);
$mform->addHelpButton('timeclose', 'diaryclosetime', 'diary');
// 20201015 Added Edit all, enable/disable setting. 20230925 Modified to use site default.
$name = 'editall';
$label = get_string($name, $plugin);
$mform->addElement('selectyesno', $name, $label);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->editall);
// 20241113 Added Delete entry, enable/disable setting.
$name = 'deleteentry';
$label = get_string('deleteentries', $plugin);
$mform->addElement('selectyesno', $name, $label);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->deleteentries);
// 20201119 Added Edit dates, enable/disable setting. 20230925 Modified to use site default.
$name = 'editdates';
$label = get_string($name, $plugin);
$mform->addElement('selectyesno', $name, $label);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->editdates);
// Maximum number of times an existing entry can be opened for editing.
$name = 'maxeditopens';
$label = get_string($name, $plugin);
$mform->addElement('text', $name, $label, $mediumtextoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, (int)($diaryconfig->maxeditopens ?? 0));
// 20210704 Added heading for appearance options section.
$name = 'appearancehdr';
$label = get_string('appearance');
$mform->addElement('header', $name, $label);
$mform->setExpanded($name, true);
// Diary entry/feedback overall background colour setting.
$name = 'entrybgc';
$label = get_string('entrybgc_title', 'diary');
$description = get_string('entrybgc_descr', 'diary');
$default = get_string('entrybgc_colour', 'diary');
$mform->setType($name, PARAM_TEXT);
$mform->addElement('text', $name, $label, ['id' => 'diary_entrybgc_picker']);
$mform->addHelpButton($name, $name, $plugin);
$mform->setDefault($name, $diaryconfig->entrybgc);
// Diary entry text background colour setting.
$name = 'entrytextbgc';
$label = get_string('entrytextbgc_title', 'diary');
$description = get_string('entrytextbgc_descr', 'diary');
$default = get_string('entrytextbgc_colour', 'diary');
$mform->setType($name, PARAM_TEXT);
$mform->addElement('text', $name, $label, ['id' => 'diary_entrytextbgc_picker']);
$mform->addHelpButton($name, $name, $plugin);
$mform->setDefault($name, $diaryconfig->entrytextbgc);
// Entry/prompt border toggle for this activity.
$name = 'enableborders';
$label = get_string('enableborders', 'diary');
$mform->addElement('selectyesno', $name, $label);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, (int)($diaryconfig->enableborders ?? 0));
$name = 'borderstyle';
$label = get_string('borderstyle', 'diary');
$mform->addElement('select', $name, $label, [
'none' => get_string('borderstylenone', 'diary'),
'thin' => get_string('borderstylethin', 'diary'),
'double' => get_string('borderstyledouble', 'diary'),
]);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_ALPHANUMEXT);
$mform->setDefault($name, $diaryconfig->borderstyle ?? 'none');
$mform->disabledIf($name, 'enableborders', 'eq', 0);
$name = 'bordercolor';
$label = get_string('bordercolor', 'diary');
$mform->addElement('text', $name, $label, ['id' => 'diary_bordercolor_picker']);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_TEXT);
$mform->setDefault($name, $diaryconfig->bordercolor ?? get_string('bordercolor_default', 'diary'));
$mform->disabledIf($name, 'enableborders', 'eq', 0);
$mform->addElement('html', "
<script>
(function() {
var ids = ['diary_entrybgc_picker', 'diary_entrytextbgc_picker', 'diary_bordercolor_picker'];
var colors = {
'red': '#ff0000', 'blue': '#0000ff', 'green': '#008000',
'yellow': '#ffff00', 'pink': '#ffc0cb', 'white': '#ffffff',
'orange': '#ffa500', 'purple': '#800080'
};
ids.forEach(function(id) {
var cp = document.getElementById(id);
if (cp) {
var currentVal = cp.value.toLowerCase();
if (colors[currentVal]) {
cp.value = colors[currentVal];
}
cp.type = 'color';
cp.style.width = '60px';
cp.style.height = '35px';
cp.style.cursor = 'pointer';
}
});
})();
</script>
");
// 20210812 Added enable/disable setting for statistics.
$name = 'enablestats';
$label = get_string($name, $plugin);
$mform->addElement('selectyesno', $name, $label);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->enablestats);
// 20231109 Added enable/disable setting for titles.
$name = 'enabletitles';
$label = get_string($name, $plugin);
$mform->addElement('selectyesno', $name, $label);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->enabletitles);
// 20250301 Added heading for submission options section.
$name = 'submissionsettingshdr';
$label = get_string('submissionsettings', 'diary');
$mform->addElement('header', $name, $label);
$mform->setExpanded($name, true);
// 20250301 Added enable/disable setting for email upon submitting an entry.
$name = 'submissionemail';
$label = get_string($name, $plugin);
$mform->addElement('selectyesno', $name, $label);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, 0);
// 20230204 Added enable/disable setting for teacheremail.
$options = [];
$options['0'] = 'Delay';
$options['1'] = 'Now';
// 20230204 Added enable/disable setting for teacheremail.
$name = 'teacheremail';
$label = get_string($name, $plugin);
$mform->addElement('select', $name, $label, $options);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->teacheremail);
$mform->disabledIf($name, 'submissionemail', 'eq', 0);
// 20230204 Added enable/disable setting for studentemail.
$name = 'studentemail';
$label = get_string($name, $plugin);
$mform->addElement('select', $name, $label, $options);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->studentemail);
$mform->disabledIf($name, 'submissionemail', 'eq', 0);
// 20210704 Added heading for autorating options section.
$name = 'autorating';
$label = get_string($name, $plugin);
$mform->addElement('header', $name, $label);
$mform->setExpanded($name, true);
// 20210709 Added enable/disable setting for autorating.
$name = 'enableautorating';
$label = get_string($name, $plugin);
$mform->addElement('selectyesno', $name, $label);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->autorating);
// 20210711 Added heading for minimum/maximum options section.
$name = 'minmaxhdr';
$label = get_string($name, $plugin);
$mform->addElement('header', $name, $label);
$mform->setExpanded($name, true);
// 20210709 Added minimum character count setting.
$name = 'mincharacterlimit';
$label = get_string($name, $plugin);
$mform->addElement('text', $name, $label, $mediumtextoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->mincharacterlimit);
$mform->disabledIf($name, 'enableautorating', 'eq', 0);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20210709 Added maximum character count setting.
$name = 'maxcharacterlimit';
$label = get_string($name, $plugin);
$mform->addElement('text', $name, $label, $mediumtextoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->maxcharacterlimit);
$mform->disabledIf($name, 'enableautorating', 'eq', 0);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20211006 Added a selector to set error percent of each minimum or maximum character penalty.
$name = 'minmaxcharpercent';
$label = get_string($name, $plugin);
$mform->addElement('select', $name, $label, $ratingoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setDefault($name, $diaryconfig->minmaxcharpercent);
$mform->setType($name, PARAM_INT);
$mform->disabledIf($name, 'enableautorating', 'eq', 0);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20210709 Added minimum word count setting.
$name = 'minwordlimit';
$label = get_string($name, $plugin);
$mform->addElement('text', $name, $label, $mediumtextoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->minwordlimit);
$mform->disabledIf($name, 'enableautorating', 'eq', 0);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20210709 Added maximum word count setting.
$name = 'maxwordlimit';
$label = get_string($name, $plugin);
$mform->addElement('text', $name, $label, $mediumtextoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->maxwordlimit);
$mform->disabledIf($name, 'enableautorating', 'eq', 0);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20211006 Added a selector to set error percent of each minimum or maximum word penalty.
$name = 'minmaxwordpercent';
$label = get_string($name, $plugin);
$mform->addElement('select', $name, $label, $ratingoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setDefault($name, $diaryconfig->minmaxwordpercent);
$mform->setType($name, PARAM_INT);
$mform->disabledIf($name, 'enableautorating', 'eq', 0);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20211006 Added minimum sentence count setting.
$name = 'minsentencelimit';
$label = get_string($name, $plugin);
$mform->addElement('text', $name, $label, $mediumtextoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->minsentencelimit);
$mform->disabledIf($name, 'enableautorating', 'eq', 0);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20211006 Added maximum sentence count setting.
$name = 'maxsentencelimit';
$label = get_string($name, $plugin);
$mform->addElement('text', $name, $label, $mediumtextoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->maxsentencelimit);
$mform->disabledIf($name, 'enableautorating', 'eq', 0);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20211006 Added a selector to set error percent of each minimum or maximum sentence penalty.
$name = 'minmaxsentpercent';
$label = get_string($name, $plugin);
$mform->addElement('select', $name, $label, $ratingoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setDefault($name, $diaryconfig->minmaxsentpercent);
$mform->setType($name, PARAM_INT);
$mform->disabledIf($name, 'enableautorating', 'eq', 0);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20211006 Added minimum paragraph count setting.
$name = 'minparagraphlimit';
$label = get_string($name, $plugin);
$mform->addElement('text', $name, $label, $mediumtextoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->minparagraphlimit);
$mform->disabledIf($name, 'enableautorating', 'eq', 0);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20211006 Added maximum paragraph count setting.
$name = 'maxparagraphlimit';
$label = get_string($name, $plugin);
$mform->addElement('text', $name, $label, $mediumtextoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_INT);
$mform->setDefault($name, $diaryconfig->maxparagraphlimit);
$mform->disabledIf($name, 'enableautorating', 'eq', 0);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20211006 Added a selector to set error percent of each minimum or maximum paragraph penalty.
$name = 'minmaxparapercent';
$label = get_string($name, $plugin);
$mform->addElement('select', $name, $label, $ratingoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setDefault($name, $diaryconfig->minmaxparapercent);
$mform->setType($name, PARAM_INT);
$mform->disabledIf($name, 'enableautorating', 'eq', 0);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20210703 Added the common errors header.
$name = 'commonerrors';
$label = get_string($name, $plugin);
$mform->addElement('header', $name, $label);
$mform->setExpanded($name, true);
// 20210703 Added selector to pick a glossary of common errors.
$name = 'errorcmid';
$label = get_string($name, $plugin);
$options = $this->get_errorcmid_options($PAGE->course->id);
$mform->addElement('select', $name, $label, $options);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType('errorcmid', PARAM_INT);
$mform->disabledIf('errorcmid', 'itemtype', 'eq', 5);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20210703 Added a selector to set error percent of each penalty.
$name = 'errorpercent';
$label = get_string($name, $plugin);
$mform->addElement('select', $name, $label, $ratingoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setDefault($name, $this->get_my_default_value($name, 5));
$mform->setType($name, PARAM_INT);
$mform->disabledIf($name, 'errorcmid', 'eq', 0);
$mform->disabledIf($name, 'itemtype', 'eq', 5);
$mform->disabledIf($name, 'enablestats', 'eq', 0);
// 20260401 Keep the three common-error matching controls on one row (Essay-style).
$errormatchgroup = [];
$errormatchgroup[] = $mform->createElement('select', 'errorfullmatch', '', $this->diary_get_fullmatch_options($plugin));
$errormatchgroup[] = $mform->createElement('select', 'errorcasesensitive', '', $this->get_casesensitive_options($plugin));
$errormatchgroup[] = $mform->createElement('select', 'errorignorebreaks', '', $this->get_ignorebreaks_options($plugin));
$mform->addGroup($errormatchgroup, 'errorbehavior', get_string('errorbehavior', $plugin), ' ', false);
$mform->addHelpButton('errorbehavior', 'errorbehavior', $plugin);
$mform->setDefault('errorfullmatch', $this->get_my_default_value('errorfullmatch', 1));
$mform->setType('errorfullmatch', PARAM_INT);
$mform->disabledIf('errorfullmatch', 'errorcmid', 'eq', 0);
$mform->disabledIf('errorfullmatch', 'itemtype', 'eq', 5);
$mform->disabledIf('errorfullmatch', 'enablestats', 'eq', 0);
$mform->setDefault('errorcasesensitive', $this->get_my_default_value('errorcasesensitive', 0));
$mform->setType('errorcasesensitive', PARAM_INT);
$mform->disabledIf('errorcasesensitive', 'errorcmid', 'eq', 0);
$mform->disabledIf('errorcasesensitive', 'itemtype', 'eq', 5);
$mform->disabledIf('errorcasesensitive', 'enablestats', 'eq', 0);
$mform->setDefault('errorignorebreaks', $this->get_my_default_value('errorignorebreaks', 0));
$mform->setType('errorignorebreaks', PARAM_INT);
$mform->disabledIf('errorignorebreaks', 'errorcmid', 'eq', 0);
$mform->disabledIf('errorignorebreaks', 'itemtype', 'eq', 5);
$mform->disabledIf('errorignorebreaks', 'enablestats', 'eq', 0);
// Add the rest of the common settings.
$this->standard_grading_coursemodule_elements();
// Warn about Count of ratings with Point maximum grade >10.
$name = 'countofratingswarning';
$warningdata = (object) [
'threshold' => self::COUNT_RATINGS_POINT_WARNING_THRESHOLD,
'pointdefault' => $CFG->gradepointdefault ?? '',
'pointmax' => $CFG->gradepointmax ?? '',
];
$warning = '<div class="alert alert-warning">'
. get_string('countofratingspointwarning', 'diary', $warningdata)
. '</div>';
$mform->addElement('static', $name, '', $warning);
$mform->hideIf($name, 'assessed', 'neq', RATING_AGGREGATE_COUNT);
$mform->hideIf($name, 'scale[modgrade_type]', 'neq', 'point');
$mform->hideIf($name, 'scale[modgrade_point]', 'in', '|0|1|2|3|4|5|6|7|8|9|10');
$this->standard_coursemodule_elements();
$this->add_action_buttons();
}
/**
* Preprocess form data before rendering.
*
* Loads per-activity border setting stored in plugin config.
*
* @param array $defaultvalues
* @return void
*/
public function data_preprocessing(&$defaultvalues) {
if (!empty($defaultvalues['instance'])) {
$instanceid = (int)$defaultvalues['instance'];
$stored = get_config('mod_diary', 'enableborders_' . $instanceid);
if ($stored !== false && $stored !== null && $stored !== '') {
$defaultvalues['enableborders'] = (int)$stored;
}
$storedstyle = get_config('mod_diary', 'borderstyle_' . $instanceid);
if ($storedstyle !== false && $storedstyle !== null && $storedstyle !== '') {
$defaultvalues['borderstyle'] = (string)$storedstyle;
}
$storedcolor = get_config('mod_diary', 'bordercolor_' . $instanceid);
if ($storedcolor !== false && $storedcolor !== null && $storedcolor !== '') {
$defaultvalues['bordercolor'] = (string)$storedcolor;
}
}
}
/**
* Validate submitted form data.
*
* @param array $data
* @param array $files
* @return array
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
$assessed = $data['assessed'] ?? 0;
$gradetype = $data['scale']['modgrade_type'] ?? '';
$gradepoint = $data['scale']['modgrade_point'] ?? '';
if (
(int)$assessed === RATING_AGGREGATE_COUNT
&& $gradetype === 'point'
&& $gradepoint !== ''
&& is_numeric($gradepoint)
&& (float)$gradepoint > self::COUNT_RATINGS_POINT_WARNING_THRESHOLD
) {
$errors['scale[modgrade_point]'] = get_string(
'countofratingspointvalidation',
'diary',
(object)['threshold' => self::COUNT_RATINGS_POINT_WARNING_THRESHOLD]
);
}
return $errors;
}
/**
* Get array of glossary options.
*
* @param array $courseid
* @return array $options
*/
protected function get_errorcmid_options($courseid = 0) {
$options = ['0' => ''];
$modinfo = get_fast_modinfo($courseid);
foreach ($modinfo->cms as $cmid => $cm) {
if ($cm->modname == 'glossary' && $cm->uservisible) {
$options[$cm->id] = format_text($cm->name);
}
}
return $options;
}
/**
* Returns default value for an item.
*
* @param string $name Item name
* @param string|mixed|null $default Default value (optional, default = null)
* @return string|mixed|null Default value for field with this $name
*/
protected function get_my_default_value($name, $default) {
if (method_exists($this, 'get_default_value')) {
// Moodle >= 3.10.
return $this->get_default_value($name, $default);
} else {
// Moodle <= 3.9.
return get_user_preferences($this->plugin_name() . '_' . $name, $default);
}
}
/**
* Get array of countable item types.
*
* @param string $plugin name
* @return [type => description]
*/
protected function get_itemtype_options($plugin) {
$options['0'] = get_string('none');
$options['1'] = get_string('chars', $plugin);
$options['2'] = get_string('words', $plugin);
$options['3'] = get_string('sentences', $plugin);
$options['4'] = get_string('paragraphs', $plugin);
return $options;
}
/**
* Get array of full match options.
*
* @param string $plugin name
* @return [value => description]
*/
protected function diary_get_fullmatch_options($plugin) {
return [0 => get_string('phrasefullmatchno', $plugin), 1 => get_string('phrasefullmatchyes', $plugin)];
}
/**
* Get array of case sensitivity options.
*
* @param string $plugin name
* @return [value => description]
*/
protected function get_casesensitive_options($plugin) {
return [0 => get_string('phrasecasesensitiveno', $plugin), 1 => get_string('phrasecasesensitiveyes', $plugin)];
}
/**
* Get array of options for ignoring breaks
*
* @param string $plugin name
* @return [value => description]
*/
protected function get_ignorebreaks_options($plugin) {
return [0 => get_string('phraseignorebreaksno', $plugin), 1 => get_string('phraseignorebreaksyes', $plugin)];
}
}