Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
Public Member Functions | |
__get ($name) | |
Magic method getter, redirects to read only values. More... | |
__isset ($name) | |
Full support for isset on our magic read only properties. More... | |
__set ($name, $value) | |
Magic setter method, we do not want anybody to modify properties from the outside. More... | |
__unset ($name) | |
All properties are read only, sorry. More... | |
delete () | |
Delete the context content and the context record itself. | |
delete_capabilities () | |
Unassign all capabilities from a context. | |
delete_content () | |
Delete all data linked to content, do not delete the context record itself. | |
get_capabilities () | |
not used More... | |
get_child_contexts () | |
Recursive function which, given a context, find all its children context ids. More... | |
get_context_name ($withprefix=true, $short=false, $escape=true) | |
Returns human readable context identifier. More... | |
get_course_context ($strict=true) | |
Is this context part of any course? If yes return course context. More... | |
get_parent_context () | |
Returns parent context. More... | |
get_parent_context_ids ($includeself=false) | |
Returns parent context ids of this context in reversed order, i.e. More... | |
get_parent_context_paths ($includeself=false) | |
Returns parent context paths of this context. More... | |
get_parent_contexts ($includeself=false) | |
Returns parent contexts of this context in reversed order, i.e. More... | |
get_url () | |
not used More... | |
getIterator () | |
Create an iterator because magic vars can't be seen by 'foreach'. More... | |
is_child_of (context $possibleparent, bool $includeself) | |
Determine if the current context is a child of the possible parent. More... | |
is_locked () | |
Whether the current context is locked. More... | |
is_parent_of (context $possiblechild, bool $includeself) | |
Determine if the current context is a parent of the possible child. More... | |
mark_dirty () | |
Mark a context as dirty (with timestamp) so as to force reloading of the context. | |
reload_if_dirty () | |
Reset all cached permissions and definitions if the necessary. More... | |
reset_paths ($rebuild=true) | |
Remove all context path info and optionally rebuild it. More... | |
set_locked (bool $locked) | |
Set whether this context has been locked or not. More... | |
update_moved (context $newparent) | |
Update context info after moving context in the tree structure. More... | |
Static Public Member Functions | |
static | build_all_paths ($force=false) |
Rebuild paths and depths in all context levels. More... | |
static | cleanup_instances () |
Remove stale contexts that belonged to deleted instances. More... | |
static | create_instances ($contextlevel=null, $buildpaths=true) |
Create all context instances at the given level and above. More... | |
static | delete_instance ($contextlevel, $instanceid) |
Delete context instance. More... | |
static | get_all_levels () |
Returns a list of all context levels. More... | |
static | get_class_for_level ($contextlevel) |
Returns a class name of the context level class. More... | |
static | get_level_name ($contextlevel) |
Returns the name of specified context level. More... | |
static | get_preload_record_columns ($tablealias) |
Returns all fields necessary for context preloading from user $rec. More... | |
static | get_preload_record_columns_sql ($tablealias) |
Returns all fields necessary for context preloading from user $rec. More... | |
static | instance_by_id ($id, $strictness=MUST_EXIST) |
Get a context instance as an object, from a given context id. More... | |
static | preload_contexts_by_id (array $contextids) |
Preload a set of contexts using their contextid. More... | |
static | preload_course ($courseid) |
Preload all contexts instances from course. More... | |
static | preload_from_record (stdClass $rec) |
Preloads context information from db record and strips the cached info. More... | |
static | reset_caches () |
Resets the cache to remove all data. More... | |
static | reset_levels () |
Reset internal context levels array. | |
Protected Member Functions | |
__construct () | |
Instance does not make sense here, only static use. | |
Static Protected Member Functions | |
static | build_paths ($force) |
Rebuild context paths and depths at context level. More... | |
static | cache_add (context $context) |
Adds a context to the cache. More... | |
static | cache_get ($contextlevel, $instance) |
Gets a context from the cache. More... | |
static | cache_get_by_id ($id) |
Gets a context from the cache based on its id. More... | |
static | cache_remove (context $context) |
Removes a context from the cache. More... | |
static | create_instance_from_record (stdClass $record) |
This function is also used to work around 'protected' keyword problems in context_helper. More... | |
static | create_level_instances () |
Create missing context instances at given level. More... | |
static | get_cleanup_sql () |
Returns sql necessary for purging of stale context instances. More... | |
static | insert_context_record ($contextlevel, $instanceid, $parentpath) |
Utility method for context creation. More... | |
static | merge_context_temp_table () |
Copy prepared new contexts from temp table to context table, we do this in db specific way for perf reasons only. | |
Protected Attributes | |
int | $_contextlevel |
The context level Can be accessed publicly through $context->contextlevel One of CONTEXT_* e.g. More... | |
int | $_depth |
The depth of the context in relation to parent contexts Can be accessed publicly through $context->depth. | |
int | $_id |
The context id Can be accessed publicly through $context->id. | |
int | $_instanceid |
Id of the item this context is related to e.g. More... | |
int | $_locked |
Whether this context is locked or not. More... | |
string | $_path |
The path to the context always starting from the system context Can be accessed publicly through $context->path. | |
Static Protected Attributes | |
static int | $cache_count = 0 |
Context count Why do we do count contexts? Because count($array) is horribly slow for large arrays. | |
static array | $cache_preloaded = array() |
Context caching info. | |
static context_system | $systemcontext = null |
The system context once initialised. | |
|
inherited |
Magic method getter, redirects to read only values.
string | $name |
mixed |
|
inherited |
Full support for isset on our magic read only properties.
string | $name |
bool |
|
inherited |
Magic setter method, we do not want anybody to modify properties from the outside.
string | $name | |
mixed | $value |
|
inherited |
All properties are read only, sorry.
string | $name |
|
static |
Rebuild paths and depths in all context levels.
bool | $force | false means add missing only |
void |
|
staticprotectedinherited |
Rebuild context paths and depths at context level.
bool | $force |
void |
Reimplemented in context_system, context_user, context_coursecat, context_course, context_module, and context_block.
|
staticprotectedinherited |
Adds a context to the cache.
If the cache is full, discards a batch of older entries.
context | $context | New context to add |
void |
|
staticprotectedinherited |
Gets a context from the cache.
int | $contextlevel | Context level |
int | $instance | Instance ID |
context|bool | Context or false if not in cache |
|
staticprotectedinherited |
Gets a context from the cache based on its id.
int | $id | Context ID |
context|bool | Context or false if not in cache |
|
staticprotectedinherited |
Removes a context from the cache.
context | $context | Context object to remove |
void |
|
static |
Remove stale contexts that belonged to deleted instances.
Ideally all code should cleanup contexts properly, unfortunately accidents happen...
void |
|
staticprotectedinherited |
This function is also used to work around 'protected' keyword problems in context_helper.
stdClass | $record |
context | instance |
|
static |
Create all context instances at the given level and above.
int | $contextlevel | null means all levels |
bool | $buildpaths |
void |
|
staticprotectedinherited |
Create missing context instances at given level.
void |
Reimplemented in context_system, context_user, context_coursecat, context_course, context_module, and context_block.
|
static |
Delete context instance.
int | $contextlevel | |
int | $instanceid |
void |
|
static |
Returns a list of all context levels.
array | int=>string (level=>level class name) |
context_helper::get_capabilities | ( | ) |
not used
Reimplemented from context.
|
inherited |
Recursive function which, given a context, find all its children context ids.
For course category contexts it will return immediate children and all subcategory contexts. It will NOT recurse into courses or subcategories categories. If you want to do that, call it on the returned courses/categories.
When called for a course context, it will return the modules and blocks displayed in the course page and blocks displayed on the module pages.
If called on a user/course/module context it will populate the cache with the appropriate contexts ;-)
array | Array of child records |
Reimplemented in context_system, context_coursecat, and context_block.
|
static |
Returns a class name of the context level class.
int | $contextlevel | (CONTEXT_SYSTEM, etc.) |
string | class name of the context class |
|
staticprotectedinherited |
Returns sql necessary for purging of stale context instances.
string | cleanup SQL |
Reimplemented in context_system, context_user, context_coursecat, context_course, context_module, and context_block.
|
inherited |
Returns human readable context identifier.
boolean | $withprefix | whether to prefix the name of the context with the type of context, e.g. User, Course, Forum, etc. |
boolean | $short | whether to use the short name of the thing. Only applies to course contexts |
boolean | $escape | Whether the returned name of the thing is to be HTML escaped or not. |
string | the human readable context name. |
Reimplemented in context_system, context_user, context_coursecat, context_course, context_module, and context_block.
|
inherited |
Is this context part of any course? If yes return course context.
bool | $strict | true means throw exception if not found, false means return false if not found |
context_course | context of the enclosing course, null if not found or exception |
Reimplemented in context_course, context_module, and context_block.
|
static |
Returns the name of specified context level.
int | $contextlevel |
string | name of the context level |
|
inherited |
Returns parent context.
context |
|
inherited |
Returns parent context ids of this context in reversed order, i.e.
parent first, then grand parent, etc.
bool | $includeself | true means include self too |
array | of context ids |
|
inherited |
Returns parent context paths of this context.
bool | $includeself | true means include self too |
array | of context paths |
|
inherited |
Returns parent contexts of this context in reversed order, i.e.
parent first, then grand parent, etc.
bool | $includeself | true means include self too |
array | of context instances |
|
static |
Returns all fields necessary for context preloading from user $rec.
This helps with performance when dealing with hundreds of contexts.
string | $tablealias | context table alias in the query |
array | (table.column=>alias, ...) |
|
static |
Returns all fields necessary for context preloading from user $rec.
This helps with performance when dealing with hundreds of contexts.
string | $tablealias | context table alias in the query |
string |
context_helper::get_url | ( | ) |
not used
Reimplemented from context.
|
inherited |
Create an iterator because magic vars can't be seen by 'foreach'.
Now we can convert context object to array using convert_to_array(), and feed it properly to json_encode().
|
staticprotectedinherited |
Utility method for context creation.
int | $contextlevel | |
int | $instanceid | |
string | $parentpath |
stdClass | context record |
|
staticinherited |
Get a context instance as an object, from a given context id.
int | $id | context id |
int | $strictness | IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; MUST_EXIST means throw exception if no record found |
context|bool | the context object or false if not found |
|
inherited |
Determine if the current context is a child of the possible parent.
context | $possibleparent | |
bool | $includeself | Whether to check the current context |
bool |
|
inherited |
Whether the current context is locked.
bool |
|
inherited |
Determine if the current context is a parent of the possible child.
context | $possiblechild | |
bool | $includeself | Whether to check the current context |
bool |
|
static |
Preload a set of contexts using their contextid.
array | $contextids |
|
static |
Preload all contexts instances from course.
To be used if you expect multiple queries for course activities...
int | $courseid |
|
static |
Preloads context information from db record and strips the cached info.
The db request has to contain all columns from context_helper::get_preload_record_columns().
stdClass | $rec |
void | (modifies $rec) |
Reimplemented from context.
|
inherited |
Reset all cached permissions and definitions if the necessary.
void |
|
static |
Resets the cache to remove all data.
Reimplemented from context.
|
inherited |
Remove all context path info and optionally rebuild it.
bool | $rebuild |
void |
|
inherited |
Set whether this context has been locked or not.
bool | $locked |
$this |
Reimplemented in context_system.
|
inherited |
Update context info after moving context in the tree structure.
context | $newparent |
void |
|
protectedinherited |
The context level Can be accessed publicly through $context->contextlevel One of CONTEXT_* e.g.
CONTEXT_COURSE, CONTEXT_MODULE
|
protectedinherited |
Id of the item this context is related to e.g.
COURSE_CONTEXT => course.id Can be accessed publicly through $context->instanceid
|
protectedinherited |
Whether this context is locked or not.
Can be accessed publicly through $context->locked.