/** * Renders the list of courses * * This is internal function, please use {@link core_course_renderer::courses_list()} or another public * method from outside of the class * * If list of courses is specified in $courses; the argument $chelper is only used * to retrieve display options and attributes, only methods get_show_courses(), * get_courses_display_option() and get_and_erase_attributes() are called. * * @param coursecat_helper $chelper various display options * @param array $courses the list of courses to display * @param int|null $totalcount total number of courses (affects display mode if it is AUTO or pagination if applicable), * defaulted to count($courses) * @return string */ protected function coursecat_courses(coursecat_helper $chelper, $courses, $totalcount = null) { global $CFG; if ($totalcount === null) { $totalcount = count($courses); } if (!$totalcount) { // Courses count is cached during courses retrieval. return ''; } if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO) { // In 'auto' course display mode we analyse if number of courses is more or less than $CFG->courseswithsummarieslimit if ($totalcount <= $CFG->courseswithsummarieslimit) { $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED); } else { $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED); } } // prepare content of paging bar if it is needed $paginationurl = $chelper->get_courses_display_option('paginationurl'); $paginationallowall = $chelper->get_courses_display_option('paginationallowall'); if ($totalcount > count($courses)) { // there are more results that can fit on one page if ($paginationurl) { // the option paginationurl was specified, display pagingbar $perpage = $chelper->get_courses_display_option('limit', $CFG->coursesperpage); $page = $chelper->get_courses_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_courses_display_option('viewmoreurl')) { // the option for 'View more' link was specified, display more link $viewmoretext = $chelper->get_courses_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 courses $attributes = $chelper->get_and_erase_attributes('courses'); $content = html_writer::start_tag('div', $attributes); if (!empty($pagingbar)) { $content .= $pagingbar; } $coursecount = 0; foreach ($courses as $course) { $coursecount++; $classes = $coursecount % 2 ? 'odd' : 'even'; if ($coursecount == 1) { $classes .= ' first'; } if ($coursecount >= count($courses)) { $classes .= ' last'; } $content .= $this->coursecat_coursebox($chelper, $course, $classes); } if (!empty($pagingbar)) { $content .= $pagingbar; } if (!empty($morelink)) { $content .= $morelink; } $content .= html_writer::end_tag('div'); // .courses return $content; }