[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * course_overview block rendrer 19 * 20 * @package block_course_overview 21 * @copyright 2012 Adam Olley <adam.olley@netspot.com.au> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 defined('MOODLE_INTERNAL') || die; 25 26 /** 27 * Course_overview block rendrer 28 * 29 * @copyright 2012 Adam Olley <adam.olley@netspot.com.au> 30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 */ 32 class block_course_overview_renderer extends plugin_renderer_base { 33 34 /** 35 * Construct contents of course_overview block 36 * 37 * @param array $courses list of courses in sorted order 38 * @param array $overviews list of course overviews 39 * @return string html to be displayed in course_overview block 40 */ 41 public function course_overview($courses, $overviews) { 42 $html = ''; 43 $config = get_config('block_course_overview'); 44 if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { 45 global $CFG; 46 require_once($CFG->libdir.'/coursecatlib.php'); 47 } 48 $ismovingcourse = false; 49 $courseordernumber = 0; 50 $maxcourses = count($courses); 51 $userediting = false; 52 // Intialise string/icon etc if user is editing and courses > 1 53 if ($this->page->user_is_editing() && (count($courses) > 1)) { 54 $userediting = true; 55 $this->page->requires->js_init_call('M.block_course_overview.add_handles'); 56 57 // Check if course is moving 58 $ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL); 59 $movingcourseid = optional_param('courseid', 0, PARAM_INT); 60 } 61 62 // Render first movehere icon. 63 if ($ismovingcourse) { 64 // Remove movecourse param from url. 65 $this->page->ensure_param_not_in_url('movecourse'); 66 67 // Show moving course notice, so user knows what is being moved. 68 $html .= $this->output->box_start('notice'); 69 $a = new stdClass(); 70 $a->fullname = $courses[$movingcourseid]->fullname; 71 $a->cancellink = html_writer::link($this->page->url, get_string('cancel')); 72 $html .= get_string('movingcourse', 'block_course_overview', $a); 73 $html .= $this->output->box_end(); 74 75 $moveurl = new moodle_url('/blocks/course_overview/move.php', 76 array('sesskey' => sesskey(), 'moveto' => 0, 'courseid' => $movingcourseid)); 77 // Create move icon, so it can be used. 78 $movetofirsticon = html_writer::empty_tag('img', 79 array('src' => $this->output->pix_url('movehere'), 80 'alt' => get_string('movetofirst', 'block_course_overview', $courses[$movingcourseid]->fullname), 81 'title' => get_string('movehere'))); 82 $moveurl = html_writer::link($moveurl, $movetofirsticon); 83 $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); 84 } 85 86 foreach ($courses as $key => $course) { 87 // If moving course, then don't show course which needs to be moved. 88 if ($ismovingcourse && ($course->id == $movingcourseid)) { 89 continue; 90 } 91 $html .= $this->output->box_start('coursebox', "course-{$course->id}"); 92 $html .= html_writer::start_tag('div', array('class' => 'course_title')); 93 // If user is editing, then add move icons. 94 if ($userediting && !$ismovingcourse) { 95 $moveicon = html_writer::empty_tag('img', 96 array('src' => $this->pix_url('t/move')->out(false), 97 'alt' => get_string('movecourse', 'block_course_overview', $course->fullname), 98 'title' => get_string('move'))); 99 $moveurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'movecourse' => 1, 'courseid' => $course->id)); 100 $moveurl = html_writer::link($moveurl, $moveicon); 101 $html .= html_writer::tag('div', $moveurl, array('class' => 'move')); 102 103 } 104 105 // No need to pass title through s() here as it will be done automatically by html_writer. 106 $attributes = array('title' => $course->fullname); 107 if ($course->id > 0) { 108 if (empty($course->visible)) { 109 $attributes['class'] = 'dimmed'; 110 } 111 $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); 112 $coursefullname = format_string(get_course_display_name_for_list($course), true, $course->id); 113 $link = html_writer::link($courseurl, $coursefullname, $attributes); 114 $html .= $this->output->heading($link, 2, 'title'); 115 } else { 116 $html .= $this->output->heading(html_writer::link( 117 new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)), 118 format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title'); 119 } 120 $html .= $this->output->box('', 'flush'); 121 $html .= html_writer::end_tag('div'); 122 123 if (!empty($config->showchildren) && ($course->id > 0)) { 124 // List children here. 125 if ($children = block_course_overview_get_child_shortnames($course->id)) { 126 $html .= html_writer::tag('span', $children, array('class' => 'coursechildren')); 127 } 128 } 129 130 // If user is moving courses, then down't show overview. 131 if (isset($overviews[$course->id]) && !$ismovingcourse) { 132 $html .= $this->activity_display($course->id, $overviews[$course->id]); 133 } 134 135 if ($config->showcategories != BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_NONE) { 136 // List category parent or categories path here. 137 $currentcategory = coursecat::get($course->category, IGNORE_MISSING); 138 if ($currentcategory !== null) { 139 $html .= html_writer::start_tag('div', array('class' => 'categorypath')); 140 if ($config->showcategories == BLOCKS_COURSE_OVERVIEW_SHOWCATEGORIES_FULL_PATH) { 141 foreach ($currentcategory->get_parents() as $categoryid) { 142 $category = coursecat::get($categoryid, IGNORE_MISSING); 143 if ($category !== null) { 144 $html .= $category->get_formatted_name().' / '; 145 } 146 } 147 } 148 $html .= $currentcategory->get_formatted_name(); 149 $html .= html_writer::end_tag('div'); 150 } 151 } 152 153 $html .= $this->output->box('', 'flush'); 154 $html .= $this->output->box_end(); 155 $courseordernumber++; 156 if ($ismovingcourse) { 157 $moveurl = new moodle_url('/blocks/course_overview/move.php', 158 array('sesskey' => sesskey(), 'moveto' => $courseordernumber, 'courseid' => $movingcourseid)); 159 $a = new stdClass(); 160 $a->movingcoursename = $courses[$movingcourseid]->fullname; 161 $a->currentcoursename = $course->fullname; 162 $movehereicon = html_writer::empty_tag('img', 163 array('src' => $this->output->pix_url('movehere'), 164 'alt' => get_string('moveafterhere', 'block_course_overview', $a), 165 'title' => get_string('movehere'))); 166 $moveurl = html_writer::link($moveurl, $movehereicon); 167 $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); 168 } 169 } 170 // Wrap course list in a div and return. 171 return html_writer::tag('div', $html, array('class' => 'course_list')); 172 } 173 174 /** 175 * Coustuct activities overview for a course 176 * 177 * @param int $cid course id 178 * @param array $overview overview of activities in course 179 * @return string html of activities overview 180 */ 181 protected function activity_display($cid, $overview) { 182 $output = html_writer::start_tag('div', array('class' => 'activity_info')); 183 foreach (array_keys($overview) as $module) { 184 $output .= html_writer::start_tag('div', array('class' => 'activity_overview')); 185 $url = new moodle_url("/mod/$module/index.php", array('id' => $cid)); 186 $modulename = get_string('modulename', $module); 187 $icontext = html_writer::link($url, $this->output->pix_icon('icon', $modulename, 'mod_'.$module, array('class'=>'iconlarge'))); 188 if (get_string_manager()->string_exists("activityoverview", $module)) { 189 $icontext .= get_string("activityoverview", $module); 190 } else { 191 $icontext .= get_string("activityoverview", 'block_course_overview', $modulename); 192 } 193 194 // Add collapsible region with overview text in it. 195 $output .= $this->collapsible_region($overview[$module], '', 'region_'.$cid.'_'.$module, $icontext, '', true); 196 197 $output .= html_writer::end_tag('div'); 198 } 199 $output .= html_writer::end_tag('div'); 200 return $output; 201 } 202 203 /** 204 * Constructs header in editing mode 205 * 206 * @param int $max maximum number of courses 207 * @return string html of header bar. 208 */ 209 public function editing_bar_head($max = 0) { 210 $output = $this->output->box_start('notice'); 211 212 $options = array('0' => get_string('alwaysshowall', 'block_course_overview')); 213 for ($i = 1; $i <= $max; $i++) { 214 $options[$i] = $i; 215 } 216 $url = new moodle_url('/my/index.php'); 217 $select = new single_select($url, 'mynumber', $options, block_course_overview_get_max_user_courses(), array()); 218 $select->set_label(get_string('numtodisplay', 'block_course_overview')); 219 $output .= $this->output->render($select); 220 221 $output .= $this->output->box_end(); 222 return $output; 223 } 224 225 /** 226 * Show hidden courses count 227 * 228 * @param int $total count of hidden courses 229 * @return string html 230 */ 231 public function hidden_courses($total) { 232 if ($total <= 0) { 233 return; 234 } 235 $output = $this->output->box_start('notice'); 236 $plural = $total > 1 ? 'plural' : ''; 237 $config = get_config('block_course_overview'); 238 // Show view all course link to user if forcedefaultmaxcourses is not empty. 239 if (!empty($config->forcedefaultmaxcourses)) { 240 $output .= get_string('hiddencoursecount'.$plural, 'block_course_overview', $total); 241 } else { 242 $a = new stdClass(); 243 $a->coursecount = $total; 244 $a->showalllink = html_writer::link(new moodle_url('/my/index.php', array('mynumber' => block_course_overview::SHOW_ALL_COURSES)), 245 get_string('showallcourses')); 246 $output .= get_string('hiddencoursecountwithshowall'.$plural, 'block_course_overview', $a); 247 } 248 249 $output .= $this->output->box_end(); 250 return $output; 251 } 252 253 /** 254 * Creates collapsable region 255 * 256 * @param string $contents existing contents 257 * @param string $classes class names added to the div that is output. 258 * @param string $id id added to the div that is output. Must not be blank. 259 * @param string $caption text displayed at the top. Clicking on this will cause the region to expand or contract. 260 * @param string $userpref the name of the user preference that stores the user's preferred default state. 261 * (May be blank if you do not wish the state to be persisted. 262 * @param bool $default Initial collapsed state to use if the user_preference it not set. 263 * @return bool if true, return the HTML as a string, rather than printing it. 264 */ 265 protected function collapsible_region($contents, $classes, $id, $caption, $userpref = '', $default = false) { 266 $output = $this->collapsible_region_start($classes, $id, $caption, $userpref, $default); 267 $output .= $contents; 268 $output .= $this->collapsible_region_end(); 269 270 return $output; 271 } 272 273 /** 274 * Print (or return) the start of a collapsible region, that has a caption that can 275 * be clicked to expand or collapse the region. If JavaScript is off, then the region 276 * will always be expanded. 277 * 278 * @param string $classes class names added to the div that is output. 279 * @param string $id id added to the div that is output. Must not be blank. 280 * @param string $caption text displayed at the top. Clicking on this will cause the region to expand or contract. 281 * @param string $userpref the name of the user preference that stores the user's preferred default state. 282 * (May be blank if you do not wish the state to be persisted. 283 * @param bool $default Initial collapsed state to use if the user_preference it not set. 284 * @return bool if true, return the HTML as a string, rather than printing it. 285 */ 286 protected function collapsible_region_start($classes, $id, $caption, $userpref = '', $default = false) { 287 // Work out the initial state. 288 if (!empty($userpref) and is_string($userpref)) { 289 user_preference_allow_ajax_update($userpref, PARAM_BOOL); 290 $collapsed = get_user_preferences($userpref, $default); 291 } else { 292 $collapsed = $default; 293 $userpref = false; 294 } 295 296 if ($collapsed) { 297 $classes .= ' collapsed'; 298 } 299 300 $output = ''; 301 $output .= '<div id="' . $id . '" class="collapsibleregion ' . $classes . '">'; 302 $output .= '<div id="' . $id . '_sizer">'; 303 $output .= '<div id="' . $id . '_caption" class="collapsibleregioncaption">'; 304 $output .= $caption . ' '; 305 $output .= '</div><div id="' . $id . '_inner" class="collapsibleregioninner">'; 306 $this->page->requires->js_init_call('M.block_course_overview.collapsible', array($id, $userpref, get_string('clicktohideshow'))); 307 308 return $output; 309 } 310 311 /** 312 * Close a region started with print_collapsible_region_start. 313 * 314 * @return string return the HTML as a string, rather than printing it. 315 */ 316 protected function collapsible_region_end() { 317 $output = '</div></div></div>'; 318 return $output; 319 } 320 321 /** 322 * Cretes html for welcome area 323 * 324 * @param int $msgcount number of messages 325 * @return string html string for welcome area. 326 */ 327 public function welcome_area($msgcount) { 328 global $CFG, $USER; 329 $output = $this->output->box_start('welcome_area'); 330 331 $picture = $this->output->user_picture($USER, array('size' => 75, 'class' => 'welcome_userpicture')); 332 $output .= html_writer::tag('div', $picture, array('class' => 'profilepicture')); 333 334 $output .= $this->output->box_start('welcome_message'); 335 $output .= $this->output->heading(get_string('welcome', 'block_course_overview', $USER->firstname)); 336 337 if (!empty($CFG->messaging)) { 338 $plural = 's'; 339 if ($msgcount > 0) { 340 $output .= get_string('youhavemessages', 'block_course_overview', $msgcount); 341 if ($msgcount == 1) { 342 $plural = ''; 343 } 344 } else { 345 $output .= get_string('youhavenomessages', 'block_course_overview'); 346 } 347 $output .= html_writer::link(new moodle_url('/message/index.php'), 348 get_string('message'.$plural, 'block_course_overview')); 349 } 350 $output .= $this->output->box_end(); 351 $output .= $this->output->box('', 'flush'); 352 $output .= $this->output->box_end(); 353 354 return $output; 355 } 356 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |