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,000
moodle/moodle
lib/dml/moodle_database.php
moodle_database.query_end
protected function query_end($result) { if ($this->loggingquery) { return; } if ($result !== false) { $this->query_log(); // free memory $this->last_sql = null; $this->last_params = null; $this->print_debug_time(); return; } // remember current info, log queries may alter it $type = $this->last_type; $sql = $this->last_sql; $params = $this->last_params; $error = $this->get_last_error(); $this->query_log($error); switch ($type) { case SQL_QUERY_SELECT: case SQL_QUERY_AUX: throw new dml_read_exception($error, $sql, $params); case SQL_QUERY_INSERT: case SQL_QUERY_UPDATE: throw new dml_write_exception($error, $sql, $params); case SQL_QUERY_STRUCTURE: $this->get_manager(); // includes ddl exceptions classes ;-) throw new ddl_change_structure_exception($error, $sql); } }
php
protected function query_end($result) { if ($this->loggingquery) { return; } if ($result !== false) { $this->query_log(); // free memory $this->last_sql = null; $this->last_params = null; $this->print_debug_time(); return; } // remember current info, log queries may alter it $type = $this->last_type; $sql = $this->last_sql; $params = $this->last_params; $error = $this->get_last_error(); $this->query_log($error); switch ($type) { case SQL_QUERY_SELECT: case SQL_QUERY_AUX: throw new dml_read_exception($error, $sql, $params); case SQL_QUERY_INSERT: case SQL_QUERY_UPDATE: throw new dml_write_exception($error, $sql, $params); case SQL_QUERY_STRUCTURE: $this->get_manager(); // includes ddl exceptions classes ;-) throw new ddl_change_structure_exception($error, $sql); } }
[ "protected", "function", "query_end", "(", "$", "result", ")", "{", "if", "(", "$", "this", "->", "loggingquery", ")", "{", "return", ";", "}", "if", "(", "$", "result", "!==", "false", ")", "{", "$", "this", "->", "query_log", "(", ")", ";", "// free memory", "$", "this", "->", "last_sql", "=", "null", ";", "$", "this", "->", "last_params", "=", "null", ";", "$", "this", "->", "print_debug_time", "(", ")", ";", "return", ";", "}", "// remember current info, log queries may alter it", "$", "type", "=", "$", "this", "->", "last_type", ";", "$", "sql", "=", "$", "this", "->", "last_sql", ";", "$", "params", "=", "$", "this", "->", "last_params", ";", "$", "error", "=", "$", "this", "->", "get_last_error", "(", ")", ";", "$", "this", "->", "query_log", "(", "$", "error", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "SQL_QUERY_SELECT", ":", "case", "SQL_QUERY_AUX", ":", "throw", "new", "dml_read_exception", "(", "$", "error", ",", "$", "sql", ",", "$", "params", ")", ";", "case", "SQL_QUERY_INSERT", ":", "case", "SQL_QUERY_UPDATE", ":", "throw", "new", "dml_write_exception", "(", "$", "error", ",", "$", "sql", ",", "$", "params", ")", ";", "case", "SQL_QUERY_STRUCTURE", ":", "$", "this", "->", "get_manager", "(", ")", ";", "// includes ddl exceptions classes ;-)", "throw", "new", "ddl_change_structure_exception", "(", "$", "error", ",", "$", "sql", ")", ";", "}", "}" ]
This should be called immediately after each db query. It does a clean up of resources. It also throws exceptions if the sql that ran produced errors. @param mixed $result The db specific result obtained from running a query. @throws dml_read_exception | dml_write_exception | ddl_change_structure_exception @return void
[ "This", "should", "be", "called", "immediately", "after", "each", "db", "query", ".", "It", "does", "a", "clean", "up", "of", "resources", ".", "It", "also", "throws", "exceptions", "if", "the", "sql", "that", "ran", "produced", "errors", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L462-L494
213,001
moodle/moodle
lib/dml/moodle_database.php
moodle_database.print_debug
protected function print_debug($sql, array $params=null, $obj=null) { if (!$this->get_debug()) { return; } if (CLI_SCRIPT) { $separator = "--------------------------------\n"; echo $separator; echo "{$sql}\n"; if (!is_null($params)) { echo "[" . var_export($params, true) . "]\n"; } echo $separator; } else if (AJAX_SCRIPT) { $separator = "--------------------------------"; error_log($separator); error_log($sql); if (!is_null($params)) { error_log("[" . var_export($params, true) . "]"); } error_log($separator); } else { $separator = "<hr />\n"; echo $separator; echo s($sql) . "\n"; if (!is_null($params)) { echo "[" . s(var_export($params, true)) . "]\n"; } echo $separator; } }
php
protected function print_debug($sql, array $params=null, $obj=null) { if (!$this->get_debug()) { return; } if (CLI_SCRIPT) { $separator = "--------------------------------\n"; echo $separator; echo "{$sql}\n"; if (!is_null($params)) { echo "[" . var_export($params, true) . "]\n"; } echo $separator; } else if (AJAX_SCRIPT) { $separator = "--------------------------------"; error_log($separator); error_log($sql); if (!is_null($params)) { error_log("[" . var_export($params, true) . "]"); } error_log($separator); } else { $separator = "<hr />\n"; echo $separator; echo s($sql) . "\n"; if (!is_null($params)) { echo "[" . s(var_export($params, true)) . "]\n"; } echo $separator; } }
[ "protected", "function", "print_debug", "(", "$", "sql", ",", "array", "$", "params", "=", "null", ",", "$", "obj", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "get_debug", "(", ")", ")", "{", "return", ";", "}", "if", "(", "CLI_SCRIPT", ")", "{", "$", "separator", "=", "\"--------------------------------\\n\"", ";", "echo", "$", "separator", ";", "echo", "\"{$sql}\\n\"", ";", "if", "(", "!", "is_null", "(", "$", "params", ")", ")", "{", "echo", "\"[\"", ".", "var_export", "(", "$", "params", ",", "true", ")", ".", "\"]\\n\"", ";", "}", "echo", "$", "separator", ";", "}", "else", "if", "(", "AJAX_SCRIPT", ")", "{", "$", "separator", "=", "\"--------------------------------\"", ";", "error_log", "(", "$", "separator", ")", ";", "error_log", "(", "$", "sql", ")", ";", "if", "(", "!", "is_null", "(", "$", "params", ")", ")", "{", "error_log", "(", "\"[\"", ".", "var_export", "(", "$", "params", ",", "true", ")", ".", "\"]\"", ")", ";", "}", "error_log", "(", "$", "separator", ")", ";", "}", "else", "{", "$", "separator", "=", "\"<hr />\\n\"", ";", "echo", "$", "separator", ";", "echo", "s", "(", "$", "sql", ")", ".", "\"\\n\"", ";", "if", "(", "!", "is_null", "(", "$", "params", ")", ")", "{", "echo", "\"[\"", ".", "s", "(", "var_export", "(", "$", "params", ",", "true", ")", ")", ".", "\"]\\n\"", ";", "}", "echo", "$", "separator", ";", "}", "}" ]
Prints sql debug info @param string $sql The query which is being debugged. @param array $params The query parameters. (optional) @param mixed $obj The library specific object. (optional) @return void
[ "Prints", "sql", "debug", "info" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L592-L621
213,002
moodle/moodle
lib/dml/moodle_database.php
moodle_database.print_debug_time
protected function print_debug_time() { if (!$this->get_debug()) { return; } $time = $this->query_time(); $message = "Query took: {$time} seconds.\n"; if (CLI_SCRIPT) { echo $message; echo "--------------------------------\n"; } else if (AJAX_SCRIPT) { error_log($message); error_log("--------------------------------"); } else { echo s($message); echo "<hr />\n"; } }
php
protected function print_debug_time() { if (!$this->get_debug()) { return; } $time = $this->query_time(); $message = "Query took: {$time} seconds.\n"; if (CLI_SCRIPT) { echo $message; echo "--------------------------------\n"; } else if (AJAX_SCRIPT) { error_log($message); error_log("--------------------------------"); } else { echo s($message); echo "<hr />\n"; } }
[ "protected", "function", "print_debug_time", "(", ")", "{", "if", "(", "!", "$", "this", "->", "get_debug", "(", ")", ")", "{", "return", ";", "}", "$", "time", "=", "$", "this", "->", "query_time", "(", ")", ";", "$", "message", "=", "\"Query took: {$time} seconds.\\n\"", ";", "if", "(", "CLI_SCRIPT", ")", "{", "echo", "$", "message", ";", "echo", "\"--------------------------------\\n\"", ";", "}", "else", "if", "(", "AJAX_SCRIPT", ")", "{", "error_log", "(", "$", "message", ")", ";", "error_log", "(", "\"--------------------------------\"", ")", ";", "}", "else", "{", "echo", "s", "(", "$", "message", ")", ";", "echo", "\"<hr />\\n\"", ";", "}", "}" ]
Prints the time a query took to run. @return void
[ "Prints", "the", "time", "a", "query", "took", "to", "run", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L627-L643
213,003
moodle/moodle
lib/dml/moodle_database.php
moodle_database.where_clause
protected function where_clause($table, array $conditions=null) { // We accept nulls in conditions $conditions = is_null($conditions) ? array() : $conditions; if (empty($conditions)) { return array('', array()); } // Some checks performed under debugging only if (debugging()) { $columns = $this->get_columns($table); if (empty($columns)) { // no supported columns means most probably table does not exist throw new dml_exception('ddltablenotexist', $table); } foreach ($conditions as $key=>$value) { if (!isset($columns[$key])) { $a = new stdClass(); $a->fieldname = $key; $a->tablename = $table; throw new dml_exception('ddlfieldnotexist', $a); } $column = $columns[$key]; if ($column->meta_type == 'X') { //ok so the column is a text column. sorry no text columns in the where clause conditions throw new dml_exception('textconditionsnotallowed', $conditions); } } } $allowed_types = $this->allowed_param_types(); $where = array(); $params = array(); foreach ($conditions as $key=>$value) { if (is_int($key)) { throw new dml_exception('invalidnumkey'); } if (is_null($value)) { $where[] = "$key IS NULL"; } else { if ($allowed_types & SQL_PARAMS_NAMED) { // Need to verify key names because they can contain, originally, // spaces and other forbidden chars when using sql_xxx() functions and friends. $normkey = trim(preg_replace('/[^a-zA-Z0-9_-]/', '_', $key), '-_'); if ($normkey !== $key) { debugging('Invalid key found in the conditions array.'); } $where[] = "$key = :$normkey"; $params[$normkey] = $value; } else { $where[] = "$key = ?"; $params[] = $value; } } } $where = implode(" AND ", $where); return array($where, $params); }
php
protected function where_clause($table, array $conditions=null) { // We accept nulls in conditions $conditions = is_null($conditions) ? array() : $conditions; if (empty($conditions)) { return array('', array()); } // Some checks performed under debugging only if (debugging()) { $columns = $this->get_columns($table); if (empty($columns)) { // no supported columns means most probably table does not exist throw new dml_exception('ddltablenotexist', $table); } foreach ($conditions as $key=>$value) { if (!isset($columns[$key])) { $a = new stdClass(); $a->fieldname = $key; $a->tablename = $table; throw new dml_exception('ddlfieldnotexist', $a); } $column = $columns[$key]; if ($column->meta_type == 'X') { //ok so the column is a text column. sorry no text columns in the where clause conditions throw new dml_exception('textconditionsnotallowed', $conditions); } } } $allowed_types = $this->allowed_param_types(); $where = array(); $params = array(); foreach ($conditions as $key=>$value) { if (is_int($key)) { throw new dml_exception('invalidnumkey'); } if (is_null($value)) { $where[] = "$key IS NULL"; } else { if ($allowed_types & SQL_PARAMS_NAMED) { // Need to verify key names because they can contain, originally, // spaces and other forbidden chars when using sql_xxx() functions and friends. $normkey = trim(preg_replace('/[^a-zA-Z0-9_-]/', '_', $key), '-_'); if ($normkey !== $key) { debugging('Invalid key found in the conditions array.'); } $where[] = "$key = :$normkey"; $params[$normkey] = $value; } else { $where[] = "$key = ?"; $params[] = $value; } } } $where = implode(" AND ", $where); return array($where, $params); }
[ "protected", "function", "where_clause", "(", "$", "table", ",", "array", "$", "conditions", "=", "null", ")", "{", "// We accept nulls in conditions", "$", "conditions", "=", "is_null", "(", "$", "conditions", ")", "?", "array", "(", ")", ":", "$", "conditions", ";", "if", "(", "empty", "(", "$", "conditions", ")", ")", "{", "return", "array", "(", "''", ",", "array", "(", ")", ")", ";", "}", "// Some checks performed under debugging only", "if", "(", "debugging", "(", ")", ")", "{", "$", "columns", "=", "$", "this", "->", "get_columns", "(", "$", "table", ")", ";", "if", "(", "empty", "(", "$", "columns", ")", ")", "{", "// no supported columns means most probably table does not exist", "throw", "new", "dml_exception", "(", "'ddltablenotexist'", ",", "$", "table", ")", ";", "}", "foreach", "(", "$", "conditions", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "$", "columns", "[", "$", "key", "]", ")", ")", "{", "$", "a", "=", "new", "stdClass", "(", ")", ";", "$", "a", "->", "fieldname", "=", "$", "key", ";", "$", "a", "->", "tablename", "=", "$", "table", ";", "throw", "new", "dml_exception", "(", "'ddlfieldnotexist'", ",", "$", "a", ")", ";", "}", "$", "column", "=", "$", "columns", "[", "$", "key", "]", ";", "if", "(", "$", "column", "->", "meta_type", "==", "'X'", ")", "{", "//ok so the column is a text column. sorry no text columns in the where clause conditions", "throw", "new", "dml_exception", "(", "'textconditionsnotallowed'", ",", "$", "conditions", ")", ";", "}", "}", "}", "$", "allowed_types", "=", "$", "this", "->", "allowed_param_types", "(", ")", ";", "$", "where", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", ")", ";", "foreach", "(", "$", "conditions", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_int", "(", "$", "key", ")", ")", "{", "throw", "new", "dml_exception", "(", "'invalidnumkey'", ")", ";", "}", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "$", "where", "[", "]", "=", "\"$key IS NULL\"", ";", "}", "else", "{", "if", "(", "$", "allowed_types", "&", "SQL_PARAMS_NAMED", ")", "{", "// Need to verify key names because they can contain, originally,", "// spaces and other forbidden chars when using sql_xxx() functions and friends.", "$", "normkey", "=", "trim", "(", "preg_replace", "(", "'/[^a-zA-Z0-9_-]/'", ",", "'_'", ",", "$", "key", ")", ",", "'-_'", ")", ";", "if", "(", "$", "normkey", "!==", "$", "key", ")", "{", "debugging", "(", "'Invalid key found in the conditions array.'", ")", ";", "}", "$", "where", "[", "]", "=", "\"$key = :$normkey\"", ";", "$", "params", "[", "$", "normkey", "]", "=", "$", "value", ";", "}", "else", "{", "$", "where", "[", "]", "=", "\"$key = ?\"", ";", "$", "params", "[", "]", "=", "$", "value", ";", "}", "}", "}", "$", "where", "=", "implode", "(", "\" AND \"", ",", "$", "where", ")", ";", "return", "array", "(", "$", "where", ",", "$", "params", ")", ";", "}" ]
Returns the SQL WHERE conditions. @param string $table The table name that these conditions will be validated against. @param array $conditions The conditions to build the where clause. (must not contain numeric indexes) @throws dml_exception @return array An array list containing sql 'where' part and 'params'.
[ "Returns", "the", "SQL", "WHERE", "conditions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L652-L710
213,004
moodle/moodle
lib/dml/moodle_database.php
moodle_database.where_clause_list
protected function where_clause_list($field, array $values) { if (empty($values)) { return array("1 = 2", array()); // Fake condition, won't return rows ever. MDL-17645 } // Note: Do not use get_in_or_equal() because it can not deal with bools and nulls. $params = array(); $select = ""; $values = (array)$values; foreach ($values as $value) { if (is_bool($value)) { $value = (int)$value; } if (is_null($value)) { $select = "$field IS NULL"; } else { $params[] = $value; } } if ($params) { if ($select !== "") { $select = "$select OR "; } $count = count($params); if ($count == 1) { $select = $select."$field = ?"; } else { $qs = str_repeat(',?', $count); $qs = ltrim($qs, ','); $select = $select."$field IN ($qs)"; } } return array($select, $params); }
php
protected function where_clause_list($field, array $values) { if (empty($values)) { return array("1 = 2", array()); // Fake condition, won't return rows ever. MDL-17645 } // Note: Do not use get_in_or_equal() because it can not deal with bools and nulls. $params = array(); $select = ""; $values = (array)$values; foreach ($values as $value) { if (is_bool($value)) { $value = (int)$value; } if (is_null($value)) { $select = "$field IS NULL"; } else { $params[] = $value; } } if ($params) { if ($select !== "") { $select = "$select OR "; } $count = count($params); if ($count == 1) { $select = $select."$field = ?"; } else { $qs = str_repeat(',?', $count); $qs = ltrim($qs, ','); $select = $select."$field IN ($qs)"; } } return array($select, $params); }
[ "protected", "function", "where_clause_list", "(", "$", "field", ",", "array", "$", "values", ")", "{", "if", "(", "empty", "(", "$", "values", ")", ")", "{", "return", "array", "(", "\"1 = 2\"", ",", "array", "(", ")", ")", ";", "// Fake condition, won't return rows ever. MDL-17645", "}", "// Note: Do not use get_in_or_equal() because it can not deal with bools and nulls.", "$", "params", "=", "array", "(", ")", ";", "$", "select", "=", "\"\"", ";", "$", "values", "=", "(", "array", ")", "$", "values", ";", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "if", "(", "is_bool", "(", "$", "value", ")", ")", "{", "$", "value", "=", "(", "int", ")", "$", "value", ";", "}", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "$", "select", "=", "\"$field IS NULL\"", ";", "}", "else", "{", "$", "params", "[", "]", "=", "$", "value", ";", "}", "}", "if", "(", "$", "params", ")", "{", "if", "(", "$", "select", "!==", "\"\"", ")", "{", "$", "select", "=", "\"$select OR \"", ";", "}", "$", "count", "=", "count", "(", "$", "params", ")", ";", "if", "(", "$", "count", "==", "1", ")", "{", "$", "select", "=", "$", "select", ".", "\"$field = ?\"", ";", "}", "else", "{", "$", "qs", "=", "str_repeat", "(", "',?'", ",", "$", "count", ")", ";", "$", "qs", "=", "ltrim", "(", "$", "qs", ",", "','", ")", ";", "$", "select", "=", "$", "select", ".", "\"$field IN ($qs)\"", ";", "}", "}", "return", "array", "(", "$", "select", ",", "$", "params", ")", ";", "}" ]
Returns SQL WHERE conditions for the ..._list group of methods. @param string $field the name of a field. @param array $values the values field might take. @return array An array containing sql 'where' part and 'params'
[ "Returns", "SQL", "WHERE", "conditions", "for", "the", "...", "_list", "group", "of", "methods", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L719-L753
213,005
moodle/moodle
lib/dml/moodle_database.php
moodle_database.normalise_limit_from_num
protected function normalise_limit_from_num($limitfrom, $limitnum) { global $CFG; // We explicilty treat these cases as 0. if ($limitfrom === null || $limitfrom === '' || $limitfrom === -1) { $limitfrom = 0; } if ($limitnum === null || $limitnum === '' || $limitnum === -1) { $limitnum = 0; } if ($CFG->debugdeveloper) { if (!is_numeric($limitfrom)) { $strvalue = var_export($limitfrom, true); debugging("Non-numeric limitfrom parameter detected: $strvalue, did you pass the correct arguments?", DEBUG_DEVELOPER); } else if ($limitfrom < 0) { debugging("Negative limitfrom parameter detected: $limitfrom, did you pass the correct arguments?", DEBUG_DEVELOPER); } if (!is_numeric($limitnum)) { $strvalue = var_export($limitnum, true); debugging("Non-numeric limitnum parameter detected: $strvalue, did you pass the correct arguments?", DEBUG_DEVELOPER); } else if ($limitnum < 0) { debugging("Negative limitnum parameter detected: $limitnum, did you pass the correct arguments?", DEBUG_DEVELOPER); } } $limitfrom = (int)$limitfrom; $limitnum = (int)$limitnum; $limitfrom = max(0, $limitfrom); $limitnum = max(0, $limitnum); return array($limitfrom, $limitnum); }
php
protected function normalise_limit_from_num($limitfrom, $limitnum) { global $CFG; // We explicilty treat these cases as 0. if ($limitfrom === null || $limitfrom === '' || $limitfrom === -1) { $limitfrom = 0; } if ($limitnum === null || $limitnum === '' || $limitnum === -1) { $limitnum = 0; } if ($CFG->debugdeveloper) { if (!is_numeric($limitfrom)) { $strvalue = var_export($limitfrom, true); debugging("Non-numeric limitfrom parameter detected: $strvalue, did you pass the correct arguments?", DEBUG_DEVELOPER); } else if ($limitfrom < 0) { debugging("Negative limitfrom parameter detected: $limitfrom, did you pass the correct arguments?", DEBUG_DEVELOPER); } if (!is_numeric($limitnum)) { $strvalue = var_export($limitnum, true); debugging("Non-numeric limitnum parameter detected: $strvalue, did you pass the correct arguments?", DEBUG_DEVELOPER); } else if ($limitnum < 0) { debugging("Negative limitnum parameter detected: $limitnum, did you pass the correct arguments?", DEBUG_DEVELOPER); } } $limitfrom = (int)$limitfrom; $limitnum = (int)$limitnum; $limitfrom = max(0, $limitfrom); $limitnum = max(0, $limitnum); return array($limitfrom, $limitnum); }
[ "protected", "function", "normalise_limit_from_num", "(", "$", "limitfrom", ",", "$", "limitnum", ")", "{", "global", "$", "CFG", ";", "// We explicilty treat these cases as 0.", "if", "(", "$", "limitfrom", "===", "null", "||", "$", "limitfrom", "===", "''", "||", "$", "limitfrom", "===", "-", "1", ")", "{", "$", "limitfrom", "=", "0", ";", "}", "if", "(", "$", "limitnum", "===", "null", "||", "$", "limitnum", "===", "''", "||", "$", "limitnum", "===", "-", "1", ")", "{", "$", "limitnum", "=", "0", ";", "}", "if", "(", "$", "CFG", "->", "debugdeveloper", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "limitfrom", ")", ")", "{", "$", "strvalue", "=", "var_export", "(", "$", "limitfrom", ",", "true", ")", ";", "debugging", "(", "\"Non-numeric limitfrom parameter detected: $strvalue, did you pass the correct arguments?\"", ",", "DEBUG_DEVELOPER", ")", ";", "}", "else", "if", "(", "$", "limitfrom", "<", "0", ")", "{", "debugging", "(", "\"Negative limitfrom parameter detected: $limitfrom, did you pass the correct arguments?\"", ",", "DEBUG_DEVELOPER", ")", ";", "}", "if", "(", "!", "is_numeric", "(", "$", "limitnum", ")", ")", "{", "$", "strvalue", "=", "var_export", "(", "$", "limitnum", ",", "true", ")", ";", "debugging", "(", "\"Non-numeric limitnum parameter detected: $strvalue, did you pass the correct arguments?\"", ",", "DEBUG_DEVELOPER", ")", ";", "}", "else", "if", "(", "$", "limitnum", "<", "0", ")", "{", "debugging", "(", "\"Negative limitnum parameter detected: $limitnum, did you pass the correct arguments?\"", ",", "DEBUG_DEVELOPER", ")", ";", "}", "}", "$", "limitfrom", "=", "(", "int", ")", "$", "limitfrom", ";", "$", "limitnum", "=", "(", "int", ")", "$", "limitnum", ";", "$", "limitfrom", "=", "max", "(", "0", ",", "$", "limitfrom", ")", ";", "$", "limitnum", "=", "max", "(", "0", ",", "$", "limitnum", ")", ";", "return", "array", "(", "$", "limitfrom", ",", "$", "limitnum", ")", ";", "}" ]
Ensures that limit params are numeric and positive integers, to be passed to the database. We explicitly treat null, '' and -1 as 0 in order to provide compatibility with how limit values have been passed historically. @param int $limitfrom Where to start results from @param int $limitnum How many results to return @return array Normalised limit params in array($limitfrom, $limitnum)
[ "Ensures", "that", "limit", "params", "are", "numeric", "and", "positive", "integers", "to", "be", "passed", "to", "the", "database", ".", "We", "explicitly", "treat", "null", "and", "-", "1", "as", "0", "in", "order", "to", "provide", "compatibility", "with", "how", "limit", "values", "have", "been", "passed", "historically", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1026-L1063
213,006
moodle/moodle
lib/dml/moodle_database.php
moodle_database.reset_caches
public function reset_caches($tablenames = null) { if (!empty($tablenames)) { $dbmetapurged = false; foreach ($tablenames as $tablename) { if ($this->temptables->is_temptable($tablename)) { $this->get_temp_tables_cache()->delete($tablename); } else if ($dbmetapurged === false) { $this->tables = null; $this->get_metacache()->purge(); $this->metacache = null; $dbmetapurged = true; } } } else { $this->get_temp_tables_cache()->purge(); $this->tables = null; // Purge MUC as well. $this->get_metacache()->purge(); $this->metacache = null; } }
php
public function reset_caches($tablenames = null) { if (!empty($tablenames)) { $dbmetapurged = false; foreach ($tablenames as $tablename) { if ($this->temptables->is_temptable($tablename)) { $this->get_temp_tables_cache()->delete($tablename); } else if ($dbmetapurged === false) { $this->tables = null; $this->get_metacache()->purge(); $this->metacache = null; $dbmetapurged = true; } } } else { $this->get_temp_tables_cache()->purge(); $this->tables = null; // Purge MUC as well. $this->get_metacache()->purge(); $this->metacache = null; } }
[ "public", "function", "reset_caches", "(", "$", "tablenames", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "tablenames", ")", ")", "{", "$", "dbmetapurged", "=", "false", ";", "foreach", "(", "$", "tablenames", "as", "$", "tablename", ")", "{", "if", "(", "$", "this", "->", "temptables", "->", "is_temptable", "(", "$", "tablename", ")", ")", "{", "$", "this", "->", "get_temp_tables_cache", "(", ")", "->", "delete", "(", "$", "tablename", ")", ";", "}", "else", "if", "(", "$", "dbmetapurged", "===", "false", ")", "{", "$", "this", "->", "tables", "=", "null", ";", "$", "this", "->", "get_metacache", "(", ")", "->", "purge", "(", ")", ";", "$", "this", "->", "metacache", "=", "null", ";", "$", "dbmetapurged", "=", "true", ";", "}", "}", "}", "else", "{", "$", "this", "->", "get_temp_tables_cache", "(", ")", "->", "purge", "(", ")", ";", "$", "this", "->", "tables", "=", "null", ";", "// Purge MUC as well.", "$", "this", "->", "get_metacache", "(", ")", "->", "purge", "(", ")", ";", "$", "this", "->", "metacache", "=", "null", ";", "}", "}" ]
Resets the internal column details cache @param array|null $tablenames an array of xmldb table names affected by this request. @return void
[ "Resets", "the", "internal", "column", "details", "cache" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1102-L1122
213,007
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_manager
public function get_manager() { global $CFG; if (!$this->database_manager) { require_once($CFG->libdir.'/ddllib.php'); $classname = $this->get_dbfamily().'_sql_generator'; require_once("$CFG->libdir/ddl/$classname.php"); $generator = new $classname($this, $this->temptables); $this->database_manager = new database_manager($this, $generator); } return $this->database_manager; }
php
public function get_manager() { global $CFG; if (!$this->database_manager) { require_once($CFG->libdir.'/ddllib.php'); $classname = $this->get_dbfamily().'_sql_generator'; require_once("$CFG->libdir/ddl/$classname.php"); $generator = new $classname($this, $this->temptables); $this->database_manager = new database_manager($this, $generator); } return $this->database_manager; }
[ "public", "function", "get_manager", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "$", "this", "->", "database_manager", ")", "{", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/ddllib.php'", ")", ";", "$", "classname", "=", "$", "this", "->", "get_dbfamily", "(", ")", ".", "'_sql_generator'", ";", "require_once", "(", "\"$CFG->libdir/ddl/$classname.php\"", ")", ";", "$", "generator", "=", "new", "$", "classname", "(", "$", "this", ",", "$", "this", "->", "temptables", ")", ";", "$", "this", "->", "database_manager", "=", "new", "database_manager", "(", "$", "this", ",", "$", "generator", ")", ";", "}", "return", "$", "this", "->", "database_manager", ";", "}" ]
Returns the sql generator used for db manipulation. Used mostly in upgrade.php scripts. @return database_manager The instance used to perform ddl operations. @see lib/ddl/database_manager.php
[ "Returns", "the", "sql", "generator", "used", "for", "db", "manipulation", ".", "Used", "mostly", "in", "upgrade", ".", "php", "scripts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1130-L1143
213,008
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_recordset
public function get_recordset($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { list($select, $params) = $this->where_clause($table, $conditions); return $this->get_recordset_select($table, $select, $params, $sort, $fields, $limitfrom, $limitnum); }
php
public function get_recordset($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { list($select, $params) = $this->where_clause($table, $conditions); return $this->get_recordset_select($table, $select, $params, $sort, $fields, $limitfrom, $limitnum); }
[ "public", "function", "get_recordset", "(", "$", "table", ",", "array", "$", "conditions", "=", "null", ",", "$", "sort", "=", "''", ",", "$", "fields", "=", "'*'", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "list", "(", "$", "select", ",", "$", "params", ")", "=", "$", "this", "->", "where_clause", "(", "$", "table", ",", "$", "conditions", ")", ";", "return", "$", "this", "->", "get_recordset_select", "(", "$", "table", ",", "$", "select", ",", "$", "params", ",", "$", "sort", ",", "$", "fields", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ";", "}" ]
Get a number of records as a moodle_recordset where all the given conditions met. Selects records from the table $table. If specified, only records meeting $conditions. If specified, the results will be sorted as specified by $sort. This is added to the SQL as "ORDER BY $sort". Example values of $sort might be "time ASC" or "time DESC". If $fields is specified, only those fields are returned. Since this method is a little less readable, use of it should be restricted to code where it's possible there might be large datasets being returned. For known small datasets use get_records - it leads to simpler code. If you only want some of the records, specify $limitfrom and $limitnum. The query will skip the first $limitfrom records (according to the sort order) and then return the next $limitnum records. If either of $limitfrom or $limitnum is specified, both must be present. The return value is a moodle_recordset if the query succeeds. If an error occurs, false is returned. @param string $table the table to query. @param array $conditions optional array $fieldname=>requestedvalue with AND in between @param string $sort an order to sort the results in (optional, a valid SQL ORDER BY parameter). @param string $fields a comma separated list of fields to return (optional, by default all fields are returned). @param int $limitfrom return a subset of records, starting at this point (optional). @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set). @return moodle_recordset A moodle_recordset instance @throws dml_exception A DML specific exception is thrown for any errors.
[ "Get", "a", "number", "of", "records", "as", "a", "moodle_recordset", "where", "all", "the", "given", "conditions", "met", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1240-L1243
213,009
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_recordset_list
public function get_recordset_list($table, $field, array $values, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { list($select, $params) = $this->where_clause_list($field, $values); return $this->get_recordset_select($table, $select, $params, $sort, $fields, $limitfrom, $limitnum); }
php
public function get_recordset_list($table, $field, array $values, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { list($select, $params) = $this->where_clause_list($field, $values); return $this->get_recordset_select($table, $select, $params, $sort, $fields, $limitfrom, $limitnum); }
[ "public", "function", "get_recordset_list", "(", "$", "table", ",", "$", "field", ",", "array", "$", "values", ",", "$", "sort", "=", "''", ",", "$", "fields", "=", "'*'", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "list", "(", "$", "select", ",", "$", "params", ")", "=", "$", "this", "->", "where_clause_list", "(", "$", "field", ",", "$", "values", ")", ";", "return", "$", "this", "->", "get_recordset_select", "(", "$", "table", ",", "$", "select", ",", "$", "params", ",", "$", "sort", ",", "$", "fields", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ";", "}" ]
Get a number of records as a moodle_recordset where one field match one list of values. Only records where $field takes one of the values $values are returned. $values must be an array of values. Other arguments and the return type are like {@link function get_recordset}. @param string $table the table to query. @param string $field a field to check (optional). @param array $values array of values the field must have @param string $sort an order to sort the results in (optional, a valid SQL ORDER BY parameter). @param string $fields a comma separated list of fields to return (optional, by default all fields are returned). @param int $limitfrom return a subset of records, starting at this point (optional). @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set). @return moodle_recordset A moodle_recordset instance. @throws dml_exception A DML specific exception is thrown for any errors.
[ "Get", "a", "number", "of", "records", "as", "a", "moodle_recordset", "where", "one", "field", "match", "one", "list", "of", "values", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1263-L1266
213,010
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_recordset_select
public function get_recordset_select($table, $select, array $params=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { $sql = "SELECT $fields FROM {".$table."}"; if ($select) { $sql .= " WHERE $select"; } if ($sort) { $sql .= " ORDER BY $sort"; } return $this->get_recordset_sql($sql, $params, $limitfrom, $limitnum); }
php
public function get_recordset_select($table, $select, array $params=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { $sql = "SELECT $fields FROM {".$table."}"; if ($select) { $sql .= " WHERE $select"; } if ($sort) { $sql .= " ORDER BY $sort"; } return $this->get_recordset_sql($sql, $params, $limitfrom, $limitnum); }
[ "public", "function", "get_recordset_select", "(", "$", "table", ",", "$", "select", ",", "array", "$", "params", "=", "null", ",", "$", "sort", "=", "''", ",", "$", "fields", "=", "'*'", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "$", "sql", "=", "\"SELECT $fields FROM {\"", ".", "$", "table", ".", "\"}\"", ";", "if", "(", "$", "select", ")", "{", "$", "sql", ".=", "\" WHERE $select\"", ";", "}", "if", "(", "$", "sort", ")", "{", "$", "sql", ".=", "\" ORDER BY $sort\"", ";", "}", "return", "$", "this", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ";", "}" ]
Get a number of records as a moodle_recordset which match a particular WHERE clause. If given, $select is used as the SELECT parameter in the SQL query, otherwise all records from the table are returned. Other arguments and the return type are like {@link function get_recordset}. @param string $table the table to query. @param string $select A fragment of SQL to be used in a where clause in the SQL call. @param array $params array of sql parameters @param string $sort an order to sort the results in (optional, a valid SQL ORDER BY parameter). @param string $fields a comma separated list of fields to return (optional, by default all fields are returned). @param int $limitfrom return a subset of records, starting at this point (optional). @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set). @return moodle_recordset A moodle_recordset instance. @throws dml_exception A DML specific exception is thrown for any errors.
[ "Get", "a", "number", "of", "records", "as", "a", "moodle_recordset", "which", "match", "a", "particular", "WHERE", "clause", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1286-L1295
213,011
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_records
public function get_records($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { list($select, $params) = $this->where_clause($table, $conditions); return $this->get_records_select($table, $select, $params, $sort, $fields, $limitfrom, $limitnum); }
php
public function get_records($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { list($select, $params) = $this->where_clause($table, $conditions); return $this->get_records_select($table, $select, $params, $sort, $fields, $limitfrom, $limitnum); }
[ "public", "function", "get_records", "(", "$", "table", ",", "array", "$", "conditions", "=", "null", ",", "$", "sort", "=", "''", ",", "$", "fields", "=", "'*'", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "list", "(", "$", "select", ",", "$", "params", ")", "=", "$", "this", "->", "where_clause", "(", "$", "table", ",", "$", "conditions", ")", ";", "return", "$", "this", "->", "get_records_select", "(", "$", "table", ",", "$", "select", ",", "$", "params", ",", "$", "sort", ",", "$", "fields", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ";", "}" ]
Get a number of records as an array of objects where all the given conditions met. If the query succeeds and returns at least one record, the return value is an array of objects, one object for each record found. The array key is the value from the first column of the result set. The object associated with that key has a member variable for each column of the results. @param string $table the table to query. @param array $conditions optional array $fieldname=>requestedvalue with AND in between @param string $sort an order to sort the results in (optional, a valid SQL ORDER BY parameter). @param string $fields a comma separated list of fields to return (optional, by default all fields are returned). The first field will be used as key for the array so must be a unique field such as 'id'. @param int $limitfrom return a subset of records, starting at this point (optional). @param int $limitnum return a subset comprising this many records in total (optional, required if $limitfrom is set). @return array An array of Objects indexed by first column. @throws dml_exception A DML specific exception is thrown for any errors.
[ "Get", "a", "number", "of", "records", "as", "an", "array", "of", "objects", "where", "all", "the", "given", "conditions", "met", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1349-L1352
213,012
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_records_list
public function get_records_list($table, $field, array $values, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { list($select, $params) = $this->where_clause_list($field, $values); return $this->get_records_select($table, $select, $params, $sort, $fields, $limitfrom, $limitnum); }
php
public function get_records_list($table, $field, array $values, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { list($select, $params) = $this->where_clause_list($field, $values); return $this->get_records_select($table, $select, $params, $sort, $fields, $limitfrom, $limitnum); }
[ "public", "function", "get_records_list", "(", "$", "table", ",", "$", "field", ",", "array", "$", "values", ",", "$", "sort", "=", "''", ",", "$", "fields", "=", "'*'", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "list", "(", "$", "select", ",", "$", "params", ")", "=", "$", "this", "->", "where_clause_list", "(", "$", "field", ",", "$", "values", ")", ";", "return", "$", "this", "->", "get_records_select", "(", "$", "table", ",", "$", "select", ",", "$", "params", ",", "$", "sort", ",", "$", "fields", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ";", "}" ]
Get a number of records as an array of objects where one field match one list of values. Return value is like {@link function get_records}. @param string $table The database table to be checked against. @param string $field The field to search @param array $values An array of values @param string $sort Sort order (as valid SQL sort parameter) @param string $fields A comma separated list of fields to be returned from the chosen table. If specified, the first field should be a unique one such as 'id' since it will be used as a key in the associative array. @param int $limitfrom return a subset of records, starting at this point (optional). @param int $limitnum return a subset comprising this many records in total (optional). @return array An array of objects indexed by first column @throws dml_exception A DML specific exception is thrown for any errors.
[ "Get", "a", "number", "of", "records", "as", "an", "array", "of", "objects", "where", "one", "field", "match", "one", "list", "of", "values", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1371-L1374
213,013
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_records_select
public function get_records_select($table, $select, array $params=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { if ($select) { $select = "WHERE $select"; } if ($sort) { $sort = " ORDER BY $sort"; } return $this->get_records_sql("SELECT $fields FROM {" . $table . "} $select $sort", $params, $limitfrom, $limitnum); }
php
public function get_records_select($table, $select, array $params=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { if ($select) { $select = "WHERE $select"; } if ($sort) { $sort = " ORDER BY $sort"; } return $this->get_records_sql("SELECT $fields FROM {" . $table . "} $select $sort", $params, $limitfrom, $limitnum); }
[ "public", "function", "get_records_select", "(", "$", "table", ",", "$", "select", ",", "array", "$", "params", "=", "null", ",", "$", "sort", "=", "''", ",", "$", "fields", "=", "'*'", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "if", "(", "$", "select", ")", "{", "$", "select", "=", "\"WHERE $select\"", ";", "}", "if", "(", "$", "sort", ")", "{", "$", "sort", "=", "\" ORDER BY $sort\"", ";", "}", "return", "$", "this", "->", "get_records_sql", "(", "\"SELECT $fields FROM {\"", ".", "$", "table", ".", "\"} $select $sort\"", ",", "$", "params", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ";", "}" ]
Get a number of records as an array of objects which match a particular WHERE clause. Return value is like {@link function get_records}. @param string $table The table to query. @param string $select A fragment of SQL to be used in a where clause in the SQL call. @param array $params An array of sql parameters @param string $sort An order to sort the results in (optional, a valid SQL ORDER BY parameter). @param string $fields A comma separated list of fields to return (optional, by default all fields are returned). The first field will be used as key for the array so must be a unique field such as 'id'. @param int $limitfrom return a subset of records, starting at this point (optional). @param int $limitnum return a subset comprising this many records in total (optional, required if $limitfrom is set). @return array of objects indexed by first column @throws dml_exception A DML specific exception is thrown for any errors.
[ "Get", "a", "number", "of", "records", "as", "an", "array", "of", "objects", "which", "match", "a", "particular", "WHERE", "clause", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1393-L1401
213,014
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_records_menu
public function get_records_menu($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { $menu = array(); if ($records = $this->get_records($table, $conditions, $sort, $fields, $limitfrom, $limitnum)) { foreach ($records as $record) { $record = (array)$record; $key = array_shift($record); $value = array_shift($record); $menu[$key] = $value; } } return $menu; }
php
public function get_records_menu($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { $menu = array(); if ($records = $this->get_records($table, $conditions, $sort, $fields, $limitfrom, $limitnum)) { foreach ($records as $record) { $record = (array)$record; $key = array_shift($record); $value = array_shift($record); $menu[$key] = $value; } } return $menu; }
[ "public", "function", "get_records_menu", "(", "$", "table", ",", "array", "$", "conditions", "=", "null", ",", "$", "sort", "=", "''", ",", "$", "fields", "=", "'*'", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "$", "menu", "=", "array", "(", ")", ";", "if", "(", "$", "records", "=", "$", "this", "->", "get_records", "(", "$", "table", ",", "$", "conditions", ",", "$", "sort", ",", "$", "fields", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ")", "{", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "record", "=", "(", "array", ")", "$", "record", ";", "$", "key", "=", "array_shift", "(", "$", "record", ")", ";", "$", "value", "=", "array_shift", "(", "$", "record", ")", ";", "$", "menu", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "menu", ";", "}" ]
Get the first two columns from a number of records as an associative array where all the given conditions met. Arguments are like {@link function get_recordset}. If no errors occur the return value is an associative whose keys come from the first field of each record, and whose values are the corresponding second fields. False is returned if an error occurs. @param string $table the table to query. @param array $conditions optional array $fieldname=>requestedvalue with AND in between @param string $sort an order to sort the results in (optional, a valid SQL ORDER BY parameter). @param string $fields a comma separated list of fields to return - the number of fields should be 2! @param int $limitfrom return a subset of records, starting at this point (optional). @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set). @return array an associative array @throws dml_exception A DML specific exception is thrown for any errors.
[ "Get", "the", "first", "two", "columns", "from", "a", "number", "of", "records", "as", "an", "associative", "array", "where", "all", "the", "given", "conditions", "met", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1438-L1449
213,015
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_records_select_menu
public function get_records_select_menu($table, $select, array $params=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { $menu = array(); if ($records = $this->get_records_select($table, $select, $params, $sort, $fields, $limitfrom, $limitnum)) { foreach ($records as $record) { $record = (array)$record; $key = array_shift($record); $value = array_shift($record); $menu[$key] = $value; } } return $menu; }
php
public function get_records_select_menu($table, $select, array $params=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) { $menu = array(); if ($records = $this->get_records_select($table, $select, $params, $sort, $fields, $limitfrom, $limitnum)) { foreach ($records as $record) { $record = (array)$record; $key = array_shift($record); $value = array_shift($record); $menu[$key] = $value; } } return $menu; }
[ "public", "function", "get_records_select_menu", "(", "$", "table", ",", "$", "select", ",", "array", "$", "params", "=", "null", ",", "$", "sort", "=", "''", ",", "$", "fields", "=", "'*'", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "$", "menu", "=", "array", "(", ")", ";", "if", "(", "$", "records", "=", "$", "this", "->", "get_records_select", "(", "$", "table", ",", "$", "select", ",", "$", "params", ",", "$", "sort", ",", "$", "fields", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ")", "{", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "record", "=", "(", "array", ")", "$", "record", ";", "$", "key", "=", "array_shift", "(", "$", "record", ")", ";", "$", "value", "=", "array_shift", "(", "$", "record", ")", ";", "$", "menu", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "menu", ";", "}" ]
Get the first two columns from a number of records as an associative array which match a particular WHERE clause. Arguments are like {@link function get_recordset_select}. Return value is like {@link function get_records_menu}. @param string $table The database table to be checked against. @param string $select A fragment of SQL to be used in a where clause in the SQL call. @param array $params array of sql parameters @param string $sort Sort order (optional) - a valid SQL order parameter @param string $fields A comma separated list of fields to be returned from the chosen table - the number of fields should be 2! @param int $limitfrom return a subset of records, starting at this point (optional). @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set). @return array an associative array @throws dml_exception A DML specific exception is thrown for any errors.
[ "Get", "the", "first", "two", "columns", "from", "a", "number", "of", "records", "as", "an", "associative", "array", "which", "match", "a", "particular", "WHERE", "clause", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1467-L1478
213,016
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_records_sql_menu
public function get_records_sql_menu($sql, array $params=null, $limitfrom=0, $limitnum=0) { $menu = array(); if ($records = $this->get_records_sql($sql, $params, $limitfrom, $limitnum)) { foreach ($records as $record) { $record = (array)$record; $key = array_shift($record); $value = array_shift($record); $menu[$key] = $value; } } return $menu; }
php
public function get_records_sql_menu($sql, array $params=null, $limitfrom=0, $limitnum=0) { $menu = array(); if ($records = $this->get_records_sql($sql, $params, $limitfrom, $limitnum)) { foreach ($records as $record) { $record = (array)$record; $key = array_shift($record); $value = array_shift($record); $menu[$key] = $value; } } return $menu; }
[ "public", "function", "get_records_sql_menu", "(", "$", "sql", ",", "array", "$", "params", "=", "null", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "$", "menu", "=", "array", "(", ")", ";", "if", "(", "$", "records", "=", "$", "this", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ")", "{", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "record", "=", "(", "array", ")", "$", "record", ";", "$", "key", "=", "array_shift", "(", "$", "record", ")", ";", "$", "value", "=", "array_shift", "(", "$", "record", ")", ";", "$", "menu", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "menu", ";", "}" ]
Get the first two columns from a number of records as an associative array using a SQL statement. Arguments are like {@link function get_recordset_sql}. Return value is like {@link function get_records_menu}. @param string $sql The SQL string you wish to be executed. @param array $params array of sql parameters @param int $limitfrom return a subset of records, starting at this point (optional). @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set). @return array an associative array @throws dml_exception A DML specific exception is thrown for any errors.
[ "Get", "the", "first", "two", "columns", "from", "a", "number", "of", "records", "as", "an", "associative", "array", "using", "a", "SQL", "statement", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1493-L1504
213,017
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_record
public function get_record($table, array $conditions, $fields='*', $strictness=IGNORE_MISSING) { list($select, $params) = $this->where_clause($table, $conditions); return $this->get_record_select($table, $select, $params, $fields, $strictness); }
php
public function get_record($table, array $conditions, $fields='*', $strictness=IGNORE_MISSING) { list($select, $params) = $this->where_clause($table, $conditions); return $this->get_record_select($table, $select, $params, $fields, $strictness); }
[ "public", "function", "get_record", "(", "$", "table", ",", "array", "$", "conditions", ",", "$", "fields", "=", "'*'", ",", "$", "strictness", "=", "IGNORE_MISSING", ")", "{", "list", "(", "$", "select", ",", "$", "params", ")", "=", "$", "this", "->", "where_clause", "(", "$", "table", ",", "$", "conditions", ")", ";", "return", "$", "this", "->", "get_record_select", "(", "$", "table", ",", "$", "select", ",", "$", "params", ",", "$", "fields", ",", "$", "strictness", ")", ";", "}" ]
Get a single database record as an object where all the given conditions met. @param string $table The table to select from. @param array $conditions optional array $fieldname=>requestedvalue with AND in between @param string $fields A comma separated list of fields to be returned from the chosen table. @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means we will throw an exception if no record or multiple records found. @todo MDL-30407 MUST_EXIST option should not throw a dml_exception, it should throw a different exception as it's a requested check. @return mixed a fieldset object containing the first matching record, false or exception if error not found depending on mode @throws dml_exception A DML specific exception is thrown for any errors.
[ "Get", "a", "single", "database", "record", "as", "an", "object", "where", "all", "the", "given", "conditions", "met", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1520-L1523
213,018
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_record_select
public function get_record_select($table, $select, array $params=null, $fields='*', $strictness=IGNORE_MISSING) { if ($select) { $select = "WHERE $select"; } try { return $this->get_record_sql("SELECT $fields FROM {" . $table . "} $select", $params, $strictness); } catch (dml_missing_record_exception $e) { // create new exception which will contain correct table name throw new dml_missing_record_exception($table, $e->sql, $e->params); } }
php
public function get_record_select($table, $select, array $params=null, $fields='*', $strictness=IGNORE_MISSING) { if ($select) { $select = "WHERE $select"; } try { return $this->get_record_sql("SELECT $fields FROM {" . $table . "} $select", $params, $strictness); } catch (dml_missing_record_exception $e) { // create new exception which will contain correct table name throw new dml_missing_record_exception($table, $e->sql, $e->params); } }
[ "public", "function", "get_record_select", "(", "$", "table", ",", "$", "select", ",", "array", "$", "params", "=", "null", ",", "$", "fields", "=", "'*'", ",", "$", "strictness", "=", "IGNORE_MISSING", ")", "{", "if", "(", "$", "select", ")", "{", "$", "select", "=", "\"WHERE $select\"", ";", "}", "try", "{", "return", "$", "this", "->", "get_record_sql", "(", "\"SELECT $fields FROM {\"", ".", "$", "table", ".", "\"} $select\"", ",", "$", "params", ",", "$", "strictness", ")", ";", "}", "catch", "(", "dml_missing_record_exception", "$", "e", ")", "{", "// create new exception which will contain correct table name", "throw", "new", "dml_missing_record_exception", "(", "$", "table", ",", "$", "e", "->", "sql", ",", "$", "e", "->", "params", ")", ";", "}", "}" ]
Get a single database record as an object which match a particular WHERE clause. @param string $table The database table to be checked against. @param string $select A fragment of SQL to be used in a where clause in the SQL call. @param array $params array of sql parameters @param string $fields A comma separated list of fields to be returned from the chosen table. @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found @return stdClass|false a fieldset object containing the first matching record, false or exception if error not found depending on mode @throws dml_exception A DML specific exception is thrown for any errors.
[ "Get", "a", "single", "database", "record", "as", "an", "object", "which", "match", "a", "particular", "WHERE", "clause", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1538-L1548
213,019
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_field
public function get_field($table, $return, array $conditions, $strictness=IGNORE_MISSING) { list($select, $params) = $this->where_clause($table, $conditions); return $this->get_field_select($table, $return, $select, $params, $strictness); }
php
public function get_field($table, $return, array $conditions, $strictness=IGNORE_MISSING) { list($select, $params) = $this->where_clause($table, $conditions); return $this->get_field_select($table, $return, $select, $params, $strictness); }
[ "public", "function", "get_field", "(", "$", "table", ",", "$", "return", ",", "array", "$", "conditions", ",", "$", "strictness", "=", "IGNORE_MISSING", ")", "{", "list", "(", "$", "select", ",", "$", "params", ")", "=", "$", "this", "->", "where_clause", "(", "$", "table", ",", "$", "conditions", ")", ";", "return", "$", "this", "->", "get_field_select", "(", "$", "table", ",", "$", "return", ",", "$", "select", ",", "$", "params", ",", "$", "strictness", ")", ";", "}" ]
Get a single field value from a table record where all the given conditions met. @param string $table the table to query. @param string $return the field to return the value of. @param array $conditions optional array $fieldname=>requestedvalue with AND in between @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found @return mixed the specified value false if not found @throws dml_exception A DML specific exception is thrown for any errors.
[ "Get", "a", "single", "field", "value", "from", "a", "table", "record", "where", "all", "the", "given", "conditions", "met", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1602-L1605
213,020
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_field_select
public function get_field_select($table, $return, $select, array $params=null, $strictness=IGNORE_MISSING) { if ($select) { $select = "WHERE $select"; } try { return $this->get_field_sql("SELECT $return FROM {" . $table . "} $select", $params, $strictness); } catch (dml_missing_record_exception $e) { // create new exception which will contain correct table name throw new dml_missing_record_exception($table, $e->sql, $e->params); } }
php
public function get_field_select($table, $return, $select, array $params=null, $strictness=IGNORE_MISSING) { if ($select) { $select = "WHERE $select"; } try { return $this->get_field_sql("SELECT $return FROM {" . $table . "} $select", $params, $strictness); } catch (dml_missing_record_exception $e) { // create new exception which will contain correct table name throw new dml_missing_record_exception($table, $e->sql, $e->params); } }
[ "public", "function", "get_field_select", "(", "$", "table", ",", "$", "return", ",", "$", "select", ",", "array", "$", "params", "=", "null", ",", "$", "strictness", "=", "IGNORE_MISSING", ")", "{", "if", "(", "$", "select", ")", "{", "$", "select", "=", "\"WHERE $select\"", ";", "}", "try", "{", "return", "$", "this", "->", "get_field_sql", "(", "\"SELECT $return FROM {\"", ".", "$", "table", ".", "\"} $select\"", ",", "$", "params", ",", "$", "strictness", ")", ";", "}", "catch", "(", "dml_missing_record_exception", "$", "e", ")", "{", "// create new exception which will contain correct table name", "throw", "new", "dml_missing_record_exception", "(", "$", "table", ",", "$", "e", "->", "sql", ",", "$", "e", "->", "params", ")", ";", "}", "}" ]
Get a single field value from a table record which match a particular WHERE clause. @param string $table the table to query. @param string $return the field to return the value of. @param string $select A fragment of SQL to be used in a where clause returning one row with one column @param array $params array of sql parameters @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found @return mixed the specified value false if not found @throws dml_exception A DML specific exception is thrown for any errors.
[ "Get", "a", "single", "field", "value", "from", "a", "table", "record", "which", "match", "a", "particular", "WHERE", "clause", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1620-L1630
213,021
moodle/moodle
lib/dml/moodle_database.php
moodle_database.get_fieldset_select
public function get_fieldset_select($table, $return, $select, array $params=null) { if ($select) { $select = "WHERE $select"; } return $this->get_fieldset_sql("SELECT $return FROM {" . $table . "} $select", $params); }
php
public function get_fieldset_select($table, $return, $select, array $params=null) { if ($select) { $select = "WHERE $select"; } return $this->get_fieldset_sql("SELECT $return FROM {" . $table . "} $select", $params); }
[ "public", "function", "get_fieldset_select", "(", "$", "table", ",", "$", "return", ",", "$", "select", ",", "array", "$", "params", "=", "null", ")", "{", "if", "(", "$", "select", ")", "{", "$", "select", "=", "\"WHERE $select\"", ";", "}", "return", "$", "this", "->", "get_fieldset_sql", "(", "\"SELECT $return FROM {\"", ".", "$", "table", ".", "\"} $select\"", ",", "$", "params", ")", ";", "}" ]
Selects records and return values of chosen field as an array which match a particular WHERE clause. @param string $table the table to query. @param string $return the field we are intered in @param string $select A fragment of SQL to be used in a where clause in the SQL call. @param array $params array of sql parameters @return array of values @throws dml_exception A DML specific exception is thrown for any errors.
[ "Selects", "records", "and", "return", "values", "of", "chosen", "field", "as", "an", "array", "which", "match", "a", "particular", "WHERE", "clause", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1662-L1667
213,022
moodle/moodle
lib/dml/moodle_database.php
moodle_database.set_field
public function set_field($table, $newfield, $newvalue, array $conditions=null) { list($select, $params) = $this->where_clause($table, $conditions); return $this->set_field_select($table, $newfield, $newvalue, $select, $params); }
php
public function set_field($table, $newfield, $newvalue, array $conditions=null) { list($select, $params) = $this->where_clause($table, $conditions); return $this->set_field_select($table, $newfield, $newvalue, $select, $params); }
[ "public", "function", "set_field", "(", "$", "table", ",", "$", "newfield", ",", "$", "newvalue", ",", "array", "$", "conditions", "=", "null", ")", "{", "list", "(", "$", "select", ",", "$", "params", ")", "=", "$", "this", "->", "where_clause", "(", "$", "table", ",", "$", "conditions", ")", ";", "return", "$", "this", "->", "set_field_select", "(", "$", "table", ",", "$", "newfield", ",", "$", "newvalue", ",", "$", "select", ",", "$", "params", ")", ";", "}" ]
Set a single field in every table record where all the given conditions met. @param string $table The database table to be checked against. @param string $newfield the field to set. @param string $newvalue the value to set the field to. @param array $conditions optional array $fieldname=>requestedvalue with AND in between @return bool true @throws dml_exception A DML specific exception is thrown for any errors.
[ "Set", "a", "single", "field", "in", "every", "table", "record", "where", "all", "the", "given", "conditions", "met", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1791-L1794
213,023
moodle/moodle
lib/dml/moodle_database.php
moodle_database.count_records
public function count_records($table, array $conditions=null) { list($select, $params) = $this->where_clause($table, $conditions); return $this->count_records_select($table, $select, $params); }
php
public function count_records($table, array $conditions=null) { list($select, $params) = $this->where_clause($table, $conditions); return $this->count_records_select($table, $select, $params); }
[ "public", "function", "count_records", "(", "$", "table", ",", "array", "$", "conditions", "=", "null", ")", "{", "list", "(", "$", "select", ",", "$", "params", ")", "=", "$", "this", "->", "where_clause", "(", "$", "table", ",", "$", "conditions", ")", ";", "return", "$", "this", "->", "count_records_select", "(", "$", "table", ",", "$", "select", ",", "$", "params", ")", ";", "}" ]
Count the records in a table where all the given conditions met. @param string $table The table to query. @param array $conditions optional array $fieldname=>requestedvalue with AND in between @return int The count of records returned from the specified criteria. @throws dml_exception A DML specific exception is thrown for any errors.
[ "Count", "the", "records", "in", "a", "table", "where", "all", "the", "given", "conditions", "met", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1818-L1821
213,024
moodle/moodle
lib/dml/moodle_database.php
moodle_database.count_records_select
public function count_records_select($table, $select, array $params=null, $countitem="COUNT('x')") { if ($select) { $select = "WHERE $select"; } return $this->count_records_sql("SELECT $countitem FROM {" . $table . "} $select", $params); }
php
public function count_records_select($table, $select, array $params=null, $countitem="COUNT('x')") { if ($select) { $select = "WHERE $select"; } return $this->count_records_sql("SELECT $countitem FROM {" . $table . "} $select", $params); }
[ "public", "function", "count_records_select", "(", "$", "table", ",", "$", "select", ",", "array", "$", "params", "=", "null", ",", "$", "countitem", "=", "\"COUNT('x')\"", ")", "{", "if", "(", "$", "select", ")", "{", "$", "select", "=", "\"WHERE $select\"", ";", "}", "return", "$", "this", "->", "count_records_sql", "(", "\"SELECT $countitem FROM {\"", ".", "$", "table", ".", "\"} $select\"", ",", "$", "params", ")", ";", "}" ]
Count the records in a table which match a particular WHERE clause. @param string $table The database table to be checked against. @param string $select A fragment of SQL to be used in a WHERE clause in the SQL call. @param array $params array of sql parameters @param string $countitem The count string to be used in the SQL call. Default is COUNT('x'). @return int The count of records returned from the specified criteria. @throws dml_exception A DML specific exception is thrown for any errors.
[ "Count", "the", "records", "in", "a", "table", "which", "match", "a", "particular", "WHERE", "clause", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1833-L1838
213,025
moodle/moodle
lib/dml/moodle_database.php
moodle_database.record_exists
public function record_exists($table, array $conditions) { list($select, $params) = $this->where_clause($table, $conditions); return $this->record_exists_select($table, $select, $params); }
php
public function record_exists($table, array $conditions) { list($select, $params) = $this->where_clause($table, $conditions); return $this->record_exists_select($table, $select, $params); }
[ "public", "function", "record_exists", "(", "$", "table", ",", "array", "$", "conditions", ")", "{", "list", "(", "$", "select", ",", "$", "params", ")", "=", "$", "this", "->", "where_clause", "(", "$", "table", ",", "$", "conditions", ")", ";", "return", "$", "this", "->", "record_exists_select", "(", "$", "table", ",", "$", "select", ",", "$", "params", ")", ";", "}" ]
Test whether a record exists in a table where all the given conditions met. @param string $table The table to check. @param array $conditions optional array $fieldname=>requestedvalue with AND in between @return bool true if a matching record exists, else false. @throws dml_exception A DML specific exception is thrown for any errors.
[ "Test", "whether", "a", "record", "exists", "in", "a", "table", "where", "all", "the", "given", "conditions", "met", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1869-L1872
213,026
moodle/moodle
lib/dml/moodle_database.php
moodle_database.record_exists_select
public function record_exists_select($table, $select, array $params=null) { if ($select) { $select = "WHERE $select"; } return $this->record_exists_sql("SELECT 'x' FROM {" . $table . "} $select", $params); }
php
public function record_exists_select($table, $select, array $params=null) { if ($select) { $select = "WHERE $select"; } return $this->record_exists_sql("SELECT 'x' FROM {" . $table . "} $select", $params); }
[ "public", "function", "record_exists_select", "(", "$", "table", ",", "$", "select", ",", "array", "$", "params", "=", "null", ")", "{", "if", "(", "$", "select", ")", "{", "$", "select", "=", "\"WHERE $select\"", ";", "}", "return", "$", "this", "->", "record_exists_sql", "(", "\"SELECT 'x' FROM {\"", ".", "$", "table", ".", "\"} $select\"", ",", "$", "params", ")", ";", "}" ]
Test whether any records exists in a table which match a particular WHERE clause. @param string $table The database table to be checked against. @param string $select A fragment of SQL to be used in a WHERE clause in the SQL call. @param array $params array of sql parameters @return bool true if a matching record exists, else false. @throws dml_exception A DML specific exception is thrown for any errors.
[ "Test", "whether", "any", "records", "exists", "in", "a", "table", "which", "match", "a", "particular", "WHERE", "clause", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1883-L1888
213,027
moodle/moodle
lib/dml/moodle_database.php
moodle_database.record_exists_sql
public function record_exists_sql($sql, array $params=null) { $mrs = $this->get_recordset_sql($sql, $params, 0, 1); $return = $mrs->valid(); $mrs->close(); return $return; }
php
public function record_exists_sql($sql, array $params=null) { $mrs = $this->get_recordset_sql($sql, $params, 0, 1); $return = $mrs->valid(); $mrs->close(); return $return; }
[ "public", "function", "record_exists_sql", "(", "$", "sql", ",", "array", "$", "params", "=", "null", ")", "{", "$", "mrs", "=", "$", "this", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ",", "0", ",", "1", ")", ";", "$", "return", "=", "$", "mrs", "->", "valid", "(", ")", ";", "$", "mrs", "->", "close", "(", ")", ";", "return", "$", "return", ";", "}" ]
Test whether a SQL SELECT statement returns any records. This function returns true if the SQL statement executes without any errors and returns at least one record. @param string $sql The SQL statement to execute. @param array $params array of sql parameters @return bool true if the SQL executes without errors and returns at least one record. @throws dml_exception A DML specific exception is thrown for any errors.
[ "Test", "whether", "a", "SQL", "SELECT", "statement", "returns", "any", "records", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1901-L1906
213,028
moodle/moodle
lib/dml/moodle_database.php
moodle_database.delete_records
public function delete_records($table, array $conditions=null) { // truncate is drop/create (DDL), not transactional safe, // so we don't use the shortcut within them. MDL-29198 if (is_null($conditions) && empty($this->transactions)) { return $this->execute("TRUNCATE TABLE {".$table."}"); } list($select, $params) = $this->where_clause($table, $conditions); return $this->delete_records_select($table, $select, $params); }
php
public function delete_records($table, array $conditions=null) { // truncate is drop/create (DDL), not transactional safe, // so we don't use the shortcut within them. MDL-29198 if (is_null($conditions) && empty($this->transactions)) { return $this->execute("TRUNCATE TABLE {".$table."}"); } list($select, $params) = $this->where_clause($table, $conditions); return $this->delete_records_select($table, $select, $params); }
[ "public", "function", "delete_records", "(", "$", "table", ",", "array", "$", "conditions", "=", "null", ")", "{", "// truncate is drop/create (DDL), not transactional safe,", "// so we don't use the shortcut within them. MDL-29198", "if", "(", "is_null", "(", "$", "conditions", ")", "&&", "empty", "(", "$", "this", "->", "transactions", ")", ")", "{", "return", "$", "this", "->", "execute", "(", "\"TRUNCATE TABLE {\"", ".", "$", "table", ".", "\"}\"", ")", ";", "}", "list", "(", "$", "select", ",", "$", "params", ")", "=", "$", "this", "->", "where_clause", "(", "$", "table", ",", "$", "conditions", ")", ";", "return", "$", "this", "->", "delete_records_select", "(", "$", "table", ",", "$", "select", ",", "$", "params", ")", ";", "}" ]
Delete the records from a table where all the given conditions met. If conditions not specified, table is truncated. @param string $table the table to delete from. @param array $conditions optional array $fieldname=>requestedvalue with AND in between @return bool true. @throws dml_exception A DML specific exception is thrown for any errors.
[ "Delete", "the", "records", "from", "a", "table", "where", "all", "the", "given", "conditions", "met", ".", "If", "conditions", "not", "specified", "table", "is", "truncated", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1917-L1925
213,029
moodle/moodle
lib/dml/moodle_database.php
moodle_database.delete_records_list
public function delete_records_list($table, $field, array $values) { list($select, $params) = $this->where_clause_list($field, $values); return $this->delete_records_select($table, $select, $params); }
php
public function delete_records_list($table, $field, array $values) { list($select, $params) = $this->where_clause_list($field, $values); return $this->delete_records_select($table, $select, $params); }
[ "public", "function", "delete_records_list", "(", "$", "table", ",", "$", "field", ",", "array", "$", "values", ")", "{", "list", "(", "$", "select", ",", "$", "params", ")", "=", "$", "this", "->", "where_clause_list", "(", "$", "field", ",", "$", "values", ")", ";", "return", "$", "this", "->", "delete_records_select", "(", "$", "table", ",", "$", "select", ",", "$", "params", ")", ";", "}" ]
Delete the records from a table where one field match one list of values. @param string $table the table to delete from. @param string $field The field to search @param array $values array of values @return bool true. @throws dml_exception A DML specific exception is thrown for any errors.
[ "Delete", "the", "records", "from", "a", "table", "where", "one", "field", "match", "one", "list", "of", "values", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L1936-L1939
213,030
moodle/moodle
lib/dml/moodle_database.php
moodle_database.sql_like_escape
public function sql_like_escape($text, $escapechar = '\\') { $text = str_replace('_', $escapechar.'_', $text); $text = str_replace('%', $escapechar.'%', $text); return $text; }
php
public function sql_like_escape($text, $escapechar = '\\') { $text = str_replace('_', $escapechar.'_', $text); $text = str_replace('%', $escapechar.'%', $text); return $text; }
[ "public", "function", "sql_like_escape", "(", "$", "text", ",", "$", "escapechar", "=", "'\\\\'", ")", "{", "$", "text", "=", "str_replace", "(", "'_'", ",", "$", "escapechar", ".", "'_'", ",", "$", "text", ")", ";", "$", "text", "=", "str_replace", "(", "'%'", ",", "$", "escapechar", ".", "'%'", ",", "$", "text", ")", ";", "return", "$", "text", ";", "}" ]
Escape sql LIKE special characters like '_' or '%'. @param string $text The string containing characters needing escaping. @param string $escapechar The desired escape character, defaults to '\\'. @return string The escaped sql LIKE string.
[ "Escape", "sql", "LIKE", "special", "characters", "like", "_", "or", "%", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L2150-L2154
213,031
moodle/moodle
lib/dml/moodle_database.php
moodle_database.sql_isnotempty
public function sql_isnotempty($tablename, $fieldname, $nullablefield, $textfield) { return ' ( NOT ' . $this->sql_isempty($tablename, $fieldname, $nullablefield, $textfield) . ') '; }
php
public function sql_isnotempty($tablename, $fieldname, $nullablefield, $textfield) { return ' ( NOT ' . $this->sql_isempty($tablename, $fieldname, $nullablefield, $textfield) . ') '; }
[ "public", "function", "sql_isnotempty", "(", "$", "tablename", ",", "$", "fieldname", ",", "$", "nullablefield", ",", "$", "textfield", ")", "{", "return", "' ( NOT '", ".", "$", "this", "->", "sql_isempty", "(", "$", "tablename", ",", "$", "fieldname", ",", "$", "nullablefield", ",", "$", "textfield", ")", ".", "') '", ";", "}" ]
Returns the proper SQL to know if one field is not empty. Note that the function behavior strongly relies on the parameters passed describing the field so, please, be accurate when specifying them. This function should be applied in all the places where conditions of the type: ... AND fieldname != ''; are being used. Final result for text fields should be: ... AND ' . sql_isnotempty('tablename', 'fieldname', true/false, true/false); and for varchar fields result should be: ... AND fieldname != :empty; "; $params['empty'] = ''; (see parameters description below) @param string $tablename Name of the table (without prefix). This is not used for now but can be necessary in the future if we want to use some introspection using meta information against the DB. @param string $fieldname The name of the field we are going to check. @param bool $nullablefield Specifies if the field is nullable (true) or not (false) in the DB. @param bool $textfield Specifies if it is a text (also called clob) field (true) or a varchar one (false). @return string The sql code to be added to check for non empty values.
[ "Returns", "the", "proper", "SQL", "to", "know", "if", "one", "field", "is", "not", "empty", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L2329-L2331
213,032
moodle/moodle
lib/dml/moodle_database.php
moodle_database.replace_all_text
public function replace_all_text($table, database_column_info $column, $search, $replace) { if (!$this->replace_all_text_supported()) { return; } // NOTE: override this methods if following standard compliant SQL // does not work for your driver. // Enclose the column name by the proper quotes if it's a reserved word. $columnname = $this->get_manager()->generator->getEncQuoted($column->name); $searchsql = $this->sql_like($columnname, '?'); $searchparam = '%'.$this->sql_like_escape($search).'%'; $sql = "UPDATE {".$table."} SET $columnname = REPLACE($columnname, ?, ?) WHERE $searchsql"; if ($column->meta_type === 'X') { $this->execute($sql, array($search, $replace, $searchparam)); } else if ($column->meta_type === 'C') { if (core_text::strlen($search) < core_text::strlen($replace)) { $colsize = $column->max_length; $sql = "UPDATE {".$table."} SET $columnname = " . $this->sql_substr("REPLACE(" . $columnname . ", ?, ?)", 1, $colsize) . " WHERE $searchsql"; } $this->execute($sql, array($search, $replace, $searchparam)); } }
php
public function replace_all_text($table, database_column_info $column, $search, $replace) { if (!$this->replace_all_text_supported()) { return; } // NOTE: override this methods if following standard compliant SQL // does not work for your driver. // Enclose the column name by the proper quotes if it's a reserved word. $columnname = $this->get_manager()->generator->getEncQuoted($column->name); $searchsql = $this->sql_like($columnname, '?'); $searchparam = '%'.$this->sql_like_escape($search).'%'; $sql = "UPDATE {".$table."} SET $columnname = REPLACE($columnname, ?, ?) WHERE $searchsql"; if ($column->meta_type === 'X') { $this->execute($sql, array($search, $replace, $searchparam)); } else if ($column->meta_type === 'C') { if (core_text::strlen($search) < core_text::strlen($replace)) { $colsize = $column->max_length; $sql = "UPDATE {".$table."} SET $columnname = " . $this->sql_substr("REPLACE(" . $columnname . ", ?, ?)", 1, $colsize) . " WHERE $searchsql"; } $this->execute($sql, array($search, $replace, $searchparam)); } }
[ "public", "function", "replace_all_text", "(", "$", "table", ",", "database_column_info", "$", "column", ",", "$", "search", ",", "$", "replace", ")", "{", "if", "(", "!", "$", "this", "->", "replace_all_text_supported", "(", ")", ")", "{", "return", ";", "}", "// NOTE: override this methods if following standard compliant SQL", "// does not work for your driver.", "// Enclose the column name by the proper quotes if it's a reserved word.", "$", "columnname", "=", "$", "this", "->", "get_manager", "(", ")", "->", "generator", "->", "getEncQuoted", "(", "$", "column", "->", "name", ")", ";", "$", "searchsql", "=", "$", "this", "->", "sql_like", "(", "$", "columnname", ",", "'?'", ")", ";", "$", "searchparam", "=", "'%'", ".", "$", "this", "->", "sql_like_escape", "(", "$", "search", ")", ".", "'%'", ";", "$", "sql", "=", "\"UPDATE {\"", ".", "$", "table", ".", "\"}\n SET $columnname = REPLACE($columnname, ?, ?)\n WHERE $searchsql\"", ";", "if", "(", "$", "column", "->", "meta_type", "===", "'X'", ")", "{", "$", "this", "->", "execute", "(", "$", "sql", ",", "array", "(", "$", "search", ",", "$", "replace", ",", "$", "searchparam", ")", ")", ";", "}", "else", "if", "(", "$", "column", "->", "meta_type", "===", "'C'", ")", "{", "if", "(", "core_text", "::", "strlen", "(", "$", "search", ")", "<", "core_text", "::", "strlen", "(", "$", "replace", ")", ")", "{", "$", "colsize", "=", "$", "column", "->", "max_length", ";", "$", "sql", "=", "\"UPDATE {\"", ".", "$", "table", ".", "\"}\n SET $columnname = \"", ".", "$", "this", "->", "sql_substr", "(", "\"REPLACE(\"", ".", "$", "columnname", ".", "\", ?, ?)\"", ",", "1", ",", "$", "colsize", ")", ".", "\"\n WHERE $searchsql\"", ";", "}", "$", "this", "->", "execute", "(", "$", "sql", ",", "array", "(", "$", "search", ",", "$", "replace", ",", "$", "searchparam", ")", ")", ";", "}", "}" ]
Replace given text in all rows of column. @since Moodle 2.6.1 @param string $table name of the table @param database_column_info $column @param string $search @param string $replace
[ "Replace", "given", "text", "in", "all", "rows", "of", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L2395-L2425
213,033
moodle/moodle
lib/dml/moodle_database.php
moodle_database.commit_delegated_transaction
public function commit_delegated_transaction(moodle_transaction $transaction) { if ($transaction->is_disposed()) { throw new dml_transaction_exception('Transactions already disposed', $transaction); } // mark as disposed so that it can not be used again $transaction->dispose(); if (empty($this->transactions)) { throw new dml_transaction_exception('Transaction not started', $transaction); } if ($this->force_rollback) { throw new dml_transaction_exception('Tried to commit transaction after lower level rollback', $transaction); } if ($transaction !== $this->transactions[count($this->transactions) - 1]) { // one incorrect commit at any level rollbacks everything $this->force_rollback = true; throw new dml_transaction_exception('Invalid transaction commit attempt', $transaction); } if (count($this->transactions) == 1) { // only commit the top most level $this->commit_transaction(); } array_pop($this->transactions); if (empty($this->transactions)) { \core\event\manager::database_transaction_commited(); \core\message\manager::database_transaction_commited(); } }
php
public function commit_delegated_transaction(moodle_transaction $transaction) { if ($transaction->is_disposed()) { throw new dml_transaction_exception('Transactions already disposed', $transaction); } // mark as disposed so that it can not be used again $transaction->dispose(); if (empty($this->transactions)) { throw new dml_transaction_exception('Transaction not started', $transaction); } if ($this->force_rollback) { throw new dml_transaction_exception('Tried to commit transaction after lower level rollback', $transaction); } if ($transaction !== $this->transactions[count($this->transactions) - 1]) { // one incorrect commit at any level rollbacks everything $this->force_rollback = true; throw new dml_transaction_exception('Invalid transaction commit attempt', $transaction); } if (count($this->transactions) == 1) { // only commit the top most level $this->commit_transaction(); } array_pop($this->transactions); if (empty($this->transactions)) { \core\event\manager::database_transaction_commited(); \core\message\manager::database_transaction_commited(); } }
[ "public", "function", "commit_delegated_transaction", "(", "moodle_transaction", "$", "transaction", ")", "{", "if", "(", "$", "transaction", "->", "is_disposed", "(", ")", ")", "{", "throw", "new", "dml_transaction_exception", "(", "'Transactions already disposed'", ",", "$", "transaction", ")", ";", "}", "// mark as disposed so that it can not be used again", "$", "transaction", "->", "dispose", "(", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "transactions", ")", ")", "{", "throw", "new", "dml_transaction_exception", "(", "'Transaction not started'", ",", "$", "transaction", ")", ";", "}", "if", "(", "$", "this", "->", "force_rollback", ")", "{", "throw", "new", "dml_transaction_exception", "(", "'Tried to commit transaction after lower level rollback'", ",", "$", "transaction", ")", ";", "}", "if", "(", "$", "transaction", "!==", "$", "this", "->", "transactions", "[", "count", "(", "$", "this", "->", "transactions", ")", "-", "1", "]", ")", "{", "// one incorrect commit at any level rollbacks everything", "$", "this", "->", "force_rollback", "=", "true", ";", "throw", "new", "dml_transaction_exception", "(", "'Invalid transaction commit attempt'", ",", "$", "transaction", ")", ";", "}", "if", "(", "count", "(", "$", "this", "->", "transactions", ")", "==", "1", ")", "{", "// only commit the top most level", "$", "this", "->", "commit_transaction", "(", ")", ";", "}", "array_pop", "(", "$", "this", "->", "transactions", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "transactions", ")", ")", "{", "\\", "core", "\\", "event", "\\", "manager", "::", "database_transaction_commited", "(", ")", ";", "\\", "core", "\\", "message", "\\", "manager", "::", "database_transaction_commited", "(", ")", ";", "}", "}" ]
Indicates delegated transaction finished successfully. The real database transaction is committed only if all delegated transactions committed. @param moodle_transaction $transaction The transaction to commit @return void @throws dml_transaction_exception Creates and throws transaction related exceptions.
[ "Indicates", "delegated", "transaction", "finished", "successfully", ".", "The", "real", "database", "transaction", "is", "committed", "only", "if", "all", "delegated", "transactions", "committed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L2512-L2543
213,034
moodle/moodle
lib/dml/moodle_database.php
moodle_database.rollback_delegated_transaction
public function rollback_delegated_transaction(moodle_transaction $transaction, $e) { if (!($e instanceof Exception) && !($e instanceof Throwable)) { // PHP7 - we catch Throwables in phpunit but can't use that as the type hint in PHP5. $e = new \coding_exception("Must be given an Exception or Throwable object!"); } if ($transaction->is_disposed()) { throw new dml_transaction_exception('Transactions already disposed', $transaction); } // mark as disposed so that it can not be used again $transaction->dispose(); // one rollback at any level rollbacks everything $this->force_rollback = true; if (empty($this->transactions) or $transaction !== $this->transactions[count($this->transactions) - 1]) { // this may or may not be a coding problem, better just rethrow the exception, // because we do not want to loose the original $e throw $e; } if (count($this->transactions) == 1) { // only rollback the top most level $this->rollback_transaction(); } array_pop($this->transactions); if (empty($this->transactions)) { // finally top most level rolled back $this->force_rollback = false; \core\event\manager::database_transaction_rolledback(); \core\message\manager::database_transaction_rolledback(); } throw $e; }
php
public function rollback_delegated_transaction(moodle_transaction $transaction, $e) { if (!($e instanceof Exception) && !($e instanceof Throwable)) { // PHP7 - we catch Throwables in phpunit but can't use that as the type hint in PHP5. $e = new \coding_exception("Must be given an Exception or Throwable object!"); } if ($transaction->is_disposed()) { throw new dml_transaction_exception('Transactions already disposed', $transaction); } // mark as disposed so that it can not be used again $transaction->dispose(); // one rollback at any level rollbacks everything $this->force_rollback = true; if (empty($this->transactions) or $transaction !== $this->transactions[count($this->transactions) - 1]) { // this may or may not be a coding problem, better just rethrow the exception, // because we do not want to loose the original $e throw $e; } if (count($this->transactions) == 1) { // only rollback the top most level $this->rollback_transaction(); } array_pop($this->transactions); if (empty($this->transactions)) { // finally top most level rolled back $this->force_rollback = false; \core\event\manager::database_transaction_rolledback(); \core\message\manager::database_transaction_rolledback(); } throw $e; }
[ "public", "function", "rollback_delegated_transaction", "(", "moodle_transaction", "$", "transaction", ",", "$", "e", ")", "{", "if", "(", "!", "(", "$", "e", "instanceof", "Exception", ")", "&&", "!", "(", "$", "e", "instanceof", "Throwable", ")", ")", "{", "// PHP7 - we catch Throwables in phpunit but can't use that as the type hint in PHP5.", "$", "e", "=", "new", "\\", "coding_exception", "(", "\"Must be given an Exception or Throwable object!\"", ")", ";", "}", "if", "(", "$", "transaction", "->", "is_disposed", "(", ")", ")", "{", "throw", "new", "dml_transaction_exception", "(", "'Transactions already disposed'", ",", "$", "transaction", ")", ";", "}", "// mark as disposed so that it can not be used again", "$", "transaction", "->", "dispose", "(", ")", ";", "// one rollback at any level rollbacks everything", "$", "this", "->", "force_rollback", "=", "true", ";", "if", "(", "empty", "(", "$", "this", "->", "transactions", ")", "or", "$", "transaction", "!==", "$", "this", "->", "transactions", "[", "count", "(", "$", "this", "->", "transactions", ")", "-", "1", "]", ")", "{", "// this may or may not be a coding problem, better just rethrow the exception,", "// because we do not want to loose the original $e", "throw", "$", "e", ";", "}", "if", "(", "count", "(", "$", "this", "->", "transactions", ")", "==", "1", ")", "{", "// only rollback the top most level", "$", "this", "->", "rollback_transaction", "(", ")", ";", "}", "array_pop", "(", "$", "this", "->", "transactions", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "transactions", ")", ")", "{", "// finally top most level rolled back", "$", "this", "->", "force_rollback", "=", "false", ";", "\\", "core", "\\", "event", "\\", "manager", "::", "database_transaction_rolledback", "(", ")", ";", "\\", "core", "\\", "message", "\\", "manager", "::", "database_transaction_rolledback", "(", ")", ";", "}", "throw", "$", "e", ";", "}" ]
Call when delegated transaction failed, this rolls back all delegated transactions up to the top most level. In many cases you do not need to call this method manually, because all open delegated transactions are rolled back automatically if exceptions not caught. @param moodle_transaction $transaction An instance of a moodle_transaction. @param Exception|Throwable $e The related exception/throwable to this transaction rollback. @return void This does not return, instead the exception passed in will be rethrown.
[ "Call", "when", "delegated", "transaction", "failed", "this", "rolls", "back", "all", "delegated", "transactions", "up", "to", "the", "top", "most", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L2564-L2596
213,035
moodle/moodle
lib/dml/moodle_database.php
moodle_database.force_transaction_rollback
public function force_transaction_rollback() { if ($this->transactions) { try { $this->rollback_transaction(); } catch (dml_exception $e) { // ignore any sql errors here, the connection might be broken } } // now enable transactions again $this->transactions = array(); $this->force_rollback = false; \core\event\manager::database_transaction_rolledback(); \core\message\manager::database_transaction_rolledback(); }
php
public function force_transaction_rollback() { if ($this->transactions) { try { $this->rollback_transaction(); } catch (dml_exception $e) { // ignore any sql errors here, the connection might be broken } } // now enable transactions again $this->transactions = array(); $this->force_rollback = false; \core\event\manager::database_transaction_rolledback(); \core\message\manager::database_transaction_rolledback(); }
[ "public", "function", "force_transaction_rollback", "(", ")", "{", "if", "(", "$", "this", "->", "transactions", ")", "{", "try", "{", "$", "this", "->", "rollback_transaction", "(", ")", ";", "}", "catch", "(", "dml_exception", "$", "e", ")", "{", "// ignore any sql errors here, the connection might be broken", "}", "}", "// now enable transactions again", "$", "this", "->", "transactions", "=", "array", "(", ")", ";", "$", "this", "->", "force_rollback", "=", "false", ";", "\\", "core", "\\", "event", "\\", "manager", "::", "database_transaction_rolledback", "(", ")", ";", "\\", "core", "\\", "message", "\\", "manager", "::", "database_transaction_rolledback", "(", ")", ";", "}" ]
Force rollback of all delegated transaction. Does not throw any exceptions and does not log anything. This method should be used only from default exception handlers and other core code. @return void
[ "Force", "rollback", "of", "all", "delegated", "transaction", ".", "Does", "not", "throw", "any", "exceptions", "and", "does", "not", "log", "anything", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/moodle_database.php#L2614-L2629
213,036
moodle/moodle
mod/data/classes/search/sortedcontentqueue.php
sortedcontentqueue.compare
public function compare($key1 , $key2) { $record1 = $this->contents[$key1]; $record2 = $this->contents[$key2]; // If a content's fieldtype is compulsory in the database than it would have priority than any other noncompulsory content. if ( ($record1->required && $record2->required) || (!$record1->required && !$record2->required)) { if ($record1->priority === $record2->priority) { return $key1 < $key2 ? 1 : -1; } return $record1->priority < $record2->priority ? -1 : 1; } else if ($record1->required && !$record2->required) { return 1; } else { return -1; } }
php
public function compare($key1 , $key2) { $record1 = $this->contents[$key1]; $record2 = $this->contents[$key2]; // If a content's fieldtype is compulsory in the database than it would have priority than any other noncompulsory content. if ( ($record1->required && $record2->required) || (!$record1->required && !$record2->required)) { if ($record1->priority === $record2->priority) { return $key1 < $key2 ? 1 : -1; } return $record1->priority < $record2->priority ? -1 : 1; } else if ($record1->required && !$record2->required) { return 1; } else { return -1; } }
[ "public", "function", "compare", "(", "$", "key1", ",", "$", "key2", ")", "{", "$", "record1", "=", "$", "this", "->", "contents", "[", "$", "key1", "]", ";", "$", "record2", "=", "$", "this", "->", "contents", "[", "$", "key2", "]", ";", "// If a content's fieldtype is compulsory in the database than it would have priority than any other noncompulsory content.", "if", "(", "(", "$", "record1", "->", "required", "&&", "$", "record2", "->", "required", ")", "||", "(", "!", "$", "record1", "->", "required", "&&", "!", "$", "record2", "->", "required", ")", ")", "{", "if", "(", "$", "record1", "->", "priority", "===", "$", "record2", "->", "priority", ")", "{", "return", "$", "key1", "<", "$", "key2", "?", "1", ":", "-", "1", ";", "}", "return", "$", "record1", "->", "priority", "<", "$", "record2", "->", "priority", "?", "-", "1", ":", "1", ";", "}", "else", "if", "(", "$", "record1", "->", "required", "&&", "!", "$", "record2", "->", "required", ")", "{", "return", "1", ";", "}", "else", "{", "return", "-", "1", ";", "}", "}" ]
comparator function overriden for sorting the records ...as per 'required' and 'priotirity' field values @param int $key1 @param int $key2 @return bool
[ "comparator", "function", "overriden", "for", "sorting", "the", "records", "...", "as", "per", "required", "and", "priotirity", "field", "values" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/classes/search/sortedcontentqueue.php#L61-L79
213,037
moodle/moodle
backup/moodle2/backup_custom_fields.php
encrypted_final_element.set_key
protected function set_key($key) { $bytes = strlen($key); // Get key length in bytes. // Only accept keys with the expected (backup::CIPHERKEYLEN) key length. There are a number of hashing, // random generators to achieve this esasily, like the one shown below to create the default // site encryption key and ivs. if ($bytes !== backup::CIPHERKEYLEN) { $info = (object)array('expected' => backup::CIPHERKEYLEN, 'found' => $bytes); throw new base_element_struct_exception('encrypted_final_element incorrect key length', $info); } // Everything went ok, store the key. $this->key = $key; }
php
protected function set_key($key) { $bytes = strlen($key); // Get key length in bytes. // Only accept keys with the expected (backup::CIPHERKEYLEN) key length. There are a number of hashing, // random generators to achieve this esasily, like the one shown below to create the default // site encryption key and ivs. if ($bytes !== backup::CIPHERKEYLEN) { $info = (object)array('expected' => backup::CIPHERKEYLEN, 'found' => $bytes); throw new base_element_struct_exception('encrypted_final_element incorrect key length', $info); } // Everything went ok, store the key. $this->key = $key; }
[ "protected", "function", "set_key", "(", "$", "key", ")", "{", "$", "bytes", "=", "strlen", "(", "$", "key", ")", ";", "// Get key length in bytes.", "// Only accept keys with the expected (backup::CIPHERKEYLEN) key length. There are a number of hashing,", "// random generators to achieve this esasily, like the one shown below to create the default", "// site encryption key and ivs.", "if", "(", "$", "bytes", "!==", "backup", "::", "CIPHERKEYLEN", ")", "{", "$", "info", "=", "(", "object", ")", "array", "(", "'expected'", "=>", "backup", "::", "CIPHERKEYLEN", ",", "'found'", "=>", "$", "bytes", ")", ";", "throw", "new", "base_element_struct_exception", "(", "'encrypted_final_element incorrect key length'", ",", "$", "info", ")", ";", "}", "// Everything went ok, store the key.", "$", "this", "->", "key", "=", "$", "key", ";", "}" ]
Set the encryption key manually, overriding default backup_encryptkey config. @param string $key key to be used for encrypting. Required to be 256-bit key. Use a safe generation technique. See self::generate_encryption_random_key() below.
[ "Set", "the", "encryption", "key", "manually", "overriding", "default", "backup_encryptkey", "config", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_custom_fields.php#L145-L157
213,038
moodle/moodle
backup/moodle2/backup_custom_fields.php
encrypted_final_element.set_value
public function set_value($value) { // No openssl available, skip this field completely. if (!function_exists('openssl_encrypt')) { return; } // No hmac available, skip this field completely. if (!function_exists('hash_hmac')) { return; } // Cypher not available, skip this field completely. if (!in_array(backup::CIPHER, openssl_get_cipher_methods())) { return; } // Ensure we have a good key, manual or default. if (empty($this->key)) { // The key has not been set manually, look for it at config (base64 encoded there). $enckey = get_config('backup', 'backup_encryptkey'); if ($enckey === false) { // Has not been set, calculate and save an appropiate random key automatically. $enckey = base64_encode(self::generate_encryption_random_key(backup::CIPHERKEYLEN)); set_config('backup_encryptkey', $enckey, 'backup'); } $this->set_key(base64_decode($enckey)); } // Now we need an iv for this operation. $iv = self::generate_encryption_random_key(openssl_cipher_iv_length(backup::CIPHER)); // Everything is ready, let's encrypt and prepend the 1-shot iv. $value = $iv . openssl_encrypt($value, backup::CIPHER, $this->key, OPENSSL_RAW_DATA, $iv); // Calculate the hmac of the value (iv + encrypted) and prepend it. $hmac = hash_hmac('sha256', $value, $this->key, true); $value = $hmac . $value; // Ready, set the encoded value. parent::set_value(base64_encode($value)); // Finally, if the field has an "encrypted" attribute, set it to true. if ($att = $this->get_attribute('encrypted')) { $att->set_value('true'); } }
php
public function set_value($value) { // No openssl available, skip this field completely. if (!function_exists('openssl_encrypt')) { return; } // No hmac available, skip this field completely. if (!function_exists('hash_hmac')) { return; } // Cypher not available, skip this field completely. if (!in_array(backup::CIPHER, openssl_get_cipher_methods())) { return; } // Ensure we have a good key, manual or default. if (empty($this->key)) { // The key has not been set manually, look for it at config (base64 encoded there). $enckey = get_config('backup', 'backup_encryptkey'); if ($enckey === false) { // Has not been set, calculate and save an appropiate random key automatically. $enckey = base64_encode(self::generate_encryption_random_key(backup::CIPHERKEYLEN)); set_config('backup_encryptkey', $enckey, 'backup'); } $this->set_key(base64_decode($enckey)); } // Now we need an iv for this operation. $iv = self::generate_encryption_random_key(openssl_cipher_iv_length(backup::CIPHER)); // Everything is ready, let's encrypt and prepend the 1-shot iv. $value = $iv . openssl_encrypt($value, backup::CIPHER, $this->key, OPENSSL_RAW_DATA, $iv); // Calculate the hmac of the value (iv + encrypted) and prepend it. $hmac = hash_hmac('sha256', $value, $this->key, true); $value = $hmac . $value; // Ready, set the encoded value. parent::set_value(base64_encode($value)); // Finally, if the field has an "encrypted" attribute, set it to true. if ($att = $this->get_attribute('encrypted')) { $att->set_value('true'); } }
[ "public", "function", "set_value", "(", "$", "value", ")", "{", "// No openssl available, skip this field completely.", "if", "(", "!", "function_exists", "(", "'openssl_encrypt'", ")", ")", "{", "return", ";", "}", "// No hmac available, skip this field completely.", "if", "(", "!", "function_exists", "(", "'hash_hmac'", ")", ")", "{", "return", ";", "}", "// Cypher not available, skip this field completely.", "if", "(", "!", "in_array", "(", "backup", "::", "CIPHER", ",", "openssl_get_cipher_methods", "(", ")", ")", ")", "{", "return", ";", "}", "// Ensure we have a good key, manual or default.", "if", "(", "empty", "(", "$", "this", "->", "key", ")", ")", "{", "// The key has not been set manually, look for it at config (base64 encoded there).", "$", "enckey", "=", "get_config", "(", "'backup'", ",", "'backup_encryptkey'", ")", ";", "if", "(", "$", "enckey", "===", "false", ")", "{", "// Has not been set, calculate and save an appropiate random key automatically.", "$", "enckey", "=", "base64_encode", "(", "self", "::", "generate_encryption_random_key", "(", "backup", "::", "CIPHERKEYLEN", ")", ")", ";", "set_config", "(", "'backup_encryptkey'", ",", "$", "enckey", ",", "'backup'", ")", ";", "}", "$", "this", "->", "set_key", "(", "base64_decode", "(", "$", "enckey", ")", ")", ";", "}", "// Now we need an iv for this operation.", "$", "iv", "=", "self", "::", "generate_encryption_random_key", "(", "openssl_cipher_iv_length", "(", "backup", "::", "CIPHER", ")", ")", ";", "// Everything is ready, let's encrypt and prepend the 1-shot iv.", "$", "value", "=", "$", "iv", ".", "openssl_encrypt", "(", "$", "value", ",", "backup", "::", "CIPHER", ",", "$", "this", "->", "key", ",", "OPENSSL_RAW_DATA", ",", "$", "iv", ")", ";", "// Calculate the hmac of the value (iv + encrypted) and prepend it.", "$", "hmac", "=", "hash_hmac", "(", "'sha256'", ",", "$", "value", ",", "$", "this", "->", "key", ",", "true", ")", ";", "$", "value", "=", "$", "hmac", ".", "$", "value", ";", "// Ready, set the encoded value.", "parent", "::", "set_value", "(", "base64_encode", "(", "$", "value", ")", ")", ";", "// Finally, if the field has an \"encrypted\" attribute, set it to true.", "if", "(", "$", "att", "=", "$", "this", "->", "get_attribute", "(", "'encrypted'", ")", ")", "{", "$", "att", "->", "set_value", "(", "'true'", ")", ";", "}", "}" ]
Set the value of the field. This method sets the value of the element, encrypted using the specified key for it, defaulting to (and generating) backup_encryptkey config. HMAC is used for integrity. @param string $value plain-text content the will be stored encrypted and encoded.
[ "Set", "the", "value", "of", "the", "field", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_custom_fields.php#L167-L213
213,039
moodle/moodle
lib/phpexcel/PHPExcel/Writer/Excel2007/Chart.php
PHPExcel_Writer_Excel2007_Chart.writeBubbles
private function writeBubbles($plotSeriesValues, $objWriter, PHPExcel_Worksheet $pSheet) { if (is_null($plotSeriesValues)) { return; } $objWriter->startElement('c:bubbleSize'); $objWriter->startElement('c:numLit'); $objWriter->startElement('c:formatCode'); $objWriter->writeRawData('General'); $objWriter->endElement(); $objWriter->startElement('c:ptCount'); $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount()); $objWriter->endElement(); $dataValues = $plotSeriesValues->getDataValues(); if (!empty($dataValues)) { if (is_array($dataValues)) { foreach ($dataValues as $plotSeriesKey => $plotSeriesValue) { $objWriter->startElement('c:pt'); $objWriter->writeAttribute('idx', $plotSeriesKey); $objWriter->startElement('c:v'); $objWriter->writeRawData(1); $objWriter->endElement(); $objWriter->endElement(); } } } $objWriter->endElement(); $objWriter->endElement(); $objWriter->startElement('c:bubble3D'); $objWriter->writeAttribute('val', 0); $objWriter->endElement(); }
php
private function writeBubbles($plotSeriesValues, $objWriter, PHPExcel_Worksheet $pSheet) { if (is_null($plotSeriesValues)) { return; } $objWriter->startElement('c:bubbleSize'); $objWriter->startElement('c:numLit'); $objWriter->startElement('c:formatCode'); $objWriter->writeRawData('General'); $objWriter->endElement(); $objWriter->startElement('c:ptCount'); $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount()); $objWriter->endElement(); $dataValues = $plotSeriesValues->getDataValues(); if (!empty($dataValues)) { if (is_array($dataValues)) { foreach ($dataValues as $plotSeriesKey => $plotSeriesValue) { $objWriter->startElement('c:pt'); $objWriter->writeAttribute('idx', $plotSeriesKey); $objWriter->startElement('c:v'); $objWriter->writeRawData(1); $objWriter->endElement(); $objWriter->endElement(); } } } $objWriter->endElement(); $objWriter->endElement(); $objWriter->startElement('c:bubble3D'); $objWriter->writeAttribute('val', 0); $objWriter->endElement(); }
[ "private", "function", "writeBubbles", "(", "$", "plotSeriesValues", ",", "$", "objWriter", ",", "PHPExcel_Worksheet", "$", "pSheet", ")", "{", "if", "(", "is_null", "(", "$", "plotSeriesValues", ")", ")", "{", "return", ";", "}", "$", "objWriter", "->", "startElement", "(", "'c:bubbleSize'", ")", ";", "$", "objWriter", "->", "startElement", "(", "'c:numLit'", ")", ";", "$", "objWriter", "->", "startElement", "(", "'c:formatCode'", ")", ";", "$", "objWriter", "->", "writeRawData", "(", "'General'", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "$", "objWriter", "->", "startElement", "(", "'c:ptCount'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'val'", ",", "$", "plotSeriesValues", "->", "getPointCount", "(", ")", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "$", "dataValues", "=", "$", "plotSeriesValues", "->", "getDataValues", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "dataValues", ")", ")", "{", "if", "(", "is_array", "(", "$", "dataValues", ")", ")", "{", "foreach", "(", "$", "dataValues", "as", "$", "plotSeriesKey", "=>", "$", "plotSeriesValue", ")", "{", "$", "objWriter", "->", "startElement", "(", "'c:pt'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'idx'", ",", "$", "plotSeriesKey", ")", ";", "$", "objWriter", "->", "startElement", "(", "'c:v'", ")", ";", "$", "objWriter", "->", "writeRawData", "(", "1", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "}", "}", "}", "$", "objWriter", "->", "endElement", "(", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "$", "objWriter", "->", "startElement", "(", "'c:bubble3D'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'val'", ",", "0", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "}" ]
Write Bubble Chart Details @param PHPExcel_Chart_DataSeriesValues $plotSeriesValues @param PHPExcel_Shared_XMLWriter $objWriter XML Writer @throws PHPExcel_Writer_Exception
[ "Write", "Bubble", "Chart", "Details" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Chart.php#L1344-L1381
213,040
moodle/moodle
admin/tool/dataprivacy/classes/data_registry.php
data_registry.var_names_from_context
public static function var_names_from_context($classname, $pluginname = '') { $pluginname = trim($pluginname); if (!empty($pluginname)) { $categoryvar = $classname . '_' . $pluginname . '_category'; $purposevar = $classname . '_' . $pluginname . '_purpose'; } else { $categoryvar = $classname . '_category'; $purposevar = $classname . '_purpose'; } return [ $purposevar, $categoryvar ]; }
php
public static function var_names_from_context($classname, $pluginname = '') { $pluginname = trim($pluginname); if (!empty($pluginname)) { $categoryvar = $classname . '_' . $pluginname . '_category'; $purposevar = $classname . '_' . $pluginname . '_purpose'; } else { $categoryvar = $classname . '_category'; $purposevar = $classname . '_purpose'; } return [ $purposevar, $categoryvar ]; }
[ "public", "static", "function", "var_names_from_context", "(", "$", "classname", ",", "$", "pluginname", "=", "''", ")", "{", "$", "pluginname", "=", "trim", "(", "$", "pluginname", ")", ";", "if", "(", "!", "empty", "(", "$", "pluginname", ")", ")", "{", "$", "categoryvar", "=", "$", "classname", ".", "'_'", ".", "$", "pluginname", ".", "'_category'", ";", "$", "purposevar", "=", "$", "classname", ".", "'_'", ".", "$", "pluginname", ".", "'_purpose'", ";", "}", "else", "{", "$", "categoryvar", "=", "$", "classname", ".", "'_category'", ";", "$", "purposevar", "=", "$", "classname", ".", "'_purpose'", ";", "}", "return", "[", "$", "purposevar", ",", "$", "categoryvar", "]", ";", "}" ]
Returns purpose and category var names from a context class name @param string $classname The context level's class. @param string $pluginname The name of the plugin associated with the context level. @return string[]
[ "Returns", "purpose", "and", "category", "var", "names", "from", "a", "context", "class", "name" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/data_registry.php#L49-L62
213,041
moodle/moodle
admin/tool/dataprivacy/classes/data_registry.php
data_registry.get_defaults
public static function get_defaults($contextlevel, $pluginname = '') { $classname = \context_helper::get_class_for_level($contextlevel); list($purposevar, $categoryvar) = self::var_names_from_context($classname, $pluginname); $purposeid = get_config('tool_dataprivacy', $purposevar); $categoryid = get_config('tool_dataprivacy', $categoryvar); if (!empty($pluginname)) { list($purposevar, $categoryvar) = self::var_names_from_context($classname); // If the plugin-level doesn't have a default purpose set, try the context level. if ($purposeid == false) { $purposeid = get_config('tool_dataprivacy', $purposevar); } // If the plugin-level doesn't have a default category set, try the context level. if ($categoryid == false) { $categoryid = get_config('tool_dataprivacy', $categoryvar); } } if (empty($purposeid)) { $purposeid = context_instance::NOTSET; } if (empty($categoryid)) { $categoryid = context_instance::NOTSET; } return [$purposeid, $categoryid]; }
php
public static function get_defaults($contextlevel, $pluginname = '') { $classname = \context_helper::get_class_for_level($contextlevel); list($purposevar, $categoryvar) = self::var_names_from_context($classname, $pluginname); $purposeid = get_config('tool_dataprivacy', $purposevar); $categoryid = get_config('tool_dataprivacy', $categoryvar); if (!empty($pluginname)) { list($purposevar, $categoryvar) = self::var_names_from_context($classname); // If the plugin-level doesn't have a default purpose set, try the context level. if ($purposeid == false) { $purposeid = get_config('tool_dataprivacy', $purposevar); } // If the plugin-level doesn't have a default category set, try the context level. if ($categoryid == false) { $categoryid = get_config('tool_dataprivacy', $categoryvar); } } if (empty($purposeid)) { $purposeid = context_instance::NOTSET; } if (empty($categoryid)) { $categoryid = context_instance::NOTSET; } return [$purposeid, $categoryid]; }
[ "public", "static", "function", "get_defaults", "(", "$", "contextlevel", ",", "$", "pluginname", "=", "''", ")", "{", "$", "classname", "=", "\\", "context_helper", "::", "get_class_for_level", "(", "$", "contextlevel", ")", ";", "list", "(", "$", "purposevar", ",", "$", "categoryvar", ")", "=", "self", "::", "var_names_from_context", "(", "$", "classname", ",", "$", "pluginname", ")", ";", "$", "purposeid", "=", "get_config", "(", "'tool_dataprivacy'", ",", "$", "purposevar", ")", ";", "$", "categoryid", "=", "get_config", "(", "'tool_dataprivacy'", ",", "$", "categoryvar", ")", ";", "if", "(", "!", "empty", "(", "$", "pluginname", ")", ")", "{", "list", "(", "$", "purposevar", ",", "$", "categoryvar", ")", "=", "self", "::", "var_names_from_context", "(", "$", "classname", ")", ";", "// If the plugin-level doesn't have a default purpose set, try the context level.", "if", "(", "$", "purposeid", "==", "false", ")", "{", "$", "purposeid", "=", "get_config", "(", "'tool_dataprivacy'", ",", "$", "purposevar", ")", ";", "}", "// If the plugin-level doesn't have a default category set, try the context level.", "if", "(", "$", "categoryid", "==", "false", ")", "{", "$", "categoryid", "=", "get_config", "(", "'tool_dataprivacy'", ",", "$", "categoryvar", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "purposeid", ")", ")", "{", "$", "purposeid", "=", "context_instance", "::", "NOTSET", ";", "}", "if", "(", "empty", "(", "$", "categoryid", ")", ")", "{", "$", "categoryid", "=", "context_instance", "::", "NOTSET", ";", "}", "return", "[", "$", "purposeid", ",", "$", "categoryid", "]", ";", "}" ]
Returns the default purpose id and category id for the provided context level. The caller code is responsible of checking that $contextlevel is an integer. @param int $contextlevel The context level. @param string $pluginname The name of the plugin associated with the context level. @return int[]|false[]
[ "Returns", "the", "default", "purpose", "id", "and", "category", "id", "for", "the", "provided", "context", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/data_registry.php#L73-L101
213,042
moodle/moodle
admin/tool/dataprivacy/classes/data_registry.php
data_registry.defaults_set
public static function defaults_set() { list($purposeid, $categoryid) = self::get_defaults(CONTEXT_SYSTEM); if (empty($purposeid) || empty($categoryid)) { return false; } return true; }
php
public static function defaults_set() { list($purposeid, $categoryid) = self::get_defaults(CONTEXT_SYSTEM); if (empty($purposeid) || empty($categoryid)) { return false; } return true; }
[ "public", "static", "function", "defaults_set", "(", ")", "{", "list", "(", "$", "purposeid", ",", "$", "categoryid", ")", "=", "self", "::", "get_defaults", "(", "CONTEXT_SYSTEM", ")", ";", "if", "(", "empty", "(", "$", "purposeid", ")", "||", "empty", "(", "$", "categoryid", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Are data registry defaults set? At least the system defaults need to be set. @return bool
[ "Are", "data", "registry", "defaults", "set?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/data_registry.php#L110-L116
213,043
moodle/moodle
admin/tool/dataprivacy/classes/data_registry.php
data_registry.get_site_categories
public static function get_site_categories() { global $DB; if (method_exists('\core_course_category', 'get_all')) { $categories = \core_course_category::get_all(['returnhidden' => true]); } else { // Fallback (to be removed once this gets integrated into master). $ids = $DB->get_fieldset_select('course_categories', 'id', ''); $categories = \core_course_category::get_many($ids); } foreach ($categories as $key => $category) { if (!$category->is_uservisible()) { unset($categories[$key]); } } return $categories; }
php
public static function get_site_categories() { global $DB; if (method_exists('\core_course_category', 'get_all')) { $categories = \core_course_category::get_all(['returnhidden' => true]); } else { // Fallback (to be removed once this gets integrated into master). $ids = $DB->get_fieldset_select('course_categories', 'id', ''); $categories = \core_course_category::get_many($ids); } foreach ($categories as $key => $category) { if (!$category->is_uservisible()) { unset($categories[$key]); } } return $categories; }
[ "public", "static", "function", "get_site_categories", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "method_exists", "(", "'\\core_course_category'", ",", "'get_all'", ")", ")", "{", "$", "categories", "=", "\\", "core_course_category", "::", "get_all", "(", "[", "'returnhidden'", "=>", "true", "]", ")", ";", "}", "else", "{", "// Fallback (to be removed once this gets integrated into master).", "$", "ids", "=", "$", "DB", "->", "get_fieldset_select", "(", "'course_categories'", ",", "'id'", ",", "''", ")", ";", "$", "categories", "=", "\\", "core_course_category", "::", "get_many", "(", "$", "ids", ")", ";", "}", "foreach", "(", "$", "categories", "as", "$", "key", "=>", "$", "category", ")", "{", "if", "(", "!", "$", "category", "->", "is_uservisible", "(", ")", ")", "{", "unset", "(", "$", "categories", "[", "$", "key", "]", ")", ";", "}", "}", "return", "$", "categories", ";", "}" ]
Returns all site categories that are visible to the current user. @return \core_course_category[]
[ "Returns", "all", "site", "categories", "that", "are", "visible", "to", "the", "current", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/data_registry.php#L123-L140
213,044
moodle/moodle
admin/tool/dataprivacy/classes/data_registry.php
data_registry.get_subject_scope
public static function get_subject_scope(\context $context) { if ($contextcourse = $context->get_course_context(false)) { // Below course level we look at module or block level roles + course-assigned roles. $courseroles = get_roles_used_in_context($contextcourse, false); $roles = $courseroles + get_roles_used_in_context($context, false); } else { // We list category + system for others (we don't work with user instances so no need to work about them). $roles = get_roles_used_in_context($context); } return array_map(function($role) { if ($role->name) { return $role->name; } else { return $role->shortname; } }, $roles); }
php
public static function get_subject_scope(\context $context) { if ($contextcourse = $context->get_course_context(false)) { // Below course level we look at module or block level roles + course-assigned roles. $courseroles = get_roles_used_in_context($contextcourse, false); $roles = $courseroles + get_roles_used_in_context($context, false); } else { // We list category + system for others (we don't work with user instances so no need to work about them). $roles = get_roles_used_in_context($context); } return array_map(function($role) { if ($role->name) { return $role->name; } else { return $role->shortname; } }, $roles); }
[ "public", "static", "function", "get_subject_scope", "(", "\\", "context", "$", "context", ")", "{", "if", "(", "$", "contextcourse", "=", "$", "context", "->", "get_course_context", "(", "false", ")", ")", "{", "// Below course level we look at module or block level roles + course-assigned roles.", "$", "courseroles", "=", "get_roles_used_in_context", "(", "$", "contextcourse", ",", "false", ")", ";", "$", "roles", "=", "$", "courseroles", "+", "get_roles_used_in_context", "(", "$", "context", ",", "false", ")", ";", "}", "else", "{", "// We list category + system for others (we don't work with user instances so no need to work about them).", "$", "roles", "=", "get_roles_used_in_context", "(", "$", "context", ")", ";", "}", "return", "array_map", "(", "function", "(", "$", "role", ")", "{", "if", "(", "$", "role", "->", "name", ")", "{", "return", "$", "role", "->", "name", ";", "}", "else", "{", "return", "$", "role", "->", "shortname", ";", "}", "}", ",", "$", "roles", ")", ";", "}" ]
Returns the roles assigned to the provided level. Important to note that it returns course-level assigned roles if the provided context level is below course. @param \context $context @return array
[ "Returns", "the", "roles", "assigned", "to", "the", "provided", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/data_registry.php#L151-L169
213,045
moodle/moodle
admin/tool/dataprivacy/classes/data_registry.php
data_registry.get_effective_contextlevel_value
public static function get_effective_contextlevel_value($contextlevel, $element) { if ($element !== 'purpose' && $element !== 'category') { throw new coding_exception('Only \'purpose\' and \'category\' are supported.'); } $fieldname = $element . 'id'; if ($contextlevel != CONTEXT_SYSTEM && $contextlevel != CONTEXT_USER) { throw new \coding_exception('Only context_system and context_user values can be retrieved, no other context levels ' . 'have a purpose or a category.'); } list($purposeid, $categoryid) = self::get_effective_default_contextlevel_purpose_and_category($contextlevel); // Note: The $$fieldname points to either $purposeid, or $categoryid. if (context_instance::NOTSET != $$fieldname && context_instance::INHERIT != $$fieldname) { // There is a specific value set. return self::get_element_instance($element, $$fieldname); } throw new coding_exception('Something went wrong, system defaults should be set and we should already have a value.'); }
php
public static function get_effective_contextlevel_value($contextlevel, $element) { if ($element !== 'purpose' && $element !== 'category') { throw new coding_exception('Only \'purpose\' and \'category\' are supported.'); } $fieldname = $element . 'id'; if ($contextlevel != CONTEXT_SYSTEM && $contextlevel != CONTEXT_USER) { throw new \coding_exception('Only context_system and context_user values can be retrieved, no other context levels ' . 'have a purpose or a category.'); } list($purposeid, $categoryid) = self::get_effective_default_contextlevel_purpose_and_category($contextlevel); // Note: The $$fieldname points to either $purposeid, or $categoryid. if (context_instance::NOTSET != $$fieldname && context_instance::INHERIT != $$fieldname) { // There is a specific value set. return self::get_element_instance($element, $$fieldname); } throw new coding_exception('Something went wrong, system defaults should be set and we should already have a value.'); }
[ "public", "static", "function", "get_effective_contextlevel_value", "(", "$", "contextlevel", ",", "$", "element", ")", "{", "if", "(", "$", "element", "!==", "'purpose'", "&&", "$", "element", "!==", "'category'", ")", "{", "throw", "new", "coding_exception", "(", "'Only \\'purpose\\' and \\'category\\' are supported.'", ")", ";", "}", "$", "fieldname", "=", "$", "element", ".", "'id'", ";", "if", "(", "$", "contextlevel", "!=", "CONTEXT_SYSTEM", "&&", "$", "contextlevel", "!=", "CONTEXT_USER", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Only context_system and context_user values can be retrieved, no other context levels '", ".", "'have a purpose or a category.'", ")", ";", "}", "list", "(", "$", "purposeid", ",", "$", "categoryid", ")", "=", "self", "::", "get_effective_default_contextlevel_purpose_and_category", "(", "$", "contextlevel", ")", ";", "// Note: The $$fieldname points to either $purposeid, or $categoryid.", "if", "(", "context_instance", "::", "NOTSET", "!=", "$", "$", "fieldname", "&&", "context_instance", "::", "INHERIT", "!=", "$", "$", "fieldname", ")", "{", "// There is a specific value set.", "return", "self", "::", "get_element_instance", "(", "$", "element", ",", "$", "$", "fieldname", ")", ";", "}", "throw", "new", "coding_exception", "(", "'Something went wrong, system defaults should be set and we should already have a value.'", ")", ";", "}" ]
Returns the effective value for a context level. Note that this is different from the effective default context level (see get_effective_default_contextlevel_purpose_and_category) as this is returning the value set in the data registry, not in the defaults page. @param int $contextlevel @param string $element 'category' or 'purpose' @return \tool_dataprivacy\purpose|false
[ "Returns", "the", "effective", "value", "for", "a", "context", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/data_registry.php#L279-L299
213,046
moodle/moodle
admin/tool/dataprivacy/classes/data_registry.php
data_registry.get_effective_default_contextlevel_purpose_and_category
public static function get_effective_default_contextlevel_purpose_and_category($contextlevel, $forcedpurposevalue = false, $forcedcategoryvalue = false, $component = '') { // Get the defaults for this context level. list($purposeid, $categoryid) = self::get_defaults($contextlevel, $component); // Honour forced values. if ($forcedpurposevalue) { $purposeid = $forcedpurposevalue; } if ($forcedcategoryvalue) { $categoryid = $forcedcategoryvalue; } if ($contextlevel == CONTEXT_USER) { // Only user context levels inherit from a parent context level. list($parentpurposeid, $parentcategoryid) = self::get_defaults(CONTEXT_SYSTEM); if (context_instance::INHERIT == $purposeid || context_instance::NOTSET == $purposeid) { $purposeid = (int)$parentpurposeid; } if (context_instance::INHERIT == $categoryid || context_instance::NOTSET == $categoryid) { $categoryid = $parentcategoryid; } } return [$purposeid, $categoryid]; }
php
public static function get_effective_default_contextlevel_purpose_and_category($contextlevel, $forcedpurposevalue = false, $forcedcategoryvalue = false, $component = '') { // Get the defaults for this context level. list($purposeid, $categoryid) = self::get_defaults($contextlevel, $component); // Honour forced values. if ($forcedpurposevalue) { $purposeid = $forcedpurposevalue; } if ($forcedcategoryvalue) { $categoryid = $forcedcategoryvalue; } if ($contextlevel == CONTEXT_USER) { // Only user context levels inherit from a parent context level. list($parentpurposeid, $parentcategoryid) = self::get_defaults(CONTEXT_SYSTEM); if (context_instance::INHERIT == $purposeid || context_instance::NOTSET == $purposeid) { $purposeid = (int)$parentpurposeid; } if (context_instance::INHERIT == $categoryid || context_instance::NOTSET == $categoryid) { $categoryid = $parentcategoryid; } } return [$purposeid, $categoryid]; }
[ "public", "static", "function", "get_effective_default_contextlevel_purpose_and_category", "(", "$", "contextlevel", ",", "$", "forcedpurposevalue", "=", "false", ",", "$", "forcedcategoryvalue", "=", "false", ",", "$", "component", "=", "''", ")", "{", "// Get the defaults for this context level.", "list", "(", "$", "purposeid", ",", "$", "categoryid", ")", "=", "self", "::", "get_defaults", "(", "$", "contextlevel", ",", "$", "component", ")", ";", "// Honour forced values.", "if", "(", "$", "forcedpurposevalue", ")", "{", "$", "purposeid", "=", "$", "forcedpurposevalue", ";", "}", "if", "(", "$", "forcedcategoryvalue", ")", "{", "$", "categoryid", "=", "$", "forcedcategoryvalue", ";", "}", "if", "(", "$", "contextlevel", "==", "CONTEXT_USER", ")", "{", "// Only user context levels inherit from a parent context level.", "list", "(", "$", "parentpurposeid", ",", "$", "parentcategoryid", ")", "=", "self", "::", "get_defaults", "(", "CONTEXT_SYSTEM", ")", ";", "if", "(", "context_instance", "::", "INHERIT", "==", "$", "purposeid", "||", "context_instance", "::", "NOTSET", "==", "$", "purposeid", ")", "{", "$", "purposeid", "=", "(", "int", ")", "$", "parentpurposeid", ";", "}", "if", "(", "context_instance", "::", "INHERIT", "==", "$", "categoryid", "||", "context_instance", "::", "NOTSET", "==", "$", "categoryid", ")", "{", "$", "categoryid", "=", "$", "parentcategoryid", ";", "}", "}", "return", "[", "$", "purposeid", ",", "$", "categoryid", "]", ";", "}" ]
Returns the effective default purpose and category for a context level. @param int $contextlevel @param int|bool $forcedpurposevalue Use this value as if this was this context level purpose. @param int|bool $forcedcategoryvalue Use this value as if this was this context level category. @param string $component The name of the component to check. @return int[]
[ "Returns", "the", "effective", "default", "purpose", "and", "category", "for", "a", "context", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/data_registry.php#L310-L337
213,047
moodle/moodle
admin/tool/dataprivacy/classes/data_registry.php
data_registry.get_element_instance
private static function get_element_instance($element, $id) { if ($element !== 'purpose' && $element !== 'category') { throw new coding_exception('No other elements than purpose and category are allowed'); } $classname = '\tool_dataprivacy\\' . $element; return new $classname($id); }
php
private static function get_element_instance($element, $id) { if ($element !== 'purpose' && $element !== 'category') { throw new coding_exception('No other elements than purpose and category are allowed'); } $classname = '\tool_dataprivacy\\' . $element; return new $classname($id); }
[ "private", "static", "function", "get_element_instance", "(", "$", "element", ",", "$", "id", ")", "{", "if", "(", "$", "element", "!==", "'purpose'", "&&", "$", "element", "!==", "'category'", ")", "{", "throw", "new", "coding_exception", "(", "'No other elements than purpose and category are allowed'", ")", ";", "}", "$", "classname", "=", "'\\tool_dataprivacy\\\\'", ".", "$", "element", ";", "return", "new", "$", "classname", "(", "$", "id", ")", ";", "}" ]
Returns an instance of the provided element. @throws \coding_exception @param string $element The element name 'purpose' or 'category' @param int $id The element id @return \core\persistent
[ "Returns", "an", "instance", "of", "the", "provided", "element", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/data_registry.php#L347-L354
213,048
moodle/moodle
lib/spout/src/Spout/Reader/XLSX/Helper/SharedStringsCaching/FileBasedStrategy.php
FileBasedStrategy.getSharedStringTempFilePath
protected function getSharedStringTempFilePath($sharedStringIndex) { $numTempFile = intval($sharedStringIndex / $this->maxNumStringsPerTempFile); return $this->tempFolder . '/sharedstrings' . $numTempFile; }
php
protected function getSharedStringTempFilePath($sharedStringIndex) { $numTempFile = intval($sharedStringIndex / $this->maxNumStringsPerTempFile); return $this->tempFolder . '/sharedstrings' . $numTempFile; }
[ "protected", "function", "getSharedStringTempFilePath", "(", "$", "sharedStringIndex", ")", "{", "$", "numTempFile", "=", "intval", "(", "$", "sharedStringIndex", "/", "$", "this", "->", "maxNumStringsPerTempFile", ")", ";", "return", "$", "this", "->", "tempFolder", ".", "'/sharedstrings'", ".", "$", "numTempFile", ";", "}" ]
Returns the path for the temp file that should contain the string for the given index @param int $sharedStringIndex Index of the shared string in the sharedStrings.xml file @return string The temp file path for the given index
[ "Returns", "the", "path", "for", "the", "temp", "file", "that", "should", "contain", "the", "string", "for", "the", "given", "index" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/SharedStringsCaching/FileBasedStrategy.php#L100-L104
213,049
moodle/moodle
lib/spout/src/Spout/Reader/XLSX/Helper/SharedStringsCaching/FileBasedStrategy.php
FileBasedStrategy.getStringAtIndex
public function getStringAtIndex($sharedStringIndex) { $tempFilePath = $this->getSharedStringTempFilePath($sharedStringIndex); $indexInFile = $sharedStringIndex % $this->maxNumStringsPerTempFile; if (!$this->globalFunctionsHelper->file_exists($tempFilePath)) { throw new SharedStringNotFoundException("Shared string temp file not found: $tempFilePath ; for index: $sharedStringIndex"); } if ($this->inMemoryTempFilePath !== $tempFilePath) { // free memory unset($this->inMemoryTempFileContents); $this->inMemoryTempFileContents = explode(PHP_EOL, $this->globalFunctionsHelper->file_get_contents($tempFilePath)); $this->inMemoryTempFilePath = $tempFilePath; } $sharedString = null; // Using isset here because it is way faster than array_key_exists... if (isset($this->inMemoryTempFileContents[$indexInFile])) { $escapedSharedString = $this->inMemoryTempFileContents[$indexInFile]; $sharedString = $this->unescapeLineFeed($escapedSharedString); } if ($sharedString === null) { throw new SharedStringNotFoundException("Shared string not found for index: $sharedStringIndex"); } return rtrim($sharedString, PHP_EOL); }
php
public function getStringAtIndex($sharedStringIndex) { $tempFilePath = $this->getSharedStringTempFilePath($sharedStringIndex); $indexInFile = $sharedStringIndex % $this->maxNumStringsPerTempFile; if (!$this->globalFunctionsHelper->file_exists($tempFilePath)) { throw new SharedStringNotFoundException("Shared string temp file not found: $tempFilePath ; for index: $sharedStringIndex"); } if ($this->inMemoryTempFilePath !== $tempFilePath) { // free memory unset($this->inMemoryTempFileContents); $this->inMemoryTempFileContents = explode(PHP_EOL, $this->globalFunctionsHelper->file_get_contents($tempFilePath)); $this->inMemoryTempFilePath = $tempFilePath; } $sharedString = null; // Using isset here because it is way faster than array_key_exists... if (isset($this->inMemoryTempFileContents[$indexInFile])) { $escapedSharedString = $this->inMemoryTempFileContents[$indexInFile]; $sharedString = $this->unescapeLineFeed($escapedSharedString); } if ($sharedString === null) { throw new SharedStringNotFoundException("Shared string not found for index: $sharedStringIndex"); } return rtrim($sharedString, PHP_EOL); }
[ "public", "function", "getStringAtIndex", "(", "$", "sharedStringIndex", ")", "{", "$", "tempFilePath", "=", "$", "this", "->", "getSharedStringTempFilePath", "(", "$", "sharedStringIndex", ")", ";", "$", "indexInFile", "=", "$", "sharedStringIndex", "%", "$", "this", "->", "maxNumStringsPerTempFile", ";", "if", "(", "!", "$", "this", "->", "globalFunctionsHelper", "->", "file_exists", "(", "$", "tempFilePath", ")", ")", "{", "throw", "new", "SharedStringNotFoundException", "(", "\"Shared string temp file not found: $tempFilePath ; for index: $sharedStringIndex\"", ")", ";", "}", "if", "(", "$", "this", "->", "inMemoryTempFilePath", "!==", "$", "tempFilePath", ")", "{", "// free memory", "unset", "(", "$", "this", "->", "inMemoryTempFileContents", ")", ";", "$", "this", "->", "inMemoryTempFileContents", "=", "explode", "(", "PHP_EOL", ",", "$", "this", "->", "globalFunctionsHelper", "->", "file_get_contents", "(", "$", "tempFilePath", ")", ")", ";", "$", "this", "->", "inMemoryTempFilePath", "=", "$", "tempFilePath", ";", "}", "$", "sharedString", "=", "null", ";", "// Using isset here because it is way faster than array_key_exists...", "if", "(", "isset", "(", "$", "this", "->", "inMemoryTempFileContents", "[", "$", "indexInFile", "]", ")", ")", "{", "$", "escapedSharedString", "=", "$", "this", "->", "inMemoryTempFileContents", "[", "$", "indexInFile", "]", ";", "$", "sharedString", "=", "$", "this", "->", "unescapeLineFeed", "(", "$", "escapedSharedString", ")", ";", "}", "if", "(", "$", "sharedString", "===", "null", ")", "{", "throw", "new", "SharedStringNotFoundException", "(", "\"Shared string not found for index: $sharedStringIndex\"", ")", ";", "}", "return", "rtrim", "(", "$", "sharedString", ",", "PHP_EOL", ")", ";", "}" ]
Returns the string located at the given index from the cache. @param int $sharedStringIndex Index of the shared string in the sharedStrings.xml file @return string The shared string at the given index @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If no shared string found for the given index
[ "Returns", "the", "string", "located", "at", "the", "given", "index", "from", "the", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/SharedStringsCaching/FileBasedStrategy.php#L128-L158
213,050
moodle/moodle
question/engine/bank.php
question_bank.get_qtype
public static function get_qtype($qtypename, $mustexist = true) { global $CFG; if (isset(self::$questiontypes[$qtypename])) { return self::$questiontypes[$qtypename]; } $file = core_component::get_plugin_directory('qtype', $qtypename) . '/questiontype.php'; if (!is_readable($file)) { if ($mustexist || $qtypename == 'missingtype') { throw new coding_exception('Unknown question type ' . $qtypename); } else { return self::get_qtype('missingtype'); } } include_once($file); $class = 'qtype_' . $qtypename; if (!class_exists($class)) { throw new coding_exception("Class {$class} must be defined in {$file}."); } self::$questiontypes[$qtypename] = new $class(); return self::$questiontypes[$qtypename]; }
php
public static function get_qtype($qtypename, $mustexist = true) { global $CFG; if (isset(self::$questiontypes[$qtypename])) { return self::$questiontypes[$qtypename]; } $file = core_component::get_plugin_directory('qtype', $qtypename) . '/questiontype.php'; if (!is_readable($file)) { if ($mustexist || $qtypename == 'missingtype') { throw new coding_exception('Unknown question type ' . $qtypename); } else { return self::get_qtype('missingtype'); } } include_once($file); $class = 'qtype_' . $qtypename; if (!class_exists($class)) { throw new coding_exception("Class {$class} must be defined in {$file}."); } self::$questiontypes[$qtypename] = new $class(); return self::$questiontypes[$qtypename]; }
[ "public", "static", "function", "get_qtype", "(", "$", "qtypename", ",", "$", "mustexist", "=", "true", ")", "{", "global", "$", "CFG", ";", "if", "(", "isset", "(", "self", "::", "$", "questiontypes", "[", "$", "qtypename", "]", ")", ")", "{", "return", "self", "::", "$", "questiontypes", "[", "$", "qtypename", "]", ";", "}", "$", "file", "=", "core_component", "::", "get_plugin_directory", "(", "'qtype'", ",", "$", "qtypename", ")", ".", "'/questiontype.php'", ";", "if", "(", "!", "is_readable", "(", "$", "file", ")", ")", "{", "if", "(", "$", "mustexist", "||", "$", "qtypename", "==", "'missingtype'", ")", "{", "throw", "new", "coding_exception", "(", "'Unknown question type '", ".", "$", "qtypename", ")", ";", "}", "else", "{", "return", "self", "::", "get_qtype", "(", "'missingtype'", ")", ";", "}", "}", "include_once", "(", "$", "file", ")", ";", "$", "class", "=", "'qtype_'", ".", "$", "qtypename", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "coding_exception", "(", "\"Class {$class} must be defined in {$file}.\"", ")", ";", "}", "self", "::", "$", "questiontypes", "[", "$", "qtypename", "]", "=", "new", "$", "class", "(", ")", ";", "return", "self", "::", "$", "questiontypes", "[", "$", "qtypename", "]", ";", "}" ]
Get the question type class for a particular question type. @param string $qtypename the question type name. For example 'multichoice' or 'shortanswer'. @param bool $mustexist if false, the missing question type is returned when the requested question type is not installed. @return question_type the corresponding question type class.
[ "Get", "the", "question", "type", "class", "for", "a", "particular", "question", "type", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/bank.php#L87-L107
213,051
moodle/moodle
question/engine/bank.php
question_bank.sort_qtype_array
public static function sort_qtype_array($qtypes, $config = null) { if (is_null($config)) { $config = self::get_config(); } $sortorder = array(); $otherqtypes = array(); foreach ($qtypes as $name => $localname) { $sortvar = $name . '_sortorder'; if (isset($config->$sortvar)) { $sortorder[$config->$sortvar] = $name; } else { $otherqtypes[$name] = $localname; } } ksort($sortorder); core_collator::asort($otherqtypes); $sortedqtypes = array(); foreach ($sortorder as $name) { $sortedqtypes[$name] = $qtypes[$name]; } foreach ($otherqtypes as $name => $notused) { $sortedqtypes[$name] = $qtypes[$name]; } return $sortedqtypes; }
php
public static function sort_qtype_array($qtypes, $config = null) { if (is_null($config)) { $config = self::get_config(); } $sortorder = array(); $otherqtypes = array(); foreach ($qtypes as $name => $localname) { $sortvar = $name . '_sortorder'; if (isset($config->$sortvar)) { $sortorder[$config->$sortvar] = $name; } else { $otherqtypes[$name] = $localname; } } ksort($sortorder); core_collator::asort($otherqtypes); $sortedqtypes = array(); foreach ($sortorder as $name) { $sortedqtypes[$name] = $qtypes[$name]; } foreach ($otherqtypes as $name => $notused) { $sortedqtypes[$name] = $qtypes[$name]; } return $sortedqtypes; }
[ "public", "static", "function", "sort_qtype_array", "(", "$", "qtypes", ",", "$", "config", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "config", ")", ")", "{", "$", "config", "=", "self", "::", "get_config", "(", ")", ";", "}", "$", "sortorder", "=", "array", "(", ")", ";", "$", "otherqtypes", "=", "array", "(", ")", ";", "foreach", "(", "$", "qtypes", "as", "$", "name", "=>", "$", "localname", ")", "{", "$", "sortvar", "=", "$", "name", ".", "'_sortorder'", ";", "if", "(", "isset", "(", "$", "config", "->", "$", "sortvar", ")", ")", "{", "$", "sortorder", "[", "$", "config", "->", "$", "sortvar", "]", "=", "$", "name", ";", "}", "else", "{", "$", "otherqtypes", "[", "$", "name", "]", "=", "$", "localname", ";", "}", "}", "ksort", "(", "$", "sortorder", ")", ";", "core_collator", "::", "asort", "(", "$", "otherqtypes", ")", ";", "$", "sortedqtypes", "=", "array", "(", ")", ";", "foreach", "(", "$", "sortorder", "as", "$", "name", ")", "{", "$", "sortedqtypes", "[", "$", "name", "]", "=", "$", "qtypes", "[", "$", "name", "]", ";", "}", "foreach", "(", "$", "otherqtypes", "as", "$", "name", "=>", "$", "notused", ")", "{", "$", "sortedqtypes", "[", "$", "name", "]", "=", "$", "qtypes", "[", "$", "name", "]", ";", "}", "return", "$", "sortedqtypes", ";", "}" ]
Sort an array of question types according to the order the admin set up, and then alphabetically for the rest. @param array qtype->name() => qtype->local_name(). @return array sorted array.
[ "Sort", "an", "array", "of", "question", "types", "according", "to", "the", "order", "the", "admin", "set", "up", "and", "then", "alphabetically", "for", "the", "rest", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/bank.php#L169-L196
213,052
moodle/moodle
question/engine/bank.php
question_bank.get_all_question_types_in_categories
public static function get_all_question_types_in_categories($categories) { global $DB; list($categorysql, $params) = $DB->get_in_or_equal($categories); $sql = "SELECT DISTINCT q.qtype FROM {question} q WHERE q.category $categorysql"; $qtypes = $DB->get_fieldset_sql($sql, $params); return $qtypes; }
php
public static function get_all_question_types_in_categories($categories) { global $DB; list($categorysql, $params) = $DB->get_in_or_equal($categories); $sql = "SELECT DISTINCT q.qtype FROM {question} q WHERE q.category $categorysql"; $qtypes = $DB->get_fieldset_sql($sql, $params); return $qtypes; }
[ "public", "static", "function", "get_all_question_types_in_categories", "(", "$", "categories", ")", "{", "global", "$", "DB", ";", "list", "(", "$", "categorysql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "categories", ")", ";", "$", "sql", "=", "\"SELECT DISTINCT q.qtype\n FROM {question} q\n WHERE q.category $categorysql\"", ";", "$", "qtypes", "=", "$", "DB", "->", "get_fieldset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "return", "$", "qtypes", ";", "}" ]
Return a list of the different question types present in the given categories. @param array $categories a list of category ids @return array the list of question types in the categories @since Moodle 3.1
[ "Return", "a", "list", "of", "the", "different", "question", "types", "present", "in", "the", "given", "categories", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/bank.php#L418-L428
213,053
moodle/moodle
question/engine/bank.php
question_finder.get_questions_from_categories
public function get_questions_from_categories($categoryids, $extraconditions, $extraparams = array()) { global $DB; list($qcsql, $qcparams) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED, 'qc'); if ($extraconditions) { $extraconditions = ' AND (' . $extraconditions . ')'; } return $DB->get_records_select_menu('question', "category {$qcsql} AND parent = 0 AND hidden = 0 {$extraconditions}", $qcparams + $extraparams, '', 'id,id AS id2'); }
php
public function get_questions_from_categories($categoryids, $extraconditions, $extraparams = array()) { global $DB; list($qcsql, $qcparams) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED, 'qc'); if ($extraconditions) { $extraconditions = ' AND (' . $extraconditions . ')'; } return $DB->get_records_select_menu('question', "category {$qcsql} AND parent = 0 AND hidden = 0 {$extraconditions}", $qcparams + $extraparams, '', 'id,id AS id2'); }
[ "public", "function", "get_questions_from_categories", "(", "$", "categoryids", ",", "$", "extraconditions", ",", "$", "extraparams", "=", "array", "(", ")", ")", "{", "global", "$", "DB", ";", "list", "(", "$", "qcsql", ",", "$", "qcparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "categoryids", ",", "SQL_PARAMS_NAMED", ",", "'qc'", ")", ";", "if", "(", "$", "extraconditions", ")", "{", "$", "extraconditions", "=", "' AND ('", ".", "$", "extraconditions", ".", "')'", ";", "}", "return", "$", "DB", "->", "get_records_select_menu", "(", "'question'", ",", "\"category {$qcsql}\n AND parent = 0\n AND hidden = 0\n {$extraconditions}\"", ",", "$", "qcparams", "+", "$", "extraparams", ",", "''", ",", "'id,id AS id2'", ")", ";", "}" ]
Get the ids of all the questions in a list of categories. @param array $categoryids either a categoryid, or a comma-separated list category ids, or an array of them. @param string $extraconditions extra conditions to AND with the rest of the where clause. Must use named parameters. @param array $extraparams any parameters used by $extraconditions. @return array questionid => questionid.
[ "Get", "the", "ids", "of", "all", "the", "questions", "in", "a", "list", "of", "categories", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/bank.php#L491-L506
213,054
moodle/moodle
question/engine/bank.php
question_finder.get_questions_from_categories_with_usage_counts
public function get_questions_from_categories_with_usage_counts($categoryids, qubaid_condition $qubaids, $extraconditions = '', $extraparams = array()) { return $this->get_questions_from_categories_and_tags_with_usage_counts( $categoryids, $qubaids, $extraconditions, $extraparams); }
php
public function get_questions_from_categories_with_usage_counts($categoryids, qubaid_condition $qubaids, $extraconditions = '', $extraparams = array()) { return $this->get_questions_from_categories_and_tags_with_usage_counts( $categoryids, $qubaids, $extraconditions, $extraparams); }
[ "public", "function", "get_questions_from_categories_with_usage_counts", "(", "$", "categoryids", ",", "qubaid_condition", "$", "qubaids", ",", "$", "extraconditions", "=", "''", ",", "$", "extraparams", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "get_questions_from_categories_and_tags_with_usage_counts", "(", "$", "categoryids", ",", "$", "qubaids", ",", "$", "extraconditions", ",", "$", "extraparams", ")", ";", "}" ]
Get the ids of all the questions in a list of categories, with the number of times they have already been used in a given set of usages. The result array is returned in order of increasing (count previous uses). @param array $categoryids an array question_category ids. @param qubaid_condition $qubaids which question_usages to count previous uses from. @param string $extraconditions extra conditions to AND with the rest of the where clause. Must use named parameters. @param array $extraparams any parameters used by $extraconditions. @return array questionid => count of number of previous uses.
[ "Get", "the", "ids", "of", "all", "the", "questions", "in", "a", "list", "of", "categories", "with", "the", "number", "of", "times", "they", "have", "already", "been", "used", "in", "a", "given", "set", "of", "usages", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/bank.php#L521-L525
213,055
moodle/moodle
question/engine/bank.php
question_finder.get_questions_from_categories_and_tags_with_usage_counts
public function get_questions_from_categories_and_tags_with_usage_counts($categoryids, qubaid_condition $qubaids, $extraconditions = '', $extraparams = array(), $tagids = array()) { global $DB; list($qcsql, $qcparams) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED, 'qc'); $select = "q.id, (SELECT COUNT(1) FROM " . $qubaids->from_question_attempts('qa') . " WHERE qa.questionid = q.id AND " . $qubaids->where() . " ) AS previous_attempts"; $from = "{question} q"; $where = "q.category {$qcsql} AND q.parent = 0 AND q.hidden = 0"; $params = $qcparams; if (!empty($tagids)) { // We treat each additional tag as an AND condition rather than // an OR condition. // // For example, if the user filters by the tags "foo" and "bar" then // we reduce the question list to questions that are tagged with both // "foo" AND "bar". Any question that does not have ALL of the specified // tags will be omitted. list($tagsql, $tagparams) = $DB->get_in_or_equal($tagids, SQL_PARAMS_NAMED, 'ti'); $tagparams['tagcount'] = count($tagids); $tagparams['questionitemtype'] = 'question'; $tagparams['questioncomponent'] = 'core_question'; $where .= " AND q.id IN (SELECT ti.itemid FROM {tag_instance} ti WHERE ti.itemtype = :questionitemtype AND ti.component = :questioncomponent AND ti.tagid {$tagsql} GROUP BY ti.itemid HAVING COUNT(itemid) = :tagcount)"; $params += $tagparams; } if ($extraconditions) { $extraconditions = ' AND (' . $extraconditions . ')'; } return $DB->get_records_sql_menu("SELECT $select FROM $from WHERE $where $extraconditions ORDER BY previous_attempts", $qubaids->from_where_params() + $params + $extraparams); }
php
public function get_questions_from_categories_and_tags_with_usage_counts($categoryids, qubaid_condition $qubaids, $extraconditions = '', $extraparams = array(), $tagids = array()) { global $DB; list($qcsql, $qcparams) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED, 'qc'); $select = "q.id, (SELECT COUNT(1) FROM " . $qubaids->from_question_attempts('qa') . " WHERE qa.questionid = q.id AND " . $qubaids->where() . " ) AS previous_attempts"; $from = "{question} q"; $where = "q.category {$qcsql} AND q.parent = 0 AND q.hidden = 0"; $params = $qcparams; if (!empty($tagids)) { // We treat each additional tag as an AND condition rather than // an OR condition. // // For example, if the user filters by the tags "foo" and "bar" then // we reduce the question list to questions that are tagged with both // "foo" AND "bar". Any question that does not have ALL of the specified // tags will be omitted. list($tagsql, $tagparams) = $DB->get_in_or_equal($tagids, SQL_PARAMS_NAMED, 'ti'); $tagparams['tagcount'] = count($tagids); $tagparams['questionitemtype'] = 'question'; $tagparams['questioncomponent'] = 'core_question'; $where .= " AND q.id IN (SELECT ti.itemid FROM {tag_instance} ti WHERE ti.itemtype = :questionitemtype AND ti.component = :questioncomponent AND ti.tagid {$tagsql} GROUP BY ti.itemid HAVING COUNT(itemid) = :tagcount)"; $params += $tagparams; } if ($extraconditions) { $extraconditions = ' AND (' . $extraconditions . ')'; } return $DB->get_records_sql_menu("SELECT $select FROM $from WHERE $where $extraconditions ORDER BY previous_attempts", $qubaids->from_where_params() + $params + $extraparams); }
[ "public", "function", "get_questions_from_categories_and_tags_with_usage_counts", "(", "$", "categoryids", ",", "qubaid_condition", "$", "qubaids", ",", "$", "extraconditions", "=", "''", ",", "$", "extraparams", "=", "array", "(", ")", ",", "$", "tagids", "=", "array", "(", ")", ")", "{", "global", "$", "DB", ";", "list", "(", "$", "qcsql", ",", "$", "qcparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "categoryids", ",", "SQL_PARAMS_NAMED", ",", "'qc'", ")", ";", "$", "select", "=", "\"q.id, (SELECT COUNT(1)\n FROM \"", ".", "$", "qubaids", "->", "from_question_attempts", "(", "'qa'", ")", ".", "\"\n WHERE qa.questionid = q.id AND \"", ".", "$", "qubaids", "->", "where", "(", ")", ".", "\"\n ) AS previous_attempts\"", ";", "$", "from", "=", "\"{question} q\"", ";", "$", "where", "=", "\"q.category {$qcsql}\n AND q.parent = 0\n AND q.hidden = 0\"", ";", "$", "params", "=", "$", "qcparams", ";", "if", "(", "!", "empty", "(", "$", "tagids", ")", ")", "{", "// We treat each additional tag as an AND condition rather than", "// an OR condition.", "//", "// For example, if the user filters by the tags \"foo\" and \"bar\" then", "// we reduce the question list to questions that are tagged with both", "// \"foo\" AND \"bar\". Any question that does not have ALL of the specified", "// tags will be omitted.", "list", "(", "$", "tagsql", ",", "$", "tagparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "tagids", ",", "SQL_PARAMS_NAMED", ",", "'ti'", ")", ";", "$", "tagparams", "[", "'tagcount'", "]", "=", "count", "(", "$", "tagids", ")", ";", "$", "tagparams", "[", "'questionitemtype'", "]", "=", "'question'", ";", "$", "tagparams", "[", "'questioncomponent'", "]", "=", "'core_question'", ";", "$", "where", ".=", "\" AND q.id IN (SELECT ti.itemid\n FROM {tag_instance} ti\n WHERE ti.itemtype = :questionitemtype\n AND ti.component = :questioncomponent\n AND ti.tagid {$tagsql}\n GROUP BY ti.itemid\n HAVING COUNT(itemid) = :tagcount)\"", ";", "$", "params", "+=", "$", "tagparams", ";", "}", "if", "(", "$", "extraconditions", ")", "{", "$", "extraconditions", "=", "' AND ('", ".", "$", "extraconditions", ".", "')'", ";", "}", "return", "$", "DB", "->", "get_records_sql_menu", "(", "\"SELECT $select\n FROM $from\n WHERE $where $extraconditions\n ORDER BY previous_attempts\"", ",", "$", "qubaids", "->", "from_where_params", "(", ")", "+", "$", "params", "+", "$", "extraparams", ")", ";", "}" ]
Get the ids of all the questions in a list of categories that have ALL the provided tags, with the number of times they have already been used in a given set of usages. The result array is returned in order of increasing (count previous uses). @param array $categoryids an array of question_category ids. @param qubaid_condition $qubaids which question_usages to count previous uses from. @param string $extraconditions extra conditions to AND with the rest of the where clause. Must use named parameters. @param array $extraparams any parameters used by $extraconditions. @param array $tagids an array of tag ids @return array questionid => count of number of previous uses.
[ "Get", "the", "ids", "of", "all", "the", "questions", "in", "a", "list", "of", "categories", "that", "have", "ALL", "the", "provided", "tags", "with", "the", "number", "of", "times", "they", "have", "already", "been", "used", "in", "a", "given", "set", "of", "usages", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/bank.php#L541-L588
213,056
moodle/moodle
group/autogroup_form.php
autogroup_form.validation
function validation($data, $files) { global $CFG, $COURSE; $errors = parent::validation($data, $files); if ($data['allocateby'] != 'no') { $source = array(); if ($data['cohortid']) { $source['cohortid'] = $data['cohortid']; } if ($data['groupingid']) { $source['groupingid'] = $data['groupingid']; } if ($data['groupid']) { $source['groupid'] = $data['groupid']; } if (!$users = groups_get_potential_members($data['courseid'], $data['roleid'], $source)) { $errors['roleid'] = get_string('nousersinrole', 'group'); } /// Check the number entered is sane if ($data['groupby'] == 'groups') { $usercnt = count($users); if ($data['number'] > $usercnt || $data['number'] < 1) { $errors['number'] = get_string('toomanygroups', 'group', $usercnt); } } } //try to detect group name duplicates $name = groups_parse_name(trim($data['namingscheme']), 0); if (groups_get_group_by_name($COURSE->id, $name)) { $errors['namingscheme'] = get_string('groupnameexists', 'group', $name); } // check grouping name duplicates if ( isset($data['grouping']) && $data['grouping'] == '-1') { $name = trim($data['groupingname']); if (empty($name)) { $errors['groupingname'] = get_string('required'); } else if (groups_get_grouping_by_name($COURSE->id, $name)) { $errors['groupingname'] = get_string('groupingnameexists', 'group', $name); } } /// Check the naming scheme if ($data['groupby'] == 'groups' and $data['number'] == 1) { // we can use the name as is because there will be only one group max } else { $matchcnt = preg_match_all('/[#@]{1,1}/', $data['namingscheme'], $matches); if ($matchcnt != 1) { $errors['namingscheme'] = get_string('badnamingscheme', 'group'); } } return $errors; }
php
function validation($data, $files) { global $CFG, $COURSE; $errors = parent::validation($data, $files); if ($data['allocateby'] != 'no') { $source = array(); if ($data['cohortid']) { $source['cohortid'] = $data['cohortid']; } if ($data['groupingid']) { $source['groupingid'] = $data['groupingid']; } if ($data['groupid']) { $source['groupid'] = $data['groupid']; } if (!$users = groups_get_potential_members($data['courseid'], $data['roleid'], $source)) { $errors['roleid'] = get_string('nousersinrole', 'group'); } /// Check the number entered is sane if ($data['groupby'] == 'groups') { $usercnt = count($users); if ($data['number'] > $usercnt || $data['number'] < 1) { $errors['number'] = get_string('toomanygroups', 'group', $usercnt); } } } //try to detect group name duplicates $name = groups_parse_name(trim($data['namingscheme']), 0); if (groups_get_group_by_name($COURSE->id, $name)) { $errors['namingscheme'] = get_string('groupnameexists', 'group', $name); } // check grouping name duplicates if ( isset($data['grouping']) && $data['grouping'] == '-1') { $name = trim($data['groupingname']); if (empty($name)) { $errors['groupingname'] = get_string('required'); } else if (groups_get_grouping_by_name($COURSE->id, $name)) { $errors['groupingname'] = get_string('groupingnameexists', 'group', $name); } } /// Check the naming scheme if ($data['groupby'] == 'groups' and $data['number'] == 1) { // we can use the name as is because there will be only one group max } else { $matchcnt = preg_match_all('/[#@]{1,1}/', $data['namingscheme'], $matches); if ($matchcnt != 1) { $errors['namingscheme'] = get_string('badnamingscheme', 'group'); } } return $errors; }
[ "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "global", "$", "CFG", ",", "$", "COURSE", ";", "$", "errors", "=", "parent", "::", "validation", "(", "$", "data", ",", "$", "files", ")", ";", "if", "(", "$", "data", "[", "'allocateby'", "]", "!=", "'no'", ")", "{", "$", "source", "=", "array", "(", ")", ";", "if", "(", "$", "data", "[", "'cohortid'", "]", ")", "{", "$", "source", "[", "'cohortid'", "]", "=", "$", "data", "[", "'cohortid'", "]", ";", "}", "if", "(", "$", "data", "[", "'groupingid'", "]", ")", "{", "$", "source", "[", "'groupingid'", "]", "=", "$", "data", "[", "'groupingid'", "]", ";", "}", "if", "(", "$", "data", "[", "'groupid'", "]", ")", "{", "$", "source", "[", "'groupid'", "]", "=", "$", "data", "[", "'groupid'", "]", ";", "}", "if", "(", "!", "$", "users", "=", "groups_get_potential_members", "(", "$", "data", "[", "'courseid'", "]", ",", "$", "data", "[", "'roleid'", "]", ",", "$", "source", ")", ")", "{", "$", "errors", "[", "'roleid'", "]", "=", "get_string", "(", "'nousersinrole'", ",", "'group'", ")", ";", "}", "/// Check the number entered is sane", "if", "(", "$", "data", "[", "'groupby'", "]", "==", "'groups'", ")", "{", "$", "usercnt", "=", "count", "(", "$", "users", ")", ";", "if", "(", "$", "data", "[", "'number'", "]", ">", "$", "usercnt", "||", "$", "data", "[", "'number'", "]", "<", "1", ")", "{", "$", "errors", "[", "'number'", "]", "=", "get_string", "(", "'toomanygroups'", ",", "'group'", ",", "$", "usercnt", ")", ";", "}", "}", "}", "//try to detect group name duplicates", "$", "name", "=", "groups_parse_name", "(", "trim", "(", "$", "data", "[", "'namingscheme'", "]", ")", ",", "0", ")", ";", "if", "(", "groups_get_group_by_name", "(", "$", "COURSE", "->", "id", ",", "$", "name", ")", ")", "{", "$", "errors", "[", "'namingscheme'", "]", "=", "get_string", "(", "'groupnameexists'", ",", "'group'", ",", "$", "name", ")", ";", "}", "// check grouping name duplicates", "if", "(", "isset", "(", "$", "data", "[", "'grouping'", "]", ")", "&&", "$", "data", "[", "'grouping'", "]", "==", "'-1'", ")", "{", "$", "name", "=", "trim", "(", "$", "data", "[", "'groupingname'", "]", ")", ";", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "$", "errors", "[", "'groupingname'", "]", "=", "get_string", "(", "'required'", ")", ";", "}", "else", "if", "(", "groups_get_grouping_by_name", "(", "$", "COURSE", "->", "id", ",", "$", "name", ")", ")", "{", "$", "errors", "[", "'groupingname'", "]", "=", "get_string", "(", "'groupingnameexists'", ",", "'group'", ",", "$", "name", ")", ";", "}", "}", "/// Check the naming scheme", "if", "(", "$", "data", "[", "'groupby'", "]", "==", "'groups'", "and", "$", "data", "[", "'number'", "]", "==", "1", ")", "{", "// we can use the name as is because there will be only one group max", "}", "else", "{", "$", "matchcnt", "=", "preg_match_all", "(", "'/[#@]{1,1}/'", ",", "$", "data", "[", "'namingscheme'", "]", ",", "$", "matches", ")", ";", "if", "(", "$", "matchcnt", "!=", "1", ")", "{", "$", "errors", "[", "'namingscheme'", "]", "=", "get_string", "(", "'badnamingscheme'", ",", "'group'", ")", ";", "}", "}", "return", "$", "errors", ";", "}" ]
Performs validation of the form information @param array $data @param array $files @return array $errors An array of $errors
[ "Performs", "validation", "of", "the", "form", "information" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/autogroup_form.php#L196-L252
213,057
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/Bucket.php
Bucket.delete
public function delete($id) { $file = $this->collectionWrapper->findFileById($id); $this->collectionWrapper->deleteFileAndChunksById($id); if ($file === null) { throw FileNotFoundException::byId($id, $this->getFilesNamespace()); } }
php
public function delete($id) { $file = $this->collectionWrapper->findFileById($id); $this->collectionWrapper->deleteFileAndChunksById($id); if ($file === null) { throw FileNotFoundException::byId($id, $this->getFilesNamespace()); } }
[ "public", "function", "delete", "(", "$", "id", ")", "{", "$", "file", "=", "$", "this", "->", "collectionWrapper", "->", "findFileById", "(", "$", "id", ")", ";", "$", "this", "->", "collectionWrapper", "->", "deleteFileAndChunksById", "(", "$", "id", ")", ";", "if", "(", "$", "file", "===", "null", ")", "{", "throw", "FileNotFoundException", "::", "byId", "(", "$", "id", ",", "$", "this", "->", "getFilesNamespace", "(", ")", ")", ";", "}", "}" ]
Delete a file from the GridFS bucket. If the files collection document is not found, this method will still attempt to delete orphaned chunks. @param mixed $id File ID @throws FileNotFoundException if no file could be selected @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Delete", "a", "file", "from", "the", "GridFS", "bucket", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/Bucket.php#L174-L182
213,058
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/Bucket.php
Bucket.downloadToStream
public function downloadToStream($id, $destination) { if ( ! is_resource($destination) || get_resource_type($destination) != "stream") { throw InvalidArgumentException::invalidType('$destination', $destination, 'resource'); } stream_copy_to_stream($this->openDownloadStream($id), $destination); }
php
public function downloadToStream($id, $destination) { if ( ! is_resource($destination) || get_resource_type($destination) != "stream") { throw InvalidArgumentException::invalidType('$destination', $destination, 'resource'); } stream_copy_to_stream($this->openDownloadStream($id), $destination); }
[ "public", "function", "downloadToStream", "(", "$", "id", ",", "$", "destination", ")", "{", "if", "(", "!", "is_resource", "(", "$", "destination", ")", "||", "get_resource_type", "(", "$", "destination", ")", "!=", "\"stream\"", ")", "{", "throw", "InvalidArgumentException", "::", "invalidType", "(", "'$destination'", ",", "$", "destination", ",", "'resource'", ")", ";", "}", "stream_copy_to_stream", "(", "$", "this", "->", "openDownloadStream", "(", "$", "id", ")", ",", "$", "destination", ")", ";", "}" ]
Writes the contents of a GridFS file to a writable stream. @param mixed $id File ID @param resource $destination Writable Stream @throws FileNotFoundException if no file could be selected @throws InvalidArgumentException if $destination is not a stream @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Writes", "the", "contents", "of", "a", "GridFS", "file", "to", "a", "writable", "stream", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/Bucket.php#L193-L200
213,059
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/Bucket.php
Bucket.downloadToStreamByName
public function downloadToStreamByName($filename, $destination, array $options = []) { if ( ! is_resource($destination) || get_resource_type($destination) != "stream") { throw InvalidArgumentException::invalidType('$destination', $destination, 'resource'); } stream_copy_to_stream($this->openDownloadStreamByName($filename, $options), $destination); }
php
public function downloadToStreamByName($filename, $destination, array $options = []) { if ( ! is_resource($destination) || get_resource_type($destination) != "stream") { throw InvalidArgumentException::invalidType('$destination', $destination, 'resource'); } stream_copy_to_stream($this->openDownloadStreamByName($filename, $options), $destination); }
[ "public", "function", "downloadToStreamByName", "(", "$", "filename", ",", "$", "destination", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "is_resource", "(", "$", "destination", ")", "||", "get_resource_type", "(", "$", "destination", ")", "!=", "\"stream\"", ")", "{", "throw", "InvalidArgumentException", "::", "invalidType", "(", "'$destination'", ",", "$", "destination", ",", "'resource'", ")", ";", "}", "stream_copy_to_stream", "(", "$", "this", "->", "openDownloadStreamByName", "(", "$", "filename", ",", "$", "options", ")", ",", "$", "destination", ")", ";", "}" ]
Writes the contents of a GridFS file, which is selected by name and revision, to a writable stream. Supported options: * revision (integer): Which revision (i.e. documents with the same filename and different uploadDate) of the file to retrieve. Defaults to -1 (i.e. the most recent revision). Revision numbers are defined as follows: * 0 = the original stored file * 1 = the first revision * 2 = the second revision * etc… * -2 = the second most recent revision * -1 = the most recent revision @param string $filename Filename @param resource $destination Writable Stream @param array $options Download options @throws FileNotFoundException if no file could be selected @throws InvalidArgumentException if $destination is not a stream @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Writes", "the", "contents", "of", "a", "GridFS", "file", "which", "is", "selected", "by", "name", "and", "revision", "to", "a", "writable", "stream", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/Bucket.php#L228-L235
213,060
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/Bucket.php
Bucket.getFileIdForStream
public function getFileIdForStream($stream) { $file = $this->getRawFileDocumentForStream($stream); /* Filter the raw document through the specified type map, but override * the root type so we can reliably access the ID. */ $typeMap = ['root' => 'stdClass'] + $this->typeMap; $file = \MongoDB\apply_type_map_to_document($file, $typeMap); if ( ! isset($file->_id) && ! property_exists($file, '_id')) { throw new CorruptFileException('file._id does not exist'); } return $file->_id; }
php
public function getFileIdForStream($stream) { $file = $this->getRawFileDocumentForStream($stream); /* Filter the raw document through the specified type map, but override * the root type so we can reliably access the ID. */ $typeMap = ['root' => 'stdClass'] + $this->typeMap; $file = \MongoDB\apply_type_map_to_document($file, $typeMap); if ( ! isset($file->_id) && ! property_exists($file, '_id')) { throw new CorruptFileException('file._id does not exist'); } return $file->_id; }
[ "public", "function", "getFileIdForStream", "(", "$", "stream", ")", "{", "$", "file", "=", "$", "this", "->", "getRawFileDocumentForStream", "(", "$", "stream", ")", ";", "/* Filter the raw document through the specified type map, but override\n * the root type so we can reliably access the ID.\n */", "$", "typeMap", "=", "[", "'root'", "=>", "'stdClass'", "]", "+", "$", "this", "->", "typeMap", ";", "$", "file", "=", "\\", "MongoDB", "\\", "apply_type_map_to_document", "(", "$", "file", ",", "$", "typeMap", ")", ";", "if", "(", "!", "isset", "(", "$", "file", "->", "_id", ")", "&&", "!", "property_exists", "(", "$", "file", ",", "'_id'", ")", ")", "{", "throw", "new", "CorruptFileException", "(", "'file._id does not exist'", ")", ";", "}", "return", "$", "file", "->", "_id", ";", "}" ]
Gets the file document's ID of the GridFS file associated with a stream. @param resource $stream GridFS stream @return mixed @throws CorruptFileException if the file "_id" field does not exist @throws InvalidArgumentException if $stream is not a GridFS stream @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Gets", "the", "file", "document", "s", "ID", "of", "the", "GridFS", "file", "associated", "with", "a", "stream", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/Bucket.php#L347-L362
213,061
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/Bucket.php
Bucket.openDownloadStream
public function openDownloadStream($id) { $file = $this->collectionWrapper->findFileById($id); if ($file === null) { throw FileNotFoundException::byId($id, $this->getFilesNamespace()); } return $this->openDownloadStreamByFile($file); }
php
public function openDownloadStream($id) { $file = $this->collectionWrapper->findFileById($id); if ($file === null) { throw FileNotFoundException::byId($id, $this->getFilesNamespace()); } return $this->openDownloadStreamByFile($file); }
[ "public", "function", "openDownloadStream", "(", "$", "id", ")", "{", "$", "file", "=", "$", "this", "->", "collectionWrapper", "->", "findFileById", "(", "$", "id", ")", ";", "if", "(", "$", "file", "===", "null", ")", "{", "throw", "FileNotFoundException", "::", "byId", "(", "$", "id", ",", "$", "this", "->", "getFilesNamespace", "(", ")", ")", ";", "}", "return", "$", "this", "->", "openDownloadStreamByFile", "(", "$", "file", ")", ";", "}" ]
Opens a readable stream for reading a GridFS file. @param mixed $id File ID @return resource @throws FileNotFoundException if no file could be selected @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Opens", "a", "readable", "stream", "for", "reading", "a", "GridFS", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/Bucket.php#L424-L433
213,062
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/Bucket.php
Bucket.openDownloadStreamByName
public function openDownloadStreamByName($filename, array $options = []) { $options += ['revision' => -1]; $file = $this->collectionWrapper->findFileByFilenameAndRevision($filename, $options['revision']); if ($file === null) { throw FileNotFoundException::byFilenameAndRevision($filename, $options['revision'], $this->getFilesNamespace()); } return $this->openDownloadStreamByFile($file); }
php
public function openDownloadStreamByName($filename, array $options = []) { $options += ['revision' => -1]; $file = $this->collectionWrapper->findFileByFilenameAndRevision($filename, $options['revision']); if ($file === null) { throw FileNotFoundException::byFilenameAndRevision($filename, $options['revision'], $this->getFilesNamespace()); } return $this->openDownloadStreamByFile($file); }
[ "public", "function", "openDownloadStreamByName", "(", "$", "filename", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "+=", "[", "'revision'", "=>", "-", "1", "]", ";", "$", "file", "=", "$", "this", "->", "collectionWrapper", "->", "findFileByFilenameAndRevision", "(", "$", "filename", ",", "$", "options", "[", "'revision'", "]", ")", ";", "if", "(", "$", "file", "===", "null", ")", "{", "throw", "FileNotFoundException", "::", "byFilenameAndRevision", "(", "$", "filename", ",", "$", "options", "[", "'revision'", "]", ",", "$", "this", "->", "getFilesNamespace", "(", ")", ")", ";", "}", "return", "$", "this", "->", "openDownloadStreamByFile", "(", "$", "file", ")", ";", "}" ]
Opens a readable stream stream to read a GridFS file, which is selected by name and revision. Supported options: * revision (integer): Which revision (i.e. documents with the same filename and different uploadDate) of the file to retrieve. Defaults to -1 (i.e. the most recent revision). Revision numbers are defined as follows: * 0 = the original stored file * 1 = the first revision * 2 = the second revision * etc… * -2 = the second most recent revision * -1 = the most recent revision @param string $filename Filename @param array $options Download options @return resource @throws FileNotFoundException if no file could be selected @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Opens", "a", "readable", "stream", "stream", "to", "read", "a", "GridFS", "file", "which", "is", "selected", "by", "name", "and", "revision", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/Bucket.php#L460-L471
213,063
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/Bucket.php
Bucket.openUploadStream
public function openUploadStream($filename, array $options = []) { $options += ['chunkSizeBytes' => $this->chunkSizeBytes]; $path = $this->createPathForUpload(); $context = stream_context_create([ self::$streamWrapperProtocol => [ 'collectionWrapper' => $this->collectionWrapper, 'filename' => $filename, 'options' => $options, ], ]); return fopen($path, 'w', false, $context); }
php
public function openUploadStream($filename, array $options = []) { $options += ['chunkSizeBytes' => $this->chunkSizeBytes]; $path = $this->createPathForUpload(); $context = stream_context_create([ self::$streamWrapperProtocol => [ 'collectionWrapper' => $this->collectionWrapper, 'filename' => $filename, 'options' => $options, ], ]); return fopen($path, 'w', false, $context); }
[ "public", "function", "openUploadStream", "(", "$", "filename", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "+=", "[", "'chunkSizeBytes'", "=>", "$", "this", "->", "chunkSizeBytes", "]", ";", "$", "path", "=", "$", "this", "->", "createPathForUpload", "(", ")", ";", "$", "context", "=", "stream_context_create", "(", "[", "self", "::", "$", "streamWrapperProtocol", "=>", "[", "'collectionWrapper'", "=>", "$", "this", "->", "collectionWrapper", ",", "'filename'", "=>", "$", "filename", ",", "'options'", "=>", "$", "options", ",", "]", ",", "]", ")", ";", "return", "fopen", "(", "$", "path", ",", "'w'", ",", "false", ",", "$", "context", ")", ";", "}" ]
Opens a writable stream for writing a GridFS file. Supported options: * _id (mixed): File document identifier. Defaults to a new ObjectId. * chunkSizeBytes (integer): The chunk size in bytes. Defaults to the bucket's chunk size. * disableMD5 (boolean): When true, no MD5 sum will be generated for the stored file. Defaults to "false". * metadata (document): User data for the "metadata" field of the files collection document. @param string $filename Filename @param array $options Upload options @return resource
[ "Opens", "a", "writable", "stream", "for", "writing", "a", "GridFS", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/Bucket.php#L493-L507
213,064
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/Bucket.php
Bucket.rename
public function rename($id, $newFilename) { $updateResult = $this->collectionWrapper->updateFilenameForId($id, $newFilename); if ($updateResult->getModifiedCount() === 1) { return; } /* If the update resulted in no modification, it's possible that the * file did not exist, in which case we must raise an error. Checking * the write result's matched count will be most efficient, but fall * back to a findOne operation if necessary (i.e. legacy writes). */ $found = $updateResult->getMatchedCount() !== null ? $updateResult->getMatchedCount() === 1 : $this->collectionWrapper->findFileById($id) !== null; if ( ! $found) { throw FileNotFoundException::byId($id, $this->getFilesNamespace()); } }
php
public function rename($id, $newFilename) { $updateResult = $this->collectionWrapper->updateFilenameForId($id, $newFilename); if ($updateResult->getModifiedCount() === 1) { return; } /* If the update resulted in no modification, it's possible that the * file did not exist, in which case we must raise an error. Checking * the write result's matched count will be most efficient, but fall * back to a findOne operation if necessary (i.e. legacy writes). */ $found = $updateResult->getMatchedCount() !== null ? $updateResult->getMatchedCount() === 1 : $this->collectionWrapper->findFileById($id) !== null; if ( ! $found) { throw FileNotFoundException::byId($id, $this->getFilesNamespace()); } }
[ "public", "function", "rename", "(", "$", "id", ",", "$", "newFilename", ")", "{", "$", "updateResult", "=", "$", "this", "->", "collectionWrapper", "->", "updateFilenameForId", "(", "$", "id", ",", "$", "newFilename", ")", ";", "if", "(", "$", "updateResult", "->", "getModifiedCount", "(", ")", "===", "1", ")", "{", "return", ";", "}", "/* If the update resulted in no modification, it's possible that the\n * file did not exist, in which case we must raise an error. Checking\n * the write result's matched count will be most efficient, but fall\n * back to a findOne operation if necessary (i.e. legacy writes).\n */", "$", "found", "=", "$", "updateResult", "->", "getMatchedCount", "(", ")", "!==", "null", "?", "$", "updateResult", "->", "getMatchedCount", "(", ")", "===", "1", ":", "$", "this", "->", "collectionWrapper", "->", "findFileById", "(", "$", "id", ")", "!==", "null", ";", "if", "(", "!", "$", "found", ")", "{", "throw", "FileNotFoundException", "::", "byId", "(", "$", "id", ",", "$", "this", "->", "getFilesNamespace", "(", ")", ")", ";", "}", "}" ]
Renames the GridFS file with the specified ID. @param mixed $id File ID @param string $newFilename New filename @throws FileNotFoundException if no file could be selected @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Renames", "the", "GridFS", "file", "with", "the", "specified", "ID", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/Bucket.php#L517-L537
213,065
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/Bucket.php
Bucket.uploadFromStream
public function uploadFromStream($filename, $source, array $options = []) { if ( ! is_resource($source) || get_resource_type($source) != "stream") { throw InvalidArgumentException::invalidType('$source', $source, 'resource'); } $destination = $this->openUploadStream($filename, $options); stream_copy_to_stream($source, $destination); return $this->getFileIdForStream($destination); }
php
public function uploadFromStream($filename, $source, array $options = []) { if ( ! is_resource($source) || get_resource_type($source) != "stream") { throw InvalidArgumentException::invalidType('$source', $source, 'resource'); } $destination = $this->openUploadStream($filename, $options); stream_copy_to_stream($source, $destination); return $this->getFileIdForStream($destination); }
[ "public", "function", "uploadFromStream", "(", "$", "filename", ",", "$", "source", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "is_resource", "(", "$", "source", ")", "||", "get_resource_type", "(", "$", "source", ")", "!=", "\"stream\"", ")", "{", "throw", "InvalidArgumentException", "::", "invalidType", "(", "'$source'", ",", "$", "source", ",", "'resource'", ")", ";", "}", "$", "destination", "=", "$", "this", "->", "openUploadStream", "(", "$", "filename", ",", "$", "options", ")", ";", "stream_copy_to_stream", "(", "$", "source", ",", "$", "destination", ")", ";", "return", "$", "this", "->", "getFileIdForStream", "(", "$", "destination", ")", ";", "}" ]
Writes the contents of a readable stream to a GridFS file. Supported options: * _id (mixed): File document identifier. Defaults to a new ObjectId. * chunkSizeBytes (integer): The chunk size in bytes. Defaults to the bucket's chunk size. * disableMD5 (boolean): When true, no MD5 sum will be generated for the stored file. Defaults to "false". * metadata (document): User data for the "metadata" field of the files collection document. @param string $filename Filename @param resource $source Readable stream @param array $options Stream options @return mixed ID of the newly created GridFS file @throws InvalidArgumentException if $source is not a GridFS stream @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Writes", "the", "contents", "of", "a", "readable", "stream", "to", "a", "GridFS", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/Bucket.php#L562-L572
213,066
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/Bucket.php
Bucket.createPathForFile
private function createPathForFile(stdClass $file) { if ( ! is_object($file->_id) || method_exists($file->_id, '__toString')) { $id = (string) $file->_id; } else { $id = \MongoDB\BSON\toJSON(\MongoDB\BSON\fromPHP(['_id' => $file->_id])); } return sprintf( '%s://%s/%s.files/%s', self::$streamWrapperProtocol, urlencode($this->databaseName), urlencode($this->bucketName), urlencode($id) ); }
php
private function createPathForFile(stdClass $file) { if ( ! is_object($file->_id) || method_exists($file->_id, '__toString')) { $id = (string) $file->_id; } else { $id = \MongoDB\BSON\toJSON(\MongoDB\BSON\fromPHP(['_id' => $file->_id])); } return sprintf( '%s://%s/%s.files/%s', self::$streamWrapperProtocol, urlencode($this->databaseName), urlencode($this->bucketName), urlencode($id) ); }
[ "private", "function", "createPathForFile", "(", "stdClass", "$", "file", ")", "{", "if", "(", "!", "is_object", "(", "$", "file", "->", "_id", ")", "||", "method_exists", "(", "$", "file", "->", "_id", ",", "'__toString'", ")", ")", "{", "$", "id", "=", "(", "string", ")", "$", "file", "->", "_id", ";", "}", "else", "{", "$", "id", "=", "\\", "MongoDB", "\\", "BSON", "\\", "toJSON", "(", "\\", "MongoDB", "\\", "BSON", "\\", "fromPHP", "(", "[", "'_id'", "=>", "$", "file", "->", "_id", "]", ")", ")", ";", "}", "return", "sprintf", "(", "'%s://%s/%s.files/%s'", ",", "self", "::", "$", "streamWrapperProtocol", ",", "urlencode", "(", "$", "this", "->", "databaseName", ")", ",", "urlencode", "(", "$", "this", "->", "bucketName", ")", ",", "urlencode", "(", "$", "id", ")", ")", ";", "}" ]
Creates a path for an existing GridFS file. @param stdClass $file GridFS file document @return string
[ "Creates", "a", "path", "for", "an", "existing", "GridFS", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/Bucket.php#L580-L595
213,067
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/Bucket.php
Bucket.createPathForUpload
private function createPathForUpload() { return sprintf( '%s://%s/%s.files', self::$streamWrapperProtocol, urlencode($this->databaseName), urlencode($this->bucketName) ); }
php
private function createPathForUpload() { return sprintf( '%s://%s/%s.files', self::$streamWrapperProtocol, urlencode($this->databaseName), urlencode($this->bucketName) ); }
[ "private", "function", "createPathForUpload", "(", ")", "{", "return", "sprintf", "(", "'%s://%s/%s.files'", ",", "self", "::", "$", "streamWrapperProtocol", ",", "urlencode", "(", "$", "this", "->", "databaseName", ")", ",", "urlencode", "(", "$", "this", "->", "bucketName", ")", ")", ";", "}" ]
Creates a path for a new GridFS file, which does not yet have an ID. @return string
[ "Creates", "a", "path", "for", "a", "new", "GridFS", "file", "which", "does", "not", "yet", "have", "an", "ID", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/Bucket.php#L602-L610
213,068
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/Bucket.php
Bucket.openDownloadStreamByFile
private function openDownloadStreamByFile(stdClass $file) { $path = $this->createPathForFile($file); $context = stream_context_create([ self::$streamWrapperProtocol => [ 'collectionWrapper' => $this->collectionWrapper, 'file' => $file, ], ]); return fopen($path, 'r', false, $context); }
php
private function openDownloadStreamByFile(stdClass $file) { $path = $this->createPathForFile($file); $context = stream_context_create([ self::$streamWrapperProtocol => [ 'collectionWrapper' => $this->collectionWrapper, 'file' => $file, ], ]); return fopen($path, 'r', false, $context); }
[ "private", "function", "openDownloadStreamByFile", "(", "stdClass", "$", "file", ")", "{", "$", "path", "=", "$", "this", "->", "createPathForFile", "(", "$", "file", ")", ";", "$", "context", "=", "stream_context_create", "(", "[", "self", "::", "$", "streamWrapperProtocol", "=>", "[", "'collectionWrapper'", "=>", "$", "this", "->", "collectionWrapper", ",", "'file'", "=>", "$", "file", ",", "]", ",", "]", ")", ";", "return", "fopen", "(", "$", "path", ",", "'r'", ",", "false", ",", "$", "context", ")", ";", "}" ]
Opens a readable stream for the GridFS file. @param stdClass $file GridFS file document @return resource
[ "Opens", "a", "readable", "stream", "for", "the", "GridFS", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/Bucket.php#L653-L664
213,069
moodle/moodle
question/classes/statistics/questions/calculated_question_summary.php
calculated_question_summary.get_min_max_of
public function get_min_max_of($attribute) { $getmethod = 'get_min_max_of_' . $attribute; if (method_exists($this, $getmethod)) { return $this->$getmethod(); } else { $min = $max = null; $set = false; // We cannot simply use min or max functions because, in theory, some attributes might be non-scalar. foreach (array_column($this->subqstats, $attribute) as $value) { if (is_scalar($value) || is_null($value)) { if (!$set) { // It is not good enough to check if (!isset($min)), // because $min might have been set to null in an earlier iteration. $min = $value; $max = $value; $set = true; } $min = $this->min($min, $value); $max = $this->max($max, $value); } } return [$min, $max]; } }
php
public function get_min_max_of($attribute) { $getmethod = 'get_min_max_of_' . $attribute; if (method_exists($this, $getmethod)) { return $this->$getmethod(); } else { $min = $max = null; $set = false; // We cannot simply use min or max functions because, in theory, some attributes might be non-scalar. foreach (array_column($this->subqstats, $attribute) as $value) { if (is_scalar($value) || is_null($value)) { if (!$set) { // It is not good enough to check if (!isset($min)), // because $min might have been set to null in an earlier iteration. $min = $value; $max = $value; $set = true; } $min = $this->min($min, $value); $max = $this->max($max, $value); } } return [$min, $max]; } }
[ "public", "function", "get_min_max_of", "(", "$", "attribute", ")", "{", "$", "getmethod", "=", "'get_min_max_of_'", ".", "$", "attribute", ";", "if", "(", "method_exists", "(", "$", "this", ",", "$", "getmethod", ")", ")", "{", "return", "$", "this", "->", "$", "getmethod", "(", ")", ";", "}", "else", "{", "$", "min", "=", "$", "max", "=", "null", ";", "$", "set", "=", "false", ";", "// We cannot simply use min or max functions because, in theory, some attributes might be non-scalar.", "foreach", "(", "array_column", "(", "$", "this", "->", "subqstats", ",", "$", "attribute", ")", "as", "$", "value", ")", "{", "if", "(", "is_scalar", "(", "$", "value", ")", "||", "is_null", "(", "$", "value", ")", ")", "{", "if", "(", "!", "$", "set", ")", "{", "// It is not good enough to check if (!isset($min)),", "// because $min might have been set to null in an earlier iteration.", "$", "min", "=", "$", "value", ";", "$", "max", "=", "$", "value", ";", "$", "set", "=", "true", ";", "}", "$", "min", "=", "$", "this", "->", "min", "(", "$", "min", ",", "$", "value", ")", ";", "$", "max", "=", "$", "this", "->", "max", "(", "$", "max", ",", "$", "value", ")", ";", "}", "}", "return", "[", "$", "min", ",", "$", "max", "]", ";", "}", "}" ]
Returns the minimum and maximum values of the given attribute in the summarised calculated stats. @param string $attribute The attribute that we are looking for its extremums. @return array An array of [min,max]
[ "Returns", "the", "minimum", "and", "maximum", "values", "of", "the", "given", "attribute", "in", "the", "summarised", "calculated", "stats", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/calculated_question_summary.php#L81-L106
213,070
moodle/moodle
question/classes/statistics/questions/calculated_question_summary.php
calculated_question_summary.get_min_max_of_sd
protected function get_min_max_of_sd() { $min = $max = null; $set = false; foreach ($this->subqstats as $subqstat) { if (isset($subqstat->sd) && $subqstat->maxmark) { $value = $subqstat->sd / $subqstat->maxmark; } else { $value = null; } if (!$set) { // It is not good enough to check if (!isset($min)), // because $min might have been set to null in an earlier iteration. $min = $value; $max = $value; $set = true; } $min = $this->min($min, $value); $max = $this->max($max, $value); } return [$min, $max]; }
php
protected function get_min_max_of_sd() { $min = $max = null; $set = false; foreach ($this->subqstats as $subqstat) { if (isset($subqstat->sd) && $subqstat->maxmark) { $value = $subqstat->sd / $subqstat->maxmark; } else { $value = null; } if (!$set) { // It is not good enough to check if (!isset($min)), // because $min might have been set to null in an earlier iteration. $min = $value; $max = $value; $set = true; } $min = $this->min($min, $value); $max = $this->max($max, $value); } return [$min, $max]; }
[ "protected", "function", "get_min_max_of_sd", "(", ")", "{", "$", "min", "=", "$", "max", "=", "null", ";", "$", "set", "=", "false", ";", "foreach", "(", "$", "this", "->", "subqstats", "as", "$", "subqstat", ")", "{", "if", "(", "isset", "(", "$", "subqstat", "->", "sd", ")", "&&", "$", "subqstat", "->", "maxmark", ")", "{", "$", "value", "=", "$", "subqstat", "->", "sd", "/", "$", "subqstat", "->", "maxmark", ";", "}", "else", "{", "$", "value", "=", "null", ";", "}", "if", "(", "!", "$", "set", ")", "{", "// It is not good enough to check if (!isset($min)),", "// because $min might have been set to null in an earlier iteration.", "$", "min", "=", "$", "value", ";", "$", "max", "=", "$", "value", ";", "$", "set", "=", "true", ";", "}", "$", "min", "=", "$", "this", "->", "min", "(", "$", "min", ",", "$", "value", ")", ";", "$", "max", "=", "$", "this", "->", "max", "(", "$", "max", ",", "$", "value", ")", ";", "}", "return", "[", "$", "min", ",", "$", "max", "]", ";", "}" ]
Returns the minimum and maximum values of the standard deviation in the summarised calculated stats. @return array An array of [min,max]
[ "Returns", "the", "minimum", "and", "maximum", "values", "of", "the", "standard", "deviation", "in", "the", "summarised", "calculated", "stats", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/calculated_question_summary.php#L112-L135
213,071
moodle/moodle
question/classes/statistics/questions/calculated_question_summary.php
calculated_question_summary.max
protected function max(float $value1 = null, float $value2 = null) { $temp1 = $value1 ?: 0; $temp2 = $value2 ?: 0; $tempmax = max($temp1, $temp2); if (!$tempmax && $value1 !== 0 && $value2 !== 0) { $max = null; } else { $max = $tempmax; } return $max; }
php
protected function max(float $value1 = null, float $value2 = null) { $temp1 = $value1 ?: 0; $temp2 = $value2 ?: 0; $tempmax = max($temp1, $temp2); if (!$tempmax && $value1 !== 0 && $value2 !== 0) { $max = null; } else { $max = $tempmax; } return $max; }
[ "protected", "function", "max", "(", "float", "$", "value1", "=", "null", ",", "float", "$", "value2", "=", "null", ")", "{", "$", "temp1", "=", "$", "value1", "?", ":", "0", ";", "$", "temp2", "=", "$", "value2", "?", ":", "0", ";", "$", "tempmax", "=", "max", "(", "$", "temp1", ",", "$", "temp2", ")", ";", "if", "(", "!", "$", "tempmax", "&&", "$", "value1", "!==", "0", "&&", "$", "value2", "!==", "0", ")", "{", "$", "max", "=", "null", ";", "}", "else", "{", "$", "max", "=", "$", "tempmax", ";", "}", "return", "$", "max", ";", "}" ]
Find higher value. A zero value is almost considered equal to zero in comparisons. The only difference is that when being compared to zero, zero is higher than null. @param float|null $value1 @param float|null $value2 @return float|null
[ "Find", "higher", "value", ".", "A", "zero", "value", "is", "almost", "considered", "equal", "to", "zero", "in", "comparisons", ".", "The", "only", "difference", "is", "that", "when", "being", "compared", "to", "zero", "zero", "is", "higher", "than", "null", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/calculated_question_summary.php#L146-L159
213,072
moodle/moodle
question/classes/statistics/questions/calculated_question_summary.php
calculated_question_summary.min
protected function min(float $value1 = null, float $value2 = null) { $temp1 = $value1 ?: 0; $temp2 = $value2 ?: 0; $tempmin = min($temp1, $temp2); if (!$tempmin && $value1 !== 0 && $value2 !== 0) { $min = null; } else { $min = $tempmin; } return $min; }
php
protected function min(float $value1 = null, float $value2 = null) { $temp1 = $value1 ?: 0; $temp2 = $value2 ?: 0; $tempmin = min($temp1, $temp2); if (!$tempmin && $value1 !== 0 && $value2 !== 0) { $min = null; } else { $min = $tempmin; } return $min; }
[ "protected", "function", "min", "(", "float", "$", "value1", "=", "null", ",", "float", "$", "value2", "=", "null", ")", "{", "$", "temp1", "=", "$", "value1", "?", ":", "0", ";", "$", "temp2", "=", "$", "value2", "?", ":", "0", ";", "$", "tempmin", "=", "min", "(", "$", "temp1", ",", "$", "temp2", ")", ";", "if", "(", "!", "$", "tempmin", "&&", "$", "value1", "!==", "0", "&&", "$", "value2", "!==", "0", ")", "{", "$", "min", "=", "null", ";", "}", "else", "{", "$", "min", "=", "$", "tempmin", ";", "}", "return", "$", "min", ";", "}" ]
Find lower value. A zero value is almost considered equal to zero in comparisons. The only difference is that when being compared to zero, zero is lower than null. @param float|null $value1 @param float|null $value2 @return mixed|null
[ "Find", "lower", "value", ".", "A", "zero", "value", "is", "almost", "considered", "equal", "to", "zero", "in", "comparisons", ".", "The", "only", "difference", "is", "that", "when", "being", "compared", "to", "zero", "zero", "is", "lower", "than", "null", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/calculated_question_summary.php#L170-L183
213,073
moodle/moodle
lib/spout/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php
SharedStringsHelper.writeString
public function writeString($string) { fwrite($this->sharedStringsFilePointer, '<si><t xml:space="preserve">' . $this->stringsEscaper->escape($string) . '</t></si>'); $this->numSharedStrings++; // Shared string ID is zero-based return ($this->numSharedStrings - 1); }
php
public function writeString($string) { fwrite($this->sharedStringsFilePointer, '<si><t xml:space="preserve">' . $this->stringsEscaper->escape($string) . '</t></si>'); $this->numSharedStrings++; // Shared string ID is zero-based return ($this->numSharedStrings - 1); }
[ "public", "function", "writeString", "(", "$", "string", ")", "{", "fwrite", "(", "$", "this", "->", "sharedStringsFilePointer", ",", "'<si><t xml:space=\"preserve\">'", ".", "$", "this", "->", "stringsEscaper", "->", "escape", "(", "$", "string", ")", ".", "'</t></si>'", ")", ";", "$", "this", "->", "numSharedStrings", "++", ";", "// Shared string ID is zero-based", "return", "(", "$", "this", "->", "numSharedStrings", "-", "1", ")", ";", "}" ]
Writes the given string into the sharedStrings.xml file. Starting and ending whitespaces are preserved. @param string $string @return int ID of the written shared string
[ "Writes", "the", "given", "string", "into", "the", "sharedStrings", ".", "xml", "file", ".", "Starting", "and", "ending", "whitespaces", "are", "preserved", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php#L75-L82
213,074
moodle/moodle
lib/spout/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php
SharedStringsHelper.close
public function close() { if (!is_resource($this->sharedStringsFilePointer)) { return; } fwrite($this->sharedStringsFilePointer, '</sst>'); // Replace the default strings count with the actual number of shared strings in the file header $firstPartHeaderLength = strlen(self::SHARED_STRINGS_XML_FILE_FIRST_PART_HEADER); $defaultStringsCountPartLength = strlen(self::DEFAULT_STRINGS_COUNT_PART); // Adding 1 to take into account the space between the last xml attribute and "count" fseek($this->sharedStringsFilePointer, $firstPartHeaderLength + 1); fwrite($this->sharedStringsFilePointer, sprintf("%-{$defaultStringsCountPartLength}s", 'count="' . $this->numSharedStrings . '" uniqueCount="' . $this->numSharedStrings . '"')); fclose($this->sharedStringsFilePointer); }
php
public function close() { if (!is_resource($this->sharedStringsFilePointer)) { return; } fwrite($this->sharedStringsFilePointer, '</sst>'); // Replace the default strings count with the actual number of shared strings in the file header $firstPartHeaderLength = strlen(self::SHARED_STRINGS_XML_FILE_FIRST_PART_HEADER); $defaultStringsCountPartLength = strlen(self::DEFAULT_STRINGS_COUNT_PART); // Adding 1 to take into account the space between the last xml attribute and "count" fseek($this->sharedStringsFilePointer, $firstPartHeaderLength + 1); fwrite($this->sharedStringsFilePointer, sprintf("%-{$defaultStringsCountPartLength}s", 'count="' . $this->numSharedStrings . '" uniqueCount="' . $this->numSharedStrings . '"')); fclose($this->sharedStringsFilePointer); }
[ "public", "function", "close", "(", ")", "{", "if", "(", "!", "is_resource", "(", "$", "this", "->", "sharedStringsFilePointer", ")", ")", "{", "return", ";", "}", "fwrite", "(", "$", "this", "->", "sharedStringsFilePointer", ",", "'</sst>'", ")", ";", "// Replace the default strings count with the actual number of shared strings in the file header", "$", "firstPartHeaderLength", "=", "strlen", "(", "self", "::", "SHARED_STRINGS_XML_FILE_FIRST_PART_HEADER", ")", ";", "$", "defaultStringsCountPartLength", "=", "strlen", "(", "self", "::", "DEFAULT_STRINGS_COUNT_PART", ")", ";", "// Adding 1 to take into account the space between the last xml attribute and \"count\"", "fseek", "(", "$", "this", "->", "sharedStringsFilePointer", ",", "$", "firstPartHeaderLength", "+", "1", ")", ";", "fwrite", "(", "$", "this", "->", "sharedStringsFilePointer", ",", "sprintf", "(", "\"%-{$defaultStringsCountPartLength}s\"", ",", "'count=\"'", ".", "$", "this", "->", "numSharedStrings", ".", "'\" uniqueCount=\"'", ".", "$", "this", "->", "numSharedStrings", ".", "'\"'", ")", ")", ";", "fclose", "(", "$", "this", "->", "sharedStringsFilePointer", ")", ";", "}" ]
Finishes writing the data in the sharedStrings.xml file and closes the file. @return void
[ "Finishes", "writing", "the", "data", "in", "the", "sharedStrings", ".", "xml", "file", "and", "closes", "the", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php#L89-L106
213,075
moodle/moodle
lib/classes/lock/lock_config.php
lock_config.get_lock_factory
public static function get_lock_factory($type) { global $CFG, $DB; $lockfactory = null; if (during_initial_install()) { $lockfactory = new \core\lock\installation_lock_factory($type); } else if (isset($CFG->lock_factory) && $CFG->lock_factory != 'auto') { if (!class_exists($CFG->lock_factory)) { // In this case I guess it is not safe to continue. Different cluster nodes could end up using different locking // types because of an installation error. throw new \coding_exception('Lock factory set in $CFG does not exist: ' . $CFG->lock_factory); } $lockfactoryclass = $CFG->lock_factory; $lockfactory = new $lockfactoryclass($type); } else { $dbtype = clean_param($DB->get_dbfamily(), PARAM_ALPHA); // DB Specific lock factory is preferred - should support auto-release. $lockfactoryclass = "\\core\\lock\\${dbtype}_lock_factory"; if (!class_exists($lockfactoryclass)) { $lockfactoryclass = '\core\lock\file_lock_factory'; } /* @var lock_factory $lockfactory */ $lockfactory = new $lockfactoryclass($type); if (!$lockfactory->is_available()) { // Final fallback - DB row locking. $lockfactory = new \core\lock\db_record_lock_factory($type); } } return $lockfactory; }
php
public static function get_lock_factory($type) { global $CFG, $DB; $lockfactory = null; if (during_initial_install()) { $lockfactory = new \core\lock\installation_lock_factory($type); } else if (isset($CFG->lock_factory) && $CFG->lock_factory != 'auto') { if (!class_exists($CFG->lock_factory)) { // In this case I guess it is not safe to continue. Different cluster nodes could end up using different locking // types because of an installation error. throw new \coding_exception('Lock factory set in $CFG does not exist: ' . $CFG->lock_factory); } $lockfactoryclass = $CFG->lock_factory; $lockfactory = new $lockfactoryclass($type); } else { $dbtype = clean_param($DB->get_dbfamily(), PARAM_ALPHA); // DB Specific lock factory is preferred - should support auto-release. $lockfactoryclass = "\\core\\lock\\${dbtype}_lock_factory"; if (!class_exists($lockfactoryclass)) { $lockfactoryclass = '\core\lock\file_lock_factory'; } /* @var lock_factory $lockfactory */ $lockfactory = new $lockfactoryclass($type); if (!$lockfactory->is_available()) { // Final fallback - DB row locking. $lockfactory = new \core\lock\db_record_lock_factory($type); } } return $lockfactory; }
[ "public", "static", "function", "get_lock_factory", "(", "$", "type", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "lockfactory", "=", "null", ";", "if", "(", "during_initial_install", "(", ")", ")", "{", "$", "lockfactory", "=", "new", "\\", "core", "\\", "lock", "\\", "installation_lock_factory", "(", "$", "type", ")", ";", "}", "else", "if", "(", "isset", "(", "$", "CFG", "->", "lock_factory", ")", "&&", "$", "CFG", "->", "lock_factory", "!=", "'auto'", ")", "{", "if", "(", "!", "class_exists", "(", "$", "CFG", "->", "lock_factory", ")", ")", "{", "// In this case I guess it is not safe to continue. Different cluster nodes could end up using different locking", "// types because of an installation error.", "throw", "new", "\\", "coding_exception", "(", "'Lock factory set in $CFG does not exist: '", ".", "$", "CFG", "->", "lock_factory", ")", ";", "}", "$", "lockfactoryclass", "=", "$", "CFG", "->", "lock_factory", ";", "$", "lockfactory", "=", "new", "$", "lockfactoryclass", "(", "$", "type", ")", ";", "}", "else", "{", "$", "dbtype", "=", "clean_param", "(", "$", "DB", "->", "get_dbfamily", "(", ")", ",", "PARAM_ALPHA", ")", ";", "// DB Specific lock factory is preferred - should support auto-release.", "$", "lockfactoryclass", "=", "\"\\\\core\\\\lock\\\\${dbtype}_lock_factory\"", ";", "if", "(", "!", "class_exists", "(", "$", "lockfactoryclass", ")", ")", "{", "$", "lockfactoryclass", "=", "'\\core\\lock\\file_lock_factory'", ";", "}", "/* @var lock_factory $lockfactory */", "$", "lockfactory", "=", "new", "$", "lockfactoryclass", "(", "$", "type", ")", ";", "if", "(", "!", "$", "lockfactory", "->", "is_available", "(", ")", ")", "{", "// Final fallback - DB row locking.", "$", "lockfactory", "=", "new", "\\", "core", "\\", "lock", "\\", "db_record_lock_factory", "(", "$", "type", ")", ";", "}", "}", "return", "$", "lockfactory", ";", "}" ]
Get an instance of the currently configured locking subclass. @param string $type - Unique namespace for the locks generated by this factory. e.g. core_cron @return \core\lock\lock_factory @throws \coding_exception
[ "Get", "an", "instance", "of", "the", "currently", "configured", "locking", "subclass", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/lock/lock_config.php#L47-L78
213,076
moodle/moodle
blocks/recentlyaccesseditems/classes/privacy/provider.php
provider.export_recentitems
protected static function export_recentitems(int $userid, \context $context) { global $DB; $sql = "SELECT ra.id, c.fullname, ra.timeaccess, m.name, ra.cmid FROM {block_recentlyaccesseditems} ra JOIN {course} c ON c.id = ra.courseid JOIN {course_modules} cm on cm.id = ra.cmid JOIN {modules} m ON m.id = cm.module WHERE ra.userid = :userid"; $params = ['userid' => $userid]; $records = $DB->get_records_sql($sql, $params); if (!empty($records)) { $recentitems = (object) array_map(function($record) use($context) { return [ 'course_name' => format_string($record->fullname, true, ['context' => $context]), 'module_name' => format_string($record->name), 'timeaccess' => transform::datetime($record->timeaccess) ]; }, $records); writer::with_context($context)->export_data([get_string('privacy:recentlyaccesseditemspath', 'block_recentlyaccesseditems')], $recentitems); } }
php
protected static function export_recentitems(int $userid, \context $context) { global $DB; $sql = "SELECT ra.id, c.fullname, ra.timeaccess, m.name, ra.cmid FROM {block_recentlyaccesseditems} ra JOIN {course} c ON c.id = ra.courseid JOIN {course_modules} cm on cm.id = ra.cmid JOIN {modules} m ON m.id = cm.module WHERE ra.userid = :userid"; $params = ['userid' => $userid]; $records = $DB->get_records_sql($sql, $params); if (!empty($records)) { $recentitems = (object) array_map(function($record) use($context) { return [ 'course_name' => format_string($record->fullname, true, ['context' => $context]), 'module_name' => format_string($record->name), 'timeaccess' => transform::datetime($record->timeaccess) ]; }, $records); writer::with_context($context)->export_data([get_string('privacy:recentlyaccesseditemspath', 'block_recentlyaccesseditems')], $recentitems); } }
[ "protected", "static", "function", "export_recentitems", "(", "int", "$", "userid", ",", "\\", "context", "$", "context", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT ra.id, c.fullname, ra.timeaccess, m.name, ra.cmid\n FROM {block_recentlyaccesseditems} ra\n JOIN {course} c ON c.id = ra.courseid\n JOIN {course_modules} cm on cm.id = ra.cmid\n JOIN {modules} m ON m.id = cm.module\n WHERE ra.userid = :userid\"", ";", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", "]", ";", "$", "records", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "if", "(", "!", "empty", "(", "$", "records", ")", ")", "{", "$", "recentitems", "=", "(", "object", ")", "array_map", "(", "function", "(", "$", "record", ")", "use", "(", "$", "context", ")", "{", "return", "[", "'course_name'", "=>", "format_string", "(", "$", "record", "->", "fullname", ",", "true", ",", "[", "'context'", "=>", "$", "context", "]", ")", ",", "'module_name'", "=>", "format_string", "(", "$", "record", "->", "name", ")", ",", "'timeaccess'", "=>", "transform", "::", "datetime", "(", "$", "record", "->", "timeaccess", ")", "]", ";", "}", ",", "$", "records", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "[", "get_string", "(", "'privacy:recentlyaccesseditemspath'", ",", "'block_recentlyaccesseditems'", ")", "]", ",", "$", "recentitems", ")", ";", "}", "}" ]
Export information about the most recently accessed items. @param int $userid The user ID. @param \context $context The user context.
[ "Export", "information", "about", "the", "most", "recently", "accessed", "items", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/recentlyaccesseditems/classes/privacy/provider.php#L124-L146
213,077
moodle/moodle
mod/lesson/pagetypes/shortanswer.php
lesson_page_type_shortanswer.create_answers
public function create_answers($properties) { if (isset($properties->enableotheranswers) && $properties->enableotheranswers) { $properties->response_editor = array_values($properties->response_editor); $properties->jumpto = array_values($properties->jumpto); $properties->score = array_values($properties->score); $wrongresponse = end($properties->response_editor); $wrongkey = key($properties->response_editor); $properties->answer_editor[$wrongkey] = LESSON_OTHER_ANSWERS; } parent::create_answers($properties); }
php
public function create_answers($properties) { if (isset($properties->enableotheranswers) && $properties->enableotheranswers) { $properties->response_editor = array_values($properties->response_editor); $properties->jumpto = array_values($properties->jumpto); $properties->score = array_values($properties->score); $wrongresponse = end($properties->response_editor); $wrongkey = key($properties->response_editor); $properties->answer_editor[$wrongkey] = LESSON_OTHER_ANSWERS; } parent::create_answers($properties); }
[ "public", "function", "create_answers", "(", "$", "properties", ")", "{", "if", "(", "isset", "(", "$", "properties", "->", "enableotheranswers", ")", "&&", "$", "properties", "->", "enableotheranswers", ")", "{", "$", "properties", "->", "response_editor", "=", "array_values", "(", "$", "properties", "->", "response_editor", ")", ";", "$", "properties", "->", "jumpto", "=", "array_values", "(", "$", "properties", "->", "jumpto", ")", ";", "$", "properties", "->", "score", "=", "array_values", "(", "$", "properties", "->", "score", ")", ";", "$", "wrongresponse", "=", "end", "(", "$", "properties", "->", "response_editor", ")", ";", "$", "wrongkey", "=", "key", "(", "$", "properties", "->", "response_editor", ")", ";", "$", "properties", "->", "answer_editor", "[", "$", "wrongkey", "]", "=", "LESSON_OTHER_ANSWERS", ";", "}", "parent", "::", "create_answers", "(", "$", "properties", ")", ";", "}" ]
Creates answers for this page type. @param object $properties The answer properties.
[ "Creates", "answers", "for", "this", "page", "type", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/pagetypes/shortanswer.php#L80-L90
213,078
moodle/moodle
mod/lesson/pagetypes/shortanswer.php
lesson_page_type_shortanswer.update
public function update($properties, $context = null, $maxbytes = null) { if ($properties->enableotheranswers) { $properties->response_editor = array_values($properties->response_editor); $properties->jumpto = array_values($properties->jumpto); $properties->score = array_values($properties->score); $wrongresponse = end($properties->response_editor); $wrongkey = key($properties->response_editor); $properties->answer_editor[$wrongkey] = LESSON_OTHER_ANSWERS; } parent::update($properties, $context, $maxbytes); }
php
public function update($properties, $context = null, $maxbytes = null) { if ($properties->enableotheranswers) { $properties->response_editor = array_values($properties->response_editor); $properties->jumpto = array_values($properties->jumpto); $properties->score = array_values($properties->score); $wrongresponse = end($properties->response_editor); $wrongkey = key($properties->response_editor); $properties->answer_editor[$wrongkey] = LESSON_OTHER_ANSWERS; } parent::update($properties, $context, $maxbytes); }
[ "public", "function", "update", "(", "$", "properties", ",", "$", "context", "=", "null", ",", "$", "maxbytes", "=", "null", ")", "{", "if", "(", "$", "properties", "->", "enableotheranswers", ")", "{", "$", "properties", "->", "response_editor", "=", "array_values", "(", "$", "properties", "->", "response_editor", ")", ";", "$", "properties", "->", "jumpto", "=", "array_values", "(", "$", "properties", "->", "jumpto", ")", ";", "$", "properties", "->", "score", "=", "array_values", "(", "$", "properties", "->", "score", ")", ";", "$", "wrongresponse", "=", "end", "(", "$", "properties", "->", "response_editor", ")", ";", "$", "wrongkey", "=", "key", "(", "$", "properties", "->", "response_editor", ")", ";", "$", "properties", "->", "answer_editor", "[", "$", "wrongkey", "]", "=", "LESSON_OTHER_ANSWERS", ";", "}", "parent", "::", "update", "(", "$", "properties", ",", "$", "context", ",", "$", "maxbytes", ")", ";", "}" ]
Update the answers for this page type. @param object $properties The answer properties. @param context $context The context for this module. @param int $maxbytes The maximum bytes for any uploades.
[ "Update", "the", "answers", "for", "this", "page", "type", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/pagetypes/shortanswer.php#L99-L109
213,079
moodle/moodle
mod/lesson/pagetypes/shortanswer.php
lesson_page_type_shortanswer.update_form_data
public function update_form_data(stdClass $data) : stdClass { $answercount = count($this->get_answers()); // Check for other answer entry. $lastanswer = $data->{'answer_editor[' . ($answercount - 1) . ']'}; if (strpos($lastanswer, LESSON_OTHER_ANSWERS) !== false) { $data->{'answer_editor[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'answer_editor[' . ($answercount - 1) . ']'}; $data->{'response_editor[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'response_editor[' . ($answercount - 1) . ']'}; $data->{'jumpto[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'jumpto[' . ($answercount - 1) . ']'}; $data->{'score[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'score[' . ($answercount - 1) . ']'}; $data->enableotheranswers = true; // Unset the old values. unset($data->{'answer_editor[' . ($answercount - 1) . ']'}); unset($data->{'response_editor[' . ($answercount - 1) . ']'}); unset($data->{'jumpto[' . ($answercount - 1) . ']'}); unset($data->{'score[' . ($answercount - 1) . ']'}); } return $data; }
php
public function update_form_data(stdClass $data) : stdClass { $answercount = count($this->get_answers()); // Check for other answer entry. $lastanswer = $data->{'answer_editor[' . ($answercount - 1) . ']'}; if (strpos($lastanswer, LESSON_OTHER_ANSWERS) !== false) { $data->{'answer_editor[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'answer_editor[' . ($answercount - 1) . ']'}; $data->{'response_editor[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'response_editor[' . ($answercount - 1) . ']'}; $data->{'jumpto[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'jumpto[' . ($answercount - 1) . ']'}; $data->{'score[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'score[' . ($answercount - 1) . ']'}; $data->enableotheranswers = true; // Unset the old values. unset($data->{'answer_editor[' . ($answercount - 1) . ']'}); unset($data->{'response_editor[' . ($answercount - 1) . ']'}); unset($data->{'jumpto[' . ($answercount - 1) . ']'}); unset($data->{'score[' . ($answercount - 1) . ']'}); } return $data; }
[ "public", "function", "update_form_data", "(", "stdClass", "$", "data", ")", ":", "stdClass", "{", "$", "answercount", "=", "count", "(", "$", "this", "->", "get_answers", "(", ")", ")", ";", "// Check for other answer entry.", "$", "lastanswer", "=", "$", "data", "->", "{", "'answer_editor['", ".", "(", "$", "answercount", "-", "1", ")", ".", "']'", "}", ";", "if", "(", "strpos", "(", "$", "lastanswer", ",", "LESSON_OTHER_ANSWERS", ")", "!==", "false", ")", "{", "$", "data", "->", "{", "'answer_editor['", ".", "(", "$", "this", "->", "lesson", "->", "maxanswers", "+", "1", ")", ".", "']'", "}", "=", "$", "data", "->", "{", "'answer_editor['", ".", "(", "$", "answercount", "-", "1", ")", ".", "']'", "}", ";", "$", "data", "->", "{", "'response_editor['", ".", "(", "$", "this", "->", "lesson", "->", "maxanswers", "+", "1", ")", ".", "']'", "}", "=", "$", "data", "->", "{", "'response_editor['", ".", "(", "$", "answercount", "-", "1", ")", ".", "']'", "}", ";", "$", "data", "->", "{", "'jumpto['", ".", "(", "$", "this", "->", "lesson", "->", "maxanswers", "+", "1", ")", ".", "']'", "}", "=", "$", "data", "->", "{", "'jumpto['", ".", "(", "$", "answercount", "-", "1", ")", ".", "']'", "}", ";", "$", "data", "->", "{", "'score['", ".", "(", "$", "this", "->", "lesson", "->", "maxanswers", "+", "1", ")", ".", "']'", "}", "=", "$", "data", "->", "{", "'score['", ".", "(", "$", "answercount", "-", "1", ")", ".", "']'", "}", ";", "$", "data", "->", "enableotheranswers", "=", "true", ";", "// Unset the old values.", "unset", "(", "$", "data", "->", "{", "'answer_editor['", ".", "(", "$", "answercount", "-", "1", ")", ".", "']'", "}", ")", ";", "unset", "(", "$", "data", "->", "{", "'response_editor['", ".", "(", "$", "answercount", "-", "1", ")", ".", "']'", "}", ")", ";", "unset", "(", "$", "data", "->", "{", "'jumpto['", ".", "(", "$", "answercount", "-", "1", ")", ".", "']'", "}", ")", ";", "unset", "(", "$", "data", "->", "{", "'score['", ".", "(", "$", "answercount", "-", "1", ")", ".", "']'", "}", ")", ";", "}", "return", "$", "data", ";", "}" ]
Make updates to the form data if required. In this case to put the all other answer data into the write section of the form. @param stdClass $data The form data to update. @return stdClass The updated fom data.
[ "Make", "updates", "to", "the", "form", "data", "if", "required", ".", "In", "this", "case", "to", "put", "the", "all", "other", "answer", "data", "into", "the", "write", "section", "of", "the", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/pagetypes/shortanswer.php#L393-L412
213,080
moodle/moodle
backup/util/dbops/backup_structure_dbops.class.php
backup_structure_dbops.annotate_files
public static function annotate_files($backupid, $contextid, $component, $filearea, $itemid, \core\progress\base $progress = null) { global $DB; $sql = 'SELECT id FROM {files} WHERE contextid = ? AND component = ?'; $params = array($contextid, $component); if (!is_null($filearea)) { // Add filearea to query and params if necessary $sql .= ' AND filearea = ?'; $params[] = $filearea; } if (!is_null($itemid)) { // Add itemid to query and params if necessary $sql .= ' AND itemid = ?'; $params[] = $itemid; } if ($progress) { $progress->start_progress(''); } $rs = $DB->get_recordset_sql($sql, $params); foreach ($rs as $record) { if ($progress) { $progress->progress(); } self::insert_backup_ids_record($backupid, 'file', $record->id); } if ($progress) { $progress->end_progress(); } $rs->close(); }
php
public static function annotate_files($backupid, $contextid, $component, $filearea, $itemid, \core\progress\base $progress = null) { global $DB; $sql = 'SELECT id FROM {files} WHERE contextid = ? AND component = ?'; $params = array($contextid, $component); if (!is_null($filearea)) { // Add filearea to query and params if necessary $sql .= ' AND filearea = ?'; $params[] = $filearea; } if (!is_null($itemid)) { // Add itemid to query and params if necessary $sql .= ' AND itemid = ?'; $params[] = $itemid; } if ($progress) { $progress->start_progress(''); } $rs = $DB->get_recordset_sql($sql, $params); foreach ($rs as $record) { if ($progress) { $progress->progress(); } self::insert_backup_ids_record($backupid, 'file', $record->id); } if ($progress) { $progress->end_progress(); } $rs->close(); }
[ "public", "static", "function", "annotate_files", "(", "$", "backupid", ",", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "\\", "core", "\\", "progress", "\\", "base", "$", "progress", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "'SELECT id\n FROM {files}\n WHERE contextid = ?\n AND component = ?'", ";", "$", "params", "=", "array", "(", "$", "contextid", ",", "$", "component", ")", ";", "if", "(", "!", "is_null", "(", "$", "filearea", ")", ")", "{", "// Add filearea to query and params if necessary", "$", "sql", ".=", "' AND filearea = ?'", ";", "$", "params", "[", "]", "=", "$", "filearea", ";", "}", "if", "(", "!", "is_null", "(", "$", "itemid", ")", ")", "{", "// Add itemid to query and params if necessary", "$", "sql", ".=", "' AND itemid = ?'", ";", "$", "params", "[", "]", "=", "$", "itemid", ";", "}", "if", "(", "$", "progress", ")", "{", "$", "progress", "->", "start_progress", "(", "''", ")", ";", "}", "$", "rs", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "foreach", "(", "$", "rs", "as", "$", "record", ")", "{", "if", "(", "$", "progress", ")", "{", "$", "progress", "->", "progress", "(", ")", ";", "}", "self", "::", "insert_backup_ids_record", "(", "$", "backupid", ",", "'file'", ",", "$", "record", "->", "id", ")", ";", "}", "if", "(", "$", "progress", ")", "{", "$", "progress", "->", "end_progress", "(", ")", ";", "}", "$", "rs", "->", "close", "(", ")", ";", "}" ]
Adds backup id database record for all files in the given file area. @param string $backupid Backup ID @param int $contextid Context id @param string $component Component @param string $filearea File area @param int $itemid Item id @param \core\progress\base $progress
[ "Adds", "backup", "id", "database", "record", "for", "all", "files", "in", "the", "given", "file", "area", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_structure_dbops.class.php#L118-L150
213,081
moodle/moodle
backup/util/dbops/backup_structure_dbops.class.php
backup_structure_dbops.move_annotations_to_final
public static function move_annotations_to_final($backupid, $itemname, \core\progress\base $progress) { global $DB; $progress->start_progress('move_annotations_to_final'); $rs = $DB->get_recordset('backup_ids_temp', array('backupid' => $backupid, 'itemname' => $itemname)); $progress->progress(); foreach($rs as $annotation) { // If corresponding 'itemfinal' annotation does not exist, update 'item' to 'itemfinal' if (! $DB->record_exists('backup_ids_temp', array('backupid' => $backupid, 'itemname' => $itemname . 'final', 'itemid' => $annotation->itemid))) { $DB->set_field('backup_ids_temp', 'itemname', $itemname . 'final', array('id' => $annotation->id)); } $progress->progress(); } $rs->close(); // All the remaining $itemname annotations can be safely deleted $DB->delete_records('backup_ids_temp', array('backupid' => $backupid, 'itemname' => $itemname)); $progress->end_progress(); }
php
public static function move_annotations_to_final($backupid, $itemname, \core\progress\base $progress) { global $DB; $progress->start_progress('move_annotations_to_final'); $rs = $DB->get_recordset('backup_ids_temp', array('backupid' => $backupid, 'itemname' => $itemname)); $progress->progress(); foreach($rs as $annotation) { // If corresponding 'itemfinal' annotation does not exist, update 'item' to 'itemfinal' if (! $DB->record_exists('backup_ids_temp', array('backupid' => $backupid, 'itemname' => $itemname . 'final', 'itemid' => $annotation->itemid))) { $DB->set_field('backup_ids_temp', 'itemname', $itemname . 'final', array('id' => $annotation->id)); } $progress->progress(); } $rs->close(); // All the remaining $itemname annotations can be safely deleted $DB->delete_records('backup_ids_temp', array('backupid' => $backupid, 'itemname' => $itemname)); $progress->end_progress(); }
[ "public", "static", "function", "move_annotations_to_final", "(", "$", "backupid", ",", "$", "itemname", ",", "\\", "core", "\\", "progress", "\\", "base", "$", "progress", ")", "{", "global", "$", "DB", ";", "$", "progress", "->", "start_progress", "(", "'move_annotations_to_final'", ")", ";", "$", "rs", "=", "$", "DB", "->", "get_recordset", "(", "'backup_ids_temp'", ",", "array", "(", "'backupid'", "=>", "$", "backupid", ",", "'itemname'", "=>", "$", "itemname", ")", ")", ";", "$", "progress", "->", "progress", "(", ")", ";", "foreach", "(", "$", "rs", "as", "$", "annotation", ")", "{", "// If corresponding 'itemfinal' annotation does not exist, update 'item' to 'itemfinal'", "if", "(", "!", "$", "DB", "->", "record_exists", "(", "'backup_ids_temp'", ",", "array", "(", "'backupid'", "=>", "$", "backupid", ",", "'itemname'", "=>", "$", "itemname", ".", "'final'", ",", "'itemid'", "=>", "$", "annotation", "->", "itemid", ")", ")", ")", "{", "$", "DB", "->", "set_field", "(", "'backup_ids_temp'", ",", "'itemname'", ",", "$", "itemname", ".", "'final'", ",", "array", "(", "'id'", "=>", "$", "annotation", "->", "id", ")", ")", ";", "}", "$", "progress", "->", "progress", "(", ")", ";", "}", "$", "rs", "->", "close", "(", ")", ";", "// All the remaining $itemname annotations can be safely deleted", "$", "DB", "->", "delete_records", "(", "'backup_ids_temp'", ",", "array", "(", "'backupid'", "=>", "$", "backupid", ",", "'itemname'", "=>", "$", "itemname", ")", ")", ";", "$", "progress", "->", "end_progress", "(", ")", ";", "}" ]
Moves all the existing 'item' annotations to their final 'itemfinal' ones for a given backup. @param string $backupid Backup ID @param string $itemname Item name @param \core\progress\base $progress Progress tracker
[ "Moves", "all", "the", "existing", "item", "annotations", "to", "their", "final", "itemfinal", "ones", "for", "a", "given", "backup", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_structure_dbops.class.php#L160-L178
213,082
moodle/moodle
lib/classes/task/grade_history_cleanup_task.php
grade_history_cleanup_task.execute
public function execute() { global $CFG, $DB; if (!empty($CFG->gradehistorylifetime)) { $now = time(); $histlifetime = $now - ($CFG->gradehistorylifetime * DAYSECS); $tables = [ 'grade_outcomes_history', 'grade_categories_history', 'grade_items_history', 'grade_grades_history', 'scale_history' ]; foreach ($tables as $table) { if ($DB->delete_records_select($table, "timemodified < ?", [$histlifetime])) { mtrace(" Deleted old grade history records from '$table'"); } } } }
php
public function execute() { global $CFG, $DB; if (!empty($CFG->gradehistorylifetime)) { $now = time(); $histlifetime = $now - ($CFG->gradehistorylifetime * DAYSECS); $tables = [ 'grade_outcomes_history', 'grade_categories_history', 'grade_items_history', 'grade_grades_history', 'scale_history' ]; foreach ($tables as $table) { if ($DB->delete_records_select($table, "timemodified < ?", [$histlifetime])) { mtrace(" Deleted old grade history records from '$table'"); } } } }
[ "public", "function", "execute", "(", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "gradehistorylifetime", ")", ")", "{", "$", "now", "=", "time", "(", ")", ";", "$", "histlifetime", "=", "$", "now", "-", "(", "$", "CFG", "->", "gradehistorylifetime", "*", "DAYSECS", ")", ";", "$", "tables", "=", "[", "'grade_outcomes_history'", ",", "'grade_categories_history'", ",", "'grade_items_history'", ",", "'grade_grades_history'", ",", "'scale_history'", "]", ";", "foreach", "(", "$", "tables", "as", "$", "table", ")", "{", "if", "(", "$", "DB", "->", "delete_records_select", "(", "$", "table", ",", "\"timemodified < ?\"", ",", "[", "$", "histlifetime", "]", ")", ")", "{", "mtrace", "(", "\" Deleted old grade history records from '$table'\"", ")", ";", "}", "}", "}", "}" ]
Cleanup history tables.
[ "Cleanup", "history", "tables", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/grade_history_cleanup_task.php#L47-L66
213,083
moodle/moodle
user/classes/output/myprofile/category.php
category.sort_nodes
public function sort_nodes() { $tempnodes = array(); $this->validate_after_order(); // First content noes. foreach ($this->nodes as $node) { $after = $node->after; $content = $node->content; if (($after == null && !empty($content)) || $node->name === 'editprofile') { // Can go anywhere in the cat. Also show content nodes first. $tempnodes = array_merge($tempnodes, array($node->name => $node), $this->find_nodes_after($node)); } } // Now nodes with no content. foreach ($this->nodes as $node) { $after = $node->after; $content = $node->content; if ($after == null && empty($content)) { // Can go anywhere in the cat. Also show content nodes first. $tempnodes = array_merge($tempnodes, array($node->name => $node), $this->find_nodes_after($node)); } } if (count($tempnodes) !== count($this->nodes)) { // Orphan nodes found. throw new \coding_exception('Some of the nodes specified contains invalid \'after\' property'); } $this->nodes = $tempnodes; }
php
public function sort_nodes() { $tempnodes = array(); $this->validate_after_order(); // First content noes. foreach ($this->nodes as $node) { $after = $node->after; $content = $node->content; if (($after == null && !empty($content)) || $node->name === 'editprofile') { // Can go anywhere in the cat. Also show content nodes first. $tempnodes = array_merge($tempnodes, array($node->name => $node), $this->find_nodes_after($node)); } } // Now nodes with no content. foreach ($this->nodes as $node) { $after = $node->after; $content = $node->content; if ($after == null && empty($content)) { // Can go anywhere in the cat. Also show content nodes first. $tempnodes = array_merge($tempnodes, array($node->name => $node), $this->find_nodes_after($node)); } } if (count($tempnodes) !== count($this->nodes)) { // Orphan nodes found. throw new \coding_exception('Some of the nodes specified contains invalid \'after\' property'); } $this->nodes = $tempnodes; }
[ "public", "function", "sort_nodes", "(", ")", "{", "$", "tempnodes", "=", "array", "(", ")", ";", "$", "this", "->", "validate_after_order", "(", ")", ";", "// First content noes.", "foreach", "(", "$", "this", "->", "nodes", "as", "$", "node", ")", "{", "$", "after", "=", "$", "node", "->", "after", ";", "$", "content", "=", "$", "node", "->", "content", ";", "if", "(", "(", "$", "after", "==", "null", "&&", "!", "empty", "(", "$", "content", ")", ")", "||", "$", "node", "->", "name", "===", "'editprofile'", ")", "{", "// Can go anywhere in the cat. Also show content nodes first.", "$", "tempnodes", "=", "array_merge", "(", "$", "tempnodes", ",", "array", "(", "$", "node", "->", "name", "=>", "$", "node", ")", ",", "$", "this", "->", "find_nodes_after", "(", "$", "node", ")", ")", ";", "}", "}", "// Now nodes with no content.", "foreach", "(", "$", "this", "->", "nodes", "as", "$", "node", ")", "{", "$", "after", "=", "$", "node", "->", "after", ";", "$", "content", "=", "$", "node", "->", "content", ";", "if", "(", "$", "after", "==", "null", "&&", "empty", "(", "$", "content", ")", ")", "{", "// Can go anywhere in the cat. Also show content nodes first.", "$", "tempnodes", "=", "array_merge", "(", "$", "tempnodes", ",", "array", "(", "$", "node", "->", "name", "=>", "$", "node", ")", ",", "$", "this", "->", "find_nodes_after", "(", "$", "node", ")", ")", ";", "}", "}", "if", "(", "count", "(", "$", "tempnodes", ")", "!==", "count", "(", "$", "this", "->", "nodes", ")", ")", "{", "// Orphan nodes found.", "throw", "new", "\\", "coding_exception", "(", "'Some of the nodes specified contains invalid \\'after\\' property'", ")", ";", "}", "$", "this", "->", "nodes", "=", "$", "tempnodes", ";", "}" ]
Sort nodes of the category in the order in which they should be displayed. @see \core_user\output\myprofile\tree::sort_categories() @throws \coding_exception
[ "Sort", "nodes", "of", "the", "category", "in", "the", "order", "in", "which", "they", "should", "be", "displayed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/output/myprofile/category.php#L108-L137
213,084
moodle/moodle
user/classes/output/myprofile/category.php
category.validate_after_order
protected function validate_after_order() { $nodearray = $this->nodes; foreach ($this->nodes as $node) { $after = $node->after; if (!empty($after)) { if (empty($nodearray[$after])) { throw new \coding_exception('node {$node->name} specified contains invalid \'after\' property'); } else { // Valid node found. $afternode = $nodearray[$after]; $beforecontent = $node->content; $aftercontent = $afternode->content; if ((empty($beforecontent) && !empty($aftercontent)) || (!empty($beforecontent) && empty($aftercontent))) { // Only node with content are allowed after content nodes. Same goes for no content nodes. throw new \coding_exception('node {$node->name} specified contains invalid \'after\' property'); } } } } }
php
protected function validate_after_order() { $nodearray = $this->nodes; foreach ($this->nodes as $node) { $after = $node->after; if (!empty($after)) { if (empty($nodearray[$after])) { throw new \coding_exception('node {$node->name} specified contains invalid \'after\' property'); } else { // Valid node found. $afternode = $nodearray[$after]; $beforecontent = $node->content; $aftercontent = $afternode->content; if ((empty($beforecontent) && !empty($aftercontent)) || (!empty($beforecontent) && empty($aftercontent))) { // Only node with content are allowed after content nodes. Same goes for no content nodes. throw new \coding_exception('node {$node->name} specified contains invalid \'after\' property'); } } } } }
[ "protected", "function", "validate_after_order", "(", ")", "{", "$", "nodearray", "=", "$", "this", "->", "nodes", ";", "foreach", "(", "$", "this", "->", "nodes", "as", "$", "node", ")", "{", "$", "after", "=", "$", "node", "->", "after", ";", "if", "(", "!", "empty", "(", "$", "after", ")", ")", "{", "if", "(", "empty", "(", "$", "nodearray", "[", "$", "after", "]", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'node {$node->name} specified contains invalid \\'after\\' property'", ")", ";", "}", "else", "{", "// Valid node found.", "$", "afternode", "=", "$", "nodearray", "[", "$", "after", "]", ";", "$", "beforecontent", "=", "$", "node", "->", "content", ";", "$", "aftercontent", "=", "$", "afternode", "->", "content", ";", "if", "(", "(", "empty", "(", "$", "beforecontent", ")", "&&", "!", "empty", "(", "$", "aftercontent", ")", ")", "||", "(", "!", "empty", "(", "$", "beforecontent", ")", "&&", "empty", "(", "$", "aftercontent", ")", ")", ")", "{", "// Only node with content are allowed after content nodes. Same goes for no content nodes.", "throw", "new", "\\", "coding_exception", "(", "'node {$node->name} specified contains invalid \\'after\\' property'", ")", ";", "}", "}", "}", "}", "}" ]
Verifies that node with content can come after node with content only . Also verifies the same thing for nodes without content. @throws \coding_exception
[ "Verifies", "that", "node", "with", "content", "can", "come", "after", "node", "with", "content", "only", ".", "Also", "verifies", "the", "same", "thing", "for", "nodes", "without", "content", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/output/myprofile/category.php#L144-L164
213,085
moodle/moodle
user/classes/output/myprofile/category.php
category.find_nodes_after
protected function find_nodes_after($node) { $return = array(); $nodearray = $this->nodes; foreach ($nodearray as $nodeelement) { if ($nodeelement->after === $node->name) { // Find all nodes that comes after this node as well. $return = array_merge($return, array($nodeelement->name => $nodeelement), $this->find_nodes_after($nodeelement)); } } return $return; }
php
protected function find_nodes_after($node) { $return = array(); $nodearray = $this->nodes; foreach ($nodearray as $nodeelement) { if ($nodeelement->after === $node->name) { // Find all nodes that comes after this node as well. $return = array_merge($return, array($nodeelement->name => $nodeelement), $this->find_nodes_after($nodeelement)); } } return $return; }
[ "protected", "function", "find_nodes_after", "(", "$", "node", ")", "{", "$", "return", "=", "array", "(", ")", ";", "$", "nodearray", "=", "$", "this", "->", "nodes", ";", "foreach", "(", "$", "nodearray", "as", "$", "nodeelement", ")", "{", "if", "(", "$", "nodeelement", "->", "after", "===", "$", "node", "->", "name", ")", "{", "// Find all nodes that comes after this node as well.", "$", "return", "=", "array_merge", "(", "$", "return", ",", "array", "(", "$", "nodeelement", "->", "name", "=>", "$", "nodeelement", ")", ",", "$", "this", "->", "find_nodes_after", "(", "$", "nodeelement", ")", ")", ";", "}", "}", "return", "$", "return", ";", "}" ]
Given a node object find all node objects that should appear after it. @param node $node node object @return array
[ "Given", "a", "node", "object", "find", "all", "node", "objects", "that", "should", "appear", "after", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/output/myprofile/category.php#L173-L183
213,086
moodle/moodle
auth/cas/auth.php
auth_plugin_cas.user_login
function user_login ($username, $password) { $this->connectCAS(); return phpCAS::isAuthenticated() && (trim(core_text::strtolower(phpCAS::getUser())) == $username); }
php
function user_login ($username, $password) { $this->connectCAS(); return phpCAS::isAuthenticated() && (trim(core_text::strtolower(phpCAS::getUser())) == $username); }
[ "function", "user_login", "(", "$", "username", ",", "$", "password", ")", "{", "$", "this", "->", "connectCAS", "(", ")", ";", "return", "phpCAS", "::", "isAuthenticated", "(", ")", "&&", "(", "trim", "(", "core_text", "::", "strtolower", "(", "phpCAS", "::", "getUser", "(", ")", ")", ")", "==", "$", "username", ")", ";", "}" ]
Authenticates user against CAS Returns true if the username and password work and false if they are wrong or don't exist. @param string $username The username (with system magic quotes) @param string $password The password (with system magic quotes) @return bool Authentication success or failure.
[ "Authenticates", "user", "against", "CAS", "Returns", "true", "if", "the", "username", "and", "password", "work", "and", "false", "if", "they", "are", "wrong", "or", "don", "t", "exist", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/auth.php#L72-L75
213,087
moodle/moodle
auth/cas/auth.php
auth_plugin_cas.sync_users
function sync_users($do_updates=true) { if (empty($this->config->host_url)) { error_log('[AUTH CAS] '.get_string('noldapserver', 'auth_cas')); return; } parent::sync_users($do_updates); }
php
function sync_users($do_updates=true) { if (empty($this->config->host_url)) { error_log('[AUTH CAS] '.get_string('noldapserver', 'auth_cas')); return; } parent::sync_users($do_updates); }
[ "function", "sync_users", "(", "$", "do_updates", "=", "true", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "config", "->", "host_url", ")", ")", "{", "error_log", "(", "'[AUTH CAS] '", ".", "get_string", "(", "'noldapserver'", ",", "'auth_cas'", ")", ")", ";", "return", ";", "}", "parent", "::", "sync_users", "(", "$", "do_updates", ")", ";", "}" ]
Syncronizes users from LDAP server to moodle user table. If no LDAP servers are configured, simply return. Otherwise, call parent class method to do the work. @param bool $do_updates will do pull in data updates from LDAP if relevant @return nothing
[ "Syncronizes", "users", "from", "LDAP", "server", "to", "moodle", "user", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/auth.php#L314-L320
213,088
moodle/moodle
auth/cas/auth.php
auth_plugin_cas.postlogout_hook
public function postlogout_hook($user) { global $CFG; // Only redirect to CAS logout if the user is logged as a CAS user. if (!empty($this->config->logoutcas) && $user->auth == $this->authtype) { $backurl = !empty($this->config->logout_return_url) ? $this->config->logout_return_url : $CFG->wwwroot; $this->connectCAS(); phpCAS::logoutWithRedirectService($backurl); } }
php
public function postlogout_hook($user) { global $CFG; // Only redirect to CAS logout if the user is logged as a CAS user. if (!empty($this->config->logoutcas) && $user->auth == $this->authtype) { $backurl = !empty($this->config->logout_return_url) ? $this->config->logout_return_url : $CFG->wwwroot; $this->connectCAS(); phpCAS::logoutWithRedirectService($backurl); } }
[ "public", "function", "postlogout_hook", "(", "$", "user", ")", "{", "global", "$", "CFG", ";", "// Only redirect to CAS logout if the user is logged as a CAS user.", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "logoutcas", ")", "&&", "$", "user", "->", "auth", "==", "$", "this", "->", "authtype", ")", "{", "$", "backurl", "=", "!", "empty", "(", "$", "this", "->", "config", "->", "logout_return_url", ")", "?", "$", "this", "->", "config", "->", "logout_return_url", ":", "$", "CFG", "->", "wwwroot", ";", "$", "this", "->", "connectCAS", "(", ")", ";", "phpCAS", "::", "logoutWithRedirectService", "(", "$", "backurl", ")", ";", "}", "}" ]
Post logout hook. Note: this method replace the prelogout_hook method to avoid redirect to CAS logout before the event userlogout being triggered. @param stdClass $user clone of USER object object before the user session was terminated
[ "Post", "logout", "hook", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/auth.php#L346-L354
213,089
moodle/moodle
admin/tool/log/store/legacy/classes/log/store.php
store.replace_sql_legacy
protected static function replace_sql_legacy($selectwhere, array $params, $sort = '') { // Following mapping is done to make can_delete_course() compatible with legacy store. if ($selectwhere == "userid = :userid AND courseid = :courseid AND eventname = :eventname AND timecreated > :since" and empty($sort)) { $replace = "module = 'course' AND action = 'new' AND userid = :userid AND url = :url AND time > :since"; $params += array('url' => "view.php?id={$params['courseid']}"); return array($replace, $params, $sort); } // Replace db field names to make it compatible with legacy log. foreach (self::$standardtolegacyfields as $from => $to) { $selectwhere = str_replace($from, $to, $selectwhere); if (!empty($sort)) { $sort = str_replace($from, $to, $sort); } if (isset($params[$from])) { $params[$to] = $params[$from]; unset($params[$from]); } } // Replace crud fields. $selectwhere = preg_replace_callback("/(crud).*?(<>|=|!=).*?'(.*?)'/s", 'self::replace_crud', $selectwhere); return array($selectwhere, $params, $sort); }
php
protected static function replace_sql_legacy($selectwhere, array $params, $sort = '') { // Following mapping is done to make can_delete_course() compatible with legacy store. if ($selectwhere == "userid = :userid AND courseid = :courseid AND eventname = :eventname AND timecreated > :since" and empty($sort)) { $replace = "module = 'course' AND action = 'new' AND userid = :userid AND url = :url AND time > :since"; $params += array('url' => "view.php?id={$params['courseid']}"); return array($replace, $params, $sort); } // Replace db field names to make it compatible with legacy log. foreach (self::$standardtolegacyfields as $from => $to) { $selectwhere = str_replace($from, $to, $selectwhere); if (!empty($sort)) { $sort = str_replace($from, $to, $sort); } if (isset($params[$from])) { $params[$to] = $params[$from]; unset($params[$from]); } } // Replace crud fields. $selectwhere = preg_replace_callback("/(crud).*?(<>|=|!=).*?'(.*?)'/s", 'self::replace_crud', $selectwhere); return array($selectwhere, $params, $sort); }
[ "protected", "static", "function", "replace_sql_legacy", "(", "$", "selectwhere", ",", "array", "$", "params", ",", "$", "sort", "=", "''", ")", "{", "// Following mapping is done to make can_delete_course() compatible with legacy store.", "if", "(", "$", "selectwhere", "==", "\"userid = :userid AND courseid = :courseid AND eventname = :eventname AND timecreated > :since\"", "and", "empty", "(", "$", "sort", ")", ")", "{", "$", "replace", "=", "\"module = 'course' AND action = 'new' AND userid = :userid AND url = :url AND time > :since\"", ";", "$", "params", "+=", "array", "(", "'url'", "=>", "\"view.php?id={$params['courseid']}\"", ")", ";", "return", "array", "(", "$", "replace", ",", "$", "params", ",", "$", "sort", ")", ";", "}", "// Replace db field names to make it compatible with legacy log.", "foreach", "(", "self", "::", "$", "standardtolegacyfields", "as", "$", "from", "=>", "$", "to", ")", "{", "$", "selectwhere", "=", "str_replace", "(", "$", "from", ",", "$", "to", ",", "$", "selectwhere", ")", ";", "if", "(", "!", "empty", "(", "$", "sort", ")", ")", "{", "$", "sort", "=", "str_replace", "(", "$", "from", ",", "$", "to", ",", "$", "sort", ")", ";", "}", "if", "(", "isset", "(", "$", "params", "[", "$", "from", "]", ")", ")", "{", "$", "params", "[", "$", "to", "]", "=", "$", "params", "[", "$", "from", "]", ";", "unset", "(", "$", "params", "[", "$", "from", "]", ")", ";", "}", "}", "// Replace crud fields.", "$", "selectwhere", "=", "preg_replace_callback", "(", "\"/(crud).*?(<>|=|!=).*?'(.*?)'/s\"", ",", "'self::replace_crud'", ",", "$", "selectwhere", ")", ";", "return", "array", "(", "$", "selectwhere", ",", "$", "params", ",", "$", "sort", ")", ";", "}" ]
This method contains mapping required for Moodle core to make legacy store compatible with other sql_reader based queries. @param string $selectwhere Select statment @param array $params params for the sql @param string $sort sort fields @return array returns an array containing the sql predicate, an array of params and sorting parameter.
[ "This", "method", "contains", "mapping", "required", "for", "Moodle", "core", "to", "make", "legacy", "store", "compatible", "with", "other", "sql_reader", "based", "queries", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/store/legacy/classes/log/store.php#L67-L92
213,090
moodle/moodle
mod/book/backup/moodle2/restore_book_stepslib.php
restore_book_activity_structure_step.process_book_chapter
protected function process_book_chapter($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->course = $this->get_courseid(); $data->bookid = $this->get_new_parentid('book'); $newitemid = $DB->insert_record('book_chapters', $data); $this->set_mapping('book_chapter', $oldid, $newitemid, true); }
php
protected function process_book_chapter($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->course = $this->get_courseid(); $data->bookid = $this->get_new_parentid('book'); $newitemid = $DB->insert_record('book_chapters', $data); $this->set_mapping('book_chapter', $oldid, $newitemid, true); }
[ "protected", "function", "process_book_chapter", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "oldid", "=", "$", "data", "->", "id", ";", "$", "data", "->", "course", "=", "$", "this", "->", "get_courseid", "(", ")", ";", "$", "data", "->", "bookid", "=", "$", "this", "->", "get_new_parentid", "(", "'book'", ")", ";", "$", "newitemid", "=", "$", "DB", "->", "insert_record", "(", "'book_chapters'", ",", "$", "data", ")", ";", "$", "this", "->", "set_mapping", "(", "'book_chapter'", ",", "$", "oldid", ",", "$", "newitemid", ",", "true", ")", ";", "}" ]
Process chapter tag information @param array $data information
[ "Process", "chapter", "tag", "information" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/book/backup/moodle2/restore_book_stepslib.php#L65-L76
213,091
moodle/moodle
user/classes/output/myprofile/manager.php
manager.build_tree
public static function build_tree($user, $iscurrentuser, $course = null) { global $CFG; $tree = new tree(); // Add core nodes. require_once($CFG->libdir . "/myprofilelib.php"); core_myprofile_navigation($tree, $user, $iscurrentuser, $course); // Core components. $components = \core_component::get_core_subsystems(); foreach ($components as $component => $directory) { if (empty($directory)) { continue; } $file = $directory . "/lib.php"; if (is_readable($file)) { require_once($file); $function = "core_" . $component . "_myprofile_navigation"; if (function_exists($function)) { $function($tree, $user, $iscurrentuser, $course); } } } // Plugins. $pluginswithfunction = get_plugins_with_function('myprofile_navigation', 'lib.php'); foreach ($pluginswithfunction as $plugins) { foreach ($plugins as $function) { $function($tree, $user, $iscurrentuser, $course); } } $tree->sort_categories(); return $tree; }
php
public static function build_tree($user, $iscurrentuser, $course = null) { global $CFG; $tree = new tree(); // Add core nodes. require_once($CFG->libdir . "/myprofilelib.php"); core_myprofile_navigation($tree, $user, $iscurrentuser, $course); // Core components. $components = \core_component::get_core_subsystems(); foreach ($components as $component => $directory) { if (empty($directory)) { continue; } $file = $directory . "/lib.php"; if (is_readable($file)) { require_once($file); $function = "core_" . $component . "_myprofile_navigation"; if (function_exists($function)) { $function($tree, $user, $iscurrentuser, $course); } } } // Plugins. $pluginswithfunction = get_plugins_with_function('myprofile_navigation', 'lib.php'); foreach ($pluginswithfunction as $plugins) { foreach ($plugins as $function) { $function($tree, $user, $iscurrentuser, $course); } } $tree->sort_categories(); return $tree; }
[ "public", "static", "function", "build_tree", "(", "$", "user", ",", "$", "iscurrentuser", ",", "$", "course", "=", "null", ")", "{", "global", "$", "CFG", ";", "$", "tree", "=", "new", "tree", "(", ")", ";", "// Add core nodes.", "require_once", "(", "$", "CFG", "->", "libdir", ".", "\"/myprofilelib.php\"", ")", ";", "core_myprofile_navigation", "(", "$", "tree", ",", "$", "user", ",", "$", "iscurrentuser", ",", "$", "course", ")", ";", "// Core components.", "$", "components", "=", "\\", "core_component", "::", "get_core_subsystems", "(", ")", ";", "foreach", "(", "$", "components", "as", "$", "component", "=>", "$", "directory", ")", "{", "if", "(", "empty", "(", "$", "directory", ")", ")", "{", "continue", ";", "}", "$", "file", "=", "$", "directory", ".", "\"/lib.php\"", ";", "if", "(", "is_readable", "(", "$", "file", ")", ")", "{", "require_once", "(", "$", "file", ")", ";", "$", "function", "=", "\"core_\"", ".", "$", "component", ".", "\"_myprofile_navigation\"", ";", "if", "(", "function_exists", "(", "$", "function", ")", ")", "{", "$", "function", "(", "$", "tree", ",", "$", "user", ",", "$", "iscurrentuser", ",", "$", "course", ")", ";", "}", "}", "}", "// Plugins.", "$", "pluginswithfunction", "=", "get_plugins_with_function", "(", "'myprofile_navigation'", ",", "'lib.php'", ")", ";", "foreach", "(", "$", "pluginswithfunction", "as", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "function", ")", "{", "$", "function", "(", "$", "tree", ",", "$", "user", ",", "$", "iscurrentuser", ",", "$", "course", ")", ";", "}", "}", "$", "tree", "->", "sort_categories", "(", ")", ";", "return", "$", "tree", ";", "}" ]
Parse all callbacks and builds the tree. @param integer $user ID of the user for which the profile is displayed. @param bool $iscurrentuser true if the profile being viewed is of current user, else false. @param \stdClass $course Course object @return tree Fully build tree to be rendered on my profile page.
[ "Parse", "all", "callbacks", "and", "builds", "the", "tree", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/output/myprofile/manager.php#L46-L81
213,092
moodle/moodle
course/switchrole_form.php
switchrole_form.in_alternative_role
protected function in_alternative_role($context) { global $USER, $PAGE; if (!empty($USER->access['rsw']) && is_array($USER->access['rsw'])) { if (!empty($PAGE->context) && !empty($USER->access['rsw'][$PAGE->context->path])) { return $USER->access['rsw'][$PAGE->context->path]; } foreach ($USER->access['rsw'] as $key=>$role) { if (strpos($context->path, $key)===0) { return $role; } } } return false; }
php
protected function in_alternative_role($context) { global $USER, $PAGE; if (!empty($USER->access['rsw']) && is_array($USER->access['rsw'])) { if (!empty($PAGE->context) && !empty($USER->access['rsw'][$PAGE->context->path])) { return $USER->access['rsw'][$PAGE->context->path]; } foreach ($USER->access['rsw'] as $key=>$role) { if (strpos($context->path, $key)===0) { return $role; } } } return false; }
[ "protected", "function", "in_alternative_role", "(", "$", "context", ")", "{", "global", "$", "USER", ",", "$", "PAGE", ";", "if", "(", "!", "empty", "(", "$", "USER", "->", "access", "[", "'rsw'", "]", ")", "&&", "is_array", "(", "$", "USER", "->", "access", "[", "'rsw'", "]", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "PAGE", "->", "context", ")", "&&", "!", "empty", "(", "$", "USER", "->", "access", "[", "'rsw'", "]", "[", "$", "PAGE", "->", "context", "->", "path", "]", ")", ")", "{", "return", "$", "USER", "->", "access", "[", "'rsw'", "]", "[", "$", "PAGE", "->", "context", "->", "path", "]", ";", "}", "foreach", "(", "$", "USER", "->", "access", "[", "'rsw'", "]", "as", "$", "key", "=>", "$", "role", ")", "{", "if", "(", "strpos", "(", "$", "context", "->", "path", ",", "$", "key", ")", "===", "0", ")", "{", "return", "$", "role", ";", "}", "}", "}", "return", "false", ";", "}" ]
Determine whether the user is assuming another role This function checks to see if the user is assuming another role by means of role switching. In doing this we compare each RSW key (context path) against the current context path. This ensures that we can provide the switching options against both the course and any page shown under the course. @param context $context @return bool|int The role(int) if the user is in another role, false otherwise
[ "Determine", "whether", "the", "user", "is", "assuming", "another", "role" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/switchrole_form.php#L46-L59
213,093
moodle/moodle
course/classes/analytics/indicator/potential_cognitive_depth.php
potential_cognitive_depth.get_cognitive_indicator
protected function get_cognitive_indicator($modname) { $indicators = \core_analytics\manager::get_all_indicators(); foreach ($indicators as $indicator) { if ($indicator instanceof community_of_inquiry_activity && $indicator->get_indicator_type() === community_of_inquiry_activity::INDICATOR_COGNITIVE && $indicator->get_activity_type() === $modname) { return $indicator; } } return false; }
php
protected function get_cognitive_indicator($modname) { $indicators = \core_analytics\manager::get_all_indicators(); foreach ($indicators as $indicator) { if ($indicator instanceof community_of_inquiry_activity && $indicator->get_indicator_type() === community_of_inquiry_activity::INDICATOR_COGNITIVE && $indicator->get_activity_type() === $modname) { return $indicator; } } return false; }
[ "protected", "function", "get_cognitive_indicator", "(", "$", "modname", ")", "{", "$", "indicators", "=", "\\", "core_analytics", "\\", "manager", "::", "get_all_indicators", "(", ")", ";", "foreach", "(", "$", "indicators", "as", "$", "indicator", ")", "{", "if", "(", "$", "indicator", "instanceof", "community_of_inquiry_activity", "&&", "$", "indicator", "->", "get_indicator_type", "(", ")", "===", "community_of_inquiry_activity", "::", "INDICATOR_COGNITIVE", "&&", "$", "indicator", "->", "get_activity_type", "(", ")", "===", "$", "modname", ")", "{", "return", "$", "indicator", ";", "}", "}", "return", "false", ";", "}" ]
Returns the cognitive depth class of this indicator. @param string $modname @return \core_analytics\local\indicator\base|false
[ "Returns", "the", "cognitive", "depth", "class", "of", "this", "indicator", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/analytics/indicator/potential_cognitive_depth.php#L125-L135
213,094
moodle/moodle
question/type/ddmarker/shapes.php
qtype_ddmarker_shape.is_only_numbers
protected function is_only_numbers() { $args = func_get_args(); foreach ($args as $arg) { if (0 === preg_match('!^[0-9]+$!', $arg)) { return false; } } return true; }
php
protected function is_only_numbers() { $args = func_get_args(); foreach ($args as $arg) { if (0 === preg_match('!^[0-9]+$!', $arg)) { return false; } } return true; }
[ "protected", "function", "is_only_numbers", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "foreach", "(", "$", "args", "as", "$", "arg", ")", "{", "if", "(", "0", "===", "preg_match", "(", "'!^[0-9]+$!'", ",", "$", "arg", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Test if all passed parameters consist of only numbers. @return bool True if only numbers
[ "Test", "if", "all", "passed", "parameters", "consist", "of", "only", "numbers", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddmarker/shapes.php#L67-L75
213,095
moodle/moodle
question/type/ddmarker/shapes.php
qtype_ddmarker_shape.is_point_in_bounding_box
protected function is_point_in_bounding_box($pointxy, $xleftytop, $xrightybottom) { if ($pointxy[0] < $xleftytop[0]) { return false; } else if ($pointxy[0] > $xrightybottom[0]) { return false; } else if ($pointxy[1] < $xleftytop[1]) { return false; } else if ($pointxy[1] > $xrightybottom[1]) { return false; } return true; }
php
protected function is_point_in_bounding_box($pointxy, $xleftytop, $xrightybottom) { if ($pointxy[0] < $xleftytop[0]) { return false; } else if ($pointxy[0] > $xrightybottom[0]) { return false; } else if ($pointxy[1] < $xleftytop[1]) { return false; } else if ($pointxy[1] > $xrightybottom[1]) { return false; } return true; }
[ "protected", "function", "is_point_in_bounding_box", "(", "$", "pointxy", ",", "$", "xleftytop", ",", "$", "xrightybottom", ")", "{", "if", "(", "$", "pointxy", "[", "0", "]", "<", "$", "xleftytop", "[", "0", "]", ")", "{", "return", "false", ";", "}", "else", "if", "(", "$", "pointxy", "[", "0", "]", ">", "$", "xrightybottom", "[", "0", "]", ")", "{", "return", "false", ";", "}", "else", "if", "(", "$", "pointxy", "[", "1", "]", "<", "$", "xleftytop", "[", "1", "]", ")", "{", "return", "false", ";", "}", "else", "if", "(", "$", "pointxy", "[", "1", "]", ">", "$", "xrightybottom", "[", "1", "]", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks if the point is within the bounding box made by top left and bottom right @param array $pointxy Array of the point (x, y) @param array $xleftytop Top left point of bounding box @param array $xrightybottom Bottom left point of bounding box @return bool
[ "Checks", "if", "the", "point", "is", "within", "the", "bounding", "box", "made", "by", "top", "left", "and", "bottom", "right" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddmarker/shapes.php#L85-L96
213,096
moodle/moodle
question/type/ddmarker/shapes.php
qtype_ddmarker_shape.get_coords_interpreter_error
public function get_coords_interpreter_error() { if ($this->error) { $a = new stdClass(); $a->shape = self::human_readable_name(true); $a->coordsstring = self::human_readable_coords_format(); return get_string('formerror_'.$this->error, 'qtype_ddmarker', $a); } else { return false; } }
php
public function get_coords_interpreter_error() { if ($this->error) { $a = new stdClass(); $a->shape = self::human_readable_name(true); $a->coordsstring = self::human_readable_coords_format(); return get_string('formerror_'.$this->error, 'qtype_ddmarker', $a); } else { return false; } }
[ "public", "function", "get_coords_interpreter_error", "(", ")", "{", "if", "(", "$", "this", "->", "error", ")", "{", "$", "a", "=", "new", "stdClass", "(", ")", ";", "$", "a", "->", "shape", "=", "self", "::", "human_readable_name", "(", "true", ")", ";", "$", "a", "->", "coordsstring", "=", "self", "::", "human_readable_coords_format", "(", ")", ";", "return", "get_string", "(", "'formerror_'", ".", "$", "this", "->", "error", ",", "'qtype_ddmarker'", ",", "$", "a", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Gets any coordinate error @return string|bool String of the error or false if there is no error
[ "Gets", "any", "coordinate", "error" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddmarker/shapes.php#L103-L112
213,097
moodle/moodle
question/type/ddmarker/shapes.php
qtype_ddmarker_shape.human_readable_name
public static function human_readable_name($lowercase = false) { $stringid = 'shape_'.self::name(); if ($lowercase) { $stringid .= '_lowercase'; } return get_string($stringid, 'qtype_ddmarker'); }
php
public static function human_readable_name($lowercase = false) { $stringid = 'shape_'.self::name(); if ($lowercase) { $stringid .= '_lowercase'; } return get_string($stringid, 'qtype_ddmarker'); }
[ "public", "static", "function", "human_readable_name", "(", "$", "lowercase", "=", "false", ")", "{", "$", "stringid", "=", "'shape_'", ".", "self", "::", "name", "(", ")", ";", "if", "(", "$", "lowercase", ")", "{", "$", "stringid", ".=", "'_lowercase'", ";", "}", "return", "get_string", "(", "$", "stringid", ",", "'qtype_ddmarker'", ")", ";", "}" ]
Return a human readable name of the shape. @param bool $lowercase True if it should be lowercase. @return string
[ "Return", "a", "human", "readable", "name", "of", "the", "shape", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddmarker/shapes.php#L137-L143
213,098
moodle/moodle
question/type/ddmarker/shapes.php
qtype_ddmarker_point.dist
public function dist($other) { return sqrt(pow($this->x - $other->x, 2) + pow($this->y - $other->y, 2)); }
php
public function dist($other) { return sqrt(pow($this->x - $other->x, 2) + pow($this->y - $other->y, 2)); }
[ "public", "function", "dist", "(", "$", "other", ")", "{", "return", "sqrt", "(", "pow", "(", "$", "this", "->", "x", "-", "$", "other", "->", "x", ",", "2", ")", "+", "pow", "(", "$", "this", "->", "y", "-", "$", "other", "->", "y", ",", "2", ")", ")", ";", "}" ]
Return the distance between this point and another
[ "Return", "the", "distance", "between", "this", "point", "and", "another" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddmarker/shapes.php#L481-L483
213,099
moodle/moodle
mod/workshop/classes/privacy/provider.php
provider.export_user_data
public static function export_user_data(approved_contextlist $contextlist) { global $DB; if (!count($contextlist)) { return; } $user = $contextlist->get_user(); // Export general information about all workshops. foreach ($contextlist->get_contexts() as $context) { if ($context->contextlevel != CONTEXT_MODULE) { continue; } $data = helper::get_context_data($context, $user); static::append_extra_workshop_data($context, $user, $data, []); writer::with_context($context)->export_data([], $data); helper::export_context_files($context, $user); } // Export the user's own submission and all example submissions he/she created. static::export_submissions($contextlist); // Export all given assessments. static::export_assessments($contextlist); }
php
public static function export_user_data(approved_contextlist $contextlist) { global $DB; if (!count($contextlist)) { return; } $user = $contextlist->get_user(); // Export general information about all workshops. foreach ($contextlist->get_contexts() as $context) { if ($context->contextlevel != CONTEXT_MODULE) { continue; } $data = helper::get_context_data($context, $user); static::append_extra_workshop_data($context, $user, $data, []); writer::with_context($context)->export_data([], $data); helper::export_context_files($context, $user); } // Export the user's own submission and all example submissions he/she created. static::export_submissions($contextlist); // Export all given assessments. static::export_assessments($contextlist); }
[ "public", "static", "function", "export_user_data", "(", "approved_contextlist", "$", "contextlist", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "count", "(", "$", "contextlist", ")", ")", "{", "return", ";", "}", "$", "user", "=", "$", "contextlist", "->", "get_user", "(", ")", ";", "// Export general information about all workshops.", "foreach", "(", "$", "contextlist", "->", "get_contexts", "(", ")", "as", "$", "context", ")", "{", "if", "(", "$", "context", "->", "contextlevel", "!=", "CONTEXT_MODULE", ")", "{", "continue", ";", "}", "$", "data", "=", "helper", "::", "get_context_data", "(", "$", "context", ",", "$", "user", ")", ";", "static", "::", "append_extra_workshop_data", "(", "$", "context", ",", "$", "user", ",", "$", "data", ",", "[", "]", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "[", "]", ",", "$", "data", ")", ";", "helper", "::", "export_context_files", "(", "$", "context", ",", "$", "user", ")", ";", "}", "// Export the user's own submission and all example submissions he/she created.", "static", "::", "export_submissions", "(", "$", "contextlist", ")", ";", "// Export all given assessments.", "static", "::", "export_assessments", "(", "$", "contextlist", ")", ";", "}" ]
Export personal data stored in the given contexts. @param approved_contextlist $contextlist List of contexts approved for export.
[ "Export", "personal", "data", "stored", "in", "the", "given", "contexts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/classes/privacy/provider.php#L229-L254