Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
|
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. More...
Public Member Functions | |
__construct ($course, $userid) | |
Constructs based on course. | |
__empty ($name) | |
Magic method for function empty() | |
__get ($name) | |
Magic method getter. | |
__isset ($name) | |
Magic method for function isset() | |
__set ($name, $value) | |
Magic method setter. | |
get_cm ($cmid) | |
Obtains a single course-module object (for a course-module that is on this course). | |
get_cms () | |
get_course () | |
Returns course object that was used in the first get_fast_modinfo() call. | |
get_course_id () | |
get_groups ($groupingid=0) | |
Returns groups that the current user belongs to on the course. | |
get_instances () | |
Obtains all module instances on this course. | |
get_instances_of ($modname) | |
Obtains all instances of a particular module on this course. | |
get_section_info ($sectionnumber, $strictness=IGNORE_MISSING) | |
Gets data about specific numbered section. | |
get_section_info_all () | |
Gets all sections as array from section number => data about section. | |
get_section_info_by_id (int $sectionid, int $strictness=IGNORE_MISSING) | |
Gets data about specific section ID. | |
get_sections () | |
get_used_module_names ($plural=false) | |
Returns array of localised human-readable module names used in this course. | |
get_user_id () | |
Static Public Member Functions | |
static | build_course_cache (\stdClass $course, bool $partialrebuild=false) |
Builds and stores in MUC object containing information about course modules and sections together with cached fields from table course. | |
static | build_section_cache ($courseid) |
This method can not be used anymore. | |
static | clear_instance_cache ($courseorid=null, int $newcacherev=0) |
Clears the cache used in course_modinfo\instance() | |
static | get_array_of_activities (stdClass $course, bool $usecache=false) |
For a given course, returns an array of course activity objects. | |
static | instance ($courseorid, $userid=0) |
Returns the instance of course_modinfo for the specified course and specified user. | |
static | purge_course_cache (int $courseid) |
Purge the cache of a given course. | |
static | purge_course_module_cache (int $courseid, int $cmid) |
Purge the cache of a course module. | |
static | purge_course_modules_cache (int $courseid, array $cmids) |
Purge the cache of multiple course modules. | |
static | purge_course_section_cache_by_id (int $courseid, int $sectionid) |
Purge the cache of a course section by its id. | |
static | purge_course_section_cache_by_number (int $courseid, int $sectionno) |
Purge the cache of a course section by its number. | |
Static Public Attributes | |
static array | $cachedfields |
List of fields from DB table 'course' that are cached in MUC and are always present in course_modinfo\$course. | |
Static Protected Member Functions | |
static | build_course_section_cache (\stdClass $course, bool $usecache=false) |
Builds a list of information about sections on a course to be stored in the course cache. | |
static | inner_build_course_cache (\stdClass $course, bool $partialrebuild=false) |
Called to build course cache when there is already a lock obtained. | |
Static Protected Attributes | |
static float[] | $cacheaccessed = array() |
Timestamps (microtime) when the course_modinfo instances were last accessed. | |
static course_modinfo[] | $instancecache = array() |
Static cache for generated course_modinfo instances. | |
static int[] | $mincacherevs = [] |
Store a list of known course cacherev values. | |
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 get_fast_modinfo() to retrieve the instance of the object for particular course and particular user.
section; this only includes sections that contain at least one course-module order of appearance Is an array of grouping id => array of group id => group id. Includes grouping id 0 for 'all groups'
course_modinfo::__construct | ( | $course, | |
$userid ) |
Constructs based on course.
Note: This constructor should not usually be called directly. Use get_fast_modinfo($course) instead as this maintains a cache.
stdClass | $course | course object, only property id is required. |
int | $userid | User ID |
moodle_exception | if course is not found |
course_modinfo::__empty | ( | $name | ) |
Magic method for function empty()
string | $name |
bool |
course_modinfo::__get | ( | $name | ) |
Magic method getter.
string | $name |
mixed |
course_modinfo::__isset | ( | $name | ) |
Magic method for function isset()
string | $name |
bool |
course_modinfo::__set | ( | $name, | |
$value ) |
Magic method setter.
Will display the developer warning when trying to set/overwrite existing property.
string | $name | |
mixed | $value |
|
static |
Builds and stores in MUC object containing information about course modules and sections together with cached fields from table course.
stdClass | $course | object from DB table course. Must have property 'id' but preferably should have all cached fields. |
boolean | $partialrebuild | Indicate if it's partial course cache rebuild or not |
stdClass | object with all cached keys of the course plus fields modinfo and sectioncache. The same object is stored in MUC |
moodle_exception | if course is not found (if $course object misses some of the necessary fields it is re-requested from database) |
|
staticprotected |
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.)
stdClass | $course | Course object (must contain fields |
boolean | $usecache | use cached section info if exists, use true for partial course rebuild |
array | Information about sections, indexed by section number (not id) |
|
static |
This method can not be used anymore.
|
static |
Clears the cache used in course_modinfo\instance()
Used in get_fast_modinfo() when called with argument $reset = true and in 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.
null | int | stdClass | $courseorid | if specified removes only cached value for this course |
int | $newcacherev | If specified, the known cache rev for this course id will be updated |
|
static |
For a given course, returns an array of course activity objects.
stdClass | $course | Course object |
bool | $usecache | get activities from cache if modinfo exists when $usecache is true |
array | list of activities |
course_modinfo::get_cm | ( | $cmid | ) |
Obtains a single course-module object (for a course-module that is on this course).
int | $cmid | Course-module ID |
cm_info | Information about that course-module |
moodle_exception | If the course-module does not exist |
course_modinfo::get_cms | ( | ) |
cm_info[] | Array from course-module instance to cm_info object within this course, in order of appearance |
course_modinfo::get_course | ( | ) |
Returns course object that was used in the first 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
stdClass |
course_modinfo::get_course_id | ( | ) |
int | Course ID |
course_modinfo::get_groups | ( | $groupingid = 0 | ) |
Returns groups that the current user belongs to on the course.
Note: If not already available, this may make a database query.
int | $groupingid | Grouping ID or 0 (default) for all groups |
int[] | Array of int (group id) => int (same group id again); empty array if none |
course_modinfo::get_instances | ( | ) |
Obtains all module instances on this course.
cm_info[][] | Array from module name => array from instance id => cm_info |
course_modinfo::get_instances_of | ( | $modname | ) |
Obtains all instances of a particular module on this course.
string | $modname | Name of module (not full frankenstyle) e.g. 'label' |
cm_info[] | Array from instance id => cm_info for modules on this course; empty if none |
course_modinfo::get_section_info | ( | $sectionnumber, | |
$strictness = IGNORE_MISSING ) |
Gets data about specific numbered section.
int | $sectionnumber | Number (not id) of section |
int | $strictness | Use MUST_EXIST to throw exception if it doesn't |
section_info | Information for numbered section or null if not found |
course_modinfo::get_section_info_all | ( | ) |
Gets all sections as array from section number => data about section.
section_info[] | Array of section_info objects organised by section number |
course_modinfo::get_section_info_by_id | ( | int | $sectionid, |
int | $strictness = IGNORE_MISSING ) |
Gets data about specific section ID.
int | $sectionid | ID (not number) of section |
int | $strictness | Use MUST_EXIST to throw exception if it doesn't |
section_info|null | Information for numbered section or null if not found |
course_modinfo::get_sections | ( | ) |
array | Array from section number (e.g. 0) to array of course-module IDs in that section; this only includes sections that contain at least one course-module |
course_modinfo::get_used_module_names | ( | $plural = false | ) |
Returns array of localised human-readable module names used in this course.
bool | $plural | if true returns the plural form of modules names |
array |
course_modinfo::get_user_id | ( | ) |
int | User ID |
|
staticprotected |
Called to build course cache when there is already a lock obtained.
stdClass | $course | object from DB table course |
bool | $partialrebuild | Indicate if it's partial course cache rebuild or not |
stdClass | Course object that has been stored in MUC |
|
static |
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 get_fast_modinfo()
int | stdClass | $courseorid | object from DB table 'course' (must have field 'id' and recommended to have field 'cacherev') or just a course id |
int | $userid | User id to populate 'availble' and 'uservisible' attributes of modules and sections. Set to 0 for current user (default). Set to -1 to avoid calculation of dynamic user-depended data. |
course_modinfo |
|
static |
Purge the cache of a given course.
int | $courseid | Course id |
|
static |
Purge the cache of a course module.
int | $courseid | Course id |
int | $cmid | Course module id |
|
static |
Purge the cache of multiple course modules.
int | $courseid | Course id |
int[] | $cmids | List of course module ids |
void |
|
static |
Purge the cache of a course section by its id.
int | $courseid | The course to purge cache in |
int | $sectionid | The section id to purge |
|
static |
Purge the cache of a course section by its number.
int | $courseid | The course to purge cache in |
int | $sectionno | The section number to purge |
|
staticprotected |
Timestamps (microtime) when the course_modinfo instances were last accessed.
It is used to remove the least recent accessed instances when static cache is full
|
static |
List of fields from DB table 'course' that are cached in MUC and are always present in course_modinfo\$course.
|
staticprotected |
Static cache for generated course_modinfo instances.
|
staticprotected |
Store a list of known course cacherev values.
This is in case people reuse a course object (with an old cacherev value) within the same request when calling things like get_fast_modinfo, after rebuild_course_cache.