|
int const | COURSE_CACHE_LOCK_EXPIRY = 180 |
| Maximum time the course cache building lock can be held.
|
|
int const | COURSE_CACHE_LOCK_WAIT = 60 |
| Time to wait for the course cache building lock before throwing an exception.
|
|
|
static array | $cachedfields |
| List of fields from DB table 'course' that are cached in MUC and are always present in course_modinfo\$course.
|
|
|
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.
|
|
◆ __construct()
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.
- Parameters
-
stdClass | $course | course object, only property id is required. |
int | $userid | User ID |
- Exceptions
-
◆ __empty()
course_modinfo::__empty |
( |
| $name | ) |
|
Magic method for function empty()
- Parameters
-
- Return values
-
◆ __get()
course_modinfo::__get |
( |
| $name | ) |
|
Magic method getter.
- Parameters
-
- Return values
-
◆ __isset()
course_modinfo::__isset |
( |
| $name | ) |
|
Magic method for function isset()
- Parameters
-
- Return values
-
◆ __set()
course_modinfo::__set |
( |
| $name, |
|
|
| $value ) |
Magic method setter.
Will display the developer warning when trying to set/overwrite existing property.
- Parameters
-
◆ build_course_cache()
static course_modinfo::build_course_cache |
( |
\stdClass | $course, |
|
|
bool | $partialrebuild = false ) |
|
static |
Builds and stores in MUC object containing information about course modules and sections together with cached fields from table course.
- Parameters
-
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 |
- Return values
-
stdClass | object with all cached keys of the course plus fields modinfo and sectioncache. The same object is stored in MUC |
- Exceptions
-
moodle_exception | if course is not found (if $course object misses some of the necessary fields it is re-requested from database) |
◆ build_course_section_cache()
static course_modinfo::build_course_section_cache |
( |
\stdClass | $course, |
|
|
bool | $usecache = false ) |
|
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.)
- Parameters
-
stdClass | $course | Course object (must contain fields |
boolean | $usecache | use cached section info if exists, use true for partial course rebuild |
- Return values
-
array | Information about sections, indexed by section number (not id) |
◆ build_section_cache()
static course_modinfo::build_section_cache |
( |
| $courseid | ) |
|
|
static |
This method can not be used anymore.
- See also
- course_modinfo\build_course_cache()
- Deprecated
- since 2.6
◆ clear_instance_cache()
static course_modinfo::clear_instance_cache |
( |
| $courseorid = null | ) |
|
|
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()
- Parameters
-
null | int | stdClass | $courseorid | if specified removes only cached value for this course |
◆ get_array_of_activities()
static course_modinfo::get_array_of_activities |
( |
stdClass | $course, |
|
|
bool | $usecache = false ) |
|
static |
For a given course, returns an array of course activity objects.
- Parameters
-
stdClass | $course | Course object |
bool | $usecache | get activities from cache if modinfo exists when $usecache is true |
- Return values
-
◆ get_cm()
course_modinfo::get_cm |
( |
| $cmid | ) |
|
Obtains a single course-module object (for a course-module that is on this course).
- Parameters
-
- Return values
-
cm_info | Information about that course-module |
- Exceptions
-
◆ get_cms()
course_modinfo::get_cms |
( |
| ) |
|
- Return values
-
cm_info[] | Array from course-module instance to cm_info object within this course, in order of appearance |
◆ get_course()
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
- Return values
-
◆ get_course_id()
course_modinfo::get_course_id |
( |
| ) |
|
◆ get_groups()
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.
- Parameters
-
int | $groupingid | Grouping ID or 0 (default) for all groups |
- Return values
-
int[] | Array of int (group id) => int (same group id again); empty array if none |
◆ get_instances()
course_modinfo::get_instances |
( |
| ) |
|
Obtains all module instances on this course.
- Return values
-
cm_info[][] | Array from module name => array from instance id => cm_info |
◆ get_instances_of()
course_modinfo::get_instances_of |
( |
| $modname | ) |
|
Obtains all instances of a particular module on this course.
- Parameters
-
string | $modname | Name of module (not full frankenstyle) e.g. 'label' |
- Return values
-
cm_info[] | Array from instance id => cm_info for modules on this course; empty if none |
◆ get_section_info()
course_modinfo::get_section_info |
( |
| $sectionnumber, |
|
|
| $strictness = IGNORE_MISSING ) |
Gets data about specific numbered section.
- Parameters
-
int | $sectionnumber | Number (not id) of section |
int | $strictness | Use MUST_EXIST to throw exception if it doesn't |
- Return values
-
section_info | Information for numbered section or null if not found |
◆ get_section_info_all()
course_modinfo::get_section_info_all |
( |
| ) |
|
Gets all sections as array from section number => data about section.
- Return values
-
section_info[] | Array of section_info objects organised by section number |
◆ get_section_info_by_id()
course_modinfo::get_section_info_by_id |
( |
int | $sectionid, |
|
|
int | $strictness = IGNORE_MISSING ) |
Gets data about specific section ID.
- Parameters
-
int | $sectionid | ID (not number) of section |
int | $strictness | Use MUST_EXIST to throw exception if it doesn't |
- Return values
-
section_info|null | Information for numbered section or null if not found |
◆ get_sections()
course_modinfo::get_sections |
( |
| ) |
|
- Return values
-
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 |
◆ get_used_module_names()
course_modinfo::get_used_module_names |
( |
| $plural = false | ) |
|
Returns array of localised human-readable module names used in this course.
- Parameters
-
bool | $plural | if true returns the plural form of modules names |
- Return values
-
◆ get_user_id()
course_modinfo::get_user_id |
( |
| ) |
|
◆ inner_build_course_cache()
static course_modinfo::inner_build_course_cache |
( |
\stdClass | $course, |
|
|
bool | $partialrebuild = false ) |
|
staticprotected |
Called to build course cache when there is already a lock obtained.
- Parameters
-
stdClass | $course | object from DB table course |
bool | $partialrebuild | Indicate if it's partial course cache rebuild or not |
- Return values
-
stdClass | Course object that has been stored in MUC |
◆ instance()
static course_modinfo::instance |
( |
| $courseorid, |
|
|
| $userid = 0 ) |
|
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()
- Parameters
-
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. |
- Return values
-
◆ purge_course_cache()
static course_modinfo::purge_course_cache |
( |
int | $courseid | ) |
|
|
static |
Purge the cache of a given course.
- Parameters
-
◆ purge_course_module_cache()
static course_modinfo::purge_course_module_cache |
( |
int | $courseid, |
|
|
int | $cmid ) |
|
static |
Purge the cache of a course module.
- Parameters
-
int | $courseid | Course id |
int | $cmid | Course module id |
◆ purge_course_modules_cache()
static course_modinfo::purge_course_modules_cache |
( |
int | $courseid, |
|
|
array | $cmids ) |
|
static |
Purge the cache of multiple course modules.
- Parameters
-
int | $courseid | Course id |
int[] | $cmids | List of course module ids |
- Return values
-
◆ purge_course_section_cache_by_id()
static course_modinfo::purge_course_section_cache_by_id |
( |
int | $courseid, |
|
|
int | $sectionid ) |
|
static |
Purge the cache of a course section by its id.
- Parameters
-
int | $courseid | The course to purge cache in |
int | $sectionid | The section id to purge |
◆ purge_course_section_cache_by_number()
static course_modinfo::purge_course_section_cache_by_number |
( |
int | $courseid, |
|
|
int | $sectionno ) |
|
static |
Purge the cache of a course section by its number.
- Parameters
-
int | $courseid | The course to purge cache in |
int | $sectionno | The section number to purge |
◆ $cacheaccessed
float [] course_modinfo::$cacheaccessed = array() |
|
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
◆ $cachedfields
array course_modinfo::$cachedfields |
|
static |
Initial value:= array('shortname', 'fullname', 'format',
'enablecompletion', 'groupmode', 'groupmodeforce', 'cacherev')
List of fields from DB table 'course' that are cached in MUC and are always present in course_modinfo\$course.
◆ $instancecache
Static cache for generated course_modinfo instances.
- See also
- course_modinfo\instance()
-
course_modinfo\clear_instance_cache()
The documentation for this class was generated from the following file: