MDL-11082 Improved groups upgrade performance 1.8x -> 1.9; thanks Eloy for telling...
[moodle-pu.git] / mod / glossary / mod_form.php
blob5de7f0f6dac51505a593bdb16c0deacebdb56670
1 <?php
2 require_once ($CFG->dirroot.'/course/moodleform_mod.php');
4 class mod_glossary_mod_form extends moodleform_mod {
6 function definition() {
8 global $CFG, $COURSE;
9 $mform =& $this->_form;
11 //-------------------------------------------------------------------------------
12 $mform->addElement('header', 'general', get_string('general', 'form'));
14 $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
15 $mform->setType('name', PARAM_TEXT);
16 $mform->addRule('name', null, 'required', null, 'client');
18 $mform->addElement('htmleditor', 'intro', get_string('description'));
19 $mform->setType('intro', PARAM_RAW);
20 $mform->addRule('intro', get_string('required'), 'required', null, 'client');
21 $mform->setHelpButton('intro', array('writing', 'questions', 'text'), false, 'editorhelpbutton');
23 $mform->addElement('text', 'entbypage', get_string('entbypage', 'glossary'));
24 $mform->setDefault('entbypage', 10);
25 $mform->addRule('entbypage', null, 'required', null, 'client');
26 $mform->addRule('entbypage', null, 'numeric', null, 'client');
28 if (has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
29 $mform->addElement('checkbox', 'globalglossary', get_string('isglobal', 'glossary'));
30 $mform->setHelpButton('globalglossary', array('globalglossary', get_string('globalglossary', 'glossary'), 'glossary'));
32 }else{
33 $mform->addElement('hidden', 'globalglossary');
36 $options = array(1=>get_string('mainglossary', 'glossary'), 0=>get_string('secondaryglossary', 'glossary'));
37 $mform->addElement('select', 'mainglossary', get_string('glossarytype', 'glossary'), $options);
38 $mform->setHelpButton('mainglossary', array('mainglossary', get_string('mainglossary', 'glossary'), 'glossary'));
39 $mform->setDefault('mainglossary', 0);
41 $mform->addElement('selectyesno', 'allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'));
42 $mform->setDefault('allowduplicatedentries', $CFG->glossary_dupentries);
43 $mform->setHelpButton('allowduplicatedentries', array('allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'), 'glossary'));
45 $mform->addElement('selectyesno', 'allowcomments', get_string('allowcomments', 'glossary'));
46 $mform->setDefault('allowcomments', $CFG->glossary_allowcomments);
47 $mform->setHelpButton('allowcomments', array('allowcomments', get_string('allowcomments', 'glossary'), 'glossary'));
49 $mform->addElement('selectyesno', 'allowprintview', get_string('allowprintview', 'glossary'));
50 $mform->setDefault('allowprintview', 1);
51 $mform->setHelpButton('allowprintview', array('allowprintview', get_string('allowprintview', 'glossary'), 'glossary'));
53 $mform->addElement('selectyesno', 'usedynalink', get_string('usedynalink', 'glossary'));
54 $mform->setDefault('usedynalink', $CFG->glossary_linkbydefault);
55 $mform->setHelpButton('usedynalink', array('usedynalink', get_string('usedynalink', 'glossary'), 'glossary'));
57 $mform->addElement('selectyesno', 'defaultapproval', get_string('defaultapproval', 'glossary'));
58 $mform->setDefault('defaultapproval', $CFG->glossary_defaultapproval);
59 $mform->setHelpButton('defaultapproval', array('defaultapproval', get_string('defaultapproval', 'glossary'), 'glossary'));
61 //get and update available formats
62 $recformats = glossary_get_available_formats();
64 $formats = array();
66 //Take names
67 foreach ($recformats as $format) {
68 $formats[$format->name] = get_string('displayformat'.$format->name, 'glossary');
70 //Sort it
71 asort($formats);
72 $mform->addElement('select', 'displayformat', get_string('displayformat', 'glossary'), $formats);
73 $mform->setDefault('displayformat', 'dictionary');
74 $mform->setHelpButton('displayformat', array('displayformat', get_string('displayformat', 'glossary'), 'glossary'));
76 $mform->addElement('selectyesno', 'showspecial', get_string('showspecial', 'glossary'));
77 $mform->setDefault('showspecial', 1);
78 $mform->setHelpButton('showspecial', array('shows', get_string('showspecial', 'glossary'), 'glossary'));
80 $mform->addElement('selectyesno', 'showalphabet', get_string('showalphabet', 'glossary'));
81 $mform->setDefault('showalphabet', 1);
82 $mform->setHelpButton('showalphabet', array('shows', get_string('showalphabet', 'glossary'), 'glossary'));
84 $mform->addElement('selectyesno', 'showall', get_string('showall', 'glossary'));
85 $mform->setDefault('showall', 1);
86 $mform->setHelpButton('showall', array('shows', get_string('showall', 'glossary'), 'glossary'));
88 $mform->addElement('selectyesno', 'editalways', get_string('editalways', 'glossary'));
89 $mform->setDefault('editalways', 0);
90 $mform->setHelpButton('editalways', array('editalways', get_string('editalways', 'glossary'), 'glossary'));
92 if ($CFG->enablerssfeeds && isset($CFG->glossary_enablerssfeeds) && $CFG->glossary_enablerssfeeds) {
93 //-------------------------------------------------------------------------------
94 $mform->addElement('header', '', get_string('rss'));
95 $choices = array();
96 $choices[0] = get_string('none');
97 $choices[1] = get_string('withauthor', 'glossary');
98 $choices[2] = get_string('withoutauthor', 'glossary');
99 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
100 $mform->setHelpButton('rsstype', array('rsstype', get_string('rsstype'), 'glossary'));
102 $choices = array();
103 $choices[0] = '0';
104 $choices[1] = '1';
105 $choices[2] = '2';
106 $choices[3] = '3';
107 $choices[4] = '4';
108 $choices[5] = '5';
109 $choices[10] = '10';
110 $choices[15] = '15';
111 $choices[20] = '20';
112 $choices[25] = '25';
113 $choices[30] = '30';
114 $choices[40] = '40';
115 $choices[50] = '50';
116 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
117 $mform->setHelpButton('rssarticles', array('rssarticles', get_string('rssarticles'), 'glossary'));
118 $mform->disabledIf('rssarticles', 'rsstype', 'eq', 0);
121 //-------------------------------------------------------------------------------
122 $mform->addElement('header', '', get_string('grade'));
123 $mform->addElement('checkbox', 'userating', get_string('allowratings', 'glossary') , get_string('ratingsuse', 'glossary'));
125 $options=array();
126 $options[2] = get_string('ratingonlyteachers', 'glossary', moodle_strtolower($COURSE->teachers));
127 $options[1] = get_string('ratingeveryone', 'glossary');
128 $mform->addElement('select', 'assessed', get_string('users'), $options);
129 $mform->disabledIf('assessed', 'userating');
131 $mform->addElement('modgrade', 'scale', get_string('grade'), false);
132 $mform->disabledIf('scale', 'userating');
134 $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'glossary'));
135 $mform->disabledIf('ratingtime', 'userating');
137 $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
138 $mform->disabledIf('assesstimestart', 'userating');
139 $mform->disabledIf('assesstimestart', 'ratingtime');
141 $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
142 $mform->disabledIf('assesstimefinish', 'userating');
143 $mform->disabledIf('assesstimefinish', 'ratingtime');
145 //-------------------------------------------------------------------------------
146 $this->standard_coursemodule_elements(array('groups'=>false));
148 //-------------------------------------------------------------------------------
149 // buttons
150 $this->add_action_buttons();
153 function definition_after_data() {
154 parent::definition_after_data();
155 global $COURSE;
156 $mform =& $this->_form;
157 $mainglossaryel =& $mform->getElement('mainglossary');
158 $mainglossary = get_record('glossary', 'mainglossary', 1, 'course', $COURSE->id);
159 if ($mainglossary && ($mainglossary->id != $mform->getElementValue('instance'))){
160 //secondary glossary, a main one already exists in this course.
161 $mainglossaryel->setValue(0);
162 $mainglossaryel->freeze();
163 $mainglossaryel->setPersistantFreeze(true);
164 } else {
165 $mainglossaryel->unfreeze();
166 $mainglossaryel->setPersistantFreeze(false);
171 function data_preprocessing(&$default_values){
172 if (empty($default_values['scale'])){
173 $default_values['assessed'] = 0;
176 if (empty($default_values['assessed'])){
177 $default_values['userating'] = 0;
178 $default_values['ratingtime'] = 0;
179 } else {
180 $default_values['userating'] = 1;
181 $default_values['ratingtime']=
182 ($default_values['assesstimestart'] && $default_values['assesstimefinish']) ? 1 : 0;