Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

View all courses

From MoodleDocs
Revision as of 04:02, 2 January 2013 by Marina Glancy (talk | contribs)

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:

  • id: 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)
  • omitsubcategories: 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 courses_list_frontpage($displaytype) {
  global $CFG;
  if ($displaytype == FRONTPAGECATEGORYNAMES || $displaytype == FRONTPAGECATEGORYCOMBO) {
    $coursecategory = new course_category(array(
      'id' => 0,
      'expandsubcategoriesdepth' => $CFG->maxcategorydepth,
      'displaycourses' => ($displaytype === FRONTPAGECATEGORYNAMES) ? '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(
      'id' => 0,
      'enrolledcoursesonly' => true,
      'omitsubcategories' => true,
    ));
    return $this->render($coursecategory);
  }
  return '';
}

/** invoked from /course/index.php */
public function courses_list_all() {
  global $CFG;
  $coursecategory = new course_category(array(
    'id' => 0,
    'displaycourses' => 'collapsed',
  ));
  return $this->render($coursecategory);
}

/** invoked from /course/category.php */
public function course_category($category) {
  global $CFG;
  $coursecategory = new course_category(array(
    'id' => is_object($category) ? $category->id : $category,
    'displaycourses' => 'expanded',
    'sortcourses' => 'fullname',
    'sortcategories' => 'fullname',
  ));
  return $this->render($coursecategory);
}

}