Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
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 * This file contains a custom renderer class used by the forum module. 20 * 21 * @package mod_forum 22 * @copyright 2009 Sam Hemelryk 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 /** 27 * A custom renderer class that extends the plugin_renderer_base and 28 * is used by the forum module. 29 * 30 * @package mod_forum 31 * @copyright 2009 Sam Hemelryk 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 **/ 34 class mod_forum_renderer extends plugin_renderer_base { 35 36 /** 37 * Returns the navigation to the previous and next discussion. 38 * 39 * @param mixed $prev Previous discussion record, or false. 40 * @param mixed $next Next discussion record, or false. 41 * @return string The output. 42 */ 43 public function neighbouring_discussion_navigation($prev, $next) { 44 $html = ''; 45 if ($prev || $next) { 46 $html .= html_writer::start_tag('div', array('class' => 'discussion-nav clearfix')); 47 $html .= html_writer::start_tag('ul'); 48 if ($prev) { 49 $url = new moodle_url('/mod/forum/discuss.php', array('d' => $prev->id)); 50 $html .= html_writer::start_tag('li', array('class' => 'prev-discussion')); 51 $html .= html_writer::link($url, $this->output->larrow() . ' ' . format_string($prev->name), 52 array('aria-label' => get_string('prevdiscussiona', 'mod_forum', format_string($prev->name)), 53 'class' => 'btn btn-link')); 54 $html .= html_writer::end_tag('li'); 55 } 56 if ($next) { 57 $url = new moodle_url('/mod/forum/discuss.php', array('d' => $next->id)); 58 $html .= html_writer::start_tag('li', array('class' => 'next-discussion')); 59 $html .= html_writer::link($url, format_string($next->name) . ' ' . $this->output->rarrow(), 60 array('aria-label' => get_string('nextdiscussiona', 'mod_forum', format_string($next->name)), 61 'class' => 'btn btn-link')); 62 $html .= html_writer::end_tag('li'); 63 } 64 $html .= html_writer::end_tag('ul'); 65 $html .= html_writer::end_tag('div'); 66 } 67 return $html; 68 } 69 70 /** 71 * This method is used to generate HTML for a subscriber selection form that 72 * uses two user_selector controls 73 * 74 * @param user_selector_base $existinguc 75 * @param user_selector_base $potentialuc 76 * @return string 77 */ 78 public function subscriber_selection_form(user_selector_base $existinguc, user_selector_base $potentialuc) { 79 $output = ''; 80 $formattributes = array(); 81 $formattributes['id'] = 'subscriberform'; 82 $formattributes['action'] = ''; 83 $formattributes['method'] = 'post'; 84 $output .= html_writer::start_tag('form', $formattributes); 85 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey())); 86 87 $existingcell = new html_table_cell(); 88 $existingcell->text = $existinguc->display(true); 89 $existingcell->attributes['class'] = 'existing'; 90 $actioncell = new html_table_cell(); 91 $actioncell->text = html_writer::start_tag('div', array()); 92 $actioncell->text .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'subscribe', 'value'=>$this->page->theme->larrow.' '.get_string('add'), 'class'=>'actionbutton')); 93 $actioncell->text .= html_writer::empty_tag('br', array()); 94 $actioncell->text .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'unsubscribe', 'value'=>$this->page->theme->rarrow.' '.get_string('remove'), 'class'=>'actionbutton')); 95 $actioncell->text .= html_writer::end_tag('div', array()); 96 $actioncell->attributes['class'] = 'actions'; 97 $potentialcell = new html_table_cell(); 98 $potentialcell->text = $potentialuc->display(true); 99 $potentialcell->attributes['class'] = 'potential'; 100 101 $table = new html_table(); 102 $table->attributes['class'] = 'subscribertable boxaligncenter'; 103 $table->data = array(new html_table_row(array($existingcell, $actioncell, $potentialcell))); 104 $output .= html_writer::table($table); 105 106 $output .= html_writer::end_tag('form'); 107 return $output; 108 } 109 110 /** 111 * This function generates HTML to display a subscriber overview, primarily used on 112 * the subscribers page if editing was turned off 113 * 114 * @param array $users 115 * @param object $forum 116 * @param object $course 117 * @return string 118 */ 119 public function subscriber_overview($users, $forum , $course) { 120 $output = ''; 121 $modinfo = get_fast_modinfo($course); 122 if (!$users || !is_array($users) || count($users)===0) { 123 $output .= $this->output->heading(get_string("nosubscribers", "forum")); 124 } else if (!isset($modinfo->instances['forum'][$forum->id])) { 125 $output .= $this->output->heading(get_string("invalidmodule", "error")); 126 } else { 127 $cm = $modinfo->instances['forum'][$forum->id]; 128 $canviewemail = in_array('email', get_extra_user_fields(context_module::instance($cm->id))); 129 $strparams = new stdclass(); 130 $strparams->name = format_string($forum->name); 131 $strparams->count = count($users); 132 $output .= $this->output->heading(get_string("subscriberstowithcount", "forum", $strparams)); 133 $table = new html_table(); 134 $table->cellpadding = 5; 135 $table->cellspacing = 5; 136 $table->tablealign = 'center'; 137 $table->data = array(); 138 foreach ($users as $user) { 139 $info = array($this->output->user_picture($user, array('courseid'=>$course->id)), fullname($user)); 140 if ($canviewemail) { 141 array_push($info, $user->email); 142 } 143 $table->data[] = $info; 144 } 145 $output .= html_writer::table($table); 146 } 147 return $output; 148 } 149 150 /** 151 * This is used to display a control containing all of the subscribed users so that 152 * it can be searched 153 * 154 * @param user_selector_base $existingusers 155 * @return string 156 */ 157 public function subscribed_users(user_selector_base $existingusers) { 158 $output = $this->output->box_start('subscriberdiv boxaligncenter'); 159 $output .= html_writer::tag('p', get_string('forcesubscribed', 'forum')); 160 $output .= $existingusers->display(true); 161 $output .= $this->output->box_end(); 162 return $output; 163 } 164 165 /** 166 * Generate the HTML for an icon to be displayed beside the subject of a timed discussion. 167 * 168 * @param object $discussion 169 * @param bool $visiblenow Indicicates that the discussion is currently 170 * visible to all users. 171 * @return string 172 */ 173 public function timed_discussion_tooltip($discussion, $visiblenow) { 174 $dates = array(); 175 if ($discussion->timestart) { 176 $dates[] = get_string('displaystart', 'mod_forum').': '.userdate($discussion->timestart); 177 } 178 if ($discussion->timeend) { 179 $dates[] = get_string('displayend', 'mod_forum').': '.userdate($discussion->timeend); 180 } 181 182 $str = $visiblenow ? 'timedvisible' : 'timedhidden'; 183 $dates[] = get_string($str, 'mod_forum'); 184 185 $tooltip = implode("\n", $dates); 186 return $this->pix_icon('i/calendar', $tooltip, 'moodle', array('class' => 'smallicon timedpost')); 187 } 188 189 /** 190 * Display a forum post in the relevant context. 191 * 192 * @param \mod_forum\output\forum_post $post The post to display. 193 * @return string 194 */ 195 public function render_forum_post_email(\mod_forum\output\forum_post_email $post) { 196 $data = $post->export_for_template($this, $this->target === RENDERER_TARGET_TEXTEMAIL); 197 return $this->render_from_template('mod_forum/' . $this->forum_post_template(), $data); 198 } 199 200 /** 201 * The template name for this renderer. 202 * 203 * @return string 204 */ 205 public function forum_post_template() { 206 return 'forum_post'; 207 } 208 209 /** 210 * Create the inplace_editable used to select forum digest options. 211 * 212 * @param stdClass $forum The forum to create the editable for. 213 * @param int $value The current value for this user 214 * @return inplace_editable 215 */ 216 public function render_digest_options($forum, $value) { 217 $options = forum_get_user_digest_options(); 218 $editable = new \core\output\inplace_editable( 219 'mod_forum', 220 'digestoptions', 221 $forum->id, 222 true, 223 $options[$value], 224 $value 225 ); 226 227 $editable->set_type_select($options); 228 229 return $editable; 230 } 231 232 /** 233 * Render quick search form. 234 * 235 * @param \mod_forum\output\quick_search_form $form The renderable. 236 * @return string 237 */ 238 public function render_quick_search_form(\mod_forum\output\quick_search_form $form) { 239 return $this->render_from_template('mod_forum/quick_search_form', $form->export_for_template($this)); 240 } 241 242 /** 243 * Render big search form. 244 * 245 * @param \mod_forum\output\big_search_form $form The renderable. 246 * @return string 247 */ 248 public function render_big_search_form(\mod_forum\output\big_search_form $form) { 249 return $this->render_from_template('mod_forum/big_search_form', $form->export_for_template($this)); 250 } 251 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body