Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
context_module Class Reference
Inheritance diagram for context_module:
context

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 ()
 Returns array of relevant context capability records. 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 ()
 Returns the most relevant URL for this context. 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 get_level_name ()
 Returns human readable context level name. More...
 
static instance ($cmid, $strictness=MUST_EXIST)
 Returns module context instance. More...
 
static instance_by_id ($id, $strictness=MUST_EXIST)
 Get a context instance as an object, from a given context id. More...
 

Protected Member Functions

 __construct (stdClass $record)
 Please use context_module::instance($cmid) if you need the instance of context. More...
 

Static Protected Member Functions

static build_paths ($force)
 Rebuild context paths and depths at module 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 module context 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.
 
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...
 

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.
 

Constructor & Destructor Documentation

◆ __construct()

context_module::__construct ( stdClass  $record)
protected

Please use context_module::instance($cmid) if you need the instance of context.

Alternatively if you know only the context id use context::instance_by_id($contextid)

Parameters
stdClass$record

Reimplemented from context.

Member Function Documentation

◆ __get()

context::__get (   $name)
inherited

Magic method getter, redirects to read only values.

Parameters
string$name
Return values
mixed

◆ __isset()

context::__isset (   $name)
inherited

Full support for isset on our magic read only properties.

Parameters
string$name
Return values
bool

◆ __set()

context::__set (   $name,
  $value 
)
inherited

Magic setter method, we do not want anybody to modify properties from the outside.

Parameters
string$name
mixed$value

◆ __unset()

context::__unset (   $name)
inherited

All properties are read only, sorry.

Parameters
string$name

◆ build_paths()

static context_module::build_paths (   $force)
staticprotected

Rebuild context paths and depths at module context level.

Parameters
bool$force

Reimplemented from context.

◆ cache_add()

static context::cache_add ( context  $context)
staticprotectedinherited

Adds a context to the cache.

If the cache is full, discards a batch of older entries.

Parameters
context$contextNew context to add
Return values
void

◆ cache_get()

static context::cache_get (   $contextlevel,
  $instance 
)
staticprotectedinherited

Gets a context from the cache.

Parameters
int$contextlevelContext level
int$instanceInstance ID
Return values
context|boolContext or false if not in cache

◆ cache_get_by_id()

static context::cache_get_by_id (   $id)
staticprotectedinherited

Gets a context from the cache based on its id.

Parameters
int$idContext ID
Return values
context|boolContext or false if not in cache

◆ cache_remove()

static context::cache_remove ( context  $context)
staticprotectedinherited

Removes a context from the cache.

Parameters
context$contextContext object to remove
Return values
void

◆ create_instance_from_record()

static context::create_instance_from_record ( stdClass  $record)
staticprotectedinherited

This function is also used to work around 'protected' keyword problems in context_helper.

Parameters
stdClass$record
Return values
contextinstance

◆ create_level_instances()

static context_module::create_level_instances ( )
staticprotected

Create missing context instances at module context level.

Reimplemented from context.

◆ get_capabilities()

context_module::get_capabilities ( )

Returns array of relevant context capability records.

Return values
array

Reimplemented from context.

◆ get_child_contexts()

context::get_child_contexts ( )
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 ;-)

Return values
arrayArray of child records

Reimplemented in context_system, context_coursecat, and context_block.

◆ get_cleanup_sql()

static context_module::get_cleanup_sql ( )
staticprotected

Returns sql necessary for purging of stale context instances.

Return values
stringcleanup SQL

Reimplemented from context.

◆ get_context_name()

context_module::get_context_name (   $withprefix = true,
  $short = false,
  $escape = true 
)

Returns human readable context identifier.

Parameters
boolean$withprefixwhether to prefix the name of the context with the module name, e.g. Forum, Glossary, etc.
boolean$shortdoes not apply to module context
boolean$escapeWhether the returned name of the context is to be HTML escaped or not.
Return values
stringthe human readable context name.

Reimplemented from context.

◆ get_course_context()

context_module::get_course_context (   $strict = true)

Is this context part of any course? If yes return course context.

Parameters
bool$stricttrue means throw exception if not found, false means return false if not found
Return values
context_coursecontext of the enclosing course, null if not found or exception

Reimplemented from context.

◆ get_level_name()

