forked from davosmith/moodle-checklist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_form.php
185 lines (155 loc) · 8.32 KB
/
mod_form.php
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
<?php
// This file is part of the Checklist plugin for 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 defines the main checklist configuration form
* It uses the standard core Moodle (>1.8) formslib. For
* more info about them, please visit:
*
* http://docs.moodle.org/en/Development:lib/formslib.php
*
* The form must provide support for, at least these fields:
* - name: text element of 64cc max
*
* Also, it's usual to use these fields:
* - intro: one htmlarea element to describe the activity
* (will be showed in the list of activities of
* newmodule type (index.php) and in the header
* of the checklist main page (view.php).
* - introformat: The format used to write the contents
* of the intro field. It automatically defaults
* to HTML when the htmleditor is used and can be
* manually selected if the htmleditor is not used
* (standard formats are: MOODLE, HTML, PLAIN, MARKDOWN)
* See lib/weblib.php Constants and the format_text()
* function for more info
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/course/moodleform_mod.php');
class mod_checklist_mod_form extends moodleform_mod {
public function definition() {
global $CFG;
$mform = $this->_form;
// Adding the "general" fieldset, where all the common settings are showed.
$mform->addElement('header', 'general', get_string('general', 'form'));
// Adding the standard "name" field.
$mform->addElement('text', 'name', get_string('modulename', 'checklist'), array('size' => '64'));
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
if ($CFG->branch < 29) {
$this->add_intro_editor(true, get_string('checklistintro', 'checklist'));
} else {
$this->standard_intro_elements(get_string('checklistintro', 'checklist'));
}
$mform->addElement('header', 'checklistsettings', get_string('checklistsettings', 'checklist'));
$mform->setExpanded('checklistsettings', true);
$ynoptions = array(0 => get_string('no'), 1 => get_string('yes'));
$mform->addElement('select', 'useritemsallowed', get_string('useritemsallowed', 'checklist'), $ynoptions);
$teditoptions = array(
CHECKLIST_MARKING_STUDENT => get_string('teachernoteditcheck', 'checklist'),
CHECKLIST_MARKING_TEACHER => get_string('teacheroverwritecheck', 'checklist'),
CHECKLIST_MARKING_BOTH => get_string('teacheralongsidecheck', 'checklist')
);
$mform->addElement('select', 'teacheredit', get_string('teacheredit', 'checklist'), $teditoptions);
$mform->addElement('select', 'duedatesoncalendar', get_string('duedatesoncalendar', 'checklist'), $ynoptions);
$mform->setDefault('duedatesoncalendar', 0);
$mform->addElement('select', 'teachercomments', get_string('teachercomments', 'checklist'), $ynoptions);
$mform->setDefault('teachercomments', 1);
$mform->addElement('text', 'maxgrade', get_string('maximumgrade'), array('size' => '10'));
$mform->setDefault('maxgrade', 100);
$mform->setType('maxgrade', PARAM_INT);
$emailrecipients = array(
CHECKLIST_EMAIL_NO => get_string('no'),
CHECKLIST_EMAIL_STUDENT => get_string('teachernoteditcheck', 'checklist'),
CHECKLIST_EMAIL_TEACHER => get_string('teacheroverwritecheck', 'checklist'),
CHECKLIST_EMAIL_BOTH => get_string('teacheralongsidecheck', 'checklist')
);
$mform->addElement('select', 'emailoncomplete', get_string('emailoncomplete', 'checklist'), $emailrecipients);
$mform->setDefault('emailoncomplete', 0);
$mform->addHelpButton('emailoncomplete', 'emailoncomplete', 'checklist');
$autopopulateoptions = array(
CHECKLIST_AUTOPOPULATE_NO => get_string('no'),
CHECKLIST_AUTOPOPULATE_SECTION => get_string('importfromsection', 'checklist'),
CHECKLIST_AUTOPOPULATE_COURSE => get_string('importfromcourse', 'checklist')
);
$mform->addElement('select', 'autopopulate', get_string('autopopulate', 'checklist'), $autopopulateoptions);
$mform->setDefault('autopopulate', 0);
$mform->addHelpButton('autopopulate', 'autopopulate', 'checklist');
$checkdisable = true;
$str = 'autoupdate';
if (get_config('mod_checklist', 'linkcourses')) {
$str = 'autoupdate2';
$checkdisable = false;
}
$autoupdateoptions = array(
CHECKLIST_AUTOUPDATE_NO => get_string('no'),
CHECKLIST_AUTOUPDATE_YES => get_string('yesnooverride', 'checklist'),
CHECKLIST_AUTOUPDATE_YES_OVERRIDE => get_string('yesoverride', 'checklist')
);
$mform->addElement('select', 'autoupdate', get_string($str, 'checklist'), $autoupdateoptions);
$mform->setDefault('autoupdate', 1);
$mform->addHelpButton('autoupdate', $str, 'checklist');
$mform->addElement('static', 'autoupdatenote', '', get_string('autoupdatenote', 'checklist'));
if ($checkdisable) {
$mform->disabledIf('autoupdate', 'autopopulate', 'eq', 0);
}
$mform->addElement('selectyesno', 'lockteachermarks', get_string('lockteachermarks', 'checklist'));
$mform->setDefault('lockteachermarks', 0);
$mform->addHelpButton('lockteachermarks', 'lockteachermarks', 'checklist');
// Add standard elements, common to all modules.
$this->standard_coursemodule_elements();
// Add standard buttons, common to all modules.
$this->add_action_buttons();
}
public function data_preprocessing(&$defaultvalues) {
parent::data_preprocessing($defaultvalues);
// Set up the completion checkboxes which aren't part of standard data.
// We also make the default value (if you turn on the checkbox) for those
// numbers to be 1, this will not apply unless checkbox is ticked.
$defaultvalues['completionpercentenabled'] = !empty($defaultvalues['completionpercent']) ? 1 : 0;
if (empty($defaultvalues['completionpercent'])) {
$defaultvalues['completionpercent'] = 100;
}
}
public function add_completion_rules() {
$mform =& $this->_form;
$group = array();
$group[] =& $mform->createElement('checkbox', 'completionpercentenabled', '', get_string('completionpercent', 'checklist'), array('class' => 'checkbox-inline'));
$group[] =& $mform->createElement('text', 'completionpercent', '', array('size' => 3));
$mform->setType('completionpercent', PARAM_INT);
$mform->addGroup($group, 'completionpercentgroup', get_string('completionpercentgroup', 'checklist'), array(' '), false);
$mform->disabledIf('completionpercent', 'completionpercentenabled', 'notchecked');
return array('completionpercentgroup');
}
public function completion_rule_enabled($data) {
return (!empty($data['completionpercentenabled']) && $data['completionpercent'] != 0);
}
public function get_data() {
$data = parent::get_data();
if (!$data) {
return false;
}
// Turn off completion settings if the checkboxes aren't ticked.
if (isset($data->completionpercent)) {
$autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
if (empty($data->completionpercentenabled) || !$autocompletion) {
$data->completionpercent = 0;
}
}
return $data;
}
}