MDL-65835 plagiarism: Initial deprecation of old functions.
[moodle.git] / mod / workshop / mod_form.php
CommitLineData
4eab2e7f 1<?php
53fad4b9
DM
2// This file is part of Moodle - http://moodle.org/
3//
4eab2e7f
DM
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.
53fad4b9 13//
4eab2e7f
DM
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/>.
53fad4b9 16
4eab2e7f
DM
17/**
18 * The main workshop configuration form
19 *
20 * The UI mockup has been proposed in MDL-18688
53fad4b9 21 * It uses the standard core Moodle formslib. For more info about them, please
728ebac7 22 * visit: http://docs.moodle.org/dev/lib/formslib.php
4eab2e7f 23 *
5cdcfcb9 24 * @package mod_workshop
65601f04
DM
25 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4eab2e7f
DM
27 */
28
6867e05d
DM
29defined('MOODLE_INTERNAL') || die();
30
6516b9e9 31require_once($CFG->dirroot . '/course/moodleform_mod.php');
1fcf0ca8 32require_once(__DIR__ . '/locallib.php');
6516b9e9 33require_once($CFG->libdir . '/filelib.php');
4eab2e7f 34
a74cadfa
DM
35/**
36 * Module settings form for Workshop instances
37 */
4eab2e7f
DM
38class mod_workshop_mod_form extends moodleform_mod {
39
a74cadfa
DM
40 /** @var object the course this instance is part of */
41 protected $course = null;
42
43 /**
44 * Constructor
45 */
46 public function __construct($current, $section, $cm, $course) {
47 $this->course = $course;
48 parent::__construct($current, $section, $cm, $course);
49 }
50
6516b9e9
DM
51 /**
52 * Defines the workshop instance configuration form
53 *
54 * @return void
55 */
a74cadfa 56 public function definition() {
7d2ad716 57 global $CFG, $PAGE;
4eab2e7f 58
4eab2e7f 59 $workshopconfig = get_config('workshop');
74e28b26 60 $mform = $this->_form;
4eab2e7f 61
6516b9e9 62 // General --------------------------------------------------------------------
4eab2e7f
DM
63 $mform->addElement('header', 'general', get_string('general', 'form'));
64
6516b9e9 65 // Workshop name
4eab2e7f 66 $label = get_string('workshopname', 'workshop');
1a282212 67 $mform->addElement('text', 'name', $label, array('size' => '64'));
4eab2e7f
DM
68 if (!empty($CFG->formatstringstriptags)) {
69 $mform->setType('name', PARAM_TEXT);
70 } else {
b8ea3041 71 $mform->setType('name', PARAM_CLEANHTML);
4eab2e7f
DM
72 }
73 $mform->addRule('name', null, 'required', null, 'client');
74 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
4eab2e7f 75
6516b9e9 76 // Introduction
6398ff53 77 $this->standard_intro_elements(get_string('introduction', 'workshop'));
4eab2e7f 78
6516b9e9 79 // Grading settings -----------------------------------------------------------
4eab2e7f 80 $mform->addElement('header', 'gradingsettings', get_string('gradingsettings', 'workshop'));
9e31e23d
DM
81 $mform->setExpanded('gradingsettings');
82
83 $label = get_string('strategy', 'workshop');
84 $mform->addElement('select', 'strategy', $label, workshop::available_strategies_list());
85 $mform->setDefault('strategy', $workshopconfig->strategy);
86 $mform->addHelpButton('strategy', 'strategy', 'workshop');
4eab2e7f 87
f6e8b318 88 $grades = workshop::available_maxgrades_list();
a74cadfa 89 $gradecategories = grade_get_categories_menu($this->course->id);
4eab2e7f 90
b4857acb 91 $label = get_string('submissiongrade', 'workshop');
a74cadfa
DM
92 $mform->addGroup(array(
93 $mform->createElement('select', 'grade', '', $grades),
94 $mform->createElement('select', 'gradecategory', '', $gradecategories),
95 ), 'submissiongradegroup', $label, ' ', false);
4eab2e7f 96 $mform->setDefault('grade', $workshopconfig->grade);
a74cadfa 97 $mform->addHelpButton('submissiongradegroup', 'submissiongrade', 'workshop');
4eab2e7f 98
8164fad4
GF
99 $mform->addElement('text', 'submissiongradepass', get_string('gradetopasssubmission', 'workshop'));
100 $mform->addHelpButton('submissiongradepass', 'gradepass', 'grades');
101 $mform->setDefault('submissiongradepass', '');
f747f5a0 102 $mform->setType('submissiongradepass', PARAM_RAW);
8164fad4 103
b4857acb 104 $label = get_string('gradinggrade', 'workshop');
a74cadfa
DM
105 $mform->addGroup(array(
106 $mform->createElement('select', 'gradinggrade', '', $grades),
107 $mform->createElement('select', 'gradinggradecategory', '', $gradecategories),
108 ), 'gradinggradegroup', $label, ' ', false);
4eab2e7f 109 $mform->setDefault('gradinggrade', $workshopconfig->gradinggrade);
a74cadfa 110 $mform->addHelpButton('gradinggradegroup', 'gradinggrade', 'workshop');
4eab2e7f 111
8164fad4
GF
112 $mform->addElement('text', 'gradinggradepass', get_string('gradetopassgrading', 'workshop'));
113 $mform->addHelpButton('gradinggradepass', 'gradepass', 'grades');
114 $mform->setDefault('gradinggradepass', '');
f747f5a0 115 $mform->setType('gradinggradepass', PARAM_RAW);
8164fad4 116
b4857acb 117 $options = array();
1a282212 118 for ($i = 5; $i >= 0; $i--) {
b4857acb
DM
119 $options[$i] = $i;
120 }
121 $label = get_string('gradedecimals', 'workshop');
122 $mform->addElement('select', 'gradedecimals', $label, $options);
b4857acb
DM
123 $mform->setDefault('gradedecimals', $workshopconfig->gradedecimals);
124
6516b9e9 125 // Submission settings --------------------------------------------------------
4eab2e7f
DM
126 $mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'workshop'));
127
6516b9e9
DM
128 $label = get_string('instructauthors', 'workshop');
129 $mform->addElement('editor', 'instructauthorseditor', $label, null,
130 workshop::instruction_editors_options($this->context));
131
7d2ad716
MJ
132 $typeelements = [];
133 foreach (['submissiontypetext', 'submissiontypefile'] as $type) {
134 $available = $type . 'available';
135 $required = $type . 'required';
136 $availablelabel = get_string($available, 'workshop');
137 $requiredlabel = get_string($required, 'workshop');
138 $typeelements[] = $mform->createElement('advcheckbox', $available, '', $availablelabel);
139 $typeelements[] = $mform->createElement('advcheckbox', $required, '', $requiredlabel);
140 $mform->setDefault($available, 1);
141 }
142 // We can't use <br> as the separator as it does not work well in this case with the Boost theme.
143 // Instead, separate both tuples with a full-width empty div.
144 $mform->addGroup($typeelements, 'submissiontypes', get_string('submissiontypes', 'workshop'),
145 array(' ', '<div style="width:100%"></div>'), false);
146
4eab2e7f 147 $options = array();
7d2ad716 148 for ($i = 7; $i >= 1; $i--) {
4eab2e7f
DM
149 $options[$i] = $i;
150 }
151 $label = get_string('nattachments', 'workshop');
152 $mform->addElement('select', 'nattachments', $label, $options);
153 $mform->setDefault('nattachments', 1);
385247d9 154 $mform->hideIf('nattachments', 'submissiontypefileavailable');
6405b254 155
1a282212 156 $label = get_string('allowedfiletypesforsubmission', 'workshop');
f9a8d980 157 $mform->addElement('filetypes', 'submissionfiletypes', $label);
1a282212 158 $mform->addHelpButton('submissionfiletypes', 'allowedfiletypesforsubmission', 'workshop');
385247d9 159 $mform->hideIf('submissionfiletypes', 'submissiontypefileavailable');
1a282212 160
367b977d 161 $options = get_max_upload_sizes($CFG->maxbytes, $this->course->maxbytes, 0, $workshopconfig->maxbytes);
e2a81c66 162 $mform->addElement('select', 'maxbytes', get_string('maxbytes', 'workshop'), $options);
4eab2e7f 163 $mform->setDefault('maxbytes', $workshopconfig->maxbytes);
385247d9 164 $mform->hideIf('maxbytes', 'submissiontypefileavailable');
4eab2e7f 165
f6e8b318 166 $label = get_string('latesubmissions', 'workshop');
e2a81c66 167 $text = get_string('latesubmissions_desc', 'workshop');
0d0b7d99 168 $mform->addElement('checkbox', 'latesubmissions', $label, $text);
e2a81c66 169 $mform->addHelpButton('latesubmissions', 'latesubmissions', 'workshop');
f6e8b318 170
6516b9e9 171 // Assessment settings --------------------------------------------------------
4eab2e7f
DM
172 $mform->addElement('header', 'assessmentsettings', get_string('assessmentsettings', 'workshop'));
173
15d12b54
DM
174 $label = get_string('instructreviewers', 'workshop');
175 $mform->addElement('editor', 'instructreviewerseditor', $label, null,
176 workshop::instruction_editors_options($this->context));
6516b9e9 177
9e31e23d
DM
178 $label = get_string('useselfassessment', 'workshop');
179 $text = get_string('useselfassessment_desc', 'workshop');
180 $mform->addElement('checkbox', 'useselfassessment', $label, $text);
181 $mform->addHelpButton('useselfassessment', 'useselfassessment', 'workshop');
182
183 // Feedback -------------------------------------------------------------------
184 $mform->addElement('header', 'feedbacksettings', get_string('feedbacksettings', 'workshop'));
185
1c6b484d
DM
186 $mform->addElement('select', 'overallfeedbackmode', get_string('overallfeedbackmode', 'mod_workshop'), array(
187 0 => get_string('overallfeedbackmode_0', 'mod_workshop'),
188 1 => get_string('overallfeedbackmode_1', 'mod_workshop'),
189 2 => get_string('overallfeedbackmode_2', 'mod_workshop')));
190 $mform->addHelpButton('overallfeedbackmode', 'overallfeedbackmode', 'mod_workshop');
191 $mform->setDefault('overallfeedbackmode', 1);
1c6b484d
DM
192
193 $options = array();
194 for ($i = 7; $i >= 0; $i--) {
195 $options[$i] = $i;
196 }
197 $mform->addElement('select', 'overallfeedbackfiles', get_string('overallfeedbackfiles', 'workshop'), $options);
198 $mform->setDefault('overallfeedbackfiles', 0);
385247d9 199 $mform->hideIf('overallfeedbackfiles', 'overallfeedbackmode', 'eq', 0);
1c6b484d 200
1a282212 201 $label = get_string('allowedfiletypesforoverallfeedback', 'workshop');
f9a8d980 202 $mform->addElement('filetypes', 'overallfeedbackfiletypes', $label);
1a282212 203 $mform->addHelpButton('overallfeedbackfiletypes', 'allowedfiletypesforoverallfeedback', 'workshop');
385247d9 204 $mform->hideIf('overallfeedbackfiletypes', 'overallfeedbackfiles', 'eq', 0);
1a282212 205
1c6b484d
DM
206 $options = get_max_upload_sizes($CFG->maxbytes, $this->course->maxbytes);
207 $mform->addElement('select', 'overallfeedbackmaxbytes', get_string('overallfeedbackmaxbytes', 'workshop'), $options);
1c6b484d 208 $mform->setDefault('overallfeedbackmaxbytes', $workshopconfig->maxbytes);
385247d9
DS
209 $mform->hideIf('overallfeedbackmaxbytes', 'overallfeedbackmode', 'eq', 0);
210 $mform->hideIf('overallfeedbackmaxbytes', 'overallfeedbackfiles', 'eq', 0);
1c6b484d 211
9e31e23d
DM
212 $label = get_string('conclusion', 'workshop');
213 $mform->addElement('editor', 'conclusioneditor', $label, null,
214 workshop::instruction_editors_options($this->context));
215 $mform->addHelpButton('conclusioneditor', 'conclusion', 'workshop');
216
217 // Example submissions --------------------------------------------------------
218 $mform->addElement('header', 'examplesubmissionssettings', get_string('examplesubmissions', 'workshop'));
219
220 $label = get_string('useexamples', 'workshop');
221 $text = get_string('useexamples_desc', 'workshop');
222 $mform->addElement('checkbox', 'useexamples', $label, $text);
223 $mform->addHelpButton('useexamples', 'useexamples', 'workshop');
224
4eab2e7f 225 $label = get_string('examplesmode', 'workshop');
f6e8b318 226 $options = workshop::available_example_modes_list();
4eab2e7f
DM
227 $mform->addElement('select', 'examplesmode', $label, $options);
228 $mform->setDefault('examplesmode', $workshopconfig->examplesmode);
385247d9 229 $mform->hideIf('examplesmode', 'useexamples');
5a49f825 230
9e31e23d
DM
231 // Availability ---------------------------------------------------------------
232 $mform->addElement('header', 'accesscontrol', get_string('availability', 'core'));
4eab2e7f
DM
233
234 $label = get_string('submissionstart', 'workshop');
de2f199b 235 $mform->addElement('date_time_selector', 'submissionstart', $label, array('optional' => true));
4eab2e7f
DM
236
237 $label = get_string('submissionend', 'workshop');
de2f199b 238 $mform->addElement('date_time_selector', 'submissionend', $label, array('optional' => true));
4eab2e7f 239
3ff08057
DM
240 $label = get_string('submissionendswitch', 'mod_workshop');
241 $mform->addElement('checkbox', 'phaseswitchassessment', $label);
385247d9 242 $mform->hideIf('phaseswitchassessment', 'submissionend[enabled]');
3ff08057
DM
243 $mform->addHelpButton('phaseswitchassessment', 'submissionendswitch', 'mod_workshop');
244
4eab2e7f 245 $label = get_string('assessmentstart', 'workshop');
de2f199b 246 $mform->addElement('date_time_selector', 'assessmentstart', $label, array('optional' => true));
4eab2e7f
DM
247
248 $label = get_string('assessmentend', 'workshop');
de2f199b 249 $mform->addElement('date_time_selector', 'assessmentend', $label, array('optional' => true));
4eab2e7f 250
67ba9007 251 $coursecontext = context_course::instance($this->course->id);
d0d65b49 252 // To be removed (deprecated) with MDL-67526.
67fbfe8b 253 plagiarism_get_form_elements_module($mform, $coursecontext, 'mod_workshop');
67ba9007 254
5924db72 255 // Common module settings, Restrict availability, Activity completion etc. ----
45ab2d9a 256 $features = array('groups' => true, 'groupings' => true,
1a282212 257 'outcomes' => true, 'gradecat' => false, 'idnumber' => false);
53fad4b9 258
4eab2e7f
DM
259 $this->standard_coursemodule_elements();
260
6516b9e9 261 // Standard buttons, common to all modules ------------------------------------
4eab2e7f 262 $this->add_action_buttons();
7d2ad716
MJ
263
264 $PAGE->requires->js_call_amd('mod_workshop/modform', 'init');
6516b9e9 265 }
4eab2e7f 266
6516b9e9
DM
267 /**
268 * Prepares the form before data are set
269 *
a74cadfa
DM
270 * Additional wysiwyg editor are prepared here, the introeditor is prepared automatically by core.
271 * Grade items are set here because the core modedit supports single grade item only.
6516b9e9
DM
272 *
273 * @param array $data to be set
274 * @return void
275 */
a74cadfa 276 public function data_preprocessing(&$data) {
6516b9e9
DM
277 if ($this->current->instance) {
278 // editing an existing workshop - let us prepare the added editor elements (intro done automatically)
279 $draftitemid = file_get_submitted_draft_itemid('instructauthors');
280 $data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
6a0d85aa 281 'mod_workshop', 'instructauthors', 0,
6516b9e9
DM
282 workshop::instruction_editors_options($this->context),
283 $data['instructauthors']);
284 $data['instructauthorseditor']['format'] = $data['instructauthorsformat'];
285 $data['instructauthorseditor']['itemid'] = $draftitemid;
15d12b54
DM
286
287 $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
288 $data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
6a0d85aa 289 'mod_workshop', 'instructreviewers', 0,
15d12b54
DM
290 workshop::instruction_editors_options($this->context),
291 $data['instructreviewers']);
292 $data['instructreviewerseditor']['format'] = $data['instructreviewersformat'];
293 $data['instructreviewerseditor']['itemid'] = $draftitemid;
5a49f825
DM
294
295 $draftitemid = file_get_submitted_draft_itemid('conclusion');
296 $data['conclusioneditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
297 'mod_workshop', 'conclusion', 0,
298 workshop::instruction_editors_options($this->context),
299 $data['conclusion']);
300 $data['conclusioneditor']['format'] = $data['conclusionformat'];
301 $data['conclusioneditor']['itemid'] = $draftitemid;
7d2ad716
MJ
302 // Set submission type checkboxes.
303 foreach (['submissiontypetext', 'submissiontypefile'] as $type) {
304 $data[$type . 'available'] = 1;
305 $data[$type . 'required'] = 0;
306 if ($data[$type] == WORKSHOP_SUBMISSION_TYPE_DISABLED) {
307 $data[$type . 'available'] = 0;
308 } else if ($data[$type] == WORKSHOP_SUBMISSION_TYPE_REQUIRED) {
309 $data[$type . 'required'] = 1;
310 }
311 }
6516b9e9
DM
312 } else {
313 // adding a new workshop instance
314 $draftitemid = file_get_submitted_draft_itemid('instructauthors');
6a0d85aa 315 file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructauthors', 0); // no context yet, itemid not used
884482fb 316 $data['instructauthorseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
15d12b54
DM
317
318 $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
6a0d85aa 319 file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructreviewers', 0); // no context yet, itemid not used
884482fb 320 $data['instructreviewerseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
5a49f825
DM
321
322 $draftitemid = file_get_submitted_draft_itemid('conclusion');
323 file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'conclusion', 0); // no context yet, itemid not used
324 $data['conclusioneditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
6516b9e9 325 }
4eab2e7f 326 }
a74cadfa 327
7d2ad716
MJ
328 /**
329 * Combine submission type checkboxes into integer values for the database.
330 *
331 * @param stdClass $data The submitted form data.
332 */
333 public function data_postprocessing($data) {
334 parent::data_postprocessing($data);
335
336 foreach (['text', 'file'] as $type) {
337 $field = 'submissiontype' . $type;
338 $available = $field . 'available';
339 $required = $field . 'required';
340 if ($data->$required) {
341 $data->$field = WORKSHOP_SUBMISSION_TYPE_REQUIRED;
342 } else if ($data->$available) {
343 $data->$field = WORKSHOP_SUBMISSION_TYPE_AVAILABLE;
344 } else {
345 $data->$field = WORKSHOP_SUBMISSION_TYPE_DISABLED;
346 }
347 unset($data->$available);
348 unset($data->$required);
349 }
350 }
351
a74cadfa
DM
352 /**
353 * Set the grade item categories when editing an instance
354 */
355 public function definition_after_data() {
356
357 $mform =& $this->_form;
358
359 if ($id = $mform->getElementValue('update')) {
360 $instance = $mform->getElementValue('instance');
361
362 $gradeitems = grade_item::fetch_all(array(
363 'itemtype' => 'mod',
364 'itemmodule' => 'workshop',
365 'iteminstance' => $instance,
366 'courseid' => $this->course->id));
367
368 if (!empty($gradeitems)) {
369 foreach ($gradeitems as $gradeitem) {
370 // here comes really crappy way how to set the value of the fields
371 // gradecategory and gradinggradecategory - grrr QuickForms
8164fad4 372 $decimalpoints = $gradeitem->get_decimals();
a74cadfa 373 if ($gradeitem->itemnumber == 0) {
395bca32 374 $mform->setDefault('submissiongradepass', format_float($gradeitem->gradepass, $decimalpoints));
a74cadfa
DM
375 $group = $mform->getElement('submissiongradegroup');
376 $elements = $group->getElements();
377 foreach ($elements as $element) {
378 if ($element->getName() == 'gradecategory') {
379 $element->setValue($gradeitem->categoryid);
380 }
381 }
382 } else if ($gradeitem->itemnumber == 1) {
395bca32 383 $mform->setDefault('gradinggradepass', format_float($gradeitem->gradepass, $decimalpoints));
a74cadfa
DM
384 $group = $mform->getElement('gradinggradegroup');
385 $elements = $group->getElements();
386 foreach ($elements as $element) {
387 if ($element->getName() == 'gradinggradecategory') {
388 $element->setValue($gradeitem->categoryid);
389 }
390 }
391 }
392 }
393 }
394 }
7d2ad716
MJ
395 $typevalues = $mform->getElementValue('submissiontypes');
396 foreach (['submissiontypetext', 'submissiontypefile'] as $type) {
397 // Don't leave a disabled "required" checkbox checked.
398 if (!$typevalues[$type . 'available']) {
399 $mform->setDefault($type . 'required', 0);
400 }
401 }
a74cadfa
DM
402
403 parent::definition_after_data();
404 }
df558765
DM
405
406 /**
407 * Validates the form input
408 *
409 * @param array $data submitted data
410 * @param array $files submitted files
411 * @return array eventual errors indexed by the field name
412 */
2fc04a4b 413 public function validation($data, $files) {
90faa6ae 414 $errors = parent::validation($data, $files);
df558765
DM
415
416 // check the phases borders are valid
417 if ($data['submissionstart'] > 0 and $data['submissionend'] > 0 and $data['submissionstart'] >= $data['submissionend']) {
418 $errors['submissionend'] = get_string('submissionendbeforestart', 'mod_workshop');
419 }
420 if ($data['assessmentstart'] > 0 and $data['assessmentend'] > 0 and $data['assessmentstart'] >= $data['assessmentend']) {
421 $errors['assessmentend'] = get_string('assessmentendbeforestart', 'mod_workshop');
422 }
423
424 // check the phases do not overlap
425 if (max($data['submissionstart'], $data['submissionend']) > 0 and max($data['assessmentstart'], $data['assessmentend']) > 0) {
426 $phasesubmissionend = max($data['submissionstart'], $data['submissionend']);
427 $phaseassessmentstart = min($data['assessmentstart'], $data['assessmentend']);
428 if ($phaseassessmentstart == 0) {
429 $phaseassessmentstart = max($data['assessmentstart'], $data['assessmentend']);
430 }
431 if ($phasesubmissionend > 0 and $phaseassessmentstart > 0 and $phaseassessmentstart < $phasesubmissionend) {
432 foreach (array('submissionend', 'submissionstart', 'assessmentstart', 'assessmentend') as $f) {
433 if ($data[$f] > 0) {
434 $errors[$f] = get_string('phasesoverlap', 'mod_workshop');
435 break;
436 }
437 }
438 }
439 }
440
f747f5a0 441 // Check that the submission grade pass is a valid number.
ebf0598e 442 if (!empty($data['submissiongradepass'])) {
f747f5a0 443 $submissiongradefloat = unformat_float($data['submissiongradepass'], true);
ebf0598e 444 if ($submissiongradefloat === false) {
f747f5a0
JD
445 $errors['submissiongradepass'] = get_string('err_numeric', 'form');
446 } else {
447 if ($submissiongradefloat > $data['grade']) {
448 $errors['submissiongradepass'] = get_string('gradepassgreaterthangrade', 'grades', $data['grade']);
449 }
450 }
8164fad4 451 }
f747f5a0
JD
452
453 // Check that the grade pass is a valid number.
ebf0598e 454 if (!empty($data['gradinggradepass'])) {
f747f5a0 455 $gradepassfloat = unformat_float($data['gradinggradepass'], true);
ebf0598e 456 if ($gradepassfloat === false) {
f747f5a0
JD
457 $errors['gradinggradepass'] = get_string('err_numeric', 'form');
458 } else {
459 if ($gradepassfloat > $data['gradinggrade']) {
460 $errors['gradinggradepass'] = get_string('gradepassgreaterthangrade', 'grades', $data['gradinggrade']);
461 }
462 }
8164fad4
GF
463 }
464
7d2ad716
MJ
465 if (!$data['submissiontypetextavailable'] && !$data['submissiontypefileavailable']) {
466 // One submission type must be available.
467 $errors['submissiontypes'] = get_string('nosubmissiontype', 'workshop');
468 }
469
df558765
DM
470 return $errors;
471 }
4eab2e7f 472}