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,400
moodle/moodle
cache/classes/helper.php
cache_helper.purge_by_definition
public static function purge_by_definition($component, $area, array $identifiers = array()) { // Create the cache. $cache = cache::make($component, $area, $identifiers); // Initialise, in case of a store. if ($cache instanceof cache_store) { $factory = cache_factory::instance(); $definition = $factory->create_definition($component, $area, null); $cacheddefinition = clone $definition; $cacheddefinition->set_identifiers($identifiers); $cache->initialise($cacheddefinition); } // Purge baby, purge. $cache->purge(); return true; }
php
public static function purge_by_definition($component, $area, array $identifiers = array()) { // Create the cache. $cache = cache::make($component, $area, $identifiers); // Initialise, in case of a store. if ($cache instanceof cache_store) { $factory = cache_factory::instance(); $definition = $factory->create_definition($component, $area, null); $cacheddefinition = clone $definition; $cacheddefinition->set_identifiers($identifiers); $cache->initialise($cacheddefinition); } // Purge baby, purge. $cache->purge(); return true; }
[ "public", "static", "function", "purge_by_definition", "(", "$", "component", ",", "$", "area", ",", "array", "$", "identifiers", "=", "array", "(", ")", ")", "{", "// Create the cache.", "$", "cache", "=", "cache", "::", "make", "(", "$", "component", ",", "$", "area", ",", "$", "identifiers", ")", ";", "// Initialise, in case of a store.", "if", "(", "$", "cache", "instanceof", "cache_store", ")", "{", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "$", "definition", "=", "$", "factory", "->", "create_definition", "(", "$", "component", ",", "$", "area", ",", "null", ")", ";", "$", "cacheddefinition", "=", "clone", "$", "definition", ";", "$", "cacheddefinition", "->", "set_identifiers", "(", "$", "identifiers", ")", ";", "$", "cache", "->", "initialise", "(", "$", "cacheddefinition", ")", ";", "}", "// Purge baby, purge.", "$", "cache", "->", "purge", "(", ")", ";", "return", "true", ";", "}" ]
Purges the cache for a specific definition. @param string $component @param string $area @param array $identifiers @return bool
[ "Purges", "the", "cache", "for", "a", "specific", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L293-L307
218,401
moodle/moodle
cache/classes/helper.php
cache_helper.ensure_ready_for_stats
protected static function ensure_ready_for_stats($store, $definition, $mode = cache_store::MODE_APPLICATION) { // This function is performance-sensitive, so exit as quickly as possible // if we do not need to do anything. if (isset(self::$stats[$definition]['stores'][$store])) { return; } if (!array_key_exists($definition, self::$stats)) { self::$stats[$definition] = array( 'mode' => $mode, 'stores' => array( $store => array( 'hits' => 0, 'misses' => 0, 'sets' => 0, ) ) ); } else if (!array_key_exists($store, self::$stats[$definition]['stores'])) { self::$stats[$definition]['stores'][$store] = array( 'hits' => 0, 'misses' => 0, 'sets' => 0, ); } }
php
protected static function ensure_ready_for_stats($store, $definition, $mode = cache_store::MODE_APPLICATION) { // This function is performance-sensitive, so exit as quickly as possible // if we do not need to do anything. if (isset(self::$stats[$definition]['stores'][$store])) { return; } if (!array_key_exists($definition, self::$stats)) { self::$stats[$definition] = array( 'mode' => $mode, 'stores' => array( $store => array( 'hits' => 0, 'misses' => 0, 'sets' => 0, ) ) ); } else if (!array_key_exists($store, self::$stats[$definition]['stores'])) { self::$stats[$definition]['stores'][$store] = array( 'hits' => 0, 'misses' => 0, 'sets' => 0, ); } }
[ "protected", "static", "function", "ensure_ready_for_stats", "(", "$", "store", ",", "$", "definition", ",", "$", "mode", "=", "cache_store", "::", "MODE_APPLICATION", ")", "{", "// This function is performance-sensitive, so exit as quickly as possible", "// if we do not need to do anything.", "if", "(", "isset", "(", "self", "::", "$", "stats", "[", "$", "definition", "]", "[", "'stores'", "]", "[", "$", "store", "]", ")", ")", "{", "return", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "definition", ",", "self", "::", "$", "stats", ")", ")", "{", "self", "::", "$", "stats", "[", "$", "definition", "]", "=", "array", "(", "'mode'", "=>", "$", "mode", ",", "'stores'", "=>", "array", "(", "$", "store", "=>", "array", "(", "'hits'", "=>", "0", ",", "'misses'", "=>", "0", ",", "'sets'", "=>", "0", ",", ")", ")", ")", ";", "}", "else", "if", "(", "!", "array_key_exists", "(", "$", "store", ",", "self", "::", "$", "stats", "[", "$", "definition", "]", "[", "'stores'", "]", ")", ")", "{", "self", "::", "$", "stats", "[", "$", "definition", "]", "[", "'stores'", "]", "[", "$", "store", "]", "=", "array", "(", "'hits'", "=>", "0", ",", "'misses'", "=>", "0", ",", "'sets'", "=>", "0", ",", ")", ";", "}", "}" ]
Ensure that the stats array is ready to collect information for the given store and definition. @param string $store @param string $definition A string that identifies the definition. @param int $mode One of cache_store::MODE_*. Since 2.9.
[ "Ensure", "that", "the", "stats", "array", "is", "ready", "to", "collect", "information", "for", "the", "given", "store", "and", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L367-L391
218,402
moodle/moodle
cache/classes/helper.php
cache_helper.get_definition_stat_id_and_mode
protected static function get_definition_stat_id_and_mode($definition) { if (!($definition instanceof cache_definition)) { // All core calls to this method have been updated, this is the legacy state. // We'll use application as the default as that is the most common, really this is not accurate of course but // at this point we can only guess and as it only affects calls to cache stat outside of core (of which there should // be none) I think that is fine. debugging('Please update you cache stat calls to pass the definition rather than just its ID.', DEBUG_DEVELOPER); return array((string)$definition, cache_store::MODE_APPLICATION); } return array($definition->get_id(), $definition->get_mode()); }
php
protected static function get_definition_stat_id_and_mode($definition) { if (!($definition instanceof cache_definition)) { // All core calls to this method have been updated, this is the legacy state. // We'll use application as the default as that is the most common, really this is not accurate of course but // at this point we can only guess and as it only affects calls to cache stat outside of core (of which there should // be none) I think that is fine. debugging('Please update you cache stat calls to pass the definition rather than just its ID.', DEBUG_DEVELOPER); return array((string)$definition, cache_store::MODE_APPLICATION); } return array($definition->get_id(), $definition->get_mode()); }
[ "protected", "static", "function", "get_definition_stat_id_and_mode", "(", "$", "definition", ")", "{", "if", "(", "!", "(", "$", "definition", "instanceof", "cache_definition", ")", ")", "{", "// All core calls to this method have been updated, this is the legacy state.", "// We'll use application as the default as that is the most common, really this is not accurate of course but", "// at this point we can only guess and as it only affects calls to cache stat outside of core (of which there should", "// be none) I think that is fine.", "debugging", "(", "'Please update you cache stat calls to pass the definition rather than just its ID.'", ",", "DEBUG_DEVELOPER", ")", ";", "return", "array", "(", "(", "string", ")", "$", "definition", ",", "cache_store", "::", "MODE_APPLICATION", ")", ";", "}", "return", "array", "(", "$", "definition", "->", "get_id", "(", ")", ",", "$", "definition", "->", "get_mode", "(", ")", ")", ";", "}" ]
Returns a string to describe the definition. This method supports the definition as a string due to legacy requirements. It is backwards compatible when a string is passed but is not accurate. @since 2.9 @param cache_definition|string $definition @return string
[ "Returns", "a", "string", "to", "describe", "the", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L403-L413
218,403
moodle/moodle
cache/classes/helper.php
cache_helper.record_cache_hit
public static function record_cache_hit($store, $definition, $hits = 1) { list($definitionstr, $mode) = self::get_definition_stat_id_and_mode($definition); self::ensure_ready_for_stats($store, $definitionstr, $mode); self::$stats[$definitionstr]['stores'][$store]['hits'] += $hits; }
php
public static function record_cache_hit($store, $definition, $hits = 1) { list($definitionstr, $mode) = self::get_definition_stat_id_and_mode($definition); self::ensure_ready_for_stats($store, $definitionstr, $mode); self::$stats[$definitionstr]['stores'][$store]['hits'] += $hits; }
[ "public", "static", "function", "record_cache_hit", "(", "$", "store", ",", "$", "definition", ",", "$", "hits", "=", "1", ")", "{", "list", "(", "$", "definitionstr", ",", "$", "mode", ")", "=", "self", "::", "get_definition_stat_id_and_mode", "(", "$", "definition", ")", ";", "self", "::", "ensure_ready_for_stats", "(", "$", "store", ",", "$", "definitionstr", ",", "$", "mode", ")", ";", "self", "::", "$", "stats", "[", "$", "definitionstr", "]", "[", "'stores'", "]", "[", "$", "store", "]", "[", "'hits'", "]", "+=", "$", "hits", ";", "}" ]
Record a cache hit in the stats for the given store and definition. In Moodle 2.9 the $definition argument changed from accepting only a string to accepting a string or a cache_definition instance. It is preferable to pass a cache definition instance. @internal @param cache_definition $store @param cache_definition $definition You used to be able to pass a string here, however that is deprecated please pass the actual cache_definition object now. @param int $hits The number of hits to record (by default 1)
[ "Record", "a", "cache", "hit", "in", "the", "stats", "for", "the", "given", "store", "and", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L427-L431
218,404
moodle/moodle
cache/classes/helper.php
cache_helper.record_cache_miss
public static function record_cache_miss($store, $definition, $misses = 1) { list($definitionstr, $mode) = self::get_definition_stat_id_and_mode($definition); self::ensure_ready_for_stats($store, $definitionstr, $mode); self::$stats[$definitionstr]['stores'][$store]['misses'] += $misses; }
php
public static function record_cache_miss($store, $definition, $misses = 1) { list($definitionstr, $mode) = self::get_definition_stat_id_and_mode($definition); self::ensure_ready_for_stats($store, $definitionstr, $mode); self::$stats[$definitionstr]['stores'][$store]['misses'] += $misses; }
[ "public", "static", "function", "record_cache_miss", "(", "$", "store", ",", "$", "definition", ",", "$", "misses", "=", "1", ")", "{", "list", "(", "$", "definitionstr", ",", "$", "mode", ")", "=", "self", "::", "get_definition_stat_id_and_mode", "(", "$", "definition", ")", ";", "self", "::", "ensure_ready_for_stats", "(", "$", "store", ",", "$", "definitionstr", ",", "$", "mode", ")", ";", "self", "::", "$", "stats", "[", "$", "definitionstr", "]", "[", "'stores'", "]", "[", "$", "store", "]", "[", "'misses'", "]", "+=", "$", "misses", ";", "}" ]
Record a cache miss in the stats for the given store and definition. In Moodle 2.9 the $definition argument changed from accepting only a string to accepting a string or a cache_definition instance. It is preferable to pass a cache definition instance. @internal @param string $store @param cache_definition $definition You used to be able to pass a string here, however that is deprecated please pass the actual cache_definition object now. @param int $misses The number of misses to record (by default 1)
[ "Record", "a", "cache", "miss", "in", "the", "stats", "for", "the", "given", "store", "and", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L445-L449
218,405
moodle/moodle
cache/classes/helper.php
cache_helper.record_cache_set
public static function record_cache_set($store, $definition, $sets = 1) { list($definitionstr, $mode) = self::get_definition_stat_id_and_mode($definition); self::ensure_ready_for_stats($store, $definitionstr, $mode); self::$stats[$definitionstr]['stores'][$store]['sets'] += $sets; }
php
public static function record_cache_set($store, $definition, $sets = 1) { list($definitionstr, $mode) = self::get_definition_stat_id_and_mode($definition); self::ensure_ready_for_stats($store, $definitionstr, $mode); self::$stats[$definitionstr]['stores'][$store]['sets'] += $sets; }
[ "public", "static", "function", "record_cache_set", "(", "$", "store", ",", "$", "definition", ",", "$", "sets", "=", "1", ")", "{", "list", "(", "$", "definitionstr", ",", "$", "mode", ")", "=", "self", "::", "get_definition_stat_id_and_mode", "(", "$", "definition", ")", ";", "self", "::", "ensure_ready_for_stats", "(", "$", "store", ",", "$", "definitionstr", ",", "$", "mode", ")", ";", "self", "::", "$", "stats", "[", "$", "definitionstr", "]", "[", "'stores'", "]", "[", "$", "store", "]", "[", "'sets'", "]", "+=", "$", "sets", ";", "}" ]
Record a cache set in the stats for the given store and definition. In Moodle 2.9 the $definition argument changed from accepting only a string to accepting a string or a cache_definition instance. It is preferable to pass a cache definition instance. @internal @param string $store @param cache_definition $definition You used to be able to pass a string here, however that is deprecated please pass the actual cache_definition object now. @param int $sets The number of sets to record (by default 1)
[ "Record", "a", "cache", "set", "in", "the", "stats", "for", "the", "given", "store", "and", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L463-L467
218,406
moodle/moodle
cache/classes/helper.php
cache_helper.purge_all
public static function purge_all($usewriter = false) { $factory = cache_factory::instance(); $config = $factory->create_config_instance($usewriter); foreach ($config->get_all_stores() as $store) { self::purge_store($store['name'], $config); } foreach ($factory->get_adhoc_caches_in_use() as $cache) { $cache->purge(); } }
php
public static function purge_all($usewriter = false) { $factory = cache_factory::instance(); $config = $factory->create_config_instance($usewriter); foreach ($config->get_all_stores() as $store) { self::purge_store($store['name'], $config); } foreach ($factory->get_adhoc_caches_in_use() as $cache) { $cache->purge(); } }
[ "public", "static", "function", "purge_all", "(", "$", "usewriter", "=", "false", ")", "{", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "$", "config", "=", "$", "factory", "->", "create_config_instance", "(", "$", "usewriter", ")", ";", "foreach", "(", "$", "config", "->", "get_all_stores", "(", ")", "as", "$", "store", ")", "{", "self", "::", "purge_store", "(", "$", "store", "[", "'name'", "]", ",", "$", "config", ")", ";", "}", "foreach", "(", "$", "factory", "->", "get_adhoc_caches_in_use", "(", ")", "as", "$", "cache", ")", "{", "$", "cache", "->", "purge", "(", ")", ";", "}", "}" ]
Purge all of the cache stores of all of their data. Think twice before calling this method. It will purge **ALL** caches regardless of whether they have been used recently or anything. This will involve full setup of the cache + the purge operation. On a site using caching heavily this WILL be painful. @param bool $usewriter If set to true the cache_config_writer class is used. This class is special as it avoids it is still usable when caches have been disabled. Please use this option only if you really must. It's purpose is to allow the cache to be purged when it would be otherwise impossible.
[ "Purge", "all", "of", "the", "cache", "stores", "of", "all", "of", "their", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L489-L498
218,407
moodle/moodle
cache/classes/helper.php
cache_helper.purge_store
public static function purge_store($storename, cache_config $config = null) { if ($config === null) { $config = cache_config::instance(); } $stores = $config->get_all_stores(); if (!array_key_exists($storename, $stores)) { // The store does not exist. return false; } $store = $stores[$storename]; $class = $store['class']; // We check are_requirements_met although we expect is_ready is going to check as well. if (!$class::are_requirements_met()) { return false; } // Found the store: is it ready? /* @var cache_store $instance */ $instance = new $class($store['name'], $store['configuration']); if (!$instance->is_ready()) { unset($instance); return false; } foreach ($config->get_definitions_by_store($storename) as $id => $definition) { $definition = cache_definition::load($id, $definition); $definitioninstance = clone($instance); $definitioninstance->initialise($definition); $definitioninstance->purge(); unset($definitioninstance); } return true; }
php
public static function purge_store($storename, cache_config $config = null) { if ($config === null) { $config = cache_config::instance(); } $stores = $config->get_all_stores(); if (!array_key_exists($storename, $stores)) { // The store does not exist. return false; } $store = $stores[$storename]; $class = $store['class']; // We check are_requirements_met although we expect is_ready is going to check as well. if (!$class::are_requirements_met()) { return false; } // Found the store: is it ready? /* @var cache_store $instance */ $instance = new $class($store['name'], $store['configuration']); if (!$instance->is_ready()) { unset($instance); return false; } foreach ($config->get_definitions_by_store($storename) as $id => $definition) { $definition = cache_definition::load($id, $definition); $definitioninstance = clone($instance); $definitioninstance->initialise($definition); $definitioninstance->purge(); unset($definitioninstance); } return true; }
[ "public", "static", "function", "purge_store", "(", "$", "storename", ",", "cache_config", "$", "config", "=", "null", ")", "{", "if", "(", "$", "config", "===", "null", ")", "{", "$", "config", "=", "cache_config", "::", "instance", "(", ")", ";", "}", "$", "stores", "=", "$", "config", "->", "get_all_stores", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "storename", ",", "$", "stores", ")", ")", "{", "// The store does not exist.", "return", "false", ";", "}", "$", "store", "=", "$", "stores", "[", "$", "storename", "]", ";", "$", "class", "=", "$", "store", "[", "'class'", "]", ";", "// We check are_requirements_met although we expect is_ready is going to check as well.", "if", "(", "!", "$", "class", "::", "are_requirements_met", "(", ")", ")", "{", "return", "false", ";", "}", "// Found the store: is it ready?", "/* @var cache_store $instance */", "$", "instance", "=", "new", "$", "class", "(", "$", "store", "[", "'name'", "]", ",", "$", "store", "[", "'configuration'", "]", ")", ";", "if", "(", "!", "$", "instance", "->", "is_ready", "(", ")", ")", "{", "unset", "(", "$", "instance", ")", ";", "return", "false", ";", "}", "foreach", "(", "$", "config", "->", "get_definitions_by_store", "(", "$", "storename", ")", "as", "$", "id", "=>", "$", "definition", ")", "{", "$", "definition", "=", "cache_definition", "::", "load", "(", "$", "id", ",", "$", "definition", ")", ";", "$", "definitioninstance", "=", "clone", "(", "$", "instance", ")", ";", "$", "definitioninstance", "->", "initialise", "(", "$", "definition", ")", ";", "$", "definitioninstance", "->", "purge", "(", ")", ";", "unset", "(", "$", "definitioninstance", ")", ";", "}", "return", "true", ";", "}" ]
Purges a store given its name. @param string $storename @param cache_config $config @return bool
[ "Purges", "a", "store", "given", "its", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L507-L542
218,408
moodle/moodle
cache/classes/helper.php
cache_helper.purge_stores_used_by_definition
public static function purge_stores_used_by_definition($component, $area) { $factory = cache_factory::instance(); $config = $factory->create_config_instance(); $definition = $factory->create_definition($component, $area); $stores = $config->get_stores_for_definition($definition); foreach ($stores as $store) { self::purge_store($store['name']); } }
php
public static function purge_stores_used_by_definition($component, $area) { $factory = cache_factory::instance(); $config = $factory->create_config_instance(); $definition = $factory->create_definition($component, $area); $stores = $config->get_stores_for_definition($definition); foreach ($stores as $store) { self::purge_store($store['name']); } }
[ "public", "static", "function", "purge_stores_used_by_definition", "(", "$", "component", ",", "$", "area", ")", "{", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "$", "config", "=", "$", "factory", "->", "create_config_instance", "(", ")", ";", "$", "definition", "=", "$", "factory", "->", "create_definition", "(", "$", "component", ",", "$", "area", ")", ";", "$", "stores", "=", "$", "config", "->", "get_stores_for_definition", "(", "$", "definition", ")", ";", "foreach", "(", "$", "stores", "as", "$", "store", ")", "{", "self", "::", "purge_store", "(", "$", "store", "[", "'name'", "]", ")", ";", "}", "}" ]
Purges all of the stores used by a definition. Unlike cache_helper::purge_by_definition this purges all of the data from the stores not just the data relating to the definition. This function is useful when you must purge a definition that requires setup but you don't want to set it up. @param string $component @param string $area
[ "Purges", "all", "of", "the", "stores", "used", "by", "a", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L555-L563
218,409
moodle/moodle
cache/classes/helper.php
cache_helper.get_definition_name
public static function get_definition_name($definition) { if ($definition instanceof cache_definition) { return $definition->get_name(); } $identifier = 'cachedef_'.clean_param($definition['area'], PARAM_STRINGID); $component = $definition['component']; if ($component === 'core') { $component = 'cache'; } return new lang_string($identifier, $component); }
php
public static function get_definition_name($definition) { if ($definition instanceof cache_definition) { return $definition->get_name(); } $identifier = 'cachedef_'.clean_param($definition['area'], PARAM_STRINGID); $component = $definition['component']; if ($component === 'core') { $component = 'cache'; } return new lang_string($identifier, $component); }
[ "public", "static", "function", "get_definition_name", "(", "$", "definition", ")", "{", "if", "(", "$", "definition", "instanceof", "cache_definition", ")", "{", "return", "$", "definition", "->", "get_name", "(", ")", ";", "}", "$", "identifier", "=", "'cachedef_'", ".", "clean_param", "(", "$", "definition", "[", "'area'", "]", ",", "PARAM_STRINGID", ")", ";", "$", "component", "=", "$", "definition", "[", "'component'", "]", ";", "if", "(", "$", "component", "===", "'core'", ")", "{", "$", "component", "=", "'cache'", ";", "}", "return", "new", "lang_string", "(", "$", "identifier", ",", "$", "component", ")", ";", "}" ]
Returns the translated name of the definition. @param cache_definition $definition @return lang_string
[ "Returns", "the", "translated", "name", "of", "the", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L571-L581
218,410
moodle/moodle
cache/classes/helper.php
cache_helper.hash_key
public static function hash_key($key, cache_definition $definition) { if ($definition->uses_simple_keys()) { if (debugging() && preg_match('#[^a-zA-Z0-9_]#', $key)) { throw new coding_exception('Cache definition '.$definition->get_id().' requires simple keys. Invalid key provided.', $key); } // We put the key first so that we can be sure the start of the key changes. return (string)$key . '-' . $definition->generate_single_key_prefix(); } $key = $definition->generate_single_key_prefix() . '-' . $key; return sha1($key); }
php
public static function hash_key($key, cache_definition $definition) { if ($definition->uses_simple_keys()) { if (debugging() && preg_match('#[^a-zA-Z0-9_]#', $key)) { throw new coding_exception('Cache definition '.$definition->get_id().' requires simple keys. Invalid key provided.', $key); } // We put the key first so that we can be sure the start of the key changes. return (string)$key . '-' . $definition->generate_single_key_prefix(); } $key = $definition->generate_single_key_prefix() . '-' . $key; return sha1($key); }
[ "public", "static", "function", "hash_key", "(", "$", "key", ",", "cache_definition", "$", "definition", ")", "{", "if", "(", "$", "definition", "->", "uses_simple_keys", "(", ")", ")", "{", "if", "(", "debugging", "(", ")", "&&", "preg_match", "(", "'#[^a-zA-Z0-9_]#'", ",", "$", "key", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Cache definition '", ".", "$", "definition", "->", "get_id", "(", ")", ".", "' requires simple keys. Invalid key provided.'", ",", "$", "key", ")", ";", "}", "// We put the key first so that we can be sure the start of the key changes.", "return", "(", "string", ")", "$", "key", ".", "'-'", ".", "$", "definition", "->", "generate_single_key_prefix", "(", ")", ";", "}", "$", "key", "=", "$", "definition", "->", "generate_single_key_prefix", "(", ")", ".", "'-'", ".", "$", "key", ";", "return", "sha1", "(", "$", "key", ")", ";", "}" ]
Hashes a descriptive key to make it shorter and still unique. @param string|int $key @param cache_definition $definition @return string
[ "Hashes", "a", "descriptive", "key", "to", "make", "it", "shorter", "and", "still", "unique", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L589-L599
218,411
moodle/moodle
cache/classes/helper.php
cache_helper.update_definitions
public static function update_definitions($coreonly = false) { global $CFG; // Include locallib. require_once($CFG->dirroot.'/cache/locallib.php'); // First update definitions cache_config_writer::update_definitions($coreonly); // Second reset anything we have already initialised to ensure we're all up to date. cache_factory::reset(); }
php
public static function update_definitions($coreonly = false) { global $CFG; // Include locallib. require_once($CFG->dirroot.'/cache/locallib.php'); // First update definitions cache_config_writer::update_definitions($coreonly); // Second reset anything we have already initialised to ensure we're all up to date. cache_factory::reset(); }
[ "public", "static", "function", "update_definitions", "(", "$", "coreonly", "=", "false", ")", "{", "global", "$", "CFG", ";", "// Include locallib.", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/cache/locallib.php'", ")", ";", "// First update definitions", "cache_config_writer", "::", "update_definitions", "(", "$", "coreonly", ")", ";", "// Second reset anything we have already initialised to ensure we're all up to date.", "cache_factory", "::", "reset", "(", ")", ";", "}" ]
Finds all definitions and updates them within the cache config file. @param bool $coreonly If set to true only core definitions will be updated.
[ "Finds", "all", "definitions", "and", "updates", "them", "within", "the", "cache", "config", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L606-L614
218,412
moodle/moodle
cache/classes/helper.php
cache_helper.get_site_identifier
public static function get_site_identifier() { global $CFG; if (!is_null(self::$siteidentifier)) { return self::$siteidentifier; } // If site identifier hasn't been collected yet attempt to get it from the cache config. $factory = cache_factory::instance(); // If the factory is initialising then we don't want to try to get it from the config or we risk // causing the cache to enter an infinite initialisation loop. if (!$factory->is_initialising()) { $config = $factory->create_config_instance(); self::$siteidentifier = $config->get_site_identifier(); } if (is_null(self::$siteidentifier)) { // If the site identifier is still null then config isn't aware of it yet. // We'll see if the CFG is loaded, and if not we will just use unknown. // It's very important here that we don't use get_config. We don't want an endless cache loop! if (!empty($CFG->siteidentifier)) { self::$siteidentifier = self::update_site_identifier($CFG->siteidentifier); } else { // It's not being recorded in MUC's config and the config data hasn't been loaded yet. // Likely we are initialising. return 'unknown'; } } return self::$siteidentifier; }
php
public static function get_site_identifier() { global $CFG; if (!is_null(self::$siteidentifier)) { return self::$siteidentifier; } // If site identifier hasn't been collected yet attempt to get it from the cache config. $factory = cache_factory::instance(); // If the factory is initialising then we don't want to try to get it from the config or we risk // causing the cache to enter an infinite initialisation loop. if (!$factory->is_initialising()) { $config = $factory->create_config_instance(); self::$siteidentifier = $config->get_site_identifier(); } if (is_null(self::$siteidentifier)) { // If the site identifier is still null then config isn't aware of it yet. // We'll see if the CFG is loaded, and if not we will just use unknown. // It's very important here that we don't use get_config. We don't want an endless cache loop! if (!empty($CFG->siteidentifier)) { self::$siteidentifier = self::update_site_identifier($CFG->siteidentifier); } else { // It's not being recorded in MUC's config and the config data hasn't been loaded yet. // Likely we are initialising. return 'unknown'; } } return self::$siteidentifier; }
[ "public", "static", "function", "get_site_identifier", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "is_null", "(", "self", "::", "$", "siteidentifier", ")", ")", "{", "return", "self", "::", "$", "siteidentifier", ";", "}", "// If site identifier hasn't been collected yet attempt to get it from the cache config.", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "// If the factory is initialising then we don't want to try to get it from the config or we risk", "// causing the cache to enter an infinite initialisation loop.", "if", "(", "!", "$", "factory", "->", "is_initialising", "(", ")", ")", "{", "$", "config", "=", "$", "factory", "->", "create_config_instance", "(", ")", ";", "self", "::", "$", "siteidentifier", "=", "$", "config", "->", "get_site_identifier", "(", ")", ";", "}", "if", "(", "is_null", "(", "self", "::", "$", "siteidentifier", ")", ")", "{", "// If the site identifier is still null then config isn't aware of it yet.", "// We'll see if the CFG is loaded, and if not we will just use unknown.", "// It's very important here that we don't use get_config. We don't want an endless cache loop!", "if", "(", "!", "empty", "(", "$", "CFG", "->", "siteidentifier", ")", ")", "{", "self", "::", "$", "siteidentifier", "=", "self", "::", "update_site_identifier", "(", "$", "CFG", "->", "siteidentifier", ")", ";", "}", "else", "{", "// It's not being recorded in MUC's config and the config data hasn't been loaded yet.", "// Likely we are initialising.", "return", "'unknown'", ";", "}", "}", "return", "self", "::", "$", "siteidentifier", ";", "}" ]
Returns the site identifier. @return string
[ "Returns", "the", "site", "identifier", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L640-L666
218,413
moodle/moodle
cache/classes/helper.php
cache_helper.clean_old_session_data
public static function clean_old_session_data($output = false) { global $CFG; if ($output) { mtrace('Cleaning up stale session data from cache stores.'); } $factory = cache_factory::instance(); $config = $factory->create_config_instance(); $definitions = $config->get_definitions(); $purgetime = time() - $CFG->sessiontimeout; foreach ($definitions as $definitionarray) { // We are only interested in session caches. if (!($definitionarray['mode'] & cache_store::MODE_SESSION)) { continue; } $definition = $factory->create_definition($definitionarray['component'], $definitionarray['area']); $stores = $config->get_stores_for_definition($definition); // Turn them into store instances. $stores = self::initialise_cachestore_instances($stores, $definition); // Initialise all of the stores used for that definition. foreach ($stores as $store) { // If the store doesn't support searching we can skip it. if (!($store instanceof cache_is_searchable)) { debugging('Cache stores used for session definitions should ideally be searchable.', DEBUG_DEVELOPER); continue; } // Get all of the keys. $keys = $store->find_by_prefix(cache_session::KEY_PREFIX); $todelete = array(); foreach ($store->get_many($keys) as $key => $value) { if (strpos($key, cache_session::KEY_PREFIX) !== 0 || !is_array($value) || !isset($value['lastaccess'])) { continue; } if ((int)$value['lastaccess'] < $purgetime || true) { $todelete[] = $key; } } if (count($todelete)) { $outcome = (int)$store->delete_many($todelete); if ($output) { $strdef = s($definition->get_id()); $strstore = s($store->my_name()); mtrace("- Removed {$outcome} old {$strdef} sessions from the '{$strstore}' cache store."); } } } } }
php
public static function clean_old_session_data($output = false) { global $CFG; if ($output) { mtrace('Cleaning up stale session data from cache stores.'); } $factory = cache_factory::instance(); $config = $factory->create_config_instance(); $definitions = $config->get_definitions(); $purgetime = time() - $CFG->sessiontimeout; foreach ($definitions as $definitionarray) { // We are only interested in session caches. if (!($definitionarray['mode'] & cache_store::MODE_SESSION)) { continue; } $definition = $factory->create_definition($definitionarray['component'], $definitionarray['area']); $stores = $config->get_stores_for_definition($definition); // Turn them into store instances. $stores = self::initialise_cachestore_instances($stores, $definition); // Initialise all of the stores used for that definition. foreach ($stores as $store) { // If the store doesn't support searching we can skip it. if (!($store instanceof cache_is_searchable)) { debugging('Cache stores used for session definitions should ideally be searchable.', DEBUG_DEVELOPER); continue; } // Get all of the keys. $keys = $store->find_by_prefix(cache_session::KEY_PREFIX); $todelete = array(); foreach ($store->get_many($keys) as $key => $value) { if (strpos($key, cache_session::KEY_PREFIX) !== 0 || !is_array($value) || !isset($value['lastaccess'])) { continue; } if ((int)$value['lastaccess'] < $purgetime || true) { $todelete[] = $key; } } if (count($todelete)) { $outcome = (int)$store->delete_many($todelete); if ($output) { $strdef = s($definition->get_id()); $strstore = s($store->my_name()); mtrace("- Removed {$outcome} old {$strdef} sessions from the '{$strstore}' cache store."); } } } } }
[ "public", "static", "function", "clean_old_session_data", "(", "$", "output", "=", "false", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "output", ")", "{", "mtrace", "(", "'Cleaning up stale session data from cache stores.'", ")", ";", "}", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "$", "config", "=", "$", "factory", "->", "create_config_instance", "(", ")", ";", "$", "definitions", "=", "$", "config", "->", "get_definitions", "(", ")", ";", "$", "purgetime", "=", "time", "(", ")", "-", "$", "CFG", "->", "sessiontimeout", ";", "foreach", "(", "$", "definitions", "as", "$", "definitionarray", ")", "{", "// We are only interested in session caches.", "if", "(", "!", "(", "$", "definitionarray", "[", "'mode'", "]", "&", "cache_store", "::", "MODE_SESSION", ")", ")", "{", "continue", ";", "}", "$", "definition", "=", "$", "factory", "->", "create_definition", "(", "$", "definitionarray", "[", "'component'", "]", ",", "$", "definitionarray", "[", "'area'", "]", ")", ";", "$", "stores", "=", "$", "config", "->", "get_stores_for_definition", "(", "$", "definition", ")", ";", "// Turn them into store instances.", "$", "stores", "=", "self", "::", "initialise_cachestore_instances", "(", "$", "stores", ",", "$", "definition", ")", ";", "// Initialise all of the stores used for that definition.", "foreach", "(", "$", "stores", "as", "$", "store", ")", "{", "// If the store doesn't support searching we can skip it.", "if", "(", "!", "(", "$", "store", "instanceof", "cache_is_searchable", ")", ")", "{", "debugging", "(", "'Cache stores used for session definitions should ideally be searchable.'", ",", "DEBUG_DEVELOPER", ")", ";", "continue", ";", "}", "// Get all of the keys.", "$", "keys", "=", "$", "store", "->", "find_by_prefix", "(", "cache_session", "::", "KEY_PREFIX", ")", ";", "$", "todelete", "=", "array", "(", ")", ";", "foreach", "(", "$", "store", "->", "get_many", "(", "$", "keys", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "strpos", "(", "$", "key", ",", "cache_session", "::", "KEY_PREFIX", ")", "!==", "0", "||", "!", "is_array", "(", "$", "value", ")", "||", "!", "isset", "(", "$", "value", "[", "'lastaccess'", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "(", "int", ")", "$", "value", "[", "'lastaccess'", "]", "<", "$", "purgetime", "||", "true", ")", "{", "$", "todelete", "[", "]", "=", "$", "key", ";", "}", "}", "if", "(", "count", "(", "$", "todelete", ")", ")", "{", "$", "outcome", "=", "(", "int", ")", "$", "store", "->", "delete_many", "(", "$", "todelete", ")", ";", "if", "(", "$", "output", ")", "{", "$", "strdef", "=", "s", "(", "$", "definition", "->", "get_id", "(", ")", ")", ";", "$", "strstore", "=", "s", "(", "$", "store", "->", "my_name", "(", ")", ")", ";", "mtrace", "(", "\"- Removed {$outcome} old {$strdef} sessions from the '{$strstore}' cache store.\"", ")", ";", "}", "}", "}", "}", "}" ]
Cleans old session data from cache stores used for session based definitions. @param bool $output If set to true output will be given.
[ "Cleans", "old", "session", "data", "from", "cache", "stores", "used", "for", "session", "based", "definitions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L690-L736
218,414
moodle/moodle
cache/classes/helper.php
cache_helper.get_stores_suitable_for_mode_default
public static function get_stores_suitable_for_mode_default() { $factory = cache_factory::instance(); $config = $factory->create_config_instance(); $requirements = 0; foreach ($config->get_definitions() as $definition) { $definition = cache_definition::load($definition['component'].'/'.$definition['area'], $definition); $requirements = $requirements | $definition->get_requirements_bin(); } $stores = array(); foreach ($config->get_all_stores() as $name => $store) { if (!empty($store['features']) && ($store['features'] & $requirements)) { $stores[$name] = $store; } } return $stores; }
php
public static function get_stores_suitable_for_mode_default() { $factory = cache_factory::instance(); $config = $factory->create_config_instance(); $requirements = 0; foreach ($config->get_definitions() as $definition) { $definition = cache_definition::load($definition['component'].'/'.$definition['area'], $definition); $requirements = $requirements | $definition->get_requirements_bin(); } $stores = array(); foreach ($config->get_all_stores() as $name => $store) { if (!empty($store['features']) && ($store['features'] & $requirements)) { $stores[$name] = $store; } } return $stores; }
[ "public", "static", "function", "get_stores_suitable_for_mode_default", "(", ")", "{", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "$", "config", "=", "$", "factory", "->", "create_config_instance", "(", ")", ";", "$", "requirements", "=", "0", ";", "foreach", "(", "$", "config", "->", "get_definitions", "(", ")", "as", "$", "definition", ")", "{", "$", "definition", "=", "cache_definition", "::", "load", "(", "$", "definition", "[", "'component'", "]", ".", "'/'", ".", "$", "definition", "[", "'area'", "]", ",", "$", "definition", ")", ";", "$", "requirements", "=", "$", "requirements", "|", "$", "definition", "->", "get_requirements_bin", "(", ")", ";", "}", "$", "stores", "=", "array", "(", ")", ";", "foreach", "(", "$", "config", "->", "get_all_stores", "(", ")", "as", "$", "name", "=>", "$", "store", ")", "{", "if", "(", "!", "empty", "(", "$", "store", "[", "'features'", "]", ")", "&&", "(", "$", "store", "[", "'features'", "]", "&", "$", "requirements", ")", ")", "{", "$", "stores", "[", "$", "name", "]", "=", "$", "store", ";", "}", "}", "return", "$", "stores", ";", "}" ]
Returns an array of stores that would meet the requirements for every definition. These stores would be 100% suitable to map as defaults for cache modes. @return array[] An array of stores, keys are the store names.
[ "Returns", "an", "array", "of", "stores", "that", "would", "meet", "the", "requirements", "for", "every", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L745-L760
218,415
moodle/moodle
cache/classes/helper.php
cache_helper.get_stores_suitable_for_definition
public static function get_stores_suitable_for_definition(cache_definition $definition) { $factory = cache_factory::instance(); $stores = array(); if ($factory->is_initialising() || $factory->stores_disabled()) { // No suitable stores here. return $stores; } else { $stores = self::get_cache_stores($definition); // If mappingsonly is set, having 0 stores is ok. if ((count($stores) === 0) && (!$definition->is_for_mappings_only())) { // No suitable stores we found for the definition. We need to come up with a sensible default. // If this has happened we can be sure that the user has mapped custom stores to either the // mode of the definition. The first alternative to try is the system default for the mode. // e.g. the default file store instance for application definitions. $config = $factory->create_config_instance(); foreach ($config->get_stores($definition->get_mode()) as $name => $details) { if (!empty($details['default'])) { $stores[] = $factory->create_store_from_config($name, $details, $definition); break; } } } } return $stores; }
php
public static function get_stores_suitable_for_definition(cache_definition $definition) { $factory = cache_factory::instance(); $stores = array(); if ($factory->is_initialising() || $factory->stores_disabled()) { // No suitable stores here. return $stores; } else { $stores = self::get_cache_stores($definition); // If mappingsonly is set, having 0 stores is ok. if ((count($stores) === 0) && (!$definition->is_for_mappings_only())) { // No suitable stores we found for the definition. We need to come up with a sensible default. // If this has happened we can be sure that the user has mapped custom stores to either the // mode of the definition. The first alternative to try is the system default for the mode. // e.g. the default file store instance for application definitions. $config = $factory->create_config_instance(); foreach ($config->get_stores($definition->get_mode()) as $name => $details) { if (!empty($details['default'])) { $stores[] = $factory->create_store_from_config($name, $details, $definition); break; } } } } return $stores; }
[ "public", "static", "function", "get_stores_suitable_for_definition", "(", "cache_definition", "$", "definition", ")", "{", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "$", "stores", "=", "array", "(", ")", ";", "if", "(", "$", "factory", "->", "is_initialising", "(", ")", "||", "$", "factory", "->", "stores_disabled", "(", ")", ")", "{", "// No suitable stores here.", "return", "$", "stores", ";", "}", "else", "{", "$", "stores", "=", "self", "::", "get_cache_stores", "(", "$", "definition", ")", ";", "// If mappingsonly is set, having 0 stores is ok.", "if", "(", "(", "count", "(", "$", "stores", ")", "===", "0", ")", "&&", "(", "!", "$", "definition", "->", "is_for_mappings_only", "(", ")", ")", ")", "{", "// No suitable stores we found for the definition. We need to come up with a sensible default.", "// If this has happened we can be sure that the user has mapped custom stores to either the", "// mode of the definition. The first alternative to try is the system default for the mode.", "// e.g. the default file store instance for application definitions.", "$", "config", "=", "$", "factory", "->", "create_config_instance", "(", ")", ";", "foreach", "(", "$", "config", "->", "get_stores", "(", "$", "definition", "->", "get_mode", "(", ")", ")", "as", "$", "name", "=>", "$", "details", ")", "{", "if", "(", "!", "empty", "(", "$", "details", "[", "'default'", "]", ")", ")", "{", "$", "stores", "[", "]", "=", "$", "factory", "->", "create_store_from_config", "(", "$", "name", ",", "$", "details", ",", "$", "definition", ")", ";", "break", ";", "}", "}", "}", "}", "return", "$", "stores", ";", "}" ]
Returns stores suitable for use with a given definition. @param cache_definition $definition @return cache_store[]
[ "Returns", "stores", "suitable", "for", "use", "with", "a", "given", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L768-L792
218,416
moodle/moodle
cache/classes/helper.php
cache_helper.warnings
public static function warnings(array $stores = null) { global $CFG; if ($stores === null) { require_once($CFG->dirroot.'/cache/locallib.php'); $stores = cache_administration_helper::get_store_instance_summaries(); } $warnings = array(); foreach ($stores as $store) { if (!empty($store['warnings'])) { $warnings = array_merge($warnings, $store['warnings']); } } return $warnings; }
php
public static function warnings(array $stores = null) { global $CFG; if ($stores === null) { require_once($CFG->dirroot.'/cache/locallib.php'); $stores = cache_administration_helper::get_store_instance_summaries(); } $warnings = array(); foreach ($stores as $store) { if (!empty($store['warnings'])) { $warnings = array_merge($warnings, $store['warnings']); } } return $warnings; }
[ "public", "static", "function", "warnings", "(", "array", "$", "stores", "=", "null", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "stores", "===", "null", ")", "{", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/cache/locallib.php'", ")", ";", "$", "stores", "=", "cache_administration_helper", "::", "get_store_instance_summaries", "(", ")", ";", "}", "$", "warnings", "=", "array", "(", ")", ";", "foreach", "(", "$", "stores", "as", "$", "store", ")", "{", "if", "(", "!", "empty", "(", "$", "store", "[", "'warnings'", "]", ")", ")", "{", "$", "warnings", "=", "array_merge", "(", "$", "warnings", ",", "$", "store", "[", "'warnings'", "]", ")", ";", "}", "}", "return", "$", "warnings", ";", "}" ]
Returns an array of warnings from the cache API. The warning returned here are for things like conflicting store instance configurations etc. These get shown on the admin notifications page for example. @param array|null $stores An array of stores to get warnings for, or null for all. @return string[]
[ "Returns", "an", "array", "of", "warnings", "from", "the", "cache", "API", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L803-L816
218,417
moodle/moodle
enrol/lti/classes/data_connector.php
data_connector.deleteToolConsumer
public function deleteToolConsumer($consumer) { global $DB; $consumerpk = $consumer->getRecordId(); $deletecondition = ['consumerid' => $consumerpk]; // Delete any nonce values for this consumer. $DB->delete_records($this->noncetable, $deletecondition); // Delete any outstanding share keys for resource links for this consumer. $where = "resourcelinkid IN ( SELECT rl.id FROM {{$this->resourcelinktable}} rl WHERE rl.consumerid = :consumerid )"; $DB->delete_records_select($this->sharekeytable, $where, $deletecondition); // Delete any outstanding share keys for resource links for contexts in this consumer. $where = "resourcelinkid IN ( SELECT rl.id FROM {{$this->resourcelinktable}} rl INNER JOIN {{$this->contexttable}} c ON rl.contextid = c.id WHERE c.consumerid = :consumerid )"; $DB->delete_records_select($this->sharekeytable, $where, $deletecondition); // Delete any users in resource links for this consumer. $where = "resourcelinkid IN ( SELECT rl.id FROM {{$this->resourcelinktable}} rl WHERE rl.consumerid = :consumerid )"; $DB->delete_records_select($this->userresulttable, $where, $deletecondition); // Delete any users in resource links for contexts in this consumer. $where = "resourcelinkid IN ( SELECT rl.id FROM {{$this->resourcelinktable}} rl INNER JOIN {{$this->contexttable}} c ON rl.contextid = c.id WHERE c.consumerid = :consumerid )"; $DB->delete_records_select($this->userresulttable, $where, $deletecondition); // Update any resource links for which this consumer is acting as a primary resource link. $where = "primaryresourcelinkid IN ( SELECT rl.id FROM {{$this->resourcelinktable}} rl WHERE rl.consumerid = :consumerid )"; $updaterecords = $DB->get_records_select($this->resourcelinktable, $where, $deletecondition); foreach ($updaterecords as $record) { $record->primaryresourcelinkid = null; $record->shareapproved = null; $DB->update_record($this->resourcelinktable, $record); } // Update any resource links for contexts in which this consumer is acting as a primary resource link. $where = "primaryresourcelinkid IN ( SELECT rl.id FROM {{$this->resourcelinktable}} rl INNER JOIN {{$this->contexttable}} c ON rl.contextid = c.id WHERE c.consumerid = :consumerid )"; $updaterecords = $DB->get_records_select($this->resourcelinktable, $where, $deletecondition); foreach ($updaterecords as $record) { $record->primaryresourcelinkid = null; $record->shareapproved = null; $DB->update_record($this->resourcelinktable, $record); } // Delete any resource links for contexts in this consumer. $where = "contextid IN ( SELECT c.id FROM {{$this->contexttable}} c WHERE c.consumerid = :consumerid )"; $DB->delete_records_select($this->resourcelinktable, $where, $deletecondition); // Delete any resource links for this consumer. $DB->delete_records($this->resourcelinktable, $deletecondition); // Delete any contexts for this consumer. $DB->delete_records($this->contexttable, $deletecondition); // Delete consumer. $DB->delete_records($this->consumertable, ['id' => $consumerpk]); $consumer->initialize(); return true; }
php
public function deleteToolConsumer($consumer) { global $DB; $consumerpk = $consumer->getRecordId(); $deletecondition = ['consumerid' => $consumerpk]; // Delete any nonce values for this consumer. $DB->delete_records($this->noncetable, $deletecondition); // Delete any outstanding share keys for resource links for this consumer. $where = "resourcelinkid IN ( SELECT rl.id FROM {{$this->resourcelinktable}} rl WHERE rl.consumerid = :consumerid )"; $DB->delete_records_select($this->sharekeytable, $where, $deletecondition); // Delete any outstanding share keys for resource links for contexts in this consumer. $where = "resourcelinkid IN ( SELECT rl.id FROM {{$this->resourcelinktable}} rl INNER JOIN {{$this->contexttable}} c ON rl.contextid = c.id WHERE c.consumerid = :consumerid )"; $DB->delete_records_select($this->sharekeytable, $where, $deletecondition); // Delete any users in resource links for this consumer. $where = "resourcelinkid IN ( SELECT rl.id FROM {{$this->resourcelinktable}} rl WHERE rl.consumerid = :consumerid )"; $DB->delete_records_select($this->userresulttable, $where, $deletecondition); // Delete any users in resource links for contexts in this consumer. $where = "resourcelinkid IN ( SELECT rl.id FROM {{$this->resourcelinktable}} rl INNER JOIN {{$this->contexttable}} c ON rl.contextid = c.id WHERE c.consumerid = :consumerid )"; $DB->delete_records_select($this->userresulttable, $where, $deletecondition); // Update any resource links for which this consumer is acting as a primary resource link. $where = "primaryresourcelinkid IN ( SELECT rl.id FROM {{$this->resourcelinktable}} rl WHERE rl.consumerid = :consumerid )"; $updaterecords = $DB->get_records_select($this->resourcelinktable, $where, $deletecondition); foreach ($updaterecords as $record) { $record->primaryresourcelinkid = null; $record->shareapproved = null; $DB->update_record($this->resourcelinktable, $record); } // Update any resource links for contexts in which this consumer is acting as a primary resource link. $where = "primaryresourcelinkid IN ( SELECT rl.id FROM {{$this->resourcelinktable}} rl INNER JOIN {{$this->contexttable}} c ON rl.contextid = c.id WHERE c.consumerid = :consumerid )"; $updaterecords = $DB->get_records_select($this->resourcelinktable, $where, $deletecondition); foreach ($updaterecords as $record) { $record->primaryresourcelinkid = null; $record->shareapproved = null; $DB->update_record($this->resourcelinktable, $record); } // Delete any resource links for contexts in this consumer. $where = "contextid IN ( SELECT c.id FROM {{$this->contexttable}} c WHERE c.consumerid = :consumerid )"; $DB->delete_records_select($this->resourcelinktable, $where, $deletecondition); // Delete any resource links for this consumer. $DB->delete_records($this->resourcelinktable, $deletecondition); // Delete any contexts for this consumer. $DB->delete_records($this->contexttable, $deletecondition); // Delete consumer. $DB->delete_records($this->consumertable, ['id' => $consumerpk]); $consumer->initialize(); return true; }
[ "public", "function", "deleteToolConsumer", "(", "$", "consumer", ")", "{", "global", "$", "DB", ";", "$", "consumerpk", "=", "$", "consumer", "->", "getRecordId", "(", ")", ";", "$", "deletecondition", "=", "[", "'consumerid'", "=>", "$", "consumerpk", "]", ";", "// Delete any nonce values for this consumer.", "$", "DB", "->", "delete_records", "(", "$", "this", "->", "noncetable", ",", "$", "deletecondition", ")", ";", "// Delete any outstanding share keys for resource links for this consumer.", "$", "where", "=", "\"resourcelinkid IN (\n SELECT rl.id\n FROM {{$this->resourcelinktable}} rl\n WHERE rl.consumerid = :consumerid\n )\"", ";", "$", "DB", "->", "delete_records_select", "(", "$", "this", "->", "sharekeytable", ",", "$", "where", ",", "$", "deletecondition", ")", ";", "// Delete any outstanding share keys for resource links for contexts in this consumer.", "$", "where", "=", "\"resourcelinkid IN (\n SELECT rl.id\n FROM {{$this->resourcelinktable}} rl\n INNER JOIN {{$this->contexttable}} c\n ON rl.contextid = c.id\n WHERE c.consumerid = :consumerid\n )\"", ";", "$", "DB", "->", "delete_records_select", "(", "$", "this", "->", "sharekeytable", ",", "$", "where", ",", "$", "deletecondition", ")", ";", "// Delete any users in resource links for this consumer.", "$", "where", "=", "\"resourcelinkid IN (\n SELECT rl.id\n FROM {{$this->resourcelinktable}} rl\n WHERE rl.consumerid = :consumerid\n )\"", ";", "$", "DB", "->", "delete_records_select", "(", "$", "this", "->", "userresulttable", ",", "$", "where", ",", "$", "deletecondition", ")", ";", "// Delete any users in resource links for contexts in this consumer.", "$", "where", "=", "\"resourcelinkid IN (\n SELECT rl.id\n FROM {{$this->resourcelinktable}} rl\n INNER JOIN {{$this->contexttable}} c\n ON rl.contextid = c.id\n WHERE c.consumerid = :consumerid\n )\"", ";", "$", "DB", "->", "delete_records_select", "(", "$", "this", "->", "userresulttable", ",", "$", "where", ",", "$", "deletecondition", ")", ";", "// Update any resource links for which this consumer is acting as a primary resource link.", "$", "where", "=", "\"primaryresourcelinkid IN (\n SELECT rl.id\n FROM {{$this->resourcelinktable}} rl\n WHERE rl.consumerid = :consumerid\n )\"", ";", "$", "updaterecords", "=", "$", "DB", "->", "get_records_select", "(", "$", "this", "->", "resourcelinktable", ",", "$", "where", ",", "$", "deletecondition", ")", ";", "foreach", "(", "$", "updaterecords", "as", "$", "record", ")", "{", "$", "record", "->", "primaryresourcelinkid", "=", "null", ";", "$", "record", "->", "shareapproved", "=", "null", ";", "$", "DB", "->", "update_record", "(", "$", "this", "->", "resourcelinktable", ",", "$", "record", ")", ";", "}", "// Update any resource links for contexts in which this consumer is acting as a primary resource link.", "$", "where", "=", "\"primaryresourcelinkid IN (\n SELECT rl.id\n FROM {{$this->resourcelinktable}} rl\n INNER JOIN {{$this->contexttable}} c\n ON rl.contextid = c.id\n WHERE c.consumerid = :consumerid\n )\"", ";", "$", "updaterecords", "=", "$", "DB", "->", "get_records_select", "(", "$", "this", "->", "resourcelinktable", ",", "$", "where", ",", "$", "deletecondition", ")", ";", "foreach", "(", "$", "updaterecords", "as", "$", "record", ")", "{", "$", "record", "->", "primaryresourcelinkid", "=", "null", ";", "$", "record", "->", "shareapproved", "=", "null", ";", "$", "DB", "->", "update_record", "(", "$", "this", "->", "resourcelinktable", ",", "$", "record", ")", ";", "}", "// Delete any resource links for contexts in this consumer.", "$", "where", "=", "\"contextid IN (\n SELECT c.id\n FROM {{$this->contexttable}} c\n WHERE c.consumerid = :consumerid\n )\"", ";", "$", "DB", "->", "delete_records_select", "(", "$", "this", "->", "resourcelinktable", ",", "$", "where", ",", "$", "deletecondition", ")", ";", "// Delete any resource links for this consumer.", "$", "DB", "->", "delete_records", "(", "$", "this", "->", "resourcelinktable", ",", "$", "deletecondition", ")", ";", "// Delete any contexts for this consumer.", "$", "DB", "->", "delete_records", "(", "$", "this", "->", "contexttable", ",", "$", "deletecondition", ")", ";", "// Delete consumer.", "$", "DB", "->", "delete_records", "(", "$", "this", "->", "consumertable", ",", "[", "'id'", "=>", "$", "consumerpk", "]", ")", ";", "$", "consumer", "->", "initialize", "(", ")", ";", "return", "true", ";", "}" ]
Delete tool consumer object and related records. @param ToolConsumer $consumer Consumer object @return boolean True if the tool consumer object was successfully deleted
[ "Delete", "tool", "consumer", "object", "and", "related", "records", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/data_connector.php#L173-L266
218,418
moodle/moodle
enrol/lti/classes/data_connector.php
data_connector.getToolConsumers
public function getToolConsumers() { global $DB; $consumers = []; $rsconsumers = $DB->get_recordset($this->consumertable, null, 'name'); foreach ($rsconsumers as $row) { $consumer = new ToolProvider\ToolConsumer($row->consumerkey, $this); $this->build_tool_consumer_object($row, $consumer); $consumers[] = $consumer; } $rsconsumers->close(); return $consumers; }
php
public function getToolConsumers() { global $DB; $consumers = []; $rsconsumers = $DB->get_recordset($this->consumertable, null, 'name'); foreach ($rsconsumers as $row) { $consumer = new ToolProvider\ToolConsumer($row->consumerkey, $this); $this->build_tool_consumer_object($row, $consumer); $consumers[] = $consumer; } $rsconsumers->close(); return $consumers; }
[ "public", "function", "getToolConsumers", "(", ")", "{", "global", "$", "DB", ";", "$", "consumers", "=", "[", "]", ";", "$", "rsconsumers", "=", "$", "DB", "->", "get_recordset", "(", "$", "this", "->", "consumertable", ",", "null", ",", "'name'", ")", ";", "foreach", "(", "$", "rsconsumers", "as", "$", "row", ")", "{", "$", "consumer", "=", "new", "ToolProvider", "\\", "ToolConsumer", "(", "$", "row", "->", "consumerkey", ",", "$", "this", ")", ";", "$", "this", "->", "build_tool_consumer_object", "(", "$", "row", ",", "$", "consumer", ")", ";", "$", "consumers", "[", "]", "=", "$", "consumer", ";", "}", "$", "rsconsumers", "->", "close", "(", ")", ";", "return", "$", "consumers", ";", "}" ]
Load all tool consumers from the database. @return array
[ "Load", "all", "tool", "consumers", "from", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/data_connector.php#L272-L285
218,419
moodle/moodle
enrol/lti/classes/data_connector.php
data_connector.get_contexts_from_consumer
public function get_contexts_from_consumer(ToolConsumer $consumer) { global $DB; $contexts = []; $contextrecords = $DB->get_records($this->contexttable, ['consumerid' => $consumer->getRecordId()], '', 'lticontextkey'); foreach ($contextrecords as $record) { $context = Context::fromConsumer($consumer, $record->lticontextkey); $contexts[] = $context; } return $contexts; }
php
public function get_contexts_from_consumer(ToolConsumer $consumer) { global $DB; $contexts = []; $contextrecords = $DB->get_records($this->contexttable, ['consumerid' => $consumer->getRecordId()], '', 'lticontextkey'); foreach ($contextrecords as $record) { $context = Context::fromConsumer($consumer, $record->lticontextkey); $contexts[] = $context; } return $contexts; }
[ "public", "function", "get_contexts_from_consumer", "(", "ToolConsumer", "$", "consumer", ")", "{", "global", "$", "DB", ";", "$", "contexts", "=", "[", "]", ";", "$", "contextrecords", "=", "$", "DB", "->", "get_records", "(", "$", "this", "->", "contexttable", ",", "[", "'consumerid'", "=>", "$", "consumer", "->", "getRecordId", "(", ")", "]", ",", "''", ",", "'lticontextkey'", ")", ";", "foreach", "(", "$", "contextrecords", "as", "$", "record", ")", "{", "$", "context", "=", "Context", "::", "fromConsumer", "(", "$", "consumer", ",", "$", "record", "->", "lticontextkey", ")", ";", "$", "contexts", "[", "]", "=", "$", "context", ";", "}", "return", "$", "contexts", ";", "}" ]
Fetches the list of Context objects that are linked to a ToolConsumer. @param ToolConsumer $consumer @return Context[]
[ "Fetches", "the", "list", "of", "Context", "objects", "that", "are", "linked", "to", "a", "ToolConsumer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/data_connector.php#L917-L928
218,420
moodle/moodle
enrol/lti/classes/data_connector.php
data_connector.get_resourcelink_from_consumer
public function get_resourcelink_from_consumer(ToolConsumer $consumer) { global $DB; $resourcelink = null; if ($resourcelinkrecord = $DB->get_record($this->resourcelinktable, ['consumerid' => $consumer->getRecordId()], 'ltiresourcelinkkey')) { $resourcelink = ResourceLink::fromConsumer($consumer, $resourcelinkrecord->ltiresourcelinkkey); } return $resourcelink; }
php
public function get_resourcelink_from_consumer(ToolConsumer $consumer) { global $DB; $resourcelink = null; if ($resourcelinkrecord = $DB->get_record($this->resourcelinktable, ['consumerid' => $consumer->getRecordId()], 'ltiresourcelinkkey')) { $resourcelink = ResourceLink::fromConsumer($consumer, $resourcelinkrecord->ltiresourcelinkkey); } return $resourcelink; }
[ "public", "function", "get_resourcelink_from_consumer", "(", "ToolConsumer", "$", "consumer", ")", "{", "global", "$", "DB", ";", "$", "resourcelink", "=", "null", ";", "if", "(", "$", "resourcelinkrecord", "=", "$", "DB", "->", "get_record", "(", "$", "this", "->", "resourcelinktable", ",", "[", "'consumerid'", "=>", "$", "consumer", "->", "getRecordId", "(", ")", "]", ",", "'ltiresourcelinkkey'", ")", ")", "{", "$", "resourcelink", "=", "ResourceLink", "::", "fromConsumer", "(", "$", "consumer", ",", "$", "resourcelinkrecord", "->", "ltiresourcelinkkey", ")", ";", "}", "return", "$", "resourcelink", ";", "}" ]
Fetches a resource link record that is associated with a ToolConsumer. @param ToolConsumer $consumer @return ResourceLink
[ "Fetches", "a", "resource", "link", "record", "that", "is", "associated", "with", "a", "ToolConsumer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/data_connector.php#L936-L946
218,421
moodle/moodle
enrol/lti/classes/data_connector.php
data_connector.get_resourcelink_from_context
public function get_resourcelink_from_context(Context $context) { global $DB; $resourcelink = null; if ($resourcelinkrecord = $DB->get_record($this->resourcelinktable, ['contextid' => $context->getRecordId()], 'ltiresourcelinkkey')) { $resourcelink = ResourceLink::fromContext($context, $resourcelinkrecord->ltiresourcelinkkey); } return $resourcelink; }
php
public function get_resourcelink_from_context(Context $context) { global $DB; $resourcelink = null; if ($resourcelinkrecord = $DB->get_record($this->resourcelinktable, ['contextid' => $context->getRecordId()], 'ltiresourcelinkkey')) { $resourcelink = ResourceLink::fromContext($context, $resourcelinkrecord->ltiresourcelinkkey); } return $resourcelink; }
[ "public", "function", "get_resourcelink_from_context", "(", "Context", "$", "context", ")", "{", "global", "$", "DB", ";", "$", "resourcelink", "=", "null", ";", "if", "(", "$", "resourcelinkrecord", "=", "$", "DB", "->", "get_record", "(", "$", "this", "->", "resourcelinktable", ",", "[", "'contextid'", "=>", "$", "context", "->", "getRecordId", "(", ")", "]", ",", "'ltiresourcelinkkey'", ")", ")", "{", "$", "resourcelink", "=", "ResourceLink", "::", "fromContext", "(", "$", "context", ",", "$", "resourcelinkrecord", "->", "ltiresourcelinkkey", ")", ";", "}", "return", "$", "resourcelink", ";", "}" ]
Fetches a resource link record that is associated with a Context object. @param Context $context @return ResourceLink
[ "Fetches", "a", "resource", "link", "record", "that", "is", "associated", "with", "a", "Context", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/data_connector.php#L954-L964
218,422
moodle/moodle
enrol/lti/classes/data_connector.php
data_connector.get_consumers_mapped_to_tool
public function get_consumers_mapped_to_tool($toolid) { global $DB; $consumers = []; $consumerrecords = $DB->get_records('enrol_lti_tool_consumer_map', ['toolid' => $toolid], '', 'consumerid'); foreach ($consumerrecords as $record) { $consumers[] = ToolConsumer::fromRecordId($record->consumerid, $this); } return $consumers; }
php
public function get_consumers_mapped_to_tool($toolid) { global $DB; $consumers = []; $consumerrecords = $DB->get_records('enrol_lti_tool_consumer_map', ['toolid' => $toolid], '', 'consumerid'); foreach ($consumerrecords as $record) { $consumers[] = ToolConsumer::fromRecordId($record->consumerid, $this); } return $consumers; }
[ "public", "function", "get_consumers_mapped_to_tool", "(", "$", "toolid", ")", "{", "global", "$", "DB", ";", "$", "consumers", "=", "[", "]", ";", "$", "consumerrecords", "=", "$", "DB", "->", "get_records", "(", "'enrol_lti_tool_consumer_map'", ",", "[", "'toolid'", "=>", "$", "toolid", "]", ",", "''", ",", "'consumerid'", ")", ";", "foreach", "(", "$", "consumerrecords", "as", "$", "record", ")", "{", "$", "consumers", "[", "]", "=", "ToolConsumer", "::", "fromRecordId", "(", "$", "record", "->", "consumerid", ",", "$", "this", ")", ";", "}", "return", "$", "consumers", ";", "}" ]
Fetches the list of ToolConsumer objects that are linked to a tool. @param int $toolid @return ToolConsumer[]
[ "Fetches", "the", "list", "of", "ToolConsumer", "objects", "that", "are", "linked", "to", "a", "tool", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/data_connector.php#L973-L982
218,423
moodle/moodle
enrol/lti/classes/data_connector.php
data_connector.build_tool_consumer_object
protected function build_tool_consumer_object($record, ToolConsumer $consumer) { $consumer->setRecordId($record->id); $consumer->name = $record->name; $key = empty($record->consumerkey) ? $record->consumerkey256 : $record->consumerkey; $consumer->setKey($key); $consumer->secret = $record->secret; $consumer->ltiVersion = $record->ltiversion; $consumer->consumerName = $record->consumername; $consumer->consumerVersion = $record->consumerversion; $consumer->consumerGuid = $record->consumerguid; $consumer->profile = json_decode($record->profile); $consumer->toolProxy = $record->toolproxy; $settings = unserialize($record->settings); if (!is_array($settings)) { $settings = array(); } $consumer->setSettings($settings); $consumer->protected = $record->protected == 1; $consumer->enabled = $record->enabled == 1; $consumer->enableFrom = null; if (!is_null($record->enablefrom)) { $consumer->enableFrom = $record->enablefrom; } $consumer->enableUntil = null; if (!is_null($record->enableuntil)) { $consumer->enableUntil = $record->enableuntil; } $consumer->lastAccess = null; if (!is_null($record->lastaccess)) { $consumer->lastAccess = $record->lastaccess; } $consumer->created = $record->created; $consumer->updated = $record->updated; }
php
protected function build_tool_consumer_object($record, ToolConsumer $consumer) { $consumer->setRecordId($record->id); $consumer->name = $record->name; $key = empty($record->consumerkey) ? $record->consumerkey256 : $record->consumerkey; $consumer->setKey($key); $consumer->secret = $record->secret; $consumer->ltiVersion = $record->ltiversion; $consumer->consumerName = $record->consumername; $consumer->consumerVersion = $record->consumerversion; $consumer->consumerGuid = $record->consumerguid; $consumer->profile = json_decode($record->profile); $consumer->toolProxy = $record->toolproxy; $settings = unserialize($record->settings); if (!is_array($settings)) { $settings = array(); } $consumer->setSettings($settings); $consumer->protected = $record->protected == 1; $consumer->enabled = $record->enabled == 1; $consumer->enableFrom = null; if (!is_null($record->enablefrom)) { $consumer->enableFrom = $record->enablefrom; } $consumer->enableUntil = null; if (!is_null($record->enableuntil)) { $consumer->enableUntil = $record->enableuntil; } $consumer->lastAccess = null; if (!is_null($record->lastaccess)) { $consumer->lastAccess = $record->lastaccess; } $consumer->created = $record->created; $consumer->updated = $record->updated; }
[ "protected", "function", "build_tool_consumer_object", "(", "$", "record", ",", "ToolConsumer", "$", "consumer", ")", "{", "$", "consumer", "->", "setRecordId", "(", "$", "record", "->", "id", ")", ";", "$", "consumer", "->", "name", "=", "$", "record", "->", "name", ";", "$", "key", "=", "empty", "(", "$", "record", "->", "consumerkey", ")", "?", "$", "record", "->", "consumerkey256", ":", "$", "record", "->", "consumerkey", ";", "$", "consumer", "->", "setKey", "(", "$", "key", ")", ";", "$", "consumer", "->", "secret", "=", "$", "record", "->", "secret", ";", "$", "consumer", "->", "ltiVersion", "=", "$", "record", "->", "ltiversion", ";", "$", "consumer", "->", "consumerName", "=", "$", "record", "->", "consumername", ";", "$", "consumer", "->", "consumerVersion", "=", "$", "record", "->", "consumerversion", ";", "$", "consumer", "->", "consumerGuid", "=", "$", "record", "->", "consumerguid", ";", "$", "consumer", "->", "profile", "=", "json_decode", "(", "$", "record", "->", "profile", ")", ";", "$", "consumer", "->", "toolProxy", "=", "$", "record", "->", "toolproxy", ";", "$", "settings", "=", "unserialize", "(", "$", "record", "->", "settings", ")", ";", "if", "(", "!", "is_array", "(", "$", "settings", ")", ")", "{", "$", "settings", "=", "array", "(", ")", ";", "}", "$", "consumer", "->", "setSettings", "(", "$", "settings", ")", ";", "$", "consumer", "->", "protected", "=", "$", "record", "->", "protected", "==", "1", ";", "$", "consumer", "->", "enabled", "=", "$", "record", "->", "enabled", "==", "1", ";", "$", "consumer", "->", "enableFrom", "=", "null", ";", "if", "(", "!", "is_null", "(", "$", "record", "->", "enablefrom", ")", ")", "{", "$", "consumer", "->", "enableFrom", "=", "$", "record", "->", "enablefrom", ";", "}", "$", "consumer", "->", "enableUntil", "=", "null", ";", "if", "(", "!", "is_null", "(", "$", "record", "->", "enableuntil", ")", ")", "{", "$", "consumer", "->", "enableUntil", "=", "$", "record", "->", "enableuntil", ";", "}", "$", "consumer", "->", "lastAccess", "=", "null", ";", "if", "(", "!", "is_null", "(", "$", "record", "->", "lastaccess", ")", ")", "{", "$", "consumer", "->", "lastAccess", "=", "$", "record", "->", "lastaccess", ";", "}", "$", "consumer", "->", "created", "=", "$", "record", "->", "created", ";", "$", "consumer", "->", "updated", "=", "$", "record", "->", "updated", ";", "}" ]
Builds a ToolConsumer object from a record object from the DB. @param stdClass $record The DB record object. @param ToolConsumer $consumer
[ "Builds", "a", "ToolConsumer", "object", "from", "a", "record", "object", "from", "the", "DB", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/data_connector.php#L990-L1023
218,424
moodle/moodle
lib/htmlpurifier/HTMLPurifier/URI.php
HTMLPurifier_URI.isLocal
public function isLocal($config, $context) { if ($this->host === null) { return true; } $uri_def = $config->getDefinition('URI'); if ($uri_def->host === $this->host) { return true; } return false; }
php
public function isLocal($config, $context) { if ($this->host === null) { return true; } $uri_def = $config->getDefinition('URI'); if ($uri_def->host === $this->host) { return true; } return false; }
[ "public", "function", "isLocal", "(", "$", "config", ",", "$", "context", ")", "{", "if", "(", "$", "this", "->", "host", "===", "null", ")", "{", "return", "true", ";", "}", "$", "uri_def", "=", "$", "config", "->", "getDefinition", "(", "'URI'", ")", ";", "if", "(", "$", "uri_def", "->", "host", "===", "$", "this", "->", "host", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Returns true if this URL might be considered a 'local' URL given the current context. This is true when the host is null, or when it matches the host supplied to the configuration. Note that this does not do any scheme checking, so it is mostly only appropriate for metadata that doesn't care about protocol security. isBenign is probably what you actually want. @param HTMLPurifier_Config $config @param HTMLPurifier_Context $context @return bool
[ "Returns", "true", "if", "this", "URL", "might", "be", "considered", "a", "local", "URL", "given", "the", "current", "context", ".", "This", "is", "true", "when", "the", "host", "is", "null", "or", "when", "it", "matches", "the", "host", "supplied", "to", "the", "configuration", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/URI.php#L273-L283
218,425
moodle/moodle
mod/feedback/classes/responses_table.php
mod_feedback_responses_table.other_cols
public function other_cols($column, $row) { if (preg_match('/^val(\d+)$/', $column, $matches)) { $items = $this->feedbackstructure->get_items(); $itemobj = feedback_get_item_class($items[$matches[1]]->typ); return trim($itemobj->get_printval($items[$matches[1]], (object) ['value' => $row->$column] )); } return $row->$column; }
php
public function other_cols($column, $row) { if (preg_match('/^val(\d+)$/', $column, $matches)) { $items = $this->feedbackstructure->get_items(); $itemobj = feedback_get_item_class($items[$matches[1]]->typ); return trim($itemobj->get_printval($items[$matches[1]], (object) ['value' => $row->$column] )); } return $row->$column; }
[ "public", "function", "other_cols", "(", "$", "column", ",", "$", "row", ")", "{", "if", "(", "preg_match", "(", "'/^val(\\d+)$/'", ",", "$", "column", ",", "$", "matches", ")", ")", "{", "$", "items", "=", "$", "this", "->", "feedbackstructure", "->", "get_items", "(", ")", ";", "$", "itemobj", "=", "feedback_get_item_class", "(", "$", "items", "[", "$", "matches", "[", "1", "]", "]", "->", "typ", ")", ";", "return", "trim", "(", "$", "itemobj", "->", "get_printval", "(", "$", "items", "[", "$", "matches", "[", "1", "]", "]", ",", "(", "object", ")", "[", "'value'", "=>", "$", "row", "->", "$", "column", "]", ")", ")", ";", "}", "return", "$", "row", "->", "$", "column", ";", "}" ]
Allows to set the display column value for all columns without "col_xxxxx" method. @param string $column column name @param stdClass $row current record result of SQL query
[ "Allows", "to", "set", "the", "display", "column", "value", "for", "all", "columns", "without", "col_xxxxx", "method", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_table.php#L192-L199
218,426
moodle/moodle
mod/feedback/classes/responses_table.php
mod_feedback_responses_table.col_userpic
public function col_userpic($row) { global $OUTPUT; $user = user_picture::unalias($row, [], $this->useridfield); return $OUTPUT->user_picture($user, array('courseid' => $this->feedbackstructure->get_cm()->course)); }
php
public function col_userpic($row) { global $OUTPUT; $user = user_picture::unalias($row, [], $this->useridfield); return $OUTPUT->user_picture($user, array('courseid' => $this->feedbackstructure->get_cm()->course)); }
[ "public", "function", "col_userpic", "(", "$", "row", ")", "{", "global", "$", "OUTPUT", ";", "$", "user", "=", "user_picture", "::", "unalias", "(", "$", "row", ",", "[", "]", ",", "$", "this", "->", "useridfield", ")", ";", "return", "$", "OUTPUT", "->", "user_picture", "(", "$", "user", ",", "array", "(", "'courseid'", "=>", "$", "this", "->", "feedbackstructure", "->", "get_cm", "(", ")", "->", "course", ")", ")", ";", "}" ]
Prepares column userpic for display @param stdClass $row @return string
[ "Prepares", "column", "userpic", "for", "display" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_table.php#L206-L210
218,427
moodle/moodle
mod/feedback/classes/responses_table.php
mod_feedback_responses_table.col_deleteentry
public function col_deleteentry($row) { global $OUTPUT; $deleteentryurl = new moodle_url($this->baseurl, ['delete' => $row->id, 'sesskey' => sesskey()]); $deleteaction = new confirm_action(get_string('confirmdeleteentry', 'feedback')); return $OUTPUT->action_icon($deleteentryurl, new pix_icon('t/delete', get_string('delete_entry', 'feedback')), $deleteaction); }
php
public function col_deleteentry($row) { global $OUTPUT; $deleteentryurl = new moodle_url($this->baseurl, ['delete' => $row->id, 'sesskey' => sesskey()]); $deleteaction = new confirm_action(get_string('confirmdeleteentry', 'feedback')); return $OUTPUT->action_icon($deleteentryurl, new pix_icon('t/delete', get_string('delete_entry', 'feedback')), $deleteaction); }
[ "public", "function", "col_deleteentry", "(", "$", "row", ")", "{", "global", "$", "OUTPUT", ";", "$", "deleteentryurl", "=", "new", "moodle_url", "(", "$", "this", "->", "baseurl", ",", "[", "'delete'", "=>", "$", "row", "->", "id", ",", "'sesskey'", "=>", "sesskey", "(", ")", "]", ")", ";", "$", "deleteaction", "=", "new", "confirm_action", "(", "get_string", "(", "'confirmdeleteentry'", ",", "'feedback'", ")", ")", ";", "return", "$", "OUTPUT", "->", "action_icon", "(", "$", "deleteentryurl", ",", "new", "pix_icon", "(", "'t/delete'", ",", "get_string", "(", "'delete_entry'", ",", "'feedback'", ")", ")", ",", "$", "deleteaction", ")", ";", "}" ]
Prepares column deleteentry for display @param stdClass $row @return string
[ "Prepares", "column", "deleteentry", "for", "display" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_table.php#L217-L223
218,428
moodle/moodle
mod/feedback/classes/responses_table.php
mod_feedback_responses_table.get_link_single_entry
protected function get_link_single_entry($row) { return new moodle_url($this->baseurl, ['userid' => $row->{$this->useridfield}, 'showcompleted' => $row->id]); }
php
protected function get_link_single_entry($row) { return new moodle_url($this->baseurl, ['userid' => $row->{$this->useridfield}, 'showcompleted' => $row->id]); }
[ "protected", "function", "get_link_single_entry", "(", "$", "row", ")", "{", "return", "new", "moodle_url", "(", "$", "this", "->", "baseurl", ",", "[", "'userid'", "=>", "$", "row", "->", "{", "$", "this", "->", "useridfield", "}", ",", "'showcompleted'", "=>", "$", "row", "->", "id", "]", ")", ";", "}" ]
Returns a link for viewing a single response @param stdClass $row @return \moodle_url
[ "Returns", "a", "link", "for", "viewing", "a", "single", "response" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_table.php#L230-L232
218,429
moodle/moodle
mod/feedback/classes/responses_table.php
mod_feedback_responses_table.col_completed_timemodified
public function col_completed_timemodified($student) { if ($this->is_downloading()) { return userdate($student->completed_timemodified); } else { return html_writer::link($this->get_link_single_entry($student), userdate($student->completed_timemodified)); } }
php
public function col_completed_timemodified($student) { if ($this->is_downloading()) { return userdate($student->completed_timemodified); } else { return html_writer::link($this->get_link_single_entry($student), userdate($student->completed_timemodified)); } }
[ "public", "function", "col_completed_timemodified", "(", "$", "student", ")", "{", "if", "(", "$", "this", "->", "is_downloading", "(", ")", ")", "{", "return", "userdate", "(", "$", "student", "->", "completed_timemodified", ")", ";", "}", "else", "{", "return", "html_writer", "::", "link", "(", "$", "this", "->", "get_link_single_entry", "(", "$", "student", ")", ",", "userdate", "(", "$", "student", "->", "completed_timemodified", ")", ")", ";", "}", "}" ]
Prepares column completed_timemodified for display @param stdClass $student @return string
[ "Prepares", "column", "completed_timemodified", "for", "display" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_table.php#L239-L246
218,430
moodle/moodle
mod/feedback/classes/responses_table.php
mod_feedback_responses_table.col_courseid
public function col_courseid($row) { $courses = $this->feedbackstructure->get_completed_courses(); $name = ''; if (isset($courses[$row->courseid])) { $name = $courses[$row->courseid]; if (!$this->is_downloading()) { $name = html_writer::link(course_get_url($row->courseid), $name); } } return $name; }
php
public function col_courseid($row) { $courses = $this->feedbackstructure->get_completed_courses(); $name = ''; if (isset($courses[$row->courseid])) { $name = $courses[$row->courseid]; if (!$this->is_downloading()) { $name = html_writer::link(course_get_url($row->courseid), $name); } } return $name; }
[ "public", "function", "col_courseid", "(", "$", "row", ")", "{", "$", "courses", "=", "$", "this", "->", "feedbackstructure", "->", "get_completed_courses", "(", ")", ";", "$", "name", "=", "''", ";", "if", "(", "isset", "(", "$", "courses", "[", "$", "row", "->", "courseid", "]", ")", ")", "{", "$", "name", "=", "$", "courses", "[", "$", "row", "->", "courseid", "]", ";", "if", "(", "!", "$", "this", "->", "is_downloading", "(", ")", ")", "{", "$", "name", "=", "html_writer", "::", "link", "(", "course_get_url", "(", "$", "row", "->", "courseid", ")", ",", "$", "name", ")", ";", "}", "}", "return", "$", "name", ";", "}" ]
Prepares column courseid for display @param array $row @return string
[ "Prepares", "column", "courseid", "for", "display" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_table.php#L253-L263
218,431
moodle/moodle
mod/feedback/classes/responses_table.php
mod_feedback_responses_table.col_groups
public function col_groups($row) { $groups = ''; if ($usergrps = groups_get_all_groups($this->feedbackstructure->get_cm()->course, $row->userid, 0, 'name')) { foreach ($usergrps as $group) { $groups .= format_string($group->name). ' '; } } return trim($groups); }
php
public function col_groups($row) { $groups = ''; if ($usergrps = groups_get_all_groups($this->feedbackstructure->get_cm()->course, $row->userid, 0, 'name')) { foreach ($usergrps as $group) { $groups .= format_string($group->name). ' '; } } return trim($groups); }
[ "public", "function", "col_groups", "(", "$", "row", ")", "{", "$", "groups", "=", "''", ";", "if", "(", "$", "usergrps", "=", "groups_get_all_groups", "(", "$", "this", "->", "feedbackstructure", "->", "get_cm", "(", ")", "->", "course", ",", "$", "row", "->", "userid", ",", "0", ",", "'name'", ")", ")", "{", "foreach", "(", "$", "usergrps", "as", "$", "group", ")", "{", "$", "groups", ".=", "format_string", "(", "$", "group", "->", "name", ")", ".", "' '", ";", "}", "}", "return", "trim", "(", "$", "groups", ")", ";", "}" ]
Prepares column groups for display @param array $row @return string
[ "Prepares", "column", "groups", "for", "display" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_table.php#L270-L278
218,432
moodle/moodle
mod/feedback/classes/responses_table.php
mod_feedback_responses_table.add_all_values_to_output
protected function add_all_values_to_output() { $tablecolumns = array_keys($this->columns); $tableheaders = $this->headers; $items = $this->feedbackstructure->get_items(true); if (!$this->is_downloading() && !$this->buildforexternal) { // In preview mode do not show all columns or the page becomes unreadable. // The information message will be displayed to the teacher that the rest of the data can be viewed when downloading. $items = array_slice($items, 0, self::PREVIEWCOLUMNSLIMIT, true); } $columnscount = 0; $this->hasmorecolumns = max(0, count($items) - self::TABLEJOINLIMIT); // Add feedback response values. foreach ($items as $nr => $item) { if ($columnscount++ < self::TABLEJOINLIMIT) { // Mysql has a limit on the number of tables in the join, so we only add limited number of columns here, // the rest will be added in {@link self::build_table()} and {@link self::build_table_chunk()} functions. $this->sql->fields .= ", v{$nr}.value AS val{$nr}"; $this->sql->from .= " LEFT OUTER JOIN {feedback_value} v{$nr} " . "ON v{$nr}.completed = c.id AND v{$nr}.item = :itemid{$nr}"; $this->sql->params["itemid{$nr}"] = $item->id; } $tablecolumns[] = "val{$nr}"; $itemobj = feedback_get_item_class($item->typ); $tableheaders[] = $itemobj->get_display_name($item); } // Add 'Delete entry' column. if (!$this->is_downloading() && has_capability('mod/feedback:deletesubmissions', $this->get_context())) { $tablecolumns[] = 'deleteentry'; $tableheaders[] = ''; } $this->define_columns($tablecolumns); $this->define_headers($tableheaders); }
php
protected function add_all_values_to_output() { $tablecolumns = array_keys($this->columns); $tableheaders = $this->headers; $items = $this->feedbackstructure->get_items(true); if (!$this->is_downloading() && !$this->buildforexternal) { // In preview mode do not show all columns or the page becomes unreadable. // The information message will be displayed to the teacher that the rest of the data can be viewed when downloading. $items = array_slice($items, 0, self::PREVIEWCOLUMNSLIMIT, true); } $columnscount = 0; $this->hasmorecolumns = max(0, count($items) - self::TABLEJOINLIMIT); // Add feedback response values. foreach ($items as $nr => $item) { if ($columnscount++ < self::TABLEJOINLIMIT) { // Mysql has a limit on the number of tables in the join, so we only add limited number of columns here, // the rest will be added in {@link self::build_table()} and {@link self::build_table_chunk()} functions. $this->sql->fields .= ", v{$nr}.value AS val{$nr}"; $this->sql->from .= " LEFT OUTER JOIN {feedback_value} v{$nr} " . "ON v{$nr}.completed = c.id AND v{$nr}.item = :itemid{$nr}"; $this->sql->params["itemid{$nr}"] = $item->id; } $tablecolumns[] = "val{$nr}"; $itemobj = feedback_get_item_class($item->typ); $tableheaders[] = $itemobj->get_display_name($item); } // Add 'Delete entry' column. if (!$this->is_downloading() && has_capability('mod/feedback:deletesubmissions', $this->get_context())) { $tablecolumns[] = 'deleteentry'; $tableheaders[] = ''; } $this->define_columns($tablecolumns); $this->define_headers($tableheaders); }
[ "protected", "function", "add_all_values_to_output", "(", ")", "{", "$", "tablecolumns", "=", "array_keys", "(", "$", "this", "->", "columns", ")", ";", "$", "tableheaders", "=", "$", "this", "->", "headers", ";", "$", "items", "=", "$", "this", "->", "feedbackstructure", "->", "get_items", "(", "true", ")", ";", "if", "(", "!", "$", "this", "->", "is_downloading", "(", ")", "&&", "!", "$", "this", "->", "buildforexternal", ")", "{", "// In preview mode do not show all columns or the page becomes unreadable.", "// The information message will be displayed to the teacher that the rest of the data can be viewed when downloading.", "$", "items", "=", "array_slice", "(", "$", "items", ",", "0", ",", "self", "::", "PREVIEWCOLUMNSLIMIT", ",", "true", ")", ";", "}", "$", "columnscount", "=", "0", ";", "$", "this", "->", "hasmorecolumns", "=", "max", "(", "0", ",", "count", "(", "$", "items", ")", "-", "self", "::", "TABLEJOINLIMIT", ")", ";", "// Add feedback response values.", "foreach", "(", "$", "items", "as", "$", "nr", "=>", "$", "item", ")", "{", "if", "(", "$", "columnscount", "++", "<", "self", "::", "TABLEJOINLIMIT", ")", "{", "// Mysql has a limit on the number of tables in the join, so we only add limited number of columns here,", "// the rest will be added in {@link self::build_table()} and {@link self::build_table_chunk()} functions.", "$", "this", "->", "sql", "->", "fields", ".=", "\", v{$nr}.value AS val{$nr}\"", ";", "$", "this", "->", "sql", "->", "from", ".=", "\" LEFT OUTER JOIN {feedback_value} v{$nr} \"", ".", "\"ON v{$nr}.completed = c.id AND v{$nr}.item = :itemid{$nr}\"", ";", "$", "this", "->", "sql", "->", "params", "[", "\"itemid{$nr}\"", "]", "=", "$", "item", "->", "id", ";", "}", "$", "tablecolumns", "[", "]", "=", "\"val{$nr}\"", ";", "$", "itemobj", "=", "feedback_get_item_class", "(", "$", "item", "->", "typ", ")", ";", "$", "tableheaders", "[", "]", "=", "$", "itemobj", "->", "get_display_name", "(", "$", "item", ")", ";", "}", "// Add 'Delete entry' column.", "if", "(", "!", "$", "this", "->", "is_downloading", "(", ")", "&&", "has_capability", "(", "'mod/feedback:deletesubmissions'", ",", "$", "this", "->", "get_context", "(", ")", ")", ")", "{", "$", "tablecolumns", "[", "]", "=", "'deleteentry'", ";", "$", "tableheaders", "[", "]", "=", "''", ";", "}", "$", "this", "->", "define_columns", "(", "$", "tablecolumns", ")", ";", "$", "this", "->", "define_headers", "(", "$", "tableheaders", ")", ";", "}" ]
Adds common values to the table that do not change the number or order of entries and are only needed when outputting or downloading data.
[ "Adds", "common", "values", "to", "the", "table", "that", "do", "not", "change", "the", "number", "or", "order", "of", "entries", "and", "are", "only", "needed", "when", "outputting", "or", "downloading", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_table.php#L284-L322
218,433
moodle/moodle
mod/feedback/classes/responses_table.php
mod_feedback_responses_table.display
public function display() { global $OUTPUT; groups_print_activity_menu($this->feedbackstructure->get_cm(), $this->baseurl->out()); $grandtotal = $this->get_total_responses_count(); if (!$grandtotal) { echo $OUTPUT->box(get_string('nothingtodisplay'), 'generalbox nothingtodisplay'); return; } if (count($this->feedbackstructure->get_items(true)) > self::PREVIEWCOLUMNSLIMIT) { echo $OUTPUT->notification(get_string('questionslimited', 'feedback', self::PREVIEWCOLUMNSLIMIT), 'info'); } $this->out($this->showall ? $grandtotal : FEEDBACK_DEFAULT_PAGE_COUNT, $grandtotal > FEEDBACK_DEFAULT_PAGE_COUNT); // Toggle 'Show all' link. if ($this->totalrows > FEEDBACK_DEFAULT_PAGE_COUNT) { if (!$this->use_pages) { echo html_writer::div(html_writer::link(new moodle_url($this->baseurl, [$this->showallparamname => 0]), get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)), 'showall'); } else { echo html_writer::div(html_writer::link(new moodle_url($this->baseurl, [$this->showallparamname => 1]), get_string('showall', '', $this->totalrows)), 'showall'); } } }
php
public function display() { global $OUTPUT; groups_print_activity_menu($this->feedbackstructure->get_cm(), $this->baseurl->out()); $grandtotal = $this->get_total_responses_count(); if (!$grandtotal) { echo $OUTPUT->box(get_string('nothingtodisplay'), 'generalbox nothingtodisplay'); return; } if (count($this->feedbackstructure->get_items(true)) > self::PREVIEWCOLUMNSLIMIT) { echo $OUTPUT->notification(get_string('questionslimited', 'feedback', self::PREVIEWCOLUMNSLIMIT), 'info'); } $this->out($this->showall ? $grandtotal : FEEDBACK_DEFAULT_PAGE_COUNT, $grandtotal > FEEDBACK_DEFAULT_PAGE_COUNT); // Toggle 'Show all' link. if ($this->totalrows > FEEDBACK_DEFAULT_PAGE_COUNT) { if (!$this->use_pages) { echo html_writer::div(html_writer::link(new moodle_url($this->baseurl, [$this->showallparamname => 0]), get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)), 'showall'); } else { echo html_writer::div(html_writer::link(new moodle_url($this->baseurl, [$this->showallparamname => 1]), get_string('showall', '', $this->totalrows)), 'showall'); } } }
[ "public", "function", "display", "(", ")", "{", "global", "$", "OUTPUT", ";", "groups_print_activity_menu", "(", "$", "this", "->", "feedbackstructure", "->", "get_cm", "(", ")", ",", "$", "this", "->", "baseurl", "->", "out", "(", ")", ")", ";", "$", "grandtotal", "=", "$", "this", "->", "get_total_responses_count", "(", ")", ";", "if", "(", "!", "$", "grandtotal", ")", "{", "echo", "$", "OUTPUT", "->", "box", "(", "get_string", "(", "'nothingtodisplay'", ")", ",", "'generalbox nothingtodisplay'", ")", ";", "return", ";", "}", "if", "(", "count", "(", "$", "this", "->", "feedbackstructure", "->", "get_items", "(", "true", ")", ")", ">", "self", "::", "PREVIEWCOLUMNSLIMIT", ")", "{", "echo", "$", "OUTPUT", "->", "notification", "(", "get_string", "(", "'questionslimited'", ",", "'feedback'", ",", "self", "::", "PREVIEWCOLUMNSLIMIT", ")", ",", "'info'", ")", ";", "}", "$", "this", "->", "out", "(", "$", "this", "->", "showall", "?", "$", "grandtotal", ":", "FEEDBACK_DEFAULT_PAGE_COUNT", ",", "$", "grandtotal", ">", "FEEDBACK_DEFAULT_PAGE_COUNT", ")", ";", "// Toggle 'Show all' link.", "if", "(", "$", "this", "->", "totalrows", ">", "FEEDBACK_DEFAULT_PAGE_COUNT", ")", "{", "if", "(", "!", "$", "this", "->", "use_pages", ")", "{", "echo", "html_writer", "::", "div", "(", "html_writer", "::", "link", "(", "new", "moodle_url", "(", "$", "this", "->", "baseurl", ",", "[", "$", "this", "->", "showallparamname", "=>", "0", "]", ")", ",", "get_string", "(", "'showperpage'", ",", "''", ",", "FEEDBACK_DEFAULT_PAGE_COUNT", ")", ")", ",", "'showall'", ")", ";", "}", "else", "{", "echo", "html_writer", "::", "div", "(", "html_writer", "::", "link", "(", "new", "moodle_url", "(", "$", "this", "->", "baseurl", ",", "[", "$", "this", "->", "showallparamname", "=>", "1", "]", ")", ",", "get_string", "(", "'showall'", ",", "''", ",", "$", "this", "->", "totalrows", ")", ")", ",", "'showall'", ")", ";", "}", "}", "}" ]
Displays the table
[ "Displays", "the", "table" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_table.php#L409-L435
218,434
moodle/moodle
mod/feedback/classes/responses_table.php
mod_feedback_responses_table.download
public function download() { \core\session\manager::write_close(); $this->out($this->get_total_responses_count(), false); exit; }
php
public function download() { \core\session\manager::write_close(); $this->out($this->get_total_responses_count(), false); exit; }
[ "public", "function", "download", "(", ")", "{", "\\", "core", "\\", "session", "\\", "manager", "::", "write_close", "(", ")", ";", "$", "this", "->", "out", "(", "$", "this", "->", "get_total_responses_count", "(", ")", ",", "false", ")", ";", "exit", ";", "}" ]
Download the data.
[ "Download", "the", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_table.php#L476-L480
218,435
moodle/moodle
mod/feedback/classes/responses_table.php
mod_feedback_responses_table.build_table_chunk
protected function build_table_chunk(&$rows, &$columnsgroups) { global $DB; if (!$rows) { return; } foreach ($columnsgroups as $columnsgroup) { $fields = 'c.id'; $from = '{feedback_completed} c'; $params = []; foreach ($columnsgroup as $nr => $item) { $fields .= ", v{$nr}.value AS val{$nr}"; $from .= " LEFT OUTER JOIN {feedback_value} v{$nr} " . "ON v{$nr}.completed = c.id AND v{$nr}.item = :itemid{$nr}"; $params["itemid{$nr}"] = $item->id; } list($idsql, $idparams) = $DB->get_in_or_equal(array_keys($rows), SQL_PARAMS_NAMED); $sql = "SELECT $fields FROM $from WHERE c.id ".$idsql; $results = $DB->get_records_sql($sql, $params + $idparams); foreach ($results as $result) { foreach ($result as $key => $value) { $rows[$result->id]->{$key} = $value; } } } foreach ($rows as $row) { if ($this->buildforexternal) { $this->add_data_for_external($row); } else { $this->add_data_keyed($this->format_row($row), $this->get_row_class($row)); } } }
php
protected function build_table_chunk(&$rows, &$columnsgroups) { global $DB; if (!$rows) { return; } foreach ($columnsgroups as $columnsgroup) { $fields = 'c.id'; $from = '{feedback_completed} c'; $params = []; foreach ($columnsgroup as $nr => $item) { $fields .= ", v{$nr}.value AS val{$nr}"; $from .= " LEFT OUTER JOIN {feedback_value} v{$nr} " . "ON v{$nr}.completed = c.id AND v{$nr}.item = :itemid{$nr}"; $params["itemid{$nr}"] = $item->id; } list($idsql, $idparams) = $DB->get_in_or_equal(array_keys($rows), SQL_PARAMS_NAMED); $sql = "SELECT $fields FROM $from WHERE c.id ".$idsql; $results = $DB->get_records_sql($sql, $params + $idparams); foreach ($results as $result) { foreach ($result as $key => $value) { $rows[$result->id]->{$key} = $value; } } } foreach ($rows as $row) { if ($this->buildforexternal) { $this->add_data_for_external($row); } else { $this->add_data_keyed($this->format_row($row), $this->get_row_class($row)); } } }
[ "protected", "function", "build_table_chunk", "(", "&", "$", "rows", ",", "&", "$", "columnsgroups", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "$", "rows", ")", "{", "return", ";", "}", "foreach", "(", "$", "columnsgroups", "as", "$", "columnsgroup", ")", "{", "$", "fields", "=", "'c.id'", ";", "$", "from", "=", "'{feedback_completed} c'", ";", "$", "params", "=", "[", "]", ";", "foreach", "(", "$", "columnsgroup", "as", "$", "nr", "=>", "$", "item", ")", "{", "$", "fields", ".=", "\", v{$nr}.value AS val{$nr}\"", ";", "$", "from", ".=", "\" LEFT OUTER JOIN {feedback_value} v{$nr} \"", ".", "\"ON v{$nr}.completed = c.id AND v{$nr}.item = :itemid{$nr}\"", ";", "$", "params", "[", "\"itemid{$nr}\"", "]", "=", "$", "item", "->", "id", ";", "}", "list", "(", "$", "idsql", ",", "$", "idparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "array_keys", "(", "$", "rows", ")", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sql", "=", "\"SELECT $fields FROM $from WHERE c.id \"", ".", "$", "idsql", ";", "$", "results", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", "+", "$", "idparams", ")", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "foreach", "(", "$", "result", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "rows", "[", "$", "result", "->", "id", "]", "->", "{", "$", "key", "}", "=", "$", "value", ";", "}", "}", "}", "foreach", "(", "$", "rows", "as", "$", "row", ")", "{", "if", "(", "$", "this", "->", "buildforexternal", ")", "{", "$", "this", "->", "add_data_for_external", "(", "$", "row", ")", ";", "}", "else", "{", "$", "this", "->", "add_data_keyed", "(", "$", "this", "->", "format_row", "(", "$", "row", ")", ",", "$", "this", "->", "get_row_class", "(", "$", "row", ")", ")", ";", "}", "}", "}" ]
Retrieve additional columns. Database engine may have a limit on number of joins. @param array $rows Array of rows with already retrieved data, new values will be added to this array @param array $columnsgroups array of arrays of columns. Each element has up to self::TABLEJOINLIMIT items. This is easy to calculate but because we can call this method many times we calculate it once and pass by reference for performance reasons
[ "Retrieve", "additional", "columns", ".", "Database", "engine", "may", "have", "a", "limit", "on", "number", "of", "joins", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_table.php#L536-L569
218,436
moodle/moodle
mod/feedback/classes/responses_table.php
mod_feedback_responses_table.get_responses_for_external
protected function get_responses_for_external($row) { $responses = []; foreach ($row as $el => $val) { // Get id from column name. if (preg_match('/^val(\d+)$/', $el, $matches)) { $id = $matches[1]; $responses[] = [ 'id' => $id, 'name' => $this->headers[$this->columns[$el]], 'printval' => $this->other_cols($el, $row), 'rawval' => $val, ]; } } return $responses; }
php
protected function get_responses_for_external($row) { $responses = []; foreach ($row as $el => $val) { // Get id from column name. if (preg_match('/^val(\d+)$/', $el, $matches)) { $id = $matches[1]; $responses[] = [ 'id' => $id, 'name' => $this->headers[$this->columns[$el]], 'printval' => $this->other_cols($el, $row), 'rawval' => $val, ]; } } return $responses; }
[ "protected", "function", "get_responses_for_external", "(", "$", "row", ")", "{", "$", "responses", "=", "[", "]", ";", "foreach", "(", "$", "row", "as", "$", "el", "=>", "$", "val", ")", "{", "// Get id from column name.", "if", "(", "preg_match", "(", "'/^val(\\d+)$/'", ",", "$", "el", ",", "$", "matches", ")", ")", "{", "$", "id", "=", "$", "matches", "[", "1", "]", ";", "$", "responses", "[", "]", "=", "[", "'id'", "=>", "$", "id", ",", "'name'", "=>", "$", "this", "->", "headers", "[", "$", "this", "->", "columns", "[", "$", "el", "]", "]", ",", "'printval'", "=>", "$", "this", "->", "other_cols", "(", "$", "el", ",", "$", "row", ")", ",", "'rawval'", "=>", "$", "val", ",", "]", ";", "}", "}", "return", "$", "responses", ";", "}" ]
Return user responses data ready for the external function. @param stdClass $row the table row containing the responses @return array returns the responses ready to be used by an external function @since Moodle 3.3
[ "Return", "user", "responses", "data", "ready", "for", "the", "external", "function", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_table.php#L592-L608
218,437
moodle/moodle
mod/feedback/classes/responses_table.php
mod_feedback_responses_table.export_external_structure
public function export_external_structure($page = 0, $perpage = 0) { $this->buildforexternal = true; $this->add_all_values_to_output(); // Set-up. $this->setup(); // Override values, if needed. if ($perpage > 0) { $this->pageable = true; $this->currpage = $page; $this->pagesize = $perpage; } else { $this->pagesize = $this->get_total_responses_count(); } $this->query_db($this->pagesize, false); $this->build_table(); $this->close_recordset(); return $this->dataforexternal; }
php
public function export_external_structure($page = 0, $perpage = 0) { $this->buildforexternal = true; $this->add_all_values_to_output(); // Set-up. $this->setup(); // Override values, if needed. if ($perpage > 0) { $this->pageable = true; $this->currpage = $page; $this->pagesize = $perpage; } else { $this->pagesize = $this->get_total_responses_count(); } $this->query_db($this->pagesize, false); $this->build_table(); $this->close_recordset(); return $this->dataforexternal; }
[ "public", "function", "export_external_structure", "(", "$", "page", "=", "0", ",", "$", "perpage", "=", "0", ")", "{", "$", "this", "->", "buildforexternal", "=", "true", ";", "$", "this", "->", "add_all_values_to_output", "(", ")", ";", "// Set-up.", "$", "this", "->", "setup", "(", ")", ";", "// Override values, if needed.", "if", "(", "$", "perpage", ">", "0", ")", "{", "$", "this", "->", "pageable", "=", "true", ";", "$", "this", "->", "currpage", "=", "$", "page", ";", "$", "this", "->", "pagesize", "=", "$", "perpage", ";", "}", "else", "{", "$", "this", "->", "pagesize", "=", "$", "this", "->", "get_total_responses_count", "(", ")", ";", "}", "$", "this", "->", "query_db", "(", "$", "this", "->", "pagesize", ",", "false", ")", ";", "$", "this", "->", "build_table", "(", ")", ";", "$", "this", "->", "close_recordset", "(", ")", ";", "return", "$", "this", "->", "dataforexternal", ";", "}" ]
Exports the table as an external structure handling pagination. @param int $page page number (for pagination) @param int $perpage elements per page @since Moodle 3.3 @return array returns the table ready to be used by an external function
[ "Exports", "the", "table", "as", "an", "external", "structure", "handling", "pagination", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_table.php#L635-L653
218,438
moodle/moodle
course/moodleform_mod.php
moodleform_mod.plugin_extend_coursemodule_validation
protected function plugin_extend_coursemodule_validation($data) { $errors = array(); $callbacks = get_plugins_with_function('coursemodule_validation', 'lib.php'); foreach ($callbacks as $type => $plugins) { foreach ($plugins as $plugin => $pluginfunction) { // We have exposed all the important properties with public getters - the errors array should be pass by reference. $pluginerrors = $pluginfunction($this, $data); if (!empty($pluginerrors)) { $errors = array_merge($errors, $pluginerrors); } } } return $errors; }
php
protected function plugin_extend_coursemodule_validation($data) { $errors = array(); $callbacks = get_plugins_with_function('coursemodule_validation', 'lib.php'); foreach ($callbacks as $type => $plugins) { foreach ($plugins as $plugin => $pluginfunction) { // We have exposed all the important properties with public getters - the errors array should be pass by reference. $pluginerrors = $pluginfunction($this, $data); if (!empty($pluginerrors)) { $errors = array_merge($errors, $pluginerrors); } } } return $errors; }
[ "protected", "function", "plugin_extend_coursemodule_validation", "(", "$", "data", ")", "{", "$", "errors", "=", "array", "(", ")", ";", "$", "callbacks", "=", "get_plugins_with_function", "(", "'coursemodule_validation'", ",", "'lib.php'", ")", ";", "foreach", "(", "$", "callbacks", "as", "$", "type", "=>", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "plugin", "=>", "$", "pluginfunction", ")", "{", "// We have exposed all the important properties with public getters - the errors array should be pass by reference.", "$", "pluginerrors", "=", "$", "pluginfunction", "(", "$", "this", ",", "$", "data", ")", ";", "if", "(", "!", "empty", "(", "$", "pluginerrors", ")", ")", "{", "$", "errors", "=", "array_merge", "(", "$", "errors", ",", "$", "pluginerrors", ")", ";", "}", "}", "}", "return", "$", "errors", ";", "}" ]
Extend the validation function from any other plugin. @param stdClass $data The form data. @return array $errors The list of errors keyed by element name.
[ "Extend", "the", "validation", "function", "from", "any", "other", "plugin", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/moodleform_mod.php#L453-L467
218,439
moodle/moodle
course/moodleform_mod.php
moodleform_mod.plugin_extend_coursemodule_standard_elements
protected function plugin_extend_coursemodule_standard_elements() { $callbacks = get_plugins_with_function('coursemodule_standard_elements', 'lib.php'); foreach ($callbacks as $type => $plugins) { foreach ($plugins as $plugin => $pluginfunction) { // We have exposed all the important properties with public getters - and the callback can manipulate the mform // directly. $pluginfunction($this, $this->_form); } } }
php
protected function plugin_extend_coursemodule_standard_elements() { $callbacks = get_plugins_with_function('coursemodule_standard_elements', 'lib.php'); foreach ($callbacks as $type => $plugins) { foreach ($plugins as $plugin => $pluginfunction) { // We have exposed all the important properties with public getters - and the callback can manipulate the mform // directly. $pluginfunction($this, $this->_form); } } }
[ "protected", "function", "plugin_extend_coursemodule_standard_elements", "(", ")", "{", "$", "callbacks", "=", "get_plugins_with_function", "(", "'coursemodule_standard_elements'", ",", "'lib.php'", ")", ";", "foreach", "(", "$", "callbacks", "as", "$", "type", "=>", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "plugin", "=>", "$", "pluginfunction", ")", "{", "// We have exposed all the important properties with public getters - and the callback can manipulate the mform", "// directly.", "$", "pluginfunction", "(", "$", "this", ",", "$", "this", "->", "_form", ")", ";", "}", "}", "}" ]
Plugins can extend the coursemodule settings form.
[ "Plugins", "can", "extend", "the", "coursemodule", "settings", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/moodleform_mod.php#L743-L752
218,440
moodle/moodle
course/moodleform_mod.php
moodleform_mod.apply_admin_locked_flags
protected function apply_admin_locked_flags() { global $OUTPUT; if (!$this->applyadminlockedflags) { return; } $settings = get_config($this->_modname); $mform = $this->_form; $lockedicon = html_writer::tag('span', $OUTPUT->pix_icon('t/locked', get_string('locked', 'admin')), array('class' => 'action-icon')); $isupdate = !empty($this->_cm); foreach ($settings as $name => $value) { if (strpos('_', $name) !== false) { continue; } if ($mform->elementExists($name)) { $element = $mform->getElement($name); $lockedsetting = $name . '_locked'; if (!empty($settings->$lockedsetting)) { // Always lock locked settings for new modules, // for updates, only lock them if the current value is the same as the default (or there is no current value). $value = $settings->$name; if ($isupdate && isset($this->current->$name)) { $value = $this->current->$name; } if ($value == $settings->$name) { $mform->setConstant($name, $settings->$name); $element->setLabel($element->getLabel() . $lockedicon); // Do not use hardfreeze because we need the hidden input to check dependencies. $element->freeze(); } } } } }
php
protected function apply_admin_locked_flags() { global $OUTPUT; if (!$this->applyadminlockedflags) { return; } $settings = get_config($this->_modname); $mform = $this->_form; $lockedicon = html_writer::tag('span', $OUTPUT->pix_icon('t/locked', get_string('locked', 'admin')), array('class' => 'action-icon')); $isupdate = !empty($this->_cm); foreach ($settings as $name => $value) { if (strpos('_', $name) !== false) { continue; } if ($mform->elementExists($name)) { $element = $mform->getElement($name); $lockedsetting = $name . '_locked'; if (!empty($settings->$lockedsetting)) { // Always lock locked settings for new modules, // for updates, only lock them if the current value is the same as the default (or there is no current value). $value = $settings->$name; if ($isupdate && isset($this->current->$name)) { $value = $this->current->$name; } if ($value == $settings->$name) { $mform->setConstant($name, $settings->$name); $element->setLabel($element->getLabel() . $lockedicon); // Do not use hardfreeze because we need the hidden input to check dependencies. $element->freeze(); } } } } }
[ "protected", "function", "apply_admin_locked_flags", "(", ")", "{", "global", "$", "OUTPUT", ";", "if", "(", "!", "$", "this", "->", "applyadminlockedflags", ")", "{", "return", ";", "}", "$", "settings", "=", "get_config", "(", "$", "this", "->", "_modname", ")", ";", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "lockedicon", "=", "html_writer", "::", "tag", "(", "'span'", ",", "$", "OUTPUT", "->", "pix_icon", "(", "'t/locked'", ",", "get_string", "(", "'locked'", ",", "'admin'", ")", ")", ",", "array", "(", "'class'", "=>", "'action-icon'", ")", ")", ";", "$", "isupdate", "=", "!", "empty", "(", "$", "this", "->", "_cm", ")", ";", "foreach", "(", "$", "settings", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "strpos", "(", "'_'", ",", "$", "name", ")", "!==", "false", ")", "{", "continue", ";", "}", "if", "(", "$", "mform", "->", "elementExists", "(", "$", "name", ")", ")", "{", "$", "element", "=", "$", "mform", "->", "getElement", "(", "$", "name", ")", ";", "$", "lockedsetting", "=", "$", "name", ".", "'_locked'", ";", "if", "(", "!", "empty", "(", "$", "settings", "->", "$", "lockedsetting", ")", ")", "{", "// Always lock locked settings for new modules,", "// for updates, only lock them if the current value is the same as the default (or there is no current value).", "$", "value", "=", "$", "settings", "->", "$", "name", ";", "if", "(", "$", "isupdate", "&&", "isset", "(", "$", "this", "->", "current", "->", "$", "name", ")", ")", "{", "$", "value", "=", "$", "this", "->", "current", "->", "$", "name", ";", "}", "if", "(", "$", "value", "==", "$", "settings", "->", "$", "name", ")", "{", "$", "mform", "->", "setConstant", "(", "$", "name", ",", "$", "settings", "->", "$", "name", ")", ";", "$", "element", "->", "setLabel", "(", "$", "element", "->", "getLabel", "(", ")", ".", "$", "lockedicon", ")", ";", "// Do not use hardfreeze because we need the hidden input to check dependencies.", "$", "element", "->", "freeze", "(", ")", ";", "}", "}", "}", "}", "}" ]
Get the list of admin settings for this module and apply any locked settings. This cannot happen in apply_admin_defaults because we do not the current values of the settings in that function because set_data has not been called yet. @return void
[ "Get", "the", "list", "of", "admin", "settings", "for", "this", "module", "and", "apply", "any", "locked", "settings", ".", "This", "cannot", "happen", "in", "apply_admin_defaults", "because", "we", "do", "not", "the", "current", "values", "of", "the", "settings", "in", "that", "function", "because", "set_data", "has", "not", "been", "called", "yet", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/moodleform_mod.php#L994-L1031
218,441
moodle/moodle
rating/classes/privacy/provider.php
provider.export_area_ratings
public static function export_area_ratings( int $userid, \context $context, array $subcontext, string $component, string $ratingarea, int $itemid, bool $onlyuser = true ) { global $DB; $rm = new \rating_manager(); $ratings = $rm->get_all_ratings_for_item((object) [ 'context' => $context, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, ]); if ($onlyuser) { $ratings = array_filter($ratings, function($rating) use ($userid){ return ($rating->userid == $userid); }); } if (empty($ratings)) { return; } $toexport = array_map(function($rating) { return (object) [ 'rating' => $rating->rating, 'author' => $rating->userid, ]; }, $ratings); $writer = \core_privacy\local\request\writer::with_context($context) ->export_related_data($subcontext, 'rating', $toexport); }
php
public static function export_area_ratings( int $userid, \context $context, array $subcontext, string $component, string $ratingarea, int $itemid, bool $onlyuser = true ) { global $DB; $rm = new \rating_manager(); $ratings = $rm->get_all_ratings_for_item((object) [ 'context' => $context, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, ]); if ($onlyuser) { $ratings = array_filter($ratings, function($rating) use ($userid){ return ($rating->userid == $userid); }); } if (empty($ratings)) { return; } $toexport = array_map(function($rating) { return (object) [ 'rating' => $rating->rating, 'author' => $rating->userid, ]; }, $ratings); $writer = \core_privacy\local\request\writer::with_context($context) ->export_related_data($subcontext, 'rating', $toexport); }
[ "public", "static", "function", "export_area_ratings", "(", "int", "$", "userid", ",", "\\", "context", "$", "context", ",", "array", "$", "subcontext", ",", "string", "$", "component", ",", "string", "$", "ratingarea", ",", "int", "$", "itemid", ",", "bool", "$", "onlyuser", "=", "true", ")", "{", "global", "$", "DB", ";", "$", "rm", "=", "new", "\\", "rating_manager", "(", ")", ";", "$", "ratings", "=", "$", "rm", "->", "get_all_ratings_for_item", "(", "(", "object", ")", "[", "'context'", "=>", "$", "context", ",", "'component'", "=>", "$", "component", ",", "'ratingarea'", "=>", "$", "ratingarea", ",", "'itemid'", "=>", "$", "itemid", ",", "]", ")", ";", "if", "(", "$", "onlyuser", ")", "{", "$", "ratings", "=", "array_filter", "(", "$", "ratings", ",", "function", "(", "$", "rating", ")", "use", "(", "$", "userid", ")", "{", "return", "(", "$", "rating", "->", "userid", "==", "$", "userid", ")", ";", "}", ")", ";", "}", "if", "(", "empty", "(", "$", "ratings", ")", ")", "{", "return", ";", "}", "$", "toexport", "=", "array_map", "(", "function", "(", "$", "rating", ")", "{", "return", "(", "object", ")", "[", "'rating'", "=>", "$", "rating", "->", "rating", ",", "'author'", "=>", "$", "rating", "->", "userid", ",", "]", ";", "}", ",", "$", "ratings", ")", ";", "$", "writer", "=", "\\", "core_privacy", "\\", "local", "\\", "request", "\\", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_related_data", "(", "$", "subcontext", ",", "'rating'", ",", "$", "toexport", ")", ";", "}" ]
Export all ratings which match the specified component, areaid, and itemid. If requesting ratings for a users own content, and you wish to include all ratings of that content, specify $onlyuser as false. When requesting ratings for another users content, you should only export the ratings that the specified user made themselves. @param int $userid The user whose information is to be exported @param \context $context The context being stored. @param array $subcontext The subcontext within the context to export this information @param string $component The component to fetch data from @param string $ratingarea The ratingarea that the data was stored in within the component @param int $itemid The itemid within that ratingarea @param bool $onlyuser Whether to only export ratings that the current user has made, or all ratings
[ "Export", "all", "ratings", "which", "match", "the", "specified", "component", "areaid", "and", "itemid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/classes/privacy/provider.php#L89-L127
218,442
moodle/moodle
rating/classes/privacy/provider.php
provider.get_sql_join
public static function get_sql_join($alias, $component, $ratingarea, $itemidjoin, $userid, $innerjoin = false) { static $count = 0; $count++; $userwhere = ''; if ($innerjoin) { // Join the rating table with the specified alias and the relevant join params. $join = "JOIN {rating} {$alias} ON "; $join .= "{$alias}.itemid = {$itemidjoin}"; $userwhere .= "{$alias}.userid = :ratinguserid{$count} AND "; $userwhere .= "{$alias}.component = :ratingcomponent{$count} AND "; $userwhere .= "{$alias}.ratingarea = :ratingarea{$count}"; } else { // Join the rating table with the specified alias and the relevant join params. $join = "LEFT JOIN {rating} {$alias} ON "; $join .= "{$alias}.userid = :ratinguserid{$count} AND "; $join .= "{$alias}.component = :ratingcomponent{$count} AND "; $join .= "{$alias}.ratingarea = :ratingarea{$count} AND "; $join .= "{$alias}.itemid = {$itemidjoin}"; // Match against the specified user. $userwhere = "{$alias}.id IS NOT NULL"; } $params = [ 'ratingcomponent' . $count => $component, 'ratingarea' . $count => $ratingarea, 'ratinguserid' . $count => $userid, ]; $return = (object) [ 'join' => $join, 'params' => $params, 'userwhere' => $userwhere, ]; return $return; }
php
public static function get_sql_join($alias, $component, $ratingarea, $itemidjoin, $userid, $innerjoin = false) { static $count = 0; $count++; $userwhere = ''; if ($innerjoin) { // Join the rating table with the specified alias and the relevant join params. $join = "JOIN {rating} {$alias} ON "; $join .= "{$alias}.itemid = {$itemidjoin}"; $userwhere .= "{$alias}.userid = :ratinguserid{$count} AND "; $userwhere .= "{$alias}.component = :ratingcomponent{$count} AND "; $userwhere .= "{$alias}.ratingarea = :ratingarea{$count}"; } else { // Join the rating table with the specified alias and the relevant join params. $join = "LEFT JOIN {rating} {$alias} ON "; $join .= "{$alias}.userid = :ratinguserid{$count} AND "; $join .= "{$alias}.component = :ratingcomponent{$count} AND "; $join .= "{$alias}.ratingarea = :ratingarea{$count} AND "; $join .= "{$alias}.itemid = {$itemidjoin}"; // Match against the specified user. $userwhere = "{$alias}.id IS NOT NULL"; } $params = [ 'ratingcomponent' . $count => $component, 'ratingarea' . $count => $ratingarea, 'ratinguserid' . $count => $userid, ]; $return = (object) [ 'join' => $join, 'params' => $params, 'userwhere' => $userwhere, ]; return $return; }
[ "public", "static", "function", "get_sql_join", "(", "$", "alias", ",", "$", "component", ",", "$", "ratingarea", ",", "$", "itemidjoin", ",", "$", "userid", ",", "$", "innerjoin", "=", "false", ")", "{", "static", "$", "count", "=", "0", ";", "$", "count", "++", ";", "$", "userwhere", "=", "''", ";", "if", "(", "$", "innerjoin", ")", "{", "// Join the rating table with the specified alias and the relevant join params.", "$", "join", "=", "\"JOIN {rating} {$alias} ON \"", ";", "$", "join", ".=", "\"{$alias}.itemid = {$itemidjoin}\"", ";", "$", "userwhere", ".=", "\"{$alias}.userid = :ratinguserid{$count} AND \"", ";", "$", "userwhere", ".=", "\"{$alias}.component = :ratingcomponent{$count} AND \"", ";", "$", "userwhere", ".=", "\"{$alias}.ratingarea = :ratingarea{$count}\"", ";", "}", "else", "{", "// Join the rating table with the specified alias and the relevant join params.", "$", "join", "=", "\"LEFT JOIN {rating} {$alias} ON \"", ";", "$", "join", ".=", "\"{$alias}.userid = :ratinguserid{$count} AND \"", ";", "$", "join", ".=", "\"{$alias}.component = :ratingcomponent{$count} AND \"", ";", "$", "join", ".=", "\"{$alias}.ratingarea = :ratingarea{$count} AND \"", ";", "$", "join", ".=", "\"{$alias}.itemid = {$itemidjoin}\"", ";", "// Match against the specified user.", "$", "userwhere", "=", "\"{$alias}.id IS NOT NULL\"", ";", "}", "$", "params", "=", "[", "'ratingcomponent'", ".", "$", "count", "=>", "$", "component", ",", "'ratingarea'", ".", "$", "count", "=>", "$", "ratingarea", ",", "'ratinguserid'", ".", "$", "count", "=>", "$", "userid", ",", "]", ";", "$", "return", "=", "(", "object", ")", "[", "'join'", "=>", "$", "join", ",", "'params'", "=>", "$", "params", ",", "'userwhere'", "=>", "$", "userwhere", ",", "]", ";", "return", "$", "return", ";", "}" ]
Get the SQL required to find all submission items where this user has had any involvements. If possible an inner join should be used. @param string $alias The name of the table alias to use. @param string $component The na eof the component to fetch ratings for. @param string $ratingarea The rating area to fetch results for. @param string $itemidjoin The right-hand-side of the JOIN ON clause. @param int $userid The ID of the user being stored. @param bool $innerjoin Whether to use an inner join (preferred) @return \stdClass
[ "Get", "the", "SQL", "required", "to", "find", "all", "submission", "items", "where", "this", "user", "has", "had", "any", "involvements", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/classes/privacy/provider.php#L142-L180
218,443
moodle/moodle
rating/classes/privacy/provider.php
provider.delete_ratings
public static function delete_ratings(\context $context, string $component = null, string $ratingarea = null, int $itemid = null) { global $DB; $options = ['contextid' => $context->id]; if ($component) { $options['component'] = $component; } if ($ratingarea) { $options['ratingarea'] = $ratingarea; } if ($itemid) { $options['itemid'] = $itemid; } $DB->delete_records('rating', $options); }
php
public static function delete_ratings(\context $context, string $component = null, string $ratingarea = null, int $itemid = null) { global $DB; $options = ['contextid' => $context->id]; if ($component) { $options['component'] = $component; } if ($ratingarea) { $options['ratingarea'] = $ratingarea; } if ($itemid) { $options['itemid'] = $itemid; } $DB->delete_records('rating', $options); }
[ "public", "static", "function", "delete_ratings", "(", "\\", "context", "$", "context", ",", "string", "$", "component", "=", "null", ",", "string", "$", "ratingarea", "=", "null", ",", "int", "$", "itemid", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "options", "=", "[", "'contextid'", "=>", "$", "context", "->", "id", "]", ";", "if", "(", "$", "component", ")", "{", "$", "options", "[", "'component'", "]", "=", "$", "component", ";", "}", "if", "(", "$", "ratingarea", ")", "{", "$", "options", "[", "'ratingarea'", "]", "=", "$", "ratingarea", ";", "}", "if", "(", "$", "itemid", ")", "{", "$", "options", "[", "'itemid'", "]", "=", "$", "itemid", ";", "}", "$", "DB", "->", "delete_records", "(", "'rating'", ",", "$", "options", ")", ";", "}" ]
Deletes all ratings for a specified context, component, ratingarea and itemid. Only delete ratings when the item itself was deleted. We never delete ratings for one user but not others - this may affect grades, therefore ratings made by particular user are not considered personal information. @param \context $context Details about which context to delete ratings for. @param string $component Component to delete. @param string $ratingarea Rating area to delete. @param int $itemid The item ID for use with deletion.
[ "Deletes", "all", "ratings", "for", "a", "specified", "context", "component", "ratingarea", "and", "itemid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/classes/privacy/provider.php#L195-L211
218,444
moodle/moodle
lib/adodb/drivers/adodb-mssqlnative.inc.php
ADODB_mssqlnative.CreateSequence2012
function CreateSequence2012($seq='adodbseq',$start=1){ if (!$this->sequences){ $sql = "SELECT name FROM sys.sequences"; $this->sequences = $this->GetCol($sql); } $ok = $this->Execute("CREATE SEQUENCE $seq START WITH $start INCREMENT BY 1"); if (!$ok) die("CANNOT CREATE SEQUENCE" . print_r(sqlsrv_errors(),true)); $this->sequences[] = $seq; }
php
function CreateSequence2012($seq='adodbseq',$start=1){ if (!$this->sequences){ $sql = "SELECT name FROM sys.sequences"; $this->sequences = $this->GetCol($sql); } $ok = $this->Execute("CREATE SEQUENCE $seq START WITH $start INCREMENT BY 1"); if (!$ok) die("CANNOT CREATE SEQUENCE" . print_r(sqlsrv_errors(),true)); $this->sequences[] = $seq; }
[ "function", "CreateSequence2012", "(", "$", "seq", "=", "'adodbseq'", ",", "$", "start", "=", "1", ")", "{", "if", "(", "!", "$", "this", "->", "sequences", ")", "{", "$", "sql", "=", "\"SELECT name FROM sys.sequences\"", ";", "$", "this", "->", "sequences", "=", "$", "this", "->", "GetCol", "(", "$", "sql", ")", ";", "}", "$", "ok", "=", "$", "this", "->", "Execute", "(", "\"CREATE SEQUENCE $seq START WITH $start INCREMENT BY 1\"", ")", ";", "if", "(", "!", "$", "ok", ")", "die", "(", "\"CANNOT CREATE SEQUENCE\"", ".", "print_r", "(", "sqlsrv_errors", "(", ")", ",", "true", ")", ")", ";", "$", "this", "->", "sequences", "[", "]", "=", "$", "seq", ";", "}" ]
Proper Sequences Only available to Server 2012 and up
[ "Proper", "Sequences", "Only", "available", "to", "Server", "2012", "and", "up" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-mssqlnative.inc.php#L259-L268
218,445
moodle/moodle
lib/adodb/drivers/adodb-mssqlnative.inc.php
ADODB_mssqlnative.GenID2012
function GenID2012($seq='adodbseq',$start=1) { /* * First time in create an array of sequence names that we * can use in later requests to see if the sequence exists * the overhead is creating a list of sequences every time * we need access to at least 1. If we really care about * performance, we could maybe flag a 'nocheck' class variable */ if (!$this->sequences){ $sql = "SELECT name FROM sys.sequences"; $this->sequences = $this->GetCol($sql); } if (!is_array($this->sequences) || is_array($this->sequences) && !in_array($seq,$this->sequences)){ $this->CreateSequence2012($seq, $start); } $num = $this->GetOne("SELECT NEXT VALUE FOR $seq"); return $num; }
php
function GenID2012($seq='adodbseq',$start=1) { /* * First time in create an array of sequence names that we * can use in later requests to see if the sequence exists * the overhead is creating a list of sequences every time * we need access to at least 1. If we really care about * performance, we could maybe flag a 'nocheck' class variable */ if (!$this->sequences){ $sql = "SELECT name FROM sys.sequences"; $this->sequences = $this->GetCol($sql); } if (!is_array($this->sequences) || is_array($this->sequences) && !in_array($seq,$this->sequences)){ $this->CreateSequence2012($seq, $start); } $num = $this->GetOne("SELECT NEXT VALUE FOR $seq"); return $num; }
[ "function", "GenID2012", "(", "$", "seq", "=", "'adodbseq'", ",", "$", "start", "=", "1", ")", "{", "/*\n\t\t * First time in create an array of sequence names that we\n\t\t * can use in later requests to see if the sequence exists\n\t\t * the overhead is creating a list of sequences every time\n\t\t * we need access to at least 1. If we really care about\n\t\t * performance, we could maybe flag a 'nocheck' class variable\n\t\t */", "if", "(", "!", "$", "this", "->", "sequences", ")", "{", "$", "sql", "=", "\"SELECT name FROM sys.sequences\"", ";", "$", "this", "->", "sequences", "=", "$", "this", "->", "GetCol", "(", "$", "sql", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "this", "->", "sequences", ")", "||", "is_array", "(", "$", "this", "->", "sequences", ")", "&&", "!", "in_array", "(", "$", "seq", ",", "$", "this", "->", "sequences", ")", ")", "{", "$", "this", "->", "CreateSequence2012", "(", "$", "seq", ",", "$", "start", ")", ";", "}", "$", "num", "=", "$", "this", "->", "GetOne", "(", "\"SELECT NEXT VALUE FOR $seq\"", ")", ";", "return", "$", "num", ";", "}" ]
Only available to Server 2012 and up Cannot do this the normal adodb way by trapping an error if the sequence does not exist because sql server will auto create a sequence with the starting number of -9223372036854775808
[ "Only", "available", "to", "Server", "2012", "and", "up", "Cannot", "do", "this", "the", "normal", "adodb", "way", "by", "trapping", "an", "error", "if", "the", "sequence", "does", "not", "exist", "because", "sql", "server", "will", "auto", "create", "a", "sequence", "with", "the", "starting", "number", "of", "-", "9223372036854775808" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-mssqlnative.inc.php#L298-L319
218,446
moodle/moodle
lib/adodb/drivers/adodb-mssqlnative.inc.php
ADORecordset_mssqlnative.NextRecordSet
function NextRecordSet() { if (!sqlsrv_next_result($this->_queryID)) return false; $this->_inited = false; $this->bind = false; $this->_currentRow = -1; $this->Init(); return true; }
php
function NextRecordSet() { if (!sqlsrv_next_result($this->_queryID)) return false; $this->_inited = false; $this->bind = false; $this->_currentRow = -1; $this->Init(); return true; }
[ "function", "NextRecordSet", "(", ")", "{", "if", "(", "!", "sqlsrv_next_result", "(", "$", "this", "->", "_queryID", ")", ")", "return", "false", ";", "$", "this", "->", "_inited", "=", "false", ";", "$", "this", "->", "bind", "=", "false", ";", "$", "this", "->", "_currentRow", "=", "-", "1", ";", "$", "this", "->", "Init", "(", ")", ";", "return", "true", ";", "}" ]
get next resultset - requires PHP 4.0.5 or later
[ "get", "next", "resultset", "-", "requires", "PHP", "4", ".", "0", ".", "5", "or", "later" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-mssqlnative.inc.php#L881-L889
218,447
moodle/moodle
auth/db/auth.php
auth_plugin_db.db_init
function db_init() { if ($this->is_configured() === false) { throw new moodle_exception('auth_dbcantconnect', 'auth_db'); } // Connect to the external database (forcing new connection). $authdb = ADONewConnection($this->config->type); if (!empty($this->config->debugauthdb)) { $authdb->debug = true; ob_start(); //Start output buffer to allow later use of the page headers. } $authdb->Connect($this->config->host, $this->config->user, $this->config->pass, $this->config->name, true); $authdb->SetFetchMode(ADODB_FETCH_ASSOC); if (!empty($this->config->setupsql)) { $authdb->Execute($this->config->setupsql); } return $authdb; }
php
function db_init() { if ($this->is_configured() === false) { throw new moodle_exception('auth_dbcantconnect', 'auth_db'); } // Connect to the external database (forcing new connection). $authdb = ADONewConnection($this->config->type); if (!empty($this->config->debugauthdb)) { $authdb->debug = true; ob_start(); //Start output buffer to allow later use of the page headers. } $authdb->Connect($this->config->host, $this->config->user, $this->config->pass, $this->config->name, true); $authdb->SetFetchMode(ADODB_FETCH_ASSOC); if (!empty($this->config->setupsql)) { $authdb->Execute($this->config->setupsql); } return $authdb; }
[ "function", "db_init", "(", ")", "{", "if", "(", "$", "this", "->", "is_configured", "(", ")", "===", "false", ")", "{", "throw", "new", "moodle_exception", "(", "'auth_dbcantconnect'", ",", "'auth_db'", ")", ";", "}", "// Connect to the external database (forcing new connection).", "$", "authdb", "=", "ADONewConnection", "(", "$", "this", "->", "config", "->", "type", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "debugauthdb", ")", ")", "{", "$", "authdb", "->", "debug", "=", "true", ";", "ob_start", "(", ")", ";", "//Start output buffer to allow later use of the page headers.", "}", "$", "authdb", "->", "Connect", "(", "$", "this", "->", "config", "->", "host", ",", "$", "this", "->", "config", "->", "user", ",", "$", "this", "->", "config", "->", "pass", ",", "$", "this", "->", "config", "->", "name", ",", "true", ")", ";", "$", "authdb", "->", "SetFetchMode", "(", "ADODB_FETCH_ASSOC", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "setupsql", ")", ")", "{", "$", "authdb", "->", "Execute", "(", "$", "this", "->", "config", "->", "setupsql", ")", ";", "}", "return", "$", "authdb", ";", "}" ]
Connect to external database. @return ADOConnection @throws moodle_exception
[ "Connect", "to", "external", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/db/auth.php#L154-L172
218,448
moodle/moodle
auth/db/auth.php
auth_plugin_db.db_attributes
function db_attributes() { $moodleattributes = array(); // If we have custom fields then merge them with user fields. $customfields = $this->get_custom_user_profile_fields(); if (!empty($customfields) && !empty($this->userfields)) { $userfields = array_merge($this->userfields, $customfields); } else { $userfields = $this->userfields; } foreach ($userfields as $field) { if (!empty($this->config->{"field_map_$field"})) { $moodleattributes[$field] = $this->config->{"field_map_$field"}; } } $moodleattributes['username'] = $this->config->fielduser; return $moodleattributes; }
php
function db_attributes() { $moodleattributes = array(); // If we have custom fields then merge them with user fields. $customfields = $this->get_custom_user_profile_fields(); if (!empty($customfields) && !empty($this->userfields)) { $userfields = array_merge($this->userfields, $customfields); } else { $userfields = $this->userfields; } foreach ($userfields as $field) { if (!empty($this->config->{"field_map_$field"})) { $moodleattributes[$field] = $this->config->{"field_map_$field"}; } } $moodleattributes['username'] = $this->config->fielduser; return $moodleattributes; }
[ "function", "db_attributes", "(", ")", "{", "$", "moodleattributes", "=", "array", "(", ")", ";", "// If we have custom fields then merge them with user fields.", "$", "customfields", "=", "$", "this", "->", "get_custom_user_profile_fields", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "customfields", ")", "&&", "!", "empty", "(", "$", "this", "->", "userfields", ")", ")", "{", "$", "userfields", "=", "array_merge", "(", "$", "this", "->", "userfields", ",", "$", "customfields", ")", ";", "}", "else", "{", "$", "userfields", "=", "$", "this", "->", "userfields", ";", "}", "foreach", "(", "$", "userfields", "as", "$", "field", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "{", "\"field_map_$field\"", "}", ")", ")", "{", "$", "moodleattributes", "[", "$", "field", "]", "=", "$", "this", "->", "config", "->", "{", "\"field_map_$field\"", "}", ";", "}", "}", "$", "moodleattributes", "[", "'username'", "]", "=", "$", "this", "->", "config", "->", "fielduser", ";", "return", "$", "moodleattributes", ";", "}" ]
Returns user attribute mappings between moodle and the external database. @return array
[ "Returns", "user", "attribute", "mappings", "between", "moodle", "and", "the", "external", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/db/auth.php#L179-L196
218,449
moodle/moodle
auth/db/auth.php
auth_plugin_db.get_userinfo
function get_userinfo($username) { global $CFG; $extusername = core_text::convert($username, 'utf-8', $this->config->extencoding); $authdb = $this->db_init(); // Array to map local fieldnames we want, to external fieldnames. $selectfields = $this->db_attributes(); $result = array(); // If at least one field is mapped from external db, get that mapped data. if ($selectfields) { $select = array(); $fieldcount = 0; foreach ($selectfields as $localname=>$externalname) { // Without aliasing, multiple occurrences of the same external // name can coalesce in only occurrence in the result. $select[] = "$externalname AS F".$fieldcount; $fieldcount++; } $select = implode(', ', $select); $sql = "SELECT $select FROM {$this->config->table} WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'"; if ($rs = $authdb->Execute($sql)) { if (!$rs->EOF) { $fields = $rs->FetchRow(); // Convert the associative array to an array of its values so we don't have to worry about the case of its keys. $fields = array_values($fields); foreach (array_keys($selectfields) as $index => $localname) { $value = $fields[$index]; $result[$localname] = core_text::convert($value, $this->config->extencoding, 'utf-8'); } } $rs->Close(); } } $authdb->Close(); return $result; }
php
function get_userinfo($username) { global $CFG; $extusername = core_text::convert($username, 'utf-8', $this->config->extencoding); $authdb = $this->db_init(); // Array to map local fieldnames we want, to external fieldnames. $selectfields = $this->db_attributes(); $result = array(); // If at least one field is mapped from external db, get that mapped data. if ($selectfields) { $select = array(); $fieldcount = 0; foreach ($selectfields as $localname=>$externalname) { // Without aliasing, multiple occurrences of the same external // name can coalesce in only occurrence in the result. $select[] = "$externalname AS F".$fieldcount; $fieldcount++; } $select = implode(', ', $select); $sql = "SELECT $select FROM {$this->config->table} WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'"; if ($rs = $authdb->Execute($sql)) { if (!$rs->EOF) { $fields = $rs->FetchRow(); // Convert the associative array to an array of its values so we don't have to worry about the case of its keys. $fields = array_values($fields); foreach (array_keys($selectfields) as $index => $localname) { $value = $fields[$index]; $result[$localname] = core_text::convert($value, $this->config->extencoding, 'utf-8'); } } $rs->Close(); } } $authdb->Close(); return $result; }
[ "function", "get_userinfo", "(", "$", "username", ")", "{", "global", "$", "CFG", ";", "$", "extusername", "=", "core_text", "::", "convert", "(", "$", "username", ",", "'utf-8'", ",", "$", "this", "->", "config", "->", "extencoding", ")", ";", "$", "authdb", "=", "$", "this", "->", "db_init", "(", ")", ";", "// Array to map local fieldnames we want, to external fieldnames.", "$", "selectfields", "=", "$", "this", "->", "db_attributes", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "// If at least one field is mapped from external db, get that mapped data.", "if", "(", "$", "selectfields", ")", "{", "$", "select", "=", "array", "(", ")", ";", "$", "fieldcount", "=", "0", ";", "foreach", "(", "$", "selectfields", "as", "$", "localname", "=>", "$", "externalname", ")", "{", "// Without aliasing, multiple occurrences of the same external", "// name can coalesce in only occurrence in the result.", "$", "select", "[", "]", "=", "\"$externalname AS F\"", ".", "$", "fieldcount", ";", "$", "fieldcount", "++", ";", "}", "$", "select", "=", "implode", "(", "', '", ",", "$", "select", ")", ";", "$", "sql", "=", "\"SELECT $select\n FROM {$this->config->table}\n WHERE {$this->config->fielduser} = '\"", ".", "$", "this", "->", "ext_addslashes", "(", "$", "extusername", ")", ".", "\"'\"", ";", "if", "(", "$", "rs", "=", "$", "authdb", "->", "Execute", "(", "$", "sql", ")", ")", "{", "if", "(", "!", "$", "rs", "->", "EOF", ")", "{", "$", "fields", "=", "$", "rs", "->", "FetchRow", "(", ")", ";", "// Convert the associative array to an array of its values so we don't have to worry about the case of its keys.", "$", "fields", "=", "array_values", "(", "$", "fields", ")", ";", "foreach", "(", "array_keys", "(", "$", "selectfields", ")", "as", "$", "index", "=>", "$", "localname", ")", "{", "$", "value", "=", "$", "fields", "[", "$", "index", "]", ";", "$", "result", "[", "$", "localname", "]", "=", "core_text", "::", "convert", "(", "$", "value", ",", "$", "this", "->", "config", "->", "extencoding", ",", "'utf-8'", ")", ";", "}", "}", "$", "rs", "->", "Close", "(", ")", ";", "}", "}", "$", "authdb", "->", "Close", "(", ")", ";", "return", "$", "result", ";", "}" ]
Reads any other information for a user from external database, then returns it in an array. @param string $username @return array
[ "Reads", "any", "other", "information", "for", "a", "user", "from", "external", "database", "then", "returns", "it", "in", "an", "array", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/db/auth.php#L205-L246
218,450
moodle/moodle
auth/db/auth.php
auth_plugin_db.user_update_password
function user_update_password($user, $newpassword) { global $DB; if ($this->is_internal()) { $puser = $DB->get_record('user', array('id'=>$user->id), '*', MUST_EXIST); // This will also update the stored hash to the latest algorithm // if the existing hash is using an out-of-date algorithm (or the // legacy md5 algorithm). if (update_internal_user_password($puser, $newpassword)) { $user->password = $puser->password; return true; } else { return false; } } else { // We should have never been called! return false; } }
php
function user_update_password($user, $newpassword) { global $DB; if ($this->is_internal()) { $puser = $DB->get_record('user', array('id'=>$user->id), '*', MUST_EXIST); // This will also update the stored hash to the latest algorithm // if the existing hash is using an out-of-date algorithm (or the // legacy md5 algorithm). if (update_internal_user_password($puser, $newpassword)) { $user->password = $puser->password; return true; } else { return false; } } else { // We should have never been called! return false; } }
[ "function", "user_update_password", "(", "$", "user", ",", "$", "newpassword", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "is_internal", "(", ")", ")", "{", "$", "puser", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "user", "->", "id", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "// This will also update the stored hash to the latest algorithm", "// if the existing hash is using an out-of-date algorithm (or the", "// legacy md5 algorithm).", "if", "(", "update_internal_user_password", "(", "$", "puser", ",", "$", "newpassword", ")", ")", "{", "$", "user", "->", "password", "=", "$", "puser", "->", "password", ";", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "// We should have never been called!", "return", "false", ";", "}", "}" ]
Change a user's password. @param stdClass $user User table object @param string $newpassword Plaintext password @return bool True on success
[ "Change", "a", "user", "s", "password", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/db/auth.php#L255-L273
218,451
moodle/moodle
auth/db/auth.php
auth_plugin_db.get_userinfo_asobj
function get_userinfo_asobj($username) { $user_array = truncate_userinfo($this->get_userinfo($username)); $user = new stdClass(); foreach($user_array as $key=>$value) { $user->{$key} = $value; } return $user; }
php
function get_userinfo_asobj($username) { $user_array = truncate_userinfo($this->get_userinfo($username)); $user = new stdClass(); foreach($user_array as $key=>$value) { $user->{$key} = $value; } return $user; }
[ "function", "get_userinfo_asobj", "(", "$", "username", ")", "{", "$", "user_array", "=", "truncate_userinfo", "(", "$", "this", "->", "get_userinfo", "(", "$", "username", ")", ")", ";", "$", "user", "=", "new", "stdClass", "(", ")", ";", "foreach", "(", "$", "user_array", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "user", "->", "{", "$", "key", "}", "=", "$", "value", ";", "}", "return", "$", "user", ";", "}" ]
Reads user information from DB and return it in an object. @param string $username username @return array
[ "Reads", "user", "information", "from", "DB", "and", "return", "it", "in", "an", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/db/auth.php#L546-L553
218,452
moodle/moodle
auth/db/auth.php
auth_plugin_db.change_password_url
function change_password_url() { if ($this->is_internal() || empty($this->config->changepasswordurl)) { // Standard form. return null; } else { // Use admin defined custom url. return new moodle_url($this->config->changepasswordurl); } }
php
function change_password_url() { if ($this->is_internal() || empty($this->config->changepasswordurl)) { // Standard form. return null; } else { // Use admin defined custom url. return new moodle_url($this->config->changepasswordurl); } }
[ "function", "change_password_url", "(", ")", "{", "if", "(", "$", "this", "->", "is_internal", "(", ")", "||", "empty", "(", "$", "this", "->", "config", "->", "changepasswordurl", ")", ")", "{", "// Standard form.", "return", "null", ";", "}", "else", "{", "// Use admin defined custom url.", "return", "new", "moodle_url", "(", "$", "this", "->", "config", "->", "changepasswordurl", ")", ";", "}", "}" ]
Returns the URL for changing the user's pw, or empty if the default can be used. @return moodle_url
[ "Returns", "the", "URL", "for", "changing", "the", "user", "s", "pw", "or", "empty", "if", "the", "default", "can", "be", "used", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/db/auth.php#L671-L679
218,453
moodle/moodle
auth/db/auth.php
auth_plugin_db.ext_addslashes
function ext_addslashes($text) { if (empty($this->config->sybasequoting)) { $text = str_replace('\\', '\\\\', $text); $text = str_replace(array('\'', '"', "\0"), array('\\\'', '\\"', '\\0'), $text); } else { $text = str_replace("'", "''", $text); } return $text; }
php
function ext_addslashes($text) { if (empty($this->config->sybasequoting)) { $text = str_replace('\\', '\\\\', $text); $text = str_replace(array('\'', '"', "\0"), array('\\\'', '\\"', '\\0'), $text); } else { $text = str_replace("'", "''", $text); } return $text; }
[ "function", "ext_addslashes", "(", "$", "text", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "config", "->", "sybasequoting", ")", ")", "{", "$", "text", "=", "str_replace", "(", "'\\\\'", ",", "'\\\\\\\\'", ",", "$", "text", ")", ";", "$", "text", "=", "str_replace", "(", "array", "(", "'\\''", ",", "'\"'", ",", "\"\\0\"", ")", ",", "array", "(", "'\\\\\\''", ",", "'\\\\\"'", ",", "'\\\\0'", ")", ",", "$", "text", ")", ";", "}", "else", "{", "$", "text", "=", "str_replace", "(", "\"'\"", ",", "\"''\"", ",", "$", "text", ")", ";", "}", "return", "$", "text", ";", "}" ]
Add slashes, we can not use placeholders or system functions. @param string $text @return string
[ "Add", "slashes", "we", "can", "not", "use", "placeholders", "or", "system", "functions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/db/auth.php#L696-L704
218,454
moodle/moodle
lib/upgradelib.php
core_upgrade_time.record_savepoint
public static function record_savepoint($version) { global $CFG, $OUTPUT; // In developer debug mode we show a notification after each individual save point. if ($CFG->debugdeveloper && self::$isrecording) { $time = microtime(true); $notification = new \core\output\notification($version . ': ' . get_string('successduration', '', format_float($time - self::$lastsavepoint, 2)), \core\output\notification::NOTIFY_SUCCESS); $notification->set_show_closebutton(false); echo $OUTPUT->render($notification); self::$lastsavepoint = $time; } }
php
public static function record_savepoint($version) { global $CFG, $OUTPUT; // In developer debug mode we show a notification after each individual save point. if ($CFG->debugdeveloper && self::$isrecording) { $time = microtime(true); $notification = new \core\output\notification($version . ': ' . get_string('successduration', '', format_float($time - self::$lastsavepoint, 2)), \core\output\notification::NOTIFY_SUCCESS); $notification->set_show_closebutton(false); echo $OUTPUT->render($notification); self::$lastsavepoint = $time; } }
[ "public", "static", "function", "record_savepoint", "(", "$", "version", ")", "{", "global", "$", "CFG", ",", "$", "OUTPUT", ";", "// In developer debug mode we show a notification after each individual save point.", "if", "(", "$", "CFG", "->", "debugdeveloper", "&&", "self", "::", "$", "isrecording", ")", "{", "$", "time", "=", "microtime", "(", "true", ")", ";", "$", "notification", "=", "new", "\\", "core", "\\", "output", "\\", "notification", "(", "$", "version", ".", "': '", ".", "get_string", "(", "'successduration'", ",", "''", ",", "format_float", "(", "$", "time", "-", "self", "::", "$", "lastsavepoint", ",", "2", ")", ")", ",", "\\", "core", "\\", "output", "\\", "notification", "::", "NOTIFY_SUCCESS", ")", ";", "$", "notification", "->", "set_show_closebutton", "(", "false", ")", ";", "echo", "$", "OUTPUT", "->", "render", "(", "$", "notification", ")", ";", "self", "::", "$", "lastsavepoint", "=", "$", "time", ";", "}", "}" ]
Records current time at the end of a given numbered step. @param float $version Version number (may have decimals, or not)
[ "Records", "current", "time", "at", "the", "end", "of", "a", "given", "numbered", "step", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/upgradelib.php#L165-L179
218,455
moodle/moodle
lib/markdown/Markdown.php
Markdown.setup
protected function setup() { // Clear global hashes. $this->urls = $this->predef_urls; $this->titles = $this->predef_titles; $this->html_hashes = array(); $this->in_anchor = false; }
php
protected function setup() { // Clear global hashes. $this->urls = $this->predef_urls; $this->titles = $this->predef_titles; $this->html_hashes = array(); $this->in_anchor = false; }
[ "protected", "function", "setup", "(", ")", "{", "// Clear global hashes.", "$", "this", "->", "urls", "=", "$", "this", "->", "predef_urls", ";", "$", "this", "->", "titles", "=", "$", "this", "->", "predef_titles", ";", "$", "this", "->", "html_hashes", "=", "array", "(", ")", ";", "$", "this", "->", "in_anchor", "=", "false", ";", "}" ]
Called before the transformation process starts to setup parser states. @return void
[ "Called", "before", "the", "transformation", "process", "starts", "to", "setup", "parser", "states", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/markdown/Markdown.php#L194-L200
218,456
moodle/moodle
lib/markdown/Markdown.php
Markdown.runSpanGamut
protected function runSpanGamut($text) { foreach ($this->span_gamut as $method => $priority) { $text = $this->$method($text); } return $text; }
php
protected function runSpanGamut($text) { foreach ($this->span_gamut as $method => $priority) { $text = $this->$method($text); } return $text; }
[ "protected", "function", "runSpanGamut", "(", "$", "text", ")", "{", "foreach", "(", "$", "this", "->", "span_gamut", "as", "$", "method", "=>", "$", "priority", ")", "{", "$", "text", "=", "$", "this", "->", "$", "method", "(", "$", "text", ")", ";", "}", "return", "$", "text", ";", "}" ]
Run span gamut transformations @param string $text @return string
[ "Run", "span", "gamut", "transformations" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/markdown/Markdown.php#L617-L623
218,457
moodle/moodle
lib/markdown/Markdown.php
Markdown.doHardBreaks
protected function doHardBreaks($text) { if ($this->hard_wrap) { return preg_replace_callback('/ *\n/', array($this, '_doHardBreaks_callback'), $text); } else { return preg_replace_callback('/ {2,}\n/', array($this, '_doHardBreaks_callback'), $text); } }
php
protected function doHardBreaks($text) { if ($this->hard_wrap) { return preg_replace_callback('/ *\n/', array($this, '_doHardBreaks_callback'), $text); } else { return preg_replace_callback('/ {2,}\n/', array($this, '_doHardBreaks_callback'), $text); } }
[ "protected", "function", "doHardBreaks", "(", "$", "text", ")", "{", "if", "(", "$", "this", "->", "hard_wrap", ")", "{", "return", "preg_replace_callback", "(", "'/ *\\n/'", ",", "array", "(", "$", "this", ",", "'_doHardBreaks_callback'", ")", ",", "$", "text", ")", ";", "}", "else", "{", "return", "preg_replace_callback", "(", "'/ {2,}\\n/'", ",", "array", "(", "$", "this", ",", "'_doHardBreaks_callback'", ")", ",", "$", "text", ")", ";", "}", "}" ]
Do hard breaks @param string $text @return string
[ "Do", "hard", "breaks" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/markdown/Markdown.php#L630-L638
218,458
moodle/moodle
lib/markdown/Markdown.php
Markdown._generateIdFromHeaderValue
protected function _generateIdFromHeaderValue($headerValue) { if (!is_callable($this->header_id_func)) { return ""; } $idValue = call_user_func($this->header_id_func, $headerValue); if (!$idValue) { return ""; } return ' id="' . $this->encodeAttribute($idValue) . '"'; }
php
protected function _generateIdFromHeaderValue($headerValue) { if (!is_callable($this->header_id_func)) { return ""; } $idValue = call_user_func($this->header_id_func, $headerValue); if (!$idValue) { return ""; } return ' id="' . $this->encodeAttribute($idValue) . '"'; }
[ "protected", "function", "_generateIdFromHeaderValue", "(", "$", "headerValue", ")", "{", "if", "(", "!", "is_callable", "(", "$", "this", "->", "header_id_func", ")", ")", "{", "return", "\"\"", ";", "}", "$", "idValue", "=", "call_user_func", "(", "$", "this", "->", "header_id_func", ",", "$", "headerValue", ")", ";", "if", "(", "!", "$", "idValue", ")", "{", "return", "\"\"", ";", "}", "return", "' id=\"'", ".", "$", "this", "->", "encodeAttribute", "(", "$", "idValue", ")", ".", "'\"'", ";", "}" ]
If a header_id_func property is set, we can use it to automatically generate an id attribute. This method returns a string in the form id="foo", or an empty string otherwise. @param string $headerValue @return string
[ "If", "a", "header_id_func", "property", "is", "set", "we", "can", "use", "it", "to", "automatically", "generate", "an", "id", "attribute", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/markdown/Markdown.php#L980-L991
218,459
moodle/moodle
lib/markdown/Markdown.php
Markdown._doLists_callback
protected function _doLists_callback($matches) { // Re-usable patterns to match list item bullets and number markers: $marker_ul_re = '[*+-]'; $marker_ol_re = '\d+[\.]'; $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; $marker_ol_start_re = '[0-9]+'; $list = $matches[1]; $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); $list .= "\n"; $result = $this->processListItems($list, $marker_any_re); $ol_start = 1; if ($this->enhanced_ordered_list) { // Get the start number for ordered list. if ($list_type == 'ol') { $ol_start_array = array(); $ol_start_check = preg_match("/$marker_ol_start_re/", $matches[4], $ol_start_array); if ($ol_start_check){ $ol_start = $ol_start_array[0]; } } } if ($ol_start > 1 && $list_type == 'ol'){ $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n" . $result . "</$list_type>"); } else { $result = $this->hashBlock("<$list_type>\n" . $result . "</$list_type>"); } return "\n". $result ."\n\n"; }
php
protected function _doLists_callback($matches) { // Re-usable patterns to match list item bullets and number markers: $marker_ul_re = '[*+-]'; $marker_ol_re = '\d+[\.]'; $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; $marker_ol_start_re = '[0-9]+'; $list = $matches[1]; $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); $list .= "\n"; $result = $this->processListItems($list, $marker_any_re); $ol_start = 1; if ($this->enhanced_ordered_list) { // Get the start number for ordered list. if ($list_type == 'ol') { $ol_start_array = array(); $ol_start_check = preg_match("/$marker_ol_start_re/", $matches[4], $ol_start_array); if ($ol_start_check){ $ol_start = $ol_start_array[0]; } } } if ($ol_start > 1 && $list_type == 'ol'){ $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n" . $result . "</$list_type>"); } else { $result = $this->hashBlock("<$list_type>\n" . $result . "</$list_type>"); } return "\n". $result ."\n\n"; }
[ "protected", "function", "_doLists_callback", "(", "$", "matches", ")", "{", "// Re-usable patterns to match list item bullets and number markers:", "$", "marker_ul_re", "=", "'[*+-]'", ";", "$", "marker_ol_re", "=", "'\\d+[\\.]'", ";", "$", "marker_any_re", "=", "\"(?:$marker_ul_re|$marker_ol_re)\"", ";", "$", "marker_ol_start_re", "=", "'[0-9]+'", ";", "$", "list", "=", "$", "matches", "[", "1", "]", ";", "$", "list_type", "=", "preg_match", "(", "\"/$marker_ul_re/\"", ",", "$", "matches", "[", "4", "]", ")", "?", "\"ul\"", ":", "\"ol\"", ";", "$", "marker_any_re", "=", "(", "$", "list_type", "==", "\"ul\"", "?", "$", "marker_ul_re", ":", "$", "marker_ol_re", ")", ";", "$", "list", ".=", "\"\\n\"", ";", "$", "result", "=", "$", "this", "->", "processListItems", "(", "$", "list", ",", "$", "marker_any_re", ")", ";", "$", "ol_start", "=", "1", ";", "if", "(", "$", "this", "->", "enhanced_ordered_list", ")", "{", "// Get the start number for ordered list.", "if", "(", "$", "list_type", "==", "'ol'", ")", "{", "$", "ol_start_array", "=", "array", "(", ")", ";", "$", "ol_start_check", "=", "preg_match", "(", "\"/$marker_ol_start_re/\"", ",", "$", "matches", "[", "4", "]", ",", "$", "ol_start_array", ")", ";", "if", "(", "$", "ol_start_check", ")", "{", "$", "ol_start", "=", "$", "ol_start_array", "[", "0", "]", ";", "}", "}", "}", "if", "(", "$", "ol_start", ">", "1", "&&", "$", "list_type", "==", "'ol'", ")", "{", "$", "result", "=", "$", "this", "->", "hashBlock", "(", "\"<$list_type start=\\\"$ol_start\\\">\\n\"", ".", "$", "result", ".", "\"</$list_type>\"", ")", ";", "}", "else", "{", "$", "result", "=", "$", "this", "->", "hashBlock", "(", "\"<$list_type>\\n\"", ".", "$", "result", ".", "\"</$list_type>\"", ")", ";", "}", "return", "\"\\n\"", ".", "$", "result", ".", "\"\\n\\n\"", ";", "}" ]
List parsing callback @param array $matches @return string
[ "List", "parsing", "callback" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/markdown/Markdown.php#L1065-L1098
218,460
moodle/moodle
lib/markdown/Markdown.php
Markdown._processListItems_callback
protected function _processListItems_callback($matches) { $item = $matches[4]; $leading_line =& $matches[1]; $leading_space =& $matches[2]; $marker_space = $matches[3]; $tailing_blank_line =& $matches[5]; if ($leading_line || $tailing_blank_line || preg_match('/\n{2,}/', $item)) { // Replace marker with the appropriate whitespace indentation $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item; $item = $this->runBlockGamut($this->outdent($item)."\n"); } else { // Recursion for sub-lists: $item = $this->doLists($this->outdent($item)); $item = $this->formParagraphs($item, false); } return "<li>" . $item . "</li>\n"; }
php
protected function _processListItems_callback($matches) { $item = $matches[4]; $leading_line =& $matches[1]; $leading_space =& $matches[2]; $marker_space = $matches[3]; $tailing_blank_line =& $matches[5]; if ($leading_line || $tailing_blank_line || preg_match('/\n{2,}/', $item)) { // Replace marker with the appropriate whitespace indentation $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item; $item = $this->runBlockGamut($this->outdent($item)."\n"); } else { // Recursion for sub-lists: $item = $this->doLists($this->outdent($item)); $item = $this->formParagraphs($item, false); } return "<li>" . $item . "</li>\n"; }
[ "protected", "function", "_processListItems_callback", "(", "$", "matches", ")", "{", "$", "item", "=", "$", "matches", "[", "4", "]", ";", "$", "leading_line", "=", "&", "$", "matches", "[", "1", "]", ";", "$", "leading_space", "=", "&", "$", "matches", "[", "2", "]", ";", "$", "marker_space", "=", "$", "matches", "[", "3", "]", ";", "$", "tailing_blank_line", "=", "&", "$", "matches", "[", "5", "]", ";", "if", "(", "$", "leading_line", "||", "$", "tailing_blank_line", "||", "preg_match", "(", "'/\\n{2,}/'", ",", "$", "item", ")", ")", "{", "// Replace marker with the appropriate whitespace indentation", "$", "item", "=", "$", "leading_space", ".", "str_repeat", "(", "' '", ",", "strlen", "(", "$", "marker_space", ")", ")", ".", "$", "item", ";", "$", "item", "=", "$", "this", "->", "runBlockGamut", "(", "$", "this", "->", "outdent", "(", "$", "item", ")", ".", "\"\\n\"", ")", ";", "}", "else", "{", "// Recursion for sub-lists:", "$", "item", "=", "$", "this", "->", "doLists", "(", "$", "this", "->", "outdent", "(", "$", "item", ")", ")", ";", "$", "item", "=", "$", "this", "->", "formParagraphs", "(", "$", "item", ",", "false", ")", ";", "}", "return", "\"<li>\"", ".", "$", "item", ".", "\"</li>\\n\"", ";", "}" ]
List item parsing callback @param array $matches @return string
[ "List", "item", "parsing", "callback" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/markdown/Markdown.php#L1162-L1182
218,461
moodle/moodle
lib/markdown/Markdown.php
Markdown._doCodeBlocks_callback
protected function _doCodeBlocks_callback($matches) { $codeblock = $matches[1]; $codeblock = $this->outdent($codeblock); if ($this->code_block_content_func) { $codeblock = call_user_func($this->code_block_content_func, $codeblock, ""); } else { $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); } # trim leading newlines and trailing newlines $codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock); $codeblock = "<pre><code>$codeblock\n</code></pre>"; return "\n\n" . $this->hashBlock($codeblock) . "\n\n"; }
php
protected function _doCodeBlocks_callback($matches) { $codeblock = $matches[1]; $codeblock = $this->outdent($codeblock); if ($this->code_block_content_func) { $codeblock = call_user_func($this->code_block_content_func, $codeblock, ""); } else { $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); } # trim leading newlines and trailing newlines $codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock); $codeblock = "<pre><code>$codeblock\n</code></pre>"; return "\n\n" . $this->hashBlock($codeblock) . "\n\n"; }
[ "protected", "function", "_doCodeBlocks_callback", "(", "$", "matches", ")", "{", "$", "codeblock", "=", "$", "matches", "[", "1", "]", ";", "$", "codeblock", "=", "$", "this", "->", "outdent", "(", "$", "codeblock", ")", ";", "if", "(", "$", "this", "->", "code_block_content_func", ")", "{", "$", "codeblock", "=", "call_user_func", "(", "$", "this", "->", "code_block_content_func", ",", "$", "codeblock", ",", "\"\"", ")", ";", "}", "else", "{", "$", "codeblock", "=", "htmlspecialchars", "(", "$", "codeblock", ",", "ENT_NOQUOTES", ")", ";", "}", "# trim leading newlines and trailing newlines", "$", "codeblock", "=", "preg_replace", "(", "'/\\A\\n+|\\n+\\z/'", ",", "''", ",", "$", "codeblock", ")", ";", "$", "codeblock", "=", "\"<pre><code>$codeblock\\n</code></pre>\"", ";", "return", "\"\\n\\n\"", ".", "$", "this", "->", "hashBlock", "(", "$", "codeblock", ")", ".", "\"\\n\\n\"", ";", "}" ]
Code block parsing callback @param array $matches @return string
[ "Code", "block", "parsing", "callback" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/markdown/Markdown.php#L1210-L1225
218,462
moodle/moodle
lib/markdown/Markdown.php
Markdown._doAutoLinks_url_callback
protected function _doAutoLinks_url_callback($matches) { $url = $this->encodeURLAttribute($matches[1], $text); $link = "<a href=\"$url\">$text</a>"; return $this->hashPart($link); }
php
protected function _doAutoLinks_url_callback($matches) { $url = $this->encodeURLAttribute($matches[1], $text); $link = "<a href=\"$url\">$text</a>"; return $this->hashPart($link); }
[ "protected", "function", "_doAutoLinks_url_callback", "(", "$", "matches", ")", "{", "$", "url", "=", "$", "this", "->", "encodeURLAttribute", "(", "$", "matches", "[", "1", "]", ",", "$", "text", ")", ";", "$", "link", "=", "\"<a href=\\\"$url\\\">$text</a>\"", ";", "return", "$", "this", "->", "hashPart", "(", "$", "link", ")", ";", "}" ]
Parse URL callback @param array $matches @return string
[ "Parse", "URL", "callback" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/markdown/Markdown.php#L1646-L1650
218,463
moodle/moodle
lib/markdown/Markdown.php
Markdown._doAutoLinks_email_callback
protected function _doAutoLinks_email_callback($matches) { $addr = $matches[1]; $url = $this->encodeURLAttribute("mailto:$addr", $text); $link = "<a href=\"$url\">$text</a>"; return $this->hashPart($link); }
php
protected function _doAutoLinks_email_callback($matches) { $addr = $matches[1]; $url = $this->encodeURLAttribute("mailto:$addr", $text); $link = "<a href=\"$url\">$text</a>"; return $this->hashPart($link); }
[ "protected", "function", "_doAutoLinks_email_callback", "(", "$", "matches", ")", "{", "$", "addr", "=", "$", "matches", "[", "1", "]", ";", "$", "url", "=", "$", "this", "->", "encodeURLAttribute", "(", "\"mailto:$addr\"", ",", "$", "text", ")", ";", "$", "link", "=", "\"<a href=\\\"$url\\\">$text</a>\"", ";", "return", "$", "this", "->", "hashPart", "(", "$", "link", ")", ";", "}" ]
Parse email address callback @param array $matches @return string
[ "Parse", "email", "address", "callback" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/markdown/Markdown.php#L1657-L1662
218,464
moodle/moodle
filter/tex/latex.php
latex.construct_latex_document
function construct_latex_document( $formula, $fontsize=12 ) { global $CFG; $formula = filter_tex_sanitize_formula($formula); // $fontsize don't affects to formula's size. $density can change size $doc = "\\documentclass[{$fontsize}pt]{article}\n"; $doc .= get_config('filter_tex', 'latexpreamble'); $doc .= "\\pagestyle{empty}\n"; $doc .= "\\begin{document}\n"; //dlnsk $doc .= "$ {$formula} $\n"; if (preg_match("/^[[:space:]]*\\\\begin\\{(gather|align|alignat|multline).?\\}/i",$formula)) { $doc .= "$formula\n"; } else { $doc .= "$ {$formula} $\n"; } $doc .= "\\end{document}\n"; return $doc; }
php
function construct_latex_document( $formula, $fontsize=12 ) { global $CFG; $formula = filter_tex_sanitize_formula($formula); // $fontsize don't affects to formula's size. $density can change size $doc = "\\documentclass[{$fontsize}pt]{article}\n"; $doc .= get_config('filter_tex', 'latexpreamble'); $doc .= "\\pagestyle{empty}\n"; $doc .= "\\begin{document}\n"; //dlnsk $doc .= "$ {$formula} $\n"; if (preg_match("/^[[:space:]]*\\\\begin\\{(gather|align|alignat|multline).?\\}/i",$formula)) { $doc .= "$formula\n"; } else { $doc .= "$ {$formula} $\n"; } $doc .= "\\end{document}\n"; return $doc; }
[ "function", "construct_latex_document", "(", "$", "formula", ",", "$", "fontsize", "=", "12", ")", "{", "global", "$", "CFG", ";", "$", "formula", "=", "filter_tex_sanitize_formula", "(", "$", "formula", ")", ";", "// $fontsize don't affects to formula's size. $density can change size", "$", "doc", "=", "\"\\\\documentclass[{$fontsize}pt]{article}\\n\"", ";", "$", "doc", ".=", "get_config", "(", "'filter_tex'", ",", "'latexpreamble'", ")", ";", "$", "doc", ".=", "\"\\\\pagestyle{empty}\\n\"", ";", "$", "doc", ".=", "\"\\\\begin{document}\\n\"", ";", "//dlnsk $doc .= \"$ {$formula} $\\n\";", "if", "(", "preg_match", "(", "\"/^[[:space:]]*\\\\\\\\begin\\\\{(gather|align|alignat|multline).?\\\\}/i\"", ",", "$", "formula", ")", ")", "{", "$", "doc", ".=", "\"$formula\\n\"", ";", "}", "else", "{", "$", "doc", ".=", "\"$ {$formula} $\\n\"", ";", "}", "$", "doc", ".=", "\"\\\\end{document}\\n\"", ";", "return", "$", "doc", ";", "}" ]
Turn the bit of TeX into a valid latex document @param string $forumula the TeX formula @param int $fontsize the font size @return string the latex document
[ "Turn", "the", "bit", "of", "TeX", "into", "a", "valid", "latex", "document" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/filter/tex/latex.php#L50-L68
218,465
moodle/moodle
filter/tex/latex.php
latex.execute
function execute( $command, $log=null ) { $output = array(); exec( $command, $output, $return_code ); if ($log) { fwrite( $log, "COMMAND: $command \n" ); $outputs = implode( "\n", $output ); fwrite( $log, "OUTPUT: $outputs \n" ); fwrite( $log, "RETURN_CODE: $return_code\n " ); } return $return_code; }
php
function execute( $command, $log=null ) { $output = array(); exec( $command, $output, $return_code ); if ($log) { fwrite( $log, "COMMAND: $command \n" ); $outputs = implode( "\n", $output ); fwrite( $log, "OUTPUT: $outputs \n" ); fwrite( $log, "RETURN_CODE: $return_code\n " ); } return $return_code; }
[ "function", "execute", "(", "$", "command", ",", "$", "log", "=", "null", ")", "{", "$", "output", "=", "array", "(", ")", ";", "exec", "(", "$", "command", ",", "$", "output", ",", "$", "return_code", ")", ";", "if", "(", "$", "log", ")", "{", "fwrite", "(", "$", "log", ",", "\"COMMAND: $command \\n\"", ")", ";", "$", "outputs", "=", "implode", "(", "\"\\n\"", ",", "$", "output", ")", ";", "fwrite", "(", "$", "log", ",", "\"OUTPUT: $outputs \\n\"", ")", ";", "fwrite", "(", "$", "log", ",", "\"RETURN_CODE: $return_code\\n \"", ")", ";", "}", "return", "$", "return_code", ";", "}" ]
execute an external command, with optional logging @param string $command command to execute @param file $log valid open file handle - log info will be written to this file @return return code from execution of command
[ "execute", "an", "external", "command", "with", "optional", "logging" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/filter/tex/latex.php#L76-L86
218,466
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client._getServerBaseURL
private function _getServerBaseURL() { // the URL is build only when needed if ( empty($this->_server['base_url']) ) { $this->_server['base_url'] = 'https://' . $this->_getServerHostname(); if ($this->_getServerPort()!=443) { $this->_server['base_url'] .= ':' .$this->_getServerPort(); } $this->_server['base_url'] .= $this->_getServerURI(); } return $this->_server['base_url']; }
php
private function _getServerBaseURL() { // the URL is build only when needed if ( empty($this->_server['base_url']) ) { $this->_server['base_url'] = 'https://' . $this->_getServerHostname(); if ($this->_getServerPort()!=443) { $this->_server['base_url'] .= ':' .$this->_getServerPort(); } $this->_server['base_url'] .= $this->_getServerURI(); } return $this->_server['base_url']; }
[ "private", "function", "_getServerBaseURL", "(", ")", "{", "// the URL is build only when needed", "if", "(", "empty", "(", "$", "this", "->", "_server", "[", "'base_url'", "]", ")", ")", "{", "$", "this", "->", "_server", "[", "'base_url'", "]", "=", "'https://'", ".", "$", "this", "->", "_getServerHostname", "(", ")", ";", "if", "(", "$", "this", "->", "_getServerPort", "(", ")", "!=", "443", ")", "{", "$", "this", "->", "_server", "[", "'base_url'", "]", ".=", "':'", ".", "$", "this", "->", "_getServerPort", "(", ")", ";", "}", "$", "this", "->", "_server", "[", "'base_url'", "]", ".=", "$", "this", "->", "_getServerURI", "(", ")", ";", "}", "return", "$", "this", "->", "_server", "[", "'base_url'", "]", ";", "}" ]
This method is used to retrieve the base URL of the CAS server. @return string a URL.
[ "This", "method", "is", "used", "to", "retrieve", "the", "base", "URL", "of", "the", "CAS", "server", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L313-L325
218,467
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client.getServerLoginURL
public function getServerLoginURL($gateway=false,$renew=false) { phpCAS::traceBegin(); // the URL is build only when needed if ( empty($this->_server['login_url']) ) { $this->_server['login_url'] = $this->_buildQueryUrl($this->_getServerBaseURL().'login','service='.urlencode($this->getURL())); } $url = $this->_server['login_url']; if ($renew) { // It is recommended that when the "renew" parameter is set, its // value be "true" $url = $this->_buildQueryUrl($url, 'renew=true'); } elseif ($gateway) { // It is recommended that when the "gateway" parameter is set, its // value be "true" $url = $this->_buildQueryUrl($url, 'gateway=true'); } phpCAS::traceEnd($url); return $url; }
php
public function getServerLoginURL($gateway=false,$renew=false) { phpCAS::traceBegin(); // the URL is build only when needed if ( empty($this->_server['login_url']) ) { $this->_server['login_url'] = $this->_buildQueryUrl($this->_getServerBaseURL().'login','service='.urlencode($this->getURL())); } $url = $this->_server['login_url']; if ($renew) { // It is recommended that when the "renew" parameter is set, its // value be "true" $url = $this->_buildQueryUrl($url, 'renew=true'); } elseif ($gateway) { // It is recommended that when the "gateway" parameter is set, its // value be "true" $url = $this->_buildQueryUrl($url, 'gateway=true'); } phpCAS::traceEnd($url); return $url; }
[ "public", "function", "getServerLoginURL", "(", "$", "gateway", "=", "false", ",", "$", "renew", "=", "false", ")", "{", "phpCAS", "::", "traceBegin", "(", ")", ";", "// the URL is build only when needed", "if", "(", "empty", "(", "$", "this", "->", "_server", "[", "'login_url'", "]", ")", ")", "{", "$", "this", "->", "_server", "[", "'login_url'", "]", "=", "$", "this", "->", "_buildQueryUrl", "(", "$", "this", "->", "_getServerBaseURL", "(", ")", ".", "'login'", ",", "'service='", ".", "urlencode", "(", "$", "this", "->", "getURL", "(", ")", ")", ")", ";", "}", "$", "url", "=", "$", "this", "->", "_server", "[", "'login_url'", "]", ";", "if", "(", "$", "renew", ")", "{", "// It is recommended that when the \"renew\" parameter is set, its", "// value be \"true\"", "$", "url", "=", "$", "this", "->", "_buildQueryUrl", "(", "$", "url", ",", "'renew=true'", ")", ";", "}", "elseif", "(", "$", "gateway", ")", "{", "// It is recommended that when the \"gateway\" parameter is set, its", "// value be \"true\"", "$", "url", "=", "$", "this", "->", "_buildQueryUrl", "(", "$", "url", ",", "'gateway=true'", ")", ";", "}", "phpCAS", "::", "traceEnd", "(", "$", "url", ")", ";", "return", "$", "url", ";", "}" ]
This method is used to retrieve the login URL of the CAS server. @param bool $gateway true to check authentication, false to force it @param bool $renew true to force the authentication with the CAS server @return a URL. @note It is recommended that CAS implementations ignore the "gateway" parameter if "renew" is set
[ "This", "method", "is", "used", "to", "retrieve", "the", "login", "URL", "of", "the", "CAS", "server", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L337-L356
218,468
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client.getServerSamlValidateURL
public function getServerSamlValidateURL() { phpCAS::traceBegin(); // the URL is build only when needed if ( empty($this->_server['saml_validate_url']) ) { switch ($this->getServerVersion()) { case SAML_VERSION_1_1: $this->_server['saml_validate_url'] = $this->_getServerBaseURL().'samlValidate'; break; } } $url = $this->_buildQueryUrl( $this->_server['saml_validate_url'], 'TARGET='.urlencode($this->getURL()) ); phpCAS::traceEnd($url); return $url; }
php
public function getServerSamlValidateURL() { phpCAS::traceBegin(); // the URL is build only when needed if ( empty($this->_server['saml_validate_url']) ) { switch ($this->getServerVersion()) { case SAML_VERSION_1_1: $this->_server['saml_validate_url'] = $this->_getServerBaseURL().'samlValidate'; break; } } $url = $this->_buildQueryUrl( $this->_server['saml_validate_url'], 'TARGET='.urlencode($this->getURL()) ); phpCAS::traceEnd($url); return $url; }
[ "public", "function", "getServerSamlValidateURL", "(", ")", "{", "phpCAS", "::", "traceBegin", "(", ")", ";", "// the URL is build only when needed", "if", "(", "empty", "(", "$", "this", "->", "_server", "[", "'saml_validate_url'", "]", ")", ")", "{", "switch", "(", "$", "this", "->", "getServerVersion", "(", ")", ")", "{", "case", "SAML_VERSION_1_1", ":", "$", "this", "->", "_server", "[", "'saml_validate_url'", "]", "=", "$", "this", "->", "_getServerBaseURL", "(", ")", ".", "'samlValidate'", ";", "break", ";", "}", "}", "$", "url", "=", "$", "this", "->", "_buildQueryUrl", "(", "$", "this", "->", "_server", "[", "'saml_validate_url'", "]", ",", "'TARGET='", ".", "urlencode", "(", "$", "this", "->", "getURL", "(", ")", ")", ")", ";", "phpCAS", "::", "traceEnd", "(", "$", "url", ")", ";", "return", "$", "url", ";", "}" ]
This method is used to retrieve the SAML validating URL of the CAS server. @return string samlValidate URL.
[ "This", "method", "is", "used", "to", "retrieve", "the", "SAML", "validating", "URL", "of", "the", "CAS", "server", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L463-L481
218,469
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client.getServerProxyValidateURL
public function getServerProxyValidateURL() { phpCAS::traceBegin(); // the URL is build only when needed if ( empty($this->_server['proxy_validate_url']) ) { switch ($this->getServerVersion()) { case CAS_VERSION_1_0: $this->_server['proxy_validate_url'] = ''; break; case CAS_VERSION_2_0: $this->_server['proxy_validate_url'] = $this->_getServerBaseURL().'proxyValidate'; break; case CAS_VERSION_3_0: $this->_server['proxy_validate_url'] = $this->_getServerBaseURL().'p3/proxyValidate'; break; } } $url = $this->_buildQueryUrl( $this->_server['proxy_validate_url'], 'service='.urlencode($this->getURL()) ); phpCAS::traceEnd($url); return $url; }
php
public function getServerProxyValidateURL() { phpCAS::traceBegin(); // the URL is build only when needed if ( empty($this->_server['proxy_validate_url']) ) { switch ($this->getServerVersion()) { case CAS_VERSION_1_0: $this->_server['proxy_validate_url'] = ''; break; case CAS_VERSION_2_0: $this->_server['proxy_validate_url'] = $this->_getServerBaseURL().'proxyValidate'; break; case CAS_VERSION_3_0: $this->_server['proxy_validate_url'] = $this->_getServerBaseURL().'p3/proxyValidate'; break; } } $url = $this->_buildQueryUrl( $this->_server['proxy_validate_url'], 'service='.urlencode($this->getURL()) ); phpCAS::traceEnd($url); return $url; }
[ "public", "function", "getServerProxyValidateURL", "(", ")", "{", "phpCAS", "::", "traceBegin", "(", ")", ";", "// the URL is build only when needed", "if", "(", "empty", "(", "$", "this", "->", "_server", "[", "'proxy_validate_url'", "]", ")", ")", "{", "switch", "(", "$", "this", "->", "getServerVersion", "(", ")", ")", "{", "case", "CAS_VERSION_1_0", ":", "$", "this", "->", "_server", "[", "'proxy_validate_url'", "]", "=", "''", ";", "break", ";", "case", "CAS_VERSION_2_0", ":", "$", "this", "->", "_server", "[", "'proxy_validate_url'", "]", "=", "$", "this", "->", "_getServerBaseURL", "(", ")", ".", "'proxyValidate'", ";", "break", ";", "case", "CAS_VERSION_3_0", ":", "$", "this", "->", "_server", "[", "'proxy_validate_url'", "]", "=", "$", "this", "->", "_getServerBaseURL", "(", ")", ".", "'p3/proxyValidate'", ";", "break", ";", "}", "}", "$", "url", "=", "$", "this", "->", "_buildQueryUrl", "(", "$", "this", "->", "_server", "[", "'proxy_validate_url'", "]", ",", "'service='", ".", "urlencode", "(", "$", "this", "->", "getURL", "(", ")", ")", ")", ";", "phpCAS", "::", "traceEnd", "(", "$", "url", ")", ";", "return", "$", "url", ";", "}" ]
This method is used to retrieve the proxy validating URL of the CAS server. @return string proxyValidate URL.
[ "This", "method", "is", "used", "to", "retrieve", "the", "proxy", "validating", "URL", "of", "the", "CAS", "server", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L488-L511
218,470
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client.getServerProxyURL
public function getServerProxyURL() { // the URL is build only when needed if ( empty($this->_server['proxy_url']) ) { switch ($this->getServerVersion()) { case CAS_VERSION_1_0: $this->_server['proxy_url'] = ''; break; case CAS_VERSION_2_0: case CAS_VERSION_3_0: $this->_server['proxy_url'] = $this->_getServerBaseURL().'proxy'; break; } } return $this->_server['proxy_url']; }
php
public function getServerProxyURL() { // the URL is build only when needed if ( empty($this->_server['proxy_url']) ) { switch ($this->getServerVersion()) { case CAS_VERSION_1_0: $this->_server['proxy_url'] = ''; break; case CAS_VERSION_2_0: case CAS_VERSION_3_0: $this->_server['proxy_url'] = $this->_getServerBaseURL().'proxy'; break; } } return $this->_server['proxy_url']; }
[ "public", "function", "getServerProxyURL", "(", ")", "{", "// the URL is build only when needed", "if", "(", "empty", "(", "$", "this", "->", "_server", "[", "'proxy_url'", "]", ")", ")", "{", "switch", "(", "$", "this", "->", "getServerVersion", "(", ")", ")", "{", "case", "CAS_VERSION_1_0", ":", "$", "this", "->", "_server", "[", "'proxy_url'", "]", "=", "''", ";", "break", ";", "case", "CAS_VERSION_2_0", ":", "case", "CAS_VERSION_3_0", ":", "$", "this", "->", "_server", "[", "'proxy_url'", "]", "=", "$", "this", "->", "_getServerBaseURL", "(", ")", ".", "'proxy'", ";", "break", ";", "}", "}", "return", "$", "this", "->", "_server", "[", "'proxy_url'", "]", ";", "}" ]
This method is used to retrieve the proxy URL of the CAS server. @return string proxy URL.
[ "This", "method", "is", "used", "to", "retrieve", "the", "proxy", "URL", "of", "the", "CAS", "server", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L519-L534
218,471
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client.getServerLogoutURL
public function getServerLogoutURL() { // the URL is build only when needed if ( empty($this->_server['logout_url']) ) { $this->_server['logout_url'] = $this->_getServerBaseURL().'logout'; } return $this->_server['logout_url']; }
php
public function getServerLogoutURL() { // the URL is build only when needed if ( empty($this->_server['logout_url']) ) { $this->_server['logout_url'] = $this->_getServerBaseURL().'logout'; } return $this->_server['logout_url']; }
[ "public", "function", "getServerLogoutURL", "(", ")", "{", "// the URL is build only when needed", "if", "(", "empty", "(", "$", "this", "->", "_server", "[", "'logout_url'", "]", ")", ")", "{", "$", "this", "->", "_server", "[", "'logout_url'", "]", "=", "$", "this", "->", "_getServerBaseURL", "(", ")", ".", "'logout'", ";", "}", "return", "$", "this", "->", "_server", "[", "'logout_url'", "]", ";", "}" ]
This method is used to retrieve the logout URL of the CAS server. @return string logout URL.
[ "This", "method", "is", "used", "to", "retrieve", "the", "logout", "URL", "of", "the", "CAS", "server", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L541-L548
218,472
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client.ensureAuthenticationCallSuccessful
public function ensureAuthenticationCallSuccessful() { $this->_ensureAuthenticationCalled(); if (!$this->_authentication_caller['result']) { throw new CAS_OutOfSequenceException( 'authentication was checked (by ' . $this->getAuthenticationCallerMethod() . '() at ' . $this->getAuthenticationCallerFile() . ':' . $this->getAuthenticationCallerLine() . ') but the method returned false' ); } }
php
public function ensureAuthenticationCallSuccessful() { $this->_ensureAuthenticationCalled(); if (!$this->_authentication_caller['result']) { throw new CAS_OutOfSequenceException( 'authentication was checked (by ' . $this->getAuthenticationCallerMethod() . '() at ' . $this->getAuthenticationCallerFile() . ':' . $this->getAuthenticationCallerLine() . ') but the method returned false' ); } }
[ "public", "function", "ensureAuthenticationCallSuccessful", "(", ")", "{", "$", "this", "->", "_ensureAuthenticationCalled", "(", ")", ";", "if", "(", "!", "$", "this", "->", "_authentication_caller", "[", "'result'", "]", ")", "{", "throw", "new", "CAS_OutOfSequenceException", "(", "'authentication was checked (by '", ".", "$", "this", "->", "getAuthenticationCallerMethod", "(", ")", ".", "'() at '", ".", "$", "this", "->", "getAuthenticationCallerFile", "(", ")", ".", "':'", ".", "$", "this", "->", "getAuthenticationCallerLine", "(", ")", ".", "') but the method returned false'", ")", ";", "}", "}" ]
Ensure that authentication was checked. Terminate with exception if no authentication was performed @throws CAS_OutOfSequenceBeforeAuthenticationCallException @return void
[ "Ensure", "that", "authentication", "was", "checked", ".", "Terminate", "with", "exception", "if", "no", "authentication", "was", "performed" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L822-L834
218,473
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client.getAttributes
public function getAttributes() { // Sequence validation $this->ensureAuthenticationCallSuccessful(); // This is likely a duplicate check that could be removed.... if ( empty($this->_user) ) { // if no user is set, there shouldn't be any attributes also... phpCAS::error( 'this method should be used only after '.__CLASS__ .'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()' ); } return $this->_attributes; }
php
public function getAttributes() { // Sequence validation $this->ensureAuthenticationCallSuccessful(); // This is likely a duplicate check that could be removed.... if ( empty($this->_user) ) { // if no user is set, there shouldn't be any attributes also... phpCAS::error( 'this method should be used only after '.__CLASS__ .'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()' ); } return $this->_attributes; }
[ "public", "function", "getAttributes", "(", ")", "{", "// Sequence validation", "$", "this", "->", "ensureAuthenticationCallSuccessful", "(", ")", ";", "// This is likely a duplicate check that could be removed....", "if", "(", "empty", "(", "$", "this", "->", "_user", ")", ")", "{", "// if no user is set, there shouldn't be any attributes also...", "phpCAS", "::", "error", "(", "'this method should be used only after '", ".", "__CLASS__", ".", "'::forceAuthentication() or '", ".", "__CLASS__", ".", "'::isAuthenticated()'", ")", ";", "}", "return", "$", "this", "->", "_attributes", ";", "}" ]
Get an key values arry of attributes @return arry of attributes
[ "Get", "an", "key", "values", "arry", "of", "attributes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L1172-L1185
218,474
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client.getAttribute
public function getAttribute($key) { // Sequence validation $this->ensureAuthenticationCallSuccessful(); if ($this->_hasAttribute($key)) { return $this->_attributes[$key]; } }
php
public function getAttribute($key) { // Sequence validation $this->ensureAuthenticationCallSuccessful(); if ($this->_hasAttribute($key)) { return $this->_attributes[$key]; } }
[ "public", "function", "getAttribute", "(", "$", "key", ")", "{", "// Sequence validation", "$", "this", "->", "ensureAuthenticationCallSuccessful", "(", ")", ";", "if", "(", "$", "this", "->", "_hasAttribute", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "_attributes", "[", "$", "key", "]", ";", "}", "}" ]
Get a specific attribute by name @param string $key name of attribute @return string attribute values
[ "Get", "a", "specific", "attribute", "by", "name" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L1234-L1242
218,475
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client.forceAuthentication
public function forceAuthentication() { phpCAS::traceBegin(); if ( $this->isAuthenticated() ) { // the user is authenticated, nothing to be done. phpCAS::trace('no need to authenticate'); $res = true; } else { // the user is not authenticated, redirect to the CAS server if (isset($_SESSION['phpCAS']['auth_checked'])) { unset($_SESSION['phpCAS']['auth_checked']); } $this->redirectToCas(false/* no gateway */); // never reached $res = false; } phpCAS::traceEnd($res); return $res; }
php
public function forceAuthentication() { phpCAS::traceBegin(); if ( $this->isAuthenticated() ) { // the user is authenticated, nothing to be done. phpCAS::trace('no need to authenticate'); $res = true; } else { // the user is not authenticated, redirect to the CAS server if (isset($_SESSION['phpCAS']['auth_checked'])) { unset($_SESSION['phpCAS']['auth_checked']); } $this->redirectToCas(false/* no gateway */); // never reached $res = false; } phpCAS::traceEnd($res); return $res; }
[ "public", "function", "forceAuthentication", "(", ")", "{", "phpCAS", "::", "traceBegin", "(", ")", ";", "if", "(", "$", "this", "->", "isAuthenticated", "(", ")", ")", "{", "// the user is authenticated, nothing to be done.", "phpCAS", "::", "trace", "(", "'no need to authenticate'", ")", ";", "$", "res", "=", "true", ";", "}", "else", "{", "// the user is not authenticated, redirect to the CAS server", "if", "(", "isset", "(", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'auth_checked'", "]", ")", ")", "{", "unset", "(", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'auth_checked'", "]", ")", ";", "}", "$", "this", "->", "redirectToCas", "(", "false", "/* no gateway */", ")", ";", "// never reached", "$", "res", "=", "false", ";", "}", "phpCAS", "::", "traceEnd", "(", "$", "res", ")", ";", "return", "$", "res", ";", "}" ]
This method is called to be sure that the user is authenticated. When not authenticated, halt by redirecting to the CAS server; otherwise return true. @return true when the user is authenticated; otherwise halt.
[ "This", "method", "is", "called", "to", "be", "sure", "that", "the", "user", "is", "authenticated", ".", "When", "not", "authenticated", "halt", "by", "redirecting", "to", "the", "CAS", "server", ";", "otherwise", "return", "true", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L1276-L1295
218,476
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client.checkAuthentication
public function checkAuthentication() { phpCAS::traceBegin(); $res = false; if ( $this->isAuthenticated() ) { phpCAS::trace('user is authenticated'); /* The 'auth_checked' variable is removed just in case it's set. */ unset($_SESSION['phpCAS']['auth_checked']); $res = true; } else if (isset($_SESSION['phpCAS']['auth_checked'])) { // the previous request has redirected the client to the CAS server // with gateway=true unset($_SESSION['phpCAS']['auth_checked']); $res = false; } else { // avoid a check against CAS on every request if (!isset($_SESSION['phpCAS']['unauth_count'])) { $_SESSION['phpCAS']['unauth_count'] = -2; // uninitialized } if (($_SESSION['phpCAS']['unauth_count'] != -2 && $this->_cache_times_for_auth_recheck == -1) || ($_SESSION['phpCAS']['unauth_count'] >= 0 && $_SESSION['phpCAS']['unauth_count'] < $this->_cache_times_for_auth_recheck) ) { $res = false; if ($this->_cache_times_for_auth_recheck != -1) { $_SESSION['phpCAS']['unauth_count']++; phpCAS::trace( 'user is not authenticated (cached for ' .$_SESSION['phpCAS']['unauth_count'].' times of ' .$this->_cache_times_for_auth_recheck.')' ); } else { phpCAS::trace( 'user is not authenticated (cached for until login pressed)' ); } } else { $_SESSION['phpCAS']['unauth_count'] = 0; $_SESSION['phpCAS']['auth_checked'] = true; phpCAS::trace('user is not authenticated (cache reset)'); $this->redirectToCas(true/* gateway */); // never reached $res = false; } } phpCAS::traceEnd($res); return $res; }
php
public function checkAuthentication() { phpCAS::traceBegin(); $res = false; if ( $this->isAuthenticated() ) { phpCAS::trace('user is authenticated'); /* The 'auth_checked' variable is removed just in case it's set. */ unset($_SESSION['phpCAS']['auth_checked']); $res = true; } else if (isset($_SESSION['phpCAS']['auth_checked'])) { // the previous request has redirected the client to the CAS server // with gateway=true unset($_SESSION['phpCAS']['auth_checked']); $res = false; } else { // avoid a check against CAS on every request if (!isset($_SESSION['phpCAS']['unauth_count'])) { $_SESSION['phpCAS']['unauth_count'] = -2; // uninitialized } if (($_SESSION['phpCAS']['unauth_count'] != -2 && $this->_cache_times_for_auth_recheck == -1) || ($_SESSION['phpCAS']['unauth_count'] >= 0 && $_SESSION['phpCAS']['unauth_count'] < $this->_cache_times_for_auth_recheck) ) { $res = false; if ($this->_cache_times_for_auth_recheck != -1) { $_SESSION['phpCAS']['unauth_count']++; phpCAS::trace( 'user is not authenticated (cached for ' .$_SESSION['phpCAS']['unauth_count'].' times of ' .$this->_cache_times_for_auth_recheck.')' ); } else { phpCAS::trace( 'user is not authenticated (cached for until login pressed)' ); } } else { $_SESSION['phpCAS']['unauth_count'] = 0; $_SESSION['phpCAS']['auth_checked'] = true; phpCAS::trace('user is not authenticated (cache reset)'); $this->redirectToCas(true/* gateway */); // never reached $res = false; } } phpCAS::traceEnd($res); return $res; }
[ "public", "function", "checkAuthentication", "(", ")", "{", "phpCAS", "::", "traceBegin", "(", ")", ";", "$", "res", "=", "false", ";", "if", "(", "$", "this", "->", "isAuthenticated", "(", ")", ")", "{", "phpCAS", "::", "trace", "(", "'user is authenticated'", ")", ";", "/* The 'auth_checked' variable is removed just in case it's set. */", "unset", "(", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'auth_checked'", "]", ")", ";", "$", "res", "=", "true", ";", "}", "else", "if", "(", "isset", "(", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'auth_checked'", "]", ")", ")", "{", "// the previous request has redirected the client to the CAS server", "// with gateway=true", "unset", "(", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'auth_checked'", "]", ")", ";", "$", "res", "=", "false", ";", "}", "else", "{", "// avoid a check against CAS on every request", "if", "(", "!", "isset", "(", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'unauth_count'", "]", ")", ")", "{", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'unauth_count'", "]", "=", "-", "2", ";", "// uninitialized", "}", "if", "(", "(", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'unauth_count'", "]", "!=", "-", "2", "&&", "$", "this", "->", "_cache_times_for_auth_recheck", "==", "-", "1", ")", "||", "(", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'unauth_count'", "]", ">=", "0", "&&", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'unauth_count'", "]", "<", "$", "this", "->", "_cache_times_for_auth_recheck", ")", ")", "{", "$", "res", "=", "false", ";", "if", "(", "$", "this", "->", "_cache_times_for_auth_recheck", "!=", "-", "1", ")", "{", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'unauth_count'", "]", "++", ";", "phpCAS", "::", "trace", "(", "'user is not authenticated (cached for '", ".", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'unauth_count'", "]", ".", "' times of '", ".", "$", "this", "->", "_cache_times_for_auth_recheck", ".", "')'", ")", ";", "}", "else", "{", "phpCAS", "::", "trace", "(", "'user is not authenticated (cached for until login pressed)'", ")", ";", "}", "}", "else", "{", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'unauth_count'", "]", "=", "0", ";", "$", "_SESSION", "[", "'phpCAS'", "]", "[", "'auth_checked'", "]", "=", "true", ";", "phpCAS", "::", "trace", "(", "'user is not authenticated (cache reset)'", ")", ";", "$", "this", "->", "redirectToCas", "(", "true", "/* gateway */", ")", ";", "// never reached", "$", "res", "=", "false", ";", "}", "}", "phpCAS", "::", "traceEnd", "(", "$", "res", ")", ";", "return", "$", "res", ";", "}" ]
This method is called to check whether the user is authenticated or not. @return true when the user is authenticated, false when a previous gateway login failed or the function will not return if the user is redirected to the cas server for a gateway login attempt
[ "This", "method", "is", "called", "to", "check", "whether", "the", "user", "is", "authenticated", "or", "not", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L1327-L1377
218,477
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client.setCasServerCACert
public function setCasServerCACert($cert, $validate_cn) { // Argument validation if (gettype($cert) != 'string') { throw new CAS_TypeMismatchException($cert, '$cert', 'string'); } if (gettype($validate_cn) != 'boolean') { throw new CAS_TypeMismatchException($validate_cn, '$validate_cn', 'boolean'); } if ( !file_exists($cert) && $this->_requestImplementation !== 'CAS_TestHarness_DummyRequest'){ throw new CAS_InvalidArgumentException("Certificate file does not exist " . $this->_requestImplementation); } $this->_cas_server_ca_cert = $cert; $this->_cas_server_cn_validate = $validate_cn; }
php
public function setCasServerCACert($cert, $validate_cn) { // Argument validation if (gettype($cert) != 'string') { throw new CAS_TypeMismatchException($cert, '$cert', 'string'); } if (gettype($validate_cn) != 'boolean') { throw new CAS_TypeMismatchException($validate_cn, '$validate_cn', 'boolean'); } if ( !file_exists($cert) && $this->_requestImplementation !== 'CAS_TestHarness_DummyRequest'){ throw new CAS_InvalidArgumentException("Certificate file does not exist " . $this->_requestImplementation); } $this->_cas_server_ca_cert = $cert; $this->_cas_server_cn_validate = $validate_cn; }
[ "public", "function", "setCasServerCACert", "(", "$", "cert", ",", "$", "validate_cn", ")", "{", "// Argument validation", "if", "(", "gettype", "(", "$", "cert", ")", "!=", "'string'", ")", "{", "throw", "new", "CAS_TypeMismatchException", "(", "$", "cert", ",", "'$cert'", ",", "'string'", ")", ";", "}", "if", "(", "gettype", "(", "$", "validate_cn", ")", "!=", "'boolean'", ")", "{", "throw", "new", "CAS_TypeMismatchException", "(", "$", "validate_cn", ",", "'$validate_cn'", ",", "'boolean'", ")", ";", "}", "if", "(", "!", "file_exists", "(", "$", "cert", ")", "&&", "$", "this", "->", "_requestImplementation", "!==", "'CAS_TestHarness_DummyRequest'", ")", "{", "throw", "new", "CAS_InvalidArgumentException", "(", "\"Certificate file does not exist \"", ".", "$", "this", "->", "_requestImplementation", ")", ";", "}", "$", "this", "->", "_cas_server_ca_cert", "=", "$", "cert", ";", "$", "this", "->", "_cas_server_cn_validate", "=", "$", "validate_cn", ";", "}" ]
Set the CA certificate of the CAS server. @param string $cert the PEM certificate file name of the CA that emited the cert of the server @param bool $validate_cn valiate CN of the CAS server certificate @return void
[ "Set", "the", "CA", "certificate", "of", "the", "CAS", "server", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L1944-L1958
218,478
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client._setSessionAttributes
private function _setSessionAttributes($text_response) { phpCAS::traceBegin(); $result = false; $attr_array = array(); // create new DOMDocument Object $dom = new DOMDocument(); // Fix possible whitspace problems $dom->preserveWhiteSpace = false; if (($dom->loadXML($text_response))) { $xPath = new DOMXpath($dom); $xPath->registerNamespace('samlp', 'urn:oasis:names:tc:SAML:1.0:protocol'); $xPath->registerNamespace('saml', 'urn:oasis:names:tc:SAML:1.0:assertion'); $nodelist = $xPath->query("//saml:Attribute"); if ($nodelist) { foreach ($nodelist as $node) { $xres = $xPath->query("saml:AttributeValue", $node); $name = $node->getAttribute("AttributeName"); $value_array = array(); foreach ($xres as $node2) { $value_array[] = $node2->nodeValue; } $attr_array[$name] = $value_array; } // UGent addition... foreach ($attr_array as $attr_key => $attr_value) { if (count($attr_value) > 1) { $this->_attributes[$attr_key] = $attr_value; phpCAS::trace("* " . $attr_key . "=" . print_r($attr_value, true)); } else { $this->_attributes[$attr_key] = $attr_value[0]; phpCAS::trace("* " . $attr_key . "=" . $attr_value[0]); } } $result = true; } else { phpCAS::trace("SAML Attributes are empty"); $result = false; } } phpCAS::traceEnd($result); return $result; }
php
private function _setSessionAttributes($text_response) { phpCAS::traceBegin(); $result = false; $attr_array = array(); // create new DOMDocument Object $dom = new DOMDocument(); // Fix possible whitspace problems $dom->preserveWhiteSpace = false; if (($dom->loadXML($text_response))) { $xPath = new DOMXpath($dom); $xPath->registerNamespace('samlp', 'urn:oasis:names:tc:SAML:1.0:protocol'); $xPath->registerNamespace('saml', 'urn:oasis:names:tc:SAML:1.0:assertion'); $nodelist = $xPath->query("//saml:Attribute"); if ($nodelist) { foreach ($nodelist as $node) { $xres = $xPath->query("saml:AttributeValue", $node); $name = $node->getAttribute("AttributeName"); $value_array = array(); foreach ($xres as $node2) { $value_array[] = $node2->nodeValue; } $attr_array[$name] = $value_array; } // UGent addition... foreach ($attr_array as $attr_key => $attr_value) { if (count($attr_value) > 1) { $this->_attributes[$attr_key] = $attr_value; phpCAS::trace("* " . $attr_key . "=" . print_r($attr_value, true)); } else { $this->_attributes[$attr_key] = $attr_value[0]; phpCAS::trace("* " . $attr_key . "=" . $attr_value[0]); } } $result = true; } else { phpCAS::trace("SAML Attributes are empty"); $result = false; } } phpCAS::traceEnd($result); return $result; }
[ "private", "function", "_setSessionAttributes", "(", "$", "text_response", ")", "{", "phpCAS", "::", "traceBegin", "(", ")", ";", "$", "result", "=", "false", ";", "$", "attr_array", "=", "array", "(", ")", ";", "// create new DOMDocument Object", "$", "dom", "=", "new", "DOMDocument", "(", ")", ";", "// Fix possible whitspace problems", "$", "dom", "->", "preserveWhiteSpace", "=", "false", ";", "if", "(", "(", "$", "dom", "->", "loadXML", "(", "$", "text_response", ")", ")", ")", "{", "$", "xPath", "=", "new", "DOMXpath", "(", "$", "dom", ")", ";", "$", "xPath", "->", "registerNamespace", "(", "'samlp'", ",", "'urn:oasis:names:tc:SAML:1.0:protocol'", ")", ";", "$", "xPath", "->", "registerNamespace", "(", "'saml'", ",", "'urn:oasis:names:tc:SAML:1.0:assertion'", ")", ";", "$", "nodelist", "=", "$", "xPath", "->", "query", "(", "\"//saml:Attribute\"", ")", ";", "if", "(", "$", "nodelist", ")", "{", "foreach", "(", "$", "nodelist", "as", "$", "node", ")", "{", "$", "xres", "=", "$", "xPath", "->", "query", "(", "\"saml:AttributeValue\"", ",", "$", "node", ")", ";", "$", "name", "=", "$", "node", "->", "getAttribute", "(", "\"AttributeName\"", ")", ";", "$", "value_array", "=", "array", "(", ")", ";", "foreach", "(", "$", "xres", "as", "$", "node2", ")", "{", "$", "value_array", "[", "]", "=", "$", "node2", "->", "nodeValue", ";", "}", "$", "attr_array", "[", "$", "name", "]", "=", "$", "value_array", ";", "}", "// UGent addition...", "foreach", "(", "$", "attr_array", "as", "$", "attr_key", "=>", "$", "attr_value", ")", "{", "if", "(", "count", "(", "$", "attr_value", ")", ">", "1", ")", "{", "$", "this", "->", "_attributes", "[", "$", "attr_key", "]", "=", "$", "attr_value", ";", "phpCAS", "::", "trace", "(", "\"* \"", ".", "$", "attr_key", ".", "\"=\"", ".", "print_r", "(", "$", "attr_value", ",", "true", ")", ")", ";", "}", "else", "{", "$", "this", "->", "_attributes", "[", "$", "attr_key", "]", "=", "$", "attr_value", "[", "0", "]", ";", "phpCAS", "::", "trace", "(", "\"* \"", ".", "$", "attr_key", ".", "\"=\"", ".", "$", "attr_value", "[", "0", "]", ")", ";", "}", "}", "$", "result", "=", "true", ";", "}", "else", "{", "phpCAS", "::", "trace", "(", "\"SAML Attributes are empty\"", ")", ";", "$", "result", "=", "false", ";", "}", "}", "phpCAS", "::", "traceEnd", "(", "$", "result", ")", ";", "return", "$", "result", ";", "}" ]
This method will parse the DOM and pull out the attributes from the SAML payload and put them into an array, then put the array into the session. @param string $text_response the SAML payload. @return bool true when successfull and false if no attributes a found
[ "This", "method", "will", "parse", "the", "DOM", "and", "pull", "out", "the", "attributes", "from", "the", "SAML", "payload", "and", "put", "them", "into", "an", "array", "then", "put", "the", "array", "into", "the", "session", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L2162-L2208
218,479
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client.setCallbackURL
public function setCallbackURL($url) { // Sequence validation $this->ensureIsProxy(); // Argument Validation if (gettype($url) != 'string') throw new CAS_TypeMismatchException($url, '$url', 'string'); return $this->_callback_url = $url; }
php
public function setCallbackURL($url) { // Sequence validation $this->ensureIsProxy(); // Argument Validation if (gettype($url) != 'string') throw new CAS_TypeMismatchException($url, '$url', 'string'); return $this->_callback_url = $url; }
[ "public", "function", "setCallbackURL", "(", "$", "url", ")", "{", "// Sequence validation", "$", "this", "->", "ensureIsProxy", "(", ")", ";", "// Argument Validation", "if", "(", "gettype", "(", "$", "url", ")", "!=", "'string'", ")", "throw", "new", "CAS_TypeMismatchException", "(", "$", "url", ",", "'$url'", ",", "'string'", ")", ";", "return", "$", "this", "->", "_callback_url", "=", "$", "url", ";", "}" ]
This method sets the callback url. @param string $url url to set callback @return void
[ "This", "method", "sets", "the", "callback", "url", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L2383-L2392
218,480
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client._storePGT
private function _storePGT($pgt,$pgt_iou) { // ensure that storage is initialized $this->_initPGTStorage(); // writes the PGT $this->_pgt_storage->write($pgt, $pgt_iou); }
php
private function _storePGT($pgt,$pgt_iou) { // ensure that storage is initialized $this->_initPGTStorage(); // writes the PGT $this->_pgt_storage->write($pgt, $pgt_iou); }
[ "private", "function", "_storePGT", "(", "$", "pgt", ",", "$", "pgt_iou", ")", "{", "// ensure that storage is initialized", "$", "this", "->", "_initPGTStorage", "(", ")", ";", "// writes the PGT", "$", "this", "->", "_pgt_storage", "->", "write", "(", "$", "pgt", ",", "$", "pgt_iou", ")", ";", "}" ]
This method stores a PGT. Halts on error. @param string $pgt the PGT to store @param string $pgt_iou its corresponding Iou @return void
[ "This", "method", "stores", "a", "PGT", ".", "Halts", "on", "error", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L2474-L2480
218,481
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client._validatePGT
private function _validatePGT(&$validate_url,$text_response,$tree_response) { phpCAS::traceBegin(); if ( $tree_response->getElementsByTagName("proxyGrantingTicket")->length == 0) { phpCAS::trace('<proxyGrantingTicket> not found'); // authentication succeded, but no PGT Iou was transmitted throw new CAS_AuthenticationException( $this, 'Ticket validated but no PGT Iou transmitted', $validate_url, false/*$no_response*/, false/*$bad_response*/, $text_response ); } else { // PGT Iou transmitted, extract it $pgt_iou = trim( $tree_response->getElementsByTagName("proxyGrantingTicket")->item(0)->nodeValue ); if (preg_match('/PGTIOU-[\.\-\w]/', $pgt_iou)) { $pgt = $this->_loadPGT($pgt_iou); if ( $pgt == false ) { phpCAS::trace('could not load PGT'); throw new CAS_AuthenticationException( $this, 'PGT Iou was transmitted but PGT could not be retrieved', $validate_url, false/*$no_response*/, false/*$bad_response*/, $text_response ); } $this->_setPGT($pgt); } else { phpCAS::trace('PGTiou format error'); throw new CAS_AuthenticationException( $this, 'PGT Iou was transmitted but has wrong format', $validate_url, false/*$no_response*/, false/*$bad_response*/, $text_response ); } } phpCAS::traceEnd(true); return true; }
php
private function _validatePGT(&$validate_url,$text_response,$tree_response) { phpCAS::traceBegin(); if ( $tree_response->getElementsByTagName("proxyGrantingTicket")->length == 0) { phpCAS::trace('<proxyGrantingTicket> not found'); // authentication succeded, but no PGT Iou was transmitted throw new CAS_AuthenticationException( $this, 'Ticket validated but no PGT Iou transmitted', $validate_url, false/*$no_response*/, false/*$bad_response*/, $text_response ); } else { // PGT Iou transmitted, extract it $pgt_iou = trim( $tree_response->getElementsByTagName("proxyGrantingTicket")->item(0)->nodeValue ); if (preg_match('/PGTIOU-[\.\-\w]/', $pgt_iou)) { $pgt = $this->_loadPGT($pgt_iou); if ( $pgt == false ) { phpCAS::trace('could not load PGT'); throw new CAS_AuthenticationException( $this, 'PGT Iou was transmitted but PGT could not be retrieved', $validate_url, false/*$no_response*/, false/*$bad_response*/, $text_response ); } $this->_setPGT($pgt); } else { phpCAS::trace('PGTiou format error'); throw new CAS_AuthenticationException( $this, 'PGT Iou was transmitted but has wrong format', $validate_url, false/*$no_response*/, false/*$bad_response*/, $text_response ); } } phpCAS::traceEnd(true); return true; }
[ "private", "function", "_validatePGT", "(", "&", "$", "validate_url", ",", "$", "text_response", ",", "$", "tree_response", ")", "{", "phpCAS", "::", "traceBegin", "(", ")", ";", "if", "(", "$", "tree_response", "->", "getElementsByTagName", "(", "\"proxyGrantingTicket\"", ")", "->", "length", "==", "0", ")", "{", "phpCAS", "::", "trace", "(", "'<proxyGrantingTicket> not found'", ")", ";", "// authentication succeded, but no PGT Iou was transmitted", "throw", "new", "CAS_AuthenticationException", "(", "$", "this", ",", "'Ticket validated but no PGT Iou transmitted'", ",", "$", "validate_url", ",", "false", "/*$no_response*/", ",", "false", "/*$bad_response*/", ",", "$", "text_response", ")", ";", "}", "else", "{", "// PGT Iou transmitted, extract it", "$", "pgt_iou", "=", "trim", "(", "$", "tree_response", "->", "getElementsByTagName", "(", "\"proxyGrantingTicket\"", ")", "->", "item", "(", "0", ")", "->", "nodeValue", ")", ";", "if", "(", "preg_match", "(", "'/PGTIOU-[\\.\\-\\w]/'", ",", "$", "pgt_iou", ")", ")", "{", "$", "pgt", "=", "$", "this", "->", "_loadPGT", "(", "$", "pgt_iou", ")", ";", "if", "(", "$", "pgt", "==", "false", ")", "{", "phpCAS", "::", "trace", "(", "'could not load PGT'", ")", ";", "throw", "new", "CAS_AuthenticationException", "(", "$", "this", ",", "'PGT Iou was transmitted but PGT could not be retrieved'", ",", "$", "validate_url", ",", "false", "/*$no_response*/", ",", "false", "/*$bad_response*/", ",", "$", "text_response", ")", ";", "}", "$", "this", "->", "_setPGT", "(", "$", "pgt", ")", ";", "}", "else", "{", "phpCAS", "::", "trace", "(", "'PGTiou format error'", ")", ";", "throw", "new", "CAS_AuthenticationException", "(", "$", "this", ",", "'PGT Iou was transmitted but has wrong format'", ",", "$", "validate_url", ",", "false", "/*$no_response*/", ",", "false", "/*$bad_response*/", ",", "$", "text_response", ")", ";", "}", "}", "phpCAS", "::", "traceEnd", "(", "true", ")", ";", "return", "true", ";", "}" ]
This method is used to validate a PGT; halt on failure. @param string &$validate_url the URL of the request to the CAS server. @param string $text_response the response of the CAS server, as is (XML text); result of CAS_Client::validateCAS10() or CAS_Client::validateCAS20(). @param string $tree_response the response of the CAS server, as a DOM XML tree; result of CAS_Client::validateCAS10() or CAS_Client::validateCAS20(). @return bool true when successfull and issue a CAS_AuthenticationException and false on an error
[ "This", "method", "is", "used", "to", "validate", "a", "PGT", ";", "halt", "on", "failure", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L2604-L2643
218,482
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client._readURL
private function _readURL($url, &$headers, &$body, &$err_msg) { phpCAS::traceBegin(); $className = $this->_requestImplementation; $request = new $className(); if (count($this->_curl_options)) { $request->setCurlOptions($this->_curl_options); } $request->setUrl($url); if (empty($this->_cas_server_ca_cert) && !$this->_no_cas_server_validation) { phpCAS::error( 'one of the methods phpCAS::setCasServerCACert() or phpCAS::setNoCasServerValidation() must be called.' ); } if ($this->_cas_server_ca_cert != '') { $request->setSslCaCert( $this->_cas_server_ca_cert, $this->_cas_server_cn_validate ); } // add extra stuff if SAML if ($this->getServerVersion() == SAML_VERSION_1_1) { $request->addHeader("soapaction: http://www.oasis-open.org/committees/security"); $request->addHeader("cache-control: no-cache"); $request->addHeader("pragma: no-cache"); $request->addHeader("accept: text/xml"); $request->addHeader("connection: keep-alive"); $request->addHeader("content-type: text/xml"); $request->makePost(); $request->setPostBody($this->_buildSAMLPayload()); } if ($request->send()) { $headers = $request->getResponseHeaders(); $body = $request->getResponseBody(); $err_msg = ''; phpCAS::traceEnd(true); return true; } else { $headers = ''; $body = ''; $err_msg = $request->getErrorMessage(); phpCAS::traceEnd(false); return false; } }
php
private function _readURL($url, &$headers, &$body, &$err_msg) { phpCAS::traceBegin(); $className = $this->_requestImplementation; $request = new $className(); if (count($this->_curl_options)) { $request->setCurlOptions($this->_curl_options); } $request->setUrl($url); if (empty($this->_cas_server_ca_cert) && !$this->_no_cas_server_validation) { phpCAS::error( 'one of the methods phpCAS::setCasServerCACert() or phpCAS::setNoCasServerValidation() must be called.' ); } if ($this->_cas_server_ca_cert != '') { $request->setSslCaCert( $this->_cas_server_ca_cert, $this->_cas_server_cn_validate ); } // add extra stuff if SAML if ($this->getServerVersion() == SAML_VERSION_1_1) { $request->addHeader("soapaction: http://www.oasis-open.org/committees/security"); $request->addHeader("cache-control: no-cache"); $request->addHeader("pragma: no-cache"); $request->addHeader("accept: text/xml"); $request->addHeader("connection: keep-alive"); $request->addHeader("content-type: text/xml"); $request->makePost(); $request->setPostBody($this->_buildSAMLPayload()); } if ($request->send()) { $headers = $request->getResponseHeaders(); $body = $request->getResponseBody(); $err_msg = ''; phpCAS::traceEnd(true); return true; } else { $headers = ''; $body = ''; $err_msg = $request->getErrorMessage(); phpCAS::traceEnd(false); return false; } }
[ "private", "function", "_readURL", "(", "$", "url", ",", "&", "$", "headers", ",", "&", "$", "body", ",", "&", "$", "err_msg", ")", "{", "phpCAS", "::", "traceBegin", "(", ")", ";", "$", "className", "=", "$", "this", "->", "_requestImplementation", ";", "$", "request", "=", "new", "$", "className", "(", ")", ";", "if", "(", "count", "(", "$", "this", "->", "_curl_options", ")", ")", "{", "$", "request", "->", "setCurlOptions", "(", "$", "this", "->", "_curl_options", ")", ";", "}", "$", "request", "->", "setUrl", "(", "$", "url", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "_cas_server_ca_cert", ")", "&&", "!", "$", "this", "->", "_no_cas_server_validation", ")", "{", "phpCAS", "::", "error", "(", "'one of the methods phpCAS::setCasServerCACert() or phpCAS::setNoCasServerValidation() must be called.'", ")", ";", "}", "if", "(", "$", "this", "->", "_cas_server_ca_cert", "!=", "''", ")", "{", "$", "request", "->", "setSslCaCert", "(", "$", "this", "->", "_cas_server_ca_cert", ",", "$", "this", "->", "_cas_server_cn_validate", ")", ";", "}", "// add extra stuff if SAML", "if", "(", "$", "this", "->", "getServerVersion", "(", ")", "==", "SAML_VERSION_1_1", ")", "{", "$", "request", "->", "addHeader", "(", "\"soapaction: http://www.oasis-open.org/committees/security\"", ")", ";", "$", "request", "->", "addHeader", "(", "\"cache-control: no-cache\"", ")", ";", "$", "request", "->", "addHeader", "(", "\"pragma: no-cache\"", ")", ";", "$", "request", "->", "addHeader", "(", "\"accept: text/xml\"", ")", ";", "$", "request", "->", "addHeader", "(", "\"connection: keep-alive\"", ")", ";", "$", "request", "->", "addHeader", "(", "\"content-type: text/xml\"", ")", ";", "$", "request", "->", "makePost", "(", ")", ";", "$", "request", "->", "setPostBody", "(", "$", "this", "->", "_buildSAMLPayload", "(", ")", ")", ";", "}", "if", "(", "$", "request", "->", "send", "(", ")", ")", "{", "$", "headers", "=", "$", "request", "->", "getResponseHeaders", "(", ")", ";", "$", "body", "=", "$", "request", "->", "getResponseBody", "(", ")", ";", "$", "err_msg", "=", "''", ";", "phpCAS", "::", "traceEnd", "(", "true", ")", ";", "return", "true", ";", "}", "else", "{", "$", "headers", "=", "''", ";", "$", "body", "=", "''", ";", "$", "err_msg", "=", "$", "request", "->", "getErrorMessage", "(", ")", ";", "phpCAS", "::", "traceEnd", "(", "false", ")", ";", "return", "false", ";", "}", "}" ]
This method is used to acces a remote URL. @param string $url the URL to access. @param string &$headers an array containing the HTTP header lines of the response (an empty array on failure). @param string &$body the body of the response, as a string (empty on failure). @param string &$err_msg an error message, filled on failure. @return true on success, false otherwise (in this later case, $err_msg contains an error message).
[ "This", "method", "is", "used", "to", "acces", "a", "remote", "URL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L2790-L2838
218,483
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client._addAttributeToArray
private function _addAttributeToArray(array &$attributeArray, $name, $value) { // If multiple attributes exist, add as an array value if (isset($attributeArray[$name])) { // Initialize the array with the existing value if (!is_array($attributeArray[$name])) { $existingValue = $attributeArray[$name]; $attributeArray[$name] = array($existingValue); } $attributeArray[$name][] = trim($value); } else { $attributeArray[$name] = trim($value); } }
php
private function _addAttributeToArray(array &$attributeArray, $name, $value) { // If multiple attributes exist, add as an array value if (isset($attributeArray[$name])) { // Initialize the array with the existing value if (!is_array($attributeArray[$name])) { $existingValue = $attributeArray[$name]; $attributeArray[$name] = array($existingValue); } $attributeArray[$name][] = trim($value); } else { $attributeArray[$name] = trim($value); } }
[ "private", "function", "_addAttributeToArray", "(", "array", "&", "$", "attributeArray", ",", "$", "name", ",", "$", "value", ")", "{", "// If multiple attributes exist, add as an array value", "if", "(", "isset", "(", "$", "attributeArray", "[", "$", "name", "]", ")", ")", "{", "// Initialize the array with the existing value", "if", "(", "!", "is_array", "(", "$", "attributeArray", "[", "$", "name", "]", ")", ")", "{", "$", "existingValue", "=", "$", "attributeArray", "[", "$", "name", "]", ";", "$", "attributeArray", "[", "$", "name", "]", "=", "array", "(", "$", "existingValue", ")", ";", "}", "$", "attributeArray", "[", "$", "name", "]", "[", "]", "=", "trim", "(", "$", "value", ")", ";", "}", "else", "{", "$", "attributeArray", "[", "$", "name", "]", "=", "trim", "(", "$", "value", ")", ";", "}", "}" ]
Add an attribute value to an array of attributes. @param array &$attributeArray reference to array @param string $name name of attribute @param string $value value of attribute @return void
[ "Add", "an", "attribute", "value", "to", "an", "array", "of", "attributes", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L3461-L3475
218,484
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client._isHttps
private function _isHttps() { if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) { return ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'); } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTOCOL'])) { return ($_SERVER['HTTP_X_FORWARDED_PROTOCOL'] === 'https'); } elseif ( isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') !== 0 ) { return true; } return false; }
php
private function _isHttps() { if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) { return ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'); } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTOCOL'])) { return ($_SERVER['HTTP_X_FORWARDED_PROTOCOL'] === 'https'); } elseif ( isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') !== 0 ) { return true; } return false; }
[ "private", "function", "_isHttps", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_PROTO'", "]", ")", ")", "{", "return", "(", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_PROTO'", "]", "===", "'https'", ")", ";", "}", "elseif", "(", "!", "empty", "(", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_PROTOCOL'", "]", ")", ")", "{", "return", "(", "$", "_SERVER", "[", "'HTTP_X_FORWARDED_PROTOCOL'", "]", "===", "'https'", ")", ";", "}", "elseif", "(", "isset", "(", "$", "_SERVER", "[", "'HTTPS'", "]", ")", "&&", "!", "empty", "(", "$", "_SERVER", "[", "'HTTPS'", "]", ")", "&&", "strcasecmp", "(", "$", "_SERVER", "[", "'HTTPS'", "]", ",", "'off'", ")", "!==", "0", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
This method checks to see if the request is secured via HTTPS @return bool true if https, false otherwise
[ "This", "method", "checks", "to", "see", "if", "the", "request", "is", "secured", "via", "HTTPS" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L3617-L3631
218,485
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client._buildQueryUrl
private function _buildQueryUrl($url, $query) { $url .= (strstr($url, '?') === false) ? '?' : '&'; $url .= $query; return $url; }
php
private function _buildQueryUrl($url, $query) { $url .= (strstr($url, '?') === false) ? '?' : '&'; $url .= $query; return $url; }
[ "private", "function", "_buildQueryUrl", "(", "$", "url", ",", "$", "query", ")", "{", "$", "url", ".=", "(", "strstr", "(", "$", "url", ",", "'?'", ")", "===", "false", ")", "?", "'?'", ":", "'&'", ";", "$", "url", ".=", "$", "query", ";", "return", "$", "url", ";", "}" ]
This method is used to append query parameters to an url. Since the url might already contain parameter it has to be detected and to build a proper URL @param string $url base url to add the query params to @param string $query params in query form with & separated @return url with query params
[ "This", "method", "is", "used", "to", "append", "query", "parameters", "to", "an", "url", ".", "Since", "the", "url", "might", "already", "contain", "parameter", "it", "has", "to", "be", "detected", "and", "to", "build", "a", "proper", "URL" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L3662-L3667
218,486
moodle/moodle
auth/cas/CAS/CAS/Client.php
CAS_Client._getNodeType
private function _getNodeType($nodeURL) { phpCAS::traceBegin(); if (preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $nodeURL)) { phpCAS::traceEnd(self::IP); return self::IP; } else { phpCAS::traceEnd(self::HOSTNAME); return self::HOSTNAME; } }
php
private function _getNodeType($nodeURL) { phpCAS::traceBegin(); if (preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $nodeURL)) { phpCAS::traceEnd(self::IP); return self::IP; } else { phpCAS::traceEnd(self::HOSTNAME); return self::HOSTNAME; } }
[ "private", "function", "_getNodeType", "(", "$", "nodeURL", ")", "{", "phpCAS", "::", "traceBegin", "(", ")", ";", "if", "(", "preg_match", "(", "\"/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/\"", ",", "$", "nodeURL", ")", ")", "{", "phpCAS", "::", "traceEnd", "(", "self", "::", "IP", ")", ";", "return", "self", "::", "IP", ";", "}", "else", "{", "phpCAS", "::", "traceEnd", "(", "self", "::", "HOSTNAME", ")", ";", "return", "self", "::", "HOSTNAME", ";", "}", "}" ]
Determine the node type from the URL. @param String $nodeURL The node URL. @return string hostname
[ "Determine", "the", "node", "type", "from", "the", "URL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Client.php#L3796-L3806
218,487
moodle/moodle
mod/forum/classes/local/data_mappers/legacy/post.php
post.to_legacy_objects
public function to_legacy_objects(array $posts) : array { return array_map(function(post_entity $post) { return (object) [ 'id' => $post->get_id(), 'discussion' => $post->get_discussion_id(), 'parent' => $post->get_parent_id(), 'userid' => $post->get_author_id(), 'created' => $post->get_time_created(), 'modified' => $post->get_time_modified(), 'mailed' => $post->has_been_mailed(), 'subject' => $post->get_subject(), 'message' => $post->get_message(), 'messageformat' => $post->get_message_format(), 'messagetrust' => $post->is_message_trusted(), 'attachment' => $post->has_attachments(), 'totalscore' => $post->get_total_score(), 'mailnow' => $post->should_mail_now(), 'deleted' => $post->is_deleted(), 'privatereplyto' => $post->get_private_reply_recipient_id(), ]; }, $posts); }
php
public function to_legacy_objects(array $posts) : array { return array_map(function(post_entity $post) { return (object) [ 'id' => $post->get_id(), 'discussion' => $post->get_discussion_id(), 'parent' => $post->get_parent_id(), 'userid' => $post->get_author_id(), 'created' => $post->get_time_created(), 'modified' => $post->get_time_modified(), 'mailed' => $post->has_been_mailed(), 'subject' => $post->get_subject(), 'message' => $post->get_message(), 'messageformat' => $post->get_message_format(), 'messagetrust' => $post->is_message_trusted(), 'attachment' => $post->has_attachments(), 'totalscore' => $post->get_total_score(), 'mailnow' => $post->should_mail_now(), 'deleted' => $post->is_deleted(), 'privatereplyto' => $post->get_private_reply_recipient_id(), ]; }, $posts); }
[ "public", "function", "to_legacy_objects", "(", "array", "$", "posts", ")", ":", "array", "{", "return", "array_map", "(", "function", "(", "post_entity", "$", "post", ")", "{", "return", "(", "object", ")", "[", "'id'", "=>", "$", "post", "->", "get_id", "(", ")", ",", "'discussion'", "=>", "$", "post", "->", "get_discussion_id", "(", ")", ",", "'parent'", "=>", "$", "post", "->", "get_parent_id", "(", ")", ",", "'userid'", "=>", "$", "post", "->", "get_author_id", "(", ")", ",", "'created'", "=>", "$", "post", "->", "get_time_created", "(", ")", ",", "'modified'", "=>", "$", "post", "->", "get_time_modified", "(", ")", ",", "'mailed'", "=>", "$", "post", "->", "has_been_mailed", "(", ")", ",", "'subject'", "=>", "$", "post", "->", "get_subject", "(", ")", ",", "'message'", "=>", "$", "post", "->", "get_message", "(", ")", ",", "'messageformat'", "=>", "$", "post", "->", "get_message_format", "(", ")", ",", "'messagetrust'", "=>", "$", "post", "->", "is_message_trusted", "(", ")", ",", "'attachment'", "=>", "$", "post", "->", "has_attachments", "(", ")", ",", "'totalscore'", "=>", "$", "post", "->", "get_total_score", "(", ")", ",", "'mailnow'", "=>", "$", "post", "->", "should_mail_now", "(", ")", ",", "'deleted'", "=>", "$", "post", "->", "is_deleted", "(", ")", ",", "'privatereplyto'", "=>", "$", "post", "->", "get_private_reply_recipient_id", "(", ")", ",", "]", ";", "}", ",", "$", "posts", ")", ";", "}" ]
Convert a list of post entities into stdClasses. @param post_entity[] $posts The posts to convert. @return stdClass[]
[ "Convert", "a", "list", "of", "post", "entities", "into", "stdClasses", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/data_mappers/legacy/post.php#L45-L66
218,488
moodle/moodle
mod/chat/classes/event/message_sent.php
message_sent.get_legacy_logdata
protected function get_legacy_logdata() { $message = $this->get_record_snapshot('chat_messages', $this->objectid); return array($this->courseid, 'chat', 'talk', 'view.php?id=' . $this->contextinstanceid, $message->chatid, $this->contextinstanceid, $this->relateduserid); }
php
protected function get_legacy_logdata() { $message = $this->get_record_snapshot('chat_messages', $this->objectid); return array($this->courseid, 'chat', 'talk', 'view.php?id=' . $this->contextinstanceid, $message->chatid, $this->contextinstanceid, $this->relateduserid); }
[ "protected", "function", "get_legacy_logdata", "(", ")", "{", "$", "message", "=", "$", "this", "->", "get_record_snapshot", "(", "'chat_messages'", ",", "$", "this", "->", "objectid", ")", ";", "return", "array", "(", "$", "this", "->", "courseid", ",", "'chat'", ",", "'talk'", ",", "'view.php?id='", ".", "$", "this", "->", "contextinstanceid", ",", "$", "message", "->", "chatid", ",", "$", "this", "->", "contextinstanceid", ",", "$", "this", "->", "relateduserid", ")", ";", "}" ]
Return legacy log data. @return array
[ "Return", "legacy", "log", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/chat/classes/event/message_sent.php#L53-L57
218,489
moodle/moodle
grade/report/singleview/classes/local/screen/screen.php
screen.setup_structure
public function setup_structure() { $this->structure = new grade_structure(); $this->structure->modinfo = get_fast_modinfo($this->course); }
php
public function setup_structure() { $this->structure = new grade_structure(); $this->structure->modinfo = get_fast_modinfo($this->course); }
[ "public", "function", "setup_structure", "(", ")", "{", "$", "this", "->", "structure", "=", "new", "grade_structure", "(", ")", ";", "$", "this", "->", "structure", "->", "modinfo", "=", "get_fast_modinfo", "(", "$", "this", "->", "course", ")", ";", "}" ]
Cache the grade_structure class
[ "Cache", "the", "grade_structure", "class" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/screen.php#L110-L113
218,490
moodle/moodle
grade/report/singleview/classes/local/screen/screen.php
screen.fetch_grade_or_default
public function fetch_grade_or_default($item, $userid) { $grade = grade_grade::fetch(array( 'itemid' => $item->id, 'userid' => $userid )); if (!$grade) { $default = new stdClass; $default->userid = $userid; $default->itemid = $item->id; $default->feedback = ''; $grade = new grade_grade($default, false); } $grade->grade_item = $item; return $grade; }
php
public function fetch_grade_or_default($item, $userid) { $grade = grade_grade::fetch(array( 'itemid' => $item->id, 'userid' => $userid )); if (!$grade) { $default = new stdClass; $default->userid = $userid; $default->itemid = $item->id; $default->feedback = ''; $grade = new grade_grade($default, false); } $grade->grade_item = $item; return $grade; }
[ "public", "function", "fetch_grade_or_default", "(", "$", "item", ",", "$", "userid", ")", "{", "$", "grade", "=", "grade_grade", "::", "fetch", "(", "array", "(", "'itemid'", "=>", "$", "item", "->", "id", ",", "'userid'", "=>", "$", "userid", ")", ")", ";", "if", "(", "!", "$", "grade", ")", "{", "$", "default", "=", "new", "stdClass", ";", "$", "default", "->", "userid", "=", "$", "userid", ";", "$", "default", "->", "itemid", "=", "$", "item", "->", "id", ";", "$", "default", "->", "feedback", "=", "''", ";", "$", "grade", "=", "new", "grade_grade", "(", "$", "default", ",", "false", ")", ";", "}", "$", "grade", "->", "grade_item", "=", "$", "item", ";", "return", "$", "grade", ";", "}" ]
Get the grade_grade @param grade_item $item The grade_item @param int $userid The user id @return grade_grade
[ "Get", "the", "grade_grade" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/screen.php#L145-L163
218,491
moodle/moodle
grade/report/singleview/classes/local/screen/screen.php
screen.make_toggle
public function make_toggle($key) { $attrs = array('href' => '#'); // Do proper lang strings for title attributes exist for the given key? $strmanager = \get_string_manager(); $titleall = get_string('all'); $titlenone = get_string('none'); if ($strmanager->string_exists(strtolower($key) . 'all', 'gradereport_singleview')) { $titleall = get_string(strtolower($key) . 'all', 'gradereport_singleview'); } if ($strmanager->string_exists(strtolower($key) . 'none', 'gradereport_singleview')) { $titlenone = get_string(strtolower($key) . 'none', 'gradereport_singleview'); } $all = html_writer::tag('a', get_string('all'), $attrs + array( 'class' => 'include all ' . $key, 'title' => $titleall )); $none = html_writer::tag('a', get_string('none'), $attrs + array( 'class' => 'include none ' . $key, 'title' => $titlenone )); return html_writer::tag('span', "$all / $none", array( 'class' => 'inclusion_links' )); }
php
public function make_toggle($key) { $attrs = array('href' => '#'); // Do proper lang strings for title attributes exist for the given key? $strmanager = \get_string_manager(); $titleall = get_string('all'); $titlenone = get_string('none'); if ($strmanager->string_exists(strtolower($key) . 'all', 'gradereport_singleview')) { $titleall = get_string(strtolower($key) . 'all', 'gradereport_singleview'); } if ($strmanager->string_exists(strtolower($key) . 'none', 'gradereport_singleview')) { $titlenone = get_string(strtolower($key) . 'none', 'gradereport_singleview'); } $all = html_writer::tag('a', get_string('all'), $attrs + array( 'class' => 'include all ' . $key, 'title' => $titleall )); $none = html_writer::tag('a', get_string('none'), $attrs + array( 'class' => 'include none ' . $key, 'title' => $titlenone )); return html_writer::tag('span', "$all / $none", array( 'class' => 'inclusion_links' )); }
[ "public", "function", "make_toggle", "(", "$", "key", ")", "{", "$", "attrs", "=", "array", "(", "'href'", "=>", "'#'", ")", ";", "// Do proper lang strings for title attributes exist for the given key?", "$", "strmanager", "=", "\\", "get_string_manager", "(", ")", ";", "$", "titleall", "=", "get_string", "(", "'all'", ")", ";", "$", "titlenone", "=", "get_string", "(", "'none'", ")", ";", "if", "(", "$", "strmanager", "->", "string_exists", "(", "strtolower", "(", "$", "key", ")", ".", "'all'", ",", "'gradereport_singleview'", ")", ")", "{", "$", "titleall", "=", "get_string", "(", "strtolower", "(", "$", "key", ")", ".", "'all'", ",", "'gradereport_singleview'", ")", ";", "}", "if", "(", "$", "strmanager", "->", "string_exists", "(", "strtolower", "(", "$", "key", ")", ".", "'none'", ",", "'gradereport_singleview'", ")", ")", "{", "$", "titlenone", "=", "get_string", "(", "strtolower", "(", "$", "key", ")", ".", "'none'", ",", "'gradereport_singleview'", ")", ";", "}", "$", "all", "=", "html_writer", "::", "tag", "(", "'a'", ",", "get_string", "(", "'all'", ")", ",", "$", "attrs", "+", "array", "(", "'class'", "=>", "'include all '", ".", "$", "key", ",", "'title'", "=>", "$", "titleall", ")", ")", ";", "$", "none", "=", "html_writer", "::", "tag", "(", "'a'", ",", "get_string", "(", "'none'", ")", ",", "$", "attrs", "+", "array", "(", "'class'", "=>", "'include none '", ".", "$", "key", ",", "'title'", "=>", "$", "titlenone", ")", ")", ";", "return", "html_writer", "::", "tag", "(", "'span'", ",", "\"$all / $none\"", ",", "array", "(", "'class'", "=>", "'inclusion_links'", ")", ")", ";", "}" ]
Make the HTML element that toggles all the checkboxes on or off. @param string $key A unique key for this control - inserted in the classes. @return string
[ "Make", "the", "HTML", "element", "that", "toggles", "all", "the", "checkboxes", "on", "or", "off", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/screen.php#L171-L198
218,492
moodle/moodle
grade/report/singleview/classes/local/screen/screen.php
screen.load_users
protected function load_users() { global $CFG; // Create a graded_users_iterator because it will properly check the groups etc. $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $this->context); require_once($CFG->dirroot.'/grade/lib.php'); $gui = new \graded_users_iterator($this->course, null, $this->groupid); $gui->require_active_enrolment($showonlyactiveenrol); $gui->init(); // Flatten the users. $users = array(); while ($user = $gui->next_user()) { $users[$user->user->id] = $user->user; } $gui->close(); return $users; }
php
protected function load_users() { global $CFG; // Create a graded_users_iterator because it will properly check the groups etc. $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $this->context); require_once($CFG->dirroot.'/grade/lib.php'); $gui = new \graded_users_iterator($this->course, null, $this->groupid); $gui->require_active_enrolment($showonlyactiveenrol); $gui->init(); // Flatten the users. $users = array(); while ($user = $gui->next_user()) { $users[$user->user->id] = $user->user; } $gui->close(); return $users; }
[ "protected", "function", "load_users", "(", ")", "{", "global", "$", "CFG", ";", "// Create a graded_users_iterator because it will properly check the groups etc.", "$", "defaultgradeshowactiveenrol", "=", "!", "empty", "(", "$", "CFG", "->", "grade_report_showonlyactiveenrol", ")", ";", "$", "showonlyactiveenrol", "=", "get_user_preferences", "(", "'grade_report_showonlyactiveenrol'", ",", "$", "defaultgradeshowactiveenrol", ")", ";", "$", "showonlyactiveenrol", "=", "$", "showonlyactiveenrol", "||", "!", "has_capability", "(", "'moodle/course:viewsuspendedusers'", ",", "$", "this", "->", "context", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/grade/lib.php'", ")", ";", "$", "gui", "=", "new", "\\", "graded_users_iterator", "(", "$", "this", "->", "course", ",", "null", ",", "$", "this", "->", "groupid", ")", ";", "$", "gui", "->", "require_active_enrolment", "(", "$", "showonlyactiveenrol", ")", ";", "$", "gui", "->", "init", "(", ")", ";", "// Flatten the users.", "$", "users", "=", "array", "(", ")", ";", "while", "(", "$", "user", "=", "$", "gui", "->", "next_user", "(", ")", ")", "{", "$", "users", "[", "$", "user", "->", "user", "->", "id", "]", "=", "$", "user", "->", "user", ";", "}", "$", "gui", "->", "close", "(", ")", ";", "return", "$", "users", ";", "}" ]
Load a valid list of users for this gradebook as the screen "items". @return array $users A list of enroled users.
[ "Load", "a", "valid", "list", "of", "users", "for", "this", "gradebook", "as", "the", "screen", "items", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/screen.php#L418-L438
218,493
moodle/moodle
grade/report/singleview/classes/local/screen/screen.php
screen.perpage_select
public function perpage_select() { global $PAGE, $OUTPUT; $options = array_combine(self::$validperpage, self::$validperpage); $url = new moodle_url($PAGE->url); $url->remove_params(['page', 'perpage']); $out = ''; $select = new \single_select($url, 'perpage', $options, $this->perpage, null, 'perpagechanger'); $select->label = get_string('itemsperpage', 'gradereport_singleview'); $out .= $OUTPUT->render($select); return $out; }
php
public function perpage_select() { global $PAGE, $OUTPUT; $options = array_combine(self::$validperpage, self::$validperpage); $url = new moodle_url($PAGE->url); $url->remove_params(['page', 'perpage']); $out = ''; $select = new \single_select($url, 'perpage', $options, $this->perpage, null, 'perpagechanger'); $select->label = get_string('itemsperpage', 'gradereport_singleview'); $out .= $OUTPUT->render($select); return $out; }
[ "public", "function", "perpage_select", "(", ")", "{", "global", "$", "PAGE", ",", "$", "OUTPUT", ";", "$", "options", "=", "array_combine", "(", "self", "::", "$", "validperpage", ",", "self", "::", "$", "validperpage", ")", ";", "$", "url", "=", "new", "moodle_url", "(", "$", "PAGE", "->", "url", ")", ";", "$", "url", "->", "remove_params", "(", "[", "'page'", ",", "'perpage'", "]", ")", ";", "$", "out", "=", "''", ";", "$", "select", "=", "new", "\\", "single_select", "(", "$", "url", ",", "'perpage'", ",", "$", "options", ",", "$", "this", "->", "perpage", ",", "null", ",", "'perpagechanger'", ")", ";", "$", "select", "->", "label", "=", "get_string", "(", "'itemsperpage'", ",", "'gradereport_singleview'", ")", ";", "$", "out", ".=", "$", "OUTPUT", "->", "render", "(", "$", "select", ")", ";", "return", "$", "out", ";", "}" ]
Allow selection of number of items to display per page. @return string
[ "Allow", "selection", "of", "number", "of", "items", "to", "display", "per", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/screen.php#L444-L458
218,494
moodle/moodle
lib/classes/task/scheduled_task.php
scheduled_task.eval_cron_field
public function eval_cron_field($field, $min, $max) { // Cleanse the input. $field = trim($field); // Format for a field is: // <fieldlist> := <range>(/<step>)(,<fieldlist>) // <step> := int // <range> := <any>|<int>|<min-max> // <any> := * // <min-max> := int-int // End of format BNF. // This function is complicated but is covered by unit tests. $range = array(); $matches = array(); preg_match_all('@[0-9]+|\*|,|/|-@', $field, $matches); $last = 0; $inrange = false; $instep = false; foreach ($matches[0] as $match) { if ($match == '*') { array_push($range, range($min, $max)); } else if ($match == '/') { $instep = true; } else if ($match == '-') { $inrange = true; } else if (is_numeric($match)) { if ($instep) { $i = 0; for ($i = 0; $i < count($range[count($range) - 1]); $i++) { if (($i) % $match != 0) { $range[count($range) - 1][$i] = -1; } } $inrange = false; } else if ($inrange) { if (count($range)) { $range[count($range) - 1] = range($last, $match); } $inrange = false; } else { if ($match >= $min && $match <= $max) { array_push($range, $match); } $last = $match; } } } // Flatten the result. $result = array(); foreach ($range as $r) { if (is_array($r)) { foreach ($r as $rr) { if ($rr >= $min && $rr <= $max) { $result[$rr] = 1; } } } else if (is_numeric($r)) { if ($r >= $min && $r <= $max) { $result[$r] = 1; } } } $result = array_keys($result); sort($result, SORT_NUMERIC); return $result; }
php
public function eval_cron_field($field, $min, $max) { // Cleanse the input. $field = trim($field); // Format for a field is: // <fieldlist> := <range>(/<step>)(,<fieldlist>) // <step> := int // <range> := <any>|<int>|<min-max> // <any> := * // <min-max> := int-int // End of format BNF. // This function is complicated but is covered by unit tests. $range = array(); $matches = array(); preg_match_all('@[0-9]+|\*|,|/|-@', $field, $matches); $last = 0; $inrange = false; $instep = false; foreach ($matches[0] as $match) { if ($match == '*') { array_push($range, range($min, $max)); } else if ($match == '/') { $instep = true; } else if ($match == '-') { $inrange = true; } else if (is_numeric($match)) { if ($instep) { $i = 0; for ($i = 0; $i < count($range[count($range) - 1]); $i++) { if (($i) % $match != 0) { $range[count($range) - 1][$i] = -1; } } $inrange = false; } else if ($inrange) { if (count($range)) { $range[count($range) - 1] = range($last, $match); } $inrange = false; } else { if ($match >= $min && $match <= $max) { array_push($range, $match); } $last = $match; } } } // Flatten the result. $result = array(); foreach ($range as $r) { if (is_array($r)) { foreach ($r as $rr) { if ($rr >= $min && $rr <= $max) { $result[$rr] = 1; } } } else if (is_numeric($r)) { if ($r >= $min && $r <= $max) { $result[$r] = 1; } } } $result = array_keys($result); sort($result, SORT_NUMERIC); return $result; }
[ "public", "function", "eval_cron_field", "(", "$", "field", ",", "$", "min", ",", "$", "max", ")", "{", "// Cleanse the input.", "$", "field", "=", "trim", "(", "$", "field", ")", ";", "// Format for a field is:", "// <fieldlist> := <range>(/<step>)(,<fieldlist>)", "// <step> := int", "// <range> := <any>|<int>|<min-max>", "// <any> := *", "// <min-max> := int-int", "// End of format BNF.", "// This function is complicated but is covered by unit tests.", "$", "range", "=", "array", "(", ")", ";", "$", "matches", "=", "array", "(", ")", ";", "preg_match_all", "(", "'@[0-9]+|\\*|,|/|-@'", ",", "$", "field", ",", "$", "matches", ")", ";", "$", "last", "=", "0", ";", "$", "inrange", "=", "false", ";", "$", "instep", "=", "false", ";", "foreach", "(", "$", "matches", "[", "0", "]", "as", "$", "match", ")", "{", "if", "(", "$", "match", "==", "'*'", ")", "{", "array_push", "(", "$", "range", ",", "range", "(", "$", "min", ",", "$", "max", ")", ")", ";", "}", "else", "if", "(", "$", "match", "==", "'/'", ")", "{", "$", "instep", "=", "true", ";", "}", "else", "if", "(", "$", "match", "==", "'-'", ")", "{", "$", "inrange", "=", "true", ";", "}", "else", "if", "(", "is_numeric", "(", "$", "match", ")", ")", "{", "if", "(", "$", "instep", ")", "{", "$", "i", "=", "0", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "range", "[", "count", "(", "$", "range", ")", "-", "1", "]", ")", ";", "$", "i", "++", ")", "{", "if", "(", "(", "$", "i", ")", "%", "$", "match", "!=", "0", ")", "{", "$", "range", "[", "count", "(", "$", "range", ")", "-", "1", "]", "[", "$", "i", "]", "=", "-", "1", ";", "}", "}", "$", "inrange", "=", "false", ";", "}", "else", "if", "(", "$", "inrange", ")", "{", "if", "(", "count", "(", "$", "range", ")", ")", "{", "$", "range", "[", "count", "(", "$", "range", ")", "-", "1", "]", "=", "range", "(", "$", "last", ",", "$", "match", ")", ";", "}", "$", "inrange", "=", "false", ";", "}", "else", "{", "if", "(", "$", "match", ">=", "$", "min", "&&", "$", "match", "<=", "$", "max", ")", "{", "array_push", "(", "$", "range", ",", "$", "match", ")", ";", "}", "$", "last", "=", "$", "match", ";", "}", "}", "}", "// Flatten the result.", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "range", "as", "$", "r", ")", "{", "if", "(", "is_array", "(", "$", "r", ")", ")", "{", "foreach", "(", "$", "r", "as", "$", "rr", ")", "{", "if", "(", "$", "rr", ">=", "$", "min", "&&", "$", "rr", "<=", "$", "max", ")", "{", "$", "result", "[", "$", "rr", "]", "=", "1", ";", "}", "}", "}", "else", "if", "(", "is_numeric", "(", "$", "r", ")", ")", "{", "if", "(", "$", "r", ">=", "$", "min", "&&", "$", "r", "<=", "$", "max", ")", "{", "$", "result", "[", "$", "r", "]", "=", "1", ";", "}", "}", "}", "$", "result", "=", "array_keys", "(", "$", "result", ")", ";", "sort", "(", "$", "result", ",", "SORT_NUMERIC", ")", ";", "return", "$", "result", ";", "}" ]
Take a cron field definition and return an array of valid numbers with the range min-max. @param string $field - The field definition. @param int $min - The minimum allowable value. @param int $max - The maximum allowable value. @return array(int)
[ "Take", "a", "cron", "field", "definition", "and", "return", "an", "array", "of", "valid", "numbers", "with", "the", "range", "min", "-", "max", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/scheduled_task.php#L229-L299
218,495
moodle/moodle
lib/classes/task/scheduled_task.php
scheduled_task.get_next_scheduled_time
public function get_next_scheduled_time() { global $CFG; $validminutes = $this->eval_cron_field($this->minute, self::MINUTEMIN, self::MINUTEMAX); $validhours = $this->eval_cron_field($this->hour, self::HOURMIN, self::HOURMAX); // We need to change to the server timezone before using php date() functions. \core_date::set_default_server_timezone(); $daysinmonth = date("t"); $validdays = $this->eval_cron_field($this->day, 1, $daysinmonth); $validdaysofweek = $this->eval_cron_field($this->dayofweek, 0, 7); $validmonths = $this->eval_cron_field($this->month, 1, 12); $nextvalidyear = date('Y'); $currentminute = date("i") + 1; $currenthour = date("H"); $currentday = date("j"); $currentmonth = date("n"); $currentdayofweek = date("w"); $nextvalidminute = $this->next_in_list($currentminute, $validminutes); if ($nextvalidminute < $currentminute) { $currenthour += 1; } $nextvalidhour = $this->next_in_list($currenthour, $validhours); if ($nextvalidhour < $currenthour) { $currentdayofweek += 1; $currentday += 1; } $nextvaliddayofmonth = $this->next_in_list($currentday, $validdays); $nextvaliddayofweek = $this->next_in_list($currentdayofweek, $validdaysofweek); $daysincrementbymonth = $nextvaliddayofmonth - $currentday; if ($nextvaliddayofmonth < $currentday) { $daysincrementbymonth += $daysinmonth; } $daysincrementbyweek = $nextvaliddayofweek - $currentdayofweek; if ($nextvaliddayofweek < $currentdayofweek) { $daysincrementbyweek += 7; } // Special handling for dayofmonth vs dayofweek: // if either field is * - use the other field // otherwise - choose the soonest (see man 5 cron). if ($this->dayofweek == '*') { $daysincrement = $daysincrementbymonth; } else if ($this->day == '*') { $daysincrement = $daysincrementbyweek; } else { // Take the smaller increment of days by month or week. $daysincrement = $daysincrementbymonth; if ($daysincrementbyweek < $daysincrementbymonth) { $daysincrement = $daysincrementbyweek; } } $nextvaliddayofmonth = $currentday + $daysincrement; if ($nextvaliddayofmonth > $daysinmonth) { $currentmonth += 1; $nextvaliddayofmonth -= $daysinmonth; } $nextvalidmonth = $this->next_in_list($currentmonth, $validmonths); if ($nextvalidmonth < $currentmonth) { $nextvalidyear += 1; } // Work out the next valid time. $nexttime = mktime($nextvalidhour, $nextvalidminute, 0, $nextvalidmonth, $nextvaliddayofmonth, $nextvalidyear); return $nexttime; }
php
public function get_next_scheduled_time() { global $CFG; $validminutes = $this->eval_cron_field($this->minute, self::MINUTEMIN, self::MINUTEMAX); $validhours = $this->eval_cron_field($this->hour, self::HOURMIN, self::HOURMAX); // We need to change to the server timezone before using php date() functions. \core_date::set_default_server_timezone(); $daysinmonth = date("t"); $validdays = $this->eval_cron_field($this->day, 1, $daysinmonth); $validdaysofweek = $this->eval_cron_field($this->dayofweek, 0, 7); $validmonths = $this->eval_cron_field($this->month, 1, 12); $nextvalidyear = date('Y'); $currentminute = date("i") + 1; $currenthour = date("H"); $currentday = date("j"); $currentmonth = date("n"); $currentdayofweek = date("w"); $nextvalidminute = $this->next_in_list($currentminute, $validminutes); if ($nextvalidminute < $currentminute) { $currenthour += 1; } $nextvalidhour = $this->next_in_list($currenthour, $validhours); if ($nextvalidhour < $currenthour) { $currentdayofweek += 1; $currentday += 1; } $nextvaliddayofmonth = $this->next_in_list($currentday, $validdays); $nextvaliddayofweek = $this->next_in_list($currentdayofweek, $validdaysofweek); $daysincrementbymonth = $nextvaliddayofmonth - $currentday; if ($nextvaliddayofmonth < $currentday) { $daysincrementbymonth += $daysinmonth; } $daysincrementbyweek = $nextvaliddayofweek - $currentdayofweek; if ($nextvaliddayofweek < $currentdayofweek) { $daysincrementbyweek += 7; } // Special handling for dayofmonth vs dayofweek: // if either field is * - use the other field // otherwise - choose the soonest (see man 5 cron). if ($this->dayofweek == '*') { $daysincrement = $daysincrementbymonth; } else if ($this->day == '*') { $daysincrement = $daysincrementbyweek; } else { // Take the smaller increment of days by month or week. $daysincrement = $daysincrementbymonth; if ($daysincrementbyweek < $daysincrementbymonth) { $daysincrement = $daysincrementbyweek; } } $nextvaliddayofmonth = $currentday + $daysincrement; if ($nextvaliddayofmonth > $daysinmonth) { $currentmonth += 1; $nextvaliddayofmonth -= $daysinmonth; } $nextvalidmonth = $this->next_in_list($currentmonth, $validmonths); if ($nextvalidmonth < $currentmonth) { $nextvalidyear += 1; } // Work out the next valid time. $nexttime = mktime($nextvalidhour, $nextvalidminute, 0, $nextvalidmonth, $nextvaliddayofmonth, $nextvalidyear); return $nexttime; }
[ "public", "function", "get_next_scheduled_time", "(", ")", "{", "global", "$", "CFG", ";", "$", "validminutes", "=", "$", "this", "->", "eval_cron_field", "(", "$", "this", "->", "minute", ",", "self", "::", "MINUTEMIN", ",", "self", "::", "MINUTEMAX", ")", ";", "$", "validhours", "=", "$", "this", "->", "eval_cron_field", "(", "$", "this", "->", "hour", ",", "self", "::", "HOURMIN", ",", "self", "::", "HOURMAX", ")", ";", "// We need to change to the server timezone before using php date() functions.", "\\", "core_date", "::", "set_default_server_timezone", "(", ")", ";", "$", "daysinmonth", "=", "date", "(", "\"t\"", ")", ";", "$", "validdays", "=", "$", "this", "->", "eval_cron_field", "(", "$", "this", "->", "day", ",", "1", ",", "$", "daysinmonth", ")", ";", "$", "validdaysofweek", "=", "$", "this", "->", "eval_cron_field", "(", "$", "this", "->", "dayofweek", ",", "0", ",", "7", ")", ";", "$", "validmonths", "=", "$", "this", "->", "eval_cron_field", "(", "$", "this", "->", "month", ",", "1", ",", "12", ")", ";", "$", "nextvalidyear", "=", "date", "(", "'Y'", ")", ";", "$", "currentminute", "=", "date", "(", "\"i\"", ")", "+", "1", ";", "$", "currenthour", "=", "date", "(", "\"H\"", ")", ";", "$", "currentday", "=", "date", "(", "\"j\"", ")", ";", "$", "currentmonth", "=", "date", "(", "\"n\"", ")", ";", "$", "currentdayofweek", "=", "date", "(", "\"w\"", ")", ";", "$", "nextvalidminute", "=", "$", "this", "->", "next_in_list", "(", "$", "currentminute", ",", "$", "validminutes", ")", ";", "if", "(", "$", "nextvalidminute", "<", "$", "currentminute", ")", "{", "$", "currenthour", "+=", "1", ";", "}", "$", "nextvalidhour", "=", "$", "this", "->", "next_in_list", "(", "$", "currenthour", ",", "$", "validhours", ")", ";", "if", "(", "$", "nextvalidhour", "<", "$", "currenthour", ")", "{", "$", "currentdayofweek", "+=", "1", ";", "$", "currentday", "+=", "1", ";", "}", "$", "nextvaliddayofmonth", "=", "$", "this", "->", "next_in_list", "(", "$", "currentday", ",", "$", "validdays", ")", ";", "$", "nextvaliddayofweek", "=", "$", "this", "->", "next_in_list", "(", "$", "currentdayofweek", ",", "$", "validdaysofweek", ")", ";", "$", "daysincrementbymonth", "=", "$", "nextvaliddayofmonth", "-", "$", "currentday", ";", "if", "(", "$", "nextvaliddayofmonth", "<", "$", "currentday", ")", "{", "$", "daysincrementbymonth", "+=", "$", "daysinmonth", ";", "}", "$", "daysincrementbyweek", "=", "$", "nextvaliddayofweek", "-", "$", "currentdayofweek", ";", "if", "(", "$", "nextvaliddayofweek", "<", "$", "currentdayofweek", ")", "{", "$", "daysincrementbyweek", "+=", "7", ";", "}", "// Special handling for dayofmonth vs dayofweek:", "// if either field is * - use the other field", "// otherwise - choose the soonest (see man 5 cron).", "if", "(", "$", "this", "->", "dayofweek", "==", "'*'", ")", "{", "$", "daysincrement", "=", "$", "daysincrementbymonth", ";", "}", "else", "if", "(", "$", "this", "->", "day", "==", "'*'", ")", "{", "$", "daysincrement", "=", "$", "daysincrementbyweek", ";", "}", "else", "{", "// Take the smaller increment of days by month or week.", "$", "daysincrement", "=", "$", "daysincrementbymonth", ";", "if", "(", "$", "daysincrementbyweek", "<", "$", "daysincrementbymonth", ")", "{", "$", "daysincrement", "=", "$", "daysincrementbyweek", ";", "}", "}", "$", "nextvaliddayofmonth", "=", "$", "currentday", "+", "$", "daysincrement", ";", "if", "(", "$", "nextvaliddayofmonth", ">", "$", "daysinmonth", ")", "{", "$", "currentmonth", "+=", "1", ";", "$", "nextvaliddayofmonth", "-=", "$", "daysinmonth", ";", "}", "$", "nextvalidmonth", "=", "$", "this", "->", "next_in_list", "(", "$", "currentmonth", ",", "$", "validmonths", ")", ";", "if", "(", "$", "nextvalidmonth", "<", "$", "currentmonth", ")", "{", "$", "nextvalidyear", "+=", "1", ";", "}", "// Work out the next valid time.", "$", "nexttime", "=", "mktime", "(", "$", "nextvalidhour", ",", "$", "nextvalidminute", ",", "0", ",", "$", "nextvalidmonth", ",", "$", "nextvaliddayofmonth", ",", "$", "nextvalidyear", ")", ";", "return", "$", "nexttime", ";", "}" ]
Calculate when this task should next be run based on the schedule. @return int $nextruntime.
[ "Calculate", "when", "this", "task", "should", "next", "be", "run", "based", "on", "the", "schedule", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/scheduled_task.php#L328-L405
218,496
moodle/moodle
competency/classes/external/competency_framework_exporter.php
competency_framework_exporter.get_other_values
protected function get_other_values(renderer_base $output) { $filters = array('competencyframeworkid' => $this->persistent->get('id')); $context = $this->persistent->get_context(); $competenciescount = 0; try { api::count_competencies($filters); } catch (\required_capability_exception $re) { $competenciescount = 0; } return array( 'canmanage' => has_capability('moodle/competency:competencymanage', $context), 'competenciescount' => $competenciescount, 'contextname' => $context->get_context_name(), 'contextnamenoprefix' => $context->get_context_name(false) ); }
php
protected function get_other_values(renderer_base $output) { $filters = array('competencyframeworkid' => $this->persistent->get('id')); $context = $this->persistent->get_context(); $competenciescount = 0; try { api::count_competencies($filters); } catch (\required_capability_exception $re) { $competenciescount = 0; } return array( 'canmanage' => has_capability('moodle/competency:competencymanage', $context), 'competenciescount' => $competenciescount, 'contextname' => $context->get_context_name(), 'contextnamenoprefix' => $context->get_context_name(false) ); }
[ "protected", "function", "get_other_values", "(", "renderer_base", "$", "output", ")", "{", "$", "filters", "=", "array", "(", "'competencyframeworkid'", "=>", "$", "this", "->", "persistent", "->", "get", "(", "'id'", ")", ")", ";", "$", "context", "=", "$", "this", "->", "persistent", "->", "get_context", "(", ")", ";", "$", "competenciescount", "=", "0", ";", "try", "{", "api", "::", "count_competencies", "(", "$", "filters", ")", ";", "}", "catch", "(", "\\", "required_capability_exception", "$", "re", ")", "{", "$", "competenciescount", "=", "0", ";", "}", "return", "array", "(", "'canmanage'", "=>", "has_capability", "(", "'moodle/competency:competencymanage'", ",", "$", "context", ")", ",", "'competenciescount'", "=>", "$", "competenciescount", ",", "'contextname'", "=>", "$", "context", "->", "get_context_name", "(", ")", ",", "'contextnamenoprefix'", "=>", "$", "context", "->", "get_context_name", "(", "false", ")", ")", ";", "}" ]
Get other values that do not belong to the basic persisent. @param renderer_base $output @return Array
[ "Get", "other", "values", "that", "do", "not", "belong", "to", "the", "basic", "persisent", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external/competency_framework_exporter.php#L53-L68
218,497
moodle/moodle
lib/spout/src/Spout/Reader/Wrapper/XMLInternalErrorsHelper.php
XMLInternalErrorsHelper.resetXMLInternalErrorsSettingAndThrowIfXMLErrorOccured
protected function resetXMLInternalErrorsSettingAndThrowIfXMLErrorOccured() { if ($this->hasXMLErrorOccured()) { $this->resetXMLInternalErrorsSetting(); throw new XMLProcessingException($this->getLastXMLErrorMessage()); } $this->resetXMLInternalErrorsSetting(); }
php
protected function resetXMLInternalErrorsSettingAndThrowIfXMLErrorOccured() { if ($this->hasXMLErrorOccured()) { $this->resetXMLInternalErrorsSetting(); throw new XMLProcessingException($this->getLastXMLErrorMessage()); } $this->resetXMLInternalErrorsSetting(); }
[ "protected", "function", "resetXMLInternalErrorsSettingAndThrowIfXMLErrorOccured", "(", ")", "{", "if", "(", "$", "this", "->", "hasXMLErrorOccured", "(", ")", ")", "{", "$", "this", "->", "resetXMLInternalErrorsSetting", "(", ")", ";", "throw", "new", "XMLProcessingException", "(", "$", "this", "->", "getLastXMLErrorMessage", "(", ")", ")", ";", "}", "$", "this", "->", "resetXMLInternalErrorsSetting", "(", ")", ";", "}" ]
Throws an XMLProcessingException if an error occured. It also always resets the "libxml_use_internal_errors" setting back to its initial value. @return void @throws \Box\Spout\Reader\Exception\XMLProcessingException
[ "Throws", "an", "XMLProcessingException", "if", "an", "error", "occured", ".", "It", "also", "always", "resets", "the", "libxml_use_internal_errors", "setting", "back", "to", "its", "initial", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/Wrapper/XMLInternalErrorsHelper.php#L36-L44
218,498
moodle/moodle
question/type/calculatedmulti/edit_calculatedmulti_form.php
qtype_calculatedmulti_edit_form.validate_text
protected function validate_text($errors, $field, $text) { $problems = qtype_calculated_find_formula_errors_in_text($text); if ($problems) { $errors[$field] = $problems; } return $errors; }
php
protected function validate_text($errors, $field, $text) { $problems = qtype_calculated_find_formula_errors_in_text($text); if ($problems) { $errors[$field] = $problems; } return $errors; }
[ "protected", "function", "validate_text", "(", "$", "errors", ",", "$", "field", ",", "$", "text", ")", "{", "$", "problems", "=", "qtype_calculated_find_formula_errors_in_text", "(", "$", "text", ")", ";", "if", "(", "$", "problems", ")", "{", "$", "errors", "[", "$", "field", "]", "=", "$", "problems", ";", "}", "return", "$", "errors", ";", "}" ]
Validate the equations in the some question content. @param array $errors where errors are being accumulated. @param string $field the field being validated. @param string $text the content of that field. @return array the updated $errors array.
[ "Validate", "the", "equations", "in", "the", "some", "question", "content", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculatedmulti/edit_calculatedmulti_form.php#L240-L246
218,499
moodle/moodle
lib/adodb/drivers/adodb-oci8.inc.php
ADODB_oci8.MetaForeignKeys
function MetaForeignKeys($table, $owner=false, $upper=false) { global $ADODB_FETCH_MODE; $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; $table = $this->qstr(strtoupper($table)); if (!$owner) { $owner = $this->user; $tabp = 'user_'; } else $tabp = 'all_'; $owner = ' and owner='.$this->qstr(strtoupper($owner)); $sql = "select constraint_name,r_owner,r_constraint_name from {$tabp}constraints where constraint_type = 'R' and table_name = $table $owner"; $constraints = $this->GetArray($sql); $arr = false; foreach($constraints as $constr) { $cons = $this->qstr($constr[0]); $rowner = $this->qstr($constr[1]); $rcons = $this->qstr($constr[2]); $cols = $this->GetArray("select column_name from {$tabp}cons_columns where constraint_name=$cons $owner order by position"); $tabcol = $this->GetArray("select table_name,column_name from {$tabp}cons_columns where owner=$rowner and constraint_name=$rcons order by position"); if ($cols && $tabcol) for ($i=0, $max=sizeof($cols); $i < $max; $i++) { $arr[$tabcol[$i][0]] = $cols[$i][0].'='.$tabcol[$i][1]; } } $ADODB_FETCH_MODE = $save; return $arr; }
php
function MetaForeignKeys($table, $owner=false, $upper=false) { global $ADODB_FETCH_MODE; $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; $table = $this->qstr(strtoupper($table)); if (!$owner) { $owner = $this->user; $tabp = 'user_'; } else $tabp = 'all_'; $owner = ' and owner='.$this->qstr(strtoupper($owner)); $sql = "select constraint_name,r_owner,r_constraint_name from {$tabp}constraints where constraint_type = 'R' and table_name = $table $owner"; $constraints = $this->GetArray($sql); $arr = false; foreach($constraints as $constr) { $cons = $this->qstr($constr[0]); $rowner = $this->qstr($constr[1]); $rcons = $this->qstr($constr[2]); $cols = $this->GetArray("select column_name from {$tabp}cons_columns where constraint_name=$cons $owner order by position"); $tabcol = $this->GetArray("select table_name,column_name from {$tabp}cons_columns where owner=$rowner and constraint_name=$rcons order by position"); if ($cols && $tabcol) for ($i=0, $max=sizeof($cols); $i < $max; $i++) { $arr[$tabcol[$i][0]] = $cols[$i][0].'='.$tabcol[$i][1]; } } $ADODB_FETCH_MODE = $save; return $arr; }
[ "function", "MetaForeignKeys", "(", "$", "table", ",", "$", "owner", "=", "false", ",", "$", "upper", "=", "false", ")", "{", "global", "$", "ADODB_FETCH_MODE", ";", "$", "save", "=", "$", "ADODB_FETCH_MODE", ";", "$", "ADODB_FETCH_MODE", "=", "ADODB_FETCH_NUM", ";", "$", "table", "=", "$", "this", "->", "qstr", "(", "strtoupper", "(", "$", "table", ")", ")", ";", "if", "(", "!", "$", "owner", ")", "{", "$", "owner", "=", "$", "this", "->", "user", ";", "$", "tabp", "=", "'user_'", ";", "}", "else", "$", "tabp", "=", "'all_'", ";", "$", "owner", "=", "' and owner='", ".", "$", "this", "->", "qstr", "(", "strtoupper", "(", "$", "owner", ")", ")", ";", "$", "sql", "=", "\"select constraint_name,r_owner,r_constraint_name\n\tfrom {$tabp}constraints\n\twhere constraint_type = 'R' and table_name = $table $owner\"", ";", "$", "constraints", "=", "$", "this", "->", "GetArray", "(", "$", "sql", ")", ";", "$", "arr", "=", "false", ";", "foreach", "(", "$", "constraints", "as", "$", "constr", ")", "{", "$", "cons", "=", "$", "this", "->", "qstr", "(", "$", "constr", "[", "0", "]", ")", ";", "$", "rowner", "=", "$", "this", "->", "qstr", "(", "$", "constr", "[", "1", "]", ")", ";", "$", "rcons", "=", "$", "this", "->", "qstr", "(", "$", "constr", "[", "2", "]", ")", ";", "$", "cols", "=", "$", "this", "->", "GetArray", "(", "\"select column_name from {$tabp}cons_columns where constraint_name=$cons $owner order by position\"", ")", ";", "$", "tabcol", "=", "$", "this", "->", "GetArray", "(", "\"select table_name,column_name from {$tabp}cons_columns where owner=$rowner and constraint_name=$rcons order by position\"", ")", ";", "if", "(", "$", "cols", "&&", "$", "tabcol", ")", "for", "(", "$", "i", "=", "0", ",", "$", "max", "=", "sizeof", "(", "$", "cols", ")", ";", "$", "i", "<", "$", "max", ";", "$", "i", "++", ")", "{", "$", "arr", "[", "$", "tabcol", "[", "$", "i", "]", "[", "0", "]", "]", "=", "$", "cols", "[", "$", "i", "]", "[", "0", "]", ".", "'='", ".", "$", "tabcol", "[", "$", "i", "]", "[", "1", "]", ";", "}", "}", "$", "ADODB_FETCH_MODE", "=", "$", "save", ";", "return", "$", "arr", ";", "}" ]
returns assoc array where keys are tables, and values are foreign keys @param str $table @param str $owner [optional][default=NULL] @param bool $upper [optional][discarded] @return mixed[] Array of foreign key information @link http://gis.mit.edu/classes/11.521/sqlnotes/referential_integrity.html
[ "returns", "assoc", "array", "where", "keys", "are", "tables", "and", "values", "are", "foreign", "keys" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-oci8.inc.php#L1447-L1484