2 require_once ($CFG->dirroot
.'/course/moodleform_mod.php');
4 class mod_glossary_mod_form
extends moodleform_mod
{
6 function definition() {
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 if (!empty($CFG->formatstringstriptags
)) {
16 $mform->setType('name', PARAM_TEXT
);
18 $mform->setType('name', PARAM_CLEAN
);
20 $mform->addRule('name', null, 'required', null, 'client');
22 $mform->addElement('htmleditor', 'intro', get_string('description'));
23 $mform->setType('intro', PARAM_RAW
);
24 $mform->addRule('intro', get_string('required'), 'required', null, 'client');
25 $mform->setHelpButton('intro', array('writing', 'questions', 'text'), false, 'editorhelpbutton');
27 $mform->addElement('text', 'entbypage', get_string('entbypage', 'glossary'));
28 $mform->setDefault('entbypage', 10);
29 $mform->addRule('entbypage', null, 'required', null, 'client');
30 $mform->addRule('entbypage', null, 'numeric', null, 'client');
32 if (has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_SYSTEM
))) {
33 $mform->addElement('checkbox', 'globalglossary', get_string('isglobal', 'glossary'));
34 $mform->setHelpButton('globalglossary', array('globalglossary', get_string('globalglossary', 'glossary'), 'glossary'));
37 $mform->addElement('hidden', 'globalglossary');
40 $options = array(1=>get_string('mainglossary', 'glossary'), 0=>get_string('secondaryglossary', 'glossary'));
41 $mform->addElement('select', 'mainglossary', get_string('glossarytype', 'glossary'), $options);
42 $mform->setHelpButton('mainglossary', array('mainglossary', get_string('mainglossary', 'glossary'), 'glossary'));
43 $mform->setDefault('mainglossary', 0);
45 $mform->addElement('selectyesno', 'allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'));
46 $mform->setDefault('allowduplicatedentries', $CFG->glossary_dupentries
);
47 $mform->setHelpButton('allowduplicatedentries', array('allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'), 'glossary'));
49 $mform->addElement('selectyesno', 'allowcomments', get_string('allowcomments', 'glossary'));
50 $mform->setDefault('allowcomments', $CFG->glossary_allowcomments
);
51 $mform->setHelpButton('allowcomments', array('allowcomments', get_string('allowcomments', 'glossary'), 'glossary'));
53 $mform->addElement('selectyesno', 'allowprintview', get_string('allowprintview', 'glossary'));
54 $mform->setDefault('allowprintview', 1);
55 $mform->setHelpButton('allowprintview', array('allowprintview', get_string('allowprintview', 'glossary'), 'glossary'));
57 $mform->addElement('selectyesno', 'usedynalink', get_string('usedynalink', 'glossary'));
58 $mform->setDefault('usedynalink', $CFG->glossary_linkbydefault
);
59 $mform->setHelpButton('usedynalink', array('usedynalink', get_string('usedynalink', 'glossary'), 'glossary'));
61 $mform->addElement('selectyesno', 'defaultapproval', get_string('defaultapproval', 'glossary'));
62 $mform->setDefault('defaultapproval', $CFG->glossary_defaultapproval
);
63 $mform->setHelpButton('defaultapproval', array('defaultapproval', get_string('defaultapproval', 'glossary'), 'glossary'));
65 //get and update available formats
66 $recformats = glossary_get_available_formats();
71 foreach ($recformats as $format) {
72 $formats[$format->name
] = get_string('displayformat'.$format->name
, 'glossary');
76 $mform->addElement('select', 'displayformat', get_string('displayformat', 'glossary'), $formats);
77 $mform->setDefault('displayformat', 'dictionary');
78 $mform->setHelpButton('displayformat', array('displayformat', get_string('displayformat', 'glossary'), 'glossary'));
80 $mform->addElement('selectyesno', 'showspecial', get_string('showspecial', 'glossary'));
81 $mform->setDefault('showspecial', 1);
82 $mform->setHelpButton('showspecial', array('shows', get_string('showspecial', 'glossary'), 'glossary'));
84 $mform->addElement('selectyesno', 'showalphabet', get_string('showalphabet', 'glossary'));
85 $mform->setDefault('showalphabet', 1);
86 $mform->setHelpButton('showalphabet', array('shows', get_string('showalphabet', 'glossary'), 'glossary'));
88 $mform->addElement('selectyesno', 'showall', get_string('showall', 'glossary'));
89 $mform->setDefault('showall', 1);
90 $mform->setHelpButton('showall', array('shows', get_string('showall', 'glossary'), 'glossary'));
92 $mform->addElement('selectyesno', 'editalways', get_string('editalways', 'glossary'));
93 $mform->setDefault('editalways', 0);
94 $mform->setHelpButton('editalways', array('editalways', get_string('editalways', 'glossary'), 'glossary'));
96 if ($CFG->enablerssfeeds
&& isset($CFG->glossary_enablerssfeeds
) && $CFG->glossary_enablerssfeeds
) {
97 //-------------------------------------------------------------------------------
98 $mform->addElement('header', '', get_string('rss'));
100 $choices[0] = get_string('none');
101 $choices[1] = get_string('withauthor', 'glossary');
102 $choices[2] = get_string('withoutauthor', 'glossary');
103 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
104 $mform->setHelpButton('rsstype', array('rsstype', get_string('rsstype'), 'glossary'));
120 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
121 $mform->setHelpButton('rssarticles', array('rssarticles', get_string('rssarticles'), 'glossary'));
122 $mform->disabledIf('rssarticles', 'rsstype', 'eq', 0);
125 //-------------------------------------------------------------------------------
126 $mform->addElement('header', '', get_string('grade'));
127 $mform->addElement('checkbox', 'userating', get_string('allowratings', 'glossary') , get_string('ratingsuse', 'glossary'));
130 $options[2] = get_string('ratingonlyteachers', 'glossary', moodle_strtolower($COURSE->teachers
));
131 $options[1] = get_string('ratingeveryone', 'glossary');
132 $mform->addElement('select', 'assessed', get_string('users'), $options);
133 $mform->disabledIf('assessed', 'userating');
135 $mform->addElement('modgrade', 'scale', get_string('grade'), false);
136 $mform->disabledIf('scale', 'userating');
138 $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'glossary'));
139 $mform->disabledIf('ratingtime', 'userating');
141 $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
142 $mform->disabledIf('assesstimestart', 'userating');
143 $mform->disabledIf('assesstimestart', 'ratingtime');
145 $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
146 $mform->disabledIf('assesstimefinish', 'userating');
147 $mform->disabledIf('assesstimefinish', 'ratingtime');
149 //-------------------------------------------------------------------------------
150 $this->standard_coursemodule_elements(array('groups'=>false, 'groupmembersonly'=>true));
152 //-------------------------------------------------------------------------------
154 $this->add_action_buttons();
157 function definition_after_data() {
158 parent
::definition_after_data();
160 $mform =& $this->_form
;
161 $mainglossaryel =& $mform->getElement('mainglossary');
162 $mainglossary = get_record('glossary', 'mainglossary', 1, 'course', $COURSE->id
);
163 if ($mainglossary && ($mainglossary->id
!= $mform->getElementValue('instance'))){
164 //secondary glossary, a main one already exists in this course.
165 $mainglossaryel->setValue(0);
166 $mainglossaryel->freeze();
167 $mainglossaryel->setPersistantFreeze(true);
169 $mainglossaryel->unfreeze();
170 $mainglossaryel->setPersistantFreeze(false);
175 function data_preprocessing(&$default_values){
176 if (empty($default_values['scale'])){
177 $default_values['assessed'] = 0;
180 if (empty($default_values['assessed'])){
181 $default_values['userating'] = 0;
182 $default_values['ratingtime'] = 0;
184 $default_values['userating'] = 1;
185 $default_values['ratingtime']=
186 ($default_values['assesstimestart'] && $default_values['assesstimefinish']) ?
1 : 0;