Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
/lib/ -> modinfolib.php (source)

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

modinfolib.php - Functions/classes relating to cached information about module instances on a course.

Author: sam marshall
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 3393 lines (135 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 4 classes

course_modinfo:: (31 methods):
  __get()
  __isset()
  __empty()
  __set()
  get_course()
  get_course_id()
  get_user_id()
  get_sections()
  get_cms()
  get_cm()
  get_instances()
  get_used_module_names()
  get_instances_of()
  get_groups_all()
  get_groups()
  get_section_info_all()
  get_section_info()
  get_section_info_by_id()
  clear_instance_cache()
  instance()
  __construct()
  build_section_cache()
  build_course_section_cache()
  build_course_cache()
  inner_build_course_cache()
  purge_course_section_cache_by_id()
  purge_course_section_cache_by_number()
  purge_course_module_cache()
  purge_course_modules_cache()
  get_array_of_activities()
  purge_course_cache()

cm_info:: (64 methods):
  __call()
  __get()
  getIterator()
  __isset()
  __empty()
  __set()
  has_view()
  get_url()
  get_content()
  get_formatted_content()
  has_custom_cmlist_item()
  get_name()
  get_formatted_name()
  get_extra_classes()
  get_on_click()
  get_custom_data()
  get_after_link()
  get_activitybadge()
  get_after_edit_icons()
  get_icon_url()
  get_grouping_label()
  get_module_type_name()
  get_module_type_name_plural()
  get_modinfo()
  get_section_info()
  get_course()
  get_course_id()
  get_course_groupmode()
  get_course_groupmodeforce()
  get_effective_groupmode()
  get_context()
  get_course_module_record()
  set_content()
  set_extra_classes()
  set_icon_url()
  set_on_click()
  override_customdata()
  set_after_link()
  set_after_edit_icons()
  set_name()
  set_no_view_link()
  set_user_visible()
  set_custom_cmlist_item()
  set_available()
  check_not_view_only()
  __construct()
  create()
  obtain_dynamic_data()
  get_user_visible()
  is_visible_on_course_page()
  is_stealth()
  get_available()
  get_deprecated_group_members_only()
  get_available_info()
  update_user_visible()
  is_user_access_restricted_by_group()
  is_user_access_restricted_by_capability()
  is_user_access_restricted_by_conditional_access()
  call_mod_function()
  obtain_view_data()
  get_fast_modinfo()
  get_course_and_cm_from_cmid()
  get_course_and_cm_from_instance()
  rebuild_course_cache()

cached_cm_info:: (0 methods):

section_info:: (12 methods):
  __construct()
  __isset()
  __empty()
  __get()
  get_available()
  get_availableinfo()
  getIterator()
  get_uservisible()
  get_sequence()
  get_course()
  get_modinfo()
  convert_for_section_cache()


Class: course_modinfo  - X-Ref

Information about a course that is cached in the course table 'modinfo' field (and then in
memory) in order to reduce the need for other database queries.

This includes information about the course-modules and the sections on the course. It can also
include dynamic data that has been updated for the current user.

Use {@link get_fast_modinfo()} to retrieve the instance of the object for particular course
and particular user.

__get($name)   X-Ref
Magic method getter

param: string $name
return: mixed

__isset($name)   X-Ref
Magic method for function isset()

param: string $name
return: bool

__empty($name)   X-Ref
Magic method for function empty()

param: string $name
return: bool

__set($name, $value)   X-Ref
Magic method setter

Will display the developer warning when trying to set/overwrite existing property.

param: string $name
param: mixed $value

get_course()   X-Ref
Returns course object that was used in the first {@link get_fast_modinfo()} call.

It may not contain all fields from DB table {course} but always has at least the following:
id,shortname,fullname,format,enablecompletion,groupmode,groupmodeforce,cacherev

return: stdClass

get_course_id()   X-Ref

return: int Course ID

get_user_id()   X-Ref

return: int User ID

get_sections()   X-Ref

return: array Array from section number (e.g. 0) to array of course-module IDs in that

get_cms()   X-Ref

return: cm_info[] Array from course-module instance to cm_info object within this course, in

get_cm($cmid)   X-Ref
Obtains a single course-module object (for a course-module that is on this course).

param: int $cmid Course-module ID
return: cm_info Information about that course-module

get_instances()   X-Ref
Obtains all module instances on this course.

return: cm_info[][] Array from module name => array from instance id => cm_info

get_used_module_names($plural = false)   X-Ref
Returns array of localised human-readable module names used in this course

param: bool $plural if true returns the plural form of modules names
return: array

get_instances_of($modname)   X-Ref
Obtains all instances of a particular module on this course.

param: string $modname Name of module (not full frankenstyle) e.g. 'label'
return: cm_info[] Array from instance id => cm_info for modules on this course; empty if none

get_groups_all()   X-Ref
Groups that the current user belongs to organised by grouping id. Calculated on the first request.

return: int[][] array of grouping id => array of group id => group id. Includes grouping id 0 for 'all groups'

get_groups($groupingid = 0)   X-Ref
Returns groups that the current user belongs to on the course. Note: If not already
available, this may make a database query.

param: int $groupingid Grouping ID or 0 (default) for all groups
return: int[] Array of int (group id) => int (same group id again); empty array if none

get_section_info_all()   X-Ref
Gets all sections as array from section number => data about section.

return: section_info[] Array of section_info objects organised by section number

get_section_info($sectionnumber, $strictness = IGNORE_MISSING)   X-Ref
Gets data about specific numbered section.

param: int $sectionnumber Number (not id) of section
param: int $strictness Use MUST_EXIST to throw exception if it doesn't
return: section_info Information for numbered section or null if not found

get_section_info_by_id(int $sectionid, int $strictness = IGNORE_MISSING)   X-Ref
Gets data about specific section ID.

param: int $sectionid ID (not number) of section
param: int $strictness Use MUST_EXIST to throw exception if it doesn't
return: section_info|null Information for numbered section or null if not found

clear_instance_cache($courseorid = null, int $newcacherev = 0)   X-Ref
Clears the cache used in course_modinfo::instance()

Used in {@link get_fast_modinfo()} when called with argument $reset = true
and in {@link rebuild_course_cache()}

If the cacherev for the course is known to have updated (i.e. when doing
rebuild_course_cache), it should be specified here.

param: null|int|stdClass $courseorid if specified removes only cached value for this course
param: int $newcacherev If specified, the known cache rev for this course id will be updated

instance($courseorid, $userid = 0)   X-Ref
Returns the instance of course_modinfo for the specified course and specified user

This function uses static cache for the retrieved instances. The cache
size is limited by MAX_MODINFO_CACHE_SIZE. If instance is not found in
the static cache or it was created for another user or the cacherev validation
failed - a new instance is constructed and returned.

Used in {@link get_fast_modinfo()}

param: int|stdClass $courseorid object from DB table 'course' (must have field 'id'
param: int $userid User id to populate 'availble' and 'uservisible' attributes of modules and sections.
return: course_modinfo

__construct($course, $userid)   X-Ref
Constructs based on course.
Note: This constructor should not usually be called directly.
Use get_fast_modinfo($course) instead as this maintains a cache.

param: stdClass $course course object, only property id is required.
param: int $userid User ID

build_section_cache($courseid)   X-Ref
This method can not be used anymore.


build_course_section_cache(\stdClass $course, bool $usecache = false)   X-Ref
Builds a list of information about sections on a course to be stored in
the course cache. (Does not include information that is already cached
in some other way.)

param: stdClass $course Course object (must contain fields
param: boolean $usecache use cached section info if exists, use true for partial course rebuild
return: array Information about sections, indexed by section number (not id)

build_course_cache(\stdClass $course, bool $partialrebuild = false)   X-Ref
Builds and stores in MUC object containing information about course
modules and sections together with cached fields from table course.

param: stdClass $course object from DB table course. Must have property 'id'
param: boolean $partialrebuild Indicate if it's partial course cache rebuild or not
return: stdClass object with all cached keys of the course plus fields modinfo and sectioncache.

inner_build_course_cache(\stdClass $course, bool $partialrebuild = false)   X-Ref
Called to build course cache when there is already a lock obtained.

param: stdClass $course object from DB table course
param: bool $partialrebuild Indicate if it's partial course cache rebuild or not
return: stdClass Course object that has been stored in MUC

purge_course_section_cache_by_id(int $courseid, int $sectionid)   X-Ref
Purge the cache of a course section by its id.

param: int $courseid The course to purge cache in
param: int $sectionid The section _id_ to purge

purge_course_section_cache_by_number(int $courseid, int $sectionno)   X-Ref
Purge the cache of a course section by its number.

param: int $courseid The course to purge cache in
param: int $sectionno The section number to purge

purge_course_module_cache(int $courseid, int $cmid)   X-Ref
Purge the cache of a course module.

param: int $courseid Course id
param: int $cmid Course module id

purge_course_modules_cache(int $courseid, array $cmids)   X-Ref
Purge the cache of multiple course modules.

param: int $courseid Course id
param: int[] $cmids List of course module ids
return: void

get_array_of_activities(stdClass $course, bool $usecache = false)   X-Ref
For a given course, returns an array of course activity objects

param: stdClass $course Course object
param: bool $usecache get activities from cache if modinfo exists when $usecache is true
return: array list of activities

purge_course_cache(int $courseid)   X-Ref
Purge the cache of a given course

param: int $courseid Course id

Class: cm_info  - X-Ref

Data about a single module on a course. This contains most of the fields in the course_modules
table, plus additional data when required.

The object can be accessed by core or any plugin (i.e. course format, block, filter, etc.) as
get_fast_modinfo($courseorid)->cms[$coursemoduleid]
or
get_fast_modinfo($courseorid)->instances[$moduletype][$instanceid]

There are three stages when activity module can add/modify data in this object:

<b>Stage 1 - during building the cache.</b>
Allows to add to the course cache static user-independent information about the module.
Modules should try to include only absolutely necessary information that may be required
when displaying course view page. The information is stored in application-level cache
and reset when {@link rebuild_course_cache()} is called or cache is purged by admin.

Modules can implement callback XXX_get_coursemodule_info() returning instance of object
{@link cached_cm_info}

<b>Stage 2 - dynamic data.</b>
Dynamic data is user-dependent, it is stored in request-level cache. To reset this cache
{@link get_fast_modinfo()} with $reset argument may be called.

Dynamic data is obtained when any of the following properties/methods is requested:
- {@link cm_info::$url}
- {@link cm_info::$name}
- {@link cm_info::$onclick}
- {@link cm_info::get_icon_url()}
- {@link cm_info::$uservisible}
- {@link cm_info::$available}
- {@link cm_info::$availableinfo}
- plus any of the properties listed in Stage 3.

Modules can implement callback <b>XXX_cm_info_dynamic()</b> and inside this callback they
are allowed to use any of the following set methods:
- {@link cm_info::set_available()}
- {@link cm_info::set_name()}
- {@link cm_info::set_no_view_link()}
- {@link cm_info::set_user_visible()}
- {@link cm_info::set_on_click()}
- {@link cm_info::set_icon_url()}
- {@link cm_info::override_customdata()}
Any methods affecting view elements can also be set in this callback.

<b>Stage 3 (view data).</b>
Also user-dependend data stored in request-level cache. Second stage is created
because populating the view data can be expensive as it may access much more
Moodle APIs such as filters, user information, output renderers and we
don't want to request it until necessary.
View data is obtained when any of the following properties/methods is requested:
- {@link cm_info::$afterediticons}
- {@link cm_info::$content}
- {@link cm_info::get_formatted_content()}
- {@link cm_info::$extraclasses}
- {@link cm_info::$afterlink}

Modules can implement callback <b>XXX_cm_info_view()</b> and inside this callback they
are allowed to use any of the following set methods:
- {@link cm_info::set_after_edit_icons()}
- {@link cm_info::set_after_link()}
- {@link cm_info::set_content()}
- {@link cm_info::set_extra_classes()}

__call($name, $arguments)   X-Ref
Magic method to call functions that are now declared as private but were public in Moodle before 2.6.
These private methods can not be used anymore.

param: string $name
param: array $arguments
return: mixed

__get($name)   X-Ref
Magic method getter

param: string $name
return: mixed

getIterator()   X-Ref
Implementation of IteratorAggregate::getIterator(), allows to cycle through properties
and use {@link convert_to_array()}

return: ArrayIterator

__isset($name)   X-Ref
Magic method for function isset()

param: string $name
return: bool

__empty($name)   X-Ref
Magic method for function empty()

param: string $name
return: bool

__set($name, $value)   X-Ref
Magic method setter

Will display the developer warning when trying to set/overwrite property.

param: string $name
param: mixed $value

has_view()   X-Ref

return: bool True if this module has a 'view' page that should be linked to in navigation

get_url()   X-Ref
Gets the URL to link to for this module.

This method is normally called by the property ->url, but can be called directly if
there is a case when it might be called recursively (you can't call property values
recursively).

return: moodle_url URL to link to for this module, or null if it doesn't have a view page

get_content()   X-Ref
Obtains content to display on main (view) page.
Note: Will collect view data, if not already obtained.

return: string Content to display on main page below link, or empty string if none

get_formatted_content($options = array()   X-Ref
Returns the content to display on course/overview page, formatted and passed through filters

if $options['context'] is not specified, the module context is used

param: array|stdClass $options formatting options, see {@link format_text()}
return: string

has_custom_cmlist_item()   X-Ref
Return the module custom cmlist item flag.

Activities like label uses this flag to indicate that it should be
displayed as a custom course item instead of a tipical activity card.

return: bool

get_name()   X-Ref
Getter method for property $name, ensures that dynamic data is obtained.

This method is normally called by the property ->name, but can be called directly if there
is a case when it might be called recursively (you can't call property values recursively).

return: string

get_formatted_name($options = array()   X-Ref
Returns the name to display on course/overview page, formatted and passed through filters

if $options['context'] is not specified, the module context is used

param: array|stdClass $options formatting options, see {@link format_string()}
return: string

get_extra_classes()   X-Ref
Note: Will collect view data, if not already obtained.

return: string Extra CSS classes to add to html output for this activity on main page

get_on_click()   X-Ref

return: string Content of HTML on-click attribute. This string will be used literally

get_custom_data()   X-Ref
Getter method for property $customdata, ensures that dynamic data is retrieved.

This method is normally called by the property ->customdata, but can be called directly if there
is a case when it might be called recursively (you can't call property values recursively).

return: mixed Optional custom data stored in modinfo cache for this activity, or null if none

get_after_link()   X-Ref
Note: Will collect view data, if not already obtained.

return: string Extra HTML code to display after link

get_activitybadge(?renderer_base $output = null)   X-Ref
Get the activity badge data associated to this course module (if the module supports it).
Modules can use this method to provide additional data to be displayed in the activity badge.

param: renderer_base $output Output render to use, or null for default (global)
return: stdClass|null The activitybadge data (badgecontent, badgestyle...) or null if the module doesn't implement it.

get_after_edit_icons()   X-Ref
Note: Will collect view data, if not already obtained.

return: string Extra HTML code to display after editing icons (e.g. more icons)

get_icon_url($output = null)   X-Ref
Fetch the module's icon URL.

This function fetches the course module instance's icon URL.
This method adds a `filtericon` parameter in the URL when rendering the monologo version of the course module icon or when
the plugin declares, via its `filtericon` custom data, that the icon needs to be filtered.
This additional information can be used by plugins when rendering the module icon to determine whether to apply
CSS filtering to the icon.

param: core_renderer $output Output render to use, or null for default (global)
return: moodle_url Icon URL for a suitable icon to put beside this cm

get_grouping_label($textclasses = '')   X-Ref

param: string $textclasses additionnal classes for grouping label
return: string An empty string or HTML grouping label span tag

get_module_type_name($plural = false)   X-Ref
Returns a localised human-readable name of the module type.

param: bool $plural If true, the function returns the plural form of the name.
return: lang_string

get_module_type_name_plural()   X-Ref
Returns a localised human-readable name of the module type in plural form - calculated on request

return: string

get_modinfo()   X-Ref

return: course_modinfo Modinfo object that this came from

get_section_info()   X-Ref
Returns the section this module belongs to

return: section_info

get_course()   X-Ref
Returns course object that was used in the first {@link get_fast_modinfo()} call.

It may not contain all fields from DB table {course} but always has at least the following:
id,shortname,fullname,format,enablecompletion,groupmode,groupmodeforce,cacherev

If the course object lacks the field you need you can use the global
function {@link get_course()} that will save extra query if you access
current course or frontpage course.

return: stdClass

get_course_id()   X-Ref
Returns course id for which the modinfo was generated.

return: int

get_course_groupmode()   X-Ref
Returns group mode used for the course containing the module

return: int one of constants NOGROUPS, SEPARATEGROUPS, VISIBLEGROUPS

get_course_groupmodeforce()   X-Ref
Returns whether group mode is forced for the course containing the module

return: bool

get_effective_groupmode()   X-Ref
Returns effective groupmode of the module that may be overwritten by forced course groupmode.

return: int one of constants NOGROUPS, SEPARATEGROUPS, VISIBLEGROUPS

get_context()   X-Ref

return: context_module Current module context

get_course_module_record($additionalfields = false)   X-Ref
Returns itself in the form of stdClass.

The object includes all fields that table course_modules has and additionally
fields 'name', 'modname', 'sectionnum' (if requested).

This can be used as a faster alternative to {@link get_coursemodule_from_id()}

param: bool $additionalfields include additional fields 'name', 'modname', 'sectionnum'
return: stdClass

set_content($content, $isformatted = false)   X-Ref
Sets content to display on course view page below link (if present).

param: string $content New content as HTML string (empty string if none)
param: bool $isformatted Whether user content is already passed through format_text/format_string and should not
return: void

set_extra_classes($extraclasses)   X-Ref
Sets extra classes to include in CSS.

param: string $extraclasses Extra classes (empty string if none)
return: void

set_icon_url(moodle_url $iconurl)   X-Ref
Sets the external full url that points to the icon being used
by the activity. Useful for external-tool modules (lti...)
If set, takes precedence over $icon and $iconcomponent

param: moodle_url $iconurl full external url pointing to icon image for activity
return: void

set_on_click($onclick)   X-Ref
Sets value of on-click attribute for JavaScript.
Note: May not be called from _cm_info_view (only _cm_info_dynamic).

param: string $onclick New onclick attribute which should be HTML-escaped
return: void

override_customdata($name, $value)   X-Ref
Overrides the value of an element in the customdata array.

param: string $name The key in the customdata array
param: mixed $value The value

set_after_link($afterlink)   X-Ref
Sets HTML that displays after link on course view page.

param: string $afterlink HTML string (empty string if none)
return: void

set_after_edit_icons($afterediticons)   X-Ref
Sets HTML that displays after edit icons on course view page.

param: string $afterediticons HTML string (empty string if none)
return: void

set_name($name)   X-Ref
Changes the name (text of link) for this module instance.
Note: May not be called from _cm_info_view (only _cm_info_dynamic).

param: string $name Name of activity / link text
return: void

set_no_view_link()   X-Ref
Turns off the view link for this module instance.
Note: May not be called from _cm_info_view (only _cm_info_dynamic).

return: void

set_user_visible($uservisible)   X-Ref
Sets the 'uservisible' flag. This can be used (by setting false) to prevent access and
display of this module link for the current user.
Note: May not be called from _cm_info_view (only _cm_info_dynamic).

param: bool $uservisible
return: void

set_custom_cmlist_item(bool $customcmlistitem)   X-Ref
Sets the 'customcmlistitem' flag

This can be used (by setting true) to prevent the course from rendering the
activity item as a regular activity card. This is applied to activities like labels.

param: bool $customcmlistitem if the cmlist item of that activity has a special dysplay other than a card.

set_available($available, $showavailability=0, $availableinfo='')   X-Ref
Sets the 'available' flag and related details. This flag is normally used to make
course modules unavailable until a certain date or condition is met. (When a course
module is unavailable, it is still visible to users who have viewhiddenactivities
permission.)

When this is function is called, user-visible status is recalculated automatically.

The $showavailability flag does not really do anything any more, but is retained
for backward compatibility. Setting this to false will cause $availableinfo to
be ignored.

Note: May not be called from _cm_info_view (only _cm_info_dynamic).
param: bool $available False if this item is not 'available'
param: int $showavailability 0 = do not show this item at all if it's not available,
param: string $availableinfo Information about why this is not available, or
return: void

check_not_view_only()   X-Ref
Some set functions can only be called from _cm_info_dynamic and not _cm_info_view.
This is because they may affect parts of this object which are used on pages other
than the view page (e.g. in the navigation block, or when checking access on
module pages).

return: void

__construct(course_modinfo $modinfo, $notused1, $mod, $notused2)   X-Ref
Constructor should not be called directly; use {@link get_fast_modinfo()}

param: course_modinfo $modinfo Parent object
param: stdClass $notused1 Argument not used
param: stdClass $mod Module object from the modinfo field of course table
param: stdClass $notused2 Argument not used

create($cm, $userid = 0)   X-Ref
Creates a cm_info object from a database record (also accepts cm_info
in which case it is just returned unchanged).

param: stdClass|cm_info|null|bool $cm Stdclass or cm_info (or null or false)
param: int $userid Optional userid (default to current)
return: cm_info|null Object as cm_info, or null if input was null/false

obtain_dynamic_data()   X-Ref
If dynamic data for this course-module is not yet available, gets it.

This function is automatically called when requesting any course_modinfo property
that can be modified by modules (have a set_xxx method).

Dynamic data is data which does not come directly from the cache but is calculated at
runtime based on the current user. Primarily this concerns whether the user can access
the module or not.

As part of this function, the module's _cm_info_dynamic function from its lib.php will
be called (if it exists). Make sure that the functions that are called here do not use
any getter magic method from cm_info.
return: void

get_user_visible()   X-Ref
Getter method for property $uservisible, ensures that dynamic data is retrieved.

This method is normally called by the property ->uservisible, but can be called directly if
there is a case when it might be called recursively (you can't call property values
recursively).

return: bool

is_visible_on_course_page()   X-Ref
Returns whether this module is visible to the current user on course page

Activity may be visible on the course page but not available, for example
when it is hidden conditionally but the condition information is displayed.

return: bool

is_stealth()   X-Ref
Whether this module is available but hidden from course page

"Stealth" modules are the ones that are not shown on course page but available by following url.
They are normally also displayed in grade reports and other reports.
Module will be stealth either if visibleoncoursepage=0 or it is a visible module inside the hidden
section.

return: bool

get_available()   X-Ref
Getter method for property $available, ensures that dynamic data is retrieved

return: bool

get_deprecated_group_members_only()   X-Ref
This method can not be used anymore.


get_available_info()   X-Ref
Getter method for property $availableinfo, ensures that dynamic data is retrieved

return: string Available info (HTML)

update_user_visible()   X-Ref
Works out whether activity is available to the current user

If the activity is unavailable, additional checks are required to determine if its hidden or greyed out

return: void

is_user_access_restricted_by_group()   X-Ref
This method has been deprecated and should not be used.


is_user_access_restricted_by_capability()   X-Ref
Checks whether mod/...:view capability restricts the current user's access.

return: bool True if the user access is restricted.

is_user_access_restricted_by_conditional_access()   X-Ref
Checks whether the module's conditional access settings mean that the
user cannot see the activity at all


call_mod_function($type)   X-Ref
Calls a module function (if exists), passing in one parameter: this object.

param: string $type Name of function e.g. if this is 'grooblezorb' and the modname is
return: void

obtain_view_data()   X-Ref
If view data for this course-module is not yet available, obtains it.

This function is automatically called if any of the functions (marked) which require
view data are called.

View data is data which is needed only for displaying the course main page (& any similar
functionality on other pages) but is not needed in general. Obtaining view data may have
a performance cost.

As part of this function, the module's _cm_info_view function from its lib.php will
be called (if it exists).
return: void

get_fast_modinfo($courseorid, $userid = 0, $resetonly = false)   X-Ref
Returns reference to full info about modules in course (including visibility).
Cached and as fast as possible (0 or 1 db query).

use get_fast_modinfo($courseid, 0, true) to reset the static cache for particular course
use get_fast_modinfo(0, 0, true) to reset the static cache for all courses

use rebuild_course_cache($courseid, true) to reset the application AND static cache
for particular course when it's contents has changed

param: int|stdClass $courseorid object from DB table 'course' (must have field 'id'
param: int $userid User id to populate 'availble' and 'uservisible' attributes of modules and sections.
param: bool $resetonly whether we want to get modinfo or just reset the cache
return: course_modinfo|null Module information for course, or null if resetting

get_course_and_cm_from_cmid($cmorid, $modulename = '', $courseorid = 0, $userid = 0)   X-Ref
Efficiently retrieves the $course (stdclass) and $cm (cm_info) objects, given
a cmid. If module name is also provided, it will ensure the cm is of that type.

Usage:
list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'forum');

Using this method has a performance advantage because it works by loading
modinfo for the course - which will then be cached and it is needed later
in most requests. It also guarantees that the $cm object is a cm_info and
not a stdclass.

The $course object can be supplied if already known and will speed
up this function - although it is more efficient to use this function to
get the course if you are starting from a cmid.

To avoid security problems and obscure bugs, you should always specify
$modulename if the cmid value came from user input.

By default this obtains information (for example, whether user can access
the activity) for current user, but you can specify a userid if required.

param: stdClass|int $cmorid Id of course-module, or database object
param: string $modulename Optional modulename (improves security)
param: stdClass|int $courseorid Optional course object if already loaded
param: int $userid Optional userid (default = current)
return: array Array with 2 elements $course and $cm

get_course_and_cm_from_instance($instanceorid, $modulename, $courseorid = 0, $userid = 0)   X-Ref
Efficiently retrieves the $course (stdclass) and $cm (cm_info) objects, given
an instance id or record and module name.

Usage:
list($course, $cm) = get_course_and_cm_from_instance($forum, 'forum');

Using this method has a performance advantage because it works by loading
modinfo for the course - which will then be cached and it is needed later
in most requests. It also guarantees that the $cm object is a cm_info and
not a stdclass.

The $course object can be supplied if already known and will speed
up this function - although it is more efficient to use this function to
get the course if you are starting from an instance id.

By default this obtains information (for example, whether user can access
the activity) for current user, but you can specify a userid if required.

param: stdclass|int $instanceorid Id of module instance, or database object
param: string $modulename Modulename (required)
param: stdClass|int $courseorid Optional course object if already loaded
param: int $userid Optional userid (default = current)
return: array Array with 2 elements $course and $cm

rebuild_course_cache(int $courseid = 0, bool $clearonly = false, bool $partialrebuild = false)   X-Ref
Rebuilds or resets the cached list of course activities stored in MUC.

rebuild_course_cache() must NEVER be called from lib/db/upgrade.php.
At the same time course cache may ONLY be cleared using this function in
upgrade scripts of plugins.

During the bulk operations if it is necessary to reset cache of multiple
courses it is enough to call {@link increment_revision_number()} for the
table 'course' and field 'cacherev' specifying affected courses in select.

Cached course information is stored in MUC core/coursemodinfo and is
validated with the DB field {course}.cacherev

param: int $courseid id of course to rebuild, empty means all
param: boolean $clearonly only clear the cache, gets rebuild automatically on the fly.
param: boolean $partialrebuild will not delete the whole cache when it's true.
return: void

Class: cached_cm_info  - X-Ref

Class that is the return value for the _get_coursemodule_info module API function.

Note: For backward compatibility, you can also return a stdclass object from that function.
The difference is that the stdclass object may contain an 'extra' field (deprecated,
use extraclasses and onclick instead). The stdclass object may not contain
the new fields defined here (content, extraclasses, customdata).

Class: section_info  - X-Ref

Data about a single section on a course. This contains the fields from the
course_sections table, plus additional data when required.

__construct($data, $number, $notused1, $notused2, $modinfo, $notused3)   X-Ref
Constructs object from database information plus extra required data.

param: object $data Array entry from cached sectioncache
param: int $number Section number (array key)
param: int $notused1 argument not used (informaion is available in $modinfo)
param: int $notused2 argument not used (informaion is available in $modinfo)
param: course_modinfo $modinfo Owner (needed for checking availability)
param: int $notused3 argument not used (informaion is available in $modinfo)

__isset($name)   X-Ref
Magic method to check if the property is set

param: string $name name of the property
return: bool

__empty($name)   X-Ref
Magic method to check if the property is empty

param: string $name name of the property
return: bool

__get($name)   X-Ref
Magic method to retrieve the property, this is either basic section property
or availability information or additional properties added by course format

param: string $name name of the property
return: bool

get_available()   X-Ref
Finds whether this section is available at the moment for the current user.

The value can be accessed publicly as $sectioninfo->available, but can be called directly if there
is a case when it might be called recursively (you can't call property values recursively).

return: bool

get_availableinfo()   X-Ref
Returns the availability text shown next to the section on course page.

return: string

getIterator()   X-Ref
Implementation of IteratorAggregate::getIterator(), allows to cycle through properties
and use {@link convert_to_array()}

return: ArrayIterator

get_uservisible()   X-Ref
Works out whether activity is visible *for current user* - if this is false, they
aren't allowed to access it.

return: bool

get_sequence()   X-Ref
Restores the course_sections.sequence value

return: string

get_course()   X-Ref
Returns course ID - from course_sections table

return: int

get_modinfo()   X-Ref
Modinfo object

return: course_modinfo

convert_for_section_cache($section)   X-Ref
Prepares section data for inclusion in sectioncache cache, removing items
that are set to defaults, and adding availability data if required.

Called by build_section_cache in course_modinfo only; do not use otherwise.
param: object $section Raw section data object