1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* This file contains the forms to create and edit an instance of this module
|
|
|
19 |
*
|
|
|
20 |
* @package mod_assign
|
|
|
21 |
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
|
|
26 |
|
|
|
27 |
require_once($CFG->dirroot.'/course/moodleform_mod.php');
|
|
|
28 |
require_once($CFG->dirroot . '/mod/assign/locallib.php');
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Assignment settings form.
|
|
|
32 |
*
|
|
|
33 |
* @package mod_assign
|
|
|
34 |
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
|
|
|
35 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
36 |
*/
|
|
|
37 |
class mod_assign_mod_form extends moodleform_mod {
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Called to define this moodle form
|
|
|
41 |
*
|
|
|
42 |
* @return void
|
|
|
43 |
*/
|
|
|
44 |
public function definition() {
|
1441 |
ariadna |
45 |
global $CFG, $COURSE, $OUTPUT;;
|
1 |
efrain |
46 |
$mform = $this->_form;
|
|
|
47 |
|
|
|
48 |
$mform->addElement('header', 'general', get_string('general', 'form'));
|
|
|
49 |
|
|
|
50 |
$mform->addElement('text', 'name', get_string('assignmentname', 'assign'), array('size'=>'64'));
|
|
|
51 |
if (!empty($CFG->formatstringstriptags)) {
|
|
|
52 |
$mform->setType('name', PARAM_TEXT);
|
|
|
53 |
} else {
|
|
|
54 |
$mform->setType('name', PARAM_CLEANHTML);
|
|
|
55 |
}
|
|
|
56 |
$mform->addRule('name', null, 'required', null, 'client');
|
|
|
57 |
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
|
|
|
58 |
|
|
|
59 |
$this->standard_intro_elements(get_string('description', 'assign'));
|
|
|
60 |
|
|
|
61 |
// Activity.
|
|
|
62 |
$mform->addElement('editor', 'activityeditor',
|
|
|
63 |
get_string('activityeditor', 'assign'), array('rows' => 10), array('maxfiles' => EDITOR_UNLIMITED_FILES,
|
|
|
64 |
'noclean' => true, 'context' => $this->context, 'subdirs' => true));
|
|
|
65 |
$mform->addHelpButton('activityeditor', 'activityeditor', 'assign');
|
|
|
66 |
$mform->setType('activityeditor', PARAM_RAW);
|
|
|
67 |
|
|
|
68 |
$mform->addElement('filemanager', 'introattachments',
|
|
|
69 |
get_string('introattachments', 'assign'),
|
|
|
70 |
null, array('subdirs' => 0, 'maxbytes' => $COURSE->maxbytes) );
|
|
|
71 |
$mform->addHelpButton('introattachments', 'introattachments', 'assign');
|
|
|
72 |
|
|
|
73 |
$mform->addElement('advcheckbox', 'submissionattachments', get_string('submissionattachments', 'assign'));
|
|
|
74 |
$mform->addHelpButton('submissionattachments', 'submissionattachments', 'assign');
|
|
|
75 |
|
1441 |
ariadna |
76 |
[$assignment] = $this->get_assign();
|
1 |
efrain |
77 |
|
|
|
78 |
$mform->addElement('header', 'availability', get_string('availability', 'assign'));
|
|
|
79 |
$mform->setExpanded('availability', true);
|
|
|
80 |
|
|
|
81 |
$name = get_string('allowsubmissionsfromdate', 'assign');
|
|
|
82 |
$options = array('optional'=>true);
|
|
|
83 |
$mform->addElement('date_time_selector', 'allowsubmissionsfromdate', $name, $options);
|
|
|
84 |
$mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'assign');
|
|
|
85 |
|
1441 |
ariadna |
86 |
// Add the option to recalculate the penalty if there is existing grade.
|
|
|
87 |
$penaltysettingmessage = '';
|
|
|
88 |
if ($assignment->has_instance()
|
|
|
89 |
&& \mod_assign\penalty\helper::is_penalty_enabled($assignment->get_instance()->id)
|
|
|
90 |
&& $assignment->count_grades() > 0) {
|
|
|
91 |
// Create notification.
|
|
|
92 |
$penaltysettingmessage = $OUTPUT->notification(get_string('penaltyduedatechangemessage', 'assign'), 'warning', false);
|
|
|
93 |
$mform->addElement('html', $penaltysettingmessage);
|
|
|
94 |
$mform->addElement('select', 'recalculatepenalty', get_string('modgraderecalculatepenalty', 'grades'), [
|
|
|
95 |
'' => get_string('choose'),
|
|
|
96 |
'no' => get_string('no'),
|
|
|
97 |
'yes' => get_string('yes'),
|
|
|
98 |
]);
|
|
|
99 |
$mform->addHelpButton('recalculatepenalty', 'modgraderecalculatepenalty', 'grades');
|
|
|
100 |
}
|
|
|
101 |
|
1 |
efrain |
102 |
$name = get_string('duedate', 'assign');
|
|
|
103 |
$mform->addElement('date_time_selector', 'duedate', $name, array('optional'=>true));
|
|
|
104 |
$mform->addHelpButton('duedate', 'duedate', 'assign');
|
1441 |
ariadna |
105 |
$mform->disabledIf('duedate', 'recalculatepenalty', 'eq', '');
|
1 |
efrain |
106 |
|
|
|
107 |
$name = get_string('cutoffdate', 'assign');
|
|
|
108 |
$mform->addElement('date_time_selector', 'cutoffdate', $name, array('optional'=>true));
|
|
|
109 |
$mform->addHelpButton('cutoffdate', 'cutoffdate', 'assign');
|
|
|
110 |
|
|
|
111 |
$name = get_string('gradingduedate', 'assign');
|
|
|
112 |
$mform->addElement('date_time_selector', 'gradingduedate', $name, array('optional' => true));
|
|
|
113 |
$mform->addHelpButton('gradingduedate', 'gradingduedate', 'assign');
|
|
|
114 |
|
|
|
115 |
$timelimitenabled = get_config('assign', 'enabletimelimit');
|
|
|
116 |
// Time limit.
|
|
|
117 |
if ($timelimitenabled) {
|
|
|
118 |
$mform->addElement('duration', 'timelimit', get_string('timelimit', 'assign'),
|
|
|
119 |
array('optional' => true));
|
|
|
120 |
$mform->addHelpButton('timelimit', 'timelimit', 'assign');
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
$name = get_string('alwaysshowdescription', 'assign');
|
|
|
124 |
$mform->addElement('checkbox', 'alwaysshowdescription', $name);
|
|
|
125 |
$mform->addHelpButton('alwaysshowdescription', 'alwaysshowdescription', 'assign');
|
|
|
126 |
$mform->disabledIf('alwaysshowdescription', 'allowsubmissionsfromdate[enabled]', 'notchecked');
|
|
|
127 |
|
|
|
128 |
$assignment->add_all_plugin_settings($mform);
|
|
|
129 |
|
|
|
130 |
$mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'assign'));
|
|
|
131 |
|
|
|
132 |
$name = get_string('submissiondrafts', 'assign');
|
|
|
133 |
$mform->addElement('selectyesno', 'submissiondrafts', $name);
|
|
|
134 |
$mform->addHelpButton('submissiondrafts', 'submissiondrafts', 'assign');
|
|
|
135 |
if ($assignment->has_submissions_or_grades()) {
|
|
|
136 |
$mform->freeze('submissiondrafts');
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
$name = get_string('requiresubmissionstatement', 'assign');
|
|
|
140 |
$mform->addElement('selectyesno', 'requiresubmissionstatement', $name);
|
|
|
141 |
$mform->addHelpButton('requiresubmissionstatement',
|
|
|
142 |
'requiresubmissionstatement',
|
|
|
143 |
'assign');
|
|
|
144 |
$mform->setType('requiresubmissionstatement', PARAM_BOOL);
|
|
|
145 |
|
1441 |
ariadna |
146 |
$options = [ASSIGN_UNLIMITED_ATTEMPTS => get_string('unlimitedattempts', 'mod_assign')];
|
1 |
efrain |
147 |
$options += array_combine(range(1, 30), range(1, 30));
|
|
|
148 |
$mform->addElement('select', 'maxattempts', get_string('maxattempts', 'mod_assign'), $options);
|
|
|
149 |
$mform->addHelpButton('maxattempts', 'maxattempts', 'assign');
|
|
|
150 |
|
1441 |
ariadna |
151 |
$choice = new core\output\choicelist();
|
|
|
152 |
|
|
|
153 |
$choice->add_option(
|
|
|
154 |
value: ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL,
|
|
|
155 |
name: get_string('attemptreopenmethod_manual', 'mod_assign'),
|
|
|
156 |
definition: ['description' => get_string('attemptreopenmethod_manual_help', 'mod_assign')]
|
|
|
157 |
);
|
|
|
158 |
$choice->add_option(
|
|
|
159 |
value: ASSIGN_ATTEMPT_REOPEN_METHOD_AUTOMATIC,
|
|
|
160 |
name: get_string('attemptreopenmethod_automatic', 'mod_assign'),
|
|
|
161 |
definition: ['description' => get_string('attemptreopenmethod_automatic_help', 'mod_assign')]
|
|
|
162 |
);
|
|
|
163 |
$choice->add_option(
|
|
|
164 |
value: ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS,
|
|
|
165 |
name: get_string('attemptreopenmethod_untilpass', 'mod_assign'),
|
|
|
166 |
definition: ['description' => get_string('attemptreopenmethod_untilpass_help', 'mod_assign')]
|
|
|
167 |
);
|
|
|
168 |
|
|
|
169 |
$mform->addElement('choicedropdown', 'attemptreopenmethod', get_string('attemptreopenmethod', 'mod_assign'), $choice);
|
|
|
170 |
$mform->hideIf('attemptreopenmethod', 'maxattempts', 'eq', 1);
|
|
|
171 |
|
1 |
efrain |
172 |
$mform->addElement('header', 'groupsubmissionsettings', get_string('groupsubmissionsettings', 'assign'));
|
|
|
173 |
|
|
|
174 |
$name = get_string('teamsubmission', 'assign');
|
|
|
175 |
$mform->addElement('selectyesno', 'teamsubmission', $name);
|
|
|
176 |
$mform->addHelpButton('teamsubmission', 'teamsubmission', 'assign');
|
|
|
177 |
if ($assignment->has_submissions_or_grades()) {
|
|
|
178 |
$mform->freeze('teamsubmission');
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
$name = get_string('preventsubmissionnotingroup', 'assign');
|
|
|
182 |
$mform->addElement('selectyesno', 'preventsubmissionnotingroup', $name);
|
|
|
183 |
$mform->addHelpButton('preventsubmissionnotingroup',
|
|
|
184 |
'preventsubmissionnotingroup',
|
|
|
185 |
'assign');
|
|
|
186 |
$mform->setType('preventsubmissionnotingroup', PARAM_BOOL);
|
|
|
187 |
$mform->hideIf('preventsubmissionnotingroup', 'teamsubmission', 'eq', 0);
|
|
|
188 |
|
|
|
189 |
$name = get_string('requireallteammemberssubmit', 'assign');
|
|
|
190 |
$mform->addElement('selectyesno', 'requireallteammemberssubmit', $name);
|
|
|
191 |
$mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'assign');
|
|
|
192 |
$mform->hideIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0);
|
|
|
193 |
$mform->disabledIf('requireallteammemberssubmit', 'submissiondrafts', 'eq', 0);
|
|
|
194 |
|
|
|
195 |
$groupings = groups_get_all_groupings($assignment->get_course()->id);
|
|
|
196 |
$options = array();
|
|
|
197 |
$options[0] = get_string('none');
|
|
|
198 |
foreach ($groupings as $grouping) {
|
|
|
199 |
$options[$grouping->id] = $grouping->name;
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
$name = get_string('teamsubmissiongroupingid', 'assign');
|
|
|
203 |
$mform->addElement('select', 'teamsubmissiongroupingid', $name, $options);
|
|
|
204 |
$mform->addHelpButton('teamsubmissiongroupingid', 'teamsubmissiongroupingid', 'assign');
|
|
|
205 |
$mform->hideIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0);
|
|
|
206 |
if ($assignment->has_submissions_or_grades()) {
|
|
|
207 |
$mform->freeze('teamsubmissiongroupingid');
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
$mform->addElement('header', 'notifications', get_string('notifications', 'assign'));
|
|
|
211 |
|
|
|
212 |
$name = get_string('sendnotifications', 'assign');
|
|
|
213 |
$mform->addElement('selectyesno', 'sendnotifications', $name);
|
|
|
214 |
$mform->addHelpButton('sendnotifications', 'sendnotifications', 'assign');
|
|
|
215 |
|
|
|
216 |
$name = get_string('sendlatenotifications', 'assign');
|
|
|
217 |
$mform->addElement('selectyesno', 'sendlatenotifications', $name);
|
|
|
218 |
$mform->addHelpButton('sendlatenotifications', 'sendlatenotifications', 'assign');
|
|
|
219 |
$mform->disabledIf('sendlatenotifications', 'sendnotifications', 'eq', 1);
|
|
|
220 |
|
|
|
221 |
$name = get_string('sendstudentnotificationsdefault', 'assign');
|
|
|
222 |
$mform->addElement('selectyesno', 'sendstudentnotifications', $name);
|
|
|
223 |
$mform->addHelpButton('sendstudentnotifications', 'sendstudentnotificationsdefault', 'assign');
|
|
|
224 |
|
|
|
225 |
$this->standard_grading_coursemodule_elements();
|
|
|
226 |
$name = get_string('blindmarking', 'assign');
|
|
|
227 |
$mform->addElement('selectyesno', 'blindmarking', $name);
|
|
|
228 |
$mform->addHelpButton('blindmarking', 'blindmarking', 'assign');
|
|
|
229 |
if ($assignment->has_submissions_or_grades() ) {
|
|
|
230 |
$mform->freeze('blindmarking');
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
$name = get_string('hidegrader', 'assign');
|
|
|
234 |
$mform->addElement('selectyesno', 'hidegrader', $name);
|
|
|
235 |
$mform->addHelpButton('hidegrader', 'hidegrader', 'assign');
|
|
|
236 |
|
|
|
237 |
$name = get_string('markingworkflow', 'assign');
|
|
|
238 |
$mform->addElement('selectyesno', 'markingworkflow', $name);
|
|
|
239 |
$mform->addHelpButton('markingworkflow', 'markingworkflow', 'assign');
|
|
|
240 |
|
|
|
241 |
$name = get_string('markingallocation', 'assign');
|
|
|
242 |
$mform->addElement('selectyesno', 'markingallocation', $name);
|
|
|
243 |
$mform->addHelpButton('markingallocation', 'markingallocation', 'assign');
|
|
|
244 |
$mform->hideIf('markingallocation', 'markingworkflow', 'eq', 0);
|
|
|
245 |
|
|
|
246 |
$name = get_string('markinganonymous', 'assign');
|
|
|
247 |
$mform->addElement('selectyesno', 'markinganonymous', $name);
|
|
|
248 |
$mform->addHelpButton('markinganonymous', 'markinganonymous', 'assign');
|
|
|
249 |
$mform->hideIf('markinganonymous', 'markingworkflow', 'eq', 0);
|
|
|
250 |
$mform->hideIf('markinganonymous', 'blindmarking', 'eq', 0);
|
|
|
251 |
|
1441 |
ariadna |
252 |
// Add Penalty settings if the module supports it.
|
|
|
253 |
if (\core_grades\penalty_manager::is_penalty_enabled_for_module('assign')) {
|
|
|
254 |
// Show the message if we need to change the penalty settings.
|
|
|
255 |
if (!empty($penaltysettingmessage)) {
|
|
|
256 |
$mform->addElement('html', $penaltysettingmessage);
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
// Enable or disable the penalty settings.
|
|
|
260 |
$mform->addElement('selectyesno', 'gradepenalty', get_string('gradepenalty', 'mod_assign'));
|
|
|
261 |
$mform->addHelpButton('gradepenalty', 'gradepenalty', 'mod_assign');
|
|
|
262 |
$mform->setDefault('gradepenalty', 0);
|
|
|
263 |
|
|
|
264 |
// Hide if the due date is not enabled.
|
|
|
265 |
$mform->hideIf('gradepenalty', 'duedate[enabled]');
|
|
|
266 |
|
|
|
267 |
// Hide if the grade type is not set to point.
|
|
|
268 |
$mform->hideIf('gradepenalty', 'grade[modgrade_type]', 'neq', 'point');
|
|
|
269 |
|
|
|
270 |
// Disable if the recalculate penalty is not set.
|
|
|
271 |
$mform->disabledIf('gradepenalty', 'recalculatepenalty', 'eq', '');
|
|
|
272 |
}
|
|
|
273 |
|
1 |
efrain |
274 |
$this->standard_coursemodule_elements();
|
|
|
275 |
$this->apply_admin_defaults();
|
|
|
276 |
|
|
|
277 |
$this->add_action_buttons();
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
/**
|
1441 |
ariadna |
281 |
* Override definition after data has been set.
|
|
|
282 |
*
|
|
|
283 |
* The value of date time selector will be lost in a POST request, if the selector is disabled.
|
|
|
284 |
* So, we need to set the value again.
|
|
|
285 |
*
|
|
|
286 |
* return void
|
|
|
287 |
*/
|
|
|
288 |
public function definition_after_data() {
|
|
|
289 |
parent::definition_after_data();
|
|
|
290 |
$mform = $this->_form;
|
|
|
291 |
|
|
|
292 |
// The value of date time selector will be lost in a POST request.
|
|
|
293 |
$recalculatepenalty = optional_param('recalculatepenalty', null, PARAM_TEXT);
|
|
|
294 |
if ($recalculatepenalty === '') {
|
|
|
295 |
$mform->setConstant('duedate', $mform->_defaultValues['duedate']);
|
|
|
296 |
}
|
|
|
297 |
}
|
|
|
298 |
|
|
|
299 |
/**
|
1 |
efrain |
300 |
* Perform minimal validation on the settings form
|
|
|
301 |
* @param array $data
|
|
|
302 |
* @param array $files
|
|
|
303 |
*/
|
|
|
304 |
public function validation($data, $files) {
|
|
|
305 |
$errors = parent::validation($data, $files);
|
|
|
306 |
|
|
|
307 |
if (!empty($data['allowsubmissionsfromdate']) && !empty($data['duedate'])) {
|
|
|
308 |
if ($data['duedate'] <= $data['allowsubmissionsfromdate']) {
|
|
|
309 |
$errors['duedate'] = get_string('duedateaftersubmissionvalidation', 'assign');
|
|
|
310 |
}
|
|
|
311 |
}
|
|
|
312 |
if (!empty($data['cutoffdate']) && !empty($data['duedate'])) {
|
|
|
313 |
if ($data['cutoffdate'] < $data['duedate'] ) {
|
|
|
314 |
$errors['cutoffdate'] = get_string('cutoffdatevalidation', 'assign');
|
|
|
315 |
}
|
|
|
316 |
}
|
|
|
317 |
if (!empty($data['allowsubmissionsfromdate']) && !empty($data['cutoffdate'])) {
|
|
|
318 |
if ($data['cutoffdate'] < $data['allowsubmissionsfromdate']) {
|
|
|
319 |
$errors['cutoffdate'] = get_string('cutoffdatefromdatevalidation', 'assign');
|
|
|
320 |
}
|
|
|
321 |
}
|
|
|
322 |
if ($data['gradingduedate']) {
|
|
|
323 |
if ($data['allowsubmissionsfromdate'] && $data['allowsubmissionsfromdate'] > $data['gradingduedate']) {
|
|
|
324 |
$errors['gradingduedate'] = get_string('gradingduefromdatevalidation', 'assign');
|
|
|
325 |
}
|
|
|
326 |
if ($data['duedate'] && $data['duedate'] > $data['gradingduedate']) {
|
|
|
327 |
$errors['gradingduedate'] = get_string('gradingdueduedatevalidation', 'assign');
|
|
|
328 |
}
|
|
|
329 |
}
|
1441 |
ariadna |
330 |
$multipleattemptsallowed = $data['maxattempts'] > 1 || $data['maxattempts'] == ASSIGN_UNLIMITED_ATTEMPTS;
|
|
|
331 |
if ($data['blindmarking'] && $multipleattemptsallowed &&
|
|
|
332 |
$data['attemptreopenmethod'] == ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS) {
|
1 |
efrain |
333 |
$errors['attemptreopenmethod'] = get_string('reopenuntilpassincompatiblewithblindmarking', 'assign');
|
|
|
334 |
}
|
|
|
335 |
|
1441 |
ariadna |
336 |
[$assignment] = $this->get_assign();
|
|
|
337 |
$errors = array_merge($errors, $assignment->plugin_settings_validation($data, $files));
|
|
|
338 |
|
1 |
efrain |
339 |
return $errors;
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
/**
|
|
|
343 |
* Any data processing needed before the form is displayed
|
|
|
344 |
* (needed to set up draft areas for editor and filemanager elements)
|
|
|
345 |
* @param array $defaultvalues
|
|
|
346 |
*/
|
|
|
347 |
public function data_preprocessing(&$defaultvalues) {
|
1441 |
ariadna |
348 |
[$assignment, $ctx] = $this->get_assign();
|
1 |
efrain |
349 |
|
|
|
350 |
$draftitemid = file_get_submitted_draft_itemid('introattachments');
|
|
|
351 |
file_prepare_draft_area($draftitemid, $ctx->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA,
|
|
|
352 |
0, array('subdirs' => 0));
|
|
|
353 |
$defaultvalues['introattachments'] = $draftitemid;
|
|
|
354 |
|
|
|
355 |
// Activity editor fields.
|
|
|
356 |
$activitydraftitemid = file_get_submitted_draft_itemid('activityeditor');
|
|
|
357 |
if (!empty($defaultvalues['activity'])) {
|
|
|
358 |
$defaultvalues['activityeditor'] = array(
|
|
|
359 |
'text' => file_prepare_draft_area($activitydraftitemid, $ctx->id, 'mod_assign', ASSIGN_ACTIVITYATTACHMENT_FILEAREA,
|
|
|
360 |
0, array('subdirs' => 0), $defaultvalues['activity']),
|
|
|
361 |
'format' => $defaultvalues['activityformat'],
|
|
|
362 |
'itemid' => $activitydraftitemid
|
|
|
363 |
);
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
$assignment->plugin_data_preprocessing($defaultvalues);
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
/**
|
|
|
370 |
* Add any custom completion rules to the form.
|
|
|
371 |
*
|
|
|
372 |
* @return array Contains the names of the added form elements
|
|
|
373 |
*/
|
|
|
374 |
public function add_completion_rules() {
|
|
|
375 |
$mform =& $this->_form;
|
|
|
376 |
|
|
|
377 |
$suffix = $this->get_suffix();
|
|
|
378 |
$completionsubmitel = 'completionsubmit' . $suffix;
|
|
|
379 |
$mform->addElement('advcheckbox', $completionsubmitel, '', get_string('completionsubmit', 'assign'));
|
|
|
380 |
// Enable this completion rule by default.
|
|
|
381 |
$mform->setDefault($completionsubmitel, 1);
|
|
|
382 |
|
|
|
383 |
return [$completionsubmitel];
|
|
|
384 |
}
|
|
|
385 |
|
|
|
386 |
/**
|
|
|
387 |
* Determines if completion is enabled for this module.
|
|
|
388 |
*
|
|
|
389 |
* @param array $data
|
|
|
390 |
* @return bool
|
|
|
391 |
*/
|
|
|
392 |
public function completion_rule_enabled($data) {
|
|
|
393 |
$suffix = $this->get_suffix();
|
|
|
394 |
return !empty($data['completionsubmit' . $suffix]);
|
|
|
395 |
}
|
|
|
396 |
|
1441 |
ariadna |
397 |
/**
|
|
|
398 |
* Get the list of admin settings for this module and apply any defaults/advanced/locked/required settings.
|
|
|
399 |
*
|
|
|
400 |
* @param array $datetimeoffsets - If passed, this is an array of fieldnames => times that the
|
|
|
401 |
* default date/time value should be relative to. If not passed, all
|
|
|
402 |
* date/time fields are set relative to the users current midnight.
|
|
|
403 |
* @return void
|
|
|
404 |
*/
|
|
|
405 |
public function apply_admin_defaults($datetimeoffsets = []): void {
|
|
|
406 |
parent::apply_admin_defaults($datetimeoffsets);
|
|
|
407 |
|
|
|
408 |
$isupdate = !empty($this->_cm);
|
|
|
409 |
if ($isupdate) {
|
|
|
410 |
return;
|
|
|
411 |
}
|
|
|
412 |
|
|
|
413 |
$settings = get_config('mod_assign');
|
|
|
414 |
$mform = $this->_form;
|
|
|
415 |
|
|
|
416 |
if ($mform->elementExists('grade')) {
|
|
|
417 |
$element = $mform->getElement('grade');
|
|
|
418 |
|
|
|
419 |
if (property_exists($settings, 'defaultgradetype')) {
|
|
|
420 |
$modgradetype = $element->getName() . '[modgrade_type]';
|
|
|
421 |
switch ((int)$settings->defaultgradetype) {
|
|
|
422 |
case GRADE_TYPE_NONE :
|
|
|
423 |
$mform->setDefault($modgradetype, 'none');
|
|
|
424 |
break;
|
|
|
425 |
case GRADE_TYPE_SCALE :
|
|
|
426 |
$mform->setDefault($modgradetype, 'scale');
|
|
|
427 |
break;
|
|
|
428 |
case GRADE_TYPE_VALUE :
|
|
|
429 |
$mform->setDefault($modgradetype, 'point');
|
|
|
430 |
break;
|
|
|
431 |
}
|
|
|
432 |
}
|
|
|
433 |
|
|
|
434 |
if (property_exists($settings, 'defaultgradescale')) {
|
|
|
435 |
/** @var grade_scale|false $gradescale */
|
|
|
436 |
$gradescale = grade_scale::fetch(['id' => (int)$settings->defaultgradescale, 'courseid' => 0]);
|
|
|
437 |
|
|
|
438 |
if ($gradescale) {
|
|
|
439 |
$mform->setDefault($element->getName() . '[modgrade_scale]', $gradescale->id);
|
|
|
440 |
}
|
|
|
441 |
}
|
|
|
442 |
}
|
|
|
443 |
}
|
|
|
444 |
|
|
|
445 |
/**
|
|
|
446 |
* Get a relevant assign instance for this form, and the context.
|
|
|
447 |
*
|
|
|
448 |
* If we are editing an existing assign, it is that assignment and context, otherwise it is for the course context.
|
|
|
449 |
*
|
|
|
450 |
* @return array [$assignment, $ctx] the assignment object and the context.
|
|
|
451 |
*/
|
|
|
452 |
protected function get_assign(): array {
|
|
|
453 |
global $DB;
|
|
|
454 |
|
|
|
455 |
$ctx = null;
|
|
|
456 |
if ($this->current && $this->current->coursemodule) {
|
|
|
457 |
$cm = get_coursemodule_from_instance('assign', $this->current->id, 0, false, MUST_EXIST);
|
|
|
458 |
$ctx = context_module::instance($cm->id);
|
|
|
459 |
}
|
|
|
460 |
$assignment = new assign($ctx, null, null);
|
|
|
461 |
if ($this->current && $this->current->course) {
|
|
|
462 |
if (!$ctx) {
|
|
|
463 |
$ctx = context_course::instance($this->current->course);
|
|
|
464 |
}
|
|
|
465 |
$course = $DB->get_record('course', ['id' => $this->current->course], '*', MUST_EXIST);
|
|
|
466 |
$assignment->set_course($course);
|
|
|
467 |
}
|
|
|
468 |
return [$assignment, $ctx];
|
|
|
469 |
}
|
1 |
efrain |
470 |
}
|