Exemplo n.º 1
0
 /**
  * Renders the list of subcategories in a category
  *
  * @param coursecat_helper $chelper various display options
  * @param coursecat $coursecat
  * @param int $depth depth of the category in the current tree
  * @return string
  */
 protected function coursecat_subcategories(coursecat_helper $chelper, $coursecat, $depth)
 {
     global $CFG;
     $subcategories = array();
     if (!$chelper->get_categories_display_option('nodisplay')) {
         $subcategories = $coursecat->get_children($chelper->get_categories_display_options());
     }
     $totalcount = $coursecat->get_children_count();
     if (!$totalcount) {
         // Note that we call coursecat::get_children_count() AFTER coursecat::get_children() to avoid extra DB requests.
         // Categories count is cached during children categories retrieval.
         return '';
     }
     // prepare content of paging bar or more link if it is needed
     $paginationurl = $chelper->get_categories_display_option('paginationurl');
     $paginationallowall = $chelper->get_categories_display_option('paginationallowall');
     if ($totalcount > count($subcategories)) {
         if ($paginationurl) {
             // the option 'paginationurl was specified, display pagingbar
             $perpage = $chelper->get_categories_display_option('limit', $CFG->coursesperpage);
             $page = $chelper->get_categories_display_option('offset') / $perpage;
             $pagingbar = $this->paging_bar($totalcount, $page, $perpage, $paginationurl->out(false, array('perpage' => $perpage)));
             if ($paginationallowall) {
                 $pagingbar .= html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => 'all')), get_string('showall', '', $totalcount)), array('class' => 'paging paging-showall'));
             }
         } else {
             if ($viewmoreurl = $chelper->get_categories_display_option('viewmoreurl')) {
                 // the option 'viewmoreurl' was specified, display more link (if it is link to category view page, add category id)
                 if ($viewmoreurl->compare(new moodle_url('/course/index.php'), URL_MATCH_BASE)) {
                     $viewmoreurl->param('categoryid', $coursecat->id);
                 }
                 $viewmoretext = $chelper->get_categories_display_option('viewmoretext', new lang_string('viewmore'));
                 $morelink = html_writer::tag('div', html_writer::link($viewmoreurl, $viewmoretext), array('class' => 'paging paging-morelink'));
             }
         }
     } else {
         if ($totalcount > $CFG->coursesperpage && $paginationurl && $paginationallowall) {
             // there are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode
             $pagingbar = html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => $CFG->coursesperpage)), get_string('showperpage', '', $CFG->coursesperpage)), array('class' => 'paging paging-showperpage'));
         }
     }
     // display list of subcategories
     $content = html_writer::start_tag('div', array('class' => 'subcategories'));
     if (!empty($pagingbar)) {
         $content .= $pagingbar;
     }
     foreach ($subcategories as $subcategory) {
         $content .= $this->coursecat_category($chelper, $subcategory, $depth + 1);
     }
     if (!empty($pagingbar)) {
         $content .= $pagingbar;
     }
     if (!empty($morelink)) {
         $content .= $morelink;
     }
     $content .= html_writer::end_tag('div');
     return $content;
 }