Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/glossary/mod_form.php
Go to the documentation of this file.
00001 <?php
00002 if (!defined('MOODLE_INTERNAL')) {
00003     die('Direct access to this script is forbidden.');    
00004 }
00005 
00006 require_once ($CFG->dirroot.'/course/moodleform_mod.php');
00007 
00008 class mod_glossary_mod_form extends moodleform_mod {
00009 
00010     function definition() {
00011         global $CFG, $COURSE, $DB;
00012 
00013         $mform    =& $this->_form;
00014 
00015 //-------------------------------------------------------------------------------
00016         $mform->addElement('header', 'general', get_string('general', 'form'));
00017 
00018         $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
00019         if (!empty($CFG->formatstringstriptags)) {
00020             $mform->setType('name', PARAM_TEXT);
00021         } else {
00022             $mform->setType('name', PARAM_CLEANHTML);
00023         }
00024         $mform->addRule('name', null, 'required', null, 'client');
00025 
00026         $this->add_intro_editor(true);
00027 
00028         $mform->addElement('text', 'entbypage', get_string('entbypage', 'glossary'));
00029         $mform->setDefault('entbypage', 10);
00030         $mform->addRule('entbypage', null, 'required', null, 'client');
00031         $mform->addRule('entbypage', null, 'numeric', null, 'client');
00032 
00033         if (has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_SYSTEM))) {
00034             $mform->addElement('checkbox', 'globalglossary', get_string('isglobal', 'glossary'));
00035             $mform->addHelpButton('globalglossary', 'isglobal', 'glossary');
00036 
00037         }else{
00038             $mform->addElement('hidden', 'globalglossary');
00039             $mform->setType('globalglossary', PARAM_INT);
00040         }
00041 
00042         $options = array(1=>get_string('mainglossary', 'glossary'), 0=>get_string('secondaryglossary', 'glossary'));
00043         $mform->addElement('select', 'mainglossary', get_string('glossarytype', 'glossary'), $options);
00044         $mform->addHelpButton('mainglossary', 'glossarytype', 'glossary');
00045         $mform->setDefault('mainglossary', 0);
00046 
00047         $mform->addElement('selectyesno', 'allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'));
00048         $mform->setDefault('allowduplicatedentries', $CFG->glossary_dupentries);
00049         $mform->addHelpButton('allowduplicatedentries', 'allowduplicatedentries', 'glossary');
00050 
00051         $mform->addElement('selectyesno', 'allowcomments', get_string('allowcomments', 'glossary'));
00052         $mform->setDefault('allowcomments', $CFG->glossary_allowcomments);
00053         $mform->addHelpButton('allowcomments', 'allowcomments', 'glossary');
00054 
00055         $mform->addElement('selectyesno', 'allowprintview', get_string('allowprintview', 'glossary'));
00056         $mform->setDefault('allowprintview', 1);
00057         $mform->addHelpButton('allowprintview', 'allowprintview', 'glossary');
00058 
00059         $mform->addElement('selectyesno', 'usedynalink', get_string('usedynalink', 'glossary'));
00060         $mform->setDefault('usedynalink', $CFG->glossary_linkbydefault);
00061         $mform->addHelpButton('usedynalink', 'usedynalink', 'glossary');
00062 
00063         $mform->addElement('selectyesno', 'defaultapproval', get_string('defaultapproval', 'glossary'));
00064         $mform->setDefault('defaultapproval', $CFG->glossary_defaultapproval);
00065         $mform->addHelpButton('defaultapproval', 'defaultapproval', 'glossary');
00066 
00067         //get and update available formats
00068         $recformats = glossary_get_available_formats();
00069 
00070         $formats = array();
00071 
00072         //Take names
00073         foreach ($recformats as $format) {
00074            $formats[$format->name] = get_string('displayformat'.$format->name, 'glossary');
00075         }
00076         //Sort it
00077         asort($formats);
00078         $mform->addElement('select', 'displayformat', get_string('displayformat', 'glossary'), $formats);
00079         $mform->setDefault('displayformat', 'dictionary');
00080         $mform->addHelpButton('displayformat', 'displayformat', 'glossary');
00081 
00082         $mform->addElement('selectyesno', 'showspecial', get_string('showspecial', 'glossary'));
00083         $mform->setDefault('showspecial', 1);
00084         $mform->addHelpButton('showspecial', 'showspecial', 'glossary');
00085 
00086         $mform->addElement('selectyesno', 'showalphabet', get_string('showalphabet', 'glossary'));
00087         $mform->setDefault('showalphabet', 1);
00088         $mform->addHelpButton('showalphabet', 'showalphabet', 'glossary');
00089 
00090         $mform->addElement('selectyesno', 'showall', get_string('showall', 'glossary'));
00091         $mform->setDefault('showall', 1);
00092         $mform->addHelpButton('showall', 'showall', 'glossary');
00093 
00094         $mform->addElement('selectyesno', 'editalways', get_string('editalways', 'glossary'));
00095         $mform->setDefault('editalways', 0);
00096         $mform->addHelpButton('editalways', 'editalways', 'glossary');
00097 
00098         if ($CFG->enablerssfeeds && isset($CFG->glossary_enablerssfeeds) && $CFG->glossary_enablerssfeeds) {
00099 //-------------------------------------------------------------------------------
00100             $mform->addElement('header', '', get_string('rss'));
00101             $choices = array();
00102             $choices[0] = get_string('none');
00103             $choices[1] = get_string('withauthor', 'glossary');
00104             $choices[2] = get_string('withoutauthor', 'glossary');
00105             $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
00106             $mform->addHelpButton('rsstype', 'rsstype', 'glossary');
00107 
00108             $choices = array();
00109             $choices[0] = '0';
00110             $choices[1] = '1';
00111             $choices[2] = '2';
00112             $choices[3] = '3';
00113             $choices[4] = '4';
00114             $choices[5] = '5';
00115             $choices[10] = '10';
00116             $choices[15] = '15';
00117             $choices[20] = '20';
00118             $choices[25] = '25';
00119             $choices[30] = '30';
00120             $choices[40] = '40';
00121             $choices[50] = '50';
00122             $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
00123             $mform->addHelpButton('rssarticles', 'rssarticles', 'glossary');
00124             $mform->disabledIf('rssarticles', 'rsstype', 'eq', 0);
00125         }
00126 
00127 //-------------------------------------------------------------------------------
00128 
00129         $this->standard_grading_coursemodule_elements();
00130 
00131         $this->standard_coursemodule_elements();
00132 
00133 //-------------------------------------------------------------------------------
00134         // buttons
00135         $this->add_action_buttons();
00136     }
00137 
00138     function definition_after_data() {
00139         global $COURSE, $DB;
00140 
00141         parent::definition_after_data();
00142         $mform    =& $this->_form;
00143         $mainglossaryel =& $mform->getElement('mainglossary');
00144         $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1, 'course'=>$COURSE->id));
00145         if ($mainglossary && ($mainglossary->id != $mform->getElementValue('instance'))){
00146             //secondary glossary, a main one already exists in this course.
00147             $mainglossaryel->setValue(0);
00148             $mainglossaryel->freeze();
00149             $mainglossaryel->setPersistantFreeze(true);
00150         } else {
00151             $mainglossaryel->unfreeze();
00152             $mainglossaryel->setPersistantFreeze(false);
00153 
00154         }
00155     }
00156 
00157     function data_preprocessing(&$default_values){
00158         parent::data_preprocessing($default_values);
00159 
00160         // Set up the completion checkboxes which aren't part of standard data.
00161         // We also make the default value (if you turn on the checkbox) for those
00162         // numbers to be 1, this will not apply unless checkbox is ticked.
00163         $default_values['completionentriesenabled']=
00164             !empty($default_values['completionentries']) ? 1 : 0;
00165         if (empty($default_values['completionentries'])) {
00166             $default_values['completionentries']=1;
00167         }
00168     }
00169 
00170     function add_completion_rules() {
00171         $mform =& $this->_form;
00172 
00173         $group=array();
00174         $group[] =& $mform->createElement('checkbox', 'completionentriesenabled', '', get_string('completionentries','glossary'));
00175         $group[] =& $mform->createElement('text', 'completionentries', '', array('size'=>3));
00176         $mform->setType('completionentries', PARAM_INT);
00177         $mform->addGroup($group, 'completionentriesgroup', get_string('completionentriesgroup','glossary'), array(' '), false);
00178         $mform->disabledIf('completionentries','completionentriesenabled','notchecked');
00179 
00180         return array('completionentriesgroup');
00181     }
00182 
00183     function completion_rule_enabled($data) {
00184         return (!empty($data['completionentriesenabled']) && $data['completionentries']!=0);
00185     }
00186 
00187     function get_data() {
00188         $data = parent::get_data();
00189         if (!$data) {
00190             return false;
00191         }
00192         // Turn off completion settings if the checkboxes aren't ticked
00193         $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC;
00194         if (empty($data->completionentriesenabled) || !$autocompletion) {
00195             $data->completionentries = 0;
00196         }
00197         return $data;
00198     }
00199 
00200 }
00201 
 All Data Structures Namespaces Files Functions Variables Enumerations