|
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 00035 class core_course_renderer extends plugin_renderer_base { 00036 00041 protected $strings; 00042 00049 public function __construct(moodle_page $page, $target) { 00050 $this->strings = new stdClass; 00051 parent::__construct($page, $target); 00052 } 00053 00064 public function course_category_tree(array $structure) { 00065 $this->strings->summary = get_string('summary'); 00066 00067 // Generate an id and the required JS call to make this a nice widget 00068 $id = html_writer::random_id('course_category_tree'); 00069 $this->page->requires->js_init_call('M.util.init_toggle_class_on_click', array($id, '.category.with_children .category_label', 'collapsed', '.category.with_children')); 00070 00071 // Start content generation 00072 $content = html_writer::start_tag('div', array('class'=>'course_category_tree', 'id'=>$id)); 00073 foreach ($structure as $category) { 00074 $content .= $this->course_category_tree_category($category); 00075 } 00076 $content .= html_writer::start_tag('div', array('class'=>'controls')); 00077 $content .= html_writer::tag('div', get_string('collapseall'), array('class'=>'addtoall expandall')); 00078 $content .= html_writer::tag('div', get_string('expandall'), array('class'=>'removefromall collapseall')); 00079 $content .= html_writer::end_tag('div'); 00080 $content .= html_writer::end_tag('div'); 00081 00082 // Return the course category tree HTML 00083 return $content; 00084 } 00085 00093 protected function course_category_tree_category(stdClass $category, $depth=1) { 00094 $content = ''; 00095 $hassubcategories = (isset($category->categories) && count($category->categories)>0); 00096 $hascourses = (isset($category->courses) && count($category->courses)>0); 00097 $classes = array('category'); 00098 if ($category->parent != 0) { 00099 $classes[] = 'subcategory'; 00100 } 00101 if (empty($category->visible)) { 00102 $classes[] = 'dimmed_category'; 00103 } 00104 if ($hassubcategories || $hascourses) { 00105 $classes[] = 'with_children'; 00106 if ($depth > 1) { 00107 $classes[] = 'collapsed'; 00108 } 00109 } 00110 $categoryname = format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id))); 00111 00112 $content .= html_writer::start_tag('div', array('class'=>join(' ', $classes))); 00113 $content .= html_writer::start_tag('div', array('class'=>'category_label')); 00114 $content .= html_writer::link(new moodle_url('/course/category.php', array('id'=>$category->id)), $categoryname, array('class'=>'category_link')); 00115 $content .= html_writer::end_tag('div'); 00116 if ($hassubcategories) { 00117 $content .= html_writer::start_tag('div', array('class'=>'subcategories')); 00118 foreach ($category->categories as $subcategory) { 00119 $content .= $this->course_category_tree_category($subcategory, $depth+1); 00120 } 00121 $content .= html_writer::end_tag('div'); 00122 } 00123 if ($hascourses) { 00124 $content .= html_writer::start_tag('div', array('class'=>'courses')); 00125 $coursecount = 0; 00126 foreach ($category->courses as $course) { 00127 $classes = array('course'); 00128 $linkclass = 'course_link'; 00129 if (!$course->visible) { 00130 $linkclass .= ' dimmed'; 00131 } 00132 $coursecount ++; 00133 $classes[] = ($coursecount%2)?'odd':'even'; 00134 $content .= html_writer::start_tag('div', array('class'=>join(' ', $classes))); 00135 $content .= html_writer::link(new moodle_url('/course/view.php', array('id'=>$course->id)), format_string($course->fullname), array('class'=>$linkclass)); 00136 $content .= html_writer::start_tag('div', array('class'=>'course_info clearfix')); 00137 00138 // print enrol info 00139 if ($icons = enrol_get_course_info_icons($course)) { 00140 foreach ($icons as $pix_icon) { 00141 $content .= $this->render($pix_icon); 00142 } 00143 } 00144 00145 if ($course->summary) { 00146 $image = html_writer::empty_tag('img', array('src'=>$this->output->pix_url('i/info'), 'alt'=>$this->strings->summary)); 00147 $content .= html_writer::link(new moodle_url('/course/info.php', array('id'=>$course->id)), $image, array('title'=>$this->strings->summary)); 00148 } 00149 $content .= html_writer::end_tag('div'); 00150 $content .= html_writer::end_tag('div'); 00151 } 00152 $content .= html_writer::end_tag('div'); 00153 } 00154 $content .= html_writer::end_tag('div'); 00155 return $content; 00156 } 00157 }