PageRenderTime 37ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/mod/glossary/mod_form.php

https://github.com/epsd/moodle
PHP | 207 lines | 152 code | 42 blank | 13 comment | 17 complexity | cd4020f5a8a0f23875d194671eec005a MD5 | raw file
  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. require_once ($CFG->dirroot.'/course/moodleform_mod.php');
  6. class mod_glossary_mod_form extends moodleform_mod {
  7. function definition() {
  8. global $CFG, $COURSE, $DB;
  9. $mform =& $this->_form;
  10. //-------------------------------------------------------------------------------
  11. $mform->addElement('header', 'general', get_string('general', 'form'));
  12. $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
  13. if (!empty($CFG->formatstringstriptags)) {
  14. $mform->setType('name', PARAM_TEXT);
  15. } else {
  16. $mform->setType('name', PARAM_CLEANHTML);
  17. }
  18. $mform->addRule('name', null, 'required', null, 'client');
  19. $this->add_intro_editor(true);
  20. $mform->addElement('text', 'entbypage', get_string('entbypage', 'glossary'));
  21. $mform->setDefault('entbypage', 10);
  22. $mform->addRule('entbypage', null, 'required', null, 'client');
  23. $mform->addRule('entbypage', null, 'numeric', null, 'client');
  24. if (has_capability('mod/glossary:manageentries', context_system::instance())) {
  25. $mform->addElement('checkbox', 'globalglossary', get_string('isglobal', 'glossary'));
  26. $mform->addHelpButton('globalglossary', 'isglobal', 'glossary');
  27. }else{
  28. $mform->addElement('hidden', 'globalglossary');
  29. $mform->setType('globalglossary', PARAM_INT);
  30. }
  31. $options = array(1=>get_string('mainglossary', 'glossary'), 0=>get_string('secondaryglossary', 'glossary'));
  32. $mform->addElement('select', 'mainglossary', get_string('glossarytype', 'glossary'), $options);
  33. $mform->addHelpButton('mainglossary', 'glossarytype', 'glossary');
  34. $mform->setDefault('mainglossary', 0);
  35. $mform->addElement('selectyesno', 'allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'));
  36. $mform->setDefault('allowduplicatedentries', $CFG->glossary_dupentries);
  37. $mform->addHelpButton('allowduplicatedentries', 'allowduplicatedentries', 'glossary');
  38. $mform->addElement('selectyesno', 'allowcomments', get_string('allowcomments', 'glossary'));
  39. $mform->setDefault('allowcomments', $CFG->glossary_allowcomments);
  40. $mform->addHelpButton('allowcomments', 'allowcomments', 'glossary');
  41. $mform->addElement('selectyesno', 'allowprintview', get_string('allowprintview', 'glossary'));
  42. $mform->setDefault('allowprintview', 1);
  43. $mform->addHelpButton('allowprintview', 'allowprintview', 'glossary');
  44. $mform->addElement('selectyesno', 'usedynalink', get_string('usedynalink', 'glossary'));
  45. $mform->setDefault('usedynalink', $CFG->glossary_linkbydefault);
  46. $mform->addHelpButton('usedynalink', 'usedynalink', 'glossary');
  47. $mform->addElement('selectyesno', 'defaultapproval', get_string('defaultapproval', 'glossary'));
  48. $mform->setDefault('defaultapproval', $CFG->glossary_defaultapproval);
  49. $mform->addHelpButton('defaultapproval', 'defaultapproval', 'glossary');
  50. //get and update available formats
  51. $recformats = glossary_get_available_formats();
  52. $formats = array();
  53. //Take names
  54. foreach ($recformats as $format) {
  55. $formats[$format->name] = get_string('displayformat'.$format->name, 'glossary');
  56. }
  57. //Sort it
  58. asort($formats);
  59. $mform->addElement('select', 'displayformat', get_string('displayformat', 'glossary'), $formats);
  60. $mform->setDefault('displayformat', 'dictionary');
  61. $mform->addHelpButton('displayformat', 'displayformat', 'glossary');
  62. $displayformats['default'] = get_string('displayformatdefault', 'glossary');
  63. $displayformats = array_merge($displayformats, $formats);
  64. $mform->addElement('select', 'approvaldisplayformat', get_string('approvaldisplayformat', 'glossary'), $displayformats);
  65. $mform->setDefault('approvaldisplayformat', 'default');
  66. $mform->addHelpButton('approvaldisplayformat', 'approvaldisplayformat', 'glossary');
  67. $mform->addElement('selectyesno', 'showspecial', get_string('showspecial', 'glossary'));
  68. $mform->setDefault('showspecial', 1);
  69. $mform->addHelpButton('showspecial', 'showspecial', 'glossary');
  70. $mform->addElement('selectyesno', 'showalphabet', get_string('showalphabet', 'glossary'));
  71. $mform->setDefault('showalphabet', 1);
  72. $mform->addHelpButton('showalphabet', 'showalphabet', 'glossary');
  73. $mform->addElement('selectyesno', 'showall', get_string('showall', 'glossary'));
  74. $mform->setDefault('showall', 1);
  75. $mform->addHelpButton('showall', 'showall', 'glossary');
  76. $mform->addElement('selectyesno', 'editalways', get_string('editalways', 'glossary'));
  77. $mform->setDefault('editalways', 0);
  78. $mform->addHelpButton('editalways', 'editalways', 'glossary');
  79. if ($CFG->enablerssfeeds && isset($CFG->glossary_enablerssfeeds) && $CFG->glossary_enablerssfeeds) {
  80. //-------------------------------------------------------------------------------
  81. $mform->addElement('header', '', get_string('rss'));
  82. $choices = array();
  83. $choices[0] = get_string('none');
  84. $choices[1] = get_string('withauthor', 'glossary');
  85. $choices[2] = get_string('withoutauthor', 'glossary');
  86. $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
  87. $mform->addHelpButton('rsstype', 'rsstype', 'glossary');
  88. $choices = array();
  89. $choices[0] = '0';
  90. $choices[1] = '1';
  91. $choices[2] = '2';
  92. $choices[3] = '3';
  93. $choices[4] = '4';
  94. $choices[5] = '5';
  95. $choices[10] = '10';
  96. $choices[15] = '15';
  97. $choices[20] = '20';
  98. $choices[25] = '25';
  99. $choices[30] = '30';
  100. $choices[40] = '40';
  101. $choices[50] = '50';
  102. $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
  103. $mform->addHelpButton('rssarticles', 'rssarticles', 'glossary');
  104. $mform->disabledIf('rssarticles', 'rsstype', 'eq', 0);
  105. }
  106. //-------------------------------------------------------------------------------
  107. $this->standard_grading_coursemodule_elements();
  108. $this->standard_coursemodule_elements();
  109. //-------------------------------------------------------------------------------
  110. // buttons
  111. $this->add_action_buttons();
  112. }
  113. function definition_after_data() {
  114. global $COURSE, $DB;
  115. parent::definition_after_data();
  116. $mform =& $this->_form;
  117. $mainglossaryel =& $mform->getElement('mainglossary');
  118. $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1, 'course'=>$COURSE->id));
  119. if ($mainglossary && ($mainglossary->id != $mform->getElementValue('instance'))){
  120. //secondary glossary, a main one already exists in this course.
  121. $mainglossaryel->setValue(0);
  122. $mainglossaryel->freeze();
  123. $mainglossaryel->setPersistantFreeze(true);
  124. } else {
  125. $mainglossaryel->unfreeze();
  126. $mainglossaryel->setPersistantFreeze(false);
  127. }
  128. }
  129. function data_preprocessing(&$default_values){
  130. parent::data_preprocessing($default_values);
  131. // Set up the completion checkboxes which aren't part of standard data.
  132. // We also make the default value (if you turn on the checkbox) for those
  133. // numbers to be 1, this will not apply unless checkbox is ticked.
  134. $default_values['completionentriesenabled']=
  135. !empty($default_values['completionentries']) ? 1 : 0;
  136. if (empty($default_values['completionentries'])) {
  137. $default_values['completionentries']=1;
  138. }
  139. }
  140. function add_completion_rules() {
  141. $mform =& $this->_form;
  142. $group=array();
  143. $group[] =& $mform->createElement('checkbox', 'completionentriesenabled', '', get_string('completionentries','glossary'));
  144. $group[] =& $mform->createElement('text', 'completionentries', '', array('size'=>3));
  145. $mform->setType('completionentries', PARAM_INT);
  146. $mform->addGroup($group, 'completionentriesgroup', get_string('completionentriesgroup','glossary'), array(' '), false);
  147. $mform->disabledIf('completionentries','completionentriesenabled','notchecked');
  148. return array('completionentriesgroup');
  149. }
  150. function completion_rule_enabled($data) {
  151. return (!empty($data['completionentriesenabled']) && $data['completionentries']!=0);
  152. }
  153. function get_data() {
  154. $data = parent::get_data();
  155. if (!$data) {
  156. return false;
  157. }
  158. // Turn off completion settings if the checkboxes aren't ticked
  159. $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC;
  160. if (empty($data->completionentriesenabled) || !$autocompletion) {
  161. $data->completionentries = 0;
  162. }
  163. return $data;
  164. }
  165. }