Grading grades aggregations
[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
90 $label = get_string('gradeforsubmission', 'workshop');
91 $mform->addElement('select', 'grade', $label, $grades);
92 $mform->setDefault('grade', $workshopconfig->grade);
93 $mform->setHelpButton('grade', array('grade', $label, 'workshop'));
94
95 $label = get_string('gradeforassessment', 'workshop');
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
6516b9e9 105 // Submission settings --------------------------------------------------------
4eab2e7f
DM
106 $mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'workshop'));
107
6516b9e9
DM
108 $label = get_string('instructauthors', 'workshop');
109 $mform->addElement('editor', 'instructauthorseditor', $label, null,
110 workshop::instruction_editors_options($this->context));
111
4eab2e7f
DM
112 $options = array();
113 for ($i=7; $i>=0; $i--) {
114 $options[$i] = $i;
115 }
116 $label = get_string('nattachments', 'workshop');
117 $mform->addElement('select', 'nattachments', $label, $options);
118 $mform->setDefault('nattachments', 1);
119 $mform->setHelpButton('nattachments', array('nattachments', $label, 'workshop'));
6405b254
DM
120
121 $label = get_string('latesubmissions', 'workshop');
122 $text = get_string('latesubmissionsdesc', 'workshop');
123 $mform->addElement('advcheckbox', 'latesubmissions', $label, $text);
124 $mform->setHelpButton('latesubmissions', array('latesubmissions', $label, 'workshop'));
4eab2e7f 125
53fad4b9 126 $options = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
4eab2e7f
DM
127 $options[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
128 $mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $options);
129 $mform->setDefault('maxbytes', $workshopconfig->maxbytes);
130 $mform->setHelpButton('maxbytes', array('maxbytes', $label, 'workshop'));
4eab2e7f 131
6516b9e9 132 // Assessment settings --------------------------------------------------------
4eab2e7f
DM
133 $mform->addElement('header', 'assessmentsettings', get_string('assessmentsettings', 'workshop'));
134
15d12b54
DM
135 $label = get_string('instructreviewers', 'workshop');
136 $mform->addElement('editor', 'instructreviewerseditor', $label, null,
137 workshop::instruction_editors_options($this->context));
6516b9e9 138
4eab2e7f
DM
139 $label = get_string('nexassessments', 'workshop');
140 $options = workshop_get_numbers_of_assessments();
141 $options[0] = get_string('assessallexamples', 'workshop');
142 $mform->addElement('select', 'nexassessments', $label, $options);
143 $mform->setDefault('nexassessments', $workshopconfig->nexassessments);
144 $mform->setHelpButton('nexassessments', array('nexassessments', $label, 'workshop'));
145 $mform->disabledIf('nexassessments', 'useexamples');
146
4eab2e7f
DM
147 $label = get_string('examplesmode', 'workshop');
148 $options = workshop_get_example_modes();
149 $mform->addElement('select', 'examplesmode', $label, $options);
150 $mform->setDefault('examplesmode', $workshopconfig->examplesmode);
151 $mform->setHelpButton('examplesmode', array('examplesmode', $label, 'workshop'));
6405b254 152 $mform->disabledIf('nexassessments', 'useexamples');
4eab2e7f
DM
153 $mform->setAdvanced('examplesmode');
154
155 $label = get_string('teacherweight', 'workshop');
156 $options = workshop_get_teacher_weights();
157 $mform->addElement('select', 'teacherweight', $label, $options);
158 $mform->setDefault('teacherweight', 1);
159 $mform->setHelpButton('teacherweight', array('teacherweight', $label, 'workshop'));
4eab2e7f
DM
160
161 $label = get_string('agreeassessments', 'workshop');
162 $text = get_string('agreeassessmentsdesc', 'workshop');
163 $mform->addElement('advcheckbox', 'agreeassessments', $label, $text);
164 $mform->setHelpButton('agreeassessments', array('agreeassessments', $label, 'workshop'));
165 $mform->setAdvanced('agreeassessments');
166
4eab2e7f
DM
167 $label = get_string('assessmentcomps', 'workshop');
168 $levels = array();
169 foreach (workshop_get_comparison_levels() as $code => $level) {
170 $levels[$code] = $level->name;
171 }
172 $mform->addElement('select', 'assessmentcomps', $label, $levels);
173 $mform->setDefault('assessmentcomps', $workshopconfig->assessmentcomps);
174 $mform->setHelpButton('assessmentcomps', array('assessmentcomps', $label, 'workshop'));
4eab2e7f 175
6516b9e9 176 // Access control -------------------------------------------------------------
4eab2e7f
DM
177 $mform->addElement('header', 'accesscontrol', get_string('accesscontrol', 'workshop'));
178
179 $label = get_string('submissionstart', 'workshop');
180 $mform->addElement('date_selector', 'submissionstart', $label, array('optional' => true));
181 $mform->setHelpButton('submissionstart', array('submissionstart', $label, 'workshop'));
182 $mform->setAdvanced('submissionstart');
183
184 $label = get_string('submissionend', 'workshop');
185 $mform->addElement('date_selector', 'submissionend', $label, array('optional' => true));
186 $mform->setHelpButton('submissionend', array('submissionend', $label, 'workshop'));
187 $mform->setAdvanced('submissionend');
188
189 $label = get_string('assessmentstart', 'workshop');
190 $mform->addElement('date_selector', 'assessmentstart', $label, array('optional' => true));
191 $mform->setHelpButton('assessmentstart', array('assessmentstart', $label, 'workshop'));
192 $mform->setAdvanced('assessmentstart');
193
194 $label = get_string('assessmentend', 'workshop');
195 $mform->addElement('date_selector', 'assessmentend', $label, array('optional' => true));
196 $mform->setHelpButton('assessmentend', array('assessmentend', $label, 'workshop'));
197 $mform->setAdvanced('assessmentend');
198
199 $label = get_string('releasegrades', 'workshop');
200 $mform->addElement('date_selector', 'releasegrades', $label, array('optional' => true));
201 $mform->setHelpButton('releasegrades', array('releasegrades', $label, 'workshop'));
202 $mform->setAdvanced('releasegrades');
203
6516b9e9 204 // Common module settinga, Restrict availability, Activity completion etc. ----
53fad4b9
DM
205 $features = array('groups'=>true, 'groupings'=>true, 'groupmembersonly'=>true,
206 'outcomes'=>true, 'gradecat'=>false, 'idnumber'=>false);
207
4eab2e7f
DM
208 $this->standard_coursemodule_elements();
209
6516b9e9 210 // Standard buttons, common to all modules ------------------------------------
4eab2e7f 211 $this->add_action_buttons();
6516b9e9 212 }
4eab2e7f 213
6516b9e9
DM
214 /**
215 * Prepares the form before data are set
216 *
217 * Additional wysiwyg editor are prepared here, the introeditor is prepared automatically by core
218 *
219 * @param array $data to be set
220 * @return void
221 */
222 function data_preprocessing(&$data) {
223 if ($this->current->instance) {
224 // editing an existing workshop - let us prepare the added editor elements (intro done automatically)
225 $draftitemid = file_get_submitted_draft_itemid('instructauthors');
226 $data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
227 'workshop_instructauthors', false,
228 workshop::instruction_editors_options($this->context),
229 $data['instructauthors']);
230 $data['instructauthorseditor']['format'] = $data['instructauthorsformat'];
231 $data['instructauthorseditor']['itemid'] = $draftitemid;
15d12b54
DM
232
233 $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
234 $data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
235 'workshop_instructreviewers', false,
236 workshop::instruction_editors_options($this->context),
237 $data['instructreviewers']);
238 $data['instructreviewerseditor']['format'] = $data['instructreviewersformat'];
239 $data['instructreviewerseditor']['itemid'] = $draftitemid;
6516b9e9
DM
240 } else {
241 // adding a new workshop instance
242 $draftitemid = file_get_submitted_draft_itemid('instructauthors');
243 file_prepare_draft_area($draftitemid, null, null, null); // no context, no filearea yet
244 $data['instructauthorseditor'] = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftitemid);
15d12b54
DM
245
246 $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
247 file_prepare_draft_area($draftitemid, null, null, null); // no context, no filearea yet
248 $data['instructreviewerseditor'] = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftitemid);
6516b9e9 249 }
4eab2e7f
DM
250 }
251}