forked from moodleou/moodle-mod_ouwiki
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmod_form.php
195 lines (163 loc) · 9.22 KB
/
mod_form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** Make sure this isn't being directly accessed */
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/course/moodleform_mod.php');
require_once($CFG->dirroot.'/mod/ouwiki/locallib.php');
class mod_ouwiki_mod_form extends moodleform_mod {
public function definition() {
global $CFG, $COURSE;
$mform =& $this->_form;
$data = $this->_customdata['data'] ?? null;
$mform->addElement('header', 'general', get_string('general', 'form'));
// Name and intro
$mform->addElement('text', 'name', get_string('name'), array('size' => '64'));
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', get_string('required'), 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$this->standard_intro_elements(get_string('wikiintro', 'wiki'));
$mform->addElement('header', 'wikifieldset', get_string('wikisettings', 'wiki'));
// Subwikis
$subwikisoptions = array();
$subwikisoptions[OUWIKI_SUBWIKIS_SINGLE] = get_string('subwikis_single', 'ouwiki');
$subwikisoptions[OUWIKI_SUBWIKIS_GROUPS] = get_string('subwikis_groups', 'ouwiki');
$subwikisoptions[OUWIKI_SUBWIKIS_INDIVIDUAL] = get_string('subwikis_individual', 'ouwiki');
$mform->addElement('select', 'subwikis', get_string("subwikis", "ouwiki"), $subwikisoptions);
$mform->addHelpButton('subwikis', 'subwikis', 'ouwiki');
// Annotation
$annotationoptions = array('0' => get_string('no'), '1' => get_string('yes'));
$mform->addElement('select', 'annotation', get_string('annotationsystem', 'ouwiki'), $annotationoptions);
$mform->addHelpButton('annotation', 'annotationsystem', 'ouwiki');
// Editing timeout
$timeoutoptions = array();
$timeoutoptions[0] = get_string('timeout_none', 'ouwiki');
$timeoutoptions[15*60] = get_string('numminutes', '', 15);
$timeoutoptions[30*60] = get_string('numminutes', '', 30);
$timeoutoptions[60*60] = get_string('numminutes', '', 60);
$timeoutoptions[120*60] = get_string('numhours', '', 2);
$timeoutoptions[240*60] = get_string('numhours', '', 4);
if (debugging('', DEBUG_DEVELOPER)) {
// This is not a language string because it's only for developer
// debugging, lots of which requires English...
$timeoutoptions[3*60] = '3 minutes (for testing)';
}
$mform->addElement('select', 'timeout', get_string("timeout", "ouwiki"), $timeoutoptions);
$mform->addHelpButton('timeout', 'timeout', 'ouwiki');
// Read-only controls.
$mform->addElement('date_selector', 'editbegin', get_string('editbegin', 'ouwiki'), array('optional' => true));
$mform->addHelpButton('editbegin', 'editbegin', 'ouwiki');
$mform->addElement('date_selector', 'editend', get_string('editend', 'ouwiki'), array('optional' => true));
$mform->addHelpButton('editend', 'editend', 'ouwiki');
// Display any template usage warning messages.
if ((!empty($this->current->id)) && (ouwiki_has_subwikis($this->current->id))) {
$mform->addElement('static', 'name1', get_string('note', 'ouwiki'), get_string('subwikiexist', 'ouwiki'));
}
if (isset($this->current->template)) {
$mform->addElement('static', 'name2', get_string('note', 'ouwiki'), get_string('templatefileexists', 'ouwiki',
$this->current->template));
}
// Template - previously on creation, but allow to add now add anytime.
$filepickeroptions = array();
$filepickeroptions['accepted_types'] = array('.xml', '.zip');
$filepickeroptions['maxbytes'] = $COURSE->maxbytes;
$mform->addElement('filepicker', 'template_file', get_string('template', 'ouwiki'), null, $filepickeroptions);
$mform->addHelpButton('template_file', 'template', 'ouwiki');
$lockstartpagesoptions = array('0' => get_string('no'), '1' => get_string('yes'));
$mform->addElement('select', 'lockstartpages', get_string('lockstartpages', 'ouwiki'), $lockstartpagesoptions);
$mform->addHelpButton('lockstartpages', 'lockstartpages', 'ouwiki');
// Wordcount
$wordcountoptions = array('0' => get_string('no'), '1' => get_string('yes'));
$mform->addElement('select', 'enablewordcount', get_string('showwordcounts', 'ouwiki'), $wordcountoptions);
$mform->addHelpButton('enablewordcount', 'showwordcounts', 'ouwiki');
$mform->setDefault('enablewordcount', 1);
// Enable the allow import course wiki pages into this wiki.
$mform->addElement('checkbox', 'allowimport', get_string('allowimport', 'ouwiki', 0));
$mform->addHelpButton('allowimport', 'allowimport', 'ouwiki');
$this->standard_grading_coursemodule_elements();
// Standard stuff
$this->standard_coursemodule_elements();
// Disable the 'completion with grade' if grading is turned off
if ($mform->elementExists('completionusegrade')) {
$mform->disabledIf('completionusegrade', 'grade', 'eq', 0);
}
$this->add_action_buttons();
$this->set_data($data);
}
public function add_completion_rules() {
$mform =& $this->_form;
$group = array();
$group[] =& $mform->createElement('checkbox', 'completionpagesenabled', ' ', get_string('completionpages', 'ouwiki'));
$group[] =& $mform->createElement('text', 'completionpages', ' ', array('size' => 3));
$mform->setType('completionpages', PARAM_INT);
$mform->addGroup($group, 'completionpagesgroup', get_string('completionpagesgroup', 'ouwiki'), array(' '), false);
$mform->disabledIf('completionpages', 'completionpagesenabled', 'notchecked');
$group = array();
$group[] =& $mform->createElement('checkbox', 'completioneditsenabled', ' ', get_string('completionedits', 'ouwiki'));
$group[] =& $mform->createElement('text', 'completionedits', ' ', array('size' => 3));
$mform->setType('completionedits', PARAM_INT);
$mform->addGroup($group, 'completioneditsgroup', get_string('completioneditsgroup', 'ouwiki'), array(' '), false);
$mform->disabledIf('completionedits', 'completioneditsenabled', 'notchecked');
return array('completionpagesgroup', 'completioneditsgroup');
}
public function completion_rule_enabled($data) {
return
((!empty($data['completionpagesenabled']) && $data['completionpages'] != 0)) ||
((!empty($data['completioneditsenabled']) && $data['completionedits'] != 0));
}
public function get_data() {
$data = parent::get_data();
if (!$data) {
return false;
}
// Turn off completion settings if the checkboxes aren't ticked
if (!empty($data->completionunlocked)) {
$autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
if (empty($data->completionpagesenabled) || !$autocompletion) {
$data->completionpages = 0;
}
if (empty($data->completioneditsenabled) || !$autocompletion) {
$data->completionedits = 0;
}
}
if (empty($data->allowimport)) {
$data->allowimport = 0;
}
return $data;
}
public function data_preprocessing(&$default_values) {
// Set up the completion checkboxes which aren't part of standard data.
// We also make the default value (if you turn on the checkbox) for those
// numbers to be 1, this will not apply unless checkbox is ticked.
$default_values['completionpagesenabled'] = !empty($default_values['completionpages']) ? 1 : 0;
if (empty($default_values['completionpages'])) {
$default_values['completionpages'] = 1;
}
$default_values['completioneditsenabled'] = !empty($default_values['completionedits']) ? 1 : 0;
if (empty($default_values['completionedits'])) {
$default_values['completionedits'] = 1;
}
}
public function validation($data, $files) {
$errors = parent::validation($data, $files);
if ( (($data['subwikis'] == 0) || ($data['subwikis'] == 2) ) && ($data['groupmode'] > 0) ) {
$errors['groupmode'] = get_string('errorcoursesubwiki', 'ouwiki');
}
if ( ($data['subwikis'] == 1) && ($data['groupmode'] == 0) ) {
$errors['groupmode'] = get_string('errorgroupssubwiki', 'ouwiki');
}
return $errors;
}
}