Example #1
0
 /**
  * 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)
 {
     // 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';
         }
     }
     // 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));
     // category name
     $categoryname = $coursecat->get_formatted_name();
     $categoryname = html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $coursecat->id)), $categoryname);
     if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_COUNT && ($coursescount = $coursecat->get_courses_count())) {
         $categoryname .= html_writer::tag('span', ' (' . $coursescount . ')', array('title' => get_string('numberofcourses'), 'class' => 'numberofcourse'));
     }
     $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');
     // .info
     // add category content to the output
     $content .= html_writer::tag('div', $categorycontent, array('class' => 'content'));
     $content .= html_writer::end_tag('div');
     // .category
     // Return the course category tree HTML
     return $content;
 }
 /**
  * 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)
 {
     global $CFG, $OUTPUT;
     // 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));
     if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_COUNT) {
         $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 ($OUTPUT->get_setting('enablecategoryicon')) {
         if ($OUTPUT->get_setting($categoryiconnum) && $OUTPUT->get_setting('enablecustomcategoryicon')) {
             // User has set a value for the category
             $val = $OUTPUT->get_setting($categoryiconnum);
         } else {
             // User hasn't set a value for the category, get the default
             $val = $OUTPUT->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');
     // .info
     // add category content to the output
     $content .= html_writer::tag('div', $categorycontent, array('class' => 'content'));
     $content .= html_writer::end_tag('div');
     // .category
     return $content;
 }