1 |
efrain |
1 |
<?php
|
|
|
2 |
if (!defined('MOODLE_INTERNAL')) {
|
|
|
3 |
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
|
|
4 |
}
|
|
|
5 |
|
|
|
6 |
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
|
|
|
7 |
|
|
|
8 |
class mod_glossary_mod_form extends moodleform_mod {
|
|
|
9 |
|
|
|
10 |
function definition() {
|
|
|
11 |
global $CFG, $COURSE, $DB;
|
|
|
12 |
|
|
|
13 |
$mform =& $this->_form;
|
|
|
14 |
|
|
|
15 |
//-------------------------------------------------------------------------------
|
|
|
16 |
$mform->addElement('header', 'general', get_string('general', 'form'));
|
|
|
17 |
|
|
|
18 |
$mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
|
|
|
19 |
if (!empty($CFG->formatstringstriptags)) {
|
|
|
20 |
$mform->setType('name', PARAM_TEXT);
|
|
|
21 |
} else {
|
|
|
22 |
$mform->setType('name', PARAM_CLEANHTML);
|
|
|
23 |
}
|
|
|
24 |
$mform->addRule('name', null, 'required', null, 'client');
|
|
|
25 |
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
|
|
|
26 |
|
|
|
27 |
$this->standard_intro_elements();
|
|
|
28 |
|
|
|
29 |
if (has_capability('mod/glossary:manageentries', context_system::instance())) {
|
|
|
30 |
$mform->addElement('checkbox', 'globalglossary', get_string('isglobal', 'glossary'));
|
|
|
31 |
$mform->addHelpButton('globalglossary', 'isglobal', 'glossary');
|
|
|
32 |
|
|
|
33 |
}else{
|
|
|
34 |
$mform->addElement('hidden', 'globalglossary');
|
|
|
35 |
$mform->setType('globalglossary', PARAM_INT);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
$options = array(1=>get_string('mainglossary', 'glossary'), 0=>get_string('secondaryglossary', 'glossary'));
|
|
|
39 |
$mform->addElement('select', 'mainglossary', get_string('glossarytype', 'glossary'), $options);
|
|
|
40 |
$mform->addHelpButton('mainglossary', 'glossarytype', 'glossary');
|
|
|
41 |
$mform->setDefault('mainglossary', 0);
|
|
|
42 |
|
|
|
43 |
// ----------------------------------------------------------------------
|
|
|
44 |
$mform->addElement('header', 'entrieshdr', get_string('entries', 'glossary'));
|
|
|
45 |
|
|
|
46 |
$mform->addElement('selectyesno', 'defaultapproval', get_string('defaultapproval', 'glossary'));
|
|
|
47 |
$mform->setDefault('defaultapproval', $CFG->glossary_defaultapproval);
|
|
|
48 |
$mform->addHelpButton('defaultapproval', 'defaultapproval', 'glossary');
|
|
|
49 |
|
|
|
50 |
$mform->addElement('selectyesno', 'editalways', get_string('editalways', 'glossary'));
|
|
|
51 |
$mform->setDefault('editalways', 0);
|
|
|
52 |
$mform->addHelpButton('editalways', 'editalways', 'glossary');
|
|
|
53 |
|
|
|
54 |
$mform->addElement('selectyesno', 'allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'));
|
|
|
55 |
$mform->setDefault('allowduplicatedentries', $CFG->glossary_dupentries);
|
|
|
56 |
$mform->addHelpButton('allowduplicatedentries', 'allowduplicatedentries', 'glossary');
|
|
|
57 |
|
|
|
58 |
$mform->addElement('selectyesno', 'allowcomments', get_string('allowcomments', 'glossary'));
|
|
|
59 |
$mform->setDefault('allowcomments', $CFG->glossary_allowcomments);
|
|
|
60 |
$mform->addHelpButton('allowcomments', 'allowcomments', 'glossary');
|
|
|
61 |
|
|
|
62 |
$mform->addElement('selectyesno', 'usedynalink', get_string('usedynalink', 'glossary'));
|
|
|
63 |
$mform->setDefault('usedynalink', $CFG->glossary_linkbydefault);
|
|
|
64 |
$mform->addHelpButton('usedynalink', 'usedynalink', 'glossary');
|
|
|
65 |
|
|
|
66 |
// ----------------------------------------------------------------------
|
|
|
67 |
$mform->addElement('header', 'appearancehdr', get_string('appearance'));
|
|
|
68 |
|
|
|
69 |
// Get and update available formats.
|
|
|
70 |
$recformats = glossary_get_available_formats();
|
|
|
71 |
$formats = array();
|
|
|
72 |
foreach ($recformats as $format) {
|
|
|
73 |
$formats[$format->name] = get_string('displayformat'.$format->name, 'glossary');
|
|
|
74 |
}
|
|
|
75 |
asort($formats);
|
|
|
76 |
$mform->addElement('select', 'displayformat', get_string('displayformat', 'glossary'), $formats);
|
|
|
77 |
$mform->setDefault('displayformat', 'dictionary');
|
|
|
78 |
$mform->addHelpButton('displayformat', 'displayformat', 'glossary');
|
|
|
79 |
|
|
|
80 |
$displayformats['default'] = get_string('displayformatdefault', 'glossary');
|
|
|
81 |
$displayformats = array_merge($displayformats, $formats);
|
|
|
82 |
$mform->addElement('select', 'approvaldisplayformat', get_string('approvaldisplayformat', 'glossary'), $displayformats);
|
|
|
83 |
$mform->setDefault('approvaldisplayformat', 'default');
|
|
|
84 |
$mform->addHelpButton('approvaldisplayformat', 'approvaldisplayformat', 'glossary');
|
|
|
85 |
|
|
|
86 |
$mform->addElement('text', 'entbypage', get_string('entbypage', 'glossary'));
|
|
|
87 |
$mform->setDefault('entbypage', $this->get_default_entbypage());
|
|
|
88 |
$mform->addRule('entbypage', null, 'numeric', null, 'client');
|
|
|
89 |
$mform->setType('entbypage', PARAM_INT);
|
|
|
90 |
|
|
|
91 |
$mform->addElement('selectyesno', 'showalphabet', get_string('showalphabet', 'glossary'));
|
|
|
92 |
$mform->setDefault('showalphabet', 1);
|
|
|
93 |
$mform->addHelpButton('showalphabet', 'showalphabet', 'glossary');
|
|
|
94 |
|
|
|
95 |
$mform->addElement('selectyesno', 'showall', get_string('showall', 'glossary'));
|
|
|
96 |
$mform->setDefault('showall', 1);
|
|
|
97 |
$mform->addHelpButton('showall', 'showall', 'glossary');
|
|
|
98 |
|
|
|
99 |
$mform->addElement('selectyesno', 'showspecial', get_string('showspecial', 'glossary'));
|
|
|
100 |
$mform->setDefault('showspecial', 1);
|
|
|
101 |
$mform->addHelpButton('showspecial', 'showspecial', 'glossary');
|
|
|
102 |
|
|
|
103 |
$mform->addElement('selectyesno', 'allowprintview', get_string('allowprintview', 'glossary'));
|
|
|
104 |
$mform->setDefault('allowprintview', 1);
|
|
|
105 |
$mform->addHelpButton('allowprintview', 'allowprintview', 'glossary');
|
|
|
106 |
|
|
|
107 |
if ($CFG->enablerssfeeds && isset($CFG->glossary_enablerssfeeds) && $CFG->glossary_enablerssfeeds) {
|
|
|
108 |
//-------------------------------------------------------------------------------
|
|
|
109 |
$mform->addElement('header', 'rssheader', get_string('rss'));
|
|
|
110 |
$choices = array();
|
|
|
111 |
$choices[0] = get_string('none');
|
|
|
112 |
$choices[1] = get_string('withauthor', 'glossary');
|
|
|
113 |
$choices[2] = get_string('withoutauthor', 'glossary');
|
|
|
114 |
$mform->addElement('select', 'rsstype', get_string('rsstype', 'glossary'), $choices);
|
|
|
115 |
$mform->addHelpButton('rsstype', 'rsstype', 'glossary');
|
|
|
116 |
|
|
|
117 |
$choices = array();
|
|
|
118 |
$choices[0] = '0';
|
|
|
119 |
$choices[1] = '1';
|
|
|
120 |
$choices[2] = '2';
|
|
|
121 |
$choices[3] = '3';
|
|
|
122 |
$choices[4] = '4';
|
|
|
123 |
$choices[5] = '5';
|
|
|
124 |
$choices[10] = '10';
|
|
|
125 |
$choices[15] = '15';
|
|
|
126 |
$choices[20] = '20';
|
|
|
127 |
$choices[25] = '25';
|
|
|
128 |
$choices[30] = '30';
|
|
|
129 |
$choices[40] = '40';
|
|
|
130 |
$choices[50] = '50';
|
|
|
131 |
$mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
|
|
|
132 |
$mform->addHelpButton('rssarticles', 'rssarticles', 'glossary');
|
|
|
133 |
$mform->hideIf('rssarticles', 'rsstype', 'eq', 0);
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
//-------------------------------------------------------------------------------
|
|
|
137 |
|
|
|
138 |
$this->standard_grading_coursemodule_elements();
|
|
|
139 |
|
|
|
140 |
$this->standard_coursemodule_elements();
|
|
|
141 |
|
|
|
142 |
//-------------------------------------------------------------------------------
|
|
|
143 |
// buttons
|
|
|
144 |
$this->add_action_buttons();
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
function definition_after_data() {
|
|
|
148 |
global $COURSE, $DB;
|
|
|
149 |
|
|
|
150 |
parent::definition_after_data();
|
|
|
151 |
$mform =& $this->_form;
|
|
|
152 |
$mainglossaryel =& $mform->getElement('mainglossary');
|
|
|
153 |
$mainglossary = $DB->get_record('glossary', array('mainglossary'=>1, 'course'=>$COURSE->id));
|
|
|
154 |
if ($mainglossary && ($mainglossary->id != $mform->getElementValue('instance'))){
|
|
|
155 |
//secondary glossary, a main one already exists in this course.
|
|
|
156 |
$mainglossaryel->setValue(0);
|
|
|
157 |
$mainglossaryel->freeze();
|
|
|
158 |
$mainglossaryel->setPersistantFreeze(true);
|
|
|
159 |
} else {
|
|
|
160 |
$mainglossaryel->unfreeze();
|
|
|
161 |
$mainglossaryel->setPersistantFreeze(false);
|
|
|
162 |
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
public function data_preprocessing(&$defaultvalues) {
|
|
|
167 |
parent::data_preprocessing($defaultvalues);
|
|
|
168 |
|
|
|
169 |
// Fallsback on the default setting if 'Entries shown per page' has been left blank.
|
|
|
170 |
// This prevents the field from being required and expand its section which should not
|
|
|
171 |
// be the case if there is a default value defined.
|
|
|
172 |
if (empty($defaultvalues['entbypage']) || $defaultvalues['entbypage'] < 0) {
|
|
|
173 |
$defaultvalues['entbypage'] = $this->get_default_entbypage();
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
$suffix = $this->get_suffix();
|
|
|
177 |
$completionentriesel = 'completionentries' . $suffix;
|
|
|
178 |
$completionentriesenabledel = 'completionentriesenabled' . $suffix;
|
|
|
179 |
|
|
|
180 |
// Set up the completion checkboxes which aren't part of standard data.
|
|
|
181 |
// Tick by default if Add mode or if completion entries settings is set to 1 or more.
|
|
|
182 |
if (empty($this->_instance) || !empty($defaultvalues[$completionentriesel])) {
|
|
|
183 |
$defaultvalues[$completionentriesenabledel] = 1;
|
|
|
184 |
} else {
|
|
|
185 |
$defaultvalues[$completionentriesenabledel] = 0;
|
|
|
186 |
}
|
|
|
187 |
if (empty($defaultvalues[$completionentriesel])) {
|
|
|
188 |
$defaultvalues[$completionentriesel] = 1;
|
|
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
public function add_completion_rules() {
|
|
|
193 |
$mform = $this->_form;
|
|
|
194 |
$suffix = $this->get_suffix();
|
|
|
195 |
|
|
|
196 |
$group = [];
|
|
|
197 |
$completionentriesenabledel = 'completionentriesenabled' . $suffix;
|
|
|
198 |
$group[] =& $mform->createElement(
|
|
|
199 |
'checkbox',
|
|
|
200 |
$completionentriesenabledel,
|
|
|
201 |
'',
|
|
|
202 |
get_string('completionentries', 'glossary')
|
|
|
203 |
);
|
|
|
204 |
$completionentriesel = 'completionentries' . $suffix;
|
|
|
205 |
$group[] =& $mform->createElement('text', $completionentriesel, '', ['size' => 3]);
|
|
|
206 |
$mform->setType($completionentriesel, PARAM_INT);
|
|
|
207 |
$completionentriesgroupel = 'completionentriesgroup' . $suffix;
|
|
|
208 |
$mform->addGroup($group, $completionentriesgroupel, '', ' ', false);
|
|
|
209 |
$mform->hideIf($completionentriesel, $completionentriesenabledel, 'notchecked');
|
|
|
210 |
|
|
|
211 |
return [$completionentriesgroupel];
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
public function completion_rule_enabled($data) {
|
|
|
215 |
$suffix = $this->get_suffix();
|
|
|
216 |
return (!empty($data['completionentriesenabled' . $suffix]) && $data['completionentries' . $suffix] != 0);
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
/**
|
|
|
220 |
* Allows module to modify the data returned by form get_data().
|
|
|
221 |
* This method is also called in the bulk activity completion form.
|
|
|
222 |
*
|
|
|
223 |
* Only available on moodleform_mod.
|
|
|
224 |
*
|
|
|
225 |
* @param stdClass $data the form data to be modified.
|
|
|
226 |
*/
|
|
|
227 |
public function data_postprocessing($data) {
|
|
|
228 |
parent::data_postprocessing($data);
|
|
|
229 |
if (!empty($data->completionunlocked)) {
|
|
|
230 |
// Turn off completion settings if the checkboxes aren't ticked.
|
|
|
231 |
$suffix = $this->get_suffix();
|
|
|
232 |
$completion = $data->{'completion' . $suffix};
|
|
|
233 |
$autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC;
|
|
|
234 |
if (empty($data->{'completionentriesenabled' . $suffix}) || !$autocompletion) {
|
|
|
235 |
$data->{'completionentries' . $suffix} = 0;
|
|
|
236 |
}
|
|
|
237 |
}
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
/**
|
|
|
241 |
* Returns the default value for 'Entries shown per page'.
|
|
|
242 |
*
|
|
|
243 |
* @return int default for number of entries per page.
|
|
|
244 |
*/
|
|
|
245 |
protected function get_default_entbypage() {
|
|
|
246 |
global $CFG;
|
|
|
247 |
return !empty($CFG->glossary_entbypage) ? $CFG->glossary_entbypage : 10;
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
}
|