/** * Returns HTML to display a course category as a part of a tree * * This is an internal function, to display a particular category and all its contents * use {@link core_course_renderer::course_category()} * * @param coursecat_helper $chelper various display options * @param coursecat $coursecat * @param int $depth depth of this category in the current tree * @return string */ protected function coursecat_category(coursecat_helper $chelper, $coursecat, $depth) { if (!$this->enablecategoryicon) { return parent::coursecat_category($chelper, $coursecat, $depth); } global $CFG; // Open category tag. $classes = array('category'); if (empty($coursecat->visible)) { $classes[] = 'dimmed_category'; } if ($chelper->get_subcat_depth() > 0 && $depth >= $chelper->get_subcat_depth()) { // Do not load content. $categorycontent = ''; $classes[] = 'notloaded'; if ($coursecat->get_children_count() || $chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_COLLAPSED && $coursecat->get_courses_count()) { $classes[] = 'with_children'; $classes[] = 'collapsed'; } } else { // Load category content. $categorycontent = $this->coursecat_category_content($chelper, $coursecat, $depth); $classes[] = 'loaded'; if (!empty($categorycontent)) { $classes[] = 'with_children'; } } $classes[] = 'essentialcats'; if (intval($CFG->version) >= 2013111800) { // Make sure JS file to expand category content is included. $this->coursecat_include_js(); } $content = html_writer::start_tag('div', array('class' => join(' ', $classes), 'data-categoryid' => $coursecat->id, 'data-depth' => $depth, 'data-showcourses' => $chelper->get_show_courses(), 'data-type' => self::COURSECAT_TYPE_CATEGORY)); $coursescount = $coursecat->get_courses_count(); $content .= html_writer::tag('span', '(' . $coursescount . ')', array('title' => get_string('numberofcourses'), 'class' => 'numberofcourse')); // Category name. $categoryname = html_writer::tag('span', $coursecat->get_formatted_name()); $categoryiconnum = 'categoryicon' . $coursecat->id; // Do a settings check to output our icon for the category. if (\theme_essential\toolbox::get_setting('enablecategoryicon')) { if (\theme_essential\toolbox::get_setting($categoryiconnum) && \theme_essential\toolbox::get_setting('enablecustomcategoryicon')) { // User has set a value for the category. $val = \theme_essential\toolbox::get_setting($categoryiconnum); } else { // User hasn't set a value for the category, get the default. $val = \theme_essential\toolbox::get_setting('defaultcategoryicon'); } } if (!empty($val)) { $icon = html_writer::tag('i', '', array('class' => 'fa fa-' . $val)); } else { $icon = ''; } $categoryname = html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $coursecat->id)), $icon . $categoryname); $content .= html_writer::start_tag('div', array('class' => 'info')); $content .= html_writer::tag($depth > 1 ? 'h4' : 'h3', $categoryname, array('class' => 'categoryname')); $content .= html_writer::end_tag('div'); // Class .info. // Add category content to the output. $content .= html_writer::tag('div', $categorycontent, array('class' => 'content')); $content .= html_writer::end_tag('div'); // Class .category. return $content; }