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:38, 20 December 2012 by Marina Glancy (talk | contribs)

See Courses and Categories Lists Overview in 2.4 for the current screens

General proposal

Renderer has a base function, i.e. courses_and_subcategories_list() that accepts a number of options. Each interface - frontpage, /course/index.php, /course/category.php, etc. has it's own function that themes can override than creates an array of options to be passed to the base function

There is also a script called from AJAX to load extended course contents, category, or another page of list of courses/categories

Suggested options

  • displaycourses: [none, countonly, collapsed, expanded] how (if) display courses list
  • parentcategoryid: if specified, display subcategories and courses in this category (may be specified and = 0)
  • 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
  • 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
  • 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


class core_course_renderer {

/** basic function that displays tree of subcategories and list of courses */
public function courses_and_subcategories_list($displayoptions) {
  // ...
}

/** invoked from /index.php */
public function frontpage_course_list($displaytype) {
  if ($displaytype === 'categories' || $displaytype === 'combo') {
    $displayoptions = array(
      'parentcategoryid' => 0,
      'expandsubcategoriesdepth' => $CFG->maxcategorydepth,
      'displaycourses' => ($CFG->frontpage === 'combo') ? 'collapsed' : 'none',
    );
    return $this->courses_and_subcategories_list(0, $displayoptions);
  }
  return '';
}

/** invoked from /course/index.php */
public function courses_list_all() {
  $displayoptions = array(
    'parentcategoryid' => 0,
    'displaycourses' => 'collapsed',
  );
  return $this->courses_and_subcategories_list(0, $displayoptions);
}

/** invoked from /course/category.php */
public function course_category($category) {
  $displayoptions = array(
    'parentcategoryid' => 0,
    'displaycourses' => 'expanded',
    'coursesperpage' => $CFG->coursesperpage,
    'sortcourses' => 'fullname',
    'sortcategories' => 'fullname',
  );
  return $this->courses_and_subcategories_list($category, $displayoptions);
}

}