View all courses: Difference between revisions
Line 14: | Line 14: | ||
===General proposal=== | ===General proposal=== | ||
Define '''class course_category implements renderable''' | |||
Each interface - frontpage, /course/index.php, /course/category.php, etc. has it's own function | |||
core_course_renderer will have the render function for it '''render_course_category()''' | |||
Each interface - frontpage, /course/index.php, /course/category.php, etc. has it's own function that creates an instance of the class with the necessary display options and renders it. | |||
Some options are taken from $CFG. It should be very easy for the themes to overwrite just those functions if they want more flexibility. Actually themes may have their own settings that control courses listings. | Some options are taken from $CFG. It should be very easy for the themes to overwrite just those functions if they want more flexibility. Actually themes may have their own settings that control courses listings. | ||
Line 21: | Line 24: | ||
There is also a script called from AJAX to load extended course contents, category, or another page of list of courses/categories. Options will be passed to AJAX script as arguments so it does not need to be changed by theme. | There is also a script called from AJAX to load extended course contents, category, or another page of list of courses/categories. Options will be passed to AJAX script as arguments so it does not need to be changed by theme. | ||
=== | ===course_category properties=== | ||
Some of them affect how to retrieve the data, some affect display only: | |||
* '''parentcategoryid''': if specified, display subcategories and courses in this category (0 means top level) | |||
* '''displaycourses''': [none, countonly, collapsed, expanded] how (if) display courses list | * '''displaycourses''': [none, countonly, collapsed, expanded] how (if) display courses list | ||
* '''expandsubcategoriesdepth''': depth to expand subcategories in the tree (deeper subcategories will be loaded by AJAX or proceed to category page by clicking on category name) | * '''expandsubcategoriesdepth''': depth to expand subcategories in the tree (deeper subcategories will be loaded by AJAX or proceed to category page by clicking on category name) | ||
* '''omitcategories''': for small sites, do not display categories names just list all courses in all subcategories | * '''omitcategories''': for small sites, do not display categories names just list all courses in all subcategories | ||
* '''sortcourses''': how to sort courses | * '''sortcourses''': how to sort courses | ||
* '''sortcategories''': how to sort subcategories | * '''sortcategories''': how to sort subcategories | ||
* '''categorieslimit''': limit the number of subcategories inside one category. If there are more categories, a link "More categories..." is displayed, which leads to the subcategory page, or displays the next page or loads more entries via AJAX | * '''categorieslimit''': limit the number of subcategories inside one category. If there are more categories, a link "More categories..." is displayed, which leads to the subcategory page, or displays the next page or loads more entries via AJAX. Defaults to $CFG->coursesperpage | ||
* '''courseslimit''': limit the number of courses inside one category. If there are more courses, a link "More courses..." is displayed which leads to the subcategory page, or displays the next page or loads more entries via AJAX | * '''courseslimit''': limit the number of courses inside one category. If there are more courses, a link "More courses..." is displayed which leads to the subcategory page, or displays the next page or loads more entries via AJAX. Defaults to $CFG->coursesperpage | ||
* '''categorieslimit1''', '''categorieslimit2''', etc.: limits the number of subcategories on the 1st nested level (if not specified, defaults to categorieslimit, categorieslimit1, etc.) | * '''categorieslimit1''', '''categorieslimit2''', etc.: limits the number of subcategories on the 1st nested level (if not specified, defaults to categorieslimit, categorieslimit1, etc.) | ||
* '''courseslimit1''', '''courseslimit2''', etc.: as above | * '''courseslimit1''', '''courseslimit2''', etc.: as above | ||
Line 43: | Line 48: | ||
/** basic function that displays tree of subcategories and list of courses */ | /** basic function that displays tree of subcategories and list of courses */ | ||
protected function render_course_category(course_category $course_category) { | |||
// ... | // ... | ||
} | } | ||
Line 51: | Line 56: | ||
global $CFG; | global $CFG; | ||
if ($displaytype == FRONTPAGECATEGORYNAMES || $displaytype == FRONTPAGECATEGORYCOMBO) { | if ($displaytype == FRONTPAGECATEGORYNAMES || $displaytype == FRONTPAGECATEGORYCOMBO) { | ||
$ | $coursecategory = new course_category(array( | ||
'parentcategoryid' => 0, | 'parentcategoryid' => 0, | ||
'expandsubcategoriesdepth' => $CFG->maxcategorydepth, | 'expandsubcategoriesdepth' => $CFG->maxcategorydepth, | ||
'displaycourses' => ($displaytype === 'categories') ? 'none' : 'collapsed', | 'displaycourses' => ($displaytype === 'categories') ? 'none' : 'collapsed', | ||
)); | |||
return $this->render($coursecategory); | |||
return $this-> | |||
} else if ($displaytype == FRONTPAGECOURSELIST) { | } else if ($displaytype == FRONTPAGECOURSELIST) { | ||
// more logic here, analyse $CFG->disablemycourses, etc. (see /index.php) | // more logic here, analyse $CFG->disablemycourses, etc. (see /index.php) | ||
$ | $coursecategory = new course_category(array( | ||
'parentcategoryid' => 0, | 'parentcategoryid' => 0, | ||
'enrolledcoursesonly' => true, | 'enrolledcoursesonly' => true, | ||
'omitcategories' => true, | 'omitcategories' => true, | ||
)); | |||
); | return $this->render($coursecategory); | ||
return $this-> | |||
} | } | ||
return ''; | return ''; | ||
Line 74: | Line 77: | ||
public function courses_list_all() { | public function courses_list_all() { | ||
global $CFG; | global $CFG; | ||
$ | $coursecategory = new course_category(array( | ||
'parentcategoryid' => 0, | 'parentcategoryid' => 0, | ||
'displaycourses' => 'collapsed', | 'displaycourses' => 'collapsed', | ||
)); | |||
return $this->render($coursecategory); | |||
); | |||
return $this-> | |||
} | } | ||
Line 86: | Line 87: | ||
public function course_category($category) { | public function course_category($category) { | ||
global $CFG; | global $CFG; | ||
$ | $coursecategory = new course_category(array( | ||
'parentcategoryid' => is_object($category) ? $category->id : $category, | 'parentcategoryid' => is_object($category) ? $category->id : $category, | ||
'displaycourses' => 'expanded', | 'displaycourses' => 'expanded', | ||
'sortcourses' => 'fullname', | 'sortcourses' => 'fullname', | ||
'sortcategories' => 'fullname', | 'sortcategories' => 'fullname', | ||
); | )); | ||
return $this-> | return $this->render($coursecategory); | ||
} | } | ||
} | } | ||
</pre> | </pre> |
Revision as of 05:43, 20 December 2012
See Courses and Categories Lists Overview in 2.4 for the current screens
Course/categories listings settings
The situation with settings is a little confusing at the moment. There are options that duplicate each other, ignored options, etc.
$CFG->frontpage and $CFG->frontpageloggedin are quite confusing as well, especially combination ($CFG->frontpageloggedin == FRONTPAGECOURSELIST && !empty($CFG->disablemycourses))
TODO
Course/categories listings renderer
General proposal
Define class course_category implements renderable
core_course_renderer will have the render function for it render_course_category()
Each interface - frontpage, /course/index.php, /course/category.php, etc. has it's own function that creates an instance of the class with the necessary display options and renders it.
Some options are taken from $CFG. It should be very easy for the themes to overwrite just those functions if they want more flexibility. Actually themes may have their own settings that control courses listings.
There is also a script called from AJAX to load extended course contents, category, or another page of list of courses/categories. Options will be passed to AJAX script as arguments so it does not need to be changed by theme.
course_category properties
Some of them affect how to retrieve the data, some affect display only:
- parentcategoryid: if specified, display subcategories and courses in this category (0 means top level)
- displaycourses: [none, countonly, collapsed, expanded] how (if) display courses list
- expandsubcategoriesdepth: depth to expand subcategories in the tree (deeper subcategories will be loaded by AJAX or proceed to category page by clicking on category name)
- omitcategories: for small sites, do not display categories names just list all courses in all subcategories
- sortcourses: how to sort courses
- sortcategories: how to sort subcategories
- categorieslimit: limit the number of subcategories inside one category. If there are more categories, a link "More categories..." is displayed, which leads to the subcategory page, or displays the next page or loads more entries via AJAX. Defaults to $CFG->coursesperpage
- courseslimit: limit the number of courses inside one category. If there are more courses, a link "More courses..." is displayed which leads to the subcategory page, or displays the next page or loads more entries via AJAX. Defaults to $CFG->coursesperpage
- categorieslimit1, categorieslimit2, etc.: limits the number of subcategories on the 1st nested level (if not specified, defaults to categorieslimit, categorieslimit1, etc.)
- courseslimit1, courseslimit2, etc.: as above
- ajaxdisabled: completely disable AJAX loading even if browser supports it
- enrolledcoursesonly: show only courses where this user is enrolled
- heading: add a heading (?)
Sample implementation
class core_course_renderer { /** basic function that displays tree of subcategories and list of courses */ protected function render_course_category(course_category $course_category) { // ... } /** invoked from /index.php */ public function frontpage_course_list($displaytype) { global $CFG; if ($displaytype == FRONTPAGECATEGORYNAMES || $displaytype == FRONTPAGECATEGORYCOMBO) { $coursecategory = new course_category(array( 'parentcategoryid' => 0, 'expandsubcategoriesdepth' => $CFG->maxcategorydepth, 'displaycourses' => ($displaytype === 'categories') ? 'none' : 'collapsed', )); return $this->render($coursecategory); } else if ($displaytype == FRONTPAGECOURSELIST) { // more logic here, analyse $CFG->disablemycourses, etc. (see /index.php) $coursecategory = new course_category(array( 'parentcategoryid' => 0, 'enrolledcoursesonly' => true, 'omitcategories' => true, )); return $this->render($coursecategory); } return ''; } /** invoked from /course/index.php */ public function courses_list_all() { global $CFG; $coursecategory = new course_category(array( 'parentcategoryid' => 0, 'displaycourses' => 'collapsed', )); return $this->render($coursecategory); } /** invoked from /course/category.php */ public function course_category($category) { global $CFG; $coursecategory = new course_category(array( 'parentcategoryid' => is_object($category) ? $category->id : $category, 'displaycourses' => 'expanded', 'sortcourses' => 'fullname', 'sortcategories' => 'fullname', )); return $this->render($coursecategory); } }