"MDL-22659, Thanks Davo Smith's patch on assignment plugin validation and preprocess"

This commit is contained in:
Dongsheng Cai
2010-07-19 16:04:16 +00:00
parent ec2c36f872
commit 493a82f69e
2 changed files with 68 additions and 1 deletions
+22
View File
@@ -383,6 +383,28 @@ class assignment_base {
}
/**
* Any preprocessing needed for the settings form for
* this assignment type
*
* @param array $default_values - array to fill in with the default values
* in the form 'formelement' => 'value'
* @param object $form - the form that is to be displayed
* @return none
*/
function form_data_preprocessing(&$default_values, $form) {
}
/**
* Any extra validation checks needed for the settings
* form for this assignment type
*
* See lib/formslib.php, 'validation' function for details
*/
function form_validation($data, $files) {
return array();
}
/**
* Create a new assignment activity
*
+46 -1
View File
@@ -6,6 +6,7 @@ if (!defined('MOODLE_INTERNAL')) {
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
class mod_assignment_mod_form extends moodleform_mod {
protected $_assignmentinstance = null;
function definition() {
global $CFG, $DB;
@@ -28,7 +29,7 @@ class mod_assignment_mod_form extends moodleform_mod {
$mform->setType('type', PARAM_ALPHA);
$mform->setDefault('type', $type);
require($CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php');
require_once($CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php');
$assignmentclass = 'assignment_'.$type;
$assignmentinstance = new $assignmentclass();
@@ -75,5 +76,49 @@ class mod_assignment_mod_form extends moodleform_mod {
$this->add_action_buttons();
}
// Needed by plugin assignment types if they include a filemanager element in the settings form
function has_instance() {
return ($this->_instance != NULL);
}
// Needed by plugin assignment types if they include a filemanager element in the settings form
function get_context() {
return $this->context;
}
protected function get_assignment_instance() {
global $CFG, $DB;
if ($this->_assignmentinstance) {
return $this->_assignmentinstance;
}
if (!empty($this->_instance)) {
if($ass = $DB->get_record('assignment', array('id'=>$this->_instance))) {
$type = $ass->assignmenttype;
} else {
print_error('invalidassignment', 'assignment');
}
} else {
$type = required_param('type', PARAM_ALPHA);
}
require_once($CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php');
$assignmentclass = 'assignment_'.$type;
$this->assignmentinstance = new $assignmentclass();
return $this->assignmentinstance;
}
function data_preprocessing(&$default_values) {
// Allow plugin assignment types to preprocess form data (needed if they include any filemanager elements)
$this->get_assignment_instance()->form_data_preprocessing($default_values, $this);
}
function validataion($data, $files) {
// Allow plugin assignment types to do any extra validation after the form has been submitted
$errors = parent::validation($data, $files);
$errors = array_merge($errors, $this->get_assignment_instance()->form_validation($data, $files));
return $errors;
}
}