Permalink
Browse files

MDL-37009 Added function core_course_renderer::courses_list() similar…

… to print_courses()
  • Loading branch information...
marinaglancy committed Mar 19, 2013
1 parent e2d70cc commit 9176cdb63230fdaf1787e7c8c79393e1872df451
Showing with 48 additions and 0 deletions.
  1. +48 −0 course/renderer.php
View
@@ -1052,6 +1052,54 @@ public function course_section_cm_list($course, $section, $sectionreturn = null,
return $output;
}
+ /**
+ * Displays a custom list of courses with paging bar if necessary
+ *
+ * If $paginationurl is specified but $totalcount is not, the link 'View more'
+ * appears under the list.
+ *
+ * If both $paginationurl and $totalcount are specified, and $totalcount is
+ * bigger than count($courses), a paging bar is displayed above and under the
+ * courses list.
+ *
+ * @param array $courses array of course records (or instances of course_in_list) to show on this page
+ * @param bool $showcategoryname whether to add category name to the course description
+ * @param string $additionalclasses additional CSS classes to add to the div.courses
+ * @param moodle_url $paginationurl url to view more or url to form links to the other pages in paging bar
+ * @param int $totalcount total number of courses on all pages, if omitted $paginationurl will be displayed as 'View more' link
+ * @param int $page current page number (defaults to 0 referring to the first page)
+ * @param int $perpage number of records per page (defaults to $CFG->coursesperpage)
+ * @return string
+ */
+ public function courses_list($courses, $showcategoryname = false, $additionalclasses = null, $paginationurl = null, $totalcount = null, $page = 0, $perpage = null) {
+ global $CFG;
+ // create instance of coursecat_helper to pass display options to function rendering courses list
+ $chelper = new coursecat_helper();
+ if ($showcategoryname) {
+ $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT);
+ } else {
+ $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED);
+ }
+ if ($totalcount !== null && $paginationurl !== null) {
+ // add options to display pagination
+ if ($perpage === null) {
+ $perpage = $CFG->coursesperpage;
+ }
+ $chelper->set_courses_display_options(array(
+ 'limit' => $perpage,
+ 'offset' => ((int)$page) * $perpage,
+ 'paginationurl' => $paginationurl,
+ ));
+ } else if ($paginationurl !== null) {
+ // add options to display 'View more' link
+ $chelper->set_courses_display_options(array('viewmoreurl' => $paginationurl));
+ $totalcount = count($courses) + 1; // has to be bigger than count($courses) otherwise link will not be displayed
+ }
+ $chelper->set_attributes(array('class' => $additionalclasses));
+ $content = $this->coursecat_courses($chelper, $courses, $totalcount);
+ return $content;
+ }
+
/**
* Displays one course in the list of courses.
*

0 comments on commit 9176cdb

Please sign in to comment.