|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 if (!defined('MOODLE_INTERNAL')) { 00003 die('Direct access to this script is forbidden.'); 00004 } 00005 00006 require_once ($CFG->dirroot.'/course/moodleform_mod.php'); 00007 00008 class mod_assignment_mod_form extends moodleform_mod { 00009 protected $_assignmentinstance = null; 00010 00011 function definition() { 00012 global $CFG, $DB; 00013 $mform =& $this->_form; 00014 00015 // this hack is needed for different settings of each subtype 00016 if (!empty($this->_instance)) { 00017 if($ass = $DB->get_record('assignment', array('id'=>$this->_instance))) { 00018 $type = $ass->assignmenttype; 00019 } else { 00020 print_error('invalidassignment', 'assignment'); 00021 } 00022 } else { 00023 $type = required_param('type', PARAM_ALPHA); 00024 } 00025 $mform->addElement('hidden', 'assignmenttype', $type); 00026 $mform->setType('assignmenttype', PARAM_ALPHA); 00027 $mform->setDefault('assignmenttype', $type); 00028 $mform->addElement('hidden', 'type', $type); 00029 $mform->setType('type', PARAM_ALPHA); 00030 $mform->setDefault('type', $type); 00031 00032 require_once($CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php'); 00033 $assignmentclass = 'assignment_'.$type; 00034 $assignmentinstance = new $assignmentclass(); 00035 00036 //------------------------------------------------------------------------------- 00037 $mform->addElement('header', 'general', get_string('general', 'form')); 00038 00039 // $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment')); 00040 00041 $mform->addElement('text', 'name', get_string('assignmentname', 'assignment'), array('size'=>'64')); 00042 if (!empty($CFG->formatstringstriptags)) { 00043 $mform->setType('name', PARAM_TEXT); 00044 } else { 00045 $mform->setType('name', PARAM_CLEANHTML); 00046 } 00047 $mform->addRule('name', null, 'required', null, 'client'); 00048 00049 $this->add_intro_editor(true, get_string('description', 'assignment')); 00050 00051 $mform->addElement('date_time_selector', 'timeavailable', get_string('availabledate', 'assignment'), array('optional'=>true)); 00052 $mform->setDefault('timeavailable', time()); 00053 $mform->addElement('date_time_selector', 'timedue', get_string('duedate', 'assignment'), array('optional'=>true)); 00054 $mform->setDefault('timedue', time()+7*24*3600); 00055 00056 $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes')); 00057 00058 $mform->addElement('select', 'preventlate', get_string('preventlate', 'assignment'), $ynoptions); 00059 $mform->setDefault('preventlate', 0); 00060 00061 // hack to support pluggable assignment type titles 00062 if (get_string_manager()->string_exists('type'.$type, 'assignment')) { 00063 $typetitle = get_string('type'.$type, 'assignment'); 00064 } else { 00065 $typetitle = get_string('type'.$type, 'assignment_'.$type); 00066 } 00067 00068 $this->standard_grading_coursemodule_elements(); 00069 00070 $mform->addElement('header', 'typedesc', $typetitle); 00071 00072 $assignmentinstance->setup_elements($mform); 00073 00074 $this->standard_coursemodule_elements(); 00075 00076 $this->add_action_buttons(); 00077 } 00078 00079 // Needed by plugin assignment types if they include a filemanager element in the settings form 00080 function has_instance() { 00081 return ($this->_instance != NULL); 00082 } 00083 00084 // Needed by plugin assignment types if they include a filemanager element in the settings form 00085 function get_context() { 00086 return $this->context; 00087 } 00088 00089 protected function get_assignment_instance() { 00090 global $CFG, $DB; 00091 00092 if ($this->_assignmentinstance) { 00093 return $this->_assignmentinstance; 00094 } 00095 if (!empty($this->_instance)) { 00096 if($ass = $DB->get_record('assignment', array('id'=>$this->_instance))) { 00097 $type = $ass->assignmenttype; 00098 } else { 00099 print_error('invalidassignment', 'assignment'); 00100 } 00101 } else { 00102 $type = required_param('type', PARAM_ALPHA); 00103 } 00104 require_once($CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php'); 00105 $assignmentclass = 'assignment_'.$type; 00106 $this->assignmentinstance = new $assignmentclass(); 00107 return $this->assignmentinstance; 00108 } 00109 00110 00111 function data_preprocessing(&$default_values) { 00112 // Allow plugin assignment types to preprocess form data (needed if they include any filemanager elements) 00113 $this->get_assignment_instance()->form_data_preprocessing($default_values, $this); 00114 } 00115 00116 00117 function validation($data, $files) { 00118 // Allow plugin assignment types to do any extra validation after the form has been submitted 00119 $errors = parent::validation($data, $files); 00120 $errors = array_merge($errors, $this->get_assignment_instance()->form_validation($data, $files)); 00121 return $errors; 00122 } 00123 } 00124