MDL-32235 scheduled allocation settings form displays the execution status
[moodle.git] / mod / workshop / mod_form.php
CommitLineData
4eab2e7f 1<?php
53fad4b9
DM
2
3// This file is part of Moodle - http://moodle.org/
4//
4eab2e7f
DM
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
53fad4b9 14//
4eab2e7f
DM
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
53fad4b9 17
4eab2e7f
DM
18/**
19 * The main workshop configuration form
20 *
21 * The UI mockup has been proposed in MDL-18688
53fad4b9 22 * It uses the standard core Moodle formslib. For more info about them, please
728ebac7 23 * visit: http://docs.moodle.org/dev/lib/formslib.php
4eab2e7f 24 *
65601f04
DM
25 * @package mod
26 * @subpackage workshop
27 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
28 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4eab2e7f
DM
29 */
30
6867e05d
DM
31defined('MOODLE_INTERNAL') || die();
32
6516b9e9
DM
33require_once($CFG->dirroot . '/course/moodleform_mod.php');
34require_once(dirname(__FILE__) . '/locallib.php');
35require_once($CFG->libdir . '/filelib.php');
4eab2e7f 36
a74cadfa
DM
37/**
38 * Module settings form for Workshop instances
39 */
4eab2e7f
DM
40class mod_workshop_mod_form extends moodleform_mod {
41
a74cadfa
DM
42 /** @var object the course this instance is part of */
43 protected $course = null;
44
45 /**
46 * Constructor
47 */
48 public function __construct($current, $section, $cm, $course) {
49 $this->course = $course;
50 parent::__construct($current, $section, $cm, $course);
51 }
52
6516b9e9
DM
53 /**
54 * Defines the workshop instance configuration form
55 *
56 * @return void
57 */
a74cadfa
DM
58 public function definition() {
59 global $CFG;
4eab2e7f 60
4eab2e7f 61 $workshopconfig = get_config('workshop');
74e28b26 62 $mform = $this->_form;
4eab2e7f 63
6516b9e9 64 // General --------------------------------------------------------------------
4eab2e7f
DM
65 $mform->addElement('header', 'general', get_string('general', 'form'));
66
6516b9e9 67 // Workshop name
4eab2e7f
DM
68 $label = get_string('workshopname', 'workshop');
69 $mform->addElement('text', 'name', $label, array('size'=>'64'));
70 if (!empty($CFG->formatstringstriptags)) {
71 $mform->setType('name', PARAM_TEXT);
72 } else {
b8ea3041 73 $mform->setType('name', PARAM_CLEANHTML);
4eab2e7f
DM
74 }
75 $mform->addRule('name', null, 'required', null, 'client');
76 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
4eab2e7f 77
6516b9e9 78 // Introduction
4eab2e7f
DM
79 $this->add_intro_editor(false, get_string('introduction', 'workshop'));
80
6516b9e9 81 // Workshop features ----------------------------------------------------------
4eab2e7f
DM
82 $mform->addElement('header', 'workshopfeatures', get_string('workshopfeatures', 'workshop'));
83
84 $label = get_string('useexamples', 'workshop');
e2a81c66 85 $text = get_string('useexamples_desc', 'workshop');
0d0b7d99 86 $mform->addElement('checkbox', 'useexamples', $label, $text);
e2a81c66 87 $mform->addHelpButton('useexamples', 'useexamples', 'workshop');
4eab2e7f
DM
88
89 $label = get_string('usepeerassessment', 'workshop');
e2a81c66 90 $text = get_string('usepeerassessment_desc', 'workshop');
0d0b7d99 91 $mform->addElement('checkbox', 'usepeerassessment', $label, $text);
e2a81c66 92 $mform->addHelpButton('usepeerassessment', 'usepeerassessment', 'workshop');
4eab2e7f
DM
93
94 $label = get_string('useselfassessment', 'workshop');
e2a81c66 95 $text = get_string('useselfassessment_desc', 'workshop');
0d0b7d99 96 $mform->addElement('checkbox', 'useselfassessment', $label, $text);
e2a81c66 97 $mform->addHelpButton('useselfassessment', 'useselfassessment', 'workshop');
4eab2e7f 98
6516b9e9 99 // Grading settings -----------------------------------------------------------
4eab2e7f
DM
100 $mform->addElement('header', 'gradingsettings', get_string('gradingsettings', 'workshop'));
101
f6e8b318 102 $grades = workshop::available_maxgrades_list();
a74cadfa 103 $gradecategories = grade_get_categories_menu($this->course->id);
4eab2e7f 104
b4857acb 105 $label = get_string('submissiongrade', 'workshop');
a74cadfa
DM
106 $mform->addGroup(array(
107 $mform->createElement('select', 'grade', '', $grades),
108 $mform->createElement('select', 'gradecategory', '', $gradecategories),
109 ), 'submissiongradegroup', $label, ' ', false);
4eab2e7f 110 $mform->setDefault('grade', $workshopconfig->grade);
a74cadfa 111 $mform->addHelpButton('submissiongradegroup', 'submissiongrade', 'workshop');
4eab2e7f 112
b4857acb 113 $label = get_string('gradinggrade', 'workshop');
a74cadfa
DM
114 $mform->addGroup(array(
115 $mform->createElement('select', 'gradinggrade', '', $grades),
116 $mform->createElement('select', 'gradinggradecategory', '', $gradecategories),
117 ), 'gradinggradegroup', $label, ' ', false);
4eab2e7f 118 $mform->setDefault('gradinggrade', $workshopconfig->gradinggrade);
a74cadfa 119 $mform->addHelpButton('gradinggradegroup', 'gradinggrade', 'workshop');
4eab2e7f
DM
120
121 $label = get_string('strategy', 'workshop');
f6e8b318 122 $mform->addElement('select', 'strategy', $label, workshop::available_strategies_list());
4eab2e7f 123 $mform->setDefault('strategy', $workshopconfig->strategy);
e2a81c66 124 $mform->addHelpButton('strategy', 'strategy', 'workshop');
4eab2e7f 125
b4857acb
DM
126 $options = array();
127 for ($i=5; $i>=0; $i--) {
128 $options[$i] = $i;
129 }
130 $label = get_string('gradedecimals', 'workshop');
131 $mform->addElement('select', 'gradedecimals', $label, $options);
b4857acb
DM
132 $mform->setAdvanced('gradedecimals');
133 $mform->setDefault('gradedecimals', $workshopconfig->gradedecimals);
134
6516b9e9 135 // Submission settings --------------------------------------------------------
4eab2e7f
DM
136 $mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'workshop'));
137
6516b9e9
DM
138 $label = get_string('instructauthors', 'workshop');
139 $mform->addElement('editor', 'instructauthorseditor', $label, null,
140 workshop::instruction_editors_options($this->context));
141
4eab2e7f
DM
142 $options = array();
143 for ($i=7; $i>=0; $i--) {
144 $options[$i] = $i;
145 }
146 $label = get_string('nattachments', 'workshop');
147 $mform->addElement('select', 'nattachments', $label, $options);
148 $mform->setDefault('nattachments', 1);
6405b254 149
a74cadfa
DM
150 $options = get_max_upload_sizes($CFG->maxbytes, $this->course->maxbytes);
151 $options[0] = get_string('courseuploadlimit') . ' ('.display_size($this->course->maxbytes).')';
e2a81c66 152 $mform->addElement('select', 'maxbytes', get_string('maxbytes', 'workshop'), $options);
4eab2e7f 153 $mform->setDefault('maxbytes', $workshopconfig->maxbytes);
4eab2e7f 154
f6e8b318 155 $label = get_string('latesubmissions', 'workshop');
e2a81c66 156 $text = get_string('latesubmissions_desc', 'workshop');
0d0b7d99 157 $mform->addElement('checkbox', 'latesubmissions', $label, $text);
e2a81c66 158 $mform->addHelpButton('latesubmissions', 'latesubmissions', 'workshop');
f6e8b318
DM
159 $mform->setAdvanced('latesubmissions');
160
6516b9e9 161 // Assessment settings --------------------------------------------------------
4eab2e7f
DM
162 $mform->addElement('header', 'assessmentsettings', get_string('assessmentsettings', 'workshop'));
163
15d12b54
DM
164 $label = get_string('instructreviewers', 'workshop');
165 $mform->addElement('editor', 'instructreviewerseditor', $label, null,
166 workshop::instruction_editors_options($this->context));
6516b9e9 167
4eab2e7f 168 $label = get_string('examplesmode', 'workshop');
f6e8b318 169 $options = workshop::available_example_modes_list();
4eab2e7f
DM
170 $mform->addElement('select', 'examplesmode', $label, $options);
171 $mform->setDefault('examplesmode', $workshopconfig->examplesmode);
f6e8b318 172 $mform->disabledIf('examplesmode', 'useexamples');
4eab2e7f
DM
173 $mform->setAdvanced('examplesmode');
174
6516b9e9 175 // Access control -------------------------------------------------------------
4eab2e7f
DM
176 $mform->addElement('header', 'accesscontrol', get_string('accesscontrol', 'workshop'));
177
178 $label = get_string('submissionstart', 'workshop');
de2f199b 179 $mform->addElement('date_time_selector', 'submissionstart', $label, array('optional' => true));
4eab2e7f
DM
180 $mform->setAdvanced('submissionstart');
181
182 $label = get_string('submissionend', 'workshop');
de2f199b 183 $mform->addElement('date_time_selector', 'submissionend', $label, array('optional' => true));
4eab2e7f
DM
184 $mform->setAdvanced('submissionend');
185
186 $label = get_string('assessmentstart', 'workshop');
de2f199b 187 $mform->addElement('date_time_selector', 'assessmentstart', $label, array('optional' => true));
4eab2e7f
DM
188 $mform->setAdvanced('assessmentstart');
189
190 $label = get_string('assessmentend', 'workshop');
de2f199b 191 $mform->addElement('date_time_selector', 'assessmentend', $label, array('optional' => true));
4eab2e7f
DM
192 $mform->setAdvanced('assessmentend');
193
5924db72 194 // Common module settings, Restrict availability, Activity completion etc. ----
53fad4b9
DM
195 $features = array('groups'=>true, 'groupings'=>true, 'groupmembersonly'=>true,
196 'outcomes'=>true, 'gradecat'=>false, 'idnumber'=>false);
197
4eab2e7f
DM
198 $this->standard_coursemodule_elements();
199
6516b9e9 200 // Standard buttons, common to all modules ------------------------------------
4eab2e7f 201 $this->add_action_buttons();
6516b9e9 202 }
4eab2e7f 203
6516b9e9
DM
204 /**
205 * Prepares the form before data are set
206 *
a74cadfa
DM
207 * Additional wysiwyg editor are prepared here, the introeditor is prepared automatically by core.
208 * Grade items are set here because the core modedit supports single grade item only.
6516b9e9
DM
209 *
210 * @param array $data to be set
211 * @return void
212 */
a74cadfa 213 public function data_preprocessing(&$data) {
6516b9e9
DM
214 if ($this->current->instance) {
215 // editing an existing workshop - let us prepare the added editor elements (intro done automatically)
216 $draftitemid = file_get_submitted_draft_itemid('instructauthors');
217 $data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
6a0d85aa 218 'mod_workshop', 'instructauthors', 0,
6516b9e9
DM
219 workshop::instruction_editors_options($this->context),
220 $data['instructauthors']);
221 $data['instructauthorseditor']['format'] = $data['instructauthorsformat'];
222 $data['instructauthorseditor']['itemid'] = $draftitemid;
15d12b54
DM
223
224 $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
225 $data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
6a0d85aa 226 'mod_workshop', 'instructreviewers', 0,
15d12b54
DM
227 workshop::instruction_editors_options($this->context),
228 $data['instructreviewers']);
229 $data['instructreviewerseditor']['format'] = $data['instructreviewersformat'];
230 $data['instructreviewerseditor']['itemid'] = $draftitemid;
6516b9e9
DM
231 } else {
232 // adding a new workshop instance
233 $draftitemid = file_get_submitted_draft_itemid('instructauthors');
6a0d85aa 234 file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructauthors', 0); // no context yet, itemid not used
884482fb 235 $data['instructauthorseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
15d12b54
DM
236
237 $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
6a0d85aa 238 file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructreviewers', 0); // no context yet, itemid not used
884482fb 239 $data['instructreviewerseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
6516b9e9 240 }
4eab2e7f 241 }
a74cadfa
DM
242
243 /**
244 * Set the grade item categories when editing an instance
245 */
246 public function definition_after_data() {
247
248 $mform =& $this->_form;
249
250 if ($id = $mform->getElementValue('update')) {
251 $instance = $mform->getElementValue('instance');
252
253 $gradeitems = grade_item::fetch_all(array(
254 'itemtype' => 'mod',
255 'itemmodule' => 'workshop',
256 'iteminstance' => $instance,
257 'courseid' => $this->course->id));
258
259 if (!empty($gradeitems)) {
260 foreach ($gradeitems as $gradeitem) {
261 // here comes really crappy way how to set the value of the fields
262 // gradecategory and gradinggradecategory - grrr QuickForms
263 if ($gradeitem->itemnumber == 0) {
264 $group = $mform->getElement('submissiongradegroup');
265 $elements = $group->getElements();
266 foreach ($elements as $element) {
267 if ($element->getName() == 'gradecategory') {
268 $element->setValue($gradeitem->categoryid);
269 }
270 }
271 } else if ($gradeitem->itemnumber == 1) {
272 $group = $mform->getElement('gradinggradegroup');
273 $elements = $group->getElements();
274 foreach ($elements as $element) {
275 if ($element->getName() == 'gradinggradecategory') {
276 $element->setValue($gradeitem->categoryid);
277 }
278 }
279 }
280 }
281 }
282 }
283
284 parent::definition_after_data();
285 }
4eab2e7f 286}