forked from itamart/moodle-mod_dataform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_form.php
251 lines (212 loc) · 10.9 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?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/>.
/**
* @package mod
* @subpackage dataform
* @copyright 2012 Itamar Tzadok
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* The Dataform has been developed as an enhanced counterpart
* of Moodle's Database activity module (1.9.11+ (20110323)).
* To the extent that Dataform code corresponds to Database code,
* certain copyrights on the Database module may obtain.
*/
defined('MOODLE_INTERNAL') or die;
require_once ("$CFG->dirroot/course/moodleform_mod.php");
require_once($CFG->dirroot. '/mod/dataform/mod_class.php');
class mod_dataform_mod_form extends moodleform_mod {
protected $_df = null;
function definition() {
global $CFG;
if ($cmid = optional_param('update', 0, PARAM_INT)) {
$this->_df = new dataform(0, $cmid);
}
$mform = &$this->_form;
// buttons
//-------------------------------------------------------------------------------
$this->add_action_buttons();
// name and intro
//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
// name
$mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEANHTML);
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->setDefault('name', get_string('modulename', 'dataform'));
// intro
$this->add_intro_editor(false, get_string('intro', 'dataform'));
// timing
//-------------------------------------------------------------------------------
$mform->addElement('header', 'timinghdr', get_string('timing', 'form'));
// time available
$mform->addElement('date_time_selector', 'timeavailable', get_string('dftimeavailable', 'dataform'), array('optional'=>true));
// time due
$mform->addElement('date_time_selector', 'timedue', get_string('dftimedue', 'dataform'), array('optional'=>true));
$mform->disabledIf('timedue', 'interval', 'gt', 0);
// interval between required entries
$mform->addElement('duration', 'timeinterval', get_string('dftimeinterval', 'dataform'));
$mform->disabledIf('timeinterval', 'timeavailable[off]', 'checked');
$mform->disabledIf('timeinterval', 'timedue[off]');
// number of intervals
$mform->addElement('select', 'intervalcount', get_string('dfintervalcount', 'dataform'), array_combine(range(1,100),range(1,100)));
$mform->setDefault('intervalcount', 1);
$mform->disabledIf('intervalcount', 'timeavailable[off]', 'checked');
$mform->disabledIf('intervalcount', 'timedue[off]');
$mform->disabledIf('intervalcount', 'timeinterval', 'eq', '');
// allow late
$mform->addElement('checkbox', 'allowlate', get_string('dflateallow', 'dataform') , get_string('dflateuse', 'dataform'));
// rss
//-------------------------------------------------------------------------------
if($CFG->enablerssfeeds && $CFG->dataform_enablerssfeeds){
$mform->addElement('header', 'rssshdr', get_string('rss'));
$mform->addElement('select', 'rssarticles', get_string('numberrssarticles', 'dataform') , $countoptions);
}
// grading
//-------------------------------------------------------------------------------
$mform->addElement('header', 'gradinghdr', get_string('rating', 'rating'));
// entry rating
$mform->addElement('modgrade', 'grade', get_string('grade'));
$mform->setDefault('grade', 0);
// rating method
$grademethods = array(
0 => get_string('ratingmanual', 'dataform'),
1 => get_string('ratingsavg', 'dataform'),
2 => get_string('ratingscount', 'dataform'),
3 => get_string('ratingsmax', 'dataform'),
4 => get_string('ratingsmin', 'dataform'),
5 => get_string('ratingssum', 'dataform')
);
$mform->addElement('select', 'grademethod', get_string('gradingmethod', 'dataform'), $grademethods);
$mform->setDefault('grademethod', 0);
$mform->disabledIf('grademethod', 'grade', 'eq', 0);
// entry rating
$mform->addElement('modgrade', 'rating', get_string('rating', 'dataform'));
$mform->setDefault('rating', 0);
// Notifications
//-------------------------------------------------------------------------------
$mform->addElement('header', '', get_string('notifications'));
$grp=array();
foreach (dataform::get_notification_types() as $type => $key) {
$grp[] = &$mform->createElement('advcheckbox', $type, null, get_string("messageprovider:dataform_$type", 'dataform'), null, array(0,$key));
}
$mform->addGroup($grp, 'notificationgrp', get_string('notificationenable', 'dataform'), html_writer::empty_tag('br'), false);
// entry settings
//-------------------------------------------------------------------------------
$mform->addElement('header', 'entrysettingshdr', get_string('entrysettings', 'dataform'));
// if there is an admin limit select from dropdown
if ($CFG->dataform_maxentries > 0) {
$maxoptions = (array_combine(range(0, $CFG->dataform_maxentries),range(0, $CFG->dataform_maxentries)));
// required entries
$mform->addElement('select', 'entriesrequired', get_string('entriesrequired', 'dataform'), array(0=>get_string('none')) + $maxoptions);
// required entries to view
$mform->addElement('select', 'entriestoview', get_string('entriestoview', 'dataform'), array(0=>get_string('none')) + $maxoptions);
// max entries
$mform->addElement('select', 'maxentries', get_string('entriesmax', 'dataform'), $maxoptions);
$mform->setDefault('maxentries', $CFG->dataform_maxentries);
// no admin limit so enter any number
} else if ($CFG->dataform_maxentries == -1){
// required entries
$mform->addElement('text', 'entriesrequired', get_string('entriesrequired', 'dataform'));
$mform->addRule('entriesrequired', null, 'numeric', null, 'client');
// required entries to view
$mform->addElement('text', 'entriestoview', get_string('entriestoview', 'dataform'));
$mform->addRule('entriestoview', null, 'numeric', null, 'client');
// max entries
$mform->addElement('text', 'maxentries', get_string('entriesmax', 'dataform'));
$mform->setDefault('maxentries', -1);
$mform->addRule('maxentries', null, 'numeric', null, 'client');
// admin denies non-managers entries
} else if ($CFG->dataform_maxentries == 0){
$mform->addElement('hidden', 'admindeniesentries', 1);
// required entries
$mform->addElement('text', 'entriesrequired', get_string('entriesrequired', 'dataform'));
$mform->disabledIf('entriesrequired', 'admindeniesentries', 'eq', 1);
// required entries to view
$mform->addElement('text', 'entriestoview', get_string('entriestoview', 'dataform'));
$mform->disabledIf('entriestoview', 'admindeniesentries', 'eq', 1);
// max entries
$mform->addElement('text', 'maxentries', get_string('entriesmax', 'dataform'));
$mform->disabledIf('maxentries', 'admindeniesentries', 'eq', 1);
}
$mform->setDefault('entriesrequired', 0);
$mform->setDefault('entriestoview', 0);
// anonymous entries
if ($CFG->dataform_anonymous) {
$mform->addElement('selectyesno', 'anonymous', get_string('entriesanonymous', 'dataform'));
$mform->setDefault('anonymous', 0);
}
// group entries
$mform->addElement('selectyesno', 'grouped', get_string('groupentries', 'dataform'));
$mform->disabledIf('grouped', 'groupmode', 'eq', 0);
$mform->disabledIf('grouped', 'groupmode', 'eq', -1);
// time limit to manage an entry
$mform->addElement('text', 'timelimit', get_string('entrytimelimit', 'dataform'));
$mform->setType('timelimit', PARAM_INT);
$mform->setDefault('timelimit', -1);
$mform->addRule('timelimit', null, 'numeric', null, 'client');
$mform->addElement('selectyesno', 'approval', get_string('requireapproval', 'dataform'));
// common course elements
//-------------------------------------------------------------------------------
$this->standard_coursemodule_elements();
// add separate participants group option
//_elements has a numeric index, this code accesses the elements by name
$groups = &$mform->getElement('groupmode');
$groups->addOption(get_string('separateparticipants', 'dataform'), -1);
// buttons
//-------------------------------------------------------------------------------
$this->add_action_buttons();
}
/**
*
*/
function data_preprocessing(&$data){
if (!empty($data->notification)) {
$notification = $data->notification;
foreach (dataform::get_notification_types() as $type => $key) {
$data->$type = $notification & $key;
}
}
}
/**
*
*/
function set_data($data) {
$this->data_preprocessing($data);
parent::set_data($data);
}
/**
*
*/
function get_data($slashed = true) {
if ($data = parent::get_data($slashed)) {
if (!empty($data->timeinterval)) {
$data->timedue = $data->timeavailable + ($data->timeinterval * $data->intervalcount);
}
// Set notification
$data->notification = 0;
foreach (dataform::get_notification_types() as $type => $key) {
if (!empty($data->$type)) {
$data->notification = $data->notification | $key;
}
}
}
return $data;
}
}