forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod_form.php
294 lines (246 loc) · 12.8 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
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
<?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 this module
*
* @package mod_assign
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->dirroot.'/course/moodleform_mod.php');
require_once($CFG->dirroot . '/mod/assign/locallib.php');
/**
* Assignment settings form.
*
* @package mod_assign
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_assign_mod_form extends moodleform_mod {
/**
* Called to define this moodle form
*
* @return void
*/
public function definition() {
global $CFG, $DB, $PAGE;
$mform = $this->_form;
$mform->addElement('header', 'general', get_string('general', 'form'));
$mform->addElement('text', 'name', get_string('assignmentname', 'assign'), array('size'=>'64'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEANHTML);
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$this->add_intro_editor(true, get_string('description', 'assign'));
$ctx = null;
if ($this->current && $this->current->coursemodule) {
$cm = get_coursemodule_from_instance('assign', $this->current->id, 0, false, MUST_EXIST);
$ctx = context_module::instance($cm->id);
}
$assignment = new assign($ctx, null, null);
if ($this->current && $this->current->course) {
if (!$ctx) {
$ctx = context_course::instance($this->current->course);
}
$course = $DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST);
$assignment->set_course($course);
}
$config = get_config('assign');
$mform->addElement('header', 'availability', get_string('availability', 'assign'));
$mform->setExpanded('availability', true);
$name = get_string('allowsubmissionsfromdate', 'assign');
$options = array('optional'=>true);
$mform->addElement('date_time_selector', 'allowsubmissionsfromdate', $name, $options);
$mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'assign');
$name = get_string('duedate', 'assign');
$mform->addElement('date_time_selector', 'duedate', $name, array('optional'=>true));
$mform->addHelpButton('duedate', 'duedate', 'assign');
$name = get_string('cutoffdate', 'assign');
$mform->addElement('date_time_selector', 'cutoffdate', $name, array('optional'=>true));
$mform->addHelpButton('cutoffdate', 'cutoffdate', 'assign');
$name = get_string('alwaysshowdescription', 'assign');
$mform->addElement('checkbox', 'alwaysshowdescription', $name);
$mform->addHelpButton('alwaysshowdescription', 'alwaysshowdescription', 'assign');
$mform->disabledIf('alwaysshowdescription', 'allowsubmissionsfromdate[enabled]', 'notchecked');
$assignment->add_all_plugin_settings($mform);
$mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'assign'));
$name = get_string('submissiondrafts', 'assign');
$mform->addElement('selectyesno', 'submissiondrafts', $name);
$mform->addHelpButton('submissiondrafts', 'submissiondrafts', 'assign');
$name = get_string('requiresubmissionstatement', 'assign');
$mform->addElement('selectyesno', 'requiresubmissionstatement', $name);
$mform->addHelpButton('requiresubmissionstatement',
'requiresubmissionstatement',
'assign');
$mform->setType('requiresubmissionstatement', PARAM_BOOL);
$options = array(
ASSIGN_ATTEMPT_REOPEN_METHOD_NONE => get_string('attemptreopenmethod_none', 'mod_assign'),
ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL => get_string('attemptreopenmethod_manual', 'mod_assign'),
ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS => get_string('attemptreopenmethod_untilpass', 'mod_assign')
);
$mform->addElement('select', 'attemptreopenmethod', get_string('attemptreopenmethod', 'mod_assign'), $options);
$mform->addHelpButton('attemptreopenmethod', 'attemptreopenmethod', 'mod_assign');
$options = array(ASSIGN_UNLIMITED_ATTEMPTS => get_string('unlimitedattempts', 'mod_assign'));
$options += array_combine(range(1, 30), range(1, 30));
$mform->addElement('select', 'maxattempts', get_string('maxattempts', 'mod_assign'), $options);
$mform->addHelpButton('maxattempts', 'maxattempts', 'assign');
$mform->disabledIf('maxattempts', 'attemptreopenmethod', 'eq', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE);
$mform->addElement('header', 'groupsubmissionsettings', get_string('groupsubmissionsettings', 'assign'));
$name = get_string('teamsubmission', 'assign');
$mform->addElement('selectyesno', 'teamsubmission', $name);
$mform->addHelpButton('teamsubmission', 'teamsubmission', 'assign');
$name = get_string('requireallteammemberssubmit', 'assign');
$mform->addElement('selectyesno', 'requireallteammemberssubmit', $name);
$mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'assign');
$mform->disabledIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0);
$mform->disabledIf('requireallteammemberssubmit', 'submissiondrafts', 'eq', 0);
$groupings = groups_get_all_groupings($assignment->get_course()->id);
$options = array();
$options[0] = get_string('none');
foreach ($groupings as $grouping) {
$options[$grouping->id] = $grouping->name;
}
$name = get_string('teamsubmissiongroupingid', 'assign');
$mform->addElement('select', 'teamsubmissiongroupingid', $name, $options);
$mform->addHelpButton('teamsubmissiongroupingid', 'teamsubmissiongroupingid', 'assign');
$mform->disabledIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0);
$mform->addElement('header', 'notifications', get_string('notifications', 'assign'));
$name = get_string('sendnotifications', 'assign');
$mform->addElement('selectyesno', 'sendnotifications', $name);
$mform->addHelpButton('sendnotifications', 'sendnotifications', 'assign');
$name = get_string('sendlatenotifications', 'assign');
$mform->addElement('selectyesno', 'sendlatenotifications', $name);
$mform->addHelpButton('sendlatenotifications', 'sendlatenotifications', 'assign');
$mform->disabledIf('sendlatenotifications', 'sendnotifications', 'eq', 1);
$name = get_string('sendstudentnotificationsdefault', 'assign');
$mform->addElement('selectyesno', 'sendstudentnotifications', $name);
$mform->addHelpButton('sendstudentnotifications', 'sendstudentnotificationsdefault', 'assign');
// Plagiarism enabling form.
if (!empty($CFG->enableplagiarism)) {
require_once($CFG->libdir . '/plagiarismlib.php');
plagiarism_get_form_elements_module($mform, $ctx->get_course_context(), 'mod_assign');
}
$this->standard_grading_coursemodule_elements();
$name = get_string('blindmarking', 'assign');
$mform->addElement('selectyesno', 'blindmarking', $name);
$mform->addHelpButton('blindmarking', 'blindmarking', 'assign');
if ($assignment->has_submissions_or_grades() ) {
$mform->freeze('blindmarking');
}
$name = get_string('markingworkflow', 'assign');
$mform->addElement('selectyesno', 'markingworkflow', $name);
$mform->addHelpButton('markingworkflow', 'markingworkflow', 'assign');
$name = get_string('markingallocation', 'assign');
$mform->addElement('selectyesno', 'markingallocation', $name);
$mform->addHelpButton('markingallocation', 'markingallocation', 'assign');
$mform->disabledIf('markingallocation', 'markingworkflow', 'eq', 0);
$this->standard_coursemodule_elements();
$this->apply_admin_defaults();
$this->add_action_buttons();
// Add warning popup/noscript tag, if grades are changed by user.
$hasgrade = false;
if (!empty($this->_instance)) {
$hasgrade = $DB->record_exists_select('assign_grades',
'assignment = ? AND grade <> -1',
array($this->_instance));
}
if ($mform->elementExists('grade') && $hasgrade) {
$module = array(
'name' => 'mod_assign',
'fullpath' => '/mod/assign/module.js',
'requires' => array('node', 'event'),
'strings' => array(array('changegradewarning', 'mod_assign'))
);
$PAGE->requires->js_init_call('M.mod_assign.init_grade_change', null, false, $module);
// Add noscript tag in case.
$noscriptwarning = $mform->createElement('static',
'warning',
null,
html_writer::tag('noscript',
get_string('changegradewarning', 'mod_assign')));
$mform->insertElementBefore($noscriptwarning, 'grade');
}
}
/**
* Perform minimal validation on the settings form
* @param array $data
* @param array $files
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
if ($data['allowsubmissionsfromdate'] && $data['duedate']) {
if ($data['allowsubmissionsfromdate'] > $data['duedate']) {
$errors['duedate'] = get_string('duedatevalidation', 'assign');
}
}
if ($data['duedate'] && $data['cutoffdate']) {
if ($data['duedate'] > $data['cutoffdate']) {
$errors['cutoffdate'] = get_string('cutoffdatevalidation', 'assign');
}
}
if ($data['allowsubmissionsfromdate'] && $data['cutoffdate']) {
if ($data['allowsubmissionsfromdate'] > $data['cutoffdate']) {
$errors['cutoffdate'] = get_string('cutoffdatefromdatevalidation', 'assign');
}
}
return $errors;
}
/**
* Any data processing needed before the form is displayed
* (needed to set up draft areas for editor and filemanager elements)
* @param array $defaultvalues
*/
public function data_preprocessing(&$defaultvalues) {
global $DB;
$ctx = null;
if ($this->current && $this->current->coursemodule) {
$cm = get_coursemodule_from_instance('assign', $this->current->id, 0, false, MUST_EXIST);
$ctx = context_module::instance($cm->id);
}
$assignment = new assign($ctx, null, null);
if ($this->current && $this->current->course) {
if (!$ctx) {
$ctx = context_course::instance($this->current->course);
}
$course = $DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST);
$assignment->set_course($course);
}
$assignment->plugin_data_preprocessing($defaultvalues);
}
/**
* Add any custom completion rules to the form.
*
* @return array Contains the names of the added form elements
*/
public function add_completion_rules() {
$mform =& $this->_form;
$mform->addElement('checkbox', 'completionsubmit', '', get_string('completionsubmit', 'assign'));
return array('completionsubmit');
}
/**
* Determines if completion is enabled for this module.
*
* @param array $data
* @return bool
*/
public function completion_rule_enabled($data) {
return !empty($data['completionsubmit']);
}
}