2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * This file contains the forms to create and edit an instance of this module
21 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die('Direct access to this script is forbidden.');
28 /** Include moodleform_mod.php */
29 require_once ($CFG->dirroot
.'/course/moodleform_mod.php');
30 /** Include locallib.php */
31 require_once($CFG->dirroot
. '/mod/assign/locallib.php');
34 * Assignment settings form.
37 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class mod_assign_mod_form
extends moodleform_mod
{
43 * Called to define this moodle form
47 function definition() {
48 global $CFG, $DB, $PAGE;
49 $mform = $this->_form
;
51 $mform->addElement('header', 'general', get_string('general', 'form'));
53 $mform->addElement('text', 'name', get_string('assignmentname', 'assign'), array('size'=>'64'));
54 if (!empty($CFG->formatstringstriptags
)) {
55 $mform->setType('name', PARAM_TEXT
);
57 $mform->setType('name', PARAM_CLEANHTML
);
59 $mform->addRule('name', null, 'required', null, 'client');
61 $this->add_intro_editor(true, get_string('description', 'assign'));
64 if ($this->current
&& $this->current
->coursemodule
) {
65 $cm = get_coursemodule_from_instance('assign', $this->current
->id
, 0, false, MUST_EXIST
);
66 $ctx = context_module
::instance($cm->id
);
68 $assignment = new assign($ctx, null, null);
69 if ($this->current
&& $this->current
->course
) {
71 $ctx = context_course
::instance($this->current
->course
);
73 $assignment->set_course($DB->get_record('course', array('id'=>$this->current
->course
), '*', MUST_EXIST
));
76 $config = get_config('assign');
78 $mform->addElement('header', 'general', get_string('settings', 'assign'));
79 $mform->addElement('date_time_selector', 'allowsubmissionsfromdate', get_string('allowsubmissionsfromdate', 'assign'), array('optional'=>true));
80 $mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'assign');
81 $mform->setDefault('allowsubmissionsfromdate', time());
82 $mform->addElement('date_time_selector', 'duedate', get_string('duedate', 'assign'), array('optional'=>true));
83 $mform->addHelpButton('duedate', 'duedate', 'assign');
84 $mform->setDefault('duedate', time()+
7*24*3600);
85 $mform->addElement('date_time_selector', 'cutoffdate', get_string('cutoffdate', 'assign'), array('optional'=>true));
86 $mform->addHelpButton('cutoffdate', 'cutoffdate', 'assign');
87 $mform->setDefault('cutoffdate', time()+
7*24*3600);
88 $mform->addElement('selectyesno', 'alwaysshowdescription', get_string('alwaysshowdescription', 'assign'));
89 $mform->addHelpButton('alwaysshowdescription', 'alwaysshowdescription', 'assign');
90 $mform->setDefault('alwaysshowdescription', 1);
91 $mform->addElement('selectyesno', 'submissiondrafts', get_string('submissiondrafts', 'assign'));
92 $mform->addHelpButton('submissiondrafts', 'submissiondrafts', 'assign');
93 $mform->setDefault('submissiondrafts', 0);
94 // submission statement
95 if (empty($config->requiresubmissionstatement
)) {
96 $mform->addElement('selectyesno', 'requiresubmissionstatement', get_string('requiresubmissionstatement', 'assign'));
97 $mform->setDefault('requiresubmissionstatement', 0);
98 $mform->addHelpButton('requiresubmissionstatement', 'requiresubmissionstatement', 'assign');
100 $mform->addElement('hidden', 'requiresubmissionstatement', 1);
103 $mform->addElement('selectyesno', 'sendnotifications', get_string('sendnotifications', 'assign'));
104 $mform->addHelpButton('sendnotifications', 'sendnotifications', 'assign');
105 $mform->setDefault('sendnotifications', 1);
106 $mform->addElement('selectyesno', 'sendlatenotifications', get_string('sendlatenotifications', 'assign'));
107 $mform->addHelpButton('sendlatenotifications', 'sendlatenotifications', 'assign');
108 $mform->setDefault('sendlatenotifications', 1);
109 $mform->disabledIf('sendlatenotifications', 'sendnotifications', 'eq', 1);
110 $mform->addElement('selectyesno', 'teamsubmission', get_string('teamsubmission', 'assign'));
111 $mform->addHelpButton('teamsubmission', 'teamsubmission', 'assign');
112 $mform->setDefault('teamsubmission', 0);
113 $mform->addElement('selectyesno', 'requireallteammemberssubmit', get_string('requireallteammemberssubmit', 'assign'));
114 $mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'assign');
115 $mform->setDefault('requireallteammemberssubmit', 0);
116 $mform->disabledIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0);
117 $mform->disabledIf('requireallteammemberssubmit', 'submissiondrafts', 'eq', 0);
119 $groupings = groups_get_all_groupings($assignment->get_course()->id
);
121 $options[0] = get_string('none');
122 foreach ($groupings as $grouping) {
123 $options[$grouping->id
] = $grouping->name
;
125 $mform->addElement('select', 'teamsubmissiongroupingid', get_string('teamsubmissiongroupingid', 'assign'), $options);
126 $mform->addHelpButton('teamsubmissiongroupingid', 'teamsubmissiongroupingid', 'assign');
127 $mform->setDefault('teamsubmissiongroupingid', 0);
128 $mform->disabledIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0);
130 $mform->addElement('selectyesno', 'blindmarking', get_string('blindmarking', 'assign'));
131 $mform->addHelpButton('blindmarking', 'blindmarking', 'assign');
132 $mform->setDefault('blindmarking', 0);
133 if ($assignment->has_submissions_or_grades() ) {
134 $mform->freeze('blindmarking');
138 // plagiarism enabling form
139 if (!empty($CFG->enableplagiarism
)) {
140 /** Include plagiarismlib.php */
141 require_once($CFG->libdir
. '/plagiarismlib.php');
142 plagiarism_get_form_elements_module($mform, $ctx->get_course_context(), 'mod_assign');
145 $assignment->add_all_plugin_settings($mform);
146 $this->standard_grading_coursemodule_elements();
147 $this->standard_coursemodule_elements();
149 $this->add_action_buttons();
151 // Add warning popup/noscript tag, if grades are changed by user.
152 if ($mform->elementExists('grade') && !empty($this->_instance
) && $DB->record_exists_select('assign_grades', 'assignment = ? AND grade <> -1', array($this->_instance
))) {
154 'name' => 'mod_assign',
155 'fullpath' => '/mod/assign/module.js',
156 'requires' => array('node', 'event'),
157 'strings' => array(array('changegradewarning', 'mod_assign'))
159 $PAGE->requires
->js_init_call('M.mod_assign.init_grade_change', null, false, $module);
161 // Add noscript tag in case
162 $noscriptwarning = $mform->createElement('static', 'warning', null, html_writer
::tag('noscript', get_string('changegradewarning', 'mod_assign')));
163 $mform->insertElementBefore($noscriptwarning, 'grade');
168 * Perform minimal validation on the settings form
170 * @param array $files
172 function validation($data, $files) {
173 $errors = parent
::validation($data, $files);
175 if ($data['allowsubmissionsfromdate'] && $data['duedate']) {
176 if ($data['allowsubmissionsfromdate'] > $data['duedate']) {
177 $errors['duedate'] = get_string('duedatevalidation', 'assign');
180 if ($data['duedate'] && $data['cutoffdate']) {
181 if ($data['duedate'] > $data['cutoffdate']) {
182 $errors['cutoffdate'] = get_string('cutoffdatevalidation', 'assign');
185 if ($data['allowsubmissionsfromdate'] && $data['cutoffdate']) {
186 if ($data['allowsubmissionsfromdate'] > $data['cutoffdate']) {
187 $errors['cutoffdate'] = get_string('cutoffdatefromdatevalidation', 'assign');
195 * Any data processing needed before the form is displayed
196 * (needed to set up draft areas for editor and filemanager elements)
197 * @param array $defaultvalues
199 function data_preprocessing(&$defaultvalues) {
203 if ($this->current
&& $this->current
->coursemodule
) {
204 $cm = get_coursemodule_from_instance('assign', $this->current
->id
, 0, false, MUST_EXIST
);
205 $ctx = context_module
::instance($cm->id
);
207 $assignment = new assign($ctx, null, null);
208 if ($this->current
&& $this->current
->course
) {
210 $ctx = context_course
::instance($this->current
->course
);
212 $assignment->set_course($DB->get_record('course', array('id'=>$this->current
->course
), '*', MUST_EXIST
));
214 $assignment->plugin_data_preprocessing($defaultvalues);
217 function add_completion_rules() {
218 $mform =& $this->_form
;
220 $mform->addElement('checkbox', 'completionsubmit', '', get_string('completionsubmit', 'assign'));
221 return array('completionsubmit');
224 function completion_rule_enabled($data) {
225 return !empty($data['completionsubmit']);