|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00024 if (!defined('MOODLE_INTERNAL')) { 00025 die('Direct access to this script is forbidden.'); 00026 } 00027 00028 require_once ($CFG->dirroot.'/course/moodleform_mod.php'); 00029 00030 class mod_forum_mod_form extends moodleform_mod { 00031 00032 function definition() { 00033 global $CFG, $COURSE, $DB; 00034 00035 $mform =& $this->_form; 00036 00037 //------------------------------------------------------------------------------- 00038 $mform->addElement('header', 'general', get_string('general', 'form')); 00039 00040 $mform->addElement('text', 'name', get_string('forumname', 'forum'), array('size'=>'64')); 00041 if (!empty($CFG->formatstringstriptags)) { 00042 $mform->setType('name', PARAM_TEXT); 00043 } else { 00044 $mform->setType('name', PARAM_CLEANHTML); 00045 } 00046 $mform->addRule('name', null, 'required', null, 'client'); 00047 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); 00048 00049 $forum_types = forum_get_forum_types(); 00050 00051 asort($forum_types); 00052 $mform->addElement('select', 'type', get_string('forumtype', 'forum'), $forum_types); 00053 $mform->addHelpButton('type', 'forumtype', 'forum'); 00054 $mform->setDefault('type', 'general'); 00055 00056 $this->add_intro_editor(true, get_string('forumintro', 'forum')); 00057 00058 $options = array(); 00059 $options[FORUM_CHOOSESUBSCRIBE] = get_string('subscriptionoptional', 'forum'); 00060 $options[FORUM_FORCESUBSCRIBE] = get_string('subscriptionforced', 'forum'); 00061 $options[FORUM_INITIALSUBSCRIBE] = get_string('subscriptionauto', 'forum'); 00062 $options[FORUM_DISALLOWSUBSCRIBE] = get_string('subscriptiondisabled','forum'); 00063 $mform->addElement('select', 'forcesubscribe', get_string('subscriptionmode', 'forum'), $options); 00064 $mform->addHelpButton('forcesubscribe', 'subscriptionmode', 'forum'); 00065 00066 $options = array(); 00067 $options[FORUM_TRACKING_OPTIONAL] = get_string('trackingoptional', 'forum'); 00068 $options[FORUM_TRACKING_OFF] = get_string('trackingoff', 'forum'); 00069 $options[FORUM_TRACKING_ON] = get_string('trackingon', 'forum'); 00070 $mform->addElement('select', 'trackingtype', get_string('trackingtype', 'forum'), $options); 00071 $mform->addHelpButton('trackingtype', 'trackingtype', 'forum'); 00072 00073 $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes); 00074 $choices[1] = get_string('uploadnotallowed'); 00075 $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')'; 00076 $mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'forum'), $choices); 00077 $mform->addHelpButton('maxbytes', 'maxattachmentsize', 'forum'); 00078 $mform->setDefault('maxbytes', $CFG->forum_maxbytes); 00079 00080 $choices = array(0,1,2,3,4,5,6,7,8,9,10,20,50,100); 00081 $mform->addElement('select', 'maxattachments', get_string('maxattachments', 'forum'), $choices); 00082 $mform->addHelpButton('maxattachments', 'maxattachments', 'forum'); 00083 $mform->setDefault('maxattachments', $CFG->forum_maxattachments); 00084 00085 if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) { 00086 //------------------------------------------------------------------------------- 00087 $mform->addElement('header', '', get_string('rss')); 00088 $choices = array(); 00089 $choices[0] = get_string('none'); 00090 $choices[1] = get_string('discussions', 'forum'); 00091 $choices[2] = get_string('posts', 'forum'); 00092 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices); 00093 $mform->addHelpButton('rsstype', 'rsstype', 'forum'); 00094 00095 $choices = array(); 00096 $choices[0] = '0'; 00097 $choices[1] = '1'; 00098 $choices[2] = '2'; 00099 $choices[3] = '3'; 00100 $choices[4] = '4'; 00101 $choices[5] = '5'; 00102 $choices[10] = '10'; 00103 $choices[15] = '15'; 00104 $choices[20] = '20'; 00105 $choices[25] = '25'; 00106 $choices[30] = '30'; 00107 $choices[40] = '40'; 00108 $choices[50] = '50'; 00109 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices); 00110 $mform->addHelpButton('rssarticles', 'rssarticles', 'forum'); 00111 } 00112 00113 //------------------------------------------------------------------------------- 00114 $mform->addElement('header', '', get_string('blockafter', 'forum')); 00115 $options = array(); 00116 $options[0] = get_string('blockperioddisabled','forum'); 00117 $options[60*60*24] = '1 '.get_string('day'); 00118 $options[60*60*24*2] = '2 '.get_string('days'); 00119 $options[60*60*24*3] = '3 '.get_string('days'); 00120 $options[60*60*24*4] = '4 '.get_string('days'); 00121 $options[60*60*24*5] = '5 '.get_string('days'); 00122 $options[60*60*24*6] = '6 '.get_string('days'); 00123 $options[60*60*24*7] = '1 '.get_string('week'); 00124 $mform->addElement('select', 'blockperiod', get_string('blockperiod', 'forum'), $options); 00125 $mform->addHelpButton('blockperiod', 'blockperiod', 'forum'); 00126 00127 $mform->addElement('text', 'blockafter', get_string('blockafter', 'forum')); 00128 $mform->setType('blockafter', PARAM_INT); 00129 $mform->setDefault('blockafter', '0'); 00130 $mform->addRule('blockafter', null, 'numeric', null, 'client'); 00131 $mform->addHelpButton('blockafter', 'blockafter', 'forum'); 00132 $mform->disabledIf('blockafter', 'blockperiod', 'eq', 0); 00133 00134 00135 $mform->addElement('text', 'warnafter', get_string('warnafter', 'forum')); 00136 $mform->setType('warnafter', PARAM_INT); 00137 $mform->setDefault('warnafter', '0'); 00138 $mform->addRule('warnafter', null, 'numeric', null, 'client'); 00139 $mform->addHelpButton('warnafter', 'warnafter', 'forum'); 00140 $mform->disabledIf('warnafter', 'blockperiod', 'eq', 0); 00141 00142 //------------------------------------------------------------------------------- 00143 00144 $this->standard_grading_coursemodule_elements(); 00145 00146 $this->standard_coursemodule_elements(); 00147 //------------------------------------------------------------------------------- 00148 // buttons 00149 $this->add_action_buttons(); 00150 00151 } 00152 00153 function definition_after_data() { 00154 parent::definition_after_data(); 00155 $mform =& $this->_form; 00156 $type =& $mform->getElement('type'); 00157 $typevalue = $mform->getElementValue('type'); 00158 00159 //we don't want to have these appear as possible selections in the form but 00160 //we want the form to display them if they are set. 00161 if ($typevalue[0]=='news') { 00162 $type->addOption(get_string('namenews', 'forum'), 'news'); 00163 $mform->addHelpButton('type', 'namenews', 'forum'); 00164 $type->freeze(); 00165 $type->setPersistantFreeze(true); 00166 } 00167 if ($typevalue[0]=='social') { 00168 $type->addOption(get_string('namesocial', 'forum'), 'social'); 00169 $type->freeze(); 00170 $type->setPersistantFreeze(true); 00171 } 00172 00173 } 00174 00175 function data_preprocessing(&$default_values) { 00176 parent::data_preprocessing($default_values); 00177 00178 // Set up the completion checkboxes which aren't part of standard data. 00179 // We also make the default value (if you turn on the checkbox) for those 00180 // numbers to be 1, this will not apply unless checkbox is ticked. 00181 $default_values['completiondiscussionsenabled']= 00182 !empty($default_values['completiondiscussions']) ? 1 : 0; 00183 if (empty($default_values['completiondiscussions'])) { 00184 $default_values['completiondiscussions']=1; 00185 } 00186 $default_values['completionrepliesenabled']= 00187 !empty($default_values['completionreplies']) ? 1 : 0; 00188 if (empty($default_values['completionreplies'])) { 00189 $default_values['completionreplies']=1; 00190 } 00191 $default_values['completionpostsenabled']= 00192 !empty($default_values['completionposts']) ? 1 : 0; 00193 if (empty($default_values['completionposts'])) { 00194 $default_values['completionposts']=1; 00195 } 00196 } 00197 00198 function add_completion_rules() { 00199 $mform =& $this->_form; 00200 00201 $group=array(); 00202 $group[] =& $mform->createElement('checkbox', 'completionpostsenabled', '', get_string('completionposts','forum')); 00203 $group[] =& $mform->createElement('text', 'completionposts', '', array('size'=>3)); 00204 $mform->setType('completionposts',PARAM_INT); 00205 $mform->addGroup($group, 'completionpostsgroup', get_string('completionpostsgroup','forum'), array(' '), false); 00206 $mform->disabledIf('completionposts','completionpostsenabled','notchecked'); 00207 00208 $group=array(); 00209 $group[] =& $mform->createElement('checkbox', 'completiondiscussionsenabled', '', get_string('completiondiscussions','forum')); 00210 $group[] =& $mform->createElement('text', 'completiondiscussions', '', array('size'=>3)); 00211 $mform->setType('completiondiscussions',PARAM_INT); 00212 $mform->addGroup($group, 'completiondiscussionsgroup', get_string('completiondiscussionsgroup','forum'), array(' '), false); 00213 $mform->disabledIf('completiondiscussions','completiondiscussionsenabled','notchecked'); 00214 00215 $group=array(); 00216 $group[] =& $mform->createElement('checkbox', 'completionrepliesenabled', '', get_string('completionreplies','forum')); 00217 $group[] =& $mform->createElement('text', 'completionreplies', '', array('size'=>3)); 00218 $mform->setType('completionreplies',PARAM_INT); 00219 $mform->addGroup($group, 'completionrepliesgroup', get_string('completionrepliesgroup','forum'), array(' '), false); 00220 $mform->disabledIf('completionreplies','completionrepliesenabled','notchecked'); 00221 00222 return array('completiondiscussionsgroup','completionrepliesgroup','completionpostsgroup'); 00223 } 00224 00225 function completion_rule_enabled($data) { 00226 return (!empty($data['completiondiscussionsenabled']) && $data['completiondiscussions']!=0) || 00227 (!empty($data['completionrepliesenabled']) && $data['completionreplies']!=0) || 00228 (!empty($data['completionpostsenabled']) && $data['completionposts']!=0); 00229 } 00230 00231 function get_data() { 00232 $data = parent::get_data(); 00233 if (!$data) { 00234 return false; 00235 } 00236 // Turn off completion settings if the checkboxes aren't ticked 00237 $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC; 00238 if (empty($data->completiondiscussionsenabled) || !$autocompletion) { 00239 $data->completiondiscussions = 0; 00240 } 00241 if (empty($data->completionrepliesenabled) || !$autocompletion) { 00242 $data->completionreplies = 0; 00243 } 00244 if (empty($data->completionpostsenabled) || !$autocompletion) { 00245 $data->completionposts = 0; 00246 } 00247 return $data; 00248 } 00249 } 00250