[ Index ] |
PHP Cross Reference of moodle-2.8 |
[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->add_intro_editor(true, 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('requireallteammemberssubmit', 'assign'); 142 $mform->addElement('selectyesno', 'requireallteammemberssubmit', $name); 143 $mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'assign'); 144 $mform->disabledIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0); 145 $mform->disabledIf('requireallteammemberssubmit', 'submissiondrafts', 'eq', 0); 146 147 $groupings = groups_get_all_groupings($assignment->get_course()->id); 148 $options = array(); 149 $options[0] = get_string('none'); 150 foreach ($groupings as $grouping) { 151 $options[$grouping->id] = $grouping->name; 152 } 153 154 $name = get_string('teamsubmissiongroupingid', 'assign'); 155 $mform->addElement('select', 'teamsubmissiongroupingid', $name, $options); 156 $mform->addHelpButton('teamsubmissiongroupingid', 'teamsubmissiongroupingid', 'assign'); 157 $mform->disabledIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0); 158 if ($assignment->has_submissions_or_grades()) { 159 $mform->freeze('teamsubmissiongroupingid'); 160 } 161 162 $mform->addElement('header', 'notifications', get_string('notifications', 'assign')); 163 164 $name = get_string('sendnotifications', 'assign'); 165 $mform->addElement('selectyesno', 'sendnotifications', $name); 166 $mform->addHelpButton('sendnotifications', 'sendnotifications', 'assign'); 167 168 $name = get_string('sendlatenotifications', 'assign'); 169 $mform->addElement('selectyesno', 'sendlatenotifications', $name); 170 $mform->addHelpButton('sendlatenotifications', 'sendlatenotifications', 'assign'); 171 $mform->disabledIf('sendlatenotifications', 'sendnotifications', 'eq', 1); 172 173 $name = get_string('sendstudentnotificationsdefault', 'assign'); 174 $mform->addElement('selectyesno', 'sendstudentnotifications', $name); 175 $mform->addHelpButton('sendstudentnotifications', 'sendstudentnotificationsdefault', 'assign'); 176 177 // Plagiarism enabling form. 178 if (!empty($CFG->enableplagiarism)) { 179 require_once($CFG->libdir . '/plagiarismlib.php'); 180 plagiarism_get_form_elements_module($mform, $ctx->get_course_context(), 'mod_assign'); 181 } 182 183 $this->standard_grading_coursemodule_elements(); 184 $name = get_string('blindmarking', 'assign'); 185 $mform->addElement('selectyesno', 'blindmarking', $name); 186 $mform->addHelpButton('blindmarking', 'blindmarking', 'assign'); 187 if ($assignment->has_submissions_or_grades() ) { 188 $mform->freeze('blindmarking'); 189 } 190 191 $name = get_string('markingworkflow', 'assign'); 192 $mform->addElement('selectyesno', 'markingworkflow', $name); 193 $mform->addHelpButton('markingworkflow', 'markingworkflow', 'assign'); 194 195 $name = get_string('markingallocation', 'assign'); 196 $mform->addElement('selectyesno', 'markingallocation', $name); 197 $mform->addHelpButton('markingallocation', 'markingallocation', 'assign'); 198 $mform->disabledIf('markingallocation', 'markingworkflow', 'eq', 0); 199 200 $this->standard_coursemodule_elements(); 201 $this->apply_admin_defaults(); 202 203 $this->add_action_buttons(); 204 205 // Add warning popup/noscript tag, if grades are changed by user. 206 $hasgrade = false; 207 if (!empty($this->_instance)) { 208 $hasgrade = $DB->record_exists_select('assign_grades', 209 'assignment = ? AND grade <> -1', 210 array($this->_instance)); 211 } 212 213 if ($mform->elementExists('grade') && $hasgrade) { 214 $module = array( 215 'name' => 'mod_assign', 216 'fullpath' => '/mod/assign/module.js', 217 'requires' => array('node', 'event'), 218 'strings' => array(array('changegradewarning', 'mod_assign')) 219 ); 220 $PAGE->requires->js_init_call('M.mod_assign.init_grade_change', null, false, $module); 221 222 // Add noscript tag in case. 223 $noscriptwarning = $mform->createElement('static', 224 'warning', 225 null, 226 html_writer::tag('noscript', 227 get_string('changegradewarning', 'mod_assign'))); 228 $mform->insertElementBefore($noscriptwarning, 'grade'); 229 } 230 } 231 232 /** 233 * Perform minimal validation on the settings form 234 * @param array $data 235 * @param array $files 236 */ 237 public function validation($data, $files) { 238 $errors = parent::validation($data, $files); 239 240 if ($data['allowsubmissionsfromdate'] && $data['duedate']) { 241 if ($data['allowsubmissionsfromdate'] > $data['duedate']) { 242 $errors['duedate'] = get_string('duedatevalidation', 'assign'); 243 } 244 } 245 if ($data['duedate'] && $data['cutoffdate']) { 246 if ($data['duedate'] > $data['cutoffdate']) { 247 $errors['cutoffdate'] = get_string('cutoffdatevalidation', 'assign'); 248 } 249 } 250 if ($data['allowsubmissionsfromdate'] && $data['cutoffdate']) { 251 if ($data['allowsubmissionsfromdate'] > $data['cutoffdate']) { 252 $errors['cutoffdate'] = get_string('cutoffdatefromdatevalidation', 'assign'); 253 } 254 } 255 if ($data['blindmarking'] && $data['attemptreopenmethod'] == ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS) { 256 $errors['attemptreopenmethod'] = get_string('reopenuntilpassincompatiblewithblindmarking', 'assign'); 257 } 258 259 return $errors; 260 } 261 262 /** 263 * Any data processing needed before the form is displayed 264 * (needed to set up draft areas for editor and filemanager elements) 265 * @param array $defaultvalues 266 */ 267 public function data_preprocessing(&$defaultvalues) { 268 global $DB; 269 270 $ctx = null; 271 if ($this->current && $this->current->coursemodule) { 272 $cm = get_coursemodule_from_instance('assign', $this->current->id, 0, false, MUST_EXIST); 273 $ctx = context_module::instance($cm->id); 274 } 275 $assignment = new assign($ctx, null, null); 276 if ($this->current && $this->current->course) { 277 if (!$ctx) { 278 $ctx = context_course::instance($this->current->course); 279 } 280 $course = $DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST); 281 $assignment->set_course($course); 282 } 283 284 $draftitemid = file_get_submitted_draft_itemid('introattachments'); 285 file_prepare_draft_area($draftitemid, $ctx->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 286 0, array('subdirs' => 0)); 287 $defaultvalues['introattachments'] = $draftitemid; 288 289 $assignment->plugin_data_preprocessing($defaultvalues); 290 } 291 292 /** 293 * Add any custom completion rules to the form. 294 * 295 * @return array Contains the names of the added form elements 296 */ 297 public function add_completion_rules() { 298 $mform =& $this->_form; 299 300 $mform->addElement('checkbox', 'completionsubmit', '', get_string('completionsubmit', 'assign')); 301 return array('completionsubmit'); 302 } 303 304 /** 305 * Determines if completion is enabled for this module. 306 * 307 * @param array $data 308 * @return bool 309 */ 310 public function completion_rule_enabled($data) { 311 return !empty($data['completionsubmit']); 312 } 313 314 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |