[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * @package mod_forum 20 * @copyright Jamie Pratt <[email protected]> 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 24 if (!defined('MOODLE_INTERNAL')) { 25 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page 26 } 27 28 require_once ($CFG->dirroot.'/course/moodleform_mod.php'); 29 30 class mod_forum_mod_form extends moodleform_mod { 31 32 function definition() { 33 global $CFG, $COURSE, $DB; 34 35 $mform =& $this->_form; 36 37 //------------------------------------------------------------------------------- 38 $mform->addElement('header', 'general', get_string('general', 'form')); 39 40 $mform->addElement('text', 'name', get_string('forumname', 'forum'), array('size'=>'64')); 41 if (!empty($CFG->formatstringstriptags)) { 42 $mform->setType('name', PARAM_TEXT); 43 } else { 44 $mform->setType('name', PARAM_CLEANHTML); 45 } 46 $mform->addRule('name', null, 'required', null, 'client'); 47 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 48 49 $this->add_intro_editor(true, get_string('forumintro', 'forum')); 50 51 $forumtypes = forum_get_forum_types(); 52 core_collator::asort($forumtypes, core_collator::SORT_STRING); 53 $mform->addElement('select', 'type', get_string('forumtype', 'forum'), $forumtypes); 54 $mform->addHelpButton('type', 'forumtype', 'forum'); 55 $mform->setDefault('type', 'general'); 56 57 // Attachments and word count. 58 $mform->addElement('header', 'attachmentswordcounthdr', get_string('attachmentswordcount', 'forum')); 59 60 $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes, 0, $CFG->forum_maxbytes); 61 $choices[1] = get_string('uploadnotallowed'); 62 $mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'forum'), $choices); 63 $mform->addHelpButton('maxbytes', 'maxattachmentsize', 'forum'); 64 $mform->setDefault('maxbytes', $CFG->forum_maxbytes); 65 66 $choices = array( 67 0 => 0, 68 1 => 1, 69 2 => 2, 70 3 => 3, 71 4 => 4, 72 5 => 5, 73 6 => 6, 74 7 => 7, 75 8 => 8, 76 9 => 9, 77 10 => 10, 78 20 => 20, 79 50 => 50, 80 100 => 100 81 ); 82 $mform->addElement('select', 'maxattachments', get_string('maxattachments', 'forum'), $choices); 83 $mform->addHelpButton('maxattachments', 'maxattachments', 'forum'); 84 $mform->setDefault('maxattachments', $CFG->forum_maxattachments); 85 86 $mform->addElement('selectyesno', 'displaywordcount', get_string('displaywordcount', 'forum')); 87 $mform->addHelpButton('displaywordcount', 'displaywordcount', 'forum'); 88 $mform->setDefault('displaywordcount', 0); 89 90 // Subscription and tracking. 91 $mform->addElement('header', 'subscriptionandtrackinghdr', get_string('subscriptionandtracking', 'forum')); 92 93 $options = array(); 94 $options[FORUM_CHOOSESUBSCRIBE] = get_string('subscriptionoptional', 'forum'); 95 $options[FORUM_FORCESUBSCRIBE] = get_string('subscriptionforced', 'forum'); 96 $options[FORUM_INITIALSUBSCRIBE] = get_string('subscriptionauto', 'forum'); 97 $options[FORUM_DISALLOWSUBSCRIBE] = get_string('subscriptiondisabled','forum'); 98 $mform->addElement('select', 'forcesubscribe', get_string('subscriptionmode', 'forum'), $options); 99 $mform->addHelpButton('forcesubscribe', 'subscriptionmode', 'forum'); 100 101 $options = array(); 102 $options[FORUM_TRACKING_OPTIONAL] = get_string('trackingoptional', 'forum'); 103 $options[FORUM_TRACKING_OFF] = get_string('trackingoff', 'forum'); 104 if ($CFG->forum_allowforcedreadtracking) { 105 $options[FORUM_TRACKING_FORCED] = get_string('trackingon', 'forum'); 106 } 107 $mform->addElement('select', 'trackingtype', get_string('trackingtype', 'forum'), $options); 108 $mform->addHelpButton('trackingtype', 'trackingtype', 'forum'); 109 $default = $CFG->forum_trackingtype; 110 if ((!$CFG->forum_allowforcedreadtracking) && ($default == FORUM_TRACKING_FORCED)) { 111 $default = FORUM_TRACKING_OPTIONAL; 112 } 113 $mform->setDefault('trackingtype', $default); 114 115 if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) { 116 //------------------------------------------------------------------------------- 117 $mform->addElement('header', 'rssheader', get_string('rss')); 118 $choices = array(); 119 $choices[0] = get_string('none'); 120 $choices[1] = get_string('discussions', 'forum'); 121 $choices[2] = get_string('posts', 'forum'); 122 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices); 123 $mform->addHelpButton('rsstype', 'rsstype', 'forum'); 124 125 $choices = array(); 126 $choices[0] = '0'; 127 $choices[1] = '1'; 128 $choices[2] = '2'; 129 $choices[3] = '3'; 130 $choices[4] = '4'; 131 $choices[5] = '5'; 132 $choices[10] = '10'; 133 $choices[15] = '15'; 134 $choices[20] = '20'; 135 $choices[25] = '25'; 136 $choices[30] = '30'; 137 $choices[40] = '40'; 138 $choices[50] = '50'; 139 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices); 140 $mform->addHelpButton('rssarticles', 'rssarticles', 'forum'); 141 $mform->disabledIf('rssarticles', 'rsstype', 'eq', '0'); 142 } 143 144 //------------------------------------------------------------------------------- 145 $mform->addElement('header', 'blockafterheader', get_string('blockafter', 'forum')); 146 $options = array(); 147 $options[0] = get_string('blockperioddisabled','forum'); 148 $options[60*60*24] = '1 '.get_string('day'); 149 $options[60*60*24*2] = '2 '.get_string('days'); 150 $options[60*60*24*3] = '3 '.get_string('days'); 151 $options[60*60*24*4] = '4 '.get_string('days'); 152 $options[60*60*24*5] = '5 '.get_string('days'); 153 $options[60*60*24*6] = '6 '.get_string('days'); 154 $options[60*60*24*7] = '1 '.get_string('week'); 155 $mform->addElement('select', 'blockperiod', get_string('blockperiod', 'forum'), $options); 156 $mform->addHelpButton('blockperiod', 'blockperiod', 'forum'); 157 158 $mform->addElement('text', 'blockafter', get_string('blockafter', 'forum')); 159 $mform->setType('blockafter', PARAM_INT); 160 $mform->setDefault('blockafter', '0'); 161 $mform->addRule('blockafter', null, 'numeric', null, 'client'); 162 $mform->addHelpButton('blockafter', 'blockafter', 'forum'); 163 $mform->disabledIf('blockafter', 'blockperiod', 'eq', 0); 164 165 $mform->addElement('text', 'warnafter', get_string('warnafter', 'forum')); 166 $mform->setType('warnafter', PARAM_INT); 167 $mform->setDefault('warnafter', '0'); 168 $mform->addRule('warnafter', null, 'numeric', null, 'client'); 169 $mform->addHelpButton('warnafter', 'warnafter', 'forum'); 170 $mform->disabledIf('warnafter', 'blockperiod', 'eq', 0); 171 172 $coursecontext = context_course::instance($COURSE->id); 173 plagiarism_get_form_elements_module($mform, $coursecontext, 'mod_forum'); 174 175 //------------------------------------------------------------------------------- 176 177 $this->standard_grading_coursemodule_elements(); 178 179 $this->standard_coursemodule_elements(); 180 //------------------------------------------------------------------------------- 181 // buttons 182 $this->add_action_buttons(); 183 184 } 185 186 function definition_after_data() { 187 parent::definition_after_data(); 188 $mform =& $this->_form; 189 $type =& $mform->getElement('type'); 190 $typevalue = $mform->getElementValue('type'); 191 192 //we don't want to have these appear as possible selections in the form but 193 //we want the form to display them if they are set. 194 if ($typevalue[0]=='news') { 195 $type->addOption(get_string('namenews', 'forum'), 'news'); 196 $mform->addHelpButton('type', 'namenews', 'forum'); 197 $type->freeze(); 198 $type->setPersistantFreeze(true); 199 } 200 if ($typevalue[0]=='social') { 201 $type->addOption(get_string('namesocial', 'forum'), 'social'); 202 $type->freeze(); 203 $type->setPersistantFreeze(true); 204 } 205 206 } 207 208 function data_preprocessing(&$default_values) { 209 parent::data_preprocessing($default_values); 210 211 // Set up the completion checkboxes which aren't part of standard data. 212 // We also make the default value (if you turn on the checkbox) for those 213 // numbers to be 1, this will not apply unless checkbox is ticked. 214 $default_values['completiondiscussionsenabled']= 215 !empty($default_values['completiondiscussions']) ? 1 : 0; 216 if (empty($default_values['completiondiscussions'])) { 217 $default_values['completiondiscussions']=1; 218 } 219 $default_values['completionrepliesenabled']= 220 !empty($default_values['completionreplies']) ? 1 : 0; 221 if (empty($default_values['completionreplies'])) { 222 $default_values['completionreplies']=1; 223 } 224 $default_values['completionpostsenabled']= 225 !empty($default_values['completionposts']) ? 1 : 0; 226 if (empty($default_values['completionposts'])) { 227 $default_values['completionposts']=1; 228 } 229 } 230 231 function add_completion_rules() { 232 $mform =& $this->_form; 233 234 $group=array(); 235 $group[] =& $mform->createElement('checkbox', 'completionpostsenabled', '', get_string('completionposts','forum')); 236 $group[] =& $mform->createElement('text', 'completionposts', '', array('size'=>3)); 237 $mform->setType('completionposts',PARAM_INT); 238 $mform->addGroup($group, 'completionpostsgroup', get_string('completionpostsgroup','forum'), array(' '), false); 239 $mform->disabledIf('completionposts','completionpostsenabled','notchecked'); 240 241 $group=array(); 242 $group[] =& $mform->createElement('checkbox', 'completiondiscussionsenabled', '', get_string('completiondiscussions','forum')); 243 $group[] =& $mform->createElement('text', 'completiondiscussions', '', array('size'=>3)); 244 $mform->setType('completiondiscussions',PARAM_INT); 245 $mform->addGroup($group, 'completiondiscussionsgroup', get_string('completiondiscussionsgroup','forum'), array(' '), false); 246 $mform->disabledIf('completiondiscussions','completiondiscussionsenabled','notchecked'); 247 248 $group=array(); 249 $group[] =& $mform->createElement('checkbox', 'completionrepliesenabled', '', get_string('completionreplies','forum')); 250 $group[] =& $mform->createElement('text', 'completionreplies', '', array('size'=>3)); 251 $mform->setType('completionreplies',PARAM_INT); 252 $mform->addGroup($group, 'completionrepliesgroup', get_string('completionrepliesgroup','forum'), array(' '), false); 253 $mform->disabledIf('completionreplies','completionrepliesenabled','notchecked'); 254 255 return array('completiondiscussionsgroup','completionrepliesgroup','completionpostsgroup'); 256 } 257 258 function completion_rule_enabled($data) { 259 return (!empty($data['completiondiscussionsenabled']) && $data['completiondiscussions']!=0) || 260 (!empty($data['completionrepliesenabled']) && $data['completionreplies']!=0) || 261 (!empty($data['completionpostsenabled']) && $data['completionposts']!=0); 262 } 263 264 function get_data() { 265 $data = parent::get_data(); 266 if (!$data) { 267 return false; 268 } 269 // Turn off completion settings if the checkboxes aren't ticked 270 if (!empty($data->completionunlocked)) { 271 $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC; 272 if (empty($data->completiondiscussionsenabled) || !$autocompletion) { 273 $data->completiondiscussions = 0; 274 } 275 if (empty($data->completionrepliesenabled) || !$autocompletion) { 276 $data->completionreplies = 0; 277 } 278 if (empty($data->completionpostsenabled) || !$autocompletion) { 279 $data->completionposts = 0; 280 } 281 } 282 return $data; 283 } 284 } 285
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |