[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 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. 8 // 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. 13 // 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/>. 16 17 /** 18 * This file contains the forms to create and edit an instance of this module 19 * 20 * @package mod_assign 21 * @copyright 2012 NetSpot {@link http://www.netspot.com.au} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); 26 27 require_once($CFG->dirroot.'/course/moodleform_mod.php'); 28 require_once($CFG->dirroot . '/mod/assign/locallib.php'); 29 30 /** 31 * Assignment settings form. 32 * 33 * @package mod_assign 34 * @copyright 2012 NetSpot {@link http://www.netspot.com.au} 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class mod_assign_mod_form extends moodleform_mod { 38 39 /** 40 * Called to define this moodle form 41 * 42 * @return void 43 */ 44 public function definition() { 45 global $CFG, $COURSE, $DB, $PAGE; 46 $mform = $this->_form; 47 48 $mform->addElement('header', 'general', get_string('general', 'form')); 49 50 $mform->addElement('text', 'name', get_string('assignmentname', 'assign'), array('size'=>'64')); 51 if (!empty($CFG->formatstringstriptags)) { 52 $mform->setType('name', PARAM_TEXT); 53 } else { 54 $mform->setType('name', PARAM_CLEANHTML); 55 } 56 $mform->addRule('name', null, 'required', null, 'client'); 57 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 58 59 $this->standard_intro_elements(get_string('description', 'assign')); 60 61 $mform->addElement('filemanager', 'introattachments', 62 get_string('introattachments', 'assign'), 63 null, array('subdirs' => 0, 'maxbytes' => $COURSE->maxbytes) ); 64 $mform->addHelpButton('introattachments', 'introattachments', 'assign'); 65 66 $ctx = null; 67 if ($this->current && $this->current->coursemodule) { 68 $cm = get_coursemodule_from_instance('assign', $this->current->id, 0, false, MUST_EXIST); 69 $ctx = context_module::instance($cm->id); 70 } 71 $assignment = new assign($ctx, null, null); 72 if ($this->current && $this->current->course) { 73 if (!$ctx) { 74 $ctx = context_course::instance($this->current->course); 75 } 76 $course = $DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST); 77 $assignment->set_course($course); 78 } 79 80 $config = get_config('assign'); 81 82 $mform->addElement('header', 'availability', get_string('availability', 'assign')); 83 $mform->setExpanded('availability', true); 84 85 $name = get_string('allowsubmissionsfromdate', 'assign'); 86 $options = array('optional'=>true); 87 $mform->addElement('date_time_selector', 'allowsubmissionsfromdate', $name, $options); 88 $mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'assign'); 89 90 $name = get_string('duedate', 'assign'); 91 $mform->addElement('date_time_selector', 'duedate', $name, array('optional'=>true)); 92 $mform->addHelpButton('duedate', 'duedate', 'assign'); 93 94 $name = get_string('cutoffdate', 'assign'); 95 $mform->addElement('date_time_selector', 'cutoffdate', $name, array('optional'=>true)); 96 $mform->addHelpButton('cutoffdate', 'cutoffdate', 'assign'); 97 98 $name = get_string('alwaysshowdescription', 'assign'); 99 $mform->addElement('checkbox', 'alwaysshowdescription', $name); 100 $mform->addHelpButton('alwaysshowdescription', 'alwaysshowdescription', 'assign'); 101 $mform->disabledIf('alwaysshowdescription', 'allowsubmissionsfromdate[enabled]', 'notchecked'); 102 103 $assignment->add_all_plugin_settings($mform); 104 105 $mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'assign')); 106 107 $name = get_string('submissiondrafts', 'assign'); 108 $mform->addElement('selectyesno', 'submissiondrafts', $name); 109 $mform->addHelpButton('submissiondrafts', 'submissiondrafts', 'assign'); 110 111 $name = get_string('requiresubmissionstatement', 'assign'); 112 $mform->addElement('selectyesno', 'requiresubmissionstatement', $name); 113 $mform->addHelpButton('requiresubmissionstatement', 114 'requiresubmissionstatement', 115 'assign'); 116 $mform->setType('requiresubmissionstatement', PARAM_BOOL); 117 118 $options = array( 119 ASSIGN_ATTEMPT_REOPEN_METHOD_NONE => get_string('attemptreopenmethod_none', 'mod_assign'), 120 ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL => get_string('attemptreopenmethod_manual', 'mod_assign'), 121 ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS => get_string('attemptreopenmethod_untilpass', 'mod_assign') 122 ); 123 $mform->addElement('select', 'attemptreopenmethod', get_string('attemptreopenmethod', 'mod_assign'), $options); 124 $mform->addHelpButton('attemptreopenmethod', 'attemptreopenmethod', 'mod_assign'); 125 126 $options = array(ASSIGN_UNLIMITED_ATTEMPTS => get_string('unlimitedattempts', 'mod_assign')); 127 $options += array_combine(range(1, 30), range(1, 30)); 128 $mform->addElement('select', 'maxattempts', get_string('maxattempts', 'mod_assign'), $options); 129 $mform->addHelpButton('maxattempts', 'maxattempts', 'assign'); 130 $mform->disabledIf('maxattempts', 'attemptreopenmethod', 'eq', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); 131 132 $mform->addElement('header', 'groupsubmissionsettings', get_string('groupsubmissionsettings', 'assign')); 133 134 $name = get_string('teamsubmission', 'assign'); 135 $mform->addElement('selectyesno', 'teamsubmission', $name); 136 $mform->addHelpButton('teamsubmission', 'teamsubmission', 'assign'); 137 if ($assignment->has_submissions_or_grades()) { 138 $mform->freeze('teamsubmission'); 139 } 140 141 $name = get_string('preventsubmissionnotingroup', 'assign'); 142 $mform->addElement('selectyesno', 'preventsubmissionnotingroup', $name); 143 $mform->addHelpButton('preventsubmissionnotingroup', 144 'preventsubmissionnotingroup', 145 'assign'); 146 $mform->setType('preventsubmissionnotingroup', PARAM_BOOL); 147 $mform->disabledIf('preventsubmissionnotingroup', 'teamsubmission', 'eq', 0); 148 149 $name = get_string('requireallteammemberssubmit', 'assign'); 150 $mform->addElement('selectyesno', 'requireallteammemberssubmit', $name); 151 $mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'assign'); 152 $mform->disabledIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0); 153 $mform->disabledIf('requireallteammemberssubmit', 'submissiondrafts', 'eq', 0); 154 155 $groupings = groups_get_all_groupings($assignment->get_course()->id); 156 $options = array(); 157 $options[0] = get_string('none'); 158 foreach ($groupings as $grouping) { 159 $options[$grouping->id] = $grouping->name; 160 } 161 162 $name = get_string('teamsubmissiongroupingid', 'assign'); 163 $mform->addElement('select', 'teamsubmissiongroupingid', $name, $options); 164 $mform->addHelpButton('teamsubmissiongroupingid', 'teamsubmissiongroupingid', 'assign'); 165 $mform->disabledIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0); 166 if ($assignment->has_submissions_or_grades()) { 167 $mform->freeze('teamsubmissiongroupingid'); 168 } 169 170 $mform->addElement('header', 'notifications', get_string('notifications', 'assign')); 171 172 $name = get_string('sendnotifications', 'assign'); 173 $mform->addElement('selectyesno', 'sendnotifications', $name); 174 $mform->addHelpButton('sendnotifications', 'sendnotifications', 'assign'); 175 176 $name = get_string('sendlatenotifications', 'assign'); 177 $mform->addElement('selectyesno', 'sendlatenotifications', $name); 178 $mform->addHelpButton('sendlatenotifications', 'sendlatenotifications', 'assign'); 179 $mform->disabledIf('sendlatenotifications', 'sendnotifications', 'eq', 1); 180 181 $name = get_string('sendstudentnotificationsdefault', 'assign'); 182 $mform->addElement('selectyesno', 'sendstudentnotifications', $name); 183 $mform->addHelpButton('sendstudentnotifications', 'sendstudentnotificationsdefault', 'assign'); 184 185 // Plagiarism enabling form. 186 if (!empty($CFG->enableplagiarism)) { 187 require_once($CFG->libdir . '/plagiarismlib.php'); 188 plagiarism_get_form_elements_module($mform, $ctx->get_course_context(), 'mod_assign'); 189 } 190 191 $this->standard_grading_coursemodule_elements(); 192 $name = get_string('blindmarking', 'assign'); 193 $mform->addElement('selectyesno', 'blindmarking', $name); 194 $mform->addHelpButton('blindmarking', 'blindmarking', 'assign'); 195 if ($assignment->has_submissions_or_grades() ) { 196 $mform->freeze('blindmarking'); 197 } 198 199 $name = get_string('markingworkflow', 'assign'); 200 $mform->addElement('selectyesno', 'markingworkflow', $name); 201 $mform->addHelpButton('markingworkflow', 'markingworkflow', 'assign'); 202 203 $name = get_string('markingallocation', 'assign'); 204 $mform->addElement('selectyesno', 'markingallocation', $name); 205 $mform->addHelpButton('markingallocation', 'markingallocation', 'assign'); 206 $mform->disabledIf('markingallocation', 'markingworkflow', 'eq', 0); 207 208 $this->standard_coursemodule_elements(); 209 $this->apply_admin_defaults(); 210 211 $this->add_action_buttons(); 212 } 213 214 /** 215 * Perform minimal validation on the settings form 216 * @param array $data 217 * @param array $files 218 */ 219 public function validation($data, $files) { 220 $errors = parent::validation($data, $files); 221 222 if ($data['allowsubmissionsfromdate'] && $data['duedate']) { 223 if ($data['allowsubmissionsfromdate'] > $data['duedate']) { 224 $errors['duedate'] = get_string('duedatevalidation', 'assign'); 225 } 226 } 227 if ($data['duedate'] && $data['cutoffdate']) { 228 if ($data['duedate'] > $data['cutoffdate']) { 229 $errors['cutoffdate'] = get_string('cutoffdatevalidation', 'assign'); 230 } 231 } 232 if ($data['allowsubmissionsfromdate'] && $data['cutoffdate']) { 233 if ($data['allowsubmissionsfromdate'] > $data['cutoffdate']) { 234 $errors['cutoffdate'] = get_string('cutoffdatefromdatevalidation', 'assign'); 235 } 236 } 237 if ($data['blindmarking'] && $data['attemptreopenmethod'] == ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS) { 238 $errors['attemptreopenmethod'] = get_string('reopenuntilpassincompatiblewithblindmarking', 'assign'); 239 } 240 241 return $errors; 242 } 243 244 /** 245 * Any data processing needed before the form is displayed 246 * (needed to set up draft areas for editor and filemanager elements) 247 * @param array $defaultvalues 248 */ 249 public function data_preprocessing(&$defaultvalues) { 250 global $DB; 251 252 $ctx = null; 253 if ($this->current && $this->current->coursemodule) { 254 $cm = get_coursemodule_from_instance('assign', $this->current->id, 0, false, MUST_EXIST); 255 $ctx = context_module::instance($cm->id); 256 } 257 $assignment = new assign($ctx, null, null); 258 if ($this->current && $this->current->course) { 259 if (!$ctx) { 260 $ctx = context_course::instance($this->current->course); 261 } 262 $course = $DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST); 263 $assignment->set_course($course); 264 } 265 266 $draftitemid = file_get_submitted_draft_itemid('introattachments'); 267 file_prepare_draft_area($draftitemid, $ctx->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 268 0, array('subdirs' => 0)); 269 $defaultvalues['introattachments'] = $draftitemid; 270 271 $assignment->plugin_data_preprocessing($defaultvalues); 272 } 273 274 /** 275 * Add any custom completion rules to the form. 276 * 277 * @return array Contains the names of the added form elements 278 */ 279 public function add_completion_rules() { 280 $mform =& $this->_form; 281 282 $mform->addElement('checkbox', 'completionsubmit', '', get_string('completionsubmit', 'assign')); 283 return array('completionsubmit'); 284 } 285 286 /** 287 * Determines if completion is enabled for this module. 288 * 289 * @param array $data 290 * @return bool 291 */ 292 public function completion_rule_enabled($data) { 293 return !empty($data['completionsubmit']); 294 } 295 296 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |