Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  • Differences Between: [Versions 28 and 30] [Versions 28 and 31] [Versions 28 and 32] [Versions 28 and 33] [Versions 28 and 34] [Versions 28 and 35] [Versions 28 and 36] [Versions 28 and 37]

    Renderer for use with the course section and all the goodness that falls within it. This renderer should contain methods useful to courses, and categories.

    Copyright: 2010 Sam Hemelryk
    License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
    File Size: 2455 lines (111 kb)
    Included or required:0 times
    Referenced: 1 time
    Includes or requires: 0 files

    Defines 2 classes

    core_course_renderer:: (40 methods):
      __construct()
      add_modchoosertoggle()
      course_info_box()
      course_category_tree()
      course_category_tree_category()
      course_modchooser()
      course_modchooser_module_types()
      course_modchooser_module()
      course_modchooser_title()
      course_section_cm_edit_actions()
      course_section_add_cm_control()
      course_search_form()
      course_section_cm_completion()
      is_cm_conditionally_hidden()
      course_section_cm_name()
      course_section_cm_text()
      course_section_cm_availability()
      course_section_cm_list_item()
      course_section_cm()
      course_section_cm_list()
      courses_list()
      coursecat_coursebox()
      coursecat_coursebox_content()
      coursecat_courses()
      coursecat_subcategories()
      coursecat_include_js()
      coursecat_category_content()
      coursecat_category()
      coursecat_tree()
      course_category()
      coursecat_ajax()
      search_courses()
      tagged_courses()
      frontpage_remote_course()
      frontpage_remote_host()
      frontpage_my_courses()
      frontpage_available_courses()
      add_new_course_button()
      frontpage_combo_list()
      frontpage_categories_list()

    coursecat_helper:: (17 methods):
      set_show_courses()
      get_show_courses()
      set_subcat_depth()
      get_subcat_depth()
      set_courses_display_options()
      set_courses_display_option()
      get_courses_display_option()
      get_courses_display_options()
      set_categories_display_options()
      get_categories_display_option()
      get_categories_display_options()
      set_attributes()
      get_and_erase_attributes()
      set_search_criteria()
      get_category_formatted_description()
      get_course_formatted_summary()
      get_course_formatted_name()


    Class: core_course_renderer  - X-Ref

    The core course renderer

    Can be retrieved with the following:
    $renderer = $PAGE->get_renderer('core','course');
    __construct(moodle_page $page, $target)   X-Ref
    Override the constructor so that we can initialise the string cache

    param: moodle_page $page
    param: string $target

    add_modchoosertoggle()   X-Ref
    Adds the item in course settings navigation to toggle modchooser

    Theme can overwrite as an empty function to exclude it (for example if theme does not
    use modchooser at all)

    course_info_box(stdClass $course)   X-Ref
    Renders course info box.

    return: string
    param: stdClass|course_in_list $course

    course_category_tree(array $ignored)   X-Ref
    Renderers a structured array of courses and categories into a nice XHTML tree structure.

    return: string
    param: array $ignored argument ignored

    course_category_tree_category(stdClass $category, $depth=1)   X-Ref
    Renderers a category for use with course_category_tree

    return: string
    param: array $category
    param: int $depth

    course_modchooser($modules, $course)   X-Ref
    Build the HTML for the module chooser javascript popup

    return: string The composed HTML for the module
    param: array $modules A set of modules as returned form @see
    param: object $course The course that will be displayed

    course_modchooser_module_types($modules)   X-Ref
    Build the HTML for a specified set of modules

    return: string The composed HTML for the module
    param: array $modules A set of modules as used by the

    course_modchooser_module($module, $classes = array('option')   X-Ref
    Return the HTML for the specified module adding any required classes

    return: string The composed HTML for the module
    param: object $module An object containing the title, and link. An
    param: array $classes Additional classes to add to the encompassing

    course_modchooser_title($title, $identifier = null)   X-Ref
    No description

    course_section_cm_edit_actions($actions, cm_info $mod = null, $displayoptions = array()   X-Ref
    Renders HTML for displaying the sequence of course module editing buttons

    return: string
    param: action_link[] $actions Array of action_link objects
    param: cm_info $mod The module we are displaying actions for.
    param: array $displayoptions additional display options:

    course_section_add_cm_control($course, $section, $sectionreturn = null, $displayoptions = array()   X-Ref
    Renders HTML for the menus to add activities and resources to the current course

    Note, if theme overwrites this function and it does not use modchooser,
    see also {@link core_course_renderer::add_modchoosertoggle()}

    return: string
    param: stdClass $course
    param: int $section relative section number (field course_sections.section)
    param: int $sectionreturn The section to link back to
    param: array $displayoptions additional display options, for example blocks add

    course_search_form($value = '', $format = 'plain')   X-Ref
    Renders html to display a course search form

    return: string
    param: string $value default value to populate the search field
    param: string $format display format - 'plain' (default), 'short' or 'navbar'

    course_section_cm_completion($course, &$completioninfo, cm_info $mod, $displayoptions = array()   X-Ref
    Renders html for completion box on course page

    If completion is disabled, returns empty string
    If completion is automatic, returns an icon of the current completion state
    If completion is manual, returns a form (with an icon inside) that allows user to
    toggle completion

    return: string
    param: stdClass $course course object
    param: completion_info $completioninfo completion info for the course, it is recommended
    param: cm_info $mod module to show completion for
    param: array $displayoptions display options, not used in core

    is_cm_conditionally_hidden(cm_info $mod)   X-Ref
    Checks if course module has any conditions that may make it unavailable for
    all or some of the students

    This function is internal and is only used to create CSS classes for the module name/text

    return: bool
    param: cm_info $mod

    course_section_cm_name(cm_info $mod, $displayoptions = array()   X-Ref
    Renders html to display a name with the link to the course module on a course page

    If module is unavailable for user but still needs to be displayed
    in the list, just the name is returned without a link

    Note, that for course modules that never have separate pages (i.e. labels)
    this function return an empty string

    return: string
    param: cm_info $mod
    param: array $displayoptions

    course_section_cm_text(cm_info $mod, $displayoptions = array()   X-Ref
    Renders html to display the module content on the course page (i.e. text of the labels)

    return: string
    param: cm_info $mod
    param: array $displayoptions

    course_section_cm_availability(cm_info $mod, $displayoptions = array()   X-Ref
    Renders HTML to show course module availability information (for someone who isn't allowed
    to see the activity itself, or for staff)

    return: string
    param: cm_info $mod
    param: array $displayoptions

    course_section_cm_list_item($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array()   X-Ref
    Renders HTML to display one course module for display within a section.

    This function calls:
    {@link core_course_renderer::course_section_cm()}

    return: String
    param: stdClass $course
    param: completion_info $completioninfo
    param: cm_info $mod
    param: int|null $sectionreturn
    param: array $displayoptions

    course_section_cm($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array()   X-Ref
    Renders HTML to display one course module in a course section

    This includes link, content, availability, completion info and additional information
    that module type wants to display (i.e. number of unread forum posts)

    This function calls:
    {@link core_course_renderer::course_section_cm_name()}
    {@link core_course_renderer::course_section_cm_text()}
    {@link core_course_renderer::course_section_cm_availability()}
    {@link core_course_renderer::course_section_cm_completion()}
    {@link course_get_cm_edit_actions()}
    {@link core_course_renderer::course_section_cm_edit_actions()}

    return: string
    param: stdClass $course
    param: completion_info $completioninfo
    param: cm_info $mod
    param: int|null $sectionreturn
    param: array $displayoptions

    course_section_cm_list($course, $section, $sectionreturn = null, $displayoptions = array()   X-Ref
    Renders HTML to display a list of course modules in a course section
    Also displays "move here" controls in Javascript-disabled mode

    This function calls {@link core_course_renderer::course_section_cm()}

    return: void
    param: stdClass $course course object
    param: int|stdClass|section_info $section relative section number or section object
    param: int $sectionreturn section number to return to
    param: int $displayoptions

    courses_list($courses, $showcategoryname = false, $additionalclasses = null, $paginationurl = null, $totalcount = null, $page = 0, $perpage = null)   X-Ref
    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.

    return: string
    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)

    coursecat_coursebox(coursecat_helper $chelper, $course, $additionalclasses = '')   X-Ref
    Displays one course in the list of courses.

    This is an internal function, to display an information about just one course
    please use {@link core_course_renderer::course_info_box()}

    return: string
    param: coursecat_helper $chelper various display options
    param: course_in_list|stdClass $course
    param: string $additionalclasses additional classes to add to the main <div> tag (usually

    coursecat_coursebox_content(coursecat_helper $chelper, $course)   X-Ref
    Returns HTML to display course content (summary, course contacts and optionally category name)

    This method is called from coursecat_coursebox() and may be re-used in AJAX

    return: string
    param: coursecat_helper $chelper various display options
    param: stdClass|course_in_list $course

    coursecat_courses(coursecat_helper $chelper, $courses, $totalcount = null)   X-Ref
    Renders the list of courses

    This is internal function, please use {@link core_course_renderer::courses_list()} or another public
    method from outside of the class

    If list of courses is specified in $courses; the argument $chelper is only used
    to retrieve display options and attributes, only methods get_show_courses(),
    get_courses_display_option() and get_and_erase_attributes() are called.

    return: string
    param: coursecat_helper $chelper various display options
    param: array $courses the list of courses to display
    param: int|null $totalcount total number of courses (affects display mode if it is AUTO or pagination if applicable),

    coursecat_subcategories(coursecat_helper $chelper, $coursecat, $depth)   X-Ref
    Renders the list of subcategories in a category

    return: string
    param: coursecat_helper $chelper various display options
    param: coursecat $coursecat
    param: int $depth depth of the category in the current tree

    coursecat_include_js()   X-Ref
    Make sure that javascript file for AJAX expanding of courses and categories content is included


    coursecat_category_content(coursecat_helper $chelper, $coursecat, $depth)   X-Ref
    Returns HTML to display the subcategories and courses in the given category

    This method is re-used by AJAX to expand content of not loaded category

    return: string
    param: coursecat_helper $chelper various display options
    param: coursecat $coursecat
    param: int $depth depth of the category in the current tree

    coursecat_category(coursecat_helper $chelper, $coursecat, $depth)   X-Ref
    Returns HTML to display a course category as a part of a tree

    This is an internal function, to display a particular category and all its contents
    use {@link core_course_renderer::course_category()}

    return: string
    param: coursecat_helper $chelper various display options
    param: coursecat $coursecat
    param: int $depth depth of this category in the current tree

    coursecat_tree(coursecat_helper $chelper, $coursecat)   X-Ref
    Returns HTML to display a tree of subcategories and courses in the given category

    return: string
    param: coursecat_helper $chelper various display options
    param: coursecat $coursecat top category (this category's name and description will NOT be added to the tree)

    course_category($category)   X-Ref
    Renders HTML to display particular course category - list of it's subcategories and courses

    Invoked from /course/index.php

    param: int|stdClass|coursecat $category

    coursecat_ajax()   X-Ref
    Serves requests to /course/category.ajax.php

    In this renderer implementation it may expand the category content or
    course content.

    return: string

    search_courses($searchcriteria)   X-Ref
    Renders html to display search result page

    return: string
    param: array $searchcriteria may contain elements: search, blocklist, modulelist, tagid

    tagged_courses($tagid)   X-Ref
    Renders html to print list of courses tagged with particular tag

    return: string empty string if no courses are marked with this tag or rendered list of courses
    param: int $tagid id of the tag

    frontpage_remote_course(stdClass $course)   X-Ref
    Returns HTML to display one remote course

    return: string
    param: stdClass $course remote course information, contains properties:

    frontpage_remote_host($host)   X-Ref
    Returns HTML to display one remote host

    return: string
    param: array $host host information, contains properties: name, url, count

    frontpage_my_courses()   X-Ref
    Returns HTML to print list of courses user is enrolled to for the frontpage

    Also lists remote courses or remote hosts if MNET authorisation is used

    return: string

    frontpage_available_courses()   X-Ref
    Returns HTML to print list of available courses for the frontpage

    return: string

    add_new_course_button()   X-Ref
    Returns HTML to the "add new course" button for the page

    return: string

    frontpage_combo_list()   X-Ref
    Returns HTML to print tree with course categories and courses for the frontpage

    return: string

    frontpage_categories_list()   X-Ref
    Returns HTML to print tree of course categories (with number of courses) for the frontpage

    return: string

    Class: coursecat_helper  - X-Ref

    Class storing display options and functions to help display course category and/or courses lists

    This is a wrapper for coursecat objects that also stores display options
    and functions to retrieve sorted and paginated lists of categories/courses.

    If theme overrides methods in core_course_renderers that access this class
    it may as well not use this class at all or extend it.

    set_show_courses($showcourses)   X-Ref
    Sets how (if) to show the courses - none, collapsed, expanded, etc.

    return: coursecat_helper
    param: int $showcourses SHOW_COURSES_NONE, SHOW_COURSES_COLLAPSED, SHOW_COURSES_EXPANDED, etc.

    get_show_courses()   X-Ref
    Returns how (if) to show the courses - none, collapsed, expanded, etc.

    return: int - COURSECAT_SHOW_COURSES_NONE, COURSECAT_SHOW_COURSES_COLLAPSED, COURSECAT_SHOW_COURSES_EXPANDED, etc.

    set_subcat_depth($subcatdepth)   X-Ref
    Sets the maximum depth to expand subcategories in the tree

    deeper subcategories may be loaded by AJAX or proceed to category page by clicking on category name

    return: coursecat_helper
    param: int $subcatdepth

    get_subcat_depth()   X-Ref
    Returns the maximum depth to expand subcategories in the tree

    deeper subcategories may be loaded by AJAX or proceed to category page by clicking on category name

    return: int

    set_courses_display_options($options)   X-Ref
    Sets options to display list of courses

    Options are later submitted as argument to coursecat::get_courses() and/or coursecat::search_courses()

    Options that coursecat::get_courses() accept:
    - recursive - return courses from subcategories as well. Use with care,
    this may be a huge list!
    - summary - preloads fields 'summary' and 'summaryformat'
    - coursecontacts - preloads course contacts
    - isenrolled - preloads indication whether this user is enrolled in the course
    - sort - list of fields to sort. Example
    array('idnumber' => 1, 'shortname' => 1, 'id' => -1)
    will sort by idnumber asc, shortname asc and id desc.
    Default: array('sortorder' => 1)
    Only cached fields may be used for sorting!
    - offset
    - limit - maximum number of children to return, 0 or null for no limit

    Options summary and coursecontacts are filled automatically in the set_show_courses()

    Also renderer can set here any additional options it wants to pass between renderer functions.

    return: coursecat_helper
    param: array $options

    set_courses_display_option($key, $value)   X-Ref
    Sets one option to display list of courses

    return: coursecat_helper
    param: string $key
    param: mixed $value

    get_courses_display_option($optionname, $defaultvalue = null)   X-Ref
    Return the specified option to display list of courses

    return: mixed
    param: string $optionname option name
    param: mixed $defaultvalue default value for option if it is not specified

    get_courses_display_options()   X-Ref
    Returns all options to display the courses

    This array is usually passed to {@link coursecat::get_courses()} or
    {@link coursecat::search_courses()}

    return: array

    set_categories_display_options($options)   X-Ref
    Sets options to display list of subcategories

    Options 'sort', 'offset' and 'limit' are passed to coursecat::get_children().
    Any other options may be used by renderer functions

    return: coursecat_helper
    param: array $options

    get_categories_display_option($optionname, $defaultvalue = null)   X-Ref
    Return the specified option to display list of subcategories

    return: mixed
    param: string $optionname option name
    param: mixed $defaultvalue default value for option if it is not specified

    get_categories_display_options()   X-Ref
    Returns all options to display list of subcategories

    This array is usually passed to {@link coursecat::get_children()}

    return: array

    set_attributes($attributes)   X-Ref
    Sets additional general options to pass between renderer functions, usually HTML attributes

    return: coursecat_helper
    param: array $attributes

    get_and_erase_attributes($classname)   X-Ref
    Return all attributes and erases them so they are not applied again

    return: array
    param: string $classname adds additional class name to the beginning of $attributes['class']

    set_search_criteria($searchcriteria)   X-Ref
    Sets the search criteria if the course is a search result

    Search string will be used to highlight terms in course name and description

    return: coursecat_helper
    param: array $searchcriteria

    get_category_formatted_description($coursecat, $options = null)   X-Ref
    Returns formatted and filtered description of the given category

    return: string|null
    param: coursecat $coursecat category
    param: stdClass|array $options format options, by default [noclean,overflowdiv],

    get_course_formatted_summary($course, $options = array()   X-Ref
    Returns given course's summary with proper embedded files urls and formatted

    return: string
    param: course_in_list $course
    param: array|stdClass $options additional formatting options

    get_course_formatted_name($course, $options = array()   X-Ref
    Returns course name as it is configured to appear in courses lists formatted to course context

    return: string
    param: course_in_list $course
    param: array|stdClass $options additional formatting options

    Search This Site: