Línea 40... |
Línea 40... |
40 |
* Called to define this moodle form
|
40 |
* Called to define this moodle form
|
41 |
*
|
41 |
*
|
42 |
* @return void
|
42 |
* @return void
|
43 |
*/
|
43 |
*/
|
44 |
public function definition() {
|
44 |
public function definition() {
|
45 |
global $CFG, $COURSE, $DB, $PAGE;
|
45 |
global $CFG, $COURSE, $OUTPUT;;
|
46 |
$mform = $this->_form;
|
46 |
$mform = $this->_form;
|
Línea 47... |
Línea 47... |
47 |
|
47 |
|
Línea 48... |
Línea 48... |
48 |
$mform->addElement('header', 'general', get_string('general', 'form'));
|
48 |
$mform->addElement('header', 'general', get_string('general', 'form'));
|
Línea 71... |
Línea 71... |
71 |
$mform->addHelpButton('introattachments', 'introattachments', 'assign');
|
71 |
$mform->addHelpButton('introattachments', 'introattachments', 'assign');
|
Línea 72... |
Línea 72... |
72 |
|
72 |
|
73 |
$mform->addElement('advcheckbox', 'submissionattachments', get_string('submissionattachments', 'assign'));
|
73 |
$mform->addElement('advcheckbox', 'submissionattachments', get_string('submissionattachments', 'assign'));
|
Línea 74... |
Línea -... |
74 |
$mform->addHelpButton('submissionattachments', 'submissionattachments', 'assign');
|
- |
|
75 |
|
- |
|
76 |
$ctx = null;
|
- |
|
77 |
if ($this->current && $this->current->coursemodule) {
|
- |
|
78 |
$cm = get_coursemodule_from_instance('assign', $this->current->id, 0, false, MUST_EXIST);
|
- |
|
79 |
$ctx = context_module::instance($cm->id);
|
74 |
$mform->addHelpButton('submissionattachments', 'submissionattachments', 'assign');
|
80 |
}
|
- |
|
81 |
$assignment = new assign($ctx, null, null);
|
- |
|
82 |
if ($this->current && $this->current->course) {
|
- |
|
83 |
if (!$ctx) {
|
- |
|
84 |
$ctx = context_course::instance($this->current->course);
|
- |
|
85 |
}
|
- |
|
86 |
$course = $DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST);
|
- |
|
Línea 87... |
Línea 75... |
87 |
$assignment->set_course($course);
|
75 |
|
88 |
}
|
76 |
[$assignment] = $this->get_assign();
|
Línea 89... |
Línea 77... |
89 |
|
77 |
|
90 |
$mform->addElement('header', 'availability', get_string('availability', 'assign'));
|
78 |
$mform->addElement('header', 'availability', get_string('availability', 'assign'));
|
91 |
$mform->setExpanded('availability', true);
|
79 |
$mform->setExpanded('availability', true);
|
92 |
|
80 |
|
Línea -... |
Línea 81... |
- |
|
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 |
|
- |
|
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'),
|
93 |
$name = get_string('allowsubmissionsfromdate', 'assign');
|
97 |
'yes' => get_string('yes'),
|
94 |
$options = array('optional'=>true);
|
98 |
]);
|
95 |
$mform->addElement('date_time_selector', 'allowsubmissionsfromdate', $name, $options);
|
99 |
$mform->addHelpButton('recalculatepenalty', 'modgraderecalculatepenalty', 'grades');
|
- |
|
100 |
}
|
Línea 96... |
Línea 101... |
96 |
$mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'assign');
|
101 |
|
97 |
|
102 |
$name = get_string('duedate', 'assign');
|
98 |
$name = get_string('duedate', 'assign');
|
103 |
$mform->addElement('date_time_selector', 'duedate', $name, array('optional'=>true));
|
Línea 136... |
Línea 141... |
136 |
$mform->addHelpButton('requiresubmissionstatement',
|
141 |
$mform->addHelpButton('requiresubmissionstatement',
|
137 |
'requiresubmissionstatement',
|
142 |
'requiresubmissionstatement',
|
138 |
'assign');
|
143 |
'assign');
|
139 |
$mform->setType('requiresubmissionstatement', PARAM_BOOL);
|
144 |
$mform->setType('requiresubmissionstatement', PARAM_BOOL);
|
Línea 140... |
Línea -... |
140 |
|
- |
|
141 |
$options = array(
|
- |
|
142 |
ASSIGN_ATTEMPT_REOPEN_METHOD_NONE => get_string('attemptreopenmethod_none', 'mod_assign'),
|
- |
|
143 |
ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL => get_string('attemptreopenmethod_manual', 'mod_assign'),
|
- |
|
144 |
ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS => get_string('attemptreopenmethod_untilpass', 'mod_assign')
|
- |
|
145 |
);
|
- |
|
146 |
$mform->addElement('select', 'attemptreopenmethod', get_string('attemptreopenmethod', 'mod_assign'), $options);
|
- |
|
147 |
$mform->addHelpButton('attemptreopenmethod', 'attemptreopenmethod', 'mod_assign');
|
- |
|
148 |
|
145 |
|
149 |
$options = array(ASSIGN_UNLIMITED_ATTEMPTS => get_string('unlimitedattempts', 'mod_assign'));
|
146 |
$options = [ASSIGN_UNLIMITED_ATTEMPTS => get_string('unlimitedattempts', 'mod_assign')];
|
150 |
$options += array_combine(range(1, 30), range(1, 30));
|
147 |
$options += array_combine(range(1, 30), range(1, 30));
|
151 |
$mform->addElement('select', 'maxattempts', get_string('maxattempts', 'mod_assign'), $options);
|
148 |
$mform->addElement('select', 'maxattempts', get_string('maxattempts', 'mod_assign'), $options);
|
- |
|
149 |
$mform->addHelpButton('maxattempts', 'maxattempts', 'assign');
|
- |
|
150 |
|
- |
|
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 |
|
152 |
$mform->addHelpButton('maxattempts', 'maxattempts', 'assign');
|
169 |
$mform->addElement('choicedropdown', 'attemptreopenmethod', get_string('attemptreopenmethod', 'mod_assign'), $choice);
|
Línea 153... |
Línea 170... |
153 |
$mform->hideIf('maxattempts', 'attemptreopenmethod', 'eq', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE);
|
170 |
$mform->hideIf('attemptreopenmethod', 'maxattempts', 'eq', 1);
|
Línea 154... |
Línea 171... |
154 |
|
171 |
|
155 |
$mform->addElement('header', 'groupsubmissionsettings', get_string('groupsubmissionsettings', 'assign'));
|
172 |
$mform->addElement('header', 'groupsubmissionsettings', get_string('groupsubmissionsettings', 'assign'));
|
Línea 230... |
Línea 247... |
230 |
$mform->addElement('selectyesno', 'markinganonymous', $name);
|
247 |
$mform->addElement('selectyesno', 'markinganonymous', $name);
|
231 |
$mform->addHelpButton('markinganonymous', 'markinganonymous', 'assign');
|
248 |
$mform->addHelpButton('markinganonymous', 'markinganonymous', 'assign');
|
232 |
$mform->hideIf('markinganonymous', 'markingworkflow', 'eq', 0);
|
249 |
$mform->hideIf('markinganonymous', 'markingworkflow', 'eq', 0);
|
233 |
$mform->hideIf('markinganonymous', 'blindmarking', 'eq', 0);
|
250 |
$mform->hideIf('markinganonymous', 'blindmarking', 'eq', 0);
|
Línea -... |
Línea 251... |
- |
|
251 |
|
- |
|
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 |
}
|
234 |
|
273 |
|
235 |
$this->standard_coursemodule_elements();
|
274 |
$this->standard_coursemodule_elements();
|
Línea 236... |
Línea 275... |
236 |
$this->apply_admin_defaults();
|
275 |
$this->apply_admin_defaults();
|
237 |
|
276 |
|
Línea 238... |
Línea 277... |
238 |
$this->add_action_buttons();
|
277 |
$this->add_action_buttons();
|
- |
|
278 |
}
|
- |
|
279 |
|
- |
|
280 |
/**
|
- |
|
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 |
}
|
239 |
}
|
297 |
}
|
240 |
|
298 |
|
241 |
/**
|
299 |
/**
|
242 |
* Perform minimal validation on the settings form
|
300 |
* Perform minimal validation on the settings form
|
243 |
* @param array $data
|
301 |
* @param array $data
|
Línea 267... |
Línea 325... |
267 |
}
|
325 |
}
|
268 |
if ($data['duedate'] && $data['duedate'] > $data['gradingduedate']) {
|
326 |
if ($data['duedate'] && $data['duedate'] > $data['gradingduedate']) {
|
269 |
$errors['gradingduedate'] = get_string('gradingdueduedatevalidation', 'assign');
|
327 |
$errors['gradingduedate'] = get_string('gradingdueduedatevalidation', 'assign');
|
270 |
}
|
328 |
}
|
271 |
}
|
329 |
}
|
- |
|
330 |
$multipleattemptsallowed = $data['maxattempts'] > 1 || $data['maxattempts'] == ASSIGN_UNLIMITED_ATTEMPTS;
|
- |
|
331 |
if ($data['blindmarking'] && $multipleattemptsallowed &&
|
272 |
if ($data['blindmarking'] && $data['attemptreopenmethod'] == ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS) {
|
332 |
$data['attemptreopenmethod'] == ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS) {
|
273 |
$errors['attemptreopenmethod'] = get_string('reopenuntilpassincompatiblewithblindmarking', 'assign');
|
333 |
$errors['attemptreopenmethod'] = get_string('reopenuntilpassincompatiblewithblindmarking', 'assign');
|
274 |
}
|
334 |
}
|
Línea -... |
Línea 335... |
- |
|
335 |
|
- |
|
336 |
[$assignment] = $this->get_assign();
|
- |
|
337 |
$errors = array_merge($errors, $assignment->plugin_settings_validation($data, $files));
|
275 |
|
338 |
|
276 |
return $errors;
|
339 |
return $errors;
|
Línea 277... |
Línea 340... |
277 |
}
|
340 |
}
|
278 |
|
341 |
|
279 |
/**
|
342 |
/**
|
280 |
* Any data processing needed before the form is displayed
|
343 |
* Any data processing needed before the form is displayed
|
281 |
* (needed to set up draft areas for editor and filemanager elements)
|
344 |
* (needed to set up draft areas for editor and filemanager elements)
|
282 |
* @param array $defaultvalues
|
345 |
* @param array $defaultvalues
|
283 |
*/
|
- |
|
284 |
public function data_preprocessing(&$defaultvalues) {
|
- |
|
285 |
global $DB;
|
- |
|
286 |
|
- |
|
287 |
$ctx = null;
|
- |
|
288 |
if ($this->current && $this->current->coursemodule) {
|
- |
|
289 |
$cm = get_coursemodule_from_instance('assign', $this->current->id, 0, false, MUST_EXIST);
|
- |
|
290 |
$ctx = context_module::instance($cm->id);
|
346 |
*/
|
291 |
}
|
- |
|
292 |
$assignment = new assign($ctx, null, null);
|
- |
|
293 |
if ($this->current && $this->current->course) {
|
- |
|
294 |
if (!$ctx) {
|
- |
|
295 |
$ctx = context_course::instance($this->current->course);
|
- |
|
296 |
}
|
- |
|
297 |
$course = $DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST);
|
- |
|
Línea 298... |
Línea 347... |
298 |
$assignment->set_course($course);
|
347 |
public function data_preprocessing(&$defaultvalues) {
|
299 |
}
|
348 |
[$assignment, $ctx] = $this->get_assign();
|
300 |
|
349 |
|
301 |
$draftitemid = file_get_submitted_draft_itemid('introattachments');
|
350 |
$draftitemid = file_get_submitted_draft_itemid('introattachments');
|
Línea 343... |
Línea 392... |
343 |
public function completion_rule_enabled($data) {
|
392 |
public function completion_rule_enabled($data) {
|
344 |
$suffix = $this->get_suffix();
|
393 |
$suffix = $this->get_suffix();
|
345 |
return !empty($data['completionsubmit' . $suffix]);
|
394 |
return !empty($data['completionsubmit' . $suffix]);
|
346 |
}
|
395 |
}
|
Línea -... |
Línea 396... |
- |
|
396 |
|
- |
|
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];
|
347 |
|
469 |
}
|