weekly release 2.1dev
[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 *
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
DM
36
37class mod_workshop_mod_form extends moodleform_mod {
38
6516b9e9
DM
39 /**
40 * Defines the workshop instance configuration form
41 *
42 * @return void
43 */
4eab2e7f
DM
44 function definition() {
45
46 global $CFG, $COURSE;
47 $workshopconfig = get_config('workshop');
74e28b26 48 $mform = $this->_form;
4eab2e7f 49
6516b9e9 50 // General --------------------------------------------------------------------
4eab2e7f
DM
51 $mform->addElement('header', 'general', get_string('general', 'form'));
52
6516b9e9 53 // Workshop name
4eab2e7f
DM
54 $label = get_string('workshopname', 'workshop');
55 $mform->addElement('text', 'name', $label, array('size'=>'64'));
56 if (!empty($CFG->formatstringstriptags)) {
57 $mform->setType('name', PARAM_TEXT);
58 } else {
b8ea3041 59 $mform->setType('name', PARAM_CLEANHTML);
4eab2e7f
DM
60 }
61 $mform->addRule('name', null, 'required', null, 'client');
62 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
4eab2e7f 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');
e2a81c66 71 $text = get_string('useexamples_desc', 'workshop');
0d0b7d99 72 $mform->addElement('checkbox', 'useexamples', $label, $text);
e2a81c66 73 $mform->addHelpButton('useexamples', 'useexamples', 'workshop');
4eab2e7f
DM
74
75 $label = get_string('usepeerassessment', 'workshop');
e2a81c66 76 $text = get_string('usepeerassessment_desc', 'workshop');
0d0b7d99 77 $mform->addElement('checkbox', 'usepeerassessment', $label, $text);
e2a81c66 78 $mform->addHelpButton('usepeerassessment', 'usepeerassessment', 'workshop');
4eab2e7f
DM
79
80 $label = get_string('useselfassessment', 'workshop');
e2a81c66 81 $text = get_string('useselfassessment_desc', 'workshop');
0d0b7d99 82 $mform->addElement('checkbox', 'useselfassessment', $label, $text);
e2a81c66 83 $mform->addHelpButton('useselfassessment', 'useselfassessment', 'workshop');
4eab2e7f 84
6516b9e9 85 // Grading settings -----------------------------------------------------------
4eab2e7f
DM
86 $mform->addElement('header', 'gradingsettings', get_string('gradingsettings', 'workshop'));
87
f6e8b318 88 $grades = workshop::available_maxgrades_list();
4eab2e7f 89
b4857acb 90 $label = get_string('submissiongrade', 'workshop');
4eab2e7f
DM
91 $mform->addElement('select', 'grade', $label, $grades);
92 $mform->setDefault('grade', $workshopconfig->grade);
e2a81c66 93 $mform->addHelpButton('grade', 'submissiongrade', 'workshop');
4eab2e7f 94
b4857acb 95 $label = get_string('gradinggrade', 'workshop');
4eab2e7f
DM
96 $mform->addElement('select', 'gradinggrade', $label , $grades);
97 $mform->setDefault('gradinggrade', $workshopconfig->gradinggrade);
e2a81c66 98 $mform->addHelpButton('gradinggrade', 'gradinggrade', 'workshop');
4eab2e7f
DM
99
100 $label = get_string('strategy', 'workshop');
f6e8b318 101 $mform->addElement('select', 'strategy', $label, workshop::available_strategies_list());
4eab2e7f 102 $mform->setDefault('strategy', $workshopconfig->strategy);
e2a81c66 103 $mform->addHelpButton('strategy', 'strategy', 'workshop');
4eab2e7f 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);
b4857acb
DM
111 $mform->setAdvanced('gradedecimals');
112 $mform->setDefault('gradedecimals', $workshopconfig->gradedecimals);
113
6516b9e9 114 // Submission settings --------------------------------------------------------
4eab2e7f
DM
115 $mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'workshop'));
116
6516b9e9
DM
117 $label = get_string('instructauthors', 'workshop');
118 $mform->addElement('editor', 'instructauthorseditor', $label, null,
119 workshop::instruction_editors_options($this->context));
120
4eab2e7f
DM
121 $options = array();
122 for ($i=7; $i>=0; $i--) {
123 $options[$i] = $i;
124 }
125 $label = get_string('nattachments', 'workshop');
126 $mform->addElement('select', 'nattachments', $label, $options);
127 $mform->setDefault('nattachments', 1);
6405b254 128
53fad4b9 129 $options = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
4eab2e7f 130 $options[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
e2a81c66 131 $mform->addElement('select', 'maxbytes', get_string('maxbytes', 'workshop'), $options);
4eab2e7f 132 $mform->setDefault('maxbytes', $workshopconfig->maxbytes);
4eab2e7f 133
f6e8b318 134 $label = get_string('latesubmissions', 'workshop');
e2a81c66 135 $text = get_string('latesubmissions_desc', 'workshop');
0d0b7d99 136 $mform->addElement('checkbox', 'latesubmissions', $label, $text);
e2a81c66 137 $mform->addHelpButton('latesubmissions', 'latesubmissions', 'workshop');
f6e8b318
DM
138 $mform->setAdvanced('latesubmissions');
139
6516b9e9 140 // Assessment settings --------------------------------------------------------
4eab2e7f
DM
141 $mform->addElement('header', 'assessmentsettings', get_string('assessmentsettings', 'workshop'));
142
15d12b54
DM
143 $label = get_string('instructreviewers', 'workshop');
144 $mform->addElement('editor', 'instructreviewerseditor', $label, null,
145 workshop::instruction_editors_options($this->context));
6516b9e9 146
4eab2e7f 147 $label = get_string('examplesmode', 'workshop');
f6e8b318 148 $options = workshop::available_example_modes_list();
4eab2e7f
DM
149 $mform->addElement('select', 'examplesmode', $label, $options);
150 $mform->setDefault('examplesmode', $workshopconfig->examplesmode);
f6e8b318 151 $mform->disabledIf('examplesmode', 'useexamples');
4eab2e7f
DM
152 $mform->setAdvanced('examplesmode');
153
6516b9e9 154 // Access control -------------------------------------------------------------
4eab2e7f
DM
155 $mform->addElement('header', 'accesscontrol', get_string('accesscontrol', 'workshop'));
156
157 $label = get_string('submissionstart', 'workshop');
de2f199b 158 $mform->addElement('date_time_selector', 'submissionstart', $label, array('optional' => true));
4eab2e7f
DM
159 $mform->setAdvanced('submissionstart');
160
161 $label = get_string('submissionend', 'workshop');
de2f199b 162 $mform->addElement('date_time_selector', 'submissionend', $label, array('optional' => true));
4eab2e7f
DM
163 $mform->setAdvanced('submissionend');
164
165 $label = get_string('assessmentstart', 'workshop');
de2f199b 166 $mform->addElement('date_time_selector', 'assessmentstart', $label, array('optional' => true));
4eab2e7f
DM
167 $mform->setAdvanced('assessmentstart');
168
169 $label = get_string('assessmentend', 'workshop');
de2f199b 170 $mform->addElement('date_time_selector', 'assessmentend', $label, array('optional' => true));
4eab2e7f
DM
171 $mform->setAdvanced('assessmentend');
172
5924db72 173 // Common module settings, Restrict availability, Activity completion etc. ----
53fad4b9
DM
174 $features = array('groups'=>true, 'groupings'=>true, 'groupmembersonly'=>true,
175 'outcomes'=>true, 'gradecat'=>false, 'idnumber'=>false);
176
4eab2e7f
DM
177 $this->standard_coursemodule_elements();
178
6516b9e9 179 // Standard buttons, common to all modules ------------------------------------
4eab2e7f 180 $this->add_action_buttons();
6516b9e9 181 }
4eab2e7f 182
6516b9e9
DM
183 /**
184 * Prepares the form before data are set
185 *
186 * Additional wysiwyg editor are prepared here, the introeditor is prepared automatically by core
187 *
188 * @param array $data to be set
189 * @return void
190 */
191 function data_preprocessing(&$data) {
192 if ($this->current->instance) {
193 // editing an existing workshop - let us prepare the added editor elements (intro done automatically)
194 $draftitemid = file_get_submitted_draft_itemid('instructauthors');
195 $data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
6a0d85aa 196 'mod_workshop', 'instructauthors', 0,
6516b9e9
DM
197 workshop::instruction_editors_options($this->context),
198 $data['instructauthors']);
199 $data['instructauthorseditor']['format'] = $data['instructauthorsformat'];
200 $data['instructauthorseditor']['itemid'] = $draftitemid;
15d12b54
DM
201
202 $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
203 $data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
6a0d85aa 204 'mod_workshop', 'instructreviewers', 0,
15d12b54
DM
205 workshop::instruction_editors_options($this->context),
206 $data['instructreviewers']);
207 $data['instructreviewerseditor']['format'] = $data['instructreviewersformat'];
208 $data['instructreviewerseditor']['itemid'] = $draftitemid;
6516b9e9
DM
209 } else {
210 // adding a new workshop instance
211 $draftitemid = file_get_submitted_draft_itemid('instructauthors');
6a0d85aa 212 file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructauthors', 0); // no context yet, itemid not used
884482fb 213 $data['instructauthorseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
15d12b54
DM
214
215 $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
6a0d85aa 216 file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructreviewers', 0); // no context yet, itemid not used
884482fb 217 $data['instructreviewerseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
6516b9e9 218 }
4eab2e7f
DM
219 }
220}