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
219,600
moodle/moodle
enrol/imsenterprise/locallib.php
imsenterprise_roles.determine_default_rolemapping
public function determine_default_rolemapping($imscode) { global $DB; switch($imscode) { case '01': case '04': $shortname = 'student'; break; case '06': case '08': $shortname = 'teacher'; break; case '02': case '03': $shortname = 'editingteacher'; break; case '05': case '07': $shortname = 'admin'; break; default: return 0; // Zero for no match. } return (string)$DB->get_field('role', 'id', array('shortname' => $shortname)); }
php
public function determine_default_rolemapping($imscode) { global $DB; switch($imscode) { case '01': case '04': $shortname = 'student'; break; case '06': case '08': $shortname = 'teacher'; break; case '02': case '03': $shortname = 'editingteacher'; break; case '05': case '07': $shortname = 'admin'; break; default: return 0; // Zero for no match. } return (string)$DB->get_field('role', 'id', array('shortname' => $shortname)); }
[ "public", "function", "determine_default_rolemapping", "(", "$", "imscode", ")", "{", "global", "$", "DB", ";", "switch", "(", "$", "imscode", ")", "{", "case", "'01'", ":", "case", "'04'", ":", "$", "shortname", "=", "'student'", ";", "break", ";", "case", "'06'", ":", "case", "'08'", ":", "$", "shortname", "=", "'teacher'", ";", "break", ";", "case", "'02'", ":", "case", "'03'", ":", "$", "shortname", "=", "'editingteacher'", ";", "break", ";", "case", "'05'", ":", "case", "'07'", ":", "$", "shortname", "=", "'admin'", ";", "break", ";", "default", ":", "return", "0", ";", "// Zero for no match.", "}", "return", "(", "string", ")", "$", "DB", "->", "get_field", "(", "'role'", ",", "'id'", ",", "array", "(", "'shortname'", "=>", "$", "shortname", ")", ")", ";", "}" ]
This function is only used when first setting up the plugin, to decide which role assignments to recommend by default. For example, IMS role '01' is 'Learner', so may map to 'student' in Moodle. @param string $imscode
[ "This", "function", "is", "only", "used", "when", "first", "setting", "up", "the", "plugin", "to", "decide", "which", "role", "assignments", "to", "recommend", "by", "default", ".", "For", "example", "IMS", "role", "01", "is", "Learner", "so", "may", "map", "to", "student", "in", "Moodle", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/imsenterprise/locallib.php#L72-L96
219,601
moodle/moodle
enrol/imsenterprise/locallib.php
imsenterprise_courses.get_imsnames
public function get_imsnames($courseattr) { $values = $this->imsnames; if ($courseattr == 'summary') { $values = array_merge(array('ignore' => get_string('emptyattribute', 'enrol_imsenterprise')), $values); } return $values; }
php
public function get_imsnames($courseattr) { $values = $this->imsnames; if ($courseattr == 'summary') { $values = array_merge(array('ignore' => get_string('emptyattribute', 'enrol_imsenterprise')), $values); } return $values; }
[ "public", "function", "get_imsnames", "(", "$", "courseattr", ")", "{", "$", "values", "=", "$", "this", "->", "imsnames", ";", "if", "(", "$", "courseattr", "==", "'summary'", ")", "{", "$", "values", "=", "array_merge", "(", "array", "(", "'ignore'", "=>", "get_string", "(", "'emptyattribute'", ",", "'enrol_imsenterprise'", ")", ")", ",", "$", "values", ")", ";", "}", "return", "$", "values", ";", "}" ]
Returns the assignable values for the course attribute @param string $courseattr The course attribute (shortname, fullname...) @return array Array of assignable values
[ "Returns", "the", "assignable", "values", "for", "the", "course", "attribute" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/imsenterprise/locallib.php#L132-L139
219,602
moodle/moodle
question/format/examview/format.php
qformat_examview.unxmlise
protected function unxmlise( $xml ) { // If it's not an array then it's probably just data. if (!is_array($xml)) { $text = s($xml); } else { // Otherwise parse the array. $text = ''; foreach ($xml as $tag => $data) { // If tag is '@' then it's attributes and we don't care. if ($tag!=='@') { $text = $text . $this->unxmlise( $data ); } } } // Currently we throw the tags we found. $text = strip_tags($text); return $text; }
php
protected function unxmlise( $xml ) { // If it's not an array then it's probably just data. if (!is_array($xml)) { $text = s($xml); } else { // Otherwise parse the array. $text = ''; foreach ($xml as $tag => $data) { // If tag is '@' then it's attributes and we don't care. if ($tag!=='@') { $text = $text . $this->unxmlise( $data ); } } } // Currently we throw the tags we found. $text = strip_tags($text); return $text; }
[ "protected", "function", "unxmlise", "(", "$", "xml", ")", "{", "// If it's not an array then it's probably just data.", "if", "(", "!", "is_array", "(", "$", "xml", ")", ")", "{", "$", "text", "=", "s", "(", "$", "xml", ")", ";", "}", "else", "{", "// Otherwise parse the array.", "$", "text", "=", "''", ";", "foreach", "(", "$", "xml", "as", "$", "tag", "=>", "$", "data", ")", "{", "// If tag is '@' then it's attributes and we don't care.", "if", "(", "$", "tag", "!==", "'@'", ")", "{", "$", "text", "=", "$", "text", ".", "$", "this", "->", "unxmlise", "(", "$", "data", ")", ";", "}", "}", "}", "// Currently we throw the tags we found.", "$", "text", "=", "strip_tags", "(", "$", "text", ")", ";", "return", "$", "text", ";", "}" ]
unxmlise reconstructs part of the xml data structure in order to identify the actual data therein @param array $xml section of the xml data structure @return string data with evrything else removed
[ "unxmlise", "reconstructs", "part", "of", "the", "xml", "data", "structure", "in", "order", "to", "identify", "the", "actual", "data", "therein" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/examview/format.php#L70-L88
219,603
moodle/moodle
lib/spout/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php
CellValueFormatter.getVNodeValue
protected function getVNodeValue($node) { // for cell types having a "v" tag containing the value. // if not, the returned value should be empty string. $vNode = $node->getElementsByTagName(self::XML_NODE_VALUE)->item(0); return ($vNode !== null) ? $vNode->nodeValue : ''; }
php
protected function getVNodeValue($node) { // for cell types having a "v" tag containing the value. // if not, the returned value should be empty string. $vNode = $node->getElementsByTagName(self::XML_NODE_VALUE)->item(0); return ($vNode !== null) ? $vNode->nodeValue : ''; }
[ "protected", "function", "getVNodeValue", "(", "$", "node", ")", "{", "// for cell types having a \"v\" tag containing the value.", "// if not, the returned value should be empty string.", "$", "vNode", "=", "$", "node", "->", "getElementsByTagName", "(", "self", "::", "XML_NODE_VALUE", ")", "->", "item", "(", "0", ")", ";", "return", "(", "$", "vNode", "!==", "null", ")", "?", "$", "vNode", "->", "nodeValue", ":", "''", ";", "}" ]
Returns the cell's string value from a node's nested value node @param \DOMNode $node @return string The value associated with the cell
[ "Returns", "the", "cell", "s", "string", "value", "from", "a", "node", "s", "nested", "value", "node" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php#L109-L115
219,604
moodle/moodle
lib/spout/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php
CellValueFormatter.formatInlineStringCellValue
protected function formatInlineStringCellValue($node) { // inline strings are formatted this way: // <c r="A1" t="inlineStr"><is><t>[INLINE_STRING]</t></is></c> $tNode = $node->getElementsByTagName(self::XML_NODE_INLINE_STRING_VALUE)->item(0); $cellValue = $this->escaper->unescape($tNode->nodeValue); return $cellValue; }
php
protected function formatInlineStringCellValue($node) { // inline strings are formatted this way: // <c r="A1" t="inlineStr"><is><t>[INLINE_STRING]</t></is></c> $tNode = $node->getElementsByTagName(self::XML_NODE_INLINE_STRING_VALUE)->item(0); $cellValue = $this->escaper->unescape($tNode->nodeValue); return $cellValue; }
[ "protected", "function", "formatInlineStringCellValue", "(", "$", "node", ")", "{", "// inline strings are formatted this way:", "// <c r=\"A1\" t=\"inlineStr\"><is><t>[INLINE_STRING]</t></is></c>", "$", "tNode", "=", "$", "node", "->", "getElementsByTagName", "(", "self", "::", "XML_NODE_INLINE_STRING_VALUE", ")", "->", "item", "(", "0", ")", ";", "$", "cellValue", "=", "$", "this", "->", "escaper", "->", "unescape", "(", "$", "tNode", "->", "nodeValue", ")", ";", "return", "$", "cellValue", ";", "}" ]
Returns the cell String value where string is inline. @param \DOMNode $node @return string The value associated with the cell (null when the cell has an error)
[ "Returns", "the", "cell", "String", "value", "where", "string", "is", "inline", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php#L123-L130
219,605
moodle/moodle
lib/spout/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php
CellValueFormatter.formatSharedStringCellValue
protected function formatSharedStringCellValue($nodeValue) { // shared strings are formatted this way: // <c r="A1" t="s"><v>[SHARED_STRING_INDEX]</v></c> $sharedStringIndex = intval($nodeValue); $escapedCellValue = $this->sharedStringsHelper->getStringAtIndex($sharedStringIndex); $cellValue = $this->escaper->unescape($escapedCellValue); return $cellValue; }
php
protected function formatSharedStringCellValue($nodeValue) { // shared strings are formatted this way: // <c r="A1" t="s"><v>[SHARED_STRING_INDEX]</v></c> $sharedStringIndex = intval($nodeValue); $escapedCellValue = $this->sharedStringsHelper->getStringAtIndex($sharedStringIndex); $cellValue = $this->escaper->unescape($escapedCellValue); return $cellValue; }
[ "protected", "function", "formatSharedStringCellValue", "(", "$", "nodeValue", ")", "{", "// shared strings are formatted this way:", "// <c r=\"A1\" t=\"s\"><v>[SHARED_STRING_INDEX]</v></c>", "$", "sharedStringIndex", "=", "intval", "(", "$", "nodeValue", ")", ";", "$", "escapedCellValue", "=", "$", "this", "->", "sharedStringsHelper", "->", "getStringAtIndex", "(", "$", "sharedStringIndex", ")", ";", "$", "cellValue", "=", "$", "this", "->", "escaper", "->", "unescape", "(", "$", "escapedCellValue", ")", ";", "return", "$", "cellValue", ";", "}" ]
Returns the cell String value from shared-strings file using nodeValue index. @param string $nodeValue @return string The value associated with the cell (null when the cell has an error)
[ "Returns", "the", "cell", "String", "value", "from", "shared", "-", "strings", "file", "using", "nodeValue", "index", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php#L138-L146
219,606
moodle/moodle
lib/spout/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php
CellValueFormatter.formatStrCellValue
protected function formatStrCellValue($nodeValue) { $escapedCellValue = trim($nodeValue); $cellValue = $this->escaper->unescape($escapedCellValue); return $cellValue; }
php
protected function formatStrCellValue($nodeValue) { $escapedCellValue = trim($nodeValue); $cellValue = $this->escaper->unescape($escapedCellValue); return $cellValue; }
[ "protected", "function", "formatStrCellValue", "(", "$", "nodeValue", ")", "{", "$", "escapedCellValue", "=", "trim", "(", "$", "nodeValue", ")", ";", "$", "cellValue", "=", "$", "this", "->", "escaper", "->", "unescape", "(", "$", "escapedCellValue", ")", ";", "return", "$", "cellValue", ";", "}" ]
Returns the cell String value, where string is stored in value node. @param string $nodeValue @return string The value associated with the cell (null when the cell has an error)
[ "Returns", "the", "cell", "String", "value", "where", "string", "is", "stored", "in", "value", "node", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php#L154-L159
219,607
moodle/moodle
lib/spout/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php
CellValueFormatter.formatNumericCellValue
protected function formatNumericCellValue($nodeValue, $cellStyleId) { // Numeric values can represent numbers as well as timestamps. // We need to look at the style of the cell to determine whether it is one or the other. $shouldFormatAsDate = $this->styleHelper->shouldFormatNumericValueAsDate($cellStyleId); if ($shouldFormatAsDate) { return $this->formatExcelTimestampValue(floatval($nodeValue), $cellStyleId); } else { $nodeIntValue = intval($nodeValue); return ($nodeIntValue == $nodeValue) ? $nodeIntValue : floatval($nodeValue); } }
php
protected function formatNumericCellValue($nodeValue, $cellStyleId) { // Numeric values can represent numbers as well as timestamps. // We need to look at the style of the cell to determine whether it is one or the other. $shouldFormatAsDate = $this->styleHelper->shouldFormatNumericValueAsDate($cellStyleId); if ($shouldFormatAsDate) { return $this->formatExcelTimestampValue(floatval($nodeValue), $cellStyleId); } else { $nodeIntValue = intval($nodeValue); return ($nodeIntValue == $nodeValue) ? $nodeIntValue : floatval($nodeValue); } }
[ "protected", "function", "formatNumericCellValue", "(", "$", "nodeValue", ",", "$", "cellStyleId", ")", "{", "// Numeric values can represent numbers as well as timestamps.", "// We need to look at the style of the cell to determine whether it is one or the other.", "$", "shouldFormatAsDate", "=", "$", "this", "->", "styleHelper", "->", "shouldFormatNumericValueAsDate", "(", "$", "cellStyleId", ")", ";", "if", "(", "$", "shouldFormatAsDate", ")", "{", "return", "$", "this", "->", "formatExcelTimestampValue", "(", "floatval", "(", "$", "nodeValue", ")", ",", "$", "cellStyleId", ")", ";", "}", "else", "{", "$", "nodeIntValue", "=", "intval", "(", "$", "nodeValue", ")", ";", "return", "(", "$", "nodeIntValue", "==", "$", "nodeValue", ")", "?", "$", "nodeIntValue", ":", "floatval", "(", "$", "nodeValue", ")", ";", "}", "}" ]
Returns the cell Numeric value from string of nodeValue. The value can also represent a timestamp and a DateTime will be returned. @param string $nodeValue @param int $cellStyleId 0 being the default style @return int|float|\DateTime|null The value associated with the cell
[ "Returns", "the", "cell", "Numeric", "value", "from", "string", "of", "nodeValue", ".", "The", "value", "can", "also", "represent", "a", "timestamp", "and", "a", "DateTime", "will", "be", "returned", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php#L169-L181
219,608
moodle/moodle
lib/pear/HTML/QuickForm/Renderer/Object.php
HTML_QuickForm_Renderer_Object._elementToObject
function _elementToObject(&$element, $required, $error) { if($this->_elementType) { $ret = new $this->_elementType; } $ret->name = $element->getName(); $ret->value = $element->getValue(); $ret->type = $element->getType(); $ret->frozen = $element->isFrozen(); $labels = $element->getLabel(); if (is_array($labels)) { $ret->label = array_shift($labels); foreach ($labels as $key => $label) { $key = is_int($key)? $key + 2: $key; $ret->{'label_' . $key} = $label; } } else { $ret->label = $labels; } $ret->required = $required; $ret->error = $error; if(isset($this->_elementStyles[$ret->name])) { $ret->style = $this->_elementStyles[$ret->name]; $ret->styleTemplate = "styles/". $ret->style .".html"; } if($ret->type == 'group') { $ret->separator = $element->_separator; $ret->elements = array(); } else { $ret->html = $element->toHtml(); } return $ret; }
php
function _elementToObject(&$element, $required, $error) { if($this->_elementType) { $ret = new $this->_elementType; } $ret->name = $element->getName(); $ret->value = $element->getValue(); $ret->type = $element->getType(); $ret->frozen = $element->isFrozen(); $labels = $element->getLabel(); if (is_array($labels)) { $ret->label = array_shift($labels); foreach ($labels as $key => $label) { $key = is_int($key)? $key + 2: $key; $ret->{'label_' . $key} = $label; } } else { $ret->label = $labels; } $ret->required = $required; $ret->error = $error; if(isset($this->_elementStyles[$ret->name])) { $ret->style = $this->_elementStyles[$ret->name]; $ret->styleTemplate = "styles/". $ret->style .".html"; } if($ret->type == 'group') { $ret->separator = $element->_separator; $ret->elements = array(); } else { $ret->html = $element->toHtml(); } return $ret; }
[ "function", "_elementToObject", "(", "&", "$", "element", ",", "$", "required", ",", "$", "error", ")", "{", "if", "(", "$", "this", "->", "_elementType", ")", "{", "$", "ret", "=", "new", "$", "this", "->", "_elementType", ";", "}", "$", "ret", "->", "name", "=", "$", "element", "->", "getName", "(", ")", ";", "$", "ret", "->", "value", "=", "$", "element", "->", "getValue", "(", ")", ";", "$", "ret", "->", "type", "=", "$", "element", "->", "getType", "(", ")", ";", "$", "ret", "->", "frozen", "=", "$", "element", "->", "isFrozen", "(", ")", ";", "$", "labels", "=", "$", "element", "->", "getLabel", "(", ")", ";", "if", "(", "is_array", "(", "$", "labels", ")", ")", "{", "$", "ret", "->", "label", "=", "array_shift", "(", "$", "labels", ")", ";", "foreach", "(", "$", "labels", "as", "$", "key", "=>", "$", "label", ")", "{", "$", "key", "=", "is_int", "(", "$", "key", ")", "?", "$", "key", "+", "2", ":", "$", "key", ";", "$", "ret", "->", "{", "'label_'", ".", "$", "key", "}", "=", "$", "label", ";", "}", "}", "else", "{", "$", "ret", "->", "label", "=", "$", "labels", ";", "}", "$", "ret", "->", "required", "=", "$", "required", ";", "$", "ret", "->", "error", "=", "$", "error", ";", "if", "(", "isset", "(", "$", "this", "->", "_elementStyles", "[", "$", "ret", "->", "name", "]", ")", ")", "{", "$", "ret", "->", "style", "=", "$", "this", "->", "_elementStyles", "[", "$", "ret", "->", "name", "]", ";", "$", "ret", "->", "styleTemplate", "=", "\"styles/\"", ".", "$", "ret", "->", "style", ".", "\".html\"", ";", "}", "if", "(", "$", "ret", "->", "type", "==", "'group'", ")", "{", "$", "ret", "->", "separator", "=", "$", "element", "->", "_separator", ";", "$", "ret", "->", "elements", "=", "array", "(", ")", ";", "}", "else", "{", "$", "ret", "->", "html", "=", "$", "element", "->", "toHtml", "(", ")", ";", "}", "return", "$", "ret", ";", "}" ]
Creates an object representing an element @access private @param element object An HTML_QuickForm_element object @param required bool Whether an element is required @param error string Error associated with the element @return object
[ "Creates", "an", "object", "representing", "an", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/Renderer/Object.php#L183-L216
219,609
moodle/moodle
lib/pear/HTML/QuickForm/Renderer/Object.php
HTML_QuickForm_Renderer_Object._storeObject
function _storeObject($elObj) { $name = $elObj->name; if(is_object($this->_currentGroup) && $elObj->type != 'group') { $this->_currentGroup->elements[] = $elObj; } elseif (isset($this->_currentSection)) { $this->_obj->sections[$this->_currentSection]->elements[] = $elObj; } else { $this->_obj->elements[] = $elObj; } }
php
function _storeObject($elObj) { $name = $elObj->name; if(is_object($this->_currentGroup) && $elObj->type != 'group') { $this->_currentGroup->elements[] = $elObj; } elseif (isset($this->_currentSection)) { $this->_obj->sections[$this->_currentSection]->elements[] = $elObj; } else { $this->_obj->elements[] = $elObj; } }
[ "function", "_storeObject", "(", "$", "elObj", ")", "{", "$", "name", "=", "$", "elObj", "->", "name", ";", "if", "(", "is_object", "(", "$", "this", "->", "_currentGroup", ")", "&&", "$", "elObj", "->", "type", "!=", "'group'", ")", "{", "$", "this", "->", "_currentGroup", "->", "elements", "[", "]", "=", "$", "elObj", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "_currentSection", ")", ")", "{", "$", "this", "->", "_obj", "->", "sections", "[", "$", "this", "->", "_currentSection", "]", "->", "elements", "[", "]", "=", "$", "elObj", ";", "}", "else", "{", "$", "this", "->", "_obj", "->", "elements", "[", "]", "=", "$", "elObj", ";", "}", "}" ]
Stores an object representation of an element in the form array @access private @param elObj object Object representation of an element @return void
[ "Stores", "an", "object", "representation", "of", "an", "element", "in", "the", "form", "array" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/Renderer/Object.php#L225-L235
219,610
moodle/moodle
lib/phpexcel/PHPExcel/Reader/Excel5.php
PHPExcel_Reader_Excel5.makeKey
private function makeKey($block, $valContext) { $pwarray = str_repeat("\0", 64); for ($i = 0; $i < 5; $i++) { $pwarray[$i] = $valContext[$i]; } $pwarray[5] = chr($block & 0xff); $pwarray[6] = chr(($block >> 8) & 0xff); $pwarray[7] = chr(($block >> 16) & 0xff); $pwarray[8] = chr(($block >> 24) & 0xff); $pwarray[9] = "\x80"; $pwarray[56] = "\x48"; $md5 = new PHPExcel_Reader_Excel5_MD5(); $md5->add($pwarray); $s = $md5->getContext(); return new PHPExcel_Reader_Excel5_RC4($s); }
php
private function makeKey($block, $valContext) { $pwarray = str_repeat("\0", 64); for ($i = 0; $i < 5; $i++) { $pwarray[$i] = $valContext[$i]; } $pwarray[5] = chr($block & 0xff); $pwarray[6] = chr(($block >> 8) & 0xff); $pwarray[7] = chr(($block >> 16) & 0xff); $pwarray[8] = chr(($block >> 24) & 0xff); $pwarray[9] = "\x80"; $pwarray[56] = "\x48"; $md5 = new PHPExcel_Reader_Excel5_MD5(); $md5->add($pwarray); $s = $md5->getContext(); return new PHPExcel_Reader_Excel5_RC4($s); }
[ "private", "function", "makeKey", "(", "$", "block", ",", "$", "valContext", ")", "{", "$", "pwarray", "=", "str_repeat", "(", "\"\\0\"", ",", "64", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "5", ";", "$", "i", "++", ")", "{", "$", "pwarray", "[", "$", "i", "]", "=", "$", "valContext", "[", "$", "i", "]", ";", "}", "$", "pwarray", "[", "5", "]", "=", "chr", "(", "$", "block", "&", "0xff", ")", ";", "$", "pwarray", "[", "6", "]", "=", "chr", "(", "(", "$", "block", ">>", "8", ")", "&", "0xff", ")", ";", "$", "pwarray", "[", "7", "]", "=", "chr", "(", "(", "$", "block", ">>", "16", ")", "&", "0xff", ")", ";", "$", "pwarray", "[", "8", "]", "=", "chr", "(", "(", "$", "block", ">>", "24", ")", "&", "0xff", ")", ";", "$", "pwarray", "[", "9", "]", "=", "\"\\x80\"", ";", "$", "pwarray", "[", "56", "]", "=", "\"\\x48\"", ";", "$", "md5", "=", "new", "PHPExcel_Reader_Excel5_MD5", "(", ")", ";", "$", "md5", "->", "add", "(", "$", "pwarray", ")", ";", "$", "s", "=", "$", "md5", "->", "getContext", "(", ")", ";", "return", "new", "PHPExcel_Reader_Excel5_RC4", "(", "$", "s", ")", ";", "}" ]
Make an RC4 decryptor for the given block @var int $block Block for which to create decrypto @var string $valContext MD5 context state @return PHPExcel_Reader_Excel5_RC4
[ "Make", "an", "RC4", "decryptor", "for", "the", "given", "block" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Reader/Excel5.php#L1775-L1796
219,611
moodle/moodle
calendar/classes/local/event/forms/managesubscriptions.php
managesubscriptions.definition
public function definition() { global $PAGE; $mform = $this->_form; $eventtypes = calendar_get_allowed_event_types(); if (in_array(true, $eventtypes, true) === false) { print_error('nopermissiontoupdatecalendar'); } $mform->addElement('header', 'addsubscriptionform', get_string('importcalendarheading', 'calendar')); // Name. $mform->addElement('text', 'name', get_string('subscriptionname', 'calendar'), array('maxsize' => '255', 'size' => '40')); $mform->addRule('name', get_string('required'), 'required'); $mform->setType('name', PARAM_TEXT); // Import from (url | importfile). $mform->addElement('html', get_string('importfrominstructions', 'calendar')); $choices = array(CALENDAR_IMPORT_FROM_FILE => get_string('importfromfile', 'calendar'), CALENDAR_IMPORT_FROM_URL => get_string('importfromurl', 'calendar')); $mform->addElement('select', 'importfrom', get_string('importcalendarfrom', 'calendar'), $choices); $mform->setDefault('importfrom', CALENDAR_IMPORT_FROM_URL); // URL. $mform->addElement('text', 'url', get_string('importfromurl', 'calendar'), array('maxsize' => '255', 'size' => '50')); // Cannot set as PARAM_URL since we need to allow webcal:// protocol. $mform->setType('url', PARAM_RAW); $mform->setForceLtr('url'); // Poll interval $choices = calendar_get_pollinterval_choices(); $mform->addElement('select', 'pollinterval', get_string('pollinterval', 'calendar'), $choices); $mform->setDefault('pollinterval', 604800); $mform->addHelpButton('pollinterval', 'pollinterval', 'calendar'); $mform->setType('pollinterval', PARAM_INT); // Import file $mform->addElement('filepicker', 'importfile', get_string('importfromfile', 'calendar'), null, array('accepted_types' => '.ics')); // Disable appropriate elements depending on import from value. $mform->disabledIf('pollinterval', 'importfrom', 'eq', CALENDAR_IMPORT_FROM_FILE); $mform->disabledIf('url', 'importfrom', 'eq', CALENDAR_IMPORT_FROM_FILE); $mform->disabledIf('importfile', 'importfrom', 'eq', CALENDAR_IMPORT_FROM_URL); // Add the select elements for the available event types. $this->add_event_type_elements($mform, $eventtypes); // Eventtype: 0 = user, 1 = global, anything else = course ID. $mform->addElement('submit', 'add', get_string('add')); // Add the javascript required to enhance this mform. $PAGE->requires->js_call_amd('core_calendar/event_form', 'init', [$mform->getAttribute('id')]); }
php
public function definition() { global $PAGE; $mform = $this->_form; $eventtypes = calendar_get_allowed_event_types(); if (in_array(true, $eventtypes, true) === false) { print_error('nopermissiontoupdatecalendar'); } $mform->addElement('header', 'addsubscriptionform', get_string('importcalendarheading', 'calendar')); // Name. $mform->addElement('text', 'name', get_string('subscriptionname', 'calendar'), array('maxsize' => '255', 'size' => '40')); $mform->addRule('name', get_string('required'), 'required'); $mform->setType('name', PARAM_TEXT); // Import from (url | importfile). $mform->addElement('html', get_string('importfrominstructions', 'calendar')); $choices = array(CALENDAR_IMPORT_FROM_FILE => get_string('importfromfile', 'calendar'), CALENDAR_IMPORT_FROM_URL => get_string('importfromurl', 'calendar')); $mform->addElement('select', 'importfrom', get_string('importcalendarfrom', 'calendar'), $choices); $mform->setDefault('importfrom', CALENDAR_IMPORT_FROM_URL); // URL. $mform->addElement('text', 'url', get_string('importfromurl', 'calendar'), array('maxsize' => '255', 'size' => '50')); // Cannot set as PARAM_URL since we need to allow webcal:// protocol. $mform->setType('url', PARAM_RAW); $mform->setForceLtr('url'); // Poll interval $choices = calendar_get_pollinterval_choices(); $mform->addElement('select', 'pollinterval', get_string('pollinterval', 'calendar'), $choices); $mform->setDefault('pollinterval', 604800); $mform->addHelpButton('pollinterval', 'pollinterval', 'calendar'); $mform->setType('pollinterval', PARAM_INT); // Import file $mform->addElement('filepicker', 'importfile', get_string('importfromfile', 'calendar'), null, array('accepted_types' => '.ics')); // Disable appropriate elements depending on import from value. $mform->disabledIf('pollinterval', 'importfrom', 'eq', CALENDAR_IMPORT_FROM_FILE); $mform->disabledIf('url', 'importfrom', 'eq', CALENDAR_IMPORT_FROM_FILE); $mform->disabledIf('importfile', 'importfrom', 'eq', CALENDAR_IMPORT_FROM_URL); // Add the select elements for the available event types. $this->add_event_type_elements($mform, $eventtypes); // Eventtype: 0 = user, 1 = global, anything else = course ID. $mform->addElement('submit', 'add', get_string('add')); // Add the javascript required to enhance this mform. $PAGE->requires->js_call_amd('core_calendar/event_form', 'init', [$mform->getAttribute('id')]); }
[ "public", "function", "definition", "(", ")", "{", "global", "$", "PAGE", ";", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "eventtypes", "=", "calendar_get_allowed_event_types", "(", ")", ";", "if", "(", "in_array", "(", "true", ",", "$", "eventtypes", ",", "true", ")", "===", "false", ")", "{", "print_error", "(", "'nopermissiontoupdatecalendar'", ")", ";", "}", "$", "mform", "->", "addElement", "(", "'header'", ",", "'addsubscriptionform'", ",", "get_string", "(", "'importcalendarheading'", ",", "'calendar'", ")", ")", ";", "// Name.", "$", "mform", "->", "addElement", "(", "'text'", ",", "'name'", ",", "get_string", "(", "'subscriptionname'", ",", "'calendar'", ")", ",", "array", "(", "'maxsize'", "=>", "'255'", ",", "'size'", "=>", "'40'", ")", ")", ";", "$", "mform", "->", "addRule", "(", "'name'", ",", "get_string", "(", "'required'", ")", ",", "'required'", ")", ";", "$", "mform", "->", "setType", "(", "'name'", ",", "PARAM_TEXT", ")", ";", "// Import from (url | importfile).", "$", "mform", "->", "addElement", "(", "'html'", ",", "get_string", "(", "'importfrominstructions'", ",", "'calendar'", ")", ")", ";", "$", "choices", "=", "array", "(", "CALENDAR_IMPORT_FROM_FILE", "=>", "get_string", "(", "'importfromfile'", ",", "'calendar'", ")", ",", "CALENDAR_IMPORT_FROM_URL", "=>", "get_string", "(", "'importfromurl'", ",", "'calendar'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'importfrom'", ",", "get_string", "(", "'importcalendarfrom'", ",", "'calendar'", ")", ",", "$", "choices", ")", ";", "$", "mform", "->", "setDefault", "(", "'importfrom'", ",", "CALENDAR_IMPORT_FROM_URL", ")", ";", "// URL.", "$", "mform", "->", "addElement", "(", "'text'", ",", "'url'", ",", "get_string", "(", "'importfromurl'", ",", "'calendar'", ")", ",", "array", "(", "'maxsize'", "=>", "'255'", ",", "'size'", "=>", "'50'", ")", ")", ";", "// Cannot set as PARAM_URL since we need to allow webcal:// protocol.", "$", "mform", "->", "setType", "(", "'url'", ",", "PARAM_RAW", ")", ";", "$", "mform", "->", "setForceLtr", "(", "'url'", ")", ";", "// Poll interval", "$", "choices", "=", "calendar_get_pollinterval_choices", "(", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'pollinterval'", ",", "get_string", "(", "'pollinterval'", ",", "'calendar'", ")", ",", "$", "choices", ")", ";", "$", "mform", "->", "setDefault", "(", "'pollinterval'", ",", "604800", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'pollinterval'", ",", "'pollinterval'", ",", "'calendar'", ")", ";", "$", "mform", "->", "setType", "(", "'pollinterval'", ",", "PARAM_INT", ")", ";", "// Import file", "$", "mform", "->", "addElement", "(", "'filepicker'", ",", "'importfile'", ",", "get_string", "(", "'importfromfile'", ",", "'calendar'", ")", ",", "null", ",", "array", "(", "'accepted_types'", "=>", "'.ics'", ")", ")", ";", "// Disable appropriate elements depending on import from value.", "$", "mform", "->", "disabledIf", "(", "'pollinterval'", ",", "'importfrom'", ",", "'eq'", ",", "CALENDAR_IMPORT_FROM_FILE", ")", ";", "$", "mform", "->", "disabledIf", "(", "'url'", ",", "'importfrom'", ",", "'eq'", ",", "CALENDAR_IMPORT_FROM_FILE", ")", ";", "$", "mform", "->", "disabledIf", "(", "'importfile'", ",", "'importfrom'", ",", "'eq'", ",", "CALENDAR_IMPORT_FROM_URL", ")", ";", "// Add the select elements for the available event types.", "$", "this", "->", "add_event_type_elements", "(", "$", "mform", ",", "$", "eventtypes", ")", ";", "// Eventtype: 0 = user, 1 = global, anything else = course ID.", "$", "mform", "->", "addElement", "(", "'submit'", ",", "'add'", ",", "get_string", "(", "'add'", ")", ")", ";", "// Add the javascript required to enhance this mform.", "$", "PAGE", "->", "requires", "->", "js_call_amd", "(", "'core_calendar/event_form'", ",", "'init'", ",", "[", "$", "mform", "->", "getAttribute", "(", "'id'", ")", "]", ")", ";", "}" ]
Defines the form used to add calendar subscriptions.
[ "Defines", "the", "form", "used", "to", "add", "calendar", "subscriptions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/forms/managesubscriptions.php#L42-L93
219,612
moodle/moodle
calendar/classes/local/event/forms/managesubscriptions.php
managesubscriptions.validation
public function validation($data, $files) { global $USER; $errors = parent::validation($data, $files); $eventtype = isset($data['eventtype']) ? $data['eventtype'] : null; $coursekey = ($eventtype == 'group') ? 'groupcourseid' : 'courseid'; $courseid = (!empty($data[$coursekey])) ? $data[$coursekey] : null; $eventtypes = calendar_get_allowed_event_types($courseid); if (empty($eventtype) || !isset($eventtypes[$eventtype])) { $errors['eventtype'] = get_string('invalideventtype', 'calendar'); } if ($data['importfrom'] == CALENDAR_IMPORT_FROM_FILE) { if (empty($data['importfile'])) { $errors['importfile'] = get_string('errorrequiredurlorfile', 'calendar'); } else { // Make sure the file area is not empty and contains only one file. $draftitemid = $data['importfile']; $fs = get_file_storage(); $usercontext = \context_user::instance($USER->id); $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id DESC', false); if (count($files) !== 1) { $errors['importfile'] = get_string('errorrequiredurlorfile', 'calendar'); } } } else if (($data['importfrom'] == CALENDAR_IMPORT_FROM_URL)) { // Clean input calendar url. $url = clean_param($data['url'], PARAM_URL); if (empty($url) || ($url !== $data['url'])) { $errors['url'] = get_string('invalidurl', 'error'); } } else { // Shouldn't happen. $errors['url'] = get_string('errorrequiredurlorfile', 'calendar'); } return $errors; }
php
public function validation($data, $files) { global $USER; $errors = parent::validation($data, $files); $eventtype = isset($data['eventtype']) ? $data['eventtype'] : null; $coursekey = ($eventtype == 'group') ? 'groupcourseid' : 'courseid'; $courseid = (!empty($data[$coursekey])) ? $data[$coursekey] : null; $eventtypes = calendar_get_allowed_event_types($courseid); if (empty($eventtype) || !isset($eventtypes[$eventtype])) { $errors['eventtype'] = get_string('invalideventtype', 'calendar'); } if ($data['importfrom'] == CALENDAR_IMPORT_FROM_FILE) { if (empty($data['importfile'])) { $errors['importfile'] = get_string('errorrequiredurlorfile', 'calendar'); } else { // Make sure the file area is not empty and contains only one file. $draftitemid = $data['importfile']; $fs = get_file_storage(); $usercontext = \context_user::instance($USER->id); $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id DESC', false); if (count($files) !== 1) { $errors['importfile'] = get_string('errorrequiredurlorfile', 'calendar'); } } } else if (($data['importfrom'] == CALENDAR_IMPORT_FROM_URL)) { // Clean input calendar url. $url = clean_param($data['url'], PARAM_URL); if (empty($url) || ($url !== $data['url'])) { $errors['url'] = get_string('invalidurl', 'error'); } } else { // Shouldn't happen. $errors['url'] = get_string('errorrequiredurlorfile', 'calendar'); } return $errors; }
[ "public", "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "global", "$", "USER", ";", "$", "errors", "=", "parent", "::", "validation", "(", "$", "data", ",", "$", "files", ")", ";", "$", "eventtype", "=", "isset", "(", "$", "data", "[", "'eventtype'", "]", ")", "?", "$", "data", "[", "'eventtype'", "]", ":", "null", ";", "$", "coursekey", "=", "(", "$", "eventtype", "==", "'group'", ")", "?", "'groupcourseid'", ":", "'courseid'", ";", "$", "courseid", "=", "(", "!", "empty", "(", "$", "data", "[", "$", "coursekey", "]", ")", ")", "?", "$", "data", "[", "$", "coursekey", "]", ":", "null", ";", "$", "eventtypes", "=", "calendar_get_allowed_event_types", "(", "$", "courseid", ")", ";", "if", "(", "empty", "(", "$", "eventtype", ")", "||", "!", "isset", "(", "$", "eventtypes", "[", "$", "eventtype", "]", ")", ")", "{", "$", "errors", "[", "'eventtype'", "]", "=", "get_string", "(", "'invalideventtype'", ",", "'calendar'", ")", ";", "}", "if", "(", "$", "data", "[", "'importfrom'", "]", "==", "CALENDAR_IMPORT_FROM_FILE", ")", "{", "if", "(", "empty", "(", "$", "data", "[", "'importfile'", "]", ")", ")", "{", "$", "errors", "[", "'importfile'", "]", "=", "get_string", "(", "'errorrequiredurlorfile'", ",", "'calendar'", ")", ";", "}", "else", "{", "// Make sure the file area is not empty and contains only one file.", "$", "draftitemid", "=", "$", "data", "[", "'importfile'", "]", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "usercontext", "=", "\\", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "usercontext", "->", "id", ",", "'user'", ",", "'draft'", ",", "$", "draftitemid", ",", "'id DESC'", ",", "false", ")", ";", "if", "(", "count", "(", "$", "files", ")", "!==", "1", ")", "{", "$", "errors", "[", "'importfile'", "]", "=", "get_string", "(", "'errorrequiredurlorfile'", ",", "'calendar'", ")", ";", "}", "}", "}", "else", "if", "(", "(", "$", "data", "[", "'importfrom'", "]", "==", "CALENDAR_IMPORT_FROM_URL", ")", ")", "{", "// Clean input calendar url.", "$", "url", "=", "clean_param", "(", "$", "data", "[", "'url'", "]", ",", "PARAM_URL", ")", ";", "if", "(", "empty", "(", "$", "url", ")", "||", "(", "$", "url", "!==", "$", "data", "[", "'url'", "]", ")", ")", "{", "$", "errors", "[", "'url'", "]", "=", "get_string", "(", "'invalidurl'", ",", "'error'", ")", ";", "}", "}", "else", "{", "// Shouldn't happen.", "$", "errors", "[", "'url'", "]", "=", "get_string", "(", "'errorrequiredurlorfile'", ",", "'calendar'", ")", ";", "}", "return", "$", "errors", ";", "}" ]
Validates the returned data. @param array $data @param array $files @return array
[ "Validates", "the", "returned", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/forms/managesubscriptions.php#L102-L141
219,613
moodle/moodle
lib/setuplib.php
bootstrap_renderer.early_error_content
public static function early_error_content($message, $moreinfourl, $link, $backtrace, $debuginfo = null) { global $CFG; $content = '<div style="margin-top: 6em; margin-left:auto; margin-right:auto; color:#990000; text-align:center; font-size:large; border-width:1px; border-color:black; background-color:#ffffee; border-style:solid; border-radius: 20px; border-collapse: collapse; width: 80%; -moz-border-radius: 20px; padding: 15px"> ' . $message . ' </div>'; // Check whether debug is set. $debug = (!empty($CFG->debug) && $CFG->debug >= DEBUG_DEVELOPER); // Also check we have it set in the config file. This occurs if the method to read the config table from the // database fails, reading from the config table is the first database interaction we have. $debug = $debug || (!empty($CFG->config_php_settings['debug']) && $CFG->config_php_settings['debug'] >= DEBUG_DEVELOPER ); if ($debug) { if (!empty($debuginfo)) { $debuginfo = s($debuginfo); // removes all nasty JS $debuginfo = str_replace("\n", '<br />', $debuginfo); // keep newlines $content .= '<div class="notifytiny">Debug info: ' . $debuginfo . '</div>'; } if (!empty($backtrace)) { $content .= '<div class="notifytiny">Stack trace: ' . format_backtrace($backtrace, false) . '</div>'; } } return $content; }
php
public static function early_error_content($message, $moreinfourl, $link, $backtrace, $debuginfo = null) { global $CFG; $content = '<div style="margin-top: 6em; margin-left:auto; margin-right:auto; color:#990000; text-align:center; font-size:large; border-width:1px; border-color:black; background-color:#ffffee; border-style:solid; border-radius: 20px; border-collapse: collapse; width: 80%; -moz-border-radius: 20px; padding: 15px"> ' . $message . ' </div>'; // Check whether debug is set. $debug = (!empty($CFG->debug) && $CFG->debug >= DEBUG_DEVELOPER); // Also check we have it set in the config file. This occurs if the method to read the config table from the // database fails, reading from the config table is the first database interaction we have. $debug = $debug || (!empty($CFG->config_php_settings['debug']) && $CFG->config_php_settings['debug'] >= DEBUG_DEVELOPER ); if ($debug) { if (!empty($debuginfo)) { $debuginfo = s($debuginfo); // removes all nasty JS $debuginfo = str_replace("\n", '<br />', $debuginfo); // keep newlines $content .= '<div class="notifytiny">Debug info: ' . $debuginfo . '</div>'; } if (!empty($backtrace)) { $content .= '<div class="notifytiny">Stack trace: ' . format_backtrace($backtrace, false) . '</div>'; } } return $content; }
[ "public", "static", "function", "early_error_content", "(", "$", "message", ",", "$", "moreinfourl", ",", "$", "link", ",", "$", "backtrace", ",", "$", "debuginfo", "=", "null", ")", "{", "global", "$", "CFG", ";", "$", "content", "=", "'<div style=\"margin-top: 6em; margin-left:auto; margin-right:auto; color:#990000; text-align:center; font-size:large; border-width:1px;\nborder-color:black; background-color:#ffffee; border-style:solid; border-radius: 20px; border-collapse: collapse;\nwidth: 80%; -moz-border-radius: 20px; padding: 15px\">\n'", ".", "$", "message", ".", "'\n</div>'", ";", "// Check whether debug is set.", "$", "debug", "=", "(", "!", "empty", "(", "$", "CFG", "->", "debug", ")", "&&", "$", "CFG", "->", "debug", ">=", "DEBUG_DEVELOPER", ")", ";", "// Also check we have it set in the config file. This occurs if the method to read the config table from the", "// database fails, reading from the config table is the first database interaction we have.", "$", "debug", "=", "$", "debug", "||", "(", "!", "empty", "(", "$", "CFG", "->", "config_php_settings", "[", "'debug'", "]", ")", "&&", "$", "CFG", "->", "config_php_settings", "[", "'debug'", "]", ">=", "DEBUG_DEVELOPER", ")", ";", "if", "(", "$", "debug", ")", "{", "if", "(", "!", "empty", "(", "$", "debuginfo", ")", ")", "{", "$", "debuginfo", "=", "s", "(", "$", "debuginfo", ")", ";", "// removes all nasty JS", "$", "debuginfo", "=", "str_replace", "(", "\"\\n\"", ",", "'<br />'", ",", "$", "debuginfo", ")", ";", "// keep newlines", "$", "content", ".=", "'<div class=\"notifytiny\">Debug info: '", ".", "$", "debuginfo", ".", "'</div>'", ";", "}", "if", "(", "!", "empty", "(", "$", "backtrace", ")", ")", "{", "$", "content", ".=", "'<div class=\"notifytiny\">Stack trace: '", ".", "format_backtrace", "(", "$", "backtrace", ",", "false", ")", ".", "'</div>'", ";", "}", "}", "return", "$", "content", ";", "}" ]
Returns nicely formatted error message in a div box. @static @param string $message error message @param string $moreinfourl (ignored in early errors) @param string $link (ignored in early errors) @param array $backtrace @param string $debuginfo @return string
[ "Returns", "nicely", "formatted", "error", "message", "in", "a", "div", "box", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/setuplib.php#L1984-L2009
219,614
moodle/moodle
lib/setuplib.php
bootstrap_renderer.early_error
public static function early_error($message, $moreinfourl, $link, $backtrace, $debuginfo = null, $errorcode = null) { global $CFG; if (CLI_SCRIPT) { echo "!!! $message !!!\n"; if (!empty($CFG->debug) and $CFG->debug >= DEBUG_DEVELOPER) { if (!empty($debuginfo)) { echo "\nDebug info: $debuginfo"; } if (!empty($backtrace)) { echo "\nStack trace: " . format_backtrace($backtrace, true); } } return; } else if (AJAX_SCRIPT) { $e = new stdClass(); $e->error = $message; $e->stacktrace = NULL; $e->debuginfo = NULL; if (!empty($CFG->debug) and $CFG->debug >= DEBUG_DEVELOPER) { if (!empty($debuginfo)) { $e->debuginfo = $debuginfo; } if (!empty($backtrace)) { $e->stacktrace = format_backtrace($backtrace, true); } } $e->errorcode = $errorcode; @header('Content-Type: application/json; charset=utf-8'); echo json_encode($e); return; } // In the name of protocol correctness, monitoring and performance // profiling, set the appropriate error headers for machine consumption. $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'); @header($protocol . ' 503 Service Unavailable'); // better disable any caching @header('Content-Type: text/html; charset=utf-8'); @header('X-UA-Compatible: IE=edge'); @header('Cache-Control: no-store, no-cache, must-revalidate'); @header('Cache-Control: post-check=0, pre-check=0', false); @header('Pragma: no-cache'); @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT'); @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); if (function_exists('get_string')) { $strerror = get_string('error'); } else { $strerror = 'Error'; } $content = self::early_error_content($message, $moreinfourl, $link, $backtrace, $debuginfo); return self::plain_page($strerror, $content); }
php
public static function early_error($message, $moreinfourl, $link, $backtrace, $debuginfo = null, $errorcode = null) { global $CFG; if (CLI_SCRIPT) { echo "!!! $message !!!\n"; if (!empty($CFG->debug) and $CFG->debug >= DEBUG_DEVELOPER) { if (!empty($debuginfo)) { echo "\nDebug info: $debuginfo"; } if (!empty($backtrace)) { echo "\nStack trace: " . format_backtrace($backtrace, true); } } return; } else if (AJAX_SCRIPT) { $e = new stdClass(); $e->error = $message; $e->stacktrace = NULL; $e->debuginfo = NULL; if (!empty($CFG->debug) and $CFG->debug >= DEBUG_DEVELOPER) { if (!empty($debuginfo)) { $e->debuginfo = $debuginfo; } if (!empty($backtrace)) { $e->stacktrace = format_backtrace($backtrace, true); } } $e->errorcode = $errorcode; @header('Content-Type: application/json; charset=utf-8'); echo json_encode($e); return; } // In the name of protocol correctness, monitoring and performance // profiling, set the appropriate error headers for machine consumption. $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'); @header($protocol . ' 503 Service Unavailable'); // better disable any caching @header('Content-Type: text/html; charset=utf-8'); @header('X-UA-Compatible: IE=edge'); @header('Cache-Control: no-store, no-cache, must-revalidate'); @header('Cache-Control: post-check=0, pre-check=0', false); @header('Pragma: no-cache'); @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT'); @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); if (function_exists('get_string')) { $strerror = get_string('error'); } else { $strerror = 'Error'; } $content = self::early_error_content($message, $moreinfourl, $link, $backtrace, $debuginfo); return self::plain_page($strerror, $content); }
[ "public", "static", "function", "early_error", "(", "$", "message", ",", "$", "moreinfourl", ",", "$", "link", ",", "$", "backtrace", ",", "$", "debuginfo", "=", "null", ",", "$", "errorcode", "=", "null", ")", "{", "global", "$", "CFG", ";", "if", "(", "CLI_SCRIPT", ")", "{", "echo", "\"!!! $message !!!\\n\"", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "debug", ")", "and", "$", "CFG", "->", "debug", ">=", "DEBUG_DEVELOPER", ")", "{", "if", "(", "!", "empty", "(", "$", "debuginfo", ")", ")", "{", "echo", "\"\\nDebug info: $debuginfo\"", ";", "}", "if", "(", "!", "empty", "(", "$", "backtrace", ")", ")", "{", "echo", "\"\\nStack trace: \"", ".", "format_backtrace", "(", "$", "backtrace", ",", "true", ")", ";", "}", "}", "return", ";", "}", "else", "if", "(", "AJAX_SCRIPT", ")", "{", "$", "e", "=", "new", "stdClass", "(", ")", ";", "$", "e", "->", "error", "=", "$", "message", ";", "$", "e", "->", "stacktrace", "=", "NULL", ";", "$", "e", "->", "debuginfo", "=", "NULL", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "debug", ")", "and", "$", "CFG", "->", "debug", ">=", "DEBUG_DEVELOPER", ")", "{", "if", "(", "!", "empty", "(", "$", "debuginfo", ")", ")", "{", "$", "e", "->", "debuginfo", "=", "$", "debuginfo", ";", "}", "if", "(", "!", "empty", "(", "$", "backtrace", ")", ")", "{", "$", "e", "->", "stacktrace", "=", "format_backtrace", "(", "$", "backtrace", ",", "true", ")", ";", "}", "}", "$", "e", "->", "errorcode", "=", "$", "errorcode", ";", "@", "header", "(", "'Content-Type: application/json; charset=utf-8'", ")", ";", "echo", "json_encode", "(", "$", "e", ")", ";", "return", ";", "}", "// In the name of protocol correctness, monitoring and performance", "// profiling, set the appropriate error headers for machine consumption.", "$", "protocol", "=", "(", "isset", "(", "$", "_SERVER", "[", "'SERVER_PROTOCOL'", "]", ")", "?", "$", "_SERVER", "[", "'SERVER_PROTOCOL'", "]", ":", "'HTTP/1.0'", ")", ";", "@", "header", "(", "$", "protocol", ".", "' 503 Service Unavailable'", ")", ";", "// better disable any caching", "@", "header", "(", "'Content-Type: text/html; charset=utf-8'", ")", ";", "@", "header", "(", "'X-UA-Compatible: IE=edge'", ")", ";", "@", "header", "(", "'Cache-Control: no-store, no-cache, must-revalidate'", ")", ";", "@", "header", "(", "'Cache-Control: post-check=0, pre-check=0'", ",", "false", ")", ";", "@", "header", "(", "'Pragma: no-cache'", ")", ";", "@", "header", "(", "'Expires: Mon, 20 Aug 1969 09:23:00 GMT'", ")", ";", "@", "header", "(", "'Last-Modified: '", ".", "gmdate", "(", "'D, d M Y H:i:s'", ")", ".", "' GMT'", ")", ";", "if", "(", "function_exists", "(", "'get_string'", ")", ")", "{", "$", "strerror", "=", "get_string", "(", "'error'", ")", ";", "}", "else", "{", "$", "strerror", "=", "'Error'", ";", "}", "$", "content", "=", "self", "::", "early_error_content", "(", "$", "message", ",", "$", "moreinfourl", ",", "$", "link", ",", "$", "backtrace", ",", "$", "debuginfo", ")", ";", "return", "self", "::", "plain_page", "(", "$", "strerror", ",", "$", "content", ")", ";", "}" ]
This function should only be called by this class, or from exception handlers @static @param string $message error message @param string $moreinfourl (ignored in early errors) @param string $link (ignored in early errors) @param array $backtrace @param string $debuginfo extra information for developers @return string
[ "This", "function", "should", "only", "be", "called", "by", "this", "class", "or", "from", "exception", "handlers" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/setuplib.php#L2021-L2078
219,615
moodle/moodle
lib/setuplib.php
bootstrap_renderer.plain_redirect_message
public static function plain_redirect_message($encodedurl) { $message = '<div style="margin-top: 3em; margin-left:auto; margin-right:auto; text-align:center;">' . get_string('pageshouldredirect') . '<br /><a href="'. $encodedurl .'">'. get_string('continue') .'</a></div>'; return self::plain_page(get_string('redirect'), $message); }
php
public static function plain_redirect_message($encodedurl) { $message = '<div style="margin-top: 3em; margin-left:auto; margin-right:auto; text-align:center;">' . get_string('pageshouldredirect') . '<br /><a href="'. $encodedurl .'">'. get_string('continue') .'</a></div>'; return self::plain_page(get_string('redirect'), $message); }
[ "public", "static", "function", "plain_redirect_message", "(", "$", "encodedurl", ")", "{", "$", "message", "=", "'<div style=\"margin-top: 3em; margin-left:auto; margin-right:auto; text-align:center;\">'", ".", "get_string", "(", "'pageshouldredirect'", ")", ".", "'<br /><a href=\"'", ".", "$", "encodedurl", ".", "'\">'", ".", "get_string", "(", "'continue'", ")", ".", "'</a></div>'", ";", "return", "self", "::", "plain_page", "(", "get_string", "(", "'redirect'", ")", ",", "$", "message", ")", ";", "}" ]
Page should redirect message. @static @param string $encodedurl redirect url @return string
[ "Page", "should", "redirect", "message", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/setuplib.php#L2097-L2101
219,616
moodle/moodle
lib/setuplib.php
bootstrap_renderer.plain_page
public static function plain_page($title, $content, $meta = '') { if (function_exists('get_string') && function_exists('get_html_lang')) { $htmllang = get_html_lang(); } else { $htmllang = ''; } $footer = ''; if (MDL_PERF_TEST) { $perfinfo = get_performance_info(); $footer = '<footer>' . $perfinfo['html'] . '</footer>'; } return '<!DOCTYPE html> <html ' . $htmllang . '> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> '.$meta.' <title>' . $title . '</title> </head><body>' . $content . $footer . '</body></html>'; }
php
public static function plain_page($title, $content, $meta = '') { if (function_exists('get_string') && function_exists('get_html_lang')) { $htmllang = get_html_lang(); } else { $htmllang = ''; } $footer = ''; if (MDL_PERF_TEST) { $perfinfo = get_performance_info(); $footer = '<footer>' . $perfinfo['html'] . '</footer>'; } return '<!DOCTYPE html> <html ' . $htmllang . '> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> '.$meta.' <title>' . $title . '</title> </head><body>' . $content . $footer . '</body></html>'; }
[ "public", "static", "function", "plain_page", "(", "$", "title", ",", "$", "content", ",", "$", "meta", "=", "''", ")", "{", "if", "(", "function_exists", "(", "'get_string'", ")", "&&", "function_exists", "(", "'get_html_lang'", ")", ")", "{", "$", "htmllang", "=", "get_html_lang", "(", ")", ";", "}", "else", "{", "$", "htmllang", "=", "''", ";", "}", "$", "footer", "=", "''", ";", "if", "(", "MDL_PERF_TEST", ")", "{", "$", "perfinfo", "=", "get_performance_info", "(", ")", ";", "$", "footer", "=", "'<footer>'", ".", "$", "perfinfo", "[", "'html'", "]", ".", "'</footer>'", ";", "}", "return", "'<!DOCTYPE html>\n<html '", ".", "$", "htmllang", ".", "'>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n'", ".", "$", "meta", ".", "'\n<title>'", ".", "$", "title", ".", "'</title>\n</head><body>'", ".", "$", "content", ".", "$", "footer", ".", "'</body></html>'", ";", "}" ]
Output basic html page. @static @param string $title page title @param string $content page content @param string $meta meta tag @return string html page
[ "Output", "basic", "html", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/setuplib.php#L2127-L2147
219,617
moodle/moodle
lib/pear/HTML/Common.php
HTML_Common._getAttrString
function _getAttrString($attributes) { $strAttr = ''; if (is_array($attributes)) { foreach ($attributes as $key => $value) { $strAttr .= ' ' . $key . '="' . htmlspecialchars($value) . '"'; } } return $strAttr; }
php
function _getAttrString($attributes) { $strAttr = ''; if (is_array($attributes)) { foreach ($attributes as $key => $value) { $strAttr .= ' ' . $key . '="' . htmlspecialchars($value) . '"'; } } return $strAttr; }
[ "function", "_getAttrString", "(", "$", "attributes", ")", "{", "$", "strAttr", "=", "''", ";", "if", "(", "is_array", "(", "$", "attributes", ")", ")", "{", "foreach", "(", "$", "attributes", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "strAttr", ".=", "' '", ".", "$", "key", ".", "'=\"'", ".", "htmlspecialchars", "(", "$", "value", ")", ".", "'\"'", ";", "}", "}", "return", "$", "strAttr", ";", "}" ]
Returns an HTML formatted attribute string @param array $attributes @return string @access private
[ "Returns", "an", "HTML", "formatted", "attribute", "string" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/Common.php#L165-L175
219,618
moodle/moodle
lib/pear/HTML/Common.php
HTML_Common._parseAttributes
function _parseAttributes($attributes) { if (is_array($attributes)) { $ret = array(); foreach ($attributes as $key => $value) { if (is_int($key)) { $key = $value = strtolower($value); } else { $key = strtolower($key); } $ret[$key] = $value; } return $ret; } elseif (is_string($attributes)) { $preg = "/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" . "([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/"; if (preg_match_all($preg, $attributes, $regs)) { for ($counter=0; $counter<count($regs[1]); $counter++) { $name = $regs[1][$counter]; $check = $regs[0][$counter]; $value = $regs[7][$counter]; if (trim($name) == trim($check)) { $arrAttr[strtolower(trim($name))] = strtolower(trim($name)); } else { if (substr($value, 0, 1) == "\"" || substr($value, 0, 1) == "'") { $value = substr($value, 1, -1); } $arrAttr[strtolower(trim($name))] = trim($value); } } return $arrAttr; } } }
php
function _parseAttributes($attributes) { if (is_array($attributes)) { $ret = array(); foreach ($attributes as $key => $value) { if (is_int($key)) { $key = $value = strtolower($value); } else { $key = strtolower($key); } $ret[$key] = $value; } return $ret; } elseif (is_string($attributes)) { $preg = "/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" . "([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/"; if (preg_match_all($preg, $attributes, $regs)) { for ($counter=0; $counter<count($regs[1]); $counter++) { $name = $regs[1][$counter]; $check = $regs[0][$counter]; $value = $regs[7][$counter]; if (trim($name) == trim($check)) { $arrAttr[strtolower(trim($name))] = strtolower(trim($name)); } else { if (substr($value, 0, 1) == "\"" || substr($value, 0, 1) == "'") { $value = substr($value, 1, -1); } $arrAttr[strtolower(trim($name))] = trim($value); } } return $arrAttr; } } }
[ "function", "_parseAttributes", "(", "$", "attributes", ")", "{", "if", "(", "is_array", "(", "$", "attributes", ")", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "attributes", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_int", "(", "$", "key", ")", ")", "{", "$", "key", "=", "$", "value", "=", "strtolower", "(", "$", "value", ")", ";", "}", "else", "{", "$", "key", "=", "strtolower", "(", "$", "key", ")", ";", "}", "$", "ret", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "ret", ";", "}", "elseif", "(", "is_string", "(", "$", "attributes", ")", ")", "{", "$", "preg", "=", "\"/(([A-Za-z_:]|[^\\\\x00-\\\\x7F])([A-Za-z0-9_:.-]|[^\\\\x00-\\\\x7F])*)\"", ".", "\"([ \\\\n\\\\t\\\\r]+)?(=([ \\\\n\\\\t\\\\r]+)?(\\\"[^\\\"]*\\\"|'[^']*'|[^ \\\\n\\\\t\\\\r]*))?/\"", ";", "if", "(", "preg_match_all", "(", "$", "preg", ",", "$", "attributes", ",", "$", "regs", ")", ")", "{", "for", "(", "$", "counter", "=", "0", ";", "$", "counter", "<", "count", "(", "$", "regs", "[", "1", "]", ")", ";", "$", "counter", "++", ")", "{", "$", "name", "=", "$", "regs", "[", "1", "]", "[", "$", "counter", "]", ";", "$", "check", "=", "$", "regs", "[", "0", "]", "[", "$", "counter", "]", ";", "$", "value", "=", "$", "regs", "[", "7", "]", "[", "$", "counter", "]", ";", "if", "(", "trim", "(", "$", "name", ")", "==", "trim", "(", "$", "check", ")", ")", "{", "$", "arrAttr", "[", "strtolower", "(", "trim", "(", "$", "name", ")", ")", "]", "=", "strtolower", "(", "trim", "(", "$", "name", ")", ")", ";", "}", "else", "{", "if", "(", "substr", "(", "$", "value", ",", "0", ",", "1", ")", "==", "\"\\\"\"", "||", "substr", "(", "$", "value", ",", "0", ",", "1", ")", "==", "\"'\"", ")", "{", "$", "value", "=", "substr", "(", "$", "value", ",", "1", ",", "-", "1", ")", ";", "}", "$", "arrAttr", "[", "strtolower", "(", "trim", "(", "$", "name", ")", ")", "]", "=", "trim", "(", "$", "value", ")", ";", "}", "}", "return", "$", "arrAttr", ";", "}", "}", "}" ]
Returns a valid atrributes array from either a string or array @param mixed $attributes Either a typical HTML attribute string or an associative array @access private
[ "Returns", "a", "valid", "atrributes", "array", "from", "either", "a", "string", "or", "array" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/Common.php#L182-L216
219,619
moodle/moodle
lib/pear/HTML/Common.php
HTML_Common._removeAttr
function _removeAttr($attr, &$attributes) { $attr = strtolower($attr); if (isset($attributes[$attr])) { unset($attributes[$attr]); } }
php
function _removeAttr($attr, &$attributes) { $attr = strtolower($attr); if (isset($attributes[$attr])) { unset($attributes[$attr]); } }
[ "function", "_removeAttr", "(", "$", "attr", ",", "&", "$", "attributes", ")", "{", "$", "attr", "=", "strtolower", "(", "$", "attr", ")", ";", "if", "(", "isset", "(", "$", "attributes", "[", "$", "attr", "]", ")", ")", "{", "unset", "(", "$", "attributes", "[", "$", "attr", "]", ")", ";", "}", "}" ]
Removes the given attribute from the given array @param string $attr Attribute name @param array $attributes Attribute array @since 1.4 @access private @return void @throws
[ "Removes", "the", "given", "attribute", "from", "the", "given", "array" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/Common.php#L263-L269
219,620
moodle/moodle
mod/forum/classes/output/email/renderer_textemail.php
renderer_textemail.format_message_text
public function format_message_text($cm, $post) { $message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', \context_module::instance($cm->id)->id, 'mod_forum', 'post', $post->id); return format_text_email($message, $post->messageformat); }
php
public function format_message_text($cm, $post) { $message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', \context_module::instance($cm->id)->id, 'mod_forum', 'post', $post->id); return format_text_email($message, $post->messageformat); }
[ "public", "function", "format_message_text", "(", "$", "cm", ",", "$", "post", ")", "{", "$", "message", "=", "file_rewrite_pluginfile_urls", "(", "$", "post", "->", "message", ",", "'pluginfile.php'", ",", "\\", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", "->", "id", ",", "'mod_forum'", ",", "'post'", ",", "$", "post", "->", "id", ")", ";", "return", "format_text_email", "(", "$", "message", ",", "$", "post", "->", "messageformat", ")", ";", "}" ]
The plaintext version of the e-mail message. @param \stdClass $cm @param \stdClass $post @return string
[ "The", "plaintext", "version", "of", "the", "e", "-", "mail", "message", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/output/email/renderer_textemail.php#L55-L60
219,621
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Encoder.php
HTMLPurifier_Encoder.unsafeIconv
public static function unsafeIconv($in, $out, $text) { set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler')); $r = iconv($in, $out, $text); restore_error_handler(); return $r; }
php
public static function unsafeIconv($in, $out, $text) { set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler')); $r = iconv($in, $out, $text); restore_error_handler(); return $r; }
[ "public", "static", "function", "unsafeIconv", "(", "$", "in", ",", "$", "out", ",", "$", "text", ")", "{", "set_error_handler", "(", "array", "(", "'HTMLPurifier_Encoder'", ",", "'muteErrorHandler'", ")", ")", ";", "$", "r", "=", "iconv", "(", "$", "in", ",", "$", "out", ",", "$", "text", ")", ";", "restore_error_handler", "(", ")", ";", "return", "$", "r", ";", "}" ]
iconv wrapper which mutes errors, but doesn't work around bugs. @param string $in Input encoding @param string $out Output encoding @param string $text The text to convert @return string
[ "iconv", "wrapper", "which", "mutes", "errors", "but", "doesn", "t", "work", "around", "bugs", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Encoder.php#L32-L38
219,622
moodle/moodle
auth/cas/CAS/CAS/ProxiedService/Abstract.php
CAS_ProxiedService_Abstract.setProxyTicket
public function setProxyTicket ($proxyTicket) { if (empty($proxyTicket)) { throw new CAS_InvalidArgumentException( 'Trying to initialize with an empty proxy ticket.' ); } if (!empty($this->_proxyTicket)) { throw new CAS_OutOfSequenceException( 'Already initialized, cannot change the proxy ticket.' ); } $this->_proxyTicket = $proxyTicket; }
php
public function setProxyTicket ($proxyTicket) { if (empty($proxyTicket)) { throw new CAS_InvalidArgumentException( 'Trying to initialize with an empty proxy ticket.' ); } if (!empty($this->_proxyTicket)) { throw new CAS_OutOfSequenceException( 'Already initialized, cannot change the proxy ticket.' ); } $this->_proxyTicket = $proxyTicket; }
[ "public", "function", "setProxyTicket", "(", "$", "proxyTicket", ")", "{", "if", "(", "empty", "(", "$", "proxyTicket", ")", ")", "{", "throw", "new", "CAS_InvalidArgumentException", "(", "'Trying to initialize with an empty proxy ticket.'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "_proxyTicket", ")", ")", "{", "throw", "new", "CAS_OutOfSequenceException", "(", "'Already initialized, cannot change the proxy ticket.'", ")", ";", "}", "$", "this", "->", "_proxyTicket", "=", "$", "proxyTicket", ";", "}" ]
Register a proxy ticket with the Proxy that it can use when making requests. @param string $proxyTicket proxy ticket @return void @throws InvalidArgumentException If the $proxyTicket is invalid. @throws CAS_OutOfSequenceException If called after a proxy ticket has already been initialized/set.
[ "Register", "a", "proxy", "ticket", "with", "the", "Proxy", "that", "it", "can", "use", "when", "making", "requests", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/ProxiedService/Abstract.php#L61-L74
219,623
moodle/moodle
auth/cas/CAS/CAS/ProxiedService/Abstract.php
CAS_ProxiedService_Abstract.initializeProxyTicket
protected function initializeProxyTicket() { if (!empty($this->_proxyTicket)) { throw new CAS_OutOfSequenceException( 'Already initialized, cannot initialize again.' ); } // Allow usage of a particular CAS_Client for unit testing. if (empty($this->_casClient)) { phpCAS::initializeProxiedService($this); } else { $this->_casClient->initializeProxiedService($this); } }
php
protected function initializeProxyTicket() { if (!empty($this->_proxyTicket)) { throw new CAS_OutOfSequenceException( 'Already initialized, cannot initialize again.' ); } // Allow usage of a particular CAS_Client for unit testing. if (empty($this->_casClient)) { phpCAS::initializeProxiedService($this); } else { $this->_casClient->initializeProxiedService($this); } }
[ "protected", "function", "initializeProxyTicket", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "_proxyTicket", ")", ")", "{", "throw", "new", "CAS_OutOfSequenceException", "(", "'Already initialized, cannot initialize again.'", ")", ";", "}", "// Allow usage of a particular CAS_Client for unit testing.", "if", "(", "empty", "(", "$", "this", "->", "_casClient", ")", ")", "{", "phpCAS", "::", "initializeProxiedService", "(", "$", "this", ")", ";", "}", "else", "{", "$", "this", "->", "_casClient", "->", "initializeProxiedService", "(", "$", "this", ")", ";", "}", "}" ]
Fetch our proxy ticket. Descendent classes should call this method once their service URL is available to initialize their proxy ticket. @return void @throws CAS_OutOfSequenceException If called after a proxy ticket has already been initialized.
[ "Fetch", "our", "proxy", "ticket", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/ProxiedService/Abstract.php#L133-L146
219,624
moodle/moodle
analytics/classes/course.php
course.instance
public static function instance($course, ?\context $context = null) { $courseid = $course; if (!is_scalar($courseid)) { $courseid = $course->id; } if (self::$cachedid === $courseid) { return self::$cachedinstance; } $cachedinstance = new \core_analytics\course($course, $context); self::$cachedinstance = $cachedinstance; self::$cachedid = (int)$courseid; return self::$cachedinstance; }
php
public static function instance($course, ?\context $context = null) { $courseid = $course; if (!is_scalar($courseid)) { $courseid = $course->id; } if (self::$cachedid === $courseid) { return self::$cachedinstance; } $cachedinstance = new \core_analytics\course($course, $context); self::$cachedinstance = $cachedinstance; self::$cachedid = (int)$courseid; return self::$cachedinstance; }
[ "public", "static", "function", "instance", "(", "$", "course", ",", "?", "\\", "context", "$", "context", "=", "null", ")", "{", "$", "courseid", "=", "$", "course", ";", "if", "(", "!", "is_scalar", "(", "$", "courseid", ")", ")", "{", "$", "courseid", "=", "$", "course", "->", "id", ";", "}", "if", "(", "self", "::", "$", "cachedid", "===", "$", "courseid", ")", "{", "return", "self", "::", "$", "cachedinstance", ";", "}", "$", "cachedinstance", "=", "new", "\\", "core_analytics", "\\", "course", "(", "$", "course", ",", "$", "context", ")", ";", "self", "::", "$", "cachedinstance", "=", "$", "cachedinstance", ";", "self", "::", "$", "cachedid", "=", "(", "int", ")", "$", "courseid", ";", "return", "self", "::", "$", "cachedinstance", ";", "}" ]
Returns an analytics course instance. Lazy load of course data, students and teachers. @param int|\stdClass $course Course object or course id @param \context|null $context @return \core_analytics\course
[ "Returns", "an", "analytics", "course", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/course.php#L162-L177
219,625
moodle/moodle
analytics/classes/course.php
course.load
protected function load() { // The instance constructor could be already loaded with the full course object. Using shortname // because it is a required course field. if (empty($this->course->shortname)) { $this->course = get_course($this->course->id); } $this->coursecontext = $this->get_context(); $this->now = time(); // Get the course users, including users assigned to student and teacher roles at an higher context. $cache = \cache::make_from_params(\cache_store::MODE_REQUEST, 'core_analytics', 'rolearchetypes'); // Flag the instance as loaded. $this->loaded = true; if (!$studentroles = $cache->get('student')) { $studentroles = array_keys(get_archetype_roles('student')); $cache->set('student', $studentroles); } $this->studentids = $this->get_user_ids($studentroles); if (!$teacherroles = $cache->get('teacher')) { $teacherroles = array_keys(get_archetype_roles('editingteacher') + get_archetype_roles('teacher')); $cache->set('teacher', $teacherroles); } $this->teacherids = $this->get_user_ids($teacherroles); }
php
protected function load() { // The instance constructor could be already loaded with the full course object. Using shortname // because it is a required course field. if (empty($this->course->shortname)) { $this->course = get_course($this->course->id); } $this->coursecontext = $this->get_context(); $this->now = time(); // Get the course users, including users assigned to student and teacher roles at an higher context. $cache = \cache::make_from_params(\cache_store::MODE_REQUEST, 'core_analytics', 'rolearchetypes'); // Flag the instance as loaded. $this->loaded = true; if (!$studentroles = $cache->get('student')) { $studentroles = array_keys(get_archetype_roles('student')); $cache->set('student', $studentroles); } $this->studentids = $this->get_user_ids($studentroles); if (!$teacherroles = $cache->get('teacher')) { $teacherroles = array_keys(get_archetype_roles('editingteacher') + get_archetype_roles('teacher')); $cache->set('teacher', $teacherroles); } $this->teacherids = $this->get_user_ids($teacherroles); }
[ "protected", "function", "load", "(", ")", "{", "// The instance constructor could be already loaded with the full course object. Using shortname", "// because it is a required course field.", "if", "(", "empty", "(", "$", "this", "->", "course", "->", "shortname", ")", ")", "{", "$", "this", "->", "course", "=", "get_course", "(", "$", "this", "->", "course", "->", "id", ")", ";", "}", "$", "this", "->", "coursecontext", "=", "$", "this", "->", "get_context", "(", ")", ";", "$", "this", "->", "now", "=", "time", "(", ")", ";", "// Get the course users, including users assigned to student and teacher roles at an higher context.", "$", "cache", "=", "\\", "cache", "::", "make_from_params", "(", "\\", "cache_store", "::", "MODE_REQUEST", ",", "'core_analytics'", ",", "'rolearchetypes'", ")", ";", "// Flag the instance as loaded.", "$", "this", "->", "loaded", "=", "true", ";", "if", "(", "!", "$", "studentroles", "=", "$", "cache", "->", "get", "(", "'student'", ")", ")", "{", "$", "studentroles", "=", "array_keys", "(", "get_archetype_roles", "(", "'student'", ")", ")", ";", "$", "cache", "->", "set", "(", "'student'", ",", "$", "studentroles", ")", ";", "}", "$", "this", "->", "studentids", "=", "$", "this", "->", "get_user_ids", "(", "$", "studentroles", ")", ";", "if", "(", "!", "$", "teacherroles", "=", "$", "cache", "->", "get", "(", "'teacher'", ")", ")", "{", "$", "teacherroles", "=", "array_keys", "(", "get_archetype_roles", "(", "'editingteacher'", ")", "+", "get_archetype_roles", "(", "'teacher'", ")", ")", ";", "$", "cache", "->", "set", "(", "'teacher'", ",", "$", "teacherroles", ")", ";", "}", "$", "this", "->", "teacherids", "=", "$", "this", "->", "get_user_ids", "(", "$", "teacherroles", ")", ";", "}" ]
Loads the analytics course object. @return void
[ "Loads", "the", "analytics", "course", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/course.php#L193-L222
219,626
moodle/moodle
analytics/classes/course.php
course.get_start
public function get_start() { if ($this->starttime !== null) { return $this->starttime; } // The field always exist but may have no valid if the course is created through a sync process. if (!empty($this->get_course_data()->startdate)) { $this->starttime = (int)$this->get_course_data()->startdate; } else { $this->starttime = 0; } return $this->starttime; }
php
public function get_start() { if ($this->starttime !== null) { return $this->starttime; } // The field always exist but may have no valid if the course is created through a sync process. if (!empty($this->get_course_data()->startdate)) { $this->starttime = (int)$this->get_course_data()->startdate; } else { $this->starttime = 0; } return $this->starttime; }
[ "public", "function", "get_start", "(", ")", "{", "if", "(", "$", "this", "->", "starttime", "!==", "null", ")", "{", "return", "$", "this", "->", "starttime", ";", "}", "// The field always exist but may have no valid if the course is created through a sync process.", "if", "(", "!", "empty", "(", "$", "this", "->", "get_course_data", "(", ")", "->", "startdate", ")", ")", "{", "$", "this", "->", "starttime", "=", "(", "int", ")", "$", "this", "->", "get_course_data", "(", ")", "->", "startdate", ";", "}", "else", "{", "$", "this", "->", "starttime", "=", "0", ";", "}", "return", "$", "this", "->", "starttime", ";", "}" ]
Get the course start timestamp. @return int Timestamp or 0 if has not started yet.
[ "Get", "the", "course", "start", "timestamp", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/course.php#L250-L264
219,627
moodle/moodle
analytics/classes/course.php
course.guess_start
public function guess_start() { global $DB; if (!$this->get_total_logs()) { // Can't guess. return 0; } if (!$logstore = \core_analytics\manager::get_analytics_logstore()) { return 0; } // We first try to find current course student logs. $firstlogs = array(); foreach ($this->get_students() as $studentid) { // Grrr, we are limited by logging API, we could do this easily with a // select min(timecreated) from xx where courseid = yy group by userid. // Filters based on the premise that more than 90% of people will be using // standard logstore, which contains a userid, contextlevel, contextinstanceid index. $select = "userid = :userid AND contextlevel = :contextlevel AND contextinstanceid = :contextinstanceid"; $params = array('userid' => $studentid, 'contextlevel' => CONTEXT_COURSE, 'contextinstanceid' => $this->get_id()); $events = $logstore->get_events_select($select, $params, 'timecreated ASC', 0, 1); if ($events) { $event = reset($events); $firstlogs[] = $event->timecreated; } } if (empty($firstlogs)) { // Can't guess if no student accesses. return 0; } sort($firstlogs); $firstlogsmedian = $this->median($firstlogs); $studentenrolments = enrol_get_course_users($this->get_id(), $this->get_students()); if (empty($studentenrolments)) { return 0; } $enrolstart = array(); foreach ($studentenrolments as $studentenrolment) { $enrolstart[] = ($studentenrolment->uetimestart) ? $studentenrolment->uetimestart : $studentenrolment->uetimecreated; } sort($enrolstart); $enrolstartmedian = $this->median($enrolstart); return intval(($enrolstartmedian + $firstlogsmedian) / 2); }
php
public function guess_start() { global $DB; if (!$this->get_total_logs()) { // Can't guess. return 0; } if (!$logstore = \core_analytics\manager::get_analytics_logstore()) { return 0; } // We first try to find current course student logs. $firstlogs = array(); foreach ($this->get_students() as $studentid) { // Grrr, we are limited by logging API, we could do this easily with a // select min(timecreated) from xx where courseid = yy group by userid. // Filters based on the premise that more than 90% of people will be using // standard logstore, which contains a userid, contextlevel, contextinstanceid index. $select = "userid = :userid AND contextlevel = :contextlevel AND contextinstanceid = :contextinstanceid"; $params = array('userid' => $studentid, 'contextlevel' => CONTEXT_COURSE, 'contextinstanceid' => $this->get_id()); $events = $logstore->get_events_select($select, $params, 'timecreated ASC', 0, 1); if ($events) { $event = reset($events); $firstlogs[] = $event->timecreated; } } if (empty($firstlogs)) { // Can't guess if no student accesses. return 0; } sort($firstlogs); $firstlogsmedian = $this->median($firstlogs); $studentenrolments = enrol_get_course_users($this->get_id(), $this->get_students()); if (empty($studentenrolments)) { return 0; } $enrolstart = array(); foreach ($studentenrolments as $studentenrolment) { $enrolstart[] = ($studentenrolment->uetimestart) ? $studentenrolment->uetimestart : $studentenrolment->uetimecreated; } sort($enrolstart); $enrolstartmedian = $this->median($enrolstart); return intval(($enrolstartmedian + $firstlogsmedian) / 2); }
[ "public", "function", "guess_start", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "$", "this", "->", "get_total_logs", "(", ")", ")", "{", "// Can't guess.", "return", "0", ";", "}", "if", "(", "!", "$", "logstore", "=", "\\", "core_analytics", "\\", "manager", "::", "get_analytics_logstore", "(", ")", ")", "{", "return", "0", ";", "}", "// We first try to find current course student logs.", "$", "firstlogs", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "get_students", "(", ")", "as", "$", "studentid", ")", "{", "// Grrr, we are limited by logging API, we could do this easily with a", "// select min(timecreated) from xx where courseid = yy group by userid.", "// Filters based on the premise that more than 90% of people will be using", "// standard logstore, which contains a userid, contextlevel, contextinstanceid index.", "$", "select", "=", "\"userid = :userid AND contextlevel = :contextlevel AND contextinstanceid = :contextinstanceid\"", ";", "$", "params", "=", "array", "(", "'userid'", "=>", "$", "studentid", ",", "'contextlevel'", "=>", "CONTEXT_COURSE", ",", "'contextinstanceid'", "=>", "$", "this", "->", "get_id", "(", ")", ")", ";", "$", "events", "=", "$", "logstore", "->", "get_events_select", "(", "$", "select", ",", "$", "params", ",", "'timecreated ASC'", ",", "0", ",", "1", ")", ";", "if", "(", "$", "events", ")", "{", "$", "event", "=", "reset", "(", "$", "events", ")", ";", "$", "firstlogs", "[", "]", "=", "$", "event", "->", "timecreated", ";", "}", "}", "if", "(", "empty", "(", "$", "firstlogs", ")", ")", "{", "// Can't guess if no student accesses.", "return", "0", ";", "}", "sort", "(", "$", "firstlogs", ")", ";", "$", "firstlogsmedian", "=", "$", "this", "->", "median", "(", "$", "firstlogs", ")", ";", "$", "studentenrolments", "=", "enrol_get_course_users", "(", "$", "this", "->", "get_id", "(", ")", ",", "$", "this", "->", "get_students", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "studentenrolments", ")", ")", "{", "return", "0", ";", "}", "$", "enrolstart", "=", "array", "(", ")", ";", "foreach", "(", "$", "studentenrolments", "as", "$", "studentenrolment", ")", "{", "$", "enrolstart", "[", "]", "=", "(", "$", "studentenrolment", "->", "uetimestart", ")", "?", "$", "studentenrolment", "->", "uetimestart", ":", "$", "studentenrolment", "->", "uetimecreated", ";", "}", "sort", "(", "$", "enrolstart", ")", ";", "$", "enrolstartmedian", "=", "$", "this", "->", "median", "(", "$", "enrolstart", ")", ";", "return", "intval", "(", "(", "$", "enrolstartmedian", "+", "$", "firstlogsmedian", ")", "/", "2", ")", ";", "}" ]
Guesses the start of the course based on students' activity and enrolment start dates. @return int
[ "Guesses", "the", "start", "of", "the", "course", "based", "on", "students", "activity", "and", "enrolment", "start", "dates", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/course.php#L271-L320
219,628
moodle/moodle
analytics/classes/course.php
course.was_started
public function was_started() { if ($this->started === null) { if ($this->get_start() === 0 || $this->now < $this->get_start()) { // Not yet started. $this->started = false; } else { $this->started = true; } } return $this->started; }
php
public function was_started() { if ($this->started === null) { if ($this->get_start() === 0 || $this->now < $this->get_start()) { // Not yet started. $this->started = false; } else { $this->started = true; } } return $this->started; }
[ "public", "function", "was_started", "(", ")", "{", "if", "(", "$", "this", "->", "started", "===", "null", ")", "{", "if", "(", "$", "this", "->", "get_start", "(", ")", "===", "0", "||", "$", "this", "->", "now", "<", "$", "this", "->", "get_start", "(", ")", ")", "{", "// Not yet started.", "$", "this", "->", "started", "=", "false", ";", "}", "else", "{", "$", "this", "->", "started", "=", "true", ";", "}", "}", "return", "$", "this", "->", "started", ";", "}" ]
Has the course started? @return bool
[ "Has", "the", "course", "started?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/course.php#L404-L416
219,629
moodle/moodle
analytics/classes/course.php
course.is_finished
public function is_finished() { if ($this->finished === null) { $endtime = $this->get_end(); if ($endtime === 0 || $this->now < $endtime) { // It is not yet finished or no idea when it finishes. $this->finished = false; } else { $this->finished = true; } } return $this->finished; }
php
public function is_finished() { if ($this->finished === null) { $endtime = $this->get_end(); if ($endtime === 0 || $this->now < $endtime) { // It is not yet finished or no idea when it finishes. $this->finished = false; } else { $this->finished = true; } } return $this->finished; }
[ "public", "function", "is_finished", "(", ")", "{", "if", "(", "$", "this", "->", "finished", "===", "null", ")", "{", "$", "endtime", "=", "$", "this", "->", "get_end", "(", ")", ";", "if", "(", "$", "endtime", "===", "0", "||", "$", "this", "->", "now", "<", "$", "endtime", ")", "{", "// It is not yet finished or no idea when it finishes.", "$", "this", "->", "finished", "=", "false", ";", "}", "else", "{", "$", "this", "->", "finished", "=", "true", ";", "}", "}", "return", "$", "this", "->", "finished", ";", "}" ]
Has the course finished? @return bool
[ "Has", "the", "course", "finished?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/course.php#L423-L436
219,630
moodle/moodle
analytics/classes/course.php
course.get_user_ids
public function get_user_ids($roleids) { // We need to index by ra.id as a user may have more than 1 $roles role. $records = get_role_users($roleids, $this->get_context(), true, 'ra.id, u.id AS userid, r.id AS roleid', 'ra.id ASC'); // If a user have more than 1 $roles role array_combine will discard the duplicate. $callable = array($this, 'filter_user_id'); $userids = array_values(array_map($callable, $records)); return array_combine($userids, $userids); }
php
public function get_user_ids($roleids) { // We need to index by ra.id as a user may have more than 1 $roles role. $records = get_role_users($roleids, $this->get_context(), true, 'ra.id, u.id AS userid, r.id AS roleid', 'ra.id ASC'); // If a user have more than 1 $roles role array_combine will discard the duplicate. $callable = array($this, 'filter_user_id'); $userids = array_values(array_map($callable, $records)); return array_combine($userids, $userids); }
[ "public", "function", "get_user_ids", "(", "$", "roleids", ")", "{", "// We need to index by ra.id as a user may have more than 1 $roles role.", "$", "records", "=", "get_role_users", "(", "$", "roleids", ",", "$", "this", "->", "get_context", "(", ")", ",", "true", ",", "'ra.id, u.id AS userid, r.id AS roleid'", ",", "'ra.id ASC'", ")", ";", "// If a user have more than 1 $roles role array_combine will discard the duplicate.", "$", "callable", "=", "array", "(", "$", "this", ",", "'filter_user_id'", ")", ";", "$", "userids", "=", "array_values", "(", "array_map", "(", "$", "callable", ",", "$", "records", ")", ")", ";", "return", "array_combine", "(", "$", "userids", ",", "$", "userids", ")", ";", "}" ]
Returns a list of user ids matching the specified roles in this course. @param array $roleids @return array
[ "Returns", "a", "list", "of", "user", "ids", "matching", "the", "specified", "roles", "in", "this", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/course.php#L444-L453
219,631
moodle/moodle
analytics/classes/course.php
course.get_total_logs
public function get_total_logs() { global $DB; // No logs if no students. if (empty($this->get_students())) { return 0; } if ($this->ntotallogs === null) { list($filterselect, $filterparams) = $this->course_students_query_filter(); if (!$logstore = \core_analytics\manager::get_analytics_logstore()) { $this->ntotallogs = 0; } else { $this->ntotallogs = $logstore->get_events_select_count($filterselect, $filterparams); } } return $this->ntotallogs; }
php
public function get_total_logs() { global $DB; // No logs if no students. if (empty($this->get_students())) { return 0; } if ($this->ntotallogs === null) { list($filterselect, $filterparams) = $this->course_students_query_filter(); if (!$logstore = \core_analytics\manager::get_analytics_logstore()) { $this->ntotallogs = 0; } else { $this->ntotallogs = $logstore->get_events_select_count($filterselect, $filterparams); } } return $this->ntotallogs; }
[ "public", "function", "get_total_logs", "(", ")", "{", "global", "$", "DB", ";", "// No logs if no students.", "if", "(", "empty", "(", "$", "this", "->", "get_students", "(", ")", ")", ")", "{", "return", "0", ";", "}", "if", "(", "$", "this", "->", "ntotallogs", "===", "null", ")", "{", "list", "(", "$", "filterselect", ",", "$", "filterparams", ")", "=", "$", "this", "->", "course_students_query_filter", "(", ")", ";", "if", "(", "!", "$", "logstore", "=", "\\", "core_analytics", "\\", "manager", "::", "get_analytics_logstore", "(", ")", ")", "{", "$", "this", "->", "ntotallogs", "=", "0", ";", "}", "else", "{", "$", "this", "->", "ntotallogs", "=", "$", "logstore", "->", "get_events_select_count", "(", "$", "filterselect", ",", "$", "filterparams", ")", ";", "}", "}", "return", "$", "this", "->", "ntotallogs", ";", "}" ]
Returns the total number of student logs in the course @return int
[ "Returns", "the", "total", "number", "of", "student", "logs", "in", "the", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/course.php#L474-L492
219,632
moodle/moodle
analytics/classes/course.php
course.get_all_activities
public function get_all_activities($activitytype) { // Using is set because we set it to false if there are no activities. if (!isset($this->courseactivities[$activitytype])) { $modinfo = get_fast_modinfo($this->get_course_data(), -1); $instances = $modinfo->get_instances_of($activitytype); if ($instances) { $this->courseactivities[$activitytype] = array(); foreach ($instances as $instance) { // By context. $this->courseactivities[$activitytype][$instance->context->id] = $instance; } } else { $this->courseactivities[$activitytype] = false; } } return $this->courseactivities[$activitytype]; }
php
public function get_all_activities($activitytype) { // Using is set because we set it to false if there are no activities. if (!isset($this->courseactivities[$activitytype])) { $modinfo = get_fast_modinfo($this->get_course_data(), -1); $instances = $modinfo->get_instances_of($activitytype); if ($instances) { $this->courseactivities[$activitytype] = array(); foreach ($instances as $instance) { // By context. $this->courseactivities[$activitytype][$instance->context->id] = $instance; } } else { $this->courseactivities[$activitytype] = false; } } return $this->courseactivities[$activitytype]; }
[ "public", "function", "get_all_activities", "(", "$", "activitytype", ")", "{", "// Using is set because we set it to false if there are no activities.", "if", "(", "!", "isset", "(", "$", "this", "->", "courseactivities", "[", "$", "activitytype", "]", ")", ")", "{", "$", "modinfo", "=", "get_fast_modinfo", "(", "$", "this", "->", "get_course_data", "(", ")", ",", "-", "1", ")", ";", "$", "instances", "=", "$", "modinfo", "->", "get_instances_of", "(", "$", "activitytype", ")", ";", "if", "(", "$", "instances", ")", "{", "$", "this", "->", "courseactivities", "[", "$", "activitytype", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "instances", "as", "$", "instance", ")", "{", "// By context.", "$", "this", "->", "courseactivities", "[", "$", "activitytype", "]", "[", "$", "instance", "->", "context", "->", "id", "]", "=", "$", "instance", ";", "}", "}", "else", "{", "$", "this", "->", "courseactivities", "[", "$", "activitytype", "]", "=", "false", ";", "}", "}", "return", "$", "this", "->", "courseactivities", "[", "$", "activitytype", "]", ";", "}" ]
Returns all the activities of the provided type the course has. @param string $activitytype @return array
[ "Returns", "all", "the", "activities", "of", "the", "provided", "type", "the", "course", "has", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/course.php#L500-L519
219,633
moodle/moodle
analytics/classes/course.php
course.get_student_grades
public function get_student_grades($courseactivities) { if (empty($courseactivities)) { return array(); } $grades = array(); foreach ($courseactivities as $contextid => $instance) { $gradesinfo = grade_get_grades($this->course->id, 'mod', $instance->modname, $instance->instance, $this->studentids); // Sort them by activity context and user. if ($gradesinfo && $gradesinfo->items) { foreach ($gradesinfo->items as $gradeitem) { foreach ($gradeitem->grades as $userid => $grade) { if (empty($grades[$contextid][$userid])) { // Initialise it as array because a single activity can have multiple grade items (e.g. workshop). $grades[$contextid][$userid] = array(); } $grades[$contextid][$userid][$gradeitem->id] = $grade; } } } } return $grades; }
php
public function get_student_grades($courseactivities) { if (empty($courseactivities)) { return array(); } $grades = array(); foreach ($courseactivities as $contextid => $instance) { $gradesinfo = grade_get_grades($this->course->id, 'mod', $instance->modname, $instance->instance, $this->studentids); // Sort them by activity context and user. if ($gradesinfo && $gradesinfo->items) { foreach ($gradesinfo->items as $gradeitem) { foreach ($gradeitem->grades as $userid => $grade) { if (empty($grades[$contextid][$userid])) { // Initialise it as array because a single activity can have multiple grade items (e.g. workshop). $grades[$contextid][$userid] = array(); } $grades[$contextid][$userid][$gradeitem->id] = $grade; } } } } return $grades; }
[ "public", "function", "get_student_grades", "(", "$", "courseactivities", ")", "{", "if", "(", "empty", "(", "$", "courseactivities", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "grades", "=", "array", "(", ")", ";", "foreach", "(", "$", "courseactivities", "as", "$", "contextid", "=>", "$", "instance", ")", "{", "$", "gradesinfo", "=", "grade_get_grades", "(", "$", "this", "->", "course", "->", "id", ",", "'mod'", ",", "$", "instance", "->", "modname", ",", "$", "instance", "->", "instance", ",", "$", "this", "->", "studentids", ")", ";", "// Sort them by activity context and user.", "if", "(", "$", "gradesinfo", "&&", "$", "gradesinfo", "->", "items", ")", "{", "foreach", "(", "$", "gradesinfo", "->", "items", "as", "$", "gradeitem", ")", "{", "foreach", "(", "$", "gradeitem", "->", "grades", "as", "$", "userid", "=>", "$", "grade", ")", "{", "if", "(", "empty", "(", "$", "grades", "[", "$", "contextid", "]", "[", "$", "userid", "]", ")", ")", "{", "// Initialise it as array because a single activity can have multiple grade items (e.g. workshop).", "$", "grades", "[", "$", "contextid", "]", "[", "$", "userid", "]", "=", "array", "(", ")", ";", "}", "$", "grades", "[", "$", "contextid", "]", "[", "$", "userid", "]", "[", "$", "gradeitem", "->", "id", "]", "=", "$", "grade", ";", "}", "}", "}", "}", "return", "$", "grades", ";", "}" ]
Returns the course students grades. @param array $courseactivities @return array
[ "Returns", "the", "course", "students", "grades", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/course.php#L527-L552
219,634
moodle/moodle
analytics/classes/course.php
course.update_loop_times
protected function update_loop_times($start, $end) { $avg = intval(($start + $end) / 2); return array($start, $avg, $end); }
php
protected function update_loop_times($start, $end) { $avg = intval(($start + $end) / 2); return array($start, $avg, $end); }
[ "protected", "function", "update_loop_times", "(", "$", "start", ",", "$", "end", ")", "{", "$", "avg", "=", "intval", "(", "(", "$", "start", "+", "$", "end", ")", "/", "2", ")", ";", "return", "array", "(", "$", "start", ",", "$", "avg", ",", "$", "end", ")", ";", "}" ]
Returns the average time between 2 timestamps. @param int $start @param int $end @return array [starttime, averagetime, endtime]
[ "Returns", "the", "average", "time", "between", "2", "timestamps", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/course.php#L571-L574
219,635
moodle/moodle
analytics/classes/course.php
course.course_students_query_filter
protected function course_students_query_filter($prefix = false) { global $DB; if ($prefix) { $prefix = $prefix . '.'; } // Check the amount of student logs in the 4 previous weeks. list($studentssql, $studentsparams) = $DB->get_in_or_equal($this->get_students(), SQL_PARAMS_NAMED); $filterselect = $prefix . 'courseid = :courseid AND ' . $prefix . 'userid ' . $studentssql; $filterparams = array('courseid' => $this->course->id) + $studentsparams; return array($filterselect, $filterparams); }
php
protected function course_students_query_filter($prefix = false) { global $DB; if ($prefix) { $prefix = $prefix . '.'; } // Check the amount of student logs in the 4 previous weeks. list($studentssql, $studentsparams) = $DB->get_in_or_equal($this->get_students(), SQL_PARAMS_NAMED); $filterselect = $prefix . 'courseid = :courseid AND ' . $prefix . 'userid ' . $studentssql; $filterparams = array('courseid' => $this->course->id) + $studentsparams; return array($filterselect, $filterparams); }
[ "protected", "function", "course_students_query_filter", "(", "$", "prefix", "=", "false", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "prefix", ")", "{", "$", "prefix", "=", "$", "prefix", ".", "'.'", ";", "}", "// Check the amount of student logs in the 4 previous weeks.", "list", "(", "$", "studentssql", ",", "$", "studentsparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "this", "->", "get_students", "(", ")", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "filterselect", "=", "$", "prefix", ".", "'courseid = :courseid AND '", ".", "$", "prefix", ".", "'userid '", ".", "$", "studentssql", ";", "$", "filterparams", "=", "array", "(", "'courseid'", "=>", "$", "this", "->", "course", "->", "id", ")", "+", "$", "studentsparams", ";", "return", "array", "(", "$", "filterselect", ",", "$", "filterparams", ")", ";", "}" ]
Returns the query and params used to filter the logstore by this course students. @param string $prefix @return array
[ "Returns", "the", "query", "and", "params", "used", "to", "filter", "the", "logstore", "by", "this", "course", "students", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/course.php#L582-L595
219,636
moodle/moodle
lib/xmldb/xmldb_structure.php
xmldb_structure.getTable
public function getTable($tablename) { $i = $this->findTableInArray($tablename); if ($i !== null) { return $this->tables[$i]; } return null; }
php
public function getTable($tablename) { $i = $this->findTableInArray($tablename); if ($i !== null) { return $this->tables[$i]; } return null; }
[ "public", "function", "getTable", "(", "$", "tablename", ")", "{", "$", "i", "=", "$", "this", "->", "findTableInArray", "(", "$", "tablename", ")", ";", "if", "(", "$", "i", "!==", "null", ")", "{", "return", "$", "this", "->", "tables", "[", "$", "i", "]", ";", "}", "return", "null", ";", "}" ]
Returns one xmldb_table @param string $tablename @return xmldb_table
[ "Returns", "one", "xmldb_table" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_structure.php#L72-L78
219,637
moodle/moodle
lib/xmldb/xmldb_structure.php
xmldb_structure.findTableInArray
public function findTableInArray($tablename) { foreach ($this->tables as $i => $table) { if ($tablename == $table->getName()) { return $i; } } return null; }
php
public function findTableInArray($tablename) { foreach ($this->tables as $i => $table) { if ($tablename == $table->getName()) { return $i; } } return null; }
[ "public", "function", "findTableInArray", "(", "$", "tablename", ")", "{", "foreach", "(", "$", "this", "->", "tables", "as", "$", "i", "=>", "$", "table", ")", "{", "if", "(", "$", "tablename", "==", "$", "table", "->", "getName", "(", ")", ")", "{", "return", "$", "i", ";", "}", "}", "return", "null", ";", "}" ]
Returns the position of one table in the array. @param string $tablename @return mixed
[ "Returns", "the", "position", "of", "one", "table", "in", "the", "array", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_structure.php#L85-L92
219,638
moodle/moodle
lib/xmldb/xmldb_structure.php
xmldb_structure.orderTables
public function orderTables() { $result = $this->orderElements($this->tables); if ($result) { $this->setTables($result); return true; } else { return false; } }
php
public function orderTables() { $result = $this->orderElements($this->tables); if ($result) { $this->setTables($result); return true; } else { return false; } }
[ "public", "function", "orderTables", "(", ")", "{", "$", "result", "=", "$", "this", "->", "orderElements", "(", "$", "this", "->", "tables", ")", ";", "if", "(", "$", "result", ")", "{", "$", "this", "->", "setTables", "(", "$", "result", ")", ";", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
This function will reorder the array of tables @return bool success
[ "This", "function", "will", "reorder", "the", "array", "of", "tables" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_structure.php#L98-L106
219,639
moodle/moodle
lib/xmldb/xmldb_structure.php
xmldb_structure.addTable
public function addTable($table, $after=null) { // Calculate the previous and next tables $prevtable = null; $nexttable = null; if (!$after) { if ($this->tables) { end($this->tables); $prevtable = $this->tables[key($this->tables)]; } } else { $prevtable = $this->getTable($after); } if ($prevtable && $prevtable->getNext()) { $nexttable = $this->getTable($prevtable->getNext()); } // Set current table previous and next attributes if ($prevtable) { $table->setPrevious($prevtable->getName()); $prevtable->setNext($table->getName()); } if ($nexttable) { $table->setNext($nexttable->getName()); $nexttable->setPrevious($table->getName()); } // Some more attributes $table->setLoaded(true); $table->setChanged(true); // Add the new table $this->tables[] = $table; // Reorder the whole structure $this->orderTables($this->tables); // Recalculate the hash $this->calculateHash(true); // We have one new table, so the structure has changed $this->setVersion(userdate(time(), '%Y%m%d', 99, false)); $this->setChanged(true); }
php
public function addTable($table, $after=null) { // Calculate the previous and next tables $prevtable = null; $nexttable = null; if (!$after) { if ($this->tables) { end($this->tables); $prevtable = $this->tables[key($this->tables)]; } } else { $prevtable = $this->getTable($after); } if ($prevtable && $prevtable->getNext()) { $nexttable = $this->getTable($prevtable->getNext()); } // Set current table previous and next attributes if ($prevtable) { $table->setPrevious($prevtable->getName()); $prevtable->setNext($table->getName()); } if ($nexttable) { $table->setNext($nexttable->getName()); $nexttable->setPrevious($table->getName()); } // Some more attributes $table->setLoaded(true); $table->setChanged(true); // Add the new table $this->tables[] = $table; // Reorder the whole structure $this->orderTables($this->tables); // Recalculate the hash $this->calculateHash(true); // We have one new table, so the structure has changed $this->setVersion(userdate(time(), '%Y%m%d', 99, false)); $this->setChanged(true); }
[ "public", "function", "addTable", "(", "$", "table", ",", "$", "after", "=", "null", ")", "{", "// Calculate the previous and next tables", "$", "prevtable", "=", "null", ";", "$", "nexttable", "=", "null", ";", "if", "(", "!", "$", "after", ")", "{", "if", "(", "$", "this", "->", "tables", ")", "{", "end", "(", "$", "this", "->", "tables", ")", ";", "$", "prevtable", "=", "$", "this", "->", "tables", "[", "key", "(", "$", "this", "->", "tables", ")", "]", ";", "}", "}", "else", "{", "$", "prevtable", "=", "$", "this", "->", "getTable", "(", "$", "after", ")", ";", "}", "if", "(", "$", "prevtable", "&&", "$", "prevtable", "->", "getNext", "(", ")", ")", "{", "$", "nexttable", "=", "$", "this", "->", "getTable", "(", "$", "prevtable", "->", "getNext", "(", ")", ")", ";", "}", "// Set current table previous and next attributes", "if", "(", "$", "prevtable", ")", "{", "$", "table", "->", "setPrevious", "(", "$", "prevtable", "->", "getName", "(", ")", ")", ";", "$", "prevtable", "->", "setNext", "(", "$", "table", "->", "getName", "(", ")", ")", ";", "}", "if", "(", "$", "nexttable", ")", "{", "$", "table", "->", "setNext", "(", "$", "nexttable", "->", "getName", "(", ")", ")", ";", "$", "nexttable", "->", "setPrevious", "(", "$", "table", "->", "getName", "(", ")", ")", ";", "}", "// Some more attributes", "$", "table", "->", "setLoaded", "(", "true", ")", ";", "$", "table", "->", "setChanged", "(", "true", ")", ";", "// Add the new table", "$", "this", "->", "tables", "[", "]", "=", "$", "table", ";", "// Reorder the whole structure", "$", "this", "->", "orderTables", "(", "$", "this", "->", "tables", ")", ";", "// Recalculate the hash", "$", "this", "->", "calculateHash", "(", "true", ")", ";", "// We have one new table, so the structure has changed", "$", "this", "->", "setVersion", "(", "userdate", "(", "time", "(", ")", ",", "'%Y%m%d'", ",", "99", ",", "false", ")", ")", ";", "$", "this", "->", "setChanged", "(", "true", ")", ";", "}" ]
Add one table to the structure, allowing to specify the desired order If it's not specified, then the table is added at the end. @param xmldb_table $table @param mixed $after
[ "Add", "one", "table", "to", "the", "structure", "allowing", "to", "specify", "the", "desired", "order", "If", "it", "s", "not", "specified", "then", "the", "table", "is", "added", "at", "the", "end", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_structure.php#L130-L169
219,640
moodle/moodle
lib/xmldb/xmldb_structure.php
xmldb_structure.deleteTable
public function deleteTable($tablename) { $table = $this->getTable($tablename); if ($table) { $i = $this->findTableInArray($tablename); // Look for prev and next table $prevtable = $this->getTable($table->getPrevious()); $nexttable = $this->getTable($table->getNext()); // Change their previous and next attributes if ($prevtable) { $prevtable->setNext($table->getNext()); } if ($nexttable) { $nexttable->setPrevious($table->getPrevious()); } // Delete the table unset($this->tables[$i]); // Reorder the tables $this->orderTables($this->tables); // Recalculate the hash $this->calculateHash(true); // We have one deleted table, so the structure has changed $this->setVersion(userdate(time(), '%Y%m%d', 99, false)); $this->setChanged(true); } }
php
public function deleteTable($tablename) { $table = $this->getTable($tablename); if ($table) { $i = $this->findTableInArray($tablename); // Look for prev and next table $prevtable = $this->getTable($table->getPrevious()); $nexttable = $this->getTable($table->getNext()); // Change their previous and next attributes if ($prevtable) { $prevtable->setNext($table->getNext()); } if ($nexttable) { $nexttable->setPrevious($table->getPrevious()); } // Delete the table unset($this->tables[$i]); // Reorder the tables $this->orderTables($this->tables); // Recalculate the hash $this->calculateHash(true); // We have one deleted table, so the structure has changed $this->setVersion(userdate(time(), '%Y%m%d', 99, false)); $this->setChanged(true); } }
[ "public", "function", "deleteTable", "(", "$", "tablename", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", "$", "tablename", ")", ";", "if", "(", "$", "table", ")", "{", "$", "i", "=", "$", "this", "->", "findTableInArray", "(", "$", "tablename", ")", ";", "// Look for prev and next table", "$", "prevtable", "=", "$", "this", "->", "getTable", "(", "$", "table", "->", "getPrevious", "(", ")", ")", ";", "$", "nexttable", "=", "$", "this", "->", "getTable", "(", "$", "table", "->", "getNext", "(", ")", ")", ";", "// Change their previous and next attributes", "if", "(", "$", "prevtable", ")", "{", "$", "prevtable", "->", "setNext", "(", "$", "table", "->", "getNext", "(", ")", ")", ";", "}", "if", "(", "$", "nexttable", ")", "{", "$", "nexttable", "->", "setPrevious", "(", "$", "table", "->", "getPrevious", "(", ")", ")", ";", "}", "// Delete the table", "unset", "(", "$", "this", "->", "tables", "[", "$", "i", "]", ")", ";", "// Reorder the tables", "$", "this", "->", "orderTables", "(", "$", "this", "->", "tables", ")", ";", "// Recalculate the hash", "$", "this", "->", "calculateHash", "(", "true", ")", ";", "// We have one deleted table, so the structure has changed", "$", "this", "->", "setVersion", "(", "userdate", "(", "time", "(", ")", ",", "'%Y%m%d'", ",", "99", ",", "false", ")", ")", ";", "$", "this", "->", "setChanged", "(", "true", ")", ";", "}", "}" ]
Delete one table from the Structure @param string $tablename
[ "Delete", "one", "table", "from", "the", "Structure" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_structure.php#L175-L200
219,641
moodle/moodle
lib/xmldb/xmldb_structure.php
xmldb_structure.calculateHash
public function calculateHash($recursive = false) { if (!$this->loaded) { $this->hash = null; } else { $key = $this->name . $this->path . $this->comment; if ($this->tables) { foreach ($this->tables as $tbl) { $table = $this->getTable($tbl->getName()); if ($recursive) { $table->calculateHash($recursive); } $key .= $table->getHash(); } } $this->hash = md5($key); } }
php
public function calculateHash($recursive = false) { if (!$this->loaded) { $this->hash = null; } else { $key = $this->name . $this->path . $this->comment; if ($this->tables) { foreach ($this->tables as $tbl) { $table = $this->getTable($tbl->getName()); if ($recursive) { $table->calculateHash($recursive); } $key .= $table->getHash(); } } $this->hash = md5($key); } }
[ "public", "function", "calculateHash", "(", "$", "recursive", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "loaded", ")", "{", "$", "this", "->", "hash", "=", "null", ";", "}", "else", "{", "$", "key", "=", "$", "this", "->", "name", ".", "$", "this", "->", "path", ".", "$", "this", "->", "comment", ";", "if", "(", "$", "this", "->", "tables", ")", "{", "foreach", "(", "$", "this", "->", "tables", "as", "$", "tbl", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", "$", "tbl", "->", "getName", "(", ")", ")", ";", "if", "(", "$", "recursive", ")", "{", "$", "table", "->", "calculateHash", "(", "$", "recursive", ")", ";", "}", "$", "key", ".=", "$", "table", "->", "getHash", "(", ")", ";", "}", "}", "$", "this", "->", "hash", "=", "md5", "(", "$", "key", ")", ";", "}", "}" ]
This function calculate and set the hash of one xmldb_structure @param bool $recursive
[ "This", "function", "calculate", "and", "set", "the", "hash", "of", "one", "xmldb_structure" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_structure.php#L320-L336
219,642
moodle/moodle
lib/xmldb/xmldb_structure.php
xmldb_structure.xmlOutput
public function xmlOutput() { $o = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n"; $o.= '<XMLDB PATH="' . $this->path . '"'; $o.= ' VERSION="' . $this->version . '"'; if ($this->comment) { $o.= ' COMMENT="' . htmlspecialchars($this->comment) . '"'."\n"; } $rel = array_fill(0, count(explode('/', $this->path)), '..'); $rel = implode('/', $rel); $o.= ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'."\n"; $o.= ' xsi:noNamespaceSchemaLocation="'.$rel.'/lib/xmldb/xmldb.xsd"'."\n"; $o.= '>' . "\n"; // Now the tables if ($this->tables) { $o.= ' <TABLES>' . "\n"; foreach ($this->tables as $table) { $o.= $table->xmlOutput(); } $o.= ' </TABLES>' . "\n"; } $o.= '</XMLDB>'; return $o; }
php
public function xmlOutput() { $o = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n"; $o.= '<XMLDB PATH="' . $this->path . '"'; $o.= ' VERSION="' . $this->version . '"'; if ($this->comment) { $o.= ' COMMENT="' . htmlspecialchars($this->comment) . '"'."\n"; } $rel = array_fill(0, count(explode('/', $this->path)), '..'); $rel = implode('/', $rel); $o.= ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'."\n"; $o.= ' xsi:noNamespaceSchemaLocation="'.$rel.'/lib/xmldb/xmldb.xsd"'."\n"; $o.= '>' . "\n"; // Now the tables if ($this->tables) { $o.= ' <TABLES>' . "\n"; foreach ($this->tables as $table) { $o.= $table->xmlOutput(); } $o.= ' </TABLES>' . "\n"; } $o.= '</XMLDB>'; return $o; }
[ "public", "function", "xmlOutput", "(", ")", "{", "$", "o", "=", "'<?xml version=\"1.0\" encoding=\"UTF-8\" ?>'", ".", "\"\\n\"", ";", "$", "o", ".=", "'<XMLDB PATH=\"'", ".", "$", "this", "->", "path", ".", "'\"'", ";", "$", "o", ".=", "' VERSION=\"'", ".", "$", "this", "->", "version", ".", "'\"'", ";", "if", "(", "$", "this", "->", "comment", ")", "{", "$", "o", ".=", "' COMMENT=\"'", ".", "htmlspecialchars", "(", "$", "this", "->", "comment", ")", ".", "'\"'", ".", "\"\\n\"", ";", "}", "$", "rel", "=", "array_fill", "(", "0", ",", "count", "(", "explode", "(", "'/'", ",", "$", "this", "->", "path", ")", ")", ",", "'..'", ")", ";", "$", "rel", "=", "implode", "(", "'/'", ",", "$", "rel", ")", ";", "$", "o", ".=", "' xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"'", ".", "\"\\n\"", ";", "$", "o", ".=", "' xsi:noNamespaceSchemaLocation=\"'", ".", "$", "rel", ".", "'/lib/xmldb/xmldb.xsd\"'", ".", "\"\\n\"", ";", "$", "o", ".=", "'>'", ".", "\"\\n\"", ";", "// Now the tables", "if", "(", "$", "this", "->", "tables", ")", "{", "$", "o", ".=", "' <TABLES>'", ".", "\"\\n\"", ";", "foreach", "(", "$", "this", "->", "tables", "as", "$", "table", ")", "{", "$", "o", ".=", "$", "table", "->", "xmlOutput", "(", ")", ";", "}", "$", "o", ".=", "' </TABLES>'", ".", "\"\\n\"", ";", "}", "$", "o", ".=", "'</XMLDB>'", ";", "return", "$", "o", ";", "}" ]
This function will output the XML text for one structure @return string
[ "This", "function", "will", "output", "the", "XML", "text", "for", "one", "structure" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_structure.php#L342-L365
219,643
moodle/moodle
lib/xmldb/xmldb_structure.php
xmldb_structure.getTableUses
public function getTableUses($tablename) { $uses = array(); // Check if some foreign key in the whole structure is using it // (by comparing the reftable with the tablename) if ($this->tables) { foreach ($this->tables as $table) { $keys = $table->getKeys(); if ($keys) { foreach ($keys as $key) { if ($key->getType() == XMLDB_KEY_FOREIGN) { if ($tablename == $key->getRefTable()) { $uses[] = 'table ' . $table->getName() . ' key ' . $key->getName(); } } } } } } // Return result if (!empty($uses)) { return $uses; } else { return false; } }
php
public function getTableUses($tablename) { $uses = array(); // Check if some foreign key in the whole structure is using it // (by comparing the reftable with the tablename) if ($this->tables) { foreach ($this->tables as $table) { $keys = $table->getKeys(); if ($keys) { foreach ($keys as $key) { if ($key->getType() == XMLDB_KEY_FOREIGN) { if ($tablename == $key->getRefTable()) { $uses[] = 'table ' . $table->getName() . ' key ' . $key->getName(); } } } } } } // Return result if (!empty($uses)) { return $uses; } else { return false; } }
[ "public", "function", "getTableUses", "(", "$", "tablename", ")", "{", "$", "uses", "=", "array", "(", ")", ";", "// Check if some foreign key in the whole structure is using it", "// (by comparing the reftable with the tablename)", "if", "(", "$", "this", "->", "tables", ")", "{", "foreach", "(", "$", "this", "->", "tables", "as", "$", "table", ")", "{", "$", "keys", "=", "$", "table", "->", "getKeys", "(", ")", ";", "if", "(", "$", "keys", ")", "{", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "$", "key", "->", "getType", "(", ")", "==", "XMLDB_KEY_FOREIGN", ")", "{", "if", "(", "$", "tablename", "==", "$", "key", "->", "getRefTable", "(", ")", ")", "{", "$", "uses", "[", "]", "=", "'table '", ".", "$", "table", "->", "getName", "(", ")", ".", "' key '", ".", "$", "key", "->", "getName", "(", ")", ";", "}", "}", "}", "}", "}", "}", "// Return result", "if", "(", "!", "empty", "(", "$", "uses", ")", ")", "{", "return", "$", "uses", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
This function returns the number of uses of one table inside a whole XMLDStructure. Useful to detect if the table must be locked. Return false if no uses are found. @param string $tablename @return mixed
[ "This", "function", "returns", "the", "number", "of", "uses", "of", "one", "table", "inside", "a", "whole", "XMLDStructure", ".", "Useful", "to", "detect", "if", "the", "table", "must", "be", "locked", ".", "Return", "false", "if", "no", "uses", "are", "found", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_structure.php#L374-L401
219,644
moodle/moodle
lib/xmldb/xmldb_structure.php
xmldb_structure.getFieldUses
public function getFieldUses($tablename, $fieldname) { $uses = array(); // Check if any key in the table is using it $table = $this->getTable($tablename); if ($keys = $table->getKeys()) { foreach ($keys as $key) { if (in_array($fieldname, $key->getFields()) || in_array($fieldname, $key->getRefFields())) { $uses[] = 'table ' . $table->getName() . ' key ' . $key->getName(); } } } // Check if any index in the table is using it $table = $this->getTable($tablename); if ($indexes = $table->getIndexes()) { foreach ($indexes as $index) { if (in_array($fieldname, $index->getFields())) { $uses[] = 'table ' . $table->getName() . ' index ' . $index->getName(); } } } // Check if some foreign key in the whole structure is using it // By comparing the reftable and refields with the field) if ($this->tables) { foreach ($this->tables as $table) { $keys = $table->getKeys(); if ($keys) { foreach ($keys as $key) { if ($key->getType() == XMLDB_KEY_FOREIGN) { if ($tablename == $key->getRefTable()) { $reffieds = $key->getRefFields(); if (in_array($fieldname, $key->getRefFields())) { $uses[] = 'table ' . $table->getName() . ' key ' . $key->getName(); } } } } } } } // Return result if (!empty($uses)) { return $uses; } else { return false; } }
php
public function getFieldUses($tablename, $fieldname) { $uses = array(); // Check if any key in the table is using it $table = $this->getTable($tablename); if ($keys = $table->getKeys()) { foreach ($keys as $key) { if (in_array($fieldname, $key->getFields()) || in_array($fieldname, $key->getRefFields())) { $uses[] = 'table ' . $table->getName() . ' key ' . $key->getName(); } } } // Check if any index in the table is using it $table = $this->getTable($tablename); if ($indexes = $table->getIndexes()) { foreach ($indexes as $index) { if (in_array($fieldname, $index->getFields())) { $uses[] = 'table ' . $table->getName() . ' index ' . $index->getName(); } } } // Check if some foreign key in the whole structure is using it // By comparing the reftable and refields with the field) if ($this->tables) { foreach ($this->tables as $table) { $keys = $table->getKeys(); if ($keys) { foreach ($keys as $key) { if ($key->getType() == XMLDB_KEY_FOREIGN) { if ($tablename == $key->getRefTable()) { $reffieds = $key->getRefFields(); if (in_array($fieldname, $key->getRefFields())) { $uses[] = 'table ' . $table->getName() . ' key ' . $key->getName(); } } } } } } } // Return result if (!empty($uses)) { return $uses; } else { return false; } }
[ "public", "function", "getFieldUses", "(", "$", "tablename", ",", "$", "fieldname", ")", "{", "$", "uses", "=", "array", "(", ")", ";", "// Check if any key in the table is using it", "$", "table", "=", "$", "this", "->", "getTable", "(", "$", "tablename", ")", ";", "if", "(", "$", "keys", "=", "$", "table", "->", "getKeys", "(", ")", ")", "{", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "in_array", "(", "$", "fieldname", ",", "$", "key", "->", "getFields", "(", ")", ")", "||", "in_array", "(", "$", "fieldname", ",", "$", "key", "->", "getRefFields", "(", ")", ")", ")", "{", "$", "uses", "[", "]", "=", "'table '", ".", "$", "table", "->", "getName", "(", ")", ".", "' key '", ".", "$", "key", "->", "getName", "(", ")", ";", "}", "}", "}", "// Check if any index in the table is using it", "$", "table", "=", "$", "this", "->", "getTable", "(", "$", "tablename", ")", ";", "if", "(", "$", "indexes", "=", "$", "table", "->", "getIndexes", "(", ")", ")", "{", "foreach", "(", "$", "indexes", "as", "$", "index", ")", "{", "if", "(", "in_array", "(", "$", "fieldname", ",", "$", "index", "->", "getFields", "(", ")", ")", ")", "{", "$", "uses", "[", "]", "=", "'table '", ".", "$", "table", "->", "getName", "(", ")", ".", "' index '", ".", "$", "index", "->", "getName", "(", ")", ";", "}", "}", "}", "// Check if some foreign key in the whole structure is using it", "// By comparing the reftable and refields with the field)", "if", "(", "$", "this", "->", "tables", ")", "{", "foreach", "(", "$", "this", "->", "tables", "as", "$", "table", ")", "{", "$", "keys", "=", "$", "table", "->", "getKeys", "(", ")", ";", "if", "(", "$", "keys", ")", "{", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "$", "key", "->", "getType", "(", ")", "==", "XMLDB_KEY_FOREIGN", ")", "{", "if", "(", "$", "tablename", "==", "$", "key", "->", "getRefTable", "(", ")", ")", "{", "$", "reffieds", "=", "$", "key", "->", "getRefFields", "(", ")", ";", "if", "(", "in_array", "(", "$", "fieldname", ",", "$", "key", "->", "getRefFields", "(", ")", ")", ")", "{", "$", "uses", "[", "]", "=", "'table '", ".", "$", "table", "->", "getName", "(", ")", ".", "' key '", ".", "$", "key", "->", "getName", "(", ")", ";", "}", "}", "}", "}", "}", "}", "}", "// Return result", "if", "(", "!", "empty", "(", "$", "uses", ")", ")", "{", "return", "$", "uses", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
This function returns the number of uses of one field inside a whole xmldb_structure. Useful to detect if the field must be locked. Return false if no uses are found. @param string $tablename @param string $fieldname @return mixed
[ "This", "function", "returns", "the", "number", "of", "uses", "of", "one", "field", "inside", "a", "whole", "xmldb_structure", ".", "Useful", "to", "detect", "if", "the", "field", "must", "be", "locked", ".", "Return", "false", "if", "no", "uses", "are", "found", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_structure.php#L411-L460
219,645
moodle/moodle
lib/xmldb/xmldb_structure.php
xmldb_structure.getKeyUses
public function getKeyUses($tablename, $keyname) { $uses = array(); // Check if some foreign key in the whole structure is using it // (by comparing the reftable and reffields with the fields in the key) $mytable = $this->getTable($tablename); $mykey = $mytable->getKey($keyname); if ($this->tables && $mykey) { foreach ($this->tables as $table) { $allkeys = $table->getKeys(); if ($allkeys) { foreach ($allkeys as $key) { if ($key->getType() != XMLDB_KEY_FOREIGN) { continue; } if ($key->getRefTable() == $tablename && implode(',', $key->getRefFields()) == implode(',', $mykey->getFields())) { $uses[] = 'table ' . $table->getName() . ' key ' . $key->getName(); } } } } } // Return result if (!empty($uses)) { return $uses; } else { return false; } }
php
public function getKeyUses($tablename, $keyname) { $uses = array(); // Check if some foreign key in the whole structure is using it // (by comparing the reftable and reffields with the fields in the key) $mytable = $this->getTable($tablename); $mykey = $mytable->getKey($keyname); if ($this->tables && $mykey) { foreach ($this->tables as $table) { $allkeys = $table->getKeys(); if ($allkeys) { foreach ($allkeys as $key) { if ($key->getType() != XMLDB_KEY_FOREIGN) { continue; } if ($key->getRefTable() == $tablename && implode(',', $key->getRefFields()) == implode(',', $mykey->getFields())) { $uses[] = 'table ' . $table->getName() . ' key ' . $key->getName(); } } } } } // Return result if (!empty($uses)) { return $uses; } else { return false; } }
[ "public", "function", "getKeyUses", "(", "$", "tablename", ",", "$", "keyname", ")", "{", "$", "uses", "=", "array", "(", ")", ";", "// Check if some foreign key in the whole structure is using it", "// (by comparing the reftable and reffields with the fields in the key)", "$", "mytable", "=", "$", "this", "->", "getTable", "(", "$", "tablename", ")", ";", "$", "mykey", "=", "$", "mytable", "->", "getKey", "(", "$", "keyname", ")", ";", "if", "(", "$", "this", "->", "tables", "&&", "$", "mykey", ")", "{", "foreach", "(", "$", "this", "->", "tables", "as", "$", "table", ")", "{", "$", "allkeys", "=", "$", "table", "->", "getKeys", "(", ")", ";", "if", "(", "$", "allkeys", ")", "{", "foreach", "(", "$", "allkeys", "as", "$", "key", ")", "{", "if", "(", "$", "key", "->", "getType", "(", ")", "!=", "XMLDB_KEY_FOREIGN", ")", "{", "continue", ";", "}", "if", "(", "$", "key", "->", "getRefTable", "(", ")", "==", "$", "tablename", "&&", "implode", "(", "','", ",", "$", "key", "->", "getRefFields", "(", ")", ")", "==", "implode", "(", "','", ",", "$", "mykey", "->", "getFields", "(", ")", ")", ")", "{", "$", "uses", "[", "]", "=", "'table '", ".", "$", "table", "->", "getName", "(", ")", ".", "' key '", ".", "$", "key", "->", "getName", "(", ")", ";", "}", "}", "}", "}", "}", "// Return result", "if", "(", "!", "empty", "(", "$", "uses", ")", ")", "{", "return", "$", "uses", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
This function returns the number of uses of one key inside a whole xmldb_structure. Useful to detect if the key must be locked. Return false if no uses are found. @param string $tablename @param string $keyname @return mixed
[ "This", "function", "returns", "the", "number", "of", "uses", "of", "one", "key", "inside", "a", "whole", "xmldb_structure", ".", "Useful", "to", "detect", "if", "the", "key", "must", "be", "locked", ".", "Return", "false", "if", "no", "uses", "are", "found", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_structure.php#L470-L501
219,646
moodle/moodle
lib/xmldb/xmldb_structure.php
xmldb_structure.getAllErrors
public function getAllErrors() { $errors = array(); // First the structure itself if ($this->getError()) { $errors[] = $this->getError(); } // Delegate to tables if ($this->tables) { foreach ($this->tables as $table) { if ($tableerrors = $table->getAllErrors()) { } } // Add them to the errors array if ($tableerrors) { $errors = array_merge($errors, $tableerrors); } } // Return decision if (count($errors)) { return $errors; } else { return false; } }
php
public function getAllErrors() { $errors = array(); // First the structure itself if ($this->getError()) { $errors[] = $this->getError(); } // Delegate to tables if ($this->tables) { foreach ($this->tables as $table) { if ($tableerrors = $table->getAllErrors()) { } } // Add them to the errors array if ($tableerrors) { $errors = array_merge($errors, $tableerrors); } } // Return decision if (count($errors)) { return $errors; } else { return false; } }
[ "public", "function", "getAllErrors", "(", ")", "{", "$", "errors", "=", "array", "(", ")", ";", "// First the structure itself", "if", "(", "$", "this", "->", "getError", "(", ")", ")", "{", "$", "errors", "[", "]", "=", "$", "this", "->", "getError", "(", ")", ";", "}", "// Delegate to tables", "if", "(", "$", "this", "->", "tables", ")", "{", "foreach", "(", "$", "this", "->", "tables", "as", "$", "table", ")", "{", "if", "(", "$", "tableerrors", "=", "$", "table", "->", "getAllErrors", "(", ")", ")", "{", "}", "}", "// Add them to the errors array", "if", "(", "$", "tableerrors", ")", "{", "$", "errors", "=", "array_merge", "(", "$", "errors", ",", "$", "tableerrors", ")", ";", "}", "}", "// Return decision", "if", "(", "count", "(", "$", "errors", ")", ")", "{", "return", "$", "errors", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
This function will return all the errors found in one structure looking recursively inside each table. Returns an array of errors or false @return mixed
[ "This", "function", "will", "return", "all", "the", "errors", "found", "in", "one", "structure", "looking", "recursively", "inside", "each", "table", ".", "Returns", "an", "array", "of", "errors", "or", "false" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_structure.php#L532-L557
219,647
moodle/moodle
course/lib.php
course_request.prepare
public static function prepare($data=null) { if ($data === null) { $data = new stdClass; } $data = file_prepare_standard_editor($data, 'summary', self::summary_editor_options()); return $data; }
php
public static function prepare($data=null) { if ($data === null) { $data = new stdClass; } $data = file_prepare_standard_editor($data, 'summary', self::summary_editor_options()); return $data; }
[ "public", "static", "function", "prepare", "(", "$", "data", "=", "null", ")", "{", "if", "(", "$", "data", "===", "null", ")", "{", "$", "data", "=", "new", "stdClass", ";", "}", "$", "data", "=", "file_prepare_standard_editor", "(", "$", "data", ",", "'summary'", ",", "self", "::", "summary_editor_options", "(", ")", ")", ";", "return", "$", "data", ";", "}" ]
Static function to prepare the summary editor for working with a course request. @static @param null|stdClass $data Optional, an object containing the default values for the form, these may be modified when preparing the editor so this should be called before creating the form @return stdClass An object that can be used to set the default values for an mforms form
[ "Static", "function", "to", "prepare", "the", "summary", "editor", "for", "working", "with", "a", "course", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/lib.php#L2761-L2767
219,648
moodle/moodle
course/lib.php
course_request.create
public static function create($data) { global $USER, $DB, $CFG; $data->requester = $USER->id; // Setting the default category if none set. if (empty($data->category) || empty($CFG->requestcategoryselection)) { $data->category = $CFG->defaultrequestcategory; } // Summary is a required field so copy the text over $data->summary = $data->summary_editor['text']; $data->summaryformat = $data->summary_editor['format']; $data->id = $DB->insert_record('course_request', $data); // Create a new course_request object and return it $request = new course_request($data); // Notify the admin if required. if ($users = get_users_from_config($CFG->courserequestnotify, 'moodle/site:approvecourse')) { $a = new stdClass; $a->link = "$CFG->wwwroot/course/pending.php"; $a->user = fullname($USER); $subject = get_string('courserequest'); $message = get_string('courserequestnotifyemail', 'admin', $a); foreach ($users as $user) { $request->notify($user, $USER, 'courserequested', $subject, $message); } } return $request; }
php
public static function create($data) { global $USER, $DB, $CFG; $data->requester = $USER->id; // Setting the default category if none set. if (empty($data->category) || empty($CFG->requestcategoryselection)) { $data->category = $CFG->defaultrequestcategory; } // Summary is a required field so copy the text over $data->summary = $data->summary_editor['text']; $data->summaryformat = $data->summary_editor['format']; $data->id = $DB->insert_record('course_request', $data); // Create a new course_request object and return it $request = new course_request($data); // Notify the admin if required. if ($users = get_users_from_config($CFG->courserequestnotify, 'moodle/site:approvecourse')) { $a = new stdClass; $a->link = "$CFG->wwwroot/course/pending.php"; $a->user = fullname($USER); $subject = get_string('courserequest'); $message = get_string('courserequestnotifyemail', 'admin', $a); foreach ($users as $user) { $request->notify($user, $USER, 'courserequested', $subject, $message); } } return $request; }
[ "public", "static", "function", "create", "(", "$", "data", ")", "{", "global", "$", "USER", ",", "$", "DB", ",", "$", "CFG", ";", "$", "data", "->", "requester", "=", "$", "USER", "->", "id", ";", "// Setting the default category if none set.", "if", "(", "empty", "(", "$", "data", "->", "category", ")", "||", "empty", "(", "$", "CFG", "->", "requestcategoryselection", ")", ")", "{", "$", "data", "->", "category", "=", "$", "CFG", "->", "defaultrequestcategory", ";", "}", "// Summary is a required field so copy the text over", "$", "data", "->", "summary", "=", "$", "data", "->", "summary_editor", "[", "'text'", "]", ";", "$", "data", "->", "summaryformat", "=", "$", "data", "->", "summary_editor", "[", "'format'", "]", ";", "$", "data", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'course_request'", ",", "$", "data", ")", ";", "// Create a new course_request object and return it", "$", "request", "=", "new", "course_request", "(", "$", "data", ")", ";", "// Notify the admin if required.", "if", "(", "$", "users", "=", "get_users_from_config", "(", "$", "CFG", "->", "courserequestnotify", ",", "'moodle/site:approvecourse'", ")", ")", "{", "$", "a", "=", "new", "stdClass", ";", "$", "a", "->", "link", "=", "\"$CFG->wwwroot/course/pending.php\"", ";", "$", "a", "->", "user", "=", "fullname", "(", "$", "USER", ")", ";", "$", "subject", "=", "get_string", "(", "'courserequest'", ")", ";", "$", "message", "=", "get_string", "(", "'courserequestnotifyemail'", ",", "'admin'", ",", "$", "a", ")", ";", "foreach", "(", "$", "users", "as", "$", "user", ")", "{", "$", "request", "->", "notify", "(", "$", "user", ",", "$", "USER", ",", "'courserequested'", ",", "$", "subject", ",", "$", "message", ")", ";", "}", "}", "return", "$", "request", ";", "}" ]
Static function to create a new course request when passed an array of properties for it. This function also handles saving any files that may have been used in the editor @static @param stdClass $data @return course_request The newly created course request
[ "Static", "function", "to", "create", "a", "new", "course", "request", "when", "passed", "an", "array", "of", "properties", "for", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/lib.php#L2779-L2811
219,649
moodle/moodle
course/lib.php
course_request.get_requester
public function get_requester() { global $DB; static $requesters= array(); if (!array_key_exists($this->properties->requester, $requesters)) { $requesters[$this->properties->requester] = $DB->get_record('user', array('id'=>$this->properties->requester)); } return $requesters[$this->properties->requester]; }
php
public function get_requester() { global $DB; static $requesters= array(); if (!array_key_exists($this->properties->requester, $requesters)) { $requesters[$this->properties->requester] = $DB->get_record('user', array('id'=>$this->properties->requester)); } return $requesters[$this->properties->requester]; }
[ "public", "function", "get_requester", "(", ")", "{", "global", "$", "DB", ";", "static", "$", "requesters", "=", "array", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "this", "->", "properties", "->", "requester", ",", "$", "requesters", ")", ")", "{", "$", "requesters", "[", "$", "this", "->", "properties", "->", "requester", "]", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "properties", "->", "requester", ")", ")", ";", "}", "return", "$", "requesters", "[", "$", "this", "->", "properties", "->", "requester", "]", ";", "}" ]
Returns the user who requested this course Uses a static var to cache the results and cut down the number of db queries @staticvar array $requesters An array of cached users @return stdClass The user who requested the course
[ "Returns", "the", "user", "who", "requested", "this", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/lib.php#L2885-L2892
219,650
moodle/moodle
course/lib.php
course_request.check_shortname_collision
public function check_shortname_collision($shortnamemark = '[*]') { global $DB; if ($this->properties->collision !== null) { return $this->properties->collision; } if (empty($this->properties->shortname)) { debugging('Attempting to check a course request shortname before it has been set', DEBUG_DEVELOPER); $this->properties->collision = false; } else if ($DB->record_exists('course', array('shortname' => $this->properties->shortname))) { if (!empty($shortnamemark)) { $this->properties->shortname .= ' '.$shortnamemark; } $this->properties->collision = true; } else { $this->properties->collision = false; } return $this->properties->collision; }
php
public function check_shortname_collision($shortnamemark = '[*]') { global $DB; if ($this->properties->collision !== null) { return $this->properties->collision; } if (empty($this->properties->shortname)) { debugging('Attempting to check a course request shortname before it has been set', DEBUG_DEVELOPER); $this->properties->collision = false; } else if ($DB->record_exists('course', array('shortname' => $this->properties->shortname))) { if (!empty($shortnamemark)) { $this->properties->shortname .= ' '.$shortnamemark; } $this->properties->collision = true; } else { $this->properties->collision = false; } return $this->properties->collision; }
[ "public", "function", "check_shortname_collision", "(", "$", "shortnamemark", "=", "'[*]'", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "properties", "->", "collision", "!==", "null", ")", "{", "return", "$", "this", "->", "properties", "->", "collision", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "properties", "->", "shortname", ")", ")", "{", "debugging", "(", "'Attempting to check a course request shortname before it has been set'", ",", "DEBUG_DEVELOPER", ")", ";", "$", "this", "->", "properties", "->", "collision", "=", "false", ";", "}", "else", "if", "(", "$", "DB", "->", "record_exists", "(", "'course'", ",", "array", "(", "'shortname'", "=>", "$", "this", "->", "properties", "->", "shortname", ")", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "shortnamemark", ")", ")", "{", "$", "this", "->", "properties", "->", "shortname", ".=", "' '", ".", "$", "shortnamemark", ";", "}", "$", "this", "->", "properties", "->", "collision", "=", "true", ";", "}", "else", "{", "$", "this", "->", "properties", "->", "collision", "=", "false", ";", "}", "return", "$", "this", "->", "properties", "->", "collision", ";", "}" ]
Checks that the shortname used by the course does not conflict with any other courses that exist @param string|null $shortnamemark The string to append to the requests shortname should a conflict be found @return bool true is there is a conflict, false otherwise
[ "Checks", "that", "the", "shortname", "used", "by", "the", "course", "does", "not", "conflict", "with", "any", "other", "courses", "that", "exist" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/lib.php#L2902-L2921
219,651
moodle/moodle
course/lib.php
course_request.get_category
public function get_category() { global $CFG; // If the category is not set, if the current user does not have the rights to change the category, or if the // category does not exist, we set the default category to the course to be approved. // The system level is used because the capability moodle/site:approvecourse is based on a system level. if (empty($this->properties->category) || !has_capability('moodle/course:changecategory', context_system::instance()) || (!$category = core_course_category::get($this->properties->category, IGNORE_MISSING, true))) { $category = core_course_category::get($CFG->defaultrequestcategory, IGNORE_MISSING, true); } if (!$category) { $category = core_course_category::get_default(); } return $category; }
php
public function get_category() { global $CFG; // If the category is not set, if the current user does not have the rights to change the category, or if the // category does not exist, we set the default category to the course to be approved. // The system level is used because the capability moodle/site:approvecourse is based on a system level. if (empty($this->properties->category) || !has_capability('moodle/course:changecategory', context_system::instance()) || (!$category = core_course_category::get($this->properties->category, IGNORE_MISSING, true))) { $category = core_course_category::get($CFG->defaultrequestcategory, IGNORE_MISSING, true); } if (!$category) { $category = core_course_category::get_default(); } return $category; }
[ "public", "function", "get_category", "(", ")", "{", "global", "$", "CFG", ";", "// If the category is not set, if the current user does not have the rights to change the category, or if the", "// category does not exist, we set the default category to the course to be approved.", "// The system level is used because the capability moodle/site:approvecourse is based on a system level.", "if", "(", "empty", "(", "$", "this", "->", "properties", "->", "category", ")", "||", "!", "has_capability", "(", "'moodle/course:changecategory'", ",", "context_system", "::", "instance", "(", ")", ")", "||", "(", "!", "$", "category", "=", "core_course_category", "::", "get", "(", "$", "this", "->", "properties", "->", "category", ",", "IGNORE_MISSING", ",", "true", ")", ")", ")", "{", "$", "category", "=", "core_course_category", "::", "get", "(", "$", "CFG", "->", "defaultrequestcategory", ",", "IGNORE_MISSING", ",", "true", ")", ";", "}", "if", "(", "!", "$", "category", ")", "{", "$", "category", "=", "core_course_category", "::", "get_default", "(", ")", ";", "}", "return", "$", "category", ";", "}" ]
Returns the category where this course request should be created Note that we don't check here that user has a capability to view hidden categories if he has capabilities 'moodle/site:approvecourse' and 'moodle/course:changecategory' @return core_course_category
[ "Returns", "the", "category", "where", "this", "course", "request", "should", "be", "created" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/lib.php#L2932-L2945
219,652
moodle/moodle
course/lib.php
course_request.reject
public function reject($notice) { global $USER, $DB; $user = $DB->get_record('user', array('id' => $this->properties->requester), '*', MUST_EXIST); $this->notify($user, $USER, 'courserequestrejected', get_string('courserejectsubject'), get_string('courserejectemail', 'moodle', $notice)); $this->delete(); }
php
public function reject($notice) { global $USER, $DB; $user = $DB->get_record('user', array('id' => $this->properties->requester), '*', MUST_EXIST); $this->notify($user, $USER, 'courserequestrejected', get_string('courserejectsubject'), get_string('courserejectemail', 'moodle', $notice)); $this->delete(); }
[ "public", "function", "reject", "(", "$", "notice", ")", "{", "global", "$", "USER", ",", "$", "DB", ";", "$", "user", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "properties", "->", "requester", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "this", "->", "notify", "(", "$", "user", ",", "$", "USER", ",", "'courserequestrejected'", ",", "get_string", "(", "'courserejectsubject'", ")", ",", "get_string", "(", "'courserejectemail'", ",", "'moodle'", ",", "$", "notice", ")", ")", ";", "$", "this", "->", "delete", "(", ")", ";", "}" ]
Reject a course request This function rejects a course request, emailing the requesting user the provided notice and then removing the request from the database @param string $notice The message to display to the user
[ "Reject", "a", "course", "request" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/lib.php#L3030-L3035
219,653
moodle/moodle
course/lib.php
course_request.notify
protected function notify($touser, $fromuser, $name='courserequested', $subject, $message, $courseid = null) { $eventdata = new \core\message\message(); $eventdata->courseid = empty($courseid) ? SITEID : $courseid; $eventdata->component = 'moodle'; $eventdata->name = $name; $eventdata->userfrom = $fromuser; $eventdata->userto = $touser; $eventdata->subject = $subject; $eventdata->fullmessage = $message; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; $eventdata->notification = 1; message_send($eventdata); }
php
protected function notify($touser, $fromuser, $name='courserequested', $subject, $message, $courseid = null) { $eventdata = new \core\message\message(); $eventdata->courseid = empty($courseid) ? SITEID : $courseid; $eventdata->component = 'moodle'; $eventdata->name = $name; $eventdata->userfrom = $fromuser; $eventdata->userto = $touser; $eventdata->subject = $subject; $eventdata->fullmessage = $message; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; $eventdata->notification = 1; message_send($eventdata); }
[ "protected", "function", "notify", "(", "$", "touser", ",", "$", "fromuser", ",", "$", "name", "=", "'courserequested'", ",", "$", "subject", ",", "$", "message", ",", "$", "courseid", "=", "null", ")", "{", "$", "eventdata", "=", "new", "\\", "core", "\\", "message", "\\", "message", "(", ")", ";", "$", "eventdata", "->", "courseid", "=", "empty", "(", "$", "courseid", ")", "?", "SITEID", ":", "$", "courseid", ";", "$", "eventdata", "->", "component", "=", "'moodle'", ";", "$", "eventdata", "->", "name", "=", "$", "name", ";", "$", "eventdata", "->", "userfrom", "=", "$", "fromuser", ";", "$", "eventdata", "->", "userto", "=", "$", "touser", ";", "$", "eventdata", "->", "subject", "=", "$", "subject", ";", "$", "eventdata", "->", "fullmessage", "=", "$", "message", ";", "$", "eventdata", "->", "fullmessageformat", "=", "FORMAT_PLAIN", ";", "$", "eventdata", "->", "fullmessagehtml", "=", "''", ";", "$", "eventdata", "->", "smallmessage", "=", "''", ";", "$", "eventdata", "->", "notification", "=", "1", ";", "message_send", "(", "$", "eventdata", ")", ";", "}" ]
Send a message from one user to another using events_trigger @param object $touser @param object $fromuser @param string $name @param string $subject @param string $message @param int|null $courseid
[ "Send", "a", "message", "from", "one", "user", "to", "another", "using", "events_trigger" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/lib.php#L3055-L3069
219,654
moodle/moodle
lib/mlbackend/php/phpml/src/Phpml/Clustering/FuzzyCMeans.php
FuzzyCMeans.getObjective
protected function getObjective() { $sum = 0.0; $distance = new Euclidean(); for ($i = 0; $i < $this->clustersNumber; ++$i) { $clust = $this->clusters[$i]->getCoordinates(); for ($k = 0; $k < $this->sampleCount; ++$k) { $point = $this->samples[$k]; $sum += $distance->distance($clust, $point); } } return $sum; }
php
protected function getObjective() { $sum = 0.0; $distance = new Euclidean(); for ($i = 0; $i < $this->clustersNumber; ++$i) { $clust = $this->clusters[$i]->getCoordinates(); for ($k = 0; $k < $this->sampleCount; ++$k) { $point = $this->samples[$k]; $sum += $distance->distance($clust, $point); } } return $sum; }
[ "protected", "function", "getObjective", "(", ")", "{", "$", "sum", "=", "0.0", ";", "$", "distance", "=", "new", "Euclidean", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "this", "->", "clustersNumber", ";", "++", "$", "i", ")", "{", "$", "clust", "=", "$", "this", "->", "clusters", "[", "$", "i", "]", "->", "getCoordinates", "(", ")", ";", "for", "(", "$", "k", "=", "0", ";", "$", "k", "<", "$", "this", "->", "sampleCount", ";", "++", "$", "k", ")", "{", "$", "point", "=", "$", "this", "->", "samples", "[", "$", "k", "]", ";", "$", "sum", "+=", "$", "distance", "->", "distance", "(", "$", "clust", ",", "$", "point", ")", ";", "}", "}", "return", "$", "sum", ";", "}" ]
The objective is to minimize the distance between all data points and all cluster centers. This method returns the summation of all these distances
[ "The", "objective", "is", "to", "minimize", "the", "distance", "between", "all", "data", "points", "and", "all", "cluster", "centers", ".", "This", "method", "returns", "the", "summation", "of", "all", "these", "distances" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Clustering/FuzzyCMeans.php#L190-L203
219,655
moodle/moodle
mod/glossary/classes/search/entry.php
entry.get_doc_url
public function get_doc_url(\core_search\document $doc) { global $USER; // The post is already in static cache, we fetch it in self::search_access. $entry = $this->get_entry($doc->get('itemid')); $contextmodule = \context::instance_by_id($doc->get('contextid')); if ($entry->approved == false && $entry->userid != $USER->id) { // The URL should change when the entry is not approved and it was not created by the user. $docparams = array('id' => $contextmodule->instanceid, 'mode' => 'approval'); } else { $docparams = array('id' => $contextmodule->instanceid, 'mode' => 'entry', 'hook' => $doc->get('itemid')); } return new \moodle_url('/mod/glossary/view.php', $docparams); }
php
public function get_doc_url(\core_search\document $doc) { global $USER; // The post is already in static cache, we fetch it in self::search_access. $entry = $this->get_entry($doc->get('itemid')); $contextmodule = \context::instance_by_id($doc->get('contextid')); if ($entry->approved == false && $entry->userid != $USER->id) { // The URL should change when the entry is not approved and it was not created by the user. $docparams = array('id' => $contextmodule->instanceid, 'mode' => 'approval'); } else { $docparams = array('id' => $contextmodule->instanceid, 'mode' => 'entry', 'hook' => $doc->get('itemid')); } return new \moodle_url('/mod/glossary/view.php', $docparams); }
[ "public", "function", "get_doc_url", "(", "\\", "core_search", "\\", "document", "$", "doc", ")", "{", "global", "$", "USER", ";", "// The post is already in static cache, we fetch it in self::search_access.", "$", "entry", "=", "$", "this", "->", "get_entry", "(", "$", "doc", "->", "get", "(", "'itemid'", ")", ")", ";", "$", "contextmodule", "=", "\\", "context", "::", "instance_by_id", "(", "$", "doc", "->", "get", "(", "'contextid'", ")", ")", ";", "if", "(", "$", "entry", "->", "approved", "==", "false", "&&", "$", "entry", "->", "userid", "!=", "$", "USER", "->", "id", ")", "{", "// The URL should change when the entry is not approved and it was not created by the user.", "$", "docparams", "=", "array", "(", "'id'", "=>", "$", "contextmodule", "->", "instanceid", ",", "'mode'", "=>", "'approval'", ")", ";", "}", "else", "{", "$", "docparams", "=", "array", "(", "'id'", "=>", "$", "contextmodule", "->", "instanceid", ",", "'mode'", "=>", "'entry'", ",", "'hook'", "=>", "$", "doc", "->", "get", "(", "'itemid'", ")", ")", ";", "}", "return", "new", "\\", "moodle_url", "(", "'/mod/glossary/view.php'", ",", "$", "docparams", ")", ";", "}" ]
Link to glossary entry. @param \core_search\document $doc @return \moodle_url
[ "Link", "to", "glossary", "entry", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/search/entry.php#L157-L172
219,656
moodle/moodle
mod/glossary/classes/search/entry.php
entry.get_entry
protected function get_entry($entryid) { global $DB; if (empty($this->entriesdata[$entryid])) { $this->entriesdata[$entryid] = $DB->get_record_sql("SELECT ge.*, g.course, g.defaultapproval FROM {glossary_entries} ge JOIN {glossary} g ON g.id = ge.glossaryid WHERE ge.id = ?", array('id' => $entryid), MUST_EXIST); } return $this->entriesdata[$entryid]; }
php
protected function get_entry($entryid) { global $DB; if (empty($this->entriesdata[$entryid])) { $this->entriesdata[$entryid] = $DB->get_record_sql("SELECT ge.*, g.course, g.defaultapproval FROM {glossary_entries} ge JOIN {glossary} g ON g.id = ge.glossaryid WHERE ge.id = ?", array('id' => $entryid), MUST_EXIST); } return $this->entriesdata[$entryid]; }
[ "protected", "function", "get_entry", "(", "$", "entryid", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "this", "->", "entriesdata", "[", "$", "entryid", "]", ")", ")", "{", "$", "this", "->", "entriesdata", "[", "$", "entryid", "]", "=", "$", "DB", "->", "get_record_sql", "(", "\"SELECT ge.*, g.course, g.defaultapproval FROM {glossary_entries} ge\n JOIN {glossary} g ON g.id = ge.glossaryid\n WHERE ge.id = ?\"", ",", "array", "(", "'id'", "=>", "$", "entryid", ")", ",", "MUST_EXIST", ")", ";", "}", "return", "$", "this", "->", "entriesdata", "[", "$", "entryid", "]", ";", "}" ]
Returns the specified glossary entry checking the internal cache. Store minimal information as this might grow. @throws \dml_exception @param int $entryid @return stdClass
[ "Returns", "the", "specified", "glossary", "entry", "checking", "the", "internal", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/search/entry.php#L194-L203
219,657
moodle/moodle
mod/data/classes/privacy/provider.php
provider.export_data_content
protected static function export_data_content($context, $recordobj, $fieldobj, $contentobj) { $value = (object)[ 'field' => [ // Name and description are displayed in mod_data without applying format_string(). 'name' => $fieldobj->name, 'description' => $fieldobj->description, 'type' => $fieldobj->type, 'required' => transform::yesno($fieldobj->required), ], 'content' => $contentobj->content ]; foreach (['content1', 'content2', 'content3', 'content4'] as $key) { if ($contentobj->$key !== null) { $value->$key = $contentobj->$key; } } $classname = manager::get_provider_classname_for_component('datafield_' . $fieldobj->type); if (class_exists($classname) && is_subclass_of($classname, datafield_provider::class)) { component_class_callback($classname, 'export_data_content', [$context, $recordobj, $fieldobj, $contentobj, $value]); } else { // Data field plugin does not implement datafield_provider, just export default value. writer::with_context($context)->export_data([$recordobj->id, $contentobj->id], $value); } writer::with_context($context)->export_area_files([$recordobj->id, $contentobj->id], 'mod_data', 'content', $contentobj->id); }
php
protected static function export_data_content($context, $recordobj, $fieldobj, $contentobj) { $value = (object)[ 'field' => [ // Name and description are displayed in mod_data without applying format_string(). 'name' => $fieldobj->name, 'description' => $fieldobj->description, 'type' => $fieldobj->type, 'required' => transform::yesno($fieldobj->required), ], 'content' => $contentobj->content ]; foreach (['content1', 'content2', 'content3', 'content4'] as $key) { if ($contentobj->$key !== null) { $value->$key = $contentobj->$key; } } $classname = manager::get_provider_classname_for_component('datafield_' . $fieldobj->type); if (class_exists($classname) && is_subclass_of($classname, datafield_provider::class)) { component_class_callback($classname, 'export_data_content', [$context, $recordobj, $fieldobj, $contentobj, $value]); } else { // Data field plugin does not implement datafield_provider, just export default value. writer::with_context($context)->export_data([$recordobj->id, $contentobj->id], $value); } writer::with_context($context)->export_area_files([$recordobj->id, $contentobj->id], 'mod_data', 'content', $contentobj->id); }
[ "protected", "static", "function", "export_data_content", "(", "$", "context", ",", "$", "recordobj", ",", "$", "fieldobj", ",", "$", "contentobj", ")", "{", "$", "value", "=", "(", "object", ")", "[", "'field'", "=>", "[", "// Name and description are displayed in mod_data without applying format_string().", "'name'", "=>", "$", "fieldobj", "->", "name", ",", "'description'", "=>", "$", "fieldobj", "->", "description", ",", "'type'", "=>", "$", "fieldobj", "->", "type", ",", "'required'", "=>", "transform", "::", "yesno", "(", "$", "fieldobj", "->", "required", ")", ",", "]", ",", "'content'", "=>", "$", "contentobj", "->", "content", "]", ";", "foreach", "(", "[", "'content1'", ",", "'content2'", ",", "'content3'", ",", "'content4'", "]", "as", "$", "key", ")", "{", "if", "(", "$", "contentobj", "->", "$", "key", "!==", "null", ")", "{", "$", "value", "->", "$", "key", "=", "$", "contentobj", "->", "$", "key", ";", "}", "}", "$", "classname", "=", "manager", "::", "get_provider_classname_for_component", "(", "'datafield_'", ".", "$", "fieldobj", "->", "type", ")", ";", "if", "(", "class_exists", "(", "$", "classname", ")", "&&", "is_subclass_of", "(", "$", "classname", ",", "datafield_provider", "::", "class", ")", ")", "{", "component_class_callback", "(", "$", "classname", ",", "'export_data_content'", ",", "[", "$", "context", ",", "$", "recordobj", ",", "$", "fieldobj", ",", "$", "contentobj", ",", "$", "value", "]", ")", ";", "}", "else", "{", "// Data field plugin does not implement datafield_provider, just export default value.", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "[", "$", "recordobj", "->", "id", ",", "$", "contentobj", "->", "id", "]", ",", "$", "value", ")", ";", "}", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_area_files", "(", "[", "$", "recordobj", "->", "id", ",", "$", "contentobj", "->", "id", "]", ",", "'mod_data'", ",", "'content'", ",", "$", "contentobj", "->", "id", ")", ";", "}" ]
Export one field answer in a record in database activity module @param \context $context @param \stdClass $recordobj record from DB table {data_records} @param \stdClass $fieldobj record from DB table {data_fields} @param \stdClass $contentobj record from DB table {data_content}
[ "Export", "one", "field", "answer", "in", "a", "record", "in", "database", "activity", "module" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/classes/privacy/provider.php#L244-L270
219,658
moodle/moodle
mod/data/classes/privacy/provider.php
provider.export_data
protected static function export_data($context, $user) { if (!$context) { return; } $contextdata = helper::get_context_data($context, $user); helper::export_context_files($context, $user); writer::with_context($context)->export_data([], $contextdata); }
php
protected static function export_data($context, $user) { if (!$context) { return; } $contextdata = helper::get_context_data($context, $user); helper::export_context_files($context, $user); writer::with_context($context)->export_data([], $contextdata); }
[ "protected", "static", "function", "export_data", "(", "$", "context", ",", "$", "user", ")", "{", "if", "(", "!", "$", "context", ")", "{", "return", ";", "}", "$", "contextdata", "=", "helper", "::", "get_context_data", "(", "$", "context", ",", "$", "user", ")", ";", "helper", "::", "export_context_files", "(", "$", "context", ",", "$", "user", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "[", "]", ",", "$", "contextdata", ")", ";", "}" ]
Export basic info about database activity module @param \context $context @param \stdClass $user
[ "Export", "basic", "info", "about", "database", "activity", "module" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/classes/privacy/provider.php#L389-L396
219,659
moodle/moodle
mod/data/classes/privacy/provider.php
provider.delete_data_records
protected static function delete_data_records($context, $recordstobedeleted) { global $DB; if (empty($recordstobedeleted)) { return; } list($sql, $params) = $DB->get_in_or_equal($recordstobedeleted, SQL_PARAMS_NAMED); // Delete files. get_file_storage()->delete_area_files_select($context->id, 'mod_data', 'data_records', "IN (SELECT dc.id FROM {data_content} dc WHERE dc.recordid $sql)", $params); // Delete from data_content. $DB->delete_records_select('data_content', 'recordid ' . $sql, $params); // Delete from data_records. $DB->delete_records_select('data_records', 'id ' . $sql, $params); // Delete tags. \core_tag\privacy\provider::delete_item_tags_select($context, 'mod_data', 'data_records', $sql, $params); // Delete comments. \core_comment\privacy\provider::delete_comments_for_all_users_select($context, 'mod_data', 'database_entry', $sql, $params); // Delete ratings. \core_rating\privacy\provider::delete_ratings_select($context, 'mod_data', 'entry', $sql, $params); }
php
protected static function delete_data_records($context, $recordstobedeleted) { global $DB; if (empty($recordstobedeleted)) { return; } list($sql, $params) = $DB->get_in_or_equal($recordstobedeleted, SQL_PARAMS_NAMED); // Delete files. get_file_storage()->delete_area_files_select($context->id, 'mod_data', 'data_records', "IN (SELECT dc.id FROM {data_content} dc WHERE dc.recordid $sql)", $params); // Delete from data_content. $DB->delete_records_select('data_content', 'recordid ' . $sql, $params); // Delete from data_records. $DB->delete_records_select('data_records', 'id ' . $sql, $params); // Delete tags. \core_tag\privacy\provider::delete_item_tags_select($context, 'mod_data', 'data_records', $sql, $params); // Delete comments. \core_comment\privacy\provider::delete_comments_for_all_users_select($context, 'mod_data', 'database_entry', $sql, $params); // Delete ratings. \core_rating\privacy\provider::delete_ratings_select($context, 'mod_data', 'entry', $sql, $params); }
[ "protected", "static", "function", "delete_data_records", "(", "$", "context", ",", "$", "recordstobedeleted", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "recordstobedeleted", ")", ")", "{", "return", ";", "}", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "recordstobedeleted", ",", "SQL_PARAMS_NAMED", ")", ";", "// Delete files.", "get_file_storage", "(", ")", "->", "delete_area_files_select", "(", "$", "context", "->", "id", ",", "'mod_data'", ",", "'data_records'", ",", "\"IN (SELECT dc.id FROM {data_content} dc WHERE dc.recordid $sql)\"", ",", "$", "params", ")", ";", "// Delete from data_content.", "$", "DB", "->", "delete_records_select", "(", "'data_content'", ",", "'recordid '", ".", "$", "sql", ",", "$", "params", ")", ";", "// Delete from data_records.", "$", "DB", "->", "delete_records_select", "(", "'data_records'", ",", "'id '", ".", "$", "sql", ",", "$", "params", ")", ";", "// Delete tags.", "\\", "core_tag", "\\", "privacy", "\\", "provider", "::", "delete_item_tags_select", "(", "$", "context", ",", "'mod_data'", ",", "'data_records'", ",", "$", "sql", ",", "$", "params", ")", ";", "// Delete comments.", "\\", "core_comment", "\\", "privacy", "\\", "provider", "::", "delete_comments_for_all_users_select", "(", "$", "context", ",", "'mod_data'", ",", "'database_entry'", ",", "$", "sql", ",", "$", "params", ")", ";", "// Delete ratings.", "\\", "core_rating", "\\", "privacy", "\\", "provider", "::", "delete_ratings_select", "(", "$", "context", ",", "'mod_data'", ",", "'entry'", ",", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Deletes records marked for deletion and all associated data Should be executed after all records were marked by {@link mark_data_content_for_deletion()} Deletes records from data_content and data_records tables, associated files, tags, comments and ratings. @param \context $context @param array $recordstobedeleted list of ids of the data records that need to be deleted
[ "Deletes", "records", "marked", "for", "deletion", "and", "all", "associated", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/classes/privacy/provider.php#L551-L572
219,660
moodle/moodle
cache/classes/loaders.php
cache.make
public static function make($component, $area, array $identifiers = array(), $unused = null) { $factory = cache_factory::instance(); return $factory->create_cache_from_definition($component, $area, $identifiers); }
php
public static function make($component, $area, array $identifiers = array(), $unused = null) { $factory = cache_factory::instance(); return $factory->create_cache_from_definition($component, $area, $identifiers); }
[ "public", "static", "function", "make", "(", "$", "component", ",", "$", "area", ",", "array", "$", "identifiers", "=", "array", "(", ")", ",", "$", "unused", "=", "null", ")", "{", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "return", "$", "factory", "->", "create_cache_from_definition", "(", "$", "component", ",", "$", "area", ",", "$", "identifiers", ")", ";", "}" ]
Creates a new cache instance for a pre-defined definition. @param string $component The component for the definition @param string $area The area for the definition @param array $identifiers Any additional identifiers that should be provided to the definition. @param string $unused Used to be datasourceaggregate but that was removed and this is now unused. @return cache_application|cache_session|cache_store
[ "Creates", "a", "new", "cache", "instance", "for", "a", "pre", "-", "defined", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L180-L183
219,661
moodle/moodle
cache/classes/loaders.php
cache.make_from_params
public static function make_from_params($mode, $component, $area, array $identifiers = array(), array $options = array()) { $factory = cache_factory::instance(); return $factory->create_cache_from_params($mode, $component, $area, $identifiers, $options); }
php
public static function make_from_params($mode, $component, $area, array $identifiers = array(), array $options = array()) { $factory = cache_factory::instance(); return $factory->create_cache_from_params($mode, $component, $area, $identifiers, $options); }
[ "public", "static", "function", "make_from_params", "(", "$", "mode", ",", "$", "component", ",", "$", "area", ",", "array", "$", "identifiers", "=", "array", "(", ")", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "return", "$", "factory", "->", "create_cache_from_params", "(", "$", "mode", ",", "$", "component", ",", "$", "area", ",", "$", "identifiers", ",", "$", "options", ")", ";", "}" ]
Creates a new cache instance based upon the given params. @param int $mode One of cache_store::MODE_* @param string $component The component this cache relates to. @param string $area The area this cache relates to. @param array $identifiers Any additional identifiers that should be provided to the definition. @param array $options An array of options, available options are: - simplekeys : Set to true if the keys you will use are a-zA-Z0-9_ - simpledata : Set to true if the type of the data you are going to store is scalar, or an array of scalar vars - staticacceleration : If set to true the cache will hold onto data passing through it. - staticaccelerationsize : The max size for the static acceleration array. @return cache_application|cache_session|cache_store
[ "Creates", "a", "new", "cache", "instance", "based", "upon", "the", "given", "params", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L199-L202
219,662
moodle/moodle
cache/classes/loaders.php
cache.set_is_sub_loader
protected function set_is_sub_loader($setting = true) { if ($setting) { $this->subloader = true; // Subloaders should not keep static acceleration data. $this->staticacceleration = false; $this->staticaccelerationsize = false; } else { $this->subloader = true; $this->staticacceleration = $this->definition->use_static_acceleration(); if ($this->staticacceleration) { $this->staticaccelerationsize = $this->definition->get_static_acceleration_size(); } } }
php
protected function set_is_sub_loader($setting = true) { if ($setting) { $this->subloader = true; // Subloaders should not keep static acceleration data. $this->staticacceleration = false; $this->staticaccelerationsize = false; } else { $this->subloader = true; $this->staticacceleration = $this->definition->use_static_acceleration(); if ($this->staticacceleration) { $this->staticaccelerationsize = $this->definition->get_static_acceleration_size(); } } }
[ "protected", "function", "set_is_sub_loader", "(", "$", "setting", "=", "true", ")", "{", "if", "(", "$", "setting", ")", "{", "$", "this", "->", "subloader", "=", "true", ";", "// Subloaders should not keep static acceleration data.", "$", "this", "->", "staticacceleration", "=", "false", ";", "$", "this", "->", "staticaccelerationsize", "=", "false", ";", "}", "else", "{", "$", "this", "->", "subloader", "=", "true", ";", "$", "this", "->", "staticacceleration", "=", "$", "this", "->", "definition", "->", "use_static_acceleration", "(", ")", ";", "if", "(", "$", "this", "->", "staticacceleration", ")", "{", "$", "this", "->", "staticaccelerationsize", "=", "$", "this", "->", "definition", "->", "get_static_acceleration_size", "(", ")", ";", "}", "}", "}" ]
Used to inform the loader of its state as a sub loader, or as the top of the chain. This is important as it ensures that we do not have more than one loader keeping static acceleration data. Subloaders need to be "pure" loaders in the sense that they are used to store and retrieve information from stores or the next loader/data source in the chain. Nothing fancy, nothing flash. @param bool $setting
[ "Used", "to", "inform", "the", "loader", "of", "its", "state", "as", "a", "sub", "loader", "or", "as", "the", "top", "of", "the", "chain", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L250-L263
219,663
moodle/moodle
cache/classes/loaders.php
cache.set_identifiers
public function set_identifiers(array $identifiers) { if ($this->definition->set_identifiers($identifiers)) { // As static acceleration uses input keys and not parsed keys // it much be cleared when the identifier set is changed. $this->staticaccelerationarray = array(); if ($this->staticaccelerationsize !== false) { $this->staticaccelerationkeys = array(); $this->staticaccelerationcount = 0; } } }
php
public function set_identifiers(array $identifiers) { if ($this->definition->set_identifiers($identifiers)) { // As static acceleration uses input keys and not parsed keys // it much be cleared when the identifier set is changed. $this->staticaccelerationarray = array(); if ($this->staticaccelerationsize !== false) { $this->staticaccelerationkeys = array(); $this->staticaccelerationcount = 0; } } }
[ "public", "function", "set_identifiers", "(", "array", "$", "identifiers", ")", "{", "if", "(", "$", "this", "->", "definition", "->", "set_identifiers", "(", "$", "identifiers", ")", ")", "{", "// As static acceleration uses input keys and not parsed keys", "// it much be cleared when the identifier set is changed.", "$", "this", "->", "staticaccelerationarray", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "staticaccelerationsize", "!==", "false", ")", "{", "$", "this", "->", "staticaccelerationkeys", "=", "array", "(", ")", ";", "$", "this", "->", "staticaccelerationcount", "=", "0", ";", "}", "}", "}" ]
Alters the identifiers that have been provided to the definition. This is an advanced method and should not be used unless really needed. It allows the developer to slightly alter the definition without having to re-establish the cache. It will cause more processing as the definition will need to clear and reprepare some of its properties. @param array $identifiers
[ "Alters", "the", "identifiers", "that", "have", "been", "provided", "to", "the", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L274-L284
219,664
moodle/moodle
cache/classes/loaders.php
cache.handle_invalidation_events
protected function handle_invalidation_events() { if (!$this->definition->has_invalidation_events()) { return; } // Each cache stores the current 'lastinvalidation' value within the cache itself. $lastinvalidation = $this->get('lastinvalidation'); if ($lastinvalidation === false) { // There is currently no value for the lastinvalidation token, therefore the token is not set, and there // can be nothing to invalidate. // Set the lastinvalidation value to the current purge token and return early. $this->set('lastinvalidation', self::get_purge_token()); return; } else if ($lastinvalidation == self::get_purge_token()) { // The current purge request has already been fully handled by this cache. return; } /* * Now that the whole cache check is complete, we check the meaning of any specific cache invalidation events. * These are stored in the core/eventinvalidation cache as an multi-dimensinoal array in the form: * [ * eventname => [ * keyname => purgetoken, * ] * ] * * The 'keyname' value is used to delete a specific key in the cache. * If the keyname is set to the special value 'purged', then the whole cache is purged instead. * * The 'purgetoken' is the token that this key was last purged. * a) If the purgetoken matches the last invalidation, then the key/cache is not purged. * b) If the purgetoken is newer than the last invalidation, then the key/cache is not purged. * c) If the purge token is older than the last invalidation, or it has a different token component, then the * cache is purged. * * Option b should not happen under normal operation, but may happen in race condition whereby a long-running * request's cache is cleared in another process during that request, and prior to that long-running request * creating the cache. In such a condition, it would be incorrect to clear that cache. */ $cache = self::make('core', 'eventinvalidation'); $events = $cache->get_many($this->definition->get_invalidation_events()); $todelete = array(); $purgeall = false; // Iterate the returned data for the events. foreach ($events as $event => $keys) { if ($keys === false) { // No data to be invalidated yet. continue; } // Look at each key and check the timestamp. foreach ($keys as $key => $purgetoken) { // If the timestamp of the event is more than or equal to the last invalidation (happened between the last // invalidation and now), then we need to invaliate the key. if (self::compare_purge_tokens($purgetoken, $lastinvalidation) > 0) { if ($key === 'purged') { $purgeall = true; break; } else { $todelete[] = $key; } } } } if ($purgeall) { $this->purge(); } else if (!empty($todelete)) { $todelete = array_unique($todelete); $this->delete_many($todelete); } // Set the time of the last invalidation. if ($purgeall || !empty($todelete)) { $this->set('lastinvalidation', self::get_purge_token(true)); } }
php
protected function handle_invalidation_events() { if (!$this->definition->has_invalidation_events()) { return; } // Each cache stores the current 'lastinvalidation' value within the cache itself. $lastinvalidation = $this->get('lastinvalidation'); if ($lastinvalidation === false) { // There is currently no value for the lastinvalidation token, therefore the token is not set, and there // can be nothing to invalidate. // Set the lastinvalidation value to the current purge token and return early. $this->set('lastinvalidation', self::get_purge_token()); return; } else if ($lastinvalidation == self::get_purge_token()) { // The current purge request has already been fully handled by this cache. return; } /* * Now that the whole cache check is complete, we check the meaning of any specific cache invalidation events. * These are stored in the core/eventinvalidation cache as an multi-dimensinoal array in the form: * [ * eventname => [ * keyname => purgetoken, * ] * ] * * The 'keyname' value is used to delete a specific key in the cache. * If the keyname is set to the special value 'purged', then the whole cache is purged instead. * * The 'purgetoken' is the token that this key was last purged. * a) If the purgetoken matches the last invalidation, then the key/cache is not purged. * b) If the purgetoken is newer than the last invalidation, then the key/cache is not purged. * c) If the purge token is older than the last invalidation, or it has a different token component, then the * cache is purged. * * Option b should not happen under normal operation, but may happen in race condition whereby a long-running * request's cache is cleared in another process during that request, and prior to that long-running request * creating the cache. In such a condition, it would be incorrect to clear that cache. */ $cache = self::make('core', 'eventinvalidation'); $events = $cache->get_many($this->definition->get_invalidation_events()); $todelete = array(); $purgeall = false; // Iterate the returned data for the events. foreach ($events as $event => $keys) { if ($keys === false) { // No data to be invalidated yet. continue; } // Look at each key and check the timestamp. foreach ($keys as $key => $purgetoken) { // If the timestamp of the event is more than or equal to the last invalidation (happened between the last // invalidation and now), then we need to invaliate the key. if (self::compare_purge_tokens($purgetoken, $lastinvalidation) > 0) { if ($key === 'purged') { $purgeall = true; break; } else { $todelete[] = $key; } } } } if ($purgeall) { $this->purge(); } else if (!empty($todelete)) { $todelete = array_unique($todelete); $this->delete_many($todelete); } // Set the time of the last invalidation. if ($purgeall || !empty($todelete)) { $this->set('lastinvalidation', self::get_purge_token(true)); } }
[ "protected", "function", "handle_invalidation_events", "(", ")", "{", "if", "(", "!", "$", "this", "->", "definition", "->", "has_invalidation_events", "(", ")", ")", "{", "return", ";", "}", "// Each cache stores the current 'lastinvalidation' value within the cache itself.", "$", "lastinvalidation", "=", "$", "this", "->", "get", "(", "'lastinvalidation'", ")", ";", "if", "(", "$", "lastinvalidation", "===", "false", ")", "{", "// There is currently no value for the lastinvalidation token, therefore the token is not set, and there", "// can be nothing to invalidate.", "// Set the lastinvalidation value to the current purge token and return early.", "$", "this", "->", "set", "(", "'lastinvalidation'", ",", "self", "::", "get_purge_token", "(", ")", ")", ";", "return", ";", "}", "else", "if", "(", "$", "lastinvalidation", "==", "self", "::", "get_purge_token", "(", ")", ")", "{", "// The current purge request has already been fully handled by this cache.", "return", ";", "}", "/*\n * Now that the whole cache check is complete, we check the meaning of any specific cache invalidation events.\n * These are stored in the core/eventinvalidation cache as an multi-dimensinoal array in the form:\n * [\n * eventname => [\n * keyname => purgetoken,\n * ]\n * ]\n *\n * The 'keyname' value is used to delete a specific key in the cache.\n * If the keyname is set to the special value 'purged', then the whole cache is purged instead.\n *\n * The 'purgetoken' is the token that this key was last purged.\n * a) If the purgetoken matches the last invalidation, then the key/cache is not purged.\n * b) If the purgetoken is newer than the last invalidation, then the key/cache is not purged.\n * c) If the purge token is older than the last invalidation, or it has a different token component, then the\n * cache is purged.\n *\n * Option b should not happen under normal operation, but may happen in race condition whereby a long-running\n * request's cache is cleared in another process during that request, and prior to that long-running request\n * creating the cache. In such a condition, it would be incorrect to clear that cache.\n */", "$", "cache", "=", "self", "::", "make", "(", "'core'", ",", "'eventinvalidation'", ")", ";", "$", "events", "=", "$", "cache", "->", "get_many", "(", "$", "this", "->", "definition", "->", "get_invalidation_events", "(", ")", ")", ";", "$", "todelete", "=", "array", "(", ")", ";", "$", "purgeall", "=", "false", ";", "// Iterate the returned data for the events.", "foreach", "(", "$", "events", "as", "$", "event", "=>", "$", "keys", ")", "{", "if", "(", "$", "keys", "===", "false", ")", "{", "// No data to be invalidated yet.", "continue", ";", "}", "// Look at each key and check the timestamp.", "foreach", "(", "$", "keys", "as", "$", "key", "=>", "$", "purgetoken", ")", "{", "// If the timestamp of the event is more than or equal to the last invalidation (happened between the last", "// invalidation and now), then we need to invaliate the key.", "if", "(", "self", "::", "compare_purge_tokens", "(", "$", "purgetoken", ",", "$", "lastinvalidation", ")", ">", "0", ")", "{", "if", "(", "$", "key", "===", "'purged'", ")", "{", "$", "purgeall", "=", "true", ";", "break", ";", "}", "else", "{", "$", "todelete", "[", "]", "=", "$", "key", ";", "}", "}", "}", "}", "if", "(", "$", "purgeall", ")", "{", "$", "this", "->", "purge", "(", ")", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "todelete", ")", ")", "{", "$", "todelete", "=", "array_unique", "(", "$", "todelete", ")", ";", "$", "this", "->", "delete_many", "(", "$", "todelete", ")", ";", "}", "// Set the time of the last invalidation.", "if", "(", "$", "purgeall", "||", "!", "empty", "(", "$", "todelete", ")", ")", "{", "$", "this", "->", "set", "(", "'lastinvalidation'", ",", "self", "::", "get_purge_token", "(", "true", ")", ")", ";", "}", "}" ]
Process any outstanding invalidation events for the cache we are registering, Identifiers and event invalidation are not compatible with each other at this time. As a result the cache does not need to consider identifiers when working out what to invalidate.
[ "Process", "any", "outstanding", "invalidation", "events", "for", "the", "cache", "we", "are", "registering" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L292-L368
219,665
moodle/moodle
cache/classes/loaders.php
cache.unref
protected function unref($data) { if ($this->definition->uses_simple_data()) { return $data; } // Check if it requires serialisation in order to produce a reference free copy. if ($this->requires_serialisation($data)) { // Damn, its going to have to be serialise. $data = serialize($data); // We unserialise immediately so that we don't have to do it every time on get. $data = unserialize($data); } else if (!is_scalar($data)) { // Its safe to clone, lets do it, its going to beat the pants of serialisation. $data = $this->deep_clone($data); } return $data; }
php
protected function unref($data) { if ($this->definition->uses_simple_data()) { return $data; } // Check if it requires serialisation in order to produce a reference free copy. if ($this->requires_serialisation($data)) { // Damn, its going to have to be serialise. $data = serialize($data); // We unserialise immediately so that we don't have to do it every time on get. $data = unserialize($data); } else if (!is_scalar($data)) { // Its safe to clone, lets do it, its going to beat the pants of serialisation. $data = $this->deep_clone($data); } return $data; }
[ "protected", "function", "unref", "(", "$", "data", ")", "{", "if", "(", "$", "this", "->", "definition", "->", "uses_simple_data", "(", ")", ")", "{", "return", "$", "data", ";", "}", "// Check if it requires serialisation in order to produce a reference free copy.", "if", "(", "$", "this", "->", "requires_serialisation", "(", "$", "data", ")", ")", "{", "// Damn, its going to have to be serialise.", "$", "data", "=", "serialize", "(", "$", "data", ")", ";", "// We unserialise immediately so that we don't have to do it every time on get.", "$", "data", "=", "unserialize", "(", "$", "data", ")", ";", "}", "else", "if", "(", "!", "is_scalar", "(", "$", "data", ")", ")", "{", "// Its safe to clone, lets do it, its going to beat the pants of serialisation.", "$", "data", "=", "$", "this", "->", "deep_clone", "(", "$", "data", ")", ";", "}", "return", "$", "data", ";", "}" ]
Removes references where required. @param stdClass|array $data @return mixed What ever was put in but without any references.
[ "Removes", "references", "where", "required", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L647-L662
219,666
moodle/moodle
cache/classes/loaders.php
cache.requires_serialisation
protected function requires_serialisation($value, $depth = 1) { if (is_scalar($value)) { return false; } else if (is_array($value) || $value instanceof stdClass || $value instanceof Traversable) { if ($depth > 5) { // Skrew it, mega-deep object, developer you suck, we're just going to serialise. return true; } foreach ($value as $key => $subvalue) { if ($this->requires_serialisation($subvalue, $depth++)) { return true; } } } // Its not scalar, array, or stdClass so we'll need to serialise. return true; }
php
protected function requires_serialisation($value, $depth = 1) { if (is_scalar($value)) { return false; } else if (is_array($value) || $value instanceof stdClass || $value instanceof Traversable) { if ($depth > 5) { // Skrew it, mega-deep object, developer you suck, we're just going to serialise. return true; } foreach ($value as $key => $subvalue) { if ($this->requires_serialisation($subvalue, $depth++)) { return true; } } } // Its not scalar, array, or stdClass so we'll need to serialise. return true; }
[ "protected", "function", "requires_serialisation", "(", "$", "value", ",", "$", "depth", "=", "1", ")", "{", "if", "(", "is_scalar", "(", "$", "value", ")", ")", "{", "return", "false", ";", "}", "else", "if", "(", "is_array", "(", "$", "value", ")", "||", "$", "value", "instanceof", "stdClass", "||", "$", "value", "instanceof", "Traversable", ")", "{", "if", "(", "$", "depth", ">", "5", ")", "{", "// Skrew it, mega-deep object, developer you suck, we're just going to serialise.", "return", "true", ";", "}", "foreach", "(", "$", "value", "as", "$", "key", "=>", "$", "subvalue", ")", "{", "if", "(", "$", "this", "->", "requires_serialisation", "(", "$", "subvalue", ",", "$", "depth", "++", ")", ")", "{", "return", "true", ";", "}", "}", "}", "// Its not scalar, array, or stdClass so we'll need to serialise.", "return", "true", ";", "}" ]
Checks to see if a var requires serialisation. @param mixed $value The value to check. @param int $depth Used to ensure we don't enter an endless loop (think recursion). @return bool Returns true if the value is going to require serialisation in order to ensure a reference free copy or false if its safe to clone.
[ "Checks", "to", "see", "if", "a", "var", "requires", "serialisation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L672-L688
219,667
moodle/moodle
cache/classes/loaders.php
cache.deep_clone
protected function deep_clone($value) { if (is_object($value)) { // Objects must be cloned to begin with. $value = clone $value; } if (is_array($value) || is_object($value)) { foreach ($value as $key => $subvalue) { $value[$key] = $this->deep_clone($subvalue); } } return $value; }
php
protected function deep_clone($value) { if (is_object($value)) { // Objects must be cloned to begin with. $value = clone $value; } if (is_array($value) || is_object($value)) { foreach ($value as $key => $subvalue) { $value[$key] = $this->deep_clone($subvalue); } } return $value; }
[ "protected", "function", "deep_clone", "(", "$", "value", ")", "{", "if", "(", "is_object", "(", "$", "value", ")", ")", "{", "// Objects must be cloned to begin with.", "$", "value", "=", "clone", "$", "value", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", "||", "is_object", "(", "$", "value", ")", ")", "{", "foreach", "(", "$", "value", "as", "$", "key", "=>", "$", "subvalue", ")", "{", "$", "value", "[", "$", "key", "]", "=", "$", "this", "->", "deep_clone", "(", "$", "subvalue", ")", ";", "}", "}", "return", "$", "value", ";", "}" ]
Creates a reference free clone of the given value. @param mixed $value @return mixed
[ "Creates", "a", "reference", "free", "clone", "of", "the", "given", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L696-L707
219,668
moodle/moodle
cache/classes/loaders.php
cache.store_supports_native_ttl
protected function store_supports_native_ttl() { if ($this->supportsnativettl === null) { $this->supportsnativettl = ($this->store->supports_native_ttl()); } return $this->supportsnativettl; }
php
protected function store_supports_native_ttl() { if ($this->supportsnativettl === null) { $this->supportsnativettl = ($this->store->supports_native_ttl()); } return $this->supportsnativettl; }
[ "protected", "function", "store_supports_native_ttl", "(", ")", "{", "if", "(", "$", "this", "->", "supportsnativettl", "===", "null", ")", "{", "$", "this", "->", "supportsnativettl", "=", "(", "$", "this", "->", "store", "->", "supports_native_ttl", "(", ")", ")", ";", "}", "return", "$", "this", "->", "supportsnativettl", ";", "}" ]
Returns true if the cache store supports native ttl. @return bool
[ "Returns", "true", "if", "the", "cache", "store", "supports", "native", "ttl", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L973-L978
219,669
moodle/moodle
cache/classes/loaders.php
cache.store_supports_key_awareness
protected function store_supports_key_awareness() { if ($this->supportskeyawareness === null) { $this->supportskeyawareness = ($this->store instanceof cache_is_key_aware); } return $this->supportskeyawareness; }
php
protected function store_supports_key_awareness() { if ($this->supportskeyawareness === null) { $this->supportskeyawareness = ($this->store instanceof cache_is_key_aware); } return $this->supportskeyawareness; }
[ "protected", "function", "store_supports_key_awareness", "(", ")", "{", "if", "(", "$", "this", "->", "supportskeyawareness", "===", "null", ")", "{", "$", "this", "->", "supportskeyawareness", "=", "(", "$", "this", "->", "store", "instanceof", "cache_is_key_aware", ")", ";", "}", "return", "$", "this", "->", "supportskeyawareness", ";", "}" ]
Returns true if the store supports key awareness. @return bool
[ "Returns", "true", "if", "the", "store", "supports", "key", "awareness", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1023-L1028
219,670
moodle/moodle
cache/classes/loaders.php
cache.store_supports_native_locking
protected function store_supports_native_locking() { if ($this->nativelocking === null) { $this->nativelocking = ($this->store instanceof cache_is_lockable); } return $this->nativelocking; }
php
protected function store_supports_native_locking() { if ($this->nativelocking === null) { $this->nativelocking = ($this->store instanceof cache_is_lockable); } return $this->nativelocking; }
[ "protected", "function", "store_supports_native_locking", "(", ")", "{", "if", "(", "$", "this", "->", "nativelocking", "===", "null", ")", "{", "$", "this", "->", "nativelocking", "=", "(", "$", "this", "->", "store", "instanceof", "cache_is_lockable", ")", ";", "}", "return", "$", "this", "->", "nativelocking", ";", "}" ]
Returns true if the store natively supports locking. @return bool
[ "Returns", "true", "if", "the", "store", "natively", "supports", "locking", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1035-L1040
219,671
moodle/moodle
cache/classes/loaders.php
cache.static_acceleration_has
protected function static_acceleration_has($key) { // This could be written as a single line, however it has been split because the ttl check is faster than the instanceof // and has_expired calls. if (!$this->staticacceleration || !isset($this->staticaccelerationarray[$key])) { return false; } return true; }
php
protected function static_acceleration_has($key) { // This could be written as a single line, however it has been split because the ttl check is faster than the instanceof // and has_expired calls. if (!$this->staticacceleration || !isset($this->staticaccelerationarray[$key])) { return false; } return true; }
[ "protected", "function", "static_acceleration_has", "(", "$", "key", ")", "{", "// This could be written as a single line, however it has been split because the ttl check is faster than the instanceof", "// and has_expired calls.", "if", "(", "!", "$", "this", "->", "staticacceleration", "||", "!", "isset", "(", "$", "this", "->", "staticaccelerationarray", "[", "$", "key", "]", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Returns true if the requested key exists within the static acceleration array. @param string $key The parsed key @return bool
[ "Returns", "true", "if", "the", "requested", "key", "exists", "within", "the", "static", "acceleration", "array", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1075-L1082
219,672
moodle/moodle
cache/classes/loaders.php
cache.static_acceleration_get
protected function static_acceleration_get($key) { if (!$this->staticacceleration || !isset($this->staticaccelerationarray[$key])) { $result = false; } else { $data = $this->staticaccelerationarray[$key]['data']; if ($data instanceof cache_cached_object) { $result = $data->restore_object(); } else if ($this->staticaccelerationarray[$key]['serialized']) { $result = unserialize($data); } else { $result = $data; } } if ($result !== false) { if ($this->perfdebug) { cache_helper::record_cache_hit('** static acceleration **', $this->definition); } if ($this->staticaccelerationsize > 1 && $this->staticaccelerationcount > 1) { // Check to see if this is the last item on the static acceleration keys array. if (end($this->staticaccelerationkeys) !== $key) { // It isn't the last item. // Move the item to the end of the array so that it is last to be removed. unset($this->staticaccelerationkeys[$key]); $this->staticaccelerationkeys[$key] = $key; } } return $result; } else { if ($this->perfdebug) { cache_helper::record_cache_miss('** static acceleration **', $this->definition); } return false; } }
php
protected function static_acceleration_get($key) { if (!$this->staticacceleration || !isset($this->staticaccelerationarray[$key])) { $result = false; } else { $data = $this->staticaccelerationarray[$key]['data']; if ($data instanceof cache_cached_object) { $result = $data->restore_object(); } else if ($this->staticaccelerationarray[$key]['serialized']) { $result = unserialize($data); } else { $result = $data; } } if ($result !== false) { if ($this->perfdebug) { cache_helper::record_cache_hit('** static acceleration **', $this->definition); } if ($this->staticaccelerationsize > 1 && $this->staticaccelerationcount > 1) { // Check to see if this is the last item on the static acceleration keys array. if (end($this->staticaccelerationkeys) !== $key) { // It isn't the last item. // Move the item to the end of the array so that it is last to be removed. unset($this->staticaccelerationkeys[$key]); $this->staticaccelerationkeys[$key] = $key; } } return $result; } else { if ($this->perfdebug) { cache_helper::record_cache_miss('** static acceleration **', $this->definition); } return false; } }
[ "protected", "function", "static_acceleration_get", "(", "$", "key", ")", "{", "if", "(", "!", "$", "this", "->", "staticacceleration", "||", "!", "isset", "(", "$", "this", "->", "staticaccelerationarray", "[", "$", "key", "]", ")", ")", "{", "$", "result", "=", "false", ";", "}", "else", "{", "$", "data", "=", "$", "this", "->", "staticaccelerationarray", "[", "$", "key", "]", "[", "'data'", "]", ";", "if", "(", "$", "data", "instanceof", "cache_cached_object", ")", "{", "$", "result", "=", "$", "data", "->", "restore_object", "(", ")", ";", "}", "else", "if", "(", "$", "this", "->", "staticaccelerationarray", "[", "$", "key", "]", "[", "'serialized'", "]", ")", "{", "$", "result", "=", "unserialize", "(", "$", "data", ")", ";", "}", "else", "{", "$", "result", "=", "$", "data", ";", "}", "}", "if", "(", "$", "result", "!==", "false", ")", "{", "if", "(", "$", "this", "->", "perfdebug", ")", "{", "cache_helper", "::", "record_cache_hit", "(", "'** static acceleration **'", ",", "$", "this", "->", "definition", ")", ";", "}", "if", "(", "$", "this", "->", "staticaccelerationsize", ">", "1", "&&", "$", "this", "->", "staticaccelerationcount", ">", "1", ")", "{", "// Check to see if this is the last item on the static acceleration keys array.", "if", "(", "end", "(", "$", "this", "->", "staticaccelerationkeys", ")", "!==", "$", "key", ")", "{", "// It isn't the last item.", "// Move the item to the end of the array so that it is last to be removed.", "unset", "(", "$", "this", "->", "staticaccelerationkeys", "[", "$", "key", "]", ")", ";", "$", "this", "->", "staticaccelerationkeys", "[", "$", "key", "]", "=", "$", "key", ";", "}", "}", "return", "$", "result", ";", "}", "else", "{", "if", "(", "$", "this", "->", "perfdebug", ")", "{", "cache_helper", "::", "record_cache_miss", "(", "'** static acceleration **'", ",", "$", "this", "->", "definition", ")", ";", "}", "return", "false", ";", "}", "}" ]
Returns the item from the static acceleration array if it exists there. @param string $key The parsed key @return mixed|false Dereferenced data from the static acceleration array or false if it wasn't there.
[ "Returns", "the", "item", "from", "the", "static", "acceleration", "array", "if", "it", "exists", "there", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1099-L1133
219,673
moodle/moodle
cache/classes/loaders.php
cache.static_acceleration_set
protected function static_acceleration_set($key, $data) { if ($this->staticaccelerationsize !== false && isset($this->staticaccelerationkeys[$key])) { $this->staticaccelerationcount--; unset($this->staticaccelerationkeys[$key]); } // We serialize anything that's not; // 1. A known scalar safe value. // 2. A definition that says it's simpledata. We trust it that it doesn't contain dangerous references. // 3. An object that handles dereferencing by itself. if (is_scalar($data) || $this->definition->uses_simple_data() || $data instanceof cache_cached_object) { $this->staticaccelerationarray[$key]['data'] = $data; $this->staticaccelerationarray[$key]['serialized'] = false; } else { $this->staticaccelerationarray[$key]['data'] = serialize($data); $this->staticaccelerationarray[$key]['serialized'] = true; } if ($this->staticaccelerationsize !== false) { $this->staticaccelerationcount++; $this->staticaccelerationkeys[$key] = $key; if ($this->staticaccelerationcount > $this->staticaccelerationsize) { $dropkey = array_shift($this->staticaccelerationkeys); unset($this->staticaccelerationarray[$dropkey]); $this->staticaccelerationcount--; } } return true; }
php
protected function static_acceleration_set($key, $data) { if ($this->staticaccelerationsize !== false && isset($this->staticaccelerationkeys[$key])) { $this->staticaccelerationcount--; unset($this->staticaccelerationkeys[$key]); } // We serialize anything that's not; // 1. A known scalar safe value. // 2. A definition that says it's simpledata. We trust it that it doesn't contain dangerous references. // 3. An object that handles dereferencing by itself. if (is_scalar($data) || $this->definition->uses_simple_data() || $data instanceof cache_cached_object) { $this->staticaccelerationarray[$key]['data'] = $data; $this->staticaccelerationarray[$key]['serialized'] = false; } else { $this->staticaccelerationarray[$key]['data'] = serialize($data); $this->staticaccelerationarray[$key]['serialized'] = true; } if ($this->staticaccelerationsize !== false) { $this->staticaccelerationcount++; $this->staticaccelerationkeys[$key] = $key; if ($this->staticaccelerationcount > $this->staticaccelerationsize) { $dropkey = array_shift($this->staticaccelerationkeys); unset($this->staticaccelerationarray[$dropkey]); $this->staticaccelerationcount--; } } return true; }
[ "protected", "function", "static_acceleration_set", "(", "$", "key", ",", "$", "data", ")", "{", "if", "(", "$", "this", "->", "staticaccelerationsize", "!==", "false", "&&", "isset", "(", "$", "this", "->", "staticaccelerationkeys", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "staticaccelerationcount", "--", ";", "unset", "(", "$", "this", "->", "staticaccelerationkeys", "[", "$", "key", "]", ")", ";", "}", "// We serialize anything that's not;", "// 1. A known scalar safe value.", "// 2. A definition that says it's simpledata. We trust it that it doesn't contain dangerous references.", "// 3. An object that handles dereferencing by itself.", "if", "(", "is_scalar", "(", "$", "data", ")", "||", "$", "this", "->", "definition", "->", "uses_simple_data", "(", ")", "||", "$", "data", "instanceof", "cache_cached_object", ")", "{", "$", "this", "->", "staticaccelerationarray", "[", "$", "key", "]", "[", "'data'", "]", "=", "$", "data", ";", "$", "this", "->", "staticaccelerationarray", "[", "$", "key", "]", "[", "'serialized'", "]", "=", "false", ";", "}", "else", "{", "$", "this", "->", "staticaccelerationarray", "[", "$", "key", "]", "[", "'data'", "]", "=", "serialize", "(", "$", "data", ")", ";", "$", "this", "->", "staticaccelerationarray", "[", "$", "key", "]", "[", "'serialized'", "]", "=", "true", ";", "}", "if", "(", "$", "this", "->", "staticaccelerationsize", "!==", "false", ")", "{", "$", "this", "->", "staticaccelerationcount", "++", ";", "$", "this", "->", "staticaccelerationkeys", "[", "$", "key", "]", "=", "$", "key", ";", "if", "(", "$", "this", "->", "staticaccelerationcount", ">", "$", "this", "->", "staticaccelerationsize", ")", "{", "$", "dropkey", "=", "array_shift", "(", "$", "this", "->", "staticaccelerationkeys", ")", ";", "unset", "(", "$", "this", "->", "staticaccelerationarray", "[", "$", "dropkey", "]", ")", ";", "$", "this", "->", "staticaccelerationcount", "--", ";", "}", "}", "return", "true", ";", "}" ]
Sets a key value pair into the static acceleration array. @param string $key The parsed key @param mixed $data @return bool
[ "Sets", "a", "key", "value", "pair", "into", "the", "static", "acceleration", "array", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1151-L1179
219,674
moodle/moodle
cache/classes/loaders.php
cache.static_acceleration_delete
protected function static_acceleration_delete($key) { unset($this->staticaccelerationarray[$key]); if ($this->staticaccelerationsize !== false && isset($this->staticaccelerationkeys[$key])) { unset($this->staticaccelerationkeys[$key]); $this->staticaccelerationcount--; } return true; }
php
protected function static_acceleration_delete($key) { unset($this->staticaccelerationarray[$key]); if ($this->staticaccelerationsize !== false && isset($this->staticaccelerationkeys[$key])) { unset($this->staticaccelerationkeys[$key]); $this->staticaccelerationcount--; } return true; }
[ "protected", "function", "static_acceleration_delete", "(", "$", "key", ")", "{", "unset", "(", "$", "this", "->", "staticaccelerationarray", "[", "$", "key", "]", ")", ";", "if", "(", "$", "this", "->", "staticaccelerationsize", "!==", "false", "&&", "isset", "(", "$", "this", "->", "staticaccelerationkeys", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "staticaccelerationkeys", "[", "$", "key", "]", ")", ";", "$", "this", "->", "staticaccelerationcount", "--", ";", "}", "return", "true", ";", "}" ]
Deletes an item from the static acceleration array. @param string|int $key As given to get|set|delete @return bool True on success, false otherwise.
[ "Deletes", "an", "item", "from", "the", "static", "acceleration", "array", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1196-L1203
219,675
moodle/moodle
cache/classes/loaders.php
cache.static_acceleration_purge
protected function static_acceleration_purge() { $this->staticaccelerationarray = array(); if ($this->staticaccelerationsize !== false) { $this->staticaccelerationkeys = array(); $this->staticaccelerationcount = 0; } }
php
protected function static_acceleration_purge() { $this->staticaccelerationarray = array(); if ($this->staticaccelerationsize !== false) { $this->staticaccelerationkeys = array(); $this->staticaccelerationcount = 0; } }
[ "protected", "function", "static_acceleration_purge", "(", ")", "{", "$", "this", "->", "staticaccelerationarray", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "staticaccelerationsize", "!==", "false", ")", "{", "$", "this", "->", "staticaccelerationkeys", "=", "array", "(", ")", ";", "$", "this", "->", "staticaccelerationcount", "=", "0", ";", "}", "}" ]
Purge the static acceleration cache.
[ "Purge", "the", "static", "acceleration", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1208-L1214
219,676
moodle/moodle
cache/classes/loaders.php
cache.now
public static function now($float = false) { if (self::$now === null) { self::$now = microtime(true); } if ($float) { return self::$now; } else { return (int) self::$now; } }
php
public static function now($float = false) { if (self::$now === null) { self::$now = microtime(true); } if ($float) { return self::$now; } else { return (int) self::$now; } }
[ "public", "static", "function", "now", "(", "$", "float", "=", "false", ")", "{", "if", "(", "self", "::", "$", "now", "===", "null", ")", "{", "self", "::", "$", "now", "=", "microtime", "(", "true", ")", ";", "}", "if", "(", "$", "float", ")", "{", "return", "self", "::", "$", "now", ";", "}", "else", "{", "return", "(", "int", ")", "self", "::", "$", "now", ";", "}", "}" ]
Returns the timestamp from the first request for the time from the cache API. This stamp needs to be used for all ttl and time based operations to ensure that we don't end up with timing issues. @param bool $float Whether to use floating precision accuracy. @return int|float
[ "Returns", "the", "timestamp", "from", "the", "first", "request", "for", "the", "time", "from", "the", "cache", "API", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1225-L1235
219,677
moodle/moodle
cache/classes/loaders.php
cache.get_purge_token
public static function get_purge_token($reset = false) { if (self::$purgetoken === null || $reset) { self::$now = null; self::$purgetoken = self::now(true) . '-' . uniqid('', true); } return self::$purgetoken; }
php
public static function get_purge_token($reset = false) { if (self::$purgetoken === null || $reset) { self::$now = null; self::$purgetoken = self::now(true) . '-' . uniqid('', true); } return self::$purgetoken; }
[ "public", "static", "function", "get_purge_token", "(", "$", "reset", "=", "false", ")", "{", "if", "(", "self", "::", "$", "purgetoken", "===", "null", "||", "$", "reset", ")", "{", "self", "::", "$", "now", "=", "null", ";", "self", "::", "$", "purgetoken", "=", "self", "::", "now", "(", "true", ")", ".", "'-'", ".", "uniqid", "(", "''", ",", "true", ")", ";", "}", "return", "self", "::", "$", "purgetoken", ";", "}" ]
Get a 'purge' token used for cache invalidation handling. Note: This function is intended for use from within the Cache API only and not by plugins, or cache stores. @param bool $reset Whether to reset the token and generate a new one. @return string
[ "Get", "a", "purge", "token", "used", "for", "cache", "invalidation", "handling", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1245-L1252
219,678
moodle/moodle
cache/classes/loaders.php
cache.compare_purge_tokens
public static function compare_purge_tokens($tokena, $tokenb) { if ($tokena === $tokenb) { // There is an exact match. return 0; } // The token for when the cache was last invalidated. list($atime) = explode('-', "{$tokena}-", 2); // The token for this cache. list($btime) = explode('-', "{$tokenb}-", 2); if ($atime >= $btime) { // Token A is newer. return 1; } else { // Token A is older. return -1; } }
php
public static function compare_purge_tokens($tokena, $tokenb) { if ($tokena === $tokenb) { // There is an exact match. return 0; } // The token for when the cache was last invalidated. list($atime) = explode('-', "{$tokena}-", 2); // The token for this cache. list($btime) = explode('-', "{$tokenb}-", 2); if ($atime >= $btime) { // Token A is newer. return 1; } else { // Token A is older. return -1; } }
[ "public", "static", "function", "compare_purge_tokens", "(", "$", "tokena", ",", "$", "tokenb", ")", "{", "if", "(", "$", "tokena", "===", "$", "tokenb", ")", "{", "// There is an exact match.", "return", "0", ";", "}", "// The token for when the cache was last invalidated.", "list", "(", "$", "atime", ")", "=", "explode", "(", "'-'", ",", "\"{$tokena}-\"", ",", "2", ")", ";", "// The token for this cache.", "list", "(", "$", "btime", ")", "=", "explode", "(", "'-'", ",", "\"{$tokenb}-\"", ",", "2", ")", ";", "if", "(", "$", "atime", ">=", "$", "btime", ")", "{", "// Token A is newer.", "return", "1", ";", "}", "else", "{", "// Token A is older.", "return", "-", "1", ";", "}", "}" ]
Compare a pair of purge tokens. If the two tokens are identical, then the return value is 0. If the time component of token A is newer than token B, then a positive value is returned. If the time component of token B is newer than token A, then a negative value is returned. Note: This function is intended for use from within the Cache API only and not by plugins, or cache stores. @param string $tokena @param string $tokenb @return int
[ "Compare", "a", "pair", "of", "purge", "tokens", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1267-L1286
219,679
moodle/moodle
cache/classes/loaders.php
cache_application.get_identifier
public function get_identifier() { static $instances = 0; if ($this->lockidentifier === null) { $this->lockidentifier = md5( $this->get_definition()->generate_definition_hash() . sesskey() . $instances++ . 'cache_application' ); } return $this->lockidentifier; }
php
public function get_identifier() { static $instances = 0; if ($this->lockidentifier === null) { $this->lockidentifier = md5( $this->get_definition()->generate_definition_hash() . sesskey() . $instances++ . 'cache_application' ); } return $this->lockidentifier; }
[ "public", "function", "get_identifier", "(", ")", "{", "static", "$", "instances", "=", "0", ";", "if", "(", "$", "this", "->", "lockidentifier", "===", "null", ")", "{", "$", "this", "->", "lockidentifier", "=", "md5", "(", "$", "this", "->", "get_definition", "(", ")", "->", "generate_definition_hash", "(", ")", ".", "sesskey", "(", ")", ".", "$", "instances", "++", ".", "'cache_application'", ")", ";", "}", "return", "$", "this", "->", "lockidentifier", ";", "}" ]
Returns the identifier to use @staticvar int $instances Counts the number of instances. Used as part of the lock identifier. @return string
[ "Returns", "the", "identifier", "to", "use" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1382-L1393
219,680
moodle/moodle
cache/classes/loaders.php
cache_application.acquire_lock
public function acquire_lock($key) { $key = $this->parse_key($key); if ($this->nativelocking) { return $this->get_store()->acquire_lock($key, $this->get_identifier()); } else { $this->ensure_cachelock_available(); return $this->cachelockinstance->lock($key, $this->get_identifier()); } }
php
public function acquire_lock($key) { $key = $this->parse_key($key); if ($this->nativelocking) { return $this->get_store()->acquire_lock($key, $this->get_identifier()); } else { $this->ensure_cachelock_available(); return $this->cachelockinstance->lock($key, $this->get_identifier()); } }
[ "public", "function", "acquire_lock", "(", "$", "key", ")", "{", "$", "key", "=", "$", "this", "->", "parse_key", "(", "$", "key", ")", ";", "if", "(", "$", "this", "->", "nativelocking", ")", "{", "return", "$", "this", "->", "get_store", "(", ")", "->", "acquire_lock", "(", "$", "key", ",", "$", "this", "->", "get_identifier", "(", ")", ")", ";", "}", "else", "{", "$", "this", "->", "ensure_cachelock_available", "(", ")", ";", "return", "$", "this", "->", "cachelockinstance", "->", "lock", "(", "$", "key", ",", "$", "this", "->", "get_identifier", "(", ")", ")", ";", "}", "}" ]
Acquires a lock on the given key. This is done automatically if the definition requires it. It is recommended to use a definition if you want to have locking although it is possible to do locking without having it required by the definition. The problem with such an approach is that you cannot ensure that code will consistently use locking. You will need to rely on the integrators review skills. @param string|int $key The key as given to get|set|delete @return bool Returns true if the lock could be acquired, false otherwise.
[ "Acquires", "a", "lock", "on", "the", "given", "key", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1415-L1423
219,681
moodle/moodle
cache/classes/loaders.php
cache_application.check_lock_state
public function check_lock_state($key) { $key = $this->parse_key($key); if ($this->nativelocking) { return $this->get_store()->check_lock_state($key, $this->get_identifier()); } else { $this->ensure_cachelock_available(); return $this->cachelockinstance->check_state($key, $this->get_identifier()); } }
php
public function check_lock_state($key) { $key = $this->parse_key($key); if ($this->nativelocking) { return $this->get_store()->check_lock_state($key, $this->get_identifier()); } else { $this->ensure_cachelock_available(); return $this->cachelockinstance->check_state($key, $this->get_identifier()); } }
[ "public", "function", "check_lock_state", "(", "$", "key", ")", "{", "$", "key", "=", "$", "this", "->", "parse_key", "(", "$", "key", ")", ";", "if", "(", "$", "this", "->", "nativelocking", ")", "{", "return", "$", "this", "->", "get_store", "(", ")", "->", "check_lock_state", "(", "$", "key", ",", "$", "this", "->", "get_identifier", "(", ")", ")", ";", "}", "else", "{", "$", "this", "->", "ensure_cachelock_available", "(", ")", ";", "return", "$", "this", "->", "cachelockinstance", "->", "check_state", "(", "$", "key", ",", "$", "this", "->", "get_identifier", "(", ")", ")", ";", "}", "}" ]
Checks if this cache has a lock on the given key. @param string|int $key The key as given to get|set|delete @return bool|null Returns true if there is a lock and this cache has it, null if no one has a lock on that key, false if someone else has the lock.
[ "Checks", "if", "this", "cache", "has", "a", "lock", "on", "the", "given", "key", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1432-L1440
219,682
moodle/moodle
cache/classes/loaders.php
cache_application.release_lock
public function release_lock($key) { $key = $this->parse_key($key); if ($this->nativelocking) { return $this->get_store()->release_lock($key, $this->get_identifier()); } else { $this->ensure_cachelock_available(); return $this->cachelockinstance->unlock($key, $this->get_identifier()); } }
php
public function release_lock($key) { $key = $this->parse_key($key); if ($this->nativelocking) { return $this->get_store()->release_lock($key, $this->get_identifier()); } else { $this->ensure_cachelock_available(); return $this->cachelockinstance->unlock($key, $this->get_identifier()); } }
[ "public", "function", "release_lock", "(", "$", "key", ")", "{", "$", "key", "=", "$", "this", "->", "parse_key", "(", "$", "key", ")", ";", "if", "(", "$", "this", "->", "nativelocking", ")", "{", "return", "$", "this", "->", "get_store", "(", ")", "->", "release_lock", "(", "$", "key", ",", "$", "this", "->", "get_identifier", "(", ")", ")", ";", "}", "else", "{", "$", "this", "->", "ensure_cachelock_available", "(", ")", ";", "return", "$", "this", "->", "cachelockinstance", "->", "unlock", "(", "$", "key", ",", "$", "this", "->", "get_identifier", "(", ")", ")", ";", "}", "}" ]
Releases the lock this cache has on the given key @param string|int $key @return bool True if the operation succeeded, false otherwise.
[ "Releases", "the", "lock", "this", "cache", "has", "on", "the", "given", "key" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1448-L1456
219,683
moodle/moodle
cache/classes/loaders.php
cache_application.ensure_cachelock_available
protected function ensure_cachelock_available() { if ($this->cachelockinstance === null) { $this->cachelockinstance = cache_helper::get_cachelock_for_store($this->get_store()); } }
php
protected function ensure_cachelock_available() { if ($this->cachelockinstance === null) { $this->cachelockinstance = cache_helper::get_cachelock_for_store($this->get_store()); } }
[ "protected", "function", "ensure_cachelock_available", "(", ")", "{", "if", "(", "$", "this", "->", "cachelockinstance", "===", "null", ")", "{", "$", "this", "->", "cachelockinstance", "=", "cache_helper", "::", "get_cachelock_for_store", "(", "$", "this", "->", "get_store", "(", ")", ")", ";", "}", "}" ]
Ensure that the dedicated lock store is ready to go. This should only happen if the cache store doesn't natively support it.
[ "Ensure", "that", "the", "dedicated", "lock", "store", "is", "ready", "to", "go", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1463-L1467
219,684
moodle/moodle
cache/classes/loaders.php
cache_session.check_tracked_user
protected function check_tracked_user() { if (isset($_SESSION['USER']->id) && $_SESSION['USER']->id !== null) { // Get the id of the current user. $new = $_SESSION['USER']->id; } else { // No user set up yet. $new = 0; } if ($new !== self::$loadeduserid) { // The current user doesn't match the tracked userid for this request. if (!is_null(self::$loadeduserid)) { // Purge the data we have for the old user. // This way we don't bloat the session. $this->purge(); } self::$loadeduserid = $new; $this->currentuserid = $new; } else if ($new !== $this->currentuserid) { // The current user matches the loaded user but not the user last used by this cache. $this->purge_current_user(); $this->currentuserid = $new; } }
php
protected function check_tracked_user() { if (isset($_SESSION['USER']->id) && $_SESSION['USER']->id !== null) { // Get the id of the current user. $new = $_SESSION['USER']->id; } else { // No user set up yet. $new = 0; } if ($new !== self::$loadeduserid) { // The current user doesn't match the tracked userid for this request. if (!is_null(self::$loadeduserid)) { // Purge the data we have for the old user. // This way we don't bloat the session. $this->purge(); } self::$loadeduserid = $new; $this->currentuserid = $new; } else if ($new !== $this->currentuserid) { // The current user matches the loaded user but not the user last used by this cache. $this->purge_current_user(); $this->currentuserid = $new; } }
[ "protected", "function", "check_tracked_user", "(", ")", "{", "if", "(", "isset", "(", "$", "_SESSION", "[", "'USER'", "]", "->", "id", ")", "&&", "$", "_SESSION", "[", "'USER'", "]", "->", "id", "!==", "null", ")", "{", "// Get the id of the current user.", "$", "new", "=", "$", "_SESSION", "[", "'USER'", "]", "->", "id", ";", "}", "else", "{", "// No user set up yet.", "$", "new", "=", "0", ";", "}", "if", "(", "$", "new", "!==", "self", "::", "$", "loadeduserid", ")", "{", "// The current user doesn't match the tracked userid for this request.", "if", "(", "!", "is_null", "(", "self", "::", "$", "loadeduserid", ")", ")", "{", "// Purge the data we have for the old user.", "// This way we don't bloat the session.", "$", "this", "->", "purge", "(", ")", ";", "}", "self", "::", "$", "loadeduserid", "=", "$", "new", ";", "$", "this", "->", "currentuserid", "=", "$", "new", ";", "}", "else", "if", "(", "$", "new", "!==", "$", "this", "->", "currentuserid", ")", "{", "// The current user matches the loaded user but not the user last used by this cache.", "$", "this", "->", "purge_current_user", "(", ")", ";", "$", "this", "->", "currentuserid", "=", "$", "new", ";", "}", "}" ]
Check that this cache instance is tracking the current user.
[ "Check", "that", "this", "cache", "instance", "is", "tracking", "the", "current", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1768-L1790
219,685
moodle/moodle
cache/classes/loaders.php
cache_session.purge_current_user
public function purge_current_user() { $keys = $this->get_store()->find_by_prefix($this->get_key_prefix()); $this->get_store()->delete_many($keys); }
php
public function purge_current_user() { $keys = $this->get_store()->find_by_prefix($this->get_key_prefix()); $this->get_store()->delete_many($keys); }
[ "public", "function", "purge_current_user", "(", ")", "{", "$", "keys", "=", "$", "this", "->", "get_store", "(", ")", "->", "find_by_prefix", "(", "$", "this", "->", "get_key_prefix", "(", ")", ")", ";", "$", "this", "->", "get_store", "(", ")", "->", "delete_many", "(", "$", "keys", ")", ";", "}" ]
Purges the session cache of all data belonging to the current user.
[ "Purges", "the", "session", "cache", "of", "all", "data", "belonging", "to", "the", "current", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L1795-L1798
219,686
moodle/moodle
cache/classes/loaders.php
cache_session.has_all
public function has_all(array $keys) { $this->check_tracked_user(); if (($this->has_a_ttl() && !$this->store_supports_native_ttl()) || !$this->store_supports_key_awareness()) { foreach ($keys as $key) { if (!$this->has($key)) { return false; } } return true; } // The cache must be key aware and if support native ttl if it a ttl is set. /* @var cache_store|cache_is_key_aware $store */ $store = $this->get_store(); return $store->has_all(array_map(array($this, 'parse_key'), $keys)); }
php
public function has_all(array $keys) { $this->check_tracked_user(); if (($this->has_a_ttl() && !$this->store_supports_native_ttl()) || !$this->store_supports_key_awareness()) { foreach ($keys as $key) { if (!$this->has($key)) { return false; } } return true; } // The cache must be key aware and if support native ttl if it a ttl is set. /* @var cache_store|cache_is_key_aware $store */ $store = $this->get_store(); return $store->has_all(array_map(array($this, 'parse_key'), $keys)); }
[ "public", "function", "has_all", "(", "array", "$", "keys", ")", "{", "$", "this", "->", "check_tracked_user", "(", ")", ";", "if", "(", "(", "$", "this", "->", "has_a_ttl", "(", ")", "&&", "!", "$", "this", "->", "store_supports_native_ttl", "(", ")", ")", "||", "!", "$", "this", "->", "store_supports_key_awareness", "(", ")", ")", "{", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "!", "$", "this", "->", "has", "(", "$", "key", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}", "// The cache must be key aware and if support native ttl if it a ttl is set.", "/* @var cache_store|cache_is_key_aware $store */", "$", "store", "=", "$", "this", "->", "get_store", "(", ")", ";", "return", "$", "store", "->", "has_all", "(", "array_map", "(", "array", "(", "$", "this", ",", "'parse_key'", ")", ",", "$", "keys", ")", ")", ";", "}" ]
Test is a cache has all of the given keys. It is strongly recommended to avoid the use of this function if not absolutely required. In a high load environment the cache may well change between the test and any subsequent action (get, set, delete etc). Its also worth mentioning that not all stores support key tests. For stores that don't support key tests this functionality is mimicked by using the equivalent get method. Just one more reason you should not use these methods unless you have a very good reason to do so. @param array $keys @return bool True if the cache has all of the given keys, false otherwise.
[ "Test", "is", "a", "cache", "has", "all", "of", "the", "given", "keys", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/loaders.php#L2187-L2201
219,687
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Mailbox.php
Horde_Imap_Client_Mailbox.get
public static function get($mbox, $utf7imap = false) { return ($mbox instanceof Horde_Imap_Client_Mailbox) ? $mbox : new Horde_Imap_Client_Mailbox($mbox, $utf7imap); }
php
public static function get($mbox, $utf7imap = false) { return ($mbox instanceof Horde_Imap_Client_Mailbox) ? $mbox : new Horde_Imap_Client_Mailbox($mbox, $utf7imap); }
[ "public", "static", "function", "get", "(", "$", "mbox", ",", "$", "utf7imap", "=", "false", ")", "{", "return", "(", "$", "mbox", "instanceof", "Horde_Imap_Client_Mailbox", ")", "?", "$", "mbox", ":", "new", "Horde_Imap_Client_Mailbox", "(", "$", "mbox", ",", "$", "utf7imap", ")", ";", "}" ]
Shortcut to obtaining mailbox object. @param string $mbox The mailbox name. @param boolean $utf7imap Is mailbox UTF7-IMAP encoded? Otherwise, mailbox is assumed to be UTF-8. @return Horde_Imap_Client_Mailbox A mailbox object.
[ "Shortcut", "to", "obtaining", "mailbox", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Mailbox.php#L55-L60
219,688
moodle/moodle
backup/util/helper/restore_structure_parser_processor.class.php
restore_structure_parser_processor.process_cdata
public function process_cdata($cdata) { global $CFG; if ($cdata === '$@NULL@$') { // Some cases we know we can skip complete processing return null; } else if ($cdata === '') { return ''; } else if (is_numeric($cdata)) { return $cdata; } else if (strlen($cdata) < 32) { // Impossible to have one link in 32cc return $cdata; // (http://10.0.0.1/file.php/1/1.jpg, http://10.0.0.1/mod/url/view.php?id=) } else if (strpos($cdata, '$@FILEPHP@$') === false) { // No $@FILEPHP@$, nothing to convert return $cdata; } if ($CFG->slasharguments) { $slash = '/'; $forcedownload = '?forcedownload=1'; } else { $slash = '%2F'; $forcedownload = '&amp;forcedownload=1'; } // We have to remove trailing slashes, otherwise file URLs will be restored with an extra slash. $basefileurl = rtrim(moodle_url::make_legacyfile_url($this->courseid, null)->out(true), $slash); // Decode file.php calls $search = array ("$@FILEPHP@$"); $replace = array($basefileurl); $result = str_replace($search, $replace, $cdata); // Now $@SLASH@$ and $@FORCEDOWNLOAD@$ MDL-18799 $search = array('$@SLASH@$', '$@FORCEDOWNLOAD@$'); $replace = array($slash, $forcedownload); return str_replace($search, $replace, $result); }
php
public function process_cdata($cdata) { global $CFG; if ($cdata === '$@NULL@$') { // Some cases we know we can skip complete processing return null; } else if ($cdata === '') { return ''; } else if (is_numeric($cdata)) { return $cdata; } else if (strlen($cdata) < 32) { // Impossible to have one link in 32cc return $cdata; // (http://10.0.0.1/file.php/1/1.jpg, http://10.0.0.1/mod/url/view.php?id=) } else if (strpos($cdata, '$@FILEPHP@$') === false) { // No $@FILEPHP@$, nothing to convert return $cdata; } if ($CFG->slasharguments) { $slash = '/'; $forcedownload = '?forcedownload=1'; } else { $slash = '%2F'; $forcedownload = '&amp;forcedownload=1'; } // We have to remove trailing slashes, otherwise file URLs will be restored with an extra slash. $basefileurl = rtrim(moodle_url::make_legacyfile_url($this->courseid, null)->out(true), $slash); // Decode file.php calls $search = array ("$@FILEPHP@$"); $replace = array($basefileurl); $result = str_replace($search, $replace, $cdata); // Now $@SLASH@$ and $@FORCEDOWNLOAD@$ MDL-18799 $search = array('$@SLASH@$', '$@FORCEDOWNLOAD@$'); $replace = array($slash, $forcedownload); return str_replace($search, $replace, $result); }
[ "public", "function", "process_cdata", "(", "$", "cdata", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "cdata", "===", "'$@NULL@$'", ")", "{", "// Some cases we know we can skip complete processing", "return", "null", ";", "}", "else", "if", "(", "$", "cdata", "===", "''", ")", "{", "return", "''", ";", "}", "else", "if", "(", "is_numeric", "(", "$", "cdata", ")", ")", "{", "return", "$", "cdata", ";", "}", "else", "if", "(", "strlen", "(", "$", "cdata", ")", "<", "32", ")", "{", "// Impossible to have one link in 32cc", "return", "$", "cdata", ";", "// (http://10.0.0.1/file.php/1/1.jpg, http://10.0.0.1/mod/url/view.php?id=)", "}", "else", "if", "(", "strpos", "(", "$", "cdata", ",", "'$@FILEPHP@$'", ")", "===", "false", ")", "{", "// No $@FILEPHP@$, nothing to convert", "return", "$", "cdata", ";", "}", "if", "(", "$", "CFG", "->", "slasharguments", ")", "{", "$", "slash", "=", "'/'", ";", "$", "forcedownload", "=", "'?forcedownload=1'", ";", "}", "else", "{", "$", "slash", "=", "'%2F'", ";", "$", "forcedownload", "=", "'&amp;forcedownload=1'", ";", "}", "// We have to remove trailing slashes, otherwise file URLs will be restored with an extra slash.", "$", "basefileurl", "=", "rtrim", "(", "moodle_url", "::", "make_legacyfile_url", "(", "$", "this", "->", "courseid", ",", "null", ")", "->", "out", "(", "true", ")", ",", "$", "slash", ")", ";", "// Decode file.php calls", "$", "search", "=", "array", "(", "\"$@FILEPHP@$\"", ")", ";", "$", "replace", "=", "array", "(", "$", "basefileurl", ")", ";", "$", "result", "=", "str_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "cdata", ")", ";", "// Now $@SLASH@$ and $@FORCEDOWNLOAD@$ MDL-18799", "$", "search", "=", "array", "(", "'$@SLASH@$'", ",", "'$@FORCEDOWNLOAD@$'", ")", ";", "$", "replace", "=", "array", "(", "$", "slash", ",", "$", "forcedownload", ")", ";", "return", "str_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "result", ")", ";", "}" ]
Provide NULL and legacy file.php uses decoding
[ "Provide", "NULL", "and", "legacy", "file", ".", "php", "uses", "decoding" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/restore_structure_parser_processor.class.php#L50-L84
219,689
moodle/moodle
backup/util/helper/restore_structure_parser_processor.class.php
restore_structure_parser_processor.postprocess_chunk
protected function postprocess_chunk($data) { // Iterate over all the data tags, if any of them is // not 'subplugin_XXXX' or has value, then it's a valid chunk, // pass it to standard (parent) processing of chunks. foreach ($data['tags'] as $key => $value) { if (trim($value) !== '' || strpos($key, 'subplugin_') !== 0) { parent::postprocess_chunk($data); return; } } // Arrived here, all the tags correspond to sublplugins and are empty, // skip the chunk, and debug_developer notice $this->chunks--; // not counted debugging('Missing support on restore for ' . clean_param($data['path'], PARAM_PATH) . ' subplugin (' . implode(', ', array_keys($data['tags'])) .')', DEBUG_DEVELOPER); }
php
protected function postprocess_chunk($data) { // Iterate over all the data tags, if any of them is // not 'subplugin_XXXX' or has value, then it's a valid chunk, // pass it to standard (parent) processing of chunks. foreach ($data['tags'] as $key => $value) { if (trim($value) !== '' || strpos($key, 'subplugin_') !== 0) { parent::postprocess_chunk($data); return; } } // Arrived here, all the tags correspond to sublplugins and are empty, // skip the chunk, and debug_developer notice $this->chunks--; // not counted debugging('Missing support on restore for ' . clean_param($data['path'], PARAM_PATH) . ' subplugin (' . implode(', ', array_keys($data['tags'])) .')', DEBUG_DEVELOPER); }
[ "protected", "function", "postprocess_chunk", "(", "$", "data", ")", "{", "// Iterate over all the data tags, if any of them is", "// not 'subplugin_XXXX' or has value, then it's a valid chunk,", "// pass it to standard (parent) processing of chunks.", "foreach", "(", "$", "data", "[", "'tags'", "]", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "trim", "(", "$", "value", ")", "!==", "''", "||", "strpos", "(", "$", "key", ",", "'subplugin_'", ")", "!==", "0", ")", "{", "parent", "::", "postprocess_chunk", "(", "$", "data", ")", ";", "return", ";", "}", "}", "// Arrived here, all the tags correspond to sublplugins and are empty,", "// skip the chunk, and debug_developer notice", "$", "this", "->", "chunks", "--", ";", "// not counted", "debugging", "(", "'Missing support on restore for '", ".", "clean_param", "(", "$", "data", "[", "'path'", "]", ",", "PARAM_PATH", ")", ".", "' subplugin ('", ".", "implode", "(", "', '", ",", "array_keys", "(", "$", "data", "[", "'tags'", "]", ")", ")", ".", "')'", ",", "DEBUG_DEVELOPER", ")", ";", "}" ]
Override this method so we'll be able to skip dispatching some well-known chunks, like the ones being 100% part of subplugins stuff. Useful for allowing development without having all the possible restore subplugins defined
[ "Override", "this", "method", "so", "we", "ll", "be", "able", "to", "skip", "dispatching", "some", "well", "-", "known", "chunks", "like", "the", "ones", "being", "100%", "part", "of", "subplugins", "stuff", ".", "Useful", "for", "allowing", "development", "without", "having", "all", "the", "possible", "restore", "subplugins", "defined" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/restore_structure_parser_processor.class.php#L93-L109
219,690
moodle/moodle
question/type/match/renderer.php
qtype_match_renderer.format_stem_text
public function format_stem_text($qa, $stemid) { $question = $qa->get_question(); return $question->format_text( $question->stems[$stemid], $question->stemformat[$stemid], $qa, 'qtype_match', 'subquestion', $stemid); }
php
public function format_stem_text($qa, $stemid) { $question = $qa->get_question(); return $question->format_text( $question->stems[$stemid], $question->stemformat[$stemid], $qa, 'qtype_match', 'subquestion', $stemid); }
[ "public", "function", "format_stem_text", "(", "$", "qa", ",", "$", "stemid", ")", "{", "$", "question", "=", "$", "qa", "->", "get_question", "(", ")", ";", "return", "$", "question", "->", "format_text", "(", "$", "question", "->", "stems", "[", "$", "stemid", "]", ",", "$", "question", "->", "stemformat", "[", "$", "stemid", "]", ",", "$", "qa", ",", "'qtype_match'", ",", "'subquestion'", ",", "$", "stemid", ")", ";", "}" ]
Format each question stem. Overwritten by randomsamatch renderer. @param question_attempt $qa @param integer $stemid stem index @return string
[ "Format", "each", "question", "stem", ".", "Overwritten", "by", "randomsamatch", "renderer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/match/renderer.php#L117-L122
219,691
moodle/moodle
admin/tool/xmldb/actions/view_structure_php/view_structure_php.class.php
view_structure_php.create_table_php
function create_table_php($structure, $table) { $result = ''; // Validate if we can do it if (!$table = $structure->getTable($table)) { return false; } if ($table->getAllErrors()) { return false; } // Add the standard PHP header $result .= XMLDB_PHP_HEADER; // Add contents $result .= XMLDB_LINEFEED; $result .= ' // Define table ' . $table->getName() . ' to be created.' . XMLDB_LINEFEED; $result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= XMLDB_LINEFEED; $result .= ' // Adding fields to table ' . $table->getName() . '.' . XMLDB_LINEFEED; // Iterate over each field foreach ($table->getFields() as $field) { // The field header, with name $result .= ' $table->add_field(' . "'" . $field->getName() . "', "; // The field PHP specs $result .= $field->getPHP(false); // The end of the line $result .= ');' . XMLDB_LINEFEED; } // Iterate over each key if ($keys = $table->getKeys()) { $result .= XMLDB_LINEFEED; $result .= ' // Adding keys to table ' . $table->getName() . '.' . XMLDB_LINEFEED; foreach ($keys as $key) { // The key header, with name $result .= ' $table->add_key(' . "'" . $key->getName() . "', "; // The key PHP specs $result .= $key->getPHP(); // The end of the line $result .= ');' . XMLDB_LINEFEED; } } // Iterate over each index if ($indexes = $table->getIndexes()) { $result .= XMLDB_LINEFEED; $result .= ' // Adding indexes to table ' . $table->getName() . '.' . XMLDB_LINEFEED; foreach ($indexes as $index) { // The index header, with name $result .= ' $table->add_index(' . "'" . $index->getName() . "', "; // The index PHP specs $result .= $index->getPHP(); // The end of the line $result .= ');' . XMLDB_LINEFEED; } } // Launch the proper DDL $result .= XMLDB_LINEFEED; $result .= ' // Conditionally launch create table for ' . $table->getName() . '.' . XMLDB_LINEFEED; $result .= ' if (!$dbman->table_exists($table)) {' . XMLDB_LINEFEED; $result .= ' $dbman->create_table($table);' . XMLDB_LINEFEED; $result .= ' }' . XMLDB_LINEFEED; // Add the proper upgrade_xxxx_savepoint call $result .= $this->upgrade_savepoint_php ($structure); // Add standard PHP footer $result .= XMLDB_PHP_FOOTER; return $result; }
php
function create_table_php($structure, $table) { $result = ''; // Validate if we can do it if (!$table = $structure->getTable($table)) { return false; } if ($table->getAllErrors()) { return false; } // Add the standard PHP header $result .= XMLDB_PHP_HEADER; // Add contents $result .= XMLDB_LINEFEED; $result .= ' // Define table ' . $table->getName() . ' to be created.' . XMLDB_LINEFEED; $result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED; $result .= XMLDB_LINEFEED; $result .= ' // Adding fields to table ' . $table->getName() . '.' . XMLDB_LINEFEED; // Iterate over each field foreach ($table->getFields() as $field) { // The field header, with name $result .= ' $table->add_field(' . "'" . $field->getName() . "', "; // The field PHP specs $result .= $field->getPHP(false); // The end of the line $result .= ');' . XMLDB_LINEFEED; } // Iterate over each key if ($keys = $table->getKeys()) { $result .= XMLDB_LINEFEED; $result .= ' // Adding keys to table ' . $table->getName() . '.' . XMLDB_LINEFEED; foreach ($keys as $key) { // The key header, with name $result .= ' $table->add_key(' . "'" . $key->getName() . "', "; // The key PHP specs $result .= $key->getPHP(); // The end of the line $result .= ');' . XMLDB_LINEFEED; } } // Iterate over each index if ($indexes = $table->getIndexes()) { $result .= XMLDB_LINEFEED; $result .= ' // Adding indexes to table ' . $table->getName() . '.' . XMLDB_LINEFEED; foreach ($indexes as $index) { // The index header, with name $result .= ' $table->add_index(' . "'" . $index->getName() . "', "; // The index PHP specs $result .= $index->getPHP(); // The end of the line $result .= ');' . XMLDB_LINEFEED; } } // Launch the proper DDL $result .= XMLDB_LINEFEED; $result .= ' // Conditionally launch create table for ' . $table->getName() . '.' . XMLDB_LINEFEED; $result .= ' if (!$dbman->table_exists($table)) {' . XMLDB_LINEFEED; $result .= ' $dbman->create_table($table);' . XMLDB_LINEFEED; $result .= ' }' . XMLDB_LINEFEED; // Add the proper upgrade_xxxx_savepoint call $result .= $this->upgrade_savepoint_php ($structure); // Add standard PHP footer $result .= XMLDB_PHP_FOOTER; return $result; }
[ "function", "create_table_php", "(", "$", "structure", ",", "$", "table", ")", "{", "$", "result", "=", "''", ";", "// Validate if we can do it", "if", "(", "!", "$", "table", "=", "$", "structure", "->", "getTable", "(", "$", "table", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "table", "->", "getAllErrors", "(", ")", ")", "{", "return", "false", ";", "}", "// Add the standard PHP header", "$", "result", ".=", "XMLDB_PHP_HEADER", ";", "// Add contents", "$", "result", ".=", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' // Define table '", ".", "$", "table", "->", "getName", "(", ")", ".", "' to be created.'", ".", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' $table = new xmldb_table('", ".", "\"'\"", ".", "$", "table", "->", "getName", "(", ")", ".", "\"'\"", ".", "');'", ".", "XMLDB_LINEFEED", ";", "$", "result", ".=", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' // Adding fields to table '", ".", "$", "table", "->", "getName", "(", ")", ".", "'.'", ".", "XMLDB_LINEFEED", ";", "// Iterate over each field", "foreach", "(", "$", "table", "->", "getFields", "(", ")", "as", "$", "field", ")", "{", "// The field header, with name", "$", "result", ".=", "' $table->add_field('", ".", "\"'\"", ".", "$", "field", "->", "getName", "(", ")", ".", "\"', \"", ";", "// The field PHP specs", "$", "result", ".=", "$", "field", "->", "getPHP", "(", "false", ")", ";", "// The end of the line", "$", "result", ".=", "');'", ".", "XMLDB_LINEFEED", ";", "}", "// Iterate over each key", "if", "(", "$", "keys", "=", "$", "table", "->", "getKeys", "(", ")", ")", "{", "$", "result", ".=", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' // Adding keys to table '", ".", "$", "table", "->", "getName", "(", ")", ".", "'.'", ".", "XMLDB_LINEFEED", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "// The key header, with name", "$", "result", ".=", "' $table->add_key('", ".", "\"'\"", ".", "$", "key", "->", "getName", "(", ")", ".", "\"', \"", ";", "// The key PHP specs", "$", "result", ".=", "$", "key", "->", "getPHP", "(", ")", ";", "// The end of the line", "$", "result", ".=", "');'", ".", "XMLDB_LINEFEED", ";", "}", "}", "// Iterate over each index", "if", "(", "$", "indexes", "=", "$", "table", "->", "getIndexes", "(", ")", ")", "{", "$", "result", ".=", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' // Adding indexes to table '", ".", "$", "table", "->", "getName", "(", ")", ".", "'.'", ".", "XMLDB_LINEFEED", ";", "foreach", "(", "$", "indexes", "as", "$", "index", ")", "{", "// The index header, with name", "$", "result", ".=", "' $table->add_index('", ".", "\"'\"", ".", "$", "index", "->", "getName", "(", ")", ".", "\"', \"", ";", "// The index PHP specs", "$", "result", ".=", "$", "index", "->", "getPHP", "(", ")", ";", "// The end of the line", "$", "result", ".=", "');'", ".", "XMLDB_LINEFEED", ";", "}", "}", "// Launch the proper DDL", "$", "result", ".=", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' // Conditionally launch create table for '", ".", "$", "table", "->", "getName", "(", ")", ".", "'.'", ".", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' if (!$dbman->table_exists($table)) {'", ".", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' $dbman->create_table($table);'", ".", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' }'", ".", "XMLDB_LINEFEED", ";", "// Add the proper upgrade_xxxx_savepoint call", "$", "result", ".=", "$", "this", "->", "upgrade_savepoint_php", "(", "$", "structure", ")", ";", "// Add standard PHP footer", "$", "result", ".=", "XMLDB_PHP_FOOTER", ";", "return", "$", "result", ";", "}" ]
This function will generate all the PHP code needed to create one table using XMLDB objects and functions @param xmldb_structure structure object containing all the info @param string table table code to be created @return string PHP code to be used to create the table
[ "This", "function", "will", "generate", "all", "the", "PHP", "code", "needed", "to", "create", "one", "table", "using", "XMLDB", "objects", "and", "functions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/xmldb/actions/view_structure_php/view_structure_php.class.php#L157-L227
219,692
moodle/moodle
admin/tool/xmldb/actions/view_structure_php/view_structure_php.class.php
view_structure_php.drop_table_php
function drop_table_php($structure, $table) { $result = ''; // Validate if we can do it if (!$table = $structure->getTable($table)) { return false; } if ($table->getAllErrors()) { return false; } // Add the standard PHP header $result .= XMLDB_PHP_HEADER; // Add contents $result .= XMLDB_LINEFEED; $result .= ' // Define table ' . $table->getName() . ' to be dropped.' . XMLDB_LINEFEED; $result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED; // Launch the proper DDL $result .= XMLDB_LINEFEED; $result .= ' // Conditionally launch drop table for ' . $table->getName() . '.' . XMLDB_LINEFEED; $result .= ' if ($dbman->table_exists($table)) {' . XMLDB_LINEFEED; $result .= ' $dbman->drop_table($table);' . XMLDB_LINEFEED; $result .= ' }' . XMLDB_LINEFEED; // Add the proper upgrade_xxxx_savepoint call $result .= $this->upgrade_savepoint_php ($structure); // Add standard PHP footer $result .= XMLDB_PHP_FOOTER; return $result; }
php
function drop_table_php($structure, $table) { $result = ''; // Validate if we can do it if (!$table = $structure->getTable($table)) { return false; } if ($table->getAllErrors()) { return false; } // Add the standard PHP header $result .= XMLDB_PHP_HEADER; // Add contents $result .= XMLDB_LINEFEED; $result .= ' // Define table ' . $table->getName() . ' to be dropped.' . XMLDB_LINEFEED; $result .= ' $table = new xmldb_table(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED; // Launch the proper DDL $result .= XMLDB_LINEFEED; $result .= ' // Conditionally launch drop table for ' . $table->getName() . '.' . XMLDB_LINEFEED; $result .= ' if ($dbman->table_exists($table)) {' . XMLDB_LINEFEED; $result .= ' $dbman->drop_table($table);' . XMLDB_LINEFEED; $result .= ' }' . XMLDB_LINEFEED; // Add the proper upgrade_xxxx_savepoint call $result .= $this->upgrade_savepoint_php ($structure); // Add standard PHP footer $result .= XMLDB_PHP_FOOTER; return $result; }
[ "function", "drop_table_php", "(", "$", "structure", ",", "$", "table", ")", "{", "$", "result", "=", "''", ";", "// Validate if we can do it", "if", "(", "!", "$", "table", "=", "$", "structure", "->", "getTable", "(", "$", "table", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "table", "->", "getAllErrors", "(", ")", ")", "{", "return", "false", ";", "}", "// Add the standard PHP header", "$", "result", ".=", "XMLDB_PHP_HEADER", ";", "// Add contents", "$", "result", ".=", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' // Define table '", ".", "$", "table", "->", "getName", "(", ")", ".", "' to be dropped.'", ".", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' $table = new xmldb_table('", ".", "\"'\"", ".", "$", "table", "->", "getName", "(", ")", ".", "\"'\"", ".", "');'", ".", "XMLDB_LINEFEED", ";", "// Launch the proper DDL", "$", "result", ".=", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' // Conditionally launch drop table for '", ".", "$", "table", "->", "getName", "(", ")", ".", "'.'", ".", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' if ($dbman->table_exists($table)) {'", ".", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' $dbman->drop_table($table);'", ".", "XMLDB_LINEFEED", ";", "$", "result", ".=", "' }'", ".", "XMLDB_LINEFEED", ";", "// Add the proper upgrade_xxxx_savepoint call", "$", "result", ".=", "$", "this", "->", "upgrade_savepoint_php", "(", "$", "structure", ")", ";", "// Add standard PHP footer", "$", "result", ".=", "XMLDB_PHP_FOOTER", ";", "return", "$", "result", ";", "}" ]
This function will generate all the PHP code needed to drop one table using XMLDB objects and functions @param xmldb_structure structure object containing all the info @param string table table code to be dropped @return string PHP code to be used to drop the table
[ "This", "function", "will", "generate", "all", "the", "PHP", "code", "needed", "to", "drop", "one", "table", "using", "XMLDB", "objects", "and", "functions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/xmldb/actions/view_structure_php/view_structure_php.class.php#L237-L270
219,693
moodle/moodle
blocks/tags/backup/moodle2/restore_tags_block_task.class.php
restore_tags_block_task.after_restore
public function after_restore() { global $DB; // Get the blockid. $blockid = $this->get_blockid(); // Extract block configdata and remove tag collection reference if this is another site. Also map contextid. if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) { $config = unserialize(base64_decode($configdata)); $changed = false; if (!empty($config->tagcoll) && $config->tagcoll > 1 && !$this->is_samesite()) { $config->tagcoll = 0; $changed = true; } if (!empty($config->ctx)) { if ($ctxmap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'context', $config->ctx)) { $config->ctx = $ctxmap->newitemid; } else { $config->ctx = 0; } $changed = true; } if ($changed) { $configdata = base64_encode(serialize($config)); $DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid)); } } }
php
public function after_restore() { global $DB; // Get the blockid. $blockid = $this->get_blockid(); // Extract block configdata and remove tag collection reference if this is another site. Also map contextid. if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) { $config = unserialize(base64_decode($configdata)); $changed = false; if (!empty($config->tagcoll) && $config->tagcoll > 1 && !$this->is_samesite()) { $config->tagcoll = 0; $changed = true; } if (!empty($config->ctx)) { if ($ctxmap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'context', $config->ctx)) { $config->ctx = $ctxmap->newitemid; } else { $config->ctx = 0; } $changed = true; } if ($changed) { $configdata = base64_encode(serialize($config)); $DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid)); } } }
[ "public", "function", "after_restore", "(", ")", "{", "global", "$", "DB", ";", "// Get the blockid.", "$", "blockid", "=", "$", "this", "->", "get_blockid", "(", ")", ";", "// Extract block configdata and remove tag collection reference if this is another site. Also map contextid.", "if", "(", "$", "configdata", "=", "$", "DB", "->", "get_field", "(", "'block_instances'", ",", "'configdata'", ",", "array", "(", "'id'", "=>", "$", "blockid", ")", ")", ")", "{", "$", "config", "=", "unserialize", "(", "base64_decode", "(", "$", "configdata", ")", ")", ";", "$", "changed", "=", "false", ";", "if", "(", "!", "empty", "(", "$", "config", "->", "tagcoll", ")", "&&", "$", "config", "->", "tagcoll", ">", "1", "&&", "!", "$", "this", "->", "is_samesite", "(", ")", ")", "{", "$", "config", "->", "tagcoll", "=", "0", ";", "$", "changed", "=", "true", ";", "}", "if", "(", "!", "empty", "(", "$", "config", "->", "ctx", ")", ")", "{", "if", "(", "$", "ctxmap", "=", "restore_dbops", "::", "get_backup_ids_record", "(", "$", "this", "->", "get_restoreid", "(", ")", ",", "'context'", ",", "$", "config", "->", "ctx", ")", ")", "{", "$", "config", "->", "ctx", "=", "$", "ctxmap", "->", "newitemid", ";", "}", "else", "{", "$", "config", "->", "ctx", "=", "0", ";", "}", "$", "changed", "=", "true", ";", "}", "if", "(", "$", "changed", ")", "{", "$", "configdata", "=", "base64_encode", "(", "serialize", "(", "$", "config", ")", ")", ";", "$", "DB", "->", "set_field", "(", "'block_instances'", ",", "'configdata'", ",", "$", "configdata", ",", "array", "(", "'id'", "=>", "$", "blockid", ")", ")", ";", "}", "}", "}" ]
This function, executed after all the tasks in the plan have been executed, will remove tag collection reference in case block was restored into another site. Also get mapping of contextid.
[ "This", "function", "executed", "after", "all", "the", "tasks", "in", "the", "plan", "have", "been", "executed", "will", "remove", "tag", "collection", "reference", "in", "case", "block", "was", "restored", "into", "another", "site", ".", "Also", "get", "mapping", "of", "contextid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/tags/backup/moodle2/restore_tags_block_task.class.php#L52-L79
219,694
moodle/moodle
lib/classes/chart_bar.php
chart_bar.jsonSerialize
public function jsonSerialize() { // @codingStandardsIgnoreLine (CONTRIB-6469). $data = parent::jsonSerialize(); $data['horizontal'] = $this->get_horizontal(); $data['stacked'] = $this->get_stacked(); return $data; }
php
public function jsonSerialize() { // @codingStandardsIgnoreLine (CONTRIB-6469). $data = parent::jsonSerialize(); $data['horizontal'] = $this->get_horizontal(); $data['stacked'] = $this->get_stacked(); return $data; }
[ "public", "function", "jsonSerialize", "(", ")", "{", "// @codingStandardsIgnoreLine (CONTRIB-6469).", "$", "data", "=", "parent", "::", "jsonSerialize", "(", ")", ";", "$", "data", "[", "'horizontal'", "]", "=", "$", "this", "->", "get_horizontal", "(", ")", ";", "$", "data", "[", "'stacked'", "]", "=", "$", "this", "->", "get_stacked", "(", ")", ";", "return", "$", "data", ";", "}" ]
Add the horizontal to the parent and return the serialized data. @return array
[ "Add", "the", "horizontal", "to", "the", "parent", "and", "return", "the", "serialized", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/chart_bar.php#L46-L51
219,695
moodle/moodle
admin/tool/filetypes/classes/utils.php
utils.is_extension_invalid
public static function is_extension_invalid($extension, $oldextension = '') { $extension = trim($extension); if ($extension === '' || $extension[0] === '.') { return true; } $mimeinfo = get_mimetypes_array(); if ($oldextension !== '') { unset($mimeinfo[$oldextension]); } return array_key_exists($extension, $mimeinfo); }
php
public static function is_extension_invalid($extension, $oldextension = '') { $extension = trim($extension); if ($extension === '' || $extension[0] === '.') { return true; } $mimeinfo = get_mimetypes_array(); if ($oldextension !== '') { unset($mimeinfo[$oldextension]); } return array_key_exists($extension, $mimeinfo); }
[ "public", "static", "function", "is_extension_invalid", "(", "$", "extension", ",", "$", "oldextension", "=", "''", ")", "{", "$", "extension", "=", "trim", "(", "$", "extension", ")", ";", "if", "(", "$", "extension", "===", "''", "||", "$", "extension", "[", "0", "]", "===", "'.'", ")", "{", "return", "true", ";", "}", "$", "mimeinfo", "=", "get_mimetypes_array", "(", ")", ";", "if", "(", "$", "oldextension", "!==", "''", ")", "{", "unset", "(", "$", "mimeinfo", "[", "$", "oldextension", "]", ")", ";", "}", "return", "array_key_exists", "(", "$", "extension", ",", "$", "mimeinfo", ")", ";", "}" ]
Checks if the given file type extension is invalid. The added file type extension must be unique and must not begin with a dot. @param string $extension Extension of the file type to add @param string $oldextension Extension prior to update (empty string if adding new type) @return bool True if it the file type trying to add already exists
[ "Checks", "if", "the", "given", "file", "type", "extension", "is", "invalid", ".", "The", "added", "file", "type", "extension", "must", "be", "unique", "and", "must", "not", "begin", "with", "a", "dot", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/filetypes/classes/utils.php#L45-L57
219,696
moodle/moodle
admin/tool/filetypes/classes/utils.php
utils.is_defaulticon_allowed
public static function is_defaulticon_allowed($mimetype, $oldextension = '') { $mimeinfo = get_mimetypes_array(); if ($oldextension !== '') { unset($mimeinfo[$oldextension]); } foreach ($mimeinfo as $extension => $values) { if ($values['type'] !== $mimetype) { continue; } if (!empty($values['defaulticon'])) { return false; } } return true; }
php
public static function is_defaulticon_allowed($mimetype, $oldextension = '') { $mimeinfo = get_mimetypes_array(); if ($oldextension !== '') { unset($mimeinfo[$oldextension]); } foreach ($mimeinfo as $extension => $values) { if ($values['type'] !== $mimetype) { continue; } if (!empty($values['defaulticon'])) { return false; } } return true; }
[ "public", "static", "function", "is_defaulticon_allowed", "(", "$", "mimetype", ",", "$", "oldextension", "=", "''", ")", "{", "$", "mimeinfo", "=", "get_mimetypes_array", "(", ")", ";", "if", "(", "$", "oldextension", "!==", "''", ")", "{", "unset", "(", "$", "mimeinfo", "[", "$", "oldextension", "]", ")", ";", "}", "foreach", "(", "$", "mimeinfo", "as", "$", "extension", "=>", "$", "values", ")", "{", "if", "(", "$", "values", "[", "'type'", "]", "!==", "$", "mimetype", ")", "{", "continue", ";", "}", "if", "(", "!", "empty", "(", "$", "values", "[", "'defaulticon'", "]", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks if we are allowed to turn on the 'default icon' option. You can only have one of these for a given MIME type. @param string $mimetype MIME type @param string $oldextension File extension name (before any change)
[ "Checks", "if", "we", "are", "allowed", "to", "turn", "on", "the", "default", "icon", "option", ".", "You", "can", "only", "have", "one", "of", "these", "for", "a", "given", "MIME", "type", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/filetypes/classes/utils.php#L66-L80
219,697
moodle/moodle
admin/tool/filetypes/classes/utils.php
utils.get_icons_from_path
public static function get_icons_from_path($path) { $icons = array(); if ($handle = @opendir($path)) { while (($file = readdir($handle)) !== false) { $matches = array(); if (preg_match('~(.+?)(?:-24|-32|-48|-64|-72|-80|-96|-128|-256)?\.(?:svg|gif|png)$~', $file, $matches)) { $key = $matches[1]; $icons[$key] = $key; } } closedir($handle); } ksort($icons); return $icons; }
php
public static function get_icons_from_path($path) { $icons = array(); if ($handle = @opendir($path)) { while (($file = readdir($handle)) !== false) { $matches = array(); if (preg_match('~(.+?)(?:-24|-32|-48|-64|-72|-80|-96|-128|-256)?\.(?:svg|gif|png)$~', $file, $matches)) { $key = $matches[1]; $icons[$key] = $key; } } closedir($handle); } ksort($icons); return $icons; }
[ "public", "static", "function", "get_icons_from_path", "(", "$", "path", ")", "{", "$", "icons", "=", "array", "(", ")", ";", "if", "(", "$", "handle", "=", "@", "opendir", "(", "$", "path", ")", ")", "{", "while", "(", "(", "$", "file", "=", "readdir", "(", "$", "handle", ")", ")", "!==", "false", ")", "{", "$", "matches", "=", "array", "(", ")", ";", "if", "(", "preg_match", "(", "'~(.+?)(?:-24|-32|-48|-64|-72|-80|-96|-128|-256)?\\.(?:svg|gif|png)$~'", ",", "$", "file", ",", "$", "matches", ")", ")", "{", "$", "key", "=", "$", "matches", "[", "1", "]", ";", "$", "icons", "[", "$", "key", "]", "=", "$", "key", ";", "}", "}", "closedir", "(", "$", "handle", ")", ";", "}", "ksort", "(", "$", "icons", ")", ";", "return", "$", "icons", ";", "}" ]
Gets all unique file type icons from a specific path, not including sub-directories. Icon files such as pdf.png, pdf-24.png and pdf-36.png etc. are counted as the same icon type. The resultant array has both key and value set to the icon name prefix, such as 'pdf' => 'pdf'. @param string $path The path of the icon path @return array An array of unique file icons within the given path
[ "Gets", "all", "unique", "file", "type", "icons", "from", "a", "specific", "path", "not", "including", "sub", "-", "directories", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/filetypes/classes/utils.php#L95-L110
219,698
moodle/moodle
lib/classes/update/code_manager.php
code_manager.zip_plugin_folder
public function zip_plugin_folder($folderpath, $targetzip) { if (file_exists($targetzip)) { throw new coding_exception('Attempting to create already existing ZIP file', $targetzip); } if (!is_writable(dirname($targetzip))) { throw new coding_exception('Target ZIP location not writable', dirname($targetzip)); } if (!is_dir($folderpath)) { throw new coding_exception('Attempting to ZIP non-existing source directory', $folderpath); } $files = $this->list_plugin_folder_files($folderpath); $fp = get_file_packer('application/zip'); return $fp->archive_to_pathname($files, $targetzip, false); }
php
public function zip_plugin_folder($folderpath, $targetzip) { if (file_exists($targetzip)) { throw new coding_exception('Attempting to create already existing ZIP file', $targetzip); } if (!is_writable(dirname($targetzip))) { throw new coding_exception('Target ZIP location not writable', dirname($targetzip)); } if (!is_dir($folderpath)) { throw new coding_exception('Attempting to ZIP non-existing source directory', $folderpath); } $files = $this->list_plugin_folder_files($folderpath); $fp = get_file_packer('application/zip'); return $fp->archive_to_pathname($files, $targetzip, false); }
[ "public", "function", "zip_plugin_folder", "(", "$", "folderpath", ",", "$", "targetzip", ")", "{", "if", "(", "file_exists", "(", "$", "targetzip", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Attempting to create already existing ZIP file'", ",", "$", "targetzip", ")", ";", "}", "if", "(", "!", "is_writable", "(", "dirname", "(", "$", "targetzip", ")", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Target ZIP location not writable'", ",", "dirname", "(", "$", "targetzip", ")", ")", ";", "}", "if", "(", "!", "is_dir", "(", "$", "folderpath", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Attempting to ZIP non-existing source directory'", ",", "$", "folderpath", ")", ";", "}", "$", "files", "=", "$", "this", "->", "list_plugin_folder_files", "(", "$", "folderpath", ")", ";", "$", "fp", "=", "get_file_packer", "(", "'application/zip'", ")", ";", "return", "$", "fp", "->", "archive_to_pathname", "(", "$", "files", ",", "$", "targetzip", ",", "false", ")", ";", "}" ]
Make an archive backup of the existing plugin folder. @param string $folderpath full path to the plugin folder @param string $targetzip full path to the zip file to be created @return bool true if file created, false if not
[ "Make", "an", "archive", "backup", "of", "the", "existing", "plugin", "folder", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/code_manager.php#L210-L227
219,699
moodle/moodle
lib/classes/update/code_manager.php
code_manager.archive_plugin_version
public function archive_plugin_version($folderpath, $component, $version, $overwrite=false) { if ($component !== clean_param($component, PARAM_SAFEDIR)) { // This should never happen, but just in case. throw new moodle_exception('unexpected_plugin_component_format', 'core_plugin', '', null, $component); } if ((string)$version !== clean_param((string)$version, PARAM_FILE)) { // Prevent some nasty injections via $plugin->version tricks. throw new moodle_exception('unexpected_plugin_version_format', 'core_plugin', '', null, $version); } if (empty($component) or empty($version)) { return false; } if (!is_dir($folderpath)) { return false; } $archzip = $this->temproot.'/archive/'.$component.'/'.$version.'.zip'; if (file_exists($archzip) and !$overwrite) { return true; } $tmpzip = make_request_directory().'/'.$version.'.zip'; $zipped = $this->zip_plugin_folder($folderpath, $tmpzip); if (!$zipped) { return false; } // Assert that the file looks like a valid one. list($expectedtype, $expectedname) = core_component::normalize_component($component); $actualname = $this->get_plugin_zip_root_dir($tmpzip); if ($actualname !== $expectedname) { // This should not happen. throw new moodle_exception('unexpected_archive_structure', 'core_plugin'); } make_writable_directory(dirname($archzip)); return rename($tmpzip, $archzip); }
php
public function archive_plugin_version($folderpath, $component, $version, $overwrite=false) { if ($component !== clean_param($component, PARAM_SAFEDIR)) { // This should never happen, but just in case. throw new moodle_exception('unexpected_plugin_component_format', 'core_plugin', '', null, $component); } if ((string)$version !== clean_param((string)$version, PARAM_FILE)) { // Prevent some nasty injections via $plugin->version tricks. throw new moodle_exception('unexpected_plugin_version_format', 'core_plugin', '', null, $version); } if (empty($component) or empty($version)) { return false; } if (!is_dir($folderpath)) { return false; } $archzip = $this->temproot.'/archive/'.$component.'/'.$version.'.zip'; if (file_exists($archzip) and !$overwrite) { return true; } $tmpzip = make_request_directory().'/'.$version.'.zip'; $zipped = $this->zip_plugin_folder($folderpath, $tmpzip); if (!$zipped) { return false; } // Assert that the file looks like a valid one. list($expectedtype, $expectedname) = core_component::normalize_component($component); $actualname = $this->get_plugin_zip_root_dir($tmpzip); if ($actualname !== $expectedname) { // This should not happen. throw new moodle_exception('unexpected_archive_structure', 'core_plugin'); } make_writable_directory(dirname($archzip)); return rename($tmpzip, $archzip); }
[ "public", "function", "archive_plugin_version", "(", "$", "folderpath", ",", "$", "component", ",", "$", "version", ",", "$", "overwrite", "=", "false", ")", "{", "if", "(", "$", "component", "!==", "clean_param", "(", "$", "component", ",", "PARAM_SAFEDIR", ")", ")", "{", "// This should never happen, but just in case.", "throw", "new", "moodle_exception", "(", "'unexpected_plugin_component_format'", ",", "'core_plugin'", ",", "''", ",", "null", ",", "$", "component", ")", ";", "}", "if", "(", "(", "string", ")", "$", "version", "!==", "clean_param", "(", "(", "string", ")", "$", "version", ",", "PARAM_FILE", ")", ")", "{", "// Prevent some nasty injections via $plugin->version tricks.", "throw", "new", "moodle_exception", "(", "'unexpected_plugin_version_format'", ",", "'core_plugin'", ",", "''", ",", "null", ",", "$", "version", ")", ";", "}", "if", "(", "empty", "(", "$", "component", ")", "or", "empty", "(", "$", "version", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "is_dir", "(", "$", "folderpath", ")", ")", "{", "return", "false", ";", "}", "$", "archzip", "=", "$", "this", "->", "temproot", ".", "'/archive/'", ".", "$", "component", ".", "'/'", ".", "$", "version", ".", "'.zip'", ";", "if", "(", "file_exists", "(", "$", "archzip", ")", "and", "!", "$", "overwrite", ")", "{", "return", "true", ";", "}", "$", "tmpzip", "=", "make_request_directory", "(", ")", ".", "'/'", ".", "$", "version", ".", "'.zip'", ";", "$", "zipped", "=", "$", "this", "->", "zip_plugin_folder", "(", "$", "folderpath", ",", "$", "tmpzip", ")", ";", "if", "(", "!", "$", "zipped", ")", "{", "return", "false", ";", "}", "// Assert that the file looks like a valid one.", "list", "(", "$", "expectedtype", ",", "$", "expectedname", ")", "=", "core_component", "::", "normalize_component", "(", "$", "component", ")", ";", "$", "actualname", "=", "$", "this", "->", "get_plugin_zip_root_dir", "(", "$", "tmpzip", ")", ";", "if", "(", "$", "actualname", "!==", "$", "expectedname", ")", "{", "// This should not happen.", "throw", "new", "moodle_exception", "(", "'unexpected_archive_structure'", ",", "'core_plugin'", ")", ";", "}", "make_writable_directory", "(", "dirname", "(", "$", "archzip", ")", ")", ";", "return", "rename", "(", "$", "tmpzip", ",", "$", "archzip", ")", ";", "}" ]
Archive the current plugin on-disk version. @param string $folderpath full path to the plugin folder @param string $component @param int $version @param bool $overwrite overwrite existing archive if found @return bool
[ "Archive", "the", "current", "plugin", "on", "-", "disk", "version", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/code_manager.php#L238-L281