Removing forgotten subplugins names from workshop plugin lang file
[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');
0d0b7d99 72 $mform->addElement('checkbox', 'useexamples', $label, $text);
4eab2e7f
DM
73 $mform->setHelpButton('useexamples', array('useexamples', $label, 'workshop'));
74
75 $label = get_string('usepeerassessment', 'workshop');
76 $text = get_string('usepeerassessmentdesc', 'workshop');
0d0b7d99 77 $mform->addElement('checkbox', 'usepeerassessment', $label, $text);
4eab2e7f
DM
78 $mform->setHelpButton('usepeerassessment', array('usepeerassessment', $label, 'workshop'));
79
80 $label = get_string('useselfassessment', 'workshop');
81 $text = get_string('useselfassessmentdesc', 'workshop');
0d0b7d99 82 $mform->addElement('checkbox', 'useselfassessment', $label, $text);
4eab2e7f
DM
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
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);
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');
f6e8b318 101 $mform->addElement('select', 'strategy', $label, workshop::available_strategies_list());
4eab2e7f
DM
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 130
53fad4b9 131 $options = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
4eab2e7f
DM
132 $options[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
133 $mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $options);
134 $mform->setDefault('maxbytes', $workshopconfig->maxbytes);
135 $mform->setHelpButton('maxbytes', array('maxbytes', $label, 'workshop'));
4eab2e7f 136
f6e8b318
DM
137 $label = get_string('latesubmissions', 'workshop');
138 $text = get_string('latesubmissionsdesc', 'workshop');
0d0b7d99 139 $mform->addElement('checkbox', 'latesubmissions', $label, $text);
f6e8b318
DM
140 $mform->setHelpButton('latesubmissions', array('latesubmissions', $label, 'workshop'));
141 $mform->setAdvanced('latesubmissions');
142
6516b9e9 143 // Assessment settings --------------------------------------------------------
4eab2e7f
DM
144 $mform->addElement('header', 'assessmentsettings', get_string('assessmentsettings', 'workshop'));
145
15d12b54
DM
146 $label = get_string('instructreviewers', 'workshop');
147 $mform->addElement('editor', 'instructreviewerseditor', $label, null,
148 workshop::instruction_editors_options($this->context));
6516b9e9 149
4eab2e7f 150 $label = get_string('examplesmode', 'workshop');
f6e8b318 151 $options = workshop::available_example_modes_list();
4eab2e7f
DM
152 $mform->addElement('select', 'examplesmode', $label, $options);
153 $mform->setDefault('examplesmode', $workshopconfig->examplesmode);
154 $mform->setHelpButton('examplesmode', array('examplesmode', $label, 'workshop'));
f6e8b318 155 $mform->disabledIf('examplesmode', 'useexamples');
4eab2e7f
DM
156 $mform->setAdvanced('examplesmode');
157
6516b9e9 158 // Access control -------------------------------------------------------------
4eab2e7f
DM
159 $mform->addElement('header', 'accesscontrol', get_string('accesscontrol', 'workshop'));
160
161 $label = get_string('submissionstart', 'workshop');
de2f199b 162 $mform->addElement('date_time_selector', 'submissionstart', $label, array('optional' => true));
4eab2e7f
DM
163 $mform->setHelpButton('submissionstart', array('submissionstart', $label, 'workshop'));
164 $mform->setAdvanced('submissionstart');
165
166 $label = get_string('submissionend', 'workshop');
de2f199b 167 $mform->addElement('date_time_selector', 'submissionend', $label, array('optional' => true));
4eab2e7f
DM
168 $mform->setHelpButton('submissionend', array('submissionend', $label, 'workshop'));
169 $mform->setAdvanced('submissionend');
170
171 $label = get_string('assessmentstart', 'workshop');
de2f199b 172 $mform->addElement('date_time_selector', 'assessmentstart', $label, array('optional' => true));
4eab2e7f
DM
173 $mform->setHelpButton('assessmentstart', array('assessmentstart', $label, 'workshop'));
174 $mform->setAdvanced('assessmentstart');
175
176 $label = get_string('assessmentend', 'workshop');
de2f199b 177 $mform->addElement('date_time_selector', 'assessmentend', $label, array('optional' => true));
4eab2e7f
DM
178 $mform->setHelpButton('assessmentend', array('assessmentend', $label, 'workshop'));
179 $mform->setAdvanced('assessmentend');
180
6516b9e9 181 // Common module settinga, Restrict availability, Activity completion etc. ----
53fad4b9
DM
182 $features = array('groups'=>true, 'groupings'=>true, 'groupmembersonly'=>true,
183 'outcomes'=>true, 'gradecat'=>false, 'idnumber'=>false);
184
4eab2e7f
DM
185 $this->standard_coursemodule_elements();
186
6516b9e9 187 // Standard buttons, common to all modules ------------------------------------
4eab2e7f 188 $this->add_action_buttons();
6516b9e9 189 }
4eab2e7f 190
6516b9e9
DM
191 /**
192 * Prepares the form before data are set
193 *
194 * Additional wysiwyg editor are prepared here, the introeditor is prepared automatically by core
195 *
196 * @param array $data to be set
197 * @return void
198 */
199 function data_preprocessing(&$data) {
200 if ($this->current->instance) {
201 // editing an existing workshop - let us prepare the added editor elements (intro done automatically)
202 $draftitemid = file_get_submitted_draft_itemid('instructauthors');
203 $data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
204 'workshop_instructauthors', false,
205 workshop::instruction_editors_options($this->context),
206 $data['instructauthors']);
207 $data['instructauthorseditor']['format'] = $data['instructauthorsformat'];
208 $data['instructauthorseditor']['itemid'] = $draftitemid;
15d12b54
DM
209
210 $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
211 $data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
212 'workshop_instructreviewers', false,
213 workshop::instruction_editors_options($this->context),
214 $data['instructreviewers']);
215 $data['instructreviewerseditor']['format'] = $data['instructreviewersformat'];
216 $data['instructreviewerseditor']['itemid'] = $draftitemid;
6516b9e9
DM
217 } else {
218 // adding a new workshop instance
219 $draftitemid = file_get_submitted_draft_itemid('instructauthors');
220 file_prepare_draft_area($draftitemid, null, null, null); // no context, no filearea yet
221 $data['instructauthorseditor'] = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftitemid);
15d12b54
DM
222
223 $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
224 file_prepare_draft_area($draftitemid, null, null, null); // no context, no filearea yet
225 $data['instructreviewerseditor'] = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftitemid);
6516b9e9 226 }
4eab2e7f
DM
227 }
228}