MDL-27094 fix incorrect assignment form validation method name
[moodle.git] / mod / assignment / mod_form.php
CommitLineData
436cfa9f 1<?php
bfebaf64
MD
2if (!defined('MOODLE_INTERNAL')) {
3 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
4}
5
23a7718b 6require_once ($CFG->dirroot.'/course/moodleform_mod.php');
436cfa9f 7
8class mod_assignment_mod_form extends moodleform_mod {
493a82f6 9 protected $_assignmentinstance = null;
436cfa9f 10
11 function definition() {
c18269c7 12 global $CFG, $DB;
436cfa9f 13 $mform =& $this->_form;
14
15 // this hack is needed for different settings of each subtype
16 if (!empty($this->_instance)) {
0b18169e 17 if($ass = $DB->get_record('assignment', array('id'=>$this->_instance))) {
436cfa9f 18 $type = $ass->assignmenttype;
19 } else {
a939f681 20 print_error('invalidassignment', 'assignment');
436cfa9f 21 }
22 } else {
23 $type = required_param('type', PARAM_ALPHA);
24 }
25 $mform->addElement('hidden', 'assignmenttype', $type);
d18e0fe6 26 $mform->setType('assignmenttype', PARAM_ALPHA);
436cfa9f 27 $mform->setDefault('assignmenttype', $type);
28 $mform->addElement('hidden', 'type', $type);
d18e0fe6 29 $mform->setType('type', PARAM_ALPHA);
436cfa9f 30 $mform->setDefault('type', $type);
31
493a82f6 32 require_once($CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php');
436cfa9f 33 $assignmentclass = 'assignment_'.$type;
34 $assignmentinstance = new $assignmentclass();
35
36//-------------------------------------------------------------------------------
37 $mform->addElement('header', 'general', get_string('general', 'form'));
38
39// $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment'));
40
26de8d35 41 $mform->addElement('text', 'name', get_string('assignmentname', 'assignment'), array('size'=>'64'));
8eb1d25f 42 if (!empty($CFG->formatstringstriptags)) {
43 $mform->setType('name', PARAM_TEXT);
44 } else {
b8ea3041 45 $mform->setType('name', PARAM_CLEANHTML);
8eb1d25f 46 }
436cfa9f 47 $mform->addRule('name', null, 'required', null, 'client');
48
dc5c2bd9 49 $this->add_intro_editor(true, get_string('description', 'assignment'));
436cfa9f 50
436cfa9f 51 $mform->addElement('date_time_selector', 'timeavailable', get_string('availabledate', 'assignment'), array('optional'=>true));
52 $mform->setDefault('timeavailable', time());
53 $mform->addElement('date_time_selector', 'timedue', get_string('duedate', 'assignment'), array('optional'=>true));
54 $mform->setDefault('timedue', time()+7*24*3600);
55
56 $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
57
58 $mform->addElement('select', 'preventlate', get_string('preventlate', 'assignment'), $ynoptions);
59 $mform->setDefault('preventlate', 0);
60
40fcf70c 61 // hack to support pluggable assignment type titles
5ddf75d8
AB
62 if (get_string_manager()->string_exists('type'.$type, 'assignment')) {
63 $typetitle = get_string('type'.$type, 'assignment');
64 } else {
40fcf70c 65 $typetitle = get_string('type'.$type, 'assignment_'.$type);
e7521559 66 }
40fcf70c 67
16306628
AD
68 $this->standard_grading_coursemodule_elements();
69
40fcf70c
DP
70 $mform->addElement('header', 'typedesc', $typetitle);
71
436cfa9f 72 $assignmentinstance->setup_elements($mform);
73
42f103be 74 $this->standard_coursemodule_elements();
436cfa9f 75
76 $this->add_action_buttons();
77 }
78
493a82f6
DC
79 // Needed by plugin assignment types if they include a filemanager element in the settings form
80 function has_instance() {
81 return ($this->_instance != NULL);
82 }
83
84 // Needed by plugin assignment types if they include a filemanager element in the settings form
85 function get_context() {
86 return $this->context;
87 }
88
89 protected function get_assignment_instance() {
90 global $CFG, $DB;
91
92 if ($this->_assignmentinstance) {
93 return $this->_assignmentinstance;
94 }
95 if (!empty($this->_instance)) {
96 if($ass = $DB->get_record('assignment', array('id'=>$this->_instance))) {
97 $type = $ass->assignmenttype;
98 } else {
99 print_error('invalidassignment', 'assignment');
100 }
101 } else {
102 $type = required_param('type', PARAM_ALPHA);
103 }
104 require_once($CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php');
105 $assignmentclass = 'assignment_'.$type;
106 $this->assignmentinstance = new $assignmentclass();
107 return $this->assignmentinstance;
108 }
109
110
111 function data_preprocessing(&$default_values) {
112 // Allow plugin assignment types to preprocess form data (needed if they include any filemanager elements)
113 $this->get_assignment_instance()->form_data_preprocessing($default_values, $this);
114 }
115
116
aa25e42b 117 function validation($data, $files) {
493a82f6
DC
118 // Allow plugin assignment types to do any extra validation after the form has been submitted
119 $errors = parent::validation($data, $files);
120 $errors = array_merge($errors, $this->get_assignment_instance()->form_validation($data, $files));
121 return $errors;
122 }
436cfa9f 123}
42f103be 124