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
216,300
moodle/moodle
dataformat/excel/classes/writer.php
writer.set_sheettitle
public function set_sheettitle($title) { if (!$title) { return; } // Replace any characters in the name that Excel cannot cope with. $title = strtr(trim($title, "'"), '[]*/\?:', ' '); // Shorten the title if necessary. $title = \core_text::substr($title, 0, 31); // After the substr, we might now have a single quote on the end. $title = trim($title, "'"); $this->sheettitle = $title; }
php
public function set_sheettitle($title) { if (!$title) { return; } // Replace any characters in the name that Excel cannot cope with. $title = strtr(trim($title, "'"), '[]*/\?:', ' '); // Shorten the title if necessary. $title = \core_text::substr($title, 0, 31); // After the substr, we might now have a single quote on the end. $title = trim($title, "'"); $this->sheettitle = $title; }
[ "public", "function", "set_sheettitle", "(", "$", "title", ")", "{", "if", "(", "!", "$", "title", ")", "{", "return", ";", "}", "// Replace any characters in the name that Excel cannot cope with.", "$", "title", "=", "strtr", "(", "trim", "(", "$", "title", ",", "\"'\"", ")", ",", "'[]*/\\?:'", ",", "' '", ")", ";", "// Shorten the title if necessary.", "$", "title", "=", "\\", "core_text", "::", "substr", "(", "$", "title", ",", "0", ",", "31", ")", ";", "// After the substr, we might now have a single quote on the end.", "$", "title", "=", "trim", "(", "$", "title", ",", "\"'\"", ")", ";", "$", "this", "->", "sheettitle", "=", "$", "title", ";", "}" ]
Set the title of the worksheet inside a spreadsheet For some formats this will be ignored. @param string $title
[ "Set", "the", "title", "of", "the", "worksheet", "inside", "a", "spreadsheet" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/dataformat/excel/classes/writer.php#L54-L67
216,301
moodle/moodle
mod/quiz/accessrule/delaybetweenattempts/rule.php
quizaccess_delaybetweenattempts.compute_next_start_time
protected function compute_next_start_time($numprevattempts, $lastattempt) { if ($numprevattempts == 0) { return 0; } $lastattemptfinish = $lastattempt->timefinish; if ($this->quiz->timelimit > 0) { $lastattemptfinish = min($lastattemptfinish, $lastattempt->timestart + $this->quiz->timelimit); } if ($numprevattempts == 1 && $this->quiz->delay1) { return $lastattemptfinish + $this->quiz->delay1; } else if ($numprevattempts > 1 && $this->quiz->delay2) { return $lastattemptfinish + $this->quiz->delay2; } return 0; }
php
protected function compute_next_start_time($numprevattempts, $lastattempt) { if ($numprevattempts == 0) { return 0; } $lastattemptfinish = $lastattempt->timefinish; if ($this->quiz->timelimit > 0) { $lastattemptfinish = min($lastattemptfinish, $lastattempt->timestart + $this->quiz->timelimit); } if ($numprevattempts == 1 && $this->quiz->delay1) { return $lastattemptfinish + $this->quiz->delay1; } else if ($numprevattempts > 1 && $this->quiz->delay2) { return $lastattemptfinish + $this->quiz->delay2; } return 0; }
[ "protected", "function", "compute_next_start_time", "(", "$", "numprevattempts", ",", "$", "lastattempt", ")", "{", "if", "(", "$", "numprevattempts", "==", "0", ")", "{", "return", "0", ";", "}", "$", "lastattemptfinish", "=", "$", "lastattempt", "->", "timefinish", ";", "if", "(", "$", "this", "->", "quiz", "->", "timelimit", ">", "0", ")", "{", "$", "lastattemptfinish", "=", "min", "(", "$", "lastattemptfinish", ",", "$", "lastattempt", "->", "timestart", "+", "$", "this", "->", "quiz", "->", "timelimit", ")", ";", "}", "if", "(", "$", "numprevattempts", "==", "1", "&&", "$", "this", "->", "quiz", "->", "delay1", ")", "{", "return", "$", "lastattemptfinish", "+", "$", "this", "->", "quiz", "->", "delay1", ";", "}", "else", "if", "(", "$", "numprevattempts", ">", "1", "&&", "$", "this", "->", "quiz", "->", "delay2", ")", "{", "return", "$", "lastattemptfinish", "+", "$", "this", "->", "quiz", "->", "delay2", ";", "}", "return", "0", ";", "}" ]
Compute the next time a student would be allowed to start an attempt, according to this rule. @param int $numprevattempts number of previous attempts. @param object $lastattempt information about the previous attempt. @return number the time.
[ "Compute", "the", "next", "time", "a", "student", "would", "be", "allowed", "to", "start", "an", "attempt", "according", "to", "this", "rule", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/accessrule/delaybetweenattempts/rule.php#L76-L93
216,302
moodle/moodle
customfield/classes/event/category_created.php
category_created.create_from_object
public static function create_from_object(category_controller $category) : category_created { $eventparams = [ 'objectid' => $category->get('id'), 'context' => $category->get_handler()->get_configuration_context(), 'other' => ['name' => $category->get('name')] ]; $event = self::create($eventparams); $event->add_record_snapshot($event->objecttable, $category->to_record()); return $event; }
php
public static function create_from_object(category_controller $category) : category_created { $eventparams = [ 'objectid' => $category->get('id'), 'context' => $category->get_handler()->get_configuration_context(), 'other' => ['name' => $category->get('name')] ]; $event = self::create($eventparams); $event->add_record_snapshot($event->objecttable, $category->to_record()); return $event; }
[ "public", "static", "function", "create_from_object", "(", "category_controller", "$", "category", ")", ":", "category_created", "{", "$", "eventparams", "=", "[", "'objectid'", "=>", "$", "category", "->", "get", "(", "'id'", ")", ",", "'context'", "=>", "$", "category", "->", "get_handler", "(", ")", "->", "get_configuration_context", "(", ")", ",", "'other'", "=>", "[", "'name'", "=>", "$", "category", "->", "get", "(", "'name'", ")", "]", "]", ";", "$", "event", "=", "self", "::", "create", "(", "$", "eventparams", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "$", "event", "->", "objecttable", ",", "$", "category", "->", "to_record", "(", ")", ")", ";", "return", "$", "event", ";", "}" ]
Creates an instance from a category controller object @param category_controller $category @return category_created
[ "Creates", "an", "instance", "from", "a", "category", "controller", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/event/category_created.php#L56-L65
216,303
moodle/moodle
mnet/xmlrpc/xmlparser.php
mnet_encxml_parser.initialise
function initialise() { $this->parser = xml_parser_create(); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "start_element", "end_element"); xml_set_character_data_handler($this->parser, "discard_data"); $this->tag_number = 0; // Just a unique ID for each tag $this->digest = ''; $this->remote_timestamp = ''; $this->remote_wwwroot = ''; $this->signature = ''; $this->data_object = ''; $this->key_URI = ''; $this->payload_encrypted = false; $this->cipher = array(); $this->error = array(); $this->remoteerror = null; $this->errorstarted = false; return true; }
php
function initialise() { $this->parser = xml_parser_create(); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "start_element", "end_element"); xml_set_character_data_handler($this->parser, "discard_data"); $this->tag_number = 0; // Just a unique ID for each tag $this->digest = ''; $this->remote_timestamp = ''; $this->remote_wwwroot = ''; $this->signature = ''; $this->data_object = ''; $this->key_URI = ''; $this->payload_encrypted = false; $this->cipher = array(); $this->error = array(); $this->remoteerror = null; $this->errorstarted = false; return true; }
[ "function", "initialise", "(", ")", "{", "$", "this", "->", "parser", "=", "xml_parser_create", "(", ")", ";", "xml_set_object", "(", "$", "this", "->", "parser", ",", "$", "this", ")", ";", "xml_set_element_handler", "(", "$", "this", "->", "parser", ",", "\"start_element\"", ",", "\"end_element\"", ")", ";", "xml_set_character_data_handler", "(", "$", "this", "->", "parser", ",", "\"discard_data\"", ")", ";", "$", "this", "->", "tag_number", "=", "0", ";", "// Just a unique ID for each tag", "$", "this", "->", "digest", "=", "''", ";", "$", "this", "->", "remote_timestamp", "=", "''", ";", "$", "this", "->", "remote_wwwroot", "=", "''", ";", "$", "this", "->", "signature", "=", "''", ";", "$", "this", "->", "data_object", "=", "''", ";", "$", "this", "->", "key_URI", "=", "''", ";", "$", "this", "->", "payload_encrypted", "=", "false", ";", "$", "this", "->", "cipher", "=", "array", "(", ")", ";", "$", "this", "->", "error", "=", "array", "(", ")", ";", "$", "this", "->", "remoteerror", "=", "null", ";", "$", "this", "->", "errorstarted", "=", "false", ";", "return", "true", ";", "}" ]
Set default element handlers and initialise properties to empty. @return bool True
[ "Set", "default", "element", "handlers", "and", "initialise", "properties", "to", "empty", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mnet/xmlrpc/xmlparser.php#L39-L59
216,304
moodle/moodle
mnet/xmlrpc/xmlparser.php
mnet_encxml_parser.parse
function parse($data) { $p = xml_parse($this->parser, $data); if ($p == 0) { // Parse failed $errcode = xml_get_error_code($this->parser); $errstring = xml_error_string($errcode); $lineno = xml_get_current_line_number($this->parser); if ($lineno !== false) { $error = array('lineno' => $lineno); $lineno--; // Line numbering starts at 1. while ($lineno > 0) { $data = strstr($data, "\n"); $lineno--; } $data .= "\n"; // In case there's only one line (no newline) $line = substr($data, 0, strpos($data, "\n")); $error['code'] = $errcode; $error['string'] = $errstring; $error['line'] = $line; $this->error[] = $error; } else { $this->error[] = array('code' => $errcode, 'string' => $errstring); } } if (!empty($this->remoteerror)) { return false; } if (count($this->cipher) > 0) { $this->cipher = array_values($this->cipher); $this->payload_encrypted = true; } return (bool)$p; }
php
function parse($data) { $p = xml_parse($this->parser, $data); if ($p == 0) { // Parse failed $errcode = xml_get_error_code($this->parser); $errstring = xml_error_string($errcode); $lineno = xml_get_current_line_number($this->parser); if ($lineno !== false) { $error = array('lineno' => $lineno); $lineno--; // Line numbering starts at 1. while ($lineno > 0) { $data = strstr($data, "\n"); $lineno--; } $data .= "\n"; // In case there's only one line (no newline) $line = substr($data, 0, strpos($data, "\n")); $error['code'] = $errcode; $error['string'] = $errstring; $error['line'] = $line; $this->error[] = $error; } else { $this->error[] = array('code' => $errcode, 'string' => $errstring); } } if (!empty($this->remoteerror)) { return false; } if (count($this->cipher) > 0) { $this->cipher = array_values($this->cipher); $this->payload_encrypted = true; } return (bool)$p; }
[ "function", "parse", "(", "$", "data", ")", "{", "$", "p", "=", "xml_parse", "(", "$", "this", "->", "parser", ",", "$", "data", ")", ";", "if", "(", "$", "p", "==", "0", ")", "{", "// Parse failed", "$", "errcode", "=", "xml_get_error_code", "(", "$", "this", "->", "parser", ")", ";", "$", "errstring", "=", "xml_error_string", "(", "$", "errcode", ")", ";", "$", "lineno", "=", "xml_get_current_line_number", "(", "$", "this", "->", "parser", ")", ";", "if", "(", "$", "lineno", "!==", "false", ")", "{", "$", "error", "=", "array", "(", "'lineno'", "=>", "$", "lineno", ")", ";", "$", "lineno", "--", ";", "// Line numbering starts at 1.", "while", "(", "$", "lineno", ">", "0", ")", "{", "$", "data", "=", "strstr", "(", "$", "data", ",", "\"\\n\"", ")", ";", "$", "lineno", "--", ";", "}", "$", "data", ".=", "\"\\n\"", ";", "// In case there's only one line (no newline)", "$", "line", "=", "substr", "(", "$", "data", ",", "0", ",", "strpos", "(", "$", "data", ",", "\"\\n\"", ")", ")", ";", "$", "error", "[", "'code'", "]", "=", "$", "errcode", ";", "$", "error", "[", "'string'", "]", "=", "$", "errstring", ";", "$", "error", "[", "'line'", "]", "=", "$", "line", ";", "$", "this", "->", "error", "[", "]", "=", "$", "error", ";", "}", "else", "{", "$", "this", "->", "error", "[", "]", "=", "array", "(", "'code'", "=>", "$", "errcode", ",", "'string'", "=>", "$", "errstring", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "remoteerror", ")", ")", "{", "return", "false", ";", "}", "if", "(", "count", "(", "$", "this", "->", "cipher", ")", ">", "0", ")", "{", "$", "this", "->", "cipher", "=", "array_values", "(", "$", "this", "->", "cipher", ")", ";", "$", "this", "->", "payload_encrypted", "=", "true", ";", "}", "return", "(", "bool", ")", "$", "p", ";", "}" ]
Parse a block of XML text The XML Text will be an XML-RPC request which is wrapped in an XML doc with a signature from the sender. This envelope may be encrypted and delivered within another XML envelope with a symmetric key. The parser should first decrypt this XML, and then place the XML-RPC request into the data_object property, and the signature into the signature property. See the W3C's {@link http://www.w3.org/TR/xmlenc-core/ XML Encryption Syntax and Processing} and {@link http://www.w3.org/TR/2001/PR-xmldsig-core-20010820/ XML-Signature Syntax and Processing} guidelines for more detail on the XML. -----XML-Envelope--------------------------------- | | | Symmetric-key-------------------------- | | |_____________________________________| | | | | Encrypted data------------------------- | | | | | | | -XML-Envelope------------------ | | | | | | | | | | | --Signature------------- | | | | | | |______________________| | | | | | | | | | | | | --Signed-Payload-------- | | | | | | | | | | | | | | | XML-RPC Request | | | | | | | |______________________| | | | | | | | | | | | |_____________________________| | | | |_____________________________________| | | | |________________________________________________| @param string $data The XML that you want to parse @return bool True on success - false on failure
[ "Parse", "a", "block", "of", "XML", "text" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mnet/xmlrpc/xmlparser.php#L99-L135
216,305
moodle/moodle
mnet/xmlrpc/xmlparser.php
mnet_encxml_parser.start_element
function start_element($parser, $name, $attrs) { $this->tag_number++; $handler = 'discard_data'; switch(strtoupper($name)) { case 'DIGESTVALUE': $handler = 'parse_digest'; break; case 'SIGNATUREVALUE': $handler = 'parse_signature'; break; case 'OBJECT': $handler = 'parse_object'; break; case 'RETRIEVALMETHOD': $this->key_URI = $attrs['URI']; break; case 'TIMESTAMP': $handler = 'parse_timestamp'; break; case 'WWWROOT': $handler = 'parse_wwwroot'; break; case 'CIPHERVALUE': $this->cipher[$this->tag_number] = ''; $handler = 'parse_cipher'; break; case 'FAULT': $handler = 'parse_fault'; default: break; } xml_set_character_data_handler($this->parser, $handler); return true; }
php
function start_element($parser, $name, $attrs) { $this->tag_number++; $handler = 'discard_data'; switch(strtoupper($name)) { case 'DIGESTVALUE': $handler = 'parse_digest'; break; case 'SIGNATUREVALUE': $handler = 'parse_signature'; break; case 'OBJECT': $handler = 'parse_object'; break; case 'RETRIEVALMETHOD': $this->key_URI = $attrs['URI']; break; case 'TIMESTAMP': $handler = 'parse_timestamp'; break; case 'WWWROOT': $handler = 'parse_wwwroot'; break; case 'CIPHERVALUE': $this->cipher[$this->tag_number] = ''; $handler = 'parse_cipher'; break; case 'FAULT': $handler = 'parse_fault'; default: break; } xml_set_character_data_handler($this->parser, $handler); return true; }
[ "function", "start_element", "(", "$", "parser", ",", "$", "name", ",", "$", "attrs", ")", "{", "$", "this", "->", "tag_number", "++", ";", "$", "handler", "=", "'discard_data'", ";", "switch", "(", "strtoupper", "(", "$", "name", ")", ")", "{", "case", "'DIGESTVALUE'", ":", "$", "handler", "=", "'parse_digest'", ";", "break", ";", "case", "'SIGNATUREVALUE'", ":", "$", "handler", "=", "'parse_signature'", ";", "break", ";", "case", "'OBJECT'", ":", "$", "handler", "=", "'parse_object'", ";", "break", ";", "case", "'RETRIEVALMETHOD'", ":", "$", "this", "->", "key_URI", "=", "$", "attrs", "[", "'URI'", "]", ";", "break", ";", "case", "'TIMESTAMP'", ":", "$", "handler", "=", "'parse_timestamp'", ";", "break", ";", "case", "'WWWROOT'", ":", "$", "handler", "=", "'parse_wwwroot'", ";", "break", ";", "case", "'CIPHERVALUE'", ":", "$", "this", "->", "cipher", "[", "$", "this", "->", "tag_number", "]", "=", "''", ";", "$", "handler", "=", "'parse_cipher'", ";", "break", ";", "case", "'FAULT'", ":", "$", "handler", "=", "'parse_fault'", ";", "default", ":", "break", ";", "}", "xml_set_character_data_handler", "(", "$", "this", "->", "parser", ",", "$", "handler", ")", ";", "return", "true", ";", "}" ]
Set the character-data handler to the right function for each element For each tag (element) name, this function switches the character-data handler to the function that handles that element. Note that character data is referred to the handler in blocks of 1024 bytes. @param mixed $parser The XML parser @param string $name The name of the tag, e.g. method_call @param array $attrs The tag's attributes (if any exist). @return bool True
[ "Set", "the", "character", "-", "data", "handler", "to", "the", "right", "function", "for", "each", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mnet/xmlrpc/xmlparser.php#L156-L189
216,306
moodle/moodle
mnet/xmlrpc/xmlparser.php
mnet_encxml_parser.discard_data
function discard_data($parser, $data) { if (!$this->errorstarted) { // Not interested return true; } $data = trim($data); if (isset($this->errorstarted->faultstringstarted) && !empty($data)) { $this->remoteerror .= ', message: ' . $data; } else if (isset($this->errorstarted->faultcodestarted)) { $this->remoteerror = 'code: ' . $data; unset($this->errorstarted->faultcodestarted); } else if ($data == 'faultCode') { $this->errorstarted->faultcodestarted = true; } else if ($data == 'faultString') { $this->errorstarted->faultstringstarted = true; } return true; }
php
function discard_data($parser, $data) { if (!$this->errorstarted) { // Not interested return true; } $data = trim($data); if (isset($this->errorstarted->faultstringstarted) && !empty($data)) { $this->remoteerror .= ', message: ' . $data; } else if (isset($this->errorstarted->faultcodestarted)) { $this->remoteerror = 'code: ' . $data; unset($this->errorstarted->faultcodestarted); } else if ($data == 'faultCode') { $this->errorstarted->faultcodestarted = true; } else if ($data == 'faultString') { $this->errorstarted->faultstringstarted = true; } return true; }
[ "function", "discard_data", "(", "$", "parser", ",", "$", "data", ")", "{", "if", "(", "!", "$", "this", "->", "errorstarted", ")", "{", "// Not interested", "return", "true", ";", "}", "$", "data", "=", "trim", "(", "$", "data", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "errorstarted", "->", "faultstringstarted", ")", "&&", "!", "empty", "(", "$", "data", ")", ")", "{", "$", "this", "->", "remoteerror", ".=", "', message: '", ".", "$", "data", ";", "}", "else", "if", "(", "isset", "(", "$", "this", "->", "errorstarted", "->", "faultcodestarted", ")", ")", "{", "$", "this", "->", "remoteerror", "=", "'code: '", ".", "$", "data", ";", "unset", "(", "$", "this", "->", "errorstarted", "->", "faultcodestarted", ")", ";", "}", "else", "if", "(", "$", "data", "==", "'faultCode'", ")", "{", "$", "this", "->", "errorstarted", "->", "faultcodestarted", "=", "true", ";", "}", "else", "if", "(", "$", "data", "==", "'faultString'", ")", "{", "$", "this", "->", "errorstarted", "->", "faultstringstarted", "=", "true", ";", "}", "return", "true", ";", "}" ]
Discard the next chunk of character data This is used for tags that we're not interested in. @param mixed $parser The XML parser @param string $data The content of the current tag (1024 byte chunk) @return bool True
[ "Discard", "the", "next", "chunk", "of", "character", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mnet/xmlrpc/xmlparser.php#L281-L299
216,307
moodle/moodle
mod/feedback/classes/observer.php
mod_feedback_observer.course_content_deleted
public static function course_content_deleted(\core\event\course_content_deleted $event) { global $DB; // Delete all templates of given course. $DB->delete_records('feedback_template', array('course' => $event->objectid)); }
php
public static function course_content_deleted(\core\event\course_content_deleted $event) { global $DB; // Delete all templates of given course. $DB->delete_records('feedback_template', array('course' => $event->objectid)); }
[ "public", "static", "function", "course_content_deleted", "(", "\\", "core", "\\", "event", "\\", "course_content_deleted", "$", "event", ")", "{", "global", "$", "DB", ";", "// Delete all templates of given course.", "$", "DB", "->", "delete_records", "(", "'feedback_template'", ",", "array", "(", "'course'", "=>", "$", "event", "->", "objectid", ")", ")", ";", "}" ]
Observer for the even course_content_deleted - delete all course templates. @param \core\event\course_content_deleted $event
[ "Observer", "for", "the", "even", "course_content_deleted", "-", "delete", "all", "course", "templates", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/observer.php#L41-L45
216,308
moodle/moodle
filter/urltolink/filter.php
filter_urltolink.convert_urls_into_links
protected function convert_urls_into_links(&$text) { //I've added img tags to this list of tags to ignore. //See MDL-21168 for more info. A better way to ignore tags whether or not //they are escaped partially or completely would be desirable. For example: //<a href="blah"> //&lt;a href="blah"&gt; //&lt;a href="blah"> $filterignoretagsopen = array('<a\s[^>]+?>', '<span[^>]+?class="nolink"[^>]*?>'); $filterignoretagsclose = array('</a>', '</span>'); $ignoretags = []; filter_save_ignore_tags($text,$filterignoretagsopen,$filterignoretagsclose,$ignoretags); // Check if we support unicode modifiers in regular expressions. Cache it. // TODO: this check should be a environment requirement in Moodle 2.0, as far as unicode // chars are going to arrive to URLs officially really soon (2010?) // Original RFC regex from: http://www.bytemycode.com/snippets/snippet/796/ // Various ideas from: http://alanstorm.com/url_regex_explained // Unicode check, negative assertion and other bits from Moodle. static $unicoderegexp; if (!isset($unicoderegexp)) { $unicoderegexp = @preg_match('/\pL/u', 'a'); // This will fail silently, returning false, } // TODO MDL-21296 - use of unicode modifiers may cause a timeout $urlstart = '(?:http(s)?://|(?<!://)(www\.))'; $domainsegment = '(?:[\pLl0-9][\pLl0-9-]*[\pLl0-9]|[\pLl0-9])'; $numericip = '(?:(?:[0-9]{1,3}\.){3}[0-9]{1,3})'; $port = '(?::\d*)'; $pathchar = '(?:[\pL0-9\.!$&\'\(\)*+,;=_~:@-]|%[a-f0-9]{2})'; $path = "(?:/$pathchar*)*"; $querystring = '(?:\?(?:[\pL0-9\.!$&\'\(\)*+,;=_~:@/?-]|%[a-fA-F0-9]{2})*)'; $fragment = '(?:\#(?:[\pL0-9\.!$&\'\(\)*+,;=_~:@/?-]|%[a-fA-F0-9]{2})*)'; // Lookbehind assertions. // Is not HTML attribute or CSS URL property. Unfortunately legit text like "url(http://...)" will not be a link. $lookbehindend = "(?<![]),.;])"; $regex = "$urlstart((?:$domainsegment\.)+$domainsegment|$numericip)" . "($port?$path$querystring?$fragment?)$lookbehindend"; if ($unicoderegexp) { $regex = '#' . $regex . '#ui'; } else { $regex = '#' . preg_replace(array('\pLl', '\PL'), 'a-z', $regex) . '#i'; } // Locate any HTML tags. $matches = preg_split('/(<[^<|>]*>)/i', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); // Iterate through the tokenized text to handle chunks (html and content). foreach ($matches as $idx => $chunk) { // Nothing to do. We skip completely any html chunk. if (strpos(trim($chunk), '<') === 0) { continue; } // Nothing to do. We skip any content chunk having any of these attributes. if (preg_match('#(background=")|(action=")|(style="background)|(href=")|(src=")|(url [(])#', $chunk)) { continue; } // Arrived here, we want to process every word in this chunk. $text = $chunk; $words = explode(' ', $text); foreach ($words as $idx2 => $word) { // ReDoS protection. Stop processing if a word is too large. if (strlen($word) < 4096) { $words[$idx2] = preg_replace($regex, '<a href="http$1://$2$3$4" class="_blanktarget">$0</a>', $word); } } $text = implode(' ', $words); // Copy the result back to the array. $matches[$idx] = $text; } $text = implode('', $matches); if (!empty($ignoretags)) { $ignoretags = array_reverse($ignoretags); /// Reversed so "progressive" str_replace() will solve some nesting problems. $text = str_replace(array_keys($ignoretags),$ignoretags,$text); } if (get_config('filter_urltolink', 'embedimages')) { // now try to inject the images, this code was originally in the mediapluing filter // this may be useful only if somebody relies on the fact the links in FORMAT_MOODLE get converted // to URLs which in turn change to real images $search = '/<a href="([^"]+\.(jpg|png|gif))" class="_blanktarget">([^>]*)<\/a>/is'; $text = preg_replace_callback($search, 'filter_urltolink_img_callback', $text); } }
php
protected function convert_urls_into_links(&$text) { //I've added img tags to this list of tags to ignore. //See MDL-21168 for more info. A better way to ignore tags whether or not //they are escaped partially or completely would be desirable. For example: //<a href="blah"> //&lt;a href="blah"&gt; //&lt;a href="blah"> $filterignoretagsopen = array('<a\s[^>]+?>', '<span[^>]+?class="nolink"[^>]*?>'); $filterignoretagsclose = array('</a>', '</span>'); $ignoretags = []; filter_save_ignore_tags($text,$filterignoretagsopen,$filterignoretagsclose,$ignoretags); // Check if we support unicode modifiers in regular expressions. Cache it. // TODO: this check should be a environment requirement in Moodle 2.0, as far as unicode // chars are going to arrive to URLs officially really soon (2010?) // Original RFC regex from: http://www.bytemycode.com/snippets/snippet/796/ // Various ideas from: http://alanstorm.com/url_regex_explained // Unicode check, negative assertion and other bits from Moodle. static $unicoderegexp; if (!isset($unicoderegexp)) { $unicoderegexp = @preg_match('/\pL/u', 'a'); // This will fail silently, returning false, } // TODO MDL-21296 - use of unicode modifiers may cause a timeout $urlstart = '(?:http(s)?://|(?<!://)(www\.))'; $domainsegment = '(?:[\pLl0-9][\pLl0-9-]*[\pLl0-9]|[\pLl0-9])'; $numericip = '(?:(?:[0-9]{1,3}\.){3}[0-9]{1,3})'; $port = '(?::\d*)'; $pathchar = '(?:[\pL0-9\.!$&\'\(\)*+,;=_~:@-]|%[a-f0-9]{2})'; $path = "(?:/$pathchar*)*"; $querystring = '(?:\?(?:[\pL0-9\.!$&\'\(\)*+,;=_~:@/?-]|%[a-fA-F0-9]{2})*)'; $fragment = '(?:\#(?:[\pL0-9\.!$&\'\(\)*+,;=_~:@/?-]|%[a-fA-F0-9]{2})*)'; // Lookbehind assertions. // Is not HTML attribute or CSS URL property. Unfortunately legit text like "url(http://...)" will not be a link. $lookbehindend = "(?<![]),.;])"; $regex = "$urlstart((?:$domainsegment\.)+$domainsegment|$numericip)" . "($port?$path$querystring?$fragment?)$lookbehindend"; if ($unicoderegexp) { $regex = '#' . $regex . '#ui'; } else { $regex = '#' . preg_replace(array('\pLl', '\PL'), 'a-z', $regex) . '#i'; } // Locate any HTML tags. $matches = preg_split('/(<[^<|>]*>)/i', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); // Iterate through the tokenized text to handle chunks (html and content). foreach ($matches as $idx => $chunk) { // Nothing to do. We skip completely any html chunk. if (strpos(trim($chunk), '<') === 0) { continue; } // Nothing to do. We skip any content chunk having any of these attributes. if (preg_match('#(background=")|(action=")|(style="background)|(href=")|(src=")|(url [(])#', $chunk)) { continue; } // Arrived here, we want to process every word in this chunk. $text = $chunk; $words = explode(' ', $text); foreach ($words as $idx2 => $word) { // ReDoS protection. Stop processing if a word is too large. if (strlen($word) < 4096) { $words[$idx2] = preg_replace($regex, '<a href="http$1://$2$3$4" class="_blanktarget">$0</a>', $word); } } $text = implode(' ', $words); // Copy the result back to the array. $matches[$idx] = $text; } $text = implode('', $matches); if (!empty($ignoretags)) { $ignoretags = array_reverse($ignoretags); /// Reversed so "progressive" str_replace() will solve some nesting problems. $text = str_replace(array_keys($ignoretags),$ignoretags,$text); } if (get_config('filter_urltolink', 'embedimages')) { // now try to inject the images, this code was originally in the mediapluing filter // this may be useful only if somebody relies on the fact the links in FORMAT_MOODLE get converted // to URLs which in turn change to real images $search = '/<a href="([^"]+\.(jpg|png|gif))" class="_blanktarget">([^>]*)<\/a>/is'; $text = preg_replace_callback($search, 'filter_urltolink_img_callback', $text); } }
[ "protected", "function", "convert_urls_into_links", "(", "&", "$", "text", ")", "{", "//I've added img tags to this list of tags to ignore.", "//See MDL-21168 for more info. A better way to ignore tags whether or not", "//they are escaped partially or completely would be desirable. For example:", "//<a href=\"blah\">", "//&lt;a href=\"blah\"&gt;", "//&lt;a href=\"blah\">", "$", "filterignoretagsopen", "=", "array", "(", "'<a\\s[^>]+?>'", ",", "'<span[^>]+?class=\"nolink\"[^>]*?>'", ")", ";", "$", "filterignoretagsclose", "=", "array", "(", "'</a>'", ",", "'</span>'", ")", ";", "$", "ignoretags", "=", "[", "]", ";", "filter_save_ignore_tags", "(", "$", "text", ",", "$", "filterignoretagsopen", ",", "$", "filterignoretagsclose", ",", "$", "ignoretags", ")", ";", "// Check if we support unicode modifiers in regular expressions. Cache it.", "// TODO: this check should be a environment requirement in Moodle 2.0, as far as unicode", "// chars are going to arrive to URLs officially really soon (2010?)", "// Original RFC regex from: http://www.bytemycode.com/snippets/snippet/796/", "// Various ideas from: http://alanstorm.com/url_regex_explained", "// Unicode check, negative assertion and other bits from Moodle.", "static", "$", "unicoderegexp", ";", "if", "(", "!", "isset", "(", "$", "unicoderegexp", ")", ")", "{", "$", "unicoderegexp", "=", "@", "preg_match", "(", "'/\\pL/u'", ",", "'a'", ")", ";", "// This will fail silently, returning false,", "}", "// TODO MDL-21296 - use of unicode modifiers may cause a timeout", "$", "urlstart", "=", "'(?:http(s)?://|(?<!://)(www\\.))'", ";", "$", "domainsegment", "=", "'(?:[\\pLl0-9][\\pLl0-9-]*[\\pLl0-9]|[\\pLl0-9])'", ";", "$", "numericip", "=", "'(?:(?:[0-9]{1,3}\\.){3}[0-9]{1,3})'", ";", "$", "port", "=", "'(?::\\d*)'", ";", "$", "pathchar", "=", "'(?:[\\pL0-9\\.!$&\\'\\(\\)*+,;=_~:@-]|%[a-f0-9]{2})'", ";", "$", "path", "=", "\"(?:/$pathchar*)*\"", ";", "$", "querystring", "=", "'(?:\\?(?:[\\pL0-9\\.!$&\\'\\(\\)*+,;=_~:@/?-]|%[a-fA-F0-9]{2})*)'", ";", "$", "fragment", "=", "'(?:\\#(?:[\\pL0-9\\.!$&\\'\\(\\)*+,;=_~:@/?-]|%[a-fA-F0-9]{2})*)'", ";", "// Lookbehind assertions.", "// Is not HTML attribute or CSS URL property. Unfortunately legit text like \"url(http://...)\" will not be a link.", "$", "lookbehindend", "=", "\"(?<![]),.;])\"", ";", "$", "regex", "=", "\"$urlstart((?:$domainsegment\\.)+$domainsegment|$numericip)\"", ".", "\"($port?$path$querystring?$fragment?)$lookbehindend\"", ";", "if", "(", "$", "unicoderegexp", ")", "{", "$", "regex", "=", "'#'", ".", "$", "regex", ".", "'#ui'", ";", "}", "else", "{", "$", "regex", "=", "'#'", ".", "preg_replace", "(", "array", "(", "'\\pLl'", ",", "'\\PL'", ")", ",", "'a-z'", ",", "$", "regex", ")", ".", "'#i'", ";", "}", "// Locate any HTML tags.", "$", "matches", "=", "preg_split", "(", "'/(<[^<|>]*>)/i'", ",", "$", "text", ",", "-", "1", ",", "PREG_SPLIT_NO_EMPTY", "|", "PREG_SPLIT_DELIM_CAPTURE", ")", ";", "// Iterate through the tokenized text to handle chunks (html and content).", "foreach", "(", "$", "matches", "as", "$", "idx", "=>", "$", "chunk", ")", "{", "// Nothing to do. We skip completely any html chunk.", "if", "(", "strpos", "(", "trim", "(", "$", "chunk", ")", ",", "'<'", ")", "===", "0", ")", "{", "continue", ";", "}", "// Nothing to do. We skip any content chunk having any of these attributes.", "if", "(", "preg_match", "(", "'#(background=\")|(action=\")|(style=\"background)|(href=\")|(src=\")|(url [(])#'", ",", "$", "chunk", ")", ")", "{", "continue", ";", "}", "// Arrived here, we want to process every word in this chunk.", "$", "text", "=", "$", "chunk", ";", "$", "words", "=", "explode", "(", "' '", ",", "$", "text", ")", ";", "foreach", "(", "$", "words", "as", "$", "idx2", "=>", "$", "word", ")", "{", "// ReDoS protection. Stop processing if a word is too large.", "if", "(", "strlen", "(", "$", "word", ")", "<", "4096", ")", "{", "$", "words", "[", "$", "idx2", "]", "=", "preg_replace", "(", "$", "regex", ",", "'<a href=\"http$1://$2$3$4\" class=\"_blanktarget\">$0</a>'", ",", "$", "word", ")", ";", "}", "}", "$", "text", "=", "implode", "(", "' '", ",", "$", "words", ")", ";", "// Copy the result back to the array.", "$", "matches", "[", "$", "idx", "]", "=", "$", "text", ";", "}", "$", "text", "=", "implode", "(", "''", ",", "$", "matches", ")", ";", "if", "(", "!", "empty", "(", "$", "ignoretags", ")", ")", "{", "$", "ignoretags", "=", "array_reverse", "(", "$", "ignoretags", ")", ";", "/// Reversed so \"progressive\" str_replace() will solve some nesting problems.", "$", "text", "=", "str_replace", "(", "array_keys", "(", "$", "ignoretags", ")", ",", "$", "ignoretags", ",", "$", "text", ")", ";", "}", "if", "(", "get_config", "(", "'filter_urltolink'", ",", "'embedimages'", ")", ")", "{", "// now try to inject the images, this code was originally in the mediapluing filter", "// this may be useful only if somebody relies on the fact the links in FORMAT_MOODLE get converted", "// to URLs which in turn change to real images", "$", "search", "=", "'/<a href=\"([^\"]+\\.(jpg|png|gif))\" class=\"_blanktarget\">([^>]*)<\\/a>/is'", ";", "$", "text", "=", "preg_replace_callback", "(", "$", "search", ",", "'filter_urltolink_img_callback'", ",", "$", "text", ")", ";", "}", "}" ]
Given some text this function converts any URLs it finds into HTML links @param string $text Passed in by reference. The string to be searched for urls.
[ "Given", "some", "text", "this", "function", "converts", "any", "URLs", "it", "finds", "into", "HTML", "links" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/filter/urltolink/filter.php#L69-L159
216,309
moodle/moodle
grade/grading/form/rubric/renderer.php
gradingform_rubric_renderer.display_instances
public function display_instances($instances, $defaultcontent, $cangrade) { $return = ''; if (sizeof($instances)) { $return .= html_writer::start_tag('div', array('class' => 'advancedgrade')); $idx = 0; foreach ($instances as $instance) { $return .= $this->display_instance($instance, $idx++, $cangrade); } $return .= html_writer::end_tag('div'); } return $return. $defaultcontent; }
php
public function display_instances($instances, $defaultcontent, $cangrade) { $return = ''; if (sizeof($instances)) { $return .= html_writer::start_tag('div', array('class' => 'advancedgrade')); $idx = 0; foreach ($instances as $instance) { $return .= $this->display_instance($instance, $idx++, $cangrade); } $return .= html_writer::end_tag('div'); } return $return. $defaultcontent; }
[ "public", "function", "display_instances", "(", "$", "instances", ",", "$", "defaultcontent", ",", "$", "cangrade", ")", "{", "$", "return", "=", "''", ";", "if", "(", "sizeof", "(", "$", "instances", ")", ")", "{", "$", "return", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'advancedgrade'", ")", ")", ";", "$", "idx", "=", "0", ";", "foreach", "(", "$", "instances", "as", "$", "instance", ")", "{", "$", "return", ".=", "$", "this", "->", "display_instance", "(", "$", "instance", ",", "$", "idx", "++", ",", "$", "cangrade", ")", ";", "}", "$", "return", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "}", "return", "$", "return", ".", "$", "defaultcontent", ";", "}" ]
Displays for the student the list of instances or default content if no instances found @param array $instances array of objects of type gradingform_rubric_instance @param string $defaultcontent default string that would be displayed without advanced grading @param boolean $cangrade whether current user has capability to grade in this context @return string
[ "Displays", "for", "the", "student", "the", "list", "of", "instances", "or", "default", "content", "if", "no", "instances", "found" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/rubric/renderer.php#L564-L575
216,310
moodle/moodle
grade/grading/form/rubric/renderer.php
gradingform_rubric_renderer.display_rubric_mapping_explained
public function display_rubric_mapping_explained($scores) { $html = ''; if (!$scores) { return $html; } if ($scores['minscore'] <> 0) { $html .= $this->output->notification(get_string('zerolevelsabsent', 'gradingform_rubric'), 'error'); } $html .= $this->output->notification(get_string('rubricmappingexplained', 'gradingform_rubric', (object)$scores), 'info'); return $html; }
php
public function display_rubric_mapping_explained($scores) { $html = ''; if (!$scores) { return $html; } if ($scores['minscore'] <> 0) { $html .= $this->output->notification(get_string('zerolevelsabsent', 'gradingform_rubric'), 'error'); } $html .= $this->output->notification(get_string('rubricmappingexplained', 'gradingform_rubric', (object)$scores), 'info'); return $html; }
[ "public", "function", "display_rubric_mapping_explained", "(", "$", "scores", ")", "{", "$", "html", "=", "''", ";", "if", "(", "!", "$", "scores", ")", "{", "return", "$", "html", ";", "}", "if", "(", "$", "scores", "[", "'minscore'", "]", "<>", "0", ")", "{", "$", "html", ".=", "$", "this", "->", "output", "->", "notification", "(", "get_string", "(", "'zerolevelsabsent'", ",", "'gradingform_rubric'", ")", ",", "'error'", ")", ";", "}", "$", "html", ".=", "$", "this", "->", "output", "->", "notification", "(", "get_string", "(", "'rubricmappingexplained'", ",", "'gradingform_rubric'", ",", "(", "object", ")", "$", "scores", ")", ",", "'info'", ")", ";", "return", "$", "html", ";", "}" ]
Generates and returns HTML code to display information box about how rubric score is converted to the grade @param array $scores @return string
[ "Generates", "and", "returns", "HTML", "code", "to", "display", "information", "box", "about", "how", "rubric", "score", "is", "converted", "to", "the", "grade" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/rubric/renderer.php#L634-L644
216,311
moodle/moodle
admin/tool/dataprivacy/classes/external.php
external.cancel_data_request
public static function cancel_data_request($requestid) { global $USER; $warnings = []; $params = external_api::validate_parameters(self::cancel_data_request_parameters(), [ 'requestid' => $requestid ]); $requestid = $params['requestid']; // Validate context and access to manage the registry. $context = context_user::instance($USER->id); self::validate_context($context); // Ensure the request exists. $select = 'id = :id AND (userid = :userid OR requestedby = :requestedby)'; $params = ['id' => $requestid, 'userid' => $USER->id, 'requestedby' => $USER->id]; $requests = data_request::get_records_select($select, $params); $requestexists = count($requests) === 1; $result = false; if ($requestexists) { $request = reset($requests); $datasubject = $request->get('userid'); if ($datasubject !== $USER->id) { // The user is not the subject. Check that they can cancel this request. if (!api::can_create_data_request_for_user($datasubject)) { $forusercontext = \context_user::instance($datasubject); throw new required_capability_exception($forusercontext, 'tool/dataprivacy:makedatarequestsforchildren', 'nopermissions', ''); } } // TODO: Do we want a request to be non-cancellable past a certain point? E.g. When it's already approved/processing. $result = api::update_request_status($requestid, api::DATAREQUEST_STATUS_CANCELLED); } else { $warnings[] = [ 'item' => $requestid, 'warningcode' => 'errorrequestnotfound', 'message' => get_string('errorrequestnotfound', 'tool_dataprivacy') ]; } return [ 'result' => $result, 'warnings' => $warnings ]; }
php
public static function cancel_data_request($requestid) { global $USER; $warnings = []; $params = external_api::validate_parameters(self::cancel_data_request_parameters(), [ 'requestid' => $requestid ]); $requestid = $params['requestid']; // Validate context and access to manage the registry. $context = context_user::instance($USER->id); self::validate_context($context); // Ensure the request exists. $select = 'id = :id AND (userid = :userid OR requestedby = :requestedby)'; $params = ['id' => $requestid, 'userid' => $USER->id, 'requestedby' => $USER->id]; $requests = data_request::get_records_select($select, $params); $requestexists = count($requests) === 1; $result = false; if ($requestexists) { $request = reset($requests); $datasubject = $request->get('userid'); if ($datasubject !== $USER->id) { // The user is not the subject. Check that they can cancel this request. if (!api::can_create_data_request_for_user($datasubject)) { $forusercontext = \context_user::instance($datasubject); throw new required_capability_exception($forusercontext, 'tool/dataprivacy:makedatarequestsforchildren', 'nopermissions', ''); } } // TODO: Do we want a request to be non-cancellable past a certain point? E.g. When it's already approved/processing. $result = api::update_request_status($requestid, api::DATAREQUEST_STATUS_CANCELLED); } else { $warnings[] = [ 'item' => $requestid, 'warningcode' => 'errorrequestnotfound', 'message' => get_string('errorrequestnotfound', 'tool_dataprivacy') ]; } return [ 'result' => $result, 'warnings' => $warnings ]; }
[ "public", "static", "function", "cancel_data_request", "(", "$", "requestid", ")", "{", "global", "$", "USER", ";", "$", "warnings", "=", "[", "]", ";", "$", "params", "=", "external_api", "::", "validate_parameters", "(", "self", "::", "cancel_data_request_parameters", "(", ")", ",", "[", "'requestid'", "=>", "$", "requestid", "]", ")", ";", "$", "requestid", "=", "$", "params", "[", "'requestid'", "]", ";", "// Validate context and access to manage the registry.", "$", "context", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "// Ensure the request exists.", "$", "select", "=", "'id = :id AND (userid = :userid OR requestedby = :requestedby)'", ";", "$", "params", "=", "[", "'id'", "=>", "$", "requestid", ",", "'userid'", "=>", "$", "USER", "->", "id", ",", "'requestedby'", "=>", "$", "USER", "->", "id", "]", ";", "$", "requests", "=", "data_request", "::", "get_records_select", "(", "$", "select", ",", "$", "params", ")", ";", "$", "requestexists", "=", "count", "(", "$", "requests", ")", "===", "1", ";", "$", "result", "=", "false", ";", "if", "(", "$", "requestexists", ")", "{", "$", "request", "=", "reset", "(", "$", "requests", ")", ";", "$", "datasubject", "=", "$", "request", "->", "get", "(", "'userid'", ")", ";", "if", "(", "$", "datasubject", "!==", "$", "USER", "->", "id", ")", "{", "// The user is not the subject. Check that they can cancel this request.", "if", "(", "!", "api", "::", "can_create_data_request_for_user", "(", "$", "datasubject", ")", ")", "{", "$", "forusercontext", "=", "\\", "context_user", "::", "instance", "(", "$", "datasubject", ")", ";", "throw", "new", "required_capability_exception", "(", "$", "forusercontext", ",", "'tool/dataprivacy:makedatarequestsforchildren'", ",", "'nopermissions'", ",", "''", ")", ";", "}", "}", "// TODO: Do we want a request to be non-cancellable past a certain point? E.g. When it's already approved/processing.", "$", "result", "=", "api", "::", "update_request_status", "(", "$", "requestid", ",", "api", "::", "DATAREQUEST_STATUS_CANCELLED", ")", ";", "}", "else", "{", "$", "warnings", "[", "]", "=", "[", "'item'", "=>", "$", "requestid", ",", "'warningcode'", "=>", "'errorrequestnotfound'", ",", "'message'", "=>", "get_string", "(", "'errorrequestnotfound'", ",", "'tool_dataprivacy'", ")", "]", ";", "}", "return", "[", "'result'", "=>", "$", "result", ",", "'warnings'", "=>", "$", "warnings", "]", ";", "}" ]
Cancel a data request. @since Moodle 3.5 @param int $requestid The request ID. @return array @throws invalid_persistent_exception @throws coding_exception @throws invalid_parameter_exception @throws restricted_context_exception
[ "Cancel", "a", "data", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/external.php#L86-L133
216,312
moodle/moodle
admin/tool/dataprivacy/classes/external.php
external.contact_dpo
public static function contact_dpo($message) { global $USER; $warnings = []; $params = external_api::validate_parameters(self::contact_dpo_parameters(), [ 'message' => $message ]); $message = $params['message']; // Validate context. $userid = $USER->id; $context = context_user::instance($userid); self::validate_context($context); // Lodge the request. $datarequest = new data_request(); // The user the request is being made for. $datarequest->set('userid', $userid); // The user making the request. $datarequest->set('requestedby', $userid); // Set status. $datarequest->set('status', api::DATAREQUEST_STATUS_PENDING); // Set request type. $datarequest->set('type', api::DATAREQUEST_TYPE_OTHERS); // Set request comments. $datarequest->set('comments', $message); // Store subject access request. $datarequest->create(); // Get the list of the site Data Protection Officers. $dpos = api::get_site_dpos(); // Email the data request to the Data Protection Officer(s)/Admin(s). $result = true; foreach ($dpos as $dpo) { $sendresult = api::notify_dpo($dpo, $datarequest); if (!$sendresult) { $result = false; $warnings[] = [ 'item' => $dpo->id, 'warningcode' => 'errorsendingtodpo', 'message' => get_string('errorsendingmessagetodpo', 'tool_dataprivacy') ]; } } return [ 'result' => $result, 'warnings' => $warnings ]; }
php
public static function contact_dpo($message) { global $USER; $warnings = []; $params = external_api::validate_parameters(self::contact_dpo_parameters(), [ 'message' => $message ]); $message = $params['message']; // Validate context. $userid = $USER->id; $context = context_user::instance($userid); self::validate_context($context); // Lodge the request. $datarequest = new data_request(); // The user the request is being made for. $datarequest->set('userid', $userid); // The user making the request. $datarequest->set('requestedby', $userid); // Set status. $datarequest->set('status', api::DATAREQUEST_STATUS_PENDING); // Set request type. $datarequest->set('type', api::DATAREQUEST_TYPE_OTHERS); // Set request comments. $datarequest->set('comments', $message); // Store subject access request. $datarequest->create(); // Get the list of the site Data Protection Officers. $dpos = api::get_site_dpos(); // Email the data request to the Data Protection Officer(s)/Admin(s). $result = true; foreach ($dpos as $dpo) { $sendresult = api::notify_dpo($dpo, $datarequest); if (!$sendresult) { $result = false; $warnings[] = [ 'item' => $dpo->id, 'warningcode' => 'errorsendingtodpo', 'message' => get_string('errorsendingmessagetodpo', 'tool_dataprivacy') ]; } } return [ 'result' => $result, 'warnings' => $warnings ]; }
[ "public", "static", "function", "contact_dpo", "(", "$", "message", ")", "{", "global", "$", "USER", ";", "$", "warnings", "=", "[", "]", ";", "$", "params", "=", "external_api", "::", "validate_parameters", "(", "self", "::", "contact_dpo_parameters", "(", ")", ",", "[", "'message'", "=>", "$", "message", "]", ")", ";", "$", "message", "=", "$", "params", "[", "'message'", "]", ";", "// Validate context.", "$", "userid", "=", "$", "USER", "->", "id", ";", "$", "context", "=", "context_user", "::", "instance", "(", "$", "userid", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "// Lodge the request.", "$", "datarequest", "=", "new", "data_request", "(", ")", ";", "// The user the request is being made for.", "$", "datarequest", "->", "set", "(", "'userid'", ",", "$", "userid", ")", ";", "// The user making the request.", "$", "datarequest", "->", "set", "(", "'requestedby'", ",", "$", "userid", ")", ";", "// Set status.", "$", "datarequest", "->", "set", "(", "'status'", ",", "api", "::", "DATAREQUEST_STATUS_PENDING", ")", ";", "// Set request type.", "$", "datarequest", "->", "set", "(", "'type'", ",", "api", "::", "DATAREQUEST_TYPE_OTHERS", ")", ";", "// Set request comments.", "$", "datarequest", "->", "set", "(", "'comments'", ",", "$", "message", ")", ";", "// Store subject access request.", "$", "datarequest", "->", "create", "(", ")", ";", "// Get the list of the site Data Protection Officers.", "$", "dpos", "=", "api", "::", "get_site_dpos", "(", ")", ";", "// Email the data request to the Data Protection Officer(s)/Admin(s).", "$", "result", "=", "true", ";", "foreach", "(", "$", "dpos", "as", "$", "dpo", ")", "{", "$", "sendresult", "=", "api", "::", "notify_dpo", "(", "$", "dpo", ",", "$", "datarequest", ")", ";", "if", "(", "!", "$", "sendresult", ")", "{", "$", "result", "=", "false", ";", "$", "warnings", "[", "]", "=", "[", "'item'", "=>", "$", "dpo", "->", "id", ",", "'warningcode'", "=>", "'errorsendingtodpo'", ",", "'message'", "=>", "get_string", "(", "'errorsendingmessagetodpo'", ",", "'tool_dataprivacy'", ")", "]", ";", "}", "}", "return", "[", "'result'", "=>", "$", "result", ",", "'warnings'", "=>", "$", "warnings", "]", ";", "}" ]
Make a general enquiry to a DPO. @since Moodle 3.5 @param string $message The message to be sent to the DPO. @return array @throws coding_exception @throws invalid_parameter_exception @throws invalid_persistent_exception @throws restricted_context_exception @throws dml_exception @throws moodle_exception
[ "Make", "a", "general", "enquiry", "to", "a", "DPO", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/external.php#L173-L224
216,313
moodle/moodle
admin/tool/dataprivacy/classes/external.php
external.mark_complete
public static function mark_complete($requestid) { global $USER; $warnings = []; $params = external_api::validate_parameters(self::mark_complete_parameters(), [ 'requestid' => $requestid, ]); $requestid = $params['requestid']; // Validate context and access to manage the registry. $context = context_system::instance(); self::validate_context($context); api::check_can_manage_data_registry(); $message = get_string('markedcomplete', 'tool_dataprivacy'); // Update the data request record. if ($result = api::update_request_status($requestid, api::DATAREQUEST_STATUS_COMPLETE, $USER->id, $message)) { // Add notification in the session to be shown when the page is reloaded on the JS side. notification::success(get_string('requestmarkedcomplete', 'tool_dataprivacy')); } return [ 'result' => $result, 'warnings' => $warnings ]; }
php
public static function mark_complete($requestid) { global $USER; $warnings = []; $params = external_api::validate_parameters(self::mark_complete_parameters(), [ 'requestid' => $requestid, ]); $requestid = $params['requestid']; // Validate context and access to manage the registry. $context = context_system::instance(); self::validate_context($context); api::check_can_manage_data_registry(); $message = get_string('markedcomplete', 'tool_dataprivacy'); // Update the data request record. if ($result = api::update_request_status($requestid, api::DATAREQUEST_STATUS_COMPLETE, $USER->id, $message)) { // Add notification in the session to be shown when the page is reloaded on the JS side. notification::success(get_string('requestmarkedcomplete', 'tool_dataprivacy')); } return [ 'result' => $result, 'warnings' => $warnings ]; }
[ "public", "static", "function", "mark_complete", "(", "$", "requestid", ")", "{", "global", "$", "USER", ";", "$", "warnings", "=", "[", "]", ";", "$", "params", "=", "external_api", "::", "validate_parameters", "(", "self", "::", "mark_complete_parameters", "(", ")", ",", "[", "'requestid'", "=>", "$", "requestid", ",", "]", ")", ";", "$", "requestid", "=", "$", "params", "[", "'requestid'", "]", ";", "// Validate context and access to manage the registry.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "api", "::", "check_can_manage_data_registry", "(", ")", ";", "$", "message", "=", "get_string", "(", "'markedcomplete'", ",", "'tool_dataprivacy'", ")", ";", "// Update the data request record.", "if", "(", "$", "result", "=", "api", "::", "update_request_status", "(", "$", "requestid", ",", "api", "::", "DATAREQUEST_STATUS_COMPLETE", ",", "$", "USER", "->", "id", ",", "$", "message", ")", ")", "{", "// Add notification in the session to be shown when the page is reloaded on the JS side.", "notification", "::", "success", "(", "get_string", "(", "'requestmarkedcomplete'", ",", "'tool_dataprivacy'", ")", ")", ";", "}", "return", "[", "'result'", "=>", "$", "result", ",", "'warnings'", "=>", "$", "warnings", "]", ";", "}" ]
Mark a user's general enquiry's status as complete. @since Moodle 3.5.2 @param int $requestid The request ID of the general enquiry. @return array @throws coding_exception @throws invalid_parameter_exception @throws invalid_persistent_exception @throws restricted_context_exception @throws dml_exception @throws moodle_exception
[ "Mark", "a", "user", "s", "general", "enquiry", "s", "status", "as", "complete", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/external.php#L264-L289
216,314
moodle/moodle
admin/tool/dataprivacy/classes/external.php
external.deny_data_request
public static function deny_data_request($requestid) { $warnings = []; $params = external_api::validate_parameters(self::deny_data_request_parameters(), [ 'requestid' => $requestid ]); $requestid = $params['requestid']; // Validate context. $context = context_system::instance(); self::validate_context($context); require_capability('tool/dataprivacy:managedatarequests', $context); // Ensure the request exists. $requestexists = data_request::record_exists($requestid); $result = false; if ($requestexists) { $result = api::deny_data_request($requestid); // Add notification in the session to be shown when the page is reloaded on the JS side. notification::success(get_string('requestdenied', 'tool_dataprivacy')); } else { $warnings[] = [ 'item' => $requestid, 'warningcode' => 'errorrequestnotfound', 'message' => get_string('errorrequestnotfound', 'tool_dataprivacy') ]; } return [ 'result' => $result, 'warnings' => $warnings ]; }
php
public static function deny_data_request($requestid) { $warnings = []; $params = external_api::validate_parameters(self::deny_data_request_parameters(), [ 'requestid' => $requestid ]); $requestid = $params['requestid']; // Validate context. $context = context_system::instance(); self::validate_context($context); require_capability('tool/dataprivacy:managedatarequests', $context); // Ensure the request exists. $requestexists = data_request::record_exists($requestid); $result = false; if ($requestexists) { $result = api::deny_data_request($requestid); // Add notification in the session to be shown when the page is reloaded on the JS side. notification::success(get_string('requestdenied', 'tool_dataprivacy')); } else { $warnings[] = [ 'item' => $requestid, 'warningcode' => 'errorrequestnotfound', 'message' => get_string('errorrequestnotfound', 'tool_dataprivacy') ]; } return [ 'result' => $result, 'warnings' => $warnings ]; }
[ "public", "static", "function", "deny_data_request", "(", "$", "requestid", ")", "{", "$", "warnings", "=", "[", "]", ";", "$", "params", "=", "external_api", "::", "validate_parameters", "(", "self", "::", "deny_data_request_parameters", "(", ")", ",", "[", "'requestid'", "=>", "$", "requestid", "]", ")", ";", "$", "requestid", "=", "$", "params", "[", "'requestid'", "]", ";", "// Validate context.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "require_capability", "(", "'tool/dataprivacy:managedatarequests'", ",", "$", "context", ")", ";", "// Ensure the request exists.", "$", "requestexists", "=", "data_request", "::", "record_exists", "(", "$", "requestid", ")", ";", "$", "result", "=", "false", ";", "if", "(", "$", "requestexists", ")", "{", "$", "result", "=", "api", "::", "deny_data_request", "(", "$", "requestid", ")", ";", "// Add notification in the session to be shown when the page is reloaded on the JS side.", "notification", "::", "success", "(", "get_string", "(", "'requestdenied'", ",", "'tool_dataprivacy'", ")", ")", ";", "}", "else", "{", "$", "warnings", "[", "]", "=", "[", "'item'", "=>", "$", "requestid", ",", "'warningcode'", "=>", "'errorrequestnotfound'", ",", "'message'", "=>", "get_string", "(", "'errorrequestnotfound'", ",", "'tool_dataprivacy'", ")", "]", ";", "}", "return", "[", "'result'", "=>", "$", "result", ",", "'warnings'", "=>", "$", "warnings", "]", ";", "}" ]
Deny a data request. @since Moodle 3.5 @param int $requestid The request ID. @return array @throws coding_exception @throws dml_exception @throws invalid_parameter_exception @throws restricted_context_exception @throws moodle_exception
[ "Deny", "a", "data", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/external.php#L541-L574
216,315
moodle/moodle
admin/tool/dataprivacy/classes/external.php
external.bulk_deny_data_requests
public static function bulk_deny_data_requests($requestids) { $warnings = []; $result = false; $params = external_api::validate_parameters(self::bulk_deny_data_requests_parameters(), [ 'requestids' => $requestids ]); $requestids = $params['requestids']; // Validate context. $context = context_system::instance(); self::validate_context($context); require_capability('tool/dataprivacy:managedatarequests', $context); foreach ($requestids as $requestid) { // Ensure the request exists. $requestexists = data_request::record_exists($requestid); if ($requestexists) { api::deny_data_request($requestid); } else { $warnings[] = [ 'item' => $requestid, 'warningcode' => 'errorrequestnotfound', 'message' => get_string('errorrequestnotfound', 'tool_dataprivacy') ]; } } if (empty($warnings)) { $result = true; // Add notification in the session to be shown when the page is reloaded on the JS side. notification::success(get_string('requestsdenied', 'tool_dataprivacy')); } return [ 'result' => $result, 'warnings' => $warnings ]; }
php
public static function bulk_deny_data_requests($requestids) { $warnings = []; $result = false; $params = external_api::validate_parameters(self::bulk_deny_data_requests_parameters(), [ 'requestids' => $requestids ]); $requestids = $params['requestids']; // Validate context. $context = context_system::instance(); self::validate_context($context); require_capability('tool/dataprivacy:managedatarequests', $context); foreach ($requestids as $requestid) { // Ensure the request exists. $requestexists = data_request::record_exists($requestid); if ($requestexists) { api::deny_data_request($requestid); } else { $warnings[] = [ 'item' => $requestid, 'warningcode' => 'errorrequestnotfound', 'message' => get_string('errorrequestnotfound', 'tool_dataprivacy') ]; } } if (empty($warnings)) { $result = true; // Add notification in the session to be shown when the page is reloaded on the JS side. notification::success(get_string('requestsdenied', 'tool_dataprivacy')); } return [ 'result' => $result, 'warnings' => $warnings ]; }
[ "public", "static", "function", "bulk_deny_data_requests", "(", "$", "requestids", ")", "{", "$", "warnings", "=", "[", "]", ";", "$", "result", "=", "false", ";", "$", "params", "=", "external_api", "::", "validate_parameters", "(", "self", "::", "bulk_deny_data_requests_parameters", "(", ")", ",", "[", "'requestids'", "=>", "$", "requestids", "]", ")", ";", "$", "requestids", "=", "$", "params", "[", "'requestids'", "]", ";", "// Validate context.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "require_capability", "(", "'tool/dataprivacy:managedatarequests'", ",", "$", "context", ")", ";", "foreach", "(", "$", "requestids", "as", "$", "requestid", ")", "{", "// Ensure the request exists.", "$", "requestexists", "=", "data_request", "::", "record_exists", "(", "$", "requestid", ")", ";", "if", "(", "$", "requestexists", ")", "{", "api", "::", "deny_data_request", "(", "$", "requestid", ")", ";", "}", "else", "{", "$", "warnings", "[", "]", "=", "[", "'item'", "=>", "$", "requestid", ",", "'warningcode'", "=>", "'errorrequestnotfound'", ",", "'message'", "=>", "get_string", "(", "'errorrequestnotfound'", ",", "'tool_dataprivacy'", ")", "]", ";", "}", "}", "if", "(", "empty", "(", "$", "warnings", ")", ")", "{", "$", "result", "=", "true", ";", "// Add notification in the session to be shown when the page is reloaded on the JS side.", "notification", "::", "success", "(", "get_string", "(", "'requestsdenied'", ",", "'tool_dataprivacy'", ")", ")", ";", "}", "return", "[", "'result'", "=>", "$", "result", ",", "'warnings'", "=>", "$", "warnings", "]", ";", "}" ]
Bulk deny data requests. @since Moodle 3.5 @param array $requestids Array consisting of request ID's. @return array @throws coding_exception @throws dml_exception @throws invalid_parameter_exception @throws restricted_context_exception @throws moodle_exception
[ "Bulk", "deny", "data", "requests", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/external.php#L615-L653
216,316
moodle/moodle
admin/tool/dataprivacy/classes/external.php
external.create_purpose_form
public static function create_purpose_form($jsonformdata) { global $PAGE; $warnings = []; $params = external_api::validate_parameters(self::create_purpose_form_parameters(), [ 'jsonformdata' => $jsonformdata ]); // Validate context and access to manage the registry. self::validate_context(\context_system::instance()); api::check_can_manage_data_registry(); $serialiseddata = json_decode($params['jsonformdata']); $data = array(); parse_str($serialiseddata, $data); $purpose = new \tool_dataprivacy\purpose(0); $mform = new \tool_dataprivacy\form\purpose(null, ['persistent' => $purpose], 'post', '', null, true, $data); $validationerrors = true; if ($validateddata = $mform->get_data()) { $purpose = api::create_purpose($validateddata); $validationerrors = false; } else if ($errors = $mform->is_validated()) { throw new moodle_exception('generalerror'); } $exporter = new purpose_exporter($purpose, ['context' => \context_system::instance()]); return [ 'purpose' => $exporter->export($PAGE->get_renderer('core')), 'validationerrors' => $validationerrors, 'warnings' => $warnings ]; }
php
public static function create_purpose_form($jsonformdata) { global $PAGE; $warnings = []; $params = external_api::validate_parameters(self::create_purpose_form_parameters(), [ 'jsonformdata' => $jsonformdata ]); // Validate context and access to manage the registry. self::validate_context(\context_system::instance()); api::check_can_manage_data_registry(); $serialiseddata = json_decode($params['jsonformdata']); $data = array(); parse_str($serialiseddata, $data); $purpose = new \tool_dataprivacy\purpose(0); $mform = new \tool_dataprivacy\form\purpose(null, ['persistent' => $purpose], 'post', '', null, true, $data); $validationerrors = true; if ($validateddata = $mform->get_data()) { $purpose = api::create_purpose($validateddata); $validationerrors = false; } else if ($errors = $mform->is_validated()) { throw new moodle_exception('generalerror'); } $exporter = new purpose_exporter($purpose, ['context' => \context_system::instance()]); return [ 'purpose' => $exporter->export($PAGE->get_renderer('core')), 'validationerrors' => $validationerrors, 'warnings' => $warnings ]; }
[ "public", "static", "function", "create_purpose_form", "(", "$", "jsonformdata", ")", "{", "global", "$", "PAGE", ";", "$", "warnings", "=", "[", "]", ";", "$", "params", "=", "external_api", "::", "validate_parameters", "(", "self", "::", "create_purpose_form_parameters", "(", ")", ",", "[", "'jsonformdata'", "=>", "$", "jsonformdata", "]", ")", ";", "// Validate context and access to manage the registry.", "self", "::", "validate_context", "(", "\\", "context_system", "::", "instance", "(", ")", ")", ";", "api", "::", "check_can_manage_data_registry", "(", ")", ";", "$", "serialiseddata", "=", "json_decode", "(", "$", "params", "[", "'jsonformdata'", "]", ")", ";", "$", "data", "=", "array", "(", ")", ";", "parse_str", "(", "$", "serialiseddata", ",", "$", "data", ")", ";", "$", "purpose", "=", "new", "\\", "tool_dataprivacy", "\\", "purpose", "(", "0", ")", ";", "$", "mform", "=", "new", "\\", "tool_dataprivacy", "\\", "form", "\\", "purpose", "(", "null", ",", "[", "'persistent'", "=>", "$", "purpose", "]", ",", "'post'", ",", "''", ",", "null", ",", "true", ",", "$", "data", ")", ";", "$", "validationerrors", "=", "true", ";", "if", "(", "$", "validateddata", "=", "$", "mform", "->", "get_data", "(", ")", ")", "{", "$", "purpose", "=", "api", "::", "create_purpose", "(", "$", "validateddata", ")", ";", "$", "validationerrors", "=", "false", ";", "}", "else", "if", "(", "$", "errors", "=", "$", "mform", "->", "is_validated", "(", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'generalerror'", ")", ";", "}", "$", "exporter", "=", "new", "purpose_exporter", "(", "$", "purpose", ",", "[", "'context'", "=>", "\\", "context_system", "::", "instance", "(", ")", "]", ")", ";", "return", "[", "'purpose'", "=>", "$", "exporter", "->", "export", "(", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ")", ",", "'validationerrors'", "=>", "$", "validationerrors", ",", "'warnings'", "=>", "$", "warnings", "]", ";", "}" ]
Creates a data purpose from form data. @since Moodle 3.5 @param string $jsonformdata @return array
[ "Creates", "a", "data", "purpose", "from", "form", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/external.php#L778-L812
216,317
moodle/moodle
admin/tool/dataprivacy/classes/external.php
external.tree_extra_branches
public static function tree_extra_branches($contextid, $element) { $params = external_api::validate_parameters(self::tree_extra_branches_parameters(), [ 'contextid' => $contextid, 'element' => $element, ]); $context = context_helper::instance_by_id($params['contextid']); self::validate_context($context); api::check_can_manage_data_registry($context->id); switch ($params['element']) { case 'course': $branches = data_registry_page::get_courses_branch($context); break; case 'module': $branches = data_registry_page::get_modules_branch($context); break; case 'block': $branches = data_registry_page::get_blocks_branch($context); break; default: throw new \moodle_exception('Unsupported element provided.'); } return [ 'branches' => $branches, 'warnings' => [], ]; }
php
public static function tree_extra_branches($contextid, $element) { $params = external_api::validate_parameters(self::tree_extra_branches_parameters(), [ 'contextid' => $contextid, 'element' => $element, ]); $context = context_helper::instance_by_id($params['contextid']); self::validate_context($context); api::check_can_manage_data_registry($context->id); switch ($params['element']) { case 'course': $branches = data_registry_page::get_courses_branch($context); break; case 'module': $branches = data_registry_page::get_modules_branch($context); break; case 'block': $branches = data_registry_page::get_blocks_branch($context); break; default: throw new \moodle_exception('Unsupported element provided.'); } return [ 'branches' => $branches, 'warnings' => [], ]; }
[ "public", "static", "function", "tree_extra_branches", "(", "$", "contextid", ",", "$", "element", ")", "{", "$", "params", "=", "external_api", "::", "validate_parameters", "(", "self", "::", "tree_extra_branches_parameters", "(", ")", ",", "[", "'contextid'", "=>", "$", "contextid", ",", "'element'", "=>", "$", "element", ",", "]", ")", ";", "$", "context", "=", "context_helper", "::", "instance_by_id", "(", "$", "params", "[", "'contextid'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "api", "::", "check_can_manage_data_registry", "(", "$", "context", "->", "id", ")", ";", "switch", "(", "$", "params", "[", "'element'", "]", ")", "{", "case", "'course'", ":", "$", "branches", "=", "data_registry_page", "::", "get_courses_branch", "(", "$", "context", ")", ";", "break", ";", "case", "'module'", ":", "$", "branches", "=", "data_registry_page", "::", "get_modules_branch", "(", "$", "context", ")", ";", "break", ";", "case", "'block'", ":", "$", "branches", "=", "data_registry_page", "::", "get_blocks_branch", "(", "$", "context", ")", ";", "break", ";", "default", ":", "throw", "new", "\\", "moodle_exception", "(", "'Unsupported element provided.'", ")", ";", "}", "return", "[", "'branches'", "=>", "$", "branches", ",", "'warnings'", "=>", "[", "]", ",", "]", ";", "}" ]
Returns tree extra branches. @since Moodle 3.5 @param int $contextid @param string $element @return array
[ "Returns", "tree", "extra", "branches", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/external.php#L1167-L1197
216,318
moodle/moodle
admin/tool/dataprivacy/classes/external.php
external.confirm_contexts_for_deletion
public static function confirm_contexts_for_deletion($ids) { $warnings = []; $params = external_api::validate_parameters(self::confirm_contexts_for_deletion_parameters(), [ 'ids' => $ids ]); $ids = $params['ids']; // Validate context and access to manage the registry. self::validate_context(\context_system::instance()); api::check_can_manage_data_registry(); $result = true; if (!empty($ids)) { $expiredcontextstoapprove = []; // Loop through the deletion of expired contexts and their children if necessary. foreach ($ids as $id) { $expiredcontext = new expired_context($id); $targetcontext = context_helper::instance_by_id($expiredcontext->get('contextid')); if (!$targetcontext instanceof \context_user) { // Fetch this context's child contexts. Make sure that all of the child contexts are flagged for deletion. // User context children do not need to be considered. $childcontexts = $targetcontext->get_child_contexts(); foreach ($childcontexts as $child) { if ($expiredchildcontext = expired_context::get_record(['contextid' => $child->id])) { // Add this child context to the list for approval. $expiredcontextstoapprove[] = $expiredchildcontext; } else { // This context has not yet been flagged for deletion. $result = false; $message = get_string('errorcontexthasunexpiredchildren', 'tool_dataprivacy', $targetcontext->get_context_name(false)); $warnings[] = [ 'item' => 'tool_dataprivacy_ctxexpired', 'warningcode' => 'errorcontexthasunexpiredchildren', 'message' => $message ]; // Exit the process. break 2; } } } $expiredcontextstoapprove[] = $expiredcontext; } // Proceed with the approval if everything's in order. if ($result) { // Mark expired contexts as approved for deletion. foreach ($expiredcontextstoapprove as $expired) { // Only mark expired contexts that are pending approval. if ($expired->get('status') == expired_context::STATUS_EXPIRED) { api::set_expired_context_status($expired, expired_context::STATUS_APPROVED); } } } } else { // We don't have anything to process. $result = false; $warnings[] = [ 'item' => 'tool_dataprivacy_ctxexpired', 'warningcode' => 'errornoexpiredcontexts', 'message' => get_string('errornoexpiredcontexts', 'tool_dataprivacy') ]; } return [ 'result' => $result, 'warnings' => $warnings ]; }
php
public static function confirm_contexts_for_deletion($ids) { $warnings = []; $params = external_api::validate_parameters(self::confirm_contexts_for_deletion_parameters(), [ 'ids' => $ids ]); $ids = $params['ids']; // Validate context and access to manage the registry. self::validate_context(\context_system::instance()); api::check_can_manage_data_registry(); $result = true; if (!empty($ids)) { $expiredcontextstoapprove = []; // Loop through the deletion of expired contexts and their children if necessary. foreach ($ids as $id) { $expiredcontext = new expired_context($id); $targetcontext = context_helper::instance_by_id($expiredcontext->get('contextid')); if (!$targetcontext instanceof \context_user) { // Fetch this context's child contexts. Make sure that all of the child contexts are flagged for deletion. // User context children do not need to be considered. $childcontexts = $targetcontext->get_child_contexts(); foreach ($childcontexts as $child) { if ($expiredchildcontext = expired_context::get_record(['contextid' => $child->id])) { // Add this child context to the list for approval. $expiredcontextstoapprove[] = $expiredchildcontext; } else { // This context has not yet been flagged for deletion. $result = false; $message = get_string('errorcontexthasunexpiredchildren', 'tool_dataprivacy', $targetcontext->get_context_name(false)); $warnings[] = [ 'item' => 'tool_dataprivacy_ctxexpired', 'warningcode' => 'errorcontexthasunexpiredchildren', 'message' => $message ]; // Exit the process. break 2; } } } $expiredcontextstoapprove[] = $expiredcontext; } // Proceed with the approval if everything's in order. if ($result) { // Mark expired contexts as approved for deletion. foreach ($expiredcontextstoapprove as $expired) { // Only mark expired contexts that are pending approval. if ($expired->get('status') == expired_context::STATUS_EXPIRED) { api::set_expired_context_status($expired, expired_context::STATUS_APPROVED); } } } } else { // We don't have anything to process. $result = false; $warnings[] = [ 'item' => 'tool_dataprivacy_ctxexpired', 'warningcode' => 'errornoexpiredcontexts', 'message' => get_string('errornoexpiredcontexts', 'tool_dataprivacy') ]; } return [ 'result' => $result, 'warnings' => $warnings ]; }
[ "public", "static", "function", "confirm_contexts_for_deletion", "(", "$", "ids", ")", "{", "$", "warnings", "=", "[", "]", ";", "$", "params", "=", "external_api", "::", "validate_parameters", "(", "self", "::", "confirm_contexts_for_deletion_parameters", "(", ")", ",", "[", "'ids'", "=>", "$", "ids", "]", ")", ";", "$", "ids", "=", "$", "params", "[", "'ids'", "]", ";", "// Validate context and access to manage the registry.", "self", "::", "validate_context", "(", "\\", "context_system", "::", "instance", "(", ")", ")", ";", "api", "::", "check_can_manage_data_registry", "(", ")", ";", "$", "result", "=", "true", ";", "if", "(", "!", "empty", "(", "$", "ids", ")", ")", "{", "$", "expiredcontextstoapprove", "=", "[", "]", ";", "// Loop through the deletion of expired contexts and their children if necessary.", "foreach", "(", "$", "ids", "as", "$", "id", ")", "{", "$", "expiredcontext", "=", "new", "expired_context", "(", "$", "id", ")", ";", "$", "targetcontext", "=", "context_helper", "::", "instance_by_id", "(", "$", "expiredcontext", "->", "get", "(", "'contextid'", ")", ")", ";", "if", "(", "!", "$", "targetcontext", "instanceof", "\\", "context_user", ")", "{", "// Fetch this context's child contexts. Make sure that all of the child contexts are flagged for deletion.", "// User context children do not need to be considered.", "$", "childcontexts", "=", "$", "targetcontext", "->", "get_child_contexts", "(", ")", ";", "foreach", "(", "$", "childcontexts", "as", "$", "child", ")", "{", "if", "(", "$", "expiredchildcontext", "=", "expired_context", "::", "get_record", "(", "[", "'contextid'", "=>", "$", "child", "->", "id", "]", ")", ")", "{", "// Add this child context to the list for approval.", "$", "expiredcontextstoapprove", "[", "]", "=", "$", "expiredchildcontext", ";", "}", "else", "{", "// This context has not yet been flagged for deletion.", "$", "result", "=", "false", ";", "$", "message", "=", "get_string", "(", "'errorcontexthasunexpiredchildren'", ",", "'tool_dataprivacy'", ",", "$", "targetcontext", "->", "get_context_name", "(", "false", ")", ")", ";", "$", "warnings", "[", "]", "=", "[", "'item'", "=>", "'tool_dataprivacy_ctxexpired'", ",", "'warningcode'", "=>", "'errorcontexthasunexpiredchildren'", ",", "'message'", "=>", "$", "message", "]", ";", "// Exit the process.", "break", "2", ";", "}", "}", "}", "$", "expiredcontextstoapprove", "[", "]", "=", "$", "expiredcontext", ";", "}", "// Proceed with the approval if everything's in order.", "if", "(", "$", "result", ")", "{", "// Mark expired contexts as approved for deletion.", "foreach", "(", "$", "expiredcontextstoapprove", "as", "$", "expired", ")", "{", "// Only mark expired contexts that are pending approval.", "if", "(", "$", "expired", "->", "get", "(", "'status'", ")", "==", "expired_context", "::", "STATUS_EXPIRED", ")", "{", "api", "::", "set_expired_context_status", "(", "$", "expired", ",", "expired_context", "::", "STATUS_APPROVED", ")", ";", "}", "}", "}", "}", "else", "{", "// We don't have anything to process.", "$", "result", "=", "false", ";", "$", "warnings", "[", "]", "=", "[", "'item'", "=>", "'tool_dataprivacy_ctxexpired'", ",", "'warningcode'", "=>", "'errornoexpiredcontexts'", ",", "'message'", "=>", "get_string", "(", "'errornoexpiredcontexts'", ",", "'tool_dataprivacy'", ")", "]", ";", "}", "return", "[", "'result'", "=>", "$", "result", ",", "'warnings'", "=>", "$", "warnings", "]", ";", "}" ]
Confirm a given array of expired context record IDs @since Moodle 3.5 @param int[] $ids Array of record IDs from the expired contexts table. @return array @throws coding_exception @throws dml_exception @throws invalid_parameter_exception @throws restricted_context_exception
[ "Confirm", "a", "given", "array", "of", "expired", "context", "record", "IDs" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/external.php#L1238-L1309
216,319
moodle/moodle
admin/tool/dataprivacy/classes/external.php
external.get_category_options
public static function get_category_options($includeinherit, $includenotset) { $warnings = []; $params = self::validate_parameters(self::get_category_options_parameters(), [ 'includeinherit' => $includeinherit, 'includenotset' => $includenotset ]); $includeinherit = $params['includeinherit']; $includenotset = $params['includenotset']; $context = context_system::instance(); self::validate_context($context); api::check_can_manage_data_registry(); $categories = api::get_categories(); $options = data_registry_page::category_options($categories, $includenotset, $includeinherit); $categoryoptions = []; foreach ($options as $id => $name) { $categoryoptions[] = [ 'id' => $id, 'name' => $name, ]; } return [ 'options' => $categoryoptions, 'warnings' => $warnings ]; }
php
public static function get_category_options($includeinherit, $includenotset) { $warnings = []; $params = self::validate_parameters(self::get_category_options_parameters(), [ 'includeinherit' => $includeinherit, 'includenotset' => $includenotset ]); $includeinherit = $params['includeinherit']; $includenotset = $params['includenotset']; $context = context_system::instance(); self::validate_context($context); api::check_can_manage_data_registry(); $categories = api::get_categories(); $options = data_registry_page::category_options($categories, $includenotset, $includeinherit); $categoryoptions = []; foreach ($options as $id => $name) { $categoryoptions[] = [ 'id' => $id, 'name' => $name, ]; } return [ 'options' => $categoryoptions, 'warnings' => $warnings ]; }
[ "public", "static", "function", "get_category_options", "(", "$", "includeinherit", ",", "$", "includenotset", ")", "{", "$", "warnings", "=", "[", "]", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_category_options_parameters", "(", ")", ",", "[", "'includeinherit'", "=>", "$", "includeinherit", ",", "'includenotset'", "=>", "$", "includenotset", "]", ")", ";", "$", "includeinherit", "=", "$", "params", "[", "'includeinherit'", "]", ";", "$", "includenotset", "=", "$", "params", "[", "'includenotset'", "]", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "api", "::", "check_can_manage_data_registry", "(", ")", ";", "$", "categories", "=", "api", "::", "get_categories", "(", ")", ";", "$", "options", "=", "data_registry_page", "::", "category_options", "(", "$", "categories", ",", "$", "includenotset", ",", "$", "includeinherit", ")", ";", "$", "categoryoptions", "=", "[", "]", ";", "foreach", "(", "$", "options", "as", "$", "id", "=>", "$", "name", ")", "{", "$", "categoryoptions", "[", "]", "=", "[", "'id'", "=>", "$", "id", ",", "'name'", "=>", "$", "name", ",", "]", ";", "}", "return", "[", "'options'", "=>", "$", "categoryoptions", ",", "'warnings'", "=>", "$", "warnings", "]", ";", "}" ]
Fetches a list of data category options containing category IDs as keys and the category name for the value. @param bool $includeinherit Whether to include the "Inherit" option. @param bool $includenotset Whether to include the "Not set" option. @return array
[ "Fetches", "a", "list", "of", "data", "category", "options", "containing", "category", "IDs", "as", "keys", "and", "the", "category", "name", "for", "the", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/external.php#L1411-L1439
216,320
moodle/moodle
admin/tool/dataprivacy/classes/external.php
external.get_purpose_options
public static function get_purpose_options($includeinherit, $includenotset) { $warnings = []; $params = self::validate_parameters(self::get_category_options_parameters(), [ 'includeinherit' => $includeinherit, 'includenotset' => $includenotset ]); $includeinherit = $params['includeinherit']; $includenotset = $params['includenotset']; $context = context_system::instance(); self::validate_context($context); $purposes = api::get_purposes(); $options = data_registry_page::purpose_options($purposes, $includenotset, $includeinherit); $purposeoptions = []; foreach ($options as $id => $name) { $purposeoptions[] = [ 'id' => $id, 'name' => $name, ]; } return [ 'options' => $purposeoptions, 'warnings' => $warnings ]; }
php
public static function get_purpose_options($includeinherit, $includenotset) { $warnings = []; $params = self::validate_parameters(self::get_category_options_parameters(), [ 'includeinherit' => $includeinherit, 'includenotset' => $includenotset ]); $includeinherit = $params['includeinherit']; $includenotset = $params['includenotset']; $context = context_system::instance(); self::validate_context($context); $purposes = api::get_purposes(); $options = data_registry_page::purpose_options($purposes, $includenotset, $includeinherit); $purposeoptions = []; foreach ($options as $id => $name) { $purposeoptions[] = [ 'id' => $id, 'name' => $name, ]; } return [ 'options' => $purposeoptions, 'warnings' => $warnings ]; }
[ "public", "static", "function", "get_purpose_options", "(", "$", "includeinherit", ",", "$", "includenotset", ")", "{", "$", "warnings", "=", "[", "]", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_category_options_parameters", "(", ")", ",", "[", "'includeinherit'", "=>", "$", "includeinherit", ",", "'includenotset'", "=>", "$", "includenotset", "]", ")", ";", "$", "includeinherit", "=", "$", "params", "[", "'includeinherit'", "]", ";", "$", "includenotset", "=", "$", "params", "[", "'includenotset'", "]", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "purposes", "=", "api", "::", "get_purposes", "(", ")", ";", "$", "options", "=", "data_registry_page", "::", "purpose_options", "(", "$", "purposes", ",", "$", "includenotset", ",", "$", "includeinherit", ")", ";", "$", "purposeoptions", "=", "[", "]", ";", "foreach", "(", "$", "options", "as", "$", "id", "=>", "$", "name", ")", "{", "$", "purposeoptions", "[", "]", "=", "[", "'id'", "=>", "$", "id", ",", "'name'", "=>", "$", "name", ",", "]", ";", "}", "return", "[", "'options'", "=>", "$", "purposeoptions", ",", "'warnings'", "=>", "$", "warnings", "]", ";", "}" ]
Fetches a list of data storage purposes containing purpose IDs as keys and the purpose name for the value. @param bool $includeinherit Whether to include the "Inherit" option. @param bool $includenotset Whether to include the "Not set" option. @return array
[ "Fetches", "a", "list", "of", "data", "storage", "purposes", "containing", "purpose", "IDs", "as", "keys", "and", "the", "purpose", "name", "for", "the", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/external.php#L1479-L1506
216,321
moodle/moodle
admin/tool/dataprivacy/classes/external.php
external.get_activity_options
public static function get_activity_options($nodefaults) { $warnings = []; $params = self::validate_parameters(self::get_activity_options_parameters(), [ 'nodefaults' => $nodefaults, ]); $nodefaults = $params['nodefaults']; $context = context_system::instance(); self::validate_context($context); // Get activity module plugin info. $pluginmanager = \core_plugin_manager::instance(); $modplugins = $pluginmanager->get_enabled_plugins('mod'); $modoptions = []; // Get the module-level defaults. data_registry::get_defaults falls back to this when there are no activity defaults. list($levelpurpose, $levelcategory) = data_registry::get_defaults(CONTEXT_MODULE); foreach ($modplugins as $name) { // Check if we have default purpose and category for this module if we want don't want to fetch everything. if ($nodefaults) { list($purpose, $category) = data_registry::get_defaults(CONTEXT_MODULE, $name); // Compare this with the module-level defaults. if ($purpose !== $levelpurpose || $category !== $levelcategory) { // If the defaults for this activity has been already set, there's no need to add this in the list of options. continue; } } $displayname = $pluginmanager->plugin_name('mod_' . $name); $modoptions[] = (object)[ 'name' => $name, 'displayname' => $displayname ]; } return [ 'options' => $modoptions, 'warnings' => $warnings ]; }
php
public static function get_activity_options($nodefaults) { $warnings = []; $params = self::validate_parameters(self::get_activity_options_parameters(), [ 'nodefaults' => $nodefaults, ]); $nodefaults = $params['nodefaults']; $context = context_system::instance(); self::validate_context($context); // Get activity module plugin info. $pluginmanager = \core_plugin_manager::instance(); $modplugins = $pluginmanager->get_enabled_plugins('mod'); $modoptions = []; // Get the module-level defaults. data_registry::get_defaults falls back to this when there are no activity defaults. list($levelpurpose, $levelcategory) = data_registry::get_defaults(CONTEXT_MODULE); foreach ($modplugins as $name) { // Check if we have default purpose and category for this module if we want don't want to fetch everything. if ($nodefaults) { list($purpose, $category) = data_registry::get_defaults(CONTEXT_MODULE, $name); // Compare this with the module-level defaults. if ($purpose !== $levelpurpose || $category !== $levelcategory) { // If the defaults for this activity has been already set, there's no need to add this in the list of options. continue; } } $displayname = $pluginmanager->plugin_name('mod_' . $name); $modoptions[] = (object)[ 'name' => $name, 'displayname' => $displayname ]; } return [ 'options' => $modoptions, 'warnings' => $warnings ]; }
[ "public", "static", "function", "get_activity_options", "(", "$", "nodefaults", ")", "{", "$", "warnings", "=", "[", "]", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_activity_options_parameters", "(", ")", ",", "[", "'nodefaults'", "=>", "$", "nodefaults", ",", "]", ")", ";", "$", "nodefaults", "=", "$", "params", "[", "'nodefaults'", "]", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "// Get activity module plugin info.", "$", "pluginmanager", "=", "\\", "core_plugin_manager", "::", "instance", "(", ")", ";", "$", "modplugins", "=", "$", "pluginmanager", "->", "get_enabled_plugins", "(", "'mod'", ")", ";", "$", "modoptions", "=", "[", "]", ";", "// Get the module-level defaults. data_registry::get_defaults falls back to this when there are no activity defaults.", "list", "(", "$", "levelpurpose", ",", "$", "levelcategory", ")", "=", "data_registry", "::", "get_defaults", "(", "CONTEXT_MODULE", ")", ";", "foreach", "(", "$", "modplugins", "as", "$", "name", ")", "{", "// Check if we have default purpose and category for this module if we want don't want to fetch everything.", "if", "(", "$", "nodefaults", ")", "{", "list", "(", "$", "purpose", ",", "$", "category", ")", "=", "data_registry", "::", "get_defaults", "(", "CONTEXT_MODULE", ",", "$", "name", ")", ";", "// Compare this with the module-level defaults.", "if", "(", "$", "purpose", "!==", "$", "levelpurpose", "||", "$", "category", "!==", "$", "levelcategory", ")", "{", "// If the defaults for this activity has been already set, there's no need to add this in the list of options.", "continue", ";", "}", "}", "$", "displayname", "=", "$", "pluginmanager", "->", "plugin_name", "(", "'mod_'", ".", "$", "name", ")", ";", "$", "modoptions", "[", "]", "=", "(", "object", ")", "[", "'name'", "=>", "$", "name", ",", "'displayname'", "=>", "$", "displayname", "]", ";", "}", "return", "[", "'options'", "=>", "$", "modoptions", ",", "'warnings'", "=>", "$", "warnings", "]", ";", "}" ]
Fetches a list of activity options for setting data registry defaults. @param boolean $nodefaults If false, it will fetch all of the activities. Otherwise, it will only fetch the activities that don't have defaults yet (e.g. when adding a new activity module defaults). @return array
[ "Fetches", "a", "list", "of", "activity", "options", "for", "setting", "data", "registry", "defaults", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/external.php#L1546-L1586
216,322
moodle/moodle
lib/spout/src/Spout/Writer/ODS/Internal/Workbook.php
Workbook.close
public function close($finalFilePointer) { /** @var Worksheet[] $worksheets */ $worksheets = $this->worksheets; $numWorksheets = count($worksheets); foreach ($worksheets as $worksheet) { $worksheet->close(); } // Finish creating all the necessary files before zipping everything together $this->fileSystemHelper ->createContentFile($worksheets, $this->styleHelper) ->deleteWorksheetTempFolder() ->createStylesFile($this->styleHelper, $numWorksheets) ->zipRootFolderAndCopyToStream($finalFilePointer); $this->cleanupTempFolder(); }
php
public function close($finalFilePointer) { /** @var Worksheet[] $worksheets */ $worksheets = $this->worksheets; $numWorksheets = count($worksheets); foreach ($worksheets as $worksheet) { $worksheet->close(); } // Finish creating all the necessary files before zipping everything together $this->fileSystemHelper ->createContentFile($worksheets, $this->styleHelper) ->deleteWorksheetTempFolder() ->createStylesFile($this->styleHelper, $numWorksheets) ->zipRootFolderAndCopyToStream($finalFilePointer); $this->cleanupTempFolder(); }
[ "public", "function", "close", "(", "$", "finalFilePointer", ")", "{", "/** @var Worksheet[] $worksheets */", "$", "worksheets", "=", "$", "this", "->", "worksheets", ";", "$", "numWorksheets", "=", "count", "(", "$", "worksheets", ")", ";", "foreach", "(", "$", "worksheets", "as", "$", "worksheet", ")", "{", "$", "worksheet", "->", "close", "(", ")", ";", "}", "// Finish creating all the necessary files before zipping everything together", "$", "this", "->", "fileSystemHelper", "->", "createContentFile", "(", "$", "worksheets", ",", "$", "this", "->", "styleHelper", ")", "->", "deleteWorksheetTempFolder", "(", ")", "->", "createStylesFile", "(", "$", "this", "->", "styleHelper", ",", "$", "numWorksheets", ")", "->", "zipRootFolderAndCopyToStream", "(", "$", "finalFilePointer", ")", ";", "$", "this", "->", "cleanupTempFolder", "(", ")", ";", "}" ]
Closes the workbook and all its associated sheets. All the necessary files are written to disk and zipped together to create the ODS file. All the temporary files are then deleted. @param resource $finalFilePointer Pointer to the ODS that will be created @return void
[ "Closes", "the", "workbook", "and", "all", "its", "associated", "sheets", ".", "All", "the", "necessary", "files", "are", "written", "to", "disk", "and", "zipped", "together", "to", "create", "the", "ODS", "file", ".", "All", "the", "temporary", "files", "are", "then", "deleted", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/ODS/Internal/Workbook.php#L89-L107
216,323
moodle/moodle
mod/forum/classes/local/data_mappers/legacy/author.php
author.to_legacy_objects
public function to_legacy_objects(array $authors) : array { return array_map(function(author_entity $author) { return (object) [ 'id' => $author->get_id(), 'picture' => $author->get_picture_item_id(), 'firstname' => $author->get_first_name(), 'lastname' => $author->get_last_name(), 'fullname' => $author->get_full_name(), 'email' => $author->get_email(), 'middlename' => $author->get_middle_name(), 'firstnamephonetic' => $author->get_first_name_phonetic(), 'lastnamephonetic' => $author->get_last_name_phonetic(), 'alternatename' => $author->get_alternate_name(), 'imagealt' => $author->get_image_alt() ]; }, $authors); }
php
public function to_legacy_objects(array $authors) : array { return array_map(function(author_entity $author) { return (object) [ 'id' => $author->get_id(), 'picture' => $author->get_picture_item_id(), 'firstname' => $author->get_first_name(), 'lastname' => $author->get_last_name(), 'fullname' => $author->get_full_name(), 'email' => $author->get_email(), 'middlename' => $author->get_middle_name(), 'firstnamephonetic' => $author->get_first_name_phonetic(), 'lastnamephonetic' => $author->get_last_name_phonetic(), 'alternatename' => $author->get_alternate_name(), 'imagealt' => $author->get_image_alt() ]; }, $authors); }
[ "public", "function", "to_legacy_objects", "(", "array", "$", "authors", ")", ":", "array", "{", "return", "array_map", "(", "function", "(", "author_entity", "$", "author", ")", "{", "return", "(", "object", ")", "[", "'id'", "=>", "$", "author", "->", "get_id", "(", ")", ",", "'picture'", "=>", "$", "author", "->", "get_picture_item_id", "(", ")", ",", "'firstname'", "=>", "$", "author", "->", "get_first_name", "(", ")", ",", "'lastname'", "=>", "$", "author", "->", "get_last_name", "(", ")", ",", "'fullname'", "=>", "$", "author", "->", "get_full_name", "(", ")", ",", "'email'", "=>", "$", "author", "->", "get_email", "(", ")", ",", "'middlename'", "=>", "$", "author", "->", "get_middle_name", "(", ")", ",", "'firstnamephonetic'", "=>", "$", "author", "->", "get_first_name_phonetic", "(", ")", ",", "'lastnamephonetic'", "=>", "$", "author", "->", "get_last_name_phonetic", "(", ")", ",", "'alternatename'", "=>", "$", "author", "->", "get_alternate_name", "(", ")", ",", "'imagealt'", "=>", "$", "author", "->", "get_image_alt", "(", ")", "]", ";", "}", ",", "$", "authors", ")", ";", "}" ]
Convert a list of author entities into stdClasses. @param author_entity[] $authors The authors to convert. @return stdClass[]
[ "Convert", "a", "list", "of", "author", "entities", "into", "stdClasses", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/data_mappers/legacy/author.php#L45-L61
216,324
moodle/moodle
cache/stores/file/lib.php
cachestore_file.prescan_keys
protected function prescan_keys() { $files = glob($this->glob_keys_pattern(), GLOB_MARK | GLOB_NOSORT); if (is_array($files)) { foreach ($files as $filename) { $this->keys[basename($filename)] = filemtime($filename); } } }
php
protected function prescan_keys() { $files = glob($this->glob_keys_pattern(), GLOB_MARK | GLOB_NOSORT); if (is_array($files)) { foreach ($files as $filename) { $this->keys[basename($filename)] = filemtime($filename); } } }
[ "protected", "function", "prescan_keys", "(", ")", "{", "$", "files", "=", "glob", "(", "$", "this", "->", "glob_keys_pattern", "(", ")", ",", "GLOB_MARK", "|", "GLOB_NOSORT", ")", ";", "if", "(", "is_array", "(", "$", "files", ")", ")", "{", "foreach", "(", "$", "files", "as", "$", "filename", ")", "{", "$", "this", "->", "keys", "[", "basename", "(", "$", "filename", ")", "]", "=", "filemtime", "(", "$", "filename", ")", ";", "}", "}", "}" ]
Pre-scan the cache to see which keys are present.
[ "Pre", "-", "scan", "the", "cache", "to", "see", "which", "keys", "are", "present", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/file/lib.php#L282-L289
216,325
moodle/moodle
cache/stores/file/lib.php
cachestore_file.glob_keys_pattern
protected function glob_keys_pattern($prefix = '') { if ($this->singledirectory) { return $this->path . '/'.$prefix.'*.cache'; } else { return $this->path . '/*/'.$prefix.'*.cache'; } }
php
protected function glob_keys_pattern($prefix = '') { if ($this->singledirectory) { return $this->path . '/'.$prefix.'*.cache'; } else { return $this->path . '/*/'.$prefix.'*.cache'; } }
[ "protected", "function", "glob_keys_pattern", "(", "$", "prefix", "=", "''", ")", "{", "if", "(", "$", "this", "->", "singledirectory", ")", "{", "return", "$", "this", "->", "path", ".", "'/'", ".", "$", "prefix", ".", "'*.cache'", ";", "}", "else", "{", "return", "$", "this", "->", "path", ".", "'/*/'", ".", "$", "prefix", ".", "'*.cache'", ";", "}", "}" ]
Gets a pattern suitable for use with glob to find all keys in the cache. @param string $prefix A prefix to use. @return string The pattern.
[ "Gets", "a", "pattern", "suitable", "for", "use", "with", "glob", "to", "find", "all", "keys", "in", "the", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/file/lib.php#L297-L303
216,326
moodle/moodle
cache/stores/file/lib.php
cachestore_file.file_path_for_key
protected function file_path_for_key($key, $create = false) { if ($this->singledirectory) { // Its a single directory, easy, just the store instances path + the file name. return $this->path . '/' . $key . '.cache'; } else { // We are using a single subdirectory to achieve 1 level. // We suffix the subdir so it does not clash with any windows // reserved filenames like 'con'. $subdir = substr($key, 0, 3) . '-cache'; $dir = $this->path . '/' . $subdir; if ($create) { // Create the directory. This function does it recursivily! make_writable_directory($dir, false); } return $dir . '/' . $key . '.cache'; } }
php
protected function file_path_for_key($key, $create = false) { if ($this->singledirectory) { // Its a single directory, easy, just the store instances path + the file name. return $this->path . '/' . $key . '.cache'; } else { // We are using a single subdirectory to achieve 1 level. // We suffix the subdir so it does not clash with any windows // reserved filenames like 'con'. $subdir = substr($key, 0, 3) . '-cache'; $dir = $this->path . '/' . $subdir; if ($create) { // Create the directory. This function does it recursivily! make_writable_directory($dir, false); } return $dir . '/' . $key . '.cache'; } }
[ "protected", "function", "file_path_for_key", "(", "$", "key", ",", "$", "create", "=", "false", ")", "{", "if", "(", "$", "this", "->", "singledirectory", ")", "{", "// Its a single directory, easy, just the store instances path + the file name.", "return", "$", "this", "->", "path", ".", "'/'", ".", "$", "key", ".", "'.cache'", ";", "}", "else", "{", "// We are using a single subdirectory to achieve 1 level.", "// We suffix the subdir so it does not clash with any windows", "// reserved filenames like 'con'.", "$", "subdir", "=", "substr", "(", "$", "key", ",", "0", ",", "3", ")", ".", "'-cache'", ";", "$", "dir", "=", "$", "this", "->", "path", ".", "'/'", ".", "$", "subdir", ";", "if", "(", "$", "create", ")", "{", "// Create the directory. This function does it recursivily!", "make_writable_directory", "(", "$", "dir", ",", "false", ")", ";", "}", "return", "$", "dir", ".", "'/'", ".", "$", "key", ".", "'.cache'", ";", "}", "}" ]
Returns the file path to use for the given key. @param string $key The key to generate a file path for. @param bool $create If set to the true the directory structure the key requires will be created. @return string The full path to the file that stores a particular cache key.
[ "Returns", "the", "file", "path", "to", "use", "for", "the", "given", "key", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/file/lib.php#L312-L328
216,327
moodle/moodle
cache/stores/file/lib.php
cachestore_file.purge
public function purge() { if ($this->isready) { $files = glob($this->glob_keys_pattern(), GLOB_MARK | GLOB_NOSORT); if (is_array($files)) { foreach ($files as $filename) { @unlink($filename); } } $this->keys = array(); } return true; }
php
public function purge() { if ($this->isready) { $files = glob($this->glob_keys_pattern(), GLOB_MARK | GLOB_NOSORT); if (is_array($files)) { foreach ($files as $filename) { @unlink($filename); } } $this->keys = array(); } return true; }
[ "public", "function", "purge", "(", ")", "{", "if", "(", "$", "this", "->", "isready", ")", "{", "$", "files", "=", "glob", "(", "$", "this", "->", "glob_keys_pattern", "(", ")", ",", "GLOB_MARK", "|", "GLOB_NOSORT", ")", ";", "if", "(", "is_array", "(", "$", "files", ")", ")", "{", "foreach", "(", "$", "files", "as", "$", "filename", ")", "{", "@", "unlink", "(", "$", "filename", ")", ";", "}", "}", "$", "this", "->", "keys", "=", "array", "(", ")", ";", "}", "return", "true", ";", "}" ]
Purges the cache definition deleting all the items within it. @return boolean True on success. False otherwise.
[ "Purges", "the", "cache", "definition", "deleting", "all", "the", "items", "within", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/file/lib.php#L544-L555
216,328
moodle/moodle
cache/stores/file/lib.php
cachestore_file.purge_all_definitions
protected function purge_all_definitions() { // Warning: limit the deletion to what file store is actually able // to create using the internal {@link purge()} providing the // {@link $path} with a wildcard to perform a purge action over all the definitions. $currpath = $this->path; $this->path = $this->filestorepath.'/*'; $result = $this->purge(); $this->path = $currpath; return $result; }
php
protected function purge_all_definitions() { // Warning: limit the deletion to what file store is actually able // to create using the internal {@link purge()} providing the // {@link $path} with a wildcard to perform a purge action over all the definitions. $currpath = $this->path; $this->path = $this->filestorepath.'/*'; $result = $this->purge(); $this->path = $currpath; return $result; }
[ "protected", "function", "purge_all_definitions", "(", ")", "{", "// Warning: limit the deletion to what file store is actually able", "// to create using the internal {@link purge()} providing the", "// {@link $path} with a wildcard to perform a purge action over all the definitions.", "$", "currpath", "=", "$", "this", "->", "path", ";", "$", "this", "->", "path", "=", "$", "this", "->", "filestorepath", ".", "'/*'", ";", "$", "result", "=", "$", "this", "->", "purge", "(", ")", ";", "$", "this", "->", "path", "=", "$", "currpath", ";", "return", "$", "result", ";", "}" ]
Purges all the cache definitions deleting all items within them. @return boolean True on success. False otherwise.
[ "Purges", "all", "the", "cache", "definitions", "deleting", "all", "items", "within", "them", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/file/lib.php#L562-L571
216,329
moodle/moodle
cache/stores/file/lib.php
cachestore_file.ensure_path_exists
protected function ensure_path_exists() { global $CFG; if (!is_writable($this->path)) { if ($this->custompath && !$this->autocreate) { throw new coding_exception('File store path does not exist. It must exist and be writable by the web server.'); } $createdcfg = false; if (!isset($CFG)) { // This can only happen during destruction of objects. // A cache is being used within a destructor, php is ending a request and $CFG has // already being cleaned up. // Rebuild $CFG with directory permissions just to complete this write. $CFG = $this->cfg; $createdcfg = true; } if (!make_writable_directory($this->path, false)) { throw new coding_exception('File store path does not exist and can not be created.'); } if ($createdcfg) { // We re-created it so we'll clean it up. unset($CFG); } } return true; }
php
protected function ensure_path_exists() { global $CFG; if (!is_writable($this->path)) { if ($this->custompath && !$this->autocreate) { throw new coding_exception('File store path does not exist. It must exist and be writable by the web server.'); } $createdcfg = false; if (!isset($CFG)) { // This can only happen during destruction of objects. // A cache is being used within a destructor, php is ending a request and $CFG has // already being cleaned up. // Rebuild $CFG with directory permissions just to complete this write. $CFG = $this->cfg; $createdcfg = true; } if (!make_writable_directory($this->path, false)) { throw new coding_exception('File store path does not exist and can not be created.'); } if ($createdcfg) { // We re-created it so we'll clean it up. unset($CFG); } } return true; }
[ "protected", "function", "ensure_path_exists", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "is_writable", "(", "$", "this", "->", "path", ")", ")", "{", "if", "(", "$", "this", "->", "custompath", "&&", "!", "$", "this", "->", "autocreate", ")", "{", "throw", "new", "coding_exception", "(", "'File store path does not exist. It must exist and be writable by the web server.'", ")", ";", "}", "$", "createdcfg", "=", "false", ";", "if", "(", "!", "isset", "(", "$", "CFG", ")", ")", "{", "// This can only happen during destruction of objects.", "// A cache is being used within a destructor, php is ending a request and $CFG has", "// already being cleaned up.", "// Rebuild $CFG with directory permissions just to complete this write.", "$", "CFG", "=", "$", "this", "->", "cfg", ";", "$", "createdcfg", "=", "true", ";", "}", "if", "(", "!", "make_writable_directory", "(", "$", "this", "->", "path", ",", "false", ")", ")", "{", "throw", "new", "coding_exception", "(", "'File store path does not exist and can not be created.'", ")", ";", "}", "if", "(", "$", "createdcfg", ")", "{", "// We re-created it so we'll clean it up.", "unset", "(", "$", "CFG", ")", ";", "}", "}", "return", "true", ";", "}" ]
Checks to make sure that the path for the file cache exists. @return bool @throws coding_exception
[ "Checks", "to", "make", "sure", "that", "the", "path", "for", "the", "file", "cache", "exists", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/file/lib.php#L627-L651
216,330
moodle/moodle
cache/stores/file/lib.php
cachestore_file.write_file
protected function write_file($file, $content) { // Generate a temp file that is going to be unique. We'll rename it at the end to the desired file name. // in this way we avoid partial writes. $path = dirname($file); while (true) { $tempfile = $path.'/'.uniqid(sesskey().'.', true) . '.temp'; if (!file_exists($tempfile)) { break; } } // Open the file with mode=x. This acts to create and open the file for writing only. // If the file already exists this will return false. // We also force binary. $handle = @fopen($tempfile, 'xb+'); if ($handle === false) { // File already exists... lock already exists, return false. return false; } fwrite($handle, $content); fflush($handle); // Close the handle, we're done. fclose($handle); if (md5_file($tempfile) !== md5($content)) { // The md5 of the content of the file must match the md5 of the content given to be written. @unlink($tempfile); return false; } // Finally rename the temp file to the desired file, returning the true|false result. $result = rename($tempfile, $file); @chmod($file, $this->cfg->filepermissions); if (!$result) { // Failed to rename, don't leave files lying around. @unlink($tempfile); } return $result; }
php
protected function write_file($file, $content) { // Generate a temp file that is going to be unique. We'll rename it at the end to the desired file name. // in this way we avoid partial writes. $path = dirname($file); while (true) { $tempfile = $path.'/'.uniqid(sesskey().'.', true) . '.temp'; if (!file_exists($tempfile)) { break; } } // Open the file with mode=x. This acts to create and open the file for writing only. // If the file already exists this will return false. // We also force binary. $handle = @fopen($tempfile, 'xb+'); if ($handle === false) { // File already exists... lock already exists, return false. return false; } fwrite($handle, $content); fflush($handle); // Close the handle, we're done. fclose($handle); if (md5_file($tempfile) !== md5($content)) { // The md5 of the content of the file must match the md5 of the content given to be written. @unlink($tempfile); return false; } // Finally rename the temp file to the desired file, returning the true|false result. $result = rename($tempfile, $file); @chmod($file, $this->cfg->filepermissions); if (!$result) { // Failed to rename, don't leave files lying around. @unlink($tempfile); } return $result; }
[ "protected", "function", "write_file", "(", "$", "file", ",", "$", "content", ")", "{", "// Generate a temp file that is going to be unique. We'll rename it at the end to the desired file name.", "// in this way we avoid partial writes.", "$", "path", "=", "dirname", "(", "$", "file", ")", ";", "while", "(", "true", ")", "{", "$", "tempfile", "=", "$", "path", ".", "'/'", ".", "uniqid", "(", "sesskey", "(", ")", ".", "'.'", ",", "true", ")", ".", "'.temp'", ";", "if", "(", "!", "file_exists", "(", "$", "tempfile", ")", ")", "{", "break", ";", "}", "}", "// Open the file with mode=x. This acts to create and open the file for writing only.", "// If the file already exists this will return false.", "// We also force binary.", "$", "handle", "=", "@", "fopen", "(", "$", "tempfile", ",", "'xb+'", ")", ";", "if", "(", "$", "handle", "===", "false", ")", "{", "// File already exists... lock already exists, return false.", "return", "false", ";", "}", "fwrite", "(", "$", "handle", ",", "$", "content", ")", ";", "fflush", "(", "$", "handle", ")", ";", "// Close the handle, we're done.", "fclose", "(", "$", "handle", ")", ";", "if", "(", "md5_file", "(", "$", "tempfile", ")", "!==", "md5", "(", "$", "content", ")", ")", "{", "// The md5 of the content of the file must match the md5 of the content given to be written.", "@", "unlink", "(", "$", "tempfile", ")", ";", "return", "false", ";", "}", "// Finally rename the temp file to the desired file, returning the true|false result.", "$", "result", "=", "rename", "(", "$", "tempfile", ",", "$", "file", ")", ";", "@", "chmod", "(", "$", "file", ",", "$", "this", "->", "cfg", "->", "filepermissions", ")", ";", "if", "(", "!", "$", "result", ")", "{", "// Failed to rename, don't leave files lying around.", "@", "unlink", "(", "$", "tempfile", ")", ";", "}", "return", "$", "result", ";", "}" ]
Writes your madness to a file. There are several things going on in this function to try to ensure what we don't end up with partial writes etc. 1. Files for writing are opened with the mode xb, the file must be created and can not already exist. 2. Renaming, data is written to a temporary file, where it can be verified using md5 and is then renamed. @param string $file Absolute file path @param string $content The content to write. @return bool
[ "Writes", "your", "madness", "to", "a", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/file/lib.php#L702-L740
216,331
moodle/moodle
cache/stores/file/lib.php
cachestore_file.find_all
public function find_all() { $this->ensure_path_exists(); $files = glob($this->glob_keys_pattern(), GLOB_MARK | GLOB_NOSORT); $return = array(); if ($files === false) { return $return; } foreach ($files as $file) { $return[] = substr(basename($file), 0, -6); } return $return; }
php
public function find_all() { $this->ensure_path_exists(); $files = glob($this->glob_keys_pattern(), GLOB_MARK | GLOB_NOSORT); $return = array(); if ($files === false) { return $return; } foreach ($files as $file) { $return[] = substr(basename($file), 0, -6); } return $return; }
[ "public", "function", "find_all", "(", ")", "{", "$", "this", "->", "ensure_path_exists", "(", ")", ";", "$", "files", "=", "glob", "(", "$", "this", "->", "glob_keys_pattern", "(", ")", ",", "GLOB_MARK", "|", "GLOB_NOSORT", ")", ";", "$", "return", "=", "array", "(", ")", ";", "if", "(", "$", "files", "===", "false", ")", "{", "return", "$", "return", ";", "}", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "return", "[", "]", "=", "substr", "(", "basename", "(", "$", "file", ")", ",", "0", ",", "-", "6", ")", ";", "}", "return", "$", "return", ";", "}" ]
Finds all of the keys being used by this cache store instance. @return array
[ "Finds", "all", "of", "the", "keys", "being", "used", "by", "this", "cache", "store", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/file/lib.php#L755-L766
216,332
moodle/moodle
question/type/calculated/question.php
qtype_calculated_dataset_loader.get_values
public function get_values($itemnumber) { if ($itemnumber <= 0 || $itemnumber > $this->get_number_of_items()) { $a = new stdClass(); $a->id = $this->questionid; $a->item = $itemnumber; throw new moodle_exception('cannotgetdsfordependent', 'question', '', $a); } return $this->load_values($itemnumber); }
php
public function get_values($itemnumber) { if ($itemnumber <= 0 || $itemnumber > $this->get_number_of_items()) { $a = new stdClass(); $a->id = $this->questionid; $a->item = $itemnumber; throw new moodle_exception('cannotgetdsfordependent', 'question', '', $a); } return $this->load_values($itemnumber); }
[ "public", "function", "get_values", "(", "$", "itemnumber", ")", "{", "if", "(", "$", "itemnumber", "<=", "0", "||", "$", "itemnumber", ">", "$", "this", "->", "get_number_of_items", "(", ")", ")", "{", "$", "a", "=", "new", "stdClass", "(", ")", ";", "$", "a", "->", "id", "=", "$", "this", "->", "questionid", ";", "$", "a", "->", "item", "=", "$", "itemnumber", ";", "throw", "new", "moodle_exception", "(", "'cannotgetdsfordependent'", ",", "'question'", ",", "''", ",", "$", "a", ")", ";", "}", "return", "$", "this", "->", "load_values", "(", "$", "itemnumber", ")", ";", "}" ]
Load a particular set of values for each dataset used by this question. @param int $itemnumber which set of values to load. 0 < $itemnumber <= {@link get_number_of_items()}. @return array name => value.
[ "Load", "a", "particular", "set", "of", "values", "for", "each", "dataset", "used", "by", "this", "question", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/question.php#L242-L251
216,333
moodle/moodle
question/type/calculated/question.php
qtype_calculated_variable_substituter.format_float
public function format_float($x, $length = null, $format = null) { if (!is_null($length) && !is_null($format)) { if ($format == '1' ) { // Answer is to have $length decimals. // Decimal places. $x = sprintf('%.' . $length . 'F', $x); } else if ($x) { // Significant figures does only apply if the result is non-zero. $answer = $x; // Convert to positive answer. if ($answer < 0) { $answer = -$answer; $sign = '-'; } else { $sign = ''; } // Determine the format 0.[1-9][0-9]* for the answer... $p10 = 0; while ($answer < 1) { --$p10; $answer *= 10; } while ($answer >= 1) { ++$p10; $answer /= 10; } // ... and have the answer rounded of to the correct length. $answer = round($answer, $length); // If we rounded up to 1.0, place the answer back into 0.[1-9][0-9]* format. if ($answer >= 1) { ++$p10; $answer /= 10; } // Have the answer written on a suitable format. // Either scientific or plain numeric. if (-2 > $p10 || 4 < $p10) { // Use scientific format. $exponent = 'e'.--$p10; $answer *= 10; if (1 == $length) { $x = $sign.$answer.$exponent; } else { // Attach additional zeros at the end of $answer. $answer .= (1 == strlen($answer) ? '.' : '') . '00000000000000000000000000000000000000000x'; $x = $sign .substr($answer, 0, $length +1).$exponent; } } else { // Stick to plain numeric format. $answer *= "1e{$p10}"; if (0.1 <= $answer / "1e{$length}") { $x = $sign.$answer; } else { // Could be an idea to add some zeros here. $answer .= (preg_match('~^[0-9]*$~', $answer) ? '.' : '') . '00000000000000000000000000000000000000000x'; $oklen = $length + ($p10 < 1 ? 2-$p10 : 1); $x = $sign.substr($answer, 0, $oklen); } } } else { $x = 0.0; } } return str_replace('.', $this->decimalpoint, $x); }
php
public function format_float($x, $length = null, $format = null) { if (!is_null($length) && !is_null($format)) { if ($format == '1' ) { // Answer is to have $length decimals. // Decimal places. $x = sprintf('%.' . $length . 'F', $x); } else if ($x) { // Significant figures does only apply if the result is non-zero. $answer = $x; // Convert to positive answer. if ($answer < 0) { $answer = -$answer; $sign = '-'; } else { $sign = ''; } // Determine the format 0.[1-9][0-9]* for the answer... $p10 = 0; while ($answer < 1) { --$p10; $answer *= 10; } while ($answer >= 1) { ++$p10; $answer /= 10; } // ... and have the answer rounded of to the correct length. $answer = round($answer, $length); // If we rounded up to 1.0, place the answer back into 0.[1-9][0-9]* format. if ($answer >= 1) { ++$p10; $answer /= 10; } // Have the answer written on a suitable format. // Either scientific or plain numeric. if (-2 > $p10 || 4 < $p10) { // Use scientific format. $exponent = 'e'.--$p10; $answer *= 10; if (1 == $length) { $x = $sign.$answer.$exponent; } else { // Attach additional zeros at the end of $answer. $answer .= (1 == strlen($answer) ? '.' : '') . '00000000000000000000000000000000000000000x'; $x = $sign .substr($answer, 0, $length +1).$exponent; } } else { // Stick to plain numeric format. $answer *= "1e{$p10}"; if (0.1 <= $answer / "1e{$length}") { $x = $sign.$answer; } else { // Could be an idea to add some zeros here. $answer .= (preg_match('~^[0-9]*$~', $answer) ? '.' : '') . '00000000000000000000000000000000000000000x'; $oklen = $length + ($p10 < 1 ? 2-$p10 : 1); $x = $sign.substr($answer, 0, $oklen); } } } else { $x = 0.0; } } return str_replace('.', $this->decimalpoint, $x); }
[ "public", "function", "format_float", "(", "$", "x", ",", "$", "length", "=", "null", ",", "$", "format", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "length", ")", "&&", "!", "is_null", "(", "$", "format", ")", ")", "{", "if", "(", "$", "format", "==", "'1'", ")", "{", "// Answer is to have $length decimals.", "// Decimal places.", "$", "x", "=", "sprintf", "(", "'%.'", ".", "$", "length", ".", "'F'", ",", "$", "x", ")", ";", "}", "else", "if", "(", "$", "x", ")", "{", "// Significant figures does only apply if the result is non-zero.", "$", "answer", "=", "$", "x", ";", "// Convert to positive answer.", "if", "(", "$", "answer", "<", "0", ")", "{", "$", "answer", "=", "-", "$", "answer", ";", "$", "sign", "=", "'-'", ";", "}", "else", "{", "$", "sign", "=", "''", ";", "}", "// Determine the format 0.[1-9][0-9]* for the answer...", "$", "p10", "=", "0", ";", "while", "(", "$", "answer", "<", "1", ")", "{", "--", "$", "p10", ";", "$", "answer", "*=", "10", ";", "}", "while", "(", "$", "answer", ">=", "1", ")", "{", "++", "$", "p10", ";", "$", "answer", "/=", "10", ";", "}", "// ... and have the answer rounded of to the correct length.", "$", "answer", "=", "round", "(", "$", "answer", ",", "$", "length", ")", ";", "// If we rounded up to 1.0, place the answer back into 0.[1-9][0-9]* format.", "if", "(", "$", "answer", ">=", "1", ")", "{", "++", "$", "p10", ";", "$", "answer", "/=", "10", ";", "}", "// Have the answer written on a suitable format.", "// Either scientific or plain numeric.", "if", "(", "-", "2", ">", "$", "p10", "||", "4", "<", "$", "p10", ")", "{", "// Use scientific format.", "$", "exponent", "=", "'e'", ".", "--", "$", "p10", ";", "$", "answer", "*=", "10", ";", "if", "(", "1", "==", "$", "length", ")", "{", "$", "x", "=", "$", "sign", ".", "$", "answer", ".", "$", "exponent", ";", "}", "else", "{", "// Attach additional zeros at the end of $answer.", "$", "answer", ".=", "(", "1", "==", "strlen", "(", "$", "answer", ")", "?", "'.'", ":", "''", ")", ".", "'00000000000000000000000000000000000000000x'", ";", "$", "x", "=", "$", "sign", ".", "substr", "(", "$", "answer", ",", "0", ",", "$", "length", "+", "1", ")", ".", "$", "exponent", ";", "}", "}", "else", "{", "// Stick to plain numeric format.", "$", "answer", "*=", "\"1e{$p10}\"", ";", "if", "(", "0.1", "<=", "$", "answer", "/", "\"1e{$length}\"", ")", "{", "$", "x", "=", "$", "sign", ".", "$", "answer", ";", "}", "else", "{", "// Could be an idea to add some zeros here.", "$", "answer", ".=", "(", "preg_match", "(", "'~^[0-9]*$~'", ",", "$", "answer", ")", "?", "'.'", ":", "''", ")", ".", "'00000000000000000000000000000000000000000x'", ";", "$", "oklen", "=", "$", "length", "+", "(", "$", "p10", "<", "1", "?", "2", "-", "$", "p10", ":", "1", ")", ";", "$", "x", "=", "$", "sign", ".", "substr", "(", "$", "answer", ",", "0", ",", "$", "oklen", ")", ";", "}", "}", "}", "else", "{", "$", "x", "=", "0.0", ";", "}", "}", "return", "str_replace", "(", "'.'", ",", "$", "this", "->", "decimalpoint", ",", "$", "x", ")", ";", "}" ]
Display a float properly formatted with a certain number of decimal places. @param number $x the number to format @param int $length restrict to this many decimal places or significant figures. If null, the number is not rounded. @param int format 1 => decimalformat, 2 => significantfigures. @return string formtted number.
[ "Display", "a", "float", "properly", "formatted", "with", "a", "certain", "number", "of", "decimal", "places", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/question.php#L337-L406
216,334
moodle/moodle
question/type/calculated/question.php
qtype_calculated_variable_substituter.calculate
public function calculate($expression) { // Make sure no malicious code is present in the expression. Refer MDL-46148 for details. if ($error = qtype_calculated_find_formula_errors($expression)) { throw new moodle_exception('illegalformulasyntax', 'qtype_calculated', '', $error); } $expression = $this->substitute_values_for_eval($expression); if ($datasets = question_bank::get_qtype('calculated')->find_dataset_names($expression)) { // Some placeholders were not substituted. throw new moodle_exception('illegalformulasyntax', 'qtype_calculated', '', '{' . reset($datasets) . '}'); } return $this->calculate_raw($expression); }
php
public function calculate($expression) { // Make sure no malicious code is present in the expression. Refer MDL-46148 for details. if ($error = qtype_calculated_find_formula_errors($expression)) { throw new moodle_exception('illegalformulasyntax', 'qtype_calculated', '', $error); } $expression = $this->substitute_values_for_eval($expression); if ($datasets = question_bank::get_qtype('calculated')->find_dataset_names($expression)) { // Some placeholders were not substituted. throw new moodle_exception('illegalformulasyntax', 'qtype_calculated', '', '{' . reset($datasets) . '}'); } return $this->calculate_raw($expression); }
[ "public", "function", "calculate", "(", "$", "expression", ")", "{", "// Make sure no malicious code is present in the expression. Refer MDL-46148 for details.", "if", "(", "$", "error", "=", "qtype_calculated_find_formula_errors", "(", "$", "expression", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'illegalformulasyntax'", ",", "'qtype_calculated'", ",", "''", ",", "$", "error", ")", ";", "}", "$", "expression", "=", "$", "this", "->", "substitute_values_for_eval", "(", "$", "expression", ")", ";", "if", "(", "$", "datasets", "=", "question_bank", "::", "get_qtype", "(", "'calculated'", ")", "->", "find_dataset_names", "(", "$", "expression", ")", ")", "{", "// Some placeholders were not substituted.", "throw", "new", "moodle_exception", "(", "'illegalformulasyntax'", ",", "'qtype_calculated'", ",", "''", ",", "'{'", ".", "reset", "(", "$", "datasets", ")", ".", "'}'", ")", ";", "}", "return", "$", "this", "->", "calculate_raw", "(", "$", "expression", ")", ";", "}" ]
Evaluate an expression using the variable values. @param string $expression the expression. A PHP expression with placeholders like {a} for where the variables need to go. @return float the computed result.
[ "Evaluate", "an", "expression", "using", "the", "variable", "values", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/question.php#L422-L434
216,335
moodle/moodle
question/type/calculated/question.php
qtype_calculated_variable_substituter.calculate_raw
protected function calculate_raw($expression) { try { // In older PHP versions this this is a way to validate code passed to eval. // The trick came from http://php.net/manual/en/function.eval.php. if (@eval('return true; $result = ' . $expression . ';')) { return eval('return ' . $expression . ';'); } } catch (Throwable $e) { // PHP7 and later now throws ParseException and friends from eval(), // which is much better. } // In either case of an invalid $expression, we end here. throw new moodle_exception('illegalformulasyntax', 'qtype_calculated', '', $expression); }
php
protected function calculate_raw($expression) { try { // In older PHP versions this this is a way to validate code passed to eval. // The trick came from http://php.net/manual/en/function.eval.php. if (@eval('return true; $result = ' . $expression . ';')) { return eval('return ' . $expression . ';'); } } catch (Throwable $e) { // PHP7 and later now throws ParseException and friends from eval(), // which is much better. } // In either case of an invalid $expression, we end here. throw new moodle_exception('illegalformulasyntax', 'qtype_calculated', '', $expression); }
[ "protected", "function", "calculate_raw", "(", "$", "expression", ")", "{", "try", "{", "// In older PHP versions this this is a way to validate code passed to eval.", "// The trick came from http://php.net/manual/en/function.eval.php.", "if", "(", "@", "eval", "(", "'return true; $result = '", ".", "$", "expression", ".", "';'", ")", ")", "{", "return", "eval", "(", "'return '", ".", "$", "expression", ".", "';'", ")", ";", "}", "}", "catch", "(", "Throwable", "$", "e", ")", "{", "// PHP7 and later now throws ParseException and friends from eval(),", "// which is much better.", "}", "// In either case of an invalid $expression, we end here.", "throw", "new", "moodle_exception", "(", "'illegalformulasyntax'", ",", "'qtype_calculated'", ",", "''", ",", "$", "expression", ")", ";", "}" ]
Evaluate an expression after the variable values have been substituted. @param string $expression the expression. A PHP expression with placeholders like {a} for where the variables need to go. @return float the computed result.
[ "Evaluate", "an", "expression", "after", "the", "variable", "values", "have", "been", "substituted", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/question.php#L442-L455
216,336
moodle/moodle
cache/lib.php
cacheable_object_array.prepare_to_cache
final public function prepare_to_cache() { $result = array(); foreach ($this as $key => $value) { if ($value instanceof cacheable_object) { $value = new cache_cached_object($value); } else { throw new coding_exception('Only cacheable_object instances can be added to a cacheable_array'); } $result[$key] = $value; } return $result; }
php
final public function prepare_to_cache() { $result = array(); foreach ($this as $key => $value) { if ($value instanceof cacheable_object) { $value = new cache_cached_object($value); } else { throw new coding_exception('Only cacheable_object instances can be added to a cacheable_array'); } $result[$key] = $value; } return $result; }
[ "final", "public", "function", "prepare_to_cache", "(", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "cacheable_object", ")", "{", "$", "value", "=", "new", "cache_cached_object", "(", "$", "value", ")", ";", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Only cacheable_object instances can be added to a cacheable_array'", ")", ";", "}", "$", "result", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "result", ";", "}" ]
Returns the data to cache for this object. @return array An array of cache_cached_object instances. @throws coding_exception
[ "Returns", "the", "data", "to", "cache", "for", "this", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/lib.php#L197-L208
216,337
moodle/moodle
cache/lib.php
cacheable_object_array.wake_from_cache
final static public function wake_from_cache($data) { if (!is_array($data)) { throw new coding_exception('Invalid data type when reviving cacheable_array data'); } $result = array(); foreach ($data as $key => $value) { $result[$key] = $value->restore_object(); } $class = __CLASS__; return new $class($result); }
php
final static public function wake_from_cache($data) { if (!is_array($data)) { throw new coding_exception('Invalid data type when reviving cacheable_array data'); } $result = array(); foreach ($data as $key => $value) { $result[$key] = $value->restore_object(); } $class = __CLASS__; return new $class($result); }
[ "final", "static", "public", "function", "wake_from_cache", "(", "$", "data", ")", "{", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid data type when reviving cacheable_array data'", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "value", "->", "restore_object", "(", ")", ";", "}", "$", "class", "=", "__CLASS__", ";", "return", "new", "$", "class", "(", "$", "result", ")", ";", "}" ]
Returns the cacheable_object_array that was originally sent to the cache. @param array $data @return cacheable_object_array @throws coding_exception
[ "Returns", "the", "cacheable_object_array", "that", "was", "originally", "sent", "to", "the", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/lib.php#L217-L227
216,338
moodle/moodle
question/format/blackboard_six/formatbase.php
qformat_blackboard_six_base.store_file_for_text_field
protected function store_file_for_text_field(&$text, $tempdir, $filepathinsidetempdir, $filename) { global $USER; $fs = get_file_storage(); if (empty($text['itemid'])) { $text['itemid'] = file_get_unused_draft_itemid(); } // As question file areas don't support subdirs, // convert path to filename. // So that images with same name can be imported. $newfilename = clean_param(str_replace('/', '__', $filepathinsidetempdir . '__' . $filename), PARAM_FILE); $filerecord = array( 'contextid' => context_user::instance($USER->id)->id, 'component' => 'user', 'filearea' => 'draft', 'itemid' => $text['itemid'], 'filepath' => '/', 'filename' => $newfilename, ); $fs->create_file_from_pathname($filerecord, $tempdir . '/' . $filepathinsidetempdir . '/' . $filename); return $newfilename; }
php
protected function store_file_for_text_field(&$text, $tempdir, $filepathinsidetempdir, $filename) { global $USER; $fs = get_file_storage(); if (empty($text['itemid'])) { $text['itemid'] = file_get_unused_draft_itemid(); } // As question file areas don't support subdirs, // convert path to filename. // So that images with same name can be imported. $newfilename = clean_param(str_replace('/', '__', $filepathinsidetempdir . '__' . $filename), PARAM_FILE); $filerecord = array( 'contextid' => context_user::instance($USER->id)->id, 'component' => 'user', 'filearea' => 'draft', 'itemid' => $text['itemid'], 'filepath' => '/', 'filename' => $newfilename, ); $fs->create_file_from_pathname($filerecord, $tempdir . '/' . $filepathinsidetempdir . '/' . $filename); return $newfilename; }
[ "protected", "function", "store_file_for_text_field", "(", "&", "$", "text", ",", "$", "tempdir", ",", "$", "filepathinsidetempdir", ",", "$", "filename", ")", "{", "global", "$", "USER", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "if", "(", "empty", "(", "$", "text", "[", "'itemid'", "]", ")", ")", "{", "$", "text", "[", "'itemid'", "]", "=", "file_get_unused_draft_itemid", "(", ")", ";", "}", "// As question file areas don't support subdirs,", "// convert path to filename.", "// So that images with same name can be imported.", "$", "newfilename", "=", "clean_param", "(", "str_replace", "(", "'/'", ",", "'__'", ",", "$", "filepathinsidetempdir", ".", "'__'", ".", "$", "filename", ")", ",", "PARAM_FILE", ")", ";", "$", "filerecord", "=", "array", "(", "'contextid'", "=>", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", "->", "id", ",", "'component'", "=>", "'user'", ",", "'filearea'", "=>", "'draft'", ",", "'itemid'", "=>", "$", "text", "[", "'itemid'", "]", ",", "'filepath'", "=>", "'/'", ",", "'filename'", "=>", "$", "newfilename", ",", ")", ";", "$", "fs", "->", "create_file_from_pathname", "(", "$", "filerecord", ",", "$", "tempdir", ".", "'/'", ".", "$", "filepathinsidetempdir", ".", "'/'", ".", "$", "filename", ")", ";", "return", "$", "newfilename", ";", "}" ]
Store an image file in a draft filearea @param array $text, if itemid element don't exists it will be created @param string $tempdir path to root of image tree @param string $filepathinsidetempdir path to image in the tree @param string $filename image's name @return string new name of the image as it was stored
[ "Store", "an", "image", "file", "in", "a", "draft", "filearea" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/blackboard_six/formatbase.php#L95-L115
216,339
moodle/moodle
question/format/blackboard_six/formatbase.php
qformat_blackboard_six_base.text_field
public function text_field($text) { $data = array(); // Step one, find all file refs then add to array. preg_match_all('|<img[^>]+src="([^"]*)"|i', $text, $out); // Find all src refs. $filepaths = array(); foreach ($out[1] as $path) { $fullpath = $this->filebase . '/' . $path; if (is_readable($fullpath) && !in_array($path, $filepaths)) { $dirpath = dirname($path); $filename = basename($path); $newfilename = $this->store_file_for_text_field($data, $this->filebase, $dirpath, $filename); $text = preg_replace("|{$path}|", "@@PLUGINFILE@@/" . $newfilename, $text); $filepaths[] = $path; } } $data['text'] = $text; $data['format'] = FORMAT_HTML; return $data; }
php
public function text_field($text) { $data = array(); // Step one, find all file refs then add to array. preg_match_all('|<img[^>]+src="([^"]*)"|i', $text, $out); // Find all src refs. $filepaths = array(); foreach ($out[1] as $path) { $fullpath = $this->filebase . '/' . $path; if (is_readable($fullpath) && !in_array($path, $filepaths)) { $dirpath = dirname($path); $filename = basename($path); $newfilename = $this->store_file_for_text_field($data, $this->filebase, $dirpath, $filename); $text = preg_replace("|{$path}|", "@@PLUGINFILE@@/" . $newfilename, $text); $filepaths[] = $path; } } $data['text'] = $text; $data['format'] = FORMAT_HTML; return $data; }
[ "public", "function", "text_field", "(", "$", "text", ")", "{", "$", "data", "=", "array", "(", ")", ";", "// Step one, find all file refs then add to array.", "preg_match_all", "(", "'|<img[^>]+src=\"([^\"]*)\"|i'", ",", "$", "text", ",", "$", "out", ")", ";", "// Find all src refs.", "$", "filepaths", "=", "array", "(", ")", ";", "foreach", "(", "$", "out", "[", "1", "]", "as", "$", "path", ")", "{", "$", "fullpath", "=", "$", "this", "->", "filebase", ".", "'/'", ".", "$", "path", ";", "if", "(", "is_readable", "(", "$", "fullpath", ")", "&&", "!", "in_array", "(", "$", "path", ",", "$", "filepaths", ")", ")", "{", "$", "dirpath", "=", "dirname", "(", "$", "path", ")", ";", "$", "filename", "=", "basename", "(", "$", "path", ")", ";", "$", "newfilename", "=", "$", "this", "->", "store_file_for_text_field", "(", "$", "data", ",", "$", "this", "->", "filebase", ",", "$", "dirpath", ",", "$", "filename", ")", ";", "$", "text", "=", "preg_replace", "(", "\"|{$path}|\"", ",", "\"@@PLUGINFILE@@/\"", ".", "$", "newfilename", ",", "$", "text", ")", ";", "$", "filepaths", "[", "]", "=", "$", "path", ";", "}", "}", "$", "data", "[", "'text'", "]", "=", "$", "text", ";", "$", "data", "[", "'format'", "]", "=", "FORMAT_HTML", ";", "return", "$", "data", ";", "}" ]
Given an HTML text with references to images files, store all images in a draft filearea, and return an array with all urls in text recoded, format set to FORMAT_HTML, and itemid set to filearea itemid @param string $text text to parse and recode @return array with keys text, format, itemid.
[ "Given", "an", "HTML", "text", "with", "references", "to", "images", "files", "store", "all", "images", "in", "a", "draft", "filearea", "and", "return", "an", "array", "with", "all", "urls", "in", "text", "recoded", "format", "set", "to", "FORMAT_HTML", "and", "itemid", "set", "to", "filearea", "itemid" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/blackboard_six/formatbase.php#L125-L145
216,340
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.flag_expired_contexts
public function flag_expired_contexts() : array { $this->trace->output('Checking requirements'); if (!$this->check_requirements()) { $this->trace->output('Requirements not met. Cannot process expired retentions.', 1); return [0, 0]; } // Clear old and stale records first. $this->trace->output('Clearing obselete records.', 0); static::clear_old_records(); $this->trace->output('Done.', 1); $this->trace->output('Calculating potential course expiries.', 0); $data = static::get_nested_expiry_info_for_courses(); $coursecount = 0; $this->trace->output('Updating course expiry data.', 0); foreach ($data as $expiryrecord) { if ($this->update_from_expiry_info($expiryrecord)) { $coursecount++; } } $this->trace->output('Done.', 1); $this->trace->output('Calculating potential user expiries.', 0); $data = static::get_nested_expiry_info_for_user(); $usercount = 0; $this->trace->output('Updating user expiry data.', 0); foreach ($data as $expiryrecord) { if ($this->update_from_expiry_info($expiryrecord)) { $usercount++; } } $this->trace->output('Done.', 1); return [$coursecount, $usercount]; }
php
public function flag_expired_contexts() : array { $this->trace->output('Checking requirements'); if (!$this->check_requirements()) { $this->trace->output('Requirements not met. Cannot process expired retentions.', 1); return [0, 0]; } // Clear old and stale records first. $this->trace->output('Clearing obselete records.', 0); static::clear_old_records(); $this->trace->output('Done.', 1); $this->trace->output('Calculating potential course expiries.', 0); $data = static::get_nested_expiry_info_for_courses(); $coursecount = 0; $this->trace->output('Updating course expiry data.', 0); foreach ($data as $expiryrecord) { if ($this->update_from_expiry_info($expiryrecord)) { $coursecount++; } } $this->trace->output('Done.', 1); $this->trace->output('Calculating potential user expiries.', 0); $data = static::get_nested_expiry_info_for_user(); $usercount = 0; $this->trace->output('Updating user expiry data.', 0); foreach ($data as $expiryrecord) { if ($this->update_from_expiry_info($expiryrecord)) { $usercount++; } } $this->trace->output('Done.', 1); return [$coursecount, $usercount]; }
[ "public", "function", "flag_expired_contexts", "(", ")", ":", "array", "{", "$", "this", "->", "trace", "->", "output", "(", "'Checking requirements'", ")", ";", "if", "(", "!", "$", "this", "->", "check_requirements", "(", ")", ")", "{", "$", "this", "->", "trace", "->", "output", "(", "'Requirements not met. Cannot process expired retentions.'", ",", "1", ")", ";", "return", "[", "0", ",", "0", "]", ";", "}", "// Clear old and stale records first.", "$", "this", "->", "trace", "->", "output", "(", "'Clearing obselete records.'", ",", "0", ")", ";", "static", "::", "clear_old_records", "(", ")", ";", "$", "this", "->", "trace", "->", "output", "(", "'Done.'", ",", "1", ")", ";", "$", "this", "->", "trace", "->", "output", "(", "'Calculating potential course expiries.'", ",", "0", ")", ";", "$", "data", "=", "static", "::", "get_nested_expiry_info_for_courses", "(", ")", ";", "$", "coursecount", "=", "0", ";", "$", "this", "->", "trace", "->", "output", "(", "'Updating course expiry data.'", ",", "0", ")", ";", "foreach", "(", "$", "data", "as", "$", "expiryrecord", ")", "{", "if", "(", "$", "this", "->", "update_from_expiry_info", "(", "$", "expiryrecord", ")", ")", "{", "$", "coursecount", "++", ";", "}", "}", "$", "this", "->", "trace", "->", "output", "(", "'Done.'", ",", "1", ")", ";", "$", "this", "->", "trace", "->", "output", "(", "'Calculating potential user expiries.'", ",", "0", ")", ";", "$", "data", "=", "static", "::", "get_nested_expiry_info_for_user", "(", ")", ";", "$", "usercount", "=", "0", ";", "$", "this", "->", "trace", "->", "output", "(", "'Updating user expiry data.'", ",", "0", ")", ";", "foreach", "(", "$", "data", "as", "$", "expiryrecord", ")", "{", "if", "(", "$", "this", "->", "update_from_expiry_info", "(", "$", "expiryrecord", ")", ")", "{", "$", "usercount", "++", ";", "}", "}", "$", "this", "->", "trace", "->", "output", "(", "'Done.'", ",", "1", ")", ";", "return", "[", "$", "coursecount", ",", "$", "usercount", "]", ";", "}" ]
Flag expired contexts as expired. @return int[] The number of contexts flagged as expired for courses, and users.
[ "Flag", "expired", "contexts", "as", "expired", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L71-L108
216,341
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.clear_old_records
protected static function clear_old_records() { global $DB; $sql = "SELECT dpctx.* FROM {tool_dataprivacy_ctxexpired} dpctx LEFT JOIN {context} ctx ON ctx.id = dpctx.contextid WHERE ctx.id IS NULL"; $orphaned = $DB->get_recordset_sql($sql); foreach ($orphaned as $orphan) { $expiredcontext = new expired_context(0, $orphan); $expiredcontext->delete(); } // Delete any child of a user context. $parentpath = $DB->sql_concat('ctxuser.path', "'/%'"); $params = [ 'contextuser' => CONTEXT_USER, ]; $sql = "SELECT dpctx.* FROM {tool_dataprivacy_ctxexpired} dpctx WHERE dpctx.contextid IN ( SELECT ctx.id FROM {context} ctxuser JOIN {context} ctx ON ctx.path LIKE {$parentpath} WHERE ctxuser.contextlevel = :contextuser )"; $userchildren = $DB->get_recordset_sql($sql, $params); foreach ($userchildren as $child) { $expiredcontext = new expired_context(0, $child); $expiredcontext->delete(); } }
php
protected static function clear_old_records() { global $DB; $sql = "SELECT dpctx.* FROM {tool_dataprivacy_ctxexpired} dpctx LEFT JOIN {context} ctx ON ctx.id = dpctx.contextid WHERE ctx.id IS NULL"; $orphaned = $DB->get_recordset_sql($sql); foreach ($orphaned as $orphan) { $expiredcontext = new expired_context(0, $orphan); $expiredcontext->delete(); } // Delete any child of a user context. $parentpath = $DB->sql_concat('ctxuser.path', "'/%'"); $params = [ 'contextuser' => CONTEXT_USER, ]; $sql = "SELECT dpctx.* FROM {tool_dataprivacy_ctxexpired} dpctx WHERE dpctx.contextid IN ( SELECT ctx.id FROM {context} ctxuser JOIN {context} ctx ON ctx.path LIKE {$parentpath} WHERE ctxuser.contextlevel = :contextuser )"; $userchildren = $DB->get_recordset_sql($sql, $params); foreach ($userchildren as $child) { $expiredcontext = new expired_context(0, $child); $expiredcontext->delete(); } }
[ "protected", "static", "function", "clear_old_records", "(", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT dpctx.*\n FROM {tool_dataprivacy_ctxexpired} dpctx\n LEFT JOIN {context} ctx ON ctx.id = dpctx.contextid\n WHERE ctx.id IS NULL\"", ";", "$", "orphaned", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ")", ";", "foreach", "(", "$", "orphaned", "as", "$", "orphan", ")", "{", "$", "expiredcontext", "=", "new", "expired_context", "(", "0", ",", "$", "orphan", ")", ";", "$", "expiredcontext", "->", "delete", "(", ")", ";", "}", "// Delete any child of a user context.", "$", "parentpath", "=", "$", "DB", "->", "sql_concat", "(", "'ctxuser.path'", ",", "\"'/%'\"", ")", ";", "$", "params", "=", "[", "'contextuser'", "=>", "CONTEXT_USER", ",", "]", ";", "$", "sql", "=", "\"SELECT dpctx.*\n FROM {tool_dataprivacy_ctxexpired} dpctx\n WHERE dpctx.contextid IN (\n SELECT ctx.id\n FROM {context} ctxuser\n JOIN {context} ctx ON ctx.path LIKE {$parentpath}\n WHERE ctxuser.contextlevel = :contextuser\n )\"", ";", "$", "userchildren", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "foreach", "(", "$", "userchildren", "as", "$", "child", ")", "{", "$", "expiredcontext", "=", "new", "expired_context", "(", "0", ",", "$", "child", ")", ";", "$", "expiredcontext", "->", "delete", "(", ")", ";", "}", "}" ]
Clear old and stale records.
[ "Clear", "old", "and", "stale", "records", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L113-L146
216,342
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.get_nested_expiry_info
protected static function get_nested_expiry_info($contextpath = '') : array { $coursepaths = self::get_nested_expiry_info_for_courses($contextpath); $userpaths = self::get_nested_expiry_info_for_user($contextpath); return array_merge($coursepaths, $userpaths); }
php
protected static function get_nested_expiry_info($contextpath = '') : array { $coursepaths = self::get_nested_expiry_info_for_courses($contextpath); $userpaths = self::get_nested_expiry_info_for_user($contextpath); return array_merge($coursepaths, $userpaths); }
[ "protected", "static", "function", "get_nested_expiry_info", "(", "$", "contextpath", "=", "''", ")", ":", "array", "{", "$", "coursepaths", "=", "self", "::", "get_nested_expiry_info_for_courses", "(", "$", "contextpath", ")", ";", "$", "userpaths", "=", "self", "::", "get_nested_expiry_info_for_user", "(", "$", "contextpath", ")", ";", "return", "array_merge", "(", "$", "coursepaths", ",", "$", "userpaths", ")", ";", "}" ]
Get the full nested set of expiry data relating to all contexts. @param string $contextpath A contexpath to restrict results to @return \stdClass[]
[ "Get", "the", "full", "nested", "set", "of", "expiry", "data", "relating", "to", "all", "contexts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L154-L159
216,343
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.get_nested_expiry_info_for_courses
protected static function get_nested_expiry_info_for_courses($contextpath = '') : array { global $DB; $contextfields = \context_helper::get_preload_record_columns_sql('ctx'); $expiredfields = expired_context::get_sql_fields('expiredctx', 'expiredctx'); $purposefields = 'dpctx.purposeid'; $coursefields = 'ctxcourse.expirydate AS expirydate'; $fields = implode(', ', ['ctx.id', $contextfields, $expiredfields, $coursefields, $purposefields]); // We want all contexts at course-dependant levels. $parentpath = $DB->sql_concat('ctxcourse.path', "'/%'"); // This SQL query returns all course-dependant contexts (including the course context) // which course end date already passed. // This is ordered by the context path in reverse order, which will give the child nodes before any parent node. $params = [ 'contextlevel' => CONTEXT_COURSE, ]; $where = ''; if (!empty($contextpath)) { $where = "WHERE (ctx.path = :pathmatchexact OR ctx.path LIKE :pathmatchchildren)"; $params['pathmatchexact'] = $contextpath; $params['pathmatchchildren'] = "{$contextpath}/%"; } $sql = "SELECT $fields FROM {context} ctx JOIN ( SELECT c.enddate AS expirydate, subctx.path FROM {context} subctx JOIN {course} c ON subctx.contextlevel = :contextlevel AND subctx.instanceid = c.id AND c.format != 'site' ) ctxcourse ON ctx.path LIKE {$parentpath} OR ctx.path = ctxcourse.path LEFT JOIN {tool_dataprivacy_ctxinstance} dpctx ON dpctx.contextid = ctx.id LEFT JOIN {tool_dataprivacy_ctxexpired} expiredctx ON ctx.id = expiredctx.contextid {$where} ORDER BY ctx.path DESC"; return self::get_nested_expiry_info_from_sql($sql, $params); }
php
protected static function get_nested_expiry_info_for_courses($contextpath = '') : array { global $DB; $contextfields = \context_helper::get_preload_record_columns_sql('ctx'); $expiredfields = expired_context::get_sql_fields('expiredctx', 'expiredctx'); $purposefields = 'dpctx.purposeid'; $coursefields = 'ctxcourse.expirydate AS expirydate'; $fields = implode(', ', ['ctx.id', $contextfields, $expiredfields, $coursefields, $purposefields]); // We want all contexts at course-dependant levels. $parentpath = $DB->sql_concat('ctxcourse.path', "'/%'"); // This SQL query returns all course-dependant contexts (including the course context) // which course end date already passed. // This is ordered by the context path in reverse order, which will give the child nodes before any parent node. $params = [ 'contextlevel' => CONTEXT_COURSE, ]; $where = ''; if (!empty($contextpath)) { $where = "WHERE (ctx.path = :pathmatchexact OR ctx.path LIKE :pathmatchchildren)"; $params['pathmatchexact'] = $contextpath; $params['pathmatchchildren'] = "{$contextpath}/%"; } $sql = "SELECT $fields FROM {context} ctx JOIN ( SELECT c.enddate AS expirydate, subctx.path FROM {context} subctx JOIN {course} c ON subctx.contextlevel = :contextlevel AND subctx.instanceid = c.id AND c.format != 'site' ) ctxcourse ON ctx.path LIKE {$parentpath} OR ctx.path = ctxcourse.path LEFT JOIN {tool_dataprivacy_ctxinstance} dpctx ON dpctx.contextid = ctx.id LEFT JOIN {tool_dataprivacy_ctxexpired} expiredctx ON ctx.id = expiredctx.contextid {$where} ORDER BY ctx.path DESC"; return self::get_nested_expiry_info_from_sql($sql, $params); }
[ "protected", "static", "function", "get_nested_expiry_info_for_courses", "(", "$", "contextpath", "=", "''", ")", ":", "array", "{", "global", "$", "DB", ";", "$", "contextfields", "=", "\\", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ";", "$", "expiredfields", "=", "expired_context", "::", "get_sql_fields", "(", "'expiredctx'", ",", "'expiredctx'", ")", ";", "$", "purposefields", "=", "'dpctx.purposeid'", ";", "$", "coursefields", "=", "'ctxcourse.expirydate AS expirydate'", ";", "$", "fields", "=", "implode", "(", "', '", ",", "[", "'ctx.id'", ",", "$", "contextfields", ",", "$", "expiredfields", ",", "$", "coursefields", ",", "$", "purposefields", "]", ")", ";", "// We want all contexts at course-dependant levels.", "$", "parentpath", "=", "$", "DB", "->", "sql_concat", "(", "'ctxcourse.path'", ",", "\"'/%'\"", ")", ";", "// This SQL query returns all course-dependant contexts (including the course context)", "// which course end date already passed.", "// This is ordered by the context path in reverse order, which will give the child nodes before any parent node.", "$", "params", "=", "[", "'contextlevel'", "=>", "CONTEXT_COURSE", ",", "]", ";", "$", "where", "=", "''", ";", "if", "(", "!", "empty", "(", "$", "contextpath", ")", ")", "{", "$", "where", "=", "\"WHERE (ctx.path = :pathmatchexact OR ctx.path LIKE :pathmatchchildren)\"", ";", "$", "params", "[", "'pathmatchexact'", "]", "=", "$", "contextpath", ";", "$", "params", "[", "'pathmatchchildren'", "]", "=", "\"{$contextpath}/%\"", ";", "}", "$", "sql", "=", "\"SELECT $fields\n FROM {context} ctx\n JOIN (\n SELECT c.enddate AS expirydate, subctx.path\n FROM {context} subctx\n JOIN {course} c\n ON subctx.contextlevel = :contextlevel\n AND subctx.instanceid = c.id\n AND c.format != 'site'\n ) ctxcourse\n ON ctx.path LIKE {$parentpath} OR ctx.path = ctxcourse.path\n LEFT JOIN {tool_dataprivacy_ctxinstance} dpctx\n ON dpctx.contextid = ctx.id\n LEFT JOIN {tool_dataprivacy_ctxexpired} expiredctx\n ON ctx.id = expiredctx.contextid\n {$where}\n ORDER BY ctx.path DESC\"", ";", "return", "self", "::", "get_nested_expiry_info_from_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Get the full nested set of expiry data relating to course-related contexts. @param string $contextpath A contexpath to restrict results to @return \stdClass[]
[ "Get", "the", "full", "nested", "set", "of", "expiry", "data", "relating", "to", "course", "-", "related", "contexts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L167-L212
216,344
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.get_nested_expiry_info_for_user
protected static function get_nested_expiry_info_for_user($contextpath = '') : array { global $DB; $contextfields = \context_helper::get_preload_record_columns_sql('ctx'); $expiredfields = expired_context::get_sql_fields('expiredctx', 'expiredctx'); $purposefields = 'dpctx.purposeid'; $userfields = 'u.lastaccess AS expirydate'; $fields = implode(', ', ['ctx.id', $contextfields, $expiredfields, $userfields, $purposefields]); // We want all contexts at user-dependant levels. $parentpath = $DB->sql_concat('ctxuser.path', "'/%'"); // This SQL query returns all user-dependant contexts (including the user context) // This is ordered by the context path in reverse order, which will give the child nodes before any parent node. $params = [ 'contextlevel' => CONTEXT_USER, ]; $where = ''; if (!empty($contextpath)) { $where = "AND ctx.path = :pathmatchexact"; $params['pathmatchexact'] = $contextpath; } $sql = "SELECT $fields, u.deleted AS userdeleted FROM {context} ctx JOIN {user} u ON ctx.instanceid = u.id LEFT JOIN {tool_dataprivacy_ctxinstance} dpctx ON dpctx.contextid = ctx.id LEFT JOIN {tool_dataprivacy_ctxexpired} expiredctx ON ctx.id = expiredctx.contextid WHERE ctx.contextlevel = :contextlevel {$where} ORDER BY ctx.path DESC"; return self::get_nested_expiry_info_from_sql($sql, $params); }
php
protected static function get_nested_expiry_info_for_user($contextpath = '') : array { global $DB; $contextfields = \context_helper::get_preload_record_columns_sql('ctx'); $expiredfields = expired_context::get_sql_fields('expiredctx', 'expiredctx'); $purposefields = 'dpctx.purposeid'; $userfields = 'u.lastaccess AS expirydate'; $fields = implode(', ', ['ctx.id', $contextfields, $expiredfields, $userfields, $purposefields]); // We want all contexts at user-dependant levels. $parentpath = $DB->sql_concat('ctxuser.path', "'/%'"); // This SQL query returns all user-dependant contexts (including the user context) // This is ordered by the context path in reverse order, which will give the child nodes before any parent node. $params = [ 'contextlevel' => CONTEXT_USER, ]; $where = ''; if (!empty($contextpath)) { $where = "AND ctx.path = :pathmatchexact"; $params['pathmatchexact'] = $contextpath; } $sql = "SELECT $fields, u.deleted AS userdeleted FROM {context} ctx JOIN {user} u ON ctx.instanceid = u.id LEFT JOIN {tool_dataprivacy_ctxinstance} dpctx ON dpctx.contextid = ctx.id LEFT JOIN {tool_dataprivacy_ctxexpired} expiredctx ON ctx.id = expiredctx.contextid WHERE ctx.contextlevel = :contextlevel {$where} ORDER BY ctx.path DESC"; return self::get_nested_expiry_info_from_sql($sql, $params); }
[ "protected", "static", "function", "get_nested_expiry_info_for_user", "(", "$", "contextpath", "=", "''", ")", ":", "array", "{", "global", "$", "DB", ";", "$", "contextfields", "=", "\\", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ";", "$", "expiredfields", "=", "expired_context", "::", "get_sql_fields", "(", "'expiredctx'", ",", "'expiredctx'", ")", ";", "$", "purposefields", "=", "'dpctx.purposeid'", ";", "$", "userfields", "=", "'u.lastaccess AS expirydate'", ";", "$", "fields", "=", "implode", "(", "', '", ",", "[", "'ctx.id'", ",", "$", "contextfields", ",", "$", "expiredfields", ",", "$", "userfields", ",", "$", "purposefields", "]", ")", ";", "// We want all contexts at user-dependant levels.", "$", "parentpath", "=", "$", "DB", "->", "sql_concat", "(", "'ctxuser.path'", ",", "\"'/%'\"", ")", ";", "// This SQL query returns all user-dependant contexts (including the user context)", "// This is ordered by the context path in reverse order, which will give the child nodes before any parent node.", "$", "params", "=", "[", "'contextlevel'", "=>", "CONTEXT_USER", ",", "]", ";", "$", "where", "=", "''", ";", "if", "(", "!", "empty", "(", "$", "contextpath", ")", ")", "{", "$", "where", "=", "\"AND ctx.path = :pathmatchexact\"", ";", "$", "params", "[", "'pathmatchexact'", "]", "=", "$", "contextpath", ";", "}", "$", "sql", "=", "\"SELECT $fields, u.deleted AS userdeleted\n FROM {context} ctx\n JOIN {user} u ON ctx.instanceid = u.id\n LEFT JOIN {tool_dataprivacy_ctxinstance} dpctx\n ON dpctx.contextid = ctx.id\n LEFT JOIN {tool_dataprivacy_ctxexpired} expiredctx\n ON ctx.id = expiredctx.contextid\n WHERE ctx.contextlevel = :contextlevel {$where}\n ORDER BY ctx.path DESC\"", ";", "return", "self", "::", "get_nested_expiry_info_from_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Get the full nested set of expiry data. @param string $contextpath A contexpath to restrict results to @return \stdClass[]
[ "Get", "the", "full", "nested", "set", "of", "expiry", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L220-L255
216,345
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.get_nested_expiry_info_from_sql
protected static function get_nested_expiry_info_from_sql(string $sql, array $params) : array { global $DB; $fulllist = $DB->get_recordset_sql($sql, $params); $datalist = []; $expiredcontents = []; $pathstoskip = []; $userpurpose = data_registry::get_effective_contextlevel_value(CONTEXT_USER, 'purpose'); foreach ($fulllist as $record) { \context_helper::preload_from_record($record); $context = \context::instance_by_id($record->id, false); if (!self::is_eligible_for_deletion($pathstoskip, $context)) { // We should skip this context, and therefore all of it's children. $datalist = array_filter($datalist, function($data, $path) use ($context) { // Remove any child of this context. // Technically this should never be fulfilled because the query is ordered in path DESC, but is kept // in to be certain. return (false === strpos($path, "{$context->path}/")); }, ARRAY_FILTER_USE_BOTH); if ($record->expiredctxid) { // There was previously an expired context record. // Delete it to be on the safe side. $expiredcontext = new expired_context(null, expired_context::extract_record($record, 'expiredctx')); $expiredcontext->delete(); } continue; } if ($context instanceof \context_user) { $purpose = $userpurpose; } else { $purposevalue = $record->purposeid !== null ? $record->purposeid : context_instance::NOTSET; $purpose = api::get_effective_context_purpose($context, $purposevalue); } if ($context instanceof \context_user && !empty($record->userdeleted)) { $expiryinfo = static::get_expiry_info($purpose, $record->userdeleted); } else { $expiryinfo = static::get_expiry_info($purpose, $record->expirydate); } foreach ($datalist as $path => $data) { // Merge with already-processed children. if (strpos($path, $context->path) !== 0) { continue; } $expiryinfo->merge_with_child($data->info); } $datalist[$context->path] = (object) [ 'context' => $context, 'record' => $record, 'purpose' => $purpose, 'info' => $expiryinfo, ]; } $fulllist->close(); return $datalist; }
php
protected static function get_nested_expiry_info_from_sql(string $sql, array $params) : array { global $DB; $fulllist = $DB->get_recordset_sql($sql, $params); $datalist = []; $expiredcontents = []; $pathstoskip = []; $userpurpose = data_registry::get_effective_contextlevel_value(CONTEXT_USER, 'purpose'); foreach ($fulllist as $record) { \context_helper::preload_from_record($record); $context = \context::instance_by_id($record->id, false); if (!self::is_eligible_for_deletion($pathstoskip, $context)) { // We should skip this context, and therefore all of it's children. $datalist = array_filter($datalist, function($data, $path) use ($context) { // Remove any child of this context. // Technically this should never be fulfilled because the query is ordered in path DESC, but is kept // in to be certain. return (false === strpos($path, "{$context->path}/")); }, ARRAY_FILTER_USE_BOTH); if ($record->expiredctxid) { // There was previously an expired context record. // Delete it to be on the safe side. $expiredcontext = new expired_context(null, expired_context::extract_record($record, 'expiredctx')); $expiredcontext->delete(); } continue; } if ($context instanceof \context_user) { $purpose = $userpurpose; } else { $purposevalue = $record->purposeid !== null ? $record->purposeid : context_instance::NOTSET; $purpose = api::get_effective_context_purpose($context, $purposevalue); } if ($context instanceof \context_user && !empty($record->userdeleted)) { $expiryinfo = static::get_expiry_info($purpose, $record->userdeleted); } else { $expiryinfo = static::get_expiry_info($purpose, $record->expirydate); } foreach ($datalist as $path => $data) { // Merge with already-processed children. if (strpos($path, $context->path) !== 0) { continue; } $expiryinfo->merge_with_child($data->info); } $datalist[$context->path] = (object) [ 'context' => $context, 'record' => $record, 'purpose' => $purpose, 'info' => $expiryinfo, ]; } $fulllist->close(); return $datalist; }
[ "protected", "static", "function", "get_nested_expiry_info_from_sql", "(", "string", "$", "sql", ",", "array", "$", "params", ")", ":", "array", "{", "global", "$", "DB", ";", "$", "fulllist", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "datalist", "=", "[", "]", ";", "$", "expiredcontents", "=", "[", "]", ";", "$", "pathstoskip", "=", "[", "]", ";", "$", "userpurpose", "=", "data_registry", "::", "get_effective_contextlevel_value", "(", "CONTEXT_USER", ",", "'purpose'", ")", ";", "foreach", "(", "$", "fulllist", "as", "$", "record", ")", "{", "\\", "context_helper", "::", "preload_from_record", "(", "$", "record", ")", ";", "$", "context", "=", "\\", "context", "::", "instance_by_id", "(", "$", "record", "->", "id", ",", "false", ")", ";", "if", "(", "!", "self", "::", "is_eligible_for_deletion", "(", "$", "pathstoskip", ",", "$", "context", ")", ")", "{", "// We should skip this context, and therefore all of it's children.", "$", "datalist", "=", "array_filter", "(", "$", "datalist", ",", "function", "(", "$", "data", ",", "$", "path", ")", "use", "(", "$", "context", ")", "{", "// Remove any child of this context.", "// Technically this should never be fulfilled because the query is ordered in path DESC, but is kept", "// in to be certain.", "return", "(", "false", "===", "strpos", "(", "$", "path", ",", "\"{$context->path}/\"", ")", ")", ";", "}", ",", "ARRAY_FILTER_USE_BOTH", ")", ";", "if", "(", "$", "record", "->", "expiredctxid", ")", "{", "// There was previously an expired context record.", "// Delete it to be on the safe side.", "$", "expiredcontext", "=", "new", "expired_context", "(", "null", ",", "expired_context", "::", "extract_record", "(", "$", "record", ",", "'expiredctx'", ")", ")", ";", "$", "expiredcontext", "->", "delete", "(", ")", ";", "}", "continue", ";", "}", "if", "(", "$", "context", "instanceof", "\\", "context_user", ")", "{", "$", "purpose", "=", "$", "userpurpose", ";", "}", "else", "{", "$", "purposevalue", "=", "$", "record", "->", "purposeid", "!==", "null", "?", "$", "record", "->", "purposeid", ":", "context_instance", "::", "NOTSET", ";", "$", "purpose", "=", "api", "::", "get_effective_context_purpose", "(", "$", "context", ",", "$", "purposevalue", ")", ";", "}", "if", "(", "$", "context", "instanceof", "\\", "context_user", "&&", "!", "empty", "(", "$", "record", "->", "userdeleted", ")", ")", "{", "$", "expiryinfo", "=", "static", "::", "get_expiry_info", "(", "$", "purpose", ",", "$", "record", "->", "userdeleted", ")", ";", "}", "else", "{", "$", "expiryinfo", "=", "static", "::", "get_expiry_info", "(", "$", "purpose", ",", "$", "record", "->", "expirydate", ")", ";", "}", "foreach", "(", "$", "datalist", "as", "$", "path", "=>", "$", "data", ")", "{", "// Merge with already-processed children.", "if", "(", "strpos", "(", "$", "path", ",", "$", "context", "->", "path", ")", "!==", "0", ")", "{", "continue", ";", "}", "$", "expiryinfo", "->", "merge_with_child", "(", "$", "data", "->", "info", ")", ";", "}", "$", "datalist", "[", "$", "context", "->", "path", "]", "=", "(", "object", ")", "[", "'context'", "=>", "$", "context", ",", "'record'", "=>", "$", "record", ",", "'purpose'", "=>", "$", "purpose", ",", "'info'", "=>", "$", "expiryinfo", ",", "]", ";", "}", "$", "fulllist", "->", "close", "(", ")", ";", "return", "$", "datalist", ";", "}" ]
Get the full nested set of expiry data given appropriate SQL. Only contexts which have expired will be included. @param string $sql The SQL used to select the nested information. @param array $params The params required by the SQL. @return \stdClass[]
[ "Get", "the", "full", "nested", "set", "of", "expiry", "data", "given", "appropriate", "SQL", ".", "Only", "contexts", "which", "have", "expired", "will", "be", "included", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L265-L328
216,346
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.is_eligible_for_deletion
protected static function is_eligible_for_deletion(array &$pathstoskip, \context $context) : bool { $shouldskip = false; // Check whether any of the child contexts are ineligble. $shouldskip = !empty(array_filter($pathstoskip, function($path) use ($context) { // If any child context has already been skipped then it will appear in this list. // Since paths include parents, test if the context under test appears as the haystack in the skipped // context's needle. return false !== (strpos($context->path, $path)); })); if (!$shouldskip && $context instanceof \context_user) { $shouldskip = !self::are_user_context_dependencies_expired($context); } if ($shouldskip) { // Add this to the list of contexts to skip for parentage checks. $pathstoskip[] = $context->path; } return !$shouldskip; }
php
protected static function is_eligible_for_deletion(array &$pathstoskip, \context $context) : bool { $shouldskip = false; // Check whether any of the child contexts are ineligble. $shouldskip = !empty(array_filter($pathstoskip, function($path) use ($context) { // If any child context has already been skipped then it will appear in this list. // Since paths include parents, test if the context under test appears as the haystack in the skipped // context's needle. return false !== (strpos($context->path, $path)); })); if (!$shouldskip && $context instanceof \context_user) { $shouldskip = !self::are_user_context_dependencies_expired($context); } if ($shouldskip) { // Add this to the list of contexts to skip for parentage checks. $pathstoskip[] = $context->path; } return !$shouldskip; }
[ "protected", "static", "function", "is_eligible_for_deletion", "(", "array", "&", "$", "pathstoskip", ",", "\\", "context", "$", "context", ")", ":", "bool", "{", "$", "shouldskip", "=", "false", ";", "// Check whether any of the child contexts are ineligble.", "$", "shouldskip", "=", "!", "empty", "(", "array_filter", "(", "$", "pathstoskip", ",", "function", "(", "$", "path", ")", "use", "(", "$", "context", ")", "{", "// If any child context has already been skipped then it will appear in this list.", "// Since paths include parents, test if the context under test appears as the haystack in the skipped", "// context's needle.", "return", "false", "!==", "(", "strpos", "(", "$", "context", "->", "path", ",", "$", "path", ")", ")", ";", "}", ")", ")", ";", "if", "(", "!", "$", "shouldskip", "&&", "$", "context", "instanceof", "\\", "context_user", ")", "{", "$", "shouldskip", "=", "!", "self", "::", "are_user_context_dependencies_expired", "(", "$", "context", ")", ";", "}", "if", "(", "$", "shouldskip", ")", "{", "// Add this to the list of contexts to skip for parentage checks.", "$", "pathstoskip", "[", "]", "=", "$", "context", "->", "path", ";", "}", "return", "!", "$", "shouldskip", ";", "}" ]
Check whether the supplied context would be elible for deletion. @param array $pathstoskip A set of paths which should be skipped @param \context $context @return bool
[ "Check", "whether", "the", "supplied", "context", "would", "be", "elible", "for", "deletion", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L337-L357
216,347
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.process_approved_deletions
public function process_approved_deletions() : array { $this->trace->output('Checking requirements'); if (!$this->check_requirements()) { $this->trace->output('Requirements not met. Cannot process expired retentions.', 1); return [0, 0]; } $this->trace->output('Fetching all approved and expired contexts for deletion.'); $expiredcontexts = expired_context::get_records(['status' => expired_context::STATUS_APPROVED]); $this->trace->output('Done.', 1); $totalprocessed = 0; $usercount = 0; $coursecount = 0; foreach ($expiredcontexts as $expiredctx) { $context = \context::instance_by_id($expiredctx->get('contextid'), IGNORE_MISSING); if (empty($context)) { // Unable to process this request further. // We have no context to delete. $expiredctx->delete(); continue; } $this->trace->output("Deleting data for " . $context->get_context_name(), 2); if ($this->delete_expired_context($expiredctx)) { $this->trace->output("Done.", 3); if ($context instanceof \context_user) { $usercount++; } else { $coursecount++; } $totalprocessed++; if ($totalprocessed >= $this->get_delete_limit()) { break; } } } return [$coursecount, $usercount]; }
php
public function process_approved_deletions() : array { $this->trace->output('Checking requirements'); if (!$this->check_requirements()) { $this->trace->output('Requirements not met. Cannot process expired retentions.', 1); return [0, 0]; } $this->trace->output('Fetching all approved and expired contexts for deletion.'); $expiredcontexts = expired_context::get_records(['status' => expired_context::STATUS_APPROVED]); $this->trace->output('Done.', 1); $totalprocessed = 0; $usercount = 0; $coursecount = 0; foreach ($expiredcontexts as $expiredctx) { $context = \context::instance_by_id($expiredctx->get('contextid'), IGNORE_MISSING); if (empty($context)) { // Unable to process this request further. // We have no context to delete. $expiredctx->delete(); continue; } $this->trace->output("Deleting data for " . $context->get_context_name(), 2); if ($this->delete_expired_context($expiredctx)) { $this->trace->output("Done.", 3); if ($context instanceof \context_user) { $usercount++; } else { $coursecount++; } $totalprocessed++; if ($totalprocessed >= $this->get_delete_limit()) { break; } } } return [$coursecount, $usercount]; }
[ "public", "function", "process_approved_deletions", "(", ")", ":", "array", "{", "$", "this", "->", "trace", "->", "output", "(", "'Checking requirements'", ")", ";", "if", "(", "!", "$", "this", "->", "check_requirements", "(", ")", ")", "{", "$", "this", "->", "trace", "->", "output", "(", "'Requirements not met. Cannot process expired retentions.'", ",", "1", ")", ";", "return", "[", "0", ",", "0", "]", ";", "}", "$", "this", "->", "trace", "->", "output", "(", "'Fetching all approved and expired contexts for deletion.'", ")", ";", "$", "expiredcontexts", "=", "expired_context", "::", "get_records", "(", "[", "'status'", "=>", "expired_context", "::", "STATUS_APPROVED", "]", ")", ";", "$", "this", "->", "trace", "->", "output", "(", "'Done.'", ",", "1", ")", ";", "$", "totalprocessed", "=", "0", ";", "$", "usercount", "=", "0", ";", "$", "coursecount", "=", "0", ";", "foreach", "(", "$", "expiredcontexts", "as", "$", "expiredctx", ")", "{", "$", "context", "=", "\\", "context", "::", "instance_by_id", "(", "$", "expiredctx", "->", "get", "(", "'contextid'", ")", ",", "IGNORE_MISSING", ")", ";", "if", "(", "empty", "(", "$", "context", ")", ")", "{", "// Unable to process this request further.", "// We have no context to delete.", "$", "expiredctx", "->", "delete", "(", ")", ";", "continue", ";", "}", "$", "this", "->", "trace", "->", "output", "(", "\"Deleting data for \"", ".", "$", "context", "->", "get_context_name", "(", ")", ",", "2", ")", ";", "if", "(", "$", "this", "->", "delete_expired_context", "(", "$", "expiredctx", ")", ")", "{", "$", "this", "->", "trace", "->", "output", "(", "\"Done.\"", ",", "3", ")", ";", "if", "(", "$", "context", "instanceof", "\\", "context_user", ")", "{", "$", "usercount", "++", ";", "}", "else", "{", "$", "coursecount", "++", ";", "}", "$", "totalprocessed", "++", ";", "if", "(", "$", "totalprocessed", ">=", "$", "this", "->", "get_delete_limit", "(", ")", ")", "{", "break", ";", "}", "}", "}", "return", "[", "$", "coursecount", ",", "$", "usercount", "]", ";", "}" ]
Deletes the expired contexts. @return int[] The number of deleted contexts.
[ "Deletes", "the", "expired", "contexts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L364-L404
216,348
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.delete_expired_context
protected function delete_expired_context(expired_context $expiredctx) { $context = \context::instance_by_id($expiredctx->get('contextid')); $this->get_progress()->output("Deleting context {$context->id} - " . $context->get_context_name(true, true)); // Update the expired_context and verify that it is still ready for deletion. $expiredctx = $this->update_expired_context($expiredctx); if (empty($expiredctx)) { $this->get_progress()->output("Context has changed since approval and is no longer pending approval. Skipping", 1); return false; } if (!$expiredctx->can_process_deletion()) { // This only happens if the record was updated after being first fetched. $this->get_progress()->output("Context has changed since approval and must be re-approved. Skipping", 1); $expiredctx->set('status', expired_context::STATUS_EXPIRED); $expiredctx->save(); return false; } $privacymanager = $this->get_privacy_manager(); if ($expiredctx->is_fully_expired()) { if ($context instanceof \context_user) { $this->delete_expired_user_context($expiredctx); } else { // This context is fully expired - that is that the default retention period has been reached, and there are // no remaining overrides. $privacymanager->delete_data_for_all_users_in_context($context); } // Mark the record as cleaned. $expiredctx->set('status', expired_context::STATUS_CLEANED); $expiredctx->save(); return $context; } // We need to find all users in the context, and delete just those who have expired. $collection = $privacymanager->get_users_in_context($context); // Apply the expired and unexpired filters to remove the users in these categories. $userassignments = $this->get_role_users_for_expired_context($expiredctx, $context); $approvedcollection = new \core_privacy\local\request\userlist_collection($context); foreach ($collection as $pendinguserlist) { $userlist = filtered_userlist::create_from_userlist($pendinguserlist); $userlist->apply_expired_context_filters($userassignments->expired, $userassignments->unexpired); if (count($userlist)) { $approvedcollection->add_userlist($userlist); } } if (count($approvedcollection)) { // Perform the deletion with the newly approved collection. $privacymanager->delete_data_for_users_in_context($approvedcollection); } // Mark the record as cleaned. $expiredctx->set('status', expired_context::STATUS_CLEANED); $expiredctx->save(); return $context; }
php
protected function delete_expired_context(expired_context $expiredctx) { $context = \context::instance_by_id($expiredctx->get('contextid')); $this->get_progress()->output("Deleting context {$context->id} - " . $context->get_context_name(true, true)); // Update the expired_context and verify that it is still ready for deletion. $expiredctx = $this->update_expired_context($expiredctx); if (empty($expiredctx)) { $this->get_progress()->output("Context has changed since approval and is no longer pending approval. Skipping", 1); return false; } if (!$expiredctx->can_process_deletion()) { // This only happens if the record was updated after being first fetched. $this->get_progress()->output("Context has changed since approval and must be re-approved. Skipping", 1); $expiredctx->set('status', expired_context::STATUS_EXPIRED); $expiredctx->save(); return false; } $privacymanager = $this->get_privacy_manager(); if ($expiredctx->is_fully_expired()) { if ($context instanceof \context_user) { $this->delete_expired_user_context($expiredctx); } else { // This context is fully expired - that is that the default retention period has been reached, and there are // no remaining overrides. $privacymanager->delete_data_for_all_users_in_context($context); } // Mark the record as cleaned. $expiredctx->set('status', expired_context::STATUS_CLEANED); $expiredctx->save(); return $context; } // We need to find all users in the context, and delete just those who have expired. $collection = $privacymanager->get_users_in_context($context); // Apply the expired and unexpired filters to remove the users in these categories. $userassignments = $this->get_role_users_for_expired_context($expiredctx, $context); $approvedcollection = new \core_privacy\local\request\userlist_collection($context); foreach ($collection as $pendinguserlist) { $userlist = filtered_userlist::create_from_userlist($pendinguserlist); $userlist->apply_expired_context_filters($userassignments->expired, $userassignments->unexpired); if (count($userlist)) { $approvedcollection->add_userlist($userlist); } } if (count($approvedcollection)) { // Perform the deletion with the newly approved collection. $privacymanager->delete_data_for_users_in_context($approvedcollection); } // Mark the record as cleaned. $expiredctx->set('status', expired_context::STATUS_CLEANED); $expiredctx->save(); return $context; }
[ "protected", "function", "delete_expired_context", "(", "expired_context", "$", "expiredctx", ")", "{", "$", "context", "=", "\\", "context", "::", "instance_by_id", "(", "$", "expiredctx", "->", "get", "(", "'contextid'", ")", ")", ";", "$", "this", "->", "get_progress", "(", ")", "->", "output", "(", "\"Deleting context {$context->id} - \"", ".", "$", "context", "->", "get_context_name", "(", "true", ",", "true", ")", ")", ";", "// Update the expired_context and verify that it is still ready for deletion.", "$", "expiredctx", "=", "$", "this", "->", "update_expired_context", "(", "$", "expiredctx", ")", ";", "if", "(", "empty", "(", "$", "expiredctx", ")", ")", "{", "$", "this", "->", "get_progress", "(", ")", "->", "output", "(", "\"Context has changed since approval and is no longer pending approval. Skipping\"", ",", "1", ")", ";", "return", "false", ";", "}", "if", "(", "!", "$", "expiredctx", "->", "can_process_deletion", "(", ")", ")", "{", "// This only happens if the record was updated after being first fetched.", "$", "this", "->", "get_progress", "(", ")", "->", "output", "(", "\"Context has changed since approval and must be re-approved. Skipping\"", ",", "1", ")", ";", "$", "expiredctx", "->", "set", "(", "'status'", ",", "expired_context", "::", "STATUS_EXPIRED", ")", ";", "$", "expiredctx", "->", "save", "(", ")", ";", "return", "false", ";", "}", "$", "privacymanager", "=", "$", "this", "->", "get_privacy_manager", "(", ")", ";", "if", "(", "$", "expiredctx", "->", "is_fully_expired", "(", ")", ")", "{", "if", "(", "$", "context", "instanceof", "\\", "context_user", ")", "{", "$", "this", "->", "delete_expired_user_context", "(", "$", "expiredctx", ")", ";", "}", "else", "{", "// This context is fully expired - that is that the default retention period has been reached, and there are", "// no remaining overrides.", "$", "privacymanager", "->", "delete_data_for_all_users_in_context", "(", "$", "context", ")", ";", "}", "// Mark the record as cleaned.", "$", "expiredctx", "->", "set", "(", "'status'", ",", "expired_context", "::", "STATUS_CLEANED", ")", ";", "$", "expiredctx", "->", "save", "(", ")", ";", "return", "$", "context", ";", "}", "// We need to find all users in the context, and delete just those who have expired.", "$", "collection", "=", "$", "privacymanager", "->", "get_users_in_context", "(", "$", "context", ")", ";", "// Apply the expired and unexpired filters to remove the users in these categories.", "$", "userassignments", "=", "$", "this", "->", "get_role_users_for_expired_context", "(", "$", "expiredctx", ",", "$", "context", ")", ";", "$", "approvedcollection", "=", "new", "\\", "core_privacy", "\\", "local", "\\", "request", "\\", "userlist_collection", "(", "$", "context", ")", ";", "foreach", "(", "$", "collection", "as", "$", "pendinguserlist", ")", "{", "$", "userlist", "=", "filtered_userlist", "::", "create_from_userlist", "(", "$", "pendinguserlist", ")", ";", "$", "userlist", "->", "apply_expired_context_filters", "(", "$", "userassignments", "->", "expired", ",", "$", "userassignments", "->", "unexpired", ")", ";", "if", "(", "count", "(", "$", "userlist", ")", ")", "{", "$", "approvedcollection", "->", "add_userlist", "(", "$", "userlist", ")", ";", "}", "}", "if", "(", "count", "(", "$", "approvedcollection", ")", ")", "{", "// Perform the deletion with the newly approved collection.", "$", "privacymanager", "->", "delete_data_for_users_in_context", "(", "$", "approvedcollection", ")", ";", "}", "// Mark the record as cleaned.", "$", "expiredctx", "->", "set", "(", "'status'", ",", "expired_context", "::", "STATUS_CLEANED", ")", ";", "$", "expiredctx", "->", "save", "(", ")", ";", "return", "$", "context", ";", "}" ]
Deletes user data from the provided context. @param expired_context $expiredctx @return \context|false
[ "Deletes", "user", "data", "from", "the", "provided", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L412-L474
216,349
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.delete_expired_user_context
protected function delete_expired_user_context(expired_context $expiredctx) { global $DB; $contextid = $expiredctx->get('contextid'); $context = \context::instance_by_id($contextid); $user = \core_user::get_user($context->instanceid, '*', MUST_EXIST); $privacymanager = $this->get_privacy_manager(); // Delete all child contexts of the user context. $parentpath = $DB->sql_concat('ctxuser.path', "'/%'"); $params = [ 'contextlevel' => CONTEXT_USER, 'contextid' => $expiredctx->get('contextid'), ]; $fields = \context_helper::get_preload_record_columns_sql('ctx'); $sql = "SELECT ctx.id, $fields FROM {context} ctxuser JOIN {context} ctx ON ctx.path LIKE {$parentpath} WHERE ctxuser.contextlevel = :contextlevel AND ctxuser.id = :contextid ORDER BY ctx.path DESC"; $children = $DB->get_recordset_sql($sql, $params); foreach ($children as $child) { \context_helper::preload_from_record($child); $context = \context::instance_by_id($child->id); $privacymanager->delete_data_for_all_users_in_context($context); } $children->close(); // Delete all unprotected data that the user holds. $approvedlistcollection = new \core_privacy\local\request\contextlist_collection($user->id); $contextlistcollection = $privacymanager->get_contexts_for_userid($user->id); foreach ($contextlistcollection as $contextlist) { $contextids = []; $approvedlistcollection->add_contextlist(new \core_privacy\local\request\approved_contextlist( $user, $contextlist->get_component(), $contextlist->get_contextids() )); } $privacymanager->delete_data_for_user($approvedlistcollection, $this->get_progress()); // Delete the user context. $context = \context::instance_by_id($expiredctx->get('contextid')); $privacymanager->delete_data_for_all_users_in_context($context); // This user is now fully expired - finish by deleting the user. delete_user($user); }
php
protected function delete_expired_user_context(expired_context $expiredctx) { global $DB; $contextid = $expiredctx->get('contextid'); $context = \context::instance_by_id($contextid); $user = \core_user::get_user($context->instanceid, '*', MUST_EXIST); $privacymanager = $this->get_privacy_manager(); // Delete all child contexts of the user context. $parentpath = $DB->sql_concat('ctxuser.path', "'/%'"); $params = [ 'contextlevel' => CONTEXT_USER, 'contextid' => $expiredctx->get('contextid'), ]; $fields = \context_helper::get_preload_record_columns_sql('ctx'); $sql = "SELECT ctx.id, $fields FROM {context} ctxuser JOIN {context} ctx ON ctx.path LIKE {$parentpath} WHERE ctxuser.contextlevel = :contextlevel AND ctxuser.id = :contextid ORDER BY ctx.path DESC"; $children = $DB->get_recordset_sql($sql, $params); foreach ($children as $child) { \context_helper::preload_from_record($child); $context = \context::instance_by_id($child->id); $privacymanager->delete_data_for_all_users_in_context($context); } $children->close(); // Delete all unprotected data that the user holds. $approvedlistcollection = new \core_privacy\local\request\contextlist_collection($user->id); $contextlistcollection = $privacymanager->get_contexts_for_userid($user->id); foreach ($contextlistcollection as $contextlist) { $contextids = []; $approvedlistcollection->add_contextlist(new \core_privacy\local\request\approved_contextlist( $user, $contextlist->get_component(), $contextlist->get_contextids() )); } $privacymanager->delete_data_for_user($approvedlistcollection, $this->get_progress()); // Delete the user context. $context = \context::instance_by_id($expiredctx->get('contextid')); $privacymanager->delete_data_for_all_users_in_context($context); // This user is now fully expired - finish by deleting the user. delete_user($user); }
[ "protected", "function", "delete_expired_user_context", "(", "expired_context", "$", "expiredctx", ")", "{", "global", "$", "DB", ";", "$", "contextid", "=", "$", "expiredctx", "->", "get", "(", "'contextid'", ")", ";", "$", "context", "=", "\\", "context", "::", "instance_by_id", "(", "$", "contextid", ")", ";", "$", "user", "=", "\\", "core_user", "::", "get_user", "(", "$", "context", "->", "instanceid", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "privacymanager", "=", "$", "this", "->", "get_privacy_manager", "(", ")", ";", "// Delete all child contexts of the user context.", "$", "parentpath", "=", "$", "DB", "->", "sql_concat", "(", "'ctxuser.path'", ",", "\"'/%'\"", ")", ";", "$", "params", "=", "[", "'contextlevel'", "=>", "CONTEXT_USER", ",", "'contextid'", "=>", "$", "expiredctx", "->", "get", "(", "'contextid'", ")", ",", "]", ";", "$", "fields", "=", "\\", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ";", "$", "sql", "=", "\"SELECT ctx.id, $fields\n FROM {context} ctxuser\n JOIN {context} ctx ON ctx.path LIKE {$parentpath}\n WHERE ctxuser.contextlevel = :contextlevel AND ctxuser.id = :contextid\n ORDER BY ctx.path DESC\"", ";", "$", "children", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "foreach", "(", "$", "children", "as", "$", "child", ")", "{", "\\", "context_helper", "::", "preload_from_record", "(", "$", "child", ")", ";", "$", "context", "=", "\\", "context", "::", "instance_by_id", "(", "$", "child", "->", "id", ")", ";", "$", "privacymanager", "->", "delete_data_for_all_users_in_context", "(", "$", "context", ")", ";", "}", "$", "children", "->", "close", "(", ")", ";", "// Delete all unprotected data that the user holds.", "$", "approvedlistcollection", "=", "new", "\\", "core_privacy", "\\", "local", "\\", "request", "\\", "contextlist_collection", "(", "$", "user", "->", "id", ")", ";", "$", "contextlistcollection", "=", "$", "privacymanager", "->", "get_contexts_for_userid", "(", "$", "user", "->", "id", ")", ";", "foreach", "(", "$", "contextlistcollection", "as", "$", "contextlist", ")", "{", "$", "contextids", "=", "[", "]", ";", "$", "approvedlistcollection", "->", "add_contextlist", "(", "new", "\\", "core_privacy", "\\", "local", "\\", "request", "\\", "approved_contextlist", "(", "$", "user", ",", "$", "contextlist", "->", "get_component", "(", ")", ",", "$", "contextlist", "->", "get_contextids", "(", ")", ")", ")", ";", "}", "$", "privacymanager", "->", "delete_data_for_user", "(", "$", "approvedlistcollection", ",", "$", "this", "->", "get_progress", "(", ")", ")", ";", "// Delete the user context.", "$", "context", "=", "\\", "context", "::", "instance_by_id", "(", "$", "expiredctx", "->", "get", "(", "'contextid'", ")", ")", ";", "$", "privacymanager", "->", "delete_data_for_all_users_in_context", "(", "$", "context", ")", ";", "// This user is now fully expired - finish by deleting the user.", "delete_user", "(", "$", "user", ")", ";", "}" ]
Deletes user data from the provided user context. @param expired_context $expiredctx
[ "Deletes", "user", "data", "from", "the", "provided", "user", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L481-L534
216,350
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.has_expired
protected static function has_expired(string $period, int $comparisondate) : bool { $dt = new \DateTime(); $dt->setTimestamp($comparisondate); $dt->add(new \DateInterval($period)); return (time() >= $dt->getTimestamp()); }
php
protected static function has_expired(string $period, int $comparisondate) : bool { $dt = new \DateTime(); $dt->setTimestamp($comparisondate); $dt->add(new \DateInterval($period)); return (time() >= $dt->getTimestamp()); }
[ "protected", "static", "function", "has_expired", "(", "string", "$", "period", ",", "int", "$", "comparisondate", ")", ":", "bool", "{", "$", "dt", "=", "new", "\\", "DateTime", "(", ")", ";", "$", "dt", "->", "setTimestamp", "(", "$", "comparisondate", ")", ";", "$", "dt", "->", "add", "(", "new", "\\", "DateInterval", "(", "$", "period", ")", ")", ";", "return", "(", "time", "(", ")", ">=", "$", "dt", "->", "getTimestamp", "(", ")", ")", ";", "}" ]
Check whether a date is beyond the specified period. @param string $period The Expiry Period @param int $comparisondate The date for comparison @return bool
[ "Check", "whether", "a", "date", "is", "beyond", "the", "specified", "period", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L566-L572
216,351
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.get_expiry_info
protected static function get_expiry_info(purpose $purpose, int $comparisondate = 0) : expiry_info { $overrides = $purpose->get_purpose_overrides(); $expiredroles = $unexpiredroles = []; if (empty($overrides)) { // There are no overrides for this purpose. if (empty($comparisondate)) { // The date is empty, therefore this context cannot be considered for automatic expiry. $defaultexpired = false; } else { $defaultexpired = static::has_expired($purpose->get('retentionperiod'), $comparisondate); } return new expiry_info($defaultexpired, $purpose->get('protected'), [], [], []); } else { $protectedroles = []; foreach ($overrides as $override) { if (static::has_expired($override->get('retentionperiod'), $comparisondate)) { // This role has expired. $expiredroles[] = $override->get('roleid'); } else { // This role has not yet expired. $unexpiredroles[] = $override->get('roleid'); if ($override->get('protected')) { $protectedroles[$override->get('roleid')] = true; } } } $defaultexpired = false; if (static::has_expired($purpose->get('retentionperiod'), $comparisondate)) { $defaultexpired = true; } if ($defaultexpired) { $expiredroles = []; } return new expiry_info($defaultexpired, $purpose->get('protected'), $expiredroles, $unexpiredroles, $protectedroles); } }
php
protected static function get_expiry_info(purpose $purpose, int $comparisondate = 0) : expiry_info { $overrides = $purpose->get_purpose_overrides(); $expiredroles = $unexpiredroles = []; if (empty($overrides)) { // There are no overrides for this purpose. if (empty($comparisondate)) { // The date is empty, therefore this context cannot be considered for automatic expiry. $defaultexpired = false; } else { $defaultexpired = static::has_expired($purpose->get('retentionperiod'), $comparisondate); } return new expiry_info($defaultexpired, $purpose->get('protected'), [], [], []); } else { $protectedroles = []; foreach ($overrides as $override) { if (static::has_expired($override->get('retentionperiod'), $comparisondate)) { // This role has expired. $expiredroles[] = $override->get('roleid'); } else { // This role has not yet expired. $unexpiredroles[] = $override->get('roleid'); if ($override->get('protected')) { $protectedroles[$override->get('roleid')] = true; } } } $defaultexpired = false; if (static::has_expired($purpose->get('retentionperiod'), $comparisondate)) { $defaultexpired = true; } if ($defaultexpired) { $expiredroles = []; } return new expiry_info($defaultexpired, $purpose->get('protected'), $expiredroles, $unexpiredroles, $protectedroles); } }
[ "protected", "static", "function", "get_expiry_info", "(", "purpose", "$", "purpose", ",", "int", "$", "comparisondate", "=", "0", ")", ":", "expiry_info", "{", "$", "overrides", "=", "$", "purpose", "->", "get_purpose_overrides", "(", ")", ";", "$", "expiredroles", "=", "$", "unexpiredroles", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "overrides", ")", ")", "{", "// There are no overrides for this purpose.", "if", "(", "empty", "(", "$", "comparisondate", ")", ")", "{", "// The date is empty, therefore this context cannot be considered for automatic expiry.", "$", "defaultexpired", "=", "false", ";", "}", "else", "{", "$", "defaultexpired", "=", "static", "::", "has_expired", "(", "$", "purpose", "->", "get", "(", "'retentionperiod'", ")", ",", "$", "comparisondate", ")", ";", "}", "return", "new", "expiry_info", "(", "$", "defaultexpired", ",", "$", "purpose", "->", "get", "(", "'protected'", ")", ",", "[", "]", ",", "[", "]", ",", "[", "]", ")", ";", "}", "else", "{", "$", "protectedroles", "=", "[", "]", ";", "foreach", "(", "$", "overrides", "as", "$", "override", ")", "{", "if", "(", "static", "::", "has_expired", "(", "$", "override", "->", "get", "(", "'retentionperiod'", ")", ",", "$", "comparisondate", ")", ")", "{", "// This role has expired.", "$", "expiredroles", "[", "]", "=", "$", "override", "->", "get", "(", "'roleid'", ")", ";", "}", "else", "{", "// This role has not yet expired.", "$", "unexpiredroles", "[", "]", "=", "$", "override", "->", "get", "(", "'roleid'", ")", ";", "if", "(", "$", "override", "->", "get", "(", "'protected'", ")", ")", "{", "$", "protectedroles", "[", "$", "override", "->", "get", "(", "'roleid'", ")", "]", "=", "true", ";", "}", "}", "}", "$", "defaultexpired", "=", "false", ";", "if", "(", "static", "::", "has_expired", "(", "$", "purpose", "->", "get", "(", "'retentionperiod'", ")", ",", "$", "comparisondate", ")", ")", "{", "$", "defaultexpired", "=", "true", ";", "}", "if", "(", "$", "defaultexpired", ")", "{", "$", "expiredroles", "=", "[", "]", ";", "}", "return", "new", "expiry_info", "(", "$", "defaultexpired", ",", "$", "purpose", "->", "get", "(", "'protected'", ")", ",", "$", "expiredroles", ",", "$", "unexpiredroles", ",", "$", "protectedroles", ")", ";", "}", "}" ]
Get the expiry info object for the specified purpose and comparison date. @param purpose $purpose The purpose of this context @param int $comparisondate The date for comparison @return expiry_info
[ "Get", "the", "expiry", "info", "object", "for", "the", "specified", "purpose", "and", "comparison", "date", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L581-L621
216,352
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.update_from_expiry_info
protected function update_from_expiry_info(\stdClass $expiryrecord) { if ($isanyexpired = $expiryrecord->info->is_any_expired()) { // The context is expired in some fashion. // Create or update as required. if ($expiryrecord->record->expiredctxid) { $expiredcontext = new expired_context(null, expired_context::extract_record($expiryrecord->record, 'expiredctx')); $expiredcontext->update_from_expiry_info($expiryrecord->info); if ($expiredcontext->is_complete()) { return null; } } else { $expiredcontext = expired_context::create_from_expiry_info($expiryrecord->context, $expiryrecord->info); } if ($expiryrecord->context instanceof \context_user) { $userassignments = $this->get_role_users_for_expired_context($expiredcontext, $expiryrecord->context); if (!empty($userassignments->unexpired)) { $expiredcontext->delete(); return null; } } return $expiredcontext; } else { // The context is not expired. if ($expiryrecord->record->expiredctxid) { // There was previously an expired context record, but it is no longer relevant. // Delete it to be on the safe side. $expiredcontext = new expired_context(null, expired_context::extract_record($expiryrecord->record, 'expiredctx')); $expiredcontext->delete(); } return null; } }
php
protected function update_from_expiry_info(\stdClass $expiryrecord) { if ($isanyexpired = $expiryrecord->info->is_any_expired()) { // The context is expired in some fashion. // Create or update as required. if ($expiryrecord->record->expiredctxid) { $expiredcontext = new expired_context(null, expired_context::extract_record($expiryrecord->record, 'expiredctx')); $expiredcontext->update_from_expiry_info($expiryrecord->info); if ($expiredcontext->is_complete()) { return null; } } else { $expiredcontext = expired_context::create_from_expiry_info($expiryrecord->context, $expiryrecord->info); } if ($expiryrecord->context instanceof \context_user) { $userassignments = $this->get_role_users_for_expired_context($expiredcontext, $expiryrecord->context); if (!empty($userassignments->unexpired)) { $expiredcontext->delete(); return null; } } return $expiredcontext; } else { // The context is not expired. if ($expiryrecord->record->expiredctxid) { // There was previously an expired context record, but it is no longer relevant. // Delete it to be on the safe side. $expiredcontext = new expired_context(null, expired_context::extract_record($expiryrecord->record, 'expiredctx')); $expiredcontext->delete(); } return null; } }
[ "protected", "function", "update_from_expiry_info", "(", "\\", "stdClass", "$", "expiryrecord", ")", "{", "if", "(", "$", "isanyexpired", "=", "$", "expiryrecord", "->", "info", "->", "is_any_expired", "(", ")", ")", "{", "// The context is expired in some fashion.", "// Create or update as required.", "if", "(", "$", "expiryrecord", "->", "record", "->", "expiredctxid", ")", "{", "$", "expiredcontext", "=", "new", "expired_context", "(", "null", ",", "expired_context", "::", "extract_record", "(", "$", "expiryrecord", "->", "record", ",", "'expiredctx'", ")", ")", ";", "$", "expiredcontext", "->", "update_from_expiry_info", "(", "$", "expiryrecord", "->", "info", ")", ";", "if", "(", "$", "expiredcontext", "->", "is_complete", "(", ")", ")", "{", "return", "null", ";", "}", "}", "else", "{", "$", "expiredcontext", "=", "expired_context", "::", "create_from_expiry_info", "(", "$", "expiryrecord", "->", "context", ",", "$", "expiryrecord", "->", "info", ")", ";", "}", "if", "(", "$", "expiryrecord", "->", "context", "instanceof", "\\", "context_user", ")", "{", "$", "userassignments", "=", "$", "this", "->", "get_role_users_for_expired_context", "(", "$", "expiredcontext", ",", "$", "expiryrecord", "->", "context", ")", ";", "if", "(", "!", "empty", "(", "$", "userassignments", "->", "unexpired", ")", ")", "{", "$", "expiredcontext", "->", "delete", "(", ")", ";", "return", "null", ";", "}", "}", "return", "$", "expiredcontext", ";", "}", "else", "{", "// The context is not expired.", "if", "(", "$", "expiryrecord", "->", "record", "->", "expiredctxid", ")", "{", "// There was previously an expired context record, but it is no longer relevant.", "// Delete it to be on the safe side.", "$", "expiredcontext", "=", "new", "expired_context", "(", "null", ",", "expired_context", "::", "extract_record", "(", "$", "expiryrecord", "->", "record", ",", "'expiredctx'", ")", ")", ";", "$", "expiredcontext", "->", "delete", "(", ")", ";", "}", "return", "null", ";", "}", "}" ]
Update or delete the expired_context from the expiry_info object. This function depends upon the data structure returned from get_nested_expiry_info. If the context is expired in any way, then an expired_context will be returned, otherwise null will be returned. @param \stdClass $expiryrecord @return expired_context|null
[ "Update", "or", "delete", "the", "expired_context", "from", "the", "expiry_info", "object", ".", "This", "function", "depends", "upon", "the", "data", "structure", "returned", "from", "get_nested_expiry_info", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L632-L668
216,353
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.update_expired_context
protected function update_expired_context(expired_context $expiredctx) { // Fetch the context from the expired_context record. $context = \context::instance_by_id($expiredctx->get('contextid')); // Fetch the current nested expiry data. $expiryrecords = self::get_nested_expiry_info($context->path); if (empty($expiryrecords[$context->path])) { $expiredctx->delete(); return null; } // Refresh the record. // Note: Use the returned expiredctx. $expiredctx = $this->update_from_expiry_info($expiryrecords[$context->path]); if (empty($expiredctx)) { return null; } if (!$context instanceof \context_user) { // Where the target context is not a user, we check all children of the context. // The expiryrecords array only contains children, fetched from the get_nested_expiry_info call above. // No need to check that these _are_ children. foreach ($expiryrecords as $expiryrecord) { if ($expiryrecord->context->id === $context->id) { // This is record for the context being tested that we checked earlier. continue; } if (empty($expiryrecord->record->expiredctxid)) { // There is no expired context record for this context. // If there is no record, then this context cannot have been approved for removal. return null; } // Fetch the expired_context object for this record. // This needs to be updated from the expiry_info data too as there may be child changes to consider. $expiredcontext = new expired_context(null, expired_context::extract_record($expiryrecord->record, 'expiredctx')); $expiredcontext->update_from_expiry_info($expiryrecord->info); if (!$expiredcontext->is_complete()) { return null; } } } return $expiredctx; }
php
protected function update_expired_context(expired_context $expiredctx) { // Fetch the context from the expired_context record. $context = \context::instance_by_id($expiredctx->get('contextid')); // Fetch the current nested expiry data. $expiryrecords = self::get_nested_expiry_info($context->path); if (empty($expiryrecords[$context->path])) { $expiredctx->delete(); return null; } // Refresh the record. // Note: Use the returned expiredctx. $expiredctx = $this->update_from_expiry_info($expiryrecords[$context->path]); if (empty($expiredctx)) { return null; } if (!$context instanceof \context_user) { // Where the target context is not a user, we check all children of the context. // The expiryrecords array only contains children, fetched from the get_nested_expiry_info call above. // No need to check that these _are_ children. foreach ($expiryrecords as $expiryrecord) { if ($expiryrecord->context->id === $context->id) { // This is record for the context being tested that we checked earlier. continue; } if (empty($expiryrecord->record->expiredctxid)) { // There is no expired context record for this context. // If there is no record, then this context cannot have been approved for removal. return null; } // Fetch the expired_context object for this record. // This needs to be updated from the expiry_info data too as there may be child changes to consider. $expiredcontext = new expired_context(null, expired_context::extract_record($expiryrecord->record, 'expiredctx')); $expiredcontext->update_from_expiry_info($expiryrecord->info); if (!$expiredcontext->is_complete()) { return null; } } } return $expiredctx; }
[ "protected", "function", "update_expired_context", "(", "expired_context", "$", "expiredctx", ")", "{", "// Fetch the context from the expired_context record.", "$", "context", "=", "\\", "context", "::", "instance_by_id", "(", "$", "expiredctx", "->", "get", "(", "'contextid'", ")", ")", ";", "// Fetch the current nested expiry data.", "$", "expiryrecords", "=", "self", "::", "get_nested_expiry_info", "(", "$", "context", "->", "path", ")", ";", "if", "(", "empty", "(", "$", "expiryrecords", "[", "$", "context", "->", "path", "]", ")", ")", "{", "$", "expiredctx", "->", "delete", "(", ")", ";", "return", "null", ";", "}", "// Refresh the record.", "// Note: Use the returned expiredctx.", "$", "expiredctx", "=", "$", "this", "->", "update_from_expiry_info", "(", "$", "expiryrecords", "[", "$", "context", "->", "path", "]", ")", ";", "if", "(", "empty", "(", "$", "expiredctx", ")", ")", "{", "return", "null", ";", "}", "if", "(", "!", "$", "context", "instanceof", "\\", "context_user", ")", "{", "// Where the target context is not a user, we check all children of the context.", "// The expiryrecords array only contains children, fetched from the get_nested_expiry_info call above.", "// No need to check that these _are_ children.", "foreach", "(", "$", "expiryrecords", "as", "$", "expiryrecord", ")", "{", "if", "(", "$", "expiryrecord", "->", "context", "->", "id", "===", "$", "context", "->", "id", ")", "{", "// This is record for the context being tested that we checked earlier.", "continue", ";", "}", "if", "(", "empty", "(", "$", "expiryrecord", "->", "record", "->", "expiredctxid", ")", ")", "{", "// There is no expired context record for this context.", "// If there is no record, then this context cannot have been approved for removal.", "return", "null", ";", "}", "// Fetch the expired_context object for this record.", "// This needs to be updated from the expiry_info data too as there may be child changes to consider.", "$", "expiredcontext", "=", "new", "expired_context", "(", "null", ",", "expired_context", "::", "extract_record", "(", "$", "expiryrecord", "->", "record", ",", "'expiredctx'", ")", ")", ";", "$", "expiredcontext", "->", "update_from_expiry_info", "(", "$", "expiryrecord", "->", "info", ")", ";", "if", "(", "!", "$", "expiredcontext", "->", "is_complete", "(", ")", ")", "{", "return", "null", ";", "}", "}", "}", "return", "$", "expiredctx", ";", "}" ]
Update the expired context record. Note: You should use the return value as the provided value will be used to fetch data only. @param expired_context $expiredctx The record to update @return expired_context|null
[ "Update", "the", "expired", "context", "record", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L678-L724
216,354
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.get_role_users_for_expired_context
protected function get_role_users_for_expired_context(expired_context $expiredctx, \context $context) : \stdClass { $expiredroles = $expiredctx->get('expiredroles'); $expiredroleusers = []; if (!empty($expiredroles)) { // Find the list of expired role users. $expiredroleuserassignments = get_role_users($expiredroles, $context, true, 'ra.id, u.id AS userid', 'ra.id'); $expiredroleusers = array_map(function($assignment) { return $assignment->userid; }, $expiredroleuserassignments); } $expiredroleusers = array_unique($expiredroleusers); $unexpiredroles = $expiredctx->get('unexpiredroles'); $unexpiredroleusers = []; if (!empty($unexpiredroles)) { // Find the list of unexpired role users. $unexpiredroleuserassignments = get_role_users($unexpiredroles, $context, true, 'ra.id, u.id AS userid', 'ra.id'); $unexpiredroleusers = array_map(function($assignment) { return $assignment->userid; }, $unexpiredroleuserassignments); } $unexpiredroleusers = array_unique($unexpiredroleusers); if (!$expiredctx->get('defaultexpired')) { $tofilter = get_users_roles($context, $expiredroleusers); $tofilter = array_filter($tofilter, function($userroles) use ($expiredroles) { // Each iteration contains the list of role assignment for a specific user. // All roles that the user holds must match those in the list of expired roles. foreach ($userroles as $ra) { if (false === array_search($ra->roleid, $expiredroles)) { // This role was not found in the list of assignments. return true; } } return false; }); $unexpiredroleusers = array_merge($unexpiredroleusers, array_keys($tofilter)); } return (object) [ 'expired' => $expiredroleusers, 'unexpired' => $unexpiredroleusers, ]; }
php
protected function get_role_users_for_expired_context(expired_context $expiredctx, \context $context) : \stdClass { $expiredroles = $expiredctx->get('expiredroles'); $expiredroleusers = []; if (!empty($expiredroles)) { // Find the list of expired role users. $expiredroleuserassignments = get_role_users($expiredroles, $context, true, 'ra.id, u.id AS userid', 'ra.id'); $expiredroleusers = array_map(function($assignment) { return $assignment->userid; }, $expiredroleuserassignments); } $expiredroleusers = array_unique($expiredroleusers); $unexpiredroles = $expiredctx->get('unexpiredroles'); $unexpiredroleusers = []; if (!empty($unexpiredroles)) { // Find the list of unexpired role users. $unexpiredroleuserassignments = get_role_users($unexpiredroles, $context, true, 'ra.id, u.id AS userid', 'ra.id'); $unexpiredroleusers = array_map(function($assignment) { return $assignment->userid; }, $unexpiredroleuserassignments); } $unexpiredroleusers = array_unique($unexpiredroleusers); if (!$expiredctx->get('defaultexpired')) { $tofilter = get_users_roles($context, $expiredroleusers); $tofilter = array_filter($tofilter, function($userroles) use ($expiredroles) { // Each iteration contains the list of role assignment for a specific user. // All roles that the user holds must match those in the list of expired roles. foreach ($userroles as $ra) { if (false === array_search($ra->roleid, $expiredroles)) { // This role was not found in the list of assignments. return true; } } return false; }); $unexpiredroleusers = array_merge($unexpiredroleusers, array_keys($tofilter)); } return (object) [ 'expired' => $expiredroleusers, 'unexpired' => $unexpiredroleusers, ]; }
[ "protected", "function", "get_role_users_for_expired_context", "(", "expired_context", "$", "expiredctx", ",", "\\", "context", "$", "context", ")", ":", "\\", "stdClass", "{", "$", "expiredroles", "=", "$", "expiredctx", "->", "get", "(", "'expiredroles'", ")", ";", "$", "expiredroleusers", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "expiredroles", ")", ")", "{", "// Find the list of expired role users.", "$", "expiredroleuserassignments", "=", "get_role_users", "(", "$", "expiredroles", ",", "$", "context", ",", "true", ",", "'ra.id, u.id AS userid'", ",", "'ra.id'", ")", ";", "$", "expiredroleusers", "=", "array_map", "(", "function", "(", "$", "assignment", ")", "{", "return", "$", "assignment", "->", "userid", ";", "}", ",", "$", "expiredroleuserassignments", ")", ";", "}", "$", "expiredroleusers", "=", "array_unique", "(", "$", "expiredroleusers", ")", ";", "$", "unexpiredroles", "=", "$", "expiredctx", "->", "get", "(", "'unexpiredroles'", ")", ";", "$", "unexpiredroleusers", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "unexpiredroles", ")", ")", "{", "// Find the list of unexpired role users.", "$", "unexpiredroleuserassignments", "=", "get_role_users", "(", "$", "unexpiredroles", ",", "$", "context", ",", "true", ",", "'ra.id, u.id AS userid'", ",", "'ra.id'", ")", ";", "$", "unexpiredroleusers", "=", "array_map", "(", "function", "(", "$", "assignment", ")", "{", "return", "$", "assignment", "->", "userid", ";", "}", ",", "$", "unexpiredroleuserassignments", ")", ";", "}", "$", "unexpiredroleusers", "=", "array_unique", "(", "$", "unexpiredroleusers", ")", ";", "if", "(", "!", "$", "expiredctx", "->", "get", "(", "'defaultexpired'", ")", ")", "{", "$", "tofilter", "=", "get_users_roles", "(", "$", "context", ",", "$", "expiredroleusers", ")", ";", "$", "tofilter", "=", "array_filter", "(", "$", "tofilter", ",", "function", "(", "$", "userroles", ")", "use", "(", "$", "expiredroles", ")", "{", "// Each iteration contains the list of role assignment for a specific user.", "// All roles that the user holds must match those in the list of expired roles.", "foreach", "(", "$", "userroles", "as", "$", "ra", ")", "{", "if", "(", "false", "===", "array_search", "(", "$", "ra", "->", "roleid", ",", "$", "expiredroles", ")", ")", "{", "// This role was not found in the list of assignments.", "return", "true", ";", "}", "}", "return", "false", ";", "}", ")", ";", "$", "unexpiredroleusers", "=", "array_merge", "(", "$", "unexpiredroleusers", ",", "array_keys", "(", "$", "tofilter", ")", ")", ";", "}", "return", "(", "object", ")", "[", "'expired'", "=>", "$", "expiredroleusers", ",", "'unexpired'", "=>", "$", "unexpiredroleusers", ",", "]", ";", "}" ]
Get the list of actual users for the combination of expired, and unexpired roles. @param expired_context $expiredctx @param \context $context @return \stdClass
[ "Get", "the", "list", "of", "actual", "users", "for", "the", "combination", "of", "expired", "and", "unexpired", "roles", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L733-L777
216,355
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.is_context_expired
public static function is_context_expired(\context $context) : bool { $parents = $context->get_parent_contexts(true); foreach ($parents as $parent) { if ($parent instanceof \context_course) { // This is a context within a course. Check whether _this context_ is expired as a function of a course. return self::is_course_context_expired($context); } if ($parent instanceof \context_user) { // This is a context within a user. Check whether the _user_ has expired. return self::are_user_context_dependencies_expired($parent); } } return false; }
php
public static function is_context_expired(\context $context) : bool { $parents = $context->get_parent_contexts(true); foreach ($parents as $parent) { if ($parent instanceof \context_course) { // This is a context within a course. Check whether _this context_ is expired as a function of a course. return self::is_course_context_expired($context); } if ($parent instanceof \context_user) { // This is a context within a user. Check whether the _user_ has expired. return self::are_user_context_dependencies_expired($parent); } } return false; }
[ "public", "static", "function", "is_context_expired", "(", "\\", "context", "$", "context", ")", ":", "bool", "{", "$", "parents", "=", "$", "context", "->", "get_parent_contexts", "(", "true", ")", ";", "foreach", "(", "$", "parents", "as", "$", "parent", ")", "{", "if", "(", "$", "parent", "instanceof", "\\", "context_course", ")", "{", "// This is a context within a course. Check whether _this context_ is expired as a function of a course.", "return", "self", "::", "is_course_context_expired", "(", "$", "context", ")", ";", "}", "if", "(", "$", "parent", "instanceof", "\\", "context_user", ")", "{", "// This is a context within a user. Check whether the _user_ has expired.", "return", "self", "::", "are_user_context_dependencies_expired", "(", "$", "parent", ")", ";", "}", "}", "return", "false", ";", "}" ]
Determine whether the supplied context has expired. @param \context $context @return bool
[ "Determine", "whether", "the", "supplied", "context", "has", "expired", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L785-L800
216,356
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.is_course_expired
protected static function is_course_expired(\stdClass $course) : bool { $context = \context_course::instance($course->id); return self::is_course_context_expired($context); }
php
protected static function is_course_expired(\stdClass $course) : bool { $context = \context_course::instance($course->id); return self::is_course_context_expired($context); }
[ "protected", "static", "function", "is_course_expired", "(", "\\", "stdClass", "$", "course", ")", ":", "bool", "{", "$", "context", "=", "\\", "context_course", "::", "instance", "(", "$", "course", "->", "id", ")", ";", "return", "self", "::", "is_course_context_expired", "(", "$", "context", ")", ";", "}" ]
Check whether the course has expired. @param \stdClass $course @return bool
[ "Check", "whether", "the", "course", "has", "expired", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L808-L812
216,357
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.are_user_context_dependencies_expired
protected static function are_user_context_dependencies_expired(\context_user $context) : bool { // The context instanceid is the user's ID. if (isguestuser($context->instanceid) || is_siteadmin($context->instanceid)) { // This is an admin, or the guest and cannot expire. return false; } $courses = enrol_get_users_courses($context->instanceid, false, ['enddate']); $requireenddate = self::require_all_end_dates_for_user_deletion(); $expired = true; foreach ($courses as $course) { if (empty($course->enddate)) { // This course has no end date. if ($requireenddate) { // Course end dates are required, and this course has no end date. $expired = false; break; } // Course end dates are not required. The subsequent checks are pointless at this time so just // skip them. continue; } if ($course->enddate >= time()) { // This course is still in the future. $expired = false; break; } // This course has an end date which is in the past. if (!self::is_course_expired($course)) { // This course has not expired yet. $expired = false; break; } } return $expired; }
php
protected static function are_user_context_dependencies_expired(\context_user $context) : bool { // The context instanceid is the user's ID. if (isguestuser($context->instanceid) || is_siteadmin($context->instanceid)) { // This is an admin, or the guest and cannot expire. return false; } $courses = enrol_get_users_courses($context->instanceid, false, ['enddate']); $requireenddate = self::require_all_end_dates_for_user_deletion(); $expired = true; foreach ($courses as $course) { if (empty($course->enddate)) { // This course has no end date. if ($requireenddate) { // Course end dates are required, and this course has no end date. $expired = false; break; } // Course end dates are not required. The subsequent checks are pointless at this time so just // skip them. continue; } if ($course->enddate >= time()) { // This course is still in the future. $expired = false; break; } // This course has an end date which is in the past. if (!self::is_course_expired($course)) { // This course has not expired yet. $expired = false; break; } } return $expired; }
[ "protected", "static", "function", "are_user_context_dependencies_expired", "(", "\\", "context_user", "$", "context", ")", ":", "bool", "{", "// The context instanceid is the user's ID.", "if", "(", "isguestuser", "(", "$", "context", "->", "instanceid", ")", "||", "is_siteadmin", "(", "$", "context", "->", "instanceid", ")", ")", "{", "// This is an admin, or the guest and cannot expire.", "return", "false", ";", "}", "$", "courses", "=", "enrol_get_users_courses", "(", "$", "context", "->", "instanceid", ",", "false", ",", "[", "'enddate'", "]", ")", ";", "$", "requireenddate", "=", "self", "::", "require_all_end_dates_for_user_deletion", "(", ")", ";", "$", "expired", "=", "true", ";", "foreach", "(", "$", "courses", "as", "$", "course", ")", "{", "if", "(", "empty", "(", "$", "course", "->", "enddate", ")", ")", "{", "// This course has no end date.", "if", "(", "$", "requireenddate", ")", "{", "// Course end dates are required, and this course has no end date.", "$", "expired", "=", "false", ";", "break", ";", "}", "// Course end dates are not required. The subsequent checks are pointless at this time so just", "// skip them.", "continue", ";", "}", "if", "(", "$", "course", "->", "enddate", ">=", "time", "(", ")", ")", "{", "// This course is still in the future.", "$", "expired", "=", "false", ";", "break", ";", "}", "// This course has an end date which is in the past.", "if", "(", "!", "self", "::", "is_course_expired", "(", "$", "course", ")", ")", "{", "// This course has not expired yet.", "$", "expired", "=", "false", ";", "break", ";", "}", "}", "return", "$", "expired", ";", "}" ]
Determine whether the supplied user context's dependencies have expired. This checks whether courses have expired, and some other check, but does not check whether the user themself has expired. Although this seems unusual at first, each location calling this actually checks whether the user is elgible for deletion, irrespective if they have actually expired. For example, a request to delete the user only cares about course dependencies and the user's lack of expiry should not block their own request to be deleted; whilst the expiry eligibility check has already tested for the user being expired. @param \context_user $context @return bool
[ "Determine", "whether", "the", "supplied", "user", "context", "s", "dependencies", "have", "expired", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L842-L883
216,358
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.is_context_expired_or_unprotected_for_user
public static function is_context_expired_or_unprotected_for_user(\context $context, \stdClass $user) : bool { // User/course contexts can't expire if no purpose is set in the system context. if (!data_registry::defaults_set()) { return false; } $parents = $context->get_parent_contexts(true); foreach ($parents as $parent) { if ($parent instanceof \context_course) { // This is a context within a course. Check whether _this context_ is expired as a function of a course. return self::is_course_context_expired_or_unprotected_for_user($context, $user); } if ($parent instanceof \context_user) { // This is a context within a user. Check whether the _user_ has expired. return self::are_user_context_dependencies_expired($parent); } } return false; }
php
public static function is_context_expired_or_unprotected_for_user(\context $context, \stdClass $user) : bool { // User/course contexts can't expire if no purpose is set in the system context. if (!data_registry::defaults_set()) { return false; } $parents = $context->get_parent_contexts(true); foreach ($parents as $parent) { if ($parent instanceof \context_course) { // This is a context within a course. Check whether _this context_ is expired as a function of a course. return self::is_course_context_expired_or_unprotected_for_user($context, $user); } if ($parent instanceof \context_user) { // This is a context within a user. Check whether the _user_ has expired. return self::are_user_context_dependencies_expired($parent); } } return false; }
[ "public", "static", "function", "is_context_expired_or_unprotected_for_user", "(", "\\", "context", "$", "context", ",", "\\", "stdClass", "$", "user", ")", ":", "bool", "{", "// User/course contexts can't expire if no purpose is set in the system context.", "if", "(", "!", "data_registry", "::", "defaults_set", "(", ")", ")", "{", "return", "false", ";", "}", "$", "parents", "=", "$", "context", "->", "get_parent_contexts", "(", "true", ")", ";", "foreach", "(", "$", "parents", "as", "$", "parent", ")", "{", "if", "(", "$", "parent", "instanceof", "\\", "context_course", ")", "{", "// This is a context within a course. Check whether _this context_ is expired as a function of a course.", "return", "self", "::", "is_course_context_expired_or_unprotected_for_user", "(", "$", "context", ",", "$", "user", ")", ";", "}", "if", "(", "$", "parent", "instanceof", "\\", "context_user", ")", "{", "// This is a context within a user. Check whether the _user_ has expired.", "return", "self", "::", "are_user_context_dependencies_expired", "(", "$", "parent", ")", ";", "}", "}", "return", "false", ";", "}" ]
Determine whether the supplied context has expired or unprotected for the specified user. @param \context $context @param \stdClass $user @return bool
[ "Determine", "whether", "the", "supplied", "context", "has", "expired", "or", "unprotected", "for", "the", "specified", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L892-L912
216,359
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.get_privacy_manager
protected function get_privacy_manager() : manager { if (null === $this->manager) { $this->manager = new manager(); $this->manager->set_observer(new \tool_dataprivacy\manager_observer()); } return $this->manager; }
php
protected function get_privacy_manager() : manager { if (null === $this->manager) { $this->manager = new manager(); $this->manager->set_observer(new \tool_dataprivacy\manager_observer()); } return $this->manager; }
[ "protected", "function", "get_privacy_manager", "(", ")", ":", "manager", "{", "if", "(", "null", "===", "$", "this", "->", "manager", ")", "{", "$", "this", "->", "manager", "=", "new", "manager", "(", ")", ";", "$", "this", "->", "manager", "->", "set_observer", "(", "new", "\\", "tool_dataprivacy", "\\", "manager_observer", "(", ")", ")", ";", "}", "return", "$", "this", "->", "manager", ";", "}" ]
Create a new instance of the privacy manager. @return manager
[ "Create", "a", "new", "instance", "of", "the", "privacy", "manager", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L975-L982
216,360
moodle/moodle
admin/tool/dataprivacy/classes/expired_contexts_manager.php
expired_contexts_manager.get_progress
protected function get_progress() : \progress_trace { if (null === $this->progresstracer) { $this->set_progress(new \text_progress_trace()); } return $this->progresstracer; }
php
protected function get_progress() : \progress_trace { if (null === $this->progresstracer) { $this->set_progress(new \text_progress_trace()); } return $this->progresstracer; }
[ "protected", "function", "get_progress", "(", ")", ":", "\\", "progress_trace", "{", "if", "(", "null", "===", "$", "this", "->", "progresstracer", ")", "{", "$", "this", "->", "set_progress", "(", "new", "\\", "text_progress_trace", "(", ")", ")", ";", "}", "return", "$", "this", "->", "progresstracer", ";", "}" ]
Get the progress tracer. @return \progress_trace
[ "Get", "the", "progress", "tracer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_contexts_manager.php#L998-L1004
216,361
moodle/moodle
backup/moodle2/restore_subplugin.class.php
restore_subplugin.launch_after_execute_methods
public function launch_after_execute_methods() { // Check if the after_execute method exists and launch it $afterexecute = 'after_execute_' . basename($this->connectionpoint->get_path()); if (method_exists($this, $afterexecute)) { $this->$afterexecute(); } }
php
public function launch_after_execute_methods() { // Check if the after_execute method exists and launch it $afterexecute = 'after_execute_' . basename($this->connectionpoint->get_path()); if (method_exists($this, $afterexecute)) { $this->$afterexecute(); } }
[ "public", "function", "launch_after_execute_methods", "(", ")", "{", "// Check if the after_execute method exists and launch it", "$", "afterexecute", "=", "'after_execute_'", ".", "basename", "(", "$", "this", "->", "connectionpoint", "->", "get_path", "(", ")", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "$", "afterexecute", ")", ")", "{", "$", "this", "->", "$", "afterexecute", "(", ")", ";", "}", "}" ]
after_execute dispatcher for any restore_subplugin class This method will dispatch execution to the corresponding after_execute_xxx() method when available, with xxx being the connection point of the instance, so subplugin classes with multiple connection points will support multiple after_execute methods, one for each connection point
[ "after_execute", "dispatcher", "for", "any", "restore_subplugin", "class" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/restore_subplugin.class.php#L82-L88
216,362
moodle/moodle
backup/moodle2/restore_subplugin.class.php
restore_subplugin.launch_after_restore_methods
public function launch_after_restore_methods() { // Check if the after_restore method exists and launch it. $afterestore = 'after_restore_' . basename($this->connectionpoint->get_path()); if (method_exists($this, $afterestore)) { $this->$afterestore(); } }
php
public function launch_after_restore_methods() { // Check if the after_restore method exists and launch it. $afterestore = 'after_restore_' . basename($this->connectionpoint->get_path()); if (method_exists($this, $afterestore)) { $this->$afterestore(); } }
[ "public", "function", "launch_after_restore_methods", "(", ")", "{", "// Check if the after_restore method exists and launch it.", "$", "afterestore", "=", "'after_restore_'", ".", "basename", "(", "$", "this", "->", "connectionpoint", "->", "get_path", "(", ")", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "$", "afterestore", ")", ")", "{", "$", "this", "->", "$", "afterestore", "(", ")", ";", "}", "}" ]
The after_restore dispatcher for any restore_subplugin class. This method will dispatch execution to the corresponding after_restore_xxx() method when available, with xxx being the connection point of the instance, so subplugin classes with multiple connection points will support multiple after_restore methods, one for each connection point.
[ "The", "after_restore", "dispatcher", "for", "any", "restore_subplugin", "class", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/restore_subplugin.class.php#L99-L105
216,363
moodle/moodle
backup/moodle2/restore_subplugin.class.php
restore_subplugin.log
public function log($message, $level, $a = null, $depth = null, $display = false) { return $this->step->log($message, $level, $a, $depth, $display); }
php
public function log($message, $level, $a = null, $depth = null, $display = false) { return $this->step->log($message, $level, $a, $depth, $display); }
[ "public", "function", "log", "(", "$", "message", ",", "$", "level", ",", "$", "a", "=", "null", ",", "$", "depth", "=", "null", ",", "$", "display", "=", "false", ")", "{", "return", "$", "this", "->", "step", "->", "log", "(", "$", "message", ",", "$", "level", ",", "$", "a", ",", "$", "depth", ",", "$", "display", ")", ";", "}" ]
Call the log function from the step.
[ "Call", "the", "log", "function", "from", "the", "step", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/restore_subplugin.class.php#L182-L184
216,364
moodle/moodle
cache/locallib.php
cache_config_writer.config_save
protected function config_save() { global $CFG; $cachefile = static::get_config_file_path(); $directory = dirname($cachefile); if ($directory !== $CFG->dataroot && !file_exists($directory)) { $result = make_writable_directory($directory, false); if (!$result) { throw new cache_exception('ex_configcannotsave', 'cache', '', null, 'Cannot create config directory. Check the permissions on your moodledata directory.'); } } if (!file_exists($directory) || !is_writable($directory)) { throw new cache_exception('ex_configcannotsave', 'cache', '', null, 'Config directory is not writable. Check the permissions on the moodledata/muc directory.'); } // Prepare a configuration array to store. $configuration = $this->generate_configuration_array(); // Prepare the file content. $content = "<?php defined('MOODLE_INTERNAL') || die();\n \$configuration = ".var_export($configuration, true).";"; // We need to create a temporary cache lock instance for use here. Remember we are generating the config file // it doesn't exist and thus we can't use the normal API for this (it'll just try to use config). $lockconf = reset($this->configlocks); if ($lockconf === false) { debugging('Your cache configuration file is out of date and needs to be refreshed.', DEBUG_DEVELOPER); // Use the default $lockconf = array( 'name' => 'cachelock_file_default', 'type' => 'cachelock_file', 'dir' => 'filelocks', 'default' => true ); } $factory = cache_factory::instance(); $locking = $factory->create_lock_instance($lockconf); if ($locking->lock('configwrite', 'config', true)) { // Its safe to use w mode here because we have already acquired the lock. $handle = fopen($cachefile, 'w'); fwrite($handle, $content); fflush($handle); fclose($handle); $locking->unlock('configwrite', 'config'); @chmod($cachefile, $CFG->filepermissions); // Tell PHP to recompile the script. core_component::invalidate_opcode_php_cache($cachefile); } else { throw new cache_exception('ex_configcannotsave', 'cache', '', null, 'Unable to open the cache config file.'); } }
php
protected function config_save() { global $CFG; $cachefile = static::get_config_file_path(); $directory = dirname($cachefile); if ($directory !== $CFG->dataroot && !file_exists($directory)) { $result = make_writable_directory($directory, false); if (!$result) { throw new cache_exception('ex_configcannotsave', 'cache', '', null, 'Cannot create config directory. Check the permissions on your moodledata directory.'); } } if (!file_exists($directory) || !is_writable($directory)) { throw new cache_exception('ex_configcannotsave', 'cache', '', null, 'Config directory is not writable. Check the permissions on the moodledata/muc directory.'); } // Prepare a configuration array to store. $configuration = $this->generate_configuration_array(); // Prepare the file content. $content = "<?php defined('MOODLE_INTERNAL') || die();\n \$configuration = ".var_export($configuration, true).";"; // We need to create a temporary cache lock instance for use here. Remember we are generating the config file // it doesn't exist and thus we can't use the normal API for this (it'll just try to use config). $lockconf = reset($this->configlocks); if ($lockconf === false) { debugging('Your cache configuration file is out of date and needs to be refreshed.', DEBUG_DEVELOPER); // Use the default $lockconf = array( 'name' => 'cachelock_file_default', 'type' => 'cachelock_file', 'dir' => 'filelocks', 'default' => true ); } $factory = cache_factory::instance(); $locking = $factory->create_lock_instance($lockconf); if ($locking->lock('configwrite', 'config', true)) { // Its safe to use w mode here because we have already acquired the lock. $handle = fopen($cachefile, 'w'); fwrite($handle, $content); fflush($handle); fclose($handle); $locking->unlock('configwrite', 'config'); @chmod($cachefile, $CFG->filepermissions); // Tell PHP to recompile the script. core_component::invalidate_opcode_php_cache($cachefile); } else { throw new cache_exception('ex_configcannotsave', 'cache', '', null, 'Unable to open the cache config file.'); } }
[ "protected", "function", "config_save", "(", ")", "{", "global", "$", "CFG", ";", "$", "cachefile", "=", "static", "::", "get_config_file_path", "(", ")", ";", "$", "directory", "=", "dirname", "(", "$", "cachefile", ")", ";", "if", "(", "$", "directory", "!==", "$", "CFG", "->", "dataroot", "&&", "!", "file_exists", "(", "$", "directory", ")", ")", "{", "$", "result", "=", "make_writable_directory", "(", "$", "directory", ",", "false", ")", ";", "if", "(", "!", "$", "result", ")", "{", "throw", "new", "cache_exception", "(", "'ex_configcannotsave'", ",", "'cache'", ",", "''", ",", "null", ",", "'Cannot create config directory. Check the permissions on your moodledata directory.'", ")", ";", "}", "}", "if", "(", "!", "file_exists", "(", "$", "directory", ")", "||", "!", "is_writable", "(", "$", "directory", ")", ")", "{", "throw", "new", "cache_exception", "(", "'ex_configcannotsave'", ",", "'cache'", ",", "''", ",", "null", ",", "'Config directory is not writable. Check the permissions on the moodledata/muc directory.'", ")", ";", "}", "// Prepare a configuration array to store.", "$", "configuration", "=", "$", "this", "->", "generate_configuration_array", "(", ")", ";", "// Prepare the file content.", "$", "content", "=", "\"<?php defined('MOODLE_INTERNAL') || die();\\n \\$configuration = \"", ".", "var_export", "(", "$", "configuration", ",", "true", ")", ".", "\";\"", ";", "// We need to create a temporary cache lock instance for use here. Remember we are generating the config file", "// it doesn't exist and thus we can't use the normal API for this (it'll just try to use config).", "$", "lockconf", "=", "reset", "(", "$", "this", "->", "configlocks", ")", ";", "if", "(", "$", "lockconf", "===", "false", ")", "{", "debugging", "(", "'Your cache configuration file is out of date and needs to be refreshed.'", ",", "DEBUG_DEVELOPER", ")", ";", "// Use the default", "$", "lockconf", "=", "array", "(", "'name'", "=>", "'cachelock_file_default'", ",", "'type'", "=>", "'cachelock_file'", ",", "'dir'", "=>", "'filelocks'", ",", "'default'", "=>", "true", ")", ";", "}", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "$", "locking", "=", "$", "factory", "->", "create_lock_instance", "(", "$", "lockconf", ")", ";", "if", "(", "$", "locking", "->", "lock", "(", "'configwrite'", ",", "'config'", ",", "true", ")", ")", "{", "// Its safe to use w mode here because we have already acquired the lock.", "$", "handle", "=", "fopen", "(", "$", "cachefile", ",", "'w'", ")", ";", "fwrite", "(", "$", "handle", ",", "$", "content", ")", ";", "fflush", "(", "$", "handle", ")", ";", "fclose", "(", "$", "handle", ")", ";", "$", "locking", "->", "unlock", "(", "'configwrite'", ",", "'config'", ")", ";", "@", "chmod", "(", "$", "cachefile", ",", "$", "CFG", "->", "filepermissions", ")", ";", "// Tell PHP to recompile the script.", "core_component", "::", "invalidate_opcode_php_cache", "(", "$", "cachefile", ")", ";", "}", "else", "{", "throw", "new", "cache_exception", "(", "'ex_configcannotsave'", ",", "'cache'", ",", "''", ",", "null", ",", "'Unable to open the cache config file.'", ")", ";", "}", "}" ]
Saves the current configuration. Exceptions within this function are tolerated but must be of type cache_exception. They are caught during initialisation and written to the error log. This is required in order to avoid infinite loop situations caused by the cache throwing exceptions during its initialisation.
[ "Saves", "the", "current", "configuration", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L69-L117
216,365
moodle/moodle
cache/locallib.php
cache_config_writer.add_store_instance
public function add_store_instance($name, $plugin, array $configuration = array()) { if (array_key_exists($name, $this->configstores)) { throw new cache_exception('Duplicate name specificed for cache plugin instance. You must provide a unique name.'); } $class = 'cachestore_'.$plugin; if (!class_exists($class)) { $plugins = core_component::get_plugin_list_with_file('cachestore', 'lib.php'); if (!array_key_exists($plugin, $plugins)) { throw new cache_exception('Invalid plugin name specified. The plugin does not exist or is not valid.'); } $file = $plugins[$plugin]; if (file_exists($file)) { require_once($file); } if (!class_exists($class)) { throw new cache_exception('Invalid cache plugin specified. The plugin does not contain the required class.'); } } $reflection = new ReflectionClass($class); if (!$reflection->isSubclassOf('cache_store')) { throw new cache_exception('Invalid cache plugin specified. The plugin does not extend the required class.'); } if (!$class::are_requirements_met()) { throw new cache_exception('Unable to add new cache plugin instance. The requested plugin type is not supported.'); } $this->configstores[$name] = array( 'name' => $name, 'plugin' => $plugin, 'configuration' => $configuration, 'features' => $class::get_supported_features($configuration), 'modes' => $class::get_supported_modes($configuration), 'mappingsonly' => !empty($configuration['mappingsonly']), 'class' => $class, 'default' => false ); if (array_key_exists('lock', $configuration)) { $this->configstores[$name]['lock'] = $configuration['lock']; unset($this->configstores[$name]['configuration']['lock']); } // Call instance_created() $store = new $class($name, $this->configstores[$name]['configuration']); $store->instance_created(); $this->config_save(); return true; }
php
public function add_store_instance($name, $plugin, array $configuration = array()) { if (array_key_exists($name, $this->configstores)) { throw new cache_exception('Duplicate name specificed for cache plugin instance. You must provide a unique name.'); } $class = 'cachestore_'.$plugin; if (!class_exists($class)) { $plugins = core_component::get_plugin_list_with_file('cachestore', 'lib.php'); if (!array_key_exists($plugin, $plugins)) { throw new cache_exception('Invalid plugin name specified. The plugin does not exist or is not valid.'); } $file = $plugins[$plugin]; if (file_exists($file)) { require_once($file); } if (!class_exists($class)) { throw new cache_exception('Invalid cache plugin specified. The plugin does not contain the required class.'); } } $reflection = new ReflectionClass($class); if (!$reflection->isSubclassOf('cache_store')) { throw new cache_exception('Invalid cache plugin specified. The plugin does not extend the required class.'); } if (!$class::are_requirements_met()) { throw new cache_exception('Unable to add new cache plugin instance. The requested plugin type is not supported.'); } $this->configstores[$name] = array( 'name' => $name, 'plugin' => $plugin, 'configuration' => $configuration, 'features' => $class::get_supported_features($configuration), 'modes' => $class::get_supported_modes($configuration), 'mappingsonly' => !empty($configuration['mappingsonly']), 'class' => $class, 'default' => false ); if (array_key_exists('lock', $configuration)) { $this->configstores[$name]['lock'] = $configuration['lock']; unset($this->configstores[$name]['configuration']['lock']); } // Call instance_created() $store = new $class($name, $this->configstores[$name]['configuration']); $store->instance_created(); $this->config_save(); return true; }
[ "public", "function", "add_store_instance", "(", "$", "name", ",", "$", "plugin", ",", "array", "$", "configuration", "=", "array", "(", ")", ")", "{", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "configstores", ")", ")", "{", "throw", "new", "cache_exception", "(", "'Duplicate name specificed for cache plugin instance. You must provide a unique name.'", ")", ";", "}", "$", "class", "=", "'cachestore_'", ".", "$", "plugin", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "$", "plugins", "=", "core_component", "::", "get_plugin_list_with_file", "(", "'cachestore'", ",", "'lib.php'", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "plugin", ",", "$", "plugins", ")", ")", "{", "throw", "new", "cache_exception", "(", "'Invalid plugin name specified. The plugin does not exist or is not valid.'", ")", ";", "}", "$", "file", "=", "$", "plugins", "[", "$", "plugin", "]", ";", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "require_once", "(", "$", "file", ")", ";", "}", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "cache_exception", "(", "'Invalid cache plugin specified. The plugin does not contain the required class.'", ")", ";", "}", "}", "$", "reflection", "=", "new", "ReflectionClass", "(", "$", "class", ")", ";", "if", "(", "!", "$", "reflection", "->", "isSubclassOf", "(", "'cache_store'", ")", ")", "{", "throw", "new", "cache_exception", "(", "'Invalid cache plugin specified. The plugin does not extend the required class.'", ")", ";", "}", "if", "(", "!", "$", "class", "::", "are_requirements_met", "(", ")", ")", "{", "throw", "new", "cache_exception", "(", "'Unable to add new cache plugin instance. The requested plugin type is not supported.'", ")", ";", "}", "$", "this", "->", "configstores", "[", "$", "name", "]", "=", "array", "(", "'name'", "=>", "$", "name", ",", "'plugin'", "=>", "$", "plugin", ",", "'configuration'", "=>", "$", "configuration", ",", "'features'", "=>", "$", "class", "::", "get_supported_features", "(", "$", "configuration", ")", ",", "'modes'", "=>", "$", "class", "::", "get_supported_modes", "(", "$", "configuration", ")", ",", "'mappingsonly'", "=>", "!", "empty", "(", "$", "configuration", "[", "'mappingsonly'", "]", ")", ",", "'class'", "=>", "$", "class", ",", "'default'", "=>", "false", ")", ";", "if", "(", "array_key_exists", "(", "'lock'", ",", "$", "configuration", ")", ")", "{", "$", "this", "->", "configstores", "[", "$", "name", "]", "[", "'lock'", "]", "=", "$", "configuration", "[", "'lock'", "]", ";", "unset", "(", "$", "this", "->", "configstores", "[", "$", "name", "]", "[", "'configuration'", "]", "[", "'lock'", "]", ")", ";", "}", "// Call instance_created()", "$", "store", "=", "new", "$", "class", "(", "$", "name", ",", "$", "this", "->", "configstores", "[", "$", "name", "]", "[", "'configuration'", "]", ")", ";", "$", "store", "->", "instance_created", "(", ")", ";", "$", "this", "->", "config_save", "(", ")", ";", "return", "true", ";", "}" ]
Adds a plugin instance. This function also calls save so you should redirect immediately, or at least very shortly after calling this method. @param string $name The name for the instance (must be unique) @param string $plugin The name of the plugin. @param array $configuration The configuration data for the plugin instance. @return bool @throws cache_exception
[ "Adds", "a", "plugin", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L146-L191
216,366
moodle/moodle
cache/locallib.php
cache_config_writer.add_lock_instance
public function add_lock_instance($name, $plugin, $configuration = array()) { if (array_key_exists($name, $this->configlocks)) { throw new cache_exception('Duplicate name specificed for cache lock instance. You must provide a unique name.'); } $class = 'cachelock_'.$plugin; if (!class_exists($class)) { $plugins = core_component::get_plugin_list_with_file('cachelock', 'lib.php'); if (!array_key_exists($plugin, $plugins)) { throw new cache_exception('Invalid lock name specified. The plugin does not exist or is not valid.'); } $file = $plugins[$plugin]; if (file_exists($file)) { require_once($file); } if (!class_exists($class)) { throw new cache_exception('Invalid lock plugin specified. The plugin does not contain the required class.'); } } $reflection = new ReflectionClass($class); if (!$reflection->implementsInterface('cache_lock_interface')) { throw new cache_exception('Invalid lock plugin specified. The plugin does not implement the required interface.'); } $this->configlocks[$name] = array_merge($configuration, array( 'name' => $name, 'type' => 'cachelock_'.$plugin, 'default' => false )); $this->config_save(); }
php
public function add_lock_instance($name, $plugin, $configuration = array()) { if (array_key_exists($name, $this->configlocks)) { throw new cache_exception('Duplicate name specificed for cache lock instance. You must provide a unique name.'); } $class = 'cachelock_'.$plugin; if (!class_exists($class)) { $plugins = core_component::get_plugin_list_with_file('cachelock', 'lib.php'); if (!array_key_exists($plugin, $plugins)) { throw new cache_exception('Invalid lock name specified. The plugin does not exist or is not valid.'); } $file = $plugins[$plugin]; if (file_exists($file)) { require_once($file); } if (!class_exists($class)) { throw new cache_exception('Invalid lock plugin specified. The plugin does not contain the required class.'); } } $reflection = new ReflectionClass($class); if (!$reflection->implementsInterface('cache_lock_interface')) { throw new cache_exception('Invalid lock plugin specified. The plugin does not implement the required interface.'); } $this->configlocks[$name] = array_merge($configuration, array( 'name' => $name, 'type' => 'cachelock_'.$plugin, 'default' => false )); $this->config_save(); }
[ "public", "function", "add_lock_instance", "(", "$", "name", ",", "$", "plugin", ",", "$", "configuration", "=", "array", "(", ")", ")", "{", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "configlocks", ")", ")", "{", "throw", "new", "cache_exception", "(", "'Duplicate name specificed for cache lock instance. You must provide a unique name.'", ")", ";", "}", "$", "class", "=", "'cachelock_'", ".", "$", "plugin", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "$", "plugins", "=", "core_component", "::", "get_plugin_list_with_file", "(", "'cachelock'", ",", "'lib.php'", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "plugin", ",", "$", "plugins", ")", ")", "{", "throw", "new", "cache_exception", "(", "'Invalid lock name specified. The plugin does not exist or is not valid.'", ")", ";", "}", "$", "file", "=", "$", "plugins", "[", "$", "plugin", "]", ";", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "require_once", "(", "$", "file", ")", ";", "}", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "cache_exception", "(", "'Invalid lock plugin specified. The plugin does not contain the required class.'", ")", ";", "}", "}", "$", "reflection", "=", "new", "ReflectionClass", "(", "$", "class", ")", ";", "if", "(", "!", "$", "reflection", "->", "implementsInterface", "(", "'cache_lock_interface'", ")", ")", "{", "throw", "new", "cache_exception", "(", "'Invalid lock plugin specified. The plugin does not implement the required interface.'", ")", ";", "}", "$", "this", "->", "configlocks", "[", "$", "name", "]", "=", "array_merge", "(", "$", "configuration", ",", "array", "(", "'name'", "=>", "$", "name", ",", "'type'", "=>", "'cachelock_'", ".", "$", "plugin", ",", "'default'", "=>", "false", ")", ")", ";", "$", "this", "->", "config_save", "(", ")", ";", "}" ]
Adds a new lock instance to the config file. @param string $name The name the user gave the instance. PARAM_ALHPANUMEXT @param string $plugin The plugin we are creating an instance of. @param string $configuration Configuration data from the config instance. @throws cache_exception
[ "Adds", "a", "new", "lock", "instance", "to", "the", "config", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L201-L229
216,367
moodle/moodle
cache/locallib.php
cache_config_writer.delete_lock_instance
public function delete_lock_instance($name) { if (!array_key_exists($name, $this->configlocks)) { throw new cache_exception('The requested store does not exist.'); } if ($this->configlocks[$name]['default']) { throw new cache_exception('You can not delete the default lock.'); } foreach ($this->configstores as $store) { if (isset($store['lock']) && $store['lock'] === $name) { throw new cache_exception('You cannot delete a cache lock that is being used by a store.'); } } unset($this->configlocks[$name]); $this->config_save(); return true; }
php
public function delete_lock_instance($name) { if (!array_key_exists($name, $this->configlocks)) { throw new cache_exception('The requested store does not exist.'); } if ($this->configlocks[$name]['default']) { throw new cache_exception('You can not delete the default lock.'); } foreach ($this->configstores as $store) { if (isset($store['lock']) && $store['lock'] === $name) { throw new cache_exception('You cannot delete a cache lock that is being used by a store.'); } } unset($this->configlocks[$name]); $this->config_save(); return true; }
[ "public", "function", "delete_lock_instance", "(", "$", "name", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "configlocks", ")", ")", "{", "throw", "new", "cache_exception", "(", "'The requested store does not exist.'", ")", ";", "}", "if", "(", "$", "this", "->", "configlocks", "[", "$", "name", "]", "[", "'default'", "]", ")", "{", "throw", "new", "cache_exception", "(", "'You can not delete the default lock.'", ")", ";", "}", "foreach", "(", "$", "this", "->", "configstores", "as", "$", "store", ")", "{", "if", "(", "isset", "(", "$", "store", "[", "'lock'", "]", ")", "&&", "$", "store", "[", "'lock'", "]", "===", "$", "name", ")", "{", "throw", "new", "cache_exception", "(", "'You cannot delete a cache lock that is being used by a store.'", ")", ";", "}", "}", "unset", "(", "$", "this", "->", "configlocks", "[", "$", "name", "]", ")", ";", "$", "this", "->", "config_save", "(", ")", ";", "return", "true", ";", "}" ]
Deletes a lock instance given its name. @param string $name The name of the plugin, PARAM_ALPHANUMEXT. @return bool @throws cache_exception
[ "Deletes", "a", "lock", "instance", "given", "its", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L238-L253
216,368
moodle/moodle
cache/locallib.php
cache_config_writer.set_mode_mappings
public function set_mode_mappings(array $modemappings) { $mappings = array( cache_store::MODE_APPLICATION => array(), cache_store::MODE_SESSION => array(), cache_store::MODE_REQUEST => array(), ); foreach ($modemappings as $mode => $stores) { if (!array_key_exists($mode, $mappings)) { throw new cache_exception('The cache mode for the new mapping does not exist'); } $sort = 0; foreach ($stores as $store) { if (!array_key_exists($store, $this->configstores)) { throw new cache_exception('The instance name for the new mapping does not exist'); } if (array_key_exists($store, $mappings[$mode])) { throw new cache_exception('This cache mapping already exists'); } $mappings[$mode][] = array( 'store' => $store, 'mode' => $mode, 'sort' => $sort++ ); } } $this->configmodemappings = array_merge( $mappings[cache_store::MODE_APPLICATION], $mappings[cache_store::MODE_SESSION], $mappings[cache_store::MODE_REQUEST] ); $this->config_save(); return true; }
php
public function set_mode_mappings(array $modemappings) { $mappings = array( cache_store::MODE_APPLICATION => array(), cache_store::MODE_SESSION => array(), cache_store::MODE_REQUEST => array(), ); foreach ($modemappings as $mode => $stores) { if (!array_key_exists($mode, $mappings)) { throw new cache_exception('The cache mode for the new mapping does not exist'); } $sort = 0; foreach ($stores as $store) { if (!array_key_exists($store, $this->configstores)) { throw new cache_exception('The instance name for the new mapping does not exist'); } if (array_key_exists($store, $mappings[$mode])) { throw new cache_exception('This cache mapping already exists'); } $mappings[$mode][] = array( 'store' => $store, 'mode' => $mode, 'sort' => $sort++ ); } } $this->configmodemappings = array_merge( $mappings[cache_store::MODE_APPLICATION], $mappings[cache_store::MODE_SESSION], $mappings[cache_store::MODE_REQUEST] ); $this->config_save(); return true; }
[ "public", "function", "set_mode_mappings", "(", "array", "$", "modemappings", ")", "{", "$", "mappings", "=", "array", "(", "cache_store", "::", "MODE_APPLICATION", "=>", "array", "(", ")", ",", "cache_store", "::", "MODE_SESSION", "=>", "array", "(", ")", ",", "cache_store", "::", "MODE_REQUEST", "=>", "array", "(", ")", ",", ")", ";", "foreach", "(", "$", "modemappings", "as", "$", "mode", "=>", "$", "stores", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "mode", ",", "$", "mappings", ")", ")", "{", "throw", "new", "cache_exception", "(", "'The cache mode for the new mapping does not exist'", ")", ";", "}", "$", "sort", "=", "0", ";", "foreach", "(", "$", "stores", "as", "$", "store", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "store", ",", "$", "this", "->", "configstores", ")", ")", "{", "throw", "new", "cache_exception", "(", "'The instance name for the new mapping does not exist'", ")", ";", "}", "if", "(", "array_key_exists", "(", "$", "store", ",", "$", "mappings", "[", "$", "mode", "]", ")", ")", "{", "throw", "new", "cache_exception", "(", "'This cache mapping already exists'", ")", ";", "}", "$", "mappings", "[", "$", "mode", "]", "[", "]", "=", "array", "(", "'store'", "=>", "$", "store", ",", "'mode'", "=>", "$", "mode", ",", "'sort'", "=>", "$", "sort", "++", ")", ";", "}", "}", "$", "this", "->", "configmodemappings", "=", "array_merge", "(", "$", "mappings", "[", "cache_store", "::", "MODE_APPLICATION", "]", ",", "$", "mappings", "[", "cache_store", "::", "MODE_SESSION", "]", ",", "$", "mappings", "[", "cache_store", "::", "MODE_REQUEST", "]", ")", ";", "$", "this", "->", "config_save", "(", ")", ";", "return", "true", ";", "}" ]
Sets the mode mappings. These determine the default caches for the different modes. This function also calls save so you should redirect immediately, or at least very shortly after calling this method. @param array $modemappings @return bool @throws cache_exception
[ "Sets", "the", "mode", "mappings", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L266-L299
216,369
moodle/moodle
cache/locallib.php
cache_config_writer.edit_store_instance
public function edit_store_instance($name, $plugin, $configuration) { if (!array_key_exists($name, $this->configstores)) { throw new cache_exception('The requested instance does not exist.'); } $plugins = core_component::get_plugin_list_with_file('cachestore', 'lib.php'); if (!array_key_exists($plugin, $plugins)) { throw new cache_exception('Invalid plugin name specified. The plugin either does not exist or is not valid.'); } $class = 'cachestore_'.$plugin; $file = $plugins[$plugin]; if (!class_exists($class)) { if (file_exists($file)) { require_once($file); } if (!class_exists($class)) { throw new cache_exception('Invalid cache plugin specified. The plugin does not contain the required class.'.$class); } } $this->configstores[$name] = array( 'name' => $name, 'plugin' => $plugin, 'configuration' => $configuration, 'features' => $class::get_supported_features($configuration), 'modes' => $class::get_supported_modes($configuration), 'mappingsonly' => !empty($configuration['mappingsonly']), 'class' => $class, 'default' => $this->configstores[$name]['default'] // Can't change the default. ); if (array_key_exists('lock', $configuration)) { $this->configstores[$name]['lock'] = $configuration['lock']; unset($this->configstores[$name]['configuration']['lock']); } $this->config_save(); return true; }
php
public function edit_store_instance($name, $plugin, $configuration) { if (!array_key_exists($name, $this->configstores)) { throw new cache_exception('The requested instance does not exist.'); } $plugins = core_component::get_plugin_list_with_file('cachestore', 'lib.php'); if (!array_key_exists($plugin, $plugins)) { throw new cache_exception('Invalid plugin name specified. The plugin either does not exist or is not valid.'); } $class = 'cachestore_'.$plugin; $file = $plugins[$plugin]; if (!class_exists($class)) { if (file_exists($file)) { require_once($file); } if (!class_exists($class)) { throw new cache_exception('Invalid cache plugin specified. The plugin does not contain the required class.'.$class); } } $this->configstores[$name] = array( 'name' => $name, 'plugin' => $plugin, 'configuration' => $configuration, 'features' => $class::get_supported_features($configuration), 'modes' => $class::get_supported_modes($configuration), 'mappingsonly' => !empty($configuration['mappingsonly']), 'class' => $class, 'default' => $this->configstores[$name]['default'] // Can't change the default. ); if (array_key_exists('lock', $configuration)) { $this->configstores[$name]['lock'] = $configuration['lock']; unset($this->configstores[$name]['configuration']['lock']); } $this->config_save(); return true; }
[ "public", "function", "edit_store_instance", "(", "$", "name", ",", "$", "plugin", ",", "$", "configuration", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "configstores", ")", ")", "{", "throw", "new", "cache_exception", "(", "'The requested instance does not exist.'", ")", ";", "}", "$", "plugins", "=", "core_component", "::", "get_plugin_list_with_file", "(", "'cachestore'", ",", "'lib.php'", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "plugin", ",", "$", "plugins", ")", ")", "{", "throw", "new", "cache_exception", "(", "'Invalid plugin name specified. The plugin either does not exist or is not valid.'", ")", ";", "}", "$", "class", "=", "'cachestore_'", ".", "$", "plugin", ";", "$", "file", "=", "$", "plugins", "[", "$", "plugin", "]", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "require_once", "(", "$", "file", ")", ";", "}", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "cache_exception", "(", "'Invalid cache plugin specified. The plugin does not contain the required class.'", ".", "$", "class", ")", ";", "}", "}", "$", "this", "->", "configstores", "[", "$", "name", "]", "=", "array", "(", "'name'", "=>", "$", "name", ",", "'plugin'", "=>", "$", "plugin", ",", "'configuration'", "=>", "$", "configuration", ",", "'features'", "=>", "$", "class", "::", "get_supported_features", "(", "$", "configuration", ")", ",", "'modes'", "=>", "$", "class", "::", "get_supported_modes", "(", "$", "configuration", ")", ",", "'mappingsonly'", "=>", "!", "empty", "(", "$", "configuration", "[", "'mappingsonly'", "]", ")", ",", "'class'", "=>", "$", "class", ",", "'default'", "=>", "$", "this", "->", "configstores", "[", "$", "name", "]", "[", "'default'", "]", "// Can't change the default.", ")", ";", "if", "(", "array_key_exists", "(", "'lock'", ",", "$", "configuration", ")", ")", "{", "$", "this", "->", "configstores", "[", "$", "name", "]", "[", "'lock'", "]", "=", "$", "configuration", "[", "'lock'", "]", ";", "unset", "(", "$", "this", "->", "configstores", "[", "$", "name", "]", "[", "'configuration'", "]", "[", "'lock'", "]", ")", ";", "}", "$", "this", "->", "config_save", "(", ")", ";", "return", "true", ";", "}" ]
Edits a give plugin instance. The plugin instance is determined by its name, hence you cannot rename plugins. This function also calls save so you should redirect immediately, or at least very shortly after calling this method. @param string $name @param string $plugin @param array $configuration @return bool @throws cache_exception
[ "Edits", "a", "give", "plugin", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L314-L348
216,370
moodle/moodle
cache/locallib.php
cache_config_writer.delete_store_instance
public function delete_store_instance($name) { if (!array_key_exists($name, $this->configstores)) { throw new cache_exception('The requested store does not exist.'); } if ($this->configstores[$name]['default']) { throw new cache_exception('The can not delete the default stores.'); } foreach ($this->configmodemappings as $mapping) { if ($mapping['store'] === $name) { throw new cache_exception('You cannot delete a cache store that has mode mappings.'); } } foreach ($this->configdefinitionmappings as $mapping) { if ($mapping['store'] === $name) { throw new cache_exception('You cannot delete a cache store that has definition mappings.'); } } // Call instance_deleted() $class = 'cachestore_'.$this->configstores[$name]['plugin']; $store = new $class($name, $this->configstores[$name]['configuration']); $store->instance_deleted(); unset($this->configstores[$name]); $this->config_save(); return true; }
php
public function delete_store_instance($name) { if (!array_key_exists($name, $this->configstores)) { throw new cache_exception('The requested store does not exist.'); } if ($this->configstores[$name]['default']) { throw new cache_exception('The can not delete the default stores.'); } foreach ($this->configmodemappings as $mapping) { if ($mapping['store'] === $name) { throw new cache_exception('You cannot delete a cache store that has mode mappings.'); } } foreach ($this->configdefinitionmappings as $mapping) { if ($mapping['store'] === $name) { throw new cache_exception('You cannot delete a cache store that has definition mappings.'); } } // Call instance_deleted() $class = 'cachestore_'.$this->configstores[$name]['plugin']; $store = new $class($name, $this->configstores[$name]['configuration']); $store->instance_deleted(); unset($this->configstores[$name]); $this->config_save(); return true; }
[ "public", "function", "delete_store_instance", "(", "$", "name", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "configstores", ")", ")", "{", "throw", "new", "cache_exception", "(", "'The requested store does not exist.'", ")", ";", "}", "if", "(", "$", "this", "->", "configstores", "[", "$", "name", "]", "[", "'default'", "]", ")", "{", "throw", "new", "cache_exception", "(", "'The can not delete the default stores.'", ")", ";", "}", "foreach", "(", "$", "this", "->", "configmodemappings", "as", "$", "mapping", ")", "{", "if", "(", "$", "mapping", "[", "'store'", "]", "===", "$", "name", ")", "{", "throw", "new", "cache_exception", "(", "'You cannot delete a cache store that has mode mappings.'", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "configdefinitionmappings", "as", "$", "mapping", ")", "{", "if", "(", "$", "mapping", "[", "'store'", "]", "===", "$", "name", ")", "{", "throw", "new", "cache_exception", "(", "'You cannot delete a cache store that has definition mappings.'", ")", ";", "}", "}", "// Call instance_deleted()", "$", "class", "=", "'cachestore_'", ".", "$", "this", "->", "configstores", "[", "$", "name", "]", "[", "'plugin'", "]", ";", "$", "store", "=", "new", "$", "class", "(", "$", "name", ",", "$", "this", "->", "configstores", "[", "$", "name", "]", "[", "'configuration'", "]", ")", ";", "$", "store", "->", "instance_deleted", "(", ")", ";", "unset", "(", "$", "this", "->", "configstores", "[", "$", "name", "]", ")", ";", "$", "this", "->", "config_save", "(", ")", ";", "return", "true", ";", "}" ]
Deletes a store instance. This function also calls save so you should redirect immediately, or at least very shortly after calling this method. @param string $name The name of the instance to delete. @return bool @throws cache_exception
[ "Deletes", "a", "store", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L360-L386
216,371
moodle/moodle
cache/locallib.php
cache_config_writer.get_default_stores
protected static function get_default_stores() { global $CFG; require_once($CFG->dirroot.'/cache/stores/file/lib.php'); require_once($CFG->dirroot.'/cache/stores/session/lib.php'); require_once($CFG->dirroot.'/cache/stores/static/lib.php'); return array( 'default_application' => array( 'name' => 'default_application', 'plugin' => 'file', 'configuration' => array(), 'features' => cachestore_file::get_supported_features(), 'modes' => cachestore_file::get_supported_modes(), 'default' => true, ), 'default_session' => array( 'name' => 'default_session', 'plugin' => 'session', 'configuration' => array(), 'features' => cachestore_session::get_supported_features(), 'modes' => cachestore_session::get_supported_modes(), 'default' => true, ), 'default_request' => array( 'name' => 'default_request', 'plugin' => 'static', 'configuration' => array(), 'features' => cachestore_static::get_supported_features(), 'modes' => cachestore_static::get_supported_modes(), 'default' => true, ) ); }
php
protected static function get_default_stores() { global $CFG; require_once($CFG->dirroot.'/cache/stores/file/lib.php'); require_once($CFG->dirroot.'/cache/stores/session/lib.php'); require_once($CFG->dirroot.'/cache/stores/static/lib.php'); return array( 'default_application' => array( 'name' => 'default_application', 'plugin' => 'file', 'configuration' => array(), 'features' => cachestore_file::get_supported_features(), 'modes' => cachestore_file::get_supported_modes(), 'default' => true, ), 'default_session' => array( 'name' => 'default_session', 'plugin' => 'session', 'configuration' => array(), 'features' => cachestore_session::get_supported_features(), 'modes' => cachestore_session::get_supported_modes(), 'default' => true, ), 'default_request' => array( 'name' => 'default_request', 'plugin' => 'static', 'configuration' => array(), 'features' => cachestore_static::get_supported_features(), 'modes' => cachestore_static::get_supported_modes(), 'default' => true, ) ); }
[ "protected", "static", "function", "get_default_stores", "(", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/cache/stores/file/lib.php'", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/cache/stores/session/lib.php'", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/cache/stores/static/lib.php'", ")", ";", "return", "array", "(", "'default_application'", "=>", "array", "(", "'name'", "=>", "'default_application'", ",", "'plugin'", "=>", "'file'", ",", "'configuration'", "=>", "array", "(", ")", ",", "'features'", "=>", "cachestore_file", "::", "get_supported_features", "(", ")", ",", "'modes'", "=>", "cachestore_file", "::", "get_supported_modes", "(", ")", ",", "'default'", "=>", "true", ",", ")", ",", "'default_session'", "=>", "array", "(", "'name'", "=>", "'default_session'", ",", "'plugin'", "=>", "'session'", ",", "'configuration'", "=>", "array", "(", ")", ",", "'features'", "=>", "cachestore_session", "::", "get_supported_features", "(", ")", ",", "'modes'", "=>", "cachestore_session", "::", "get_supported_modes", "(", ")", ",", "'default'", "=>", "true", ",", ")", ",", "'default_request'", "=>", "array", "(", "'name'", "=>", "'default_request'", ",", "'plugin'", "=>", "'static'", ",", "'configuration'", "=>", "array", "(", ")", ",", "'features'", "=>", "cachestore_static", "::", "get_supported_features", "(", ")", ",", "'modes'", "=>", "cachestore_static", "::", "get_supported_modes", "(", ")", ",", "'default'", "=>", "true", ",", ")", ")", ";", "}" ]
Returns an array of default stores for use. @return array
[ "Returns", "an", "array", "of", "default", "stores", "for", "use", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L447-L480
216,372
moodle/moodle
cache/locallib.php
cache_config_writer.update_default_config_stores
public static function update_default_config_stores() { $factory = cache_factory::instance(); $factory->updating_started(); $config = $factory->create_config_instance(true); $config->configstores = array_merge($config->configstores, self::get_default_stores()); $config->config_save(); $factory->updating_finished(); }
php
public static function update_default_config_stores() { $factory = cache_factory::instance(); $factory->updating_started(); $config = $factory->create_config_instance(true); $config->configstores = array_merge($config->configstores, self::get_default_stores()); $config->config_save(); $factory->updating_finished(); }
[ "public", "static", "function", "update_default_config_stores", "(", ")", "{", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "$", "factory", "->", "updating_started", "(", ")", ";", "$", "config", "=", "$", "factory", "->", "create_config_instance", "(", "true", ")", ";", "$", "config", "->", "configstores", "=", "array_merge", "(", "$", "config", "->", "configstores", ",", "self", "::", "get_default_stores", "(", ")", ")", ";", "$", "config", "->", "config_save", "(", ")", ";", "$", "factory", "->", "updating_finished", "(", ")", ";", "}" ]
Updates the default stores within the MUC config file.
[ "Updates", "the", "default", "stores", "within", "the", "MUC", "config", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L485-L492
216,373
moodle/moodle
cache/locallib.php
cache_config_writer.update_definitions
public static function update_definitions($coreonly = false) { $factory = cache_factory::instance(); $factory->updating_started(); $config = $factory->create_config_instance(true); $config->write_definitions_to_cache(self::locate_definitions($coreonly)); $factory->updating_finished(); }
php
public static function update_definitions($coreonly = false) { $factory = cache_factory::instance(); $factory->updating_started(); $config = $factory->create_config_instance(true); $config->write_definitions_to_cache(self::locate_definitions($coreonly)); $factory->updating_finished(); }
[ "public", "static", "function", "update_definitions", "(", "$", "coreonly", "=", "false", ")", "{", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "$", "factory", "->", "updating_started", "(", ")", ";", "$", "config", "=", "$", "factory", "->", "create_config_instance", "(", "true", ")", ";", "$", "config", "->", "write_definitions_to_cache", "(", "self", "::", "locate_definitions", "(", "$", "coreonly", ")", ")", ";", "$", "factory", "->", "updating_finished", "(", ")", ";", "}" ]
Updates the definition in the configuration from those found in the cache files. Calls config_save further down, you should redirect immediately or asap after calling this method. @param bool $coreonly If set to true only core definitions will be updated.
[ "Updates", "the", "definition", "in", "the", "configuration", "from", "those", "found", "in", "the", "cache", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L501-L507
216,374
moodle/moodle
cache/locallib.php
cache_config_writer.locate_definitions
protected static function locate_definitions($coreonly = false) { global $CFG; $files = array(); if (file_exists($CFG->dirroot.'/lib/db/caches.php')) { $files['core'] = $CFG->dirroot.'/lib/db/caches.php'; } if (!$coreonly) { $plugintypes = core_component::get_plugin_types(); foreach ($plugintypes as $type => $location) { $plugins = core_component::get_plugin_list_with_file($type, 'db/caches.php'); foreach ($plugins as $plugin => $filepath) { $component = clean_param($type.'_'.$plugin, PARAM_COMPONENT); // Standardised plugin name. $files[$component] = $filepath; } } } $definitions = array(); foreach ($files as $component => $file) { $filedefs = self::load_caches_file($file); foreach ($filedefs as $area => $definition) { $area = clean_param($area, PARAM_AREA); $id = $component.'/'.$area; $definition['component'] = $component; $definition['area'] = $area; if (array_key_exists($id, $definitions)) { debugging('Error: duplicate cache definition found with id: '.$id, DEBUG_DEVELOPER); continue; } $definitions[$id] = $definition; } } return $definitions; }
php
protected static function locate_definitions($coreonly = false) { global $CFG; $files = array(); if (file_exists($CFG->dirroot.'/lib/db/caches.php')) { $files['core'] = $CFG->dirroot.'/lib/db/caches.php'; } if (!$coreonly) { $plugintypes = core_component::get_plugin_types(); foreach ($plugintypes as $type => $location) { $plugins = core_component::get_plugin_list_with_file($type, 'db/caches.php'); foreach ($plugins as $plugin => $filepath) { $component = clean_param($type.'_'.$plugin, PARAM_COMPONENT); // Standardised plugin name. $files[$component] = $filepath; } } } $definitions = array(); foreach ($files as $component => $file) { $filedefs = self::load_caches_file($file); foreach ($filedefs as $area => $definition) { $area = clean_param($area, PARAM_AREA); $id = $component.'/'.$area; $definition['component'] = $component; $definition['area'] = $area; if (array_key_exists($id, $definitions)) { debugging('Error: duplicate cache definition found with id: '.$id, DEBUG_DEVELOPER); continue; } $definitions[$id] = $definition; } } return $definitions; }
[ "protected", "static", "function", "locate_definitions", "(", "$", "coreonly", "=", "false", ")", "{", "global", "$", "CFG", ";", "$", "files", "=", "array", "(", ")", ";", "if", "(", "file_exists", "(", "$", "CFG", "->", "dirroot", ".", "'/lib/db/caches.php'", ")", ")", "{", "$", "files", "[", "'core'", "]", "=", "$", "CFG", "->", "dirroot", ".", "'/lib/db/caches.php'", ";", "}", "if", "(", "!", "$", "coreonly", ")", "{", "$", "plugintypes", "=", "core_component", "::", "get_plugin_types", "(", ")", ";", "foreach", "(", "$", "plugintypes", "as", "$", "type", "=>", "$", "location", ")", "{", "$", "plugins", "=", "core_component", "::", "get_plugin_list_with_file", "(", "$", "type", ",", "'db/caches.php'", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", "=>", "$", "filepath", ")", "{", "$", "component", "=", "clean_param", "(", "$", "type", ".", "'_'", ".", "$", "plugin", ",", "PARAM_COMPONENT", ")", ";", "// Standardised plugin name.", "$", "files", "[", "$", "component", "]", "=", "$", "filepath", ";", "}", "}", "}", "$", "definitions", "=", "array", "(", ")", ";", "foreach", "(", "$", "files", "as", "$", "component", "=>", "$", "file", ")", "{", "$", "filedefs", "=", "self", "::", "load_caches_file", "(", "$", "file", ")", ";", "foreach", "(", "$", "filedefs", "as", "$", "area", "=>", "$", "definition", ")", "{", "$", "area", "=", "clean_param", "(", "$", "area", ",", "PARAM_AREA", ")", ";", "$", "id", "=", "$", "component", ".", "'/'", ".", "$", "area", ";", "$", "definition", "[", "'component'", "]", "=", "$", "component", ";", "$", "definition", "[", "'area'", "]", "=", "$", "area", ";", "if", "(", "array_key_exists", "(", "$", "id", ",", "$", "definitions", ")", ")", "{", "debugging", "(", "'Error: duplicate cache definition found with id: '", ".", "$", "id", ",", "DEBUG_DEVELOPER", ")", ";", "continue", ";", "}", "$", "definitions", "[", "$", "id", "]", "=", "$", "definition", ";", "}", "}", "return", "$", "definitions", ";", "}" ]
Locates all of the definition files. @param bool $coreonly If set to true only core definitions will be updated. @return array
[ "Locates", "all", "of", "the", "definition", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L515-L551
216,375
moodle/moodle
cache/locallib.php
cache_config_writer.write_definitions_to_cache
private function write_definitions_to_cache(array $definitions) { // Preserve the selected sharing option when updating the definitions. // This is set by the user and should never come from caches.php. foreach ($definitions as $key => $definition) { unset($definitions[$key]['selectedsharingoption']); unset($definitions[$key]['userinputsharingkey']); if (isset($this->configdefinitions[$key]) && isset($this->configdefinitions[$key]['selectedsharingoption'])) { $definitions[$key]['selectedsharingoption'] = $this->configdefinitions[$key]['selectedsharingoption']; } if (isset($this->configdefinitions[$key]) && isset($this->configdefinitions[$key]['userinputsharingkey'])) { $definitions[$key]['userinputsharingkey'] = $this->configdefinitions[$key]['userinputsharingkey']; } } $this->configdefinitions = $definitions; foreach ($this->configdefinitionmappings as $key => $mapping) { if (!array_key_exists($mapping['definition'], $definitions)) { unset($this->configdefinitionmappings[$key]); } } $this->config_save(); }
php
private function write_definitions_to_cache(array $definitions) { // Preserve the selected sharing option when updating the definitions. // This is set by the user and should never come from caches.php. foreach ($definitions as $key => $definition) { unset($definitions[$key]['selectedsharingoption']); unset($definitions[$key]['userinputsharingkey']); if (isset($this->configdefinitions[$key]) && isset($this->configdefinitions[$key]['selectedsharingoption'])) { $definitions[$key]['selectedsharingoption'] = $this->configdefinitions[$key]['selectedsharingoption']; } if (isset($this->configdefinitions[$key]) && isset($this->configdefinitions[$key]['userinputsharingkey'])) { $definitions[$key]['userinputsharingkey'] = $this->configdefinitions[$key]['userinputsharingkey']; } } $this->configdefinitions = $definitions; foreach ($this->configdefinitionmappings as $key => $mapping) { if (!array_key_exists($mapping['definition'], $definitions)) { unset($this->configdefinitionmappings[$key]); } } $this->config_save(); }
[ "private", "function", "write_definitions_to_cache", "(", "array", "$", "definitions", ")", "{", "// Preserve the selected sharing option when updating the definitions.", "// This is set by the user and should never come from caches.php.", "foreach", "(", "$", "definitions", "as", "$", "key", "=>", "$", "definition", ")", "{", "unset", "(", "$", "definitions", "[", "$", "key", "]", "[", "'selectedsharingoption'", "]", ")", ";", "unset", "(", "$", "definitions", "[", "$", "key", "]", "[", "'userinputsharingkey'", "]", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "configdefinitions", "[", "$", "key", "]", ")", "&&", "isset", "(", "$", "this", "->", "configdefinitions", "[", "$", "key", "]", "[", "'selectedsharingoption'", "]", ")", ")", "{", "$", "definitions", "[", "$", "key", "]", "[", "'selectedsharingoption'", "]", "=", "$", "this", "->", "configdefinitions", "[", "$", "key", "]", "[", "'selectedsharingoption'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "configdefinitions", "[", "$", "key", "]", ")", "&&", "isset", "(", "$", "this", "->", "configdefinitions", "[", "$", "key", "]", "[", "'userinputsharingkey'", "]", ")", ")", "{", "$", "definitions", "[", "$", "key", "]", "[", "'userinputsharingkey'", "]", "=", "$", "this", "->", "configdefinitions", "[", "$", "key", "]", "[", "'userinputsharingkey'", "]", ";", "}", "}", "$", "this", "->", "configdefinitions", "=", "$", "definitions", ";", "foreach", "(", "$", "this", "->", "configdefinitionmappings", "as", "$", "key", "=>", "$", "mapping", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "mapping", "[", "'definition'", "]", ",", "$", "definitions", ")", ")", "{", "unset", "(", "$", "this", "->", "configdefinitionmappings", "[", "$", "key", "]", ")", ";", "}", "}", "$", "this", "->", "config_save", "(", ")", ";", "}" ]
Writes the updated definitions for the config file. @param array $definitions
[ "Writes", "the", "updated", "definitions", "for", "the", "config", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L557-L579
216,376
moodle/moodle
cache/locallib.php
cache_config_writer.set_definition_mappings
public function set_definition_mappings($definition, $mappings) { if (!array_key_exists($definition, $this->configdefinitions)) { throw new coding_exception('Invalid definition name passed when updating mappings.'); } foreach ($mappings as $store) { if (!array_key_exists($store, $this->configstores)) { throw new coding_exception('Invalid store name passed when updating definition mappings.'); } } foreach ($this->configdefinitionmappings as $key => $mapping) { if ($mapping['definition'] == $definition) { unset($this->configdefinitionmappings[$key]); } } $sort = count($mappings); foreach ($mappings as $store) { $this->configdefinitionmappings[] = array( 'store' => $store, 'definition' => $definition, 'sort' => $sort ); $sort--; } $this->config_save(); }
php
public function set_definition_mappings($definition, $mappings) { if (!array_key_exists($definition, $this->configdefinitions)) { throw new coding_exception('Invalid definition name passed when updating mappings.'); } foreach ($mappings as $store) { if (!array_key_exists($store, $this->configstores)) { throw new coding_exception('Invalid store name passed when updating definition mappings.'); } } foreach ($this->configdefinitionmappings as $key => $mapping) { if ($mapping['definition'] == $definition) { unset($this->configdefinitionmappings[$key]); } } $sort = count($mappings); foreach ($mappings as $store) { $this->configdefinitionmappings[] = array( 'store' => $store, 'definition' => $definition, 'sort' => $sort ); $sort--; } $this->config_save(); }
[ "public", "function", "set_definition_mappings", "(", "$", "definition", ",", "$", "mappings", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "definition", ",", "$", "this", "->", "configdefinitions", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid definition name passed when updating mappings.'", ")", ";", "}", "foreach", "(", "$", "mappings", "as", "$", "store", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "store", ",", "$", "this", "->", "configstores", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid store name passed when updating definition mappings.'", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "configdefinitionmappings", "as", "$", "key", "=>", "$", "mapping", ")", "{", "if", "(", "$", "mapping", "[", "'definition'", "]", "==", "$", "definition", ")", "{", "unset", "(", "$", "this", "->", "configdefinitionmappings", "[", "$", "key", "]", ")", ";", "}", "}", "$", "sort", "=", "count", "(", "$", "mappings", ")", ";", "foreach", "(", "$", "mappings", "as", "$", "store", ")", "{", "$", "this", "->", "configdefinitionmappings", "[", "]", "=", "array", "(", "'store'", "=>", "$", "store", ",", "'definition'", "=>", "$", "definition", ",", "'sort'", "=>", "$", "sort", ")", ";", "$", "sort", "--", ";", "}", "$", "this", "->", "config_save", "(", ")", ";", "}" ]
Sets the mappings for a given definition. @param string $definition @param array $mappings @throws coding_exception
[ "Sets", "the", "mappings", "for", "a", "given", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L602-L627
216,377
moodle/moodle
cache/locallib.php
cache_config_writer.set_definition_sharing
public function set_definition_sharing($definition, $sharingoption, $userinputsharingkey = null) { if (!array_key_exists($definition, $this->configdefinitions)) { throw new coding_exception('Invalid definition name passed when updating sharing options.'); } if (!($this->configdefinitions[$definition]['sharingoptions'] & $sharingoption)) { throw new coding_exception('Invalid sharing option passed when updating definition.'); } $this->configdefinitions[$definition]['selectedsharingoption'] = (int)$sharingoption; if (!empty($userinputsharingkey)) { $this->configdefinitions[$definition]['userinputsharingkey'] = (string)$userinputsharingkey; } $this->config_save(); }
php
public function set_definition_sharing($definition, $sharingoption, $userinputsharingkey = null) { if (!array_key_exists($definition, $this->configdefinitions)) { throw new coding_exception('Invalid definition name passed when updating sharing options.'); } if (!($this->configdefinitions[$definition]['sharingoptions'] & $sharingoption)) { throw new coding_exception('Invalid sharing option passed when updating definition.'); } $this->configdefinitions[$definition]['selectedsharingoption'] = (int)$sharingoption; if (!empty($userinputsharingkey)) { $this->configdefinitions[$definition]['userinputsharingkey'] = (string)$userinputsharingkey; } $this->config_save(); }
[ "public", "function", "set_definition_sharing", "(", "$", "definition", ",", "$", "sharingoption", ",", "$", "userinputsharingkey", "=", "null", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "definition", ",", "$", "this", "->", "configdefinitions", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid definition name passed when updating sharing options.'", ")", ";", "}", "if", "(", "!", "(", "$", "this", "->", "configdefinitions", "[", "$", "definition", "]", "[", "'sharingoptions'", "]", "&", "$", "sharingoption", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid sharing option passed when updating definition.'", ")", ";", "}", "$", "this", "->", "configdefinitions", "[", "$", "definition", "]", "[", "'selectedsharingoption'", "]", "=", "(", "int", ")", "$", "sharingoption", ";", "if", "(", "!", "empty", "(", "$", "userinputsharingkey", ")", ")", "{", "$", "this", "->", "configdefinitions", "[", "$", "definition", "]", "[", "'userinputsharingkey'", "]", "=", "(", "string", ")", "$", "userinputsharingkey", ";", "}", "$", "this", "->", "config_save", "(", ")", ";", "}" ]
Sets the selected sharing options and key for a definition. @param string $definition The name of the definition to set for. @param int $sharingoption The sharing option to set. @param string|null $userinputsharingkey The user input key or null. @throws coding_exception
[ "Sets", "the", "selected", "sharing", "options", "and", "key", "for", "a", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L649-L661
216,378
moodle/moodle
cache/locallib.php
cache_administration_helper.get_store_instance_summaries
public static function get_store_instance_summaries() { $return = array(); $default = array(); $instance = cache_config::instance(); $stores = $instance->get_all_stores(); $locks = $instance->get_locks(); foreach ($stores as $name => $details) { $class = $details['class']; $store = false; if ($class::are_requirements_met()) { $store = new $class($details['name'], $details['configuration']); } $lock = (isset($details['lock'])) ? $locks[$details['lock']] : $instance->get_default_lock(); $record = array( 'name' => $name, 'plugin' => $details['plugin'], 'default' => $details['default'], 'isready' => $store ? $store->is_ready() : false, 'requirementsmet' => $class::are_requirements_met(), 'mappings' => 0, 'lock' => $lock, 'modes' => array( cache_store::MODE_APPLICATION => ($class::get_supported_modes($return) & cache_store::MODE_APPLICATION) == cache_store::MODE_APPLICATION, cache_store::MODE_SESSION => ($class::get_supported_modes($return) & cache_store::MODE_SESSION) == cache_store::MODE_SESSION, cache_store::MODE_REQUEST => ($class::get_supported_modes($return) & cache_store::MODE_REQUEST) == cache_store::MODE_REQUEST, ), 'supports' => array( 'multipleidentifiers' => $store ? $store->supports_multiple_identifiers() : false, 'dataguarantee' => $store ? $store->supports_data_guarantee() : false, 'nativettl' => $store ? $store->supports_native_ttl() : false, 'nativelocking' => ($store instanceof cache_is_lockable), 'keyawareness' => ($store instanceof cache_is_key_aware), 'searchable' => ($store instanceof cache_is_searchable) ), 'warnings' => $store ? $store->get_warnings() : array() ); if (empty($details['default'])) { $return[$name] = $record; } else { $default[$name] = $record; } } ksort($return); ksort($default); $return = $return + $default; foreach ($instance->get_definition_mappings() as $mapping) { if (!array_key_exists($mapping['store'], $return)) { continue; } $return[$mapping['store']]['mappings']++; } return $return; }
php
public static function get_store_instance_summaries() { $return = array(); $default = array(); $instance = cache_config::instance(); $stores = $instance->get_all_stores(); $locks = $instance->get_locks(); foreach ($stores as $name => $details) { $class = $details['class']; $store = false; if ($class::are_requirements_met()) { $store = new $class($details['name'], $details['configuration']); } $lock = (isset($details['lock'])) ? $locks[$details['lock']] : $instance->get_default_lock(); $record = array( 'name' => $name, 'plugin' => $details['plugin'], 'default' => $details['default'], 'isready' => $store ? $store->is_ready() : false, 'requirementsmet' => $class::are_requirements_met(), 'mappings' => 0, 'lock' => $lock, 'modes' => array( cache_store::MODE_APPLICATION => ($class::get_supported_modes($return) & cache_store::MODE_APPLICATION) == cache_store::MODE_APPLICATION, cache_store::MODE_SESSION => ($class::get_supported_modes($return) & cache_store::MODE_SESSION) == cache_store::MODE_SESSION, cache_store::MODE_REQUEST => ($class::get_supported_modes($return) & cache_store::MODE_REQUEST) == cache_store::MODE_REQUEST, ), 'supports' => array( 'multipleidentifiers' => $store ? $store->supports_multiple_identifiers() : false, 'dataguarantee' => $store ? $store->supports_data_guarantee() : false, 'nativettl' => $store ? $store->supports_native_ttl() : false, 'nativelocking' => ($store instanceof cache_is_lockable), 'keyawareness' => ($store instanceof cache_is_key_aware), 'searchable' => ($store instanceof cache_is_searchable) ), 'warnings' => $store ? $store->get_warnings() : array() ); if (empty($details['default'])) { $return[$name] = $record; } else { $default[$name] = $record; } } ksort($return); ksort($default); $return = $return + $default; foreach ($instance->get_definition_mappings() as $mapping) { if (!array_key_exists($mapping['store'], $return)) { continue; } $return[$mapping['store']]['mappings']++; } return $return; }
[ "public", "static", "function", "get_store_instance_summaries", "(", ")", "{", "$", "return", "=", "array", "(", ")", ";", "$", "default", "=", "array", "(", ")", ";", "$", "instance", "=", "cache_config", "::", "instance", "(", ")", ";", "$", "stores", "=", "$", "instance", "->", "get_all_stores", "(", ")", ";", "$", "locks", "=", "$", "instance", "->", "get_locks", "(", ")", ";", "foreach", "(", "$", "stores", "as", "$", "name", "=>", "$", "details", ")", "{", "$", "class", "=", "$", "details", "[", "'class'", "]", ";", "$", "store", "=", "false", ";", "if", "(", "$", "class", "::", "are_requirements_met", "(", ")", ")", "{", "$", "store", "=", "new", "$", "class", "(", "$", "details", "[", "'name'", "]", ",", "$", "details", "[", "'configuration'", "]", ")", ";", "}", "$", "lock", "=", "(", "isset", "(", "$", "details", "[", "'lock'", "]", ")", ")", "?", "$", "locks", "[", "$", "details", "[", "'lock'", "]", "]", ":", "$", "instance", "->", "get_default_lock", "(", ")", ";", "$", "record", "=", "array", "(", "'name'", "=>", "$", "name", ",", "'plugin'", "=>", "$", "details", "[", "'plugin'", "]", ",", "'default'", "=>", "$", "details", "[", "'default'", "]", ",", "'isready'", "=>", "$", "store", "?", "$", "store", "->", "is_ready", "(", ")", ":", "false", ",", "'requirementsmet'", "=>", "$", "class", "::", "are_requirements_met", "(", ")", ",", "'mappings'", "=>", "0", ",", "'lock'", "=>", "$", "lock", ",", "'modes'", "=>", "array", "(", "cache_store", "::", "MODE_APPLICATION", "=>", "(", "$", "class", "::", "get_supported_modes", "(", "$", "return", ")", "&", "cache_store", "::", "MODE_APPLICATION", ")", "==", "cache_store", "::", "MODE_APPLICATION", ",", "cache_store", "::", "MODE_SESSION", "=>", "(", "$", "class", "::", "get_supported_modes", "(", "$", "return", ")", "&", "cache_store", "::", "MODE_SESSION", ")", "==", "cache_store", "::", "MODE_SESSION", ",", "cache_store", "::", "MODE_REQUEST", "=>", "(", "$", "class", "::", "get_supported_modes", "(", "$", "return", ")", "&", "cache_store", "::", "MODE_REQUEST", ")", "==", "cache_store", "::", "MODE_REQUEST", ",", ")", ",", "'supports'", "=>", "array", "(", "'multipleidentifiers'", "=>", "$", "store", "?", "$", "store", "->", "supports_multiple_identifiers", "(", ")", ":", "false", ",", "'dataguarantee'", "=>", "$", "store", "?", "$", "store", "->", "supports_data_guarantee", "(", ")", ":", "false", ",", "'nativettl'", "=>", "$", "store", "?", "$", "store", "->", "supports_native_ttl", "(", ")", ":", "false", ",", "'nativelocking'", "=>", "(", "$", "store", "instanceof", "cache_is_lockable", ")", ",", "'keyawareness'", "=>", "(", "$", "store", "instanceof", "cache_is_key_aware", ")", ",", "'searchable'", "=>", "(", "$", "store", "instanceof", "cache_is_searchable", ")", ")", ",", "'warnings'", "=>", "$", "store", "?", "$", "store", "->", "get_warnings", "(", ")", ":", "array", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "details", "[", "'default'", "]", ")", ")", "{", "$", "return", "[", "$", "name", "]", "=", "$", "record", ";", "}", "else", "{", "$", "default", "[", "$", "name", "]", "=", "$", "record", ";", "}", "}", "ksort", "(", "$", "return", ")", ";", "ksort", "(", "$", "default", ")", ";", "$", "return", "=", "$", "return", "+", "$", "default", ";", "foreach", "(", "$", "instance", "->", "get_definition_mappings", "(", ")", "as", "$", "mapping", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "mapping", "[", "'store'", "]", ",", "$", "return", ")", ")", "{", "continue", ";", "}", "$", "return", "[", "$", "mapping", "[", "'store'", "]", "]", "[", "'mappings'", "]", "++", ";", "}", "return", "$", "return", ";", "}" ]
Returns an array containing all of the information about stores a renderer needs. @return array
[ "Returns", "an", "array", "containing", "all", "of", "the", "information", "about", "stores", "a", "renderer", "needs", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L679-L737
216,379
moodle/moodle
cache/locallib.php
cache_administration_helper.get_store_plugin_summaries
public static function get_store_plugin_summaries() { $return = array(); $plugins = core_component::get_plugin_list_with_file('cachestore', 'lib.php', true); foreach ($plugins as $plugin => $path) { $class = 'cachestore_'.$plugin; $return[$plugin] = array( 'name' => get_string('pluginname', 'cachestore_'.$plugin), 'requirementsmet' => $class::are_requirements_met(), 'instances' => 0, 'modes' => array( cache_store::MODE_APPLICATION => ($class::get_supported_modes() & cache_store::MODE_APPLICATION), cache_store::MODE_SESSION => ($class::get_supported_modes() & cache_store::MODE_SESSION), cache_store::MODE_REQUEST => ($class::get_supported_modes() & cache_store::MODE_REQUEST), ), 'supports' => array( 'multipleidentifiers' => ($class::get_supported_features() & cache_store::SUPPORTS_MULTIPLE_IDENTIFIERS), 'dataguarantee' => ($class::get_supported_features() & cache_store::SUPPORTS_DATA_GUARANTEE), 'nativettl' => ($class::get_supported_features() & cache_store::SUPPORTS_NATIVE_TTL), 'nativelocking' => (in_array('cache_is_lockable', class_implements($class))), 'keyawareness' => (array_key_exists('cache_is_key_aware', class_implements($class))), ), 'canaddinstance' => ($class::can_add_instance() && $class::are_requirements_met()) ); } $instance = cache_config::instance(); $stores = $instance->get_all_stores(); foreach ($stores as $store) { $plugin = $store['plugin']; if (array_key_exists($plugin, $return)) { $return[$plugin]['instances']++; } } return $return; }
php
public static function get_store_plugin_summaries() { $return = array(); $plugins = core_component::get_plugin_list_with_file('cachestore', 'lib.php', true); foreach ($plugins as $plugin => $path) { $class = 'cachestore_'.$plugin; $return[$plugin] = array( 'name' => get_string('pluginname', 'cachestore_'.$plugin), 'requirementsmet' => $class::are_requirements_met(), 'instances' => 0, 'modes' => array( cache_store::MODE_APPLICATION => ($class::get_supported_modes() & cache_store::MODE_APPLICATION), cache_store::MODE_SESSION => ($class::get_supported_modes() & cache_store::MODE_SESSION), cache_store::MODE_REQUEST => ($class::get_supported_modes() & cache_store::MODE_REQUEST), ), 'supports' => array( 'multipleidentifiers' => ($class::get_supported_features() & cache_store::SUPPORTS_MULTIPLE_IDENTIFIERS), 'dataguarantee' => ($class::get_supported_features() & cache_store::SUPPORTS_DATA_GUARANTEE), 'nativettl' => ($class::get_supported_features() & cache_store::SUPPORTS_NATIVE_TTL), 'nativelocking' => (in_array('cache_is_lockable', class_implements($class))), 'keyawareness' => (array_key_exists('cache_is_key_aware', class_implements($class))), ), 'canaddinstance' => ($class::can_add_instance() && $class::are_requirements_met()) ); } $instance = cache_config::instance(); $stores = $instance->get_all_stores(); foreach ($stores as $store) { $plugin = $store['plugin']; if (array_key_exists($plugin, $return)) { $return[$plugin]['instances']++; } } return $return; }
[ "public", "static", "function", "get_store_plugin_summaries", "(", ")", "{", "$", "return", "=", "array", "(", ")", ";", "$", "plugins", "=", "core_component", "::", "get_plugin_list_with_file", "(", "'cachestore'", ",", "'lib.php'", ",", "true", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", "=>", "$", "path", ")", "{", "$", "class", "=", "'cachestore_'", ".", "$", "plugin", ";", "$", "return", "[", "$", "plugin", "]", "=", "array", "(", "'name'", "=>", "get_string", "(", "'pluginname'", ",", "'cachestore_'", ".", "$", "plugin", ")", ",", "'requirementsmet'", "=>", "$", "class", "::", "are_requirements_met", "(", ")", ",", "'instances'", "=>", "0", ",", "'modes'", "=>", "array", "(", "cache_store", "::", "MODE_APPLICATION", "=>", "(", "$", "class", "::", "get_supported_modes", "(", ")", "&", "cache_store", "::", "MODE_APPLICATION", ")", ",", "cache_store", "::", "MODE_SESSION", "=>", "(", "$", "class", "::", "get_supported_modes", "(", ")", "&", "cache_store", "::", "MODE_SESSION", ")", ",", "cache_store", "::", "MODE_REQUEST", "=>", "(", "$", "class", "::", "get_supported_modes", "(", ")", "&", "cache_store", "::", "MODE_REQUEST", ")", ",", ")", ",", "'supports'", "=>", "array", "(", "'multipleidentifiers'", "=>", "(", "$", "class", "::", "get_supported_features", "(", ")", "&", "cache_store", "::", "SUPPORTS_MULTIPLE_IDENTIFIERS", ")", ",", "'dataguarantee'", "=>", "(", "$", "class", "::", "get_supported_features", "(", ")", "&", "cache_store", "::", "SUPPORTS_DATA_GUARANTEE", ")", ",", "'nativettl'", "=>", "(", "$", "class", "::", "get_supported_features", "(", ")", "&", "cache_store", "::", "SUPPORTS_NATIVE_TTL", ")", ",", "'nativelocking'", "=>", "(", "in_array", "(", "'cache_is_lockable'", ",", "class_implements", "(", "$", "class", ")", ")", ")", ",", "'keyawareness'", "=>", "(", "array_key_exists", "(", "'cache_is_key_aware'", ",", "class_implements", "(", "$", "class", ")", ")", ")", ",", ")", ",", "'canaddinstance'", "=>", "(", "$", "class", "::", "can_add_instance", "(", ")", "&&", "$", "class", "::", "are_requirements_met", "(", ")", ")", ")", ";", "}", "$", "instance", "=", "cache_config", "::", "instance", "(", ")", ";", "$", "stores", "=", "$", "instance", "->", "get_all_stores", "(", ")", ";", "foreach", "(", "$", "stores", "as", "$", "store", ")", "{", "$", "plugin", "=", "$", "store", "[", "'plugin'", "]", ";", "if", "(", "array_key_exists", "(", "$", "plugin", ",", "$", "return", ")", ")", "{", "$", "return", "[", "$", "plugin", "]", "[", "'instances'", "]", "++", ";", "}", "}", "return", "$", "return", ";", "}" ]
Returns an array of information about plugins, everything a renderer needs. @return array
[ "Returns", "an", "array", "of", "information", "about", "plugins", "everything", "a", "renderer", "needs", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L743-L778
216,380
moodle/moodle
cache/locallib.php
cache_administration_helper.get_definition_summaries
public static function get_definition_summaries() { $factory = cache_factory::instance(); $config = $factory->create_config_instance(); $storenames = array(); foreach ($config->get_all_stores() as $key => $store) { if (!empty($store['default'])) { $storenames[$key] = new lang_string('store_'.$key, 'cache'); } else { $storenames[$store['name']] = $store['name']; } } /* @var cache_definition[] $definitions */ $definitions = array(); foreach ($config->get_definitions() as $key => $definition) { $definitions[$key] = cache_definition::load($definition['component'].'/'.$definition['area'], $definition); } foreach ($definitions as $id => $definition) { $mappings = array(); foreach (cache_helper::get_stores_suitable_for_definition($definition) as $store) { $mappings[] = $storenames[$store->my_name()]; } $return[$id] = array( 'id' => $id, 'name' => $definition->get_name(), 'mode' => $definition->get_mode(), 'component' => $definition->get_component(), 'area' => $definition->get_area(), 'mappings' => $mappings, 'canuselocalstore' => $definition->can_use_localstore(), 'sharingoptions' => self::get_definition_sharing_options($definition->get_sharing_options(), false), 'selectedsharingoption' => self::get_definition_sharing_options($definition->get_selected_sharing_option(), true), 'userinputsharingkey' => $definition->get_user_input_sharing_key() ); } return $return; }
php
public static function get_definition_summaries() { $factory = cache_factory::instance(); $config = $factory->create_config_instance(); $storenames = array(); foreach ($config->get_all_stores() as $key => $store) { if (!empty($store['default'])) { $storenames[$key] = new lang_string('store_'.$key, 'cache'); } else { $storenames[$store['name']] = $store['name']; } } /* @var cache_definition[] $definitions */ $definitions = array(); foreach ($config->get_definitions() as $key => $definition) { $definitions[$key] = cache_definition::load($definition['component'].'/'.$definition['area'], $definition); } foreach ($definitions as $id => $definition) { $mappings = array(); foreach (cache_helper::get_stores_suitable_for_definition($definition) as $store) { $mappings[] = $storenames[$store->my_name()]; } $return[$id] = array( 'id' => $id, 'name' => $definition->get_name(), 'mode' => $definition->get_mode(), 'component' => $definition->get_component(), 'area' => $definition->get_area(), 'mappings' => $mappings, 'canuselocalstore' => $definition->can_use_localstore(), 'sharingoptions' => self::get_definition_sharing_options($definition->get_sharing_options(), false), 'selectedsharingoption' => self::get_definition_sharing_options($definition->get_selected_sharing_option(), true), 'userinputsharingkey' => $definition->get_user_input_sharing_key() ); } return $return; }
[ "public", "static", "function", "get_definition_summaries", "(", ")", "{", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "$", "config", "=", "$", "factory", "->", "create_config_instance", "(", ")", ";", "$", "storenames", "=", "array", "(", ")", ";", "foreach", "(", "$", "config", "->", "get_all_stores", "(", ")", "as", "$", "key", "=>", "$", "store", ")", "{", "if", "(", "!", "empty", "(", "$", "store", "[", "'default'", "]", ")", ")", "{", "$", "storenames", "[", "$", "key", "]", "=", "new", "lang_string", "(", "'store_'", ".", "$", "key", ",", "'cache'", ")", ";", "}", "else", "{", "$", "storenames", "[", "$", "store", "[", "'name'", "]", "]", "=", "$", "store", "[", "'name'", "]", ";", "}", "}", "/* @var cache_definition[] $definitions */", "$", "definitions", "=", "array", "(", ")", ";", "foreach", "(", "$", "config", "->", "get_definitions", "(", ")", "as", "$", "key", "=>", "$", "definition", ")", "{", "$", "definitions", "[", "$", "key", "]", "=", "cache_definition", "::", "load", "(", "$", "definition", "[", "'component'", "]", ".", "'/'", ".", "$", "definition", "[", "'area'", "]", ",", "$", "definition", ")", ";", "}", "foreach", "(", "$", "definitions", "as", "$", "id", "=>", "$", "definition", ")", "{", "$", "mappings", "=", "array", "(", ")", ";", "foreach", "(", "cache_helper", "::", "get_stores_suitable_for_definition", "(", "$", "definition", ")", "as", "$", "store", ")", "{", "$", "mappings", "[", "]", "=", "$", "storenames", "[", "$", "store", "->", "my_name", "(", ")", "]", ";", "}", "$", "return", "[", "$", "id", "]", "=", "array", "(", "'id'", "=>", "$", "id", ",", "'name'", "=>", "$", "definition", "->", "get_name", "(", ")", ",", "'mode'", "=>", "$", "definition", "->", "get_mode", "(", ")", ",", "'component'", "=>", "$", "definition", "->", "get_component", "(", ")", ",", "'area'", "=>", "$", "definition", "->", "get_area", "(", ")", ",", "'mappings'", "=>", "$", "mappings", ",", "'canuselocalstore'", "=>", "$", "definition", "->", "can_use_localstore", "(", ")", ",", "'sharingoptions'", "=>", "self", "::", "get_definition_sharing_options", "(", "$", "definition", "->", "get_sharing_options", "(", ")", ",", "false", ")", ",", "'selectedsharingoption'", "=>", "self", "::", "get_definition_sharing_options", "(", "$", "definition", "->", "get_selected_sharing_option", "(", ")", ",", "true", ")", ",", "'userinputsharingkey'", "=>", "$", "definition", "->", "get_user_input_sharing_key", "(", ")", ")", ";", "}", "return", "$", "return", ";", "}" ]
Returns an array about the definitions. All the information a renderer needs. @return array
[ "Returns", "an", "array", "about", "the", "definitions", ".", "All", "the", "information", "a", "renderer", "needs", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L784-L819
216,381
moodle/moodle
cache/locallib.php
cache_administration_helper.get_definition_sharing_options
public static function get_definition_sharing_options($sharingoption, $isselectedoptions = true) { $options = array(); $prefix = ($isselectedoptions) ? 'sharingselected' : 'sharing'; if ($sharingoption & cache_definition::SHARING_ALL) { $options[cache_definition::SHARING_ALL] = new lang_string($prefix.'_all', 'cache'); } if ($sharingoption & cache_definition::SHARING_SITEID) { $options[cache_definition::SHARING_SITEID] = new lang_string($prefix.'_siteid', 'cache'); } if ($sharingoption & cache_definition::SHARING_VERSION) { $options[cache_definition::SHARING_VERSION] = new lang_string($prefix.'_version', 'cache'); } if ($sharingoption & cache_definition::SHARING_INPUT) { $options[cache_definition::SHARING_INPUT] = new lang_string($prefix.'_input', 'cache'); } return $options; }
php
public static function get_definition_sharing_options($sharingoption, $isselectedoptions = true) { $options = array(); $prefix = ($isselectedoptions) ? 'sharingselected' : 'sharing'; if ($sharingoption & cache_definition::SHARING_ALL) { $options[cache_definition::SHARING_ALL] = new lang_string($prefix.'_all', 'cache'); } if ($sharingoption & cache_definition::SHARING_SITEID) { $options[cache_definition::SHARING_SITEID] = new lang_string($prefix.'_siteid', 'cache'); } if ($sharingoption & cache_definition::SHARING_VERSION) { $options[cache_definition::SHARING_VERSION] = new lang_string($prefix.'_version', 'cache'); } if ($sharingoption & cache_definition::SHARING_INPUT) { $options[cache_definition::SHARING_INPUT] = new lang_string($prefix.'_input', 'cache'); } return $options; }
[ "public", "static", "function", "get_definition_sharing_options", "(", "$", "sharingoption", ",", "$", "isselectedoptions", "=", "true", ")", "{", "$", "options", "=", "array", "(", ")", ";", "$", "prefix", "=", "(", "$", "isselectedoptions", ")", "?", "'sharingselected'", ":", "'sharing'", ";", "if", "(", "$", "sharingoption", "&", "cache_definition", "::", "SHARING_ALL", ")", "{", "$", "options", "[", "cache_definition", "::", "SHARING_ALL", "]", "=", "new", "lang_string", "(", "$", "prefix", ".", "'_all'", ",", "'cache'", ")", ";", "}", "if", "(", "$", "sharingoption", "&", "cache_definition", "::", "SHARING_SITEID", ")", "{", "$", "options", "[", "cache_definition", "::", "SHARING_SITEID", "]", "=", "new", "lang_string", "(", "$", "prefix", ".", "'_siteid'", ",", "'cache'", ")", ";", "}", "if", "(", "$", "sharingoption", "&", "cache_definition", "::", "SHARING_VERSION", ")", "{", "$", "options", "[", "cache_definition", "::", "SHARING_VERSION", "]", "=", "new", "lang_string", "(", "$", "prefix", ".", "'_version'", ",", "'cache'", ")", ";", "}", "if", "(", "$", "sharingoption", "&", "cache_definition", "::", "SHARING_INPUT", ")", "{", "$", "options", "[", "cache_definition", "::", "SHARING_INPUT", "]", "=", "new", "lang_string", "(", "$", "prefix", ".", "'_input'", ",", "'cache'", ")", ";", "}", "return", "$", "options", ";", "}" ]
Given a sharing option hash this function returns an array of strings that can be used to describe it. @param int $sharingoption The sharing option hash to get strings for. @param bool $isselectedoptions Set to true if the strings will be used to view the selected options. @return array An array of lang_string's.
[ "Given", "a", "sharing", "option", "hash", "this", "function", "returns", "an", "array", "of", "strings", "that", "can", "be", "used", "to", "describe", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L828-L844
216,382
moodle/moodle
cache/locallib.php
cache_administration_helper.get_definition_actions
public static function get_definition_actions(context $context, array $definition) { if (has_capability('moodle/site:config', $context)) { $actions = array(); // Edit mappings. $actions[] = array( 'text' => get_string('editmappings', 'cache'), 'url' => new moodle_url('/cache/admin.php', array('action' => 'editdefinitionmapping', 'sesskey' => sesskey())) ); // Edit sharing. if (count($definition['sharingoptions']) > 1) { $actions[] = array( 'text' => get_string('editsharing', 'cache'), 'url' => new moodle_url('/cache/admin.php', array('action' => 'editdefinitionsharing', 'sesskey' => sesskey())) ); } // Purge. $actions[] = array( 'text' => get_string('purge', 'cache'), 'url' => new moodle_url('/cache/admin.php', array('action' => 'purgedefinition', 'sesskey' => sesskey())) ); return $actions; } return array(); }
php
public static function get_definition_actions(context $context, array $definition) { if (has_capability('moodle/site:config', $context)) { $actions = array(); // Edit mappings. $actions[] = array( 'text' => get_string('editmappings', 'cache'), 'url' => new moodle_url('/cache/admin.php', array('action' => 'editdefinitionmapping', 'sesskey' => sesskey())) ); // Edit sharing. if (count($definition['sharingoptions']) > 1) { $actions[] = array( 'text' => get_string('editsharing', 'cache'), 'url' => new moodle_url('/cache/admin.php', array('action' => 'editdefinitionsharing', 'sesskey' => sesskey())) ); } // Purge. $actions[] = array( 'text' => get_string('purge', 'cache'), 'url' => new moodle_url('/cache/admin.php', array('action' => 'purgedefinition', 'sesskey' => sesskey())) ); return $actions; } return array(); }
[ "public", "static", "function", "get_definition_actions", "(", "context", "$", "context", ",", "array", "$", "definition", ")", "{", "if", "(", "has_capability", "(", "'moodle/site:config'", ",", "$", "context", ")", ")", "{", "$", "actions", "=", "array", "(", ")", ";", "// Edit mappings.", "$", "actions", "[", "]", "=", "array", "(", "'text'", "=>", "get_string", "(", "'editmappings'", ",", "'cache'", ")", ",", "'url'", "=>", "new", "moodle_url", "(", "'/cache/admin.php'", ",", "array", "(", "'action'", "=>", "'editdefinitionmapping'", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ")", ";", "// Edit sharing.", "if", "(", "count", "(", "$", "definition", "[", "'sharingoptions'", "]", ")", ">", "1", ")", "{", "$", "actions", "[", "]", "=", "array", "(", "'text'", "=>", "get_string", "(", "'editsharing'", ",", "'cache'", ")", ",", "'url'", "=>", "new", "moodle_url", "(", "'/cache/admin.php'", ",", "array", "(", "'action'", "=>", "'editdefinitionsharing'", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ")", ";", "}", "// Purge.", "$", "actions", "[", "]", "=", "array", "(", "'text'", "=>", "get_string", "(", "'purge'", ",", "'cache'", ")", ",", "'url'", "=>", "new", "moodle_url", "(", "'/cache/admin.php'", ",", "array", "(", "'action'", "=>", "'purgedefinition'", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ")", ";", "return", "$", "actions", ";", "}", "return", "array", "(", ")", ";", "}" ]
Returns all of the actions that can be performed on a definition. @param context $context @return array
[ "Returns", "all", "of", "the", "actions", "that", "can", "be", "performed", "on", "a", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L851-L874
216,383
moodle/moodle
cache/locallib.php
cache_administration_helper.get_store_instance_actions
public static function get_store_instance_actions($name, array $storedetails) { $actions = array(); if (has_capability('moodle/site:config', context_system::instance())) { $baseurl = new moodle_url('/cache/admin.php', array('store' => $name, 'sesskey' => sesskey())); if (empty($storedetails['default'])) { $actions[] = array( 'text' => get_string('editstore', 'cache'), 'url' => new moodle_url($baseurl, array('action' => 'editstore', 'plugin' => $storedetails['plugin'])) ); $actions[] = array( 'text' => get_string('deletestore', 'cache'), 'url' => new moodle_url($baseurl, array('action' => 'deletestore')) ); } $actions[] = array( 'text' => get_string('purge', 'cache'), 'url' => new moodle_url($baseurl, array('action' => 'purgestore')) ); } return $actions; }
php
public static function get_store_instance_actions($name, array $storedetails) { $actions = array(); if (has_capability('moodle/site:config', context_system::instance())) { $baseurl = new moodle_url('/cache/admin.php', array('store' => $name, 'sesskey' => sesskey())); if (empty($storedetails['default'])) { $actions[] = array( 'text' => get_string('editstore', 'cache'), 'url' => new moodle_url($baseurl, array('action' => 'editstore', 'plugin' => $storedetails['plugin'])) ); $actions[] = array( 'text' => get_string('deletestore', 'cache'), 'url' => new moodle_url($baseurl, array('action' => 'deletestore')) ); } $actions[] = array( 'text' => get_string('purge', 'cache'), 'url' => new moodle_url($baseurl, array('action' => 'purgestore')) ); } return $actions; }
[ "public", "static", "function", "get_store_instance_actions", "(", "$", "name", ",", "array", "$", "storedetails", ")", "{", "$", "actions", "=", "array", "(", ")", ";", "if", "(", "has_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ")", "{", "$", "baseurl", "=", "new", "moodle_url", "(", "'/cache/admin.php'", ",", "array", "(", "'store'", "=>", "$", "name", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ";", "if", "(", "empty", "(", "$", "storedetails", "[", "'default'", "]", ")", ")", "{", "$", "actions", "[", "]", "=", "array", "(", "'text'", "=>", "get_string", "(", "'editstore'", ",", "'cache'", ")", ",", "'url'", "=>", "new", "moodle_url", "(", "$", "baseurl", ",", "array", "(", "'action'", "=>", "'editstore'", ",", "'plugin'", "=>", "$", "storedetails", "[", "'plugin'", "]", ")", ")", ")", ";", "$", "actions", "[", "]", "=", "array", "(", "'text'", "=>", "get_string", "(", "'deletestore'", ",", "'cache'", ")", ",", "'url'", "=>", "new", "moodle_url", "(", "$", "baseurl", ",", "array", "(", "'action'", "=>", "'deletestore'", ")", ")", ")", ";", "}", "$", "actions", "[", "]", "=", "array", "(", "'text'", "=>", "get_string", "(", "'purge'", ",", "'cache'", ")", ",", "'url'", "=>", "new", "moodle_url", "(", "$", "baseurl", ",", "array", "(", "'action'", "=>", "'purgestore'", ")", ")", ")", ";", "}", "return", "$", "actions", ";", "}" ]
Returns all of the actions that can be performed on a store. @param string $name The name of the store @param array $storedetails @return array
[ "Returns", "all", "of", "the", "actions", "that", "can", "be", "performed", "on", "a", "store", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L883-L903
216,384
moodle/moodle
cache/locallib.php
cache_administration_helper.get_store_plugin_actions
public static function get_store_plugin_actions($name, array $plugindetails) { $actions = array(); if (has_capability('moodle/site:config', context_system::instance())) { if (!empty($plugindetails['canaddinstance'])) { $url = new moodle_url('/cache/admin.php', array('action' => 'addstore', 'plugin' => $name, 'sesskey' => sesskey())); $actions[] = array( 'text' => get_string('addinstance', 'cache'), 'url' => $url ); } } return $actions; }
php
public static function get_store_plugin_actions($name, array $plugindetails) { $actions = array(); if (has_capability('moodle/site:config', context_system::instance())) { if (!empty($plugindetails['canaddinstance'])) { $url = new moodle_url('/cache/admin.php', array('action' => 'addstore', 'plugin' => $name, 'sesskey' => sesskey())); $actions[] = array( 'text' => get_string('addinstance', 'cache'), 'url' => $url ); } } return $actions; }
[ "public", "static", "function", "get_store_plugin_actions", "(", "$", "name", ",", "array", "$", "plugindetails", ")", "{", "$", "actions", "=", "array", "(", ")", ";", "if", "(", "has_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "plugindetails", "[", "'canaddinstance'", "]", ")", ")", "{", "$", "url", "=", "new", "moodle_url", "(", "'/cache/admin.php'", ",", "array", "(", "'action'", "=>", "'addstore'", ",", "'plugin'", "=>", "$", "name", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ";", "$", "actions", "[", "]", "=", "array", "(", "'text'", "=>", "get_string", "(", "'addinstance'", ",", "'cache'", ")", ",", "'url'", "=>", "$", "url", ")", ";", "}", "}", "return", "$", "actions", ";", "}" ]
Returns all of the actions that can be performed on a plugin. @param string $name The name of the plugin @param array $plugindetails @return array
[ "Returns", "all", "of", "the", "actions", "that", "can", "be", "performed", "on", "a", "plugin", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L913-L925
216,385
moodle/moodle
cache/locallib.php
cache_administration_helper.get_add_store_form
public static function get_add_store_form($plugin) { global $CFG; // Needed for includes. $plugins = core_component::get_plugin_list('cachestore'); if (!array_key_exists($plugin, $plugins)) { throw new coding_exception('Invalid cache plugin used when trying to create an edit form.'); } $plugindir = $plugins[$plugin]; $class = 'cachestore_addinstance_form'; if (file_exists($plugindir.'/addinstanceform.php')) { require_once($plugindir.'/addinstanceform.php'); if (class_exists('cachestore_'.$plugin.'_addinstance_form')) { $class = 'cachestore_'.$plugin.'_addinstance_form'; if (!array_key_exists('cachestore_addinstance_form', class_parents($class))) { throw new coding_exception('Cache plugin add instance forms must extend cachestore_addinstance_form'); } } } $locks = self::get_possible_locks_for_stores($plugindir, $plugin); $url = new moodle_url('/cache/admin.php', array('action' => 'addstore')); return new $class($url, array('plugin' => $plugin, 'store' => null, 'locks' => $locks)); }
php
public static function get_add_store_form($plugin) { global $CFG; // Needed for includes. $plugins = core_component::get_plugin_list('cachestore'); if (!array_key_exists($plugin, $plugins)) { throw new coding_exception('Invalid cache plugin used when trying to create an edit form.'); } $plugindir = $plugins[$plugin]; $class = 'cachestore_addinstance_form'; if (file_exists($plugindir.'/addinstanceform.php')) { require_once($plugindir.'/addinstanceform.php'); if (class_exists('cachestore_'.$plugin.'_addinstance_form')) { $class = 'cachestore_'.$plugin.'_addinstance_form'; if (!array_key_exists('cachestore_addinstance_form', class_parents($class))) { throw new coding_exception('Cache plugin add instance forms must extend cachestore_addinstance_form'); } } } $locks = self::get_possible_locks_for_stores($plugindir, $plugin); $url = new moodle_url('/cache/admin.php', array('action' => 'addstore')); return new $class($url, array('plugin' => $plugin, 'store' => null, 'locks' => $locks)); }
[ "public", "static", "function", "get_add_store_form", "(", "$", "plugin", ")", "{", "global", "$", "CFG", ";", "// Needed for includes.", "$", "plugins", "=", "core_component", "::", "get_plugin_list", "(", "'cachestore'", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "plugin", ",", "$", "plugins", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid cache plugin used when trying to create an edit form.'", ")", ";", "}", "$", "plugindir", "=", "$", "plugins", "[", "$", "plugin", "]", ";", "$", "class", "=", "'cachestore_addinstance_form'", ";", "if", "(", "file_exists", "(", "$", "plugindir", ".", "'/addinstanceform.php'", ")", ")", "{", "require_once", "(", "$", "plugindir", ".", "'/addinstanceform.php'", ")", ";", "if", "(", "class_exists", "(", "'cachestore_'", ".", "$", "plugin", ".", "'_addinstance_form'", ")", ")", "{", "$", "class", "=", "'cachestore_'", ".", "$", "plugin", ".", "'_addinstance_form'", ";", "if", "(", "!", "array_key_exists", "(", "'cachestore_addinstance_form'", ",", "class_parents", "(", "$", "class", ")", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Cache plugin add instance forms must extend cachestore_addinstance_form'", ")", ";", "}", "}", "}", "$", "locks", "=", "self", "::", "get_possible_locks_for_stores", "(", "$", "plugindir", ",", "$", "plugin", ")", ";", "$", "url", "=", "new", "moodle_url", "(", "'/cache/admin.php'", ",", "array", "(", "'action'", "=>", "'addstore'", ")", ")", ";", "return", "new", "$", "class", "(", "$", "url", ",", "array", "(", "'plugin'", "=>", "$", "plugin", ",", "'store'", "=>", "null", ",", "'locks'", "=>", "$", "locks", ")", ")", ";", "}" ]
Returns a form that can be used to add a store instance. @param string $plugin The plugin to add an instance of @return cachestore_addinstance_form @throws coding_exception
[ "Returns", "a", "form", "that", "can", "be", "used", "to", "add", "a", "store", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L934-L956
216,386
moodle/moodle
cache/locallib.php
cache_administration_helper.get_edit_store_form
public static function get_edit_store_form($plugin, $store) { global $CFG; // Needed for includes. $plugins = core_component::get_plugin_list('cachestore'); if (!array_key_exists($plugin, $plugins)) { throw new coding_exception('Invalid cache plugin used when trying to create an edit form.'); } $factory = cache_factory::instance(); $config = $factory->create_config_instance(); $stores = $config->get_all_stores(); if (!array_key_exists($store, $stores)) { throw new coding_exception('Invalid store name given when trying to create an edit form.'); } $plugindir = $plugins[$plugin]; $class = 'cachestore_addinstance_form'; if (file_exists($plugindir.'/addinstanceform.php')) { require_once($plugindir.'/addinstanceform.php'); if (class_exists('cachestore_'.$plugin.'_addinstance_form')) { $class = 'cachestore_'.$plugin.'_addinstance_form'; if (!array_key_exists('cachestore_addinstance_form', class_parents($class))) { throw new coding_exception('Cache plugin add instance forms must extend cachestore_addinstance_form'); } } } $locks = self::get_possible_locks_for_stores($plugindir, $plugin); $url = new moodle_url('/cache/admin.php', array('action' => 'editstore', 'plugin' => $plugin, 'store' => $store)); $editform = new $class($url, array('plugin' => $plugin, 'store' => $store, 'locks' => $locks)); if (isset($stores[$store]['lock'])) { $editform->set_data(array('lock' => $stores[$store]['lock'])); } // See if the cachestore is going to want to load data for the form. // If it has a customised add instance form then it is going to want to. $storeclass = 'cachestore_'.$plugin; $storedata = $stores[$store]; if (array_key_exists('configuration', $storedata) && array_key_exists('cache_is_configurable', class_implements($storeclass))) { $storeclass::config_set_edit_form_data($editform, $storedata['configuration']); } return $editform; }
php
public static function get_edit_store_form($plugin, $store) { global $CFG; // Needed for includes. $plugins = core_component::get_plugin_list('cachestore'); if (!array_key_exists($plugin, $plugins)) { throw new coding_exception('Invalid cache plugin used when trying to create an edit form.'); } $factory = cache_factory::instance(); $config = $factory->create_config_instance(); $stores = $config->get_all_stores(); if (!array_key_exists($store, $stores)) { throw new coding_exception('Invalid store name given when trying to create an edit form.'); } $plugindir = $plugins[$plugin]; $class = 'cachestore_addinstance_form'; if (file_exists($plugindir.'/addinstanceform.php')) { require_once($plugindir.'/addinstanceform.php'); if (class_exists('cachestore_'.$plugin.'_addinstance_form')) { $class = 'cachestore_'.$plugin.'_addinstance_form'; if (!array_key_exists('cachestore_addinstance_form', class_parents($class))) { throw new coding_exception('Cache plugin add instance forms must extend cachestore_addinstance_form'); } } } $locks = self::get_possible_locks_for_stores($plugindir, $plugin); $url = new moodle_url('/cache/admin.php', array('action' => 'editstore', 'plugin' => $plugin, 'store' => $store)); $editform = new $class($url, array('plugin' => $plugin, 'store' => $store, 'locks' => $locks)); if (isset($stores[$store]['lock'])) { $editform->set_data(array('lock' => $stores[$store]['lock'])); } // See if the cachestore is going to want to load data for the form. // If it has a customised add instance form then it is going to want to. $storeclass = 'cachestore_'.$plugin; $storedata = $stores[$store]; if (array_key_exists('configuration', $storedata) && array_key_exists('cache_is_configurable', class_implements($storeclass))) { $storeclass::config_set_edit_form_data($editform, $storedata['configuration']); } return $editform; }
[ "public", "static", "function", "get_edit_store_form", "(", "$", "plugin", ",", "$", "store", ")", "{", "global", "$", "CFG", ";", "// Needed for includes.", "$", "plugins", "=", "core_component", "::", "get_plugin_list", "(", "'cachestore'", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "plugin", ",", "$", "plugins", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid cache plugin used when trying to create an edit form.'", ")", ";", "}", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "$", "config", "=", "$", "factory", "->", "create_config_instance", "(", ")", ";", "$", "stores", "=", "$", "config", "->", "get_all_stores", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "store", ",", "$", "stores", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid store name given when trying to create an edit form.'", ")", ";", "}", "$", "plugindir", "=", "$", "plugins", "[", "$", "plugin", "]", ";", "$", "class", "=", "'cachestore_addinstance_form'", ";", "if", "(", "file_exists", "(", "$", "plugindir", ".", "'/addinstanceform.php'", ")", ")", "{", "require_once", "(", "$", "plugindir", ".", "'/addinstanceform.php'", ")", ";", "if", "(", "class_exists", "(", "'cachestore_'", ".", "$", "plugin", ".", "'_addinstance_form'", ")", ")", "{", "$", "class", "=", "'cachestore_'", ".", "$", "plugin", ".", "'_addinstance_form'", ";", "if", "(", "!", "array_key_exists", "(", "'cachestore_addinstance_form'", ",", "class_parents", "(", "$", "class", ")", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Cache plugin add instance forms must extend cachestore_addinstance_form'", ")", ";", "}", "}", "}", "$", "locks", "=", "self", "::", "get_possible_locks_for_stores", "(", "$", "plugindir", ",", "$", "plugin", ")", ";", "$", "url", "=", "new", "moodle_url", "(", "'/cache/admin.php'", ",", "array", "(", "'action'", "=>", "'editstore'", ",", "'plugin'", "=>", "$", "plugin", ",", "'store'", "=>", "$", "store", ")", ")", ";", "$", "editform", "=", "new", "$", "class", "(", "$", "url", ",", "array", "(", "'plugin'", "=>", "$", "plugin", ",", "'store'", "=>", "$", "store", ",", "'locks'", "=>", "$", "locks", ")", ")", ";", "if", "(", "isset", "(", "$", "stores", "[", "$", "store", "]", "[", "'lock'", "]", ")", ")", "{", "$", "editform", "->", "set_data", "(", "array", "(", "'lock'", "=>", "$", "stores", "[", "$", "store", "]", "[", "'lock'", "]", ")", ")", ";", "}", "// See if the cachestore is going to want to load data for the form.", "// If it has a customised add instance form then it is going to want to.", "$", "storeclass", "=", "'cachestore_'", ".", "$", "plugin", ";", "$", "storedata", "=", "$", "stores", "[", "$", "store", "]", ";", "if", "(", "array_key_exists", "(", "'configuration'", ",", "$", "storedata", ")", "&&", "array_key_exists", "(", "'cache_is_configurable'", ",", "class_implements", "(", "$", "storeclass", ")", ")", ")", "{", "$", "storeclass", "::", "config_set_edit_form_data", "(", "$", "editform", ",", "$", "storedata", "[", "'configuration'", "]", ")", ";", "}", "return", "$", "editform", ";", "}" ]
Returns a form that can be used to edit a store instance. @param string $plugin @param string $store @return cachestore_addinstance_form @throws coding_exception
[ "Returns", "a", "form", "that", "can", "be", "used", "to", "edit", "a", "store", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L966-L1005
216,387
moodle/moodle
cache/locallib.php
cache_administration_helper.get_possible_locks_for_stores
protected static function get_possible_locks_for_stores($plugindir, $plugin) { global $CFG; // Needed for includes. $supportsnativelocking = false; if (file_exists($plugindir.'/lib.php')) { require_once($plugindir.'/lib.php'); $pluginclass = 'cachestore_'.$plugin; if (class_exists($pluginclass)) { $supportsnativelocking = array_key_exists('cache_is_lockable', class_implements($pluginclass)); } } if (!$supportsnativelocking) { $config = cache_config::instance(); $locks = array(); foreach ($config->get_locks() as $lock => $conf) { if (!empty($conf['default'])) { $name = get_string($lock, 'cache'); } else { $name = $lock; } $locks[$lock] = $name; } } else { $locks = false; } return $locks; }
php
protected static function get_possible_locks_for_stores($plugindir, $plugin) { global $CFG; // Needed for includes. $supportsnativelocking = false; if (file_exists($plugindir.'/lib.php')) { require_once($plugindir.'/lib.php'); $pluginclass = 'cachestore_'.$plugin; if (class_exists($pluginclass)) { $supportsnativelocking = array_key_exists('cache_is_lockable', class_implements($pluginclass)); } } if (!$supportsnativelocking) { $config = cache_config::instance(); $locks = array(); foreach ($config->get_locks() as $lock => $conf) { if (!empty($conf['default'])) { $name = get_string($lock, 'cache'); } else { $name = $lock; } $locks[$lock] = $name; } } else { $locks = false; } return $locks; }
[ "protected", "static", "function", "get_possible_locks_for_stores", "(", "$", "plugindir", ",", "$", "plugin", ")", "{", "global", "$", "CFG", ";", "// Needed for includes.", "$", "supportsnativelocking", "=", "false", ";", "if", "(", "file_exists", "(", "$", "plugindir", ".", "'/lib.php'", ")", ")", "{", "require_once", "(", "$", "plugindir", ".", "'/lib.php'", ")", ";", "$", "pluginclass", "=", "'cachestore_'", ".", "$", "plugin", ";", "if", "(", "class_exists", "(", "$", "pluginclass", ")", ")", "{", "$", "supportsnativelocking", "=", "array_key_exists", "(", "'cache_is_lockable'", ",", "class_implements", "(", "$", "pluginclass", ")", ")", ";", "}", "}", "if", "(", "!", "$", "supportsnativelocking", ")", "{", "$", "config", "=", "cache_config", "::", "instance", "(", ")", ";", "$", "locks", "=", "array", "(", ")", ";", "foreach", "(", "$", "config", "->", "get_locks", "(", ")", "as", "$", "lock", "=>", "$", "conf", ")", "{", "if", "(", "!", "empty", "(", "$", "conf", "[", "'default'", "]", ")", ")", "{", "$", "name", "=", "get_string", "(", "$", "lock", ",", "'cache'", ")", ";", "}", "else", "{", "$", "name", "=", "$", "lock", ";", "}", "$", "locks", "[", "$", "lock", "]", "=", "$", "name", ";", "}", "}", "else", "{", "$", "locks", "=", "false", ";", "}", "return", "$", "locks", ";", "}" ]
Returns an array of suitable lock instances for use with this plugin, or false if the plugin handles locking itself. @param string $plugindir @param string $plugin @return array|false
[ "Returns", "an", "array", "of", "suitable", "lock", "instances", "for", "use", "with", "this", "plugin", "or", "false", "if", "the", "plugin", "handles", "locking", "itself", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L1014-L1041
216,388
moodle/moodle
cache/locallib.php
cache_administration_helper.get_definition_store_options
public static function get_definition_store_options($component, $area) { $factory = cache_factory::instance(); $definition = $factory->create_definition($component, $area); $config = cache_config::instance(); $currentstores = $config->get_stores_for_definition($definition); $possiblestores = $config->get_stores($definition->get_mode(), $definition->get_requirements_bin()); $defaults = array(); foreach ($currentstores as $key => $store) { if (!empty($store['default'])) { $defaults[] = $key; unset($currentstores[$key]); } } foreach ($possiblestores as $key => $store) { if ($store['default']) { unset($possiblestores[$key]); $possiblestores[$key] = $store; } } return array($currentstores, $possiblestores, $defaults); }
php
public static function get_definition_store_options($component, $area) { $factory = cache_factory::instance(); $definition = $factory->create_definition($component, $area); $config = cache_config::instance(); $currentstores = $config->get_stores_for_definition($definition); $possiblestores = $config->get_stores($definition->get_mode(), $definition->get_requirements_bin()); $defaults = array(); foreach ($currentstores as $key => $store) { if (!empty($store['default'])) { $defaults[] = $key; unset($currentstores[$key]); } } foreach ($possiblestores as $key => $store) { if ($store['default']) { unset($possiblestores[$key]); $possiblestores[$key] = $store; } } return array($currentstores, $possiblestores, $defaults); }
[ "public", "static", "function", "get_definition_store_options", "(", "$", "component", ",", "$", "area", ")", "{", "$", "factory", "=", "cache_factory", "::", "instance", "(", ")", ";", "$", "definition", "=", "$", "factory", "->", "create_definition", "(", "$", "component", ",", "$", "area", ")", ";", "$", "config", "=", "cache_config", "::", "instance", "(", ")", ";", "$", "currentstores", "=", "$", "config", "->", "get_stores_for_definition", "(", "$", "definition", ")", ";", "$", "possiblestores", "=", "$", "config", "->", "get_stores", "(", "$", "definition", "->", "get_mode", "(", ")", ",", "$", "definition", "->", "get_requirements_bin", "(", ")", ")", ";", "$", "defaults", "=", "array", "(", ")", ";", "foreach", "(", "$", "currentstores", "as", "$", "key", "=>", "$", "store", ")", "{", "if", "(", "!", "empty", "(", "$", "store", "[", "'default'", "]", ")", ")", "{", "$", "defaults", "[", "]", "=", "$", "key", ";", "unset", "(", "$", "currentstores", "[", "$", "key", "]", ")", ";", "}", "}", "foreach", "(", "$", "possiblestores", "as", "$", "key", "=>", "$", "store", ")", "{", "if", "(", "$", "store", "[", "'default'", "]", ")", "{", "unset", "(", "$", "possiblestores", "[", "$", "key", "]", ")", ";", "$", "possiblestores", "[", "$", "key", "]", "=", "$", "store", ";", "}", "}", "return", "array", "(", "$", "currentstores", ",", "$", "possiblestores", ",", "$", "defaults", ")", ";", "}" ]
Get an array of stores that are suitable to be used for a given definition. @param string $component @param string $area @return array Array containing 3 elements 1. An array of currently used stores 2. An array of suitable stores 3. An array of default stores
[ "Get", "an", "array", "of", "stores", "that", "are", "suitable", "to", "be", "used", "for", "a", "given", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L1078-L1099
216,389
moodle/moodle
cache/locallib.php
cache_administration_helper.get_default_mode_stores
public static function get_default_mode_stores() { global $OUTPUT; $instance = cache_config::instance(); $adequatestores = cache_helper::get_stores_suitable_for_mode_default(); $icon = new pix_icon('i/warning', new lang_string('inadequatestoreformapping', 'cache')); $storenames = array(); foreach ($instance->get_all_stores() as $key => $store) { if (!empty($store['default'])) { $storenames[$key] = new lang_string('store_'.$key, 'cache'); } } $modemappings = array( cache_store::MODE_APPLICATION => array(), cache_store::MODE_SESSION => array(), cache_store::MODE_REQUEST => array(), ); foreach ($instance->get_mode_mappings() as $mapping) { $mode = $mapping['mode']; if (!array_key_exists($mode, $modemappings)) { debugging('Unknown mode in cache store mode mappings', DEBUG_DEVELOPER); continue; } if (array_key_exists($mapping['store'], $storenames)) { $modemappings[$mode][$mapping['store']] = $storenames[$mapping['store']]; } else { $modemappings[$mode][$mapping['store']] = $mapping['store']; } if (!array_key_exists($mapping['store'], $adequatestores)) { $modemappings[$mode][$mapping['store']] = $modemappings[$mode][$mapping['store']].' '.$OUTPUT->render($icon); } } return $modemappings; }
php
public static function get_default_mode_stores() { global $OUTPUT; $instance = cache_config::instance(); $adequatestores = cache_helper::get_stores_suitable_for_mode_default(); $icon = new pix_icon('i/warning', new lang_string('inadequatestoreformapping', 'cache')); $storenames = array(); foreach ($instance->get_all_stores() as $key => $store) { if (!empty($store['default'])) { $storenames[$key] = new lang_string('store_'.$key, 'cache'); } } $modemappings = array( cache_store::MODE_APPLICATION => array(), cache_store::MODE_SESSION => array(), cache_store::MODE_REQUEST => array(), ); foreach ($instance->get_mode_mappings() as $mapping) { $mode = $mapping['mode']; if (!array_key_exists($mode, $modemappings)) { debugging('Unknown mode in cache store mode mappings', DEBUG_DEVELOPER); continue; } if (array_key_exists($mapping['store'], $storenames)) { $modemappings[$mode][$mapping['store']] = $storenames[$mapping['store']]; } else { $modemappings[$mode][$mapping['store']] = $mapping['store']; } if (!array_key_exists($mapping['store'], $adequatestores)) { $modemappings[$mode][$mapping['store']] = $modemappings[$mode][$mapping['store']].' '.$OUTPUT->render($icon); } } return $modemappings; }
[ "public", "static", "function", "get_default_mode_stores", "(", ")", "{", "global", "$", "OUTPUT", ";", "$", "instance", "=", "cache_config", "::", "instance", "(", ")", ";", "$", "adequatestores", "=", "cache_helper", "::", "get_stores_suitable_for_mode_default", "(", ")", ";", "$", "icon", "=", "new", "pix_icon", "(", "'i/warning'", ",", "new", "lang_string", "(", "'inadequatestoreformapping'", ",", "'cache'", ")", ")", ";", "$", "storenames", "=", "array", "(", ")", ";", "foreach", "(", "$", "instance", "->", "get_all_stores", "(", ")", "as", "$", "key", "=>", "$", "store", ")", "{", "if", "(", "!", "empty", "(", "$", "store", "[", "'default'", "]", ")", ")", "{", "$", "storenames", "[", "$", "key", "]", "=", "new", "lang_string", "(", "'store_'", ".", "$", "key", ",", "'cache'", ")", ";", "}", "}", "$", "modemappings", "=", "array", "(", "cache_store", "::", "MODE_APPLICATION", "=>", "array", "(", ")", ",", "cache_store", "::", "MODE_SESSION", "=>", "array", "(", ")", ",", "cache_store", "::", "MODE_REQUEST", "=>", "array", "(", ")", ",", ")", ";", "foreach", "(", "$", "instance", "->", "get_mode_mappings", "(", ")", "as", "$", "mapping", ")", "{", "$", "mode", "=", "$", "mapping", "[", "'mode'", "]", ";", "if", "(", "!", "array_key_exists", "(", "$", "mode", ",", "$", "modemappings", ")", ")", "{", "debugging", "(", "'Unknown mode in cache store mode mappings'", ",", "DEBUG_DEVELOPER", ")", ";", "continue", ";", "}", "if", "(", "array_key_exists", "(", "$", "mapping", "[", "'store'", "]", ",", "$", "storenames", ")", ")", "{", "$", "modemappings", "[", "$", "mode", "]", "[", "$", "mapping", "[", "'store'", "]", "]", "=", "$", "storenames", "[", "$", "mapping", "[", "'store'", "]", "]", ";", "}", "else", "{", "$", "modemappings", "[", "$", "mode", "]", "[", "$", "mapping", "[", "'store'", "]", "]", "=", "$", "mapping", "[", "'store'", "]", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "mapping", "[", "'store'", "]", ",", "$", "adequatestores", ")", ")", "{", "$", "modemappings", "[", "$", "mode", "]", "[", "$", "mapping", "[", "'store'", "]", "]", "=", "$", "modemappings", "[", "$", "mode", "]", "[", "$", "mapping", "[", "'store'", "]", "]", ".", "' '", ".", "$", "OUTPUT", "->", "render", "(", "$", "icon", ")", ";", "}", "}", "return", "$", "modemappings", ";", "}" ]
Get the default stores for all modes. @return array An array containing sub-arrays, one for each mode.
[ "Get", "the", "default", "stores", "for", "all", "modes", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L1106-L1138
216,390
moodle/moodle
cache/locallib.php
cache_administration_helper.get_lock_summaries
public static function get_lock_summaries() { $locks = array(); $instance = cache_config::instance(); $stores = $instance->get_all_stores(); foreach ($instance->get_locks() as $lock) { $default = !empty($lock['default']); if ($default) { $name = new lang_string($lock['name'], 'cache'); } else { $name = $lock['name']; } $uses = 0; foreach ($stores as $store) { if (!empty($store['lock']) && $store['lock'] === $lock['name']) { $uses++; } } $lockdata = array( 'name' => $name, 'default' => $default, 'uses' => $uses, 'type' => get_string('pluginname', $lock['type']) ); $locks[$lock['name']] = $lockdata; } return $locks; }
php
public static function get_lock_summaries() { $locks = array(); $instance = cache_config::instance(); $stores = $instance->get_all_stores(); foreach ($instance->get_locks() as $lock) { $default = !empty($lock['default']); if ($default) { $name = new lang_string($lock['name'], 'cache'); } else { $name = $lock['name']; } $uses = 0; foreach ($stores as $store) { if (!empty($store['lock']) && $store['lock'] === $lock['name']) { $uses++; } } $lockdata = array( 'name' => $name, 'default' => $default, 'uses' => $uses, 'type' => get_string('pluginname', $lock['type']) ); $locks[$lock['name']] = $lockdata; } return $locks; }
[ "public", "static", "function", "get_lock_summaries", "(", ")", "{", "$", "locks", "=", "array", "(", ")", ";", "$", "instance", "=", "cache_config", "::", "instance", "(", ")", ";", "$", "stores", "=", "$", "instance", "->", "get_all_stores", "(", ")", ";", "foreach", "(", "$", "instance", "->", "get_locks", "(", ")", "as", "$", "lock", ")", "{", "$", "default", "=", "!", "empty", "(", "$", "lock", "[", "'default'", "]", ")", ";", "if", "(", "$", "default", ")", "{", "$", "name", "=", "new", "lang_string", "(", "$", "lock", "[", "'name'", "]", ",", "'cache'", ")", ";", "}", "else", "{", "$", "name", "=", "$", "lock", "[", "'name'", "]", ";", "}", "$", "uses", "=", "0", ";", "foreach", "(", "$", "stores", "as", "$", "store", ")", "{", "if", "(", "!", "empty", "(", "$", "store", "[", "'lock'", "]", ")", "&&", "$", "store", "[", "'lock'", "]", "===", "$", "lock", "[", "'name'", "]", ")", "{", "$", "uses", "++", ";", "}", "}", "$", "lockdata", "=", "array", "(", "'name'", "=>", "$", "name", ",", "'default'", "=>", "$", "default", ",", "'uses'", "=>", "$", "uses", ",", "'type'", "=>", "get_string", "(", "'pluginname'", ",", "$", "lock", "[", "'type'", "]", ")", ")", ";", "$", "locks", "[", "$", "lock", "[", "'name'", "]", "]", "=", "$", "lockdata", ";", "}", "return", "$", "locks", ";", "}" ]
Returns an array summarising the locks available in the system
[ "Returns", "an", "array", "summarising", "the", "locks", "available", "in", "the", "system" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L1143-L1169
216,391
moodle/moodle
cache/locallib.php
cache_administration_helper.get_addable_lock_options
public static function get_addable_lock_options() { $plugins = core_component::get_plugin_list_with_class('cachelock', '', 'lib.php'); $options = array(); $len = strlen('cachelock_'); foreach ($plugins as $plugin => $class) { $method = "$class::can_add_instance"; if (is_callable($method) && !call_user_func($method)) { // Can't add an instance of this plugin. continue; } $options[substr($plugin, $len)] = get_string('pluginname', $plugin); } return $options; }
php
public static function get_addable_lock_options() { $plugins = core_component::get_plugin_list_with_class('cachelock', '', 'lib.php'); $options = array(); $len = strlen('cachelock_'); foreach ($plugins as $plugin => $class) { $method = "$class::can_add_instance"; if (is_callable($method) && !call_user_func($method)) { // Can't add an instance of this plugin. continue; } $options[substr($plugin, $len)] = get_string('pluginname', $plugin); } return $options; }
[ "public", "static", "function", "get_addable_lock_options", "(", ")", "{", "$", "plugins", "=", "core_component", "::", "get_plugin_list_with_class", "(", "'cachelock'", ",", "''", ",", "'lib.php'", ")", ";", "$", "options", "=", "array", "(", ")", ";", "$", "len", "=", "strlen", "(", "'cachelock_'", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", "=>", "$", "class", ")", "{", "$", "method", "=", "\"$class::can_add_instance\"", ";", "if", "(", "is_callable", "(", "$", "method", ")", "&&", "!", "call_user_func", "(", "$", "method", ")", ")", "{", "// Can't add an instance of this plugin.", "continue", ";", "}", "$", "options", "[", "substr", "(", "$", "plugin", ",", "$", "len", ")", "]", "=", "get_string", "(", "'pluginname'", ",", "$", "plugin", ")", ";", "}", "return", "$", "options", ";", "}" ]
Returns an array of lock plugins for which we can add an instance. Suitable for use within an mform select element. @return array
[ "Returns", "an", "array", "of", "lock", "plugins", "for", "which", "we", "can", "add", "an", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L1178-L1191
216,392
moodle/moodle
cache/locallib.php
cache_administration_helper.get_add_lock_form
public static function get_add_lock_form($plugin, array $lockplugin = null) { global $CFG; // Needed for includes. $plugins = core_component::get_plugin_list('cachelock'); if (!array_key_exists($plugin, $plugins)) { throw new coding_exception('Invalid cache lock plugin requested when trying to create a form.'); } $plugindir = $plugins[$plugin]; $class = 'cache_lock_form'; if (file_exists($plugindir.'/addinstanceform.php') && in_array('cache_is_configurable', class_implements($class))) { require_once($plugindir.'/addinstanceform.php'); if (class_exists('cachelock_'.$plugin.'_addinstance_form')) { $class = 'cachelock_'.$plugin.'_addinstance_form'; if (!array_key_exists('cache_lock_form', class_parents($class))) { throw new coding_exception('Cache lock plugin add instance forms must extend cache_lock_form'); } } } return new $class(null, array('lock' => $plugin)); }
php
public static function get_add_lock_form($plugin, array $lockplugin = null) { global $CFG; // Needed for includes. $plugins = core_component::get_plugin_list('cachelock'); if (!array_key_exists($plugin, $plugins)) { throw new coding_exception('Invalid cache lock plugin requested when trying to create a form.'); } $plugindir = $plugins[$plugin]; $class = 'cache_lock_form'; if (file_exists($plugindir.'/addinstanceform.php') && in_array('cache_is_configurable', class_implements($class))) { require_once($plugindir.'/addinstanceform.php'); if (class_exists('cachelock_'.$plugin.'_addinstance_form')) { $class = 'cachelock_'.$plugin.'_addinstance_form'; if (!array_key_exists('cache_lock_form', class_parents($class))) { throw new coding_exception('Cache lock plugin add instance forms must extend cache_lock_form'); } } } return new $class(null, array('lock' => $plugin)); }
[ "public", "static", "function", "get_add_lock_form", "(", "$", "plugin", ",", "array", "$", "lockplugin", "=", "null", ")", "{", "global", "$", "CFG", ";", "// Needed for includes.", "$", "plugins", "=", "core_component", "::", "get_plugin_list", "(", "'cachelock'", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "plugin", ",", "$", "plugins", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid cache lock plugin requested when trying to create a form.'", ")", ";", "}", "$", "plugindir", "=", "$", "plugins", "[", "$", "plugin", "]", ";", "$", "class", "=", "'cache_lock_form'", ";", "if", "(", "file_exists", "(", "$", "plugindir", ".", "'/addinstanceform.php'", ")", "&&", "in_array", "(", "'cache_is_configurable'", ",", "class_implements", "(", "$", "class", ")", ")", ")", "{", "require_once", "(", "$", "plugindir", ".", "'/addinstanceform.php'", ")", ";", "if", "(", "class_exists", "(", "'cachelock_'", ".", "$", "plugin", ".", "'_addinstance_form'", ")", ")", "{", "$", "class", "=", "'cachelock_'", ".", "$", "plugin", ".", "'_addinstance_form'", ";", "if", "(", "!", "array_key_exists", "(", "'cache_lock_form'", ",", "class_parents", "(", "$", "class", ")", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Cache lock plugin add instance forms must extend cache_lock_form'", ")", ";", "}", "}", "}", "return", "new", "$", "class", "(", "null", ",", "array", "(", "'lock'", "=>", "$", "plugin", ")", ")", ";", "}" ]
Gets the form to use when adding a lock instance. @param string $plugin @param array $lockplugin @return cache_lock_form @throws coding_exception
[ "Gets", "the", "form", "to", "use", "when", "adding", "a", "lock", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L1201-L1219
216,393
moodle/moodle
cache/locallib.php
cache_administration_helper.get_lock_configuration_from_data
public static function get_lock_configuration_from_data($plugin, $data) { global $CFG; $file = $CFG->dirroot.'/cache/locks/'.$plugin.'/lib.php'; if (!file_exists($file)) { throw new coding_exception('Invalid cache plugin provided. '.$file); } require_once($file); $class = 'cachelock_'.$plugin; if (!class_exists($class)) { throw new coding_exception('Invalid cache plugin provided.'); } if (array_key_exists('cache_is_configurable', class_implements($class))) { return $class::config_get_configuration_array($data); } return array(); }
php
public static function get_lock_configuration_from_data($plugin, $data) { global $CFG; $file = $CFG->dirroot.'/cache/locks/'.$plugin.'/lib.php'; if (!file_exists($file)) { throw new coding_exception('Invalid cache plugin provided. '.$file); } require_once($file); $class = 'cachelock_'.$plugin; if (!class_exists($class)) { throw new coding_exception('Invalid cache plugin provided.'); } if (array_key_exists('cache_is_configurable', class_implements($class))) { return $class::config_get_configuration_array($data); } return array(); }
[ "public", "static", "function", "get_lock_configuration_from_data", "(", "$", "plugin", ",", "$", "data", ")", "{", "global", "$", "CFG", ";", "$", "file", "=", "$", "CFG", "->", "dirroot", ".", "'/cache/locks/'", ".", "$", "plugin", ".", "'/lib.php'", ";", "if", "(", "!", "file_exists", "(", "$", "file", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid cache plugin provided. '", ".", "$", "file", ")", ";", "}", "require_once", "(", "$", "file", ")", ";", "$", "class", "=", "'cachelock_'", ".", "$", "plugin", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid cache plugin provided.'", ")", ";", "}", "if", "(", "array_key_exists", "(", "'cache_is_configurable'", ",", "class_implements", "(", "$", "class", ")", ")", ")", "{", "return", "$", "class", "::", "config_get_configuration_array", "(", "$", "data", ")", ";", "}", "return", "array", "(", ")", ";", "}" ]
Gets configuration data from a new lock instance form. @param string $plugin @param stdClass $data @return array @throws coding_exception
[ "Gets", "configuration", "data", "from", "a", "new", "lock", "instance", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/locallib.php#L1229-L1244
216,394
moodle/moodle
lib/pear/HTML/QuickForm/advcheckbox.php
HTML_QuickForm_advcheckbox.getOnclickJs
function getOnclickJs($elementName) { $onclickJs = 'if (this.checked) { this.form[\''.$elementName.'\'].value=\''.addcslashes($this->_values[1], '\'').'\'; }'; $onclickJs .= 'else { this.form[\''.$elementName.'\'].value=\''.addcslashes($this->_values[0], '\'').'\'; }'; return $onclickJs; }
php
function getOnclickJs($elementName) { $onclickJs = 'if (this.checked) { this.form[\''.$elementName.'\'].value=\''.addcslashes($this->_values[1], '\'').'\'; }'; $onclickJs .= 'else { this.form[\''.$elementName.'\'].value=\''.addcslashes($this->_values[0], '\'').'\'; }'; return $onclickJs; }
[ "function", "getOnclickJs", "(", "$", "elementName", ")", "{", "$", "onclickJs", "=", "'if (this.checked) { this.form[\\''", ".", "$", "elementName", ".", "'\\'].value=\\''", ".", "addcslashes", "(", "$", "this", "->", "_values", "[", "1", "]", ",", "'\\''", ")", ".", "'\\'; }'", ";", "$", "onclickJs", ".=", "'else { this.form[\\''", ".", "$", "elementName", ".", "'\\'].value=\\''", ".", "addcslashes", "(", "$", "this", "->", "_values", "[", "0", "]", ",", "'\\''", ")", ".", "'\\'; }'", ";", "return", "$", "onclickJs", ";", "}" ]
Create the javascript for the onclick event which will set the value of the hidden field @param string $elementName The element name @access public @return string @deprecated Deprecated since 3.2.6, this element no longer uses any javascript
[ "Create", "the", "javascript", "for", "the", "onclick", "event", "which", "will", "set", "the", "value", "of", "the", "hidden", "field" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/advcheckbox.php#L127-L132
216,395
moodle/moodle
lib/pear/HTML/QuickForm/advcheckbox.php
HTML_QuickForm_advcheckbox.setValues
function setValues($values) { if (empty($values)) { // give it default checkbox behavior $this->_values = array('', 1); } elseif (is_scalar($values)) { // if it's string, then assume the value to // be passed is for when the element is checked $this->_values = array('', $values); } else { $this->_values = $values; } $this->updateAttributes(array('value' => $this->_values[1])); $this->setChecked($this->_currentValue == $this->_values[1]); }
php
function setValues($values) { if (empty($values)) { // give it default checkbox behavior $this->_values = array('', 1); } elseif (is_scalar($values)) { // if it's string, then assume the value to // be passed is for when the element is checked $this->_values = array('', $values); } else { $this->_values = $values; } $this->updateAttributes(array('value' => $this->_values[1])); $this->setChecked($this->_currentValue == $this->_values[1]); }
[ "function", "setValues", "(", "$", "values", ")", "{", "if", "(", "empty", "(", "$", "values", ")", ")", "{", "// give it default checkbox behavior", "$", "this", "->", "_values", "=", "array", "(", "''", ",", "1", ")", ";", "}", "elseif", "(", "is_scalar", "(", "$", "values", ")", ")", "{", "// if it's string, then assume the value to", "// be passed is for when the element is checked", "$", "this", "->", "_values", "=", "array", "(", "''", ",", "$", "values", ")", ";", "}", "else", "{", "$", "this", "->", "_values", "=", "$", "values", ";", "}", "$", "this", "->", "updateAttributes", "(", "array", "(", "'value'", "=>", "$", "this", "->", "_values", "[", "1", "]", ")", ")", ";", "$", "this", "->", "setChecked", "(", "$", "this", "->", "_currentValue", "==", "$", "this", "->", "_values", "[", "1", "]", ")", ";", "}" ]
Sets the values used by the hidden element @param mixed $values The values, either a string or an array @access public @return void
[ "Sets", "the", "values", "used", "by", "the", "hidden", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/advcheckbox.php#L145-L159
216,396
moodle/moodle
lib/pear/HTML/QuickForm/advcheckbox.php
HTML_QuickForm_advcheckbox.setValue
function setValue($value) { $this->setChecked(isset($this->_values[1]) && $value == $this->_values[1]); $this->_currentValue = $value; }
php
function setValue($value) { $this->setChecked(isset($this->_values[1]) && $value == $this->_values[1]); $this->_currentValue = $value; }
[ "function", "setValue", "(", "$", "value", ")", "{", "$", "this", "->", "setChecked", "(", "isset", "(", "$", "this", "->", "_values", "[", "1", "]", ")", "&&", "$", "value", "==", "$", "this", "->", "_values", "[", "1", "]", ")", ";", "$", "this", "->", "_currentValue", "=", "$", "value", ";", "}" ]
Sets the element's value @param mixed Element's value @access public
[ "Sets", "the", "element", "s", "value" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/advcheckbox.php#L170-L174
216,397
moodle/moodle
lib/pear/HTML/QuickForm/advcheckbox.php
HTML_QuickForm_advcheckbox.toHtml
function toHtml() { if ($this->_flagFrozen) { return parent::toHtml(); } else { return '<input' . $this->_getAttrString(array( 'type' => 'hidden', 'name' => $this->getName(), 'value' => $this->_values[0] )) . ' />' . parent::toHtml(); } }
php
function toHtml() { if ($this->_flagFrozen) { return parent::toHtml(); } else { return '<input' . $this->_getAttrString(array( 'type' => 'hidden', 'name' => $this->getName(), 'value' => $this->_values[0] )) . ' />' . parent::toHtml(); } }
[ "function", "toHtml", "(", ")", "{", "if", "(", "$", "this", "->", "_flagFrozen", ")", "{", "return", "parent", "::", "toHtml", "(", ")", ";", "}", "else", "{", "return", "'<input'", ".", "$", "this", "->", "_getAttrString", "(", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "$", "this", "->", "getName", "(", ")", ",", "'value'", "=>", "$", "this", "->", "_values", "[", "0", "]", ")", ")", ".", "' />'", ".", "parent", "::", "toHtml", "(", ")", ";", "}", "}" ]
Returns the checkbox element in HTML and the additional hidden element in HTML @access public @return string
[ "Returns", "the", "checkbox", "element", "in", "HTML", "and", "the", "additional", "hidden", "element", "in", "HTML" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/advcheckbox.php#L204-L216
216,398
moodle/moodle
lib/pear/HTML/QuickForm/advcheckbox.php
HTML_QuickForm_advcheckbox.exportValue
function exportValue(&$submitValues, $assoc = false) { $value = $this->_findValue($submitValues); if (null === $value) { $value = $this->getValue(); } elseif (is_array($this->_values) && ($value != $this->_values[0]) && ($value != $this->_values[1])) { $value = null; } return $this->_prepareValue($value, $assoc); }
php
function exportValue(&$submitValues, $assoc = false) { $value = $this->_findValue($submitValues); if (null === $value) { $value = $this->getValue(); } elseif (is_array($this->_values) && ($value != $this->_values[0]) && ($value != $this->_values[1])) { $value = null; } return $this->_prepareValue($value, $assoc); }
[ "function", "exportValue", "(", "&", "$", "submitValues", ",", "$", "assoc", "=", "false", ")", "{", "$", "value", "=", "$", "this", "->", "_findValue", "(", "$", "submitValues", ")", ";", "if", "(", "null", "===", "$", "value", ")", "{", "$", "value", "=", "$", "this", "->", "getValue", "(", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "this", "->", "_values", ")", "&&", "(", "$", "value", "!=", "$", "this", "->", "_values", "[", "0", "]", ")", "&&", "(", "$", "value", "!=", "$", "this", "->", "_values", "[", "1", "]", ")", ")", "{", "$", "value", "=", "null", ";", "}", "return", "$", "this", "->", "_prepareValue", "(", "$", "value", ",", "$", "assoc", ")", ";", "}" ]
This element has a value even if it is not checked, thus we override checkbox's behaviour here
[ "This", "element", "has", "a", "value", "even", "if", "it", "is", "not", "checked", "thus", "we", "override", "checkbox", "s", "behaviour", "here" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/advcheckbox.php#L274-L283
216,399
moodle/moodle
mod/quiz/classes/output/edit_renderer.php
edit_renderer.edit_page
public function edit_page(\quiz $quizobj, structure $structure, \question_edit_contexts $contexts, \moodle_url $pageurl, array $pagevars) { $output = ''; // Page title. $output .= $this->heading_with_help(get_string('editingquizx', 'quiz', format_string($quizobj->get_quiz_name())), 'editingquiz', 'quiz', '', get_string('basicideasofquiz', 'quiz'), 2); // Information at the top. $output .= $this->quiz_state_warnings($structure); $output .= html_writer::start_div('mod_quiz-edit-top-controls'); $output .= $this->quiz_information($structure); $output .= $this->maximum_grade_input($structure, $pageurl); $output .= html_writer::start_div('mod_quiz-edit-action-buttons btn-group edit-toolbar', ['role' => 'group']); $output .= $this->repaginate_button($structure, $pageurl); $output .= $this->selectmultiple_button($structure); $output .= html_writer::end_tag('div'); $output .= $this->total_marks($quizobj->get_quiz()); $output .= $this->selectmultiple_controls($structure); $output .= html_writer::end_tag('div'); // Show the questions organised into sections and pages. $output .= $this->start_section_list($structure); foreach ($structure->get_sections() as $section) { $output .= $this->start_section($structure, $section); $output .= $this->questions_in_section($structure, $section, $contexts, $pagevars, $pageurl); if ($structure->is_last_section($section)) { $output .= \html_writer::start_div('last-add-menu'); $output .= html_writer::tag('span', $this->add_menu_actions($structure, 0, $pageurl, $contexts, $pagevars), array('class' => 'add-menu-outer')); $output .= \html_writer::end_div(); } $output .= $this->end_section(); } $output .= $this->end_section_list(); // Initialise the JavaScript. $this->initialise_editing_javascript($structure, $contexts, $pagevars, $pageurl); // Include the contents of any other popups required. if ($structure->can_be_edited()) { $thiscontext = $contexts->lowest(); $this->page->requires->js_call_amd('mod_quiz/quizquestionbank', 'init', [ $thiscontext->id ]); $this->page->requires->js_call_amd('mod_quiz/add_random_question', 'init', [ $thiscontext->id, $pagevars['cat'], $pageurl->out_as_local_url(true), $pageurl->param('cmid') ]); // Include the question chooser. $output .= $this->question_chooser(); } return $output; }
php
public function edit_page(\quiz $quizobj, structure $structure, \question_edit_contexts $contexts, \moodle_url $pageurl, array $pagevars) { $output = ''; // Page title. $output .= $this->heading_with_help(get_string('editingquizx', 'quiz', format_string($quizobj->get_quiz_name())), 'editingquiz', 'quiz', '', get_string('basicideasofquiz', 'quiz'), 2); // Information at the top. $output .= $this->quiz_state_warnings($structure); $output .= html_writer::start_div('mod_quiz-edit-top-controls'); $output .= $this->quiz_information($structure); $output .= $this->maximum_grade_input($structure, $pageurl); $output .= html_writer::start_div('mod_quiz-edit-action-buttons btn-group edit-toolbar', ['role' => 'group']); $output .= $this->repaginate_button($structure, $pageurl); $output .= $this->selectmultiple_button($structure); $output .= html_writer::end_tag('div'); $output .= $this->total_marks($quizobj->get_quiz()); $output .= $this->selectmultiple_controls($structure); $output .= html_writer::end_tag('div'); // Show the questions organised into sections and pages. $output .= $this->start_section_list($structure); foreach ($structure->get_sections() as $section) { $output .= $this->start_section($structure, $section); $output .= $this->questions_in_section($structure, $section, $contexts, $pagevars, $pageurl); if ($structure->is_last_section($section)) { $output .= \html_writer::start_div('last-add-menu'); $output .= html_writer::tag('span', $this->add_menu_actions($structure, 0, $pageurl, $contexts, $pagevars), array('class' => 'add-menu-outer')); $output .= \html_writer::end_div(); } $output .= $this->end_section(); } $output .= $this->end_section_list(); // Initialise the JavaScript. $this->initialise_editing_javascript($structure, $contexts, $pagevars, $pageurl); // Include the contents of any other popups required. if ($structure->can_be_edited()) { $thiscontext = $contexts->lowest(); $this->page->requires->js_call_amd('mod_quiz/quizquestionbank', 'init', [ $thiscontext->id ]); $this->page->requires->js_call_amd('mod_quiz/add_random_question', 'init', [ $thiscontext->id, $pagevars['cat'], $pageurl->out_as_local_url(true), $pageurl->param('cmid') ]); // Include the question chooser. $output .= $this->question_chooser(); } return $output; }
[ "public", "function", "edit_page", "(", "\\", "quiz", "$", "quizobj", ",", "structure", "$", "structure", ",", "\\", "question_edit_contexts", "$", "contexts", ",", "\\", "moodle_url", "$", "pageurl", ",", "array", "$", "pagevars", ")", "{", "$", "output", "=", "''", ";", "// Page title.", "$", "output", ".=", "$", "this", "->", "heading_with_help", "(", "get_string", "(", "'editingquizx'", ",", "'quiz'", ",", "format_string", "(", "$", "quizobj", "->", "get_quiz_name", "(", ")", ")", ")", ",", "'editingquiz'", ",", "'quiz'", ",", "''", ",", "get_string", "(", "'basicideasofquiz'", ",", "'quiz'", ")", ",", "2", ")", ";", "// Information at the top.", "$", "output", ".=", "$", "this", "->", "quiz_state_warnings", "(", "$", "structure", ")", ";", "$", "output", ".=", "html_writer", "::", "start_div", "(", "'mod_quiz-edit-top-controls'", ")", ";", "$", "output", ".=", "$", "this", "->", "quiz_information", "(", "$", "structure", ")", ";", "$", "output", ".=", "$", "this", "->", "maximum_grade_input", "(", "$", "structure", ",", "$", "pageurl", ")", ";", "$", "output", ".=", "html_writer", "::", "start_div", "(", "'mod_quiz-edit-action-buttons btn-group edit-toolbar'", ",", "[", "'role'", "=>", "'group'", "]", ")", ";", "$", "output", ".=", "$", "this", "->", "repaginate_button", "(", "$", "structure", ",", "$", "pageurl", ")", ";", "$", "output", ".=", "$", "this", "->", "selectmultiple_button", "(", "$", "structure", ")", ";", "$", "output", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "$", "output", ".=", "$", "this", "->", "total_marks", "(", "$", "quizobj", "->", "get_quiz", "(", ")", ")", ";", "$", "output", ".=", "$", "this", "->", "selectmultiple_controls", "(", "$", "structure", ")", ";", "$", "output", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "// Show the questions organised into sections and pages.", "$", "output", ".=", "$", "this", "->", "start_section_list", "(", "$", "structure", ")", ";", "foreach", "(", "$", "structure", "->", "get_sections", "(", ")", "as", "$", "section", ")", "{", "$", "output", ".=", "$", "this", "->", "start_section", "(", "$", "structure", ",", "$", "section", ")", ";", "$", "output", ".=", "$", "this", "->", "questions_in_section", "(", "$", "structure", ",", "$", "section", ",", "$", "contexts", ",", "$", "pagevars", ",", "$", "pageurl", ")", ";", "if", "(", "$", "structure", "->", "is_last_section", "(", "$", "section", ")", ")", "{", "$", "output", ".=", "\\", "html_writer", "::", "start_div", "(", "'last-add-menu'", ")", ";", "$", "output", ".=", "html_writer", "::", "tag", "(", "'span'", ",", "$", "this", "->", "add_menu_actions", "(", "$", "structure", ",", "0", ",", "$", "pageurl", ",", "$", "contexts", ",", "$", "pagevars", ")", ",", "array", "(", "'class'", "=>", "'add-menu-outer'", ")", ")", ";", "$", "output", ".=", "\\", "html_writer", "::", "end_div", "(", ")", ";", "}", "$", "output", ".=", "$", "this", "->", "end_section", "(", ")", ";", "}", "$", "output", ".=", "$", "this", "->", "end_section_list", "(", ")", ";", "// Initialise the JavaScript.", "$", "this", "->", "initialise_editing_javascript", "(", "$", "structure", ",", "$", "contexts", ",", "$", "pagevars", ",", "$", "pageurl", ")", ";", "// Include the contents of any other popups required.", "if", "(", "$", "structure", "->", "can_be_edited", "(", ")", ")", "{", "$", "thiscontext", "=", "$", "contexts", "->", "lowest", "(", ")", ";", "$", "this", "->", "page", "->", "requires", "->", "js_call_amd", "(", "'mod_quiz/quizquestionbank'", ",", "'init'", ",", "[", "$", "thiscontext", "->", "id", "]", ")", ";", "$", "this", "->", "page", "->", "requires", "->", "js_call_amd", "(", "'mod_quiz/add_random_question'", ",", "'init'", ",", "[", "$", "thiscontext", "->", "id", ",", "$", "pagevars", "[", "'cat'", "]", ",", "$", "pageurl", "->", "out_as_local_url", "(", "true", ")", ",", "$", "pageurl", "->", "param", "(", "'cmid'", ")", "]", ")", ";", "// Include the question chooser.", "$", "output", ".=", "$", "this", "->", "question_chooser", "(", ")", ";", "}", "return", "$", "output", ";", "}" ]
Render the edit page @param \quiz $quizobj object containing all the quiz settings information. @param structure $structure object containing the structure of the quiz. @param \question_edit_contexts $contexts the relevant question bank contexts. @param \moodle_url $pageurl the canonical URL of this page. @param array $pagevars the variables from {@link question_edit_setup()}. @return string HTML to output.
[ "Render", "the", "edit", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/output/edit_renderer.php#L51-L118