[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/mod/glossary/ -> mod_form.php (source)

   1  <?php
   2  require_once ($CFG->dirroot.'/course/moodleform_mod.php');
   3  
   4  class mod_glossary_mod_form extends moodleform_mod {
   5  
   6      function definition() {
   7  
   8          global $CFG, $COURSE;
   9          $mform    =& $this->_form;
  10  
  11  //-------------------------------------------------------------------------------
  12          $mform->addElement('header', 'general', get_string('general', 'form'));
  13  
  14          $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
  15          if (!empty($CFG->formatstringstriptags)) {
  16              $mform->setType('name', PARAM_TEXT);
  17          } else {
  18              $mform->setType('name', PARAM_CLEAN);
  19          }
  20          $mform->addRule('name', null, 'required', null, 'client');
  21  
  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');
  26  
  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');
  31  
  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'));
  35  
  36          }else{
  37              $mform->addElement('hidden', 'globalglossary');
  38          }
  39  
  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);
  44  
  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'));
  48  
  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'));
  52  
  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'));
  56  
  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'));
  60  
  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'));
  64  
  65          //get and update available formats
  66          $recformats = glossary_get_available_formats();
  67  
  68          $formats = array();
  69  
  70          //Take names
  71          foreach ($recformats as $format) {
  72             $formats[$format->name] = get_string('displayformat'.$format->name, 'glossary');
  73          }
  74          //Sort it
  75          asort($formats);
  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'));
  79  
  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'));
  83  
  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'));
  87  
  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'));
  91  
  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'));
  95  
  96          if ($CFG->enablerssfeeds && isset($CFG->glossary_enablerssfeeds) && $CFG->glossary_enablerssfeeds) {
  97  //-------------------------------------------------------------------------------
  98              $mform->addElement('header', '', get_string('rss'));
  99              $choices = array();
 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'));
 105  
 106              $choices = array();
 107              $choices[0] = '0';
 108              $choices[1] = '1';
 109              $choices[2] = '2';
 110              $choices[3] = '3';
 111              $choices[4] = '4';
 112              $choices[5] = '5';
 113              $choices[10] = '10';
 114              $choices[15] = '15';
 115              $choices[20] = '20';
 116              $choices[25] = '25';
 117              $choices[30] = '30';
 118              $choices[40] = '40';
 119              $choices[50] = '50';
 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);
 123          }
 124  
 125  //-------------------------------------------------------------------------------
 126          $mform->addElement('header', '', get_string('grade'));
 127          $mform->addElement('checkbox', 'userating', get_string('allowratings', 'glossary') , get_string('ratingsuse', 'glossary'));
 128  
 129          $options=array();
 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');
 134  
 135          $mform->addElement('modgrade', 'scale', get_string('grade'), false);
 136          $mform->disabledIf('scale', 'userating');
 137  
 138          $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'glossary'));
 139          $mform->disabledIf('ratingtime', 'userating');
 140  
 141          $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
 142          $mform->disabledIf('assesstimestart', 'userating');
 143          $mform->disabledIf('assesstimestart', 'ratingtime');
 144  
 145          $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
 146          $mform->disabledIf('assesstimefinish', 'userating');
 147          $mform->disabledIf('assesstimefinish', 'ratingtime');
 148  
 149  //-------------------------------------------------------------------------------
 150          $this->standard_coursemodule_elements(array('groups'=>false, 'groupmembersonly'=>true));
 151  
 152  //-------------------------------------------------------------------------------
 153          // buttons
 154          $this->add_action_buttons();
 155      }
 156  
 157      function definition_after_data() {
 158          parent::definition_after_data();
 159          global $COURSE;
 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);
 168          } else {
 169              $mainglossaryel->unfreeze();
 170              $mainglossaryel->setPersistantFreeze(false);
 171  
 172          }
 173      }
 174  
 175      function data_preprocessing(&$default_values){
 176          if (empty($default_values['scale'])){
 177              $default_values['assessed'] = 0;
 178          }        
 179  
 180          if (empty($default_values['assessed'])){
 181              $default_values['userating'] = 0;
 182              $default_values['ratingtime'] = 0;
 183          } else {
 184              $default_values['userating'] = 1;
 185              $default_values['ratingtime']=
 186                  ($default_values['assesstimestart'] && $default_values['assesstimefinish']) ? 1 : 0;
 187          }
 188      }
 189  
 190  }
 191  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7