forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_form.php
229 lines (185 loc) · 10.3 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
<?php
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
class mod_glossary_mod_form extends moodleform_mod {
function definition() {
global $CFG, $COURSE, $DB;
$mform =& $this->_form;
//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
$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->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$this->standard_intro_elements();
if (has_capability('mod/glossary:manageentries', context_system::instance())) {
$mform->addElement('checkbox', 'globalglossary', get_string('isglobal', 'glossary'));
$mform->addHelpButton('globalglossary', 'isglobal', 'glossary');
}else{
$mform->addElement('hidden', 'globalglossary');
$mform->setType('globalglossary', PARAM_INT);
}
$options = array(1=>get_string('mainglossary', 'glossary'), 0=>get_string('secondaryglossary', 'glossary'));
$mform->addElement('select', 'mainglossary', get_string('glossarytype', 'glossary'), $options);
$mform->addHelpButton('mainglossary', 'glossarytype', 'glossary');
$mform->setDefault('mainglossary', 0);
// ----------------------------------------------------------------------
$mform->addElement('header', 'entrieshdr', get_string('entries', 'glossary'));
$mform->addElement('selectyesno', 'defaultapproval', get_string('defaultapproval', 'glossary'));
$mform->setDefault('defaultapproval', $CFG->glossary_defaultapproval);
$mform->addHelpButton('defaultapproval', 'defaultapproval', 'glossary');
$mform->addElement('selectyesno', 'editalways', get_string('editalways', 'glossary'));
$mform->setDefault('editalways', 0);
$mform->addHelpButton('editalways', 'editalways', 'glossary');
$mform->addElement('selectyesno', 'allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'));
$mform->setDefault('allowduplicatedentries', $CFG->glossary_dupentries);
$mform->addHelpButton('allowduplicatedentries', 'allowduplicatedentries', 'glossary');
$mform->addElement('selectyesno', 'allowcomments', get_string('allowcomments', 'glossary'));
$mform->setDefault('allowcomments', $CFG->glossary_allowcomments);
$mform->addHelpButton('allowcomments', 'allowcomments', 'glossary');
$mform->addElement('selectyesno', 'usedynalink', get_string('usedynalink', 'glossary'));
$mform->setDefault('usedynalink', $CFG->glossary_linkbydefault);
$mform->addHelpButton('usedynalink', 'usedynalink', 'glossary');
// ----------------------------------------------------------------------
$mform->addElement('header', 'appearancehdr', get_string('appearance'));
// Get and update available formats.
$recformats = glossary_get_available_formats();
$formats = array();
foreach ($recformats as $format) {
$formats[$format->name] = get_string('displayformat'.$format->name, 'glossary');
}
asort($formats);
$mform->addElement('select', 'displayformat', get_string('displayformat', 'glossary'), $formats);
$mform->setDefault('displayformat', 'dictionary');
$mform->addHelpButton('displayformat', 'displayformat', 'glossary');
$displayformats['default'] = get_string('displayformatdefault', 'glossary');
$displayformats = array_merge($displayformats, $formats);
$mform->addElement('select', 'approvaldisplayformat', get_string('approvaldisplayformat', 'glossary'), $displayformats);
$mform->setDefault('approvaldisplayformat', 'default');
$mform->addHelpButton('approvaldisplayformat', 'approvaldisplayformat', 'glossary');
$mform->addElement('text', 'entbypage', get_string('entbypage', 'glossary'));
$mform->setDefault('entbypage', $this->get_default_entbypage());
$mform->addRule('entbypage', null, 'numeric', null, 'client');
$mform->setType('entbypage', PARAM_INT);
$mform->addElement('selectyesno', 'showalphabet', get_string('showalphabet', 'glossary'));
$mform->setDefault('showalphabet', 1);
$mform->addHelpButton('showalphabet', 'showalphabet', 'glossary');
$mform->addElement('selectyesno', 'showall', get_string('showall', 'glossary'));
$mform->setDefault('showall', 1);
$mform->addHelpButton('showall', 'showall', 'glossary');
$mform->addElement('selectyesno', 'showspecial', get_string('showspecial', 'glossary'));
$mform->setDefault('showspecial', 1);
$mform->addHelpButton('showspecial', 'showspecial', 'glossary');
$mform->addElement('selectyesno', 'allowprintview', get_string('allowprintview', 'glossary'));
$mform->setDefault('allowprintview', 1);
$mform->addHelpButton('allowprintview', 'allowprintview', 'glossary');
if ($CFG->enablerssfeeds && isset($CFG->glossary_enablerssfeeds) && $CFG->glossary_enablerssfeeds) {
//-------------------------------------------------------------------------------
$mform->addElement('header', 'rssheader', get_string('rss'));
$choices = array();
$choices[0] = get_string('none');
$choices[1] = get_string('withauthor', 'glossary');
$choices[2] = get_string('withoutauthor', 'glossary');
$mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
$mform->addHelpButton('rsstype', 'rsstype', 'glossary');
$choices = array();
$choices[0] = '0';
$choices[1] = '1';
$choices[2] = '2';
$choices[3] = '3';
$choices[4] = '4';
$choices[5] = '5';
$choices[10] = '10';
$choices[15] = '15';
$choices[20] = '20';
$choices[25] = '25';
$choices[30] = '30';
$choices[40] = '40';
$choices[50] = '50';
$mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
$mform->addHelpButton('rssarticles', 'rssarticles', 'glossary');
$mform->disabledIf('rssarticles', 'rsstype', 'eq', 0);
}
//-------------------------------------------------------------------------------
$this->standard_grading_coursemodule_elements();
$this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
}
function definition_after_data() {
global $COURSE, $DB;
parent::definition_after_data();
$mform =& $this->_form;
$mainglossaryel =& $mform->getElement('mainglossary');
$mainglossary = $DB->get_record('glossary', array('mainglossary'=>1, 'course'=>$COURSE->id));
if ($mainglossary && ($mainglossary->id != $mform->getElementValue('instance'))){
//secondary glossary, a main one already exists in this course.
$mainglossaryel->setValue(0);
$mainglossaryel->freeze();
$mainglossaryel->setPersistantFreeze(true);
} else {
$mainglossaryel->unfreeze();
$mainglossaryel->setPersistantFreeze(false);
}
}
function data_preprocessing(&$default_values){
parent::data_preprocessing($default_values);
// Fallsback on the default setting if 'Entries shown per page' has been left blank.
// This prevents the field from being required and expand its section which should not
// be the case if there is a default value defined.
if (empty($default_values['entbypage']) || $default_values['entbypage'] < 0) {
$default_values['entbypage'] = $this->get_default_entbypage();
}
// 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['completionentriesenabled']=
!empty($default_values['completionentries']) ? 1 : 0;
if (empty($default_values['completionentries'])) {
$default_values['completionentries']=1;
}
}
function add_completion_rules() {
$mform =& $this->_form;
$group=array();
$group[] =& $mform->createElement('checkbox', 'completionentriesenabled', '', get_string('completionentries','glossary'));
$group[] =& $mform->createElement('text', 'completionentries', '', array('size'=>3));
$mform->setType('completionentries', PARAM_INT);
$mform->addGroup($group, 'completionentriesgroup', get_string('completionentriesgroup','glossary'), array(' '), false);
$mform->disabledIf('completionentries','completionentriesenabled','notchecked');
return array('completionentriesgroup');
}
function completion_rule_enabled($data) {
return (!empty($data['completionentriesenabled']) && $data['completionentries']!=0);
}
function get_data() {
$data = parent::get_data();
if (!$data) {
return false;
}
if (!empty($data->completionunlocked)) {
// Turn off completion settings if the checkboxes aren't ticked
$autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC;
if (empty($data->completionentriesenabled) || !$autocompletion) {
$data->completionentries = 0;
}
}
return $data;
}
/**
* Returns the default value for 'Entries shown per page'.
*
* @return int default for number of entries per page.
*/
protected function get_default_entbypage() {
global $CFG;
return !empty($CFG->glossary_entbypage) ? $CFG->glossary_entbypage : 10;
}
}