MDL-19930 workshop: comments grading strategy
[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
4eab2e7f
DM
23 * visit: http://docs.moodle.org/en/Development:lib/formslib.php
24 *
25 * @package mod-workshop
26 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 */
29
6867e05d
DM
30defined('MOODLE_INTERNAL') || die();
31
6516b9e9
DM
32require_once($CFG->dirroot . '/course/moodleform_mod.php');
33require_once(dirname(__FILE__) . '/locallib.php');
34require_once($CFG->libdir . '/filelib.php');
4eab2e7f
DM
35
36class mod_workshop_mod_form extends moodleform_mod {
37
6516b9e9
DM
38 /**
39 * Defines the workshop instance configuration form
40 *
41 * @return void
42 */
4eab2e7f
DM
43 function definition() {
44
45 global $CFG, $COURSE;
46 $workshopconfig = get_config('workshop');
74e28b26 47 $mform = $this->_form;
4eab2e7f 48
6516b9e9 49 // General --------------------------------------------------------------------
4eab2e7f
DM
50 $mform->addElement('header', 'general', get_string('general', 'form'));
51
6516b9e9 52 // Workshop name
4eab2e7f
DM
53 $label = get_string('workshopname', 'workshop');
54 $mform->addElement('text', 'name', $label, array('size'=>'64'));
55 if (!empty($CFG->formatstringstriptags)) {
56 $mform->setType('name', PARAM_TEXT);
57 } else {
58 $mform->setType('name', PARAM_CLEAN);
59 }
60 $mform->addRule('name', null, 'required', null, 'client');
61 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
62 $mform->setHelpButton('name', array('workshopname', $label, 'workshop'));
63
6516b9e9 64 // Introduction
4eab2e7f
DM
65 $this->add_intro_editor(false, get_string('introduction', 'workshop'));
66
6516b9e9 67 // Workshop features ----------------------------------------------------------
4eab2e7f
DM
68 $mform->addElement('header', 'workshopfeatures', get_string('workshopfeatures', 'workshop'));
69
70 $label = get_string('useexamples', 'workshop');
71 $text = get_string('useexamplesdesc', 'workshop');
72 $mform->addElement('advcheckbox', 'useexamples', $label, $text);
73 $mform->setHelpButton('useexamples', array('useexamples', $label, 'workshop'));
74
75 $label = get_string('usepeerassessment', 'workshop');
76 $text = get_string('usepeerassessmentdesc', 'workshop');
77 $mform->addElement('advcheckbox', 'usepeerassessment', $label, $text);
78 $mform->setHelpButton('usepeerassessment', array('usepeerassessment', $label, 'workshop'));
79
80 $label = get_string('useselfassessment', 'workshop');
81 $text = get_string('useselfassessmentdesc', 'workshop');
82 $mform->addElement('advcheckbox', 'useselfassessment', $label, $text);
83 $mform->setHelpButton('useselfassessment', array('useselfassessment', $label, 'workshop'));
84
6516b9e9 85 // Grading settings -----------------------------------------------------------
4eab2e7f
DM
86 $mform->addElement('header', 'gradingsettings', get_string('gradingsettings', 'workshop'));
87
88 $grades = workshop_get_maxgrades();
89
b4857acb 90 $label = get_string('submissiongrade', 'workshop');
4eab2e7f
DM
91 $mform->addElement('select', 'grade', $label, $grades);
92 $mform->setDefault('grade', $workshopconfig->grade);
93 $mform->setHelpButton('grade', array('grade', $label, 'workshop'));
94
b4857acb 95 $label = get_string('gradinggrade', 'workshop');
4eab2e7f
DM
96 $mform->addElement('select', 'gradinggrade', $label , $grades);
97 $mform->setDefault('gradinggrade', $workshopconfig->gradinggrade);
98 $mform->setHelpButton('gradinggrade', array('gradinggrade', $label, 'workshop'));
99
100 $label = get_string('strategy', 'workshop');
101 $mform->addElement('select', 'strategy', $label, workshop_get_strategies());
102 $mform->setDefault('strategy', $workshopconfig->strategy);
103 $mform->setHelpButton('strategy', array('strategy', $label, 'workshop'));
104
b4857acb
DM
105 $options = array();
106 for ($i=5; $i>=0; $i--) {
107 $options[$i] = $i;
108 }
109 $label = get_string('gradedecimals', 'workshop');
110 $mform->addElement('select', 'gradedecimals', $label, $options);
111 $mform->setHelpButton('gradedecimals', array('gradedecimals', $label, 'workshop'));
112 $mform->setAdvanced('gradedecimals');
113 $mform->setDefault('gradedecimals', $workshopconfig->gradedecimals);
114
6516b9e9 115 // Submission settings --------------------------------------------------------
4eab2e7f
DM
116 $mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'workshop'));
117
6516b9e9
DM
118 $label = get_string('instructauthors', 'workshop');
119 $mform->addElement('editor', 'instructauthorseditor', $label, null,
120 workshop::instruction_editors_options($this->context));
121
4eab2e7f
DM
122 $options = array();
123 for ($i=7; $i>=0; $i--) {
124 $options[$i] = $i;
125 }
126 $label = get_string('nattachments', 'workshop');
127 $mform->addElement('select', 'nattachments', $label, $options);
128 $mform->setDefault('nattachments', 1);
129 $mform->setHelpButton('nattachments', array('nattachments', $label, 'workshop'));
6405b254
DM
130
131 $label = get_string('latesubmissions', 'workshop');
132 $text = get_string('latesubmissionsdesc', 'workshop');
133 $mform->addElement('advcheckbox', 'latesubmissions', $label, $text);
134 $mform->setHelpButton('latesubmissions', array('latesubmissions', $label, 'workshop'));
4eab2e7f 135
53fad4b9 136 $options = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
4eab2e7f
DM
137 $options[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
138 $mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $options);
139 $mform->setDefault('maxbytes', $workshopconfig->maxbytes);
140 $mform->setHelpButton('maxbytes', array('maxbytes', $label, 'workshop'));
4eab2e7f 141
6516b9e9 142 // Assessment settings --------------------------------------------------------
4eab2e7f
DM
143 $mform->addElement('header', 'assessmentsettings', get_string('assessmentsettings', 'workshop'));
144
15d12b54
DM
145 $label = get_string('instructreviewers', 'workshop');
146 $mform->addElement('editor', 'instructreviewerseditor', $label, null,
147 workshop::instruction_editors_options($this->context));
6516b9e9 148
4eab2e7f
DM
149 $label = get_string('nexassessments', 'workshop');
150 $options = workshop_get_numbers_of_assessments();
151 $options[0] = get_string('assessallexamples', 'workshop');
152 $mform->addElement('select', 'nexassessments', $label, $options);
153 $mform->setDefault('nexassessments', $workshopconfig->nexassessments);
154 $mform->setHelpButton('nexassessments', array('nexassessments', $label, 'workshop'));
155 $mform->disabledIf('nexassessments', 'useexamples');
156
4eab2e7f
DM
157 $label = get_string('examplesmode', 'workshop');
158 $options = workshop_get_example_modes();
159 $mform->addElement('select', 'examplesmode', $label, $options);
160 $mform->setDefault('examplesmode', $workshopconfig->examplesmode);
161 $mform->setHelpButton('examplesmode', array('examplesmode', $label, 'workshop'));
6405b254 162 $mform->disabledIf('nexassessments', 'useexamples');
4eab2e7f
DM
163 $mform->setAdvanced('examplesmode');
164
165 $label = get_string('teacherweight', 'workshop');
166 $options = workshop_get_teacher_weights();
167 $mform->addElement('select', 'teacherweight', $label, $options);
168 $mform->setDefault('teacherweight', 1);
169 $mform->setHelpButton('teacherweight', array('teacherweight', $label, 'workshop'));
4eab2e7f
DM
170
171 $label = get_string('agreeassessments', 'workshop');
172 $text = get_string('agreeassessmentsdesc', 'workshop');
173 $mform->addElement('advcheckbox', 'agreeassessments', $label, $text);
174 $mform->setHelpButton('agreeassessments', array('agreeassessments', $label, 'workshop'));
175 $mform->setAdvanced('agreeassessments');
176
4eab2e7f
DM
177 $label = get_string('assessmentcomps', 'workshop');
178 $levels = array();
179 foreach (workshop_get_comparison_levels() as $code => $level) {
180 $levels[$code] = $level->name;
181 }
182 $mform->addElement('select', 'assessmentcomps', $label, $levels);
183 $mform->setDefault('assessmentcomps', $workshopconfig->assessmentcomps);
184 $mform->setHelpButton('assessmentcomps', array('assessmentcomps', $label, 'workshop'));
4eab2e7f 185
6516b9e9 186 // Access control -------------------------------------------------------------
4eab2e7f
DM
187 $mform->addElement('header', 'accesscontrol', get_string('accesscontrol', 'workshop'));
188
189 $label = get_string('submissionstart', 'workshop');
190 $mform->addElement('date_selector', 'submissionstart', $label, array('optional' => true));
191 $mform->setHelpButton('submissionstart', array('submissionstart', $label, 'workshop'));
192 $mform->setAdvanced('submissionstart');
193
194 $label = get_string('submissionend', 'workshop');
195 $mform->addElement('date_selector', 'submissionend', $label, array('optional' => true));
196 $mform->setHelpButton('submissionend', array('submissionend', $label, 'workshop'));
197 $mform->setAdvanced('submissionend');
198
199 $label = get_string('assessmentstart', 'workshop');
200 $mform->addElement('date_selector', 'assessmentstart', $label, array('optional' => true));
201 $mform->setHelpButton('assessmentstart', array('assessmentstart', $label, 'workshop'));
202 $mform->setAdvanced('assessmentstart');
203
204 $label = get_string('assessmentend', 'workshop');
205 $mform->addElement('date_selector', 'assessmentend', $label, array('optional' => true));
206 $mform->setHelpButton('assessmentend', array('assessmentend', $label, 'workshop'));
207 $mform->setAdvanced('assessmentend');
208
209 $label = get_string('releasegrades', 'workshop');
210 $mform->addElement('date_selector', 'releasegrades', $label, array('optional' => true));
211 $mform->setHelpButton('releasegrades', array('releasegrades', $label, 'workshop'));
212 $mform->setAdvanced('releasegrades');
213
6516b9e9 214 // Common module settinga, Restrict availability, Activity completion etc. ----
53fad4b9
DM
215 $features = array('groups'=>true, 'groupings'=>true, 'groupmembersonly'=>true,
216 'outcomes'=>true, 'gradecat'=>false, 'idnumber'=>false);
217
4eab2e7f
DM
218 $this->standard_coursemodule_elements();
219
6516b9e9 220 // Standard buttons, common to all modules ------------------------------------
4eab2e7f 221 $this->add_action_buttons();
6516b9e9 222 }
4eab2e7f 223
6516b9e9
DM
224 /**
225 * Prepares the form before data are set
226 *
227 * Additional wysiwyg editor are prepared here, the introeditor is prepared automatically by core
228 *
229 * @param array $data to be set
230 * @return void
231 */
232 function data_preprocessing(&$data) {
233 if ($this->current->instance) {
234 // editing an existing workshop - let us prepare the added editor elements (intro done automatically)
235 $draftitemid = file_get_submitted_draft_itemid('instructauthors');
236 $data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
237 'workshop_instructauthors', false,
238 workshop::instruction_editors_options($this->context),
239 $data['instructauthors']);
240 $data['instructauthorseditor']['format'] = $data['instructauthorsformat'];
241 $data['instructauthorseditor']['itemid'] = $draftitemid;
15d12b54
DM
242
243 $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
244 $data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
245 'workshop_instructreviewers', false,
246 workshop::instruction_editors_options($this->context),
247 $data['instructreviewers']);
248 $data['instructreviewerseditor']['format'] = $data['instructreviewersformat'];
249 $data['instructreviewerseditor']['itemid'] = $draftitemid;
6516b9e9
DM
250 } else {
251 // adding a new workshop instance
252 $draftitemid = file_get_submitted_draft_itemid('instructauthors');
253 file_prepare_draft_area($draftitemid, null, null, null); // no context, no filearea yet
254 $data['instructauthorseditor'] = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftitemid);
15d12b54
DM
255
256 $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
257 file_prepare_draft_area($draftitemid, null, null, null); // no context, no filearea yet
258 $data['instructreviewerseditor'] = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftitemid);
6516b9e9 259 }
4eab2e7f
DM
260 }
261}