Note:

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

View all courses: Difference between revisions

From MoodleDocs
No edit summary
 
Line 1: Line 1:
See [[Courses and Categories Lists Overview in 2.4]] for the current screens
See [[Courses and Categories Lists Overview in 2.4]] for the current screens
Migration 2.4 -> 2.5 for developers : [[Courses lists upgrade to 2.5]]


==Front page settings==
==Front page settings==

Latest revision as of 02:12, 11 March 2013

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

Migration 2.4 -> 2.5 for developers : Courses lists upgrade to 2.5

Front page settings

Current situation

There are two settings 'frontpage' and 'frontpageloggedin' that allow admin to select the sections to be shown on front page (for not logged in/guest and logged in users respectfully). There are 4 available types of sections:

  • FRONTPAGENEWS(0) => 'News items'
  • FRONTPAGECOURSELIST(1) => 'List of courses'
  • FRONTPAGECATEGORYNAMES(2) => 'List of categories'
  • FRONTPAGECATEGORYCOMBO(4) => 'Combo list'

"News items" is not related to courses list

"List of courses" will show:

  • if user is logged in and not admin and empty($CFG->disablemycourses) - My courses including remote courses
  • otherwise if number of courses in the system is less than FRONTPAGECOURSELIMIT (200) - All courses
  • otherwise - course search box

"List of categories" and "Combo list" will show categories or categories&courses combo but in completely different layouts. The number of shown sublevels is regulated by $CFG->maxcategorydepth

Proposed solution

Leave settings 'frontpage' and 'frontpageloggedin' but have different set of available options there:

  • News items;
  • Enrolled courses (legacy) (available only in 'frontpageloggedin') - shows courses this user is enrolled in and remote courses. Not recommended to use, suggest to substitute with "My moodle" page;
  • Course search box;
  • List of courses - shows all courses with descriptions without organising them by category. Only first FRONTPAGECOURSELIMIT (200) courses are shown, and then link 'More...'.
  • List of categories - shows course categories only;
  • Combo list - shows courses names (with link to descriptions) organised by categories.

During upgrade we analyse $CFG->disablemycourses and may substitute 'List of courses' in $CFG->frontpageloggedin with 'Enrolled courses'. Also we will replace 'List of courses' or 'Combo list' with 'Course search box' (if number of courses in the system is more than 200 or 500 respectfully), so that users see the same type of listing on the frontpage after upgrade.

Also develop a block that shows remote courses and hosts to be added to the 'My moodle' page

Changes to settings:

  • Transform FRONTPAGECOURSELIMIT into $CFG->frontpagecourselimit, by default 200
  • Deprecate $CFG->disablemycourses, remove it from config-distr.php
  • Deprecate $CFG->numcoursesincombo (500) - there may be not many categories on each of top levels and $CFG->maxcategorydepth is reasonable, why not show the combo list even when there are many courses in the system?

Course/categories listings renderer

Pages

/course/category.php is deprecated, it redirects to /course/index.php. Later accepts the 'id' argument (category id)

/course/index.php shows that category content (has 'id' argument). View only.

Categories editing to be moved to /course/manage.php and should not depend on editing mode.

Category listing prepare and rendering

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, 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, auto] 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 course_category($category) {
  global $CFG;
  $coursecategory = new course_category(array(
    'id' => is_object($category) ? $category->id : $category,
    'displaycourses' => 'auto',
    'sortcourses' => 'sortorder',
    'sortcategories' => 'sortorder',
  ));
  return $this->render($coursecategory);
}

}