static context_module::get_level_name ( )
static

Returns human readable context level name.

Return values
stringthe human readable context level name.

◆ get_parent_context()

context::get_parent_context ( )
inherited

Returns parent context.

Return values
context

◆ get_parent_context_ids()

context::get_parent_context_ids (   $includeself = false)
inherited

Returns parent context ids of this context in reversed order, i.e.

parent first, then grand parent, etc.

Parameters
bool$includeselftrue means include self too
Return values
arrayof context ids

◆ get_parent_context_paths()

context::get_parent_context_paths (   $includeself = false)
inherited

Returns parent context paths of this context.

Parameters
bool$includeselftrue means include self too
Return values
arrayof context paths

◆ get_parent_contexts()

context::get_parent_contexts (   $includeself = false)
inherited

Returns parent contexts of this context in reversed order, i.e.

parent first, then grand parent, etc.

Parameters
bool$includeselftrue means include self too
Return values
arrayof context instances

◆ get_url()

context_module::get_url ( )

Returns the most relevant URL for this context.

Return values
moodle_url

Reimplemented from context.

◆ getIterator()

context::getIterator ( )
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().

◆ insert_context_record()

static context::insert_context_record (   $contextlevel,
  $instanceid,
  $parentpath 
)
staticprotectedinherited

Utility method for context creation.

Parameters
int$contextlevel
int$instanceid
string$parentpath
Return values
stdClasscontext record

◆ instance()

static context_module::instance (   $cmid,
  $strictness = MUST_EXIST 
)
static

Returns module context instance.

Parameters
int$cmidid of the record from {course_modules} table; pass cmid there, NOT id in the instance column
int$strictness
Return values
context_modulecontext instance

◆ instance_by_id()

static context::instance_by_id (   $id,
  $strictness = MUST_EXIST 
)
staticinherited

Get a context instance as an object, from a given context id.

Parameters
int$idcontext id
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; MUST_EXIST means throw exception if no record found
Return values
context|boolthe context object or false if not found

◆ is_child_of()

context::is_child_of ( context  $possibleparent,
bool  $includeself 
)
inherited

Determine if the current context is a child of the possible parent.

Parameters
context$possibleparent
bool$includeselfWhether to check the current context
Return values
bool

◆ is_locked()

context::is_locked ( )
inherited

Whether the current context is locked.

Return values
bool

◆ is_parent_of()

context::is_parent_of ( context  $possiblechild,
bool  $includeself 
)
inherited

Determine if the current context is a parent of the possible child.

Parameters
context$possiblechild
bool$includeselfWhether to check the current context
Return values
bool

◆ preload_from_record()

static context::preload_from_record ( stdClass  $rec)
staticprotectedinherited

Preloads context information from db record and strips the cached info.

Parameters
stdClass$rec
Return values
void(modifies $rec)

Reimplemented in context_helper.

◆ reload_if_dirty()

context::reload_if_dirty ( )
inherited

Reset all cached permissions and definitions if the necessary.

Return values
void

◆ reset_caches()

static context::reset_caches ( )
staticprotectedinherited

Resets the cache to remove all data.

Reimplemented in context_helper.

◆ reset_paths()

context::reset_paths (   $rebuild = true)
inherited

Remove all context path info and optionally rebuild it.

Parameters
bool$rebuild
Return values
void

◆ set_locked()

context::set_locked ( bool  $locked)
inherited

Set whether this context has been locked or not.

Parameters
bool$locked
Return values
$this

Reimplemented in context_system.

◆ update_moved()

context::update_moved ( context  $newparent)
inherited

Update context info after moving context in the tree structure.

Parameters
context$newparent
Return values
void

Member Data Documentation

◆ $_contextlevel

int context::$_contextlevel
protectedinherited

The context level Can be accessed publicly through $context->contextlevel One of CONTEXT_* e.g.

CONTEXT_COURSE, CONTEXT_MODULE

◆ $_instanceid

int context::$_instanceid
protectedinherited

Id of the item this context is related to e.g.

COURSE_CONTEXT => course.id Can be accessed publicly through $context->instanceid

◆ $_locked

int context::$_locked
protectedinherited

Whether this context is locked or not.

Can be accessed publicly through $context->locked.


The documentation for this class was generated from the following file: