Skip to content

Commit

Permalink
"MDL-22659, Thanks Davo Smith's patch on assignment plugin validation…
Browse files Browse the repository at this point in the history
… and preprocess"
  • Loading branch information
Dongsheng Cai committed Jul 19, 2010
1 parent ec2c36f commit 493a82f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
22 changes: 22 additions & 0 deletions mod/assignment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,28 @@ function setup_elements(&$mform) {

}

/**
* 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
*
Expand Down
47 changes: 46 additions & 1 deletion mod/assignment/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require_once ($CFG->dirroot.'/course/moodleform_mod.php');

class mod_assignment_mod_form extends moodleform_mod {
protected $_assignmentinstance = null;

function definition() {
global $CFG, $DB;
Expand All @@ -28,7 +29,7 @@ function definition() {
$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();

Expand Down Expand Up @@ -75,5 +76,49 @@ function definition() {
$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;
}
}

0 comments on commit 493a82f

Please sign in to comment.