2007-01-10 13:38:04 +00:00
|
|
|
<?php
|
2010-05-13 02:02:05 +00:00
|
|
|
if (!defined('MOODLE_INTERNAL')) {
|
|
|
|
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
|
|
|
}
|
|
|
|
|
2007-06-10 23:20:45 +00:00
|
|
|
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
|
2007-01-10 13:38:04 +00:00
|
|
|
|
|
|
|
class mod_assignment_mod_form extends moodleform_mod {
|
2010-07-19 16:04:16 +00:00
|
|
|
protected $_assignmentinstance = null;
|
2007-01-10 13:38:04 +00:00
|
|
|
|
|
|
|
function definition() {
|
2008-06-01 21:36:11 +00:00
|
|
|
global $CFG, $DB;
|
2007-01-10 13:38:04 +00:00
|
|
|
$mform =& $this->_form;
|
|
|
|
|
|
|
|
// this hack is needed for different settings of each subtype
|
|
|
|
if (!empty($this->_instance)) {
|
2008-06-03 15:06:53 +00:00
|
|
|
if($ass = $DB->get_record('assignment', array('id'=>$this->_instance))) {
|
2007-01-10 13:38:04 +00:00
|
|
|
$type = $ass->assignmenttype;
|
|
|
|
} else {
|
2008-05-22 07:20:45 +00:00
|
|
|
print_error('invalidassignment', 'assignment');
|
2007-01-10 13:38:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$type = required_param('type', PARAM_ALPHA);
|
|
|
|
}
|
|
|
|
$mform->addElement('hidden', 'assignmenttype', $type);
|
2009-09-26 17:07:08 +00:00
|
|
|
$mform->setType('assignmenttype', PARAM_ALPHA);
|
2007-01-10 13:38:04 +00:00
|
|
|
$mform->setDefault('assignmenttype', $type);
|
|
|
|
$mform->addElement('hidden', 'type', $type);
|
2009-09-26 17:07:08 +00:00
|
|
|
$mform->setType('type', PARAM_ALPHA);
|
2007-01-10 13:38:04 +00:00
|
|
|
$mform->setDefault('type', $type);
|
|
|
|
|
2010-07-19 16:04:16 +00:00
|
|
|
require_once($CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php');
|
2007-01-10 13:38:04 +00:00
|
|
|
$assignmentclass = 'assignment_'.$type;
|
|
|
|
$assignmentinstance = new $assignmentclass();
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
$mform->addElement('header', 'general', get_string('general', 'form'));
|
|
|
|
|
|
|
|
// $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment'));
|
|
|
|
|
2007-01-11 19:47:08 +00:00
|
|
|
$mform->addElement('text', 'name', get_string('assignmentname', 'assignment'), array('size'=>'64'));
|
2008-07-26 15:15:25 +00:00
|
|
|
if (!empty($CFG->formatstringstriptags)) {
|
|
|
|
$mform->setType('name', PARAM_TEXT);
|
|
|
|
} else {
|
2010-09-02 18:29:39 +00:00
|
|
|
$mform->setType('name', PARAM_CLEANHTML);
|
2008-07-26 15:15:25 +00:00
|
|
|
}
|
2007-01-10 13:38:04 +00:00
|
|
|
$mform->addRule('name', null, 'required', null, 'client');
|
|
|
|
|
2009-04-21 21:17:21 +00:00
|
|
|
$this->add_intro_editor(true, get_string('description', 'assignment'));
|
2007-01-10 13:38:04 +00:00
|
|
|
|
|
|
|
$mform->addElement('date_time_selector', 'timeavailable', get_string('availabledate', 'assignment'), array('optional'=>true));
|
|
|
|
$mform->setDefault('timeavailable', time());
|
|
|
|
$mform->addElement('date_time_selector', 'timedue', get_string('duedate', 'assignment'), array('optional'=>true));
|
|
|
|
$mform->setDefault('timedue', time()+7*24*3600);
|
|
|
|
|
|
|
|
$ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
|
|
|
|
|
|
|
|
$mform->addElement('select', 'preventlate', get_string('preventlate', 'assignment'), $ynoptions);
|
|
|
|
$mform->setDefault('preventlate', 0);
|
|
|
|
|
2009-10-30 21:13:31 +00:00
|
|
|
// hack to support pluggable assignment type titles
|
2010-09-23 12:29:48 +00:00
|
|
|
if (get_string_manager()->string_exists('type'.$type, 'assignment')) {
|
|
|
|
$typetitle = get_string('type'.$type, 'assignment');
|
|
|
|
} else {
|
2009-10-30 21:13:31 +00:00
|
|
|
$typetitle = get_string('type'.$type, 'assignment_'.$type);
|
2009-11-01 13:17:47 +00:00
|
|
|
}
|
2009-10-30 21:13:31 +00:00
|
|
|
|
2010-08-13 08:29:13 +00:00
|
|
|
$this->standard_grading_coursemodule_elements();
|
|
|
|
|
2009-10-30 21:13:31 +00:00
|
|
|
$mform->addElement('header', 'typedesc', $typetitle);
|
|
|
|
|
2007-01-10 13:38:04 +00:00
|
|
|
$assignmentinstance->setup_elements($mform);
|
|
|
|
|
2009-04-21 08:57:20 +00:00
|
|
|
$this->standard_coursemodule_elements();
|
2007-01-10 13:38:04 +00:00
|
|
|
|
|
|
|
$this->add_action_buttons();
|
|
|
|
}
|
|
|
|
|
2010-07-19 16:04:16 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-10 21:01:53 +02:00
|
|
|
function validation($data, $files) {
|
2010-07-19 16:04:16 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2007-01-10 13:38:04 +00:00
|
|
|
}
|
2009-04-21 08:57:20 +00:00
|
|
|
|