id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
218,600
moodle/moodle
message/classes/time_last_message_between_users.php
time_last_message_between_users.get_instance_for_cache
public static function get_instance_for_cache(\cache_definition $definition) { if (is_null(self::$instance)) { self::$instance = new time_last_message_between_users(); } return self::$instance; }
php
public static function get_instance_for_cache(\cache_definition $definition) { if (is_null(self::$instance)) { self::$instance = new time_last_message_between_users(); } return self::$instance; }
[ "public", "static", "function", "get_instance_for_cache", "(", "\\", "cache_definition", "$", "definition", ")", "{", "if", "(", "is_null", "(", "self", "::", "$", "instance", ")", ")", "{", "self", "::", "$", "instance", "=", "new", "time_last_message_between_users", "(", ")", ";", "}", "return", "self", "::", "$", "instance", ";", "}" ]
Returns an instance of the data source class that the cache can use for loading data using the other methods specified by the cache_data_source interface. @param \cache_definition $definition @return object
[ "Returns", "an", "instance", "of", "the", "data", "source", "class", "that", "the", "cache", "can", "use", "for", "loading", "data", "using", "the", "other", "methods", "specified", "by", "the", "cache_data_source", "interface", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/time_last_message_between_users.php#L50-L55
218,601
moodle/moodle
message/classes/time_last_message_between_users.php
time_last_message_between_users.load_for_cache
public function load_for_cache($key) { $message = api::get_most_recent_conversation_message($key); if ($message) { return $message->timecreated; } else { return null; } }
php
public function load_for_cache($key) { $message = api::get_most_recent_conversation_message($key); if ($message) { return $message->timecreated; } else { return null; } }
[ "public", "function", "load_for_cache", "(", "$", "key", ")", "{", "$", "message", "=", "api", "::", "get_most_recent_conversation_message", "(", "$", "key", ")", ";", "if", "(", "$", "message", ")", "{", "return", "$", "message", "->", "timecreated", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Loads the data for the key provided ready formatted for caching. @param string|int $key The key to load. @return mixed What ever data should be returned, or false if it can't be loaded.
[ "Loads", "the", "data", "for", "the", "key", "provided", "ready", "formatted", "for", "caching", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/time_last_message_between_users.php#L63-L71
218,602
moodle/moodle
message/classes/time_last_message_between_users.php
time_last_message_between_users.load_many_for_cache
public function load_many_for_cache(array $keys) { $results = []; foreach ($keys as $key) { $results[] = $this->load_for_cache($key); } return $results; }
php
public function load_many_for_cache(array $keys) { $results = []; foreach ($keys as $key) { $results[] = $this->load_for_cache($key); } return $results; }
[ "public", "function", "load_many_for_cache", "(", "array", "$", "keys", ")", "{", "$", "results", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "$", "results", "[", "]", "=", "$", "this", "->", "load_for_cache", "(", "$", "key", ")", ";", "}", "return", "$", "results", ";", "}" ]
Loads several keys for the cache. @param array $keys An array of keys each of which will be string|int. @return array An array of matching data items.
[ "Loads", "several", "keys", "for", "the", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/time_last_message_between_users.php#L79-L87
218,603
moodle/moodle
lib/accesslib.php
context.reset_caches
protected static function reset_caches() { self::$cache_contextsbyid = array(); self::$cache_contexts = array(); self::$cache_count = 0; self::$cache_preloaded = array(); self::$systemcontext = null; }
php
protected static function reset_caches() { self::$cache_contextsbyid = array(); self::$cache_contexts = array(); self::$cache_count = 0; self::$cache_preloaded = array(); self::$systemcontext = null; }
[ "protected", "static", "function", "reset_caches", "(", ")", "{", "self", "::", "$", "cache_contextsbyid", "=", "array", "(", ")", ";", "self", "::", "$", "cache_contexts", "=", "array", "(", ")", ";", "self", "::", "$", "cache_count", "=", "0", ";", "self", "::", "$", "cache_preloaded", "=", "array", "(", ")", ";", "self", "::", "$", "systemcontext", "=", "null", ";", "}" ]
Resets the cache to remove all data. @static
[ "Resets", "the", "cache", "to", "remove", "all", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L4839-L4846
218,604
moodle/moodle
lib/accesslib.php
context.cache_add
protected static function cache_add(context $context) { if (isset(self::$cache_contextsbyid[$context->id])) { // already cached, no need to do anything - this is relatively cheap, we do all this because count() is slow return; } if (self::$cache_count >= CONTEXT_CACHE_MAX_SIZE) { $i = 0; foreach(self::$cache_contextsbyid as $ctx) { $i++; if ($i <= 100) { // we want to keep the first contexts to be loaded on this page, hopefully they will be needed again later continue; } if ($i > (CONTEXT_CACHE_MAX_SIZE / 3)) { // we remove oldest third of the contexts to make room for more contexts break; } unset(self::$cache_contextsbyid[$ctx->id]); unset(self::$cache_contexts[$ctx->contextlevel][$ctx->instanceid]); self::$cache_count--; } } self::$cache_contexts[$context->contextlevel][$context->instanceid] = $context; self::$cache_contextsbyid[$context->id] = $context; self::$cache_count++; }
php
protected static function cache_add(context $context) { if (isset(self::$cache_contextsbyid[$context->id])) { // already cached, no need to do anything - this is relatively cheap, we do all this because count() is slow return; } if (self::$cache_count >= CONTEXT_CACHE_MAX_SIZE) { $i = 0; foreach(self::$cache_contextsbyid as $ctx) { $i++; if ($i <= 100) { // we want to keep the first contexts to be loaded on this page, hopefully they will be needed again later continue; } if ($i > (CONTEXT_CACHE_MAX_SIZE / 3)) { // we remove oldest third of the contexts to make room for more contexts break; } unset(self::$cache_contextsbyid[$ctx->id]); unset(self::$cache_contexts[$ctx->contextlevel][$ctx->instanceid]); self::$cache_count--; } } self::$cache_contexts[$context->contextlevel][$context->instanceid] = $context; self::$cache_contextsbyid[$context->id] = $context; self::$cache_count++; }
[ "protected", "static", "function", "cache_add", "(", "context", "$", "context", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "cache_contextsbyid", "[", "$", "context", "->", "id", "]", ")", ")", "{", "// already cached, no need to do anything - this is relatively cheap, we do all this because count() is slow", "return", ";", "}", "if", "(", "self", "::", "$", "cache_count", ">=", "CONTEXT_CACHE_MAX_SIZE", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "self", "::", "$", "cache_contextsbyid", "as", "$", "ctx", ")", "{", "$", "i", "++", ";", "if", "(", "$", "i", "<=", "100", ")", "{", "// we want to keep the first contexts to be loaded on this page, hopefully they will be needed again later", "continue", ";", "}", "if", "(", "$", "i", ">", "(", "CONTEXT_CACHE_MAX_SIZE", "/", "3", ")", ")", "{", "// we remove oldest third of the contexts to make room for more contexts", "break", ";", "}", "unset", "(", "self", "::", "$", "cache_contextsbyid", "[", "$", "ctx", "->", "id", "]", ")", ";", "unset", "(", "self", "::", "$", "cache_contexts", "[", "$", "ctx", "->", "contextlevel", "]", "[", "$", "ctx", "->", "instanceid", "]", ")", ";", "self", "::", "$", "cache_count", "--", ";", "}", "}", "self", "::", "$", "cache_contexts", "[", "$", "context", "->", "contextlevel", "]", "[", "$", "context", "->", "instanceid", "]", "=", "$", "context", ";", "self", "::", "$", "cache_contextsbyid", "[", "$", "context", "->", "id", "]", "=", "$", "context", ";", "self", "::", "$", "cache_count", "++", ";", "}" ]
Adds a context to the cache. If the cache is full, discards a batch of older entries. @static @param context $context New context to add @return void
[ "Adds", "a", "context", "to", "the", "cache", ".", "If", "the", "cache", "is", "full", "discards", "a", "batch", "of", "older", "entries", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L4856-L4883
218,605
moodle/moodle
lib/accesslib.php
context.cache_remove
protected static function cache_remove(context $context) { if (!isset(self::$cache_contextsbyid[$context->id])) { // not cached, no need to do anything - this is relatively cheap, we do all this because count() is slow return; } unset(self::$cache_contexts[$context->contextlevel][$context->instanceid]); unset(self::$cache_contextsbyid[$context->id]); self::$cache_count--; if (self::$cache_count < 0) { self::$cache_count = 0; } }
php
protected static function cache_remove(context $context) { if (!isset(self::$cache_contextsbyid[$context->id])) { // not cached, no need to do anything - this is relatively cheap, we do all this because count() is slow return; } unset(self::$cache_contexts[$context->contextlevel][$context->instanceid]); unset(self::$cache_contextsbyid[$context->id]); self::$cache_count--; if (self::$cache_count < 0) { self::$cache_count = 0; } }
[ "protected", "static", "function", "cache_remove", "(", "context", "$", "context", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "cache_contextsbyid", "[", "$", "context", "->", "id", "]", ")", ")", "{", "// not cached, no need to do anything - this is relatively cheap, we do all this because count() is slow", "return", ";", "}", "unset", "(", "self", "::", "$", "cache_contexts", "[", "$", "context", "->", "contextlevel", "]", "[", "$", "context", "->", "instanceid", "]", ")", ";", "unset", "(", "self", "::", "$", "cache_contextsbyid", "[", "$", "context", "->", "id", "]", ")", ";", "self", "::", "$", "cache_count", "--", ";", "if", "(", "self", "::", "$", "cache_count", "<", "0", ")", "{", "self", "::", "$", "cache_count", "=", "0", ";", "}", "}" ]
Removes a context from the cache. @static @param context $context Context object to remove @return void
[ "Removes", "a", "context", "from", "the", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L4892-L4905
218,606
moodle/moodle
lib/accesslib.php
context.cache_get
protected static function cache_get($contextlevel, $instance) { if (isset(self::$cache_contexts[$contextlevel][$instance])) { return self::$cache_contexts[$contextlevel][$instance]; } return false; }
php
protected static function cache_get($contextlevel, $instance) { if (isset(self::$cache_contexts[$contextlevel][$instance])) { return self::$cache_contexts[$contextlevel][$instance]; } return false; }
[ "protected", "static", "function", "cache_get", "(", "$", "contextlevel", ",", "$", "instance", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "cache_contexts", "[", "$", "contextlevel", "]", "[", "$", "instance", "]", ")", ")", "{", "return", "self", "::", "$", "cache_contexts", "[", "$", "contextlevel", "]", "[", "$", "instance", "]", ";", "}", "return", "false", ";", "}" ]
Gets a context from the cache. @static @param int $contextlevel Context level @param int $instance Instance ID @return context|bool Context or false if not in cache
[ "Gets", "a", "context", "from", "the", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L4915-L4920
218,607
moodle/moodle
lib/accesslib.php
context.cache_get_by_id
protected static function cache_get_by_id($id) { if (isset(self::$cache_contextsbyid[$id])) { return self::$cache_contextsbyid[$id]; } return false; }
php
protected static function cache_get_by_id($id) { if (isset(self::$cache_contextsbyid[$id])) { return self::$cache_contextsbyid[$id]; } return false; }
[ "protected", "static", "function", "cache_get_by_id", "(", "$", "id", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "cache_contextsbyid", "[", "$", "id", "]", ")", ")", "{", "return", "self", "::", "$", "cache_contextsbyid", "[", "$", "id", "]", ";", "}", "return", "false", ";", "}" ]
Gets a context from the cache based on its id. @static @param int $id Context ID @return context|bool Context or false if not in cache
[ "Gets", "a", "context", "from", "the", "cache", "based", "on", "its", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L4929-L4934
218,608
moodle/moodle
lib/accesslib.php
context.preload_from_record
protected static function preload_from_record(stdClass $rec) { $notenoughdata = false; $notenoughdata = $notenoughdata || empty($rec->ctxid); $notenoughdata = $notenoughdata || empty($rec->ctxlevel); $notenoughdata = $notenoughdata || !isset($rec->ctxinstance); $notenoughdata = $notenoughdata || empty($rec->ctxpath); $notenoughdata = $notenoughdata || empty($rec->ctxdepth); $notenoughdata = $notenoughdata || !isset($rec->ctxlocked); if ($notenoughdata) { // The record does not have enough data, passed here repeatedly or context does not exist yet. if (isset($rec->ctxid) && !isset($rec->ctxlocked)) { debugging('Locked value missing. Code is possibly not usings the getter properly.', DEBUG_DEVELOPER); } return; } $record = (object) [ 'id' => $rec->ctxid, 'contextlevel' => $rec->ctxlevel, 'instanceid' => $rec->ctxinstance, 'path' => $rec->ctxpath, 'depth' => $rec->ctxdepth, 'locked' => $rec->ctxlocked, ]; unset($rec->ctxid); unset($rec->ctxlevel); unset($rec->ctxinstance); unset($rec->ctxpath); unset($rec->ctxdepth); unset($rec->ctxlocked); return context::create_instance_from_record($record); }
php
protected static function preload_from_record(stdClass $rec) { $notenoughdata = false; $notenoughdata = $notenoughdata || empty($rec->ctxid); $notenoughdata = $notenoughdata || empty($rec->ctxlevel); $notenoughdata = $notenoughdata || !isset($rec->ctxinstance); $notenoughdata = $notenoughdata || empty($rec->ctxpath); $notenoughdata = $notenoughdata || empty($rec->ctxdepth); $notenoughdata = $notenoughdata || !isset($rec->ctxlocked); if ($notenoughdata) { // The record does not have enough data, passed here repeatedly or context does not exist yet. if (isset($rec->ctxid) && !isset($rec->ctxlocked)) { debugging('Locked value missing. Code is possibly not usings the getter properly.', DEBUG_DEVELOPER); } return; } $record = (object) [ 'id' => $rec->ctxid, 'contextlevel' => $rec->ctxlevel, 'instanceid' => $rec->ctxinstance, 'path' => $rec->ctxpath, 'depth' => $rec->ctxdepth, 'locked' => $rec->ctxlocked, ]; unset($rec->ctxid); unset($rec->ctxlevel); unset($rec->ctxinstance); unset($rec->ctxpath); unset($rec->ctxdepth); unset($rec->ctxlocked); return context::create_instance_from_record($record); }
[ "protected", "static", "function", "preload_from_record", "(", "stdClass", "$", "rec", ")", "{", "$", "notenoughdata", "=", "false", ";", "$", "notenoughdata", "=", "$", "notenoughdata", "||", "empty", "(", "$", "rec", "->", "ctxid", ")", ";", "$", "notenoughdata", "=", "$", "notenoughdata", "||", "empty", "(", "$", "rec", "->", "ctxlevel", ")", ";", "$", "notenoughdata", "=", "$", "notenoughdata", "||", "!", "isset", "(", "$", "rec", "->", "ctxinstance", ")", ";", "$", "notenoughdata", "=", "$", "notenoughdata", "||", "empty", "(", "$", "rec", "->", "ctxpath", ")", ";", "$", "notenoughdata", "=", "$", "notenoughdata", "||", "empty", "(", "$", "rec", "->", "ctxdepth", ")", ";", "$", "notenoughdata", "=", "$", "notenoughdata", "||", "!", "isset", "(", "$", "rec", "->", "ctxlocked", ")", ";", "if", "(", "$", "notenoughdata", ")", "{", "// The record does not have enough data, passed here repeatedly or context does not exist yet.", "if", "(", "isset", "(", "$", "rec", "->", "ctxid", ")", "&&", "!", "isset", "(", "$", "rec", "->", "ctxlocked", ")", ")", "{", "debugging", "(", "'Locked value missing. Code is possibly not usings the getter properly.'", ",", "DEBUG_DEVELOPER", ")", ";", "}", "return", ";", "}", "$", "record", "=", "(", "object", ")", "[", "'id'", "=>", "$", "rec", "->", "ctxid", ",", "'contextlevel'", "=>", "$", "rec", "->", "ctxlevel", ",", "'instanceid'", "=>", "$", "rec", "->", "ctxinstance", ",", "'path'", "=>", "$", "rec", "->", "ctxpath", ",", "'depth'", "=>", "$", "rec", "->", "ctxdepth", ",", "'locked'", "=>", "$", "rec", "->", "ctxlocked", ",", "]", ";", "unset", "(", "$", "rec", "->", "ctxid", ")", ";", "unset", "(", "$", "rec", "->", "ctxlevel", ")", ";", "unset", "(", "$", "rec", "->", "ctxinstance", ")", ";", "unset", "(", "$", "rec", "->", "ctxpath", ")", ";", "unset", "(", "$", "rec", "->", "ctxdepth", ")", ";", "unset", "(", "$", "rec", "->", "ctxlocked", ")", ";", "return", "context", "::", "create_instance_from_record", "(", "$", "record", ")", ";", "}" ]
Preloads context information from db record and strips the cached info. @static @param stdClass $rec @return void (modifies $rec)
[ "Preloads", "context", "information", "from", "db", "record", "and", "strips", "the", "cached", "info", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L4943-L4976
218,609
moodle/moodle
lib/accesslib.php
context.create_instance_from_record
protected static function create_instance_from_record(stdClass $record) { $classname = context_helper::get_class_for_level($record->contextlevel); if ($context = context::cache_get_by_id($record->id)) { return $context; } $context = new $classname($record); context::cache_add($context); return $context; }
php
protected static function create_instance_from_record(stdClass $record) { $classname = context_helper::get_class_for_level($record->contextlevel); if ($context = context::cache_get_by_id($record->id)) { return $context; } $context = new $classname($record); context::cache_add($context); return $context; }
[ "protected", "static", "function", "create_instance_from_record", "(", "stdClass", "$", "record", ")", "{", "$", "classname", "=", "context_helper", "::", "get_class_for_level", "(", "$", "record", "->", "contextlevel", ")", ";", "if", "(", "$", "context", "=", "context", "::", "cache_get_by_id", "(", "$", "record", "->", "id", ")", ")", "{", "return", "$", "context", ";", "}", "$", "context", "=", "new", "$", "classname", "(", "$", "record", ")", ";", "context", "::", "cache_add", "(", "$", "context", ")", ";", "return", "$", "context", ";", "}" ]
This function is also used to work around 'protected' keyword problems in context_helper. @static @param stdClass $record @return context instance
[ "This", "function", "is", "also", "used", "to", "work", "around", "protected", "keyword", "problems", "in", "context_helper", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5097-L5108
218,610
moodle/moodle
lib/accesslib.php
context.merge_context_temp_table
protected static function merge_context_temp_table() { global $DB; /* MDL-11347: * - mysql does not allow to use FROM in UPDATE statements * - using two tables after UPDATE works in mysql, but might give unexpected * results in pg 8 (depends on configuration) * - using table alias in UPDATE does not work in pg < 8.2 * * Different code for each database - mostly for performance reasons */ $dbfamily = $DB->get_dbfamily(); if ($dbfamily == 'mysql') { $updatesql = "UPDATE {context} ct, {context_temp} temp SET ct.path = temp.path, ct.depth = temp.depth, ct.locked = temp.locked WHERE ct.id = temp.id"; } else if ($dbfamily == 'oracle') { $updatesql = "UPDATE {context} ct SET (ct.path, ct.depth, ct.locked) = (SELECT temp.path, temp.depth, temp.locked FROM {context_temp} temp WHERE temp.id=ct.id) WHERE EXISTS (SELECT 'x' FROM {context_temp} temp WHERE temp.id = ct.id)"; } else if ($dbfamily == 'postgres' or $dbfamily == 'mssql') { $updatesql = "UPDATE {context} SET path = temp.path, depth = temp.depth, locked = temp.locked FROM {context_temp} temp WHERE temp.id={context}.id"; } else { // sqlite and others $updatesql = "UPDATE {context} SET path = (SELECT path FROM {context_temp} WHERE id = {context}.id), depth = (SELECT depth FROM {context_temp} WHERE id = {context}.id), locked = (SELECT locked FROM {context_temp} WHERE id = {context}.id) WHERE id IN (SELECT id FROM {context_temp})"; } $DB->execute($updatesql); }
php
protected static function merge_context_temp_table() { global $DB; /* MDL-11347: * - mysql does not allow to use FROM in UPDATE statements * - using two tables after UPDATE works in mysql, but might give unexpected * results in pg 8 (depends on configuration) * - using table alias in UPDATE does not work in pg < 8.2 * * Different code for each database - mostly for performance reasons */ $dbfamily = $DB->get_dbfamily(); if ($dbfamily == 'mysql') { $updatesql = "UPDATE {context} ct, {context_temp} temp SET ct.path = temp.path, ct.depth = temp.depth, ct.locked = temp.locked WHERE ct.id = temp.id"; } else if ($dbfamily == 'oracle') { $updatesql = "UPDATE {context} ct SET (ct.path, ct.depth, ct.locked) = (SELECT temp.path, temp.depth, temp.locked FROM {context_temp} temp WHERE temp.id=ct.id) WHERE EXISTS (SELECT 'x' FROM {context_temp} temp WHERE temp.id = ct.id)"; } else if ($dbfamily == 'postgres' or $dbfamily == 'mssql') { $updatesql = "UPDATE {context} SET path = temp.path, depth = temp.depth, locked = temp.locked FROM {context_temp} temp WHERE temp.id={context}.id"; } else { // sqlite and others $updatesql = "UPDATE {context} SET path = (SELECT path FROM {context_temp} WHERE id = {context}.id), depth = (SELECT depth FROM {context_temp} WHERE id = {context}.id), locked = (SELECT locked FROM {context_temp} WHERE id = {context}.id) WHERE id IN (SELECT id FROM {context_temp})"; } $DB->execute($updatesql); }
[ "protected", "static", "function", "merge_context_temp_table", "(", ")", "{", "global", "$", "DB", ";", "/* MDL-11347:\n * - mysql does not allow to use FROM in UPDATE statements\n * - using two tables after UPDATE works in mysql, but might give unexpected\n * results in pg 8 (depends on configuration)\n * - using table alias in UPDATE does not work in pg < 8.2\n *\n * Different code for each database - mostly for performance reasons\n */", "$", "dbfamily", "=", "$", "DB", "->", "get_dbfamily", "(", ")", ";", "if", "(", "$", "dbfamily", "==", "'mysql'", ")", "{", "$", "updatesql", "=", "\"UPDATE {context} ct, {context_temp} temp\n SET ct.path = temp.path,\n ct.depth = temp.depth,\n ct.locked = temp.locked\n WHERE ct.id = temp.id\"", ";", "}", "else", "if", "(", "$", "dbfamily", "==", "'oracle'", ")", "{", "$", "updatesql", "=", "\"UPDATE {context} ct\n SET (ct.path, ct.depth, ct.locked) =\n (SELECT temp.path, temp.depth, temp.locked\n FROM {context_temp} temp\n WHERE temp.id=ct.id)\n WHERE EXISTS (SELECT 'x'\n FROM {context_temp} temp\n WHERE temp.id = ct.id)\"", ";", "}", "else", "if", "(", "$", "dbfamily", "==", "'postgres'", "or", "$", "dbfamily", "==", "'mssql'", ")", "{", "$", "updatesql", "=", "\"UPDATE {context}\n SET path = temp.path,\n depth = temp.depth,\n locked = temp.locked\n FROM {context_temp} temp\n WHERE temp.id={context}.id\"", ";", "}", "else", "{", "// sqlite and others", "$", "updatesql", "=", "\"UPDATE {context}\n SET path = (SELECT path FROM {context_temp} WHERE id = {context}.id),\n depth = (SELECT depth FROM {context_temp} WHERE id = {context}.id),\n locked = (SELECT locked FROM {context_temp} WHERE id = {context}.id)\n WHERE id IN (SELECT id FROM {context_temp})\"", ";", "}", "$", "DB", "->", "execute", "(", "$", "updatesql", ")", ";", "}" ]
Copy prepared new contexts from temp table to context table, we do this in db specific way for perf reasons only. @static
[ "Copy", "prepared", "new", "contexts", "from", "temp", "table", "to", "context", "table", "we", "do", "this", "in", "db", "specific", "way", "for", "perf", "reasons", "only", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5115-L5160
218,611
moodle/moodle
lib/accesslib.php
context.instance_by_id
public static function instance_by_id($id, $strictness = MUST_EXIST) { global $DB; if (get_called_class() !== 'context' and get_called_class() !== 'context_helper') { // some devs might confuse context->id and instanceid, better prevent these mistakes completely throw new coding_exception('use only context::instance_by_id() for real context levels use ::instance() methods'); } if ($id == SYSCONTEXTID) { return context_system::instance(0, $strictness); } if (is_array($id) or is_object($id) or empty($id)) { throw new coding_exception('Invalid context id specified context::instance_by_id()'); } if ($context = context::cache_get_by_id($id)) { return $context; } if ($record = $DB->get_record('context', array('id'=>$id), '*', $strictness)) { return context::create_instance_from_record($record); } return false; }
php
public static function instance_by_id($id, $strictness = MUST_EXIST) { global $DB; if (get_called_class() !== 'context' and get_called_class() !== 'context_helper') { // some devs might confuse context->id and instanceid, better prevent these mistakes completely throw new coding_exception('use only context::instance_by_id() for real context levels use ::instance() methods'); } if ($id == SYSCONTEXTID) { return context_system::instance(0, $strictness); } if (is_array($id) or is_object($id) or empty($id)) { throw new coding_exception('Invalid context id specified context::instance_by_id()'); } if ($context = context::cache_get_by_id($id)) { return $context; } if ($record = $DB->get_record('context', array('id'=>$id), '*', $strictness)) { return context::create_instance_from_record($record); } return false; }
[ "public", "static", "function", "instance_by_id", "(", "$", "id", ",", "$", "strictness", "=", "MUST_EXIST", ")", "{", "global", "$", "DB", ";", "if", "(", "get_called_class", "(", ")", "!==", "'context'", "and", "get_called_class", "(", ")", "!==", "'context_helper'", ")", "{", "// some devs might confuse context->id and instanceid, better prevent these mistakes completely", "throw", "new", "coding_exception", "(", "'use only context::instance_by_id() for real context levels use ::instance() methods'", ")", ";", "}", "if", "(", "$", "id", "==", "SYSCONTEXTID", ")", "{", "return", "context_system", "::", "instance", "(", "0", ",", "$", "strictness", ")", ";", "}", "if", "(", "is_array", "(", "$", "id", ")", "or", "is_object", "(", "$", "id", ")", "or", "empty", "(", "$", "id", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid context id specified context::instance_by_id()'", ")", ";", "}", "if", "(", "$", "context", "=", "context", "::", "cache_get_by_id", "(", "$", "id", ")", ")", "{", "return", "$", "context", ";", "}", "if", "(", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'context'", ",", "array", "(", "'id'", "=>", "$", "id", ")", ",", "'*'", ",", "$", "strictness", ")", ")", "{", "return", "context", "::", "create_instance_from_record", "(", "$", "record", ")", ";", "}", "return", "false", ";", "}" ]
Get a context instance as an object, from a given context id. @static @param int $id context id @param 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 @return context|bool the context object or false if not found
[ "Get", "a", "context", "instance", "as", "an", "object", "from", "a", "given", "context", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5171-L5196
218,612
moodle/moodle
lib/accesslib.php
context.update_moved
public function update_moved(context $newparent) { global $DB; $frompath = $this->_path; $newpath = $newparent->path . '/' . $this->_id; $trans = $DB->start_delegated_transaction(); $setdepth = ''; if (($newparent->depth +1) != $this->_depth) { $diff = $newparent->depth - $this->_depth + 1; $setdepth = ", depth = depth + $diff"; } $sql = "UPDATE {context} SET path = ? $setdepth WHERE id = ?"; $params = array($newpath, $this->_id); $DB->execute($sql, $params); $this->_path = $newpath; $this->_depth = $newparent->depth + 1; $sql = "UPDATE {context} SET path = ".$DB->sql_concat("?", $DB->sql_substr("path", strlen($frompath)+1))." $setdepth WHERE path LIKE ?"; $params = array($newpath, "{$frompath}/%"); $DB->execute($sql, $params); $this->mark_dirty(); context::reset_caches(); $trans->allow_commit(); }
php
public function update_moved(context $newparent) { global $DB; $frompath = $this->_path; $newpath = $newparent->path . '/' . $this->_id; $trans = $DB->start_delegated_transaction(); $setdepth = ''; if (($newparent->depth +1) != $this->_depth) { $diff = $newparent->depth - $this->_depth + 1; $setdepth = ", depth = depth + $diff"; } $sql = "UPDATE {context} SET path = ? $setdepth WHERE id = ?"; $params = array($newpath, $this->_id); $DB->execute($sql, $params); $this->_path = $newpath; $this->_depth = $newparent->depth + 1; $sql = "UPDATE {context} SET path = ".$DB->sql_concat("?", $DB->sql_substr("path", strlen($frompath)+1))." $setdepth WHERE path LIKE ?"; $params = array($newpath, "{$frompath}/%"); $DB->execute($sql, $params); $this->mark_dirty(); context::reset_caches(); $trans->allow_commit(); }
[ "public", "function", "update_moved", "(", "context", "$", "newparent", ")", "{", "global", "$", "DB", ";", "$", "frompath", "=", "$", "this", "->", "_path", ";", "$", "newpath", "=", "$", "newparent", "->", "path", ".", "'/'", ".", "$", "this", "->", "_id", ";", "$", "trans", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "$", "setdepth", "=", "''", ";", "if", "(", "(", "$", "newparent", "->", "depth", "+", "1", ")", "!=", "$", "this", "->", "_depth", ")", "{", "$", "diff", "=", "$", "newparent", "->", "depth", "-", "$", "this", "->", "_depth", "+", "1", ";", "$", "setdepth", "=", "\", depth = depth + $diff\"", ";", "}", "$", "sql", "=", "\"UPDATE {context}\n SET path = ?\n $setdepth\n WHERE id = ?\"", ";", "$", "params", "=", "array", "(", "$", "newpath", ",", "$", "this", "->", "_id", ")", ";", "$", "DB", "->", "execute", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "this", "->", "_path", "=", "$", "newpath", ";", "$", "this", "->", "_depth", "=", "$", "newparent", "->", "depth", "+", "1", ";", "$", "sql", "=", "\"UPDATE {context}\n SET path = \"", ".", "$", "DB", "->", "sql_concat", "(", "\"?\"", ",", "$", "DB", "->", "sql_substr", "(", "\"path\"", ",", "strlen", "(", "$", "frompath", ")", "+", "1", ")", ")", ".", "\"\n $setdepth\n WHERE path LIKE ?\"", ";", "$", "params", "=", "array", "(", "$", "newpath", ",", "\"{$frompath}/%\"", ")", ";", "$", "DB", "->", "execute", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "this", "->", "mark_dirty", "(", ")", ";", "context", "::", "reset_caches", "(", ")", ";", "$", "trans", "->", "allow_commit", "(", ")", ";", "}" ]
Update context info after moving context in the tree structure. @param context $newparent @return void
[ "Update", "context", "info", "after", "moving", "context", "in", "the", "tree", "structure", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5204-L5239
218,613
moodle/moodle
lib/accesslib.php
context.set_locked
public function set_locked(bool $locked) { global $DB; if ($this->_locked == $locked) { return $this; } $this->_locked = $locked; $DB->set_field('context', 'locked', (int) $locked, ['id' => $this->id]); $this->mark_dirty(); self::reset_caches(); return $this; }
php
public function set_locked(bool $locked) { global $DB; if ($this->_locked == $locked) { return $this; } $this->_locked = $locked; $DB->set_field('context', 'locked', (int) $locked, ['id' => $this->id]); $this->mark_dirty(); self::reset_caches(); return $this; }
[ "public", "function", "set_locked", "(", "bool", "$", "locked", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "_locked", "==", "$", "locked", ")", "{", "return", "$", "this", ";", "}", "$", "this", "->", "_locked", "=", "$", "locked", ";", "$", "DB", "->", "set_field", "(", "'context'", ",", "'locked'", ",", "(", "int", ")", "$", "locked", ",", "[", "'id'", "=>", "$", "this", "->", "id", "]", ")", ";", "$", "this", "->", "mark_dirty", "(", ")", ";", "self", "::", "reset_caches", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set whether this context has been locked or not. @param bool $locked @return $this
[ "Set", "whether", "this", "context", "has", "been", "locked", "or", "not", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5247-L5260
218,614
moodle/moodle
lib/accesslib.php
context.reset_paths
public function reset_paths($rebuild = true) { global $DB; if ($this->_path) { $this->mark_dirty(); } $DB->set_field_select('context', 'depth', 0, "path LIKE '%/$this->_id/%'"); $DB->set_field_select('context', 'path', NULL, "path LIKE '%/$this->_id/%'"); if ($this->_contextlevel != CONTEXT_SYSTEM) { $DB->set_field('context', 'depth', 0, array('id'=>$this->_id)); $DB->set_field('context', 'path', NULL, array('id'=>$this->_id)); $this->_depth = 0; $this->_path = null; } if ($rebuild) { context_helper::build_all_paths(false); } context::reset_caches(); }
php
public function reset_paths($rebuild = true) { global $DB; if ($this->_path) { $this->mark_dirty(); } $DB->set_field_select('context', 'depth', 0, "path LIKE '%/$this->_id/%'"); $DB->set_field_select('context', 'path', NULL, "path LIKE '%/$this->_id/%'"); if ($this->_contextlevel != CONTEXT_SYSTEM) { $DB->set_field('context', 'depth', 0, array('id'=>$this->_id)); $DB->set_field('context', 'path', NULL, array('id'=>$this->_id)); $this->_depth = 0; $this->_path = null; } if ($rebuild) { context_helper::build_all_paths(false); } context::reset_caches(); }
[ "public", "function", "reset_paths", "(", "$", "rebuild", "=", "true", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "_path", ")", "{", "$", "this", "->", "mark_dirty", "(", ")", ";", "}", "$", "DB", "->", "set_field_select", "(", "'context'", ",", "'depth'", ",", "0", ",", "\"path LIKE '%/$this->_id/%'\"", ")", ";", "$", "DB", "->", "set_field_select", "(", "'context'", ",", "'path'", ",", "NULL", ",", "\"path LIKE '%/$this->_id/%'\"", ")", ";", "if", "(", "$", "this", "->", "_contextlevel", "!=", "CONTEXT_SYSTEM", ")", "{", "$", "DB", "->", "set_field", "(", "'context'", ",", "'depth'", ",", "0", ",", "array", "(", "'id'", "=>", "$", "this", "->", "_id", ")", ")", ";", "$", "DB", "->", "set_field", "(", "'context'", ",", "'path'", ",", "NULL", ",", "array", "(", "'id'", "=>", "$", "this", "->", "_id", ")", ")", ";", "$", "this", "->", "_depth", "=", "0", ";", "$", "this", "->", "_path", "=", "null", ";", "}", "if", "(", "$", "rebuild", ")", "{", "context_helper", "::", "build_all_paths", "(", "false", ")", ";", "}", "context", "::", "reset_caches", "(", ")", ";", "}" ]
Remove all context path info and optionally rebuild it. @param bool $rebuild @return void
[ "Remove", "all", "context", "path", "info", "and", "optionally", "rebuild", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5268-L5288
218,615
moodle/moodle
lib/accesslib.php
context.delete_content
public function delete_content() { global $CFG, $DB; blocks_delete_all_for_context($this->_id); filter_delete_all_for_context($this->_id); require_once($CFG->dirroot . '/comment/lib.php'); comment::delete_comments(array('contextid'=>$this->_id)); require_once($CFG->dirroot.'/rating/lib.php'); $delopt = new stdclass(); $delopt->contextid = $this->_id; $rm = new rating_manager(); $rm->delete_ratings($delopt); // delete all files attached to this context $fs = get_file_storage(); $fs->delete_area_files($this->_id); // Delete all repository instances attached to this context. require_once($CFG->dirroot . '/repository/lib.php'); repository::delete_all_for_context($this->_id); // delete all advanced grading data attached to this context require_once($CFG->dirroot.'/grade/grading/lib.php'); grading_manager::delete_all_for_context($this->_id); // now delete stuff from role related tables, role_unassign_all // and unenrol should be called earlier to do proper cleanup $DB->delete_records('role_assignments', array('contextid'=>$this->_id)); $DB->delete_records('role_names', array('contextid'=>$this->_id)); $this->delete_capabilities(); }
php
public function delete_content() { global $CFG, $DB; blocks_delete_all_for_context($this->_id); filter_delete_all_for_context($this->_id); require_once($CFG->dirroot . '/comment/lib.php'); comment::delete_comments(array('contextid'=>$this->_id)); require_once($CFG->dirroot.'/rating/lib.php'); $delopt = new stdclass(); $delopt->contextid = $this->_id; $rm = new rating_manager(); $rm->delete_ratings($delopt); // delete all files attached to this context $fs = get_file_storage(); $fs->delete_area_files($this->_id); // Delete all repository instances attached to this context. require_once($CFG->dirroot . '/repository/lib.php'); repository::delete_all_for_context($this->_id); // delete all advanced grading data attached to this context require_once($CFG->dirroot.'/grade/grading/lib.php'); grading_manager::delete_all_for_context($this->_id); // now delete stuff from role related tables, role_unassign_all // and unenrol should be called earlier to do proper cleanup $DB->delete_records('role_assignments', array('contextid'=>$this->_id)); $DB->delete_records('role_names', array('contextid'=>$this->_id)); $this->delete_capabilities(); }
[ "public", "function", "delete_content", "(", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "blocks_delete_all_for_context", "(", "$", "this", "->", "_id", ")", ";", "filter_delete_all_for_context", "(", "$", "this", "->", "_id", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/comment/lib.php'", ")", ";", "comment", "::", "delete_comments", "(", "array", "(", "'contextid'", "=>", "$", "this", "->", "_id", ")", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/rating/lib.php'", ")", ";", "$", "delopt", "=", "new", "stdclass", "(", ")", ";", "$", "delopt", "->", "contextid", "=", "$", "this", "->", "_id", ";", "$", "rm", "=", "new", "rating_manager", "(", ")", ";", "$", "rm", "->", "delete_ratings", "(", "$", "delopt", ")", ";", "// delete all files attached to this context", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "fs", "->", "delete_area_files", "(", "$", "this", "->", "_id", ")", ";", "// Delete all repository instances attached to this context.", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/repository/lib.php'", ")", ";", "repository", "::", "delete_all_for_context", "(", "$", "this", "->", "_id", ")", ";", "// delete all advanced grading data attached to this context", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/grade/grading/lib.php'", ")", ";", "grading_manager", "::", "delete_all_for_context", "(", "$", "this", "->", "_id", ")", ";", "// now delete stuff from role related tables, role_unassign_all", "// and unenrol should be called earlier to do proper cleanup", "$", "DB", "->", "delete_records", "(", "'role_assignments'", ",", "array", "(", "'contextid'", "=>", "$", "this", "->", "_id", ")", ")", ";", "$", "DB", "->", "delete_records", "(", "'role_names'", ",", "array", "(", "'contextid'", "=>", "$", "this", "->", "_id", ")", ")", ";", "$", "this", "->", "delete_capabilities", "(", ")", ";", "}" ]
Delete all data linked to content, do not delete the context record itself
[ "Delete", "all", "data", "linked", "to", "content", "do", "not", "delete", "the", "context", "record", "itself" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5293-L5325
218,616
moodle/moodle
lib/accesslib.php
context.delete_capabilities
public function delete_capabilities() { global $DB; $ids = $DB->get_fieldset_select('role_capabilities', 'DISTINCT roleid', 'contextid = ?', array($this->_id)); if ($ids) { $DB->delete_records('role_capabilities', array('contextid' => $this->_id)); // Reset any cache of these roles, including MUC. accesslib_clear_role_cache($ids); } }
php
public function delete_capabilities() { global $DB; $ids = $DB->get_fieldset_select('role_capabilities', 'DISTINCT roleid', 'contextid = ?', array($this->_id)); if ($ids) { $DB->delete_records('role_capabilities', array('contextid' => $this->_id)); // Reset any cache of these roles, including MUC. accesslib_clear_role_cache($ids); } }
[ "public", "function", "delete_capabilities", "(", ")", "{", "global", "$", "DB", ";", "$", "ids", "=", "$", "DB", "->", "get_fieldset_select", "(", "'role_capabilities'", ",", "'DISTINCT roleid'", ",", "'contextid = ?'", ",", "array", "(", "$", "this", "->", "_id", ")", ")", ";", "if", "(", "$", "ids", ")", "{", "$", "DB", "->", "delete_records", "(", "'role_capabilities'", ",", "array", "(", "'contextid'", "=>", "$", "this", "->", "_id", ")", ")", ";", "// Reset any cache of these roles, including MUC.", "accesslib_clear_role_cache", "(", "$", "ids", ")", ";", "}", "}" ]
Unassign all capabilities from a context.
[ "Unassign", "all", "capabilities", "from", "a", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5330-L5340
218,617
moodle/moodle
lib/accesslib.php
context.delete
public function delete() { global $DB; if ($this->_contextlevel <= CONTEXT_SYSTEM) { throw new coding_exception('Cannot delete system context'); } // double check the context still exists if (!$DB->record_exists('context', array('id'=>$this->_id))) { context::cache_remove($this); return; } $this->delete_content(); $DB->delete_records('context', array('id'=>$this->_id)); // purge static context cache if entry present context::cache_remove($this); }
php
public function delete() { global $DB; if ($this->_contextlevel <= CONTEXT_SYSTEM) { throw new coding_exception('Cannot delete system context'); } // double check the context still exists if (!$DB->record_exists('context', array('id'=>$this->_id))) { context::cache_remove($this); return; } $this->delete_content(); $DB->delete_records('context', array('id'=>$this->_id)); // purge static context cache if entry present context::cache_remove($this); }
[ "public", "function", "delete", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "_contextlevel", "<=", "CONTEXT_SYSTEM", ")", "{", "throw", "new", "coding_exception", "(", "'Cannot delete system context'", ")", ";", "}", "// double check the context still exists", "if", "(", "!", "$", "DB", "->", "record_exists", "(", "'context'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "_id", ")", ")", ")", "{", "context", "::", "cache_remove", "(", "$", "this", ")", ";", "return", ";", "}", "$", "this", "->", "delete_content", "(", ")", ";", "$", "DB", "->", "delete_records", "(", "'context'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "_id", ")", ")", ";", "// purge static context cache if entry present", "context", "::", "cache_remove", "(", "$", "this", ")", ";", "}" ]
Delete the context content and the context record itself
[ "Delete", "the", "context", "content", "and", "the", "context", "record", "itself" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5345-L5362
218,618
moodle/moodle
lib/accesslib.php
context.insert_context_record
protected static function insert_context_record($contextlevel, $instanceid, $parentpath) { global $DB; $record = new stdClass(); $record->contextlevel = $contextlevel; $record->instanceid = $instanceid; $record->depth = 0; $record->path = null; //not known before insert $record->locked = 0; $record->id = $DB->insert_record('context', $record); // now add path if known - it can be added later if (!is_null($parentpath)) { $record->path = $parentpath.'/'.$record->id; $record->depth = substr_count($record->path, '/'); $DB->update_record('context', $record); } return $record; }
php
protected static function insert_context_record($contextlevel, $instanceid, $parentpath) { global $DB; $record = new stdClass(); $record->contextlevel = $contextlevel; $record->instanceid = $instanceid; $record->depth = 0; $record->path = null; //not known before insert $record->locked = 0; $record->id = $DB->insert_record('context', $record); // now add path if known - it can be added later if (!is_null($parentpath)) { $record->path = $parentpath.'/'.$record->id; $record->depth = substr_count($record->path, '/'); $DB->update_record('context', $record); } return $record; }
[ "protected", "static", "function", "insert_context_record", "(", "$", "contextlevel", ",", "$", "instanceid", ",", "$", "parentpath", ")", "{", "global", "$", "DB", ";", "$", "record", "=", "new", "stdClass", "(", ")", ";", "$", "record", "->", "contextlevel", "=", "$", "contextlevel", ";", "$", "record", "->", "instanceid", "=", "$", "instanceid", ";", "$", "record", "->", "depth", "=", "0", ";", "$", "record", "->", "path", "=", "null", ";", "//not known before insert", "$", "record", "->", "locked", "=", "0", ";", "$", "record", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'context'", ",", "$", "record", ")", ";", "// now add path if known - it can be added later", "if", "(", "!", "is_null", "(", "$", "parentpath", ")", ")", "{", "$", "record", "->", "path", "=", "$", "parentpath", ".", "'/'", ".", "$", "record", "->", "id", ";", "$", "record", "->", "depth", "=", "substr_count", "(", "$", "record", "->", "path", ",", "'/'", ")", ";", "$", "DB", "->", "update_record", "(", "'context'", ",", "$", "record", ")", ";", "}", "return", "$", "record", ";", "}" ]
Utility method for context creation @static @param int $contextlevel @param int $instanceid @param string $parentpath @return stdClass context record
[ "Utility", "method", "for", "context", "creation" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5375-L5395
218,619
moodle/moodle
lib/accesslib.php
context.is_locked
public function is_locked() { if ($this->_locked) { return true; } if ($parent = $this->get_parent_context()) { return $parent->is_locked(); } return false; }
php
public function is_locked() { if ($this->_locked) { return true; } if ($parent = $this->get_parent_context()) { return $parent->is_locked(); } return false; }
[ "public", "function", "is_locked", "(", ")", "{", "if", "(", "$", "this", "->", "_locked", ")", "{", "return", "true", ";", "}", "if", "(", "$", "parent", "=", "$", "this", "->", "get_parent_context", "(", ")", ")", "{", "return", "$", "parent", "->", "is_locked", "(", ")", ";", "}", "return", "false", ";", "}" ]
Whether the current context is locked. @return bool
[ "Whether", "the", "current", "context", "is", "locked", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5416-L5426
218,620
moodle/moodle
lib/accesslib.php
context.get_parent_contexts
public function get_parent_contexts($includeself = false) { if (!$contextids = $this->get_parent_context_ids($includeself)) { return array(); } // Preload the contexts to reduce DB calls. context_helper::preload_contexts_by_id($contextids); $result = array(); foreach ($contextids as $contextid) { $parent = context::instance_by_id($contextid, MUST_EXIST); $result[$parent->id] = $parent; } return $result; }
php
public function get_parent_contexts($includeself = false) { if (!$contextids = $this->get_parent_context_ids($includeself)) { return array(); } // Preload the contexts to reduce DB calls. context_helper::preload_contexts_by_id($contextids); $result = array(); foreach ($contextids as $contextid) { $parent = context::instance_by_id($contextid, MUST_EXIST); $result[$parent->id] = $parent; } return $result; }
[ "public", "function", "get_parent_contexts", "(", "$", "includeself", "=", "false", ")", "{", "if", "(", "!", "$", "contextids", "=", "$", "this", "->", "get_parent_context_ids", "(", "$", "includeself", ")", ")", "{", "return", "array", "(", ")", ";", "}", "// Preload the contexts to reduce DB calls.", "context_helper", "::", "preload_contexts_by_id", "(", "$", "contextids", ")", ";", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "contextids", "as", "$", "contextid", ")", "{", "$", "parent", "=", "context", "::", "instance_by_id", "(", "$", "contextid", ",", "MUST_EXIST", ")", ";", "$", "result", "[", "$", "parent", "->", "id", "]", "=", "$", "parent", ";", "}", "return", "$", "result", ";", "}" ]
Returns parent contexts of this context in reversed order, i.e. parent first, then grand parent, etc. @param bool $includeself true means include self too @return array of context instances
[ "Returns", "parent", "contexts", "of", "this", "context", "in", "reversed", "order", "i", ".", "e", ".", "parent", "first", "then", "grand", "parent", "etc", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5486-L5501
218,621
moodle/moodle
lib/accesslib.php
context.get_parent_context_ids
public function get_parent_context_ids($includeself = false) { if (empty($this->_path)) { return array(); } $parentcontexts = trim($this->_path, '/'); // kill leading slash $parentcontexts = explode('/', $parentcontexts); if (!$includeself) { array_pop($parentcontexts); // and remove its own id } return array_reverse($parentcontexts); }
php
public function get_parent_context_ids($includeself = false) { if (empty($this->_path)) { return array(); } $parentcontexts = trim($this->_path, '/'); // kill leading slash $parentcontexts = explode('/', $parentcontexts); if (!$includeself) { array_pop($parentcontexts); // and remove its own id } return array_reverse($parentcontexts); }
[ "public", "function", "get_parent_context_ids", "(", "$", "includeself", "=", "false", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_path", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "parentcontexts", "=", "trim", "(", "$", "this", "->", "_path", ",", "'/'", ")", ";", "// kill leading slash", "$", "parentcontexts", "=", "explode", "(", "'/'", ",", "$", "parentcontexts", ")", ";", "if", "(", "!", "$", "includeself", ")", "{", "array_pop", "(", "$", "parentcontexts", ")", ";", "// and remove its own id", "}", "return", "array_reverse", "(", "$", "parentcontexts", ")", ";", "}" ]
Returns parent context ids of this context in reversed order, i.e. parent first, then grand parent, etc. @param bool $includeself true means include self too @return array of context ids
[ "Returns", "parent", "context", "ids", "of", "this", "context", "in", "reversed", "order", "i", ".", "e", ".", "parent", "first", "then", "grand", "parent", "etc", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5510-L5522
218,622
moodle/moodle
lib/accesslib.php
context.get_parent_context_paths
public function get_parent_context_paths($includeself = false) { if (empty($this->_path)) { return array(); } $contextids = explode('/', $this->_path); $path = ''; $paths = array(); foreach ($contextids as $contextid) { if ($contextid) { $path .= '/' . $contextid; $paths[$contextid] = $path; } } if (!$includeself) { unset($paths[$this->_id]); } return $paths; }
php
public function get_parent_context_paths($includeself = false) { if (empty($this->_path)) { return array(); } $contextids = explode('/', $this->_path); $path = ''; $paths = array(); foreach ($contextids as $contextid) { if ($contextid) { $path .= '/' . $contextid; $paths[$contextid] = $path; } } if (!$includeself) { unset($paths[$this->_id]); } return $paths; }
[ "public", "function", "get_parent_context_paths", "(", "$", "includeself", "=", "false", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_path", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "contextids", "=", "explode", "(", "'/'", ",", "$", "this", "->", "_path", ")", ";", "$", "path", "=", "''", ";", "$", "paths", "=", "array", "(", ")", ";", "foreach", "(", "$", "contextids", "as", "$", "contextid", ")", "{", "if", "(", "$", "contextid", ")", "{", "$", "path", ".=", "'/'", ".", "$", "contextid", ";", "$", "paths", "[", "$", "contextid", "]", "=", "$", "path", ";", "}", "}", "if", "(", "!", "$", "includeself", ")", "{", "unset", "(", "$", "paths", "[", "$", "this", "->", "_id", "]", ")", ";", "}", "return", "$", "paths", ";", "}" ]
Returns parent context paths of this context. @param bool $includeself true means include self too @return array of context paths
[ "Returns", "parent", "context", "paths", "of", "this", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5530-L5551
218,623
moodle/moodle
lib/accesslib.php
context.get_parent_context
public function get_parent_context() { if (empty($this->_path) or $this->_id == SYSCONTEXTID) { return false; } $parentcontexts = trim($this->_path, '/'); // kill leading slash $parentcontexts = explode('/', $parentcontexts); array_pop($parentcontexts); // self $contextid = array_pop($parentcontexts); // immediate parent return context::instance_by_id($contextid, MUST_EXIST); }
php
public function get_parent_context() { if (empty($this->_path) or $this->_id == SYSCONTEXTID) { return false; } $parentcontexts = trim($this->_path, '/'); // kill leading slash $parentcontexts = explode('/', $parentcontexts); array_pop($parentcontexts); // self $contextid = array_pop($parentcontexts); // immediate parent return context::instance_by_id($contextid, MUST_EXIST); }
[ "public", "function", "get_parent_context", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_path", ")", "or", "$", "this", "->", "_id", "==", "SYSCONTEXTID", ")", "{", "return", "false", ";", "}", "$", "parentcontexts", "=", "trim", "(", "$", "this", "->", "_path", ",", "'/'", ")", ";", "// kill leading slash", "$", "parentcontexts", "=", "explode", "(", "'/'", ",", "$", "parentcontexts", ")", ";", "array_pop", "(", "$", "parentcontexts", ")", ";", "// self", "$", "contextid", "=", "array_pop", "(", "$", "parentcontexts", ")", ";", "// immediate parent", "return", "context", "::", "instance_by_id", "(", "$", "contextid", ",", "MUST_EXIST", ")", ";", "}" ]
Returns parent context @return context
[ "Returns", "parent", "context" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5558-L5569
218,624
moodle/moodle
lib/accesslib.php
context.reload_if_dirty
public function reload_if_dirty() { global $ACCESSLIB_PRIVATE, $USER; // Load dirty contexts list if needed if (CLI_SCRIPT) { if (!isset($ACCESSLIB_PRIVATE->dirtycontexts)) { // we do not load dirty flags in CLI and cron $ACCESSLIB_PRIVATE->dirtycontexts = array(); } } else { if (!isset($USER->access['time'])) { // Nothing has been loaded yet, so we do not need to check dirty flags now. return; } // From skodak: No idea why -2 is there, server cluster time difference maybe... $changedsince = $USER->access['time'] - 2; if (!isset($ACCESSLIB_PRIVATE->dirtycontexts)) { $ACCESSLIB_PRIVATE->dirtycontexts = get_cache_flags('accesslib/dirtycontexts', $changedsince); } if (!isset($ACCESSLIB_PRIVATE->dirtyusers[$USER->id])) { $ACCESSLIB_PRIVATE->dirtyusers[$USER->id] = get_cache_flag('accesslib/dirtyusers', $USER->id, $changedsince); } } $dirty = false; if (!empty($ACCESSLIB_PRIVATE->dirtyusers[$USER->id])) { $dirty = true; } else if (!empty($ACCESSLIB_PRIVATE->dirtycontexts)) { $paths = $this->get_parent_context_paths(true); foreach ($paths as $path) { if (isset($ACCESSLIB_PRIVATE->dirtycontexts[$path])) { $dirty = true; break; } } } if ($dirty) { // Reload all capabilities of USER and others - preserving loginas, roleswitches, etc. // Then cleanup any marks of dirtyness... at least from our short term memory! reload_all_capabilities(); } }
php
public function reload_if_dirty() { global $ACCESSLIB_PRIVATE, $USER; // Load dirty contexts list if needed if (CLI_SCRIPT) { if (!isset($ACCESSLIB_PRIVATE->dirtycontexts)) { // we do not load dirty flags in CLI and cron $ACCESSLIB_PRIVATE->dirtycontexts = array(); } } else { if (!isset($USER->access['time'])) { // Nothing has been loaded yet, so we do not need to check dirty flags now. return; } // From skodak: No idea why -2 is there, server cluster time difference maybe... $changedsince = $USER->access['time'] - 2; if (!isset($ACCESSLIB_PRIVATE->dirtycontexts)) { $ACCESSLIB_PRIVATE->dirtycontexts = get_cache_flags('accesslib/dirtycontexts', $changedsince); } if (!isset($ACCESSLIB_PRIVATE->dirtyusers[$USER->id])) { $ACCESSLIB_PRIVATE->dirtyusers[$USER->id] = get_cache_flag('accesslib/dirtyusers', $USER->id, $changedsince); } } $dirty = false; if (!empty($ACCESSLIB_PRIVATE->dirtyusers[$USER->id])) { $dirty = true; } else if (!empty($ACCESSLIB_PRIVATE->dirtycontexts)) { $paths = $this->get_parent_context_paths(true); foreach ($paths as $path) { if (isset($ACCESSLIB_PRIVATE->dirtycontexts[$path])) { $dirty = true; break; } } } if ($dirty) { // Reload all capabilities of USER and others - preserving loginas, roleswitches, etc. // Then cleanup any marks of dirtyness... at least from our short term memory! reload_all_capabilities(); } }
[ "public", "function", "reload_if_dirty", "(", ")", "{", "global", "$", "ACCESSLIB_PRIVATE", ",", "$", "USER", ";", "// Load dirty contexts list if needed", "if", "(", "CLI_SCRIPT", ")", "{", "if", "(", "!", "isset", "(", "$", "ACCESSLIB_PRIVATE", "->", "dirtycontexts", ")", ")", "{", "// we do not load dirty flags in CLI and cron", "$", "ACCESSLIB_PRIVATE", "->", "dirtycontexts", "=", "array", "(", ")", ";", "}", "}", "else", "{", "if", "(", "!", "isset", "(", "$", "USER", "->", "access", "[", "'time'", "]", ")", ")", "{", "// Nothing has been loaded yet, so we do not need to check dirty flags now.", "return", ";", "}", "// From skodak: No idea why -2 is there, server cluster time difference maybe...", "$", "changedsince", "=", "$", "USER", "->", "access", "[", "'time'", "]", "-", "2", ";", "if", "(", "!", "isset", "(", "$", "ACCESSLIB_PRIVATE", "->", "dirtycontexts", ")", ")", "{", "$", "ACCESSLIB_PRIVATE", "->", "dirtycontexts", "=", "get_cache_flags", "(", "'accesslib/dirtycontexts'", ",", "$", "changedsince", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "ACCESSLIB_PRIVATE", "->", "dirtyusers", "[", "$", "USER", "->", "id", "]", ")", ")", "{", "$", "ACCESSLIB_PRIVATE", "->", "dirtyusers", "[", "$", "USER", "->", "id", "]", "=", "get_cache_flag", "(", "'accesslib/dirtyusers'", ",", "$", "USER", "->", "id", ",", "$", "changedsince", ")", ";", "}", "}", "$", "dirty", "=", "false", ";", "if", "(", "!", "empty", "(", "$", "ACCESSLIB_PRIVATE", "->", "dirtyusers", "[", "$", "USER", "->", "id", "]", ")", ")", "{", "$", "dirty", "=", "true", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "ACCESSLIB_PRIVATE", "->", "dirtycontexts", ")", ")", "{", "$", "paths", "=", "$", "this", "->", "get_parent_context_paths", "(", "true", ")", ";", "foreach", "(", "$", "paths", "as", "$", "path", ")", "{", "if", "(", "isset", "(", "$", "ACCESSLIB_PRIVATE", "->", "dirtycontexts", "[", "$", "path", "]", ")", ")", "{", "$", "dirty", "=", "true", ";", "break", ";", "}", "}", "}", "if", "(", "$", "dirty", ")", "{", "// Reload all capabilities of USER and others - preserving loginas, roleswitches, etc.", "// Then cleanup any marks of dirtyness... at least from our short term memory!", "reload_all_capabilities", "(", ")", ";", "}", "}" ]
Reset all cached permissions and definitions if the necessary. @return void
[ "Reset", "all", "cached", "permissions", "and", "definitions", "if", "the", "necessary", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5620-L5667
218,625
moodle/moodle
lib/accesslib.php
context_helper.get_class_for_level
public static function get_class_for_level($contextlevel) { self::init_levels(); if (isset(self::$alllevels[$contextlevel])) { return self::$alllevels[$contextlevel]; } else { throw new coding_exception('Invalid context level specified'); } }
php
public static function get_class_for_level($contextlevel) { self::init_levels(); if (isset(self::$alllevels[$contextlevel])) { return self::$alllevels[$contextlevel]; } else { throw new coding_exception('Invalid context level specified'); } }
[ "public", "static", "function", "get_class_for_level", "(", "$", "contextlevel", ")", "{", "self", "::", "init_levels", "(", ")", ";", "if", "(", "isset", "(", "self", "::", "$", "alllevels", "[", "$", "contextlevel", "]", ")", ")", "{", "return", "self", "::", "$", "alllevels", "[", "$", "contextlevel", "]", ";", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Invalid context level specified'", ")", ";", "}", "}" ]
Returns a class name of the context level class @static @param int $contextlevel (CONTEXT_SYSTEM, etc.) @return string class name of the context class
[ "Returns", "a", "class", "name", "of", "the", "context", "level", "class" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5781-L5788
218,626
moodle/moodle
lib/accesslib.php
context_helper.cleanup_instances
public static function cleanup_instances() { global $DB; self::init_levels(); $sqls = array(); foreach (self::$alllevels as $level=>$classname) { $sqls[] = $classname::get_cleanup_sql(); } $sql = implode(" UNION ", $sqls); // it is probably better to use transactions, it might be faster too $transaction = $DB->start_delegated_transaction(); $rs = $DB->get_recordset_sql($sql); foreach ($rs as $record) { $context = context::create_instance_from_record($record); $context->delete(); } $rs->close(); $transaction->allow_commit(); }
php
public static function cleanup_instances() { global $DB; self::init_levels(); $sqls = array(); foreach (self::$alllevels as $level=>$classname) { $sqls[] = $classname::get_cleanup_sql(); } $sql = implode(" UNION ", $sqls); // it is probably better to use transactions, it might be faster too $transaction = $DB->start_delegated_transaction(); $rs = $DB->get_recordset_sql($sql); foreach ($rs as $record) { $context = context::create_instance_from_record($record); $context->delete(); } $rs->close(); $transaction->allow_commit(); }
[ "public", "static", "function", "cleanup_instances", "(", ")", "{", "global", "$", "DB", ";", "self", "::", "init_levels", "(", ")", ";", "$", "sqls", "=", "array", "(", ")", ";", "foreach", "(", "self", "::", "$", "alllevels", "as", "$", "level", "=>", "$", "classname", ")", "{", "$", "sqls", "[", "]", "=", "$", "classname", "::", "get_cleanup_sql", "(", ")", ";", "}", "$", "sql", "=", "implode", "(", "\" UNION \"", ",", "$", "sqls", ")", ";", "// it is probably better to use transactions, it might be faster too", "$", "transaction", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "$", "rs", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ")", ";", "foreach", "(", "$", "rs", "as", "$", "record", ")", "{", "$", "context", "=", "context", "::", "create_instance_from_record", "(", "$", "record", ")", ";", "$", "context", "->", "delete", "(", ")", ";", "}", "$", "rs", "->", "close", "(", ")", ";", "$", "transaction", "->", "allow_commit", "(", ")", ";", "}" ]
Remove stale contexts that belonged to deleted instances. Ideally all code should cleanup contexts properly, unfortunately accidents happen... @static @return void
[ "Remove", "stale", "contexts", "that", "belonged", "to", "deleted", "instances", ".", "Ideally", "all", "code", "should", "cleanup", "contexts", "properly", "unfortunately", "accidents", "happen", "..." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5808-L5830
218,627
moodle/moodle
lib/accesslib.php
context_helper.create_instances
public static function create_instances($contextlevel = null, $buildpaths = true) { self::init_levels(); foreach (self::$alllevels as $level=>$classname) { if ($contextlevel and $level > $contextlevel) { // skip potential sub-contexts continue; } $classname::create_level_instances(); if ($buildpaths) { $classname::build_paths(false); } } }
php
public static function create_instances($contextlevel = null, $buildpaths = true) { self::init_levels(); foreach (self::$alllevels as $level=>$classname) { if ($contextlevel and $level > $contextlevel) { // skip potential sub-contexts continue; } $classname::create_level_instances(); if ($buildpaths) { $classname::build_paths(false); } } }
[ "public", "static", "function", "create_instances", "(", "$", "contextlevel", "=", "null", ",", "$", "buildpaths", "=", "true", ")", "{", "self", "::", "init_levels", "(", ")", ";", "foreach", "(", "self", "::", "$", "alllevels", "as", "$", "level", "=>", "$", "classname", ")", "{", "if", "(", "$", "contextlevel", "and", "$", "level", ">", "$", "contextlevel", ")", "{", "// skip potential sub-contexts", "continue", ";", "}", "$", "classname", "::", "create_level_instances", "(", ")", ";", "if", "(", "$", "buildpaths", ")", "{", "$", "classname", "::", "build_paths", "(", "false", ")", ";", "}", "}", "}" ]
Create all context instances at the given level and above. @static @param int $contextlevel null means all levels @param bool $buildpaths @return void
[ "Create", "all", "context", "instances", "at", "the", "given", "level", "and", "above", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5840-L5852
218,628
moodle/moodle
lib/accesslib.php
context_helper.build_all_paths
public static function build_all_paths($force = false) { self::init_levels(); foreach (self::$alllevels as $classname) { $classname::build_paths($force); } // reset static course cache - it might have incorrect cached data accesslib_clear_all_caches(true); }
php
public static function build_all_paths($force = false) { self::init_levels(); foreach (self::$alllevels as $classname) { $classname::build_paths($force); } // reset static course cache - it might have incorrect cached data accesslib_clear_all_caches(true); }
[ "public", "static", "function", "build_all_paths", "(", "$", "force", "=", "false", ")", "{", "self", "::", "init_levels", "(", ")", ";", "foreach", "(", "self", "::", "$", "alllevels", "as", "$", "classname", ")", "{", "$", "classname", "::", "build_paths", "(", "$", "force", ")", ";", "}", "// reset static course cache - it might have incorrect cached data", "accesslib_clear_all_caches", "(", "true", ")", ";", "}" ]
Rebuild paths and depths in all context levels. @static @param bool $force false means add missing only @return void
[ "Rebuild", "paths", "and", "depths", "in", "all", "context", "levels", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5861-L5869
218,629
moodle/moodle
lib/accesslib.php
context_helper.preload_contexts_by_id
public static function preload_contexts_by_id(array $contextids) { global $DB; // Determine which contexts are not already cached. $tofetch = []; foreach ($contextids as $contextid) { if (!self::cache_get_by_id($contextid)) { $tofetch[] = $contextid; } } if (count($tofetch) > 1) { // There are at least two to fetch. // There is no point only fetching a single context as this would be no more efficient than calling the existing code. list($insql, $inparams) = $DB->get_in_or_equal($tofetch, SQL_PARAMS_NAMED); $ctxs = $DB->get_records_select('context', "id {$insql}", $inparams, '', \context_helper::get_preload_record_columns_sql('{context}')); foreach ($ctxs as $ctx) { self::preload_from_record($ctx); } } }
php
public static function preload_contexts_by_id(array $contextids) { global $DB; // Determine which contexts are not already cached. $tofetch = []; foreach ($contextids as $contextid) { if (!self::cache_get_by_id($contextid)) { $tofetch[] = $contextid; } } if (count($tofetch) > 1) { // There are at least two to fetch. // There is no point only fetching a single context as this would be no more efficient than calling the existing code. list($insql, $inparams) = $DB->get_in_or_equal($tofetch, SQL_PARAMS_NAMED); $ctxs = $DB->get_records_select('context', "id {$insql}", $inparams, '', \context_helper::get_preload_record_columns_sql('{context}')); foreach ($ctxs as $ctx) { self::preload_from_record($ctx); } } }
[ "public", "static", "function", "preload_contexts_by_id", "(", "array", "$", "contextids", ")", "{", "global", "$", "DB", ";", "// Determine which contexts are not already cached.", "$", "tofetch", "=", "[", "]", ";", "foreach", "(", "$", "contextids", "as", "$", "contextid", ")", "{", "if", "(", "!", "self", "::", "cache_get_by_id", "(", "$", "contextid", ")", ")", "{", "$", "tofetch", "[", "]", "=", "$", "contextid", ";", "}", "}", "if", "(", "count", "(", "$", "tofetch", ")", ">", "1", ")", "{", "// There are at least two to fetch.", "// There is no point only fetching a single context as this would be no more efficient than calling the existing code.", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "tofetch", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "ctxs", "=", "$", "DB", "->", "get_records_select", "(", "'context'", ",", "\"id {$insql}\"", ",", "$", "inparams", ",", "''", ",", "\\", "context_helper", "::", "get_preload_record_columns_sql", "(", "'{context}'", ")", ")", ";", "foreach", "(", "$", "ctxs", "as", "$", "ctx", ")", "{", "self", "::", "preload_from_record", "(", "$", "ctx", ")", ";", "}", "}", "}" ]
Preload a set of contexts using their contextid. @param array $contextids
[ "Preload", "a", "set", "of", "contexts", "using", "their", "contextid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5935-L5956
218,630
moodle/moodle
lib/accesslib.php
context_helper.preload_course
public static function preload_course($courseid) { // Users can call this multiple times without doing any harm if (isset(context::$cache_preloaded[$courseid])) { return; } $coursecontext = context_course::instance($courseid); $coursecontext->get_child_contexts(); context::$cache_preloaded[$courseid] = true; }
php
public static function preload_course($courseid) { // Users can call this multiple times without doing any harm if (isset(context::$cache_preloaded[$courseid])) { return; } $coursecontext = context_course::instance($courseid); $coursecontext->get_child_contexts(); context::$cache_preloaded[$courseid] = true; }
[ "public", "static", "function", "preload_course", "(", "$", "courseid", ")", "{", "// Users can call this multiple times without doing any harm", "if", "(", "isset", "(", "context", "::", "$", "cache_preloaded", "[", "$", "courseid", "]", ")", ")", "{", "return", ";", "}", "$", "coursecontext", "=", "context_course", "::", "instance", "(", "$", "courseid", ")", ";", "$", "coursecontext", "->", "get_child_contexts", "(", ")", ";", "context", "::", "$", "cache_preloaded", "[", "$", "courseid", "]", "=", "true", ";", "}" ]
Preload all contexts instances from course. To be used if you expect multiple queries for course activities... @static @param int $courseid
[ "Preload", "all", "contexts", "instances", "from", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5966-L5975
218,631
moodle/moodle
lib/accesslib.php
context_helper.delete_instance
public static function delete_instance($contextlevel, $instanceid) { global $DB; // double check the context still exists if ($record = $DB->get_record('context', array('contextlevel'=>$contextlevel, 'instanceid'=>$instanceid))) { $context = context::create_instance_from_record($record); $context->delete(); } else { // we should try to purge the cache anyway } }
php
public static function delete_instance($contextlevel, $instanceid) { global $DB; // double check the context still exists if ($record = $DB->get_record('context', array('contextlevel'=>$contextlevel, 'instanceid'=>$instanceid))) { $context = context::create_instance_from_record($record); $context->delete(); } else { // we should try to purge the cache anyway } }
[ "public", "static", "function", "delete_instance", "(", "$", "contextlevel", ",", "$", "instanceid", ")", "{", "global", "$", "DB", ";", "// double check the context still exists", "if", "(", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'context'", ",", "array", "(", "'contextlevel'", "=>", "$", "contextlevel", ",", "'instanceid'", "=>", "$", "instanceid", ")", ")", ")", "{", "$", "context", "=", "context", "::", "create_instance_from_record", "(", "$", "record", ")", ";", "$", "context", "->", "delete", "(", ")", ";", "}", "else", "{", "// we should try to purge the cache anyway", "}", "}" ]
Delete context instance @static @param int $contextlevel @param int $instanceid @return void
[ "Delete", "context", "instance" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L5985-L5995
218,632
moodle/moodle
lib/accesslib.php
context_system.instance
public static function instance($instanceid = 0, $strictness = MUST_EXIST, $cache = true) { global $DB; if ($instanceid != 0) { debugging('context_system::instance(): invalid $id parameter detected, should be 0'); } if (defined('SYSCONTEXTID') and $cache) { // dangerous: define this in config.php to eliminate 1 query/page if (!isset(context::$systemcontext)) { $record = new stdClass(); $record->id = SYSCONTEXTID; $record->contextlevel = CONTEXT_SYSTEM; $record->instanceid = 0; $record->path = '/'.SYSCONTEXTID; $record->depth = 1; $record->locked = 0; context::$systemcontext = new context_system($record); } return context::$systemcontext; } try { // We ignore the strictness completely because system context must exist except during install. $record = $DB->get_record('context', array('contextlevel'=>CONTEXT_SYSTEM), '*', MUST_EXIST); } catch (dml_exception $e) { //table or record does not exist if (!during_initial_install()) { // do not mess with system context after install, it simply must exist throw $e; } $record = null; } if (!$record) { $record = new stdClass(); $record->contextlevel = CONTEXT_SYSTEM; $record->instanceid = 0; $record->depth = 1; $record->path = null; // Not known before insert. $record->locked = 0; try { if ($DB->count_records('context')) { // contexts already exist, this is very weird, system must be first!!! return null; } if (defined('SYSCONTEXTID')) { // this would happen only in unittest on sites that went through weird 1.7 upgrade $record->id = SYSCONTEXTID; $DB->import_record('context', $record); $DB->get_manager()->reset_sequence('context'); } else { $record->id = $DB->insert_record('context', $record); } } catch (dml_exception $e) { // can not create context - table does not exist yet, sorry return null; } } if ($record->instanceid != 0) { // this is very weird, somebody must be messing with context table debugging('Invalid system context detected'); } if ($record->depth != 1 or $record->path != '/'.$record->id) { // fix path if necessary, initial install or path reset $record->depth = 1; $record->path = '/'.$record->id; $DB->update_record('context', $record); } if (empty($record->locked)) { $record->locked = 0; } if (!defined('SYSCONTEXTID')) { define('SYSCONTEXTID', $record->id); } context::$systemcontext = new context_system($record); return context::$systemcontext; }
php
public static function instance($instanceid = 0, $strictness = MUST_EXIST, $cache = true) { global $DB; if ($instanceid != 0) { debugging('context_system::instance(): invalid $id parameter detected, should be 0'); } if (defined('SYSCONTEXTID') and $cache) { // dangerous: define this in config.php to eliminate 1 query/page if (!isset(context::$systemcontext)) { $record = new stdClass(); $record->id = SYSCONTEXTID; $record->contextlevel = CONTEXT_SYSTEM; $record->instanceid = 0; $record->path = '/'.SYSCONTEXTID; $record->depth = 1; $record->locked = 0; context::$systemcontext = new context_system($record); } return context::$systemcontext; } try { // We ignore the strictness completely because system context must exist except during install. $record = $DB->get_record('context', array('contextlevel'=>CONTEXT_SYSTEM), '*', MUST_EXIST); } catch (dml_exception $e) { //table or record does not exist if (!during_initial_install()) { // do not mess with system context after install, it simply must exist throw $e; } $record = null; } if (!$record) { $record = new stdClass(); $record->contextlevel = CONTEXT_SYSTEM; $record->instanceid = 0; $record->depth = 1; $record->path = null; // Not known before insert. $record->locked = 0; try { if ($DB->count_records('context')) { // contexts already exist, this is very weird, system must be first!!! return null; } if (defined('SYSCONTEXTID')) { // this would happen only in unittest on sites that went through weird 1.7 upgrade $record->id = SYSCONTEXTID; $DB->import_record('context', $record); $DB->get_manager()->reset_sequence('context'); } else { $record->id = $DB->insert_record('context', $record); } } catch (dml_exception $e) { // can not create context - table does not exist yet, sorry return null; } } if ($record->instanceid != 0) { // this is very weird, somebody must be messing with context table debugging('Invalid system context detected'); } if ($record->depth != 1 or $record->path != '/'.$record->id) { // fix path if necessary, initial install or path reset $record->depth = 1; $record->path = '/'.$record->id; $DB->update_record('context', $record); } if (empty($record->locked)) { $record->locked = 0; } if (!defined('SYSCONTEXTID')) { define('SYSCONTEXTID', $record->id); } context::$systemcontext = new context_system($record); return context::$systemcontext; }
[ "public", "static", "function", "instance", "(", "$", "instanceid", "=", "0", ",", "$", "strictness", "=", "MUST_EXIST", ",", "$", "cache", "=", "true", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "instanceid", "!=", "0", ")", "{", "debugging", "(", "'context_system::instance(): invalid $id parameter detected, should be 0'", ")", ";", "}", "if", "(", "defined", "(", "'SYSCONTEXTID'", ")", "and", "$", "cache", ")", "{", "// dangerous: define this in config.php to eliminate 1 query/page", "if", "(", "!", "isset", "(", "context", "::", "$", "systemcontext", ")", ")", "{", "$", "record", "=", "new", "stdClass", "(", ")", ";", "$", "record", "->", "id", "=", "SYSCONTEXTID", ";", "$", "record", "->", "contextlevel", "=", "CONTEXT_SYSTEM", ";", "$", "record", "->", "instanceid", "=", "0", ";", "$", "record", "->", "path", "=", "'/'", ".", "SYSCONTEXTID", ";", "$", "record", "->", "depth", "=", "1", ";", "$", "record", "->", "locked", "=", "0", ";", "context", "::", "$", "systemcontext", "=", "new", "context_system", "(", "$", "record", ")", ";", "}", "return", "context", "::", "$", "systemcontext", ";", "}", "try", "{", "// We ignore the strictness completely because system context must exist except during install.", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'context'", ",", "array", "(", "'contextlevel'", "=>", "CONTEXT_SYSTEM", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "}", "catch", "(", "dml_exception", "$", "e", ")", "{", "//table or record does not exist", "if", "(", "!", "during_initial_install", "(", ")", ")", "{", "// do not mess with system context after install, it simply must exist", "throw", "$", "e", ";", "}", "$", "record", "=", "null", ";", "}", "if", "(", "!", "$", "record", ")", "{", "$", "record", "=", "new", "stdClass", "(", ")", ";", "$", "record", "->", "contextlevel", "=", "CONTEXT_SYSTEM", ";", "$", "record", "->", "instanceid", "=", "0", ";", "$", "record", "->", "depth", "=", "1", ";", "$", "record", "->", "path", "=", "null", ";", "// Not known before insert.", "$", "record", "->", "locked", "=", "0", ";", "try", "{", "if", "(", "$", "DB", "->", "count_records", "(", "'context'", ")", ")", "{", "// contexts already exist, this is very weird, system must be first!!!", "return", "null", ";", "}", "if", "(", "defined", "(", "'SYSCONTEXTID'", ")", ")", "{", "// this would happen only in unittest on sites that went through weird 1.7 upgrade", "$", "record", "->", "id", "=", "SYSCONTEXTID", ";", "$", "DB", "->", "import_record", "(", "'context'", ",", "$", "record", ")", ";", "$", "DB", "->", "get_manager", "(", ")", "->", "reset_sequence", "(", "'context'", ")", ";", "}", "else", "{", "$", "record", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'context'", ",", "$", "record", ")", ";", "}", "}", "catch", "(", "dml_exception", "$", "e", ")", "{", "// can not create context - table does not exist yet, sorry", "return", "null", ";", "}", "}", "if", "(", "$", "record", "->", "instanceid", "!=", "0", ")", "{", "// this is very weird, somebody must be messing with context table", "debugging", "(", "'Invalid system context detected'", ")", ";", "}", "if", "(", "$", "record", "->", "depth", "!=", "1", "or", "$", "record", "->", "path", "!=", "'/'", ".", "$", "record", "->", "id", ")", "{", "// fix path if necessary, initial install or path reset", "$", "record", "->", "depth", "=", "1", ";", "$", "record", "->", "path", "=", "'/'", ".", "$", "record", "->", "id", ";", "$", "DB", "->", "update_record", "(", "'context'", ",", "$", "record", ")", ";", "}", "if", "(", "empty", "(", "$", "record", "->", "locked", ")", ")", "{", "$", "record", "->", "locked", "=", "0", ";", "}", "if", "(", "!", "defined", "(", "'SYSCONTEXTID'", ")", ")", "{", "define", "(", "'SYSCONTEXTID'", ",", "$", "record", "->", "id", ")", ";", "}", "context", "::", "$", "systemcontext", "=", "new", "context_system", "(", "$", "record", ")", ";", "return", "context", "::", "$", "systemcontext", ";", "}" ]
Returns system context instance. @static @param int $instanceid should be 0 @param int $strictness @param bool $cache @return context_system context instance
[ "Returns", "system", "context", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L6110-L6192
218,633
moodle/moodle
lib/accesslib.php
context_system.get_child_contexts
public function get_child_contexts() { global $DB; debugging('Fetching of system context child courses is strongly discouraged on production servers (it may eat all available memory)!'); // Just get all the contexts except for CONTEXT_SYSTEM level // and hope we don't OOM in the process - don't cache $sql = "SELECT c.* FROM {context} c WHERE contextlevel > ".CONTEXT_SYSTEM; $records = $DB->get_records_sql($sql); $result = array(); foreach ($records as $record) { $result[$record->id] = context::create_instance_from_record($record); } return $result; }
php
public function get_child_contexts() { global $DB; debugging('Fetching of system context child courses is strongly discouraged on production servers (it may eat all available memory)!'); // Just get all the contexts except for CONTEXT_SYSTEM level // and hope we don't OOM in the process - don't cache $sql = "SELECT c.* FROM {context} c WHERE contextlevel > ".CONTEXT_SYSTEM; $records = $DB->get_records_sql($sql); $result = array(); foreach ($records as $record) { $result[$record->id] = context::create_instance_from_record($record); } return $result; }
[ "public", "function", "get_child_contexts", "(", ")", "{", "global", "$", "DB", ";", "debugging", "(", "'Fetching of system context child courses is strongly discouraged on production servers (it may eat all available memory)!'", ")", ";", "// Just get all the contexts except for CONTEXT_SYSTEM level", "// and hope we don't OOM in the process - don't cache", "$", "sql", "=", "\"SELECT c.*\n FROM {context} c\n WHERE contextlevel > \"", ".", "CONTEXT_SYSTEM", ";", "$", "records", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ")", ";", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "result", "[", "$", "record", "->", "id", "]", "=", "context", "::", "create_instance_from_record", "(", "$", "record", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns all site contexts except the system context, DO NOT call on production servers!! Contexts are not cached. @return array
[ "Returns", "all", "site", "contexts", "except", "the", "system", "context", "DO", "NOT", "call", "on", "production", "servers!!" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L6201-L6219
218,634
moodle/moodle
lib/accesslib.php
context_system.build_paths
protected static function build_paths($force) { global $DB; /* note: ignore $force here, we always do full test of system context */ // exactly one record must exist $record = $DB->get_record('context', array('contextlevel'=>CONTEXT_SYSTEM), '*', MUST_EXIST); if ($record->instanceid != 0) { debugging('Invalid system context detected'); } if (defined('SYSCONTEXTID') and $record->id != SYSCONTEXTID) { debugging('Invalid SYSCONTEXTID detected'); } if ($record->depth != 1 or $record->path != '/'.$record->id) { // fix path if necessary, initial install or path reset $record->depth = 1; $record->path = '/'.$record->id; $DB->update_record('context', $record); } }
php
protected static function build_paths($force) { global $DB; /* note: ignore $force here, we always do full test of system context */ // exactly one record must exist $record = $DB->get_record('context', array('contextlevel'=>CONTEXT_SYSTEM), '*', MUST_EXIST); if ($record->instanceid != 0) { debugging('Invalid system context detected'); } if (defined('SYSCONTEXTID') and $record->id != SYSCONTEXTID) { debugging('Invalid SYSCONTEXTID detected'); } if ($record->depth != 1 or $record->path != '/'.$record->id) { // fix path if necessary, initial install or path reset $record->depth = 1; $record->path = '/'.$record->id; $DB->update_record('context', $record); } }
[ "protected", "static", "function", "build_paths", "(", "$", "force", ")", "{", "global", "$", "DB", ";", "/* note: ignore $force here, we always do full test of system context */", "// exactly one record must exist", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'context'", ",", "array", "(", "'contextlevel'", "=>", "CONTEXT_SYSTEM", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "if", "(", "$", "record", "->", "instanceid", "!=", "0", ")", "{", "debugging", "(", "'Invalid system context detected'", ")", ";", "}", "if", "(", "defined", "(", "'SYSCONTEXTID'", ")", "and", "$", "record", "->", "id", "!=", "SYSCONTEXTID", ")", "{", "debugging", "(", "'Invalid SYSCONTEXTID detected'", ")", ";", "}", "if", "(", "$", "record", "->", "depth", "!=", "1", "or", "$", "record", "->", "path", "!=", "'/'", ".", "$", "record", "->", "id", ")", "{", "// fix path if necessary, initial install or path reset", "$", "record", "->", "depth", "=", "1", ";", "$", "record", "->", "path", "=", "'/'", ".", "$", "record", "->", "id", ";", "$", "DB", "->", "update_record", "(", "'context'", ",", "$", "record", ")", ";", "}", "}" ]
Rebuild context paths and depths at system context level. @static @param bool $force
[ "Rebuild", "context", "paths", "and", "depths", "at", "system", "context", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L6243-L6265
218,635
moodle/moodle
lib/accesslib.php
context_user.instance
public static function instance($userid, $strictness = MUST_EXIST) { global $DB; if ($context = context::cache_get(CONTEXT_USER, $userid)) { return $context; } if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_USER, 'instanceid' => $userid))) { if ($user = $DB->get_record('user', array('id' => $userid, 'deleted' => 0), 'id', $strictness)) { $record = context::insert_context_record(CONTEXT_USER, $user->id, '/'.SYSCONTEXTID, 0); } } if ($record) { $context = new context_user($record); context::cache_add($context); return $context; } return false; }
php
public static function instance($userid, $strictness = MUST_EXIST) { global $DB; if ($context = context::cache_get(CONTEXT_USER, $userid)) { return $context; } if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_USER, 'instanceid' => $userid))) { if ($user = $DB->get_record('user', array('id' => $userid, 'deleted' => 0), 'id', $strictness)) { $record = context::insert_context_record(CONTEXT_USER, $user->id, '/'.SYSCONTEXTID, 0); } } if ($record) { $context = new context_user($record); context::cache_add($context); return $context; } return false; }
[ "public", "static", "function", "instance", "(", "$", "userid", ",", "$", "strictness", "=", "MUST_EXIST", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "context", "=", "context", "::", "cache_get", "(", "CONTEXT_USER", ",", "$", "userid", ")", ")", "{", "return", "$", "context", ";", "}", "if", "(", "!", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'context'", ",", "array", "(", "'contextlevel'", "=>", "CONTEXT_USER", ",", "'instanceid'", "=>", "$", "userid", ")", ")", ")", "{", "if", "(", "$", "user", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "userid", ",", "'deleted'", "=>", "0", ")", ",", "'id'", ",", "$", "strictness", ")", ")", "{", "$", "record", "=", "context", "::", "insert_context_record", "(", "CONTEXT_USER", ",", "$", "user", "->", "id", ",", "'/'", ".", "SYSCONTEXTID", ",", "0", ")", ";", "}", "}", "if", "(", "$", "record", ")", "{", "$", "context", "=", "new", "context_user", "(", "$", "record", ")", ";", "context", "::", "cache_add", "(", "$", "context", ")", ";", "return", "$", "context", ";", "}", "return", "false", ";", "}" ]
Returns user context instance. @static @param int $userid id from {user} table @param int $strictness @return context_user context instance
[ "Returns", "user", "context", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L6378-L6398
218,636
moodle/moodle
lib/accesslib.php
context_user.build_paths
protected static function build_paths($force) { global $DB; // First update normal users. $path = $DB->sql_concat('?', 'id'); $pathstart = '/' . SYSCONTEXTID . '/'; $params = array($pathstart); if ($force) { $where = "depth <> 2 OR path IS NULL OR path <> ({$path})"; $params[] = $pathstart; } else { $where = "depth = 0 OR path IS NULL"; } $sql = "UPDATE {context} SET depth = 2, path = {$path} WHERE contextlevel = " . CONTEXT_USER . " AND ($where)"; $DB->execute($sql, $params); }
php
protected static function build_paths($force) { global $DB; // First update normal users. $path = $DB->sql_concat('?', 'id'); $pathstart = '/' . SYSCONTEXTID . '/'; $params = array($pathstart); if ($force) { $where = "depth <> 2 OR path IS NULL OR path <> ({$path})"; $params[] = $pathstart; } else { $where = "depth = 0 OR path IS NULL"; } $sql = "UPDATE {context} SET depth = 2, path = {$path} WHERE contextlevel = " . CONTEXT_USER . " AND ($where)"; $DB->execute($sql, $params); }
[ "protected", "static", "function", "build_paths", "(", "$", "force", ")", "{", "global", "$", "DB", ";", "// First update normal users.", "$", "path", "=", "$", "DB", "->", "sql_concat", "(", "'?'", ",", "'id'", ")", ";", "$", "pathstart", "=", "'/'", ".", "SYSCONTEXTID", ".", "'/'", ";", "$", "params", "=", "array", "(", "$", "pathstart", ")", ";", "if", "(", "$", "force", ")", "{", "$", "where", "=", "\"depth <> 2 OR path IS NULL OR path <> ({$path})\"", ";", "$", "params", "[", "]", "=", "$", "pathstart", ";", "}", "else", "{", "$", "where", "=", "\"depth = 0 OR path IS NULL\"", ";", "}", "$", "sql", "=", "\"UPDATE {context}\n SET depth = 2,\n path = {$path}\n WHERE contextlevel = \"", ".", "CONTEXT_USER", ".", "\"\n AND ($where)\"", ";", "$", "DB", "->", "execute", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Rebuild context paths and depths at user context level. @static @param bool $force
[ "Rebuild", "context", "paths", "and", "depths", "at", "user", "context", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L6443-L6464
218,637
moodle/moodle
lib/accesslib.php
context_coursecat.instance
public static function instance($categoryid, $strictness = MUST_EXIST) { global $DB; if ($context = context::cache_get(CONTEXT_COURSECAT, $categoryid)) { return $context; } if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_COURSECAT, 'instanceid' => $categoryid))) { if ($category = $DB->get_record('course_categories', array('id' => $categoryid), 'id,parent', $strictness)) { if ($category->parent) { $parentcontext = context_coursecat::instance($category->parent); $record = context::insert_context_record(CONTEXT_COURSECAT, $category->id, $parentcontext->path); } else { $record = context::insert_context_record(CONTEXT_COURSECAT, $category->id, '/'.SYSCONTEXTID, 0); } } } if ($record) { $context = new context_coursecat($record); context::cache_add($context); return $context; } return false; }
php
public static function instance($categoryid, $strictness = MUST_EXIST) { global $DB; if ($context = context::cache_get(CONTEXT_COURSECAT, $categoryid)) { return $context; } if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_COURSECAT, 'instanceid' => $categoryid))) { if ($category = $DB->get_record('course_categories', array('id' => $categoryid), 'id,parent', $strictness)) { if ($category->parent) { $parentcontext = context_coursecat::instance($category->parent); $record = context::insert_context_record(CONTEXT_COURSECAT, $category->id, $parentcontext->path); } else { $record = context::insert_context_record(CONTEXT_COURSECAT, $category->id, '/'.SYSCONTEXTID, 0); } } } if ($record) { $context = new context_coursecat($record); context::cache_add($context); return $context; } return false; }
[ "public", "static", "function", "instance", "(", "$", "categoryid", ",", "$", "strictness", "=", "MUST_EXIST", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "context", "=", "context", "::", "cache_get", "(", "CONTEXT_COURSECAT", ",", "$", "categoryid", ")", ")", "{", "return", "$", "context", ";", "}", "if", "(", "!", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'context'", ",", "array", "(", "'contextlevel'", "=>", "CONTEXT_COURSECAT", ",", "'instanceid'", "=>", "$", "categoryid", ")", ")", ")", "{", "if", "(", "$", "category", "=", "$", "DB", "->", "get_record", "(", "'course_categories'", ",", "array", "(", "'id'", "=>", "$", "categoryid", ")", ",", "'id,parent'", ",", "$", "strictness", ")", ")", "{", "if", "(", "$", "category", "->", "parent", ")", "{", "$", "parentcontext", "=", "context_coursecat", "::", "instance", "(", "$", "category", "->", "parent", ")", ";", "$", "record", "=", "context", "::", "insert_context_record", "(", "CONTEXT_COURSECAT", ",", "$", "category", "->", "id", ",", "$", "parentcontext", "->", "path", ")", ";", "}", "else", "{", "$", "record", "=", "context", "::", "insert_context_record", "(", "CONTEXT_COURSECAT", ",", "$", "category", "->", "id", ",", "'/'", ".", "SYSCONTEXTID", ",", "0", ")", ";", "}", "}", "}", "if", "(", "$", "record", ")", "{", "$", "context", "=", "new", "context_coursecat", "(", "$", "record", ")", ";", "context", "::", "cache_add", "(", "$", "context", ")", ";", "return", "$", "context", ";", "}", "return", "false", ";", "}" ]
Returns course category context instance. @static @param int $categoryid id from {course_categories} table @param int $strictness @return context_coursecat context instance
[ "Returns", "course", "category", "context", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L6556-L6581
218,638
moodle/moodle
lib/accesslib.php
context_coursecat.get_child_contexts
public function get_child_contexts() { global $DB; if (empty($this->_path) or empty($this->_depth)) { debugging('Can not find child contexts of context '.$this->_id.' try rebuilding of context paths'); return array(); } $sql = "SELECT ctx.* FROM {context} ctx WHERE ctx.path LIKE ? AND (ctx.depth = ? OR ctx.contextlevel = ?)"; $params = array($this->_path.'/%', $this->depth+1, CONTEXT_COURSECAT); $records = $DB->get_records_sql($sql, $params); $result = array(); foreach ($records as $record) { $result[$record->id] = context::create_instance_from_record($record); } return $result; }
php
public function get_child_contexts() { global $DB; if (empty($this->_path) or empty($this->_depth)) { debugging('Can not find child contexts of context '.$this->_id.' try rebuilding of context paths'); return array(); } $sql = "SELECT ctx.* FROM {context} ctx WHERE ctx.path LIKE ? AND (ctx.depth = ? OR ctx.contextlevel = ?)"; $params = array($this->_path.'/%', $this->depth+1, CONTEXT_COURSECAT); $records = $DB->get_records_sql($sql, $params); $result = array(); foreach ($records as $record) { $result[$record->id] = context::create_instance_from_record($record); } return $result; }
[ "public", "function", "get_child_contexts", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "this", "->", "_path", ")", "or", "empty", "(", "$", "this", "->", "_depth", ")", ")", "{", "debugging", "(", "'Can not find child contexts of context '", ".", "$", "this", "->", "_id", ".", "' try rebuilding of context paths'", ")", ";", "return", "array", "(", ")", ";", "}", "$", "sql", "=", "\"SELECT ctx.*\n FROM {context} ctx\n WHERE ctx.path LIKE ? AND (ctx.depth = ? OR ctx.contextlevel = ?)\"", ";", "$", "params", "=", "array", "(", "$", "this", "->", "_path", ".", "'/%'", ",", "$", "this", "->", "depth", "+", "1", ",", "CONTEXT_COURSECAT", ")", ";", "$", "records", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "result", "[", "$", "record", "->", "id", "]", "=", "context", "::", "create_instance_from_record", "(", "$", "record", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns immediate child contexts of category and all subcategories, children of subcategories and courses are not returned. @return array
[ "Returns", "immediate", "child", "contexts", "of", "category", "and", "all", "subcategories", "children", "of", "subcategories", "and", "courses", "are", "not", "returned", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L6589-L6609
218,639
moodle/moodle
lib/accesslib.php
context_coursecat.create_level_instances
protected static function create_level_instances() { global $DB; $sql = "SELECT ".CONTEXT_COURSECAT.", cc.id FROM {course_categories} cc WHERE NOT EXISTS (SELECT 'x' FROM {context} cx WHERE cc.id = cx.instanceid AND cx.contextlevel=".CONTEXT_COURSECAT.")"; $contextdata = $DB->get_recordset_sql($sql); foreach ($contextdata as $context) { context::insert_context_record(CONTEXT_COURSECAT, $context->id, null); } $contextdata->close(); }
php
protected static function create_level_instances() { global $DB; $sql = "SELECT ".CONTEXT_COURSECAT.", cc.id FROM {course_categories} cc WHERE NOT EXISTS (SELECT 'x' FROM {context} cx WHERE cc.id = cx.instanceid AND cx.contextlevel=".CONTEXT_COURSECAT.")"; $contextdata = $DB->get_recordset_sql($sql); foreach ($contextdata as $context) { context::insert_context_record(CONTEXT_COURSECAT, $context->id, null); } $contextdata->close(); }
[ "protected", "static", "function", "create_level_instances", "(", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT \"", ".", "CONTEXT_COURSECAT", ".", "\", cc.id\n FROM {course_categories} cc\n WHERE NOT EXISTS (SELECT 'x'\n FROM {context} cx\n WHERE cc.id = cx.instanceid AND cx.contextlevel=\"", ".", "CONTEXT_COURSECAT", ".", "\")\"", ";", "$", "contextdata", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ")", ";", "foreach", "(", "$", "contextdata", "as", "$", "context", ")", "{", "context", "::", "insert_context_record", "(", "CONTEXT_COURSECAT", ",", "$", "context", "->", "id", ",", "null", ")", ";", "}", "$", "contextdata", "->", "close", "(", ")", ";", "}" ]
Create missing context instances at course category context level @static
[ "Create", "missing", "context", "instances", "at", "course", "category", "context", "level" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L6615-L6628
218,640
moodle/moodle
lib/accesslib.php
context_coursecat.build_paths
protected static function build_paths($force) { global $DB; if ($force or $DB->record_exists_select('context', "contextlevel = ".CONTEXT_COURSECAT." AND (depth = 0 OR path IS NULL)")) { if ($force) { $ctxemptyclause = $emptyclause = ''; } else { $ctxemptyclause = "AND (ctx.path IS NULL OR ctx.depth = 0)"; $emptyclause = "AND ({context}.path IS NULL OR {context}.depth = 0)"; } $base = '/'.SYSCONTEXTID; // Normal top level categories $sql = "UPDATE {context} SET depth=2, path=".$DB->sql_concat("'$base/'", 'id')." WHERE contextlevel=".CONTEXT_COURSECAT." AND EXISTS (SELECT 'x' FROM {course_categories} cc WHERE cc.id = {context}.instanceid AND cc.depth=1) $emptyclause"; $DB->execute($sql); // Deeper categories - one query per depthlevel $maxdepth = $DB->get_field_sql("SELECT MAX(depth) FROM {course_categories}"); for ($n=2; $n<=$maxdepth; $n++) { $sql = "INSERT INTO {context_temp} (id, path, depth, locked) SELECT ctx.id, ".$DB->sql_concat('pctx.path', "'/'", 'ctx.id').", pctx.depth+1, ctx.locked FROM {context} ctx JOIN {course_categories} cc ON (cc.id = ctx.instanceid AND ctx.contextlevel = ".CONTEXT_COURSECAT." AND cc.depth = $n) JOIN {context} pctx ON (pctx.instanceid = cc.parent AND pctx.contextlevel = ".CONTEXT_COURSECAT.") WHERE pctx.path IS NOT NULL AND pctx.depth > 0 $ctxemptyclause"; $trans = $DB->start_delegated_transaction(); $DB->delete_records('context_temp'); $DB->execute($sql); context::merge_context_temp_table(); $DB->delete_records('context_temp'); $trans->allow_commit(); } } }
php
protected static function build_paths($force) { global $DB; if ($force or $DB->record_exists_select('context', "contextlevel = ".CONTEXT_COURSECAT." AND (depth = 0 OR path IS NULL)")) { if ($force) { $ctxemptyclause = $emptyclause = ''; } else { $ctxemptyclause = "AND (ctx.path IS NULL OR ctx.depth = 0)"; $emptyclause = "AND ({context}.path IS NULL OR {context}.depth = 0)"; } $base = '/'.SYSCONTEXTID; // Normal top level categories $sql = "UPDATE {context} SET depth=2, path=".$DB->sql_concat("'$base/'", 'id')." WHERE contextlevel=".CONTEXT_COURSECAT." AND EXISTS (SELECT 'x' FROM {course_categories} cc WHERE cc.id = {context}.instanceid AND cc.depth=1) $emptyclause"; $DB->execute($sql); // Deeper categories - one query per depthlevel $maxdepth = $DB->get_field_sql("SELECT MAX(depth) FROM {course_categories}"); for ($n=2; $n<=$maxdepth; $n++) { $sql = "INSERT INTO {context_temp} (id, path, depth, locked) SELECT ctx.id, ".$DB->sql_concat('pctx.path', "'/'", 'ctx.id').", pctx.depth+1, ctx.locked FROM {context} ctx JOIN {course_categories} cc ON (cc.id = ctx.instanceid AND ctx.contextlevel = ".CONTEXT_COURSECAT." AND cc.depth = $n) JOIN {context} pctx ON (pctx.instanceid = cc.parent AND pctx.contextlevel = ".CONTEXT_COURSECAT.") WHERE pctx.path IS NOT NULL AND pctx.depth > 0 $ctxemptyclause"; $trans = $DB->start_delegated_transaction(); $DB->delete_records('context_temp'); $DB->execute($sql); context::merge_context_temp_table(); $DB->delete_records('context_temp'); $trans->allow_commit(); } } }
[ "protected", "static", "function", "build_paths", "(", "$", "force", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "force", "or", "$", "DB", "->", "record_exists_select", "(", "'context'", ",", "\"contextlevel = \"", ".", "CONTEXT_COURSECAT", ".", "\" AND (depth = 0 OR path IS NULL)\"", ")", ")", "{", "if", "(", "$", "force", ")", "{", "$", "ctxemptyclause", "=", "$", "emptyclause", "=", "''", ";", "}", "else", "{", "$", "ctxemptyclause", "=", "\"AND (ctx.path IS NULL OR ctx.depth = 0)\"", ";", "$", "emptyclause", "=", "\"AND ({context}.path IS NULL OR {context}.depth = 0)\"", ";", "}", "$", "base", "=", "'/'", ".", "SYSCONTEXTID", ";", "// Normal top level categories", "$", "sql", "=", "\"UPDATE {context}\n SET depth=2,\n path=\"", ".", "$", "DB", "->", "sql_concat", "(", "\"'$base/'\"", ",", "'id'", ")", ".", "\"\n WHERE contextlevel=\"", ".", "CONTEXT_COURSECAT", ".", "\"\n AND EXISTS (SELECT 'x'\n FROM {course_categories} cc\n WHERE cc.id = {context}.instanceid AND cc.depth=1)\n $emptyclause\"", ";", "$", "DB", "->", "execute", "(", "$", "sql", ")", ";", "// Deeper categories - one query per depthlevel", "$", "maxdepth", "=", "$", "DB", "->", "get_field_sql", "(", "\"SELECT MAX(depth) FROM {course_categories}\"", ")", ";", "for", "(", "$", "n", "=", "2", ";", "$", "n", "<=", "$", "maxdepth", ";", "$", "n", "++", ")", "{", "$", "sql", "=", "\"INSERT INTO {context_temp} (id, path, depth, locked)\n SELECT ctx.id, \"", ".", "$", "DB", "->", "sql_concat", "(", "'pctx.path'", ",", "\"'/'\"", ",", "'ctx.id'", ")", ".", "\", pctx.depth+1, ctx.locked\n FROM {context} ctx\n JOIN {course_categories} cc ON (cc.id = ctx.instanceid AND ctx.contextlevel = \"", ".", "CONTEXT_COURSECAT", ".", "\" AND cc.depth = $n)\n JOIN {context} pctx ON (pctx.instanceid = cc.parent AND pctx.contextlevel = \"", ".", "CONTEXT_COURSECAT", ".", "\")\n WHERE pctx.path IS NOT NULL AND pctx.depth > 0\n $ctxemptyclause\"", ";", "$", "trans", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "$", "DB", "->", "delete_records", "(", "'context_temp'", ")", ";", "$", "DB", "->", "execute", "(", "$", "sql", ")", ";", "context", "::", "merge_context_temp_table", "(", ")", ";", "$", "DB", "->", "delete_records", "(", "'context_temp'", ")", ";", "$", "trans", "->", "allow_commit", "(", ")", ";", "}", "}", "}" ]
Rebuild context paths and depths at course category context level. @static @param bool $force
[ "Rebuild", "context", "paths", "and", "depths", "at", "course", "category", "context", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L6653-L6696
218,641
moodle/moodle
lib/accesslib.php
context_course.instance
public static function instance($courseid, $strictness = MUST_EXIST) { global $DB; if ($context = context::cache_get(CONTEXT_COURSE, $courseid)) { return $context; } if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_COURSE, 'instanceid' => $courseid))) { if ($course = $DB->get_record('course', array('id' => $courseid), 'id,category', $strictness)) { if ($course->category) { $parentcontext = context_coursecat::instance($course->category); $record = context::insert_context_record(CONTEXT_COURSE, $course->id, $parentcontext->path); } else { $record = context::insert_context_record(CONTEXT_COURSE, $course->id, '/'.SYSCONTEXTID, 0); } } } if ($record) { $context = new context_course($record); context::cache_add($context); return $context; } return false; }
php
public static function instance($courseid, $strictness = MUST_EXIST) { global $DB; if ($context = context::cache_get(CONTEXT_COURSE, $courseid)) { return $context; } if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_COURSE, 'instanceid' => $courseid))) { if ($course = $DB->get_record('course', array('id' => $courseid), 'id,category', $strictness)) { if ($course->category) { $parentcontext = context_coursecat::instance($course->category); $record = context::insert_context_record(CONTEXT_COURSE, $course->id, $parentcontext->path); } else { $record = context::insert_context_record(CONTEXT_COURSE, $course->id, '/'.SYSCONTEXTID, 0); } } } if ($record) { $context = new context_course($record); context::cache_add($context); return $context; } return false; }
[ "public", "static", "function", "instance", "(", "$", "courseid", ",", "$", "strictness", "=", "MUST_EXIST", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "context", "=", "context", "::", "cache_get", "(", "CONTEXT_COURSE", ",", "$", "courseid", ")", ")", "{", "return", "$", "context", ";", "}", "if", "(", "!", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'context'", ",", "array", "(", "'contextlevel'", "=>", "CONTEXT_COURSE", ",", "'instanceid'", "=>", "$", "courseid", ")", ")", ")", "{", "if", "(", "$", "course", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "array", "(", "'id'", "=>", "$", "courseid", ")", ",", "'id,category'", ",", "$", "strictness", ")", ")", "{", "if", "(", "$", "course", "->", "category", ")", "{", "$", "parentcontext", "=", "context_coursecat", "::", "instance", "(", "$", "course", "->", "category", ")", ";", "$", "record", "=", "context", "::", "insert_context_record", "(", "CONTEXT_COURSE", ",", "$", "course", "->", "id", ",", "$", "parentcontext", "->", "path", ")", ";", "}", "else", "{", "$", "record", "=", "context", "::", "insert_context_record", "(", "CONTEXT_COURSE", ",", "$", "course", "->", "id", ",", "'/'", ".", "SYSCONTEXTID", ",", "0", ")", ";", "}", "}", "}", "if", "(", "$", "record", ")", "{", "$", "context", "=", "new", "context_course", "(", "$", "record", ")", ";", "context", "::", "cache_add", "(", "$", "context", ")", ";", "return", "$", "context", ";", "}", "return", "false", ";", "}" ]
Returns course context instance. @static @param int $courseid id from {course} table @param int $strictness @return context_course context instance
[ "Returns", "course", "context", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L6810-L6835
218,642
moodle/moodle
lib/accesslib.php
context_module.instance
public static function instance($cmid, $strictness = MUST_EXIST) { global $DB; if ($context = context::cache_get(CONTEXT_MODULE, $cmid)) { return $context; } if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_MODULE, 'instanceid' => $cmid))) { if ($cm = $DB->get_record('course_modules', array('id' => $cmid), 'id,course', $strictness)) { $parentcontext = context_course::instance($cm->course); $record = context::insert_context_record(CONTEXT_MODULE, $cm->id, $parentcontext->path); } } if ($record) { $context = new context_module($record); context::cache_add($context); return $context; } return false; }
php
public static function instance($cmid, $strictness = MUST_EXIST) { global $DB; if ($context = context::cache_get(CONTEXT_MODULE, $cmid)) { return $context; } if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_MODULE, 'instanceid' => $cmid))) { if ($cm = $DB->get_record('course_modules', array('id' => $cmid), 'id,course', $strictness)) { $parentcontext = context_course::instance($cm->course); $record = context::insert_context_record(CONTEXT_MODULE, $cm->id, $parentcontext->path); } } if ($record) { $context = new context_module($record); context::cache_add($context); return $context; } return false; }
[ "public", "static", "function", "instance", "(", "$", "cmid", ",", "$", "strictness", "=", "MUST_EXIST", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "context", "=", "context", "::", "cache_get", "(", "CONTEXT_MODULE", ",", "$", "cmid", ")", ")", "{", "return", "$", "context", ";", "}", "if", "(", "!", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'context'", ",", "array", "(", "'contextlevel'", "=>", "CONTEXT_MODULE", ",", "'instanceid'", "=>", "$", "cmid", ")", ")", ")", "{", "if", "(", "$", "cm", "=", "$", "DB", "->", "get_record", "(", "'course_modules'", ",", "array", "(", "'id'", "=>", "$", "cmid", ")", ",", "'id,course'", ",", "$", "strictness", ")", ")", "{", "$", "parentcontext", "=", "context_course", "::", "instance", "(", "$", "cm", "->", "course", ")", ";", "$", "record", "=", "context", "::", "insert_context_record", "(", "CONTEXT_MODULE", ",", "$", "cm", "->", "id", ",", "$", "parentcontext", "->", "path", ")", ";", "}", "}", "if", "(", "$", "record", ")", "{", "$", "context", "=", "new", "context_module", "(", "$", "record", ")", ";", "context", "::", "cache_add", "(", "$", "context", ")", ";", "return", "$", "context", ";", "}", "return", "false", ";", "}" ]
Returns module context instance. @static @param int $cmid id of the record from {course_modules} table; pass cmid there, NOT id in the instance column @param int $strictness @return context_module context instance
[ "Returns", "module", "context", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L7098-L7119
218,643
moodle/moodle
lib/accesslib.php
context_block.instance
public static function instance($blockinstanceid, $strictness = MUST_EXIST) { global $DB; if ($context = context::cache_get(CONTEXT_BLOCK, $blockinstanceid)) { return $context; } if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_BLOCK, 'instanceid' => $blockinstanceid))) { if ($bi = $DB->get_record('block_instances', array('id' => $blockinstanceid), 'id,parentcontextid', $strictness)) { $parentcontext = context::instance_by_id($bi->parentcontextid); $record = context::insert_context_record(CONTEXT_BLOCK, $bi->id, $parentcontext->path); } } if ($record) { $context = new context_block($record); context::cache_add($context); return $context; } return false; }
php
public static function instance($blockinstanceid, $strictness = MUST_EXIST) { global $DB; if ($context = context::cache_get(CONTEXT_BLOCK, $blockinstanceid)) { return $context; } if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_BLOCK, 'instanceid' => $blockinstanceid))) { if ($bi = $DB->get_record('block_instances', array('id' => $blockinstanceid), 'id,parentcontextid', $strictness)) { $parentcontext = context::instance_by_id($bi->parentcontextid); $record = context::insert_context_record(CONTEXT_BLOCK, $bi->id, $parentcontext->path); } } if ($record) { $context = new context_block($record); context::cache_add($context); return $context; } return false; }
[ "public", "static", "function", "instance", "(", "$", "blockinstanceid", ",", "$", "strictness", "=", "MUST_EXIST", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "context", "=", "context", "::", "cache_get", "(", "CONTEXT_BLOCK", ",", "$", "blockinstanceid", ")", ")", "{", "return", "$", "context", ";", "}", "if", "(", "!", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'context'", ",", "array", "(", "'contextlevel'", "=>", "CONTEXT_BLOCK", ",", "'instanceid'", "=>", "$", "blockinstanceid", ")", ")", ")", "{", "if", "(", "$", "bi", "=", "$", "DB", "->", "get_record", "(", "'block_instances'", ",", "array", "(", "'id'", "=>", "$", "blockinstanceid", ")", ",", "'id,parentcontextid'", ",", "$", "strictness", ")", ")", "{", "$", "parentcontext", "=", "context", "::", "instance_by_id", "(", "$", "bi", "->", "parentcontextid", ")", ";", "$", "record", "=", "context", "::", "insert_context_record", "(", "CONTEXT_BLOCK", ",", "$", "bi", "->", "id", ",", "$", "parentcontext", "->", "path", ")", ";", "}", "}", "if", "(", "$", "record", ")", "{", "$", "context", "=", "new", "context_block", "(", "$", "record", ")", ";", "context", "::", "cache_add", "(", "$", "context", ")", ";", "return", "$", "context", ";", "}", "return", "false", ";", "}" ]
Returns block context instance. @static @param int $blockinstanceid id from {block_instances} table. @param int $strictness @return context_block context instance
[ "Returns", "block", "context", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L7310-L7331
218,644
moodle/moodle
lib/accesslib.php
context_block.build_paths
protected static function build_paths($force) { global $DB; if ($force or $DB->record_exists_select('context', "contextlevel = ".CONTEXT_BLOCK." AND (depth = 0 OR path IS NULL)")) { if ($force) { $ctxemptyclause = ''; } else { $ctxemptyclause = "AND (ctx.path IS NULL OR ctx.depth = 0)"; } // pctx.path IS NOT NULL prevents fatal problems with broken block instances that point to invalid context parent $sql = "INSERT INTO {context_temp} (id, path, depth, locked) SELECT ctx.id, ".$DB->sql_concat('pctx.path', "'/'", 'ctx.id').", pctx.depth+1, ctx.locked FROM {context} ctx JOIN {block_instances} bi ON (bi.id = ctx.instanceid AND ctx.contextlevel = ".CONTEXT_BLOCK.") JOIN {context} pctx ON (pctx.id = bi.parentcontextid) WHERE (pctx.path IS NOT NULL AND pctx.depth > 0) $ctxemptyclause"; $trans = $DB->start_delegated_transaction(); $DB->delete_records('context_temp'); $DB->execute($sql); context::merge_context_temp_table(); $DB->delete_records('context_temp'); $trans->allow_commit(); } }
php
protected static function build_paths($force) { global $DB; if ($force or $DB->record_exists_select('context', "contextlevel = ".CONTEXT_BLOCK." AND (depth = 0 OR path IS NULL)")) { if ($force) { $ctxemptyclause = ''; } else { $ctxemptyclause = "AND (ctx.path IS NULL OR ctx.depth = 0)"; } // pctx.path IS NOT NULL prevents fatal problems with broken block instances that point to invalid context parent $sql = "INSERT INTO {context_temp} (id, path, depth, locked) SELECT ctx.id, ".$DB->sql_concat('pctx.path', "'/'", 'ctx.id').", pctx.depth+1, ctx.locked FROM {context} ctx JOIN {block_instances} bi ON (bi.id = ctx.instanceid AND ctx.contextlevel = ".CONTEXT_BLOCK.") JOIN {context} pctx ON (pctx.id = bi.parentcontextid) WHERE (pctx.path IS NOT NULL AND pctx.depth > 0) $ctxemptyclause"; $trans = $DB->start_delegated_transaction(); $DB->delete_records('context_temp'); $DB->execute($sql); context::merge_context_temp_table(); $DB->delete_records('context_temp'); $trans->allow_commit(); } }
[ "protected", "static", "function", "build_paths", "(", "$", "force", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "force", "or", "$", "DB", "->", "record_exists_select", "(", "'context'", ",", "\"contextlevel = \"", ".", "CONTEXT_BLOCK", ".", "\" AND (depth = 0 OR path IS NULL)\"", ")", ")", "{", "if", "(", "$", "force", ")", "{", "$", "ctxemptyclause", "=", "''", ";", "}", "else", "{", "$", "ctxemptyclause", "=", "\"AND (ctx.path IS NULL OR ctx.depth = 0)\"", ";", "}", "// pctx.path IS NOT NULL prevents fatal problems with broken block instances that point to invalid context parent", "$", "sql", "=", "\"INSERT INTO {context_temp} (id, path, depth, locked)\n SELECT ctx.id, \"", ".", "$", "DB", "->", "sql_concat", "(", "'pctx.path'", ",", "\"'/'\"", ",", "'ctx.id'", ")", ".", "\", pctx.depth+1, ctx.locked\n FROM {context} ctx\n JOIN {block_instances} bi ON (bi.id = ctx.instanceid AND ctx.contextlevel = \"", ".", "CONTEXT_BLOCK", ".", "\")\n JOIN {context} pctx ON (pctx.id = bi.parentcontextid)\n WHERE (pctx.path IS NOT NULL AND pctx.depth > 0)\n $ctxemptyclause\"", ";", "$", "trans", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "$", "DB", "->", "delete_records", "(", "'context_temp'", ")", ";", "$", "DB", "->", "execute", "(", "$", "sql", ")", ";", "context", "::", "merge_context_temp_table", "(", ")", ";", "$", "DB", "->", "delete_records", "(", "'context_temp'", ")", ";", "$", "trans", "->", "allow_commit", "(", ")", ";", "}", "}" ]
Rebuild context paths and depths at block context level. @static @param bool $force
[ "Rebuild", "context", "paths", "and", "depths", "at", "block", "context", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/accesslib.php#L7383-L7408
218,645
moodle/moodle
lib/spout/src/Spout/Reader/XLSX/Reader.php
Reader.openReader
protected function openReader($filePath) { $this->zip = new \ZipArchive(); if ($this->zip->open($filePath) === true) { $this->sharedStringsHelper = new SharedStringsHelper($filePath, $this->getOptions()->getTempFolder()); if ($this->sharedStringsHelper->hasSharedStrings()) { // Extracts all the strings from the sheets for easy access in the future $this->sharedStringsHelper->extractSharedStrings(); } $this->sheetIterator = new SheetIterator($filePath, $this->getOptions(), $this->sharedStringsHelper, $this->globalFunctionsHelper); } else { throw new IOException("Could not open $filePath for reading."); } }
php
protected function openReader($filePath) { $this->zip = new \ZipArchive(); if ($this->zip->open($filePath) === true) { $this->sharedStringsHelper = new SharedStringsHelper($filePath, $this->getOptions()->getTempFolder()); if ($this->sharedStringsHelper->hasSharedStrings()) { // Extracts all the strings from the sheets for easy access in the future $this->sharedStringsHelper->extractSharedStrings(); } $this->sheetIterator = new SheetIterator($filePath, $this->getOptions(), $this->sharedStringsHelper, $this->globalFunctionsHelper); } else { throw new IOException("Could not open $filePath for reading."); } }
[ "protected", "function", "openReader", "(", "$", "filePath", ")", "{", "$", "this", "->", "zip", "=", "new", "\\", "ZipArchive", "(", ")", ";", "if", "(", "$", "this", "->", "zip", "->", "open", "(", "$", "filePath", ")", "===", "true", ")", "{", "$", "this", "->", "sharedStringsHelper", "=", "new", "SharedStringsHelper", "(", "$", "filePath", ",", "$", "this", "->", "getOptions", "(", ")", "->", "getTempFolder", "(", ")", ")", ";", "if", "(", "$", "this", "->", "sharedStringsHelper", "->", "hasSharedStrings", "(", ")", ")", "{", "// Extracts all the strings from the sheets for easy access in the future", "$", "this", "->", "sharedStringsHelper", "->", "extractSharedStrings", "(", ")", ";", "}", "$", "this", "->", "sheetIterator", "=", "new", "SheetIterator", "(", "$", "filePath", ",", "$", "this", "->", "getOptions", "(", ")", ",", "$", "this", "->", "sharedStringsHelper", ",", "$", "this", "->", "globalFunctionsHelper", ")", ";", "}", "else", "{", "throw", "new", "IOException", "(", "\"Could not open $filePath for reading.\"", ")", ";", "}", "}" ]
Opens the file at the given file path to make it ready to be read. It also parses the sharedStrings.xml file to get all the shared strings available in memory and fetches all the available sheets. @param string $filePath Path of the file to be read @return void @throws \Box\Spout\Common\Exception\IOException If the file at the given path or its content cannot be read @throws \Box\Spout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file
[ "Opens", "the", "file", "at", "the", "given", "file", "path", "to", "make", "it", "ready", "to", "be", "read", ".", "It", "also", "parses", "the", "sharedStrings", ".", "xml", "file", "to", "get", "all", "the", "shared", "strings", "available", "in", "memory", "and", "fetches", "all", "the", "available", "sheets", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Reader.php#L70-L86
218,646
moodle/moodle
lib/dml/sqlite3_pdo_moodle_database.php
sqlite3_pdo_moodle_database.get_indexes
public function get_indexes($table) { $indexes = array(); $sql = 'PRAGMA index_list('.$this->prefix.$table.')'; if ($this->debug) { $this->debug_query($sql); } $rsindexes = $this->pdb->query($sql); foreach($rsindexes as $index) { $unique = (boolean)$index['unique']; $index = $index['name']; $sql = 'PRAGMA index_info("'.$index.'")'; if ($this->debug) { $this->debug_query($sql); } $rscolumns = $this->pdb->query($sql); $columns = array(); foreach($rscolumns as $row) { $columns[] = strtolower($row['name']); } $index = strtolower($index); $indexes[$index]['unique'] = $unique; $indexes[$index]['columns'] = $columns; } return $indexes; }
php
public function get_indexes($table) { $indexes = array(); $sql = 'PRAGMA index_list('.$this->prefix.$table.')'; if ($this->debug) { $this->debug_query($sql); } $rsindexes = $this->pdb->query($sql); foreach($rsindexes as $index) { $unique = (boolean)$index['unique']; $index = $index['name']; $sql = 'PRAGMA index_info("'.$index.'")'; if ($this->debug) { $this->debug_query($sql); } $rscolumns = $this->pdb->query($sql); $columns = array(); foreach($rscolumns as $row) { $columns[] = strtolower($row['name']); } $index = strtolower($index); $indexes[$index]['unique'] = $unique; $indexes[$index]['columns'] = $columns; } return $indexes; }
[ "public", "function", "get_indexes", "(", "$", "table", ")", "{", "$", "indexes", "=", "array", "(", ")", ";", "$", "sql", "=", "'PRAGMA index_list('", ".", "$", "this", "->", "prefix", ".", "$", "table", ".", "')'", ";", "if", "(", "$", "this", "->", "debug", ")", "{", "$", "this", "->", "debug_query", "(", "$", "sql", ")", ";", "}", "$", "rsindexes", "=", "$", "this", "->", "pdb", "->", "query", "(", "$", "sql", ")", ";", "foreach", "(", "$", "rsindexes", "as", "$", "index", ")", "{", "$", "unique", "=", "(", "boolean", ")", "$", "index", "[", "'unique'", "]", ";", "$", "index", "=", "$", "index", "[", "'name'", "]", ";", "$", "sql", "=", "'PRAGMA index_info(\"'", ".", "$", "index", ".", "'\")'", ";", "if", "(", "$", "this", "->", "debug", ")", "{", "$", "this", "->", "debug_query", "(", "$", "sql", ")", ";", "}", "$", "rscolumns", "=", "$", "this", "->", "pdb", "->", "query", "(", "$", "sql", ")", ";", "$", "columns", "=", "array", "(", ")", ";", "foreach", "(", "$", "rscolumns", "as", "$", "row", ")", "{", "$", "columns", "[", "]", "=", "strtolower", "(", "$", "row", "[", "'name'", "]", ")", ";", "}", "$", "index", "=", "strtolower", "(", "$", "index", ")", ";", "$", "indexes", "[", "$", "index", "]", "[", "'unique'", "]", "=", "$", "unique", ";", "$", "indexes", "[", "$", "index", "]", "[", "'columns'", "]", "=", "$", "columns", ";", "}", "return", "$", "indexes", ";", "}" ]
Return table indexes - everything lowercased @param string $table The table we want to get indexes from. @return array of arrays
[ "Return", "table", "indexes", "-", "everything", "lowercased" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/sqlite3_pdo_moodle_database.php#L169-L193
218,647
moodle/moodle
lib/dml/sqlite3_pdo_moodle_database.php
sqlite3_pdo_moodle_database.get_limit_clauses
protected function get_limit_clauses($sql, $limitfrom=0, $limitnum=0) { if ($limitnum) { $sql .= ' LIMIT '.$limitnum; if ($limitfrom) { $sql .= ' OFFSET '.$limitfrom; } } return $sql; }
php
protected function get_limit_clauses($sql, $limitfrom=0, $limitnum=0) { if ($limitnum) { $sql .= ' LIMIT '.$limitnum; if ($limitfrom) { $sql .= ' OFFSET '.$limitfrom; } } return $sql; }
[ "protected", "function", "get_limit_clauses", "(", "$", "sql", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "if", "(", "$", "limitnum", ")", "{", "$", "sql", ".=", "' LIMIT '", ".", "$", "limitnum", ";", "if", "(", "$", "limitfrom", ")", "{", "$", "sql", ".=", "' OFFSET '", ".", "$", "limitfrom", ";", "}", "}", "return", "$", "sql", ";", "}" ]
Returns the sql statement with clauses to append used to limit a recordset range. @param string $sql the SQL statement to limit. @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set). @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set). @return string the SQL statement with limiting clauses
[ "Returns", "the", "sql", "statement", "with", "clauses", "to", "append", "used", "to", "limit", "a", "recordset", "range", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/sqlite3_pdo_moodle_database.php#L335-L343
218,648
moodle/moodle
lib/dml/sqlite3_pdo_moodle_database.php
sqlite3_pdo_moodle_database.sql_bitxor
public function sql_bitxor($int1, $int2) { return '( ~' . $this->sql_bitand($int1, $int2) . ' & ' . $this->sql_bitor($int1, $int2) . ')'; }
php
public function sql_bitxor($int1, $int2) { return '( ~' . $this->sql_bitand($int1, $int2) . ' & ' . $this->sql_bitor($int1, $int2) . ')'; }
[ "public", "function", "sql_bitxor", "(", "$", "int1", ",", "$", "int2", ")", "{", "return", "'( ~'", ".", "$", "this", "->", "sql_bitand", "(", "$", "int1", ",", "$", "int2", ")", ".", "' & '", ".", "$", "this", "->", "sql_bitor", "(", "$", "int1", ",", "$", "int2", ")", ".", "')'", ";", "}" ]
Returns the SQL text to be used in order to perform one bitwise XOR operation between 2 integers. @param integer int1 first integer in the operation @param integer int2 second integer in the operation @return string the piece of SQL code to be used in your statement.
[ "Returns", "the", "SQL", "text", "to", "be", "used", "in", "order", "to", "perform", "one", "bitwise", "XOR", "operation", "between", "2", "integers", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/sqlite3_pdo_moodle_database.php#L400-L402
218,649
moodle/moodle
lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Nmtokens.php
HTMLPurifier_AttrDef_HTML_Nmtokens.split
protected function split($string, $config, $context) { // OPTIMIZABLE! // do the preg_match, capture all subpatterns for reformulation // we don't support U+00A1 and up codepoints or // escaping because I don't know how to do that with regexps // and plus it would complicate optimization efforts (you never // see that anyway). $pattern = '/(?:(?<=\s)|\A)' . // look behind for space or string start '((?:--|-?[A-Za-z_])[A-Za-z_\-0-9]*)' . '(?:(?=\s)|\z)/'; // look ahead for space or string end preg_match_all($pattern, $string, $matches); return $matches[1]; }
php
protected function split($string, $config, $context) { // OPTIMIZABLE! // do the preg_match, capture all subpatterns for reformulation // we don't support U+00A1 and up codepoints or // escaping because I don't know how to do that with regexps // and plus it would complicate optimization efforts (you never // see that anyway). $pattern = '/(?:(?<=\s)|\A)' . // look behind for space or string start '((?:--|-?[A-Za-z_])[A-Za-z_\-0-9]*)' . '(?:(?=\s)|\z)/'; // look ahead for space or string end preg_match_all($pattern, $string, $matches); return $matches[1]; }
[ "protected", "function", "split", "(", "$", "string", ",", "$", "config", ",", "$", "context", ")", "{", "// OPTIMIZABLE!", "// do the preg_match, capture all subpatterns for reformulation", "// we don't support U+00A1 and up codepoints or", "// escaping because I don't know how to do that with regexps", "// and plus it would complicate optimization efforts (you never", "// see that anyway).", "$", "pattern", "=", "'/(?:(?<=\\s)|\\A)'", ".", "// look behind for space or string start", "'((?:--|-?[A-Za-z_])[A-Za-z_\\-0-9]*)'", ".", "'(?:(?=\\s)|\\z)/'", ";", "// look ahead for space or string end", "preg_match_all", "(", "$", "pattern", ",", "$", "string", ",", "$", "matches", ")", ";", "return", "$", "matches", "[", "1", "]", ";", "}" ]
Splits a space separated list of tokens into its constituent parts. @param string $string @param HTMLPurifier_Config $config @param HTMLPurifier_Context $context @return array
[ "Splits", "a", "space", "separated", "list", "of", "tokens", "into", "its", "constituent", "parts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Nmtokens.php#L39-L53
218,650
moodle/moodle
question/classes/bank/view.php
view.get_column_type
protected function get_column_type($columnname) { if (! class_exists($columnname)) { if (class_exists('core_question\\bank\\' . $columnname)) { $columnname = 'core_question\\bank\\' . $columnname; } else { throw new \coding_exception("No such class exists: $columnname"); } } if (empty($this->requiredcolumns[$columnname])) { $this->requiredcolumns[$columnname] = new $columnname($this); } return $this->requiredcolumns[$columnname]; }
php
protected function get_column_type($columnname) { if (! class_exists($columnname)) { if (class_exists('core_question\\bank\\' . $columnname)) { $columnname = 'core_question\\bank\\' . $columnname; } else { throw new \coding_exception("No such class exists: $columnname"); } } if (empty($this->requiredcolumns[$columnname])) { $this->requiredcolumns[$columnname] = new $columnname($this); } return $this->requiredcolumns[$columnname]; }
[ "protected", "function", "get_column_type", "(", "$", "columnname", ")", "{", "if", "(", "!", "class_exists", "(", "$", "columnname", ")", ")", "{", "if", "(", "class_exists", "(", "'core_question\\\\bank\\\\'", ".", "$", "columnname", ")", ")", "{", "$", "columnname", "=", "'core_question\\\\bank\\\\'", ".", "$", "columnname", ";", "}", "else", "{", "throw", "new", "\\", "coding_exception", "(", "\"No such class exists: $columnname\"", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "this", "->", "requiredcolumns", "[", "$", "columnname", "]", ")", ")", "{", "$", "this", "->", "requiredcolumns", "[", "$", "columnname", "]", "=", "new", "$", "columnname", "(", "$", "this", ")", ";", "}", "return", "$", "this", "->", "requiredcolumns", "[", "$", "columnname", "]", ";", "}" ]
Get a column object from its name. @param string $columnname. @return \core_question\bank\column_base.
[ "Get", "a", "column", "object", "from", "its", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/bank/view.php#L157-L169
218,651
moodle/moodle
question/classes/bank/view.php
view.init_columns
protected function init_columns($wanted, $heading = '') { $this->visiblecolumns = array(); $this->extrarows = array(); foreach ($wanted as $column) { if ($column->is_extra_row()) { $this->extrarows[get_class($column)] = $column; } else { $this->visiblecolumns[get_class($column)] = $column; } } if (array_key_exists($heading, $this->requiredcolumns)) { $this->requiredcolumns[$heading]->set_as_heading(); } }
php
protected function init_columns($wanted, $heading = '') { $this->visiblecolumns = array(); $this->extrarows = array(); foreach ($wanted as $column) { if ($column->is_extra_row()) { $this->extrarows[get_class($column)] = $column; } else { $this->visiblecolumns[get_class($column)] = $column; } } if (array_key_exists($heading, $this->requiredcolumns)) { $this->requiredcolumns[$heading]->set_as_heading(); } }
[ "protected", "function", "init_columns", "(", "$", "wanted", ",", "$", "heading", "=", "''", ")", "{", "$", "this", "->", "visiblecolumns", "=", "array", "(", ")", ";", "$", "this", "->", "extrarows", "=", "array", "(", ")", ";", "foreach", "(", "$", "wanted", "as", "$", "column", ")", "{", "if", "(", "$", "column", "->", "is_extra_row", "(", ")", ")", "{", "$", "this", "->", "extrarows", "[", "get_class", "(", "$", "column", ")", "]", "=", "$", "column", ";", "}", "else", "{", "$", "this", "->", "visiblecolumns", "[", "get_class", "(", "$", "column", ")", "]", "=", "$", "column", ";", "}", "}", "if", "(", "array_key_exists", "(", "$", "heading", ",", "$", "this", "->", "requiredcolumns", ")", ")", "{", "$", "this", "->", "requiredcolumns", "[", "$", "heading", "]", "->", "set_as_heading", "(", ")", ";", "}", "}" ]
Initializing table columns @param array $wanted Collection of column names @param string $heading The name of column that is set as heading
[ "Initializing", "table", "columns" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/bank/view.php#L186-L199
218,652
moodle/moodle
question/classes/bank/view.php
view.new_sort_url
public function new_sort_url($sort, $newsortreverse) { if ($newsortreverse) { $order = -1; } else { $order = 1; } // Tricky code to add the new sort at the start, removing it from where it was before, if it was present. $newsort = array_reverse($this->sort); if (isset($newsort[$sort])) { unset($newsort[$sort]); } $newsort[$sort] = $order; $newsort = array_reverse($newsort); if (count($newsort) > self::MAX_SORTS) { $newsort = array_slice($newsort, 0, self::MAX_SORTS, true); } return $this->baseurl->out(true, $this->sort_to_params($newsort)); }
php
public function new_sort_url($sort, $newsortreverse) { if ($newsortreverse) { $order = -1; } else { $order = 1; } // Tricky code to add the new sort at the start, removing it from where it was before, if it was present. $newsort = array_reverse($this->sort); if (isset($newsort[$sort])) { unset($newsort[$sort]); } $newsort[$sort] = $order; $newsort = array_reverse($newsort); if (count($newsort) > self::MAX_SORTS) { $newsort = array_slice($newsort, 0, self::MAX_SORTS, true); } return $this->baseurl->out(true, $this->sort_to_params($newsort)); }
[ "public", "function", "new_sort_url", "(", "$", "sort", ",", "$", "newsortreverse", ")", "{", "if", "(", "$", "newsortreverse", ")", "{", "$", "order", "=", "-", "1", ";", "}", "else", "{", "$", "order", "=", "1", ";", "}", "// Tricky code to add the new sort at the start, removing it from where it was before, if it was present.", "$", "newsort", "=", "array_reverse", "(", "$", "this", "->", "sort", ")", ";", "if", "(", "isset", "(", "$", "newsort", "[", "$", "sort", "]", ")", ")", "{", "unset", "(", "$", "newsort", "[", "$", "sort", "]", ")", ";", "}", "$", "newsort", "[", "$", "sort", "]", "=", "$", "order", ";", "$", "newsort", "=", "array_reverse", "(", "$", "newsort", ")", ";", "if", "(", "count", "(", "$", "newsort", ")", ">", "self", "::", "MAX_SORTS", ")", "{", "$", "newsort", "=", "array_slice", "(", "$", "newsort", ",", "0", ",", "self", "::", "MAX_SORTS", ",", "true", ")", ";", "}", "return", "$", "this", "->", "baseurl", "->", "out", "(", "true", ",", "$", "this", "->", "sort_to_params", "(", "$", "newsort", ")", ")", ";", "}" ]
Get a URL to redisplay the page with a new sort for the question bank. @param string $sort the column, or column_subsort to sort on. @param bool $newsortreverse whether to sort in reverse order. @return string The new URL.
[ "Get", "a", "URL", "to", "redisplay", "the", "page", "with", "a", "new", "sort", "for", "the", "question", "bank", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/bank/view.php#L318-L335
218,653
moodle/moodle
question/classes/bank/view.php
view.build_query
protected function build_query() { global $DB; // Get the required tables and fields. $joins = array(); $fields = array('q.hidden', 'q.category'); foreach ($this->requiredcolumns as $column) { $extrajoins = $column->get_extra_joins(); foreach ($extrajoins as $prefix => $join) { if (isset($joins[$prefix]) && $joins[$prefix] != $join) { throw new \coding_exception('Join ' . $join . ' conflicts with previous join ' . $joins[$prefix]); } $joins[$prefix] = $join; } $fields = array_merge($fields, $column->get_required_fields()); } $fields = array_unique($fields); // Build the order by clause. $sorts = array(); foreach ($this->sort as $sort => $order) { list($colname, $subsort) = $this->parse_subsort($sort); $sorts[] = $this->requiredcolumns[$colname]->sort_expression($order < 0, $subsort); } // Build the where clause. $tests = array('q.parent = 0'); $this->sqlparams = array(); foreach ($this->searchconditions as $searchcondition) { if ($searchcondition->where()) { $tests[] = '((' . $searchcondition->where() .'))'; } if ($searchcondition->params()) { $this->sqlparams = array_merge($this->sqlparams, $searchcondition->params()); } } // Build the SQL. $sql = ' FROM {question} q ' . implode(' ', $joins); $sql .= ' WHERE ' . implode(' AND ', $tests); $this->countsql = 'SELECT count(1)' . $sql; $this->loadsql = 'SELECT ' . implode(', ', $fields) . $sql . ' ORDER BY ' . implode(', ', $sorts); }
php
protected function build_query() { global $DB; // Get the required tables and fields. $joins = array(); $fields = array('q.hidden', 'q.category'); foreach ($this->requiredcolumns as $column) { $extrajoins = $column->get_extra_joins(); foreach ($extrajoins as $prefix => $join) { if (isset($joins[$prefix]) && $joins[$prefix] != $join) { throw new \coding_exception('Join ' . $join . ' conflicts with previous join ' . $joins[$prefix]); } $joins[$prefix] = $join; } $fields = array_merge($fields, $column->get_required_fields()); } $fields = array_unique($fields); // Build the order by clause. $sorts = array(); foreach ($this->sort as $sort => $order) { list($colname, $subsort) = $this->parse_subsort($sort); $sorts[] = $this->requiredcolumns[$colname]->sort_expression($order < 0, $subsort); } // Build the where clause. $tests = array('q.parent = 0'); $this->sqlparams = array(); foreach ($this->searchconditions as $searchcondition) { if ($searchcondition->where()) { $tests[] = '((' . $searchcondition->where() .'))'; } if ($searchcondition->params()) { $this->sqlparams = array_merge($this->sqlparams, $searchcondition->params()); } } // Build the SQL. $sql = ' FROM {question} q ' . implode(' ', $joins); $sql .= ' WHERE ' . implode(' AND ', $tests); $this->countsql = 'SELECT count(1)' . $sql; $this->loadsql = 'SELECT ' . implode(', ', $fields) . $sql . ' ORDER BY ' . implode(', ', $sorts); }
[ "protected", "function", "build_query", "(", ")", "{", "global", "$", "DB", ";", "// Get the required tables and fields.", "$", "joins", "=", "array", "(", ")", ";", "$", "fields", "=", "array", "(", "'q.hidden'", ",", "'q.category'", ")", ";", "foreach", "(", "$", "this", "->", "requiredcolumns", "as", "$", "column", ")", "{", "$", "extrajoins", "=", "$", "column", "->", "get_extra_joins", "(", ")", ";", "foreach", "(", "$", "extrajoins", "as", "$", "prefix", "=>", "$", "join", ")", "{", "if", "(", "isset", "(", "$", "joins", "[", "$", "prefix", "]", ")", "&&", "$", "joins", "[", "$", "prefix", "]", "!=", "$", "join", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Join '", ".", "$", "join", ".", "' conflicts with previous join '", ".", "$", "joins", "[", "$", "prefix", "]", ")", ";", "}", "$", "joins", "[", "$", "prefix", "]", "=", "$", "join", ";", "}", "$", "fields", "=", "array_merge", "(", "$", "fields", ",", "$", "column", "->", "get_required_fields", "(", ")", ")", ";", "}", "$", "fields", "=", "array_unique", "(", "$", "fields", ")", ";", "// Build the order by clause.", "$", "sorts", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "sort", "as", "$", "sort", "=>", "$", "order", ")", "{", "list", "(", "$", "colname", ",", "$", "subsort", ")", "=", "$", "this", "->", "parse_subsort", "(", "$", "sort", ")", ";", "$", "sorts", "[", "]", "=", "$", "this", "->", "requiredcolumns", "[", "$", "colname", "]", "->", "sort_expression", "(", "$", "order", "<", "0", ",", "$", "subsort", ")", ";", "}", "// Build the where clause.", "$", "tests", "=", "array", "(", "'q.parent = 0'", ")", ";", "$", "this", "->", "sqlparams", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "searchconditions", "as", "$", "searchcondition", ")", "{", "if", "(", "$", "searchcondition", "->", "where", "(", ")", ")", "{", "$", "tests", "[", "]", "=", "'(('", ".", "$", "searchcondition", "->", "where", "(", ")", ".", "'))'", ";", "}", "if", "(", "$", "searchcondition", "->", "params", "(", ")", ")", "{", "$", "this", "->", "sqlparams", "=", "array_merge", "(", "$", "this", "->", "sqlparams", ",", "$", "searchcondition", "->", "params", "(", ")", ")", ";", "}", "}", "// Build the SQL.", "$", "sql", "=", "' FROM {question} q '", ".", "implode", "(", "' '", ",", "$", "joins", ")", ";", "$", "sql", ".=", "' WHERE '", ".", "implode", "(", "' AND '", ",", "$", "tests", ")", ";", "$", "this", "->", "countsql", "=", "'SELECT count(1)'", ".", "$", "sql", ";", "$", "this", "->", "loadsql", "=", "'SELECT '", ".", "implode", "(", "', '", ",", "$", "fields", ")", ".", "$", "sql", ".", "' ORDER BY '", ".", "implode", "(", "', '", ",", "$", "sorts", ")", ";", "}" ]
Create the SQL query to retrieve the indicated questions, based on \core_question\bank\search\condition filters.
[ "Create", "the", "SQL", "query", "to", "retrieve", "the", "indicated", "questions", "based", "on", "\\", "core_question", "\\", "bank", "\\", "search", "\\", "condition", "filters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/bank/view.php#L357-L398
218,654
moodle/moodle
question/classes/bank/view.php
view.preview_question_url
public function preview_question_url($questiondata) { return question_preview_url($questiondata->id, null, null, null, null, $this->get_most_specific_context()); }
php
public function preview_question_url($questiondata) { return question_preview_url($questiondata->id, null, null, null, null, $this->get_most_specific_context()); }
[ "public", "function", "preview_question_url", "(", "$", "questiondata", ")", "{", "return", "question_preview_url", "(", "$", "questiondata", "->", "id", ",", "null", ",", "null", ",", "null", ",", "null", ",", "$", "this", "->", "get_most_specific_context", "(", ")", ")", ";", "}" ]
Get the URL to preview a question. @param stdClass $questiondata the data defining the question. @return moodle_url the URL.
[ "Get", "the", "URL", "to", "preview", "a", "question", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/bank/view.php#L446-L449
218,655
moodle/moodle
question/classes/bank/view.php
view.display
public function display($tabname, $page, $perpage, $cat, $recurse, $showhidden, $showquestiontext, $tagids = []) { global $PAGE, $CFG; if ($this->process_actions_needing_ui()) { return; } $editcontexts = $this->contexts->having_one_edit_tab_cap($tabname); list($categoryid, $contextid) = explode(',', $cat); $catcontext = \context::instance_by_id($contextid); $thiscontext = $this->get_most_specific_context(); // Category selection form. $this->display_question_bank_header(); // Display tag filter if usetags setting is enabled. if ($CFG->usetags) { array_unshift($this->searchconditions, new \core_question\bank\search\tag_condition([$catcontext, $thiscontext], $tagids)); $PAGE->requires->js_call_amd('core_question/edit_tags', 'init', ['#questionscontainer']); } array_unshift($this->searchconditions, new \core_question\bank\search\hidden_condition(!$showhidden)); array_unshift($this->searchconditions, new \core_question\bank\search\category_condition( $cat, $recurse, $editcontexts, $this->baseurl, $this->course)); $this->display_options_form($showquestiontext); // Continues with list of questions. $this->display_question_list($editcontexts, $this->baseurl, $cat, $this->cm, null, $page, $perpage, $showhidden, $showquestiontext, $this->contexts->having_cap('moodle/question:add')); }
php
public function display($tabname, $page, $perpage, $cat, $recurse, $showhidden, $showquestiontext, $tagids = []) { global $PAGE, $CFG; if ($this->process_actions_needing_ui()) { return; } $editcontexts = $this->contexts->having_one_edit_tab_cap($tabname); list($categoryid, $contextid) = explode(',', $cat); $catcontext = \context::instance_by_id($contextid); $thiscontext = $this->get_most_specific_context(); // Category selection form. $this->display_question_bank_header(); // Display tag filter if usetags setting is enabled. if ($CFG->usetags) { array_unshift($this->searchconditions, new \core_question\bank\search\tag_condition([$catcontext, $thiscontext], $tagids)); $PAGE->requires->js_call_amd('core_question/edit_tags', 'init', ['#questionscontainer']); } array_unshift($this->searchconditions, new \core_question\bank\search\hidden_condition(!$showhidden)); array_unshift($this->searchconditions, new \core_question\bank\search\category_condition( $cat, $recurse, $editcontexts, $this->baseurl, $this->course)); $this->display_options_form($showquestiontext); // Continues with list of questions. $this->display_question_list($editcontexts, $this->baseurl, $cat, $this->cm, null, $page, $perpage, $showhidden, $showquestiontext, $this->contexts->having_cap('moodle/question:add')); }
[ "public", "function", "display", "(", "$", "tabname", ",", "$", "page", ",", "$", "perpage", ",", "$", "cat", ",", "$", "recurse", ",", "$", "showhidden", ",", "$", "showquestiontext", ",", "$", "tagids", "=", "[", "]", ")", "{", "global", "$", "PAGE", ",", "$", "CFG", ";", "if", "(", "$", "this", "->", "process_actions_needing_ui", "(", ")", ")", "{", "return", ";", "}", "$", "editcontexts", "=", "$", "this", "->", "contexts", "->", "having_one_edit_tab_cap", "(", "$", "tabname", ")", ";", "list", "(", "$", "categoryid", ",", "$", "contextid", ")", "=", "explode", "(", "','", ",", "$", "cat", ")", ";", "$", "catcontext", "=", "\\", "context", "::", "instance_by_id", "(", "$", "contextid", ")", ";", "$", "thiscontext", "=", "$", "this", "->", "get_most_specific_context", "(", ")", ";", "// Category selection form.", "$", "this", "->", "display_question_bank_header", "(", ")", ";", "// Display tag filter if usetags setting is enabled.", "if", "(", "$", "CFG", "->", "usetags", ")", "{", "array_unshift", "(", "$", "this", "->", "searchconditions", ",", "new", "\\", "core_question", "\\", "bank", "\\", "search", "\\", "tag_condition", "(", "[", "$", "catcontext", ",", "$", "thiscontext", "]", ",", "$", "tagids", ")", ")", ";", "$", "PAGE", "->", "requires", "->", "js_call_amd", "(", "'core_question/edit_tags'", ",", "'init'", ",", "[", "'#questionscontainer'", "]", ")", ";", "}", "array_unshift", "(", "$", "this", "->", "searchconditions", ",", "new", "\\", "core_question", "\\", "bank", "\\", "search", "\\", "hidden_condition", "(", "!", "$", "showhidden", ")", ")", ";", "array_unshift", "(", "$", "this", "->", "searchconditions", ",", "new", "\\", "core_question", "\\", "bank", "\\", "search", "\\", "category_condition", "(", "$", "cat", ",", "$", "recurse", ",", "$", "editcontexts", ",", "$", "this", "->", "baseurl", ",", "$", "this", "->", "course", ")", ")", ";", "$", "this", "->", "display_options_form", "(", "$", "showquestiontext", ")", ";", "// Continues with list of questions.", "$", "this", "->", "display_question_list", "(", "$", "editcontexts", ",", "$", "this", "->", "baseurl", ",", "$", "cat", ",", "$", "this", "->", "cm", ",", "null", ",", "$", "page", ",", "$", "perpage", ",", "$", "showhidden", ",", "$", "showquestiontext", ",", "$", "this", "->", "contexts", "->", "having_cap", "(", "'moodle/question:add'", ")", ")", ";", "}" ]
Shows the question bank editing interface. The function also processes a number of actions: Actions affecting the question pool: move Moves a question to a different category deleteselected Deletes the selected questions from the category Other actions: category Chooses the category displayoptions Sets display options
[ "Shows", "the", "question", "bank", "editing", "interface", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/bank/view.php#L463-L495
218,656
moodle/moodle
question/classes/bank/view.php
view.print_category_info
protected function print_category_info($category) { $formatoptions = new \stdClass(); $formatoptions->noclean = true; $formatoptions->overflowdiv = true; echo '<div class="boxaligncenter">'; echo format_text($category->info, $category->infoformat, $formatoptions, $this->course->id); echo "</div>\n"; }
php
protected function print_category_info($category) { $formatoptions = new \stdClass(); $formatoptions->noclean = true; $formatoptions->overflowdiv = true; echo '<div class="boxaligncenter">'; echo format_text($category->info, $category->infoformat, $formatoptions, $this->course->id); echo "</div>\n"; }
[ "protected", "function", "print_category_info", "(", "$", "category", ")", "{", "$", "formatoptions", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "formatoptions", "->", "noclean", "=", "true", ";", "$", "formatoptions", "->", "overflowdiv", "=", "true", ";", "echo", "'<div class=\"boxaligncenter\">'", ";", "echo", "format_text", "(", "$", "category", "->", "info", ",", "$", "category", "->", "infoformat", ",", "$", "formatoptions", ",", "$", "this", "->", "course", "->", "id", ")", ";", "echo", "\"</div>\\n\"", ";", "}" ]
prints category information @param stdClass $category the category row from the database. @deprecated since Moodle 2.7 MDL-40313. @see \core_question\bank\search\condition @todo MDL-41978 This will be deleted in Moodle 2.8
[ "prints", "category", "information" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/bank/view.php#L529-L536
218,657
moodle/moodle
question/classes/bank/view.php
view.display_category_form
protected function display_category_form($contexts, $pageurl, $current) { global $OUTPUT; debugging('display_category_form() is deprecated, please use ' . '\core_question\bank\search\condition instead.', DEBUG_DEVELOPER); // Get all the existing categories now. echo '<div class="choosecategory">'; $catmenu = question_category_options($contexts, false, 0, true); $select = new \single_select($this->baseurl, 'category', $catmenu, $current, null, 'catmenu'); $select->set_label(get_string('selectacategory', 'question')); echo $OUTPUT->render($select); echo "</div>\n"; }
php
protected function display_category_form($contexts, $pageurl, $current) { global $OUTPUT; debugging('display_category_form() is deprecated, please use ' . '\core_question\bank\search\condition instead.', DEBUG_DEVELOPER); // Get all the existing categories now. echo '<div class="choosecategory">'; $catmenu = question_category_options($contexts, false, 0, true); $select = new \single_select($this->baseurl, 'category', $catmenu, $current, null, 'catmenu'); $select->set_label(get_string('selectacategory', 'question')); echo $OUTPUT->render($select); echo "</div>\n"; }
[ "protected", "function", "display_category_form", "(", "$", "contexts", ",", "$", "pageurl", ",", "$", "current", ")", "{", "global", "$", "OUTPUT", ";", "debugging", "(", "'display_category_form() is deprecated, please use '", ".", "'\\core_question\\bank\\search\\condition instead.'", ",", "DEBUG_DEVELOPER", ")", ";", "// Get all the existing categories now.", "echo", "'<div class=\"choosecategory\">'", ";", "$", "catmenu", "=", "question_category_options", "(", "$", "contexts", ",", "false", ",", "0", ",", "true", ")", ";", "$", "select", "=", "new", "\\", "single_select", "(", "$", "this", "->", "baseurl", ",", "'category'", ",", "$", "catmenu", ",", "$", "current", ",", "null", ",", "'catmenu'", ")", ";", "$", "select", "->", "set_label", "(", "get_string", "(", "'selectacategory'", ",", "'question'", ")", ")", ";", "echo", "$", "OUTPUT", "->", "render", "(", "$", "select", ")", ";", "echo", "\"</div>\\n\"", ";", "}" ]
Prints a form to choose categories @deprecated since Moodle 2.7 MDL-40313. @see \core_question\bank\search\condition @todo MDL-41978 This will be deleted in Moodle 2.8
[ "Prints", "a", "form", "to", "choose", "categories" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/bank/view.php#L544-L557
218,658
moodle/moodle
question/classes/bank/view.php
view.display_category_form_checkbox
protected function display_category_form_checkbox($name, $value, $label) { debugging('display_category_form_checkbox() is deprecated, ' . 'please use \core_question\bank\search\condition instead.', DEBUG_DEVELOPER); echo '<div><input type="hidden" id="' . $name . '_off" name="' . $name . '" value="0" />'; echo '<input type="checkbox" id="' . $name . '_on" name="' . $name . '" value="1"'; if ($value) { echo ' checked="checked"'; } echo ' onchange="getElementById(\'displayoptions\').submit(); return true;" />'; echo '<label for="' . $name . '_on">' . $label . '</label>'; echo "</div>\n"; }
php
protected function display_category_form_checkbox($name, $value, $label) { debugging('display_category_form_checkbox() is deprecated, ' . 'please use \core_question\bank\search\condition instead.', DEBUG_DEVELOPER); echo '<div><input type="hidden" id="' . $name . '_off" name="' . $name . '" value="0" />'; echo '<input type="checkbox" id="' . $name . '_on" name="' . $name . '" value="1"'; if ($value) { echo ' checked="checked"'; } echo ' onchange="getElementById(\'displayoptions\').submit(); return true;" />'; echo '<label for="' . $name . '_on">' . $label . '</label>'; echo "</div>\n"; }
[ "protected", "function", "display_category_form_checkbox", "(", "$", "name", ",", "$", "value", ",", "$", "label", ")", "{", "debugging", "(", "'display_category_form_checkbox() is deprecated, '", ".", "'please use \\core_question\\bank\\search\\condition instead.'", ",", "DEBUG_DEVELOPER", ")", ";", "echo", "'<div><input type=\"hidden\" id=\"'", ".", "$", "name", ".", "'_off\" name=\"'", ".", "$", "name", ".", "'\" value=\"0\" />'", ";", "echo", "'<input type=\"checkbox\" id=\"'", ".", "$", "name", ".", "'_on\" name=\"'", ".", "$", "name", ".", "'\" value=\"1\"'", ";", "if", "(", "$", "value", ")", "{", "echo", "' checked=\"checked\"'", ";", "}", "echo", "' onchange=\"getElementById(\\'displayoptions\\').submit(); return true;\" />'", ";", "echo", "'<label for=\"'", ".", "$", "name", ".", "'_on\">'", ".", "$", "label", ".", "'</label>'", ";", "echo", "\"</div>\\n\"", ";", "}" ]
Print a single option checkbox. @deprecated since Moodle 2.7 MDL-40313. @see \core_question\bank\search\condition @see html_writer::checkbox @todo MDL-41978 This will be deleted in Moodle 2.8
[ "Print", "a", "single", "option", "checkbox", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/bank/view.php#L581-L592
218,659
moodle/moodle
question/classes/bank/view.php
view.display_options_form
protected function display_options_form($showquestiontext, $scriptpath = '/question/edit.php', $showtextoption = true) { global $PAGE; echo \html_writer::start_tag('form', array('method' => 'get', 'action' => new \moodle_url($scriptpath), 'id' => 'displayoptions')); echo \html_writer::start_div(); $excludes = array('recurse', 'showhidden', 'qbshowtext'); // If the URL contains any tags then we need to prevent them // being added to the form as hidden elements because the tags // are managed separately. if ($this->baseurl->param('qtagids[0]')) { $index = 0; while ($this->baseurl->param("qtagids[{$index}]")) { $excludes[] = "qtagids[{$index}]"; $index++; } } echo \html_writer::input_hidden_params($this->baseurl, $excludes); foreach ($this->searchconditions as $searchcondition) { echo $searchcondition->display_options($this); } if ($showtextoption) { $this->display_showtext_checkbox($showquestiontext); } $this->display_advanced_search_form(); $go = \html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('go'))); echo \html_writer::tag('noscript', \html_writer::div($go), array('class' => 'inline')); echo \html_writer::end_div(); echo \html_writer::end_tag('form'); $PAGE->requires->yui_module('moodle-question-searchform', 'M.question.searchform.init'); }
php
protected function display_options_form($showquestiontext, $scriptpath = '/question/edit.php', $showtextoption = true) { global $PAGE; echo \html_writer::start_tag('form', array('method' => 'get', 'action' => new \moodle_url($scriptpath), 'id' => 'displayoptions')); echo \html_writer::start_div(); $excludes = array('recurse', 'showhidden', 'qbshowtext'); // If the URL contains any tags then we need to prevent them // being added to the form as hidden elements because the tags // are managed separately. if ($this->baseurl->param('qtagids[0]')) { $index = 0; while ($this->baseurl->param("qtagids[{$index}]")) { $excludes[] = "qtagids[{$index}]"; $index++; } } echo \html_writer::input_hidden_params($this->baseurl, $excludes); foreach ($this->searchconditions as $searchcondition) { echo $searchcondition->display_options($this); } if ($showtextoption) { $this->display_showtext_checkbox($showquestiontext); } $this->display_advanced_search_form(); $go = \html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('go'))); echo \html_writer::tag('noscript', \html_writer::div($go), array('class' => 'inline')); echo \html_writer::end_div(); echo \html_writer::end_tag('form'); $PAGE->requires->yui_module('moodle-question-searchform', 'M.question.searchform.init'); }
[ "protected", "function", "display_options_form", "(", "$", "showquestiontext", ",", "$", "scriptpath", "=", "'/question/edit.php'", ",", "$", "showtextoption", "=", "true", ")", "{", "global", "$", "PAGE", ";", "echo", "\\", "html_writer", "::", "start_tag", "(", "'form'", ",", "array", "(", "'method'", "=>", "'get'", ",", "'action'", "=>", "new", "\\", "moodle_url", "(", "$", "scriptpath", ")", ",", "'id'", "=>", "'displayoptions'", ")", ")", ";", "echo", "\\", "html_writer", "::", "start_div", "(", ")", ";", "$", "excludes", "=", "array", "(", "'recurse'", ",", "'showhidden'", ",", "'qbshowtext'", ")", ";", "// If the URL contains any tags then we need to prevent them", "// being added to the form as hidden elements because the tags", "// are managed separately.", "if", "(", "$", "this", "->", "baseurl", "->", "param", "(", "'qtagids[0]'", ")", ")", "{", "$", "index", "=", "0", ";", "while", "(", "$", "this", "->", "baseurl", "->", "param", "(", "\"qtagids[{$index}]\"", ")", ")", "{", "$", "excludes", "[", "]", "=", "\"qtagids[{$index}]\"", ";", "$", "index", "++", ";", "}", "}", "echo", "\\", "html_writer", "::", "input_hidden_params", "(", "$", "this", "->", "baseurl", ",", "$", "excludes", ")", ";", "foreach", "(", "$", "this", "->", "searchconditions", "as", "$", "searchcondition", ")", "{", "echo", "$", "searchcondition", "->", "display_options", "(", "$", "this", ")", ";", "}", "if", "(", "$", "showtextoption", ")", "{", "$", "this", "->", "display_showtext_checkbox", "(", "$", "showquestiontext", ")", ";", "}", "$", "this", "->", "display_advanced_search_form", "(", ")", ";", "$", "go", "=", "\\", "html_writer", "::", "empty_tag", "(", "'input'", ",", "array", "(", "'type'", "=>", "'submit'", ",", "'value'", "=>", "get_string", "(", "'go'", ")", ")", ")", ";", "echo", "\\", "html_writer", "::", "tag", "(", "'noscript'", ",", "\\", "html_writer", "::", "div", "(", "$", "go", ")", ",", "array", "(", "'class'", "=>", "'inline'", ")", ")", ";", "echo", "\\", "html_writer", "::", "end_div", "(", ")", ";", "echo", "\\", "html_writer", "::", "end_tag", "(", "'form'", ")", ";", "$", "PAGE", "->", "requires", "->", "yui_module", "(", "'moodle-question-searchform'", ",", "'M.question.searchform.init'", ")", ";", "}" ]
Display the form with options for which questions are displayed and how they are displayed. @param bool $showquestiontext Display the text of the question within the list. @param string $path path to the script displaying this page. @param bool $showtextoption whether to include the 'Show question text' checkbox.
[ "Display", "the", "form", "with", "options", "for", "which", "questions", "are", "displayed", "and", "how", "they", "are", "displayed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/bank/view.php#L600-L633
218,660
moodle/moodle
question/classes/bank/view.php
view.display_advanced_search_form
protected function display_advanced_search_form() { print_collapsible_region_start('', 'advancedsearch', get_string('advancedsearchoptions', 'question'), 'question_bank_advanced_search'); foreach ($this->searchconditions as $searchcondition) { echo $searchcondition->display_options_adv($this); } print_collapsible_region_end(); }
php
protected function display_advanced_search_form() { print_collapsible_region_start('', 'advancedsearch', get_string('advancedsearchoptions', 'question'), 'question_bank_advanced_search'); foreach ($this->searchconditions as $searchcondition) { echo $searchcondition->display_options_adv($this); } print_collapsible_region_end(); }
[ "protected", "function", "display_advanced_search_form", "(", ")", "{", "print_collapsible_region_start", "(", "''", ",", "'advancedsearch'", ",", "get_string", "(", "'advancedsearchoptions'", ",", "'question'", ")", ",", "'question_bank_advanced_search'", ")", ";", "foreach", "(", "$", "this", "->", "searchconditions", "as", "$", "searchcondition", ")", "{", "echo", "$", "searchcondition", "->", "display_options_adv", "(", "$", "this", ")", ";", "}", "print_collapsible_region_end", "(", ")", ";", "}" ]
Print the "advanced" UI elements for the form to select which questions. Hidden by default.
[ "Print", "the", "advanced", "UI", "elements", "for", "the", "form", "to", "select", "which", "questions", ".", "Hidden", "by", "default", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/bank/view.php#L638-L645
218,661
moodle/moodle
mod/wiki/classes/privacy/provider.php
provider.export_subwiki
protected static function export_subwiki($user, context $context, $subwiki, $wikimode) { if (empty($subwiki)) { return; } $subwikiid = key($subwiki); $pages = $subwiki[$subwikiid]['pages']; unset($subwiki[$subwikiid]['pages']); writer::with_context($context)->export_data([$subwikiid], (object)$subwiki[$subwikiid]); $allfiles = $wikimode === 'individual'; // Whether to export all files or only the ones that are used. $alltexts = ''; // Store all texts that reference files to search which files are used. foreach ($pages as $page => $entry) { // Preprocess current page contents. if (!$allfiles && self::text_has_files($entry['page']['cachedcontent'])) { $alltexts .= $entry['page']['cachedcontent']; } $entry['page']['cachedcontent'] = format_text(writer::with_context($context) ->rewrite_pluginfile_urls([$subwikiid], 'mod_wiki', 'attachments', $subwikiid, $entry['page']['cachedcontent']), FORMAT_HTML, ['context' => $context]); // Add page tags. $pagetags = \core_tag_tag::get_item_tags_array('mod_wiki', 'page', $entry['page']['id']); if ($pagetags) { $entry['page']['tags'] = $pagetags; } // Preprocess revisions. if (!empty($entry['revisions'])) { // For each revision this user has made preprocess the contents. foreach ($entry['revisions'] as &$revision) { if ((!$allfiles && self::text_has_files($revision['content']))) { $alltexts .= $revision['content']; } $revision['content'] = writer::with_context($context) ->rewrite_pluginfile_urls([$subwikiid], 'mod_wiki', 'attachments', $subwikiid, $revision['content']); } } $comments = self::get_page_comments($user, $context, $entry['page']['id'], !array_key_exists('userid', $entry['page'])); if ($comments) { $entry['page']['comments'] = $comments; } writer::with_context($context)->export_related_data([$subwikiid], $page, $entry); } if ($allfiles) { // Export all files. writer::with_context($context)->export_area_files([$subwikiid], 'mod_wiki', 'attachments', $subwikiid); } else { // Analyze which files are used in the texts. self::export_used_files($context, $subwikiid, $alltexts); } }
php
protected static function export_subwiki($user, context $context, $subwiki, $wikimode) { if (empty($subwiki)) { return; } $subwikiid = key($subwiki); $pages = $subwiki[$subwikiid]['pages']; unset($subwiki[$subwikiid]['pages']); writer::with_context($context)->export_data([$subwikiid], (object)$subwiki[$subwikiid]); $allfiles = $wikimode === 'individual'; // Whether to export all files or only the ones that are used. $alltexts = ''; // Store all texts that reference files to search which files are used. foreach ($pages as $page => $entry) { // Preprocess current page contents. if (!$allfiles && self::text_has_files($entry['page']['cachedcontent'])) { $alltexts .= $entry['page']['cachedcontent']; } $entry['page']['cachedcontent'] = format_text(writer::with_context($context) ->rewrite_pluginfile_urls([$subwikiid], 'mod_wiki', 'attachments', $subwikiid, $entry['page']['cachedcontent']), FORMAT_HTML, ['context' => $context]); // Add page tags. $pagetags = \core_tag_tag::get_item_tags_array('mod_wiki', 'page', $entry['page']['id']); if ($pagetags) { $entry['page']['tags'] = $pagetags; } // Preprocess revisions. if (!empty($entry['revisions'])) { // For each revision this user has made preprocess the contents. foreach ($entry['revisions'] as &$revision) { if ((!$allfiles && self::text_has_files($revision['content']))) { $alltexts .= $revision['content']; } $revision['content'] = writer::with_context($context) ->rewrite_pluginfile_urls([$subwikiid], 'mod_wiki', 'attachments', $subwikiid, $revision['content']); } } $comments = self::get_page_comments($user, $context, $entry['page']['id'], !array_key_exists('userid', $entry['page'])); if ($comments) { $entry['page']['comments'] = $comments; } writer::with_context($context)->export_related_data([$subwikiid], $page, $entry); } if ($allfiles) { // Export all files. writer::with_context($context)->export_area_files([$subwikiid], 'mod_wiki', 'attachments', $subwikiid); } else { // Analyze which files are used in the texts. self::export_used_files($context, $subwikiid, $alltexts); } }
[ "protected", "static", "function", "export_subwiki", "(", "$", "user", ",", "context", "$", "context", ",", "$", "subwiki", ",", "$", "wikimode", ")", "{", "if", "(", "empty", "(", "$", "subwiki", ")", ")", "{", "return", ";", "}", "$", "subwikiid", "=", "key", "(", "$", "subwiki", ")", ";", "$", "pages", "=", "$", "subwiki", "[", "$", "subwikiid", "]", "[", "'pages'", "]", ";", "unset", "(", "$", "subwiki", "[", "$", "subwikiid", "]", "[", "'pages'", "]", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "[", "$", "subwikiid", "]", ",", "(", "object", ")", "$", "subwiki", "[", "$", "subwikiid", "]", ")", ";", "$", "allfiles", "=", "$", "wikimode", "===", "'individual'", ";", "// Whether to export all files or only the ones that are used.", "$", "alltexts", "=", "''", ";", "// Store all texts that reference files to search which files are used.", "foreach", "(", "$", "pages", "as", "$", "page", "=>", "$", "entry", ")", "{", "// Preprocess current page contents.", "if", "(", "!", "$", "allfiles", "&&", "self", "::", "text_has_files", "(", "$", "entry", "[", "'page'", "]", "[", "'cachedcontent'", "]", ")", ")", "{", "$", "alltexts", ".=", "$", "entry", "[", "'page'", "]", "[", "'cachedcontent'", "]", ";", "}", "$", "entry", "[", "'page'", "]", "[", "'cachedcontent'", "]", "=", "format_text", "(", "writer", "::", "with_context", "(", "$", "context", ")", "->", "rewrite_pluginfile_urls", "(", "[", "$", "subwikiid", "]", ",", "'mod_wiki'", ",", "'attachments'", ",", "$", "subwikiid", ",", "$", "entry", "[", "'page'", "]", "[", "'cachedcontent'", "]", ")", ",", "FORMAT_HTML", ",", "[", "'context'", "=>", "$", "context", "]", ")", ";", "// Add page tags.", "$", "pagetags", "=", "\\", "core_tag_tag", "::", "get_item_tags_array", "(", "'mod_wiki'", ",", "'page'", ",", "$", "entry", "[", "'page'", "]", "[", "'id'", "]", ")", ";", "if", "(", "$", "pagetags", ")", "{", "$", "entry", "[", "'page'", "]", "[", "'tags'", "]", "=", "$", "pagetags", ";", "}", "// Preprocess revisions.", "if", "(", "!", "empty", "(", "$", "entry", "[", "'revisions'", "]", ")", ")", "{", "// For each revision this user has made preprocess the contents.", "foreach", "(", "$", "entry", "[", "'revisions'", "]", "as", "&", "$", "revision", ")", "{", "if", "(", "(", "!", "$", "allfiles", "&&", "self", "::", "text_has_files", "(", "$", "revision", "[", "'content'", "]", ")", ")", ")", "{", "$", "alltexts", ".=", "$", "revision", "[", "'content'", "]", ";", "}", "$", "revision", "[", "'content'", "]", "=", "writer", "::", "with_context", "(", "$", "context", ")", "->", "rewrite_pluginfile_urls", "(", "[", "$", "subwikiid", "]", ",", "'mod_wiki'", ",", "'attachments'", ",", "$", "subwikiid", ",", "$", "revision", "[", "'content'", "]", ")", ";", "}", "}", "$", "comments", "=", "self", "::", "get_page_comments", "(", "$", "user", ",", "$", "context", ",", "$", "entry", "[", "'page'", "]", "[", "'id'", "]", ",", "!", "array_key_exists", "(", "'userid'", ",", "$", "entry", "[", "'page'", "]", ")", ")", ";", "if", "(", "$", "comments", ")", "{", "$", "entry", "[", "'page'", "]", "[", "'comments'", "]", "=", "$", "comments", ";", "}", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_related_data", "(", "[", "$", "subwikiid", "]", ",", "$", "page", ",", "$", "entry", ")", ";", "}", "if", "(", "$", "allfiles", ")", "{", "// Export all files.", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_area_files", "(", "[", "$", "subwikiid", "]", ",", "'mod_wiki'", ",", "'attachments'", ",", "$", "subwikiid", ")", ";", "}", "else", "{", "// Analyze which files are used in the texts.", "self", "::", "export_used_files", "(", "$", "context", ",", "$", "subwikiid", ",", "$", "alltexts", ")", ";", "}", "}" ]
Add one subwiki to the export Each page is added as related data because all pages in one subwiki share the same filearea @param stdClass $user @param context $context @param array $subwiki @param string $wikimode
[ "Add", "one", "subwiki", "to", "the", "export" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/privacy/provider.php#L200-L250
218,662
moodle/moodle
mod/wiki/classes/privacy/provider.php
provider.get_page_comments
protected static function get_page_comments($user, \context $context, $pageid, $onlyforthisuser = true) { global $USER, $DB; $params = [ 'contextid' => $context->id, 'commentarea' => 'wiki_page', 'itemid' => $pageid ]; $sql = "SELECT c.id, c.content, c.format, c.timecreated, c.userid FROM {comments} c WHERE c.contextid = :contextid AND c.commentarea = :commentarea AND c.itemid = :itemid"; if ($onlyforthisuser) { $sql .= " AND c.userid = :userid"; $params['userid'] = $USER->id; } $sql .= " ORDER BY c.timecreated DESC"; $rs = $DB->get_recordset_sql($sql, $params); $comments = []; foreach ($rs as $record) { if ($record->userid != $user->id) { // Clean HTML in comments that were added by other users. $comment = ['content' => format_text($record->content, $record->format, ['context' => $context])]; } else { // Export comments made by this user as they are stored. $comment = ['content' => $record->content, 'contentformat' => $record->format]; } $comment += [ 'time' => transform::datetime($record->timecreated), 'userid' => transform::user($record->userid), ]; $comments[] = (object)$comment; } $rs->close(); return $comments; }
php
protected static function get_page_comments($user, \context $context, $pageid, $onlyforthisuser = true) { global $USER, $DB; $params = [ 'contextid' => $context->id, 'commentarea' => 'wiki_page', 'itemid' => $pageid ]; $sql = "SELECT c.id, c.content, c.format, c.timecreated, c.userid FROM {comments} c WHERE c.contextid = :contextid AND c.commentarea = :commentarea AND c.itemid = :itemid"; if ($onlyforthisuser) { $sql .= " AND c.userid = :userid"; $params['userid'] = $USER->id; } $sql .= " ORDER BY c.timecreated DESC"; $rs = $DB->get_recordset_sql($sql, $params); $comments = []; foreach ($rs as $record) { if ($record->userid != $user->id) { // Clean HTML in comments that were added by other users. $comment = ['content' => format_text($record->content, $record->format, ['context' => $context])]; } else { // Export comments made by this user as they are stored. $comment = ['content' => $record->content, 'contentformat' => $record->format]; } $comment += [ 'time' => transform::datetime($record->timecreated), 'userid' => transform::user($record->userid), ]; $comments[] = (object)$comment; } $rs->close(); return $comments; }
[ "protected", "static", "function", "get_page_comments", "(", "$", "user", ",", "\\", "context", "$", "context", ",", "$", "pageid", ",", "$", "onlyforthisuser", "=", "true", ")", "{", "global", "$", "USER", ",", "$", "DB", ";", "$", "params", "=", "[", "'contextid'", "=>", "$", "context", "->", "id", ",", "'commentarea'", "=>", "'wiki_page'", ",", "'itemid'", "=>", "$", "pageid", "]", ";", "$", "sql", "=", "\"SELECT c.id, c.content, c.format, c.timecreated, c.userid\n FROM {comments} c\n WHERE c.contextid = :contextid AND\n c.commentarea = :commentarea AND\n c.itemid = :itemid\"", ";", "if", "(", "$", "onlyforthisuser", ")", "{", "$", "sql", ".=", "\" AND c.userid = :userid\"", ";", "$", "params", "[", "'userid'", "]", "=", "$", "USER", "->", "id", ";", "}", "$", "sql", ".=", "\" ORDER BY c.timecreated DESC\"", ";", "$", "rs", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "comments", "=", "[", "]", ";", "foreach", "(", "$", "rs", "as", "$", "record", ")", "{", "if", "(", "$", "record", "->", "userid", "!=", "$", "user", "->", "id", ")", "{", "// Clean HTML in comments that were added by other users.", "$", "comment", "=", "[", "'content'", "=>", "format_text", "(", "$", "record", "->", "content", ",", "$", "record", "->", "format", ",", "[", "'context'", "=>", "$", "context", "]", ")", "]", ";", "}", "else", "{", "// Export comments made by this user as they are stored.", "$", "comment", "=", "[", "'content'", "=>", "$", "record", "->", "content", ",", "'contentformat'", "=>", "$", "record", "->", "format", "]", ";", "}", "$", "comment", "+=", "[", "'time'", "=>", "transform", "::", "datetime", "(", "$", "record", "->", "timecreated", ")", ",", "'userid'", "=>", "transform", "::", "user", "(", "$", "record", "->", "userid", ")", ",", "]", ";", "$", "comments", "[", "]", "=", "(", "object", ")", "$", "comment", ";", "}", "$", "rs", "->", "close", "(", ")", ";", "return", "$", "comments", ";", "}" ]
Retrieves page comments We can not use \core_comment\privacy\provider::export_comments() because it expects each item to have a separate subcontext and we store wiki pages as related data to subwiki because the files are shared between pages. @param stdClass $user @param \context $context @param int $pageid @param bool $onlyforthisuser @return array
[ "Retrieves", "page", "comments" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/privacy/provider.php#L264-L300
218,663
moodle/moodle
mod/wiki/classes/privacy/provider.php
provider.export_used_files
protected static function export_used_files($context, $subwikiid, $alltexts) { if (!self::text_has_files($alltexts)) { return; } $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'mod_wiki', 'attachments', $subwikiid, 'filepath, filename', false); if (empty($files)) { return; } usort($files, function($file1, $file2) { return strcmp($file2->get_filepath(), $file1->get_filename()); }); foreach ($files as $file) { $filepath = $file->get_filepath() . $file->get_filename(); $needles = ['@@PLUGINFILE@@' . s($filepath), '@@PLUGINFILE@@' . $filepath, '@@PLUGINFILE@@' . str_replace(' ', '%20', $filepath), '@@PLUGINFILE@@' . s($filepath), '@@PLUGINFILE@@' . s(str_replace(' ', '%20', $filepath)) ]; $needles = array_unique($needles); $newtext = str_replace($needles, '', $alltexts); if ($newtext !== $alltexts) { $alltexts = $newtext; writer::with_context($context)->export_file([$subwikiid], $file); if (!self::text_has_files($alltexts)) { return; } } } }
php
protected static function export_used_files($context, $subwikiid, $alltexts) { if (!self::text_has_files($alltexts)) { return; } $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'mod_wiki', 'attachments', $subwikiid, 'filepath, filename', false); if (empty($files)) { return; } usort($files, function($file1, $file2) { return strcmp($file2->get_filepath(), $file1->get_filename()); }); foreach ($files as $file) { $filepath = $file->get_filepath() . $file->get_filename(); $needles = ['@@PLUGINFILE@@' . s($filepath), '@@PLUGINFILE@@' . $filepath, '@@PLUGINFILE@@' . str_replace(' ', '%20', $filepath), '@@PLUGINFILE@@' . s($filepath), '@@PLUGINFILE@@' . s(str_replace(' ', '%20', $filepath)) ]; $needles = array_unique($needles); $newtext = str_replace($needles, '', $alltexts); if ($newtext !== $alltexts) { $alltexts = $newtext; writer::with_context($context)->export_file([$subwikiid], $file); if (!self::text_has_files($alltexts)) { return; } } } }
[ "protected", "static", "function", "export_used_files", "(", "$", "context", ",", "$", "subwikiid", ",", "$", "alltexts", ")", "{", "if", "(", "!", "self", "::", "text_has_files", "(", "$", "alltexts", ")", ")", "{", "return", ";", "}", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'mod_wiki'", ",", "'attachments'", ",", "$", "subwikiid", ",", "'filepath, filename'", ",", "false", ")", ";", "if", "(", "empty", "(", "$", "files", ")", ")", "{", "return", ";", "}", "usort", "(", "$", "files", ",", "function", "(", "$", "file1", ",", "$", "file2", ")", "{", "return", "strcmp", "(", "$", "file2", "->", "get_filepath", "(", ")", ",", "$", "file1", "->", "get_filename", "(", ")", ")", ";", "}", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "filepath", "=", "$", "file", "->", "get_filepath", "(", ")", ".", "$", "file", "->", "get_filename", "(", ")", ";", "$", "needles", "=", "[", "'@@PLUGINFILE@@'", ".", "s", "(", "$", "filepath", ")", ",", "'@@PLUGINFILE@@'", ".", "$", "filepath", ",", "'@@PLUGINFILE@@'", ".", "str_replace", "(", "' '", ",", "'%20'", ",", "$", "filepath", ")", ",", "'@@PLUGINFILE@@'", ".", "s", "(", "$", "filepath", ")", ",", "'@@PLUGINFILE@@'", ".", "s", "(", "str_replace", "(", "' '", ",", "'%20'", ",", "$", "filepath", ")", ")", "]", ";", "$", "needles", "=", "array_unique", "(", "$", "needles", ")", ";", "$", "newtext", "=", "str_replace", "(", "$", "needles", ",", "''", ",", "$", "alltexts", ")", ";", "if", "(", "$", "newtext", "!==", "$", "alltexts", ")", "{", "$", "alltexts", "=", "$", "newtext", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_file", "(", "[", "$", "subwikiid", "]", ",", "$", "file", ")", ";", "if", "(", "!", "self", "::", "text_has_files", "(", "$", "alltexts", ")", ")", "{", "return", ";", "}", "}", "}", "}" ]
Analyze which files are used in the texts and export @param context $context @param int $subwikiid @param string $alltexts @return int|void
[ "Analyze", "which", "files", "are", "used", "in", "the", "texts", "and", "export" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/privacy/provider.php#L319-L350
218,664
moodle/moodle
admin/tool/capability/renderer.php
tool_capability_renderer.get_permission_strings
protected function get_permission_strings() { static $strpermissions; if (!$strpermissions) { $strpermissions = array( CAP_INHERIT => new lang_string('inherit', 'role'), CAP_ALLOW => new lang_string('allow', 'role'), CAP_PREVENT => new lang_string('prevent', 'role'), CAP_PROHIBIT => new lang_string('prohibit', 'role') ); } return $strpermissions; }
php
protected function get_permission_strings() { static $strpermissions; if (!$strpermissions) { $strpermissions = array( CAP_INHERIT => new lang_string('inherit', 'role'), CAP_ALLOW => new lang_string('allow', 'role'), CAP_PREVENT => new lang_string('prevent', 'role'), CAP_PROHIBIT => new lang_string('prohibit', 'role') ); } return $strpermissions; }
[ "protected", "function", "get_permission_strings", "(", ")", "{", "static", "$", "strpermissions", ";", "if", "(", "!", "$", "strpermissions", ")", "{", "$", "strpermissions", "=", "array", "(", "CAP_INHERIT", "=>", "new", "lang_string", "(", "'inherit'", ",", "'role'", ")", ",", "CAP_ALLOW", "=>", "new", "lang_string", "(", "'allow'", ",", "'role'", ")", ",", "CAP_PREVENT", "=>", "new", "lang_string", "(", "'prevent'", ",", "'role'", ")", ",", "CAP_PROHIBIT", "=>", "new", "lang_string", "(", "'prohibit'", ",", "'role'", ")", ")", ";", "}", "return", "$", "strpermissions", ";", "}" ]
Returns an array of permission strings. @return lang_string[]
[ "Returns", "an", "array", "of", "permission", "strings", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/capability/renderer.php#L38-L49
218,665
moodle/moodle
admin/tool/capability/renderer.php
tool_capability_renderer.capability_comparison_table
public function capability_comparison_table(array $capabilities, $contextid, array $roles) { $strpermissions = $this->get_permission_strings(); $permissionclasses = $this->get_permission_classes(); if ($contextid === context_system::instance()->id) { $strpermissions[CAP_INHERIT] = new lang_string('notset', 'role'); } $table = new html_table(); $table->attributes['class'] = 'comparisontable'; $table->head = array('&nbsp;'); foreach ($roles as $role) { $url = new moodle_url('/admin/roles/define.php', array('action' => 'view', 'roleid' => $role->id)); $table->head[] = html_writer::div(html_writer::link($url, $role->localname)); } $table->data = array(); foreach ($capabilities as $capability) { $contexts = tool_capability_calculate_role_data($capability, $roles); $captitle = new html_table_cell(get_capability_string($capability) . html_writer::span($capability)); $captitle->header = true; $row = new html_table_row(array($captitle)); foreach ($roles as $role) { if (isset($contexts[$contextid]->rolecapabilities[$role->id])) { $permission = $contexts[$contextid]->rolecapabilities[$role->id]; } else { $permission = CAP_INHERIT; } $cell = new html_table_cell($strpermissions[$permission]); $cell->attributes['class'] = $permissionclasses[$permission]; $row->cells[] = $cell; } $table->data[] = $row; } // Start the list item, and print the context name as a link to the place to make changes. if ($contextid == context_system::instance()->id) { $url = new moodle_url('/admin/roles/manage.php'); $title = get_string('changeroles', 'tool_capability'); } else { $url = new moodle_url('/admin/roles/override.php', array('contextid' => $contextid)); $title = get_string('changeoverrides', 'tool_capability'); } $context = context::instance_by_id($contextid); $html = $this->output->heading(html_writer::link($url, $context->get_context_name(), array('title' => $title)), 3); $html .= html_writer::table($table); // If there are any child contexts, print them recursively. if (!empty($contexts[$contextid]->children)) { foreach ($contexts[$contextid]->children as $childcontextid) { $html .= $this->capability_comparison_table($capabilities, $childcontextid, $roles, true); } } return $html; }
php
public function capability_comparison_table(array $capabilities, $contextid, array $roles) { $strpermissions = $this->get_permission_strings(); $permissionclasses = $this->get_permission_classes(); if ($contextid === context_system::instance()->id) { $strpermissions[CAP_INHERIT] = new lang_string('notset', 'role'); } $table = new html_table(); $table->attributes['class'] = 'comparisontable'; $table->head = array('&nbsp;'); foreach ($roles as $role) { $url = new moodle_url('/admin/roles/define.php', array('action' => 'view', 'roleid' => $role->id)); $table->head[] = html_writer::div(html_writer::link($url, $role->localname)); } $table->data = array(); foreach ($capabilities as $capability) { $contexts = tool_capability_calculate_role_data($capability, $roles); $captitle = new html_table_cell(get_capability_string($capability) . html_writer::span($capability)); $captitle->header = true; $row = new html_table_row(array($captitle)); foreach ($roles as $role) { if (isset($contexts[$contextid]->rolecapabilities[$role->id])) { $permission = $contexts[$contextid]->rolecapabilities[$role->id]; } else { $permission = CAP_INHERIT; } $cell = new html_table_cell($strpermissions[$permission]); $cell->attributes['class'] = $permissionclasses[$permission]; $row->cells[] = $cell; } $table->data[] = $row; } // Start the list item, and print the context name as a link to the place to make changes. if ($contextid == context_system::instance()->id) { $url = new moodle_url('/admin/roles/manage.php'); $title = get_string('changeroles', 'tool_capability'); } else { $url = new moodle_url('/admin/roles/override.php', array('contextid' => $contextid)); $title = get_string('changeoverrides', 'tool_capability'); } $context = context::instance_by_id($contextid); $html = $this->output->heading(html_writer::link($url, $context->get_context_name(), array('title' => $title)), 3); $html .= html_writer::table($table); // If there are any child contexts, print them recursively. if (!empty($contexts[$contextid]->children)) { foreach ($contexts[$contextid]->children as $childcontextid) { $html .= $this->capability_comparison_table($capabilities, $childcontextid, $roles, true); } } return $html; }
[ "public", "function", "capability_comparison_table", "(", "array", "$", "capabilities", ",", "$", "contextid", ",", "array", "$", "roles", ")", "{", "$", "strpermissions", "=", "$", "this", "->", "get_permission_strings", "(", ")", ";", "$", "permissionclasses", "=", "$", "this", "->", "get_permission_classes", "(", ")", ";", "if", "(", "$", "contextid", "===", "context_system", "::", "instance", "(", ")", "->", "id", ")", "{", "$", "strpermissions", "[", "CAP_INHERIT", "]", "=", "new", "lang_string", "(", "'notset'", ",", "'role'", ")", ";", "}", "$", "table", "=", "new", "html_table", "(", ")", ";", "$", "table", "->", "attributes", "[", "'class'", "]", "=", "'comparisontable'", ";", "$", "table", "->", "head", "=", "array", "(", "'&nbsp;'", ")", ";", "foreach", "(", "$", "roles", "as", "$", "role", ")", "{", "$", "url", "=", "new", "moodle_url", "(", "'/admin/roles/define.php'", ",", "array", "(", "'action'", "=>", "'view'", ",", "'roleid'", "=>", "$", "role", "->", "id", ")", ")", ";", "$", "table", "->", "head", "[", "]", "=", "html_writer", "::", "div", "(", "html_writer", "::", "link", "(", "$", "url", ",", "$", "role", "->", "localname", ")", ")", ";", "}", "$", "table", "->", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "capabilities", "as", "$", "capability", ")", "{", "$", "contexts", "=", "tool_capability_calculate_role_data", "(", "$", "capability", ",", "$", "roles", ")", ";", "$", "captitle", "=", "new", "html_table_cell", "(", "get_capability_string", "(", "$", "capability", ")", ".", "html_writer", "::", "span", "(", "$", "capability", ")", ")", ";", "$", "captitle", "->", "header", "=", "true", ";", "$", "row", "=", "new", "html_table_row", "(", "array", "(", "$", "captitle", ")", ")", ";", "foreach", "(", "$", "roles", "as", "$", "role", ")", "{", "if", "(", "isset", "(", "$", "contexts", "[", "$", "contextid", "]", "->", "rolecapabilities", "[", "$", "role", "->", "id", "]", ")", ")", "{", "$", "permission", "=", "$", "contexts", "[", "$", "contextid", "]", "->", "rolecapabilities", "[", "$", "role", "->", "id", "]", ";", "}", "else", "{", "$", "permission", "=", "CAP_INHERIT", ";", "}", "$", "cell", "=", "new", "html_table_cell", "(", "$", "strpermissions", "[", "$", "permission", "]", ")", ";", "$", "cell", "->", "attributes", "[", "'class'", "]", "=", "$", "permissionclasses", "[", "$", "permission", "]", ";", "$", "row", "->", "cells", "[", "]", "=", "$", "cell", ";", "}", "$", "table", "->", "data", "[", "]", "=", "$", "row", ";", "}", "// Start the list item, and print the context name as a link to the place to make changes.", "if", "(", "$", "contextid", "==", "context_system", "::", "instance", "(", ")", "->", "id", ")", "{", "$", "url", "=", "new", "moodle_url", "(", "'/admin/roles/manage.php'", ")", ";", "$", "title", "=", "get_string", "(", "'changeroles'", ",", "'tool_capability'", ")", ";", "}", "else", "{", "$", "url", "=", "new", "moodle_url", "(", "'/admin/roles/override.php'", ",", "array", "(", "'contextid'", "=>", "$", "contextid", ")", ")", ";", "$", "title", "=", "get_string", "(", "'changeoverrides'", ",", "'tool_capability'", ")", ";", "}", "$", "context", "=", "context", "::", "instance_by_id", "(", "$", "contextid", ")", ";", "$", "html", "=", "$", "this", "->", "output", "->", "heading", "(", "html_writer", "::", "link", "(", "$", "url", ",", "$", "context", "->", "get_context_name", "(", ")", ",", "array", "(", "'title'", "=>", "$", "title", ")", ")", ",", "3", ")", ";", "$", "html", ".=", "html_writer", "::", "table", "(", "$", "table", ")", ";", "// If there are any child contexts, print them recursively.", "if", "(", "!", "empty", "(", "$", "contexts", "[", "$", "contextid", "]", "->", "children", ")", ")", "{", "foreach", "(", "$", "contexts", "[", "$", "contextid", "]", "->", "children", "as", "$", "childcontextid", ")", "{", "$", "html", ".=", "$", "this", "->", "capability_comparison_table", "(", "$", "capabilities", ",", "$", "childcontextid", ",", "$", "roles", ",", "true", ")", ";", "}", "}", "return", "$", "html", ";", "}" ]
Produces a table to visually compare roles and capabilities. @param array $capabilities An array of capabilities to show comparison for. @param int $contextid The context we are displaying for. @param array $roles An array of roles to show comparison for. @return string
[ "Produces", "a", "table", "to", "visually", "compare", "roles", "and", "capabilities", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/capability/renderer.php#L77-L134
218,666
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Namespace/List.php
Horde_Imap_Client_Namespace_List.getNamespace
public function getNamespace($mbox, $personal = false) { $mbox = strval($mbox); if ($ns = $this[$mbox]) { return $ns; } foreach ($this->_ns as $val) { $mbox = $mbox . $val->delimiter; if (strlen($val->name) && (strpos($mbox, $val->name) === 0)) { return $val; } } return (($ns = $this['']) && (!$personal || ($ns->type === $ns::NS_PERSONAL))) ? $ns : null; }
php
public function getNamespace($mbox, $personal = false) { $mbox = strval($mbox); if ($ns = $this[$mbox]) { return $ns; } foreach ($this->_ns as $val) { $mbox = $mbox . $val->delimiter; if (strlen($val->name) && (strpos($mbox, $val->name) === 0)) { return $val; } } return (($ns = $this['']) && (!$personal || ($ns->type === $ns::NS_PERSONAL))) ? $ns : null; }
[ "public", "function", "getNamespace", "(", "$", "mbox", ",", "$", "personal", "=", "false", ")", "{", "$", "mbox", "=", "strval", "(", "$", "mbox", ")", ";", "if", "(", "$", "ns", "=", "$", "this", "[", "$", "mbox", "]", ")", "{", "return", "$", "ns", ";", "}", "foreach", "(", "$", "this", "->", "_ns", "as", "$", "val", ")", "{", "$", "mbox", "=", "$", "mbox", ".", "$", "val", "->", "delimiter", ";", "if", "(", "strlen", "(", "$", "val", "->", "name", ")", "&&", "(", "strpos", "(", "$", "mbox", ",", "$", "val", "->", "name", ")", "===", "0", ")", ")", "{", "return", "$", "val", ";", "}", "}", "return", "(", "(", "$", "ns", "=", "$", "this", "[", "''", "]", ")", "&&", "(", "!", "$", "personal", "||", "(", "$", "ns", "->", "type", "===", "$", "ns", "::", "NS_PERSONAL", ")", ")", ")", "?", "$", "ns", ":", "null", ";", "}" ]
Get namespace info for a full mailbox path. @param string $mbox The mailbox path. @param boolean $personal If true, will return the empty namespace only if it is a personal namespace. @return mixed The Horde_Imap_Client_Data_Namespace object for the mailbox path, or null if the path doesn't exist.
[ "Get", "namespace", "info", "for", "a", "full", "mailbox", "path", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Namespace/List.php#L56-L74
218,667
moodle/moodle
backup/util/helper/backup_general_helper.class.php
backup_general_helper.get_blocks_from_path
public static function get_blocks_from_path($path) { global $DB; $blocks = array(); // To return results static $availableblocks = array(); // Get and cache available blocks if (empty($availableblocks)) { $availableblocks = array_keys(core_component::get_plugin_list('block')); } $path = $path . '/blocks'; // Always look under blocks subdir if (!is_dir($path)) { return array(); } if (!$dir = opendir($path)) { return array(); } while (false !== ($file = readdir($dir))) { if ($file == '.' || $file == '..') { // Skip dots continue; } if (is_dir($path .'/' . $file)) { // Dir found, check it's a valid block if (!file_exists($path .'/' . $file . '/block.xml')) { // Skip if xml file not found continue; } // Extract block name $blockname = preg_replace('/(.*)_\d+/', '\\1', $file); // Check block exists and is installed if (in_array($blockname, $availableblocks) && $DB->record_exists('block', array('name' => $blockname))) { $blocks[$path .'/' . $file] = $blockname; } } } closedir($dir); return $blocks; }
php
public static function get_blocks_from_path($path) { global $DB; $blocks = array(); // To return results static $availableblocks = array(); // Get and cache available blocks if (empty($availableblocks)) { $availableblocks = array_keys(core_component::get_plugin_list('block')); } $path = $path . '/blocks'; // Always look under blocks subdir if (!is_dir($path)) { return array(); } if (!$dir = opendir($path)) { return array(); } while (false !== ($file = readdir($dir))) { if ($file == '.' || $file == '..') { // Skip dots continue; } if (is_dir($path .'/' . $file)) { // Dir found, check it's a valid block if (!file_exists($path .'/' . $file . '/block.xml')) { // Skip if xml file not found continue; } // Extract block name $blockname = preg_replace('/(.*)_\d+/', '\\1', $file); // Check block exists and is installed if (in_array($blockname, $availableblocks) && $DB->record_exists('block', array('name' => $blockname))) { $blocks[$path .'/' . $file] = $blockname; } } } closedir($dir); return $blocks; }
[ "public", "static", "function", "get_blocks_from_path", "(", "$", "path", ")", "{", "global", "$", "DB", ";", "$", "blocks", "=", "array", "(", ")", ";", "// To return results", "static", "$", "availableblocks", "=", "array", "(", ")", ";", "// Get and cache available blocks", "if", "(", "empty", "(", "$", "availableblocks", ")", ")", "{", "$", "availableblocks", "=", "array_keys", "(", "core_component", "::", "get_plugin_list", "(", "'block'", ")", ")", ";", "}", "$", "path", "=", "$", "path", ".", "'/blocks'", ";", "// Always look under blocks subdir", "if", "(", "!", "is_dir", "(", "$", "path", ")", ")", "{", "return", "array", "(", ")", ";", "}", "if", "(", "!", "$", "dir", "=", "opendir", "(", "$", "path", ")", ")", "{", "return", "array", "(", ")", ";", "}", "while", "(", "false", "!==", "(", "$", "file", "=", "readdir", "(", "$", "dir", ")", ")", ")", "{", "if", "(", "$", "file", "==", "'.'", "||", "$", "file", "==", "'..'", ")", "{", "// Skip dots", "continue", ";", "}", "if", "(", "is_dir", "(", "$", "path", ".", "'/'", ".", "$", "file", ")", ")", "{", "// Dir found, check it's a valid block", "if", "(", "!", "file_exists", "(", "$", "path", ".", "'/'", ".", "$", "file", ".", "'/block.xml'", ")", ")", "{", "// Skip if xml file not found", "continue", ";", "}", "// Extract block name", "$", "blockname", "=", "preg_replace", "(", "'/(.*)_\\d+/'", ",", "'\\\\1'", ",", "$", "file", ")", ";", "// Check block exists and is installed", "if", "(", "in_array", "(", "$", "blockname", ",", "$", "availableblocks", ")", "&&", "$", "DB", "->", "record_exists", "(", "'block'", ",", "array", "(", "'name'", "=>", "$", "blockname", ")", ")", ")", "{", "$", "blocks", "[", "$", "path", ".", "'/'", ".", "$", "file", "]", "=", "$", "blockname", ";", "}", "}", "}", "closedir", "(", "$", "dir", ")", ";", "return", "$", "blocks", ";", "}" ]
Load all the blocks information needed for a given path within moodle2 backup This function, given one full path (course, activities/xxxx) will look for all the blocks existing in the backup file, returning one array used to build the proper restore plan by the @restore_plan_builder
[ "Load", "all", "the", "blocks", "information", "needed", "for", "a", "given", "path", "within", "moodle2", "backup" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/backup_general_helper.class.php#L68-L106
218,668
moodle/moodle
backup/util/helper/backup_general_helper.class.php
backup_general_helper.get_backup_information_from_mbz
public static function get_backup_information_from_mbz($filepath, file_progress $progress = null) { global $CFG; if (!is_readable($filepath)) { throw new backup_helper_exception('missing_moodle_backup_file', $filepath); } // Extract moodle_backup.xml. $tmpname = 'info_from_mbz_' . time() . '_' . random_string(4); $tmpdir = make_backup_temp_directory($tmpname); $fp = get_file_packer('application/vnd.moodle.backup'); $extracted = $fp->extract_to_pathname($filepath, $tmpdir, array('moodle_backup.xml'), $progress); $moodlefile = $tmpdir . '/' . 'moodle_backup.xml'; if (!$extracted || !is_readable($moodlefile)) { throw new backup_helper_exception('missing_moodle_backup_xml_file', $moodlefile); } // Read the information and delete the temporary directory. $info = self::get_backup_information($tmpname); remove_dir($tmpdir); return $info; }
php
public static function get_backup_information_from_mbz($filepath, file_progress $progress = null) { global $CFG; if (!is_readable($filepath)) { throw new backup_helper_exception('missing_moodle_backup_file', $filepath); } // Extract moodle_backup.xml. $tmpname = 'info_from_mbz_' . time() . '_' . random_string(4); $tmpdir = make_backup_temp_directory($tmpname); $fp = get_file_packer('application/vnd.moodle.backup'); $extracted = $fp->extract_to_pathname($filepath, $tmpdir, array('moodle_backup.xml'), $progress); $moodlefile = $tmpdir . '/' . 'moodle_backup.xml'; if (!$extracted || !is_readable($moodlefile)) { throw new backup_helper_exception('missing_moodle_backup_xml_file', $moodlefile); } // Read the information and delete the temporary directory. $info = self::get_backup_information($tmpname); remove_dir($tmpdir); return $info; }
[ "public", "static", "function", "get_backup_information_from_mbz", "(", "$", "filepath", ",", "file_progress", "$", "progress", "=", "null", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "is_readable", "(", "$", "filepath", ")", ")", "{", "throw", "new", "backup_helper_exception", "(", "'missing_moodle_backup_file'", ",", "$", "filepath", ")", ";", "}", "// Extract moodle_backup.xml.", "$", "tmpname", "=", "'info_from_mbz_'", ".", "time", "(", ")", ".", "'_'", ".", "random_string", "(", "4", ")", ";", "$", "tmpdir", "=", "make_backup_temp_directory", "(", "$", "tmpname", ")", ";", "$", "fp", "=", "get_file_packer", "(", "'application/vnd.moodle.backup'", ")", ";", "$", "extracted", "=", "$", "fp", "->", "extract_to_pathname", "(", "$", "filepath", ",", "$", "tmpdir", ",", "array", "(", "'moodle_backup.xml'", ")", ",", "$", "progress", ")", ";", "$", "moodlefile", "=", "$", "tmpdir", ".", "'/'", ".", "'moodle_backup.xml'", ";", "if", "(", "!", "$", "extracted", "||", "!", "is_readable", "(", "$", "moodlefile", ")", ")", "{", "throw", "new", "backup_helper_exception", "(", "'missing_moodle_backup_xml_file'", ",", "$", "moodlefile", ")", ";", "}", "// Read the information and delete the temporary directory.", "$", "info", "=", "self", "::", "get_backup_information", "(", "$", "tmpname", ")", ";", "remove_dir", "(", "$", "tmpdir", ")", ";", "return", "$", "info", ";", "}" ]
Load and format all the needed information from a backup file. This will only extract the moodle_backup.xml file from an MBZ file and then call {@link self::get_backup_information()}. This can be a long-running (multi-minute) operation for large backups. Pass a $progress value to receive progress updates. @param string $filepath absolute path to the MBZ file. @param file_progress $progress Progress updates @return stdClass containing information. @since Moodle 2.4
[ "Load", "and", "format", "all", "the", "needed", "information", "from", "a", "backup", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/backup_general_helper.class.php#L263-L284
218,669
moodle/moodle
backup/util/helper/backup_general_helper.class.php
backup_general_helper.backup_is_samesite
public static function backup_is_samesite($info) { global $CFG; $hashedsiteid = md5(get_site_identifier()); if (isset($info->original_site_identifier_hash) && !empty($info->original_site_identifier_hash)) { return $info->original_site_identifier_hash == $hashedsiteid; } else { return $info->original_wwwroot == $CFG->wwwroot; } }
php
public static function backup_is_samesite($info) { global $CFG; $hashedsiteid = md5(get_site_identifier()); if (isset($info->original_site_identifier_hash) && !empty($info->original_site_identifier_hash)) { return $info->original_site_identifier_hash == $hashedsiteid; } else { return $info->original_wwwroot == $CFG->wwwroot; } }
[ "public", "static", "function", "backup_is_samesite", "(", "$", "info", ")", "{", "global", "$", "CFG", ";", "$", "hashedsiteid", "=", "md5", "(", "get_site_identifier", "(", ")", ")", ";", "if", "(", "isset", "(", "$", "info", "->", "original_site_identifier_hash", ")", "&&", "!", "empty", "(", "$", "info", "->", "original_site_identifier_hash", ")", ")", "{", "return", "$", "info", "->", "original_site_identifier_hash", "==", "$", "hashedsiteid", ";", "}", "else", "{", "return", "$", "info", "->", "original_wwwroot", "==", "$", "CFG", "->", "wwwroot", ";", "}", "}" ]
Given the information fetched from moodle_backup.xml file decide if we are restoring in the same site the backup was generated or no. Behavior of various parts of restore are dependent of this. Backups created natively in 2.0 and later declare the hashed site identifier. Backups created by conversion from a 1.9 backup do not declare such identifier, so there is a fallback to wwwroot comparison. See MDL-16614.
[ "Given", "the", "information", "fetched", "from", "moodle_backup", ".", "xml", "file", "decide", "if", "we", "are", "restoring", "in", "the", "same", "site", "the", "backup", "was", "generated", "or", "no", ".", "Behavior", "of", "various", "parts", "of", "restore", "are", "dependent", "of", "this", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/backup_general_helper.class.php#L297-L305
218,670
moodle/moodle
backup/util/helper/backup_general_helper.class.php
backup_general_helper.detect_backup_format
public static function detect_backup_format($tempdir) { global $CFG; require_once($CFG->dirroot . '/backup/util/helper/convert_helper.class.php'); if (convert_helper::detect_moodle2_format($tempdir)) { return backup::FORMAT_MOODLE; } // see if a converter can identify the format $converters = convert_helper::available_converters(); foreach ($converters as $name) { $classname = "{$name}_converter"; if (!class_exists($classname)) { throw new coding_exception("available_converters() is supposed to load converter classes but class $classname not found"); } $detected = call_user_func($classname .'::detect_format', $tempdir); if (!empty($detected)) { return $detected; } } return backup::FORMAT_UNKNOWN; }
php
public static function detect_backup_format($tempdir) { global $CFG; require_once($CFG->dirroot . '/backup/util/helper/convert_helper.class.php'); if (convert_helper::detect_moodle2_format($tempdir)) { return backup::FORMAT_MOODLE; } // see if a converter can identify the format $converters = convert_helper::available_converters(); foreach ($converters as $name) { $classname = "{$name}_converter"; if (!class_exists($classname)) { throw new coding_exception("available_converters() is supposed to load converter classes but class $classname not found"); } $detected = call_user_func($classname .'::detect_format', $tempdir); if (!empty($detected)) { return $detected; } } return backup::FORMAT_UNKNOWN; }
[ "public", "static", "function", "detect_backup_format", "(", "$", "tempdir", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/backup/util/helper/convert_helper.class.php'", ")", ";", "if", "(", "convert_helper", "::", "detect_moodle2_format", "(", "$", "tempdir", ")", ")", "{", "return", "backup", "::", "FORMAT_MOODLE", ";", "}", "// see if a converter can identify the format", "$", "converters", "=", "convert_helper", "::", "available_converters", "(", ")", ";", "foreach", "(", "$", "converters", "as", "$", "name", ")", "{", "$", "classname", "=", "\"{$name}_converter\"", ";", "if", "(", "!", "class_exists", "(", "$", "classname", ")", ")", "{", "throw", "new", "coding_exception", "(", "\"available_converters() is supposed to load\n converter classes but class $classname not found\"", ")", ";", "}", "$", "detected", "=", "call_user_func", "(", "$", "classname", ".", "'::detect_format'", ",", "$", "tempdir", ")", ";", "if", "(", "!", "empty", "(", "$", "detected", ")", ")", "{", "return", "$", "detected", ";", "}", "}", "return", "backup", "::", "FORMAT_UNKNOWN", ";", "}" ]
Detects the format of the given unpacked backup directory @param string $tempdir the name of the backup directory @return string one of backup::FORMAT_xxx constants
[ "Detects", "the", "format", "of", "the", "given", "unpacked", "backup", "directory" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/backup_general_helper.class.php#L313-L337
218,671
moodle/moodle
mod/assign/gradingbatchoperationsform.php
mod_assign_grading_batch_operations_form.definition
public function definition() { $mform = $this->_form; $instance = $this->_customdata; // Visible elements. $options = array(); $options['lock'] = get_string('locksubmissions', 'assign'); $options['unlock'] = get_string('unlocksubmissions', 'assign'); $options['downloadselected'] = get_string('downloadselectedsubmissions', 'assign'); if ($instance['submissiondrafts']) { $options['reverttodraft'] = get_string('reverttodraft', 'assign'); } if (has_capability('mod/assign:grade', $instance['context'])) { $options['removesubmission'] = get_string('removesubmission', 'assign'); } if ($instance['duedate'] && has_capability('mod/assign:grantextension', $instance['context'])) { $options['grantextension'] = get_string('grantextension', 'assign'); } if ($instance['attemptreopenmethod'] == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL) { $options['addattempt'] = get_string('addattempt', 'assign'); } foreach ($instance['feedbackplugins'] as $plugin) { if ($plugin->is_visible() && $plugin->is_enabled()) { foreach ($plugin->get_grading_batch_operations() as $action => $description) { $operationkey = 'plugingradingbatchoperation_' . $plugin->get_type() . '_' . $action; $options[$operationkey] = $description; } } } if ($instance['markingworkflow']) { $options['setmarkingworkflowstate'] = get_string('setmarkingworkflowstate', 'assign'); } if ($instance['markingallocation']) { $options['setmarkingallocation'] = get_string('setmarkingallocation', 'assign'); } $mform->addElement('hidden', 'action', 'gradingbatchoperation'); $mform->setType('action', PARAM_ALPHA); $mform->addElement('hidden', 'id', $instance['cm']); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'selectedusers', '', array('class'=>'selectedusers')); $mform->setType('selectedusers', PARAM_SEQUENCE); $mform->addElement('hidden', 'returnaction', 'grading'); $mform->setType('returnaction', PARAM_ALPHA); $objs = array(); $objs[] =& $mform->createElement('select', 'operation', get_string('chooseoperation', 'assign'), $options); $objs[] =& $mform->createElement('submit', 'submit', get_string('go')); $batchdescription = get_string('batchoperationsdescription', 'assign'); $mform->addElement('group', 'actionsgrp', $batchdescription, $objs, ' ', false); }
php
public function definition() { $mform = $this->_form; $instance = $this->_customdata; // Visible elements. $options = array(); $options['lock'] = get_string('locksubmissions', 'assign'); $options['unlock'] = get_string('unlocksubmissions', 'assign'); $options['downloadselected'] = get_string('downloadselectedsubmissions', 'assign'); if ($instance['submissiondrafts']) { $options['reverttodraft'] = get_string('reverttodraft', 'assign'); } if (has_capability('mod/assign:grade', $instance['context'])) { $options['removesubmission'] = get_string('removesubmission', 'assign'); } if ($instance['duedate'] && has_capability('mod/assign:grantextension', $instance['context'])) { $options['grantextension'] = get_string('grantextension', 'assign'); } if ($instance['attemptreopenmethod'] == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL) { $options['addattempt'] = get_string('addattempt', 'assign'); } foreach ($instance['feedbackplugins'] as $plugin) { if ($plugin->is_visible() && $plugin->is_enabled()) { foreach ($plugin->get_grading_batch_operations() as $action => $description) { $operationkey = 'plugingradingbatchoperation_' . $plugin->get_type() . '_' . $action; $options[$operationkey] = $description; } } } if ($instance['markingworkflow']) { $options['setmarkingworkflowstate'] = get_string('setmarkingworkflowstate', 'assign'); } if ($instance['markingallocation']) { $options['setmarkingallocation'] = get_string('setmarkingallocation', 'assign'); } $mform->addElement('hidden', 'action', 'gradingbatchoperation'); $mform->setType('action', PARAM_ALPHA); $mform->addElement('hidden', 'id', $instance['cm']); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'selectedusers', '', array('class'=>'selectedusers')); $mform->setType('selectedusers', PARAM_SEQUENCE); $mform->addElement('hidden', 'returnaction', 'grading'); $mform->setType('returnaction', PARAM_ALPHA); $objs = array(); $objs[] =& $mform->createElement('select', 'operation', get_string('chooseoperation', 'assign'), $options); $objs[] =& $mform->createElement('submit', 'submit', get_string('go')); $batchdescription = get_string('batchoperationsdescription', 'assign'); $mform->addElement('group', 'actionsgrp', $batchdescription, $objs, ' ', false); }
[ "public", "function", "definition", "(", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "instance", "=", "$", "this", "->", "_customdata", ";", "// Visible elements.", "$", "options", "=", "array", "(", ")", ";", "$", "options", "[", "'lock'", "]", "=", "get_string", "(", "'locksubmissions'", ",", "'assign'", ")", ";", "$", "options", "[", "'unlock'", "]", "=", "get_string", "(", "'unlocksubmissions'", ",", "'assign'", ")", ";", "$", "options", "[", "'downloadselected'", "]", "=", "get_string", "(", "'downloadselectedsubmissions'", ",", "'assign'", ")", ";", "if", "(", "$", "instance", "[", "'submissiondrafts'", "]", ")", "{", "$", "options", "[", "'reverttodraft'", "]", "=", "get_string", "(", "'reverttodraft'", ",", "'assign'", ")", ";", "}", "if", "(", "has_capability", "(", "'mod/assign:grade'", ",", "$", "instance", "[", "'context'", "]", ")", ")", "{", "$", "options", "[", "'removesubmission'", "]", "=", "get_string", "(", "'removesubmission'", ",", "'assign'", ")", ";", "}", "if", "(", "$", "instance", "[", "'duedate'", "]", "&&", "has_capability", "(", "'mod/assign:grantextension'", ",", "$", "instance", "[", "'context'", "]", ")", ")", "{", "$", "options", "[", "'grantextension'", "]", "=", "get_string", "(", "'grantextension'", ",", "'assign'", ")", ";", "}", "if", "(", "$", "instance", "[", "'attemptreopenmethod'", "]", "==", "ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL", ")", "{", "$", "options", "[", "'addattempt'", "]", "=", "get_string", "(", "'addattempt'", ",", "'assign'", ")", ";", "}", "foreach", "(", "$", "instance", "[", "'feedbackplugins'", "]", "as", "$", "plugin", ")", "{", "if", "(", "$", "plugin", "->", "is_visible", "(", ")", "&&", "$", "plugin", "->", "is_enabled", "(", ")", ")", "{", "foreach", "(", "$", "plugin", "->", "get_grading_batch_operations", "(", ")", "as", "$", "action", "=>", "$", "description", ")", "{", "$", "operationkey", "=", "'plugingradingbatchoperation_'", ".", "$", "plugin", "->", "get_type", "(", ")", ".", "'_'", ".", "$", "action", ";", "$", "options", "[", "$", "operationkey", "]", "=", "$", "description", ";", "}", "}", "}", "if", "(", "$", "instance", "[", "'markingworkflow'", "]", ")", "{", "$", "options", "[", "'setmarkingworkflowstate'", "]", "=", "get_string", "(", "'setmarkingworkflowstate'", ",", "'assign'", ")", ";", "}", "if", "(", "$", "instance", "[", "'markingallocation'", "]", ")", "{", "$", "options", "[", "'setmarkingallocation'", "]", "=", "get_string", "(", "'setmarkingallocation'", ",", "'assign'", ")", ";", "}", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'action'", ",", "'gradingbatchoperation'", ")", ";", "$", "mform", "->", "setType", "(", "'action'", ",", "PARAM_ALPHA", ")", ";", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'id'", ",", "$", "instance", "[", "'cm'", "]", ")", ";", "$", "mform", "->", "setType", "(", "'id'", ",", "PARAM_INT", ")", ";", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'selectedusers'", ",", "''", ",", "array", "(", "'class'", "=>", "'selectedusers'", ")", ")", ";", "$", "mform", "->", "setType", "(", "'selectedusers'", ",", "PARAM_SEQUENCE", ")", ";", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'returnaction'", ",", "'grading'", ")", ";", "$", "mform", "->", "setType", "(", "'returnaction'", ",", "PARAM_ALPHA", ")", ";", "$", "objs", "=", "array", "(", ")", ";", "$", "objs", "[", "]", "=", "&", "$", "mform", "->", "createElement", "(", "'select'", ",", "'operation'", ",", "get_string", "(", "'chooseoperation'", ",", "'assign'", ")", ",", "$", "options", ")", ";", "$", "objs", "[", "]", "=", "&", "$", "mform", "->", "createElement", "(", "'submit'", ",", "'submit'", ",", "get_string", "(", "'go'", ")", ")", ";", "$", "batchdescription", "=", "get_string", "(", "'batchoperationsdescription'", ",", "'assign'", ")", ";", "$", "mform", "->", "addElement", "(", "'group'", ",", "'actionsgrp'", ",", "$", "batchdescription", ",", "$", "objs", ",", "' '", ",", "false", ")", ";", "}" ]
Define this form - called by the parent constructor.
[ "Define", "this", "form", "-", "called", "by", "the", "parent", "constructor", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingbatchoperationsform.php#L41-L92
218,672
moodle/moodle
customfield/classes/category_controller.php
category_controller.create
public static function create(int $id, \stdClass $record = null, handler $handler = null) : category_controller { global $DB; if ($id && $record) { // This warning really should be in persistent as well. debugging('Too many parameters, either id need to be specified or a record, but not both.', DEBUG_DEVELOPER); } if ($id) { if (!$record = $DB->get_record(category::TABLE, array('id' => $id), '*', IGNORE_MISSING)) { throw new \moodle_exception('categorynotfound', 'core_customfield'); } } if (empty($record->component)) { if (!$handler) { throw new \coding_exception('Not enough parameters to initialise category_controller - unknown component'); } $record->component = $handler->get_component(); } if (empty($record->area)) { if (!$handler) { throw new \coding_exception('Not enough parameters to initialise category_controller - unknown area'); } $record->area = $handler->get_area(); } if (!isset($record->itemid)) { if (!$handler) { throw new \coding_exception('Not enough parameters to initialise category_controller - unknown itemid'); } $record->itemid = $handler->get_itemid(); } $category = new self(0, $record); if (!$category->get('contextid')) { // If contextid was not present in the record we can find it out from the handler. $handlernew = $handler ?? $category->get_handler(); $category->set('contextid', $handlernew->get_configuration_context()->id); } if ($handler) { $category->set_handler($handler); } return $category; }
php
public static function create(int $id, \stdClass $record = null, handler $handler = null) : category_controller { global $DB; if ($id && $record) { // This warning really should be in persistent as well. debugging('Too many parameters, either id need to be specified or a record, but not both.', DEBUG_DEVELOPER); } if ($id) { if (!$record = $DB->get_record(category::TABLE, array('id' => $id), '*', IGNORE_MISSING)) { throw new \moodle_exception('categorynotfound', 'core_customfield'); } } if (empty($record->component)) { if (!$handler) { throw new \coding_exception('Not enough parameters to initialise category_controller - unknown component'); } $record->component = $handler->get_component(); } if (empty($record->area)) { if (!$handler) { throw new \coding_exception('Not enough parameters to initialise category_controller - unknown area'); } $record->area = $handler->get_area(); } if (!isset($record->itemid)) { if (!$handler) { throw new \coding_exception('Not enough parameters to initialise category_controller - unknown itemid'); } $record->itemid = $handler->get_itemid(); } $category = new self(0, $record); if (!$category->get('contextid')) { // If contextid was not present in the record we can find it out from the handler. $handlernew = $handler ?? $category->get_handler(); $category->set('contextid', $handlernew->get_configuration_context()->id); } if ($handler) { $category->set_handler($handler); } return $category; }
[ "public", "static", "function", "create", "(", "int", "$", "id", ",", "\\", "stdClass", "$", "record", "=", "null", ",", "handler", "$", "handler", "=", "null", ")", ":", "category_controller", "{", "global", "$", "DB", ";", "if", "(", "$", "id", "&&", "$", "record", ")", "{", "// This warning really should be in persistent as well.", "debugging", "(", "'Too many parameters, either id need to be specified or a record, but not both.'", ",", "DEBUG_DEVELOPER", ")", ";", "}", "if", "(", "$", "id", ")", "{", "if", "(", "!", "$", "record", "=", "$", "DB", "->", "get_record", "(", "category", "::", "TABLE", ",", "array", "(", "'id'", "=>", "$", "id", ")", ",", "'*'", ",", "IGNORE_MISSING", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'categorynotfound'", ",", "'core_customfield'", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "record", "->", "component", ")", ")", "{", "if", "(", "!", "$", "handler", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Not enough parameters to initialise category_controller - unknown component'", ")", ";", "}", "$", "record", "->", "component", "=", "$", "handler", "->", "get_component", "(", ")", ";", "}", "if", "(", "empty", "(", "$", "record", "->", "area", ")", ")", "{", "if", "(", "!", "$", "handler", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Not enough parameters to initialise category_controller - unknown area'", ")", ";", "}", "$", "record", "->", "area", "=", "$", "handler", "->", "get_area", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "record", "->", "itemid", ")", ")", "{", "if", "(", "!", "$", "handler", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Not enough parameters to initialise category_controller - unknown itemid'", ")", ";", "}", "$", "record", "->", "itemid", "=", "$", "handler", "->", "get_itemid", "(", ")", ";", "}", "$", "category", "=", "new", "self", "(", "0", ",", "$", "record", ")", ";", "if", "(", "!", "$", "category", "->", "get", "(", "'contextid'", ")", ")", "{", "// If contextid was not present in the record we can find it out from the handler.", "$", "handlernew", "=", "$", "handler", "??", "$", "category", "->", "get_handler", "(", ")", ";", "$", "category", "->", "set", "(", "'contextid'", ",", "$", "handlernew", "->", "get_configuration_context", "(", ")", "->", "id", ")", ";", "}", "if", "(", "$", "handler", ")", "{", "$", "category", "->", "set_handler", "(", "$", "handler", ")", ";", "}", "return", "$", "category", ";", "}" ]
Creates an instance of category_controller Either $id or $record or $handler need to be specified If handler is known pass it to constructor to avoid retrieving it later Component, area and itemid must not conflict with the ones in handler @param int $id @param \stdClass|null $record @param handler|null $handler @return category_controller @throws \moodle_exception @throws \coding_exception
[ "Creates", "an", "instance", "of", "category_controller" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/category_controller.php#L80-L120
218,673
moodle/moodle
customfield/classes/category_controller.php
category_controller.get_handler
public function get_handler() : handler { if ($this->handler === null) { $this->handler = handler::get_handler($this->get('component'), $this->get('area'), $this->get('itemid')); } return $this->handler; }
php
public function get_handler() : handler { if ($this->handler === null) { $this->handler = handler::get_handler($this->get('component'), $this->get('area'), $this->get('itemid')); } return $this->handler; }
[ "public", "function", "get_handler", "(", ")", ":", "handler", "{", "if", "(", "$", "this", "->", "handler", "===", "null", ")", "{", "$", "this", "->", "handler", "=", "handler", "::", "get_handler", "(", "$", "this", "->", "get", "(", "'component'", ")", ",", "$", "this", "->", "get", "(", "'area'", ")", ",", "$", "this", "->", "get", "(", "'itemid'", ")", ")", ";", "}", "return", "$", "this", "->", "handler", ";", "}" ]
Gets a handler, if not known retrieve it @return handler
[ "Gets", "a", "handler", "if", "not", "known", "retrieve", "it" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/category_controller.php#L183-L188
218,674
moodle/moodle
customfield/classes/category_controller.php
category_controller.set_handler
public function set_handler(handler $handler) { // Make sure there are no conflicts. if ($this->get('component') !== $handler->get_component()) { throw new \coding_exception('Component of the handler does not match the one from the record'); } if ($this->get('area') !== $handler->get_area()) { throw new \coding_exception('Area of the handler does not match the one from the record'); } if ($this->get('itemid') != $handler->get_itemid()) { throw new \coding_exception('Itemid of the handler does not match the one from the record'); } if ($this->get('contextid') != $handler->get_configuration_context()->id) { throw new \coding_exception('Context of the handler does not match the one from the record'); } $this->handler = $handler; }
php
public function set_handler(handler $handler) { // Make sure there are no conflicts. if ($this->get('component') !== $handler->get_component()) { throw new \coding_exception('Component of the handler does not match the one from the record'); } if ($this->get('area') !== $handler->get_area()) { throw new \coding_exception('Area of the handler does not match the one from the record'); } if ($this->get('itemid') != $handler->get_itemid()) { throw new \coding_exception('Itemid of the handler does not match the one from the record'); } if ($this->get('contextid') != $handler->get_configuration_context()->id) { throw new \coding_exception('Context of the handler does not match the one from the record'); } $this->handler = $handler; }
[ "public", "function", "set_handler", "(", "handler", "$", "handler", ")", "{", "// Make sure there are no conflicts.", "if", "(", "$", "this", "->", "get", "(", "'component'", ")", "!==", "$", "handler", "->", "get_component", "(", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Component of the handler does not match the one from the record'", ")", ";", "}", "if", "(", "$", "this", "->", "get", "(", "'area'", ")", "!==", "$", "handler", "->", "get_area", "(", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Area of the handler does not match the one from the record'", ")", ";", "}", "if", "(", "$", "this", "->", "get", "(", "'itemid'", ")", "!=", "$", "handler", "->", "get_itemid", "(", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Itemid of the handler does not match the one from the record'", ")", ";", "}", "if", "(", "$", "this", "->", "get", "(", "'contextid'", ")", "!=", "$", "handler", "->", "get_configuration_context", "(", ")", "->", "id", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Context of the handler does not match the one from the record'", ")", ";", "}", "$", "this", "->", "handler", "=", "$", "handler", ";", "}" ]
Allows to set handler so we don't need to retrieve it later @param handler $handler @throws \coding_exception
[ "Allows", "to", "set", "handler", "so", "we", "don", "t", "need", "to", "retrieve", "it", "later" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/category_controller.php#L196-L211
218,675
moodle/moodle
mod/resource/classes/external.php
mod_resource_external.get_resources_by_courses
public static function get_resources_by_courses($courseids = array()) { $warnings = array(); $returnedresources = array(); $params = array( 'courseids' => $courseids, ); $params = self::validate_parameters(self::get_resources_by_courses_parameters(), $params); $mycourses = array(); if (empty($params['courseids'])) { $mycourses = enrol_get_my_courses(); $params['courseids'] = array_keys($mycourses); } // Ensure there are courseids to loop through. if (!empty($params['courseids'])) { list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses); // Get the resources in this course, this function checks users visibility permissions. // We can avoid then additional validate_context calls. $resources = get_all_instances_in_courses("resource", $courses); foreach ($resources as $resource) { $context = context_module::instance($resource->coursemodule); // Entry to return. $resource->name = external_format_string($resource->name, $context->id); list($resource->intro, $resource->introformat) = external_format_text($resource->intro, $resource->introformat, $context->id, 'mod_resource', 'intro', null); $resource->introfiles = external_util::get_area_files($context->id, 'mod_resource', 'intro', false, false); $resource->contentfiles = external_util::get_area_files($context->id, 'mod_resource', 'content'); $returnedresources[] = $resource; } } $result = array( 'resources' => $returnedresources, 'warnings' => $warnings ); return $result; }
php
public static function get_resources_by_courses($courseids = array()) { $warnings = array(); $returnedresources = array(); $params = array( 'courseids' => $courseids, ); $params = self::validate_parameters(self::get_resources_by_courses_parameters(), $params); $mycourses = array(); if (empty($params['courseids'])) { $mycourses = enrol_get_my_courses(); $params['courseids'] = array_keys($mycourses); } // Ensure there are courseids to loop through. if (!empty($params['courseids'])) { list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses); // Get the resources in this course, this function checks users visibility permissions. // We can avoid then additional validate_context calls. $resources = get_all_instances_in_courses("resource", $courses); foreach ($resources as $resource) { $context = context_module::instance($resource->coursemodule); // Entry to return. $resource->name = external_format_string($resource->name, $context->id); list($resource->intro, $resource->introformat) = external_format_text($resource->intro, $resource->introformat, $context->id, 'mod_resource', 'intro', null); $resource->introfiles = external_util::get_area_files($context->id, 'mod_resource', 'intro', false, false); $resource->contentfiles = external_util::get_area_files($context->id, 'mod_resource', 'content'); $returnedresources[] = $resource; } } $result = array( 'resources' => $returnedresources, 'warnings' => $warnings ); return $result; }
[ "public", "static", "function", "get_resources_by_courses", "(", "$", "courseids", "=", "array", "(", ")", ")", "{", "$", "warnings", "=", "array", "(", ")", ";", "$", "returnedresources", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'courseids'", "=>", "$", "courseids", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_resources_by_courses_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "mycourses", "=", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "params", "[", "'courseids'", "]", ")", ")", "{", "$", "mycourses", "=", "enrol_get_my_courses", "(", ")", ";", "$", "params", "[", "'courseids'", "]", "=", "array_keys", "(", "$", "mycourses", ")", ";", "}", "// Ensure there are courseids to loop through.", "if", "(", "!", "empty", "(", "$", "params", "[", "'courseids'", "]", ")", ")", "{", "list", "(", "$", "courses", ",", "$", "warnings", ")", "=", "external_util", "::", "validate_courses", "(", "$", "params", "[", "'courseids'", "]", ",", "$", "mycourses", ")", ";", "// Get the resources in this course, this function checks users visibility permissions.", "// We can avoid then additional validate_context calls.", "$", "resources", "=", "get_all_instances_in_courses", "(", "\"resource\"", ",", "$", "courses", ")", ";", "foreach", "(", "$", "resources", "as", "$", "resource", ")", "{", "$", "context", "=", "context_module", "::", "instance", "(", "$", "resource", "->", "coursemodule", ")", ";", "// Entry to return.", "$", "resource", "->", "name", "=", "external_format_string", "(", "$", "resource", "->", "name", ",", "$", "context", "->", "id", ")", ";", "list", "(", "$", "resource", "->", "intro", ",", "$", "resource", "->", "introformat", ")", "=", "external_format_text", "(", "$", "resource", "->", "intro", ",", "$", "resource", "->", "introformat", ",", "$", "context", "->", "id", ",", "'mod_resource'", ",", "'intro'", ",", "null", ")", ";", "$", "resource", "->", "introfiles", "=", "external_util", "::", "get_area_files", "(", "$", "context", "->", "id", ",", "'mod_resource'", ",", "'intro'", ",", "false", ",", "false", ")", ";", "$", "resource", "->", "contentfiles", "=", "external_util", "::", "get_area_files", "(", "$", "context", "->", "id", ",", "'mod_resource'", ",", "'content'", ")", ";", "$", "returnedresources", "[", "]", "=", "$", "resource", ";", "}", "}", "$", "result", "=", "array", "(", "'resources'", "=>", "$", "returnedresources", ",", "'warnings'", "=>", "$", "warnings", ")", ";", "return", "$", "result", ";", "}" ]
Returns a list of files in a provided list of courses. If no list is provided all files that the user can view will be returned. @param array $courseids course ids @return array of warnings and files @since Moodle 3.3
[ "Returns", "a", "list", "of", "files", "in", "a", "provided", "list", "of", "courses", ".", "If", "no", "list", "is", "provided", "all", "files", "that", "the", "user", "can", "view", "will", "be", "returned", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/resource/classes/external.php#L131-L174
218,676
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Lexer.php
HTMLPurifier_Lexer.create
public static function create($config) { if (!($config instanceof HTMLPurifier_Config)) { $lexer = $config; trigger_error( "Passing a prototype to HTMLPurifier_Lexer::create() is deprecated, please instead use %Core.LexerImpl", E_USER_WARNING ); } else { $lexer = $config->get('Core.LexerImpl'); } $needs_tracking = $config->get('Core.MaintainLineNumbers') || $config->get('Core.CollectErrors'); $inst = null; if (is_object($lexer)) { $inst = $lexer; } else { if (is_null($lexer)) { do { // auto-detection algorithm if ($needs_tracking) { $lexer = 'DirectLex'; break; } if (class_exists('DOMDocument', false) && method_exists('DOMDocument', 'loadHTML') && !extension_loaded('domxml') ) { // check for DOM support, because while it's part of the // core, it can be disabled compile time. Also, the PECL // domxml extension overrides the default DOM, and is evil // and nasty and we shan't bother to support it $lexer = 'DOMLex'; } else { $lexer = 'DirectLex'; } } while (0); } // do..while so we can break // instantiate recognized string names switch ($lexer) { case 'DOMLex': $inst = new HTMLPurifier_Lexer_DOMLex(); break; case 'DirectLex': $inst = new HTMLPurifier_Lexer_DirectLex(); break; case 'PH5P': $inst = new HTMLPurifier_Lexer_PH5P(); break; default: throw new HTMLPurifier_Exception( "Cannot instantiate unrecognized Lexer type " . htmlspecialchars($lexer) ); } } if (!$inst) { throw new HTMLPurifier_Exception('No lexer was instantiated'); } // once PHP DOM implements native line numbers, or we // hack out something using XSLT, remove this stipulation if ($needs_tracking && !$inst->tracksLineNumbers) { throw new HTMLPurifier_Exception( 'Cannot use lexer that does not support line numbers with ' . 'Core.MaintainLineNumbers or Core.CollectErrors (use DirectLex instead)' ); } return $inst; }
php
public static function create($config) { if (!($config instanceof HTMLPurifier_Config)) { $lexer = $config; trigger_error( "Passing a prototype to HTMLPurifier_Lexer::create() is deprecated, please instead use %Core.LexerImpl", E_USER_WARNING ); } else { $lexer = $config->get('Core.LexerImpl'); } $needs_tracking = $config->get('Core.MaintainLineNumbers') || $config->get('Core.CollectErrors'); $inst = null; if (is_object($lexer)) { $inst = $lexer; } else { if (is_null($lexer)) { do { // auto-detection algorithm if ($needs_tracking) { $lexer = 'DirectLex'; break; } if (class_exists('DOMDocument', false) && method_exists('DOMDocument', 'loadHTML') && !extension_loaded('domxml') ) { // check for DOM support, because while it's part of the // core, it can be disabled compile time. Also, the PECL // domxml extension overrides the default DOM, and is evil // and nasty and we shan't bother to support it $lexer = 'DOMLex'; } else { $lexer = 'DirectLex'; } } while (0); } // do..while so we can break // instantiate recognized string names switch ($lexer) { case 'DOMLex': $inst = new HTMLPurifier_Lexer_DOMLex(); break; case 'DirectLex': $inst = new HTMLPurifier_Lexer_DirectLex(); break; case 'PH5P': $inst = new HTMLPurifier_Lexer_PH5P(); break; default: throw new HTMLPurifier_Exception( "Cannot instantiate unrecognized Lexer type " . htmlspecialchars($lexer) ); } } if (!$inst) { throw new HTMLPurifier_Exception('No lexer was instantiated'); } // once PHP DOM implements native line numbers, or we // hack out something using XSLT, remove this stipulation if ($needs_tracking && !$inst->tracksLineNumbers) { throw new HTMLPurifier_Exception( 'Cannot use lexer that does not support line numbers with ' . 'Core.MaintainLineNumbers or Core.CollectErrors (use DirectLex instead)' ); } return $inst; }
[ "public", "static", "function", "create", "(", "$", "config", ")", "{", "if", "(", "!", "(", "$", "config", "instanceof", "HTMLPurifier_Config", ")", ")", "{", "$", "lexer", "=", "$", "config", ";", "trigger_error", "(", "\"Passing a prototype to\n HTMLPurifier_Lexer::create() is deprecated, please instead\n use %Core.LexerImpl\"", ",", "E_USER_WARNING", ")", ";", "}", "else", "{", "$", "lexer", "=", "$", "config", "->", "get", "(", "'Core.LexerImpl'", ")", ";", "}", "$", "needs_tracking", "=", "$", "config", "->", "get", "(", "'Core.MaintainLineNumbers'", ")", "||", "$", "config", "->", "get", "(", "'Core.CollectErrors'", ")", ";", "$", "inst", "=", "null", ";", "if", "(", "is_object", "(", "$", "lexer", ")", ")", "{", "$", "inst", "=", "$", "lexer", ";", "}", "else", "{", "if", "(", "is_null", "(", "$", "lexer", ")", ")", "{", "do", "{", "// auto-detection algorithm", "if", "(", "$", "needs_tracking", ")", "{", "$", "lexer", "=", "'DirectLex'", ";", "break", ";", "}", "if", "(", "class_exists", "(", "'DOMDocument'", ",", "false", ")", "&&", "method_exists", "(", "'DOMDocument'", ",", "'loadHTML'", ")", "&&", "!", "extension_loaded", "(", "'domxml'", ")", ")", "{", "// check for DOM support, because while it's part of the", "// core, it can be disabled compile time. Also, the PECL", "// domxml extension overrides the default DOM, and is evil", "// and nasty and we shan't bother to support it", "$", "lexer", "=", "'DOMLex'", ";", "}", "else", "{", "$", "lexer", "=", "'DirectLex'", ";", "}", "}", "while", "(", "0", ")", ";", "}", "// do..while so we can break", "// instantiate recognized string names", "switch", "(", "$", "lexer", ")", "{", "case", "'DOMLex'", ":", "$", "inst", "=", "new", "HTMLPurifier_Lexer_DOMLex", "(", ")", ";", "break", ";", "case", "'DirectLex'", ":", "$", "inst", "=", "new", "HTMLPurifier_Lexer_DirectLex", "(", ")", ";", "break", ";", "case", "'PH5P'", ":", "$", "inst", "=", "new", "HTMLPurifier_Lexer_PH5P", "(", ")", ";", "break", ";", "default", ":", "throw", "new", "HTMLPurifier_Exception", "(", "\"Cannot instantiate unrecognized Lexer type \"", ".", "htmlspecialchars", "(", "$", "lexer", ")", ")", ";", "}", "}", "if", "(", "!", "$", "inst", ")", "{", "throw", "new", "HTMLPurifier_Exception", "(", "'No lexer was instantiated'", ")", ";", "}", "// once PHP DOM implements native line numbers, or we", "// hack out something using XSLT, remove this stipulation", "if", "(", "$", "needs_tracking", "&&", "!", "$", "inst", "->", "tracksLineNumbers", ")", "{", "throw", "new", "HTMLPurifier_Exception", "(", "'Cannot use lexer that does not support line numbers with '", ".", "'Core.MaintainLineNumbers or Core.CollectErrors (use DirectLex instead)'", ")", ";", "}", "return", "$", "inst", ";", "}" ]
Retrieves or sets the default Lexer as a Prototype Factory. By default HTMLPurifier_Lexer_DOMLex will be returned. There are a few exceptions involving special features that only DirectLex implements. @note The behavior of this class has changed, rather than accepting a prototype object, it now accepts a configuration object. To specify your own prototype, set %Core.LexerImpl to it. This change in behavior de-singletonizes the lexer object. @param HTMLPurifier_Config $config @return HTMLPurifier_Lexer @throws HTMLPurifier_Exception
[ "Retrieves", "or", "sets", "the", "default", "Lexer", "as", "a", "Prototype", "Factory", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Lexer.php#L69-L148
218,677
moodle/moodle
lib/spout/src/Spout/Writer/WriterFactory.php
WriterFactory.create
public static function create($writerType) { $writer = null; switch ($writerType) { case Type::CSV: $writer = new CSV\Writer(); break; case Type::XLSX: $writer = new XLSX\Writer(); break; case Type::ODS: $writer = new ODS\Writer(); break; default: throw new UnsupportedTypeException('No writers supporting the given type: ' . $writerType); } $writer->setGlobalFunctionsHelper(new GlobalFunctionsHelper()); return $writer; }
php
public static function create($writerType) { $writer = null; switch ($writerType) { case Type::CSV: $writer = new CSV\Writer(); break; case Type::XLSX: $writer = new XLSX\Writer(); break; case Type::ODS: $writer = new ODS\Writer(); break; default: throw new UnsupportedTypeException('No writers supporting the given type: ' . $writerType); } $writer->setGlobalFunctionsHelper(new GlobalFunctionsHelper()); return $writer; }
[ "public", "static", "function", "create", "(", "$", "writerType", ")", "{", "$", "writer", "=", "null", ";", "switch", "(", "$", "writerType", ")", "{", "case", "Type", "::", "CSV", ":", "$", "writer", "=", "new", "CSV", "\\", "Writer", "(", ")", ";", "break", ";", "case", "Type", "::", "XLSX", ":", "$", "writer", "=", "new", "XLSX", "\\", "Writer", "(", ")", ";", "break", ";", "case", "Type", "::", "ODS", ":", "$", "writer", "=", "new", "ODS", "\\", "Writer", "(", ")", ";", "break", ";", "default", ":", "throw", "new", "UnsupportedTypeException", "(", "'No writers supporting the given type: '", ".", "$", "writerType", ")", ";", "}", "$", "writer", "->", "setGlobalFunctionsHelper", "(", "new", "GlobalFunctionsHelper", "(", ")", ")", ";", "return", "$", "writer", ";", "}" ]
This creates an instance of the appropriate writer, given the type of the file to be read @api @param string $writerType Type of the writer to instantiate @return WriterInterface @throws \Box\Spout\Common\Exception\UnsupportedTypeException
[ "This", "creates", "an", "instance", "of", "the", "appropriate", "writer", "given", "the", "type", "of", "the", "file", "to", "be", "read" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/WriterFactory.php#L26-L47
218,678
moodle/moodle
competency/classes/external.php
external.create_competency_framework
public static function create_competency_framework($competencyframework) { global $PAGE; $params = self::validate_parameters(self::create_competency_framework_parameters(), array( 'competencyframework' => $competencyframework )); $params = $params['competencyframework']; $context = self::get_context_from_params($params); self::validate_context($context); $output = $PAGE->get_renderer('core'); unset($params['contextlevel']); unset($params['instanceid']); $params['contextid'] = $context->id; $params = (object) $params; $result = api::create_framework($params); $exporter = new competency_framework_exporter($result); $record = $exporter->export($output); return $record; }
php
public static function create_competency_framework($competencyframework) { global $PAGE; $params = self::validate_parameters(self::create_competency_framework_parameters(), array( 'competencyframework' => $competencyframework )); $params = $params['competencyframework']; $context = self::get_context_from_params($params); self::validate_context($context); $output = $PAGE->get_renderer('core'); unset($params['contextlevel']); unset($params['instanceid']); $params['contextid'] = $context->id; $params = (object) $params; $result = api::create_framework($params); $exporter = new competency_framework_exporter($result); $record = $exporter->export($output); return $record; }
[ "public", "static", "function", "create_competency_framework", "(", "$", "competencyframework", ")", "{", "global", "$", "PAGE", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "create_competency_framework_parameters", "(", ")", ",", "array", "(", "'competencyframework'", "=>", "$", "competencyframework", ")", ")", ";", "$", "params", "=", "$", "params", "[", "'competencyframework'", "]", ";", "$", "context", "=", "self", "::", "get_context_from_params", "(", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "unset", "(", "$", "params", "[", "'contextlevel'", "]", ")", ";", "unset", "(", "$", "params", "[", "'instanceid'", "]", ")", ";", "$", "params", "[", "'contextid'", "]", "=", "$", "context", "->", "id", ";", "$", "params", "=", "(", "object", ")", "$", "params", ";", "$", "result", "=", "api", "::", "create_framework", "(", "$", "params", ")", ";", "$", "exporter", "=", "new", "competency_framework_exporter", "(", "$", "result", ")", ";", "$", "record", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "return", "$", "record", ";", "}" ]
Create a new competency framework @param array $competencyframework A single param with all the fields for a competency framework. @return \stdClass The new record
[ "Create", "a", "new", "competency", "framework" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L116-L137
218,679
moodle/moodle
competency/classes/external.php
external.read_competency_framework
public static function read_competency_framework($id) { global $PAGE; $params = self::validate_parameters(self::read_competency_framework_parameters(), array( 'id' => $id, )); $framework = api::read_framework($params['id']); self::validate_context($framework->get_context()); $output = $PAGE->get_renderer('core'); $exporter = new competency_framework_exporter($framework); $record = $exporter->export($output); return $record; }
php
public static function read_competency_framework($id) { global $PAGE; $params = self::validate_parameters(self::read_competency_framework_parameters(), array( 'id' => $id, )); $framework = api::read_framework($params['id']); self::validate_context($framework->get_context()); $output = $PAGE->get_renderer('core'); $exporter = new competency_framework_exporter($framework); $record = $exporter->export($output); return $record; }
[ "public", "static", "function", "read_competency_framework", "(", "$", "id", ")", "{", "global", "$", "PAGE", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "read_competency_framework_parameters", "(", ")", ",", "array", "(", "'id'", "=>", "$", "id", ",", ")", ")", ";", "$", "framework", "=", "api", "::", "read_framework", "(", "$", "params", "[", "'id'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "framework", "->", "get_context", "(", ")", ")", ";", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "$", "exporter", "=", "new", "competency_framework_exporter", "(", "$", "framework", ")", ";", "$", "record", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "return", "$", "record", ";", "}" ]
Read a competency framework by id. @param int $id The id of the framework. @return \stdClass
[ "Read", "a", "competency", "framework", "by", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L172-L185
218,680
moodle/moodle
competency/classes/external.php
external.competency_viewed
public static function competency_viewed($id) { $params = self::validate_parameters(self::competency_viewed_parameters(), array( 'id' => $id )); return api::competency_viewed($params['id']); }
php
public static function competency_viewed($id) { $params = self::validate_parameters(self::competency_viewed_parameters(), array( 'id' => $id )); return api::competency_viewed($params['id']); }
[ "public", "static", "function", "competency_viewed", "(", "$", "id", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "competency_viewed_parameters", "(", ")", ",", "array", "(", "'id'", "=>", "$", "id", ")", ")", ";", "return", "api", "::", "competency_viewed", "(", "$", "params", "[", "'id'", "]", ")", ";", "}" ]
Log event competency viewed. @param int $id The competency ID. @return boolean
[ "Log", "event", "competency", "viewed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L219-L224
218,681
moodle/moodle
competency/classes/external.php
external.duplicate_competency_framework
public static function duplicate_competency_framework($id) { global $PAGE; $params = self::validate_parameters(self::duplicate_competency_framework_parameters(), array( 'id' => $id, )); $framework = api::read_framework($params['id']); self::validate_context($framework->get_context()); $output = $PAGE->get_renderer('core'); $framework = api::duplicate_framework($params['id']); $exporter = new competency_framework_exporter($framework); $record = $exporter->export($output); return $record; }
php
public static function duplicate_competency_framework($id) { global $PAGE; $params = self::validate_parameters(self::duplicate_competency_framework_parameters(), array( 'id' => $id, )); $framework = api::read_framework($params['id']); self::validate_context($framework->get_context()); $output = $PAGE->get_renderer('core'); $framework = api::duplicate_framework($params['id']); $exporter = new competency_framework_exporter($framework); $record = $exporter->export($output); return $record; }
[ "public", "static", "function", "duplicate_competency_framework", "(", "$", "id", ")", "{", "global", "$", "PAGE", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "duplicate_competency_framework_parameters", "(", ")", ",", "array", "(", "'id'", "=>", "$", "id", ",", ")", ")", ";", "$", "framework", "=", "api", "::", "read_framework", "(", "$", "params", "[", "'id'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "framework", "->", "get_context", "(", ")", ")", ";", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "$", "framework", "=", "api", "::", "duplicate_framework", "(", "$", "params", "[", "'id'", "]", ")", ";", "$", "exporter", "=", "new", "competency_framework_exporter", "(", "$", "framework", ")", ";", "$", "record", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "return", "$", "record", ";", "}" ]
Duplicate a competency framework @param int $id The competency framework id @return boolean
[ "Duplicate", "a", "competency", "framework" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L259-L273
218,682
moodle/moodle
competency/classes/external.php
external.delete_competency_framework
public static function delete_competency_framework($id) { $params = self::validate_parameters(self::delete_competency_framework_parameters(), array( 'id' => $id, )); $framework = api::read_framework($params['id']); self::validate_context($framework->get_context()); return api::delete_framework($params['id']); }
php
public static function delete_competency_framework($id) { $params = self::validate_parameters(self::delete_competency_framework_parameters(), array( 'id' => $id, )); $framework = api::read_framework($params['id']); self::validate_context($framework->get_context()); return api::delete_framework($params['id']); }
[ "public", "static", "function", "delete_competency_framework", "(", "$", "id", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "delete_competency_framework_parameters", "(", ")", ",", "array", "(", "'id'", "=>", "$", "id", ",", ")", ")", ";", "$", "framework", "=", "api", "::", "read_framework", "(", "$", "params", "[", "'id'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "framework", "->", "get_context", "(", ")", ")", ";", "return", "api", "::", "delete_framework", "(", "$", "params", "[", "'id'", "]", ")", ";", "}" ]
Delete a competency framework @param int $id The competency framework id @return boolean
[ "Delete", "a", "competency", "framework" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L308-L317
218,683
moodle/moodle
competency/classes/external.php
external.update_competency_framework
public static function update_competency_framework($competencyframework) { $params = self::validate_parameters(self::update_competency_framework_parameters(), array( 'competencyframework' => $competencyframework )); $params = $params['competencyframework']; $framework = api::read_framework($params['id']); self::validate_context($framework->get_context()); $params = (object) $params; return api::update_framework($params); }
php
public static function update_competency_framework($competencyframework) { $params = self::validate_parameters(self::update_competency_framework_parameters(), array( 'competencyframework' => $competencyframework )); $params = $params['competencyframework']; $framework = api::read_framework($params['id']); self::validate_context($framework->get_context()); $params = (object) $params; return api::update_framework($params); }
[ "public", "static", "function", "update_competency_framework", "(", "$", "competencyframework", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "update_competency_framework_parameters", "(", ")", ",", "array", "(", "'competencyframework'", "=>", "$", "competencyframework", ")", ")", ";", "$", "params", "=", "$", "params", "[", "'competencyframework'", "]", ";", "$", "framework", "=", "api", "::", "read_framework", "(", "$", "params", "[", "'id'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "framework", "->", "get_context", "(", ")", ")", ";", "$", "params", "=", "(", "object", ")", "$", "params", ";", "return", "api", "::", "update_framework", "(", "$", "params", ")", ";", "}" ]
Update an existing competency framework @param array $competencyframework An array with all the fields for a competency framework. @return boolean
[ "Update", "an", "existing", "competency", "framework" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L345-L358
218,684
moodle/moodle
competency/classes/external.php
external.count_competency_frameworks
public static function count_competency_frameworks($context, $includes) { $params = self::validate_parameters(self::count_competency_frameworks_parameters(), array( 'context' => $context, 'includes' => $includes )); $context = self::get_context_from_params($params['context']); self::validate_context($context); return api::count_frameworks($context, $params['includes']); }
php
public static function count_competency_frameworks($context, $includes) { $params = self::validate_parameters(self::count_competency_frameworks_parameters(), array( 'context' => $context, 'includes' => $includes )); $context = self::get_context_from_params($params['context']); self::validate_context($context); return api::count_frameworks($context, $params['includes']); }
[ "public", "static", "function", "count_competency_frameworks", "(", "$", "context", ",", "$", "includes", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "count_competency_frameworks_parameters", "(", ")", ",", "array", "(", "'context'", "=>", "$", "context", ",", "'includes'", "=>", "$", "includes", ")", ")", ";", "$", "context", "=", "self", "::", "get_context_from_params", "(", "$", "params", "[", "'context'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "return", "api", "::", "count_frameworks", "(", "$", "context", ",", "$", "params", "[", "'includes'", "]", ")", ";", "}" ]
Count the existing competency frameworks @param array $context @param string $includes @return int
[ "Count", "the", "existing", "competency", "frameworks" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L523-L533
218,685
moodle/moodle
competency/classes/external.php
external.competency_framework_viewed
public static function competency_framework_viewed($id) { $params = self::validate_parameters(self::competency_framework_viewed_parameters(), array( 'id' => $id )); return api::competency_framework_viewed($params['id']); }
php
public static function competency_framework_viewed($id) { $params = self::validate_parameters(self::competency_framework_viewed_parameters(), array( 'id' => $id )); return api::competency_framework_viewed($params['id']); }
[ "public", "static", "function", "competency_framework_viewed", "(", "$", "id", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "competency_framework_viewed_parameters", "(", ")", ",", "array", "(", "'id'", "=>", "$", "id", ")", ")", ";", "return", "api", "::", "competency_framework_viewed", "(", "$", "params", "[", "'id'", "]", ")", ";", "}" ]
Log event competency framework viewed. @param int $id The competency framework ID. @return boolean
[ "Log", "event", "competency", "framework", "viewed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L568-L574
218,686
moodle/moodle
competency/classes/external.php
external.create_competency
public static function create_competency($competency) { global $PAGE; $params = self::validate_parameters(self::create_competency_parameters(), array( 'competency' => $competency )); $params = $params['competency']; $framework = api::read_framework($params['competencyframeworkid']); $context = $framework->get_context(); self::validate_context($context); $output = $PAGE->get_renderer('core'); $params = (object) $params; $result = api::create_competency($params); $exporter = new competency_exporter($result, array('context' => $context)); $record = $exporter->export($output); return $record; }
php
public static function create_competency($competency) { global $PAGE; $params = self::validate_parameters(self::create_competency_parameters(), array( 'competency' => $competency )); $params = $params['competency']; $framework = api::read_framework($params['competencyframeworkid']); $context = $framework->get_context(); self::validate_context($context); $output = $PAGE->get_renderer('core'); $params = (object) $params; $result = api::create_competency($params); $exporter = new competency_exporter($result, array('context' => $context)); $record = $exporter->export($output); return $record; }
[ "public", "static", "function", "create_competency", "(", "$", "competency", ")", "{", "global", "$", "PAGE", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "create_competency_parameters", "(", ")", ",", "array", "(", "'competency'", "=>", "$", "competency", ")", ")", ";", "$", "params", "=", "$", "params", "[", "'competency'", "]", ";", "$", "framework", "=", "api", "::", "read_framework", "(", "$", "params", "[", "'competencyframeworkid'", "]", ")", ";", "$", "context", "=", "$", "framework", "->", "get_context", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "$", "params", "=", "(", "object", ")", "$", "params", ";", "$", "result", "=", "api", "::", "create_competency", "(", "$", "params", ")", ";", "$", "exporter", "=", "new", "competency_exporter", "(", "$", "result", ",", "array", "(", "'context'", "=>", "$", "context", ")", ")", ";", "$", "record", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "return", "$", "record", ";", "}" ]
Create a new competency @param array $competency All the fields for a competency record (including id) @return array the competency
[ "Create", "a", "new", "competency" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L602-L620
218,687
moodle/moodle
competency/classes/external.php
external.read_competency
public static function read_competency($id) { global $PAGE; $params = self::validate_parameters(self::read_competency_parameters(), array( 'id' => $id, )); $competency = api::read_competency($params['id']); $context = $competency->get_context(); self::validate_context($context); $output = $PAGE->get_renderer('core'); $exporter = new competency_exporter($competency, array('context' => $context)); $record = $exporter->export($output); return $record; }
php
public static function read_competency($id) { global $PAGE; $params = self::validate_parameters(self::read_competency_parameters(), array( 'id' => $id, )); $competency = api::read_competency($params['id']); $context = $competency->get_context(); self::validate_context($context); $output = $PAGE->get_renderer('core'); $exporter = new competency_exporter($competency, array('context' => $context)); $record = $exporter->export($output); return $record; }
[ "public", "static", "function", "read_competency", "(", "$", "id", ")", "{", "global", "$", "PAGE", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "read_competency_parameters", "(", ")", ",", "array", "(", "'id'", "=>", "$", "id", ",", ")", ")", ";", "$", "competency", "=", "api", "::", "read_competency", "(", "$", "params", "[", "'id'", "]", ")", ";", "$", "context", "=", "$", "competency", "->", "get_context", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "$", "exporter", "=", "new", "competency_exporter", "(", "$", "competency", ",", "array", "(", "'context'", "=>", "$", "context", ")", ")", ";", "$", "record", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "return", "$", "record", ";", "}" ]
Read a competency by id. @param int $id The id of the competency @return \stdClass
[ "Read", "a", "competency", "by", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L655-L669
218,688
moodle/moodle
competency/classes/external.php
external.delete_competency
public static function delete_competency($id) { $params = self::validate_parameters(self::delete_competency_parameters(), array( 'id' => $id, )); $competency = api::read_competency($params['id']); $context = $competency->get_context(); self::validate_context($context); return api::delete_competency($params['id']); }
php
public static function delete_competency($id) { $params = self::validate_parameters(self::delete_competency_parameters(), array( 'id' => $id, )); $competency = api::read_competency($params['id']); $context = $competency->get_context(); self::validate_context($context); return api::delete_competency($params['id']); }
[ "public", "static", "function", "delete_competency", "(", "$", "id", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "delete_competency_parameters", "(", ")", ",", "array", "(", "'id'", "=>", "$", "id", ",", ")", ")", ";", "$", "competency", "=", "api", "::", "read_competency", "(", "$", "params", "[", "'id'", "]", ")", ";", "$", "context", "=", "$", "competency", "->", "get_context", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "return", "api", "::", "delete_competency", "(", "$", "params", "[", "'id'", "]", ")", ";", "}" ]
Delete a competency @param int $id The competency id @return boolean
[ "Delete", "a", "competency" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L704-L714
218,689
moodle/moodle
competency/classes/external.php
external.update_competency
public static function update_competency($competency) { $params = self::validate_parameters(self::update_competency_parameters(), array( 'competency' => $competency )); $params = $params['competency']; $competency = api::read_competency($params['id']); self::validate_context($competency->get_context()); $params = (object) $params; return api::update_competency($params); }
php
public static function update_competency($competency) { $params = self::validate_parameters(self::update_competency_parameters(), array( 'competency' => $competency )); $params = $params['competency']; $competency = api::read_competency($params['id']); self::validate_context($competency->get_context()); $params = (object) $params; return api::update_competency($params); }
[ "public", "static", "function", "update_competency", "(", "$", "competency", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "update_competency_parameters", "(", ")", ",", "array", "(", "'competency'", "=>", "$", "competency", ")", ")", ";", "$", "params", "=", "$", "params", "[", "'competency'", "]", ";", "$", "competency", "=", "api", "::", "read_competency", "(", "$", "params", "[", "'id'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "competency", "->", "get_context", "(", ")", ")", ";", "$", "params", "=", "(", "object", ")", "$", "params", ";", "return", "api", "::", "update_competency", "(", "$", "params", ")", ";", "}" ]
Update an existing competency @param array $competency The array of competency fields (id is required). @return boolean
[ "Update", "an", "existing", "competency" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L742-L754
218,690
moodle/moodle
competency/classes/external.php
external.list_competencies
public static function list_competencies($filters, $sort, $order, $skip, $limit) { global $PAGE; $params = self::validate_parameters(self::list_competencies_parameters(), array( 'filters' => $filters, 'sort' => $sort, 'order' => $order, 'skip' => $skip, 'limit' => $limit )); if ($params['order'] !== '' && $params['order'] !== 'ASC' && $params['order'] !== 'DESC') { throw new invalid_parameter_exception('Invalid order param. Must be ASC, DESC or empty.'); } $safefilters = array(); $validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'parentid', 'competencyframeworkid'); foreach ($params['filters'] as $filter) { if (!in_array($filter['column'], $validcolumns)) { throw new invalid_parameter_exception('Filter column was invalid'); } $safefilters[$filter['column']] = $filter['value']; } $context = null; if (isset($safefilters['competencyframeworkid'])) { $framework = api::read_framework($safefilters['competencyframeworkid']); $context = $framework->get_context(); } else { $context = context_system::instance(); } self::validate_context($context); $output = $PAGE->get_renderer('core'); $results = api::list_competencies( $safefilters, $params['sort'], $params['order'], $params['skip'], $params['limit'] ); $records = array(); foreach ($results as $result) { $exporter = new competency_exporter($result, array('context' => $context)); $record = $exporter->export($output); array_push($records, $record); } return $records; }
php
public static function list_competencies($filters, $sort, $order, $skip, $limit) { global $PAGE; $params = self::validate_parameters(self::list_competencies_parameters(), array( 'filters' => $filters, 'sort' => $sort, 'order' => $order, 'skip' => $skip, 'limit' => $limit )); if ($params['order'] !== '' && $params['order'] !== 'ASC' && $params['order'] !== 'DESC') { throw new invalid_parameter_exception('Invalid order param. Must be ASC, DESC or empty.'); } $safefilters = array(); $validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'parentid', 'competencyframeworkid'); foreach ($params['filters'] as $filter) { if (!in_array($filter['column'], $validcolumns)) { throw new invalid_parameter_exception('Filter column was invalid'); } $safefilters[$filter['column']] = $filter['value']; } $context = null; if (isset($safefilters['competencyframeworkid'])) { $framework = api::read_framework($safefilters['competencyframeworkid']); $context = $framework->get_context(); } else { $context = context_system::instance(); } self::validate_context($context); $output = $PAGE->get_renderer('core'); $results = api::list_competencies( $safefilters, $params['sort'], $params['order'], $params['skip'], $params['limit'] ); $records = array(); foreach ($results as $result) { $exporter = new competency_exporter($result, array('context' => $context)); $record = $exporter->export($output); array_push($records, $record); } return $records; }
[ "public", "static", "function", "list_competencies", "(", "$", "filters", ",", "$", "sort", ",", "$", "order", ",", "$", "skip", ",", "$", "limit", ")", "{", "global", "$", "PAGE", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "list_competencies_parameters", "(", ")", ",", "array", "(", "'filters'", "=>", "$", "filters", ",", "'sort'", "=>", "$", "sort", ",", "'order'", "=>", "$", "order", ",", "'skip'", "=>", "$", "skip", ",", "'limit'", "=>", "$", "limit", ")", ")", ";", "if", "(", "$", "params", "[", "'order'", "]", "!==", "''", "&&", "$", "params", "[", "'order'", "]", "!==", "'ASC'", "&&", "$", "params", "[", "'order'", "]", "!==", "'DESC'", ")", "{", "throw", "new", "invalid_parameter_exception", "(", "'Invalid order param. Must be ASC, DESC or empty.'", ")", ";", "}", "$", "safefilters", "=", "array", "(", ")", ";", "$", "validcolumns", "=", "array", "(", "'id'", ",", "'shortname'", ",", "'description'", ",", "'sortorder'", ",", "'idnumber'", ",", "'parentid'", ",", "'competencyframeworkid'", ")", ";", "foreach", "(", "$", "params", "[", "'filters'", "]", "as", "$", "filter", ")", "{", "if", "(", "!", "in_array", "(", "$", "filter", "[", "'column'", "]", ",", "$", "validcolumns", ")", ")", "{", "throw", "new", "invalid_parameter_exception", "(", "'Filter column was invalid'", ")", ";", "}", "$", "safefilters", "[", "$", "filter", "[", "'column'", "]", "]", "=", "$", "filter", "[", "'value'", "]", ";", "}", "$", "context", "=", "null", ";", "if", "(", "isset", "(", "$", "safefilters", "[", "'competencyframeworkid'", "]", ")", ")", "{", "$", "framework", "=", "api", "::", "read_framework", "(", "$", "safefilters", "[", "'competencyframeworkid'", "]", ")", ";", "$", "context", "=", "$", "framework", "->", "get_context", "(", ")", ";", "}", "else", "{", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "}", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "$", "results", "=", "api", "::", "list_competencies", "(", "$", "safefilters", ",", "$", "params", "[", "'sort'", "]", ",", "$", "params", "[", "'order'", "]", ",", "$", "params", "[", "'skip'", "]", ",", "$", "params", "[", "'limit'", "]", ")", ";", "$", "records", "=", "array", "(", ")", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "exporter", "=", "new", "competency_exporter", "(", "$", "result", ",", "array", "(", "'context'", "=>", "$", "context", ")", ")", ";", "$", "record", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "array_push", "(", "$", "records", ",", "$", "record", ")", ";", "}", "return", "$", "records", ";", "}" ]
List the existing competency. @param string $filters @param int $sort @param string $order @param string $skip @param int $limit @return array @throws \required_capability_exception @throws invalid_parameter_exception
[ "List", "the", "existing", "competency", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L825-L876
218,691
moodle/moodle
competency/classes/external.php
external.count_competencies
public static function count_competencies($filters) { $params = self::validate_parameters(self::count_competencies_parameters(), array( 'filters' => $filters )); $safefilters = array(); $validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'parentid', 'competencyframeworkid'); foreach ($params['filters'] as $filter) { if (!in_array($filter['column'], $validcolumns)) { throw new invalid_parameter_exception('Filter column was invalid'); } $safefilters[$filter['column']] = $filter['value']; } $context = null; if (isset($safefilters['competencyframeworkid'])) { $framework = api::read_framework($safefilters['competencyframeworkid']); $context = $framework->get_context(); } else { $context = context_system::instance(); } self::validate_context($context); return api::count_competencies($safefilters); }
php
public static function count_competencies($filters) { $params = self::validate_parameters(self::count_competencies_parameters(), array( 'filters' => $filters )); $safefilters = array(); $validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'parentid', 'competencyframeworkid'); foreach ($params['filters'] as $filter) { if (!in_array($filter['column'], $validcolumns)) { throw new invalid_parameter_exception('Filter column was invalid'); } $safefilters[$filter['column']] = $filter['value']; } $context = null; if (isset($safefilters['competencyframeworkid'])) { $framework = api::read_framework($safefilters['competencyframeworkid']); $context = $framework->get_context(); } else { $context = context_system::instance(); } self::validate_context($context); return api::count_competencies($safefilters); }
[ "public", "static", "function", "count_competencies", "(", "$", "filters", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "count_competencies_parameters", "(", ")", ",", "array", "(", "'filters'", "=>", "$", "filters", ")", ")", ";", "$", "safefilters", "=", "array", "(", ")", ";", "$", "validcolumns", "=", "array", "(", "'id'", ",", "'shortname'", ",", "'description'", ",", "'sortorder'", ",", "'idnumber'", ",", "'parentid'", ",", "'competencyframeworkid'", ")", ";", "foreach", "(", "$", "params", "[", "'filters'", "]", "as", "$", "filter", ")", "{", "if", "(", "!", "in_array", "(", "$", "filter", "[", "'column'", "]", ",", "$", "validcolumns", ")", ")", "{", "throw", "new", "invalid_parameter_exception", "(", "'Filter column was invalid'", ")", ";", "}", "$", "safefilters", "[", "$", "filter", "[", "'column'", "]", "]", "=", "$", "filter", "[", "'value'", "]", ";", "}", "$", "context", "=", "null", ";", "if", "(", "isset", "(", "$", "safefilters", "[", "'competencyframeworkid'", "]", ")", ")", "{", "$", "framework", "=", "api", "::", "read_framework", "(", "$", "safefilters", "[", "'competencyframeworkid'", "]", ")", ";", "$", "context", "=", "$", "framework", "->", "get_context", "(", ")", ";", "}", "else", "{", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "}", "self", "::", "validate_context", "(", "$", "context", ")", ";", "return", "api", "::", "count_competencies", "(", "$", "safefilters", ")", ";", "}" ]
Count the existing competency frameworks. @param string $filters Filters to use. @return boolean
[ "Count", "the", "existing", "competency", "frameworks", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L978-L1003
218,692
moodle/moodle
competency/classes/external.php
external.set_parent_competency
public static function set_parent_competency($competencyid, $parentid) { $params = self::validate_parameters(self::set_parent_competency_parameters(), array( 'competencyid' => $competencyid, 'parentid' => $parentid )); $competency = api::read_competency($params['competencyid']); self::validate_context($competency->get_context()); return api::set_parent_competency($params['competencyid'], $params['parentid']); }
php
public static function set_parent_competency($competencyid, $parentid) { $params = self::validate_parameters(self::set_parent_competency_parameters(), array( 'competencyid' => $competencyid, 'parentid' => $parentid )); $competency = api::read_competency($params['competencyid']); self::validate_context($competency->get_context()); return api::set_parent_competency($params['competencyid'], $params['parentid']); }
[ "public", "static", "function", "set_parent_competency", "(", "$", "competencyid", ",", "$", "parentid", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "set_parent_competency_parameters", "(", ")", ",", "array", "(", "'competencyid'", "=>", "$", "competencyid", ",", "'parentid'", "=>", "$", "parentid", ")", ")", ";", "$", "competency", "=", "api", "::", "read_competency", "(", "$", "params", "[", "'competencyid'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "competency", "->", "get_context", "(", ")", ")", ";", "return", "api", "::", "set_parent_competency", "(", "$", "params", "[", "'competencyid'", "]", ",", "$", "params", "[", "'parentid'", "]", ")", ";", "}" ]
Move the competency to a new parent. @param int $competencyid Competency id. @param int $parentid Parent id. @return bool
[ "Move", "the", "competency", "to", "a", "new", "parent", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L1045-L1055
218,693
moodle/moodle
competency/classes/external.php
external.reorder_course_competency
public static function reorder_course_competency($courseid, $competencyidfrom, $competencyidto) { $params = self::validate_parameters(self::reorder_course_competency_parameters(), array( 'courseid' => $courseid, 'competencyidfrom' => $competencyidfrom, 'competencyidto' => $competencyidto, )); self::validate_context(context_course::instance($params['courseid'])); return api::reorder_course_competency($params['courseid'], $params['competencyidfrom'], $params['competencyidto']); }
php
public static function reorder_course_competency($courseid, $competencyidfrom, $competencyidto) { $params = self::validate_parameters(self::reorder_course_competency_parameters(), array( 'courseid' => $courseid, 'competencyidfrom' => $competencyidfrom, 'competencyidto' => $competencyidto, )); self::validate_context(context_course::instance($params['courseid'])); return api::reorder_course_competency($params['courseid'], $params['competencyidfrom'], $params['competencyidto']); }
[ "public", "static", "function", "reorder_course_competency", "(", "$", "courseid", ",", "$", "competencyidfrom", ",", "$", "competencyidto", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "reorder_course_competency_parameters", "(", ")", ",", "array", "(", "'courseid'", "=>", "$", "courseid", ",", "'competencyidfrom'", "=>", "$", "competencyidfrom", ",", "'competencyidto'", "=>", "$", "competencyidto", ",", ")", ")", ";", "self", "::", "validate_context", "(", "context_course", "::", "instance", "(", "$", "params", "[", "'courseid'", "]", ")", ")", ";", "return", "api", "::", "reorder_course_competency", "(", "$", "params", "[", "'courseid'", "]", ",", "$", "params", "[", "'competencyidfrom'", "]", ",", "$", "params", "[", "'competencyidto'", "]", ")", ";", "}" ]
Change the order of course competencies. @param int $courseid The course id @param int $competencyidfrom The competency to move. @param int $competencyidto The competency to move to. @return bool
[ "Change", "the", "order", "of", "course", "competencies", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L1505-L1513
218,694
moodle/moodle
competency/classes/external.php
external.reorder_template_competency
public static function reorder_template_competency($templateid, $competencyidfrom, $competencyidto) { $params = self::validate_parameters(self::reorder_template_competency_parameters(), array( 'templateid' => $templateid, 'competencyidfrom' => $competencyidfrom, 'competencyidto' => $competencyidto, )); $template = api::read_template($params['templateid']); self::validate_context($template->get_context()); return api::reorder_template_competency($params['templateid'], $params['competencyidfrom'], $params['competencyidto']); }
php
public static function reorder_template_competency($templateid, $competencyidfrom, $competencyidto) { $params = self::validate_parameters(self::reorder_template_competency_parameters(), array( 'templateid' => $templateid, 'competencyidfrom' => $competencyidfrom, 'competencyidto' => $competencyidto, )); $template = api::read_template($params['templateid']); self::validate_context($template->get_context()); return api::reorder_template_competency($params['templateid'], $params['competencyidfrom'], $params['competencyidto']); }
[ "public", "static", "function", "reorder_template_competency", "(", "$", "templateid", ",", "$", "competencyidfrom", ",", "$", "competencyidto", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "reorder_template_competency_parameters", "(", ")", ",", "array", "(", "'templateid'", "=>", "$", "templateid", ",", "'competencyidfrom'", "=>", "$", "competencyidfrom", ",", "'competencyidto'", "=>", "$", "competencyidto", ",", ")", ")", ";", "$", "template", "=", "api", "::", "read_template", "(", "$", "params", "[", "'templateid'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "template", "->", "get_context", "(", ")", ")", ";", "return", "api", "::", "reorder_template_competency", "(", "$", "params", "[", "'templateid'", "]", ",", "$", "params", "[", "'competencyidfrom'", "]", ",", "$", "params", "[", "'competencyidto'", "]", ")", ";", "}" ]
Change the order of template competencies. @param int $templateid The template id @param int $competencyidfrom The competency to move. @param int $competencyidto The competency to move to. @return bool
[ "Change", "the", "order", "of", "template", "competencies", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L1561-L1572
218,695
moodle/moodle
competency/classes/external.php
external.create_template
public static function create_template($template) { global $PAGE; $params = self::validate_parameters(self::create_template_parameters(), array('template' => $template)); $params = $params['template']; $context = self::get_context_from_params($params); self::validate_context($context); $output = $PAGE->get_renderer('core'); unset($params['contextlevel']); unset($params['instanceid']); $params = (object) $params; $params->contextid = $context->id; $result = api::create_template($params); $exporter = new template_exporter($result); $record = $exporter->export($output); return $record; }
php
public static function create_template($template) { global $PAGE; $params = self::validate_parameters(self::create_template_parameters(), array('template' => $template)); $params = $params['template']; $context = self::get_context_from_params($params); self::validate_context($context); $output = $PAGE->get_renderer('core'); unset($params['contextlevel']); unset($params['instanceid']); $params = (object) $params; $params->contextid = $context->id; $result = api::create_template($params); $exporter = new template_exporter($result); $record = $exporter->export($output); return $record; }
[ "public", "static", "function", "create_template", "(", "$", "template", ")", "{", "global", "$", "PAGE", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "create_template_parameters", "(", ")", ",", "array", "(", "'template'", "=>", "$", "template", ")", ")", ";", "$", "params", "=", "$", "params", "[", "'template'", "]", ";", "$", "context", "=", "self", "::", "get_context_from_params", "(", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "unset", "(", "$", "params", "[", "'contextlevel'", "]", ")", ";", "unset", "(", "$", "params", "[", "'instanceid'", "]", ")", ";", "$", "params", "=", "(", "object", ")", "$", "params", ";", "$", "params", "->", "contextid", "=", "$", "context", "->", "id", ";", "$", "result", "=", "api", "::", "create_template", "(", "$", "params", ")", ";", "$", "exporter", "=", "new", "template_exporter", "(", "$", "result", ")", ";", "$", "record", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "return", "$", "record", ";", "}" ]
Create a new learning plan template @param array $template The list of fields for the template. @return \stdClass Record of new template.
[ "Create", "a", "new", "learning", "plan", "template" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L1600-L1618
218,696
moodle/moodle
competency/classes/external.php
external.read_template
public static function read_template($id) { global $PAGE; $params = self::validate_parameters(self::read_template_parameters(), array('id' => $id)); $template = api::read_template($params['id']); self::validate_context($template->get_context()); $output = $PAGE->get_renderer('core'); $exporter = new template_exporter($template); $record = $exporter->export($output); return $record; }
php
public static function read_template($id) { global $PAGE; $params = self::validate_parameters(self::read_template_parameters(), array('id' => $id)); $template = api::read_template($params['id']); self::validate_context($template->get_context()); $output = $PAGE->get_renderer('core'); $exporter = new template_exporter($template); $record = $exporter->export($output); return $record; }
[ "public", "static", "function", "read_template", "(", "$", "id", ")", "{", "global", "$", "PAGE", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "read_template_parameters", "(", ")", ",", "array", "(", "'id'", "=>", "$", "id", ")", ")", ";", "$", "template", "=", "api", "::", "read_template", "(", "$", "params", "[", "'id'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "template", "->", "get_context", "(", ")", ")", ";", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "$", "exporter", "=", "new", "template_exporter", "(", "$", "template", ")", ";", "$", "record", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "return", "$", "record", ";", "}" ]
Read a learning plan template by id. @param int $id The id of the template. @return \stdClass
[ "Read", "a", "learning", "plan", "template", "by", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L1653-L1664
218,697
moodle/moodle
competency/classes/external.php
external.delete_template
public static function delete_template($id, $deleteplans = true) { $params = self::validate_parameters(self::delete_template_parameters(), array( 'id' => $id, 'deleteplans' => $deleteplans, )); $template = api::read_template($params['id']); self::validate_context($template->get_context()); return api::delete_template($params['id'], $params['deleteplans']); }
php
public static function delete_template($id, $deleteplans = true) { $params = self::validate_parameters(self::delete_template_parameters(), array( 'id' => $id, 'deleteplans' => $deleteplans, )); $template = api::read_template($params['id']); self::validate_context($template->get_context()); return api::delete_template($params['id'], $params['deleteplans']); }
[ "public", "static", "function", "delete_template", "(", "$", "id", ",", "$", "deleteplans", "=", "true", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "delete_template_parameters", "(", ")", ",", "array", "(", "'id'", "=>", "$", "id", ",", "'deleteplans'", "=>", "$", "deleteplans", ",", ")", ")", ";", "$", "template", "=", "api", "::", "read_template", "(", "$", "params", "[", "'id'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "template", "->", "get_context", "(", ")", ")", ";", "return", "api", "::", "delete_template", "(", "$", "params", "[", "'id'", "]", ",", "$", "params", "[", "'deleteplans'", "]", ")", ";", "}" ]
Delete a learning plan template @param int $id The learning plan template id @param boolean $deleteplans True to delete the plans associated to template or false to unlink them @return boolean
[ "Delete", "a", "learning", "plan", "template" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L1707-L1717
218,698
moodle/moodle
competency/classes/external.php
external.update_template
public static function update_template($template) { $params = self::validate_parameters(self::update_template_parameters(), array('template' => $template)); $params = $params['template']; $template = api::read_template($params['id']); self::validate_context($template->get_context()); $params = (object) $params; return api::update_template($params); }
php
public static function update_template($template) { $params = self::validate_parameters(self::update_template_parameters(), array('template' => $template)); $params = $params['template']; $template = api::read_template($params['id']); self::validate_context($template->get_context()); $params = (object) $params; return api::update_template($params); }
[ "public", "static", "function", "update_template", "(", "$", "template", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "update_template_parameters", "(", ")", ",", "array", "(", "'template'", "=>", "$", "template", ")", ")", ";", "$", "params", "=", "$", "params", "[", "'template'", "]", ";", "$", "template", "=", "api", "::", "read_template", "(", "$", "params", "[", "'id'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "template", "->", "get_context", "(", ")", ")", ";", "$", "params", "=", "(", "object", ")", "$", "params", ";", "return", "api", "::", "update_template", "(", "$", "params", ")", ";", "}" ]
Update an existing learning plan template @param array $template The list of fields for the template. @return boolean
[ "Update", "an", "existing", "learning", "plan", "template" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L1745-L1755
218,699
moodle/moodle
competency/classes/external.php
external.list_templates
public static function list_templates($sort, $order, $skip, $limit, $context, $includes, $onlyvisible) { global $PAGE; $params = self::validate_parameters(self::list_templates_parameters(), array( 'sort' => $sort, 'order' => $order, 'skip' => $skip, 'limit' => $limit, 'context' => $context, 'includes' => $includes, 'onlyvisible' => $onlyvisible )); $context = self::get_context_from_params($params['context']); self::validate_context($context); $output = $PAGE->get_renderer('core'); if ($params['order'] !== '' && $params['order'] !== 'ASC' && $params['order'] !== 'DESC') { throw new invalid_parameter_exception('Invalid order param. Must be ASC, DESC or empty.'); } $results = api::list_templates($params['sort'], $params['order'], $params['skip'], $params['limit'], $context, $params['includes'], $params['onlyvisible']); $records = array(); foreach ($results as $result) { $exporter = new template_exporter($result); $record = $exporter->export($output); array_push($records, $record); } return $records; }
php
public static function list_templates($sort, $order, $skip, $limit, $context, $includes, $onlyvisible) { global $PAGE; $params = self::validate_parameters(self::list_templates_parameters(), array( 'sort' => $sort, 'order' => $order, 'skip' => $skip, 'limit' => $limit, 'context' => $context, 'includes' => $includes, 'onlyvisible' => $onlyvisible )); $context = self::get_context_from_params($params['context']); self::validate_context($context); $output = $PAGE->get_renderer('core'); if ($params['order'] !== '' && $params['order'] !== 'ASC' && $params['order'] !== 'DESC') { throw new invalid_parameter_exception('Invalid order param. Must be ASC, DESC or empty.'); } $results = api::list_templates($params['sort'], $params['order'], $params['skip'], $params['limit'], $context, $params['includes'], $params['onlyvisible']); $records = array(); foreach ($results as $result) { $exporter = new template_exporter($result); $record = $exporter->export($output); array_push($records, $record); } return $records; }
[ "public", "static", "function", "list_templates", "(", "$", "sort", ",", "$", "order", ",", "$", "skip", ",", "$", "limit", ",", "$", "context", ",", "$", "includes", ",", "$", "onlyvisible", ")", "{", "global", "$", "PAGE", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "list_templates_parameters", "(", ")", ",", "array", "(", "'sort'", "=>", "$", "sort", ",", "'order'", "=>", "$", "order", ",", "'skip'", "=>", "$", "skip", ",", "'limit'", "=>", "$", "limit", ",", "'context'", "=>", "$", "context", ",", "'includes'", "=>", "$", "includes", ",", "'onlyvisible'", "=>", "$", "onlyvisible", ")", ")", ";", "$", "context", "=", "self", "::", "get_context_from_params", "(", "$", "params", "[", "'context'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "if", "(", "$", "params", "[", "'order'", "]", "!==", "''", "&&", "$", "params", "[", "'order'", "]", "!==", "'ASC'", "&&", "$", "params", "[", "'order'", "]", "!==", "'DESC'", ")", "{", "throw", "new", "invalid_parameter_exception", "(", "'Invalid order param. Must be ASC, DESC or empty.'", ")", ";", "}", "$", "results", "=", "api", "::", "list_templates", "(", "$", "params", "[", "'sort'", "]", ",", "$", "params", "[", "'order'", "]", ",", "$", "params", "[", "'skip'", "]", ",", "$", "params", "[", "'limit'", "]", ",", "$", "context", ",", "$", "params", "[", "'includes'", "]", ",", "$", "params", "[", "'onlyvisible'", "]", ")", ";", "$", "records", "=", "array", "(", ")", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "exporter", "=", "new", "template_exporter", "(", "$", "result", ")", ";", "$", "record", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "array_push", "(", "$", "records", ",", "$", "record", ")", ";", "}", "return", "$", "records", ";", "}" ]
List the existing learning plan templates @param string $sort Field to sort by. @param string $order Sort order. @param int $skip Limitstart. @param int $limit Number of rows to return. @param array $context @param bool $includes @param bool $onlyvisible @return array
[ "List", "the", "existing", "learning", "plan", "templates" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external.php#L1881-L1916