-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathmod_form.php
More file actions
130 lines (108 loc) · 4.79 KB
/
mod_form.php
File metadata and controls
130 lines (108 loc) · 4.79 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
<?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/>.
/**
* Form structure for mod_journal
*
* @package mod_journal
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
**/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/course/moodleform_mod.php');
/**
* The mod_journal_mod_form class.
*
* @package mod_journal
* @copyright 2022 Elearning Software SRL http://elearningsoftware.ro
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_journal_mod_form extends moodleform_mod {
/**
* Set up the form definition.
*/
public function definition() {
global $COURSE;
$mform = &$this->_form;
$mform->addElement('header', 'general', get_string('general', 'form'));
$mform->addElement('text', 'name', get_string('journalname', 'journal'), ['size' => '64']);
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client');
$this->standard_intro_elements(get_string('journalquestion', 'journal'));
$options = [];
$options[0] = get_string('alwaysopen', 'journal');
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', 'journal'), $options);
if ($COURSE->format === 'weeks') {
$mform->setDefault('days', '7');
} else {
$mform->setDefault('days', '0');
}
// Notifications settings.
$config = get_config('journal');
$mform->addElement('checkbox', 'notifyteachers', get_string('notifyteachers', 'journal'));
$mform->addHelpButton('notifyteachers', 'notifyteachers', 'journal');
$mform->setDefault('notifyteachers', isset($config->notifyteachers_default) ? $config->notifyteachers_default : 1);
$mform->addElement('checkbox', 'notifystudents', get_string('notifystudents', 'journal'));
$mform->addHelpButton('notifystudents', 'notifystudents', 'journal');
$mform->setDefault('notifystudents', isset($config->notifystudents_default) ? $config->notifystudents_default : 1);
$this->standard_grading_coursemodule_elements();
// Apply default grade from global settings.
// We only apply this for new instances (when $this->_instance is empty).
if (empty($this->_instance)) {
$defaultgrade = isset($config->defaultgrade) ? $config->defaultgrade : false;
// If the setting is missing, fallback to 100 (Standard Moodle default).
if ($defaultgrade === false) {
$defaultgrade = 100;
}
$mform->setDefault('grade', $defaultgrade);
}
$this->standard_coursemodule_elements();
$this->add_action_buttons();
}
/**
* Returns whether the custom completion rules are enabled.
*
* @param array $data form data
* @return bool
*/
public function completion_rule_enabled($data): bool {
// Compatibility check: get_suffix only exists in Moodle 4.3+.
$suffix = method_exists($this, 'get_suffix') ? $this->get_suffix() : '';
return (!empty($data['completion_create_entry' . $suffix]));
}
/**
* Adds the custom completion rules for mod_journal
*
* @return array
*/
public function add_completion_rules(): array {
$mform = $this->_form;
// Compatibility check: get_suffix only exists in Moodle 4.3+.
$suffix = method_exists($this, 'get_suffix') ? $this->get_suffix() : '';
$fieldname = 'completion_create_entry' . $suffix;
$mform->addElement('advcheckbox', $fieldname, get_string('completiondetail:completion_create_entry', 'journal'));
$mform->setType($fieldname, PARAM_INT);
$mform->hideIf($fieldname, 'completion', 'neq', COMPLETION_TRACKING_AUTOMATIC);
return ([$fieldname]);
}
}