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
213,800
moodle/moodle
lib/dml/oci_native_moodle_database.php
oci_native_moodle_database.get_limit_sql
private function get_limit_sql($sql, array $params = null, $limitfrom=0, $limitnum=0) { list($limitfrom, $limitnum) = $this->normalise_limit_from_num($limitfrom, $limitnum); // TODO: Add the /*+ FIRST_ROWS */ hint if there isn't another hint if ($limitfrom and $limitnum) { $sql = "SELECT oracle_o.* FROM (SELECT oracle_i.*, rownum AS oracle_rownum FROM ($sql) oracle_i WHERE rownum <= :oracle_num_rows ) oracle_o WHERE oracle_rownum > :oracle_skip_rows"; $params['oracle_num_rows'] = $limitfrom + $limitnum; $params['oracle_skip_rows'] = $limitfrom; } else if ($limitfrom and !$limitnum) { $sql = "SELECT oracle_o.* FROM (SELECT oracle_i.*, rownum AS oracle_rownum FROM ($sql) oracle_i ) oracle_o WHERE oracle_rownum > :oracle_skip_rows"; $params['oracle_skip_rows'] = $limitfrom; } else if (!$limitfrom and $limitnum) { $sql = "SELECT * FROM ($sql) WHERE rownum <= :oracle_num_rows"; $params['oracle_num_rows'] = $limitnum; } return array($sql, $params); }
php
private function get_limit_sql($sql, array $params = null, $limitfrom=0, $limitnum=0) { list($limitfrom, $limitnum) = $this->normalise_limit_from_num($limitfrom, $limitnum); // TODO: Add the /*+ FIRST_ROWS */ hint if there isn't another hint if ($limitfrom and $limitnum) { $sql = "SELECT oracle_o.* FROM (SELECT oracle_i.*, rownum AS oracle_rownum FROM ($sql) oracle_i WHERE rownum <= :oracle_num_rows ) oracle_o WHERE oracle_rownum > :oracle_skip_rows"; $params['oracle_num_rows'] = $limitfrom + $limitnum; $params['oracle_skip_rows'] = $limitfrom; } else if ($limitfrom and !$limitnum) { $sql = "SELECT oracle_o.* FROM (SELECT oracle_i.*, rownum AS oracle_rownum FROM ($sql) oracle_i ) oracle_o WHERE oracle_rownum > :oracle_skip_rows"; $params['oracle_skip_rows'] = $limitfrom; } else if (!$limitfrom and $limitnum) { $sql = "SELECT * FROM ($sql) WHERE rownum <= :oracle_num_rows"; $params['oracle_num_rows'] = $limitnum; } return array($sql, $params); }
[ "private", "function", "get_limit_sql", "(", "$", "sql", ",", "array", "$", "params", "=", "null", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "list", "(", "$", "limitfrom", ",", "$", "limitnum", ")", "=", "$", "this", "->", "normalise_limit_from_num", "(", "$", "limitfrom", ",", "$", "limitnum", ")", ";", "// TODO: Add the /*+ FIRST_ROWS */ hint if there isn't another hint", "if", "(", "$", "limitfrom", "and", "$", "limitnum", ")", "{", "$", "sql", "=", "\"SELECT oracle_o.*\n FROM (SELECT oracle_i.*, rownum AS oracle_rownum\n FROM ($sql) oracle_i\n WHERE rownum <= :oracle_num_rows\n ) oracle_o\n WHERE oracle_rownum > :oracle_skip_rows\"", ";", "$", "params", "[", "'oracle_num_rows'", "]", "=", "$", "limitfrom", "+", "$", "limitnum", ";", "$", "params", "[", "'oracle_skip_rows'", "]", "=", "$", "limitfrom", ";", "}", "else", "if", "(", "$", "limitfrom", "and", "!", "$", "limitnum", ")", "{", "$", "sql", "=", "\"SELECT oracle_o.*\n FROM (SELECT oracle_i.*, rownum AS oracle_rownum\n FROM ($sql) oracle_i\n ) oracle_o\n WHERE oracle_rownum > :oracle_skip_rows\"", ";", "$", "params", "[", "'oracle_skip_rows'", "]", "=", "$", "limitfrom", ";", "}", "else", "if", "(", "!", "$", "limitfrom", "and", "$", "limitnum", ")", "{", "$", "sql", "=", "\"SELECT *\n FROM ($sql)\n WHERE rownum <= :oracle_num_rows\"", ";", "$", "params", "[", "'oracle_num_rows'", "]", "=", "$", "limitnum", ";", "}", "return", "array", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Transforms the sql and params in order to emulate the LIMIT clause available in other DBs @param string $sql the SQL select query to execute. @param array $params array of sql parameters @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set). @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set). @return array with the transformed sql and params updated
[ "Transforms", "the", "sql", "and", "params", "in", "order", "to", "emulate", "the", "LIMIT", "clause", "available", "in", "other", "DBs" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/oci_native_moodle_database.php#L727-L758
213,801
moodle/moodle
lib/dml/oci_native_moodle_database.php
oci_native_moodle_database.insert_record
public function insert_record($table, $dataobject, $returnid=true, $bulk=false) { $dataobject = (array)$dataobject; $columns = $this->get_columns($table); if (empty($columns)) { throw new dml_exception('ddltablenotexist', $table); } $cleaned = array(); foreach ($dataobject as $field=>$value) { if ($field === 'id') { continue; } if (!isset($columns[$field])) { // Non-existing table field, skip it continue; } $column = $columns[$field]; $cleaned[$field] = $this->normalise_value($column, $value); } return $this->insert_record_raw($table, $cleaned, $returnid, $bulk); }
php
public function insert_record($table, $dataobject, $returnid=true, $bulk=false) { $dataobject = (array)$dataobject; $columns = $this->get_columns($table); if (empty($columns)) { throw new dml_exception('ddltablenotexist', $table); } $cleaned = array(); foreach ($dataobject as $field=>$value) { if ($field === 'id') { continue; } if (!isset($columns[$field])) { // Non-existing table field, skip it continue; } $column = $columns[$field]; $cleaned[$field] = $this->normalise_value($column, $value); } return $this->insert_record_raw($table, $cleaned, $returnid, $bulk); }
[ "public", "function", "insert_record", "(", "$", "table", ",", "$", "dataobject", ",", "$", "returnid", "=", "true", ",", "$", "bulk", "=", "false", ")", "{", "$", "dataobject", "=", "(", "array", ")", "$", "dataobject", ";", "$", "columns", "=", "$", "this", "->", "get_columns", "(", "$", "table", ")", ";", "if", "(", "empty", "(", "$", "columns", ")", ")", "{", "throw", "new", "dml_exception", "(", "'ddltablenotexist'", ",", "$", "table", ")", ";", "}", "$", "cleaned", "=", "array", "(", ")", ";", "foreach", "(", "$", "dataobject", "as", "$", "field", "=>", "$", "value", ")", "{", "if", "(", "$", "field", "===", "'id'", ")", "{", "continue", ";", "}", "if", "(", "!", "isset", "(", "$", "columns", "[", "$", "field", "]", ")", ")", "{", "// Non-existing table field, skip it", "continue", ";", "}", "$", "column", "=", "$", "columns", "[", "$", "field", "]", ";", "$", "cleaned", "[", "$", "field", "]", "=", "$", "this", "->", "normalise_value", "(", "$", "column", ",", "$", "value", ")", ";", "}", "return", "$", "this", "->", "insert_record_raw", "(", "$", "table", ",", "$", "cleaned", ",", "$", "returnid", ",", "$", "bulk", ")", ";", "}" ]
Insert a record into a table and return the "id" field if required. Some conversions and safety checks are carried out. Lobs are supported. If the return ID isn't required, then this just reports success as true/false. $data is an object containing needed data @param string $table The database table to be inserted into @param object $data A data object with values for one or more fields in the record @param bool $returnid Should the id of the newly created record entry be returned? If this option is not requested then true/false is returned. @return bool|int true or new id @throws dml_exception A DML specific exception is thrown for any errors.
[ "Insert", "a", "record", "into", "a", "table", "and", "return", "the", "id", "field", "if", "required", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/oci_native_moodle_database.php#L1315-L1337
213,802
moodle/moodle
lib/dml/oci_native_moodle_database.php
oci_native_moodle_database.recursive_concat
protected function recursive_concat(array $args) { $count = count($args); if ($count == 1) { $arg = reset($args); return $arg; } if ($count == 2) { $args[] = "' '"; // No return here intentionally. } $first = array_shift($args); $second = array_shift($args); $third = $this->recursive_concat($args); return "MOODLELIB.TRICONCAT($first, $second, $third)"; }
php
protected function recursive_concat(array $args) { $count = count($args); if ($count == 1) { $arg = reset($args); return $arg; } if ($count == 2) { $args[] = "' '"; // No return here intentionally. } $first = array_shift($args); $second = array_shift($args); $third = $this->recursive_concat($args); return "MOODLELIB.TRICONCAT($first, $second, $third)"; }
[ "protected", "function", "recursive_concat", "(", "array", "$", "args", ")", "{", "$", "count", "=", "count", "(", "$", "args", ")", ";", "if", "(", "$", "count", "==", "1", ")", "{", "$", "arg", "=", "reset", "(", "$", "args", ")", ";", "return", "$", "arg", ";", "}", "if", "(", "$", "count", "==", "2", ")", "{", "$", "args", "[", "]", "=", "\"' '\"", ";", "// No return here intentionally.", "}", "$", "first", "=", "array_shift", "(", "$", "args", ")", ";", "$", "second", "=", "array_shift", "(", "$", "args", ")", ";", "$", "third", "=", "$", "this", "->", "recursive_concat", "(", "$", "args", ")", ";", "return", "\"MOODLELIB.TRICONCAT($first, $second, $third)\"", ";", "}" ]
Mega hacky magic to work around crazy Oracle NULL concats. @param array $args @return string
[ "Mega", "hacky", "magic", "to", "work", "around", "crazy", "Oracle", "NULL", "concats", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/oci_native_moodle_database.php#L1712-L1726
213,803
moodle/moodle
lib/dml/oci_native_moodle_database.php
oci_native_moodle_database.oci_package_installed
protected function oci_package_installed() { $sql = "SELECT 1 FROM user_objects WHERE object_type = 'PACKAGE BODY' AND object_name = 'MOODLELIB' AND status = 'VALID'"; $this->query_start($sql, null, SQL_QUERY_AUX); $stmt = $this->parse_query($sql); $result = oci_execute($stmt, $this->commit_status); $this->query_end($result, $stmt); $records = null; oci_fetch_all($stmt, $records, 0, -1, OCI_FETCHSTATEMENT_BY_ROW); oci_free_statement($stmt); return isset($records[0]) && reset($records[0]) ? true : false; }
php
protected function oci_package_installed() { $sql = "SELECT 1 FROM user_objects WHERE object_type = 'PACKAGE BODY' AND object_name = 'MOODLELIB' AND status = 'VALID'"; $this->query_start($sql, null, SQL_QUERY_AUX); $stmt = $this->parse_query($sql); $result = oci_execute($stmt, $this->commit_status); $this->query_end($result, $stmt); $records = null; oci_fetch_all($stmt, $records, 0, -1, OCI_FETCHSTATEMENT_BY_ROW); oci_free_statement($stmt); return isset($records[0]) && reset($records[0]) ? true : false; }
[ "protected", "function", "oci_package_installed", "(", ")", "{", "$", "sql", "=", "\"SELECT 1\n FROM user_objects\n WHERE object_type = 'PACKAGE BODY'\n AND object_name = 'MOODLELIB'\n AND status = 'VALID'\"", ";", "$", "this", "->", "query_start", "(", "$", "sql", ",", "null", ",", "SQL_QUERY_AUX", ")", ";", "$", "stmt", "=", "$", "this", "->", "parse_query", "(", "$", "sql", ")", ";", "$", "result", "=", "oci_execute", "(", "$", "stmt", ",", "$", "this", "->", "commit_status", ")", ";", "$", "this", "->", "query_end", "(", "$", "result", ",", "$", "stmt", ")", ";", "$", "records", "=", "null", ";", "oci_fetch_all", "(", "$", "stmt", ",", "$", "records", ",", "0", ",", "-", "1", ",", "OCI_FETCHSTATEMENT_BY_ROW", ")", ";", "oci_free_statement", "(", "$", "stmt", ")", ";", "return", "isset", "(", "$", "records", "[", "0", "]", ")", "&&", "reset", "(", "$", "records", "[", "0", "]", ")", "?", "true", ":", "false", ";", "}" ]
Is the required OCI server package installed? @return bool
[ "Is", "the", "required", "OCI", "server", "package", "installed?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/oci_native_moodle_database.php#L1762-L1776
213,804
moodle/moodle
lib/dml/oci_native_moodle_database.php
oci_native_moodle_database.attempt_oci_package_install
protected function attempt_oci_package_install() { $sqls = file_get_contents(__DIR__.'/oci_native_moodle_package.sql'); $sqls = preg_split('/^\/$/sm', $sqls); foreach ($sqls as $sql) { $sql = trim($sql); if ($sql === '' or $sql === 'SHOW ERRORS') { continue; } $this->change_database_structure($sql); } }
php
protected function attempt_oci_package_install() { $sqls = file_get_contents(__DIR__.'/oci_native_moodle_package.sql'); $sqls = preg_split('/^\/$/sm', $sqls); foreach ($sqls as $sql) { $sql = trim($sql); if ($sql === '' or $sql === 'SHOW ERRORS') { continue; } $this->change_database_structure($sql); } }
[ "protected", "function", "attempt_oci_package_install", "(", ")", "{", "$", "sqls", "=", "file_get_contents", "(", "__DIR__", ".", "'/oci_native_moodle_package.sql'", ")", ";", "$", "sqls", "=", "preg_split", "(", "'/^\\/$/sm'", ",", "$", "sqls", ")", ";", "foreach", "(", "$", "sqls", "as", "$", "sql", ")", "{", "$", "sql", "=", "trim", "(", "$", "sql", ")", ";", "if", "(", "$", "sql", "===", "''", "or", "$", "sql", "===", "'SHOW ERRORS'", ")", "{", "continue", ";", "}", "$", "this", "->", "change_database_structure", "(", "$", "sql", ")", ";", "}", "}" ]
Try to add required moodle package into oracle server.
[ "Try", "to", "add", "required", "moodle", "package", "into", "oracle", "server", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/oci_native_moodle_database.php#L1781-L1791
213,805
moodle/moodle
mod/forum/classes/local/vaults/db_table_vault.php
db_table_vault.transform_db_records_to_entities
protected function transform_db_records_to_entities(array $records) { $preprocessors = $this->get_preprocessors(); $result = array_map(function($record) { return ['record' => $record]; }, $records); $result = array_reduce(array_keys($preprocessors), function($carry, $preprocessor) use ($records, $preprocessors) { $step = $preprocessors[$preprocessor]; $dependencies = $step->execute($records); foreach ($dependencies as $index => $dependency) { // Add the new dependency to the list. $carry[$index] = array_merge($carry[$index], [$preprocessor => $dependency]); } return $carry; }, $result); return $this->from_db_records($result); }
php
protected function transform_db_records_to_entities(array $records) { $preprocessors = $this->get_preprocessors(); $result = array_map(function($record) { return ['record' => $record]; }, $records); $result = array_reduce(array_keys($preprocessors), function($carry, $preprocessor) use ($records, $preprocessors) { $step = $preprocessors[$preprocessor]; $dependencies = $step->execute($records); foreach ($dependencies as $index => $dependency) { // Add the new dependency to the list. $carry[$index] = array_merge($carry[$index], [$preprocessor => $dependency]); } return $carry; }, $result); return $this->from_db_records($result); }
[ "protected", "function", "transform_db_records_to_entities", "(", "array", "$", "records", ")", "{", "$", "preprocessors", "=", "$", "this", "->", "get_preprocessors", "(", ")", ";", "$", "result", "=", "array_map", "(", "function", "(", "$", "record", ")", "{", "return", "[", "'record'", "=>", "$", "record", "]", ";", "}", ",", "$", "records", ")", ";", "$", "result", "=", "array_reduce", "(", "array_keys", "(", "$", "preprocessors", ")", ",", "function", "(", "$", "carry", ",", "$", "preprocessor", ")", "use", "(", "$", "records", ",", "$", "preprocessors", ")", "{", "$", "step", "=", "$", "preprocessors", "[", "$", "preprocessor", "]", ";", "$", "dependencies", "=", "$", "step", "->", "execute", "(", "$", "records", ")", ";", "foreach", "(", "$", "dependencies", "as", "$", "index", "=>", "$", "dependency", ")", "{", "// Add the new dependency to the list.", "$", "carry", "[", "$", "index", "]", "=", "array_merge", "(", "$", "carry", "[", "$", "index", "]", ",", "[", "$", "preprocessor", "=>", "$", "dependency", "]", ")", ";", "}", "return", "$", "carry", ";", "}", ",", "$", "result", ")", ";", "return", "$", "this", "->", "from_db_records", "(", "$", "result", ")", ";", "}" ]
Execute the defined preprocessors on the DB record results and then convert them into entities. @param stdClass[] $records List of DB results @return array
[ "Execute", "the", "defined", "preprocessors", "on", "the", "DB", "record", "results", "and", "then", "convert", "them", "into", "entities", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/db_table_vault.php#L142-L161
213,806
moodle/moodle
mod/forum/classes/local/vaults/db_table_vault.php
db_table_vault.get_from_id
public function get_from_id(int $id) { $records = $this->get_from_ids([$id]); return count($records) ? array_shift($records) : null; }
php
public function get_from_id(int $id) { $records = $this->get_from_ids([$id]); return count($records) ? array_shift($records) : null; }
[ "public", "function", "get_from_id", "(", "int", "$", "id", ")", "{", "$", "records", "=", "$", "this", "->", "get_from_ids", "(", "[", "$", "id", "]", ")", ";", "return", "count", "(", "$", "records", ")", "?", "array_shift", "(", "$", "records", ")", ":", "null", ";", "}" ]
Get the entity for the given id. @param int $id Identifier for the entity @return object|null
[ "Get", "the", "entity", "for", "the", "given", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/db_table_vault.php#L169-L172
213,807
moodle/moodle
mod/forum/classes/local/vaults/db_table_vault.php
db_table_vault.get_from_ids
public function get_from_ids(array $ids) { $alias = $this->get_table_alias(); list($insql, $params) = $this->get_db()->get_in_or_equal($ids); $wheresql = $alias . '.id ' . $insql; $sql = $this->generate_get_records_sql($wheresql); $records = $this->get_db()->get_records_sql($sql, $params); return $this->transform_db_records_to_entities($records); }
php
public function get_from_ids(array $ids) { $alias = $this->get_table_alias(); list($insql, $params) = $this->get_db()->get_in_or_equal($ids); $wheresql = $alias . '.id ' . $insql; $sql = $this->generate_get_records_sql($wheresql); $records = $this->get_db()->get_records_sql($sql, $params); return $this->transform_db_records_to_entities($records); }
[ "public", "function", "get_from_ids", "(", "array", "$", "ids", ")", "{", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "list", "(", "$", "insql", ",", "$", "params", ")", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_in_or_equal", "(", "$", "ids", ")", ";", "$", "wheresql", "=", "$", "alias", ".", "'.id '", ".", "$", "insql", ";", "$", "sql", "=", "$", "this", "->", "generate_get_records_sql", "(", "$", "wheresql", ")", ";", "$", "records", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "return", "$", "this", "->", "transform_db_records_to_entities", "(", "$", "records", ")", ";", "}" ]
Get the list of entities for the given ids. @param int[] $ids Identifiers @return array
[ "Get", "the", "list", "of", "entities", "for", "the", "given", "ids", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/db_table_vault.php#L180-L188
213,808
moodle/moodle
lib/classes/component.php
core_component.classloader
public static function classloader($classname) { self::init(); if (isset(self::$classmap[$classname])) { // Global $CFG is expected in included scripts. global $CFG; // Function include would be faster, but for BC it is better to include only once. include_once(self::$classmap[$classname]); return; } if (isset(self::$classmaprenames[$classname]) && isset(self::$classmap[self::$classmaprenames[$classname]])) { $newclassname = self::$classmaprenames[$classname]; $debugging = "Class '%s' has been renamed for the autoloader and is now deprecated. Please use '%s' instead."; debugging(sprintf($debugging, $classname, $newclassname), DEBUG_DEVELOPER); if (PHP_VERSION_ID >= 70000 && preg_match('#\\\null(\\\|$)#', $classname)) { throw new \coding_exception("Cannot alias $classname to $newclassname"); } class_alias($newclassname, $classname); return; } $file = self::psr_classloader($classname); // If the file is found, require it. if (!empty($file)) { require($file); return; } }
php
public static function classloader($classname) { self::init(); if (isset(self::$classmap[$classname])) { // Global $CFG is expected in included scripts. global $CFG; // Function include would be faster, but for BC it is better to include only once. include_once(self::$classmap[$classname]); return; } if (isset(self::$classmaprenames[$classname]) && isset(self::$classmap[self::$classmaprenames[$classname]])) { $newclassname = self::$classmaprenames[$classname]; $debugging = "Class '%s' has been renamed for the autoloader and is now deprecated. Please use '%s' instead."; debugging(sprintf($debugging, $classname, $newclassname), DEBUG_DEVELOPER); if (PHP_VERSION_ID >= 70000 && preg_match('#\\\null(\\\|$)#', $classname)) { throw new \coding_exception("Cannot alias $classname to $newclassname"); } class_alias($newclassname, $classname); return; } $file = self::psr_classloader($classname); // If the file is found, require it. if (!empty($file)) { require($file); return; } }
[ "public", "static", "function", "classloader", "(", "$", "classname", ")", "{", "self", "::", "init", "(", ")", ";", "if", "(", "isset", "(", "self", "::", "$", "classmap", "[", "$", "classname", "]", ")", ")", "{", "// Global $CFG is expected in included scripts.", "global", "$", "CFG", ";", "// Function include would be faster, but for BC it is better to include only once.", "include_once", "(", "self", "::", "$", "classmap", "[", "$", "classname", "]", ")", ";", "return", ";", "}", "if", "(", "isset", "(", "self", "::", "$", "classmaprenames", "[", "$", "classname", "]", ")", "&&", "isset", "(", "self", "::", "$", "classmap", "[", "self", "::", "$", "classmaprenames", "[", "$", "classname", "]", "]", ")", ")", "{", "$", "newclassname", "=", "self", "::", "$", "classmaprenames", "[", "$", "classname", "]", ";", "$", "debugging", "=", "\"Class '%s' has been renamed for the autoloader and is now deprecated. Please use '%s' instead.\"", ";", "debugging", "(", "sprintf", "(", "$", "debugging", ",", "$", "classname", ",", "$", "newclassname", ")", ",", "DEBUG_DEVELOPER", ")", ";", "if", "(", "PHP_VERSION_ID", ">=", "70000", "&&", "preg_match", "(", "'#\\\\\\null(\\\\\\|$)#'", ",", "$", "classname", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "\"Cannot alias $classname to $newclassname\"", ")", ";", "}", "class_alias", "(", "$", "newclassname", ",", "$", "classname", ")", ";", "return", ";", "}", "$", "file", "=", "self", "::", "psr_classloader", "(", "$", "classname", ")", ";", "// If the file is found, require it.", "if", "(", "!", "empty", "(", "$", "file", ")", ")", "{", "require", "(", "$", "file", ")", ";", "return", ";", "}", "}" ]
Class loader for Frankenstyle named classes in standard locations. Frankenstyle namespaces are supported. The expected location for core classes is: 1/ core_xx_yy_zz ---> lib/classes/xx_yy_zz.php 2/ \core\xx_yy_zz ---> lib/classes/xx_yy_zz.php 3/ \core\xx\yy_zz ---> lib/classes/xx/yy_zz.php The expected location for plugin classes is: 1/ mod_name_xx_yy_zz ---> mod/name/classes/xx_yy_zz.php 2/ \mod_name\xx_yy_zz ---> mod/name/classes/xx_yy_zz.php 3/ \mod_name\xx\yy_zz ---> mod/name/classes/xx/yy_zz.php @param string $classname
[ "Class", "loader", "for", "Frankenstyle", "named", "classes", "in", "standard", "locations", ".", "Frankenstyle", "namespaces", "are", "supported", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L108-L135
213,809
moodle/moodle
lib/classes/component.php
core_component.psr_classloader
protected static function psr_classloader($class) { // Iterate through each PSR-4 namespace prefix. foreach (self::$psr4namespaces as $prefix => $path) { $file = self::get_class_file($class, $prefix, $path, array('\\')); if (!empty($file) && file_exists($file)) { return $file; } } // Iterate through each PSR-0 namespace prefix. foreach (self::$psr0namespaces as $prefix => $path) { $file = self::get_class_file($class, $prefix, $path, array('\\', '_')); if (!empty($file) && file_exists($file)) { return $file; } } return false; }
php
protected static function psr_classloader($class) { // Iterate through each PSR-4 namespace prefix. foreach (self::$psr4namespaces as $prefix => $path) { $file = self::get_class_file($class, $prefix, $path, array('\\')); if (!empty($file) && file_exists($file)) { return $file; } } // Iterate through each PSR-0 namespace prefix. foreach (self::$psr0namespaces as $prefix => $path) { $file = self::get_class_file($class, $prefix, $path, array('\\', '_')); if (!empty($file) && file_exists($file)) { return $file; } } return false; }
[ "protected", "static", "function", "psr_classloader", "(", "$", "class", ")", "{", "// Iterate through each PSR-4 namespace prefix.", "foreach", "(", "self", "::", "$", "psr4namespaces", "as", "$", "prefix", "=>", "$", "path", ")", "{", "$", "file", "=", "self", "::", "get_class_file", "(", "$", "class", ",", "$", "prefix", ",", "$", "path", ",", "array", "(", "'\\\\'", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "file", ")", "&&", "file_exists", "(", "$", "file", ")", ")", "{", "return", "$", "file", ";", "}", "}", "// Iterate through each PSR-0 namespace prefix.", "foreach", "(", "self", "::", "$", "psr0namespaces", "as", "$", "prefix", "=>", "$", "path", ")", "{", "$", "file", "=", "self", "::", "get_class_file", "(", "$", "class", ",", "$", "prefix", ",", "$", "path", ",", "array", "(", "'\\\\'", ",", "'_'", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "file", ")", "&&", "file_exists", "(", "$", "file", ")", ")", "{", "return", "$", "file", ";", "}", "}", "return", "false", ";", "}" ]
Return the path to a class from our defined PSR-0 or PSR-4 standard namespaces on demand. Only returns paths to files that exist. Adapated from http://www.php-fig.org/psr/psr-4/examples/ and made PSR-0 compatible. @param string $class the name of the class. @return string|bool The full path to the file defining the class. Or false if it could not be resolved or does not exist.
[ "Return", "the", "path", "to", "a", "class", "from", "our", "defined", "PSR", "-", "0", "or", "PSR", "-", "4", "standard", "namespaces", "on", "demand", ".", "Only", "returns", "paths", "to", "files", "that", "exist", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L147-L165
213,810
moodle/moodle
lib/classes/component.php
core_component.get_class_file
protected static function get_class_file($class, $prefix, $path, $separators) { global $CFG; // Does the class use the namespace prefix? $len = strlen($prefix); if (strncmp($prefix, $class, $len) !== 0) { // No, move to the next prefix. return false; } $path = $CFG->dirroot . '/' . $path; // Get the relative class name. $relativeclass = substr($class, $len); // Replace the namespace prefix with the base directory, replace namespace // separators with directory separators in the relative class name, append // with .php. $file = $path . str_replace($separators, '/', $relativeclass) . '.php'; return $file; }
php
protected static function get_class_file($class, $prefix, $path, $separators) { global $CFG; // Does the class use the namespace prefix? $len = strlen($prefix); if (strncmp($prefix, $class, $len) !== 0) { // No, move to the next prefix. return false; } $path = $CFG->dirroot . '/' . $path; // Get the relative class name. $relativeclass = substr($class, $len); // Replace the namespace prefix with the base directory, replace namespace // separators with directory separators in the relative class name, append // with .php. $file = $path . str_replace($separators, '/', $relativeclass) . '.php'; return $file; }
[ "protected", "static", "function", "get_class_file", "(", "$", "class", ",", "$", "prefix", ",", "$", "path", ",", "$", "separators", ")", "{", "global", "$", "CFG", ";", "// Does the class use the namespace prefix?", "$", "len", "=", "strlen", "(", "$", "prefix", ")", ";", "if", "(", "strncmp", "(", "$", "prefix", ",", "$", "class", ",", "$", "len", ")", "!==", "0", ")", "{", "// No, move to the next prefix.", "return", "false", ";", "}", "$", "path", "=", "$", "CFG", "->", "dirroot", ".", "'/'", ".", "$", "path", ";", "// Get the relative class name.", "$", "relativeclass", "=", "substr", "(", "$", "class", ",", "$", "len", ")", ";", "// Replace the namespace prefix with the base directory, replace namespace", "// separators with directory separators in the relative class name, append", "// with .php.", "$", "file", "=", "$", "path", ".", "str_replace", "(", "$", "separators", ",", "'/'", ",", "$", "relativeclass", ")", ".", "'.php'", ";", "return", "$", "file", ";", "}" ]
Return the path to the class based on the given namespace prefix and path it corresponds to. Will return the path even if the file does not exist. Check the file esists before requiring. @param string $class the name of the class. @param string $prefix The namespace prefix used to identify the base directory of the source files. @param string $path The relative path to the base directory of the source files. @param string[] $separators The characters that should be used for separating. @return string|bool The full path to the file defining the class. Or false if it could not be resolved.
[ "Return", "the", "path", "to", "the", "class", "based", "on", "the", "given", "namespace", "prefix", "and", "path", "it", "corresponds", "to", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L178-L198
213,811
moodle/moodle
lib/classes/component.php
core_component.is_developer
protected static function is_developer() { global $CFG; // Note we can not rely on $CFG->debug here because DB is not initialised yet. if (isset($CFG->config_php_settings['debug'])) { $debug = (int)$CFG->config_php_settings['debug']; } else { return false; } if ($debug & E_ALL and $debug & E_STRICT) { return true; } return false; }
php
protected static function is_developer() { global $CFG; // Note we can not rely on $CFG->debug here because DB is not initialised yet. if (isset($CFG->config_php_settings['debug'])) { $debug = (int)$CFG->config_php_settings['debug']; } else { return false; } if ($debug & E_ALL and $debug & E_STRICT) { return true; } return false; }
[ "protected", "static", "function", "is_developer", "(", ")", "{", "global", "$", "CFG", ";", "// Note we can not rely on $CFG->debug here because DB is not initialised yet.", "if", "(", "isset", "(", "$", "CFG", "->", "config_php_settings", "[", "'debug'", "]", ")", ")", "{", "$", "debug", "=", "(", "int", ")", "$", "CFG", "->", "config_php_settings", "[", "'debug'", "]", ";", "}", "else", "{", "return", "false", ";", "}", "if", "(", "$", "debug", "&", "E_ALL", "and", "$", "debug", "&", "E_STRICT", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Are we in developer debug mode? Note: You need to set "$CFG->debug = (E_ALL | E_STRICT);" in config.php, the reason is we need to use this before we setup DB connection or caches for CFG. @return bool
[ "Are", "we", "in", "developer", "debug", "mode?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L328-L343
213,812
moodle/moodle
lib/classes/component.php
core_component.get_cache_content
public static function get_cache_content() { if (!isset(self::$plugintypes)) { self::fill_all_caches(); } $cache = array( 'subsystems' => self::$subsystems, 'plugintypes' => self::$plugintypes, 'plugins' => self::$plugins, 'parents' => self::$parents, 'subplugins' => self::$subplugins, 'classmap' => self::$classmap, 'classmaprenames' => self::$classmaprenames, 'filemap' => self::$filemap, 'version' => self::$version, ); return '<?php $cache = '.var_export($cache, true).'; '; }
php
public static function get_cache_content() { if (!isset(self::$plugintypes)) { self::fill_all_caches(); } $cache = array( 'subsystems' => self::$subsystems, 'plugintypes' => self::$plugintypes, 'plugins' => self::$plugins, 'parents' => self::$parents, 'subplugins' => self::$subplugins, 'classmap' => self::$classmap, 'classmaprenames' => self::$classmaprenames, 'filemap' => self::$filemap, 'version' => self::$version, ); return '<?php $cache = '.var_export($cache, true).'; '; }
[ "public", "static", "function", "get_cache_content", "(", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "plugintypes", ")", ")", "{", "self", "::", "fill_all_caches", "(", ")", ";", "}", "$", "cache", "=", "array", "(", "'subsystems'", "=>", "self", "::", "$", "subsystems", ",", "'plugintypes'", "=>", "self", "::", "$", "plugintypes", ",", "'plugins'", "=>", "self", "::", "$", "plugins", ",", "'parents'", "=>", "self", "::", "$", "parents", ",", "'subplugins'", "=>", "self", "::", "$", "subplugins", ",", "'classmap'", "=>", "self", "::", "$", "classmap", ",", "'classmaprenames'", "=>", "self", "::", "$", "classmaprenames", ",", "'filemap'", "=>", "self", "::", "$", "filemap", ",", "'version'", "=>", "self", "::", "$", "version", ",", ")", ";", "return", "'<?php\n$cache = '", ".", "var_export", "(", "$", "cache", ",", "true", ")", ".", "';\n'", ";", "}" ]
Create cache file content. @private this is intended for $CFG->alternative_component_cache only. @return string
[ "Create", "cache", "file", "content", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L352-L372
213,813
moodle/moodle
lib/classes/component.php
core_component.fill_all_caches
protected static function fill_all_caches() { self::$subsystems = self::fetch_subsystems(); list(self::$plugintypes, self::$parents, self::$subplugins) = self::fetch_plugintypes(); self::$plugins = array(); foreach (self::$plugintypes as $type => $fulldir) { self::$plugins[$type] = self::fetch_plugins($type, $fulldir); } self::fill_classmap_cache(); self::fill_classmap_renames_cache(); self::fill_filemap_cache(); self::fetch_core_version(); }
php
protected static function fill_all_caches() { self::$subsystems = self::fetch_subsystems(); list(self::$plugintypes, self::$parents, self::$subplugins) = self::fetch_plugintypes(); self::$plugins = array(); foreach (self::$plugintypes as $type => $fulldir) { self::$plugins[$type] = self::fetch_plugins($type, $fulldir); } self::fill_classmap_cache(); self::fill_classmap_renames_cache(); self::fill_filemap_cache(); self::fetch_core_version(); }
[ "protected", "static", "function", "fill_all_caches", "(", ")", "{", "self", "::", "$", "subsystems", "=", "self", "::", "fetch_subsystems", "(", ")", ";", "list", "(", "self", "::", "$", "plugintypes", ",", "self", "::", "$", "parents", ",", "self", "::", "$", "subplugins", ")", "=", "self", "::", "fetch_plugintypes", "(", ")", ";", "self", "::", "$", "plugins", "=", "array", "(", ")", ";", "foreach", "(", "self", "::", "$", "plugintypes", "as", "$", "type", "=>", "$", "fulldir", ")", "{", "self", "::", "$", "plugins", "[", "$", "type", "]", "=", "self", "::", "fetch_plugins", "(", "$", "type", ",", "$", "fulldir", ")", ";", "}", "self", "::", "fill_classmap_cache", "(", ")", ";", "self", "::", "fill_classmap_renames_cache", "(", ")", ";", "self", "::", "fill_filemap_cache", "(", ")", ";", "self", "::", "fetch_core_version", "(", ")", ";", "}" ]
Fill all caches.
[ "Fill", "all", "caches", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L377-L391
213,814
moodle/moodle
lib/classes/component.php
core_component.fetch_core_version
protected static function fetch_core_version() { global $CFG; if (self::$version === null) { $version = null; // Prevent IDE complaints. require($CFG->dirroot . '/version.php'); self::$version = $version; } return self::$version; }
php
protected static function fetch_core_version() { global $CFG; if (self::$version === null) { $version = null; // Prevent IDE complaints. require($CFG->dirroot . '/version.php'); self::$version = $version; } return self::$version; }
[ "protected", "static", "function", "fetch_core_version", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "self", "::", "$", "version", "===", "null", ")", "{", "$", "version", "=", "null", ";", "// Prevent IDE complaints.", "require", "(", "$", "CFG", "->", "dirroot", ".", "'/version.php'", ")", ";", "self", "::", "$", "version", "=", "$", "version", ";", "}", "return", "self", "::", "$", "version", ";", "}" ]
Get the core version. In order for this to work properly, opcache should be reset beforehand. @return float core version.
[ "Get", "the", "core", "version", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L400-L408
213,815
moodle/moodle
lib/classes/component.php
core_component.fetch_subtypes
protected static function fetch_subtypes($ownerdir) { global $CFG; $types = array(); if (file_exists("$ownerdir/db/subplugins.php")) { $subplugins = array(); include("$ownerdir/db/subplugins.php"); foreach ($subplugins as $subtype => $dir) { if (!preg_match('/^[a-z][a-z0-9]*$/', $subtype)) { error_log("Invalid subtype '$subtype'' detected in '$ownerdir', invalid characters present."); continue; } if (isset(self::$subsystems[$subtype])) { error_log("Invalid subtype '$subtype'' detected in '$ownerdir', duplicates core subsystem."); continue; } if ($CFG->admin !== 'admin' and strpos($dir, 'admin/') === 0) { $dir = preg_replace('|^admin/|', "$CFG->admin/", $dir); } if (!is_dir("$CFG->dirroot/$dir")) { error_log("Invalid subtype directory '$dir' detected in '$ownerdir'."); continue; } $types[$subtype] = "$CFG->dirroot/$dir"; } } return $types; }
php
protected static function fetch_subtypes($ownerdir) { global $CFG; $types = array(); if (file_exists("$ownerdir/db/subplugins.php")) { $subplugins = array(); include("$ownerdir/db/subplugins.php"); foreach ($subplugins as $subtype => $dir) { if (!preg_match('/^[a-z][a-z0-9]*$/', $subtype)) { error_log("Invalid subtype '$subtype'' detected in '$ownerdir', invalid characters present."); continue; } if (isset(self::$subsystems[$subtype])) { error_log("Invalid subtype '$subtype'' detected in '$ownerdir', duplicates core subsystem."); continue; } if ($CFG->admin !== 'admin' and strpos($dir, 'admin/') === 0) { $dir = preg_replace('|^admin/|', "$CFG->admin/", $dir); } if (!is_dir("$CFG->dirroot/$dir")) { error_log("Invalid subtype directory '$dir' detected in '$ownerdir'."); continue; } $types[$subtype] = "$CFG->dirroot/$dir"; } } return $types; }
[ "protected", "static", "function", "fetch_subtypes", "(", "$", "ownerdir", ")", "{", "global", "$", "CFG", ";", "$", "types", "=", "array", "(", ")", ";", "if", "(", "file_exists", "(", "\"$ownerdir/db/subplugins.php\"", ")", ")", "{", "$", "subplugins", "=", "array", "(", ")", ";", "include", "(", "\"$ownerdir/db/subplugins.php\"", ")", ";", "foreach", "(", "$", "subplugins", "as", "$", "subtype", "=>", "$", "dir", ")", "{", "if", "(", "!", "preg_match", "(", "'/^[a-z][a-z0-9]*$/'", ",", "$", "subtype", ")", ")", "{", "error_log", "(", "\"Invalid subtype '$subtype'' detected in '$ownerdir', invalid characters present.\"", ")", ";", "continue", ";", "}", "if", "(", "isset", "(", "self", "::", "$", "subsystems", "[", "$", "subtype", "]", ")", ")", "{", "error_log", "(", "\"Invalid subtype '$subtype'' detected in '$ownerdir', duplicates core subsystem.\"", ")", ";", "continue", ";", "}", "if", "(", "$", "CFG", "->", "admin", "!==", "'admin'", "and", "strpos", "(", "$", "dir", ",", "'admin/'", ")", "===", "0", ")", "{", "$", "dir", "=", "preg_replace", "(", "'|^admin/|'", ",", "\"$CFG->admin/\"", ",", "$", "dir", ")", ";", "}", "if", "(", "!", "is_dir", "(", "\"$CFG->dirroot/$dir\"", ")", ")", "{", "error_log", "(", "\"Invalid subtype directory '$dir' detected in '$ownerdir'.\"", ")", ";", "continue", ";", "}", "$", "types", "[", "$", "subtype", "]", "=", "\"$CFG->dirroot/$dir\"", ";", "}", "}", "return", "$", "types", ";", "}" ]
Returns list of subtypes. @param string $ownerdir @return array
[ "Returns", "list", "of", "subtypes", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L603-L630
213,816
moodle/moodle
lib/classes/component.php
core_component.fetch_plugins
protected static function fetch_plugins($plugintype, $fulldir) { global $CFG; $fulldirs = (array)$fulldir; if ($plugintype === 'theme') { if (realpath($fulldir) !== realpath($CFG->dirroot.'/theme')) { // Include themes in standard location too. array_unshift($fulldirs, $CFG->dirroot.'/theme'); } } $result = array(); foreach ($fulldirs as $fulldir) { if (!is_dir($fulldir)) { continue; } $items = new \DirectoryIterator($fulldir); foreach ($items as $item) { if ($item->isDot() or !$item->isDir()) { continue; } $pluginname = $item->getFilename(); if ($plugintype === 'auth' and $pluginname === 'db') { // Special exception for this wrong plugin name. } else if (isset(self::$ignoreddirs[$pluginname])) { continue; } if (!self::is_valid_plugin_name($plugintype, $pluginname)) { // Always ignore plugins with problematic names here. continue; } $result[$pluginname] = $fulldir.'/'.$pluginname; unset($item); } unset($items); } ksort($result); return $result; }
php
protected static function fetch_plugins($plugintype, $fulldir) { global $CFG; $fulldirs = (array)$fulldir; if ($plugintype === 'theme') { if (realpath($fulldir) !== realpath($CFG->dirroot.'/theme')) { // Include themes in standard location too. array_unshift($fulldirs, $CFG->dirroot.'/theme'); } } $result = array(); foreach ($fulldirs as $fulldir) { if (!is_dir($fulldir)) { continue; } $items = new \DirectoryIterator($fulldir); foreach ($items as $item) { if ($item->isDot() or !$item->isDir()) { continue; } $pluginname = $item->getFilename(); if ($plugintype === 'auth' and $pluginname === 'db') { // Special exception for this wrong plugin name. } else if (isset(self::$ignoreddirs[$pluginname])) { continue; } if (!self::is_valid_plugin_name($plugintype, $pluginname)) { // Always ignore plugins with problematic names here. continue; } $result[$pluginname] = $fulldir.'/'.$pluginname; unset($item); } unset($items); } ksort($result); return $result; }
[ "protected", "static", "function", "fetch_plugins", "(", "$", "plugintype", ",", "$", "fulldir", ")", "{", "global", "$", "CFG", ";", "$", "fulldirs", "=", "(", "array", ")", "$", "fulldir", ";", "if", "(", "$", "plugintype", "===", "'theme'", ")", "{", "if", "(", "realpath", "(", "$", "fulldir", ")", "!==", "realpath", "(", "$", "CFG", "->", "dirroot", ".", "'/theme'", ")", ")", "{", "// Include themes in standard location too.", "array_unshift", "(", "$", "fulldirs", ",", "$", "CFG", "->", "dirroot", ".", "'/theme'", ")", ";", "}", "}", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "fulldirs", "as", "$", "fulldir", ")", "{", "if", "(", "!", "is_dir", "(", "$", "fulldir", ")", ")", "{", "continue", ";", "}", "$", "items", "=", "new", "\\", "DirectoryIterator", "(", "$", "fulldir", ")", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "if", "(", "$", "item", "->", "isDot", "(", ")", "or", "!", "$", "item", "->", "isDir", "(", ")", ")", "{", "continue", ";", "}", "$", "pluginname", "=", "$", "item", "->", "getFilename", "(", ")", ";", "if", "(", "$", "plugintype", "===", "'auth'", "and", "$", "pluginname", "===", "'db'", ")", "{", "// Special exception for this wrong plugin name.", "}", "else", "if", "(", "isset", "(", "self", "::", "$", "ignoreddirs", "[", "$", "pluginname", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "self", "::", "is_valid_plugin_name", "(", "$", "plugintype", ",", "$", "pluginname", ")", ")", "{", "// Always ignore plugins with problematic names here.", "continue", ";", "}", "$", "result", "[", "$", "pluginname", "]", "=", "$", "fulldir", ".", "'/'", ".", "$", "pluginname", ";", "unset", "(", "$", "item", ")", ";", "}", "unset", "(", "$", "items", ")", ";", "}", "ksort", "(", "$", "result", ")", ";", "return", "$", "result", ";", "}" ]
Returns list of plugins of given type in given directory. @param string $plugintype @param string $fulldir @return array
[ "Returns", "list", "of", "plugins", "of", "given", "type", "in", "given", "directory", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L638-L678
213,817
moodle/moodle
lib/classes/component.php
core_component.fill_classmap_cache
protected static function fill_classmap_cache() { global $CFG; self::$classmap = array(); self::load_classes('core', "$CFG->dirroot/lib/classes"); foreach (self::$subsystems as $subsystem => $fulldir) { if (!$fulldir) { continue; } self::load_classes('core_'.$subsystem, "$fulldir/classes"); } foreach (self::$plugins as $plugintype => $plugins) { foreach ($plugins as $pluginname => $fulldir) { self::load_classes($plugintype.'_'.$pluginname, "$fulldir/classes"); } } ksort(self::$classmap); }
php
protected static function fill_classmap_cache() { global $CFG; self::$classmap = array(); self::load_classes('core', "$CFG->dirroot/lib/classes"); foreach (self::$subsystems as $subsystem => $fulldir) { if (!$fulldir) { continue; } self::load_classes('core_'.$subsystem, "$fulldir/classes"); } foreach (self::$plugins as $plugintype => $plugins) { foreach ($plugins as $pluginname => $fulldir) { self::load_classes($plugintype.'_'.$pluginname, "$fulldir/classes"); } } ksort(self::$classmap); }
[ "protected", "static", "function", "fill_classmap_cache", "(", ")", "{", "global", "$", "CFG", ";", "self", "::", "$", "classmap", "=", "array", "(", ")", ";", "self", "::", "load_classes", "(", "'core'", ",", "\"$CFG->dirroot/lib/classes\"", ")", ";", "foreach", "(", "self", "::", "$", "subsystems", "as", "$", "subsystem", "=>", "$", "fulldir", ")", "{", "if", "(", "!", "$", "fulldir", ")", "{", "continue", ";", "}", "self", "::", "load_classes", "(", "'core_'", ".", "$", "subsystem", ",", "\"$fulldir/classes\"", ")", ";", "}", "foreach", "(", "self", "::", "$", "plugins", "as", "$", "plugintype", "=>", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "pluginname", "=>", "$", "fulldir", ")", "{", "self", "::", "load_classes", "(", "$", "plugintype", ".", "'_'", ".", "$", "pluginname", ",", "\"$fulldir/classes\"", ")", ";", "}", "}", "ksort", "(", "self", "::", "$", "classmap", ")", ";", "}" ]
Find all classes that can be autoloaded including frankenstyle namespaces.
[ "Find", "all", "classes", "that", "can", "be", "autoloaded", "including", "frankenstyle", "namespaces", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L683-L703
213,818
moodle/moodle
lib/classes/component.php
core_component.fill_filemap_cache
protected static function fill_filemap_cache() { global $CFG; self::$filemap = array(); foreach (self::$filestomap as $file) { if (!isset(self::$filemap[$file])) { self::$filemap[$file] = array(); } foreach (self::$plugins as $plugintype => $plugins) { if (!isset(self::$filemap[$file][$plugintype])) { self::$filemap[$file][$plugintype] = array(); } foreach ($plugins as $pluginname => $fulldir) { if (file_exists("$fulldir/$file")) { self::$filemap[$file][$plugintype][$pluginname] = "$fulldir/$file"; } } } } }
php
protected static function fill_filemap_cache() { global $CFG; self::$filemap = array(); foreach (self::$filestomap as $file) { if (!isset(self::$filemap[$file])) { self::$filemap[$file] = array(); } foreach (self::$plugins as $plugintype => $plugins) { if (!isset(self::$filemap[$file][$plugintype])) { self::$filemap[$file][$plugintype] = array(); } foreach ($plugins as $pluginname => $fulldir) { if (file_exists("$fulldir/$file")) { self::$filemap[$file][$plugintype][$pluginname] = "$fulldir/$file"; } } } } }
[ "protected", "static", "function", "fill_filemap_cache", "(", ")", "{", "global", "$", "CFG", ";", "self", "::", "$", "filemap", "=", "array", "(", ")", ";", "foreach", "(", "self", "::", "$", "filestomap", "as", "$", "file", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "filemap", "[", "$", "file", "]", ")", ")", "{", "self", "::", "$", "filemap", "[", "$", "file", "]", "=", "array", "(", ")", ";", "}", "foreach", "(", "self", "::", "$", "plugins", "as", "$", "plugintype", "=>", "$", "plugins", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "filemap", "[", "$", "file", "]", "[", "$", "plugintype", "]", ")", ")", "{", "self", "::", "$", "filemap", "[", "$", "file", "]", "[", "$", "plugintype", "]", "=", "array", "(", ")", ";", "}", "foreach", "(", "$", "plugins", "as", "$", "pluginname", "=>", "$", "fulldir", ")", "{", "if", "(", "file_exists", "(", "\"$fulldir/$file\"", ")", ")", "{", "self", "::", "$", "filemap", "[", "$", "file", "]", "[", "$", "plugintype", "]", "[", "$", "pluginname", "]", "=", "\"$fulldir/$file\"", ";", "}", "}", "}", "}", "}" ]
Fills up the cache defining what plugins have certain files. @see self::get_plugin_list_with_file @return void
[ "Fills", "up", "the", "cache", "defining", "what", "plugins", "have", "certain", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L711-L731
213,819
moodle/moodle
lib/classes/component.php
core_component.load_classes
protected static function load_classes($component, $fulldir, $namespace = '') { if (!is_dir($fulldir)) { return; } if (!is_readable($fulldir)) { // TODO: MDL-51711 We should generate some diagnostic debugging information in this case // because its pretty likely to lead to a missing class error further down the line. // But our early setup code can't handle errors this early at the moment. return; } $items = new \DirectoryIterator($fulldir); foreach ($items as $item) { if ($item->isDot()) { continue; } if ($item->isDir()) { $dirname = $item->getFilename(); self::load_classes($component, "$fulldir/$dirname", $namespace.'\\'.$dirname); continue; } $filename = $item->getFilename(); $classname = preg_replace('/\.php$/', '', $filename); if ($filename === $classname) { // Not a php file. continue; } if ($namespace === '') { // Legacy long frankenstyle class name. self::$classmap[$component.'_'.$classname] = "$fulldir/$filename"; } // New namespaced classes. self::$classmap[$component.$namespace.'\\'.$classname] = "$fulldir/$filename"; } unset($item); unset($items); }
php
protected static function load_classes($component, $fulldir, $namespace = '') { if (!is_dir($fulldir)) { return; } if (!is_readable($fulldir)) { // TODO: MDL-51711 We should generate some diagnostic debugging information in this case // because its pretty likely to lead to a missing class error further down the line. // But our early setup code can't handle errors this early at the moment. return; } $items = new \DirectoryIterator($fulldir); foreach ($items as $item) { if ($item->isDot()) { continue; } if ($item->isDir()) { $dirname = $item->getFilename(); self::load_classes($component, "$fulldir/$dirname", $namespace.'\\'.$dirname); continue; } $filename = $item->getFilename(); $classname = preg_replace('/\.php$/', '', $filename); if ($filename === $classname) { // Not a php file. continue; } if ($namespace === '') { // Legacy long frankenstyle class name. self::$classmap[$component.'_'.$classname] = "$fulldir/$filename"; } // New namespaced classes. self::$classmap[$component.$namespace.'\\'.$classname] = "$fulldir/$filename"; } unset($item); unset($items); }
[ "protected", "static", "function", "load_classes", "(", "$", "component", ",", "$", "fulldir", ",", "$", "namespace", "=", "''", ")", "{", "if", "(", "!", "is_dir", "(", "$", "fulldir", ")", ")", "{", "return", ";", "}", "if", "(", "!", "is_readable", "(", "$", "fulldir", ")", ")", "{", "// TODO: MDL-51711 We should generate some diagnostic debugging information in this case", "// because its pretty likely to lead to a missing class error further down the line.", "// But our early setup code can't handle errors this early at the moment.", "return", ";", "}", "$", "items", "=", "new", "\\", "DirectoryIterator", "(", "$", "fulldir", ")", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "if", "(", "$", "item", "->", "isDot", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "item", "->", "isDir", "(", ")", ")", "{", "$", "dirname", "=", "$", "item", "->", "getFilename", "(", ")", ";", "self", "::", "load_classes", "(", "$", "component", ",", "\"$fulldir/$dirname\"", ",", "$", "namespace", ".", "'\\\\'", ".", "$", "dirname", ")", ";", "continue", ";", "}", "$", "filename", "=", "$", "item", "->", "getFilename", "(", ")", ";", "$", "classname", "=", "preg_replace", "(", "'/\\.php$/'", ",", "''", ",", "$", "filename", ")", ";", "if", "(", "$", "filename", "===", "$", "classname", ")", "{", "// Not a php file.", "continue", ";", "}", "if", "(", "$", "namespace", "===", "''", ")", "{", "// Legacy long frankenstyle class name.", "self", "::", "$", "classmap", "[", "$", "component", ".", "'_'", ".", "$", "classname", "]", "=", "\"$fulldir/$filename\"", ";", "}", "// New namespaced classes.", "self", "::", "$", "classmap", "[", "$", "component", ".", "$", "namespace", ".", "'\\\\'", ".", "$", "classname", "]", "=", "\"$fulldir/$filename\"", ";", "}", "unset", "(", "$", "item", ")", ";", "unset", "(", "$", "items", ")", ";", "}" ]
Find classes in directory and recurse to subdirs. @param string $component @param string $fulldir @param string $namespace
[ "Find", "classes", "in", "directory", "and", "recurse", "to", "subdirs", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L739-L778
213,820
moodle/moodle
lib/classes/component.php
core_component.get_plugin_list
public static function get_plugin_list($plugintype) { self::init(); if (!isset(self::$plugins[$plugintype])) { return array(); } return self::$plugins[$plugintype]; }
php
public static function get_plugin_list($plugintype) { self::init(); if (!isset(self::$plugins[$plugintype])) { return array(); } return self::$plugins[$plugintype]; }
[ "public", "static", "function", "get_plugin_list", "(", "$", "plugintype", ")", "{", "self", "::", "init", "(", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "plugins", "[", "$", "plugintype", "]", ")", ")", "{", "return", "array", "(", ")", ";", "}", "return", "self", "::", "$", "plugins", "[", "$", "plugintype", "]", ";", "}" ]
Get list of plugins of given type. @param string $plugintype @return array as (string)pluginname => (string)fulldir
[ "Get", "list", "of", "plugins", "of", "given", "type", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L816-L823
213,821
moodle/moodle
lib/classes/component.php
core_component.get_plugin_list_with_class
public static function get_plugin_list_with_class($plugintype, $class, $file = null) { global $CFG; // Necessary in case it is referenced by included PHP scripts. if ($class) { $suffix = '_' . $class; } else { $suffix = ''; } $pluginclasses = array(); $plugins = self::get_plugin_list($plugintype); foreach ($plugins as $plugin => $fulldir) { // Try class in frankenstyle namespace. if ($class) { $classname = '\\' . $plugintype . '_' . $plugin . '\\' . $class; if (class_exists($classname, true)) { $pluginclasses[$plugintype . '_' . $plugin] = $classname; continue; } } // Try autoloading of class with frankenstyle prefix. $classname = $plugintype . '_' . $plugin . $suffix; if (class_exists($classname, true)) { $pluginclasses[$plugintype . '_' . $plugin] = $classname; continue; } // Fall back to old file location and class name. if ($file and file_exists("$fulldir/$file")) { include_once("$fulldir/$file"); if (class_exists($classname, false)) { $pluginclasses[$plugintype . '_' . $plugin] = $classname; continue; } } } return $pluginclasses; }
php
public static function get_plugin_list_with_class($plugintype, $class, $file = null) { global $CFG; // Necessary in case it is referenced by included PHP scripts. if ($class) { $suffix = '_' . $class; } else { $suffix = ''; } $pluginclasses = array(); $plugins = self::get_plugin_list($plugintype); foreach ($plugins as $plugin => $fulldir) { // Try class in frankenstyle namespace. if ($class) { $classname = '\\' . $plugintype . '_' . $plugin . '\\' . $class; if (class_exists($classname, true)) { $pluginclasses[$plugintype . '_' . $plugin] = $classname; continue; } } // Try autoloading of class with frankenstyle prefix. $classname = $plugintype . '_' . $plugin . $suffix; if (class_exists($classname, true)) { $pluginclasses[$plugintype . '_' . $plugin] = $classname; continue; } // Fall back to old file location and class name. if ($file and file_exists("$fulldir/$file")) { include_once("$fulldir/$file"); if (class_exists($classname, false)) { $pluginclasses[$plugintype . '_' . $plugin] = $classname; continue; } } } return $pluginclasses; }
[ "public", "static", "function", "get_plugin_list_with_class", "(", "$", "plugintype", ",", "$", "class", ",", "$", "file", "=", "null", ")", "{", "global", "$", "CFG", ";", "// Necessary in case it is referenced by included PHP scripts.", "if", "(", "$", "class", ")", "{", "$", "suffix", "=", "'_'", ".", "$", "class", ";", "}", "else", "{", "$", "suffix", "=", "''", ";", "}", "$", "pluginclasses", "=", "array", "(", ")", ";", "$", "plugins", "=", "self", "::", "get_plugin_list", "(", "$", "plugintype", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", "=>", "$", "fulldir", ")", "{", "// Try class in frankenstyle namespace.", "if", "(", "$", "class", ")", "{", "$", "classname", "=", "'\\\\'", ".", "$", "plugintype", ".", "'_'", ".", "$", "plugin", ".", "'\\\\'", ".", "$", "class", ";", "if", "(", "class_exists", "(", "$", "classname", ",", "true", ")", ")", "{", "$", "pluginclasses", "[", "$", "plugintype", ".", "'_'", ".", "$", "plugin", "]", "=", "$", "classname", ";", "continue", ";", "}", "}", "// Try autoloading of class with frankenstyle prefix.", "$", "classname", "=", "$", "plugintype", ".", "'_'", ".", "$", "plugin", ".", "$", "suffix", ";", "if", "(", "class_exists", "(", "$", "classname", ",", "true", ")", ")", "{", "$", "pluginclasses", "[", "$", "plugintype", ".", "'_'", ".", "$", "plugin", "]", "=", "$", "classname", ";", "continue", ";", "}", "// Fall back to old file location and class name.", "if", "(", "$", "file", "and", "file_exists", "(", "\"$fulldir/$file\"", ")", ")", "{", "include_once", "(", "\"$fulldir/$file\"", ")", ";", "if", "(", "class_exists", "(", "$", "classname", ",", "false", ")", ")", "{", "$", "pluginclasses", "[", "$", "plugintype", ".", "'_'", ".", "$", "plugin", "]", "=", "$", "classname", ";", "continue", ";", "}", "}", "}", "return", "$", "pluginclasses", ";", "}" ]
Get a list of all the plugins of a given type that define a certain class in a certain file. The plugin component names and class names are returned. @param string $plugintype the type of plugin, e.g. 'mod' or 'report'. @param string $class the part of the name of the class after the frankenstyle prefix. e.g 'thing' if you are looking for classes with names like report_courselist_thing. If you are looking for classes with the same name as the plugin name (e.g. qtype_multichoice) then pass ''. Frankenstyle namespaces are also supported. @param string $file the name of file within the plugin that defines the class. @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum') and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
[ "Get", "a", "list", "of", "all", "the", "plugins", "of", "a", "given", "type", "that", "define", "a", "certain", "class", "in", "a", "certain", "file", ".", "The", "plugin", "component", "names", "and", "class", "names", "are", "returned", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L839-L878
213,822
moodle/moodle
lib/classes/component.php
core_component.get_plugin_list_with_file
public static function get_plugin_list_with_file($plugintype, $file, $include = false) { global $CFG; // Necessary in case it is referenced by included PHP scripts. $pluginfiles = array(); if (isset(self::$filemap[$file])) { // If the file was supposed to be mapped, then it should have been set in the array. if (isset(self::$filemap[$file][$plugintype])) { $pluginfiles = self::$filemap[$file][$plugintype]; } } else { // Old-style search for non-cached files. $plugins = self::get_plugin_list($plugintype); foreach ($plugins as $plugin => $fulldir) { $path = $fulldir . '/' . $file; if (file_exists($path)) { $pluginfiles[$plugin] = $path; } } } if ($include) { foreach ($pluginfiles as $path) { include_once($path); } } return $pluginfiles; }
php
public static function get_plugin_list_with_file($plugintype, $file, $include = false) { global $CFG; // Necessary in case it is referenced by included PHP scripts. $pluginfiles = array(); if (isset(self::$filemap[$file])) { // If the file was supposed to be mapped, then it should have been set in the array. if (isset(self::$filemap[$file][$plugintype])) { $pluginfiles = self::$filemap[$file][$plugintype]; } } else { // Old-style search for non-cached files. $plugins = self::get_plugin_list($plugintype); foreach ($plugins as $plugin => $fulldir) { $path = $fulldir . '/' . $file; if (file_exists($path)) { $pluginfiles[$plugin] = $path; } } } if ($include) { foreach ($pluginfiles as $path) { include_once($path); } } return $pluginfiles; }
[ "public", "static", "function", "get_plugin_list_with_file", "(", "$", "plugintype", ",", "$", "file", ",", "$", "include", "=", "false", ")", "{", "global", "$", "CFG", ";", "// Necessary in case it is referenced by included PHP scripts.", "$", "pluginfiles", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "self", "::", "$", "filemap", "[", "$", "file", "]", ")", ")", "{", "// If the file was supposed to be mapped, then it should have been set in the array.", "if", "(", "isset", "(", "self", "::", "$", "filemap", "[", "$", "file", "]", "[", "$", "plugintype", "]", ")", ")", "{", "$", "pluginfiles", "=", "self", "::", "$", "filemap", "[", "$", "file", "]", "[", "$", "plugintype", "]", ";", "}", "}", "else", "{", "// Old-style search for non-cached files.", "$", "plugins", "=", "self", "::", "get_plugin_list", "(", "$", "plugintype", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", "=>", "$", "fulldir", ")", "{", "$", "path", "=", "$", "fulldir", ".", "'/'", ".", "$", "file", ";", "if", "(", "file_exists", "(", "$", "path", ")", ")", "{", "$", "pluginfiles", "[", "$", "plugin", "]", "=", "$", "path", ";", "}", "}", "}", "if", "(", "$", "include", ")", "{", "foreach", "(", "$", "pluginfiles", "as", "$", "path", ")", "{", "include_once", "(", "$", "path", ")", ";", "}", "}", "return", "$", "pluginfiles", ";", "}" ]
Get a list of all the plugins of a given type that contain a particular file. @param string $plugintype the type of plugin, e.g. 'mod' or 'report'. @param string $file the name of file that must be present in the plugin. (e.g. 'view.php', 'db/install.xml'). @param bool $include if true (default false), the file will be include_once-ed if found. @return array with plugin name as keys (e.g. 'forum', 'courselist') and the path to the file relative to dirroot as value (e.g. "$CFG->dirroot/mod/forum/view.php").
[ "Get", "a", "list", "of", "all", "the", "plugins", "of", "a", "given", "type", "that", "contain", "a", "particular", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L890-L917
213,823
moodle/moodle
lib/classes/component.php
core_component.get_component_classes_in_namespace
public static function get_component_classes_in_namespace($component = null, $namespace = '') { $classes = array(); // Only look for components if a component name is set or a namespace is set. if (isset($component) || !empty($namespace)) { // If a component parameter value is set we only want to look in that component. // Otherwise we want to check all components. $component = (isset($component)) ? self::normalize_componentname($component) : '\w+'; if ($namespace) { // We will add them later. $namespace = trim($namespace, '\\'); // We need add double backslashes as it is how classes are stored into self::$classmap. $namespace = implode('\\\\', explode('\\', $namespace)); $namespace = $namespace . '\\\\'; } $regex = '|^' . $component . '\\\\' . $namespace . '|'; $it = new RegexIterator(new ArrayIterator(self::$classmap), $regex, RegexIterator::GET_MATCH, RegexIterator::USE_KEY); // We want to be sure that they exist. foreach ($it as $classname => $classpath) { if (class_exists($classname)) { $classes[$classname] = $classpath; } } } return $classes; }
php
public static function get_component_classes_in_namespace($component = null, $namespace = '') { $classes = array(); // Only look for components if a component name is set or a namespace is set. if (isset($component) || !empty($namespace)) { // If a component parameter value is set we only want to look in that component. // Otherwise we want to check all components. $component = (isset($component)) ? self::normalize_componentname($component) : '\w+'; if ($namespace) { // We will add them later. $namespace = trim($namespace, '\\'); // We need add double backslashes as it is how classes are stored into self::$classmap. $namespace = implode('\\\\', explode('\\', $namespace)); $namespace = $namespace . '\\\\'; } $regex = '|^' . $component . '\\\\' . $namespace . '|'; $it = new RegexIterator(new ArrayIterator(self::$classmap), $regex, RegexIterator::GET_MATCH, RegexIterator::USE_KEY); // We want to be sure that they exist. foreach ($it as $classname => $classpath) { if (class_exists($classname)) { $classes[$classname] = $classpath; } } } return $classes; }
[ "public", "static", "function", "get_component_classes_in_namespace", "(", "$", "component", "=", "null", ",", "$", "namespace", "=", "''", ")", "{", "$", "classes", "=", "array", "(", ")", ";", "// Only look for components if a component name is set or a namespace is set.", "if", "(", "isset", "(", "$", "component", ")", "||", "!", "empty", "(", "$", "namespace", ")", ")", "{", "// If a component parameter value is set we only want to look in that component.", "// Otherwise we want to check all components.", "$", "component", "=", "(", "isset", "(", "$", "component", ")", ")", "?", "self", "::", "normalize_componentname", "(", "$", "component", ")", ":", "'\\w+'", ";", "if", "(", "$", "namespace", ")", "{", "// We will add them later.", "$", "namespace", "=", "trim", "(", "$", "namespace", ",", "'\\\\'", ")", ";", "// We need add double backslashes as it is how classes are stored into self::$classmap.", "$", "namespace", "=", "implode", "(", "'\\\\\\\\'", ",", "explode", "(", "'\\\\'", ",", "$", "namespace", ")", ")", ";", "$", "namespace", "=", "$", "namespace", ".", "'\\\\\\\\'", ";", "}", "$", "regex", "=", "'|^'", ".", "$", "component", ".", "'\\\\\\\\'", ".", "$", "namespace", ".", "'|'", ";", "$", "it", "=", "new", "RegexIterator", "(", "new", "ArrayIterator", "(", "self", "::", "$", "classmap", ")", ",", "$", "regex", ",", "RegexIterator", "::", "GET_MATCH", ",", "RegexIterator", "::", "USE_KEY", ")", ";", "// We want to be sure that they exist.", "foreach", "(", "$", "it", "as", "$", "classname", "=>", "$", "classpath", ")", "{", "if", "(", "class_exists", "(", "$", "classname", ")", ")", "{", "$", "classes", "[", "$", "classname", "]", "=", "$", "classpath", ";", "}", "}", "}", "return", "$", "classes", ";", "}" ]
Returns all classes in a component matching the provided namespace. It checks that the class exists. e.g. get_component_classes_in_namespace('mod_forum', 'event') @param string|null $component A valid moodle component (frankenstyle) or null if searching all components @param string $namespace Namespace from the component name or empty string if all $component classes. @return array The full class name as key and the class path as value, empty array if $component is `null` and $namespace is empty.
[ "Returns", "all", "classes", "in", "a", "component", "matching", "the", "provided", "namespace", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L931-L962
213,824
moodle/moodle
lib/classes/component.php
core_component.is_valid_plugin_name
public static function is_valid_plugin_name($plugintype, $pluginname) { if ($plugintype === 'mod') { // Modules must not have the same name as core subsystems. if (!isset(self::$subsystems)) { // Watch out, this is called from init! self::init(); } if (isset(self::$subsystems[$pluginname])) { return false; } // Modules MUST NOT have any underscores, // component normalisation would break very badly otherwise! return (bool)preg_match('/^[a-z][a-z0-9]*$/', $pluginname); } else { return (bool)preg_match('/^[a-z](?:[a-z0-9_](?!__))*[a-z0-9]+$/', $pluginname); } }
php
public static function is_valid_plugin_name($plugintype, $pluginname) { if ($plugintype === 'mod') { // Modules must not have the same name as core subsystems. if (!isset(self::$subsystems)) { // Watch out, this is called from init! self::init(); } if (isset(self::$subsystems[$pluginname])) { return false; } // Modules MUST NOT have any underscores, // component normalisation would break very badly otherwise! return (bool)preg_match('/^[a-z][a-z0-9]*$/', $pluginname); } else { return (bool)preg_match('/^[a-z](?:[a-z0-9_](?!__))*[a-z0-9]+$/', $pluginname); } }
[ "public", "static", "function", "is_valid_plugin_name", "(", "$", "plugintype", ",", "$", "pluginname", ")", "{", "if", "(", "$", "plugintype", "===", "'mod'", ")", "{", "// Modules must not have the same name as core subsystems.", "if", "(", "!", "isset", "(", "self", "::", "$", "subsystems", ")", ")", "{", "// Watch out, this is called from init!", "self", "::", "init", "(", ")", ";", "}", "if", "(", "isset", "(", "self", "::", "$", "subsystems", "[", "$", "pluginname", "]", ")", ")", "{", "return", "false", ";", "}", "// Modules MUST NOT have any underscores,", "// component normalisation would break very badly otherwise!", "return", "(", "bool", ")", "preg_match", "(", "'/^[a-z][a-z0-9]*$/'", ",", "$", "pluginname", ")", ";", "}", "else", "{", "return", "(", "bool", ")", "preg_match", "(", "'/^[a-z](?:[a-z0-9_](?!__))*[a-z0-9]+$/'", ",", "$", "pluginname", ")", ";", "}", "}" ]
This method validates a plug name. It is much faster than calling clean_param. @param string $plugintype type of plugin @param string $pluginname a string that might be a plugin name. @return bool if this string is a valid plugin name.
[ "This", "method", "validates", "a", "plug", "name", ".", "It", "is", "much", "faster", "than", "calling", "clean_param", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L1007-L1024
213,825
moodle/moodle
lib/classes/component.php
core_component.normalize_componentname
public static function normalize_componentname($componentname) { list($plugintype, $pluginname) = self::normalize_component($componentname); if ($plugintype === 'core' && is_null($pluginname)) { return $plugintype; } return $plugintype . '_' . $pluginname; }
php
public static function normalize_componentname($componentname) { list($plugintype, $pluginname) = self::normalize_component($componentname); if ($plugintype === 'core' && is_null($pluginname)) { return $plugintype; } return $plugintype . '_' . $pluginname; }
[ "public", "static", "function", "normalize_componentname", "(", "$", "componentname", ")", "{", "list", "(", "$", "plugintype", ",", "$", "pluginname", ")", "=", "self", "::", "normalize_component", "(", "$", "componentname", ")", ";", "if", "(", "$", "plugintype", "===", "'core'", "&&", "is_null", "(", "$", "pluginname", ")", ")", "{", "return", "$", "plugintype", ";", "}", "return", "$", "plugintype", ".", "'_'", ".", "$", "pluginname", ";", "}" ]
Normalize the component name. Note: this does not verify the validity of the plugin or component. @param string $component @return string
[ "Normalize", "the", "component", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L1034-L1040
213,826
moodle/moodle
lib/classes/component.php
core_component.normalize_component
public static function normalize_component($component) { if ($component === 'moodle' or $component === 'core' or $component === '') { return array('core', null); } if (strpos($component, '_') === false) { self::init(); if (array_key_exists($component, self::$subsystems)) { $type = 'core'; $plugin = $component; } else { // Everything else without underscore is a module. $type = 'mod'; $plugin = $component; } } else { list($type, $plugin) = explode('_', $component, 2); if ($type === 'moodle') { $type = 'core'; } // Any unknown type must be a subplugin. } return array($type, $plugin); }
php
public static function normalize_component($component) { if ($component === 'moodle' or $component === 'core' or $component === '') { return array('core', null); } if (strpos($component, '_') === false) { self::init(); if (array_key_exists($component, self::$subsystems)) { $type = 'core'; $plugin = $component; } else { // Everything else without underscore is a module. $type = 'mod'; $plugin = $component; } } else { list($type, $plugin) = explode('_', $component, 2); if ($type === 'moodle') { $type = 'core'; } // Any unknown type must be a subplugin. } return array($type, $plugin); }
[ "public", "static", "function", "normalize_component", "(", "$", "component", ")", "{", "if", "(", "$", "component", "===", "'moodle'", "or", "$", "component", "===", "'core'", "or", "$", "component", "===", "''", ")", "{", "return", "array", "(", "'core'", ",", "null", ")", ";", "}", "if", "(", "strpos", "(", "$", "component", ",", "'_'", ")", "===", "false", ")", "{", "self", "::", "init", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "component", ",", "self", "::", "$", "subsystems", ")", ")", "{", "$", "type", "=", "'core'", ";", "$", "plugin", "=", "$", "component", ";", "}", "else", "{", "// Everything else without underscore is a module.", "$", "type", "=", "'mod'", ";", "$", "plugin", "=", "$", "component", ";", "}", "}", "else", "{", "list", "(", "$", "type", ",", "$", "plugin", ")", "=", "explode", "(", "'_'", ",", "$", "component", ",", "2", ")", ";", "if", "(", "$", "type", "===", "'moodle'", ")", "{", "$", "type", "=", "'core'", ";", "}", "// Any unknown type must be a subplugin.", "}", "return", "array", "(", "$", "type", ",", "$", "plugin", ")", ";", "}" ]
Normalize the component name using the "frankenstyle" rules. Note: this does not verify the validity of plugin or type names. @param string $component @return array two-items list of [(string)type, (string|null)name]
[ "Normalize", "the", "component", "name", "using", "the", "frankenstyle", "rules", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L1050-L1075
213,827
moodle/moodle
lib/classes/component.php
core_component.get_component_directory
public static function get_component_directory($component) { global $CFG; list($type, $plugin) = self::normalize_component($component); if ($type === 'core') { if ($plugin === null) { return $path = $CFG->libdir; } return self::get_subsystem_directory($plugin); } return self::get_plugin_directory($type, $plugin); }
php
public static function get_component_directory($component) { global $CFG; list($type, $plugin) = self::normalize_component($component); if ($type === 'core') { if ($plugin === null) { return $path = $CFG->libdir; } return self::get_subsystem_directory($plugin); } return self::get_plugin_directory($type, $plugin); }
[ "public", "static", "function", "get_component_directory", "(", "$", "component", ")", "{", "global", "$", "CFG", ";", "list", "(", "$", "type", ",", "$", "plugin", ")", "=", "self", "::", "normalize_component", "(", "$", "component", ")", ";", "if", "(", "$", "type", "===", "'core'", ")", "{", "if", "(", "$", "plugin", "===", "null", ")", "{", "return", "$", "path", "=", "$", "CFG", "->", "libdir", ";", "}", "return", "self", "::", "get_subsystem_directory", "(", "$", "plugin", ")", ";", "}", "return", "self", "::", "get_plugin_directory", "(", "$", "type", ",", "$", "plugin", ")", ";", "}" ]
Return exact absolute path to a plugin directory. @param string $component name such as 'moodle', 'mod_forum' @return string full path to component directory; NULL if not found
[ "Return", "exact", "absolute", "path", "to", "a", "plugin", "directory", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L1083-L1096
213,828
moodle/moodle
lib/classes/component.php
core_component.get_plugin_types_with_subplugins
public static function get_plugin_types_with_subplugins() { self::init(); $return = array(); foreach (self::$supportsubplugins as $type) { $return[$type] = self::$plugintypes[$type]; } return $return; }
php
public static function get_plugin_types_with_subplugins() { self::init(); $return = array(); foreach (self::$supportsubplugins as $type) { $return[$type] = self::$plugintypes[$type]; } return $return; }
[ "public", "static", "function", "get_plugin_types_with_subplugins", "(", ")", "{", "self", "::", "init", "(", ")", ";", "$", "return", "=", "array", "(", ")", ";", "foreach", "(", "self", "::", "$", "supportsubplugins", "as", "$", "type", ")", "{", "$", "return", "[", "$", "type", "]", "=", "self", "::", "$", "plugintypes", "[", "$", "type", "]", ";", "}", "return", "$", "return", ";", "}" ]
Returns list of plugin types that allow subplugins. @return array as (string)plugintype => (string)fulldir
[ "Returns", "list", "of", "plugin", "types", "that", "allow", "subplugins", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L1102-L1110
213,829
moodle/moodle
lib/classes/component.php
core_component.get_subtype_parent
public static function get_subtype_parent($type) { self::init(); if (isset(self::$parents[$type])) { return self::$parents[$type]; } return null; }
php
public static function get_subtype_parent($type) { self::init(); if (isset(self::$parents[$type])) { return self::$parents[$type]; } return null; }
[ "public", "static", "function", "get_subtype_parent", "(", "$", "type", ")", "{", "self", "::", "init", "(", ")", ";", "if", "(", "isset", "(", "self", "::", "$", "parents", "[", "$", "type", "]", ")", ")", "{", "return", "self", "::", "$", "parents", "[", "$", "type", "]", ";", "}", "return", "null", ";", "}" ]
Returns parent of this subplugin type. @param string $type @return string parent component or null
[ "Returns", "parent", "of", "this", "subplugin", "type", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L1118-L1126
213,830
moodle/moodle
lib/classes/component.php
core_component.get_subplugins
public static function get_subplugins($component) { self::init(); if (isset(self::$subplugins[$component])) { return self::$subplugins[$component]; } return null; }
php
public static function get_subplugins($component) { self::init(); if (isset(self::$subplugins[$component])) { return self::$subplugins[$component]; } return null; }
[ "public", "static", "function", "get_subplugins", "(", "$", "component", ")", "{", "self", "::", "init", "(", ")", ";", "if", "(", "isset", "(", "self", "::", "$", "subplugins", "[", "$", "component", "]", ")", ")", "{", "return", "self", "::", "$", "subplugins", "[", "$", "component", "]", ";", "}", "return", "null", ";", "}" ]
Return all subplugins of this component. @param string $component. @return array $subtype=>array($component, ..), null if no subtypes defined
[ "Return", "all", "subplugins", "of", "this", "component", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L1133-L1141
213,831
moodle/moodle
lib/classes/component.php
core_component.get_all_versions
public static function get_all_versions() : array { global $CFG; self::init(); $versions = array(); // Main version first. $versions['core'] = self::fetch_core_version(); // The problem here is tha the component cache might be stable, // we want this to work also on frontpage without resetting the component cache. $usecache = false; if (CACHE_DISABLE_ALL or (defined('IGNORE_COMPONENT_CACHE') and IGNORE_COMPONENT_CACHE)) { $usecache = true; } // Now all plugins. $plugintypes = core_component::get_plugin_types(); foreach ($plugintypes as $type => $typedir) { if ($usecache) { $plugs = core_component::get_plugin_list($type); } else { $plugs = self::fetch_plugins($type, $typedir); } foreach ($plugs as $plug => $fullplug) { $plugin = new stdClass(); $plugin->version = null; $module = $plugin; include($fullplug.'/version.php'); $versions[$type.'_'.$plug] = $plugin->version; } } return $versions; }
php
public static function get_all_versions() : array { global $CFG; self::init(); $versions = array(); // Main version first. $versions['core'] = self::fetch_core_version(); // The problem here is tha the component cache might be stable, // we want this to work also on frontpage without resetting the component cache. $usecache = false; if (CACHE_DISABLE_ALL or (defined('IGNORE_COMPONENT_CACHE') and IGNORE_COMPONENT_CACHE)) { $usecache = true; } // Now all plugins. $plugintypes = core_component::get_plugin_types(); foreach ($plugintypes as $type => $typedir) { if ($usecache) { $plugs = core_component::get_plugin_list($type); } else { $plugs = self::fetch_plugins($type, $typedir); } foreach ($plugs as $plug => $fullplug) { $plugin = new stdClass(); $plugin->version = null; $module = $plugin; include($fullplug.'/version.php'); $versions[$type.'_'.$plug] = $plugin->version; } } return $versions; }
[ "public", "static", "function", "get_all_versions", "(", ")", ":", "array", "{", "global", "$", "CFG", ";", "self", "::", "init", "(", ")", ";", "$", "versions", "=", "array", "(", ")", ";", "// Main version first.", "$", "versions", "[", "'core'", "]", "=", "self", "::", "fetch_core_version", "(", ")", ";", "// The problem here is tha the component cache might be stable,", "// we want this to work also on frontpage without resetting the component cache.", "$", "usecache", "=", "false", ";", "if", "(", "CACHE_DISABLE_ALL", "or", "(", "defined", "(", "'IGNORE_COMPONENT_CACHE'", ")", "and", "IGNORE_COMPONENT_CACHE", ")", ")", "{", "$", "usecache", "=", "true", ";", "}", "// Now all plugins.", "$", "plugintypes", "=", "core_component", "::", "get_plugin_types", "(", ")", ";", "foreach", "(", "$", "plugintypes", "as", "$", "type", "=>", "$", "typedir", ")", "{", "if", "(", "$", "usecache", ")", "{", "$", "plugs", "=", "core_component", "::", "get_plugin_list", "(", "$", "type", ")", ";", "}", "else", "{", "$", "plugs", "=", "self", "::", "fetch_plugins", "(", "$", "type", ",", "$", "typedir", ")", ";", "}", "foreach", "(", "$", "plugs", "as", "$", "plug", "=>", "$", "fullplug", ")", "{", "$", "plugin", "=", "new", "stdClass", "(", ")", ";", "$", "plugin", "->", "version", "=", "null", ";", "$", "module", "=", "$", "plugin", ";", "include", "(", "$", "fullplug", ".", "'/version.php'", ")", ";", "$", "versions", "[", "$", "type", ".", "'_'", ".", "$", "plug", "]", "=", "$", "plugin", "->", "version", ";", "}", "}", "return", "$", "versions", ";", "}" ]
Returns hash of all versions including core and all plugins. This is relatively slow and not fully cached, use with care! @return array as (string)plugintype_pluginname => (int)version
[ "Returns", "hash", "of", "all", "versions", "including", "core", "and", "all", "plugins", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L1161-L1196
213,832
moodle/moodle
lib/classes/component.php
core_component.fill_classmap_renames_cache
protected static function fill_classmap_renames_cache() { global $CFG; self::$classmaprenames = array(); self::load_renamed_classes("$CFG->dirroot/lib/"); foreach (self::$subsystems as $subsystem => $fulldir) { self::load_renamed_classes($fulldir); } foreach (self::$plugins as $plugintype => $plugins) { foreach ($plugins as $pluginname => $fulldir) { self::load_renamed_classes($fulldir); } } }
php
protected static function fill_classmap_renames_cache() { global $CFG; self::$classmaprenames = array(); self::load_renamed_classes("$CFG->dirroot/lib/"); foreach (self::$subsystems as $subsystem => $fulldir) { self::load_renamed_classes($fulldir); } foreach (self::$plugins as $plugintype => $plugins) { foreach ($plugins as $pluginname => $fulldir) { self::load_renamed_classes($fulldir); } } }
[ "protected", "static", "function", "fill_classmap_renames_cache", "(", ")", "{", "global", "$", "CFG", ";", "self", "::", "$", "classmaprenames", "=", "array", "(", ")", ";", "self", "::", "load_renamed_classes", "(", "\"$CFG->dirroot/lib/\"", ")", ";", "foreach", "(", "self", "::", "$", "subsystems", "as", "$", "subsystem", "=>", "$", "fulldir", ")", "{", "self", "::", "load_renamed_classes", "(", "$", "fulldir", ")", ";", "}", "foreach", "(", "self", "::", "$", "plugins", "as", "$", "plugintype", "=>", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "pluginname", "=>", "$", "fulldir", ")", "{", "self", "::", "load_renamed_classes", "(", "$", "fulldir", ")", ";", "}", "}", "}" ]
Records all class renames that have been made to facilitate autoloading.
[ "Records", "all", "class", "renames", "that", "have", "been", "made", "to", "facilitate", "autoloading", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L1228-L1244
213,833
moodle/moodle
lib/classes/component.php
core_component.get_component_names
public static function get_component_names() : array { $componentnames = []; // Get all plugins. foreach (self::get_plugin_types() as $plugintype => $typedir) { foreach (self::get_plugin_list($plugintype) as $pluginname => $plugindir) { $componentnames[] = $plugintype . '_' . $pluginname; } } // Get all subsystems. foreach (self::get_core_subsystems() as $subsystemname => $subsystempath) { $componentnames[] = 'core_' . $subsystemname; } return $componentnames; }
php
public static function get_component_names() : array { $componentnames = []; // Get all plugins. foreach (self::get_plugin_types() as $plugintype => $typedir) { foreach (self::get_plugin_list($plugintype) as $pluginname => $plugindir) { $componentnames[] = $plugintype . '_' . $pluginname; } } // Get all subsystems. foreach (self::get_core_subsystems() as $subsystemname => $subsystempath) { $componentnames[] = 'core_' . $subsystemname; } return $componentnames; }
[ "public", "static", "function", "get_component_names", "(", ")", ":", "array", "{", "$", "componentnames", "=", "[", "]", ";", "// Get all plugins.", "foreach", "(", "self", "::", "get_plugin_types", "(", ")", "as", "$", "plugintype", "=>", "$", "typedir", ")", "{", "foreach", "(", "self", "::", "get_plugin_list", "(", "$", "plugintype", ")", "as", "$", "pluginname", "=>", "$", "plugindir", ")", "{", "$", "componentnames", "[", "]", "=", "$", "plugintype", ".", "'_'", ".", "$", "pluginname", ";", "}", "}", "// Get all subsystems.", "foreach", "(", "self", "::", "get_core_subsystems", "(", ")", "as", "$", "subsystemname", "=>", "$", "subsystempath", ")", "{", "$", "componentnames", "[", "]", "=", "'core_'", ".", "$", "subsystemname", ";", "}", "return", "$", "componentnames", ";", "}" ]
Returns a list of frankenstyle component names. E.g. [ 'core_course', 'core_message', 'mod_assign', ... ] @return array the list of frankenstyle component names.
[ "Returns", "a", "list", "of", "frankenstyle", "component", "names", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/component.php#L1314-L1327
213,834
moodle/moodle
admin/webservice/lib.php
service_user_selector.get_options
protected function get_options() { global $CFG; $options = parent::get_options(); $options['file'] = $CFG->admin.'/webservice/lib.php'; //need to be set, otherwise // the /user/selector/search.php //will fail to find this user_selector class $options['serviceid'] = $this->serviceid; $options['displayallowedusers'] = $this->displayallowedusers; return $options; }
php
protected function get_options() { global $CFG; $options = parent::get_options(); $options['file'] = $CFG->admin.'/webservice/lib.php'; //need to be set, otherwise // the /user/selector/search.php //will fail to find this user_selector class $options['serviceid'] = $this->serviceid; $options['displayallowedusers'] = $this->displayallowedusers; return $options; }
[ "protected", "function", "get_options", "(", ")", "{", "global", "$", "CFG", ";", "$", "options", "=", "parent", "::", "get_options", "(", ")", ";", "$", "options", "[", "'file'", "]", "=", "$", "CFG", "->", "admin", ".", "'/webservice/lib.php'", ";", "//need to be set, otherwise", "// the /user/selector/search.php", "//will fail to find this user_selector class", "$", "options", "[", "'serviceid'", "]", "=", "$", "this", "->", "serviceid", ";", "$", "options", "[", "'displayallowedusers'", "]", "=", "$", "this", "->", "displayallowedusers", ";", "return", "$", "options", ";", "}" ]
This options are automatically used by the AJAX search @global object $CFG @return object options pass to the constructor when AJAX search call a new selector
[ "This", "options", "are", "automatically", "used", "by", "the", "AJAX", "search" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/webservice/lib.php#L117-L126
213,835
moodle/moodle
backup/util/plan/base_task.class.php
base_task.add_result
public function add_result($result) { if (!is_null($this->plan)) { $this->plan->add_result($result); } else { debugging('Attempting to add a result of a task not binded with a plan', DEBUG_DEVELOPER); } }
php
public function add_result($result) { if (!is_null($this->plan)) { $this->plan->add_result($result); } else { debugging('Attempting to add a result of a task not binded with a plan', DEBUG_DEVELOPER); } }
[ "public", "function", "add_result", "(", "$", "result", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "plan", ")", ")", "{", "$", "this", "->", "plan", "->", "add_result", "(", "$", "result", ")", ";", "}", "else", "{", "debugging", "(", "'Attempting to add a result of a task not binded with a plan'", ",", "DEBUG_DEVELOPER", ")", ";", "}", "}" ]
Add the given info to the current plan's results. @see base_plan::add_result() @param array $result associative array describing a result of a task/step
[ "Add", "the", "given", "info", "to", "the", "current", "plan", "s", "results", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/plan/base_task.class.php#L233-L239
213,836
moodle/moodle
backup/util/plan/base_task.class.php
base_task.get_results
public function get_results() { if (!is_null($this->plan)) { return $this->plan->get_results(); } else { debugging('Attempting to get results of a task not binded with a plan', DEBUG_DEVELOPER); return null; } }
php
public function get_results() { if (!is_null($this->plan)) { return $this->plan->get_results(); } else { debugging('Attempting to get results of a task not binded with a plan', DEBUG_DEVELOPER); return null; } }
[ "public", "function", "get_results", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "plan", ")", ")", "{", "return", "$", "this", "->", "plan", "->", "get_results", "(", ")", ";", "}", "else", "{", "debugging", "(", "'Attempting to get results of a task not binded with a plan'", ",", "DEBUG_DEVELOPER", ")", ";", "return", "null", ";", "}", "}" ]
Return the current plan's results @return array|null
[ "Return", "the", "current", "plan", "s", "results" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/plan/base_task.class.php#L246-L253
213,837
moodle/moodle
mod/assign/classes/event/course_module_instance_list_viewed.php
course_module_instance_list_viewed.create_from_course
public static function create_from_course(\stdClass $course) { $params = array( 'context' => \context_course::instance($course->id) ); $event = \mod_assign\event\course_module_instance_list_viewed::create($params); $event->add_record_snapshot('course', $course); return $event; }
php
public static function create_from_course(\stdClass $course) { $params = array( 'context' => \context_course::instance($course->id) ); $event = \mod_assign\event\course_module_instance_list_viewed::create($params); $event->add_record_snapshot('course', $course); return $event; }
[ "public", "static", "function", "create_from_course", "(", "\\", "stdClass", "$", "course", ")", "{", "$", "params", "=", "array", "(", "'context'", "=>", "\\", "context_course", "::", "instance", "(", "$", "course", "->", "id", ")", ")", ";", "$", "event", "=", "\\", "mod_assign", "\\", "event", "\\", "course_module_instance_list_viewed", "::", "create", "(", "$", "params", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'course'", ",", "$", "course", ")", ";", "return", "$", "event", ";", "}" ]
Create the event from course record. @param \stdClass $course @return course_module_instance_list_viewed
[ "Create", "the", "event", "from", "course", "record", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/event/course_module_instance_list_viewed.php#L44-L51
213,838
moodle/moodle
question/previewlib.php
question_preview_options.load_user_defaults
public function load_user_defaults() { $defaults = get_config('question_preview'); foreach ($this->get_user_pref_fields() as $field) { $this->$field = get_user_preferences( self::OPTIONPREFIX . $field, $defaults->$field); } $this->numpartscorrect = $this->feedback; }
php
public function load_user_defaults() { $defaults = get_config('question_preview'); foreach ($this->get_user_pref_fields() as $field) { $this->$field = get_user_preferences( self::OPTIONPREFIX . $field, $defaults->$field); } $this->numpartscorrect = $this->feedback; }
[ "public", "function", "load_user_defaults", "(", ")", "{", "$", "defaults", "=", "get_config", "(", "'question_preview'", ")", ";", "foreach", "(", "$", "this", "->", "get_user_pref_fields", "(", ")", "as", "$", "field", ")", "{", "$", "this", "->", "$", "field", "=", "get_user_preferences", "(", "self", "::", "OPTIONPREFIX", ".", "$", "field", ",", "$", "defaults", "->", "$", "field", ")", ";", "}", "$", "this", "->", "numpartscorrect", "=", "$", "this", "->", "feedback", ";", "}" ]
Load the value of the options from the user_preferences table.
[ "Load", "the", "value", "of", "the", "options", "from", "the", "user_preferences", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/previewlib.php#L169-L176
213,839
moodle/moodle
question/previewlib.php
question_preview_options.save_user_preview_options
public function save_user_preview_options($newoptions) { foreach ($this->get_user_pref_fields() as $field) { if (isset($newoptions->$field)) { set_user_preference(self::OPTIONPREFIX . $field, $newoptions->$field); } } }
php
public function save_user_preview_options($newoptions) { foreach ($this->get_user_pref_fields() as $field) { if (isset($newoptions->$field)) { set_user_preference(self::OPTIONPREFIX . $field, $newoptions->$field); } } }
[ "public", "function", "save_user_preview_options", "(", "$", "newoptions", ")", "{", "foreach", "(", "$", "this", "->", "get_user_pref_fields", "(", ")", "as", "$", "field", ")", "{", "if", "(", "isset", "(", "$", "newoptions", "->", "$", "field", ")", ")", "{", "set_user_preference", "(", "self", "::", "OPTIONPREFIX", ".", "$", "field", ",", "$", "newoptions", "->", "$", "field", ")", ";", "}", "}", "}" ]
Save a change to the user's preview options to the database. @param object $newoptions
[ "Save", "a", "change", "to", "the", "user", "s", "preview", "options", "to", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/previewlib.php#L182-L188
213,840
moodle/moodle
question/previewlib.php
question_preview_options.set_from_request
public function set_from_request() { foreach ($this->get_field_types() as $field => $type) { $this->$field = optional_param($field, $this->$field, $type); } $this->numpartscorrect = $this->feedback; }
php
public function set_from_request() { foreach ($this->get_field_types() as $field => $type) { $this->$field = optional_param($field, $this->$field, $type); } $this->numpartscorrect = $this->feedback; }
[ "public", "function", "set_from_request", "(", ")", "{", "foreach", "(", "$", "this", "->", "get_field_types", "(", ")", "as", "$", "field", "=>", "$", "type", ")", "{", "$", "this", "->", "$", "field", "=", "optional_param", "(", "$", "field", ",", "$", "this", "->", "$", "field", ",", "$", "type", ")", ";", "}", "$", "this", "->", "numpartscorrect", "=", "$", "this", "->", "feedback", ";", "}" ]
Set the value of any fields included in the request.
[ "Set", "the", "value", "of", "any", "fields", "included", "in", "the", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/previewlib.php#L193-L198
213,841
moodle/moodle
lib/horde/framework/Horde/Mime/Headers/ContentParam.php
Horde_Mime_Headers_ContentParam._escapeParams
protected function _escapeParams($params) { foreach ($params as $k => $v) { foreach (str_split($v) as $c) { if (!Horde_Mime_ContentParam_Decode::isAtextNonTspecial($c)) { $params[$k] = '"' . addcslashes($v, '\\"') . '"'; break; } } } return $params; }
php
protected function _escapeParams($params) { foreach ($params as $k => $v) { foreach (str_split($v) as $c) { if (!Horde_Mime_ContentParam_Decode::isAtextNonTspecial($c)) { $params[$k] = '"' . addcslashes($v, '\\"') . '"'; break; } } } return $params; }
[ "protected", "function", "_escapeParams", "(", "$", "params", ")", "{", "foreach", "(", "$", "params", "as", "$", "k", "=>", "$", "v", ")", "{", "foreach", "(", "str_split", "(", "$", "v", ")", "as", "$", "c", ")", "{", "if", "(", "!", "Horde_Mime_ContentParam_Decode", "::", "isAtextNonTspecial", "(", "$", "c", ")", ")", "{", "$", "params", "[", "$", "k", "]", "=", "'\"'", ".", "addcslashes", "(", "$", "v", ",", "'\\\\\"'", ")", ".", "'\"'", ";", "break", ";", "}", "}", "}", "return", "$", "params", ";", "}" ]
Escape the parameter array. @param array $params Parameter array. @return array Escaped parameter array.
[ "Escape", "the", "parameter", "array", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Headers/ContentParam.php#L230-L242
213,842
moodle/moodle
lib/horde/framework/Horde/Mime/Headers/ContentParam.php
Horde_Mime_Headers_ContentParam.setContentParamValue
public function setContentParamValue($data) { $data = $this->_sanityCheck(trim($data)); if (($pos = strpos($data, ';')) !== false) { $data = substr($data, 0, $pos); } $this->_values = array($data); }
php
public function setContentParamValue($data) { $data = $this->_sanityCheck(trim($data)); if (($pos = strpos($data, ';')) !== false) { $data = substr($data, 0, $pos); } $this->_values = array($data); }
[ "public", "function", "setContentParamValue", "(", "$", "data", ")", "{", "$", "data", "=", "$", "this", "->", "_sanityCheck", "(", "trim", "(", "$", "data", ")", ")", ";", "if", "(", "(", "$", "pos", "=", "strpos", "(", "$", "data", ",", "';'", ")", ")", "!==", "false", ")", "{", "$", "data", "=", "substr", "(", "$", "data", ",", "0", ",", "$", "pos", ")", ";", "}", "$", "this", "->", "_values", "=", "array", "(", "$", "data", ")", ";", "}" ]
Set the content-parameter base value. @since 2.8.0 @param string $data Value.
[ "Set", "the", "content", "-", "parameter", "base", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Headers/ContentParam.php#L251-L259
213,843
moodle/moodle
mod/assign/gradeform.php
mod_assign_grade_form.definition
public function definition() { $mform = $this->_form; list($assignment, $data, $params) = $this->_customdata; // Visible elements. $this->assignment = $assignment; $assignment->add_grade_form_elements($mform, $data, $params); if ($data) { $this->set_data($data); } }
php
public function definition() { $mform = $this->_form; list($assignment, $data, $params) = $this->_customdata; // Visible elements. $this->assignment = $assignment; $assignment->add_grade_form_elements($mform, $data, $params); if ($data) { $this->set_data($data); } }
[ "public", "function", "definition", "(", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "list", "(", "$", "assignment", ",", "$", "data", ",", "$", "params", ")", "=", "$", "this", "->", "_customdata", ";", "// Visible elements.", "$", "this", "->", "assignment", "=", "$", "assignment", ";", "$", "assignment", "->", "add_grade_form_elements", "(", "$", "mform", ",", "$", "data", ",", "$", "params", ")", ";", "if", "(", "$", "data", ")", "{", "$", "this", "->", "set_data", "(", "$", "data", ")", ";", "}", "}" ]
Define the form - called by parent constructor.
[ "Define", "the", "form", "-", "called", "by", "parent", "constructor", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradeform.php#L46-L57
213,844
moodle/moodle
mod/assign/gradeform.php
mod_assign_grade_form.validation
public function validation($data, $files) { global $DB; $errors = parent::validation($data, $files); $instance = $this->assignment->get_instance(); // Advanced grading. if (!array_key_exists('grade', $data)) { return $errors; } if ($instance->grade > 0) { if (unformat_float($data['grade'], true) === false && (!empty($data['grade']))) { $errors['grade'] = get_string('invalidfloatforgrade', 'assign', $data['grade']); } else if (unformat_float($data['grade']) > $instance->grade) { $errors['grade'] = get_string('gradeabovemaximum', 'assign', $instance->grade); } else if (unformat_float($data['grade']) < 0) { $errors['grade'] = get_string('gradebelowzero', 'assign'); } } else { // This is a scale. if ($scale = $DB->get_record('scale', array('id'=>-($instance->grade)))) { $scaleoptions = make_menu_from_list($scale->scale); if ((int)$data['grade'] !== -1 && !array_key_exists((int)$data['grade'], $scaleoptions)) { $errors['grade'] = get_string('invalidgradeforscale', 'assign'); } } } return $errors; }
php
public function validation($data, $files) { global $DB; $errors = parent::validation($data, $files); $instance = $this->assignment->get_instance(); // Advanced grading. if (!array_key_exists('grade', $data)) { return $errors; } if ($instance->grade > 0) { if (unformat_float($data['grade'], true) === false && (!empty($data['grade']))) { $errors['grade'] = get_string('invalidfloatforgrade', 'assign', $data['grade']); } else if (unformat_float($data['grade']) > $instance->grade) { $errors['grade'] = get_string('gradeabovemaximum', 'assign', $instance->grade); } else if (unformat_float($data['grade']) < 0) { $errors['grade'] = get_string('gradebelowzero', 'assign'); } } else { // This is a scale. if ($scale = $DB->get_record('scale', array('id'=>-($instance->grade)))) { $scaleoptions = make_menu_from_list($scale->scale); if ((int)$data['grade'] !== -1 && !array_key_exists((int)$data['grade'], $scaleoptions)) { $errors['grade'] = get_string('invalidgradeforscale', 'assign'); } } } return $errors; }
[ "public", "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "global", "$", "DB", ";", "$", "errors", "=", "parent", "::", "validation", "(", "$", "data", ",", "$", "files", ")", ";", "$", "instance", "=", "$", "this", "->", "assignment", "->", "get_instance", "(", ")", ";", "// Advanced grading.", "if", "(", "!", "array_key_exists", "(", "'grade'", ",", "$", "data", ")", ")", "{", "return", "$", "errors", ";", "}", "if", "(", "$", "instance", "->", "grade", ">", "0", ")", "{", "if", "(", "unformat_float", "(", "$", "data", "[", "'grade'", "]", ",", "true", ")", "===", "false", "&&", "(", "!", "empty", "(", "$", "data", "[", "'grade'", "]", ")", ")", ")", "{", "$", "errors", "[", "'grade'", "]", "=", "get_string", "(", "'invalidfloatforgrade'", ",", "'assign'", ",", "$", "data", "[", "'grade'", "]", ")", ";", "}", "else", "if", "(", "unformat_float", "(", "$", "data", "[", "'grade'", "]", ")", ">", "$", "instance", "->", "grade", ")", "{", "$", "errors", "[", "'grade'", "]", "=", "get_string", "(", "'gradeabovemaximum'", ",", "'assign'", ",", "$", "instance", "->", "grade", ")", ";", "}", "else", "if", "(", "unformat_float", "(", "$", "data", "[", "'grade'", "]", ")", "<", "0", ")", "{", "$", "errors", "[", "'grade'", "]", "=", "get_string", "(", "'gradebelowzero'", ",", "'assign'", ")", ";", "}", "}", "else", "{", "// This is a scale.", "if", "(", "$", "scale", "=", "$", "DB", "->", "get_record", "(", "'scale'", ",", "array", "(", "'id'", "=>", "-", "(", "$", "instance", "->", "grade", ")", ")", ")", ")", "{", "$", "scaleoptions", "=", "make_menu_from_list", "(", "$", "scale", "->", "scale", ")", ";", "if", "(", "(", "int", ")", "$", "data", "[", "'grade'", "]", "!==", "-", "1", "&&", "!", "array_key_exists", "(", "(", "int", ")", "$", "data", "[", "'grade'", "]", ",", "$", "scaleoptions", ")", ")", "{", "$", "errors", "[", "'grade'", "]", "=", "get_string", "(", "'invalidgradeforscale'", ",", "'assign'", ")", ";", "}", "}", "}", "return", "$", "errors", ";", "}" ]
Perform minimal validation on the grade form @param array $data @param array $files
[ "Perform", "minimal", "validation", "on", "the", "grade", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradeform.php#L76-L104
213,845
moodle/moodle
lib/grade/grade_outcome.php
grade_outcome.delete
public function delete($source=null) { global $DB; if (!empty($this->courseid)) { $DB->delete_records('grade_outcomes_courses', array('outcomeid' => $this->id, 'courseid' => $this->courseid)); } if (parent::delete($source)) { $context = context_system::instance(); $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'grade', 'outcome', $this->id); foreach ($files as $file) { $file->delete(); } return true; } return false; }
php
public function delete($source=null) { global $DB; if (!empty($this->courseid)) { $DB->delete_records('grade_outcomes_courses', array('outcomeid' => $this->id, 'courseid' => $this->courseid)); } if (parent::delete($source)) { $context = context_system::instance(); $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'grade', 'outcome', $this->id); foreach ($files as $file) { $file->delete(); } return true; } return false; }
[ "public", "function", "delete", "(", "$", "source", "=", "null", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "courseid", ")", ")", "{", "$", "DB", "->", "delete_records", "(", "'grade_outcomes_courses'", ",", "array", "(", "'outcomeid'", "=>", "$", "this", "->", "id", ",", "'courseid'", "=>", "$", "this", "->", "courseid", ")", ")", ";", "}", "if", "(", "parent", "::", "delete", "(", "$", "source", ")", ")", "{", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'grade'", ",", "'outcome'", ",", "$", "this", "->", "id", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "file", "->", "delete", "(", ")", ";", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
Deletes this outcome from the database. @param string $source from where was the object deleted (mod/forum, manual, etc.) @return bool success
[ "Deletes", "this", "outcome", "from", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_outcome.php#L103-L118
213,846
moodle/moodle
lib/grade/grade_outcome.php
grade_outcome.use_in
public function use_in($courseid) { global $DB; if (!empty($this->courseid) and $courseid != $this->courseid) { return false; } if (!$DB->record_exists('grade_outcomes_courses', array('courseid' => $courseid, 'outcomeid' => $this->id))) { $goc = new stdClass(); $goc->courseid = $courseid; $goc->outcomeid = $this->id; $DB->insert_record('grade_outcomes_courses', $goc); } return true; }
php
public function use_in($courseid) { global $DB; if (!empty($this->courseid) and $courseid != $this->courseid) { return false; } if (!$DB->record_exists('grade_outcomes_courses', array('courseid' => $courseid, 'outcomeid' => $this->id))) { $goc = new stdClass(); $goc->courseid = $courseid; $goc->outcomeid = $this->id; $DB->insert_record('grade_outcomes_courses', $goc); } return true; }
[ "public", "function", "use_in", "(", "$", "courseid", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "courseid", ")", "and", "$", "courseid", "!=", "$", "this", "->", "courseid", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "DB", "->", "record_exists", "(", "'grade_outcomes_courses'", ",", "array", "(", "'courseid'", "=>", "$", "courseid", ",", "'outcomeid'", "=>", "$", "this", "->", "id", ")", ")", ")", "{", "$", "goc", "=", "new", "stdClass", "(", ")", ";", "$", "goc", "->", "courseid", "=", "$", "courseid", ";", "$", "goc", "->", "outcomeid", "=", "$", "this", "->", "id", ";", "$", "DB", "->", "insert_record", "(", "'grade_outcomes_courses'", ",", "$", "goc", ")", ";", "}", "return", "true", ";", "}" ]
Mark outcome as used in a course @param int $courseid @return False if invalid courseid requested
[ "Mark", "outcome", "as", "used", "in", "a", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_outcome.php#L167-L180
213,847
moodle/moodle
lib/grade/grade_outcome.php
grade_outcome.load_scale
public function load_scale() { if (empty($this->scale->id) or $this->scale->id != $this->scaleid) { $this->scale = grade_scale::fetch(array('id'=>$this->scaleid)); $this->scale->load_items(); } return $this->scale; }
php
public function load_scale() { if (empty($this->scale->id) or $this->scale->id != $this->scaleid) { $this->scale = grade_scale::fetch(array('id'=>$this->scaleid)); $this->scale->load_items(); } return $this->scale; }
[ "public", "function", "load_scale", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "scale", "->", "id", ")", "or", "$", "this", "->", "scale", "->", "id", "!=", "$", "this", "->", "scaleid", ")", "{", "$", "this", "->", "scale", "=", "grade_scale", "::", "fetch", "(", "array", "(", "'id'", "=>", "$", "this", "->", "scaleid", ")", ")", ";", "$", "this", "->", "scale", "->", "load_items", "(", ")", ";", "}", "return", "$", "this", "->", "scale", ";", "}" ]
Instantiates a grade_scale object whose data is retrieved from the database @return grade_scale
[ "Instantiates", "a", "grade_scale", "object", "whose", "data", "is", "retrieved", "from", "the", "database" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_outcome.php#L209-L215
213,848
moodle/moodle
lib/grade/grade_outcome.php
grade_outcome.fetch_all_available
public static function fetch_all_available($courseid) { global $CFG, $DB; $result = array(); $params = array($courseid); $sql = "SELECT go.* FROM {grade_outcomes} go, {grade_outcomes_courses} goc WHERE go.id = goc.outcomeid AND goc.courseid = ? ORDER BY go.id ASC"; if ($datas = $DB->get_records_sql($sql, $params)) { foreach($datas as $data) { $instance = new grade_outcome(); grade_object::set_properties($instance, $data); $result[$instance->id] = $instance; } } return $result; }
php
public static function fetch_all_available($courseid) { global $CFG, $DB; $result = array(); $params = array($courseid); $sql = "SELECT go.* FROM {grade_outcomes} go, {grade_outcomes_courses} goc WHERE go.id = goc.outcomeid AND goc.courseid = ? ORDER BY go.id ASC"; if ($datas = $DB->get_records_sql($sql, $params)) { foreach($datas as $data) { $instance = new grade_outcome(); grade_object::set_properties($instance, $data); $result[$instance->id] = $instance; } } return $result; }
[ "public", "static", "function", "fetch_all_available", "(", "$", "courseid", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "result", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "$", "courseid", ")", ";", "$", "sql", "=", "\"SELECT go.*\n FROM {grade_outcomes} go, {grade_outcomes_courses} goc\n WHERE go.id = goc.outcomeid AND goc.courseid = ?\n ORDER BY go.id ASC\"", ";", "if", "(", "$", "datas", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ")", "{", "foreach", "(", "$", "datas", "as", "$", "data", ")", "{", "$", "instance", "=", "new", "grade_outcome", "(", ")", ";", "grade_object", "::", "set_properties", "(", "$", "instance", ",", "$", "data", ")", ";", "$", "result", "[", "$", "instance", "->", "id", "]", "=", "$", "instance", ";", "}", "}", "return", "$", "result", ";", "}" ]
Static method that returns all outcomes available in course @static @param int $courseid @return array
[ "Static", "method", "that", "returns", "all", "outcomes", "available", "in", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_outcome.php#L251-L269
213,849
moodle/moodle
lib/grade/grade_outcome.php
grade_outcome.can_delete
public function can_delete() { if ($this->get_item_uses_count()) { return false; } if (empty($this->courseid)) { if ($this->get_course_uses_count()) { return false; } } return true; }
php
public function can_delete() { if ($this->get_item_uses_count()) { return false; } if (empty($this->courseid)) { if ($this->get_course_uses_count()) { return false; } } return true; }
[ "public", "function", "can_delete", "(", ")", "{", "if", "(", "$", "this", "->", "get_item_uses_count", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "courseid", ")", ")", "{", "if", "(", "$", "this", "->", "get_course_uses_count", "(", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks if outcome can be deleted. @return bool
[ "Checks", "if", "outcome", "can", "be", "deleted", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_outcome.php#L314-L324
213,850
moodle/moodle
lib/horde/framework/Horde/Mime/ContentParam/Decode.php
Horde_Mime_ContentParam_Decode.decode
public function decode($data) { $out = array(); $this->_data = $data; $this->_datalen = strlen($data); $this->_ptr = 0; while ($this->_curr() !== false) { $this->_rfc822SkipLwsp(); $this->_rfc822ParseMimeToken($param); if (is_null($param) || ($this->_curr() != '=')) { break; } ++$this->_ptr; $this->_rfc822SkipLwsp(); $value = ''; if ($this->_curr() == '"') { try { $this->_rfc822ParseQuotedString($value); } catch (Horde_Mail_Exception $e) { break; } } else { $this->_rfc822ParseMimeToken($value); if (is_null($value)) { break; } } $out[$param] = $value; $this->_rfc822SkipLwsp(); if ($this->_curr() != ';') { break; } ++$this->_ptr; } return $out; }
php
public function decode($data) { $out = array(); $this->_data = $data; $this->_datalen = strlen($data); $this->_ptr = 0; while ($this->_curr() !== false) { $this->_rfc822SkipLwsp(); $this->_rfc822ParseMimeToken($param); if (is_null($param) || ($this->_curr() != '=')) { break; } ++$this->_ptr; $this->_rfc822SkipLwsp(); $value = ''; if ($this->_curr() == '"') { try { $this->_rfc822ParseQuotedString($value); } catch (Horde_Mail_Exception $e) { break; } } else { $this->_rfc822ParseMimeToken($value); if (is_null($value)) { break; } } $out[$param] = $value; $this->_rfc822SkipLwsp(); if ($this->_curr() != ';') { break; } ++$this->_ptr; } return $out; }
[ "public", "function", "decode", "(", "$", "data", ")", "{", "$", "out", "=", "array", "(", ")", ";", "$", "this", "->", "_data", "=", "$", "data", ";", "$", "this", "->", "_datalen", "=", "strlen", "(", "$", "data", ")", ";", "$", "this", "->", "_ptr", "=", "0", ";", "while", "(", "$", "this", "->", "_curr", "(", ")", "!==", "false", ")", "{", "$", "this", "->", "_rfc822SkipLwsp", "(", ")", ";", "$", "this", "->", "_rfc822ParseMimeToken", "(", "$", "param", ")", ";", "if", "(", "is_null", "(", "$", "param", ")", "||", "(", "$", "this", "->", "_curr", "(", ")", "!=", "'='", ")", ")", "{", "break", ";", "}", "++", "$", "this", "->", "_ptr", ";", "$", "this", "->", "_rfc822SkipLwsp", "(", ")", ";", "$", "value", "=", "''", ";", "if", "(", "$", "this", "->", "_curr", "(", ")", "==", "'\"'", ")", "{", "try", "{", "$", "this", "->", "_rfc822ParseQuotedString", "(", "$", "value", ")", ";", "}", "catch", "(", "Horde_Mail_Exception", "$", "e", ")", "{", "break", ";", "}", "}", "else", "{", "$", "this", "->", "_rfc822ParseMimeToken", "(", "$", "value", ")", ";", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "break", ";", "}", "}", "$", "out", "[", "$", "param", "]", "=", "$", "value", ";", "$", "this", "->", "_rfc822SkipLwsp", "(", ")", ";", "if", "(", "$", "this", "->", "_curr", "(", ")", "!=", "';'", ")", "{", "break", ";", "}", "++", "$", "this", "->", "_ptr", ";", "}", "return", "$", "out", ";", "}" ]
Decode content parameter data. @param string $data Parameter data. @return array List of parameter key/value combinations.
[ "Decode", "content", "parameter", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/ContentParam/Decode.php#L40-L86
213,851
moodle/moodle
backup/util/settings/setting_dependency.class.php
setting_dependency.process_change
final public function process_change($changetype, $oldvalue) { // Check the type of change requested. switch ($changetype) { // Process a status change. case base_setting::CHANGED_STATUS: return $this->process_status_change($oldvalue); // Process a visibility change. case base_setting::CHANGED_VISIBILITY: return $this->process_visibility_change($oldvalue); // Process a value change. case base_setting::CHANGED_VALUE: return $this->process_value_change($oldvalue); } // Throw an exception if we get this far. throw new backup_ui_exception('unknownchangetype'); }
php
final public function process_change($changetype, $oldvalue) { // Check the type of change requested. switch ($changetype) { // Process a status change. case base_setting::CHANGED_STATUS: return $this->process_status_change($oldvalue); // Process a visibility change. case base_setting::CHANGED_VISIBILITY: return $this->process_visibility_change($oldvalue); // Process a value change. case base_setting::CHANGED_VALUE: return $this->process_value_change($oldvalue); } // Throw an exception if we get this far. throw new backup_ui_exception('unknownchangetype'); }
[ "final", "public", "function", "process_change", "(", "$", "changetype", ",", "$", "oldvalue", ")", "{", "// Check the type of change requested.", "switch", "(", "$", "changetype", ")", "{", "// Process a status change.", "case", "base_setting", "::", "CHANGED_STATUS", ":", "return", "$", "this", "->", "process_status_change", "(", "$", "oldvalue", ")", ";", "// Process a visibility change.", "case", "base_setting", "::", "CHANGED_VISIBILITY", ":", "return", "$", "this", "->", "process_visibility_change", "(", "$", "oldvalue", ")", ";", "// Process a value change.", "case", "base_setting", "::", "CHANGED_VALUE", ":", "return", "$", "this", "->", "process_value_change", "(", "$", "oldvalue", ")", ";", "}", "// Throw an exception if we get this far.", "throw", "new", "backup_ui_exception", "(", "'unknownchangetype'", ")", ";", "}" ]
Processes a change is setting called by the primary setting @param int $changetype @param mixed $oldvalue @return bool
[ "Processes", "a", "change", "is", "setting", "called", "by", "the", "primary", "setting" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/settings/setting_dependency.class.php#L95-L110
213,852
moodle/moodle
backup/util/settings/setting_dependency.class.php
setting_dependency.process_visibility_change
protected function process_visibility_change($oldvisibility) { // Store the current dependent settings visibility for comparison. $prevalue = $this->dependentsetting->get_visibility(); // Set it regardless of whether we need to. $this->dependentsetting->set_visibility($this->setting->get_visibility()); // Return true if it changed. return ($prevalue != $this->dependentsetting->get_visibility()); }
php
protected function process_visibility_change($oldvisibility) { // Store the current dependent settings visibility for comparison. $prevalue = $this->dependentsetting->get_visibility(); // Set it regardless of whether we need to. $this->dependentsetting->set_visibility($this->setting->get_visibility()); // Return true if it changed. return ($prevalue != $this->dependentsetting->get_visibility()); }
[ "protected", "function", "process_visibility_change", "(", "$", "oldvisibility", ")", "{", "// Store the current dependent settings visibility for comparison.", "$", "prevalue", "=", "$", "this", "->", "dependentsetting", "->", "get_visibility", "(", ")", ";", "// Set it regardless of whether we need to.", "$", "this", "->", "dependentsetting", "->", "set_visibility", "(", "$", "this", "->", "setting", "->", "get_visibility", "(", ")", ")", ";", "// Return true if it changed.", "return", "(", "$", "prevalue", "!=", "$", "this", "->", "dependentsetting", "->", "get_visibility", "(", ")", ")", ";", "}" ]
Processes a visibility change @param bool $oldvisibility @return bool
[ "Processes", "a", "visibility", "change" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/settings/setting_dependency.class.php#L116-L123
213,853
moodle/moodle
backup/util/settings/setting_dependency.class.php
setting_dependency_disabledif_equals.is_locked
public function is_locked() { // If the setting is locked or the dependent setting should be locked then return true. if ($this->setting->get_status() !== base_setting::NOT_LOCKED || $this->evaluate_disabled_condition($this->setting->get_value())) { return true; } // Else the dependent setting is not locked by this setting_dependency. return false; }
php
public function is_locked() { // If the setting is locked or the dependent setting should be locked then return true. if ($this->setting->get_status() !== base_setting::NOT_LOCKED || $this->evaluate_disabled_condition($this->setting->get_value())) { return true; } // Else the dependent setting is not locked by this setting_dependency. return false; }
[ "public", "function", "is_locked", "(", ")", "{", "// If the setting is locked or the dependent setting should be locked then return true.", "if", "(", "$", "this", "->", "setting", "->", "get_status", "(", ")", "!==", "base_setting", "::", "NOT_LOCKED", "||", "$", "this", "->", "evaluate_disabled_condition", "(", "$", "this", "->", "setting", "->", "get_value", "(", ")", ")", ")", "{", "return", "true", ";", "}", "// Else the dependent setting is not locked by this setting_dependency.", "return", "false", ";", "}" ]
Returns true if the dependent setting is locked by this setting_dependency. @return bool
[ "Returns", "true", "if", "the", "dependent", "setting", "is", "locked", "by", "this", "setting_dependency", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/settings/setting_dependency.class.php#L193-L201
213,854
moodle/moodle
backup/util/settings/setting_dependency.class.php
setting_dependency_disabledif_equals.process_value_change
protected function process_value_change($oldvalue) { if ($this->dependentsetting->get_status() == base_setting::LOCKED_BY_PERMISSION || $this->dependentsetting->get_status() == base_setting::LOCKED_BY_CONFIG) { // When setting is locked by permission or config do not apply dependencies. return false; } $prevalue = $this->dependentsetting->get_value(); // If the setting is the desired value enact the dependency. $settingvalue = $this->setting->get_value(); if ($this->evaluate_disabled_condition($settingvalue)) { // The dependent setting needs to be locked by hierachy and set to the // default value. $this->dependentsetting->set_status(base_setting::LOCKED_BY_HIERARCHY); // For checkboxes the default value is false, but when the setting is // locked, the value should inherit from the parent setting. if ($this->defaultvalue === false) { $this->dependentsetting->set_value($settingvalue); } else { $this->dependentsetting->set_value($this->defaultvalue); } } else if ($this->dependentsetting->get_status() == base_setting::LOCKED_BY_HIERARCHY) { // We can unlock the dependent setting. $this->dependentsetting->set_status(base_setting::NOT_LOCKED); } // Return true if the value has changed for the dependent setting. return ($prevalue != $this->dependentsetting->get_value()); }
php
protected function process_value_change($oldvalue) { if ($this->dependentsetting->get_status() == base_setting::LOCKED_BY_PERMISSION || $this->dependentsetting->get_status() == base_setting::LOCKED_BY_CONFIG) { // When setting is locked by permission or config do not apply dependencies. return false; } $prevalue = $this->dependentsetting->get_value(); // If the setting is the desired value enact the dependency. $settingvalue = $this->setting->get_value(); if ($this->evaluate_disabled_condition($settingvalue)) { // The dependent setting needs to be locked by hierachy and set to the // default value. $this->dependentsetting->set_status(base_setting::LOCKED_BY_HIERARCHY); // For checkboxes the default value is false, but when the setting is // locked, the value should inherit from the parent setting. if ($this->defaultvalue === false) { $this->dependentsetting->set_value($settingvalue); } else { $this->dependentsetting->set_value($this->defaultvalue); } } else if ($this->dependentsetting->get_status() == base_setting::LOCKED_BY_HIERARCHY) { // We can unlock the dependent setting. $this->dependentsetting->set_status(base_setting::NOT_LOCKED); } // Return true if the value has changed for the dependent setting. return ($prevalue != $this->dependentsetting->get_value()); }
[ "protected", "function", "process_value_change", "(", "$", "oldvalue", ")", "{", "if", "(", "$", "this", "->", "dependentsetting", "->", "get_status", "(", ")", "==", "base_setting", "::", "LOCKED_BY_PERMISSION", "||", "$", "this", "->", "dependentsetting", "->", "get_status", "(", ")", "==", "base_setting", "::", "LOCKED_BY_CONFIG", ")", "{", "// When setting is locked by permission or config do not apply dependencies.", "return", "false", ";", "}", "$", "prevalue", "=", "$", "this", "->", "dependentsetting", "->", "get_value", "(", ")", ";", "// If the setting is the desired value enact the dependency.", "$", "settingvalue", "=", "$", "this", "->", "setting", "->", "get_value", "(", ")", ";", "if", "(", "$", "this", "->", "evaluate_disabled_condition", "(", "$", "settingvalue", ")", ")", "{", "// The dependent setting needs to be locked by hierachy and set to the", "// default value.", "$", "this", "->", "dependentsetting", "->", "set_status", "(", "base_setting", "::", "LOCKED_BY_HIERARCHY", ")", ";", "// For checkboxes the default value is false, but when the setting is", "// locked, the value should inherit from the parent setting.", "if", "(", "$", "this", "->", "defaultvalue", "===", "false", ")", "{", "$", "this", "->", "dependentsetting", "->", "set_value", "(", "$", "settingvalue", ")", ";", "}", "else", "{", "$", "this", "->", "dependentsetting", "->", "set_value", "(", "$", "this", "->", "defaultvalue", ")", ";", "}", "}", "else", "if", "(", "$", "this", "->", "dependentsetting", "->", "get_status", "(", ")", "==", "base_setting", "::", "LOCKED_BY_HIERARCHY", ")", "{", "// We can unlock the dependent setting.", "$", "this", "->", "dependentsetting", "->", "set_status", "(", "base_setting", "::", "NOT_LOCKED", ")", ";", "}", "// Return true if the value has changed for the dependent setting.", "return", "(", "$", "prevalue", "!=", "$", "this", "->", "dependentsetting", "->", "get_value", "(", ")", ")", ";", "}" ]
Processes a value change in the primary setting @param mixed $oldvalue @return bool
[ "Processes", "a", "value", "change", "in", "the", "primary", "setting" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/settings/setting_dependency.class.php#L207-L234
213,855
moodle/moodle
backup/util/settings/setting_dependency.class.php
setting_dependency_disabledif_equals.process_status_change
protected function process_status_change($oldstatus) { // Store the dependent status. $prevalue = $this->dependentsetting->get_status(); // Store the current status. $currentstatus = $this->setting->get_status(); if ($currentstatus == base_setting::NOT_LOCKED) { if ($prevalue == base_setting::LOCKED_BY_HIERARCHY && !$this->evaluate_disabled_condition($this->setting->get_value())) { // Dependency has changes, is not fine, unlock the dependent setting. $this->dependentsetting->set_status(base_setting::NOT_LOCKED); } } else { // Make sure the dependent setting is also locked, in this case by hierarchy. $this->dependentsetting->set_status(base_setting::LOCKED_BY_HIERARCHY); } // Return true if the dependent setting has changed. return ($prevalue != $this->dependentsetting->get_status()); }
php
protected function process_status_change($oldstatus) { // Store the dependent status. $prevalue = $this->dependentsetting->get_status(); // Store the current status. $currentstatus = $this->setting->get_status(); if ($currentstatus == base_setting::NOT_LOCKED) { if ($prevalue == base_setting::LOCKED_BY_HIERARCHY && !$this->evaluate_disabled_condition($this->setting->get_value())) { // Dependency has changes, is not fine, unlock the dependent setting. $this->dependentsetting->set_status(base_setting::NOT_LOCKED); } } else { // Make sure the dependent setting is also locked, in this case by hierarchy. $this->dependentsetting->set_status(base_setting::LOCKED_BY_HIERARCHY); } // Return true if the dependent setting has changed. return ($prevalue != $this->dependentsetting->get_status()); }
[ "protected", "function", "process_status_change", "(", "$", "oldstatus", ")", "{", "// Store the dependent status.", "$", "prevalue", "=", "$", "this", "->", "dependentsetting", "->", "get_status", "(", ")", ";", "// Store the current status.", "$", "currentstatus", "=", "$", "this", "->", "setting", "->", "get_status", "(", ")", ";", "if", "(", "$", "currentstatus", "==", "base_setting", "::", "NOT_LOCKED", ")", "{", "if", "(", "$", "prevalue", "==", "base_setting", "::", "LOCKED_BY_HIERARCHY", "&&", "!", "$", "this", "->", "evaluate_disabled_condition", "(", "$", "this", "->", "setting", "->", "get_value", "(", ")", ")", ")", "{", "// Dependency has changes, is not fine, unlock the dependent setting.", "$", "this", "->", "dependentsetting", "->", "set_status", "(", "base_setting", "::", "NOT_LOCKED", ")", ";", "}", "}", "else", "{", "// Make sure the dependent setting is also locked, in this case by hierarchy.", "$", "this", "->", "dependentsetting", "->", "set_status", "(", "base_setting", "::", "LOCKED_BY_HIERARCHY", ")", ";", "}", "// Return true if the dependent setting has changed.", "return", "(", "$", "prevalue", "!=", "$", "this", "->", "dependentsetting", "->", "get_status", "(", ")", ")", ";", "}" ]
Processes a status change in the primary setting @param mixed $oldstatus @return bool
[ "Processes", "a", "status", "change", "in", "the", "primary", "setting" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/settings/setting_dependency.class.php#L240-L257
213,856
moodle/moodle
backup/util/settings/setting_dependency.class.php
setting_dependency_disabledif_equals.enforce
public function enforce() { // This will be set to true if ANYTHING changes. $changes = false; // First process any value changes. if ($this->process_value_change($this->setting->get_value())) { $changes = true; } // Second process any status changes. if ($this->process_status_change($this->setting->get_status())) { $changes = true; } // Finally process visibility changes. if ($this->process_visibility_change($this->setting->get_visibility())) { $changes = true; } return $changes; }
php
public function enforce() { // This will be set to true if ANYTHING changes. $changes = false; // First process any value changes. if ($this->process_value_change($this->setting->get_value())) { $changes = true; } // Second process any status changes. if ($this->process_status_change($this->setting->get_status())) { $changes = true; } // Finally process visibility changes. if ($this->process_visibility_change($this->setting->get_visibility())) { $changes = true; } return $changes; }
[ "public", "function", "enforce", "(", ")", "{", "// This will be set to true if ANYTHING changes.", "$", "changes", "=", "false", ";", "// First process any value changes.", "if", "(", "$", "this", "->", "process_value_change", "(", "$", "this", "->", "setting", "->", "get_value", "(", ")", ")", ")", "{", "$", "changes", "=", "true", ";", "}", "// Second process any status changes.", "if", "(", "$", "this", "->", "process_status_change", "(", "$", "this", "->", "setting", "->", "get_status", "(", ")", ")", ")", "{", "$", "changes", "=", "true", ";", "}", "// Finally process visibility changes.", "if", "(", "$", "this", "->", "process_visibility_change", "(", "$", "this", "->", "setting", "->", "get_visibility", "(", ")", ")", ")", "{", "$", "changes", "=", "true", ";", "}", "return", "$", "changes", ";", "}" ]
Enforces the dependency if required. @return bool True if there were changes
[ "Enforces", "the", "dependency", "if", "required", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/settings/setting_dependency.class.php#L262-L278
213,857
moodle/moodle
blocks/glossary_random/backup/moodle2/restore_glossary_random_block_task.class.php
restore_glossary_random_block_task.after_restore
public function after_restore() { global $DB; // Get the blockid $blockid = $this->get_blockid(); // Extract block configdata and update it to point to the new glossary if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) { $config = unserialize(base64_decode($configdata)); if (!empty($config->glossary)) { if ($glossarymap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary', $config->glossary)) { // Get glossary mapping and replace it in config $config->glossary = $glossarymap->newitemid; } else if ($this->is_samesite()) { // We are restoring on the same site, check if glossary can be used in the block in this course. $glossaryid = $DB->get_field_sql("SELECT id FROM {glossary} " . "WHERE id = ? AND (course = ? OR globalglossary = 1)", [$config->glossary, $this->get_courseid()]); if (!$glossaryid) { unset($config->glossary); } } else { // The block refers to a glossary not present in the backup file. unset($config->glossary); } // Unset config variables that are no longer used. unset($config->globalglossary); unset($config->courseid); // Save updated config. $configdata = base64_encode(serialize($config)); $DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid)); } } }
php
public function after_restore() { global $DB; // Get the blockid $blockid = $this->get_blockid(); // Extract block configdata and update it to point to the new glossary if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) { $config = unserialize(base64_decode($configdata)); if (!empty($config->glossary)) { if ($glossarymap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary', $config->glossary)) { // Get glossary mapping and replace it in config $config->glossary = $glossarymap->newitemid; } else if ($this->is_samesite()) { // We are restoring on the same site, check if glossary can be used in the block in this course. $glossaryid = $DB->get_field_sql("SELECT id FROM {glossary} " . "WHERE id = ? AND (course = ? OR globalglossary = 1)", [$config->glossary, $this->get_courseid()]); if (!$glossaryid) { unset($config->glossary); } } else { // The block refers to a glossary not present in the backup file. unset($config->glossary); } // Unset config variables that are no longer used. unset($config->globalglossary); unset($config->courseid); // Save updated config. $configdata = base64_encode(serialize($config)); $DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid)); } } }
[ "public", "function", "after_restore", "(", ")", "{", "global", "$", "DB", ";", "// Get the blockid", "$", "blockid", "=", "$", "this", "->", "get_blockid", "(", ")", ";", "// Extract block configdata and update it to point to the new glossary", "if", "(", "$", "configdata", "=", "$", "DB", "->", "get_field", "(", "'block_instances'", ",", "'configdata'", ",", "array", "(", "'id'", "=>", "$", "blockid", ")", ")", ")", "{", "$", "config", "=", "unserialize", "(", "base64_decode", "(", "$", "configdata", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "config", "->", "glossary", ")", ")", "{", "if", "(", "$", "glossarymap", "=", "restore_dbops", "::", "get_backup_ids_record", "(", "$", "this", "->", "get_restoreid", "(", ")", ",", "'glossary'", ",", "$", "config", "->", "glossary", ")", ")", "{", "// Get glossary mapping and replace it in config", "$", "config", "->", "glossary", "=", "$", "glossarymap", "->", "newitemid", ";", "}", "else", "if", "(", "$", "this", "->", "is_samesite", "(", ")", ")", "{", "// We are restoring on the same site, check if glossary can be used in the block in this course.", "$", "glossaryid", "=", "$", "DB", "->", "get_field_sql", "(", "\"SELECT id FROM {glossary} \"", ".", "\"WHERE id = ? AND (course = ? OR globalglossary = 1)\"", ",", "[", "$", "config", "->", "glossary", ",", "$", "this", "->", "get_courseid", "(", ")", "]", ")", ";", "if", "(", "!", "$", "glossaryid", ")", "{", "unset", "(", "$", "config", "->", "glossary", ")", ";", "}", "}", "else", "{", "// The block refers to a glossary not present in the backup file.", "unset", "(", "$", "config", "->", "glossary", ")", ";", "}", "// Unset config variables that are no longer used.", "unset", "(", "$", "config", "->", "globalglossary", ")", ";", "unset", "(", "$", "config", "->", "courseid", ")", ";", "// Save updated config.", "$", "configdata", "=", "base64_encode", "(", "serialize", "(", "$", "config", ")", ")", ";", "$", "DB", "->", "set_field", "(", "'block_instances'", ",", "'configdata'", ",", "$", "configdata", ",", "array", "(", "'id'", "=>", "$", "blockid", ")", ")", ";", "}", "}", "}" ]
This function, executed after all the tasks in the plan have been executed, will perform the recode of the target glossary for the block. This must be done here and not in normal execution steps because the glossary may be restored after the block.
[ "This", "function", "executed", "after", "all", "the", "tasks", "in", "the", "plan", "have", "been", "executed", "will", "perform", "the", "recode", "of", "the", "target", "glossary", "for", "the", "block", ".", "This", "must", "be", "done", "here", "and", "not", "in", "normal", "execution", "steps", "because", "the", "glossary", "may", "be", "restored", "after", "the", "block", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/glossary_random/backup/moodle2/restore_glossary_random_block_task.class.php#L53-L86
213,858
moodle/moodle
admin/tool/cohortroles/classes/api.php
api.create_cohort_role_assignment
public static function create_cohort_role_assignment(stdClass $record) { $cohortroleassignment = new cohort_role_assignment(0, $record); $context = context_system::instance(); // First we do a permissions check. require_capability('moodle/role:manage', $context); // Validate before we check for existing records. if (!$cohortroleassignment->is_valid()) { throw new invalid_persistent_exception($cohortroleassignment->get_errors()); } $existing = cohort_role_assignment::get_record((array) $record); if (!empty($existing)) { return false; } else { // OK - all set. $cohortroleassignment->create(); } return $cohortroleassignment; }
php
public static function create_cohort_role_assignment(stdClass $record) { $cohortroleassignment = new cohort_role_assignment(0, $record); $context = context_system::instance(); // First we do a permissions check. require_capability('moodle/role:manage', $context); // Validate before we check for existing records. if (!$cohortroleassignment->is_valid()) { throw new invalid_persistent_exception($cohortroleassignment->get_errors()); } $existing = cohort_role_assignment::get_record((array) $record); if (!empty($existing)) { return false; } else { // OK - all set. $cohortroleassignment->create(); } return $cohortroleassignment; }
[ "public", "static", "function", "create_cohort_role_assignment", "(", "stdClass", "$", "record", ")", "{", "$", "cohortroleassignment", "=", "new", "cohort_role_assignment", "(", "0", ",", "$", "record", ")", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "// First we do a permissions check.", "require_capability", "(", "'moodle/role:manage'", ",", "$", "context", ")", ";", "// Validate before we check for existing records.", "if", "(", "!", "$", "cohortroleassignment", "->", "is_valid", "(", ")", ")", "{", "throw", "new", "invalid_persistent_exception", "(", "$", "cohortroleassignment", "->", "get_errors", "(", ")", ")", ";", "}", "$", "existing", "=", "cohort_role_assignment", "::", "get_record", "(", "(", "array", ")", "$", "record", ")", ";", "if", "(", "!", "empty", "(", "$", "existing", ")", ")", "{", "return", "false", ";", "}", "else", "{", "// OK - all set.", "$", "cohortroleassignment", "->", "create", "(", ")", ";", "}", "return", "$", "cohortroleassignment", ";", "}" ]
Create a cohort role assignment from a record containing all the data for the class. Requires moodle/role:manage capability at the system context. @param stdClass $record Record containing all the data for an instance of the class. @return competency
[ "Create", "a", "cohort", "role", "assignment", "from", "a", "record", "containing", "all", "the", "data", "for", "the", "class", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/cohortroles/classes/api.php#L46-L66
213,859
moodle/moodle
admin/tool/cohortroles/classes/api.php
api.delete_cohort_role_assignment
public static function delete_cohort_role_assignment($id) { $cohortroleassignment = new cohort_role_assignment($id); $context = context_system::instance(); // First we do a permissions check. require_capability('moodle/role:manage', $context); // OK - all set. return $cohortroleassignment->delete(); }
php
public static function delete_cohort_role_assignment($id) { $cohortroleassignment = new cohort_role_assignment($id); $context = context_system::instance(); // First we do a permissions check. require_capability('moodle/role:manage', $context); // OK - all set. return $cohortroleassignment->delete(); }
[ "public", "static", "function", "delete_cohort_role_assignment", "(", "$", "id", ")", "{", "$", "cohortroleassignment", "=", "new", "cohort_role_assignment", "(", "$", "id", ")", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "// First we do a permissions check.", "require_capability", "(", "'moodle/role:manage'", ",", "$", "context", ")", ";", "// OK - all set.", "return", "$", "cohortroleassignment", "->", "delete", "(", ")", ";", "}" ]
Delete a cohort role assignment by id. Requires moodle/role:manage capability at the system context. @param int $id The record to delete. This will also remove this role from the user for all users in the system. @return boolean
[ "Delete", "a", "cohort", "role", "assignment", "by", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/cohortroles/classes/api.php#L76-L85
213,860
moodle/moodle
cache/stores/mongodb/MongoDB/Operation/CreateCollection.php
CreateCollection.createCommand
private function createCommand() { $cmd = ['create' => $this->collectionName]; foreach (['autoIndexId', 'capped', 'flags', 'max', 'maxTimeMS', 'size', 'validationAction', 'validationLevel'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = $this->options[$option]; } } foreach (['collation', 'indexOptionDefaults', 'storageEngine', 'validator'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = (object) $this->options[$option]; } } return new Command($cmd); }
php
private function createCommand() { $cmd = ['create' => $this->collectionName]; foreach (['autoIndexId', 'capped', 'flags', 'max', 'maxTimeMS', 'size', 'validationAction', 'validationLevel'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = $this->options[$option]; } } foreach (['collation', 'indexOptionDefaults', 'storageEngine', 'validator'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = (object) $this->options[$option]; } } return new Command($cmd); }
[ "private", "function", "createCommand", "(", ")", "{", "$", "cmd", "=", "[", "'create'", "=>", "$", "this", "->", "collectionName", "]", ";", "foreach", "(", "[", "'autoIndexId'", ",", "'capped'", ",", "'flags'", ",", "'max'", ",", "'maxTimeMS'", ",", "'size'", ",", "'validationAction'", ",", "'validationLevel'", "]", "as", "$", "option", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "$", "option", "]", ")", ")", "{", "$", "cmd", "[", "$", "option", "]", "=", "$", "this", "->", "options", "[", "$", "option", "]", ";", "}", "}", "foreach", "(", "[", "'collation'", ",", "'indexOptionDefaults'", ",", "'storageEngine'", ",", "'validator'", "]", "as", "$", "option", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "$", "option", "]", ")", ")", "{", "$", "cmd", "[", "$", "option", "]", "=", "(", "object", ")", "$", "this", "->", "options", "[", "$", "option", "]", ";", "}", "}", "return", "new", "Command", "(", "$", "cmd", ")", ";", "}" ]
Create the create command. @return Command
[ "Create", "the", "create", "command", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Operation/CreateCollection.php#L219-L236
213,861
moodle/moodle
mod/forum/classes/message/inbound/reply_handler.php
reply_handler.process_attachment
protected function process_attachment($acceptedtypes, \context_user $context, $itemid, \stdClass $attachment) { global $USER, $CFG; // Create the file record. $record = new \stdClass(); $record->filearea = 'draft'; $record->component = 'user'; $record->itemid = $itemid; $record->license = $CFG->sitedefaultlicense; $record->author = fullname($USER); $record->contextid = $context->id; $record->userid = $USER->id; // All files sent by e-mail should have a flat structure. $record->filepath = '/'; $record->filename = $attachment->filename; mtrace("--> Attaching {$record->filename} to " . "/{$record->contextid}/{$record->component}/{$record->filearea}/" . "{$record->itemid}{$record->filepath}{$record->filename}"); $fs = get_file_storage(); return $fs->create_file_from_string($record, $attachment->content); }
php
protected function process_attachment($acceptedtypes, \context_user $context, $itemid, \stdClass $attachment) { global $USER, $CFG; // Create the file record. $record = new \stdClass(); $record->filearea = 'draft'; $record->component = 'user'; $record->itemid = $itemid; $record->license = $CFG->sitedefaultlicense; $record->author = fullname($USER); $record->contextid = $context->id; $record->userid = $USER->id; // All files sent by e-mail should have a flat structure. $record->filepath = '/'; $record->filename = $attachment->filename; mtrace("--> Attaching {$record->filename} to " . "/{$record->contextid}/{$record->component}/{$record->filearea}/" . "{$record->itemid}{$record->filepath}{$record->filename}"); $fs = get_file_storage(); return $fs->create_file_from_string($record, $attachment->content); }
[ "protected", "function", "process_attachment", "(", "$", "acceptedtypes", ",", "\\", "context_user", "$", "context", ",", "$", "itemid", ",", "\\", "stdClass", "$", "attachment", ")", "{", "global", "$", "USER", ",", "$", "CFG", ";", "// Create the file record.", "$", "record", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "record", "->", "filearea", "=", "'draft'", ";", "$", "record", "->", "component", "=", "'user'", ";", "$", "record", "->", "itemid", "=", "$", "itemid", ";", "$", "record", "->", "license", "=", "$", "CFG", "->", "sitedefaultlicense", ";", "$", "record", "->", "author", "=", "fullname", "(", "$", "USER", ")", ";", "$", "record", "->", "contextid", "=", "$", "context", "->", "id", ";", "$", "record", "->", "userid", "=", "$", "USER", "->", "id", ";", "// All files sent by e-mail should have a flat structure.", "$", "record", "->", "filepath", "=", "'/'", ";", "$", "record", "->", "filename", "=", "$", "attachment", "->", "filename", ";", "mtrace", "(", "\"--> Attaching {$record->filename} to \"", ".", "\"/{$record->contextid}/{$record->component}/{$record->filearea}/\"", ".", "\"{$record->itemid}{$record->filepath}{$record->filename}\"", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "return", "$", "fs", "->", "create_file_from_string", "(", "$", "record", ",", "$", "attachment", "->", "content", ")", ";", "}" ]
Process attachments included in a message. @param string[] $acceptedtypes String The mimetypes of the acceptable attachment types. @param \context_user $context context_user The context of the user creating this attachment. @param int $itemid int The itemid to store this attachment under. @param \stdClass $attachment stdClass The Attachment data to store. @return \stored_file
[ "Process", "attachments", "included", "in", "a", "message", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/message/inbound/reply_handler.php#L280-L305
213,862
moodle/moodle
mod/forum/classes/message/inbound/reply_handler.php
reply_handler.get_success_message
public function get_success_message(\stdClass $messagedata, $handlerresult) { $a = new \stdClass(); $a->subject = $handlerresult->subject; $discussionurl = new \moodle_url('/mod/forum/discuss.php', array('d' => $handlerresult->discussion)); $discussionurl->set_anchor('p' . $handlerresult->id); $a->discussionurl = $discussionurl->out(); $message = new \stdClass(); $message->plain = get_string('postbymailsuccess', 'mod_forum', $a); $message->html = get_string('postbymailsuccess_html', 'mod_forum', $a); return $message; }
php
public function get_success_message(\stdClass $messagedata, $handlerresult) { $a = new \stdClass(); $a->subject = $handlerresult->subject; $discussionurl = new \moodle_url('/mod/forum/discuss.php', array('d' => $handlerresult->discussion)); $discussionurl->set_anchor('p' . $handlerresult->id); $a->discussionurl = $discussionurl->out(); $message = new \stdClass(); $message->plain = get_string('postbymailsuccess', 'mod_forum', $a); $message->html = get_string('postbymailsuccess_html', 'mod_forum', $a); return $message; }
[ "public", "function", "get_success_message", "(", "\\", "stdClass", "$", "messagedata", ",", "$", "handlerresult", ")", "{", "$", "a", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "a", "->", "subject", "=", "$", "handlerresult", "->", "subject", ";", "$", "discussionurl", "=", "new", "\\", "moodle_url", "(", "'/mod/forum/discuss.php'", ",", "array", "(", "'d'", "=>", "$", "handlerresult", "->", "discussion", ")", ")", ";", "$", "discussionurl", "->", "set_anchor", "(", "'p'", ".", "$", "handlerresult", "->", "id", ")", ";", "$", "a", "->", "discussionurl", "=", "$", "discussionurl", "->", "out", "(", ")", ";", "$", "message", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "message", "->", "plain", "=", "get_string", "(", "'postbymailsuccess'", ",", "'mod_forum'", ",", "$", "a", ")", ";", "$", "message", "->", "html", "=", "get_string", "(", "'postbymailsuccess_html'", ",", "'mod_forum'", ",", "$", "a", ")", ";", "return", "$", "message", ";", "}" ]
Return the content of any success notification to be sent. Both an HTML and Plain Text variant must be provided. @param \stdClass $messagedata The message data. @param \stdClass $handlerresult The record for the newly created post. @return \stdClass with keys `html` and `plain`.
[ "Return", "the", "content", "of", "any", "success", "notification", "to", "be", "sent", ".", "Both", "an", "HTML", "and", "Plain", "Text", "variant", "must", "be", "provided", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/message/inbound/reply_handler.php#L315-L326
213,863
moodle/moodle
enrol/lti/classes/tool_provider.php
tool_provider.onError
protected function onError() { global $OUTPUT; $message = $this->message; if ($this->debugMode && !empty($this->reason)) { $message = $this->reason; } // Display the error message from the provider's side if the consumer has not specified a URL to pass the error to. if (empty($this->returnUrl)) { $this->errorOutput = $OUTPUT->notification(get_string('failedrequest', 'enrol_lti', ['reason' => $message]), 'error'); } }
php
protected function onError() { global $OUTPUT; $message = $this->message; if ($this->debugMode && !empty($this->reason)) { $message = $this->reason; } // Display the error message from the provider's side if the consumer has not specified a URL to pass the error to. if (empty($this->returnUrl)) { $this->errorOutput = $OUTPUT->notification(get_string('failedrequest', 'enrol_lti', ['reason' => $message]), 'error'); } }
[ "protected", "function", "onError", "(", ")", "{", "global", "$", "OUTPUT", ";", "$", "message", "=", "$", "this", "->", "message", ";", "if", "(", "$", "this", "->", "debugMode", "&&", "!", "empty", "(", "$", "this", "->", "reason", ")", ")", "{", "$", "message", "=", "$", "this", "->", "reason", ";", "}", "// Display the error message from the provider's side if the consumer has not specified a URL to pass the error to.", "if", "(", "empty", "(", "$", "this", "->", "returnUrl", ")", ")", "{", "$", "this", "->", "errorOutput", "=", "$", "OUTPUT", "->", "notification", "(", "get_string", "(", "'failedrequest'", ",", "'enrol_lti'", ",", "[", "'reason'", "=>", "$", "message", "]", ")", ",", "'error'", ")", ";", "}", "}" ]
Override onError for custom error handling. @return void
[ "Override", "onError", "for", "custom", "error", "handling", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/tool_provider.php#L170-L182
213,864
moodle/moodle
enrol/lti/classes/tool_provider.php
tool_provider.onRegister
protected function onRegister() { global $PAGE; if (empty($this->consumer)) { $this->ok = false; $this->message = get_string('invalidtoolconsumer', 'enrol_lti'); return; } if (empty($this->returnUrl)) { $this->ok = false; $this->message = get_string('returnurlnotset', 'enrol_lti'); return; } if ($this->doToolProxyService()) { // Map tool consumer and published tool, if necessary. $this->map_tool_to_consumer(); // Indicate successful processing in message. $this->message = get_string('successfulregistration', 'enrol_lti'); // Prepare response. $returnurl = new moodle_url($this->returnUrl); $returnurl->param('lti_msg', get_string("successfulregistration", "enrol_lti")); $returnurl->param('status', 'success'); $guid = $this->consumer->getKey(); $returnurl->param('tool_proxy_guid', $guid); $returnurlout = $returnurl->out(false); $registration = new registration($returnurlout); $output = $PAGE->get_renderer('enrol_lti'); echo $output->render($registration); } else { // Tell the consumer that the registration failed. $this->ok = false; $this->message = get_string('couldnotestablishproxy', 'enrol_lti'); } }
php
protected function onRegister() { global $PAGE; if (empty($this->consumer)) { $this->ok = false; $this->message = get_string('invalidtoolconsumer', 'enrol_lti'); return; } if (empty($this->returnUrl)) { $this->ok = false; $this->message = get_string('returnurlnotset', 'enrol_lti'); return; } if ($this->doToolProxyService()) { // Map tool consumer and published tool, if necessary. $this->map_tool_to_consumer(); // Indicate successful processing in message. $this->message = get_string('successfulregistration', 'enrol_lti'); // Prepare response. $returnurl = new moodle_url($this->returnUrl); $returnurl->param('lti_msg', get_string("successfulregistration", "enrol_lti")); $returnurl->param('status', 'success'); $guid = $this->consumer->getKey(); $returnurl->param('tool_proxy_guid', $guid); $returnurlout = $returnurl->out(false); $registration = new registration($returnurlout); $output = $PAGE->get_renderer('enrol_lti'); echo $output->render($registration); } else { // Tell the consumer that the registration failed. $this->ok = false; $this->message = get_string('couldnotestablishproxy', 'enrol_lti'); } }
[ "protected", "function", "onRegister", "(", ")", "{", "global", "$", "PAGE", ";", "if", "(", "empty", "(", "$", "this", "->", "consumer", ")", ")", "{", "$", "this", "->", "ok", "=", "false", ";", "$", "this", "->", "message", "=", "get_string", "(", "'invalidtoolconsumer'", ",", "'enrol_lti'", ")", ";", "return", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "returnUrl", ")", ")", "{", "$", "this", "->", "ok", "=", "false", ";", "$", "this", "->", "message", "=", "get_string", "(", "'returnurlnotset'", ",", "'enrol_lti'", ")", ";", "return", ";", "}", "if", "(", "$", "this", "->", "doToolProxyService", "(", ")", ")", "{", "// Map tool consumer and published tool, if necessary.", "$", "this", "->", "map_tool_to_consumer", "(", ")", ";", "// Indicate successful processing in message.", "$", "this", "->", "message", "=", "get_string", "(", "'successfulregistration'", ",", "'enrol_lti'", ")", ";", "// Prepare response.", "$", "returnurl", "=", "new", "moodle_url", "(", "$", "this", "->", "returnUrl", ")", ";", "$", "returnurl", "->", "param", "(", "'lti_msg'", ",", "get_string", "(", "\"successfulregistration\"", ",", "\"enrol_lti\"", ")", ")", ";", "$", "returnurl", "->", "param", "(", "'status'", ",", "'success'", ")", ";", "$", "guid", "=", "$", "this", "->", "consumer", "->", "getKey", "(", ")", ";", "$", "returnurl", "->", "param", "(", "'tool_proxy_guid'", ",", "$", "guid", ")", ";", "$", "returnurlout", "=", "$", "returnurl", "->", "out", "(", "false", ")", ";", "$", "registration", "=", "new", "registration", "(", "$", "returnurlout", ")", ";", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'enrol_lti'", ")", ";", "echo", "$", "output", "->", "render", "(", "$", "registration", ")", ";", "}", "else", "{", "// Tell the consumer that the registration failed.", "$", "this", "->", "ok", "=", "false", ";", "$", "this", "->", "message", "=", "get_string", "(", "'couldnotestablishproxy'", ",", "'enrol_lti'", ")", ";", "}", "}" ]
Override onRegister with registration code.
[ "Override", "onRegister", "with", "registration", "code", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/tool_provider.php#L388-L428
213,865
moodle/moodle
enrol/lti/classes/tool_provider.php
tool_provider.map_tool_to_consumer
public function map_tool_to_consumer() { global $DB; if (empty($this->consumer)) { throw new moodle_exception('invalidtoolconsumer', 'enrol_lti'); } // Map the consumer to the tool. $mappingparams = [ 'toolid' => $this->tool->id, 'consumerid' => $this->consumer->getRecordId() ]; $mappingexists = $DB->record_exists('enrol_lti_tool_consumer_map', $mappingparams); if (!$mappingexists) { $DB->insert_record('enrol_lti_tool_consumer_map', (object) $mappingparams); } }
php
public function map_tool_to_consumer() { global $DB; if (empty($this->consumer)) { throw new moodle_exception('invalidtoolconsumer', 'enrol_lti'); } // Map the consumer to the tool. $mappingparams = [ 'toolid' => $this->tool->id, 'consumerid' => $this->consumer->getRecordId() ]; $mappingexists = $DB->record_exists('enrol_lti_tool_consumer_map', $mappingparams); if (!$mappingexists) { $DB->insert_record('enrol_lti_tool_consumer_map', (object) $mappingparams); } }
[ "public", "function", "map_tool_to_consumer", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "this", "->", "consumer", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'invalidtoolconsumer'", ",", "'enrol_lti'", ")", ";", "}", "// Map the consumer to the tool.", "$", "mappingparams", "=", "[", "'toolid'", "=>", "$", "this", "->", "tool", "->", "id", ",", "'consumerid'", "=>", "$", "this", "->", "consumer", "->", "getRecordId", "(", ")", "]", ";", "$", "mappingexists", "=", "$", "DB", "->", "record_exists", "(", "'enrol_lti_tool_consumer_map'", ",", "$", "mappingparams", ")", ";", "if", "(", "!", "$", "mappingexists", ")", "{", "$", "DB", "->", "insert_record", "(", "'enrol_lti_tool_consumer_map'", ",", "(", "object", ")", "$", "mappingparams", ")", ";", "}", "}" ]
Performs mapping of the tool consumer to a published tool. @throws moodle_exception
[ "Performs", "mapping", "of", "the", "tool", "consumer", "to", "a", "published", "tool", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/tool_provider.php#L435-L451
213,866
moodle/moodle
comment/locallib.php
comment_manager.get_comments
function get_comments($page) { global $DB; if ($page == 0) { $start = 0; } else { $start = $page * $this->perpage; } $comments = array(); $usernamefields = get_all_user_name_fields(true, 'u'); $sql = "SELECT c.id, c.contextid, c.itemid, c.component, c.commentarea, c.userid, c.content, $usernamefields, c.timecreated FROM {comments} c JOIN {user} u ON u.id=c.userid ORDER BY c.timecreated ASC"; $rs = $DB->get_recordset_sql($sql, null, $start, $this->perpage); $formatoptions = array('overflowdiv' => true, 'blanktarget' => true); foreach ($rs as $item) { // Set calculated fields $item->fullname = fullname($item); $item->time = userdate($item->timecreated); $item->content = format_text($item->content, FORMAT_MOODLE, $formatoptions); // Unset fields not related to the comment foreach (get_all_user_name_fields() as $namefield) { unset($item->$namefield); } unset($item->timecreated); // Record the comment $comments[] = $item; } $rs->close(); return $comments; }
php
function get_comments($page) { global $DB; if ($page == 0) { $start = 0; } else { $start = $page * $this->perpage; } $comments = array(); $usernamefields = get_all_user_name_fields(true, 'u'); $sql = "SELECT c.id, c.contextid, c.itemid, c.component, c.commentarea, c.userid, c.content, $usernamefields, c.timecreated FROM {comments} c JOIN {user} u ON u.id=c.userid ORDER BY c.timecreated ASC"; $rs = $DB->get_recordset_sql($sql, null, $start, $this->perpage); $formatoptions = array('overflowdiv' => true, 'blanktarget' => true); foreach ($rs as $item) { // Set calculated fields $item->fullname = fullname($item); $item->time = userdate($item->timecreated); $item->content = format_text($item->content, FORMAT_MOODLE, $formatoptions); // Unset fields not related to the comment foreach (get_all_user_name_fields() as $namefield) { unset($item->$namefield); } unset($item->timecreated); // Record the comment $comments[] = $item; } $rs->close(); return $comments; }
[ "function", "get_comments", "(", "$", "page", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "page", "==", "0", ")", "{", "$", "start", "=", "0", ";", "}", "else", "{", "$", "start", "=", "$", "page", "*", "$", "this", "->", "perpage", ";", "}", "$", "comments", "=", "array", "(", ")", ";", "$", "usernamefields", "=", "get_all_user_name_fields", "(", "true", ",", "'u'", ")", ";", "$", "sql", "=", "\"SELECT c.id, c.contextid, c.itemid, c.component, c.commentarea, c.userid, c.content, $usernamefields, c.timecreated\n FROM {comments} c\n JOIN {user} u\n ON u.id=c.userid\n ORDER BY c.timecreated ASC\"", ";", "$", "rs", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "null", ",", "$", "start", ",", "$", "this", "->", "perpage", ")", ";", "$", "formatoptions", "=", "array", "(", "'overflowdiv'", "=>", "true", ",", "'blanktarget'", "=>", "true", ")", ";", "foreach", "(", "$", "rs", "as", "$", "item", ")", "{", "// Set calculated fields", "$", "item", "->", "fullname", "=", "fullname", "(", "$", "item", ")", ";", "$", "item", "->", "time", "=", "userdate", "(", "$", "item", "->", "timecreated", ")", ";", "$", "item", "->", "content", "=", "format_text", "(", "$", "item", "->", "content", ",", "FORMAT_MOODLE", ",", "$", "formatoptions", ")", ";", "// Unset fields not related to the comment", "foreach", "(", "get_all_user_name_fields", "(", ")", "as", "$", "namefield", ")", "{", "unset", "(", "$", "item", "->", "$", "namefield", ")", ";", "}", "unset", "(", "$", "item", "->", "timecreated", ")", ";", "// Record the comment", "$", "comments", "[", "]", "=", "$", "item", ";", "}", "$", "rs", "->", "close", "(", ")", ";", "return", "$", "comments", ";", "}" ]
Return comments by pages @global moodle_database $DB @param int $page @return array An array of comments
[ "Return", "comments", "by", "pages" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/comment/locallib.php#L54-L88
213,867
moodle/moodle
comment/locallib.php
comment_manager.setup_course
private function setup_course($courseid) { global $PAGE, $DB; if (!empty($this->course) && $this->course->id == $courseid) { // already set, stop return; } if ($courseid == $PAGE->course->id) { $this->course = $PAGE->course; } else if (!$this->course = $DB->get_record('course', array('id' => $courseid))) { $this->course = null; } }
php
private function setup_course($courseid) { global $PAGE, $DB; if (!empty($this->course) && $this->course->id == $courseid) { // already set, stop return; } if ($courseid == $PAGE->course->id) { $this->course = $PAGE->course; } else if (!$this->course = $DB->get_record('course', array('id' => $courseid))) { $this->course = null; } }
[ "private", "function", "setup_course", "(", "$", "courseid", ")", "{", "global", "$", "PAGE", ",", "$", "DB", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "course", ")", "&&", "$", "this", "->", "course", "->", "id", "==", "$", "courseid", ")", "{", "// already set, stop", "return", ";", "}", "if", "(", "$", "courseid", "==", "$", "PAGE", "->", "course", "->", "id", ")", "{", "$", "this", "->", "course", "=", "$", "PAGE", "->", "course", ";", "}", "else", "if", "(", "!", "$", "this", "->", "course", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "array", "(", "'id'", "=>", "$", "courseid", ")", ")", ")", "{", "$", "this", "->", "course", "=", "null", ";", "}", "}" ]
Records the course object @global moodle_page $PAGE @global moodle_database $DB @param int $courseid
[ "Records", "the", "course", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/comment/locallib.php#L97-L108
213,868
moodle/moodle
comment/locallib.php
comment_manager.setup_plugin
private function setup_plugin($comment) { global $DB; $this->context = context::instance_by_id($comment->contextid, IGNORE_MISSING); if (!$this->context) { return false; } switch ($this->context->contextlevel) { case CONTEXT_BLOCK: if ($block = $DB->get_record('block_instances', array('id' => $this->context->instanceid))) { $this->plugintype = 'block'; $this->pluginname = $block->blockname; } else { return false; } break; case CONTEXT_MODULE: $this->plugintype = 'mod'; $this->cm = get_coursemodule_from_id('', $this->context->instanceid); $this->setup_course($this->cm->course); $this->modinfo = get_fast_modinfo($this->course); $this->pluginname = $this->modinfo->cms[$this->cm->id]->modname; break; } return true; }
php
private function setup_plugin($comment) { global $DB; $this->context = context::instance_by_id($comment->contextid, IGNORE_MISSING); if (!$this->context) { return false; } switch ($this->context->contextlevel) { case CONTEXT_BLOCK: if ($block = $DB->get_record('block_instances', array('id' => $this->context->instanceid))) { $this->plugintype = 'block'; $this->pluginname = $block->blockname; } else { return false; } break; case CONTEXT_MODULE: $this->plugintype = 'mod'; $this->cm = get_coursemodule_from_id('', $this->context->instanceid); $this->setup_course($this->cm->course); $this->modinfo = get_fast_modinfo($this->course); $this->pluginname = $this->modinfo->cms[$this->cm->id]->modname; break; } return true; }
[ "private", "function", "setup_plugin", "(", "$", "comment", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "context", "=", "context", "::", "instance_by_id", "(", "$", "comment", "->", "contextid", ",", "IGNORE_MISSING", ")", ";", "if", "(", "!", "$", "this", "->", "context", ")", "{", "return", "false", ";", "}", "switch", "(", "$", "this", "->", "context", "->", "contextlevel", ")", "{", "case", "CONTEXT_BLOCK", ":", "if", "(", "$", "block", "=", "$", "DB", "->", "get_record", "(", "'block_instances'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "context", "->", "instanceid", ")", ")", ")", "{", "$", "this", "->", "plugintype", "=", "'block'", ";", "$", "this", "->", "pluginname", "=", "$", "block", "->", "blockname", ";", "}", "else", "{", "return", "false", ";", "}", "break", ";", "case", "CONTEXT_MODULE", ":", "$", "this", "->", "plugintype", "=", "'mod'", ";", "$", "this", "->", "cm", "=", "get_coursemodule_from_id", "(", "''", ",", "$", "this", "->", "context", "->", "instanceid", ")", ";", "$", "this", "->", "setup_course", "(", "$", "this", "->", "cm", "->", "course", ")", ";", "$", "this", "->", "modinfo", "=", "get_fast_modinfo", "(", "$", "this", "->", "course", ")", ";", "$", "this", "->", "pluginname", "=", "$", "this", "->", "modinfo", "->", "cms", "[", "$", "this", "->", "cm", "->", "id", "]", "->", "modname", ";", "break", ";", "}", "return", "true", ";", "}" ]
Sets up the module or block information for a comment @global moodle_database $DB @param stdClass $comment @return bool
[ "Sets", "up", "the", "module", "or", "block", "information", "for", "a", "comment" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/comment/locallib.php#L117-L141
213,869
moodle/moodle
comment/locallib.php
comment_manager.get_component_comments_since
public function get_component_comments_since($course, $context, $component, $since, $cm = null) { global $DB; $commentssince = array(); $where = 'contextid = ? AND component = ? AND timecreated > ?'; $comments = $DB->get_records_select('comments', $where, array($context->id, $component, $since)); // Check item by item if we have permissions. $managersviewstatus = array(); foreach ($comments as $comment) { // Check if the manager for the item is cached. if (!isset($managersviewstatus[$comment->commentarea]) or !isset($managersviewstatus[$comment->commentarea][$comment->itemid])) { $args = new stdClass; $args->area = $comment->commentarea; $args->itemid = $comment->itemid; $args->context = $context; $args->course = $course; $args->client_id = 0; $args->component = $component; if (!empty($cm)) { $args->cm = $cm; } $manager = new comment($args); $managersviewstatus[$comment->commentarea][$comment->itemid] = $manager->can_view(); } if ($managersviewstatus[$comment->commentarea][$comment->itemid]) { $commentssince[$comment->id] = $comment; } } return $commentssince; }
php
public function get_component_comments_since($course, $context, $component, $since, $cm = null) { global $DB; $commentssince = array(); $where = 'contextid = ? AND component = ? AND timecreated > ?'; $comments = $DB->get_records_select('comments', $where, array($context->id, $component, $since)); // Check item by item if we have permissions. $managersviewstatus = array(); foreach ($comments as $comment) { // Check if the manager for the item is cached. if (!isset($managersviewstatus[$comment->commentarea]) or !isset($managersviewstatus[$comment->commentarea][$comment->itemid])) { $args = new stdClass; $args->area = $comment->commentarea; $args->itemid = $comment->itemid; $args->context = $context; $args->course = $course; $args->client_id = 0; $args->component = $component; if (!empty($cm)) { $args->cm = $cm; } $manager = new comment($args); $managersviewstatus[$comment->commentarea][$comment->itemid] = $manager->can_view(); } if ($managersviewstatus[$comment->commentarea][$comment->itemid]) { $commentssince[$comment->id] = $comment; } } return $commentssince; }
[ "public", "function", "get_component_comments_since", "(", "$", "course", ",", "$", "context", ",", "$", "component", ",", "$", "since", ",", "$", "cm", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "commentssince", "=", "array", "(", ")", ";", "$", "where", "=", "'contextid = ? AND component = ? AND timecreated > ?'", ";", "$", "comments", "=", "$", "DB", "->", "get_records_select", "(", "'comments'", ",", "$", "where", ",", "array", "(", "$", "context", "->", "id", ",", "$", "component", ",", "$", "since", ")", ")", ";", "// Check item by item if we have permissions.", "$", "managersviewstatus", "=", "array", "(", ")", ";", "foreach", "(", "$", "comments", "as", "$", "comment", ")", "{", "// Check if the manager for the item is cached.", "if", "(", "!", "isset", "(", "$", "managersviewstatus", "[", "$", "comment", "->", "commentarea", "]", ")", "or", "!", "isset", "(", "$", "managersviewstatus", "[", "$", "comment", "->", "commentarea", "]", "[", "$", "comment", "->", "itemid", "]", ")", ")", "{", "$", "args", "=", "new", "stdClass", ";", "$", "args", "->", "area", "=", "$", "comment", "->", "commentarea", ";", "$", "args", "->", "itemid", "=", "$", "comment", "->", "itemid", ";", "$", "args", "->", "context", "=", "$", "context", ";", "$", "args", "->", "course", "=", "$", "course", ";", "$", "args", "->", "client_id", "=", "0", ";", "$", "args", "->", "component", "=", "$", "component", ";", "if", "(", "!", "empty", "(", "$", "cm", ")", ")", "{", "$", "args", "->", "cm", "=", "$", "cm", ";", "}", "$", "manager", "=", "new", "comment", "(", "$", "args", ")", ";", "$", "managersviewstatus", "[", "$", "comment", "->", "commentarea", "]", "[", "$", "comment", "->", "itemid", "]", "=", "$", "manager", "->", "can_view", "(", ")", ";", "}", "if", "(", "$", "managersviewstatus", "[", "$", "comment", "->", "commentarea", "]", "[", "$", "comment", "->", "itemid", "]", ")", "{", "$", "commentssince", "[", "$", "comment", "->", "id", "]", "=", "$", "comment", ";", "}", "}", "return", "$", "commentssince", ";", "}" ]
Get comments created since a given time. @param stdClass $course course object @param stdClass $context context object @param string $component component name @param int $since the time to check @param stdClass $cm course module object @return array list of comments db records since the given timelimit @since Moodle 3.2
[ "Get", "comments", "created", "since", "a", "given", "time", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/comment/locallib.php#L234-L267
213,870
moodle/moodle
lib/google/curlio.php
moodle_google_curlio.do_request
private function do_request($curl, $request) { $url = $request->getUrl(); $method = $request->getRequestMethod(); switch (strtoupper($method)) { case 'POST': $ret = $curl->post($url, $request->getPostBody()); break; case 'GET': $ret = $curl->get($url); break; case 'HEAD': $ret = $curl->head($url); break; case 'PUT': $ret = $curl->put($url); break; default: throw new coding_exception('Unknown request type: ' . $method); break; } return $ret; }
php
private function do_request($curl, $request) { $url = $request->getUrl(); $method = $request->getRequestMethod(); switch (strtoupper($method)) { case 'POST': $ret = $curl->post($url, $request->getPostBody()); break; case 'GET': $ret = $curl->get($url); break; case 'HEAD': $ret = $curl->head($url); break; case 'PUT': $ret = $curl->put($url); break; default: throw new coding_exception('Unknown request type: ' . $method); break; } return $ret; }
[ "private", "function", "do_request", "(", "$", "curl", ",", "$", "request", ")", "{", "$", "url", "=", "$", "request", "->", "getUrl", "(", ")", ";", "$", "method", "=", "$", "request", "->", "getRequestMethod", "(", ")", ";", "switch", "(", "strtoupper", "(", "$", "method", ")", ")", "{", "case", "'POST'", ":", "$", "ret", "=", "$", "curl", "->", "post", "(", "$", "url", ",", "$", "request", "->", "getPostBody", "(", ")", ")", ";", "break", ";", "case", "'GET'", ":", "$", "ret", "=", "$", "curl", "->", "get", "(", "$", "url", ")", ";", "break", ";", "case", "'HEAD'", ":", "$", "ret", "=", "$", "curl", "->", "head", "(", "$", "url", ")", ";", "break", ";", "case", "'PUT'", ":", "$", "ret", "=", "$", "curl", "->", "put", "(", "$", "url", ")", ";", "break", ";", "default", ":", "throw", "new", "coding_exception", "(", "'Unknown request type: '", ".", "$", "method", ")", ";", "break", ";", "}", "return", "$", "ret", ";", "}" ]
Send the request via our curl object. @param curl $curl prepared curl object. @param Google_HttpRequest $request The request. @return string result of the request.
[ "Send", "the", "request", "via", "our", "curl", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/curlio.php#L54-L75
213,871
moodle/moodle
lib/google/curlio.php
moodle_google_curlio.executeRequest
public function executeRequest(Google_Http_Request $request) { $curl = new curl(); if ($request->getPostBody()) { $curl->setopt(array('CURLOPT_POSTFIELDS' => $request->getPostBody())); } $requestHeaders = $request->getRequestHeaders(); if ($requestHeaders && is_array($requestHeaders)) { $curlHeaders = array(); foreach ($requestHeaders as $k => $v) { $curlHeaders[] = "$k: $v"; } $curl->setopt(array('CURLOPT_HTTPHEADER' => $curlHeaders)); } $curl->setopt(array('CURLOPT_URL' => $request->getUrl())); $curl->setopt(array('CURLOPT_CUSTOMREQUEST' => $request->getRequestMethod())); $curl->setopt(array('CURLOPT_USERAGENT' => $request->getUserAgent())); $curl->setopt(array('CURLOPT_FOLLOWLOCATION' => false)); $curl->setopt(array('CURLOPT_SSL_VERIFYPEER' => true)); $curl->setopt(array('CURLOPT_RETURNTRANSFER' => true)); $curl->setopt(array('CURLOPT_HEADER' => true)); if ($request->canGzip()) { $curl->setopt(array('CURLOPT_ENCODING' => 'gzip,deflate')); } $curl->setopt($this->options); $respdata = $this->do_request($curl, $request); $infos = $curl->get_info(); $respheadersize = $infos['header_size']; $resphttpcode = (int) $infos['http_code']; $curlerrornum = $curl->get_errno(); $curlerror = $curl->error; if ($respdata != CURLE_OK) { throw new Google_IO_Exception($curlerror); } list($responseHeaders, $responseBody) = $this->parseHttpResponse($respdata, $respheadersize); return array($responseBody, $responseHeaders, $resphttpcode); }
php
public function executeRequest(Google_Http_Request $request) { $curl = new curl(); if ($request->getPostBody()) { $curl->setopt(array('CURLOPT_POSTFIELDS' => $request->getPostBody())); } $requestHeaders = $request->getRequestHeaders(); if ($requestHeaders && is_array($requestHeaders)) { $curlHeaders = array(); foreach ($requestHeaders as $k => $v) { $curlHeaders[] = "$k: $v"; } $curl->setopt(array('CURLOPT_HTTPHEADER' => $curlHeaders)); } $curl->setopt(array('CURLOPT_URL' => $request->getUrl())); $curl->setopt(array('CURLOPT_CUSTOMREQUEST' => $request->getRequestMethod())); $curl->setopt(array('CURLOPT_USERAGENT' => $request->getUserAgent())); $curl->setopt(array('CURLOPT_FOLLOWLOCATION' => false)); $curl->setopt(array('CURLOPT_SSL_VERIFYPEER' => true)); $curl->setopt(array('CURLOPT_RETURNTRANSFER' => true)); $curl->setopt(array('CURLOPT_HEADER' => true)); if ($request->canGzip()) { $curl->setopt(array('CURLOPT_ENCODING' => 'gzip,deflate')); } $curl->setopt($this->options); $respdata = $this->do_request($curl, $request); $infos = $curl->get_info(); $respheadersize = $infos['header_size']; $resphttpcode = (int) $infos['http_code']; $curlerrornum = $curl->get_errno(); $curlerror = $curl->error; if ($respdata != CURLE_OK) { throw new Google_IO_Exception($curlerror); } list($responseHeaders, $responseBody) = $this->parseHttpResponse($respdata, $respheadersize); return array($responseBody, $responseHeaders, $resphttpcode); }
[ "public", "function", "executeRequest", "(", "Google_Http_Request", "$", "request", ")", "{", "$", "curl", "=", "new", "curl", "(", ")", ";", "if", "(", "$", "request", "->", "getPostBody", "(", ")", ")", "{", "$", "curl", "->", "setopt", "(", "array", "(", "'CURLOPT_POSTFIELDS'", "=>", "$", "request", "->", "getPostBody", "(", ")", ")", ")", ";", "}", "$", "requestHeaders", "=", "$", "request", "->", "getRequestHeaders", "(", ")", ";", "if", "(", "$", "requestHeaders", "&&", "is_array", "(", "$", "requestHeaders", ")", ")", "{", "$", "curlHeaders", "=", "array", "(", ")", ";", "foreach", "(", "$", "requestHeaders", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "curlHeaders", "[", "]", "=", "\"$k: $v\"", ";", "}", "$", "curl", "->", "setopt", "(", "array", "(", "'CURLOPT_HTTPHEADER'", "=>", "$", "curlHeaders", ")", ")", ";", "}", "$", "curl", "->", "setopt", "(", "array", "(", "'CURLOPT_URL'", "=>", "$", "request", "->", "getUrl", "(", ")", ")", ")", ";", "$", "curl", "->", "setopt", "(", "array", "(", "'CURLOPT_CUSTOMREQUEST'", "=>", "$", "request", "->", "getRequestMethod", "(", ")", ")", ")", ";", "$", "curl", "->", "setopt", "(", "array", "(", "'CURLOPT_USERAGENT'", "=>", "$", "request", "->", "getUserAgent", "(", ")", ")", ")", ";", "$", "curl", "->", "setopt", "(", "array", "(", "'CURLOPT_FOLLOWLOCATION'", "=>", "false", ")", ")", ";", "$", "curl", "->", "setopt", "(", "array", "(", "'CURLOPT_SSL_VERIFYPEER'", "=>", "true", ")", ")", ";", "$", "curl", "->", "setopt", "(", "array", "(", "'CURLOPT_RETURNTRANSFER'", "=>", "true", ")", ")", ";", "$", "curl", "->", "setopt", "(", "array", "(", "'CURLOPT_HEADER'", "=>", "true", ")", ")", ";", "if", "(", "$", "request", "->", "canGzip", "(", ")", ")", "{", "$", "curl", "->", "setopt", "(", "array", "(", "'CURLOPT_ENCODING'", "=>", "'gzip,deflate'", ")", ")", ";", "}", "$", "curl", "->", "setopt", "(", "$", "this", "->", "options", ")", ";", "$", "respdata", "=", "$", "this", "->", "do_request", "(", "$", "curl", ",", "$", "request", ")", ";", "$", "infos", "=", "$", "curl", "->", "get_info", "(", ")", ";", "$", "respheadersize", "=", "$", "infos", "[", "'header_size'", "]", ";", "$", "resphttpcode", "=", "(", "int", ")", "$", "infos", "[", "'http_code'", "]", ";", "$", "curlerrornum", "=", "$", "curl", "->", "get_errno", "(", ")", ";", "$", "curlerror", "=", "$", "curl", "->", "error", ";", "if", "(", "$", "respdata", "!=", "CURLE_OK", ")", "{", "throw", "new", "Google_IO_Exception", "(", "$", "curlerror", ")", ";", "}", "list", "(", "$", "responseHeaders", ",", "$", "responseBody", ")", "=", "$", "this", "->", "parseHttpResponse", "(", "$", "respdata", ",", "$", "respheadersize", ")", ";", "return", "array", "(", "$", "responseBody", ",", "$", "responseHeaders", ",", "$", "resphttpcode", ")", ";", "}" ]
Execute an API request. This is a copy/paste from the parent class that uses Moodle's implementation of curl. Portions have been removed or altered. @param Google_Http_Request $request the http request to be executed @return Google_Http_Request http request with the response http code, response headers and response body filled in @throws Google_IO_Exception on curl or IO error
[ "Execute", "an", "API", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/curlio.php#L88-L133
213,872
moodle/moodle
lib/google/curlio.php
moodle_google_curlio.get_option_name_from_constant
public function get_option_name_from_constant($constant) { if (is_null(self::$constants)) { $constants = get_defined_constants(true); $constants = isset($constants['curl']) ? $constants['curl'] : array(); $constants = array_flip($constants); self::$constants = $constants; } if (isset(self::$constants[$constant])) { return self::$constants[$constant]; } throw new coding_exception('Unknown curl constant value: ' . $constant); }
php
public function get_option_name_from_constant($constant) { if (is_null(self::$constants)) { $constants = get_defined_constants(true); $constants = isset($constants['curl']) ? $constants['curl'] : array(); $constants = array_flip($constants); self::$constants = $constants; } if (isset(self::$constants[$constant])) { return self::$constants[$constant]; } throw new coding_exception('Unknown curl constant value: ' . $constant); }
[ "public", "function", "get_option_name_from_constant", "(", "$", "constant", ")", "{", "if", "(", "is_null", "(", "self", "::", "$", "constants", ")", ")", "{", "$", "constants", "=", "get_defined_constants", "(", "true", ")", ";", "$", "constants", "=", "isset", "(", "$", "constants", "[", "'curl'", "]", ")", "?", "$", "constants", "[", "'curl'", "]", ":", "array", "(", ")", ";", "$", "constants", "=", "array_flip", "(", "$", "constants", ")", ";", "self", "::", "$", "constants", "=", "$", "constants", ";", "}", "if", "(", "isset", "(", "self", "::", "$", "constants", "[", "$", "constant", "]", ")", ")", "{", "return", "self", "::", "$", "constants", "[", "$", "constant", "]", ";", "}", "throw", "new", "coding_exception", "(", "'Unknown curl constant value: '", ".", "$", "constant", ")", ";", "}" ]
Return the name of an option based on the constant value. @param int $constant value of a CURL constant. @return string name of the constant if found, or throws exception. @throws coding_exception when the constant is not found. @since Moodle 2.5
[ "Return", "the", "name", "of", "an", "option", "based", "on", "the", "constant", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/curlio.php#L191-L202
213,873
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Data/Format/List.php
Horde_Imap_Client_Data_Format_List.add
public function add($data, $merge = false) { if (is_array($data) || ($merge && ($data instanceof Traversable))) { foreach ($data as $val) { $this->add($val); } } elseif (is_object($data)) { $this->_data[] = $data; } elseif (!is_null($data)) { $this->_data[] = new Horde_Imap_Client_Data_Format_Atom($data); } return $this; }
php
public function add($data, $merge = false) { if (is_array($data) || ($merge && ($data instanceof Traversable))) { foreach ($data as $val) { $this->add($val); } } elseif (is_object($data)) { $this->_data[] = $data; } elseif (!is_null($data)) { $this->_data[] = new Horde_Imap_Client_Data_Format_Atom($data); } return $this; }
[ "public", "function", "add", "(", "$", "data", ",", "$", "merge", "=", "false", ")", "{", "if", "(", "is_array", "(", "$", "data", ")", "||", "(", "$", "merge", "&&", "(", "$", "data", "instanceof", "Traversable", ")", ")", ")", "{", "foreach", "(", "$", "data", "as", "$", "val", ")", "{", "$", "this", "->", "add", "(", "$", "val", ")", ";", "}", "}", "elseif", "(", "is_object", "(", "$", "data", ")", ")", "{", "$", "this", "->", "_data", "[", "]", "=", "$", "data", ";", "}", "elseif", "(", "!", "is_null", "(", "$", "data", ")", ")", "{", "$", "this", "->", "_data", "[", "]", "=", "new", "Horde_Imap_Client_Data_Format_Atom", "(", "$", "data", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add an element to the list. @param mixed $data The data element(s) to add. Either a Horde_Imap_Client_Data_Format object, a string value that will be treated as an IMAP atom, or an array (or iterable object) of objects to add. @param boolean $merge Merge the contents of any container objects, instead of adding the objects themselves? @return Horde_Imap_Client_Data_Format_List This object to allow for chainable calls (since 2.10.0).
[ "Add", "an", "element", "to", "the", "list", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Data/Format/List.php#L51-L64
213,874
moodle/moodle
lib/simplepie/library/SimplePie/IRI.php
SimplePie_IRI.get_iauthority
protected function get_iauthority() { if ($this->iuserinfo !== null || $this->ihost !== null || $this->port !== null) { $iauthority = ''; if ($this->iuserinfo !== null) { $iauthority .= $this->iuserinfo . '@'; } if ($this->ihost !== null) { $iauthority .= $this->ihost; } if ($this->port !== null) { $iauthority .= ':' . $this->port; } return $iauthority; } else { return null; } }
php
protected function get_iauthority() { if ($this->iuserinfo !== null || $this->ihost !== null || $this->port !== null) { $iauthority = ''; if ($this->iuserinfo !== null) { $iauthority .= $this->iuserinfo . '@'; } if ($this->ihost !== null) { $iauthority .= $this->ihost; } if ($this->port !== null) { $iauthority .= ':' . $this->port; } return $iauthority; } else { return null; } }
[ "protected", "function", "get_iauthority", "(", ")", "{", "if", "(", "$", "this", "->", "iuserinfo", "!==", "null", "||", "$", "this", "->", "ihost", "!==", "null", "||", "$", "this", "->", "port", "!==", "null", ")", "{", "$", "iauthority", "=", "''", ";", "if", "(", "$", "this", "->", "iuserinfo", "!==", "null", ")", "{", "$", "iauthority", ".=", "$", "this", "->", "iuserinfo", ".", "'@'", ";", "}", "if", "(", "$", "this", "->", "ihost", "!==", "null", ")", "{", "$", "iauthority", ".=", "$", "this", "->", "ihost", ";", "}", "if", "(", "$", "this", "->", "port", "!==", "null", ")", "{", "$", "iauthority", ".=", "':'", ".", "$", "this", "->", "port", ";", "}", "return", "$", "iauthority", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Get the complete iauthority @return string
[ "Get", "the", "complete", "iauthority" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/IRI.php#L1219-L1242
213,875
moodle/moodle
lib/classes/output/mustache_template_finder.php
mustache_template_finder.get_template_directories_for_component
public static function get_template_directories_for_component($component, $themename = '') { global $CFG, $PAGE; // Default the param. if ($themename == '') { $themename = $PAGE->theme->name; } // Clean params for safety. $component = clean_param($component, PARAM_COMPONENT); $themename = clean_param($themename, PARAM_COMPONENT); // Validate the component. $dirs = array(); $compdirectory = core_component::get_component_directory($component); if (!$compdirectory) { throw new coding_exception("Component was not valid: " . s($component)); } // Find the parent themes. $parents = array(); if ($themename === $PAGE->theme->name) { $parents = $PAGE->theme->parents; } else { $themeconfig = theme_config::load($themename); $parents = $themeconfig->parents; } // First check the theme. $dirs[] = $CFG->dirroot . '/theme/' . $themename . '/templates/' . $component . '/'; if (isset($CFG->themedir)) { $dirs[] = $CFG->themedir . '/' . $themename . '/templates/' . $component . '/'; } // Now check the parent themes. // Search each of the parent themes second. foreach ($parents as $parent) { $dirs[] = $CFG->dirroot . '/theme/' . $parent . '/templates/' . $component . '/'; if (isset($CFG->themedir)) { $dirs[] = $CFG->themedir . '/' . $parent . '/templates/' . $component . '/'; } } $dirs[] = $compdirectory . '/templates/'; return $dirs; }
php
public static function get_template_directories_for_component($component, $themename = '') { global $CFG, $PAGE; // Default the param. if ($themename == '') { $themename = $PAGE->theme->name; } // Clean params for safety. $component = clean_param($component, PARAM_COMPONENT); $themename = clean_param($themename, PARAM_COMPONENT); // Validate the component. $dirs = array(); $compdirectory = core_component::get_component_directory($component); if (!$compdirectory) { throw new coding_exception("Component was not valid: " . s($component)); } // Find the parent themes. $parents = array(); if ($themename === $PAGE->theme->name) { $parents = $PAGE->theme->parents; } else { $themeconfig = theme_config::load($themename); $parents = $themeconfig->parents; } // First check the theme. $dirs[] = $CFG->dirroot . '/theme/' . $themename . '/templates/' . $component . '/'; if (isset($CFG->themedir)) { $dirs[] = $CFG->themedir . '/' . $themename . '/templates/' . $component . '/'; } // Now check the parent themes. // Search each of the parent themes second. foreach ($parents as $parent) { $dirs[] = $CFG->dirroot . '/theme/' . $parent . '/templates/' . $component . '/'; if (isset($CFG->themedir)) { $dirs[] = $CFG->themedir . '/' . $parent . '/templates/' . $component . '/'; } } $dirs[] = $compdirectory . '/templates/'; return $dirs; }
[ "public", "static", "function", "get_template_directories_for_component", "(", "$", "component", ",", "$", "themename", "=", "''", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ";", "// Default the param.", "if", "(", "$", "themename", "==", "''", ")", "{", "$", "themename", "=", "$", "PAGE", "->", "theme", "->", "name", ";", "}", "// Clean params for safety.", "$", "component", "=", "clean_param", "(", "$", "component", ",", "PARAM_COMPONENT", ")", ";", "$", "themename", "=", "clean_param", "(", "$", "themename", ",", "PARAM_COMPONENT", ")", ";", "// Validate the component.", "$", "dirs", "=", "array", "(", ")", ";", "$", "compdirectory", "=", "core_component", "::", "get_component_directory", "(", "$", "component", ")", ";", "if", "(", "!", "$", "compdirectory", ")", "{", "throw", "new", "coding_exception", "(", "\"Component was not valid: \"", ".", "s", "(", "$", "component", ")", ")", ";", "}", "// Find the parent themes.", "$", "parents", "=", "array", "(", ")", ";", "if", "(", "$", "themename", "===", "$", "PAGE", "->", "theme", "->", "name", ")", "{", "$", "parents", "=", "$", "PAGE", "->", "theme", "->", "parents", ";", "}", "else", "{", "$", "themeconfig", "=", "theme_config", "::", "load", "(", "$", "themename", ")", ";", "$", "parents", "=", "$", "themeconfig", "->", "parents", ";", "}", "// First check the theme.", "$", "dirs", "[", "]", "=", "$", "CFG", "->", "dirroot", ".", "'/theme/'", ".", "$", "themename", ".", "'/templates/'", ".", "$", "component", ".", "'/'", ";", "if", "(", "isset", "(", "$", "CFG", "->", "themedir", ")", ")", "{", "$", "dirs", "[", "]", "=", "$", "CFG", "->", "themedir", ".", "'/'", ".", "$", "themename", ".", "'/templates/'", ".", "$", "component", ".", "'/'", ";", "}", "// Now check the parent themes.", "// Search each of the parent themes second.", "foreach", "(", "$", "parents", "as", "$", "parent", ")", "{", "$", "dirs", "[", "]", "=", "$", "CFG", "->", "dirroot", ".", "'/theme/'", ".", "$", "parent", ".", "'/templates/'", ".", "$", "component", ".", "'/'", ";", "if", "(", "isset", "(", "$", "CFG", "->", "themedir", ")", ")", "{", "$", "dirs", "[", "]", "=", "$", "CFG", "->", "themedir", ".", "'/'", ".", "$", "parent", ".", "'/templates/'", ".", "$", "component", ".", "'/'", ";", "}", "}", "$", "dirs", "[", "]", "=", "$", "compdirectory", ".", "'/templates/'", ";", "return", "$", "dirs", ";", "}" ]
Helper function for getting a list of valid template directories for a specific component. @param string $component The component to search @param string $themename The current theme name @return string[] List of valid directories for templates for this compoonent. Directories are not checked for existence.
[ "Helper", "function", "for", "getting", "a", "list", "of", "valid", "template", "directories", "for", "a", "specific", "component", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/mustache_template_finder.php#L49-L94
213,876
moodle/moodle
lib/classes/output/mustache_template_finder.php
mustache_template_finder.get_template_filepath
public static function get_template_filepath($name, $themename = '') { global $CFG, $PAGE; if (strpos($name, '/') === false) { throw new coding_exception('Templates names must be specified as "componentname/templatename"' . ' (' . s($name) . ' requested) '); } list($component, $templatename) = explode('/', $name, 2); $component = clean_param($component, PARAM_COMPONENT); if (strpos($templatename, '/') !== false) { throw new coding_exception('Templates cannot be placed in sub directories (' . s($name) . ' requested)'); } $dirs = self::get_template_directories_for_component($component, $themename); foreach ($dirs as $dir) { $candidate = $dir . $templatename . '.mustache'; if (file_exists($candidate)) { return $candidate; } } throw new moodle_exception('filenotfound', 'error', '', null, $name); }
php
public static function get_template_filepath($name, $themename = '') { global $CFG, $PAGE; if (strpos($name, '/') === false) { throw new coding_exception('Templates names must be specified as "componentname/templatename"' . ' (' . s($name) . ' requested) '); } list($component, $templatename) = explode('/', $name, 2); $component = clean_param($component, PARAM_COMPONENT); if (strpos($templatename, '/') !== false) { throw new coding_exception('Templates cannot be placed in sub directories (' . s($name) . ' requested)'); } $dirs = self::get_template_directories_for_component($component, $themename); foreach ($dirs as $dir) { $candidate = $dir . $templatename . '.mustache'; if (file_exists($candidate)) { return $candidate; } } throw new moodle_exception('filenotfound', 'error', '', null, $name); }
[ "public", "static", "function", "get_template_filepath", "(", "$", "name", ",", "$", "themename", "=", "''", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ";", "if", "(", "strpos", "(", "$", "name", ",", "'/'", ")", "===", "false", ")", "{", "throw", "new", "coding_exception", "(", "'Templates names must be specified as \"componentname/templatename\"'", ".", "' ('", ".", "s", "(", "$", "name", ")", ".", "' requested) '", ")", ";", "}", "list", "(", "$", "component", ",", "$", "templatename", ")", "=", "explode", "(", "'/'", ",", "$", "name", ",", "2", ")", ";", "$", "component", "=", "clean_param", "(", "$", "component", ",", "PARAM_COMPONENT", ")", ";", "if", "(", "strpos", "(", "$", "templatename", ",", "'/'", ")", "!==", "false", ")", "{", "throw", "new", "coding_exception", "(", "'Templates cannot be placed in sub directories ('", ".", "s", "(", "$", "name", ")", ".", "' requested)'", ")", ";", "}", "$", "dirs", "=", "self", "::", "get_template_directories_for_component", "(", "$", "component", ",", "$", "themename", ")", ";", "foreach", "(", "$", "dirs", "as", "$", "dir", ")", "{", "$", "candidate", "=", "$", "dir", ".", "$", "templatename", ".", "'.mustache'", ";", "if", "(", "file_exists", "(", "$", "candidate", ")", ")", "{", "return", "$", "candidate", ";", "}", "}", "throw", "new", "moodle_exception", "(", "'filenotfound'", ",", "'error'", ",", "''", ",", "null", ",", "$", "name", ")", ";", "}" ]
Helper function for getting a filename for a template from the template name. @param string $name - This is the componentname/templatename combined. @param string $themename - This is the current theme name. @return string
[ "Helper", "function", "for", "getting", "a", "filename", "for", "a", "template", "from", "the", "template", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/mustache_template_finder.php#L103-L126
213,877
moodle/moodle
admin/tool/policy/classes/output/renderer.php
renderer.render
public function render(renderable $widget) { $namespacedclassname = get_class($widget); $plainclassname = preg_replace('/^.*\\\/', '', $namespacedclassname); $rendermethod = 'render_'.$plainclassname; if (method_exists($this, $rendermethod)) { // Explicit rendering method exists, fall back to the default behaviour. return parent::render($widget); } $interfaces = class_implements($namespacedclassname); if (isset($interfaces['templatable'])) { // Default implementation of template-based rendering. $data = $widget->export_for_template($this); return parent::render_from_template('tool_policy/'.$plainclassname, $data); } else { return parent::render($widget); } }
php
public function render(renderable $widget) { $namespacedclassname = get_class($widget); $plainclassname = preg_replace('/^.*\\\/', '', $namespacedclassname); $rendermethod = 'render_'.$plainclassname; if (method_exists($this, $rendermethod)) { // Explicit rendering method exists, fall back to the default behaviour. return parent::render($widget); } $interfaces = class_implements($namespacedclassname); if (isset($interfaces['templatable'])) { // Default implementation of template-based rendering. $data = $widget->export_for_template($this); return parent::render_from_template('tool_policy/'.$plainclassname, $data); } else { return parent::render($widget); } }
[ "public", "function", "render", "(", "renderable", "$", "widget", ")", "{", "$", "namespacedclassname", "=", "get_class", "(", "$", "widget", ")", ";", "$", "plainclassname", "=", "preg_replace", "(", "'/^.*\\\\\\/'", ",", "''", ",", "$", "namespacedclassname", ")", ";", "$", "rendermethod", "=", "'render_'", ".", "$", "plainclassname", ";", "if", "(", "method_exists", "(", "$", "this", ",", "$", "rendermethod", ")", ")", "{", "// Explicit rendering method exists, fall back to the default behaviour.", "return", "parent", "::", "render", "(", "$", "widget", ")", ";", "}", "$", "interfaces", "=", "class_implements", "(", "$", "namespacedclassname", ")", ";", "if", "(", "isset", "(", "$", "interfaces", "[", "'templatable'", "]", ")", ")", "{", "// Default implementation of template-based rendering.", "$", "data", "=", "$", "widget", "->", "export_for_template", "(", "$", "this", ")", ";", "return", "parent", "::", "render_from_template", "(", "'tool_policy/'", ".", "$", "plainclassname", ",", "$", "data", ")", ";", "}", "else", "{", "return", "parent", "::", "render", "(", "$", "widget", ")", ";", "}", "}" ]
Overrides the parent so that templatable widgets are handled even without their explicit render method. @param renderable $widget @return string
[ "Overrides", "the", "parent", "so", "that", "templatable", "widgets", "are", "handled", "even", "without", "their", "explicit", "render", "method", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/output/renderer.php#L49-L70
213,878
moodle/moodle
lib/portfolio/formats.php
portfolio_format.make_tag
public static function make_tag($file, $path, $attributes) { $srcattr = 'href'; $tag = 'a'; $content = $file->get_filename(); if (in_array($file->get_mimetype(), portfolio_format_image::mimetypes())) { $srcattr = 'src'; $tag = 'img'; $content = ''; } $attributes[$srcattr] = $path; // this will override anything we might have been passed (which is good) $dom = new DomDocument(); $elem = null; if ($content) { $elem = $dom->createElement($tag, $content); } else { $elem = $dom->createElement($tag); } foreach ($attributes as $key => $value) { $elem->setAttribute($key, $value); } $dom->appendChild($elem); return $dom->saveXML($elem); }
php
public static function make_tag($file, $path, $attributes) { $srcattr = 'href'; $tag = 'a'; $content = $file->get_filename(); if (in_array($file->get_mimetype(), portfolio_format_image::mimetypes())) { $srcattr = 'src'; $tag = 'img'; $content = ''; } $attributes[$srcattr] = $path; // this will override anything we might have been passed (which is good) $dom = new DomDocument(); $elem = null; if ($content) { $elem = $dom->createElement($tag, $content); } else { $elem = $dom->createElement($tag); } foreach ($attributes as $key => $value) { $elem->setAttribute($key, $value); } $dom->appendChild($elem); return $dom->saveXML($elem); }
[ "public", "static", "function", "make_tag", "(", "$", "file", ",", "$", "path", ",", "$", "attributes", ")", "{", "$", "srcattr", "=", "'href'", ";", "$", "tag", "=", "'a'", ";", "$", "content", "=", "$", "file", "->", "get_filename", "(", ")", ";", "if", "(", "in_array", "(", "$", "file", "->", "get_mimetype", "(", ")", ",", "portfolio_format_image", "::", "mimetypes", "(", ")", ")", ")", "{", "$", "srcattr", "=", "'src'", ";", "$", "tag", "=", "'img'", ";", "$", "content", "=", "''", ";", "}", "$", "attributes", "[", "$", "srcattr", "]", "=", "$", "path", ";", "// this will override anything we might have been passed (which is good)", "$", "dom", "=", "new", "DomDocument", "(", ")", ";", "$", "elem", "=", "null", ";", "if", "(", "$", "content", ")", "{", "$", "elem", "=", "$", "dom", "->", "createElement", "(", "$", "tag", ",", "$", "content", ")", ";", "}", "else", "{", "$", "elem", "=", "$", "dom", "->", "createElement", "(", "$", "tag", ")", ";", "}", "foreach", "(", "$", "attributes", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "elem", "->", "setAttribute", "(", "$", "key", ",", "$", "value", ")", ";", "}", "$", "dom", "->", "appendChild", "(", "$", "elem", ")", ";", "return", "$", "dom", "->", "saveXML", "(", "$", "elem", ")", ";", "}" ]
Create portfolio tag @param stored_file $file file information object @param string $path file path @param array $attributes portfolio attributes @return string
[ "Create", "portfolio", "tag" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/formats.php#L91-L115
213,879
moodle/moodle
lib/portfolio/formats.php
portfolio_format_leap2a.file_output
public static function file_output($file, $options=null) { $id = ''; if (!is_array($options)) { $options = array(); } if (!array_key_exists('entry', $options)) { $options['entry'] = true; } if (!empty($options['entry'])) { $path = 'portfolio:' . self::file_id_prefix() . $file->get_id(); } else { $path = self::get_file_directory() . $file->get_filename(); } $attributes = array(); if (!empty($options['attributes']) && is_array($options['attributes'])) { $attributes = $options['attributes']; } $attributes['rel'] = 'enclosure'; return self::make_tag($file, $path, $attributes); }
php
public static function file_output($file, $options=null) { $id = ''; if (!is_array($options)) { $options = array(); } if (!array_key_exists('entry', $options)) { $options['entry'] = true; } if (!empty($options['entry'])) { $path = 'portfolio:' . self::file_id_prefix() . $file->get_id(); } else { $path = self::get_file_directory() . $file->get_filename(); } $attributes = array(); if (!empty($options['attributes']) && is_array($options['attributes'])) { $attributes = $options['attributes']; } $attributes['rel'] = 'enclosure'; return self::make_tag($file, $path, $attributes); }
[ "public", "static", "function", "file_output", "(", "$", "file", ",", "$", "options", "=", "null", ")", "{", "$", "id", "=", "''", ";", "if", "(", "!", "is_array", "(", "$", "options", ")", ")", "{", "$", "options", "=", "array", "(", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "'entry'", ",", "$", "options", ")", ")", "{", "$", "options", "[", "'entry'", "]", "=", "true", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'entry'", "]", ")", ")", "{", "$", "path", "=", "'portfolio:'", ".", "self", "::", "file_id_prefix", "(", ")", ".", "$", "file", "->", "get_id", "(", ")", ";", "}", "else", "{", "$", "path", "=", "self", "::", "get_file_directory", "(", ")", ".", "$", "file", "->", "get_filename", "(", ")", ";", "}", "$", "attributes", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "options", "[", "'attributes'", "]", ")", "&&", "is_array", "(", "$", "options", "[", "'attributes'", "]", ")", ")", "{", "$", "attributes", "=", "$", "options", "[", "'attributes'", "]", ";", "}", "$", "attributes", "[", "'rel'", "]", "=", "'enclosure'", ";", "return", "self", "::", "make_tag", "(", "$", "file", ",", "$", "path", ",", "$", "attributes", ")", ";", "}" ]
Return the link to a file @param stored_file $file information for existing file @param array $options array of options to pass. can contain: attributes => hash of existing html attributes (eg title, height, width, etc) @return string
[ "Return", "the", "link", "to", "a", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/formats.php#L469-L488
213,880
moodle/moodle
mod/wiki/classes/search/collaborative_page.php
collaborative_page.get_document_recordset
public function get_document_recordset($modifiedfrom = 0, \context $context = null) { global $DB; list ($contextjoin, $contextparams) = $this->get_context_restriction_sql( $context, 'wiki', 'w'); if ($contextjoin === null) { return null; } $sql = "SELECT p.*, w.id AS wikiid, w.course AS courseid, s.groupid AS groupid FROM {wiki_pages} p JOIN {wiki_subwikis} s ON s.id = p.subwikiid JOIN {wiki} w ON w.id = s.wikiid $contextjoin WHERE p.timemodified >= ? AND w.wikimode = ? ORDER BY p.timemodified ASC"; return $DB->get_recordset_sql($sql, array_merge($contextparams, [$modifiedfrom, 'collaborative'])); }
php
public function get_document_recordset($modifiedfrom = 0, \context $context = null) { global $DB; list ($contextjoin, $contextparams) = $this->get_context_restriction_sql( $context, 'wiki', 'w'); if ($contextjoin === null) { return null; } $sql = "SELECT p.*, w.id AS wikiid, w.course AS courseid, s.groupid AS groupid FROM {wiki_pages} p JOIN {wiki_subwikis} s ON s.id = p.subwikiid JOIN {wiki} w ON w.id = s.wikiid $contextjoin WHERE p.timemodified >= ? AND w.wikimode = ? ORDER BY p.timemodified ASC"; return $DB->get_recordset_sql($sql, array_merge($contextparams, [$modifiedfrom, 'collaborative'])); }
[ "public", "function", "get_document_recordset", "(", "$", "modifiedfrom", "=", "0", ",", "\\", "context", "$", "context", "=", "null", ")", "{", "global", "$", "DB", ";", "list", "(", "$", "contextjoin", ",", "$", "contextparams", ")", "=", "$", "this", "->", "get_context_restriction_sql", "(", "$", "context", ",", "'wiki'", ",", "'w'", ")", ";", "if", "(", "$", "contextjoin", "===", "null", ")", "{", "return", "null", ";", "}", "$", "sql", "=", "\"SELECT p.*, w.id AS wikiid, w.course AS courseid, s.groupid AS groupid\n FROM {wiki_pages} p\n JOIN {wiki_subwikis} s ON s.id = p.subwikiid\n JOIN {wiki} w ON w.id = s.wikiid\n $contextjoin\n WHERE p.timemodified >= ?\n AND w.wikimode = ?\n ORDER BY p.timemodified ASC\"", ";", "return", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "array_merge", "(", "$", "contextparams", ",", "[", "$", "modifiedfrom", ",", "'collaborative'", "]", ")", ")", ";", "}" ]
Returns a recordset with all required page information. @param int $modifiedfrom @param \context|null $context Optional context to restrict scope of returned results @return moodle_recordset|null Recordset (or null if no results)
[ "Returns", "a", "recordset", "with", "all", "required", "page", "information", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/search/collaborative_page.php#L51-L70
213,881
moodle/moodle
mod/wiki/classes/search/collaborative_page.php
collaborative_page.get_document
public function get_document($record, $options = array()) { try { $cm = $this->get_cm('wiki', $record->wikiid, $record->courseid); $context = \context_module::instance($cm->id); } catch (\dml_missing_record_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } catch (\dml_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } // Make a page object without extra fields. $page = clone $record; unset($page->courseid); unset($page->wikiid); // Conversion based wiki_print_page_content(). // Check if we have passed the cache time. if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) { $content = wiki_refresh_cachedcontent($page); $page = $content['page']; } // Convert to text. $content = content_to_text($page->cachedcontent, FORMAT_MOODLE); // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); $doc->set('title', content_to_text($record->title, false)); $doc->set('content', $content); $doc->set('contextid', $context->id); $doc->set('courseid', $record->courseid); if ($record->groupid > 0) { $doc->set('groupid', $record->groupid); } $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('modified', $record->timemodified); // Check if this document should be considered new. if (isset($options['lastindexedtime']) && ($options['lastindexedtime'] < $record->timecreated)) { // If the document was created after the last index time, it must be new. $doc->set_is_new(true); } return $doc; }
php
public function get_document($record, $options = array()) { try { $cm = $this->get_cm('wiki', $record->wikiid, $record->courseid); $context = \context_module::instance($cm->id); } catch (\dml_missing_record_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } catch (\dml_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } // Make a page object without extra fields. $page = clone $record; unset($page->courseid); unset($page->wikiid); // Conversion based wiki_print_page_content(). // Check if we have passed the cache time. if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) { $content = wiki_refresh_cachedcontent($page); $page = $content['page']; } // Convert to text. $content = content_to_text($page->cachedcontent, FORMAT_MOODLE); // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); $doc->set('title', content_to_text($record->title, false)); $doc->set('content', $content); $doc->set('contextid', $context->id); $doc->set('courseid', $record->courseid); if ($record->groupid > 0) { $doc->set('groupid', $record->groupid); } $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('modified', $record->timemodified); // Check if this document should be considered new. if (isset($options['lastindexedtime']) && ($options['lastindexedtime'] < $record->timecreated)) { // If the document was created after the last index time, it must be new. $doc->set_is_new(true); } return $doc; }
[ "public", "function", "get_document", "(", "$", "record", ",", "$", "options", "=", "array", "(", ")", ")", "{", "try", "{", "$", "cm", "=", "$", "this", "->", "get_cm", "(", "'wiki'", ",", "$", "record", "->", "wikiid", ",", "$", "record", "->", "courseid", ")", ";", "$", "context", "=", "\\", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "}", "catch", "(", "\\", "dml_missing_record_exception", "$", "ex", ")", "{", "// Notify it as we run here as admin, we should see everything.", "debugging", "(", "'Error retrieving '", ".", "$", "this", "->", "areaid", ".", "' '", ".", "$", "record", "->", "id", ".", "' document, not all required data is available: '", ".", "$", "ex", "->", "getMessage", "(", ")", ",", "DEBUG_DEVELOPER", ")", ";", "return", "false", ";", "}", "catch", "(", "\\", "dml_exception", "$", "ex", ")", "{", "// Notify it as we run here as admin, we should see everything.", "debugging", "(", "'Error retrieving '", ".", "$", "this", "->", "areaid", ".", "' '", ".", "$", "record", "->", "id", ".", "' document: '", ".", "$", "ex", "->", "getMessage", "(", ")", ",", "DEBUG_DEVELOPER", ")", ";", "return", "false", ";", "}", "// Make a page object without extra fields.", "$", "page", "=", "clone", "$", "record", ";", "unset", "(", "$", "page", "->", "courseid", ")", ";", "unset", "(", "$", "page", "->", "wikiid", ")", ";", "// Conversion based wiki_print_page_content().", "// Check if we have passed the cache time.", "if", "(", "$", "page", "->", "timerendered", "+", "WIKI_REFRESH_CACHE_TIME", "<", "time", "(", ")", ")", "{", "$", "content", "=", "wiki_refresh_cachedcontent", "(", "$", "page", ")", ";", "$", "page", "=", "$", "content", "[", "'page'", "]", ";", "}", "// Convert to text.", "$", "content", "=", "content_to_text", "(", "$", "page", "->", "cachedcontent", ",", "FORMAT_MOODLE", ")", ";", "// Prepare associative array with data from DB.", "$", "doc", "=", "\\", "core_search", "\\", "document_factory", "::", "instance", "(", "$", "record", "->", "id", ",", "$", "this", "->", "componentname", ",", "$", "this", "->", "areaname", ")", ";", "$", "doc", "->", "set", "(", "'title'", ",", "content_to_text", "(", "$", "record", "->", "title", ",", "false", ")", ")", ";", "$", "doc", "->", "set", "(", "'content'", ",", "$", "content", ")", ";", "$", "doc", "->", "set", "(", "'contextid'", ",", "$", "context", "->", "id", ")", ";", "$", "doc", "->", "set", "(", "'courseid'", ",", "$", "record", "->", "courseid", ")", ";", "if", "(", "$", "record", "->", "groupid", ">", "0", ")", "{", "$", "doc", "->", "set", "(", "'groupid'", ",", "$", "record", "->", "groupid", ")", ";", "}", "$", "doc", "->", "set", "(", "'owneruserid'", ",", "\\", "core_search", "\\", "manager", "::", "NO_OWNER_ID", ")", ";", "$", "doc", "->", "set", "(", "'modified'", ",", "$", "record", "->", "timemodified", ")", ";", "// Check if this document should be considered new.", "if", "(", "isset", "(", "$", "options", "[", "'lastindexedtime'", "]", ")", "&&", "(", "$", "options", "[", "'lastindexedtime'", "]", "<", "$", "record", "->", "timecreated", ")", ")", "{", "// If the document was created after the last index time, it must be new.", "$", "doc", "->", "set_is_new", "(", "true", ")", ";", "}", "return", "$", "doc", ";", "}" ]
Returns the document for a particular page. @param \stdClass $record A record containing, at least, the indexed document id and a modified timestamp @param array $options Options for document creation @return \core_search\document
[ "Returns", "the", "document", "for", "a", "particular", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/classes/search/collaborative_page.php#L79-L127
213,882
moodle/moodle
lib/tcpdf/tcpdf_barcodes_2d.php
TCPDF2DBarcode.getBarcodeSVG
public function getBarcodeSVG($w=3, $h=3, $color='black') { // send headers $code = $this->getBarcodeSVGcode($w, $h, $color); header('Content-Type: application/svg+xml'); header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); header('Content-Disposition: inline; filename="'.md5($code).'.svg";'); //header('Content-Length: '.strlen($code)); echo $code; }
php
public function getBarcodeSVG($w=3, $h=3, $color='black') { // send headers $code = $this->getBarcodeSVGcode($w, $h, $color); header('Content-Type: application/svg+xml'); header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); header('Content-Disposition: inline; filename="'.md5($code).'.svg";'); //header('Content-Length: '.strlen($code)); echo $code; }
[ "public", "function", "getBarcodeSVG", "(", "$", "w", "=", "3", ",", "$", "h", "=", "3", ",", "$", "color", "=", "'black'", ")", "{", "// send headers", "$", "code", "=", "$", "this", "->", "getBarcodeSVGcode", "(", "$", "w", ",", "$", "h", ",", "$", "color", ")", ";", "header", "(", "'Content-Type: application/svg+xml'", ")", ";", "header", "(", "'Cache-Control: public, must-revalidate, max-age=0'", ")", ";", "// HTTP/1.1", "header", "(", "'Pragma: public'", ")", ";", "header", "(", "'Expires: Sat, 26 Jul 1997 05:00:00 GMT'", ")", ";", "// Date in the past", "header", "(", "'Last-Modified: '", ".", "gmdate", "(", "'D, d M Y H:i:s'", ")", ".", "' GMT'", ")", ";", "header", "(", "'Content-Disposition: inline; filename=\"'", ".", "md5", "(", "$", "code", ")", ".", "'.svg\";'", ")", ";", "//header('Content-Length: '.strlen($code));", "echo", "$", "code", ";", "}" ]
Send barcode as SVG image object to the standard output. @param $w (int) Width of a single rectangle element in user units. @param $h (int) Height of a single rectangle element in user units. @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent). @public
[ "Send", "barcode", "as", "SVG", "image", "object", "to", "the", "standard", "output", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tcpdf/tcpdf_barcodes_2d.php#L87-L98
213,883
moodle/moodle
lib/phpexcel/PHPExcel/Style/Alignment.php
PHPExcel_Style_Alignment.setReadorder
public function setReadorder($pValue = 0) { if ($pValue < 0 || $pValue > 2) { $pValue = 0; } if ($this->isSupervisor) { $styleArray = $this->getStyleArray(array('readorder' => $pValue)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->readorder = $pValue; } return $this; }
php
public function setReadorder($pValue = 0) { if ($pValue < 0 || $pValue > 2) { $pValue = 0; } if ($this->isSupervisor) { $styleArray = $this->getStyleArray(array('readorder' => $pValue)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->readorder = $pValue; } return $this; }
[ "public", "function", "setReadorder", "(", "$", "pValue", "=", "0", ")", "{", "if", "(", "$", "pValue", "<", "0", "||", "$", "pValue", ">", "2", ")", "{", "$", "pValue", "=", "0", ";", "}", "if", "(", "$", "this", "->", "isSupervisor", ")", "{", "$", "styleArray", "=", "$", "this", "->", "getStyleArray", "(", "array", "(", "'readorder'", "=>", "$", "pValue", ")", ")", ";", "$", "this", "->", "getActiveSheet", "(", ")", "->", "getStyle", "(", "$", "this", "->", "getSelectedCells", "(", ")", ")", "->", "applyFromArray", "(", "$", "styleArray", ")", ";", "}", "else", "{", "$", "this", "->", "readorder", "=", "$", "pValue", ";", "}", "return", "$", "this", ";", "}" ]
Set read order @param int $pValue @return PHPExcel_Style_Alignment
[ "Set", "read", "order" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Style/Alignment.php#L429-L441
213,884
moodle/moodle
mod/quiz/classes/admin_review_setting.php
mod_quiz_admin_review_setting.times
protected static function times() { return array( self::DURING => get_string('reviewduring', 'quiz'), self::IMMEDIATELY_AFTER => get_string('reviewimmediately', 'quiz'), self::LATER_WHILE_OPEN => get_string('reviewopen', 'quiz'), self::AFTER_CLOSE => get_string('reviewclosed', 'quiz'), ); }
php
protected static function times() { return array( self::DURING => get_string('reviewduring', 'quiz'), self::IMMEDIATELY_AFTER => get_string('reviewimmediately', 'quiz'), self::LATER_WHILE_OPEN => get_string('reviewopen', 'quiz'), self::AFTER_CLOSE => get_string('reviewclosed', 'quiz'), ); }
[ "protected", "static", "function", "times", "(", ")", "{", "return", "array", "(", "self", "::", "DURING", "=>", "get_string", "(", "'reviewduring'", ",", "'quiz'", ")", ",", "self", "::", "IMMEDIATELY_AFTER", "=>", "get_string", "(", "'reviewimmediately'", ",", "'quiz'", ")", ",", "self", "::", "LATER_WHILE_OPEN", "=>", "get_string", "(", "'reviewopen'", ",", "'quiz'", ")", ",", "self", "::", "AFTER_CLOSE", "=>", "get_string", "(", "'reviewclosed'", ",", "'quiz'", ")", ",", ")", ";", "}" ]
Get an array of the names of all the possible times. @return array an array of time constant => lang string.
[ "Get", "an", "array", "of", "the", "names", "of", "all", "the", "possible", "times", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/admin_review_setting.php#L111-L118
213,885
moodle/moodle
admin/tool/dataprivacy/classes/category.php
category.is_used
public function is_used() { if (\tool_dataprivacy\contextlevel::is_category_used($this->get('id')) || \tool_dataprivacy\context_instance::is_category_used($this->get('id'))) { return true; } $pluginconfig = get_config('tool_dataprivacy'); $levels = \context_helper::get_all_levels(); foreach ($levels as $level => $classname) { list($unused, $categoryvar) = \tool_dataprivacy\data_registry::var_names_from_context($classname); if (!empty($pluginconfig->{$categoryvar}) && $pluginconfig->{$categoryvar} == $this->get('id')) { return true; } } return false; }
php
public function is_used() { if (\tool_dataprivacy\contextlevel::is_category_used($this->get('id')) || \tool_dataprivacy\context_instance::is_category_used($this->get('id'))) { return true; } $pluginconfig = get_config('tool_dataprivacy'); $levels = \context_helper::get_all_levels(); foreach ($levels as $level => $classname) { list($unused, $categoryvar) = \tool_dataprivacy\data_registry::var_names_from_context($classname); if (!empty($pluginconfig->{$categoryvar}) && $pluginconfig->{$categoryvar} == $this->get('id')) { return true; } } return false; }
[ "public", "function", "is_used", "(", ")", "{", "if", "(", "\\", "tool_dataprivacy", "\\", "contextlevel", "::", "is_category_used", "(", "$", "this", "->", "get", "(", "'id'", ")", ")", "||", "\\", "tool_dataprivacy", "\\", "context_instance", "::", "is_category_used", "(", "$", "this", "->", "get", "(", "'id'", ")", ")", ")", "{", "return", "true", ";", "}", "$", "pluginconfig", "=", "get_config", "(", "'tool_dataprivacy'", ")", ";", "$", "levels", "=", "\\", "context_helper", "::", "get_all_levels", "(", ")", ";", "foreach", "(", "$", "levels", "as", "$", "level", "=>", "$", "classname", ")", "{", "list", "(", "$", "unused", ",", "$", "categoryvar", ")", "=", "\\", "tool_dataprivacy", "\\", "data_registry", "::", "var_names_from_context", "(", "$", "classname", ")", ";", "if", "(", "!", "empty", "(", "$", "pluginconfig", "->", "{", "$", "categoryvar", "}", ")", "&&", "$", "pluginconfig", "->", "{", "$", "categoryvar", "}", "==", "$", "this", "->", "get", "(", "'id'", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Is this category used?. @return null
[ "Is", "this", "category", "used?", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/category.php#L72-L90
213,886
moodle/moodle
cohort/upload_form.php
cohort_upload_form.definition_after_data
public function definition_after_data() { $mform = $this->_form; $cohortfile = $mform->getElementValue('cohortfile'); $allowsubmitform = false; if ($cohortfile && ($file = $this->get_cohort_file($cohortfile))) { // File was uploaded. Parse it. $encoding = $mform->getElementValue('encoding')[0]; $delimiter = $mform->getElementValue('delimiter')[0]; $contextid = $mform->getElementValue('contextid')[0]; if (!empty($contextid) && ($context = context::instance_by_id($contextid, IGNORE_MISSING))) { $this->processeddata = $this->process_upload_file($file, $encoding, $delimiter, $context); if ($this->processeddata && count($this->processeddata) > 1 && !$this->processeddata[0]['errors']) { $allowsubmitform = true; } } } if (!$allowsubmitform) { // Hide submit button. $el = $mform->getElement('buttonar')->getElements()[0]; $el->setValue(''); $el->freeze(); } else { $mform->setExpanded('cohortfileuploadform', false); } }
php
public function definition_after_data() { $mform = $this->_form; $cohortfile = $mform->getElementValue('cohortfile'); $allowsubmitform = false; if ($cohortfile && ($file = $this->get_cohort_file($cohortfile))) { // File was uploaded. Parse it. $encoding = $mform->getElementValue('encoding')[0]; $delimiter = $mform->getElementValue('delimiter')[0]; $contextid = $mform->getElementValue('contextid')[0]; if (!empty($contextid) && ($context = context::instance_by_id($contextid, IGNORE_MISSING))) { $this->processeddata = $this->process_upload_file($file, $encoding, $delimiter, $context); if ($this->processeddata && count($this->processeddata) > 1 && !$this->processeddata[0]['errors']) { $allowsubmitform = true; } } } if (!$allowsubmitform) { // Hide submit button. $el = $mform->getElement('buttonar')->getElements()[0]; $el->setValue(''); $el->freeze(); } else { $mform->setExpanded('cohortfileuploadform', false); } }
[ "public", "function", "definition_after_data", "(", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "cohortfile", "=", "$", "mform", "->", "getElementValue", "(", "'cohortfile'", ")", ";", "$", "allowsubmitform", "=", "false", ";", "if", "(", "$", "cohortfile", "&&", "(", "$", "file", "=", "$", "this", "->", "get_cohort_file", "(", "$", "cohortfile", ")", ")", ")", "{", "// File was uploaded. Parse it.", "$", "encoding", "=", "$", "mform", "->", "getElementValue", "(", "'encoding'", ")", "[", "0", "]", ";", "$", "delimiter", "=", "$", "mform", "->", "getElementValue", "(", "'delimiter'", ")", "[", "0", "]", ";", "$", "contextid", "=", "$", "mform", "->", "getElementValue", "(", "'contextid'", ")", "[", "0", "]", ";", "if", "(", "!", "empty", "(", "$", "contextid", ")", "&&", "(", "$", "context", "=", "context", "::", "instance_by_id", "(", "$", "contextid", ",", "IGNORE_MISSING", ")", ")", ")", "{", "$", "this", "->", "processeddata", "=", "$", "this", "->", "process_upload_file", "(", "$", "file", ",", "$", "encoding", ",", "$", "delimiter", ",", "$", "context", ")", ";", "if", "(", "$", "this", "->", "processeddata", "&&", "count", "(", "$", "this", "->", "processeddata", ")", ">", "1", "&&", "!", "$", "this", "->", "processeddata", "[", "0", "]", "[", "'errors'", "]", ")", "{", "$", "allowsubmitform", "=", "true", ";", "}", "}", "}", "if", "(", "!", "$", "allowsubmitform", ")", "{", "// Hide submit button.", "$", "el", "=", "$", "mform", "->", "getElement", "(", "'buttonar'", ")", "->", "getElements", "(", ")", "[", "0", "]", ";", "$", "el", "->", "setValue", "(", "''", ")", ";", "$", "el", "->", "freeze", "(", ")", ";", "}", "else", "{", "$", "mform", "->", "setExpanded", "(", "'cohortfileuploadform'", ",", "false", ")", ";", "}", "}" ]
Process the uploaded file and allow the submit button only if it doest not have errors.
[ "Process", "the", "uploaded", "file", "and", "allow", "the", "submit", "button", "only", "if", "it", "doest", "not", "have", "errors", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cohort/upload_form.php#L108-L133
213,887
moodle/moodle
cohort/upload_form.php
cohort_upload_form.get_context_options
protected function get_context_options() { if ($this->contextoptions === null) { $this->contextoptions = array(); $displaylist = core_course_category::make_categories_list('moodle/cohort:manage'); // We need to index the options array by context id instead of category id and add option for system context. $syscontext = context_system::instance(); if (has_capability('moodle/cohort:manage', $syscontext)) { $this->contextoptions[$syscontext->id] = $syscontext->get_context_name(); } foreach ($displaylist as $cid => $name) { $context = context_coursecat::instance($cid); $this->contextoptions[$context->id] = $name; } } return $this->contextoptions; }
php
protected function get_context_options() { if ($this->contextoptions === null) { $this->contextoptions = array(); $displaylist = core_course_category::make_categories_list('moodle/cohort:manage'); // We need to index the options array by context id instead of category id and add option for system context. $syscontext = context_system::instance(); if (has_capability('moodle/cohort:manage', $syscontext)) { $this->contextoptions[$syscontext->id] = $syscontext->get_context_name(); } foreach ($displaylist as $cid => $name) { $context = context_coursecat::instance($cid); $this->contextoptions[$context->id] = $name; } } return $this->contextoptions; }
[ "protected", "function", "get_context_options", "(", ")", "{", "if", "(", "$", "this", "->", "contextoptions", "===", "null", ")", "{", "$", "this", "->", "contextoptions", "=", "array", "(", ")", ";", "$", "displaylist", "=", "core_course_category", "::", "make_categories_list", "(", "'moodle/cohort:manage'", ")", ";", "// We need to index the options array by context id instead of category id and add option for system context.", "$", "syscontext", "=", "context_system", "::", "instance", "(", ")", ";", "if", "(", "has_capability", "(", "'moodle/cohort:manage'", ",", "$", "syscontext", ")", ")", "{", "$", "this", "->", "contextoptions", "[", "$", "syscontext", "->", "id", "]", "=", "$", "syscontext", "->", "get_context_name", "(", ")", ";", "}", "foreach", "(", "$", "displaylist", "as", "$", "cid", "=>", "$", "name", ")", "{", "$", "context", "=", "context_coursecat", "::", "instance", "(", "$", "cid", ")", ";", "$", "this", "->", "contextoptions", "[", "$", "context", "->", "id", "]", "=", "$", "name", ";", "}", "}", "return", "$", "this", "->", "contextoptions", ";", "}" ]
Returns the list of contexts where current user can create cohorts. @return array
[ "Returns", "the", "list", "of", "contexts", "where", "current", "user", "can", "create", "cohorts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cohort/upload_form.php#L140-L155
213,888
moodle/moodle
cohort/upload_form.php
cohort_upload_form.get_cohort_file
protected function get_cohort_file($draftid) { global $USER; // We can not use moodleform::get_file_content() method because we need the content before the form is validated. if (!$draftid) { return null; } $fs = get_file_storage(); $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return null; } $file = reset($files); return $file; }
php
protected function get_cohort_file($draftid) { global $USER; // We can not use moodleform::get_file_content() method because we need the content before the form is validated. if (!$draftid) { return null; } $fs = get_file_storage(); $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return null; } $file = reset($files); return $file; }
[ "protected", "function", "get_cohort_file", "(", "$", "draftid", ")", "{", "global", "$", "USER", ";", "// We can not use moodleform::get_file_content() method because we need the content before the form is validated.", "if", "(", "!", "$", "draftid", ")", "{", "return", "null", ";", "}", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "context", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "if", "(", "!", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'draft'", ",", "$", "draftid", ",", "'id DESC'", ",", "false", ")", ")", "{", "return", "null", ";", "}", "$", "file", "=", "reset", "(", "$", "files", ")", ";", "return", "$", "file", ";", "}" ]
Returns the uploaded file if it is present. @param int $draftid @return stored_file|null
[ "Returns", "the", "uploaded", "file", "if", "it", "is", "present", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cohort/upload_form.php#L178-L193
213,889
moodle/moodle
cohort/upload_form.php
cohort_upload_form.get_cohorts_data
public function get_cohorts_data() { $cohorts = array(); if ($this->processeddata) { foreach ($this->processeddata as $idx => $line) { if ($idx && !empty($line['data'])) { $cohorts[] = (object)$line['data']; } } } return $cohorts; }
php
public function get_cohorts_data() { $cohorts = array(); if ($this->processeddata) { foreach ($this->processeddata as $idx => $line) { if ($idx && !empty($line['data'])) { $cohorts[] = (object)$line['data']; } } } return $cohorts; }
[ "public", "function", "get_cohorts_data", "(", ")", "{", "$", "cohorts", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "processeddata", ")", "{", "foreach", "(", "$", "this", "->", "processeddata", "as", "$", "idx", "=>", "$", "line", ")", "{", "if", "(", "$", "idx", "&&", "!", "empty", "(", "$", "line", "[", "'data'", "]", ")", ")", "{", "$", "cohorts", "[", "]", "=", "(", "object", ")", "$", "line", "[", "'data'", "]", ";", "}", "}", "}", "return", "$", "cohorts", ";", "}" ]
Returns the list of prepared objects to be added as cohorts @return array of stdClass objects, each can be passed to {@link cohort_add_cohort()}
[ "Returns", "the", "list", "of", "prepared", "objects", "to", "be", "added", "as", "cohorts" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cohort/upload_form.php#L200-L210
213,890
moodle/moodle
cohort/upload_form.php
cohort_upload_form.preview_uploaded_cohorts
protected function preview_uploaded_cohorts() { global $OUTPUT; if (empty($this->processeddata)) { return; } foreach ($this->processeddata[0]['errors'] as $error) { echo $OUTPUT->notification($error); } foreach ($this->processeddata[0]['warnings'] as $warning) { echo $OUTPUT->notification($warning, 'notifymessage'); } $table = new html_table(); $table->id = 'previewuploadedcohorts'; $columns = $this->processeddata[0]['data']; $columns['contextid'] = get_string('context', 'role'); // Add column names to the preview table. $table->head = array(''); foreach ($columns as $key => $value) { $table->head[] = $value; } $table->head[] = get_string('status'); // Add (some) rows to the preview table. $previewdrows = $this->get_previewed_rows(); foreach ($previewdrows as $idx) { $line = $this->processeddata[$idx]; $cells = array(new html_table_cell($idx)); $context = context::instance_by_id($line['data']['contextid']); foreach ($columns as $key => $value) { if ($key === 'contextid') { $text = html_writer::link(new moodle_url('/cohort/index.php', array('contextid' => $context->id)), $context->get_context_name(false)); } else { $text = s($line['data'][$key]); } $cells[] = new html_table_cell($text); } $text = ''; if ($line['errors']) { $text .= html_writer::div(join('<br>', $line['errors']), 'notifyproblem'); } if ($line['warnings']) { $text .= html_writer::div(join('<br>', $line['warnings'])); } $cells[] = new html_table_cell($text); $table->data[] = new html_table_row($cells); } if ($notdisplayed = count($this->processeddata) - count($previewdrows) - 1) { $cell = new html_table_cell(get_string('displayedrows', 'cohort', (object)array('displayed' => count($previewdrows), 'total' => count($this->processeddata) - 1))); $cell->colspan = count($columns) + 2; $table->data[] = new html_table_row(array($cell)); } echo html_writer::table($table); }
php
protected function preview_uploaded_cohorts() { global $OUTPUT; if (empty($this->processeddata)) { return; } foreach ($this->processeddata[0]['errors'] as $error) { echo $OUTPUT->notification($error); } foreach ($this->processeddata[0]['warnings'] as $warning) { echo $OUTPUT->notification($warning, 'notifymessage'); } $table = new html_table(); $table->id = 'previewuploadedcohorts'; $columns = $this->processeddata[0]['data']; $columns['contextid'] = get_string('context', 'role'); // Add column names to the preview table. $table->head = array(''); foreach ($columns as $key => $value) { $table->head[] = $value; } $table->head[] = get_string('status'); // Add (some) rows to the preview table. $previewdrows = $this->get_previewed_rows(); foreach ($previewdrows as $idx) { $line = $this->processeddata[$idx]; $cells = array(new html_table_cell($idx)); $context = context::instance_by_id($line['data']['contextid']); foreach ($columns as $key => $value) { if ($key === 'contextid') { $text = html_writer::link(new moodle_url('/cohort/index.php', array('contextid' => $context->id)), $context->get_context_name(false)); } else { $text = s($line['data'][$key]); } $cells[] = new html_table_cell($text); } $text = ''; if ($line['errors']) { $text .= html_writer::div(join('<br>', $line['errors']), 'notifyproblem'); } if ($line['warnings']) { $text .= html_writer::div(join('<br>', $line['warnings'])); } $cells[] = new html_table_cell($text); $table->data[] = new html_table_row($cells); } if ($notdisplayed = count($this->processeddata) - count($previewdrows) - 1) { $cell = new html_table_cell(get_string('displayedrows', 'cohort', (object)array('displayed' => count($previewdrows), 'total' => count($this->processeddata) - 1))); $cell->colspan = count($columns) + 2; $table->data[] = new html_table_row(array($cell)); } echo html_writer::table($table); }
[ "protected", "function", "preview_uploaded_cohorts", "(", ")", "{", "global", "$", "OUTPUT", ";", "if", "(", "empty", "(", "$", "this", "->", "processeddata", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "this", "->", "processeddata", "[", "0", "]", "[", "'errors'", "]", "as", "$", "error", ")", "{", "echo", "$", "OUTPUT", "->", "notification", "(", "$", "error", ")", ";", "}", "foreach", "(", "$", "this", "->", "processeddata", "[", "0", "]", "[", "'warnings'", "]", "as", "$", "warning", ")", "{", "echo", "$", "OUTPUT", "->", "notification", "(", "$", "warning", ",", "'notifymessage'", ")", ";", "}", "$", "table", "=", "new", "html_table", "(", ")", ";", "$", "table", "->", "id", "=", "'previewuploadedcohorts'", ";", "$", "columns", "=", "$", "this", "->", "processeddata", "[", "0", "]", "[", "'data'", "]", ";", "$", "columns", "[", "'contextid'", "]", "=", "get_string", "(", "'context'", ",", "'role'", ")", ";", "// Add column names to the preview table.", "$", "table", "->", "head", "=", "array", "(", "''", ")", ";", "foreach", "(", "$", "columns", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "table", "->", "head", "[", "]", "=", "$", "value", ";", "}", "$", "table", "->", "head", "[", "]", "=", "get_string", "(", "'status'", ")", ";", "// Add (some) rows to the preview table.", "$", "previewdrows", "=", "$", "this", "->", "get_previewed_rows", "(", ")", ";", "foreach", "(", "$", "previewdrows", "as", "$", "idx", ")", "{", "$", "line", "=", "$", "this", "->", "processeddata", "[", "$", "idx", "]", ";", "$", "cells", "=", "array", "(", "new", "html_table_cell", "(", "$", "idx", ")", ")", ";", "$", "context", "=", "context", "::", "instance_by_id", "(", "$", "line", "[", "'data'", "]", "[", "'contextid'", "]", ")", ";", "foreach", "(", "$", "columns", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "===", "'contextid'", ")", "{", "$", "text", "=", "html_writer", "::", "link", "(", "new", "moodle_url", "(", "'/cohort/index.php'", ",", "array", "(", "'contextid'", "=>", "$", "context", "->", "id", ")", ")", ",", "$", "context", "->", "get_context_name", "(", "false", ")", ")", ";", "}", "else", "{", "$", "text", "=", "s", "(", "$", "line", "[", "'data'", "]", "[", "$", "key", "]", ")", ";", "}", "$", "cells", "[", "]", "=", "new", "html_table_cell", "(", "$", "text", ")", ";", "}", "$", "text", "=", "''", ";", "if", "(", "$", "line", "[", "'errors'", "]", ")", "{", "$", "text", ".=", "html_writer", "::", "div", "(", "join", "(", "'<br>'", ",", "$", "line", "[", "'errors'", "]", ")", ",", "'notifyproblem'", ")", ";", "}", "if", "(", "$", "line", "[", "'warnings'", "]", ")", "{", "$", "text", ".=", "html_writer", "::", "div", "(", "join", "(", "'<br>'", ",", "$", "line", "[", "'warnings'", "]", ")", ")", ";", "}", "$", "cells", "[", "]", "=", "new", "html_table_cell", "(", "$", "text", ")", ";", "$", "table", "->", "data", "[", "]", "=", "new", "html_table_row", "(", "$", "cells", ")", ";", "}", "if", "(", "$", "notdisplayed", "=", "count", "(", "$", "this", "->", "processeddata", ")", "-", "count", "(", "$", "previewdrows", ")", "-", "1", ")", "{", "$", "cell", "=", "new", "html_table_cell", "(", "get_string", "(", "'displayedrows'", ",", "'cohort'", ",", "(", "object", ")", "array", "(", "'displayed'", "=>", "count", "(", "$", "previewdrows", ")", ",", "'total'", "=>", "count", "(", "$", "this", "->", "processeddata", ")", "-", "1", ")", ")", ")", ";", "$", "cell", "->", "colspan", "=", "count", "(", "$", "columns", ")", "+", "2", ";", "$", "table", "->", "data", "[", "]", "=", "new", "html_table_row", "(", "array", "(", "$", "cell", ")", ")", ";", "}", "echo", "html_writer", "::", "table", "(", "$", "table", ")", ";", "}" ]
Displays the preview of the uploaded file
[ "Displays", "the", "preview", "of", "the", "uploaded", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cohort/upload_form.php#L215-L270
213,891
moodle/moodle
cohort/upload_form.php
cohort_upload_form.get_previewed_rows
protected function get_previewed_rows() { $previewlimit = 10; if (count($this->processeddata) <= 1) { $rows = array(); } else if (count($this->processeddata) < $previewlimit + 1) { // Return all rows. $rows = range(1, count($this->processeddata) - 1); } else { // First find rows with errors and warnings (no more than 10 of each). $errorrows = $warningrows = array(); foreach ($this->processeddata as $rownum => $line) { if ($rownum && $line['errors']) { $errorrows[] = $rownum; if (count($errorrows) >= $previewlimit) { return $errorrows; } } else if ($rownum && $line['warnings']) { if (count($warningrows) + count($errorrows) < $previewlimit) { $warningrows[] = $rownum; } } } // Include as many error rows as possible and top them up with warning rows. $rows = array_merge($errorrows, array_slice($warningrows, 0, $previewlimit - count($errorrows))); // Keep adding good rows until we reach limit. for ($rownum = 1; count($rows) < $previewlimit; $rownum++) { if (!in_array($rownum, $rows)) { $rows[] = $rownum; } } asort($rows); } return $rows; }
php
protected function get_previewed_rows() { $previewlimit = 10; if (count($this->processeddata) <= 1) { $rows = array(); } else if (count($this->processeddata) < $previewlimit + 1) { // Return all rows. $rows = range(1, count($this->processeddata) - 1); } else { // First find rows with errors and warnings (no more than 10 of each). $errorrows = $warningrows = array(); foreach ($this->processeddata as $rownum => $line) { if ($rownum && $line['errors']) { $errorrows[] = $rownum; if (count($errorrows) >= $previewlimit) { return $errorrows; } } else if ($rownum && $line['warnings']) { if (count($warningrows) + count($errorrows) < $previewlimit) { $warningrows[] = $rownum; } } } // Include as many error rows as possible and top them up with warning rows. $rows = array_merge($errorrows, array_slice($warningrows, 0, $previewlimit - count($errorrows))); // Keep adding good rows until we reach limit. for ($rownum = 1; count($rows) < $previewlimit; $rownum++) { if (!in_array($rownum, $rows)) { $rows[] = $rownum; } } asort($rows); } return $rows; }
[ "protected", "function", "get_previewed_rows", "(", ")", "{", "$", "previewlimit", "=", "10", ";", "if", "(", "count", "(", "$", "this", "->", "processeddata", ")", "<=", "1", ")", "{", "$", "rows", "=", "array", "(", ")", ";", "}", "else", "if", "(", "count", "(", "$", "this", "->", "processeddata", ")", "<", "$", "previewlimit", "+", "1", ")", "{", "// Return all rows.", "$", "rows", "=", "range", "(", "1", ",", "count", "(", "$", "this", "->", "processeddata", ")", "-", "1", ")", ";", "}", "else", "{", "// First find rows with errors and warnings (no more than 10 of each).", "$", "errorrows", "=", "$", "warningrows", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "processeddata", "as", "$", "rownum", "=>", "$", "line", ")", "{", "if", "(", "$", "rownum", "&&", "$", "line", "[", "'errors'", "]", ")", "{", "$", "errorrows", "[", "]", "=", "$", "rownum", ";", "if", "(", "count", "(", "$", "errorrows", ")", ">=", "$", "previewlimit", ")", "{", "return", "$", "errorrows", ";", "}", "}", "else", "if", "(", "$", "rownum", "&&", "$", "line", "[", "'warnings'", "]", ")", "{", "if", "(", "count", "(", "$", "warningrows", ")", "+", "count", "(", "$", "errorrows", ")", "<", "$", "previewlimit", ")", "{", "$", "warningrows", "[", "]", "=", "$", "rownum", ";", "}", "}", "}", "// Include as many error rows as possible and top them up with warning rows.", "$", "rows", "=", "array_merge", "(", "$", "errorrows", ",", "array_slice", "(", "$", "warningrows", ",", "0", ",", "$", "previewlimit", "-", "count", "(", "$", "errorrows", ")", ")", ")", ";", "// Keep adding good rows until we reach limit.", "for", "(", "$", "rownum", "=", "1", ";", "count", "(", "$", "rows", ")", "<", "$", "previewlimit", ";", "$", "rownum", "++", ")", "{", "if", "(", "!", "in_array", "(", "$", "rownum", ",", "$", "rows", ")", ")", "{", "$", "rows", "[", "]", "=", "$", "rownum", ";", "}", "}", "asort", "(", "$", "rows", ")", ";", "}", "return", "$", "rows", ";", "}" ]
Find up rows to show in preview Number of previewed rows is limited but rows with errors and warnings have priority. @return array
[ "Find", "up", "rows", "to", "show", "in", "preview" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cohort/upload_form.php#L279-L312
213,892
moodle/moodle
cohort/upload_form.php
cohort_upload_form.clean_cohort_data
protected function clean_cohort_data(&$hash) { foreach ($hash as $key => $value) { switch ($key) { case 'contextid': $hash[$key] = clean_param($value, PARAM_INT); break; case 'name': $hash[$key] = core_text::substr(clean_param($value, PARAM_TEXT), 0, 254); break; case 'idnumber': $hash[$key] = core_text::substr(clean_param($value, PARAM_RAW), 0, 254); break; case 'description': $hash[$key] = clean_param($value, PARAM_RAW); break; case 'descriptionformat': $hash[$key] = clean_param($value, PARAM_INT); break; case 'visible': $tempstr = trim(core_text::strtolower($value)); if ($tempstr === '') { // Empty string is treated as "YES" (the default value for cohort visibility). $hash[$key] = 1; } else { if ($tempstr === core_text::strtolower(get_string('no')) || $tempstr === 'n') { // Special treatment for 'no' string that is not included in clean_param(). $value = 0; } $hash[$key] = clean_param($value, PARAM_BOOL) ? 1 : 0; } break; case 'theme': $hash[$key] = core_text::substr(clean_param($value, PARAM_TEXT), 0, 50); break; } } }
php
protected function clean_cohort_data(&$hash) { foreach ($hash as $key => $value) { switch ($key) { case 'contextid': $hash[$key] = clean_param($value, PARAM_INT); break; case 'name': $hash[$key] = core_text::substr(clean_param($value, PARAM_TEXT), 0, 254); break; case 'idnumber': $hash[$key] = core_text::substr(clean_param($value, PARAM_RAW), 0, 254); break; case 'description': $hash[$key] = clean_param($value, PARAM_RAW); break; case 'descriptionformat': $hash[$key] = clean_param($value, PARAM_INT); break; case 'visible': $tempstr = trim(core_text::strtolower($value)); if ($tempstr === '') { // Empty string is treated as "YES" (the default value for cohort visibility). $hash[$key] = 1; } else { if ($tempstr === core_text::strtolower(get_string('no')) || $tempstr === 'n') { // Special treatment for 'no' string that is not included in clean_param(). $value = 0; } $hash[$key] = clean_param($value, PARAM_BOOL) ? 1 : 0; } break; case 'theme': $hash[$key] = core_text::substr(clean_param($value, PARAM_TEXT), 0, 50); break; } } }
[ "protected", "function", "clean_cohort_data", "(", "&", "$", "hash", ")", "{", "foreach", "(", "$", "hash", "as", "$", "key", "=>", "$", "value", ")", "{", "switch", "(", "$", "key", ")", "{", "case", "'contextid'", ":", "$", "hash", "[", "$", "key", "]", "=", "clean_param", "(", "$", "value", ",", "PARAM_INT", ")", ";", "break", ";", "case", "'name'", ":", "$", "hash", "[", "$", "key", "]", "=", "core_text", "::", "substr", "(", "clean_param", "(", "$", "value", ",", "PARAM_TEXT", ")", ",", "0", ",", "254", ")", ";", "break", ";", "case", "'idnumber'", ":", "$", "hash", "[", "$", "key", "]", "=", "core_text", "::", "substr", "(", "clean_param", "(", "$", "value", ",", "PARAM_RAW", ")", ",", "0", ",", "254", ")", ";", "break", ";", "case", "'description'", ":", "$", "hash", "[", "$", "key", "]", "=", "clean_param", "(", "$", "value", ",", "PARAM_RAW", ")", ";", "break", ";", "case", "'descriptionformat'", ":", "$", "hash", "[", "$", "key", "]", "=", "clean_param", "(", "$", "value", ",", "PARAM_INT", ")", ";", "break", ";", "case", "'visible'", ":", "$", "tempstr", "=", "trim", "(", "core_text", "::", "strtolower", "(", "$", "value", ")", ")", ";", "if", "(", "$", "tempstr", "===", "''", ")", "{", "// Empty string is treated as \"YES\" (the default value for cohort visibility).", "$", "hash", "[", "$", "key", "]", "=", "1", ";", "}", "else", "{", "if", "(", "$", "tempstr", "===", "core_text", "::", "strtolower", "(", "get_string", "(", "'no'", ")", ")", "||", "$", "tempstr", "===", "'n'", ")", "{", "// Special treatment for 'no' string that is not included in clean_param().", "$", "value", "=", "0", ";", "}", "$", "hash", "[", "$", "key", "]", "=", "clean_param", "(", "$", "value", ",", "PARAM_BOOL", ")", "?", "1", ":", "0", ";", "}", "break", ";", "case", "'theme'", ":", "$", "hash", "[", "$", "key", "]", "=", "core_text", "::", "substr", "(", "clean_param", "(", "$", "value", ",", "PARAM_TEXT", ")", ",", "0", ",", "50", ")", ";", "break", ";", "}", "}", "}" ]
Cleans input data about one cohort. @param array $hash
[ "Cleans", "input", "data", "about", "one", "cohort", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cohort/upload_form.php#L453-L479
213,893
moodle/moodle
lib/jabber/XMPP/XMPP_Old.php
XMPPHP_XMPPOld.startXML
public function startXML($parser, $name, $attr) { if($this->xml_depth == 0) { $this->session_id = $attr['ID']; $this->authenticate(); } parent::startXML($parser, $name, $attr); }
php
public function startXML($parser, $name, $attr) { if($this->xml_depth == 0) { $this->session_id = $attr['ID']; $this->authenticate(); } parent::startXML($parser, $name, $attr); }
[ "public", "function", "startXML", "(", "$", "parser", ",", "$", "name", ",", "$", "attr", ")", "{", "if", "(", "$", "this", "->", "xml_depth", "==", "0", ")", "{", "$", "this", "->", "session_id", "=", "$", "attr", "[", "'ID'", "]", ";", "$", "this", "->", "authenticate", "(", ")", ";", "}", "parent", "::", "startXML", "(", "$", "parser", ",", "$", "name", ",", "$", "attr", ")", ";", "}" ]
Override XMLStream's startXML @param parser $parser @param string $name @param array $attr
[ "Override", "XMLStream", "s", "startXML" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/jabber/XMPP/XMPP_Old.php#L59-L65
213,894
moodle/moodle
lib/jabber/XMPP/XMPP_Old.php
XMPPHP_XMPPOld.authFieldsHandler
public function authFieldsHandler($xml) { $id = $this->getId(); $this->addidhandler($id, 'oldAuthResultHandler'); if($xml->sub('query')->hasSub('digest')) { $hash = sha1($this->session_id . $this->password); print "{$this->session_id} {$this->password}\n"; $out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><digest>{$hash}</digest><resource>{$this->resource}</resource></query></iq>"; } else { $out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><password>{$this->password}</password><resource>{$this->resource}</resource></query></iq>"; } $this->send($out); }
php
public function authFieldsHandler($xml) { $id = $this->getId(); $this->addidhandler($id, 'oldAuthResultHandler'); if($xml->sub('query')->hasSub('digest')) { $hash = sha1($this->session_id . $this->password); print "{$this->session_id} {$this->password}\n"; $out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><digest>{$hash}</digest><resource>{$this->resource}</resource></query></iq>"; } else { $out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><password>{$this->password}</password><resource>{$this->resource}</resource></query></iq>"; } $this->send($out); }
[ "public", "function", "authFieldsHandler", "(", "$", "xml", ")", "{", "$", "id", "=", "$", "this", "->", "getId", "(", ")", ";", "$", "this", "->", "addidhandler", "(", "$", "id", ",", "'oldAuthResultHandler'", ")", ";", "if", "(", "$", "xml", "->", "sub", "(", "'query'", ")", "->", "hasSub", "(", "'digest'", ")", ")", "{", "$", "hash", "=", "sha1", "(", "$", "this", "->", "session_id", ".", "$", "this", "->", "password", ")", ";", "print", "\"{$this->session_id} {$this->password}\\n\"", ";", "$", "out", "=", "\"<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><digest>{$hash}</digest><resource>{$this->resource}</resource></query></iq>\"", ";", "}", "else", "{", "$", "out", "=", "\"<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><password>{$this->password}</password><resource>{$this->resource}</resource></query></iq>\"", ";", "}", "$", "this", "->", "send", "(", "$", "out", ")", ";", "}" ]
Retrieve auth fields and send auth attempt @param XMLObj $xml
[ "Retrieve", "auth", "fields", "and", "send", "auth", "attempt" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/jabber/XMPP/XMPP_Old.php#L82-L94
213,895
moodle/moodle
lib/jabber/XMPP/XMPP_Old.php
XMPPHP_XMPPOld.oldAuthResultHandler
public function oldAuthResultHandler($xml) { if($xml->attrs['type'] != 'result') { $this->log->log("Auth failed!", XMPPHP_Log::LEVEL_ERROR); $this->disconnect(); throw new XMPPHP_Exception('Auth failed!'); } else { $this->log->log("Session started"); $this->event('session_start'); } }
php
public function oldAuthResultHandler($xml) { if($xml->attrs['type'] != 'result') { $this->log->log("Auth failed!", XMPPHP_Log::LEVEL_ERROR); $this->disconnect(); throw new XMPPHP_Exception('Auth failed!'); } else { $this->log->log("Session started"); $this->event('session_start'); } }
[ "public", "function", "oldAuthResultHandler", "(", "$", "xml", ")", "{", "if", "(", "$", "xml", "->", "attrs", "[", "'type'", "]", "!=", "'result'", ")", "{", "$", "this", "->", "log", "->", "log", "(", "\"Auth failed!\"", ",", "XMPPHP_Log", "::", "LEVEL_ERROR", ")", ";", "$", "this", "->", "disconnect", "(", ")", ";", "throw", "new", "XMPPHP_Exception", "(", "'Auth failed!'", ")", ";", "}", "else", "{", "$", "this", "->", "log", "->", "log", "(", "\"Session started\"", ")", ";", "$", "this", "->", "event", "(", "'session_start'", ")", ";", "}", "}" ]
Determine authenticated or failure @param XMLObj $xml
[ "Determine", "authenticated", "or", "failure" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/jabber/XMPP/XMPP_Old.php#L101-L110
213,896
moodle/moodle
lib/pear/HTML/QuickForm/select.php
HTML_QuickForm_select.setSelected
function setSelected($values) { if (is_string($values) && $this->getMultiple()) { $values = preg_split("/[ ]?,[ ]?/", $values); } if (is_array($values)) { $this->_values = array_values($values); } else { $this->_values = array($values); } }
php
function setSelected($values) { if (is_string($values) && $this->getMultiple()) { $values = preg_split("/[ ]?,[ ]?/", $values); } if (is_array($values)) { $this->_values = array_values($values); } else { $this->_values = array($values); } }
[ "function", "setSelected", "(", "$", "values", ")", "{", "if", "(", "is_string", "(", "$", "values", ")", "&&", "$", "this", "->", "getMultiple", "(", ")", ")", "{", "$", "values", "=", "preg_split", "(", "\"/[ ]?,[ ]?/\"", ",", "$", "values", ")", ";", "}", "if", "(", "is_array", "(", "$", "values", ")", ")", "{", "$", "this", "->", "_values", "=", "array_values", "(", "$", "values", ")", ";", "}", "else", "{", "$", "this", "->", "_values", "=", "array", "(", "$", "values", ")", ";", "}", "}" ]
Sets the default values of the select box @param mixed $values Array or comma delimited string of selected values @since 1.0 @access public @return void
[ "Sets", "the", "default", "values", "of", "the", "select", "box" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/select.php#L114-L124
213,897
moodle/moodle
lib/pear/HTML/QuickForm/select.php
HTML_QuickForm_select.loadDbResult
function loadDbResult(&$result, $textCol=null, $valueCol=null, $values=null) { if (!is_object($result) || !is_a($result, 'db_result')) { return self::raiseError('Argument 1 of HTML_Select::loadDbResult is not a valid DB_result'); } if (isset($values)) { $this->setValue($values); } $fetchMode = ($textCol && $valueCol) ? DB_FETCHMODE_ASSOC : DB_FETCHMODE_ORDERED; while (is_array($row = $result->fetchRow($fetchMode)) ) { if ($fetchMode == DB_FETCHMODE_ASSOC) { $this->addOption($row[$textCol], $row[$valueCol]); } else { $this->addOption($row[0], $row[1]); } } return true; }
php
function loadDbResult(&$result, $textCol=null, $valueCol=null, $values=null) { if (!is_object($result) || !is_a($result, 'db_result')) { return self::raiseError('Argument 1 of HTML_Select::loadDbResult is not a valid DB_result'); } if (isset($values)) { $this->setValue($values); } $fetchMode = ($textCol && $valueCol) ? DB_FETCHMODE_ASSOC : DB_FETCHMODE_ORDERED; while (is_array($row = $result->fetchRow($fetchMode)) ) { if ($fetchMode == DB_FETCHMODE_ASSOC) { $this->addOption($row[$textCol], $row[$valueCol]); } else { $this->addOption($row[0], $row[1]); } } return true; }
[ "function", "loadDbResult", "(", "&", "$", "result", ",", "$", "textCol", "=", "null", ",", "$", "valueCol", "=", "null", ",", "$", "values", "=", "null", ")", "{", "if", "(", "!", "is_object", "(", "$", "result", ")", "||", "!", "is_a", "(", "$", "result", ",", "'db_result'", ")", ")", "{", "return", "self", "::", "raiseError", "(", "'Argument 1 of HTML_Select::loadDbResult is not a valid DB_result'", ")", ";", "}", "if", "(", "isset", "(", "$", "values", ")", ")", "{", "$", "this", "->", "setValue", "(", "$", "values", ")", ";", "}", "$", "fetchMode", "=", "(", "$", "textCol", "&&", "$", "valueCol", ")", "?", "DB_FETCHMODE_ASSOC", ":", "DB_FETCHMODE_ORDERED", ";", "while", "(", "is_array", "(", "$", "row", "=", "$", "result", "->", "fetchRow", "(", "$", "fetchMode", ")", ")", ")", "{", "if", "(", "$", "fetchMode", "==", "DB_FETCHMODE_ASSOC", ")", "{", "$", "this", "->", "addOption", "(", "$", "row", "[", "$", "textCol", "]", ",", "$", "row", "[", "$", "valueCol", "]", ")", ";", "}", "else", "{", "$", "this", "->", "addOption", "(", "$", "row", "[", "0", "]", ",", "$", "row", "[", "1", "]", ")", ";", "}", "}", "return", "true", ";", "}" ]
Loads the options from DB_result object If no column names are specified the first two columns of the result are used as the text and value columns respectively @param object $result DB_result object @param string $textCol (optional) Name of column to display as the OPTION text @param string $valueCol (optional) Name of column to use as the OPTION value @param mixed $values (optional) Array or comma delimited string of selected values @since 1.0 @access public @return PEAR_Error on error or true @throws PEAR_Error
[ "Loads", "the", "options", "from", "DB_result", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/select.php#L367-L384
213,898
moodle/moodle
lib/pear/HTML/QuickForm/select.php
HTML_QuickForm_select.loadQuery
function loadQuery(&$conn, $sql, $textCol=null, $valueCol=null, $values=null) { if (is_string($conn)) { require_once('DB.php'); $dbConn = &DB::connect($conn, true); if (DB::isError($dbConn)) { return $dbConn; } } elseif (is_subclass_of($conn, "db_common")) { $dbConn = &$conn; } else { return self::raiseError('Argument 1 of HTML_Select::loadQuery is not a valid type'); } $result = $dbConn->query($sql); if (DB::isError($result)) { return $result; } $this->loadDbResult($result, $textCol, $valueCol, $values); $result->free(); if (is_string($conn)) { $dbConn->disconnect(); } return true; }
php
function loadQuery(&$conn, $sql, $textCol=null, $valueCol=null, $values=null) { if (is_string($conn)) { require_once('DB.php'); $dbConn = &DB::connect($conn, true); if (DB::isError($dbConn)) { return $dbConn; } } elseif (is_subclass_of($conn, "db_common")) { $dbConn = &$conn; } else { return self::raiseError('Argument 1 of HTML_Select::loadQuery is not a valid type'); } $result = $dbConn->query($sql); if (DB::isError($result)) { return $result; } $this->loadDbResult($result, $textCol, $valueCol, $values); $result->free(); if (is_string($conn)) { $dbConn->disconnect(); } return true; }
[ "function", "loadQuery", "(", "&", "$", "conn", ",", "$", "sql", ",", "$", "textCol", "=", "null", ",", "$", "valueCol", "=", "null", ",", "$", "values", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "conn", ")", ")", "{", "require_once", "(", "'DB.php'", ")", ";", "$", "dbConn", "=", "&", "DB", "::", "connect", "(", "$", "conn", ",", "true", ")", ";", "if", "(", "DB", "::", "isError", "(", "$", "dbConn", ")", ")", "{", "return", "$", "dbConn", ";", "}", "}", "elseif", "(", "is_subclass_of", "(", "$", "conn", ",", "\"db_common\"", ")", ")", "{", "$", "dbConn", "=", "&", "$", "conn", ";", "}", "else", "{", "return", "self", "::", "raiseError", "(", "'Argument 1 of HTML_Select::loadQuery is not a valid type'", ")", ";", "}", "$", "result", "=", "$", "dbConn", "->", "query", "(", "$", "sql", ")", ";", "if", "(", "DB", "::", "isError", "(", "$", "result", ")", ")", "{", "return", "$", "result", ";", "}", "$", "this", "->", "loadDbResult", "(", "$", "result", ",", "$", "textCol", ",", "$", "valueCol", ",", "$", "values", ")", ";", "$", "result", "->", "free", "(", ")", ";", "if", "(", "is_string", "(", "$", "conn", ")", ")", "{", "$", "dbConn", "->", "disconnect", "(", ")", ";", "}", "return", "true", ";", "}" ]
Queries a database and loads the options from the results @param mixed $conn Either an existing DB connection or a valid dsn @param string $sql SQL query string @param string $textCol (optional) Name of column to display as the OPTION text @param string $valueCol (optional) Name of column to use as the OPTION value @param mixed $values (optional) Array or comma delimited string of selected values @since 1.1 @access public @return void @throws PEAR_Error
[ "Queries", "a", "database", "and", "loads", "the", "options", "from", "the", "results" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/select.php#L402-L425
213,899
moodle/moodle
lib/pear/HTML/QuickForm/select.php
HTML_QuickForm_select.load
function load(&$options, $param1=null, $param2=null, $param3=null, $param4=null) { switch (true) { case is_array($options): return $this->loadArray($options, $param1); break; case (is_a($options, 'db_result')): return $this->loadDbResult($options, $param1, $param2, $param3); break; case (is_string($options) && !empty($options) || is_subclass_of($options, "db_common")): return $this->loadQuery($options, $param1, $param2, $param3, $param4); break; } }
php
function load(&$options, $param1=null, $param2=null, $param3=null, $param4=null) { switch (true) { case is_array($options): return $this->loadArray($options, $param1); break; case (is_a($options, 'db_result')): return $this->loadDbResult($options, $param1, $param2, $param3); break; case (is_string($options) && !empty($options) || is_subclass_of($options, "db_common")): return $this->loadQuery($options, $param1, $param2, $param3, $param4); break; } }
[ "function", "load", "(", "&", "$", "options", ",", "$", "param1", "=", "null", ",", "$", "param2", "=", "null", ",", "$", "param3", "=", "null", ",", "$", "param4", "=", "null", ")", "{", "switch", "(", "true", ")", "{", "case", "is_array", "(", "$", "options", ")", ":", "return", "$", "this", "->", "loadArray", "(", "$", "options", ",", "$", "param1", ")", ";", "break", ";", "case", "(", "is_a", "(", "$", "options", ",", "'db_result'", ")", ")", ":", "return", "$", "this", "->", "loadDbResult", "(", "$", "options", ",", "$", "param1", ",", "$", "param2", ",", "$", "param3", ")", ";", "break", ";", "case", "(", "is_string", "(", "$", "options", ")", "&&", "!", "empty", "(", "$", "options", ")", "||", "is_subclass_of", "(", "$", "options", ",", "\"db_common\"", ")", ")", ":", "return", "$", "this", "->", "loadQuery", "(", "$", "options", ",", "$", "param1", ",", "$", "param2", ",", "$", "param3", ",", "$", "param4", ")", ";", "break", ";", "}", "}" ]
Loads options from different types of data sources This method is a simulated overloaded method. The arguments, other than the first are optional and only mean something depending on the type of the first argument. If the first argument is an array then all arguments are passed in order to loadArray. If the first argument is a db_result then all arguments are passed in order to loadDbResult. If the first argument is a string or a DB connection then all arguments are passed in order to loadQuery. @param mixed $options Options source currently supports assoc array or DB_result @param mixed $param1 (optional) See function detail @param mixed $param2 (optional) See function detail @param mixed $param3 (optional) See function detail @param mixed $param4 (optional) See function detail @since 1.1 @access public @return PEAR_Error on error or true @throws PEAR_Error
[ "Loads", "options", "from", "different", "types", "of", "data", "sources" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/select.php#L449-L462