Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

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: 2802 lines (123 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

core_course_renderer:: (62 methods):
  __construct()
  add_modchoosertoggle()
  course_info_box()
  course_category_tree()
  course_category_tree_category()
  render_modchooser()
  course_modchooser()
  course_activitychooser()
  course_modchooser_module_types()
  course_modchooser_module()
  course_modchooser_title()
  course_section_cm_edit_actions()
  course_section_add_cm_control()
  course_section_add_cm_control_nonajax()
  course_search_form()
  course_section_cm_completion()
  is_cm_conditionally_hidden()
  course_section_cm_name()
  course_section_cm_classes()
  course_section_cm_name_title()
  course_section_cm_text()
  availability_info()
  course_section_cm_availability()
  course_section_cm_list_item()
  course_section_cm()
  course_section_cm_unavailable_error_message()
  course_section_cm_list()
  courses_list()
  course_name()
  course_enrolment_icons()
  coursecat_coursebox()
  course_summary()
  course_contacts()
  course_overview_files()
  course_category_name()
  course_custom_fields()
  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()
  render_activity_information()
  render_activity_navigation()
  sendingbackupinfo()
  hubinfo()
  frontpage_section1()
  frontpage_news()
  frontpage_part()
  frontpage()

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


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

param: stdClass $course
return: string

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

param: array $ignored argument ignored
return: string

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

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

render_modchooser(renderable $modchooser)   X-Ref
Render a modchooser.

param: renderable $modchooser The chooser.
return: string

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

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

course_activitychooser($courseid)   X-Ref
Build the HTML for the module chooser javascript popup.

param: int $courseid The course id to fetch modules for.
return: string

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

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

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

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

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

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

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

Renders the ajax control (the link which when clicked produces the activity chooser modal). No noscript fallback.

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

course_section_add_cm_control_nonajax($course, $section, $sectionreturn = null,$displayoptions = array()   X-Ref
Render the deprecated nonajax activity chooser.

param: stdClass $course the course object
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
return: string

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

param: string $value default value to populate the search field
return: string

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

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

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

param: cm_info $mod
return: bool

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

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

course_section_cm_classes(cm_info $mod)   X-Ref
Returns the CSS classes for the activity name/content

For items which are hidden, unavailable or stealth but should be displayed
to current user ($mod->is_visible_on_course_page()), we show those as dimmed.
Students will also see as dimmed activities names that are not yet available
but should still be displayed (without link) with availability info.

param: cm_info $mod
return: array array of two elements ($linkclasses, $textclasses)

course_section_cm_name_title(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

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

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)

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

availability_info($text, $additionalclasses = '')   X-Ref
Displays availability info for a course section or course module

param: string $text
param: string $additionalclasses
return: string

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)

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

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()}

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

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 course_get_cm_edit_actions()}
{@link core_course_renderer::course_section_cm_edit_actions()}

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

course_section_cm_unavailable_error_message(cm_info $cm)   X-Ref
Message displayed to the user when they try to access unavailable activity following URL

This method is a very simplified version of {@link course_section_cm()} to be part of the error
notification only. It also does not check if module is visible on course page or not.

The message will be displayed inside notification!

param: cm_info $cm
return: string

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()}

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
return: void

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.

param: array $courses array of course records (or instances of core_course_list_element) 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)
return: string

course_name(coursecat_helper $chelper, core_course_list_element $course)   X-Ref
Returns HTML to display course name.

param: coursecat_helper $chelper
param: core_course_list_element $course
return: string

course_enrolment_icons(core_course_list_element $course)   X-Ref
Returns HTML to display course enrolment icons.

param: core_course_list_element $course
return: string

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()}

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

course_summary(coursecat_helper $chelper, core_course_list_element $course)   X-Ref
Returns HTML to display course summary.

param: coursecat_helper $chelper
param: core_course_list_element $course
return: string

course_contacts(core_course_list_element $course)   X-Ref
Returns HTML to display course contacts.

param: core_course_list_element $course
return: string

course_overview_files(core_course_list_element $course)   X-Ref
Returns HTML to display course overview files.

param: core_course_list_element $course
return: string

course_category_name(coursecat_helper $chelper, core_course_list_element $course)   X-Ref
Returns HTML to display course category name.

param: coursecat_helper $chelper
param: core_course_list_element $course
return: string

course_custom_fields(core_course_list_element $course)   X-Ref
Returns HTML to display course custom fields.

param: core_course_list_element $course
return: string

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

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

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.

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

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

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

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

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

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()}

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

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

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

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|core_course_category $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

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

tagged_courses($tagid, $exclusivemode = true, $ctx = 0, $rec = true, $displayoptions = null)   X-Ref
Renders html to print list of courses tagged with particular tag

param: int $tagid id of the tag
param: bool $exclusivemode if set to true it means that no other entities tagged with this tag
param: int $fromctx context id where the link was displayed, may be used by callbacks
param: int $ctx context id where to search for records
param: bool $rec search in subcontexts as well
param: array $displayoptions
return: string empty string if no courses are marked with this tag or rendered list of courses

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

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

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

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

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

render_activity_information(\core_course\output\activity_information $page)   X-Ref
Renders the activity information.

Defer to template.

param: \core_course\output\activity_information $page
return: string html for the page

render_activity_navigation(\core_course\output\activity_navigation $page)   X-Ref
Renders the activity navigation.

Defer to template.

param: \core_course\output\activity_navigation $page
return: string html for the page

sendingbackupinfo($backupfile)   X-Ref
Display waiting information about backup size during uploading backup process

param: object $backupfile the backup stored_file
return: $html string

hubinfo($hubinfo)   X-Ref
Hub information (logo - name - description - link)

param: object $hubinfo
return: string html code

frontpage_section1()   X-Ref
Output frontpage summary text and frontpage modules (stored as section 1 in site course)

This may be disabled in settings

return: string

frontpage_news($forum)   X-Ref
Output news for the frontpage (extract from site-wide news forum)

param: stdClass $forum record from db table 'forum' that represents the site news forum
return: string

frontpage_part($skipdivid, $contentsdivid, $header, $contents)   X-Ref
Renders part of frontpage with a skip link (i.e. "My courses", "Site news", etc.)

param: string $skipdivid
param: string $contentsdivid
param: string $header Header of the part
param: string $contents Contents of the part
return: string

frontpage()   X-Ref
Outputs contents for frontpage as configured in $CFG->frontpage or $CFG->frontpageloggedin

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 core_course_category 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.

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

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

param: int $subcatdepth
return: coursecat_helper

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 core_course_category::get_courses() and/or core_course_category::search_courses()

Options that core_course_category::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
- customfields - preloads custom fields data
- 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.

param: array $options
return: coursecat_helper

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

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

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

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

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

This array is usually passed to {@link core_course_category::get_courses()} or
{@link core_course_category::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 core_course_category::get_children().
Any other options may be used by renderer functions

param: array $options
return: coursecat_helper

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

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

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

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

return: array

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

param: array $attributes
return: coursecat_helper

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

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

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

param: array $searchcriteria
return: coursecat_helper

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

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

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

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

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

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