id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
219,500
moodle/moodle
question/format/xml/format.php
qformat_xml.import_combined_feedback
public function import_combined_feedback($qo, $questionxml, $withshownumpartscorrect = false) { $fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'); foreach ($fields as $field) { $qo->$field = $this->import_text_with_files($questionxml, array('#', $field, 0), '', $this->get_format($qo->questiontextformat)); } if ($withshownumpartscorrect) { $qo->shownumcorrect = array_key_exists('shownumcorrect', $questionxml['#']); // Backwards compatibility. if (array_key_exists('correctresponsesfeedback', $questionxml['#'])) { $qo->shownumcorrect = $this->trans_single($this->getpath($questionxml, array('#', 'correctresponsesfeedback', 0, '#'), 1)); } } }
php
public function import_combined_feedback($qo, $questionxml, $withshownumpartscorrect = false) { $fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'); foreach ($fields as $field) { $qo->$field = $this->import_text_with_files($questionxml, array('#', $field, 0), '', $this->get_format($qo->questiontextformat)); } if ($withshownumpartscorrect) { $qo->shownumcorrect = array_key_exists('shownumcorrect', $questionxml['#']); // Backwards compatibility. if (array_key_exists('correctresponsesfeedback', $questionxml['#'])) { $qo->shownumcorrect = $this->trans_single($this->getpath($questionxml, array('#', 'correctresponsesfeedback', 0, '#'), 1)); } } }
[ "public", "function", "import_combined_feedback", "(", "$", "qo", ",", "$", "questionxml", ",", "$", "withshownumpartscorrect", "=", "false", ")", "{", "$", "fields", "=", "array", "(", "'correctfeedback'", ",", "'partiallycorrectfeedback'", ",", "'incorrectfeedback'", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "$", "qo", "->", "$", "field", "=", "$", "this", "->", "import_text_with_files", "(", "$", "questionxml", ",", "array", "(", "'#'", ",", "$", "field", ",", "0", ")", ",", "''", ",", "$", "this", "->", "get_format", "(", "$", "qo", "->", "questiontextformat", ")", ")", ";", "}", "if", "(", "$", "withshownumpartscorrect", ")", "{", "$", "qo", "->", "shownumcorrect", "=", "array_key_exists", "(", "'shownumcorrect'", ",", "$", "questionxml", "[", "'#'", "]", ")", ";", "// Backwards compatibility.", "if", "(", "array_key_exists", "(", "'correctresponsesfeedback'", ",", "$", "questionxml", "[", "'#'", "]", ")", ")", "{", "$", "qo", "->", "shownumcorrect", "=", "$", "this", "->", "trans_single", "(", "$", "this", "->", "getpath", "(", "$", "questionxml", ",", "array", "(", "'#'", ",", "'correctresponsesfeedback'", ",", "0", ",", "'#'", ")", ",", "1", ")", ")", ";", "}", "}", "}" ]
Import the common overall feedback fields. @param object $question the part of the XML relating to this question. @param object $qo the question data to add the fields to. @param bool $withshownumpartscorrect include the shownumcorrect field.
[ "Import", "the", "common", "overall", "feedback", "fields", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L299-L315
219,501
moodle/moodle
question/format/xml/format.php
qformat_xml.import_hint
public function import_hint($hintxml, $defaultformat) { $hint = new stdClass(); if (array_key_exists('hintcontent', $hintxml['#'])) { // Backwards compatibility. $hint->hint = $this->import_text_with_files($hintxml, array('#', 'hintcontent', 0), '', $defaultformat); $hint->shownumcorrect = $this->getpath($hintxml, array('#', 'statenumberofcorrectresponses', 0, '#'), 0); $hint->clearwrong = $this->getpath($hintxml, array('#', 'clearincorrectresponses', 0, '#'), 0); $hint->options = $this->getpath($hintxml, array('#', 'showfeedbacktoresponses', 0, '#'), 0); return $hint; } $hint->hint = $this->import_text_with_files($hintxml, array(), '', $defaultformat); $hint->shownumcorrect = array_key_exists('shownumcorrect', $hintxml['#']); $hint->clearwrong = array_key_exists('clearwrong', $hintxml['#']); $hint->options = $this->getpath($hintxml, array('#', 'options', 0, '#'), '', true); return $hint; }
php
public function import_hint($hintxml, $defaultformat) { $hint = new stdClass(); if (array_key_exists('hintcontent', $hintxml['#'])) { // Backwards compatibility. $hint->hint = $this->import_text_with_files($hintxml, array('#', 'hintcontent', 0), '', $defaultformat); $hint->shownumcorrect = $this->getpath($hintxml, array('#', 'statenumberofcorrectresponses', 0, '#'), 0); $hint->clearwrong = $this->getpath($hintxml, array('#', 'clearincorrectresponses', 0, '#'), 0); $hint->options = $this->getpath($hintxml, array('#', 'showfeedbacktoresponses', 0, '#'), 0); return $hint; } $hint->hint = $this->import_text_with_files($hintxml, array(), '', $defaultformat); $hint->shownumcorrect = array_key_exists('shownumcorrect', $hintxml['#']); $hint->clearwrong = array_key_exists('clearwrong', $hintxml['#']); $hint->options = $this->getpath($hintxml, array('#', 'options', 0, '#'), '', true); return $hint; }
[ "public", "function", "import_hint", "(", "$", "hintxml", ",", "$", "defaultformat", ")", "{", "$", "hint", "=", "new", "stdClass", "(", ")", ";", "if", "(", "array_key_exists", "(", "'hintcontent'", ",", "$", "hintxml", "[", "'#'", "]", ")", ")", "{", "// Backwards compatibility.", "$", "hint", "->", "hint", "=", "$", "this", "->", "import_text_with_files", "(", "$", "hintxml", ",", "array", "(", "'#'", ",", "'hintcontent'", ",", "0", ")", ",", "''", ",", "$", "defaultformat", ")", ";", "$", "hint", "->", "shownumcorrect", "=", "$", "this", "->", "getpath", "(", "$", "hintxml", ",", "array", "(", "'#'", ",", "'statenumberofcorrectresponses'", ",", "0", ",", "'#'", ")", ",", "0", ")", ";", "$", "hint", "->", "clearwrong", "=", "$", "this", "->", "getpath", "(", "$", "hintxml", ",", "array", "(", "'#'", ",", "'clearincorrectresponses'", ",", "0", ",", "'#'", ")", ",", "0", ")", ";", "$", "hint", "->", "options", "=", "$", "this", "->", "getpath", "(", "$", "hintxml", ",", "array", "(", "'#'", ",", "'showfeedbacktoresponses'", ",", "0", ",", "'#'", ")", ",", "0", ")", ";", "return", "$", "hint", ";", "}", "$", "hint", "->", "hint", "=", "$", "this", "->", "import_text_with_files", "(", "$", "hintxml", ",", "array", "(", ")", ",", "''", ",", "$", "defaultformat", ")", ";", "$", "hint", "->", "shownumcorrect", "=", "array_key_exists", "(", "'shownumcorrect'", ",", "$", "hintxml", "[", "'#'", "]", ")", ";", "$", "hint", "->", "clearwrong", "=", "array_key_exists", "(", "'clearwrong'", ",", "$", "hintxml", "[", "'#'", "]", ")", ";", "$", "hint", "->", "options", "=", "$", "this", "->", "getpath", "(", "$", "hintxml", ",", "array", "(", "'#'", ",", "'options'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "return", "$", "hint", ";", "}" ]
Import a question hint @param array $hintxml hint xml fragment. @param string $defaultformat the text format to assume for hints that do not specify. @return object hint for storing in the database.
[ "Import", "a", "question", "hint" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L323-L346
219,502
moodle/moodle
question/format/xml/format.php
qformat_xml.import_hints
public function import_hints($qo, $questionxml, $withparts = false, $withoptions = false, $defaultformat = 'html') { if (!isset($questionxml['#']['hint'])) { return; } foreach ($questionxml['#']['hint'] as $hintxml) { $hint = $this->import_hint($hintxml, $defaultformat); $qo->hint[] = $hint->hint; if ($withparts) { $qo->hintshownumcorrect[] = $hint->shownumcorrect; $qo->hintclearwrong[] = $hint->clearwrong; } if ($withoptions) { $qo->hintoptions[] = $hint->options; } } }
php
public function import_hints($qo, $questionxml, $withparts = false, $withoptions = false, $defaultformat = 'html') { if (!isset($questionxml['#']['hint'])) { return; } foreach ($questionxml['#']['hint'] as $hintxml) { $hint = $this->import_hint($hintxml, $defaultformat); $qo->hint[] = $hint->hint; if ($withparts) { $qo->hintshownumcorrect[] = $hint->shownumcorrect; $qo->hintclearwrong[] = $hint->clearwrong; } if ($withoptions) { $qo->hintoptions[] = $hint->options; } } }
[ "public", "function", "import_hints", "(", "$", "qo", ",", "$", "questionxml", ",", "$", "withparts", "=", "false", ",", "$", "withoptions", "=", "false", ",", "$", "defaultformat", "=", "'html'", ")", "{", "if", "(", "!", "isset", "(", "$", "questionxml", "[", "'#'", "]", "[", "'hint'", "]", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "questionxml", "[", "'#'", "]", "[", "'hint'", "]", "as", "$", "hintxml", ")", "{", "$", "hint", "=", "$", "this", "->", "import_hint", "(", "$", "hintxml", ",", "$", "defaultformat", ")", ";", "$", "qo", "->", "hint", "[", "]", "=", "$", "hint", "->", "hint", ";", "if", "(", "$", "withparts", ")", "{", "$", "qo", "->", "hintshownumcorrect", "[", "]", "=", "$", "hint", "->", "shownumcorrect", ";", "$", "qo", "->", "hintclearwrong", "[", "]", "=", "$", "hint", "->", "clearwrong", ";", "}", "if", "(", "$", "withoptions", ")", "{", "$", "qo", "->", "hintoptions", "[", "]", "=", "$", "hint", "->", "options", ";", "}", "}", "}" ]
Import all the question hints @param object $qo the question data that is being constructed. @param array $questionxml The xml representing the question. @param bool $withparts whether the extra fields relating to parts should be imported. @param bool $withoptions whether the extra options field should be imported. @param string $defaultformat the text format to assume for hints that do not specify. @return array of objects representing the hints in the file.
[ "Import", "all", "the", "question", "hints" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L358-L377
219,503
moodle/moodle
question/format/xml/format.php
qformat_xml.import_question_tags
public function import_question_tags($qo, $questionxml) { global $CFG; if (core_tag_tag::is_enabled('core_question', 'question')) { $qo->tags = []; if (!empty($questionxml['#']['tags'][0]['#']['tag'])) { foreach ($questionxml['#']['tags'][0]['#']['tag'] as $tagdata) { $qo->tags[] = $this->getpath($tagdata, array('#', 'text', 0, '#'), '', true); } } $qo->coursetags = []; if (!empty($questionxml['#']['coursetags'][0]['#']['tag'])) { foreach ($questionxml['#']['coursetags'][0]['#']['tag'] as $tagdata) { $qo->coursetags[] = $this->getpath($tagdata, array('#', 'text', 0, '#'), '', true); } } } }
php
public function import_question_tags($qo, $questionxml) { global $CFG; if (core_tag_tag::is_enabled('core_question', 'question')) { $qo->tags = []; if (!empty($questionxml['#']['tags'][0]['#']['tag'])) { foreach ($questionxml['#']['tags'][0]['#']['tag'] as $tagdata) { $qo->tags[] = $this->getpath($tagdata, array('#', 'text', 0, '#'), '', true); } } $qo->coursetags = []; if (!empty($questionxml['#']['coursetags'][0]['#']['tag'])) { foreach ($questionxml['#']['coursetags'][0]['#']['tag'] as $tagdata) { $qo->coursetags[] = $this->getpath($tagdata, array('#', 'text', 0, '#'), '', true); } } } }
[ "public", "function", "import_question_tags", "(", "$", "qo", ",", "$", "questionxml", ")", "{", "global", "$", "CFG", ";", "if", "(", "core_tag_tag", "::", "is_enabled", "(", "'core_question'", ",", "'question'", ")", ")", "{", "$", "qo", "->", "tags", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "questionxml", "[", "'#'", "]", "[", "'tags'", "]", "[", "0", "]", "[", "'#'", "]", "[", "'tag'", "]", ")", ")", "{", "foreach", "(", "$", "questionxml", "[", "'#'", "]", "[", "'tags'", "]", "[", "0", "]", "[", "'#'", "]", "[", "'tag'", "]", "as", "$", "tagdata", ")", "{", "$", "qo", "->", "tags", "[", "]", "=", "$", "this", "->", "getpath", "(", "$", "tagdata", ",", "array", "(", "'#'", ",", "'text'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "}", "}", "$", "qo", "->", "coursetags", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "questionxml", "[", "'#'", "]", "[", "'coursetags'", "]", "[", "0", "]", "[", "'#'", "]", "[", "'tag'", "]", ")", ")", "{", "foreach", "(", "$", "questionxml", "[", "'#'", "]", "[", "'coursetags'", "]", "[", "0", "]", "[", "'#'", "]", "[", "'tag'", "]", "as", "$", "tagdata", ")", "{", "$", "qo", "->", "coursetags", "[", "]", "=", "$", "this", "->", "getpath", "(", "$", "tagdata", ",", "array", "(", "'#'", ",", "'text'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "}", "}", "}", "}" ]
Import all the question tags @param object $qo the question data that is being constructed. @param array $questionxml The xml representing the question. @return array of objects representing the tags in the file.
[ "Import", "all", "the", "question", "tags" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L386-L405
219,504
moodle/moodle
question/format/xml/format.php
qformat_xml.import_files
public function import_files($xml) { $files = array(); foreach ($xml as $file) { $data = new stdClass(); $data->content = $file['#']; $data->encoding = $file['@']['encoding']; $data->name = $file['@']['name']; $files[] = $data; } return $files; }
php
public function import_files($xml) { $files = array(); foreach ($xml as $file) { $data = new stdClass(); $data->content = $file['#']; $data->encoding = $file['@']['encoding']; $data->name = $file['@']['name']; $files[] = $data; } return $files; }
[ "public", "function", "import_files", "(", "$", "xml", ")", "{", "$", "files", "=", "array", "(", ")", ";", "foreach", "(", "$", "xml", "as", "$", "file", ")", "{", "$", "data", "=", "new", "stdClass", "(", ")", ";", "$", "data", "->", "content", "=", "$", "file", "[", "'#'", "]", ";", "$", "data", "->", "encoding", "=", "$", "file", "[", "'@'", "]", "[", "'encoding'", "]", ";", "$", "data", "->", "name", "=", "$", "file", "[", "'@'", "]", "[", "'name'", "]", ";", "$", "files", "[", "]", "=", "$", "data", ";", "}", "return", "$", "files", ";", "}" ]
Import files from a node in the XML. @param array $xml an array of <file> nodes from the the parsed XML. @return array of things representing files - in the form that save_question expects.
[ "Import", "files", "from", "a", "node", "in", "the", "XML", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L412-L422
219,505
moodle/moodle
question/format/xml/format.php
qformat_xml.import_multichoice
public function import_multichoice($question) { // Get common parts. $qo = $this->import_headers($question); // Header parts particular to multichoice. $qo->qtype = 'multichoice'; $single = $this->getpath($question, array('#', 'single', 0, '#'), 'true'); $qo->single = $this->trans_single($single); $shuffleanswers = $this->getpath($question, array('#', 'shuffleanswers', 0, '#'), 'false'); $qo->answernumbering = $this->getpath($question, array('#', 'answernumbering', 0, '#'), 'abc'); $qo->shuffleanswers = $this->trans_single($shuffleanswers); // There was a time on the 1.8 branch when it could output an empty // answernumbering tag, so fix up any found. if (empty($qo->answernumbering)) { $qo->answernumbering = 'abc'; } // Run through the answers. $answers = $question['#']['answer']; $acount = 0; foreach ($answers as $answer) { $ans = $this->import_answer($answer, true, $this->get_format($qo->questiontextformat)); $qo->answer[$acount] = $ans->answer; $qo->fraction[$acount] = $ans->fraction; $qo->feedback[$acount] = $ans->feedback; ++$acount; } $this->import_combined_feedback($qo, $question, true); $this->import_hints($qo, $question, true, false, $this->get_format($qo->questiontextformat)); return $qo; }
php
public function import_multichoice($question) { // Get common parts. $qo = $this->import_headers($question); // Header parts particular to multichoice. $qo->qtype = 'multichoice'; $single = $this->getpath($question, array('#', 'single', 0, '#'), 'true'); $qo->single = $this->trans_single($single); $shuffleanswers = $this->getpath($question, array('#', 'shuffleanswers', 0, '#'), 'false'); $qo->answernumbering = $this->getpath($question, array('#', 'answernumbering', 0, '#'), 'abc'); $qo->shuffleanswers = $this->trans_single($shuffleanswers); // There was a time on the 1.8 branch when it could output an empty // answernumbering tag, so fix up any found. if (empty($qo->answernumbering)) { $qo->answernumbering = 'abc'; } // Run through the answers. $answers = $question['#']['answer']; $acount = 0; foreach ($answers as $answer) { $ans = $this->import_answer($answer, true, $this->get_format($qo->questiontextformat)); $qo->answer[$acount] = $ans->answer; $qo->fraction[$acount] = $ans->fraction; $qo->feedback[$acount] = $ans->feedback; ++$acount; } $this->import_combined_feedback($qo, $question, true); $this->import_hints($qo, $question, true, false, $this->get_format($qo->questiontextformat)); return $qo; }
[ "public", "function", "import_multichoice", "(", "$", "question", ")", "{", "// Get common parts.", "$", "qo", "=", "$", "this", "->", "import_headers", "(", "$", "question", ")", ";", "// Header parts particular to multichoice.", "$", "qo", "->", "qtype", "=", "'multichoice'", ";", "$", "single", "=", "$", "this", "->", "getpath", "(", "$", "question", ",", "array", "(", "'#'", ",", "'single'", ",", "0", ",", "'#'", ")", ",", "'true'", ")", ";", "$", "qo", "->", "single", "=", "$", "this", "->", "trans_single", "(", "$", "single", ")", ";", "$", "shuffleanswers", "=", "$", "this", "->", "getpath", "(", "$", "question", ",", "array", "(", "'#'", ",", "'shuffleanswers'", ",", "0", ",", "'#'", ")", ",", "'false'", ")", ";", "$", "qo", "->", "answernumbering", "=", "$", "this", "->", "getpath", "(", "$", "question", ",", "array", "(", "'#'", ",", "'answernumbering'", ",", "0", ",", "'#'", ")", ",", "'abc'", ")", ";", "$", "qo", "->", "shuffleanswers", "=", "$", "this", "->", "trans_single", "(", "$", "shuffleanswers", ")", ";", "// There was a time on the 1.8 branch when it could output an empty", "// answernumbering tag, so fix up any found.", "if", "(", "empty", "(", "$", "qo", "->", "answernumbering", ")", ")", "{", "$", "qo", "->", "answernumbering", "=", "'abc'", ";", "}", "// Run through the answers.", "$", "answers", "=", "$", "question", "[", "'#'", "]", "[", "'answer'", "]", ";", "$", "acount", "=", "0", ";", "foreach", "(", "$", "answers", "as", "$", "answer", ")", "{", "$", "ans", "=", "$", "this", "->", "import_answer", "(", "$", "answer", ",", "true", ",", "$", "this", "->", "get_format", "(", "$", "qo", "->", "questiontextformat", ")", ")", ";", "$", "qo", "->", "answer", "[", "$", "acount", "]", "=", "$", "ans", "->", "answer", ";", "$", "qo", "->", "fraction", "[", "$", "acount", "]", "=", "$", "ans", "->", "fraction", ";", "$", "qo", "->", "feedback", "[", "$", "acount", "]", "=", "$", "ans", "->", "feedback", ";", "++", "$", "acount", ";", "}", "$", "this", "->", "import_combined_feedback", "(", "$", "qo", ",", "$", "question", ",", "true", ")", ";", "$", "this", "->", "import_hints", "(", "$", "qo", ",", "$", "question", ",", "true", ",", "false", ",", "$", "this", "->", "get_format", "(", "$", "qo", "->", "questiontextformat", ")", ")", ";", "return", "$", "qo", ";", "}" ]
import multiple choice question @param array question question array from xml tree @return object question object
[ "import", "multiple", "choice", "question" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L429-L464
219,506
moodle/moodle
question/format/xml/format.php
qformat_xml.import_shortanswer
public function import_shortanswer($question) { // Get common parts. $qo = $this->import_headers($question); // Header parts particular to shortanswer. $qo->qtype = 'shortanswer'; // Get usecase. $qo->usecase = $this->getpath($question, array('#', 'usecase', 0, '#'), $qo->usecase); // Run through the answers. $answers = $question['#']['answer']; $acount = 0; foreach ($answers as $answer) { $ans = $this->import_answer($answer, false, $this->get_format($qo->questiontextformat)); $qo->answer[$acount] = $ans->answer['text']; $qo->fraction[$acount] = $ans->fraction; $qo->feedback[$acount] = $ans->feedback; ++$acount; } $this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat)); return $qo; }
php
public function import_shortanswer($question) { // Get common parts. $qo = $this->import_headers($question); // Header parts particular to shortanswer. $qo->qtype = 'shortanswer'; // Get usecase. $qo->usecase = $this->getpath($question, array('#', 'usecase', 0, '#'), $qo->usecase); // Run through the answers. $answers = $question['#']['answer']; $acount = 0; foreach ($answers as $answer) { $ans = $this->import_answer($answer, false, $this->get_format($qo->questiontextformat)); $qo->answer[$acount] = $ans->answer['text']; $qo->fraction[$acount] = $ans->fraction; $qo->feedback[$acount] = $ans->feedback; ++$acount; } $this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat)); return $qo; }
[ "public", "function", "import_shortanswer", "(", "$", "question", ")", "{", "// Get common parts.", "$", "qo", "=", "$", "this", "->", "import_headers", "(", "$", "question", ")", ";", "// Header parts particular to shortanswer.", "$", "qo", "->", "qtype", "=", "'shortanswer'", ";", "// Get usecase.", "$", "qo", "->", "usecase", "=", "$", "this", "->", "getpath", "(", "$", "question", ",", "array", "(", "'#'", ",", "'usecase'", ",", "0", ",", "'#'", ")", ",", "$", "qo", "->", "usecase", ")", ";", "// Run through the answers.", "$", "answers", "=", "$", "question", "[", "'#'", "]", "[", "'answer'", "]", ";", "$", "acount", "=", "0", ";", "foreach", "(", "$", "answers", "as", "$", "answer", ")", "{", "$", "ans", "=", "$", "this", "->", "import_answer", "(", "$", "answer", ",", "false", ",", "$", "this", "->", "get_format", "(", "$", "qo", "->", "questiontextformat", ")", ")", ";", "$", "qo", "->", "answer", "[", "$", "acount", "]", "=", "$", "ans", "->", "answer", "[", "'text'", "]", ";", "$", "qo", "->", "fraction", "[", "$", "acount", "]", "=", "$", "ans", "->", "fraction", ";", "$", "qo", "->", "feedback", "[", "$", "acount", "]", "=", "$", "ans", "->", "feedback", ";", "++", "$", "acount", ";", "}", "$", "this", "->", "import_hints", "(", "$", "qo", ",", "$", "question", ",", "false", ",", "false", ",", "$", "this", "->", "get_format", "(", "$", "qo", "->", "questiontextformat", ")", ")", ";", "return", "$", "qo", ";", "}" ]
Import short answer type question @param array question question array from xml tree @return object question object
[ "Import", "short", "answer", "type", "question" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L610-L634
219,507
moodle/moodle
question/format/xml/format.php
qformat_xml.import_description
public function import_description($question) { // Get common parts. $qo = $this->import_headers($question); // Header parts particular to shortanswer. $qo->qtype = 'description'; $qo->defaultmark = 0; $qo->length = 0; return $qo; }
php
public function import_description($question) { // Get common parts. $qo = $this->import_headers($question); // Header parts particular to shortanswer. $qo->qtype = 'description'; $qo->defaultmark = 0; $qo->length = 0; return $qo; }
[ "public", "function", "import_description", "(", "$", "question", ")", "{", "// Get common parts.", "$", "qo", "=", "$", "this", "->", "import_headers", "(", "$", "question", ")", ";", "// Header parts particular to shortanswer.", "$", "qo", "->", "qtype", "=", "'description'", ";", "$", "qo", "->", "defaultmark", "=", "0", ";", "$", "qo", "->", "length", "=", "0", ";", "return", "$", "qo", ";", "}" ]
Import description type question @param array question question array from xml tree @return object question object
[ "Import", "description", "type", "question" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L641-L649
219,508
moodle/moodle
question/format/xml/format.php
qformat_xml.import_match
public function import_match($question) { // Get common parts. $qo = $this->import_headers($question); // Header parts particular to matching. $qo->qtype = 'match'; $qo->shuffleanswers = $this->trans_single($this->getpath($question, array('#', 'shuffleanswers', 0, '#'), 1)); // Run through subquestions. $qo->subquestions = array(); $qo->subanswers = array(); foreach ($question['#']['subquestion'] as $subqxml) { $qo->subquestions[] = $this->import_text_with_files($subqxml, array(), '', $this->get_format($qo->questiontextformat)); $answers = $this->getpath($subqxml, array('#', 'answer'), array()); $qo->subanswers[] = $this->getpath($subqxml, array('#', 'answer', 0, '#', 'text', 0, '#'), '', true); } $this->import_combined_feedback($qo, $question, true); $this->import_hints($qo, $question, true, false, $this->get_format($qo->questiontextformat)); return $qo; }
php
public function import_match($question) { // Get common parts. $qo = $this->import_headers($question); // Header parts particular to matching. $qo->qtype = 'match'; $qo->shuffleanswers = $this->trans_single($this->getpath($question, array('#', 'shuffleanswers', 0, '#'), 1)); // Run through subquestions. $qo->subquestions = array(); $qo->subanswers = array(); foreach ($question['#']['subquestion'] as $subqxml) { $qo->subquestions[] = $this->import_text_with_files($subqxml, array(), '', $this->get_format($qo->questiontextformat)); $answers = $this->getpath($subqxml, array('#', 'answer'), array()); $qo->subanswers[] = $this->getpath($subqxml, array('#', 'answer', 0, '#', 'text', 0, '#'), '', true); } $this->import_combined_feedback($qo, $question, true); $this->import_hints($qo, $question, true, false, $this->get_format($qo->questiontextformat)); return $qo; }
[ "public", "function", "import_match", "(", "$", "question", ")", "{", "// Get common parts.", "$", "qo", "=", "$", "this", "->", "import_headers", "(", "$", "question", ")", ";", "// Header parts particular to matching.", "$", "qo", "->", "qtype", "=", "'match'", ";", "$", "qo", "->", "shuffleanswers", "=", "$", "this", "->", "trans_single", "(", "$", "this", "->", "getpath", "(", "$", "question", ",", "array", "(", "'#'", ",", "'shuffleanswers'", ",", "0", ",", "'#'", ")", ",", "1", ")", ")", ";", "// Run through subquestions.", "$", "qo", "->", "subquestions", "=", "array", "(", ")", ";", "$", "qo", "->", "subanswers", "=", "array", "(", ")", ";", "foreach", "(", "$", "question", "[", "'#'", "]", "[", "'subquestion'", "]", "as", "$", "subqxml", ")", "{", "$", "qo", "->", "subquestions", "[", "]", "=", "$", "this", "->", "import_text_with_files", "(", "$", "subqxml", ",", "array", "(", ")", ",", "''", ",", "$", "this", "->", "get_format", "(", "$", "qo", "->", "questiontextformat", ")", ")", ";", "$", "answers", "=", "$", "this", "->", "getpath", "(", "$", "subqxml", ",", "array", "(", "'#'", ",", "'answer'", ")", ",", "array", "(", ")", ")", ";", "$", "qo", "->", "subanswers", "[", "]", "=", "$", "this", "->", "getpath", "(", "$", "subqxml", ",", "array", "(", "'#'", ",", "'answer'", ",", "0", ",", "'#'", ",", "'text'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "}", "$", "this", "->", "import_combined_feedback", "(", "$", "qo", ",", "$", "question", ",", "true", ")", ";", "$", "this", "->", "import_hints", "(", "$", "qo", ",", "$", "question", ",", "true", ",", "false", ",", "$", "this", "->", "get_format", "(", "$", "qo", "->", "questiontextformat", ")", ")", ";", "return", "$", "qo", ";", "}" ]
Import matching type question @param array question question array from xml tree @return object question object
[ "Import", "matching", "type", "question" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L726-L751
219,509
moodle/moodle
question/format/xml/format.php
qformat_xml.import_essay
public function import_essay($question) { // Get common parts. $qo = $this->import_headers($question); // Header parts particular to essay. $qo->qtype = 'essay'; $qo->responseformat = $this->getpath($question, array('#', 'responseformat', 0, '#'), 'editor'); $qo->responsefieldlines = $this->getpath($question, array('#', 'responsefieldlines', 0, '#'), 15); $qo->responserequired = $this->getpath($question, array('#', 'responserequired', 0, '#'), 1); $qo->attachments = $this->getpath($question, array('#', 'attachments', 0, '#'), 0); $qo->attachmentsrequired = $this->getpath($question, array('#', 'attachmentsrequired', 0, '#'), 0); $qo->graderinfo = $this->import_text_with_files($question, array('#', 'graderinfo', 0), '', $this->get_format($qo->questiontextformat)); $qo->responsetemplate['text'] = $this->getpath($question, array('#', 'responsetemplate', 0, '#', 'text', 0, '#'), '', true); $qo->responsetemplate['format'] = $this->trans_format($this->getpath($question, array('#', 'responsetemplate', 0, '@', 'format'), $this->get_format($qo->questiontextformat))); return $qo; }
php
public function import_essay($question) { // Get common parts. $qo = $this->import_headers($question); // Header parts particular to essay. $qo->qtype = 'essay'; $qo->responseformat = $this->getpath($question, array('#', 'responseformat', 0, '#'), 'editor'); $qo->responsefieldlines = $this->getpath($question, array('#', 'responsefieldlines', 0, '#'), 15); $qo->responserequired = $this->getpath($question, array('#', 'responserequired', 0, '#'), 1); $qo->attachments = $this->getpath($question, array('#', 'attachments', 0, '#'), 0); $qo->attachmentsrequired = $this->getpath($question, array('#', 'attachmentsrequired', 0, '#'), 0); $qo->graderinfo = $this->import_text_with_files($question, array('#', 'graderinfo', 0), '', $this->get_format($qo->questiontextformat)); $qo->responsetemplate['text'] = $this->getpath($question, array('#', 'responsetemplate', 0, '#', 'text', 0, '#'), '', true); $qo->responsetemplate['format'] = $this->trans_format($this->getpath($question, array('#', 'responsetemplate', 0, '@', 'format'), $this->get_format($qo->questiontextformat))); return $qo; }
[ "public", "function", "import_essay", "(", "$", "question", ")", "{", "// Get common parts.", "$", "qo", "=", "$", "this", "->", "import_headers", "(", "$", "question", ")", ";", "// Header parts particular to essay.", "$", "qo", "->", "qtype", "=", "'essay'", ";", "$", "qo", "->", "responseformat", "=", "$", "this", "->", "getpath", "(", "$", "question", ",", "array", "(", "'#'", ",", "'responseformat'", ",", "0", ",", "'#'", ")", ",", "'editor'", ")", ";", "$", "qo", "->", "responsefieldlines", "=", "$", "this", "->", "getpath", "(", "$", "question", ",", "array", "(", "'#'", ",", "'responsefieldlines'", ",", "0", ",", "'#'", ")", ",", "15", ")", ";", "$", "qo", "->", "responserequired", "=", "$", "this", "->", "getpath", "(", "$", "question", ",", "array", "(", "'#'", ",", "'responserequired'", ",", "0", ",", "'#'", ")", ",", "1", ")", ";", "$", "qo", "->", "attachments", "=", "$", "this", "->", "getpath", "(", "$", "question", ",", "array", "(", "'#'", ",", "'attachments'", ",", "0", ",", "'#'", ")", ",", "0", ")", ";", "$", "qo", "->", "attachmentsrequired", "=", "$", "this", "->", "getpath", "(", "$", "question", ",", "array", "(", "'#'", ",", "'attachmentsrequired'", ",", "0", ",", "'#'", ")", ",", "0", ")", ";", "$", "qo", "->", "graderinfo", "=", "$", "this", "->", "import_text_with_files", "(", "$", "question", ",", "array", "(", "'#'", ",", "'graderinfo'", ",", "0", ")", ",", "''", ",", "$", "this", "->", "get_format", "(", "$", "qo", "->", "questiontextformat", ")", ")", ";", "$", "qo", "->", "responsetemplate", "[", "'text'", "]", "=", "$", "this", "->", "getpath", "(", "$", "question", ",", "array", "(", "'#'", ",", "'responsetemplate'", ",", "0", ",", "'#'", ",", "'text'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "$", "qo", "->", "responsetemplate", "[", "'format'", "]", "=", "$", "this", "->", "trans_format", "(", "$", "this", "->", "getpath", "(", "$", "question", ",", "array", "(", "'#'", ",", "'responsetemplate'", ",", "0", ",", "'@'", ",", "'format'", ")", ",", "$", "this", "->", "get_format", "(", "$", "qo", "->", "questiontextformat", ")", ")", ")", ";", "return", "$", "qo", ";", "}" ]
Import essay type question @param array question question array from xml tree @return object question object
[ "Import", "essay", "type", "question" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L758-L783
219,510
moodle/moodle
question/format/xml/format.php
qformat_xml.xml_escape
public function xml_escape($string) { if (!empty($string) && htmlspecialchars($string) != $string) { // If the string contains something that looks like the end // of a CDATA section, then we need to avoid errors by splitting // the string between two CDATA sections. $string = str_replace(']]>', ']]]]><![CDATA[>', $string); return "<![CDATA[{$string}]]>"; } else { return $string; } }
php
public function xml_escape($string) { if (!empty($string) && htmlspecialchars($string) != $string) { // If the string contains something that looks like the end // of a CDATA section, then we need to avoid errors by splitting // the string between two CDATA sections. $string = str_replace(']]>', ']]]]><![CDATA[>', $string); return "<![CDATA[{$string}]]>"; } else { return $string; } }
[ "public", "function", "xml_escape", "(", "$", "string", ")", "{", "if", "(", "!", "empty", "(", "$", "string", ")", "&&", "htmlspecialchars", "(", "$", "string", ")", "!=", "$", "string", ")", "{", "// If the string contains something that looks like the end", "// of a CDATA section, then we need to avoid errors by splitting", "// the string between two CDATA sections.", "$", "string", "=", "str_replace", "(", "']]>'", ",", "']]]]><![CDATA[>'", ",", "$", "string", ")", ";", "return", "\"<![CDATA[{$string}]]>\"", ";", "}", "else", "{", "return", "$", "string", ";", "}", "}" ]
Take a string, and wrap it in a CDATA secion, if that is required to make the output XML valid. @param string $string a string @return string the string, wrapped in CDATA if necessary.
[ "Take", "a", "string", "and", "wrap", "it", "in", "a", "CDATA", "secion", "if", "that", "is", "required", "to", "make", "the", "output", "XML", "valid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L1102-L1112
219,511
moodle/moodle
question/format/xml/format.php
qformat_xml.write_files
public function write_files($files) { if (empty($files)) { return ''; } $string = ''; foreach ($files as $file) { if ($file->is_directory()) { continue; } $string .= '<file name="' . $file->get_filename() . '" path="' . $file->get_filepath() . '" encoding="base64">'; $string .= base64_encode($file->get_content()); $string .= "</file>\n"; } return $string; }
php
public function write_files($files) { if (empty($files)) { return ''; } $string = ''; foreach ($files as $file) { if ($file->is_directory()) { continue; } $string .= '<file name="' . $file->get_filename() . '" path="' . $file->get_filepath() . '" encoding="base64">'; $string .= base64_encode($file->get_content()); $string .= "</file>\n"; } return $string; }
[ "public", "function", "write_files", "(", "$", "files", ")", "{", "if", "(", "empty", "(", "$", "files", ")", ")", "{", "return", "''", ";", "}", "$", "string", "=", "''", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "if", "(", "$", "file", "->", "is_directory", "(", ")", ")", "{", "continue", ";", "}", "$", "string", ".=", "'<file name=\"'", ".", "$", "file", "->", "get_filename", "(", ")", ".", "'\" path=\"'", ".", "$", "file", "->", "get_filepath", "(", ")", ".", "'\" encoding=\"base64\">'", ";", "$", "string", ".=", "base64_encode", "(", "$", "file", "->", "get_content", "(", ")", ")", ";", "$", "string", ".=", "\"</file>\\n\"", ";", "}", "return", "$", "string", ";", "}" ]
Generte the XML to represent some files. @param array of store array of stored_file objects. @return string $string the XML.
[ "Generte", "the", "XML", "to", "represent", "some", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L1139-L1153
219,512
moodle/moodle
question/format/xml/format.php
qformat_xml.write_hints
public function write_hints($question) { if (empty($question->hints)) { return ''; } $output = ''; foreach ($question->hints as $hint) { $output .= $this->write_hint($hint, $question->contextid); } return $output; }
php
public function write_hints($question) { if (empty($question->hints)) { return ''; } $output = ''; foreach ($question->hints as $hint) { $output .= $this->write_hint($hint, $question->contextid); } return $output; }
[ "public", "function", "write_hints", "(", "$", "question", ")", "{", "if", "(", "empty", "(", "$", "question", "->", "hints", ")", ")", "{", "return", "''", ";", "}", "$", "output", "=", "''", ";", "foreach", "(", "$", "question", "->", "hints", "as", "$", "hint", ")", "{", "$", "output", ".=", "$", "this", "->", "write_hint", "(", "$", "hint", ",", "$", "question", "->", "contextid", ")", ";", "}", "return", "$", "output", ";", "}" ]
Write out the hints. @param object $question the question definition data. @return string XML to output.
[ "Write", "out", "the", "hints", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L1570-L1580
219,513
moodle/moodle
question/format/xml/format.php
qformat_xml.write_combined_feedback
public function write_combined_feedback($questionoptions, $questionid, $contextid) { $fs = get_file_storage(); $output = ''; $fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'); foreach ($fields as $field) { $formatfield = $field . 'format'; $files = $fs->get_area_files($contextid, 'question', $field, $questionid); $output .= " <{$field} {$this->format($questionoptions->$formatfield)}>\n"; $output .= ' ' . $this->writetext($questionoptions->$field); $output .= $this->write_files($files); $output .= " </{$field}>\n"; } if (!empty($questionoptions->shownumcorrect)) { $output .= " <shownumcorrect/>\n"; } return $output; }
php
public function write_combined_feedback($questionoptions, $questionid, $contextid) { $fs = get_file_storage(); $output = ''; $fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'); foreach ($fields as $field) { $formatfield = $field . 'format'; $files = $fs->get_area_files($contextid, 'question', $field, $questionid); $output .= " <{$field} {$this->format($questionoptions->$formatfield)}>\n"; $output .= ' ' . $this->writetext($questionoptions->$field); $output .= $this->write_files($files); $output .= " </{$field}>\n"; } if (!empty($questionoptions->shownumcorrect)) { $output .= " <shownumcorrect/>\n"; } return $output; }
[ "public", "function", "write_combined_feedback", "(", "$", "questionoptions", ",", "$", "questionid", ",", "$", "contextid", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "output", "=", "''", ";", "$", "fields", "=", "array", "(", "'correctfeedback'", ",", "'partiallycorrectfeedback'", ",", "'incorrectfeedback'", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "$", "formatfield", "=", "$", "field", ".", "'format'", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "contextid", ",", "'question'", ",", "$", "field", ",", "$", "questionid", ")", ";", "$", "output", ".=", "\" <{$field} {$this->format($questionoptions->$formatfield)}>\\n\"", ";", "$", "output", ".=", "' '", ".", "$", "this", "->", "writetext", "(", "$", "questionoptions", "->", "$", "field", ")", ";", "$", "output", ".=", "$", "this", "->", "write_files", "(", "$", "files", ")", ";", "$", "output", ".=", "\" </{$field}>\\n\"", ";", "}", "if", "(", "!", "empty", "(", "$", "questionoptions", "->", "shownumcorrect", ")", ")", "{", "$", "output", ".=", "\" <shownumcorrect/>\\n\"", ";", "}", "return", "$", "output", ";", "}" ]
Output the combined feedback fields. @param object $questionoptions the question definition data. @param int $questionid the question id. @param int $contextid the question context id. @return string XML to output.
[ "Output", "the", "combined", "feedback", "fields", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L1620-L1639
219,514
moodle/moodle
enrol/manual/externallib.php
enrol_manual_external.enrol_users
public static function enrol_users($enrolments) { global $DB, $CFG; require_once($CFG->libdir . '/enrollib.php'); $params = self::validate_parameters(self::enrol_users_parameters(), array('enrolments' => $enrolments)); $transaction = $DB->start_delegated_transaction(); // Rollback all enrolment if an error occurs // (except if the DB doesn't support it). // Retrieve the manual enrolment plugin. $enrol = enrol_get_plugin('manual'); if (empty($enrol)) { throw new moodle_exception('manualpluginnotinstalled', 'enrol_manual'); } foreach ($params['enrolments'] as $enrolment) { // Ensure the current user is allowed to run this function in the enrolment context. $context = context_course::instance($enrolment['courseid'], IGNORE_MISSING); self::validate_context($context); // Check that the user has the permission to manual enrol. require_capability('enrol/manual:enrol', $context); // Throw an exception if user is not able to assign the role. $roles = get_assignable_roles($context); if (!array_key_exists($enrolment['roleid'], $roles)) { $errorparams = new stdClass(); $errorparams->roleid = $enrolment['roleid']; $errorparams->courseid = $enrolment['courseid']; $errorparams->userid = $enrolment['userid']; throw new moodle_exception('wsusercannotassign', 'enrol_manual', '', $errorparams); } // Check manual enrolment plugin instance is enabled/exist. $instance = null; $enrolinstances = enrol_get_instances($enrolment['courseid'], true); foreach ($enrolinstances as $courseenrolinstance) { if ($courseenrolinstance->enrol == "manual") { $instance = $courseenrolinstance; break; } } if (empty($instance)) { $errorparams = new stdClass(); $errorparams->courseid = $enrolment['courseid']; throw new moodle_exception('wsnoinstance', 'enrol_manual', $errorparams); } // Check that the plugin accept enrolment (it should always the case, it's hard coded in the plugin). if (!$enrol->allow_enrol($instance)) { $errorparams = new stdClass(); $errorparams->roleid = $enrolment['roleid']; $errorparams->courseid = $enrolment['courseid']; $errorparams->userid = $enrolment['userid']; throw new moodle_exception('wscannotenrol', 'enrol_manual', '', $errorparams); } // Finally proceed the enrolment. $enrolment['timestart'] = isset($enrolment['timestart']) ? $enrolment['timestart'] : 0; $enrolment['timeend'] = isset($enrolment['timeend']) ? $enrolment['timeend'] : 0; $enrolment['status'] = (isset($enrolment['suspend']) && !empty($enrolment['suspend'])) ? ENROL_USER_SUSPENDED : ENROL_USER_ACTIVE; $enrol->enrol_user($instance, $enrolment['userid'], $enrolment['roleid'], $enrolment['timestart'], $enrolment['timeend'], $enrolment['status']); } $transaction->allow_commit(); }
php
public static function enrol_users($enrolments) { global $DB, $CFG; require_once($CFG->libdir . '/enrollib.php'); $params = self::validate_parameters(self::enrol_users_parameters(), array('enrolments' => $enrolments)); $transaction = $DB->start_delegated_transaction(); // Rollback all enrolment if an error occurs // (except if the DB doesn't support it). // Retrieve the manual enrolment plugin. $enrol = enrol_get_plugin('manual'); if (empty($enrol)) { throw new moodle_exception('manualpluginnotinstalled', 'enrol_manual'); } foreach ($params['enrolments'] as $enrolment) { // Ensure the current user is allowed to run this function in the enrolment context. $context = context_course::instance($enrolment['courseid'], IGNORE_MISSING); self::validate_context($context); // Check that the user has the permission to manual enrol. require_capability('enrol/manual:enrol', $context); // Throw an exception if user is not able to assign the role. $roles = get_assignable_roles($context); if (!array_key_exists($enrolment['roleid'], $roles)) { $errorparams = new stdClass(); $errorparams->roleid = $enrolment['roleid']; $errorparams->courseid = $enrolment['courseid']; $errorparams->userid = $enrolment['userid']; throw new moodle_exception('wsusercannotassign', 'enrol_manual', '', $errorparams); } // Check manual enrolment plugin instance is enabled/exist. $instance = null; $enrolinstances = enrol_get_instances($enrolment['courseid'], true); foreach ($enrolinstances as $courseenrolinstance) { if ($courseenrolinstance->enrol == "manual") { $instance = $courseenrolinstance; break; } } if (empty($instance)) { $errorparams = new stdClass(); $errorparams->courseid = $enrolment['courseid']; throw new moodle_exception('wsnoinstance', 'enrol_manual', $errorparams); } // Check that the plugin accept enrolment (it should always the case, it's hard coded in the plugin). if (!$enrol->allow_enrol($instance)) { $errorparams = new stdClass(); $errorparams->roleid = $enrolment['roleid']; $errorparams->courseid = $enrolment['courseid']; $errorparams->userid = $enrolment['userid']; throw new moodle_exception('wscannotenrol', 'enrol_manual', '', $errorparams); } // Finally proceed the enrolment. $enrolment['timestart'] = isset($enrolment['timestart']) ? $enrolment['timestart'] : 0; $enrolment['timeend'] = isset($enrolment['timeend']) ? $enrolment['timeend'] : 0; $enrolment['status'] = (isset($enrolment['suspend']) && !empty($enrolment['suspend'])) ? ENROL_USER_SUSPENDED : ENROL_USER_ACTIVE; $enrol->enrol_user($instance, $enrolment['userid'], $enrolment['roleid'], $enrolment['timestart'], $enrolment['timeend'], $enrolment['status']); } $transaction->allow_commit(); }
[ "public", "static", "function", "enrol_users", "(", "$", "enrolments", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/enrollib.php'", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "enrol_users_parameters", "(", ")", ",", "array", "(", "'enrolments'", "=>", "$", "enrolments", ")", ")", ";", "$", "transaction", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "// Rollback all enrolment if an error occurs", "// (except if the DB doesn't support it).", "// Retrieve the manual enrolment plugin.", "$", "enrol", "=", "enrol_get_plugin", "(", "'manual'", ")", ";", "if", "(", "empty", "(", "$", "enrol", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'manualpluginnotinstalled'", ",", "'enrol_manual'", ")", ";", "}", "foreach", "(", "$", "params", "[", "'enrolments'", "]", "as", "$", "enrolment", ")", "{", "// Ensure the current user is allowed to run this function in the enrolment context.", "$", "context", "=", "context_course", "::", "instance", "(", "$", "enrolment", "[", "'courseid'", "]", ",", "IGNORE_MISSING", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "// Check that the user has the permission to manual enrol.", "require_capability", "(", "'enrol/manual:enrol'", ",", "$", "context", ")", ";", "// Throw an exception if user is not able to assign the role.", "$", "roles", "=", "get_assignable_roles", "(", "$", "context", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "enrolment", "[", "'roleid'", "]", ",", "$", "roles", ")", ")", "{", "$", "errorparams", "=", "new", "stdClass", "(", ")", ";", "$", "errorparams", "->", "roleid", "=", "$", "enrolment", "[", "'roleid'", "]", ";", "$", "errorparams", "->", "courseid", "=", "$", "enrolment", "[", "'courseid'", "]", ";", "$", "errorparams", "->", "userid", "=", "$", "enrolment", "[", "'userid'", "]", ";", "throw", "new", "moodle_exception", "(", "'wsusercannotassign'", ",", "'enrol_manual'", ",", "''", ",", "$", "errorparams", ")", ";", "}", "// Check manual enrolment plugin instance is enabled/exist.", "$", "instance", "=", "null", ";", "$", "enrolinstances", "=", "enrol_get_instances", "(", "$", "enrolment", "[", "'courseid'", "]", ",", "true", ")", ";", "foreach", "(", "$", "enrolinstances", "as", "$", "courseenrolinstance", ")", "{", "if", "(", "$", "courseenrolinstance", "->", "enrol", "==", "\"manual\"", ")", "{", "$", "instance", "=", "$", "courseenrolinstance", ";", "break", ";", "}", "}", "if", "(", "empty", "(", "$", "instance", ")", ")", "{", "$", "errorparams", "=", "new", "stdClass", "(", ")", ";", "$", "errorparams", "->", "courseid", "=", "$", "enrolment", "[", "'courseid'", "]", ";", "throw", "new", "moodle_exception", "(", "'wsnoinstance'", ",", "'enrol_manual'", ",", "$", "errorparams", ")", ";", "}", "// Check that the plugin accept enrolment (it should always the case, it's hard coded in the plugin).", "if", "(", "!", "$", "enrol", "->", "allow_enrol", "(", "$", "instance", ")", ")", "{", "$", "errorparams", "=", "new", "stdClass", "(", ")", ";", "$", "errorparams", "->", "roleid", "=", "$", "enrolment", "[", "'roleid'", "]", ";", "$", "errorparams", "->", "courseid", "=", "$", "enrolment", "[", "'courseid'", "]", ";", "$", "errorparams", "->", "userid", "=", "$", "enrolment", "[", "'userid'", "]", ";", "throw", "new", "moodle_exception", "(", "'wscannotenrol'", ",", "'enrol_manual'", ",", "''", ",", "$", "errorparams", ")", ";", "}", "// Finally proceed the enrolment.", "$", "enrolment", "[", "'timestart'", "]", "=", "isset", "(", "$", "enrolment", "[", "'timestart'", "]", ")", "?", "$", "enrolment", "[", "'timestart'", "]", ":", "0", ";", "$", "enrolment", "[", "'timeend'", "]", "=", "isset", "(", "$", "enrolment", "[", "'timeend'", "]", ")", "?", "$", "enrolment", "[", "'timeend'", "]", ":", "0", ";", "$", "enrolment", "[", "'status'", "]", "=", "(", "isset", "(", "$", "enrolment", "[", "'suspend'", "]", ")", "&&", "!", "empty", "(", "$", "enrolment", "[", "'suspend'", "]", ")", ")", "?", "ENROL_USER_SUSPENDED", ":", "ENROL_USER_ACTIVE", ";", "$", "enrol", "->", "enrol_user", "(", "$", "instance", ",", "$", "enrolment", "[", "'userid'", "]", ",", "$", "enrolment", "[", "'roleid'", "]", ",", "$", "enrolment", "[", "'timestart'", "]", ",", "$", "enrolment", "[", "'timeend'", "]", ",", "$", "enrolment", "[", "'status'", "]", ")", ";", "}", "$", "transaction", "->", "allow_commit", "(", ")", ";", "}" ]
Enrolment of users. Function throw an exception at the first error encountered. @param array $enrolments An array of user enrolment @since Moodle 2.2
[ "Enrolment", "of", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/manual/externallib.php#L76-L147
219,515
moodle/moodle
enrol/manual/externallib.php
enrol_manual_external.unenrol_users
public static function unenrol_users($enrolments) { global $CFG, $DB; $params = self::validate_parameters(self::unenrol_users_parameters(), array('enrolments' => $enrolments)); require_once($CFG->libdir . '/enrollib.php'); $transaction = $DB->start_delegated_transaction(); // Rollback all enrolment if an error occurs. $enrol = enrol_get_plugin('manual'); if (empty($enrol)) { throw new moodle_exception('manualpluginnotinstalled', 'enrol_manual'); } foreach ($params['enrolments'] as $enrolment) { $context = context_course::instance($enrolment['courseid']); self::validate_context($context); require_capability('enrol/manual:unenrol', $context); $instance = $DB->get_record('enrol', array('courseid' => $enrolment['courseid'], 'enrol' => 'manual')); if (!$instance) { throw new moodle_exception('wsnoinstance', 'enrol_manual', $enrolment); } $user = $DB->get_record('user', array('id' => $enrolment['userid'])); if (!$user) { throw new invalid_parameter_exception('User id not exist: '.$enrolment['userid']); } if (!$enrol->allow_unenrol($instance)) { throw new moodle_exception('wscannotunenrol', 'enrol_manual', '', $enrolment); } $enrol->unenrol_user($instance, $enrolment['userid']); } $transaction->allow_commit(); }
php
public static function unenrol_users($enrolments) { global $CFG, $DB; $params = self::validate_parameters(self::unenrol_users_parameters(), array('enrolments' => $enrolments)); require_once($CFG->libdir . '/enrollib.php'); $transaction = $DB->start_delegated_transaction(); // Rollback all enrolment if an error occurs. $enrol = enrol_get_plugin('manual'); if (empty($enrol)) { throw new moodle_exception('manualpluginnotinstalled', 'enrol_manual'); } foreach ($params['enrolments'] as $enrolment) { $context = context_course::instance($enrolment['courseid']); self::validate_context($context); require_capability('enrol/manual:unenrol', $context); $instance = $DB->get_record('enrol', array('courseid' => $enrolment['courseid'], 'enrol' => 'manual')); if (!$instance) { throw new moodle_exception('wsnoinstance', 'enrol_manual', $enrolment); } $user = $DB->get_record('user', array('id' => $enrolment['userid'])); if (!$user) { throw new invalid_parameter_exception('User id not exist: '.$enrolment['userid']); } if (!$enrol->allow_unenrol($instance)) { throw new moodle_exception('wscannotunenrol', 'enrol_manual', '', $enrolment); } $enrol->unenrol_user($instance, $enrolment['userid']); } $transaction->allow_commit(); }
[ "public", "static", "function", "unenrol_users", "(", "$", "enrolments", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "unenrol_users_parameters", "(", ")", ",", "array", "(", "'enrolments'", "=>", "$", "enrolments", ")", ")", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/enrollib.php'", ")", ";", "$", "transaction", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "// Rollback all enrolment if an error occurs.", "$", "enrol", "=", "enrol_get_plugin", "(", "'manual'", ")", ";", "if", "(", "empty", "(", "$", "enrol", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'manualpluginnotinstalled'", ",", "'enrol_manual'", ")", ";", "}", "foreach", "(", "$", "params", "[", "'enrolments'", "]", "as", "$", "enrolment", ")", "{", "$", "context", "=", "context_course", "::", "instance", "(", "$", "enrolment", "[", "'courseid'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "require_capability", "(", "'enrol/manual:unenrol'", ",", "$", "context", ")", ";", "$", "instance", "=", "$", "DB", "->", "get_record", "(", "'enrol'", ",", "array", "(", "'courseid'", "=>", "$", "enrolment", "[", "'courseid'", "]", ",", "'enrol'", "=>", "'manual'", ")", ")", ";", "if", "(", "!", "$", "instance", ")", "{", "throw", "new", "moodle_exception", "(", "'wsnoinstance'", ",", "'enrol_manual'", ",", "$", "enrolment", ")", ";", "}", "$", "user", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "enrolment", "[", "'userid'", "]", ")", ")", ";", "if", "(", "!", "$", "user", ")", "{", "throw", "new", "invalid_parameter_exception", "(", "'User id not exist: '", ".", "$", "enrolment", "[", "'userid'", "]", ")", ";", "}", "if", "(", "!", "$", "enrol", "->", "allow_unenrol", "(", "$", "instance", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'wscannotunenrol'", ",", "'enrol_manual'", ",", "''", ",", "$", "enrolment", ")", ";", "}", "$", "enrol", "->", "unenrol_user", "(", "$", "instance", ",", "$", "enrolment", "[", "'userid'", "]", ")", ";", "}", "$", "transaction", "->", "allow_commit", "(", ")", ";", "}" ]
Unenrolment of users. @param array $enrolments an array of course user and role ids @throws coding_exception @throws dml_transaction_exception @throws invalid_parameter_exception @throws moodle_exception @throws required_capability_exception @throws restricted_context_exception
[ "Unenrolment", "of", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/manual/externallib.php#L189-L217
219,516
moodle/moodle
admin/tool/uploaduser/user_form.php
admin_uploaduser_form2.definition_after_data
function definition_after_data() { $mform = $this->_form; $columns = $this->_customdata['columns']; foreach ($columns as $column) { if ($mform->elementExists($column)) { $mform->removeElement($column); } } if (!in_array('password', $columns)) { // password resetting makes sense only if password specified in csv file if ($mform->elementExists('uuforcepasswordchange')) { $mform->removeElement('uuforcepasswordchange'); } } }
php
function definition_after_data() { $mform = $this->_form; $columns = $this->_customdata['columns']; foreach ($columns as $column) { if ($mform->elementExists($column)) { $mform->removeElement($column); } } if (!in_array('password', $columns)) { // password resetting makes sense only if password specified in csv file if ($mform->elementExists('uuforcepasswordchange')) { $mform->removeElement('uuforcepasswordchange'); } } }
[ "function", "definition_after_data", "(", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "columns", "=", "$", "this", "->", "_customdata", "[", "'columns'", "]", ";", "foreach", "(", "$", "columns", "as", "$", "column", ")", "{", "if", "(", "$", "mform", "->", "elementExists", "(", "$", "column", ")", ")", "{", "$", "mform", "->", "removeElement", "(", "$", "column", ")", ";", "}", "}", "if", "(", "!", "in_array", "(", "'password'", ",", "$", "columns", ")", ")", "{", "// password resetting makes sense only if password specified in csv file", "if", "(", "$", "mform", "->", "elementExists", "(", "'uuforcepasswordchange'", ")", ")", "{", "$", "mform", "->", "removeElement", "(", "'uuforcepasswordchange'", ")", ";", "}", "}", "}" ]
Form tweaks that depend on current data.
[ "Form", "tweaks", "that", "depend", "on", "current", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/uploaduser/user_form.php#L329-L345
219,517
moodle/moodle
admin/tool/uploaduser/user_form.php
admin_uploaduser_form2.validation
function validation($data, $files) { $errors = parent::validation($data, $files); $columns = $this->_customdata['columns']; $optype = $data['uutype']; $updatetype = $data['uuupdatetype']; // detect if password column needed in file if (!in_array('password', $columns)) { switch ($optype) { case UU_USER_UPDATE: if (!empty($data['uupasswordold'])) { $errors['uupasswordold'] = get_string('missingfield', 'error', 'password'); } break; case UU_USER_ADD_UPDATE: if (empty($data['uupasswordnew'])) { $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password'); } if (!empty($data['uupasswordold'])) { $errors['uupasswordold'] = get_string('missingfield', 'error', 'password'); } break; case UU_USER_ADDNEW: if (empty($data['uupasswordnew'])) { $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password'); } break; case UU_USER_ADDINC: if (empty($data['uupasswordnew'])) { $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password'); } break; } } // If the 'Existing user details' value is set we need to ensure that the // 'Upload type' is not set to something invalid. if (!empty($updatetype) && ($optype == UU_USER_ADDNEW || $optype == UU_USER_ADDINC)) { $errors['uuupdatetype'] = get_string('invalidupdatetype', 'tool_uploaduser'); } // look for other required data if ($optype != UU_USER_UPDATE) { $requiredusernames = useredit_get_required_name_fields(); $missing = array(); foreach ($requiredusernames as $requiredusername) { if (!in_array($requiredusername, $columns)) { $missing[] = get_string('missingfield', 'error', $requiredusername);; } } if ($missing) { $errors['uutype'] = implode('<br />', $missing); } if (!in_array('email', $columns) and empty($data['email'])) { $errors['email'] = get_string('requiredtemplate', 'tool_uploaduser'); } } return $errors; }
php
function validation($data, $files) { $errors = parent::validation($data, $files); $columns = $this->_customdata['columns']; $optype = $data['uutype']; $updatetype = $data['uuupdatetype']; // detect if password column needed in file if (!in_array('password', $columns)) { switch ($optype) { case UU_USER_UPDATE: if (!empty($data['uupasswordold'])) { $errors['uupasswordold'] = get_string('missingfield', 'error', 'password'); } break; case UU_USER_ADD_UPDATE: if (empty($data['uupasswordnew'])) { $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password'); } if (!empty($data['uupasswordold'])) { $errors['uupasswordold'] = get_string('missingfield', 'error', 'password'); } break; case UU_USER_ADDNEW: if (empty($data['uupasswordnew'])) { $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password'); } break; case UU_USER_ADDINC: if (empty($data['uupasswordnew'])) { $errors['uupasswordnew'] = get_string('missingfield', 'error', 'password'); } break; } } // If the 'Existing user details' value is set we need to ensure that the // 'Upload type' is not set to something invalid. if (!empty($updatetype) && ($optype == UU_USER_ADDNEW || $optype == UU_USER_ADDINC)) { $errors['uuupdatetype'] = get_string('invalidupdatetype', 'tool_uploaduser'); } // look for other required data if ($optype != UU_USER_UPDATE) { $requiredusernames = useredit_get_required_name_fields(); $missing = array(); foreach ($requiredusernames as $requiredusername) { if (!in_array($requiredusername, $columns)) { $missing[] = get_string('missingfield', 'error', $requiredusername);; } } if ($missing) { $errors['uutype'] = implode('<br />', $missing); } if (!in_array('email', $columns) and empty($data['email'])) { $errors['email'] = get_string('requiredtemplate', 'tool_uploaduser'); } } return $errors; }
[ "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "$", "errors", "=", "parent", "::", "validation", "(", "$", "data", ",", "$", "files", ")", ";", "$", "columns", "=", "$", "this", "->", "_customdata", "[", "'columns'", "]", ";", "$", "optype", "=", "$", "data", "[", "'uutype'", "]", ";", "$", "updatetype", "=", "$", "data", "[", "'uuupdatetype'", "]", ";", "// detect if password column needed in file", "if", "(", "!", "in_array", "(", "'password'", ",", "$", "columns", ")", ")", "{", "switch", "(", "$", "optype", ")", "{", "case", "UU_USER_UPDATE", ":", "if", "(", "!", "empty", "(", "$", "data", "[", "'uupasswordold'", "]", ")", ")", "{", "$", "errors", "[", "'uupasswordold'", "]", "=", "get_string", "(", "'missingfield'", ",", "'error'", ",", "'password'", ")", ";", "}", "break", ";", "case", "UU_USER_ADD_UPDATE", ":", "if", "(", "empty", "(", "$", "data", "[", "'uupasswordnew'", "]", ")", ")", "{", "$", "errors", "[", "'uupasswordnew'", "]", "=", "get_string", "(", "'missingfield'", ",", "'error'", ",", "'password'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "[", "'uupasswordold'", "]", ")", ")", "{", "$", "errors", "[", "'uupasswordold'", "]", "=", "get_string", "(", "'missingfield'", ",", "'error'", ",", "'password'", ")", ";", "}", "break", ";", "case", "UU_USER_ADDNEW", ":", "if", "(", "empty", "(", "$", "data", "[", "'uupasswordnew'", "]", ")", ")", "{", "$", "errors", "[", "'uupasswordnew'", "]", "=", "get_string", "(", "'missingfield'", ",", "'error'", ",", "'password'", ")", ";", "}", "break", ";", "case", "UU_USER_ADDINC", ":", "if", "(", "empty", "(", "$", "data", "[", "'uupasswordnew'", "]", ")", ")", "{", "$", "errors", "[", "'uupasswordnew'", "]", "=", "get_string", "(", "'missingfield'", ",", "'error'", ",", "'password'", ")", ";", "}", "break", ";", "}", "}", "// If the 'Existing user details' value is set we need to ensure that the", "// 'Upload type' is not set to something invalid.", "if", "(", "!", "empty", "(", "$", "updatetype", ")", "&&", "(", "$", "optype", "==", "UU_USER_ADDNEW", "||", "$", "optype", "==", "UU_USER_ADDINC", ")", ")", "{", "$", "errors", "[", "'uuupdatetype'", "]", "=", "get_string", "(", "'invalidupdatetype'", ",", "'tool_uploaduser'", ")", ";", "}", "// look for other required data", "if", "(", "$", "optype", "!=", "UU_USER_UPDATE", ")", "{", "$", "requiredusernames", "=", "useredit_get_required_name_fields", "(", ")", ";", "$", "missing", "=", "array", "(", ")", ";", "foreach", "(", "$", "requiredusernames", "as", "$", "requiredusername", ")", "{", "if", "(", "!", "in_array", "(", "$", "requiredusername", ",", "$", "columns", ")", ")", "{", "$", "missing", "[", "]", "=", "get_string", "(", "'missingfield'", ",", "'error'", ",", "$", "requiredusername", ")", ";", ";", "}", "}", "if", "(", "$", "missing", ")", "{", "$", "errors", "[", "'uutype'", "]", "=", "implode", "(", "'<br />'", ",", "$", "missing", ")", ";", "}", "if", "(", "!", "in_array", "(", "'email'", ",", "$", "columns", ")", "and", "empty", "(", "$", "data", "[", "'email'", "]", ")", ")", "{", "$", "errors", "[", "'email'", "]", "=", "get_string", "(", "'requiredtemplate'", ",", "'tool_uploaduser'", ")", ";", "}", "}", "return", "$", "errors", ";", "}" ]
Server side validation.
[ "Server", "side", "validation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/uploaduser/user_form.php#L350-L410
219,518
moodle/moodle
admin/tool/uploaduser/user_form.php
admin_uploaduser_form2.get_data
function get_data() { $data = parent::get_data(); if ($data !== null and isset($data->description)) { $data->descriptionformat = $data->description['format']; $data->description = $data->description['text']; } return $data; }
php
function get_data() { $data = parent::get_data(); if ($data !== null and isset($data->description)) { $data->descriptionformat = $data->description['format']; $data->description = $data->description['text']; } return $data; }
[ "function", "get_data", "(", ")", "{", "$", "data", "=", "parent", "::", "get_data", "(", ")", ";", "if", "(", "$", "data", "!==", "null", "and", "isset", "(", "$", "data", "->", "description", ")", ")", "{", "$", "data", "->", "descriptionformat", "=", "$", "data", "->", "description", "[", "'format'", "]", ";", "$", "data", "->", "description", "=", "$", "data", "->", "description", "[", "'text'", "]", ";", "}", "return", "$", "data", ";", "}" ]
Used to reformat the data from the editor component @return stdClass
[ "Used", "to", "reformat", "the", "data", "from", "the", "editor", "component" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/uploaduser/user_form.php#L417-L426
219,519
moodle/moodle
lib/typo3/class.t3lib_utility_debug.php
t3lib_utility_Debug.prepareVariableForJavascript
public static function prepareVariableForJavascript($string, $asObject) { if ($asObject) { $string = str_replace(array( '"', '/', '<', "\n", "\r" ), array( '\"', '\/', '\<', '<br />', '' ), $string); } else { $string = str_replace(array( '"', '/', '<', "\n", "\r" ), array( '\"', '\/', '\<', '', '' ), $string); } return $string; }
php
public static function prepareVariableForJavascript($string, $asObject) { if ($asObject) { $string = str_replace(array( '"', '/', '<', "\n", "\r" ), array( '\"', '\/', '\<', '<br />', '' ), $string); } else { $string = str_replace(array( '"', '/', '<', "\n", "\r" ), array( '\"', '\/', '\<', '', '' ), $string); } return $string; }
[ "public", "static", "function", "prepareVariableForJavascript", "(", "$", "string", ",", "$", "asObject", ")", "{", "if", "(", "$", "asObject", ")", "{", "$", "string", "=", "str_replace", "(", "array", "(", "'\"'", ",", "'/'", ",", "'<'", ",", "\"\\n\"", ",", "\"\\r\"", ")", ",", "array", "(", "'\\\"'", ",", "'\\/'", ",", "'\\<'", ",", "'<br />'", ",", "''", ")", ",", "$", "string", ")", ";", "}", "else", "{", "$", "string", "=", "str_replace", "(", "array", "(", "'\"'", ",", "'/'", ",", "'<'", ",", "\"\\n\"", ",", "\"\\r\"", ")", ",", "array", "(", "'\\\"'", ",", "'\\/'", ",", "'\\<'", ",", "''", ",", "''", ")", ",", "$", "string", ")", ";", "}", "return", "$", "string", ";", "}" ]
Replaces special characters for the usage inside javascript @param string $string @param boolean $asObject @return string
[ "Replaces", "special", "characters", "for", "the", "usage", "inside", "javascript" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_utility_debug.php#L123-L139
219,520
moodle/moodle
lib/typo3/class.t3lib_utility_debug.php
t3lib_utility_Debug.convertVariableToString
public static function convertVariableToString($variable) { $string = ''; if (is_array($variable)) { $string = self::viewArray($variable); } elseif (is_object($variable)) { $string = '<strong>|Object:<pre>'; $string .= print_r($variable, TRUE); $string .= '</pre>|</strong>'; } elseif ((string) $variable !== '') { $string = '<strong>|' . htmlspecialchars((string) $variable) . '|</strong>'; } else { $string = '<strong>| debug |</strong>'; } return $string; }
php
public static function convertVariableToString($variable) { $string = ''; if (is_array($variable)) { $string = self::viewArray($variable); } elseif (is_object($variable)) { $string = '<strong>|Object:<pre>'; $string .= print_r($variable, TRUE); $string .= '</pre>|</strong>'; } elseif ((string) $variable !== '') { $string = '<strong>|' . htmlspecialchars((string) $variable) . '|</strong>'; } else { $string = '<strong>| debug |</strong>'; } return $string; }
[ "public", "static", "function", "convertVariableToString", "(", "$", "variable", ")", "{", "$", "string", "=", "''", ";", "if", "(", "is_array", "(", "$", "variable", ")", ")", "{", "$", "string", "=", "self", "::", "viewArray", "(", "$", "variable", ")", ";", "}", "elseif", "(", "is_object", "(", "$", "variable", ")", ")", "{", "$", "string", "=", "'<strong>|Object:<pre>'", ";", "$", "string", ".=", "print_r", "(", "$", "variable", ",", "TRUE", ")", ";", "$", "string", ".=", "'</pre>|</strong>'", ";", "}", "elseif", "(", "(", "string", ")", "$", "variable", "!==", "''", ")", "{", "$", "string", "=", "'<strong>|'", ".", "htmlspecialchars", "(", "(", "string", ")", "$", "variable", ")", ".", "'|</strong>'", ";", "}", "else", "{", "$", "string", "=", "'<strong>| debug |</strong>'", ";", "}", "return", "$", "string", ";", "}" ]
Converts a variable to a string @param mixed $variable @return string
[ "Converts", "a", "variable", "to", "a", "string" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_utility_debug.php#L147-L162
219,521
moodle/moodle
lib/typo3/class.t3lib_utility_debug.php
t3lib_utility_Debug.debugInPopUpWindow
public static function debugInPopUpWindow($debugVariable, $header = 'Debug', $group = 'Debug') { $debugString = self::prepareVariableForJavascript( self::convertVariableToString($debugVariable), is_object($debugVariable) ); $script = ' (function debug() { var debugMessage = "' . $debugString . '", header = "' . htmlspecialchars($header) . '", group = "' . htmlspecialchars($group) . '", browserWindow = function(debug, header, group) { var newWindow = window.open("", "TYPO3DebugWindow_" + group, "width=600,height=400,menubar=0,toolbar=1,status=0,scrollbars=1,resizable=1" ); if (newWindow.document.body.innerHTML) { newWindow.document.body.innerHTML = newWindow.document.body.innerHTML + "<hr />" + debugMessage; } else { newWindow.document.writeln( "<html><head><title>Debug: " + header + "(" + group + ")</title></head>" + "<body onload=\"self.focus()\">" + debugMessage + "</body></html>" ); } } if (!top.Ext) { browserWindow(debugMessage, header, group); } else { top.Ext.onReady(function() { if (top && top.TYPO3 && top.TYPO3.Backend) { top.TYPO3.Backend.DebugConsole.openBrowserWindow(header, debugMessage, group); } else { browserWindow(debugMessage, header, group); } }); } })(); '; echo t3lib_div::wrapJS($script); }
php
public static function debugInPopUpWindow($debugVariable, $header = 'Debug', $group = 'Debug') { $debugString = self::prepareVariableForJavascript( self::convertVariableToString($debugVariable), is_object($debugVariable) ); $script = ' (function debug() { var debugMessage = "' . $debugString . '", header = "' . htmlspecialchars($header) . '", group = "' . htmlspecialchars($group) . '", browserWindow = function(debug, header, group) { var newWindow = window.open("", "TYPO3DebugWindow_" + group, "width=600,height=400,menubar=0,toolbar=1,status=0,scrollbars=1,resizable=1" ); if (newWindow.document.body.innerHTML) { newWindow.document.body.innerHTML = newWindow.document.body.innerHTML + "<hr />" + debugMessage; } else { newWindow.document.writeln( "<html><head><title>Debug: " + header + "(" + group + ")</title></head>" + "<body onload=\"self.focus()\">" + debugMessage + "</body></html>" ); } } if (!top.Ext) { browserWindow(debugMessage, header, group); } else { top.Ext.onReady(function() { if (top && top.TYPO3 && top.TYPO3.Backend) { top.TYPO3.Backend.DebugConsole.openBrowserWindow(header, debugMessage, group); } else { browserWindow(debugMessage, header, group); } }); } })(); '; echo t3lib_div::wrapJS($script); }
[ "public", "static", "function", "debugInPopUpWindow", "(", "$", "debugVariable", ",", "$", "header", "=", "'Debug'", ",", "$", "group", "=", "'Debug'", ")", "{", "$", "debugString", "=", "self", "::", "prepareVariableForJavascript", "(", "self", "::", "convertVariableToString", "(", "$", "debugVariable", ")", ",", "is_object", "(", "$", "debugVariable", ")", ")", ";", "$", "script", "=", "'\n\t\t\t(function debug() {\n\t\t\t\tvar debugMessage = \"'", ".", "$", "debugString", ".", "'\",\n\t\t\t\t\theader = \"'", ".", "htmlspecialchars", "(", "$", "header", ")", ".", "'\",\n\t\t\t\t\tgroup = \"'", ".", "htmlspecialchars", "(", "$", "group", ")", ".", "'\",\n\n\t\t\t\t\tbrowserWindow = function(debug, header, group) {\n\t\t\t\t\t\tvar newWindow = window.open(\"\", \"TYPO3DebugWindow_\" + group,\n\t\t\t\t\t\t\t\"width=600,height=400,menubar=0,toolbar=1,status=0,scrollbars=1,resizable=1\"\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (newWindow.document.body.innerHTML) {\n\t\t\t\t\t\t\tnewWindow.document.body.innerHTML = newWindow.document.body.innerHTML +\n\t\t\t\t\t\t\t\t\"<hr />\" + debugMessage;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnewWindow.document.writeln(\n\t\t\t\t\t\t\t\t\"<html><head><title>Debug: \" + header + \"(\" + group + \")</title></head>\"\n\t\t\t\t\t\t\t\t+ \"<body onload=\\\"self.focus()\\\">\"\n\t\t\t\t\t\t\t\t+ debugMessage\n\t\t\t\t\t\t\t\t+ \"</body></html>\"\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\tif (!top.Ext) {\n\t\t\t\t\tbrowserWindow(debugMessage, header, group);\n\t\t\t\t} else {\n\t\t\t\t\ttop.Ext.onReady(function() {\n\t\t\t\t\t\tif (top && top.TYPO3 && top.TYPO3.Backend) {\n\t\t\t\t\t\t\ttop.TYPO3.Backend.DebugConsole.openBrowserWindow(header, debugMessage, group);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tbrowserWindow(debugMessage, header, group);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t})();\n\t\t'", ";", "echo", "t3lib_div", "::", "wrapJS", "(", "$", "script", ")", ";", "}" ]
Opens a debug message inside a popup window @param mixed $debugVariable @param string $header @param string $group
[ "Opens", "a", "debug", "message", "inside", "a", "popup", "window" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_utility_debug.php#L171-L214
219,522
moodle/moodle
lib/typo3/class.t3lib_utility_debug.php
t3lib_utility_Debug.debugTrail
public static function debugTrail() { $trail = debug_backtrace(); $trail = array_reverse($trail); array_pop($trail); $path = array(); foreach ($trail as $dat) { $pathFragment = $dat['class'] . $dat['type'] . $dat['function']; // add the path of the included file if (in_array($dat['function'], array('require', 'include', 'require_once', 'include_once'))) { $pathFragment .= '(' . substr($dat['args'][0], strlen(PATH_site)) . '),' . substr($dat['file'], strlen(PATH_site)); } $path[] = $pathFragment . '#' . $dat['line']; } return implode(' // ', $path); }
php
public static function debugTrail() { $trail = debug_backtrace(); $trail = array_reverse($trail); array_pop($trail); $path = array(); foreach ($trail as $dat) { $pathFragment = $dat['class'] . $dat['type'] . $dat['function']; // add the path of the included file if (in_array($dat['function'], array('require', 'include', 'require_once', 'include_once'))) { $pathFragment .= '(' . substr($dat['args'][0], strlen(PATH_site)) . '),' . substr($dat['file'], strlen(PATH_site)); } $path[] = $pathFragment . '#' . $dat['line']; } return implode(' // ', $path); }
[ "public", "static", "function", "debugTrail", "(", ")", "{", "$", "trail", "=", "debug_backtrace", "(", ")", ";", "$", "trail", "=", "array_reverse", "(", "$", "trail", ")", ";", "array_pop", "(", "$", "trail", ")", ";", "$", "path", "=", "array", "(", ")", ";", "foreach", "(", "$", "trail", "as", "$", "dat", ")", "{", "$", "pathFragment", "=", "$", "dat", "[", "'class'", "]", ".", "$", "dat", "[", "'type'", "]", ".", "$", "dat", "[", "'function'", "]", ";", "// add the path of the included file", "if", "(", "in_array", "(", "$", "dat", "[", "'function'", "]", ",", "array", "(", "'require'", ",", "'include'", ",", "'require_once'", ",", "'include_once'", ")", ")", ")", "{", "$", "pathFragment", ".=", "'('", ".", "substr", "(", "$", "dat", "[", "'args'", "]", "[", "0", "]", ",", "strlen", "(", "PATH_site", ")", ")", ".", "'),'", ".", "substr", "(", "$", "dat", "[", "'file'", "]", ",", "strlen", "(", "PATH_site", ")", ")", ";", "}", "$", "path", "[", "]", "=", "$", "pathFragment", ".", "'#'", ".", "$", "dat", "[", "'line'", "]", ";", "}", "return", "implode", "(", "' // '", ",", "$", "path", ")", ";", "}" ]
Displays the "path" of the function call stack in a string, using debug_backtrace @return string
[ "Displays", "the", "path", "of", "the", "function", "call", "stack", "in", "a", "string", "using", "debug_backtrace" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_utility_debug.php#L221-L237
219,523
moodle/moodle
lib/typo3/class.t3lib_utility_debug.php
t3lib_utility_Debug.debugRows
public static function debugRows($rows, $header = '', $returnHTML = FALSE) { if (is_array($rows)) { $firstEl = reset($rows); if (is_array($firstEl)) { $headerColumns = array_keys($firstEl); $tRows = array(); // Header: $tRows[] = '<tr><td colspan="' . count($headerColumns) . '" style="background-color:#bbbbbb; font-family: verdana,arial; font-weight: bold; font-size: 10px;"><strong>' . htmlspecialchars($header) . '</strong></td></tr>'; $tCells = array(); foreach ($headerColumns as $key) { $tCells[] = ' <td><font face="Verdana,Arial" size="1"><strong>' . htmlspecialchars($key) . '</strong></font></td>'; } $tRows[] = ' <tr>' . implode('', $tCells) . ' </tr>'; // Rows: foreach ($rows as $singleRow) { $tCells = array(); foreach ($headerColumns as $key) { $tCells[] = ' <td><font face="Verdana,Arial" size="1">' . (is_array($singleRow[$key]) ? self::debugRows($singleRow[$key], '', TRUE) : htmlspecialchars($singleRow[$key])) . '</font></td>'; } $tRows[] = ' <tr>' . implode('', $tCells) . ' </tr>'; } $table = ' <table border="1" cellpadding="1" cellspacing="0" bgcolor="white">' . implode('', $tRows) . ' </table>'; if ($returnHTML) { return $table; } else { echo $table; } } else { debug('Empty array of rows', $header); } } else { debug('No array of rows', $header); } }
php
public static function debugRows($rows, $header = '', $returnHTML = FALSE) { if (is_array($rows)) { $firstEl = reset($rows); if (is_array($firstEl)) { $headerColumns = array_keys($firstEl); $tRows = array(); // Header: $tRows[] = '<tr><td colspan="' . count($headerColumns) . '" style="background-color:#bbbbbb; font-family: verdana,arial; font-weight: bold; font-size: 10px;"><strong>' . htmlspecialchars($header) . '</strong></td></tr>'; $tCells = array(); foreach ($headerColumns as $key) { $tCells[] = ' <td><font face="Verdana,Arial" size="1"><strong>' . htmlspecialchars($key) . '</strong></font></td>'; } $tRows[] = ' <tr>' . implode('', $tCells) . ' </tr>'; // Rows: foreach ($rows as $singleRow) { $tCells = array(); foreach ($headerColumns as $key) { $tCells[] = ' <td><font face="Verdana,Arial" size="1">' . (is_array($singleRow[$key]) ? self::debugRows($singleRow[$key], '', TRUE) : htmlspecialchars($singleRow[$key])) . '</font></td>'; } $tRows[] = ' <tr>' . implode('', $tCells) . ' </tr>'; } $table = ' <table border="1" cellpadding="1" cellspacing="0" bgcolor="white">' . implode('', $tRows) . ' </table>'; if ($returnHTML) { return $table; } else { echo $table; } } else { debug('Empty array of rows', $header); } } else { debug('No array of rows', $header); } }
[ "public", "static", "function", "debugRows", "(", "$", "rows", ",", "$", "header", "=", "''", ",", "$", "returnHTML", "=", "FALSE", ")", "{", "if", "(", "is_array", "(", "$", "rows", ")", ")", "{", "$", "firstEl", "=", "reset", "(", "$", "rows", ")", ";", "if", "(", "is_array", "(", "$", "firstEl", ")", ")", "{", "$", "headerColumns", "=", "array_keys", "(", "$", "firstEl", ")", ";", "$", "tRows", "=", "array", "(", ")", ";", "// Header:", "$", "tRows", "[", "]", "=", "'<tr><td colspan=\"'", ".", "count", "(", "$", "headerColumns", ")", ".", "'\" style=\"background-color:#bbbbbb; font-family: verdana,arial; font-weight: bold; font-size: 10px;\"><strong>'", ".", "htmlspecialchars", "(", "$", "header", ")", ".", "'</strong></td></tr>'", ";", "$", "tCells", "=", "array", "(", ")", ";", "foreach", "(", "$", "headerColumns", "as", "$", "key", ")", "{", "$", "tCells", "[", "]", "=", "'\n\t\t\t\t\t\t\t<td><font face=\"Verdana,Arial\" size=\"1\"><strong>'", ".", "htmlspecialchars", "(", "$", "key", ")", ".", "'</strong></font></td>'", ";", "}", "$", "tRows", "[", "]", "=", "'\n\t\t\t\t\t\t<tr>'", ".", "implode", "(", "''", ",", "$", "tCells", ")", ".", "'\n\t\t\t\t\t\t</tr>'", ";", "// Rows:", "foreach", "(", "$", "rows", "as", "$", "singleRow", ")", "{", "$", "tCells", "=", "array", "(", ")", ";", "foreach", "(", "$", "headerColumns", "as", "$", "key", ")", "{", "$", "tCells", "[", "]", "=", "'\n\t\t\t\t\t\t\t<td><font face=\"Verdana,Arial\" size=\"1\">'", ".", "(", "is_array", "(", "$", "singleRow", "[", "$", "key", "]", ")", "?", "self", "::", "debugRows", "(", "$", "singleRow", "[", "$", "key", "]", ",", "''", ",", "TRUE", ")", ":", "htmlspecialchars", "(", "$", "singleRow", "[", "$", "key", "]", ")", ")", ".", "'</font></td>'", ";", "}", "$", "tRows", "[", "]", "=", "'\n\t\t\t\t\t\t<tr>'", ".", "implode", "(", "''", ",", "$", "tCells", ")", ".", "'\n\t\t\t\t\t\t</tr>'", ";", "}", "$", "table", "=", "'\n\t\t\t\t\t<table border=\"1\" cellpadding=\"1\" cellspacing=\"0\" bgcolor=\"white\">'", ".", "implode", "(", "''", ",", "$", "tRows", ")", ".", "'\n\t\t\t\t\t</table>'", ";", "if", "(", "$", "returnHTML", ")", "{", "return", "$", "table", ";", "}", "else", "{", "echo", "$", "table", ";", "}", "}", "else", "{", "debug", "(", "'Empty array of rows'", ",", "$", "header", ")", ";", "}", "}", "else", "{", "debug", "(", "'No array of rows'", ",", "$", "header", ")", ";", "}", "}" ]
Displays an array as rows in a table. Useful to debug output like an array of database records. @param mixed Array of arrays with similar keys @param string Table header @param boolean If TRUE, will return content instead of echo'ing out. @return void Outputs to browser.
[ "Displays", "an", "array", "as", "rows", "in", "a", "table", ".", "Useful", "to", "debug", "output", "like", "an", "array", "of", "database", "records", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_utility_debug.php#L247-L298
219,524
moodle/moodle
competency/classes/competency_framework.php
competency_framework.get_taxonomy
public function get_taxonomy($level) { $taxonomies = $this->get_taxonomies(); if (empty($taxonomies[$level])) { // If for some reason we cannot find the level, we fallback onto competency. $constant = self::TAXONOMY_COMPETENCY; } else { $constant = $taxonomies[$level]; } return $constant; }
php
public function get_taxonomy($level) { $taxonomies = $this->get_taxonomies(); if (empty($taxonomies[$level])) { // If for some reason we cannot find the level, we fallback onto competency. $constant = self::TAXONOMY_COMPETENCY; } else { $constant = $taxonomies[$level]; } return $constant; }
[ "public", "function", "get_taxonomy", "(", "$", "level", ")", "{", "$", "taxonomies", "=", "$", "this", "->", "get_taxonomies", "(", ")", ";", "if", "(", "empty", "(", "$", "taxonomies", "[", "$", "level", "]", ")", ")", "{", "// If for some reason we cannot find the level, we fallback onto competency.", "$", "constant", "=", "self", "::", "TAXONOMY_COMPETENCY", ";", "}", "else", "{", "$", "constant", "=", "$", "taxonomies", "[", "$", "level", "]", ";", "}", "return", "$", "constant", ";", "}" ]
Get the constant name for a level. @param int $level The level of the term. @return string
[ "Get", "the", "constant", "name", "for", "a", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/competency_framework.php#L163-L174
219,525
moodle/moodle
competency/classes/competency_framework.php
competency_framework.get_taxonomies
protected function get_taxonomies() { $taxonomies = explode(',', $this->raw_get('taxonomies')); // Indexing first level at 1. array_unshift($taxonomies, null); unset($taxonomies[0]); // Ensure that we do not return empty levels. foreach ($taxonomies as $i => $taxonomy) { if (empty($taxonomy)) { $taxonomies[$i] = self::TAXONOMY_COMPETENCY; } } return $taxonomies; }
php
protected function get_taxonomies() { $taxonomies = explode(',', $this->raw_get('taxonomies')); // Indexing first level at 1. array_unshift($taxonomies, null); unset($taxonomies[0]); // Ensure that we do not return empty levels. foreach ($taxonomies as $i => $taxonomy) { if (empty($taxonomy)) { $taxonomies[$i] = self::TAXONOMY_COMPETENCY; } } return $taxonomies; }
[ "protected", "function", "get_taxonomies", "(", ")", "{", "$", "taxonomies", "=", "explode", "(", "','", ",", "$", "this", "->", "raw_get", "(", "'taxonomies'", ")", ")", ";", "// Indexing first level at 1.", "array_unshift", "(", "$", "taxonomies", ",", "null", ")", ";", "unset", "(", "$", "taxonomies", "[", "0", "]", ")", ";", "// Ensure that we do not return empty levels.", "foreach", "(", "$", "taxonomies", "as", "$", "i", "=>", "$", "taxonomy", ")", "{", "if", "(", "empty", "(", "$", "taxonomy", ")", ")", "{", "$", "taxonomies", "[", "$", "i", "]", "=", "self", "::", "TAXONOMY_COMPETENCY", ";", "}", "}", "return", "$", "taxonomies", ";", "}" ]
Return the taxonomy constants indexed by level. @return array Contains the list of taxonomy constants indexed by level.
[ "Return", "the", "taxonomy", "constants", "indexed", "by", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/competency_framework.php#L181-L196
219,526
moodle/moodle
competency/classes/competency_framework.php
competency_framework.set_taxonomies
protected function set_taxonomies($taxonomies) { if (is_array($taxonomies)) { $taxonomies = implode(',', $taxonomies); } $this->raw_set('taxonomies', $taxonomies); }
php
protected function set_taxonomies($taxonomies) { if (is_array($taxonomies)) { $taxonomies = implode(',', $taxonomies); } $this->raw_set('taxonomies', $taxonomies); }
[ "protected", "function", "set_taxonomies", "(", "$", "taxonomies", ")", "{", "if", "(", "is_array", "(", "$", "taxonomies", ")", ")", "{", "$", "taxonomies", "=", "implode", "(", "','", ",", "$", "taxonomies", ")", ";", "}", "$", "this", "->", "raw_set", "(", "'taxonomies'", ",", "$", "taxonomies", ")", ";", "}" ]
Convenience method to set taxonomies from an array or string. @param string|array $taxonomies A string, or an array where the values are the term constants.
[ "Convenience", "method", "to", "set", "taxonomies", "from", "an", "array", "or", "string", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/competency_framework.php#L215-L220
219,527
moodle/moodle
competency/classes/competency_framework.php
competency_framework.validate_scaleid
protected function validate_scaleid($value) { global $DB; // Always validate that the scale exists. if (!$DB->record_exists_select('scale', 'id = :id', array('id' => $value))) { return new lang_string('invalidscaleid', 'error'); } // During update. if ($this->get('id')) { // Validate that we can only change the scale when it is not used yet. if ($this->beforeupdate->get('scaleid') != $value) { if ($this->beforeupdate->has_user_competencies()) { return new lang_string('errorscalealreadyused', 'core_competency'); } } } return true; }
php
protected function validate_scaleid($value) { global $DB; // Always validate that the scale exists. if (!$DB->record_exists_select('scale', 'id = :id', array('id' => $value))) { return new lang_string('invalidscaleid', 'error'); } // During update. if ($this->get('id')) { // Validate that we can only change the scale when it is not used yet. if ($this->beforeupdate->get('scaleid') != $value) { if ($this->beforeupdate->has_user_competencies()) { return new lang_string('errorscalealreadyused', 'core_competency'); } } } return true; }
[ "protected", "function", "validate_scaleid", "(", "$", "value", ")", "{", "global", "$", "DB", ";", "// Always validate that the scale exists.", "if", "(", "!", "$", "DB", "->", "record_exists_select", "(", "'scale'", ",", "'id = :id'", ",", "array", "(", "'id'", "=>", "$", "value", ")", ")", ")", "{", "return", "new", "lang_string", "(", "'invalidscaleid'", ",", "'error'", ")", ";", "}", "// During update.", "if", "(", "$", "this", "->", "get", "(", "'id'", ")", ")", "{", "// Validate that we can only change the scale when it is not used yet.", "if", "(", "$", "this", "->", "beforeupdate", "->", "get", "(", "'scaleid'", ")", "!=", "$", "value", ")", "{", "if", "(", "$", "this", "->", "beforeupdate", "->", "has_user_competencies", "(", ")", ")", "{", "return", "new", "lang_string", "(", "'errorscalealreadyused'", ",", "'core_competency'", ")", ";", "}", "}", "}", "return", "true", ";", "}" ]
Validate the scale ID. @param string $value The scale ID. @return bool|lang_string
[ "Validate", "the", "scale", "ID", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/competency_framework.php#L278-L299
219,528
moodle/moodle
competency/classes/competency_framework.php
competency_framework.validate_scaleconfiguration
protected function validate_scaleconfiguration($value) { $scaledefaultselected = false; $proficientselected = false; $scaleconfigurations = json_decode($value); if (is_array($scaleconfigurations)) { // The first element of the array contains the scale ID. $scaleinfo = array_shift($scaleconfigurations); if (empty($scaleinfo) || !isset($scaleinfo->scaleid) || $scaleinfo->scaleid != $this->get('scaleid')) { // This should never happen. return new lang_string('errorscaleconfiguration', 'core_competency'); } // Walk through the array to find proficient and default values. foreach ($scaleconfigurations as $scaleconfiguration) { if (isset($scaleconfiguration->scaledefault) && $scaleconfiguration->scaledefault) { $scaledefaultselected = true; } if (isset($scaleconfiguration->proficient) && $scaleconfiguration->proficient) { $proficientselected = true; } } } if (!$scaledefaultselected || !$proficientselected) { return new lang_string('errorscaleconfiguration', 'core_competency'); } return true; }
php
protected function validate_scaleconfiguration($value) { $scaledefaultselected = false; $proficientselected = false; $scaleconfigurations = json_decode($value); if (is_array($scaleconfigurations)) { // The first element of the array contains the scale ID. $scaleinfo = array_shift($scaleconfigurations); if (empty($scaleinfo) || !isset($scaleinfo->scaleid) || $scaleinfo->scaleid != $this->get('scaleid')) { // This should never happen. return new lang_string('errorscaleconfiguration', 'core_competency'); } // Walk through the array to find proficient and default values. foreach ($scaleconfigurations as $scaleconfiguration) { if (isset($scaleconfiguration->scaledefault) && $scaleconfiguration->scaledefault) { $scaledefaultselected = true; } if (isset($scaleconfiguration->proficient) && $scaleconfiguration->proficient) { $proficientselected = true; } } } if (!$scaledefaultselected || !$proficientselected) { return new lang_string('errorscaleconfiguration', 'core_competency'); } return true; }
[ "protected", "function", "validate_scaleconfiguration", "(", "$", "value", ")", "{", "$", "scaledefaultselected", "=", "false", ";", "$", "proficientselected", "=", "false", ";", "$", "scaleconfigurations", "=", "json_decode", "(", "$", "value", ")", ";", "if", "(", "is_array", "(", "$", "scaleconfigurations", ")", ")", "{", "// The first element of the array contains the scale ID.", "$", "scaleinfo", "=", "array_shift", "(", "$", "scaleconfigurations", ")", ";", "if", "(", "empty", "(", "$", "scaleinfo", ")", "||", "!", "isset", "(", "$", "scaleinfo", "->", "scaleid", ")", "||", "$", "scaleinfo", "->", "scaleid", "!=", "$", "this", "->", "get", "(", "'scaleid'", ")", ")", "{", "// This should never happen.", "return", "new", "lang_string", "(", "'errorscaleconfiguration'", ",", "'core_competency'", ")", ";", "}", "// Walk through the array to find proficient and default values.", "foreach", "(", "$", "scaleconfigurations", "as", "$", "scaleconfiguration", ")", "{", "if", "(", "isset", "(", "$", "scaleconfiguration", "->", "scaledefault", ")", "&&", "$", "scaleconfiguration", "->", "scaledefault", ")", "{", "$", "scaledefaultselected", "=", "true", ";", "}", "if", "(", "isset", "(", "$", "scaleconfiguration", "->", "proficient", ")", "&&", "$", "scaleconfiguration", "->", "proficient", ")", "{", "$", "proficientselected", "=", "true", ";", "}", "}", "}", "if", "(", "!", "$", "scaledefaultselected", "||", "!", "$", "proficientselected", ")", "{", "return", "new", "lang_string", "(", "'errorscaleconfiguration'", ",", "'core_competency'", ")", ";", "}", "return", "true", ";", "}" ]
Validate the scale configuration. @param string $value The scale configuration. @return bool|lang_string
[ "Validate", "the", "scale", "configuration", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/competency_framework.php#L307-L337
219,529
moodle/moodle
competency/classes/competency_framework.php
competency_framework.validate_taxonomies
protected function validate_taxonomies($value) { $terms = explode(',', $value); foreach ($terms as $term) { if (!empty($term) && !array_key_exists($term, self::get_taxonomies_list())) { return new lang_string('invalidtaxonomy', 'core_competency', $term); } } return true; }
php
protected function validate_taxonomies($value) { $terms = explode(',', $value); foreach ($terms as $term) { if (!empty($term) && !array_key_exists($term, self::get_taxonomies_list())) { return new lang_string('invalidtaxonomy', 'core_competency', $term); } } return true; }
[ "protected", "function", "validate_taxonomies", "(", "$", "value", ")", "{", "$", "terms", "=", "explode", "(", "','", ",", "$", "value", ")", ";", "foreach", "(", "$", "terms", "as", "$", "term", ")", "{", "if", "(", "!", "empty", "(", "$", "term", ")", "&&", "!", "array_key_exists", "(", "$", "term", ",", "self", "::", "get_taxonomies_list", "(", ")", ")", ")", "{", "return", "new", "lang_string", "(", "'invalidtaxonomy'", ",", "'core_competency'", ",", "$", "term", ")", ";", "}", "}", "return", "true", ";", "}" ]
Validate taxonomies. @param mixed $value The taxonomies. @return true|lang_string
[ "Validate", "taxonomies", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/competency_framework.php#L345-L355
219,530
moodle/moodle
competency/classes/competency_framework.php
competency_framework.get_default_grade_from_scale_configuration
public static function get_default_grade_from_scale_configuration($config) { $config = json_decode($config); if (!is_array($config)) { throw new coding_exception('Unexpected scale configuration.'); } // Remove the scale ID from the config. array_shift($config); foreach ($config as $part) { if ($part->scaledefault) { return array((int) $part->id, (int) $part->proficient); } } throw new coding_exception('Invalid scale configuration, default not found.'); }
php
public static function get_default_grade_from_scale_configuration($config) { $config = json_decode($config); if (!is_array($config)) { throw new coding_exception('Unexpected scale configuration.'); } // Remove the scale ID from the config. array_shift($config); foreach ($config as $part) { if ($part->scaledefault) { return array((int) $part->id, (int) $part->proficient); } } throw new coding_exception('Invalid scale configuration, default not found.'); }
[ "public", "static", "function", "get_default_grade_from_scale_configuration", "(", "$", "config", ")", "{", "$", "config", "=", "json_decode", "(", "$", "config", ")", ";", "if", "(", "!", "is_array", "(", "$", "config", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Unexpected scale configuration.'", ")", ";", "}", "// Remove the scale ID from the config.", "array_shift", "(", "$", "config", ")", ";", "foreach", "(", "$", "config", "as", "$", "part", ")", "{", "if", "(", "$", "part", "->", "scaledefault", ")", "{", "return", "array", "(", "(", "int", ")", "$", "part", "->", "id", ",", "(", "int", ")", "$", "part", "->", "proficient", ")", ";", "}", "}", "throw", "new", "coding_exception", "(", "'Invalid scale configuration, default not found.'", ")", ";", "}" ]
Extract the default grade from a scale configuration. Returns an array where the first element is the grade, and the second is a boolean representing whether or not this grade is considered 'proficient'. @param string $config JSON encoded config. @return array(int grade, int proficient)
[ "Extract", "the", "default", "grade", "from", "a", "scale", "configuration", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/competency_framework.php#L366-L382
219,531
moodle/moodle
competency/classes/competency_framework.php
competency_framework.get_proficiency_of_grade_from_scale_configuration
public static function get_proficiency_of_grade_from_scale_configuration($config, $grade) { $config = json_decode($config); if (!is_array($config)) { throw new coding_exception('Unexpected scale configuration.'); } // Remove the scale ID from the config. array_shift($config); foreach ($config as $part) { if ($part->id == $grade) { return (int) $part->proficient; } } return 0; }
php
public static function get_proficiency_of_grade_from_scale_configuration($config, $grade) { $config = json_decode($config); if (!is_array($config)) { throw new coding_exception('Unexpected scale configuration.'); } // Remove the scale ID from the config. array_shift($config); foreach ($config as $part) { if ($part->id == $grade) { return (int) $part->proficient; } } return 0; }
[ "public", "static", "function", "get_proficiency_of_grade_from_scale_configuration", "(", "$", "config", ",", "$", "grade", ")", "{", "$", "config", "=", "json_decode", "(", "$", "config", ")", ";", "if", "(", "!", "is_array", "(", "$", "config", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Unexpected scale configuration.'", ")", ";", "}", "// Remove the scale ID from the config.", "array_shift", "(", "$", "config", ")", ";", "foreach", "(", "$", "config", "as", "$", "part", ")", "{", "if", "(", "$", "part", "->", "id", "==", "$", "grade", ")", "{", "return", "(", "int", ")", "$", "part", "->", "proficient", ";", "}", "}", "return", "0", ";", "}" ]
Extract the proficiency of a grade from a scale configuration. @param string $config JSON encoded config. @param int $grade The grade. @return int Representing a boolean
[ "Extract", "the", "proficiency", "of", "a", "grade", "from", "a", "scale", "configuration", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/competency_framework.php#L391-L407
219,532
moodle/moodle
competency/classes/competency_framework.php
competency_framework.get_taxonomies_list
public static function get_taxonomies_list() { static $list = null; // At some point we'll have to switch to not using static cache, mainly for Unit Tests in case we // decide to allow more taxonomies to be added dynamically from a CFG variable for instance. if ($list === null) { $list = array( self::TAXONOMY_BEHAVIOUR => new lang_string('taxonomy_' . self::TAXONOMY_BEHAVIOUR, 'core_competency'), self::TAXONOMY_COMPETENCY => new lang_string('taxonomy_' . self::TAXONOMY_COMPETENCY, 'core_competency'), self::TAXONOMY_CONCEPT => new lang_string('taxonomy_' . self::TAXONOMY_CONCEPT, 'core_competency'), self::TAXONOMY_DOMAIN => new lang_string('taxonomy_' . self::TAXONOMY_DOMAIN, 'core_competency'), self::TAXONOMY_INDICATOR => new lang_string('taxonomy_' . self::TAXONOMY_INDICATOR, 'core_competency'), self::TAXONOMY_LEVEL => new lang_string('taxonomy_' . self::TAXONOMY_LEVEL, 'core_competency'), self::TAXONOMY_OUTCOME => new lang_string('taxonomy_' . self::TAXONOMY_OUTCOME, 'core_competency'), self::TAXONOMY_PRACTICE => new lang_string('taxonomy_' . self::TAXONOMY_PRACTICE, 'core_competency'), self::TAXONOMY_PROFICIENCY => new lang_string('taxonomy_' . self::TAXONOMY_PROFICIENCY, 'core_competency'), self::TAXONOMY_SKILL => new lang_string('taxonomy_' . self::TAXONOMY_SKILL, 'core_competency'), self::TAXONOMY_VALUE => new lang_string('taxonomy_' . self::TAXONOMY_VALUE, 'core_competency'), ); } return $list; }
php
public static function get_taxonomies_list() { static $list = null; // At some point we'll have to switch to not using static cache, mainly for Unit Tests in case we // decide to allow more taxonomies to be added dynamically from a CFG variable for instance. if ($list === null) { $list = array( self::TAXONOMY_BEHAVIOUR => new lang_string('taxonomy_' . self::TAXONOMY_BEHAVIOUR, 'core_competency'), self::TAXONOMY_COMPETENCY => new lang_string('taxonomy_' . self::TAXONOMY_COMPETENCY, 'core_competency'), self::TAXONOMY_CONCEPT => new lang_string('taxonomy_' . self::TAXONOMY_CONCEPT, 'core_competency'), self::TAXONOMY_DOMAIN => new lang_string('taxonomy_' . self::TAXONOMY_DOMAIN, 'core_competency'), self::TAXONOMY_INDICATOR => new lang_string('taxonomy_' . self::TAXONOMY_INDICATOR, 'core_competency'), self::TAXONOMY_LEVEL => new lang_string('taxonomy_' . self::TAXONOMY_LEVEL, 'core_competency'), self::TAXONOMY_OUTCOME => new lang_string('taxonomy_' . self::TAXONOMY_OUTCOME, 'core_competency'), self::TAXONOMY_PRACTICE => new lang_string('taxonomy_' . self::TAXONOMY_PRACTICE, 'core_competency'), self::TAXONOMY_PROFICIENCY => new lang_string('taxonomy_' . self::TAXONOMY_PROFICIENCY, 'core_competency'), self::TAXONOMY_SKILL => new lang_string('taxonomy_' . self::TAXONOMY_SKILL, 'core_competency'), self::TAXONOMY_VALUE => new lang_string('taxonomy_' . self::TAXONOMY_VALUE, 'core_competency'), ); } return $list; }
[ "public", "static", "function", "get_taxonomies_list", "(", ")", "{", "static", "$", "list", "=", "null", ";", "// At some point we'll have to switch to not using static cache, mainly for Unit Tests in case we", "// decide to allow more taxonomies to be added dynamically from a CFG variable for instance.", "if", "(", "$", "list", "===", "null", ")", "{", "$", "list", "=", "array", "(", "self", "::", "TAXONOMY_BEHAVIOUR", "=>", "new", "lang_string", "(", "'taxonomy_'", ".", "self", "::", "TAXONOMY_BEHAVIOUR", ",", "'core_competency'", ")", ",", "self", "::", "TAXONOMY_COMPETENCY", "=>", "new", "lang_string", "(", "'taxonomy_'", ".", "self", "::", "TAXONOMY_COMPETENCY", ",", "'core_competency'", ")", ",", "self", "::", "TAXONOMY_CONCEPT", "=>", "new", "lang_string", "(", "'taxonomy_'", ".", "self", "::", "TAXONOMY_CONCEPT", ",", "'core_competency'", ")", ",", "self", "::", "TAXONOMY_DOMAIN", "=>", "new", "lang_string", "(", "'taxonomy_'", ".", "self", "::", "TAXONOMY_DOMAIN", ",", "'core_competency'", ")", ",", "self", "::", "TAXONOMY_INDICATOR", "=>", "new", "lang_string", "(", "'taxonomy_'", ".", "self", "::", "TAXONOMY_INDICATOR", ",", "'core_competency'", ")", ",", "self", "::", "TAXONOMY_LEVEL", "=>", "new", "lang_string", "(", "'taxonomy_'", ".", "self", "::", "TAXONOMY_LEVEL", ",", "'core_competency'", ")", ",", "self", "::", "TAXONOMY_OUTCOME", "=>", "new", "lang_string", "(", "'taxonomy_'", ".", "self", "::", "TAXONOMY_OUTCOME", ",", "'core_competency'", ")", ",", "self", "::", "TAXONOMY_PRACTICE", "=>", "new", "lang_string", "(", "'taxonomy_'", ".", "self", "::", "TAXONOMY_PRACTICE", ",", "'core_competency'", ")", ",", "self", "::", "TAXONOMY_PROFICIENCY", "=>", "new", "lang_string", "(", "'taxonomy_'", ".", "self", "::", "TAXONOMY_PROFICIENCY", ",", "'core_competency'", ")", ",", "self", "::", "TAXONOMY_SKILL", "=>", "new", "lang_string", "(", "'taxonomy_'", ".", "self", "::", "TAXONOMY_SKILL", ",", "'core_competency'", ")", ",", "self", "::", "TAXONOMY_VALUE", "=>", "new", "lang_string", "(", "'taxonomy_'", ".", "self", "::", "TAXONOMY_VALUE", ",", "'core_competency'", ")", ",", ")", ";", "}", "return", "$", "list", ";", "}" ]
Get the list of all taxonomies. @return array Where the key is the taxonomy constant, and the value its translation.
[ "Get", "the", "list", "of", "all", "taxonomies", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/competency_framework.php#L424-L446
219,533
moodle/moodle
competency/classes/competency_framework.php
competency_framework.get_unused_idnumber
public static function get_unused_idnumber($idnumber) { global $DB; $currentidnumber = $idnumber; $counter = 0; // Iteratere while the idnumber exists. while ($DB->record_exists_select(static::TABLE, 'idnumber = ?', array($currentidnumber))) { $suffixidnumber = '_' . ++$counter; $currentidnumber = substr($idnumber, 0, 100 - strlen($suffixidnumber)).$suffixidnumber; } // Return the uniq idnumber. return $currentidnumber; }
php
public static function get_unused_idnumber($idnumber) { global $DB; $currentidnumber = $idnumber; $counter = 0; // Iteratere while the idnumber exists. while ($DB->record_exists_select(static::TABLE, 'idnumber = ?', array($currentidnumber))) { $suffixidnumber = '_' . ++$counter; $currentidnumber = substr($idnumber, 0, 100 - strlen($suffixidnumber)).$suffixidnumber; } // Return the uniq idnumber. return $currentidnumber; }
[ "public", "static", "function", "get_unused_idnumber", "(", "$", "idnumber", ")", "{", "global", "$", "DB", ";", "$", "currentidnumber", "=", "$", "idnumber", ";", "$", "counter", "=", "0", ";", "// Iteratere while the idnumber exists.", "while", "(", "$", "DB", "->", "record_exists_select", "(", "static", "::", "TABLE", ",", "'idnumber = ?'", ",", "array", "(", "$", "currentidnumber", ")", ")", ")", "{", "$", "suffixidnumber", "=", "'_'", ".", "++", "$", "counter", ";", "$", "currentidnumber", "=", "substr", "(", "$", "idnumber", ",", "0", ",", "100", "-", "strlen", "(", "$", "suffixidnumber", ")", ")", ".", "$", "suffixidnumber", ";", "}", "// Return the uniq idnumber.", "return", "$", "currentidnumber", ";", "}" ]
Get a uniq idnumber. @param string $idnumber the framework idnumber @return string
[ "Get", "a", "uniq", "idnumber", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/competency_framework.php#L454-L467
219,534
moodle/moodle
report/stats/classes/privacy/provider.php
provider.delete_stats
protected static function delete_stats(int $courseid, int $userid = null) { global $DB; $params = (isset($userid)) ? ['courseid' => $courseid, 'userid' => $userid] : ['courseid' => $courseid]; $DB->delete_records('stats_user_daily', $params); $DB->delete_records('stats_user_weekly', $params); $DB->delete_records('stats_user_monthly', $params); }
php
protected static function delete_stats(int $courseid, int $userid = null) { global $DB; $params = (isset($userid)) ? ['courseid' => $courseid, 'userid' => $userid] : ['courseid' => $courseid]; $DB->delete_records('stats_user_daily', $params); $DB->delete_records('stats_user_weekly', $params); $DB->delete_records('stats_user_monthly', $params); }
[ "protected", "static", "function", "delete_stats", "(", "int", "$", "courseid", ",", "int", "$", "userid", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "(", "isset", "(", "$", "userid", ")", ")", "?", "[", "'courseid'", "=>", "$", "courseid", ",", "'userid'", "=>", "$", "userid", "]", ":", "[", "'courseid'", "=>", "$", "courseid", "]", ";", "$", "DB", "->", "delete_records", "(", "'stats_user_daily'", ",", "$", "params", ")", ";", "$", "DB", "->", "delete_records", "(", "'stats_user_weekly'", ",", "$", "params", ")", ";", "$", "DB", "->", "delete_records", "(", "'stats_user_monthly'", ",", "$", "params", ")", ";", "}" ]
Deletes stats for a given course. @param int $courseid The course ID to delete the stats for. @param int $userid Optionally a user id to delete records with.
[ "Deletes", "stats", "for", "a", "given", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/stats/classes/privacy/provider.php#L263-L269
219,535
moodle/moodle
question/type/multichoice/renderer.php
qtype_multichoice_renderer_base.correct_choices
protected function correct_choices(array $right) { // Return appropriate string for single/multiple correct answer(s). if (count($right) == 1) { return get_string('correctansweris', 'qtype_multichoice', implode(', ', $right)); } else if (count($right) > 1) { return get_string('correctanswersare', 'qtype_multichoice', implode(', ', $right)); } else { return ""; } }
php
protected function correct_choices(array $right) { // Return appropriate string for single/multiple correct answer(s). if (count($right) == 1) { return get_string('correctansweris', 'qtype_multichoice', implode(', ', $right)); } else if (count($right) > 1) { return get_string('correctanswersare', 'qtype_multichoice', implode(', ', $right)); } else { return ""; } }
[ "protected", "function", "correct_choices", "(", "array", "$", "right", ")", "{", "// Return appropriate string for single/multiple correct answer(s).", "if", "(", "count", "(", "$", "right", ")", "==", "1", ")", "{", "return", "get_string", "(", "'correctansweris'", ",", "'qtype_multichoice'", ",", "implode", "(", "', '", ",", "$", "right", ")", ")", ";", "}", "else", "if", "(", "count", "(", "$", "right", ")", ">", "1", ")", "{", "return", "get_string", "(", "'correctanswersare'", ",", "'qtype_multichoice'", ",", "implode", "(", "', '", ",", "$", "right", ")", ")", ";", "}", "else", "{", "return", "\"\"", ";", "}", "}" ]
Function returns string based on number of correct answers @param array $right An Array of correct responses to the current question @return string based on number of correct responses
[ "Function", "returns", "string", "based", "on", "number", "of", "correct", "answers" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/multichoice/renderer.php#L207-L218
219,536
moodle/moodle
search/classes/document.php
document.add_stored_file
public function add_stored_file($file) { if (is_numeric($file)) { $this->files[$file] = $file; } else { $this->files[$file->get_id()] = $file; } }
php
public function add_stored_file($file) { if (is_numeric($file)) { $this->files[$file] = $file; } else { $this->files[$file->get_id()] = $file; } }
[ "public", "function", "add_stored_file", "(", "$", "file", ")", "{", "if", "(", "is_numeric", "(", "$", "file", ")", ")", "{", "$", "this", "->", "files", "[", "$", "file", "]", "=", "$", "file", ";", "}", "else", "{", "$", "this", "->", "files", "[", "$", "file", "->", "get_id", "(", ")", "]", "=", "$", "file", ";", "}", "}" ]
Add a stored file to the document. @param \stored_file|int $file The file to add, or file id. @return void
[ "Add", "a", "stored", "file", "to", "the", "document", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/document.php#L231-L237
219,537
moodle/moodle
search/classes/document.php
document.get_files
public function get_files() { // The files array can contain stored file ids, so we need to get instances if asked. foreach ($this->files as $id => $listfile) { if (is_numeric($listfile)) { $fs = get_file_storage(); if ($file = $fs->get_file_by_id($id)) { $this->files[$id] = $file; } else { unset($this->files[$id]); // Index is out of date and referencing a file that does not exist. } } } return $this->files; }
php
public function get_files() { // The files array can contain stored file ids, so we need to get instances if asked. foreach ($this->files as $id => $listfile) { if (is_numeric($listfile)) { $fs = get_file_storage(); if ($file = $fs->get_file_by_id($id)) { $this->files[$id] = $file; } else { unset($this->files[$id]); // Index is out of date and referencing a file that does not exist. } } } return $this->files; }
[ "public", "function", "get_files", "(", ")", "{", "// The files array can contain stored file ids, so we need to get instances if asked.", "foreach", "(", "$", "this", "->", "files", "as", "$", "id", "=>", "$", "listfile", ")", "{", "if", "(", "is_numeric", "(", "$", "listfile", ")", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "if", "(", "$", "file", "=", "$", "fs", "->", "get_file_by_id", "(", "$", "id", ")", ")", "{", "$", "this", "->", "files", "[", "$", "id", "]", "=", "$", "file", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "files", "[", "$", "id", "]", ")", ";", "// Index is out of date and referencing a file that does not exist.", "}", "}", "}", "return", "$", "this", "->", "files", ";", "}" ]
Returns the array of attached files. @return \stored_file[]
[ "Returns", "the", "array", "of", "attached", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/document.php#L244-L259
219,538
moodle/moodle
search/classes/document.php
document.is_set
public function is_set($field) { return (isset($this->data[$field]) || isset($this->extradata[$field])); }
php
public function is_set($field) { return (isset($this->data[$field]) || isset($this->extradata[$field])); }
[ "public", "function", "is_set", "(", "$", "field", ")", "{", "return", "(", "isset", "(", "$", "this", "->", "data", "[", "$", "field", "]", ")", "||", "isset", "(", "$", "this", "->", "extradata", "[", "$", "field", "]", ")", ")", ";", "}" ]
Checks if a field is set. @param string $field @return bool
[ "Checks", "if", "a", "field", "is", "set", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/document.php#L362-L364
219,539
moodle/moodle
search/classes/document.php
document.set_data_from_engine
public function set_data_from_engine($docdata) { $fields = static::$requiredfields + static::$optionalfields + static::$enginefields; foreach ($fields as $fieldname => $field) { // Optional params might not be there. if (isset($docdata[$fieldname])) { if ($field['type'] === 'tdate') { // Time fields may need a preprocessing. $this->set($fieldname, static::import_time_from_engine($docdata[$fieldname])); } else { // No way we can make this work if there is any multivalue field. if (is_array($docdata[$fieldname])) { throw new \core_search\engine_exception('multivaluedfield', 'search_solr', '', $fieldname); } $this->set($fieldname, $docdata[$fieldname]); } } } }
php
public function set_data_from_engine($docdata) { $fields = static::$requiredfields + static::$optionalfields + static::$enginefields; foreach ($fields as $fieldname => $field) { // Optional params might not be there. if (isset($docdata[$fieldname])) { if ($field['type'] === 'tdate') { // Time fields may need a preprocessing. $this->set($fieldname, static::import_time_from_engine($docdata[$fieldname])); } else { // No way we can make this work if there is any multivalue field. if (is_array($docdata[$fieldname])) { throw new \core_search\engine_exception('multivaluedfield', 'search_solr', '', $fieldname); } $this->set($fieldname, $docdata[$fieldname]); } } } }
[ "public", "function", "set_data_from_engine", "(", "$", "docdata", ")", "{", "$", "fields", "=", "static", "::", "$", "requiredfields", "+", "static", "::", "$", "optionalfields", "+", "static", "::", "$", "enginefields", ";", "foreach", "(", "$", "fields", "as", "$", "fieldname", "=>", "$", "field", ")", "{", "// Optional params might not be there.", "if", "(", "isset", "(", "$", "docdata", "[", "$", "fieldname", "]", ")", ")", "{", "if", "(", "$", "field", "[", "'type'", "]", "===", "'tdate'", ")", "{", "// Time fields may need a preprocessing.", "$", "this", "->", "set", "(", "$", "fieldname", ",", "static", "::", "import_time_from_engine", "(", "$", "docdata", "[", "$", "fieldname", "]", ")", ")", ";", "}", "else", "{", "// No way we can make this work if there is any multivalue field.", "if", "(", "is_array", "(", "$", "docdata", "[", "$", "fieldname", "]", ")", ")", "{", "throw", "new", "\\", "core_search", "\\", "engine_exception", "(", "'multivaluedfield'", ",", "'search_solr'", ",", "''", ",", "$", "fieldname", ")", ";", "}", "$", "this", "->", "set", "(", "$", "fieldname", ",", "$", "docdata", "[", "$", "fieldname", "]", ")", ";", "}", "}", "}", "}" ]
Fills the document with data coming from the search engine. @throws \core_search\engine_exception @param array $docdata @return void
[ "Fills", "the", "document", "with", "data", "coming", "from", "the", "search", "engine", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/document.php#L465-L483
219,540
moodle/moodle
search/classes/document.php
document.export_for_engine
public function export_for_engine() { // Set any unset defaults. $this->apply_defaults(); // We don't want to affect the document instance. $data = $this->data; // Apply specific engine-dependant formats and restrictions. foreach (static::$requiredfields as $fieldname => $field) { // We also check that we have everything we need. if (!isset($data[$fieldname])) { throw new \coding_exception('Missing "' . $fieldname . '" field in document with id "' . $this->data['id'] . '"'); } if ($field['type'] === 'tdate') { // Overwrite the timestamp with the engine dependant format. $data[$fieldname] = static::format_time_for_engine($data[$fieldname]); } else if ($field['type'] === 'string') { // Overwrite the string with the engine dependant format. $data[$fieldname] = static::format_string_for_engine($data[$fieldname]); } else if ($field['type'] === 'text') { // Overwrite the text with the engine dependant format. $data[$fieldname] = static::format_text_for_engine($data[$fieldname]); } } $fields = static::$optionalfields + static::$enginefields; foreach ($fields as $fieldname => $field) { if (!isset($data[$fieldname])) { continue; } if ($field['type'] === 'tdate') { // Overwrite the timestamp with the engine dependant format. $data[$fieldname] = static::format_time_for_engine($data[$fieldname]); } else if ($field['type'] === 'string') { // Overwrite the string with the engine dependant format. $data[$fieldname] = static::format_string_for_engine($data[$fieldname]); } else if ($field['type'] === 'text') { // Overwrite the text with the engine dependant format. $data[$fieldname] = static::format_text_for_engine($data[$fieldname]); } } return $data; }
php
public function export_for_engine() { // Set any unset defaults. $this->apply_defaults(); // We don't want to affect the document instance. $data = $this->data; // Apply specific engine-dependant formats and restrictions. foreach (static::$requiredfields as $fieldname => $field) { // We also check that we have everything we need. if (!isset($data[$fieldname])) { throw new \coding_exception('Missing "' . $fieldname . '" field in document with id "' . $this->data['id'] . '"'); } if ($field['type'] === 'tdate') { // Overwrite the timestamp with the engine dependant format. $data[$fieldname] = static::format_time_for_engine($data[$fieldname]); } else if ($field['type'] === 'string') { // Overwrite the string with the engine dependant format. $data[$fieldname] = static::format_string_for_engine($data[$fieldname]); } else if ($field['type'] === 'text') { // Overwrite the text with the engine dependant format. $data[$fieldname] = static::format_text_for_engine($data[$fieldname]); } } $fields = static::$optionalfields + static::$enginefields; foreach ($fields as $fieldname => $field) { if (!isset($data[$fieldname])) { continue; } if ($field['type'] === 'tdate') { // Overwrite the timestamp with the engine dependant format. $data[$fieldname] = static::format_time_for_engine($data[$fieldname]); } else if ($field['type'] === 'string') { // Overwrite the string with the engine dependant format. $data[$fieldname] = static::format_string_for_engine($data[$fieldname]); } else if ($field['type'] === 'text') { // Overwrite the text with the engine dependant format. $data[$fieldname] = static::format_text_for_engine($data[$fieldname]); } } return $data; }
[ "public", "function", "export_for_engine", "(", ")", "{", "// Set any unset defaults.", "$", "this", "->", "apply_defaults", "(", ")", ";", "// We don't want to affect the document instance.", "$", "data", "=", "$", "this", "->", "data", ";", "// Apply specific engine-dependant formats and restrictions.", "foreach", "(", "static", "::", "$", "requiredfields", "as", "$", "fieldname", "=>", "$", "field", ")", "{", "// We also check that we have everything we need.", "if", "(", "!", "isset", "(", "$", "data", "[", "$", "fieldname", "]", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Missing \"'", ".", "$", "fieldname", ".", "'\" field in document with id \"'", ".", "$", "this", "->", "data", "[", "'id'", "]", ".", "'\"'", ")", ";", "}", "if", "(", "$", "field", "[", "'type'", "]", "===", "'tdate'", ")", "{", "// Overwrite the timestamp with the engine dependant format.", "$", "data", "[", "$", "fieldname", "]", "=", "static", "::", "format_time_for_engine", "(", "$", "data", "[", "$", "fieldname", "]", ")", ";", "}", "else", "if", "(", "$", "field", "[", "'type'", "]", "===", "'string'", ")", "{", "// Overwrite the string with the engine dependant format.", "$", "data", "[", "$", "fieldname", "]", "=", "static", "::", "format_string_for_engine", "(", "$", "data", "[", "$", "fieldname", "]", ")", ";", "}", "else", "if", "(", "$", "field", "[", "'type'", "]", "===", "'text'", ")", "{", "// Overwrite the text with the engine dependant format.", "$", "data", "[", "$", "fieldname", "]", "=", "static", "::", "format_text_for_engine", "(", "$", "data", "[", "$", "fieldname", "]", ")", ";", "}", "}", "$", "fields", "=", "static", "::", "$", "optionalfields", "+", "static", "::", "$", "enginefields", ";", "foreach", "(", "$", "fields", "as", "$", "fieldname", "=>", "$", "field", ")", "{", "if", "(", "!", "isset", "(", "$", "data", "[", "$", "fieldname", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "field", "[", "'type'", "]", "===", "'tdate'", ")", "{", "// Overwrite the timestamp with the engine dependant format.", "$", "data", "[", "$", "fieldname", "]", "=", "static", "::", "format_time_for_engine", "(", "$", "data", "[", "$", "fieldname", "]", ")", ";", "}", "else", "if", "(", "$", "field", "[", "'type'", "]", "===", "'string'", ")", "{", "// Overwrite the string with the engine dependant format.", "$", "data", "[", "$", "fieldname", "]", "=", "static", "::", "format_string_for_engine", "(", "$", "data", "[", "$", "fieldname", "]", ")", ";", "}", "else", "if", "(", "$", "field", "[", "'type'", "]", "===", "'text'", ")", "{", "// Overwrite the text with the engine dependant format.", "$", "data", "[", "$", "fieldname", "]", "=", "static", "::", "format_text_for_engine", "(", "$", "data", "[", "$", "fieldname", "]", ")", ";", "}", "}", "return", "$", "data", ";", "}" ]
Returns the document ready to submit to the search engine. @throws \coding_exception @return array
[ "Returns", "the", "document", "ready", "to", "submit", "to", "the", "search", "engine", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/document.php#L541-L587
219,541
moodle/moodle
customfield/field/date/classes/field_controller.php
field_controller.config_form_validation
public function config_form_validation(array $data, $files = array()) : array { $errors = array(); // Make sure the start year is not greater than the end year. if (!empty($data['configdata']['mindate']) && !empty($data['configdata']['maxdate']) && $data['configdata']['mindate'] > $data['configdata']['maxdate']) { $errors['configdata[mindate]'] = get_string('mindateaftermax', 'customfield_date'); } return $errors; }
php
public function config_form_validation(array $data, $files = array()) : array { $errors = array(); // Make sure the start year is not greater than the end year. if (!empty($data['configdata']['mindate']) && !empty($data['configdata']['maxdate']) && $data['configdata']['mindate'] > $data['configdata']['maxdate']) { $errors['configdata[mindate]'] = get_string('mindateaftermax', 'customfield_date'); } return $errors; }
[ "public", "function", "config_form_validation", "(", "array", "$", "data", ",", "$", "files", "=", "array", "(", ")", ")", ":", "array", "{", "$", "errors", "=", "array", "(", ")", ";", "// Make sure the start year is not greater than the end year.", "if", "(", "!", "empty", "(", "$", "data", "[", "'configdata'", "]", "[", "'mindate'", "]", ")", "&&", "!", "empty", "(", "$", "data", "[", "'configdata'", "]", "[", "'maxdate'", "]", ")", "&&", "$", "data", "[", "'configdata'", "]", "[", "'mindate'", "]", ">", "$", "data", "[", "'configdata'", "]", "[", "'maxdate'", "]", ")", "{", "$", "errors", "[", "'configdata[mindate]'", "]", "=", "get_string", "(", "'mindateaftermax'", ",", "'customfield_date'", ")", ";", "}", "return", "$", "errors", ";", "}" ]
Validate the data from the config form. @param array $data @param array $files @return array associative array of error messages
[ "Validate", "the", "data", "from", "the", "config", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/field/date/classes/field_controller.php#L49-L59
219,542
moodle/moodle
customfield/field/date/classes/field_controller.php
field_controller.config_form_definition
public function config_form_definition(\MoodleQuickForm $mform) { $config = $this->get('configdata'); // Add elements. $mform->addElement('header', 'header_specificsettings', get_string('specificsettings', 'customfield_date')); $mform->setExpanded('header_specificsettings', true); $mform->addElement('advcheckbox', 'configdata[includetime]', get_string('includetime', 'customfield_date')); $mform->addElement('date_time_selector', 'configdata[mindate]', get_string('mindate', 'customfield_date'), ['optional' => true]); $mform->addElement('date_time_selector', 'configdata[maxdate]', get_string('maxdate', 'customfield_date'), ['optional' => true]); $mform->hideIf('configdata[maxdate][hour]', 'configdata[includetime]'); $mform->hideIf('configdata[maxdate][minute]', 'configdata[includetime]'); $mform->hideIf('configdata[mindate][hour]', 'configdata[includetime]'); $mform->hideIf('configdata[mindate][minute]', 'configdata[includetime]'); }
php
public function config_form_definition(\MoodleQuickForm $mform) { $config = $this->get('configdata'); // Add elements. $mform->addElement('header', 'header_specificsettings', get_string('specificsettings', 'customfield_date')); $mform->setExpanded('header_specificsettings', true); $mform->addElement('advcheckbox', 'configdata[includetime]', get_string('includetime', 'customfield_date')); $mform->addElement('date_time_selector', 'configdata[mindate]', get_string('mindate', 'customfield_date'), ['optional' => true]); $mform->addElement('date_time_selector', 'configdata[maxdate]', get_string('maxdate', 'customfield_date'), ['optional' => true]); $mform->hideIf('configdata[maxdate][hour]', 'configdata[includetime]'); $mform->hideIf('configdata[maxdate][minute]', 'configdata[includetime]'); $mform->hideIf('configdata[mindate][hour]', 'configdata[includetime]'); $mform->hideIf('configdata[mindate][minute]', 'configdata[includetime]'); }
[ "public", "function", "config_form_definition", "(", "\\", "MoodleQuickForm", "$", "mform", ")", "{", "$", "config", "=", "$", "this", "->", "get", "(", "'configdata'", ")", ";", "// Add elements.", "$", "mform", "->", "addElement", "(", "'header'", ",", "'header_specificsettings'", ",", "get_string", "(", "'specificsettings'", ",", "'customfield_date'", ")", ")", ";", "$", "mform", "->", "setExpanded", "(", "'header_specificsettings'", ",", "true", ")", ";", "$", "mform", "->", "addElement", "(", "'advcheckbox'", ",", "'configdata[includetime]'", ",", "get_string", "(", "'includetime'", ",", "'customfield_date'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'date_time_selector'", ",", "'configdata[mindate]'", ",", "get_string", "(", "'mindate'", ",", "'customfield_date'", ")", ",", "[", "'optional'", "=>", "true", "]", ")", ";", "$", "mform", "->", "addElement", "(", "'date_time_selector'", ",", "'configdata[maxdate]'", ",", "get_string", "(", "'maxdate'", ",", "'customfield_date'", ")", ",", "[", "'optional'", "=>", "true", "]", ")", ";", "$", "mform", "->", "hideIf", "(", "'configdata[maxdate][hour]'", ",", "'configdata[includetime]'", ")", ";", "$", "mform", "->", "hideIf", "(", "'configdata[maxdate][minute]'", ",", "'configdata[includetime]'", ")", ";", "$", "mform", "->", "hideIf", "(", "'configdata[mindate][hour]'", ",", "'configdata[includetime]'", ")", ";", "$", "mform", "->", "hideIf", "(", "'configdata[mindate][minute]'", ",", "'configdata[includetime]'", ")", ";", "}" ]
Add fields for editing a date field. @param \MoodleQuickForm $mform
[ "Add", "fields", "for", "editing", "a", "date", "field", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/field/date/classes/field_controller.php#L66-L85
219,543
moodle/moodle
mod/forum/classes/local/factories/renderer.php
renderer.get_discussion_renderer
public function get_discussion_renderer( forum_entity $forum, discussion_entity $discussion, int $displaymode ) : discussion_renderer { $capabilitymanager = $this->managerfactory->get_capability_manager($forum); $ratingmanager = $this->managerfactory->get_rating_manager(); $rendererbase = $this->rendererbase; $baseurl = $this->urlfactory->get_discussion_view_url_from_discussion($discussion); $notifications = []; return new discussion_renderer( $forum, $discussion, $displaymode, $rendererbase, $this->get_single_discussion_posts_renderer($displaymode, false), $this->page, $this->legacydatamapperfactory, $this->exporterfactory, $this->vaultfactory, $capabilitymanager, $ratingmanager, $this->entityfactory->get_exported_posts_sorter(), $baseurl, $notifications, function($discussion, $user, $forum) { $exportbuilder = $this->builderfactory->get_exported_discussion_builder(); return $exportedposts = $exportbuilder->build( $user, $forum, $discussion ); } ); }
php
public function get_discussion_renderer( forum_entity $forum, discussion_entity $discussion, int $displaymode ) : discussion_renderer { $capabilitymanager = $this->managerfactory->get_capability_manager($forum); $ratingmanager = $this->managerfactory->get_rating_manager(); $rendererbase = $this->rendererbase; $baseurl = $this->urlfactory->get_discussion_view_url_from_discussion($discussion); $notifications = []; return new discussion_renderer( $forum, $discussion, $displaymode, $rendererbase, $this->get_single_discussion_posts_renderer($displaymode, false), $this->page, $this->legacydatamapperfactory, $this->exporterfactory, $this->vaultfactory, $capabilitymanager, $ratingmanager, $this->entityfactory->get_exported_posts_sorter(), $baseurl, $notifications, function($discussion, $user, $forum) { $exportbuilder = $this->builderfactory->get_exported_discussion_builder(); return $exportedposts = $exportbuilder->build( $user, $forum, $discussion ); } ); }
[ "public", "function", "get_discussion_renderer", "(", "forum_entity", "$", "forum", ",", "discussion_entity", "$", "discussion", ",", "int", "$", "displaymode", ")", ":", "discussion_renderer", "{", "$", "capabilitymanager", "=", "$", "this", "->", "managerfactory", "->", "get_capability_manager", "(", "$", "forum", ")", ";", "$", "ratingmanager", "=", "$", "this", "->", "managerfactory", "->", "get_rating_manager", "(", ")", ";", "$", "rendererbase", "=", "$", "this", "->", "rendererbase", ";", "$", "baseurl", "=", "$", "this", "->", "urlfactory", "->", "get_discussion_view_url_from_discussion", "(", "$", "discussion", ")", ";", "$", "notifications", "=", "[", "]", ";", "return", "new", "discussion_renderer", "(", "$", "forum", ",", "$", "discussion", ",", "$", "displaymode", ",", "$", "rendererbase", ",", "$", "this", "->", "get_single_discussion_posts_renderer", "(", "$", "displaymode", ",", "false", ")", ",", "$", "this", "->", "page", ",", "$", "this", "->", "legacydatamapperfactory", ",", "$", "this", "->", "exporterfactory", ",", "$", "this", "->", "vaultfactory", ",", "$", "capabilitymanager", ",", "$", "ratingmanager", ",", "$", "this", "->", "entityfactory", "->", "get_exported_posts_sorter", "(", ")", ",", "$", "baseurl", ",", "$", "notifications", ",", "function", "(", "$", "discussion", ",", "$", "user", ",", "$", "forum", ")", "{", "$", "exportbuilder", "=", "$", "this", "->", "builderfactory", "->", "get_exported_discussion_builder", "(", ")", ";", "return", "$", "exportedposts", "=", "$", "exportbuilder", "->", "build", "(", "$", "user", ",", "$", "forum", ",", "$", "discussion", ")", ";", "}", ")", ";", "}" ]
Create a discussion renderer for the given forum and discussion. @param forum_entity $forum Forum the discussion belongs to @param discussion_entity $discussion Discussion to render @param int $displaymode How should the posts be formatted? @return discussion_renderer
[ "Create", "a", "discussion", "renderer", "for", "the", "given", "forum", "and", "discussion", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/renderer.php#L114-L151
219,544
moodle/moodle
mod/forum/classes/local/factories/renderer.php
renderer.get_posts_search_results_renderer
public function get_posts_search_results_renderer(array $searchterms) : posts_renderer { $urlfactory = $this->urlfactory; return new posts_renderer( $this->rendererbase, $this->builderfactory->get_exported_posts_builder(), 'mod_forum/forum_posts_with_context_links', // Post process the exported posts to add the highlighting of the search terms to the post // and also the additional context links in the subject. function($exportedposts, $forumsbyid, $discussionsbyid) use ($searchterms, $urlfactory) { $highlightwords = implode(' ', $searchterms); return array_map( function($exportedpost) use ( $forumsbyid, $discussionsbyid, $searchterms, $highlightwords, $urlfactory ) { $discussion = $discussionsbyid[$exportedpost->discussionid]; $forum = $forumsbyid[$discussion->get_forum_id()]; $viewdiscussionurl = $urlfactory->get_discussion_view_url_from_discussion($discussion); $exportedpost->urls['viewforum'] = $urlfactory->get_forum_view_url_from_forum($forum)->out(false); $exportedpost->urls['viewdiscussion'] = $viewdiscussionurl->out(false); $exportedpost->subject = highlight($highlightwords, $exportedpost->subject); $exportedpost->forumname = format_string($forum->get_name(), true); $exportedpost->discussionname = highlight($highlightwords, format_string($discussion->get_name(), true)); $exportedpost->showdiscussionname = $forum->get_type() != 'single'; // Identify search terms only found in HTML markup, and add a warning about them to // the start of the message text. This logic was copied exactly as is from the previous // implementation. $missingterms = ''; $exportedpost->message = highlight( $highlightwords, $exportedpost->message, 0, '<fgw9sdpq4>', '</fgw9sdpq4>' ); foreach ($searchterms as $searchterm) { if ( preg_match("/$searchterm/i", $exportedpost->message) && !preg_match('/<fgw9sdpq4>' . $searchterm . '<\/fgw9sdpq4>/i', $exportedpost->message) ) { $missingterms .= " $searchterm"; } } $exportedpost->message = str_replace('<fgw9sdpq4>', '<span class="highlight">', $exportedpost->message); $exportedpost->message = str_replace('</fgw9sdpq4>', '</span>', $exportedpost->message); if ($missingterms) { $strmissingsearchterms = get_string('missingsearchterms', 'forum'); $exportedpost->message = '<p class="highlight2">' . $strmissingsearchterms . ' ' . $missingterms . '</p>' . $exportedpost->message; } return $exportedpost; }, $exportedposts ); } ); }
php
public function get_posts_search_results_renderer(array $searchterms) : posts_renderer { $urlfactory = $this->urlfactory; return new posts_renderer( $this->rendererbase, $this->builderfactory->get_exported_posts_builder(), 'mod_forum/forum_posts_with_context_links', // Post process the exported posts to add the highlighting of the search terms to the post // and also the additional context links in the subject. function($exportedposts, $forumsbyid, $discussionsbyid) use ($searchterms, $urlfactory) { $highlightwords = implode(' ', $searchterms); return array_map( function($exportedpost) use ( $forumsbyid, $discussionsbyid, $searchterms, $highlightwords, $urlfactory ) { $discussion = $discussionsbyid[$exportedpost->discussionid]; $forum = $forumsbyid[$discussion->get_forum_id()]; $viewdiscussionurl = $urlfactory->get_discussion_view_url_from_discussion($discussion); $exportedpost->urls['viewforum'] = $urlfactory->get_forum_view_url_from_forum($forum)->out(false); $exportedpost->urls['viewdiscussion'] = $viewdiscussionurl->out(false); $exportedpost->subject = highlight($highlightwords, $exportedpost->subject); $exportedpost->forumname = format_string($forum->get_name(), true); $exportedpost->discussionname = highlight($highlightwords, format_string($discussion->get_name(), true)); $exportedpost->showdiscussionname = $forum->get_type() != 'single'; // Identify search terms only found in HTML markup, and add a warning about them to // the start of the message text. This logic was copied exactly as is from the previous // implementation. $missingterms = ''; $exportedpost->message = highlight( $highlightwords, $exportedpost->message, 0, '<fgw9sdpq4>', '</fgw9sdpq4>' ); foreach ($searchterms as $searchterm) { if ( preg_match("/$searchterm/i", $exportedpost->message) && !preg_match('/<fgw9sdpq4>' . $searchterm . '<\/fgw9sdpq4>/i', $exportedpost->message) ) { $missingterms .= " $searchterm"; } } $exportedpost->message = str_replace('<fgw9sdpq4>', '<span class="highlight">', $exportedpost->message); $exportedpost->message = str_replace('</fgw9sdpq4>', '</span>', $exportedpost->message); if ($missingterms) { $strmissingsearchterms = get_string('missingsearchterms', 'forum'); $exportedpost->message = '<p class="highlight2">' . $strmissingsearchterms . ' ' . $missingterms . '</p>' . $exportedpost->message; } return $exportedpost; }, $exportedposts ); } ); }
[ "public", "function", "get_posts_search_results_renderer", "(", "array", "$", "searchterms", ")", ":", "posts_renderer", "{", "$", "urlfactory", "=", "$", "this", "->", "urlfactory", ";", "return", "new", "posts_renderer", "(", "$", "this", "->", "rendererbase", ",", "$", "this", "->", "builderfactory", "->", "get_exported_posts_builder", "(", ")", ",", "'mod_forum/forum_posts_with_context_links'", ",", "// Post process the exported posts to add the highlighting of the search terms to the post", "// and also the additional context links in the subject.", "function", "(", "$", "exportedposts", ",", "$", "forumsbyid", ",", "$", "discussionsbyid", ")", "use", "(", "$", "searchterms", ",", "$", "urlfactory", ")", "{", "$", "highlightwords", "=", "implode", "(", "' '", ",", "$", "searchterms", ")", ";", "return", "array_map", "(", "function", "(", "$", "exportedpost", ")", "use", "(", "$", "forumsbyid", ",", "$", "discussionsbyid", ",", "$", "searchterms", ",", "$", "highlightwords", ",", "$", "urlfactory", ")", "{", "$", "discussion", "=", "$", "discussionsbyid", "[", "$", "exportedpost", "->", "discussionid", "]", ";", "$", "forum", "=", "$", "forumsbyid", "[", "$", "discussion", "->", "get_forum_id", "(", ")", "]", ";", "$", "viewdiscussionurl", "=", "$", "urlfactory", "->", "get_discussion_view_url_from_discussion", "(", "$", "discussion", ")", ";", "$", "exportedpost", "->", "urls", "[", "'viewforum'", "]", "=", "$", "urlfactory", "->", "get_forum_view_url_from_forum", "(", "$", "forum", ")", "->", "out", "(", "false", ")", ";", "$", "exportedpost", "->", "urls", "[", "'viewdiscussion'", "]", "=", "$", "viewdiscussionurl", "->", "out", "(", "false", ")", ";", "$", "exportedpost", "->", "subject", "=", "highlight", "(", "$", "highlightwords", ",", "$", "exportedpost", "->", "subject", ")", ";", "$", "exportedpost", "->", "forumname", "=", "format_string", "(", "$", "forum", "->", "get_name", "(", ")", ",", "true", ")", ";", "$", "exportedpost", "->", "discussionname", "=", "highlight", "(", "$", "highlightwords", ",", "format_string", "(", "$", "discussion", "->", "get_name", "(", ")", ",", "true", ")", ")", ";", "$", "exportedpost", "->", "showdiscussionname", "=", "$", "forum", "->", "get_type", "(", ")", "!=", "'single'", ";", "// Identify search terms only found in HTML markup, and add a warning about them to", "// the start of the message text. This logic was copied exactly as is from the previous", "// implementation.", "$", "missingterms", "=", "''", ";", "$", "exportedpost", "->", "message", "=", "highlight", "(", "$", "highlightwords", ",", "$", "exportedpost", "->", "message", ",", "0", ",", "'<fgw9sdpq4>'", ",", "'</fgw9sdpq4>'", ")", ";", "foreach", "(", "$", "searchterms", "as", "$", "searchterm", ")", "{", "if", "(", "preg_match", "(", "\"/$searchterm/i\"", ",", "$", "exportedpost", "->", "message", ")", "&&", "!", "preg_match", "(", "'/<fgw9sdpq4>'", ".", "$", "searchterm", ".", "'<\\/fgw9sdpq4>/i'", ",", "$", "exportedpost", "->", "message", ")", ")", "{", "$", "missingterms", ".=", "\" $searchterm\"", ";", "}", "}", "$", "exportedpost", "->", "message", "=", "str_replace", "(", "'<fgw9sdpq4>'", ",", "'<span class=\"highlight\">'", ",", "$", "exportedpost", "->", "message", ")", ";", "$", "exportedpost", "->", "message", "=", "str_replace", "(", "'</fgw9sdpq4>'", ",", "'</span>'", ",", "$", "exportedpost", "->", "message", ")", ";", "if", "(", "$", "missingterms", ")", "{", "$", "strmissingsearchterms", "=", "get_string", "(", "'missingsearchterms'", ",", "'forum'", ")", ";", "$", "exportedpost", "->", "message", "=", "'<p class=\"highlight2\">'", ".", "$", "strmissingsearchterms", ".", "' '", ".", "$", "missingterms", ".", "'</p>'", ".", "$", "exportedpost", "->", "message", ";", "}", "return", "$", "exportedpost", ";", "}", ",", "$", "exportedposts", ")", ";", "}", ")", ";", "}" ]
Create a posts renderer to render posts in the forum search results. @param string[] $searchterms The search terms to be highlighted in the posts @return posts_renderer
[ "Create", "a", "posts", "renderer", "to", "render", "posts", "in", "the", "forum", "search", "results", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/renderer.php#L274-L341
219,545
moodle/moodle
mod/forum/classes/local/factories/renderer.php
renderer.get_discussion_list_renderer
public function get_discussion_list_renderer( forum_entity $forum ) : discussion_list_renderer { $capabilitymanager = $this->managerfactory->get_capability_manager($forum); $rendererbase = $this->rendererbase; $notifications = []; switch ($forum->get_type()) { case 'news': if (SITEID == $forum->get_course_id()) { $template = 'mod_forum/frontpage_news_discussion_list'; } else { $template = 'mod_forum/news_discussion_list'; } break; case 'qanda': $template = 'mod_forum/qanda_discussion_list'; break; default: $template = 'mod_forum/discussion_list'; } return new discussion_list_renderer( $forum, $rendererbase, $this->legacydatamapperfactory, $this->exporterfactory, $this->vaultfactory, $this->builderfactory, $capabilitymanager, $this->urlfactory, $template, $notifications, function($discussions, $user, $forum) { $exporteddiscussionsummarybuilder = $this->builderfactory->get_exported_discussion_summaries_builder(); return $exporteddiscussionsummarybuilder->build( $user, $forum, $discussions ); } ); }
php
public function get_discussion_list_renderer( forum_entity $forum ) : discussion_list_renderer { $capabilitymanager = $this->managerfactory->get_capability_manager($forum); $rendererbase = $this->rendererbase; $notifications = []; switch ($forum->get_type()) { case 'news': if (SITEID == $forum->get_course_id()) { $template = 'mod_forum/frontpage_news_discussion_list'; } else { $template = 'mod_forum/news_discussion_list'; } break; case 'qanda': $template = 'mod_forum/qanda_discussion_list'; break; default: $template = 'mod_forum/discussion_list'; } return new discussion_list_renderer( $forum, $rendererbase, $this->legacydatamapperfactory, $this->exporterfactory, $this->vaultfactory, $this->builderfactory, $capabilitymanager, $this->urlfactory, $template, $notifications, function($discussions, $user, $forum) { $exporteddiscussionsummarybuilder = $this->builderfactory->get_exported_discussion_summaries_builder(); return $exporteddiscussionsummarybuilder->build( $user, $forum, $discussions ); } ); }
[ "public", "function", "get_discussion_list_renderer", "(", "forum_entity", "$", "forum", ")", ":", "discussion_list_renderer", "{", "$", "capabilitymanager", "=", "$", "this", "->", "managerfactory", "->", "get_capability_manager", "(", "$", "forum", ")", ";", "$", "rendererbase", "=", "$", "this", "->", "rendererbase", ";", "$", "notifications", "=", "[", "]", ";", "switch", "(", "$", "forum", "->", "get_type", "(", ")", ")", "{", "case", "'news'", ":", "if", "(", "SITEID", "==", "$", "forum", "->", "get_course_id", "(", ")", ")", "{", "$", "template", "=", "'mod_forum/frontpage_news_discussion_list'", ";", "}", "else", "{", "$", "template", "=", "'mod_forum/news_discussion_list'", ";", "}", "break", ";", "case", "'qanda'", ":", "$", "template", "=", "'mod_forum/qanda_discussion_list'", ";", "break", ";", "default", ":", "$", "template", "=", "'mod_forum/discussion_list'", ";", "}", "return", "new", "discussion_list_renderer", "(", "$", "forum", ",", "$", "rendererbase", ",", "$", "this", "->", "legacydatamapperfactory", ",", "$", "this", "->", "exporterfactory", ",", "$", "this", "->", "vaultfactory", ",", "$", "this", "->", "builderfactory", ",", "$", "capabilitymanager", ",", "$", "this", "->", "urlfactory", ",", "$", "template", ",", "$", "notifications", ",", "function", "(", "$", "discussions", ",", "$", "user", ",", "$", "forum", ")", "{", "$", "exporteddiscussionsummarybuilder", "=", "$", "this", "->", "builderfactory", "->", "get_exported_discussion_summaries_builder", "(", ")", ";", "return", "$", "exporteddiscussionsummarybuilder", "->", "build", "(", "$", "user", ",", "$", "forum", ",", "$", "discussions", ")", ";", "}", ")", ";", "}" ]
Create a standard type discussion list renderer. @param forum_entity $forum The forum that the discussions belong to @return discussion_list_renderer
[ "Create", "a", "standard", "type", "discussion", "list", "renderer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/renderer.php#L387-L431
219,546
moodle/moodle
mod/forum/classes/local/factories/renderer.php
renderer.get_detailed_discussion_list_renderer
private function get_detailed_discussion_list_renderer( forum_entity $forum, string $template ) : discussion_list_renderer { $capabilitymanager = $this->managerfactory->get_capability_manager($forum); $rendererbase = $this->rendererbase; $notifications = []; return new discussion_list_renderer( $forum, $rendererbase, $this->legacydatamapperfactory, $this->exporterfactory, $this->vaultfactory, $this->builderfactory, $capabilitymanager, $this->urlfactory, $template, $notifications, function($discussions, $user, $forum) use ($capabilitymanager) { $exportedpostsbuilder = $this->builderfactory->get_exported_posts_builder(); $discussionentries = []; $postentries = []; foreach ($discussions as $discussion) { $discussionentries[] = $discussion->get_discussion(); $discussionentriesids[] = $discussion->get_discussion()->get_id(); $postentries[] = $discussion->get_first_post(); } $exportedposts['posts'] = $exportedpostsbuilder->build( $user, [$forum], $discussionentries, $postentries ); $postvault = $this->vaultfactory->get_post_vault(); $canseeanyprivatereply = $capabilitymanager->can_view_any_private_reply($user); $discussionrepliescount = $postvault->get_reply_count_for_discussion_ids( $user, $discussionentriesids, $canseeanyprivatereply ); array_walk($exportedposts['posts'], function($post) use ($discussionrepliescount) { $post->discussionrepliescount = $discussionrepliescount[$post->discussionid] ?? 0; // TODO: Find a better solution due to language differences when defining the singular and plural form. $post->isreplyplural = $post->discussionrepliescount != 1 ? true : false; }); $exportedposts['state']['hasdiscussions'] = $exportedposts['posts'] ? true : false; return $exportedposts; } ); }
php
private function get_detailed_discussion_list_renderer( forum_entity $forum, string $template ) : discussion_list_renderer { $capabilitymanager = $this->managerfactory->get_capability_manager($forum); $rendererbase = $this->rendererbase; $notifications = []; return new discussion_list_renderer( $forum, $rendererbase, $this->legacydatamapperfactory, $this->exporterfactory, $this->vaultfactory, $this->builderfactory, $capabilitymanager, $this->urlfactory, $template, $notifications, function($discussions, $user, $forum) use ($capabilitymanager) { $exportedpostsbuilder = $this->builderfactory->get_exported_posts_builder(); $discussionentries = []; $postentries = []; foreach ($discussions as $discussion) { $discussionentries[] = $discussion->get_discussion(); $discussionentriesids[] = $discussion->get_discussion()->get_id(); $postentries[] = $discussion->get_first_post(); } $exportedposts['posts'] = $exportedpostsbuilder->build( $user, [$forum], $discussionentries, $postentries ); $postvault = $this->vaultfactory->get_post_vault(); $canseeanyprivatereply = $capabilitymanager->can_view_any_private_reply($user); $discussionrepliescount = $postvault->get_reply_count_for_discussion_ids( $user, $discussionentriesids, $canseeanyprivatereply ); array_walk($exportedposts['posts'], function($post) use ($discussionrepliescount) { $post->discussionrepliescount = $discussionrepliescount[$post->discussionid] ?? 0; // TODO: Find a better solution due to language differences when defining the singular and plural form. $post->isreplyplural = $post->discussionrepliescount != 1 ? true : false; }); $exportedposts['state']['hasdiscussions'] = $exportedposts['posts'] ? true : false; return $exportedposts; } ); }
[ "private", "function", "get_detailed_discussion_list_renderer", "(", "forum_entity", "$", "forum", ",", "string", "$", "template", ")", ":", "discussion_list_renderer", "{", "$", "capabilitymanager", "=", "$", "this", "->", "managerfactory", "->", "get_capability_manager", "(", "$", "forum", ")", ";", "$", "rendererbase", "=", "$", "this", "->", "rendererbase", ";", "$", "notifications", "=", "[", "]", ";", "return", "new", "discussion_list_renderer", "(", "$", "forum", ",", "$", "rendererbase", ",", "$", "this", "->", "legacydatamapperfactory", ",", "$", "this", "->", "exporterfactory", ",", "$", "this", "->", "vaultfactory", ",", "$", "this", "->", "builderfactory", ",", "$", "capabilitymanager", ",", "$", "this", "->", "urlfactory", ",", "$", "template", ",", "$", "notifications", ",", "function", "(", "$", "discussions", ",", "$", "user", ",", "$", "forum", ")", "use", "(", "$", "capabilitymanager", ")", "{", "$", "exportedpostsbuilder", "=", "$", "this", "->", "builderfactory", "->", "get_exported_posts_builder", "(", ")", ";", "$", "discussionentries", "=", "[", "]", ";", "$", "postentries", "=", "[", "]", ";", "foreach", "(", "$", "discussions", "as", "$", "discussion", ")", "{", "$", "discussionentries", "[", "]", "=", "$", "discussion", "->", "get_discussion", "(", ")", ";", "$", "discussionentriesids", "[", "]", "=", "$", "discussion", "->", "get_discussion", "(", ")", "->", "get_id", "(", ")", ";", "$", "postentries", "[", "]", "=", "$", "discussion", "->", "get_first_post", "(", ")", ";", "}", "$", "exportedposts", "[", "'posts'", "]", "=", "$", "exportedpostsbuilder", "->", "build", "(", "$", "user", ",", "[", "$", "forum", "]", ",", "$", "discussionentries", ",", "$", "postentries", ")", ";", "$", "postvault", "=", "$", "this", "->", "vaultfactory", "->", "get_post_vault", "(", ")", ";", "$", "canseeanyprivatereply", "=", "$", "capabilitymanager", "->", "can_view_any_private_reply", "(", "$", "user", ")", ";", "$", "discussionrepliescount", "=", "$", "postvault", "->", "get_reply_count_for_discussion_ids", "(", "$", "user", ",", "$", "discussionentriesids", ",", "$", "canseeanyprivatereply", ")", ";", "array_walk", "(", "$", "exportedposts", "[", "'posts'", "]", ",", "function", "(", "$", "post", ")", "use", "(", "$", "discussionrepliescount", ")", "{", "$", "post", "->", "discussionrepliescount", "=", "$", "discussionrepliescount", "[", "$", "post", "->", "discussionid", "]", "??", "0", ";", "// TODO: Find a better solution due to language differences when defining the singular and plural form.", "$", "post", "->", "isreplyplural", "=", "$", "post", "->", "discussionrepliescount", "!=", "1", "?", "true", ":", "false", ";", "}", ")", ";", "$", "exportedposts", "[", "'state'", "]", "[", "'hasdiscussions'", "]", "=", "$", "exportedposts", "[", "'posts'", "]", "?", "true", ":", "false", ";", "return", "$", "exportedposts", ";", "}", ")", ";", "}" ]
Create a discussion list renderer which shows more information about the first post. @param forum_entity $forum The forum that the discussions belong to @param string $template The template to use @return discussion_list_renderer
[ "Create", "a", "discussion", "list", "renderer", "which", "shows", "more", "information", "about", "the", "first", "post", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/renderer.php#L440-L496
219,547
moodle/moodle
mod/forum/classes/local/factories/renderer.php
renderer.get_single_discussion_list_renderer
public function get_single_discussion_list_renderer( forum_entity $forum, discussion_entity $discussion, bool $hasmultiplediscussions, int $displaymode ) : discussion_renderer { $capabilitymanager = $this->managerfactory->get_capability_manager($forum); $ratingmanager = $this->managerfactory->get_rating_manager(); $rendererbase = $this->rendererbase; $cmid = $forum->get_course_module_record()->id; $baseurl = $this->urlfactory->get_forum_view_url_from_course_module_id($cmid); $notifications = array(); if ($hasmultiplediscussions) { $notifications[] = (new notification(get_string('warnformorepost', 'forum'))) ->set_show_closebutton(true); } return new discussion_renderer( $forum, $discussion, $displaymode, $rendererbase, $this->get_single_discussion_posts_renderer($displaymode, false), $this->page, $this->legacydatamapperfactory, $this->exporterfactory, $this->vaultfactory, $capabilitymanager, $ratingmanager, $this->entityfactory->get_exported_posts_sorter(), $baseurl, $notifications ); }
php
public function get_single_discussion_list_renderer( forum_entity $forum, discussion_entity $discussion, bool $hasmultiplediscussions, int $displaymode ) : discussion_renderer { $capabilitymanager = $this->managerfactory->get_capability_manager($forum); $ratingmanager = $this->managerfactory->get_rating_manager(); $rendererbase = $this->rendererbase; $cmid = $forum->get_course_module_record()->id; $baseurl = $this->urlfactory->get_forum_view_url_from_course_module_id($cmid); $notifications = array(); if ($hasmultiplediscussions) { $notifications[] = (new notification(get_string('warnformorepost', 'forum'))) ->set_show_closebutton(true); } return new discussion_renderer( $forum, $discussion, $displaymode, $rendererbase, $this->get_single_discussion_posts_renderer($displaymode, false), $this->page, $this->legacydatamapperfactory, $this->exporterfactory, $this->vaultfactory, $capabilitymanager, $ratingmanager, $this->entityfactory->get_exported_posts_sorter(), $baseurl, $notifications ); }
[ "public", "function", "get_single_discussion_list_renderer", "(", "forum_entity", "$", "forum", ",", "discussion_entity", "$", "discussion", ",", "bool", "$", "hasmultiplediscussions", ",", "int", "$", "displaymode", ")", ":", "discussion_renderer", "{", "$", "capabilitymanager", "=", "$", "this", "->", "managerfactory", "->", "get_capability_manager", "(", "$", "forum", ")", ";", "$", "ratingmanager", "=", "$", "this", "->", "managerfactory", "->", "get_rating_manager", "(", ")", ";", "$", "rendererbase", "=", "$", "this", "->", "rendererbase", ";", "$", "cmid", "=", "$", "forum", "->", "get_course_module_record", "(", ")", "->", "id", ";", "$", "baseurl", "=", "$", "this", "->", "urlfactory", "->", "get_forum_view_url_from_course_module_id", "(", "$", "cmid", ")", ";", "$", "notifications", "=", "array", "(", ")", ";", "if", "(", "$", "hasmultiplediscussions", ")", "{", "$", "notifications", "[", "]", "=", "(", "new", "notification", "(", "get_string", "(", "'warnformorepost'", ",", "'forum'", ")", ")", ")", "->", "set_show_closebutton", "(", "true", ")", ";", "}", "return", "new", "discussion_renderer", "(", "$", "forum", ",", "$", "discussion", ",", "$", "displaymode", ",", "$", "rendererbase", ",", "$", "this", "->", "get_single_discussion_posts_renderer", "(", "$", "displaymode", ",", "false", ")", ",", "$", "this", "->", "page", ",", "$", "this", "->", "legacydatamapperfactory", ",", "$", "this", "->", "exporterfactory", ",", "$", "this", "->", "vaultfactory", ",", "$", "capabilitymanager", ",", "$", "ratingmanager", ",", "$", "this", "->", "entityfactory", "->", "get_exported_posts_sorter", "(", ")", ",", "$", "baseurl", ",", "$", "notifications", ")", ";", "}" ]
Create a single type discussion list renderer. @param forum_entity $forum Forum the discussion belongs to @param discussion_entity $discussion The discussion entity @param bool $hasmultiplediscussions Whether the forum has multiple discussions (more than one) @param int $displaymode How should the posts be formatted? @return discussion_renderer
[ "Create", "a", "single", "type", "discussion", "list", "renderer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/renderer.php#L543-L579
219,548
moodle/moodle
lib/behat/core_behat_file_helper.php
core_behat_file_helper.get_filepicker_node
protected function get_filepicker_node($filepickerelement) { // More info about the problem (in case there is a problem). $exception = new ExpectationException('"' . $filepickerelement . '" filepicker can not be found', $this->getSession()); // If no file picker label is mentioned take the first file picker from the page. if (empty($filepickerelement)) { $filepickercontainer = $this->find( 'xpath', "//*[@data-fieldtype=\"filemanager\"]", $exception ); } else { // Gets the ffilemanager node specified by the locator which contains the filepicker container. $filepickerelement = behat_context_helper::escape($filepickerelement); $filepickercontainer = $this->find( 'xpath', "//input[./@id = //label[normalize-space(.)=$filepickerelement]/@for]" . "//ancestor::*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker']", $exception ); } return $filepickercontainer; }
php
protected function get_filepicker_node($filepickerelement) { // More info about the problem (in case there is a problem). $exception = new ExpectationException('"' . $filepickerelement . '" filepicker can not be found', $this->getSession()); // If no file picker label is mentioned take the first file picker from the page. if (empty($filepickerelement)) { $filepickercontainer = $this->find( 'xpath', "//*[@data-fieldtype=\"filemanager\"]", $exception ); } else { // Gets the ffilemanager node specified by the locator which contains the filepicker container. $filepickerelement = behat_context_helper::escape($filepickerelement); $filepickercontainer = $this->find( 'xpath', "//input[./@id = //label[normalize-space(.)=$filepickerelement]/@for]" . "//ancestor::*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker']", $exception ); } return $filepickercontainer; }
[ "protected", "function", "get_filepicker_node", "(", "$", "filepickerelement", ")", "{", "// More info about the problem (in case there is a problem).", "$", "exception", "=", "new", "ExpectationException", "(", "'\"'", ".", "$", "filepickerelement", ".", "'\" filepicker can not be found'", ",", "$", "this", "->", "getSession", "(", ")", ")", ";", "// If no file picker label is mentioned take the first file picker from the page.", "if", "(", "empty", "(", "$", "filepickerelement", ")", ")", "{", "$", "filepickercontainer", "=", "$", "this", "->", "find", "(", "'xpath'", ",", "\"//*[@data-fieldtype=\\\"filemanager\\\"]\"", ",", "$", "exception", ")", ";", "}", "else", "{", "// Gets the ffilemanager node specified by the locator which contains the filepicker container.", "$", "filepickerelement", "=", "behat_context_helper", "::", "escape", "(", "$", "filepickerelement", ")", ";", "$", "filepickercontainer", "=", "$", "this", "->", "find", "(", "'xpath'", ",", "\"//input[./@id = //label[normalize-space(.)=$filepickerelement]/@for]\"", ".", "\"//ancestor::*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker']\"", ",", "$", "exception", ")", ";", "}", "return", "$", "filepickercontainer", ";", "}" ]
Gets the NodeElement for filepicker of filemanager moodleform element. The filepicker/filemanager element label is pointing to a hidden input which is not recognized as a named selector, as it is hidden... @throws ExpectationException Thrown by behat_base::find @param string $filepickerelement The filepicker form field label @return NodeElement The hidden element node.
[ "Gets", "the", "NodeElement", "for", "filepicker", "of", "filemanager", "moodleform", "element", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/core_behat_file_helper.php#L60-L84
219,549
moodle/moodle
lib/behat/core_behat_file_helper.php
core_behat_file_helper.open_element_contextual_menu
protected function open_element_contextual_menu($name, $filemanagerelement = false) { // If a filemanager is specified we restrict the search to the descendants of this particular filemanager form element. $containernode = false; $exceptionmsg = '"'.$name.'" element can not be found'; if ($filemanagerelement) { $containernode = $this->get_filepicker_node($filemanagerelement); $exceptionmsg = 'The "'.$filemanagerelement.'" filemanager ' . $exceptionmsg; $locatorprefix = "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content ')]"; } else { $locatorprefix = "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-repo-items ')]" . "//descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content ')]"; } $exception = new ExpectationException($exceptionmsg, $this->getSession()); // Avoid quote-related problems. $name = behat_context_helper::escape($name); // Get a filepicker/filemanager element (folder or file). try { // First we look at the folder as we need to click on the contextual menu otherwise it would be opened. $node = $this->find( 'xpath', $locatorprefix . "//descendant::*[self::div | self::a][contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')]" . "[contains(concat(' ', normalize-space(@class), ' '), ' fp-folder ')]" . "[normalize-space(.)=$name]" . "//descendant::a[contains(concat(' ', normalize-space(@class), ' '), ' fp-contextmenu ')]", $exception, $containernode ); } catch (ExpectationException $e) { // Here the contextual menu is hidden, we click on the thumbnail. $node = $this->find( 'xpath', $locatorprefix . "//descendant::*[self::div | self::a][contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')]" . "[normalize-space(.)=$name]" . "//descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-filename-field ')]", false, $containernode ); } // Click opens the contextual menu when clicking on files. $this->ensure_node_is_visible($node); $node->click(); }
php
protected function open_element_contextual_menu($name, $filemanagerelement = false) { // If a filemanager is specified we restrict the search to the descendants of this particular filemanager form element. $containernode = false; $exceptionmsg = '"'.$name.'" element can not be found'; if ($filemanagerelement) { $containernode = $this->get_filepicker_node($filemanagerelement); $exceptionmsg = 'The "'.$filemanagerelement.'" filemanager ' . $exceptionmsg; $locatorprefix = "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content ')]"; } else { $locatorprefix = "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-repo-items ')]" . "//descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content ')]"; } $exception = new ExpectationException($exceptionmsg, $this->getSession()); // Avoid quote-related problems. $name = behat_context_helper::escape($name); // Get a filepicker/filemanager element (folder or file). try { // First we look at the folder as we need to click on the contextual menu otherwise it would be opened. $node = $this->find( 'xpath', $locatorprefix . "//descendant::*[self::div | self::a][contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')]" . "[contains(concat(' ', normalize-space(@class), ' '), ' fp-folder ')]" . "[normalize-space(.)=$name]" . "//descendant::a[contains(concat(' ', normalize-space(@class), ' '), ' fp-contextmenu ')]", $exception, $containernode ); } catch (ExpectationException $e) { // Here the contextual menu is hidden, we click on the thumbnail. $node = $this->find( 'xpath', $locatorprefix . "//descendant::*[self::div | self::a][contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')]" . "[normalize-space(.)=$name]" . "//descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-filename-field ')]", false, $containernode ); } // Click opens the contextual menu when clicking on files. $this->ensure_node_is_visible($node); $node->click(); }
[ "protected", "function", "open_element_contextual_menu", "(", "$", "name", ",", "$", "filemanagerelement", "=", "false", ")", "{", "// If a filemanager is specified we restrict the search to the descendants of this particular filemanager form element.", "$", "containernode", "=", "false", ";", "$", "exceptionmsg", "=", "'\"'", ".", "$", "name", ".", "'\" element can not be found'", ";", "if", "(", "$", "filemanagerelement", ")", "{", "$", "containernode", "=", "$", "this", "->", "get_filepicker_node", "(", "$", "filemanagerelement", ")", ";", "$", "exceptionmsg", "=", "'The \"'", ".", "$", "filemanagerelement", ".", "'\" filemanager '", ".", "$", "exceptionmsg", ";", "$", "locatorprefix", "=", "\"//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content ')]\"", ";", "}", "else", "{", "$", "locatorprefix", "=", "\"//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-repo-items ')]\"", ".", "\"//descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content ')]\"", ";", "}", "$", "exception", "=", "new", "ExpectationException", "(", "$", "exceptionmsg", ",", "$", "this", "->", "getSession", "(", ")", ")", ";", "// Avoid quote-related problems.", "$", "name", "=", "behat_context_helper", "::", "escape", "(", "$", "name", ")", ";", "// Get a filepicker/filemanager element (folder or file).", "try", "{", "// First we look at the folder as we need to click on the contextual menu otherwise it would be opened.", "$", "node", "=", "$", "this", "->", "find", "(", "'xpath'", ",", "$", "locatorprefix", ".", "\"//descendant::*[self::div | self::a][contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')]\"", ".", "\"[contains(concat(' ', normalize-space(@class), ' '), ' fp-folder ')]\"", ".", "\"[normalize-space(.)=$name]\"", ".", "\"//descendant::a[contains(concat(' ', normalize-space(@class), ' '), ' fp-contextmenu ')]\"", ",", "$", "exception", ",", "$", "containernode", ")", ";", "}", "catch", "(", "ExpectationException", "$", "e", ")", "{", "// Here the contextual menu is hidden, we click on the thumbnail.", "$", "node", "=", "$", "this", "->", "find", "(", "'xpath'", ",", "$", "locatorprefix", ".", "\"//descendant::*[self::div | self::a][contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')]\"", ".", "\"[normalize-space(.)=$name]\"", ".", "\"//descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-filename-field ')]\"", ",", "false", ",", "$", "containernode", ")", ";", "}", "// Click opens the contextual menu when clicking on files.", "$", "this", "->", "ensure_node_is_visible", "(", "$", "node", ")", ";", "$", "node", "->", "click", "(", ")", ";", "}" ]
Opens the contextual menu of a folder or a file. Works both in filemanager elements and when dealing with repository elements inside filepicker modal window. @throws ExpectationException Thrown by behat_base::find @param string $name The name of the folder/file @param string $filemanagerelement The filemanager form element locator, the repository items are in filepicker modal window if false @return void
[ "Opens", "the", "contextual", "menu", "of", "a", "folder", "or", "a", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/core_behat_file_helper.php#L118-L169
219,550
moodle/moodle
lib/behat/core_behat_file_helper.php
core_behat_file_helper.open_add_file_window
protected function open_add_file_window($filemanagernode, $repositoryname) { $exception = new ExpectationException('No files can be added to the specified filemanager', $this->getSession()); // We should deal with single-file and multiple-file filemanagers, // catching the exception thrown by behat_base::find() in case is not multiple try { // Looking for the add button inside the specified filemanager. $add = $this->find('css', 'div.fp-btn-add a', $exception, $filemanagernode); } catch (Exception $e) { // Otherwise should be a single-file filepicker form element. $add = $this->find('css', 'input.fp-btn-choose', $exception, $filemanagernode); } $this->ensure_node_is_visible($add); $add->click(); // Wait for the default repository (if any) to load. This checks that // the relevant div exists and that it does not include the loading image. $this->ensure_element_exists( "//div[contains(concat(' ', normalize-space(@class), ' '), ' file-picker ')]" . "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content ')]" . "[not(descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content-loading ')])]", 'xpath_element'); // Getting the repository link and opening it. $repoexception = new ExpectationException('The "' . $repositoryname . '" repository has not been found', $this->getSession()); // Avoid problems with both double and single quotes in the same string. $repositoryname = behat_context_helper::escape($repositoryname); // Here we don't need to look inside the selected element because there can only be one modal window. $repositorylink = $this->find( 'xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-repo-area ')]" . "//descendant::span[contains(concat(' ', normalize-space(@class), ' '), ' fp-repo-name ')]" . "[normalize-space(.)=$repositoryname]", $repoexception ); // Selecting the repo. $this->ensure_node_is_visible($repositorylink); if (!$repositorylink->getParent()->getParent()->hasClass('active')) { // If the repository link is active, then the repository is already loaded. // Clicking it while it's active causes issues, so only click it when it isn't (see MDL-51014). $repositorylink->click(); } }
php
protected function open_add_file_window($filemanagernode, $repositoryname) { $exception = new ExpectationException('No files can be added to the specified filemanager', $this->getSession()); // We should deal with single-file and multiple-file filemanagers, // catching the exception thrown by behat_base::find() in case is not multiple try { // Looking for the add button inside the specified filemanager. $add = $this->find('css', 'div.fp-btn-add a', $exception, $filemanagernode); } catch (Exception $e) { // Otherwise should be a single-file filepicker form element. $add = $this->find('css', 'input.fp-btn-choose', $exception, $filemanagernode); } $this->ensure_node_is_visible($add); $add->click(); // Wait for the default repository (if any) to load. This checks that // the relevant div exists and that it does not include the loading image. $this->ensure_element_exists( "//div[contains(concat(' ', normalize-space(@class), ' '), ' file-picker ')]" . "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content ')]" . "[not(descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content-loading ')])]", 'xpath_element'); // Getting the repository link and opening it. $repoexception = new ExpectationException('The "' . $repositoryname . '" repository has not been found', $this->getSession()); // Avoid problems with both double and single quotes in the same string. $repositoryname = behat_context_helper::escape($repositoryname); // Here we don't need to look inside the selected element because there can only be one modal window. $repositorylink = $this->find( 'xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-repo-area ')]" . "//descendant::span[contains(concat(' ', normalize-space(@class), ' '), ' fp-repo-name ')]" . "[normalize-space(.)=$repositoryname]", $repoexception ); // Selecting the repo. $this->ensure_node_is_visible($repositorylink); if (!$repositorylink->getParent()->getParent()->hasClass('active')) { // If the repository link is active, then the repository is already loaded. // Clicking it while it's active causes issues, so only click it when it isn't (see MDL-51014). $repositorylink->click(); } }
[ "protected", "function", "open_add_file_window", "(", "$", "filemanagernode", ",", "$", "repositoryname", ")", "{", "$", "exception", "=", "new", "ExpectationException", "(", "'No files can be added to the specified filemanager'", ",", "$", "this", "->", "getSession", "(", ")", ")", ";", "// We should deal with single-file and multiple-file filemanagers,", "// catching the exception thrown by behat_base::find() in case is not multiple", "try", "{", "// Looking for the add button inside the specified filemanager.", "$", "add", "=", "$", "this", "->", "find", "(", "'css'", ",", "'div.fp-btn-add a'", ",", "$", "exception", ",", "$", "filemanagernode", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// Otherwise should be a single-file filepicker form element.", "$", "add", "=", "$", "this", "->", "find", "(", "'css'", ",", "'input.fp-btn-choose'", ",", "$", "exception", ",", "$", "filemanagernode", ")", ";", "}", "$", "this", "->", "ensure_node_is_visible", "(", "$", "add", ")", ";", "$", "add", "->", "click", "(", ")", ";", "// Wait for the default repository (if any) to load. This checks that", "// the relevant div exists and that it does not include the loading image.", "$", "this", "->", "ensure_element_exists", "(", "\"//div[contains(concat(' ', normalize-space(@class), ' '), ' file-picker ')]\"", ".", "\"//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content ')]\"", ".", "\"[not(descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content-loading ')])]\"", ",", "'xpath_element'", ")", ";", "// Getting the repository link and opening it.", "$", "repoexception", "=", "new", "ExpectationException", "(", "'The \"'", ".", "$", "repositoryname", ".", "'\" repository has not been found'", ",", "$", "this", "->", "getSession", "(", ")", ")", ";", "// Avoid problems with both double and single quotes in the same string.", "$", "repositoryname", "=", "behat_context_helper", "::", "escape", "(", "$", "repositoryname", ")", ";", "// Here we don't need to look inside the selected element because there can only be one modal window.", "$", "repositorylink", "=", "$", "this", "->", "find", "(", "'xpath'", ",", "\"//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-repo-area ')]\"", ".", "\"//descendant::span[contains(concat(' ', normalize-space(@class), ' '), ' fp-repo-name ')]\"", ".", "\"[normalize-space(.)=$repositoryname]\"", ",", "$", "repoexception", ")", ";", "// Selecting the repo.", "$", "this", "->", "ensure_node_is_visible", "(", "$", "repositorylink", ")", ";", "if", "(", "!", "$", "repositorylink", "->", "getParent", "(", ")", "->", "getParent", "(", ")", "->", "hasClass", "(", "'active'", ")", ")", "{", "// If the repository link is active, then the repository is already loaded.", "// Clicking it while it's active causes issues, so only click it when it isn't (see MDL-51014).", "$", "repositorylink", "->", "click", "(", ")", ";", "}", "}" ]
Opens the filepicker modal window and selects the repository. @throws ExpectationException Thrown by behat_base::find @param NodeElement $filemanagernode The filemanager or filepicker form element DOM node. @param mixed $repositoryname The repo name. @return void
[ "Opens", "the", "filepicker", "modal", "window", "and", "selects", "the", "repository", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/core_behat_file_helper.php#L179-L225
219,551
moodle/moodle
lib/behat/core_behat_file_helper.php
core_behat_file_helper.wait_until_contents_are_updated
protected function wait_until_contents_are_updated($filepickernode) { $exception = new ExpectationException( 'The file manager contents are requiring too much time to be updated', $this->getSession() ); // Looks for the loading image not being displayed. For single-file filepickers is // only used when accessing the filepicker, there is no filemanager-loading after selecting the file. $this->find( 'xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' filemanager ')]" . "[not(contains(concat(' ', normalize-space(@class), ' '), ' fm-updating '))]" . "|" . "//div[contains(concat(' ', normalize-space(@class), ' '), ' filemanager-loading ')]" . "[contains(@style, 'display: none;')]", $exception, $filepickernode ); }
php
protected function wait_until_contents_are_updated($filepickernode) { $exception = new ExpectationException( 'The file manager contents are requiring too much time to be updated', $this->getSession() ); // Looks for the loading image not being displayed. For single-file filepickers is // only used when accessing the filepicker, there is no filemanager-loading after selecting the file. $this->find( 'xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' filemanager ')]" . "[not(contains(concat(' ', normalize-space(@class), ' '), ' fm-updating '))]" . "|" . "//div[contains(concat(' ', normalize-space(@class), ' '), ' filemanager-loading ')]" . "[contains(@style, 'display: none;')]", $exception, $filepickernode ); }
[ "protected", "function", "wait_until_contents_are_updated", "(", "$", "filepickernode", ")", "{", "$", "exception", "=", "new", "ExpectationException", "(", "'The file manager contents are requiring too much time to be updated'", ",", "$", "this", "->", "getSession", "(", ")", ")", ";", "// Looks for the loading image not being displayed. For single-file filepickers is", "// only used when accessing the filepicker, there is no filemanager-loading after selecting the file.", "$", "this", "->", "find", "(", "'xpath'", ",", "\"//div[contains(concat(' ', normalize-space(@class), ' '), ' filemanager ')]\"", ".", "\"[not(contains(concat(' ', normalize-space(@class), ' '), ' fm-updating '))]\"", ".", "\"|\"", ".", "\"//div[contains(concat(' ', normalize-space(@class), ' '), ' filemanager-loading ')]\"", ".", "\"[contains(@style, 'display: none;')]\"", ",", "$", "exception", ",", "$", "filepickernode", ")", ";", "}" ]
Checks that the file manager contents are not being updated. This method is not used by any of our step definitions, keeping it here for users already using it. @throws ExpectationException @param NodeElement $filepickernode The file manager DOM node @return void
[ "Checks", "that", "the", "file", "manager", "contents", "are", "not", "being", "updated", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/core_behat_file_helper.php#L257-L276
219,552
moodle/moodle
repository/nextcloud/classes/ocs_client.php
ocs_client.get_api_functions
public function get_api_functions() { return [ 'create_share' => [ 'endpoint' => $this->ocsendpoint->out(false), 'method' => 'post', 'args' => [ 'path' => PARAM_TEXT, // Could be PARAM_PATH, we really don't want to enforce a Moodle understanding of paths. 'shareType' => PARAM_INT, 'shareWith' => PARAM_TEXT, // Name of receiving user/group. Required if SHARE_TYPE_USER. 'publicUpload' => PARAM_RAW, // Actually Boolean, but neither String-Boolean ('false') nor PARAM_BOOL (0/1). 'permissions' => PARAM_INT, 'shareWith' => PARAM_TEXT, 'expireDate' => PARAM_TEXT ], 'response' => 'text/xml' ], 'delete_share' => [ 'endpoint' => $this->build_share_url(), 'method' => 'delete', 'args' => [ 'share_id' => PARAM_INT ], 'response' => 'text/xml' ], 'get_shares' => [ 'endpoint' => $this->ocsendpoint->out(false), 'method' => 'get', 'args' => [ 'path' => PARAM_TEXT, 'reshares' => PARAM_RAW, // Returns not only the shares from the current user but all of the given file. 'subfiles' => PARAM_RAW, // Returns all shares within a folder, given that path defines a folder. ], 'response' => 'text/xml' ], 'get_information_of_share' => [ 'endpoint' => $this->build_share_url(), 'method' => 'get', 'args' => [ 'share_id' => PARAM_INT ], 'response' => 'text/xml' ], ]; }
php
public function get_api_functions() { return [ 'create_share' => [ 'endpoint' => $this->ocsendpoint->out(false), 'method' => 'post', 'args' => [ 'path' => PARAM_TEXT, // Could be PARAM_PATH, we really don't want to enforce a Moodle understanding of paths. 'shareType' => PARAM_INT, 'shareWith' => PARAM_TEXT, // Name of receiving user/group. Required if SHARE_TYPE_USER. 'publicUpload' => PARAM_RAW, // Actually Boolean, but neither String-Boolean ('false') nor PARAM_BOOL (0/1). 'permissions' => PARAM_INT, 'shareWith' => PARAM_TEXT, 'expireDate' => PARAM_TEXT ], 'response' => 'text/xml' ], 'delete_share' => [ 'endpoint' => $this->build_share_url(), 'method' => 'delete', 'args' => [ 'share_id' => PARAM_INT ], 'response' => 'text/xml' ], 'get_shares' => [ 'endpoint' => $this->ocsendpoint->out(false), 'method' => 'get', 'args' => [ 'path' => PARAM_TEXT, 'reshares' => PARAM_RAW, // Returns not only the shares from the current user but all of the given file. 'subfiles' => PARAM_RAW, // Returns all shares within a folder, given that path defines a folder. ], 'response' => 'text/xml' ], 'get_information_of_share' => [ 'endpoint' => $this->build_share_url(), 'method' => 'get', 'args' => [ 'share_id' => PARAM_INT ], 'response' => 'text/xml' ], ]; }
[ "public", "function", "get_api_functions", "(", ")", "{", "return", "[", "'create_share'", "=>", "[", "'endpoint'", "=>", "$", "this", "->", "ocsendpoint", "->", "out", "(", "false", ")", ",", "'method'", "=>", "'post'", ",", "'args'", "=>", "[", "'path'", "=>", "PARAM_TEXT", ",", "// Could be PARAM_PATH, we really don't want to enforce a Moodle understanding of paths.", "'shareType'", "=>", "PARAM_INT", ",", "'shareWith'", "=>", "PARAM_TEXT", ",", "// Name of receiving user/group. Required if SHARE_TYPE_USER.", "'publicUpload'", "=>", "PARAM_RAW", ",", "// Actually Boolean, but neither String-Boolean ('false') nor PARAM_BOOL (0/1).", "'permissions'", "=>", "PARAM_INT", ",", "'shareWith'", "=>", "PARAM_TEXT", ",", "'expireDate'", "=>", "PARAM_TEXT", "]", ",", "'response'", "=>", "'text/xml'", "]", ",", "'delete_share'", "=>", "[", "'endpoint'", "=>", "$", "this", "->", "build_share_url", "(", ")", ",", "'method'", "=>", "'delete'", ",", "'args'", "=>", "[", "'share_id'", "=>", "PARAM_INT", "]", ",", "'response'", "=>", "'text/xml'", "]", ",", "'get_shares'", "=>", "[", "'endpoint'", "=>", "$", "this", "->", "ocsendpoint", "->", "out", "(", "false", ")", ",", "'method'", "=>", "'get'", ",", "'args'", "=>", "[", "'path'", "=>", "PARAM_TEXT", ",", "'reshares'", "=>", "PARAM_RAW", ",", "// Returns not only the shares from the current user but all of the given file.", "'subfiles'", "=>", "PARAM_RAW", ",", "// Returns all shares within a folder, given that path defines a folder.", "]", ",", "'response'", "=>", "'text/xml'", "]", ",", "'get_information_of_share'", "=>", "[", "'endpoint'", "=>", "$", "this", "->", "build_share_url", "(", ")", ",", "'method'", "=>", "'get'", ",", "'args'", "=>", "[", "'share_id'", "=>", "PARAM_INT", "]", ",", "'response'", "=>", "'text/xml'", "]", ",", "]", ";", "}" ]
Define relevant functions of the OCS API. Previously, the instruction to create a oauthclient recommended the user to enter the return format (format=xml). However, in this case the shareid is appended at the wrong place. Therefore, a new url is build which inserts the shareid at the suitable place for delete_share and get_information_of_share. create_share docs: https://docs.nextcloud.com/server/13/developer_manual/core/ocs-share-api.html#create-a-new-share
[ "Define", "relevant", "functions", "of", "the", "OCS", "API", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/classes/ocs_client.php#L96-L139
219,553
moodle/moodle
repository/nextcloud/classes/ocs_client.php
ocs_client.build_share_url
private function build_share_url() { // Out_omit_querystring() in combination with ocsendpoint->get_path() is not used since both function include // /ocs/v1.php. $shareurl = $this->ocsendpoint->get_scheme() . '://' . $this->ocsendpoint->get_host() . ':' . $this->ocsendpoint->get_port() . $this->ocsendpoint->get_path() . '/{share_id}?' . $this->ocsendpoint->get_query_string(false); return $shareurl; }
php
private function build_share_url() { // Out_omit_querystring() in combination with ocsendpoint->get_path() is not used since both function include // /ocs/v1.php. $shareurl = $this->ocsendpoint->get_scheme() . '://' . $this->ocsendpoint->get_host() . ':' . $this->ocsendpoint->get_port() . $this->ocsendpoint->get_path() . '/{share_id}?' . $this->ocsendpoint->get_query_string(false); return $shareurl; }
[ "private", "function", "build_share_url", "(", ")", "{", "// Out_omit_querystring() in combination with ocsendpoint->get_path() is not used since both function include", "// /ocs/v1.php.", "$", "shareurl", "=", "$", "this", "->", "ocsendpoint", "->", "get_scheme", "(", ")", ".", "'://'", ".", "$", "this", "->", "ocsendpoint", "->", "get_host", "(", ")", ".", "':'", ".", "$", "this", "->", "ocsendpoint", "->", "get_port", "(", ")", ".", "$", "this", "->", "ocsendpoint", "->", "get_path", "(", ")", ".", "'/{share_id}?'", ".", "$", "this", "->", "ocsendpoint", "->", "get_query_string", "(", "false", ")", ";", "return", "$", "shareurl", ";", "}" ]
Private Function to return a url with the shareid in the path. @return string
[ "Private", "Function", "to", "return", "a", "url", "with", "the", "shareid", "in", "the", "path", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/classes/ocs_client.php#L145-L152
219,554
moodle/moodle
repository/filesystem/classes/task/cron_task.php
cron_task.execute
public function execute() { global $CFG; require_once($CFG->dirroot . '/repository/lib.php'); $fs = get_file_storage(); // Find all generated thumbnails and group them in array by itemid (itemid == repository instance id). $allfiles = array_merge( $fs->get_area_files(SYSCONTEXTID, 'repository_filesystem', 'thumb'), $fs->get_area_files(SYSCONTEXTID, 'repository_filesystem', 'icon') ); $filesbyitem = array(); foreach ($allfiles as $file) { if (!isset($filesbyitem[$file->get_itemid()])) { $filesbyitem[$file->get_itemid()] = array(); } $filesbyitem[$file->get_itemid()][] = $file; } // Find all instances of repository_filesystem. $instances = \repository::get_instances(array('type' => 'filesystem')); // Loop through all itemids of generated thumbnails. foreach ($filesbyitem as $itemid => $files) { if (!isset($instances[$itemid]) || !($instances[$itemid] instanceof repository_filesystem)) { // Instance was deleted. $fs->delete_area_files(SYSCONTEXTID, 'repository_filesystem', 'thumb', $itemid); $fs->delete_area_files(SYSCONTEXTID, 'repository_filesystem', 'icon', $itemid); mtrace(" instance $itemid does not exist: deleted all thumbnails"); } else { // Instance has some generated thumbnails, check that they are not outdated. $instances[$itemid]->remove_obsolete_thumbnails($files); } } }
php
public function execute() { global $CFG; require_once($CFG->dirroot . '/repository/lib.php'); $fs = get_file_storage(); // Find all generated thumbnails and group them in array by itemid (itemid == repository instance id). $allfiles = array_merge( $fs->get_area_files(SYSCONTEXTID, 'repository_filesystem', 'thumb'), $fs->get_area_files(SYSCONTEXTID, 'repository_filesystem', 'icon') ); $filesbyitem = array(); foreach ($allfiles as $file) { if (!isset($filesbyitem[$file->get_itemid()])) { $filesbyitem[$file->get_itemid()] = array(); } $filesbyitem[$file->get_itemid()][] = $file; } // Find all instances of repository_filesystem. $instances = \repository::get_instances(array('type' => 'filesystem')); // Loop through all itemids of generated thumbnails. foreach ($filesbyitem as $itemid => $files) { if (!isset($instances[$itemid]) || !($instances[$itemid] instanceof repository_filesystem)) { // Instance was deleted. $fs->delete_area_files(SYSCONTEXTID, 'repository_filesystem', 'thumb', $itemid); $fs->delete_area_files(SYSCONTEXTID, 'repository_filesystem', 'icon', $itemid); mtrace(" instance $itemid does not exist: deleted all thumbnails"); } else { // Instance has some generated thumbnails, check that they are not outdated. $instances[$itemid]->remove_obsolete_thumbnails($files); } } }
[ "public", "function", "execute", "(", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/repository/lib.php'", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "// Find all generated thumbnails and group them in array by itemid (itemid == repository instance id).", "$", "allfiles", "=", "array_merge", "(", "$", "fs", "->", "get_area_files", "(", "SYSCONTEXTID", ",", "'repository_filesystem'", ",", "'thumb'", ")", ",", "$", "fs", "->", "get_area_files", "(", "SYSCONTEXTID", ",", "'repository_filesystem'", ",", "'icon'", ")", ")", ";", "$", "filesbyitem", "=", "array", "(", ")", ";", "foreach", "(", "$", "allfiles", "as", "$", "file", ")", "{", "if", "(", "!", "isset", "(", "$", "filesbyitem", "[", "$", "file", "->", "get_itemid", "(", ")", "]", ")", ")", "{", "$", "filesbyitem", "[", "$", "file", "->", "get_itemid", "(", ")", "]", "=", "array", "(", ")", ";", "}", "$", "filesbyitem", "[", "$", "file", "->", "get_itemid", "(", ")", "]", "[", "]", "=", "$", "file", ";", "}", "// Find all instances of repository_filesystem.", "$", "instances", "=", "\\", "repository", "::", "get_instances", "(", "array", "(", "'type'", "=>", "'filesystem'", ")", ")", ";", "// Loop through all itemids of generated thumbnails.", "foreach", "(", "$", "filesbyitem", "as", "$", "itemid", "=>", "$", "files", ")", "{", "if", "(", "!", "isset", "(", "$", "instances", "[", "$", "itemid", "]", ")", "||", "!", "(", "$", "instances", "[", "$", "itemid", "]", "instanceof", "repository_filesystem", ")", ")", "{", "// Instance was deleted.", "$", "fs", "->", "delete_area_files", "(", "SYSCONTEXTID", ",", "'repository_filesystem'", ",", "'thumb'", ",", "$", "itemid", ")", ";", "$", "fs", "->", "delete_area_files", "(", "SYSCONTEXTID", ",", "'repository_filesystem'", ",", "'icon'", ",", "$", "itemid", ")", ";", "mtrace", "(", "\" instance $itemid does not exist: deleted all thumbnails\"", ")", ";", "}", "else", "{", "// Instance has some generated thumbnails, check that they are not outdated.", "$", "instances", "[", "$", "itemid", "]", "->", "remove_obsolete_thumbnails", "(", "$", "files", ")", ";", "}", "}", "}" ]
Run file system repository cron.
[ "Run", "file", "system", "repository", "cron", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/filesystem/classes/task/cron_task.php#L40-L71
219,555
moodle/moodle
privacy/classes/local/sitepolicy/default_handler.php
default_handler.is_defined
public static function is_defined($forguests = false) { global $CFG; if (!empty($CFG->sitepolicyhandler)) { // This handler can also be used as a fallback in case of invalid $CFG->sitepolicyhandler, // in this case assume that no site policy is set. return false; } if (!$forguests) { return !empty($CFG->sitepolicy); } else { return !empty($CFG->sitepolicyguest); } }
php
public static function is_defined($forguests = false) { global $CFG; if (!empty($CFG->sitepolicyhandler)) { // This handler can also be used as a fallback in case of invalid $CFG->sitepolicyhandler, // in this case assume that no site policy is set. return false; } if (!$forguests) { return !empty($CFG->sitepolicy); } else { return !empty($CFG->sitepolicyguest); } }
[ "public", "static", "function", "is_defined", "(", "$", "forguests", "=", "false", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "sitepolicyhandler", ")", ")", "{", "// This handler can also be used as a fallback in case of invalid $CFG->sitepolicyhandler,", "// in this case assume that no site policy is set.", "return", "false", ";", "}", "if", "(", "!", "$", "forguests", ")", "{", "return", "!", "empty", "(", "$", "CFG", "->", "sitepolicy", ")", ";", "}", "else", "{", "return", "!", "empty", "(", "$", "CFG", "->", "sitepolicyguest", ")", ";", "}", "}" ]
Checks if the site has site policy defined @param bool $forguests @return bool
[ "Checks", "if", "the", "site", "has", "site", "policy", "defined" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/sitepolicy/default_handler.php#L46-L58
219,556
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.create_subscription
public static function create_subscription($ruleid, $courseid, $cmid, $userid = 0) { global $DB, $USER; $subscription = new \stdClass(); $subscription->ruleid = $ruleid; $subscription->courseid = $courseid; $subscription->cmid = $cmid; $subscription->userid = empty($userid) ? $USER->id : $userid; if ($DB->record_exists('tool_monitor_subscriptions', (array)$subscription)) { // Subscription already exists. return false; } $subscription->timecreated = time(); $subscription->id = $DB->insert_record('tool_monitor_subscriptions', $subscription); // Trigger a subscription created event. if ($subscription->id) { if (!empty($subscription->courseid)) { $courseid = $subscription->courseid; $context = \context_course::instance($subscription->courseid); } else { $courseid = 0; $context = \context_system::instance(); } $params = array( 'objectid' => $subscription->id, 'courseid' => $courseid, 'context' => $context ); $event = \tool_monitor\event\subscription_created::create($params); $event->trigger(); // Let's invalidate the cache. $cache = \cache::make('tool_monitor', 'eventsubscriptions'); $cache->delete($courseid); } return $subscription->id; }
php
public static function create_subscription($ruleid, $courseid, $cmid, $userid = 0) { global $DB, $USER; $subscription = new \stdClass(); $subscription->ruleid = $ruleid; $subscription->courseid = $courseid; $subscription->cmid = $cmid; $subscription->userid = empty($userid) ? $USER->id : $userid; if ($DB->record_exists('tool_monitor_subscriptions', (array)$subscription)) { // Subscription already exists. return false; } $subscription->timecreated = time(); $subscription->id = $DB->insert_record('tool_monitor_subscriptions', $subscription); // Trigger a subscription created event. if ($subscription->id) { if (!empty($subscription->courseid)) { $courseid = $subscription->courseid; $context = \context_course::instance($subscription->courseid); } else { $courseid = 0; $context = \context_system::instance(); } $params = array( 'objectid' => $subscription->id, 'courseid' => $courseid, 'context' => $context ); $event = \tool_monitor\event\subscription_created::create($params); $event->trigger(); // Let's invalidate the cache. $cache = \cache::make('tool_monitor', 'eventsubscriptions'); $cache->delete($courseid); } return $subscription->id; }
[ "public", "static", "function", "create_subscription", "(", "$", "ruleid", ",", "$", "courseid", ",", "$", "cmid", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "subscription", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "subscription", "->", "ruleid", "=", "$", "ruleid", ";", "$", "subscription", "->", "courseid", "=", "$", "courseid", ";", "$", "subscription", "->", "cmid", "=", "$", "cmid", ";", "$", "subscription", "->", "userid", "=", "empty", "(", "$", "userid", ")", "?", "$", "USER", "->", "id", ":", "$", "userid", ";", "if", "(", "$", "DB", "->", "record_exists", "(", "'tool_monitor_subscriptions'", ",", "(", "array", ")", "$", "subscription", ")", ")", "{", "// Subscription already exists.", "return", "false", ";", "}", "$", "subscription", "->", "timecreated", "=", "time", "(", ")", ";", "$", "subscription", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'tool_monitor_subscriptions'", ",", "$", "subscription", ")", ";", "// Trigger a subscription created event.", "if", "(", "$", "subscription", "->", "id", ")", "{", "if", "(", "!", "empty", "(", "$", "subscription", "->", "courseid", ")", ")", "{", "$", "courseid", "=", "$", "subscription", "->", "courseid", ";", "$", "context", "=", "\\", "context_course", "::", "instance", "(", "$", "subscription", "->", "courseid", ")", ";", "}", "else", "{", "$", "courseid", "=", "0", ";", "$", "context", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "}", "$", "params", "=", "array", "(", "'objectid'", "=>", "$", "subscription", "->", "id", ",", "'courseid'", "=>", "$", "courseid", ",", "'context'", "=>", "$", "context", ")", ";", "$", "event", "=", "\\", "tool_monitor", "\\", "event", "\\", "subscription_created", "::", "create", "(", "$", "params", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "// Let's invalidate the cache.", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'tool_monitor'", ",", "'eventsubscriptions'", ")", ";", "$", "cache", "->", "delete", "(", "$", "courseid", ")", ";", "}", "return", "$", "subscription", "->", "id", ";", "}" ]
Subscribe a user to a given rule. @param int $ruleid Rule id. @param int $courseid Course id. @param int $cmid Course module id. @param int $userid User who is subscribing, defaults to $USER. @return bool|int returns id of the created subscription.
[ "Subscribe", "a", "user", "to", "a", "given", "rule", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L52-L92
219,557
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.delete_subscription
public static function delete_subscription($subscriptionorid, $checkuser = true) { global $DB, $USER; if (is_object($subscriptionorid)) { $subscription = $subscriptionorid; } else { $subscription = self::get_subscription($subscriptionorid); } if ($checkuser && $subscription->userid != $USER->id) { throw new \coding_exception('Invalid subscription supplied'); } // Store the subscription before we delete it. $subscription = $DB->get_record('tool_monitor_subscriptions', array('id' => $subscription->id)); $success = $DB->delete_records('tool_monitor_subscriptions', array('id' => $subscription->id)); // If successful trigger a subscription_deleted event. if ($success) { if (!empty($subscription->courseid) && ($coursecontext = \context_course::instance($subscription->courseid, IGNORE_MISSING))) { $courseid = $subscription->courseid; $context = $coursecontext; } else { $courseid = 0; $context = \context_system::instance(); } $params = array( 'objectid' => $subscription->id, 'courseid' => $courseid, 'context' => $context ); $event = \tool_monitor\event\subscription_deleted::create($params); $event->add_record_snapshot('tool_monitor_subscriptions', $subscription); $event->trigger(); // Let's invalidate the cache. $cache = \cache::make('tool_monitor', 'eventsubscriptions'); $cache->delete($courseid); } return $success; }
php
public static function delete_subscription($subscriptionorid, $checkuser = true) { global $DB, $USER; if (is_object($subscriptionorid)) { $subscription = $subscriptionorid; } else { $subscription = self::get_subscription($subscriptionorid); } if ($checkuser && $subscription->userid != $USER->id) { throw new \coding_exception('Invalid subscription supplied'); } // Store the subscription before we delete it. $subscription = $DB->get_record('tool_monitor_subscriptions', array('id' => $subscription->id)); $success = $DB->delete_records('tool_monitor_subscriptions', array('id' => $subscription->id)); // If successful trigger a subscription_deleted event. if ($success) { if (!empty($subscription->courseid) && ($coursecontext = \context_course::instance($subscription->courseid, IGNORE_MISSING))) { $courseid = $subscription->courseid; $context = $coursecontext; } else { $courseid = 0; $context = \context_system::instance(); } $params = array( 'objectid' => $subscription->id, 'courseid' => $courseid, 'context' => $context ); $event = \tool_monitor\event\subscription_deleted::create($params); $event->add_record_snapshot('tool_monitor_subscriptions', $subscription); $event->trigger(); // Let's invalidate the cache. $cache = \cache::make('tool_monitor', 'eventsubscriptions'); $cache->delete($courseid); } return $success; }
[ "public", "static", "function", "delete_subscription", "(", "$", "subscriptionorid", ",", "$", "checkuser", "=", "true", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "if", "(", "is_object", "(", "$", "subscriptionorid", ")", ")", "{", "$", "subscription", "=", "$", "subscriptionorid", ";", "}", "else", "{", "$", "subscription", "=", "self", "::", "get_subscription", "(", "$", "subscriptionorid", ")", ";", "}", "if", "(", "$", "checkuser", "&&", "$", "subscription", "->", "userid", "!=", "$", "USER", "->", "id", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Invalid subscription supplied'", ")", ";", "}", "// Store the subscription before we delete it.", "$", "subscription", "=", "$", "DB", "->", "get_record", "(", "'tool_monitor_subscriptions'", ",", "array", "(", "'id'", "=>", "$", "subscription", "->", "id", ")", ")", ";", "$", "success", "=", "$", "DB", "->", "delete_records", "(", "'tool_monitor_subscriptions'", ",", "array", "(", "'id'", "=>", "$", "subscription", "->", "id", ")", ")", ";", "// If successful trigger a subscription_deleted event.", "if", "(", "$", "success", ")", "{", "if", "(", "!", "empty", "(", "$", "subscription", "->", "courseid", ")", "&&", "(", "$", "coursecontext", "=", "\\", "context_course", "::", "instance", "(", "$", "subscription", "->", "courseid", ",", "IGNORE_MISSING", ")", ")", ")", "{", "$", "courseid", "=", "$", "subscription", "->", "courseid", ";", "$", "context", "=", "$", "coursecontext", ";", "}", "else", "{", "$", "courseid", "=", "0", ";", "$", "context", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "}", "$", "params", "=", "array", "(", "'objectid'", "=>", "$", "subscription", "->", "id", ",", "'courseid'", "=>", "$", "courseid", ",", "'context'", "=>", "$", "context", ")", ";", "$", "event", "=", "\\", "tool_monitor", "\\", "event", "\\", "subscription_deleted", "::", "create", "(", "$", "params", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'tool_monitor_subscriptions'", ",", "$", "subscription", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "// Let's invalidate the cache.", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'tool_monitor'", ",", "'eventsubscriptions'", ")", ";", "$", "cache", "->", "delete", "(", "$", "courseid", ")", ";", "}", "return", "$", "success", ";", "}" ]
Delete a subscription. @param subscription|int $subscriptionorid an instance of subscription class or id. @param bool $checkuser Check if the subscription belongs to current user before deleting. @return bool @throws \coding_exception if $checkuser is true and the subscription doesn't belong to the current user.
[ "Delete", "a", "subscription", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L103-L145
219,558
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.remove_all_subscriptions_for_rule
public static function remove_all_subscriptions_for_rule($ruleid, $coursecontext = null) { global $DB; // Store all the subscriptions we have to delete. $subscriptions = $DB->get_recordset('tool_monitor_subscriptions', array('ruleid' => $ruleid)); // Now delete them. $success = $DB->delete_records('tool_monitor_subscriptions', array('ruleid' => $ruleid)); // If successful and there were subscriptions that were deleted trigger a subscription deleted event. if ($success && $subscriptions) { foreach ($subscriptions as $subscription) { // It is possible that we are deleting rules associated with a deleted course, so we should be // passing the context as the second parameter. if (!is_null($coursecontext)) { $context = $coursecontext; $courseid = $subscription->courseid; } else if (!empty($subscription->courseid) && ($coursecontext = \context_course::instance($subscription->courseid, IGNORE_MISSING))) { $courseid = $subscription->courseid; $context = $coursecontext; } else { $courseid = 0; $context = \context_system::instance(); } $params = array( 'objectid' => $subscription->id, 'courseid' => $courseid, 'context' => $context ); $event = \tool_monitor\event\subscription_deleted::create($params); $event->add_record_snapshot('tool_monitor_subscriptions', $subscription); $event->trigger(); // Let's invalidate the cache. $cache = \cache::make('tool_monitor', 'eventsubscriptions'); $cache->delete($courseid); } } $subscriptions->close(); return $success; }
php
public static function remove_all_subscriptions_for_rule($ruleid, $coursecontext = null) { global $DB; // Store all the subscriptions we have to delete. $subscriptions = $DB->get_recordset('tool_monitor_subscriptions', array('ruleid' => $ruleid)); // Now delete them. $success = $DB->delete_records('tool_monitor_subscriptions', array('ruleid' => $ruleid)); // If successful and there were subscriptions that were deleted trigger a subscription deleted event. if ($success && $subscriptions) { foreach ($subscriptions as $subscription) { // It is possible that we are deleting rules associated with a deleted course, so we should be // passing the context as the second parameter. if (!is_null($coursecontext)) { $context = $coursecontext; $courseid = $subscription->courseid; } else if (!empty($subscription->courseid) && ($coursecontext = \context_course::instance($subscription->courseid, IGNORE_MISSING))) { $courseid = $subscription->courseid; $context = $coursecontext; } else { $courseid = 0; $context = \context_system::instance(); } $params = array( 'objectid' => $subscription->id, 'courseid' => $courseid, 'context' => $context ); $event = \tool_monitor\event\subscription_deleted::create($params); $event->add_record_snapshot('tool_monitor_subscriptions', $subscription); $event->trigger(); // Let's invalidate the cache. $cache = \cache::make('tool_monitor', 'eventsubscriptions'); $cache->delete($courseid); } } $subscriptions->close(); return $success; }
[ "public", "static", "function", "remove_all_subscriptions_for_rule", "(", "$", "ruleid", ",", "$", "coursecontext", "=", "null", ")", "{", "global", "$", "DB", ";", "// Store all the subscriptions we have to delete.", "$", "subscriptions", "=", "$", "DB", "->", "get_recordset", "(", "'tool_monitor_subscriptions'", ",", "array", "(", "'ruleid'", "=>", "$", "ruleid", ")", ")", ";", "// Now delete them.", "$", "success", "=", "$", "DB", "->", "delete_records", "(", "'tool_monitor_subscriptions'", ",", "array", "(", "'ruleid'", "=>", "$", "ruleid", ")", ")", ";", "// If successful and there were subscriptions that were deleted trigger a subscription deleted event.", "if", "(", "$", "success", "&&", "$", "subscriptions", ")", "{", "foreach", "(", "$", "subscriptions", "as", "$", "subscription", ")", "{", "// It is possible that we are deleting rules associated with a deleted course, so we should be", "// passing the context as the second parameter.", "if", "(", "!", "is_null", "(", "$", "coursecontext", ")", ")", "{", "$", "context", "=", "$", "coursecontext", ";", "$", "courseid", "=", "$", "subscription", "->", "courseid", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "subscription", "->", "courseid", ")", "&&", "(", "$", "coursecontext", "=", "\\", "context_course", "::", "instance", "(", "$", "subscription", "->", "courseid", ",", "IGNORE_MISSING", ")", ")", ")", "{", "$", "courseid", "=", "$", "subscription", "->", "courseid", ";", "$", "context", "=", "$", "coursecontext", ";", "}", "else", "{", "$", "courseid", "=", "0", ";", "$", "context", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "}", "$", "params", "=", "array", "(", "'objectid'", "=>", "$", "subscription", "->", "id", ",", "'courseid'", "=>", "$", "courseid", ",", "'context'", "=>", "$", "context", ")", ";", "$", "event", "=", "\\", "tool_monitor", "\\", "event", "\\", "subscription_deleted", "::", "create", "(", "$", "params", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'tool_monitor_subscriptions'", ",", "$", "subscription", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "// Let's invalidate the cache.", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'tool_monitor'", ",", "'eventsubscriptions'", ")", ";", "$", "cache", "->", "delete", "(", "$", "courseid", ")", ";", "}", "}", "$", "subscriptions", "->", "close", "(", ")", ";", "return", "$", "success", ";", "}" ]
Delete all subscribers for a given rule. @param int $ruleid rule id. @param \context|null $coursecontext the context of the course - this is passed when we can not get the context via \context_course as the course has been deleted. @return bool
[ "Delete", "all", "subscribers", "for", "a", "given", "rule", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L180-L224
219,559
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.remove_all_subscriptions_in_course
public static function remove_all_subscriptions_in_course($coursecontext) { global $DB; // Store all the subscriptions we have to delete. if ($subscriptions = $DB->get_records('tool_monitor_subscriptions', ['courseid' => $coursecontext->instanceid])) { // Delete subscriptions in bulk. $DB->delete_records('tool_monitor_subscriptions', ['courseid' => $coursecontext->instanceid]); // Trigger events one by one. foreach ($subscriptions as $subscription) { $params = ['objectid' => $subscription->id, 'context' => $coursecontext]; $event = \tool_monitor\event\subscription_deleted::create($params); $event->add_record_snapshot('tool_monitor_subscriptions', $subscription); $event->trigger(); } } }
php
public static function remove_all_subscriptions_in_course($coursecontext) { global $DB; // Store all the subscriptions we have to delete. if ($subscriptions = $DB->get_records('tool_monitor_subscriptions', ['courseid' => $coursecontext->instanceid])) { // Delete subscriptions in bulk. $DB->delete_records('tool_monitor_subscriptions', ['courseid' => $coursecontext->instanceid]); // Trigger events one by one. foreach ($subscriptions as $subscription) { $params = ['objectid' => $subscription->id, 'context' => $coursecontext]; $event = \tool_monitor\event\subscription_deleted::create($params); $event->add_record_snapshot('tool_monitor_subscriptions', $subscription); $event->trigger(); } } }
[ "public", "static", "function", "remove_all_subscriptions_in_course", "(", "$", "coursecontext", ")", "{", "global", "$", "DB", ";", "// Store all the subscriptions we have to delete.", "if", "(", "$", "subscriptions", "=", "$", "DB", "->", "get_records", "(", "'tool_monitor_subscriptions'", ",", "[", "'courseid'", "=>", "$", "coursecontext", "->", "instanceid", "]", ")", ")", "{", "// Delete subscriptions in bulk.", "$", "DB", "->", "delete_records", "(", "'tool_monitor_subscriptions'", ",", "[", "'courseid'", "=>", "$", "coursecontext", "->", "instanceid", "]", ")", ";", "// Trigger events one by one.", "foreach", "(", "$", "subscriptions", "as", "$", "subscription", ")", "{", "$", "params", "=", "[", "'objectid'", "=>", "$", "subscription", "->", "id", ",", "'context'", "=>", "$", "coursecontext", "]", ";", "$", "event", "=", "\\", "tool_monitor", "\\", "event", "\\", "subscription_deleted", "::", "create", "(", "$", "params", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'tool_monitor_subscriptions'", ",", "$", "subscription", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}", "}", "}" ]
Delete all subscriptions in a course. This is called after a course was deleted, context no longer exists but we kept the object @param \context_course $coursecontext the context of the course
[ "Delete", "all", "subscriptions", "in", "a", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L233-L249
219,560
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.get_subscription
public static function get_subscription($subscriptionorid) { global $DB; if (is_object($subscriptionorid)) { return new subscription($subscriptionorid); } $sql = self::get_subscription_join_rule_sql(); $sql .= "WHERE s.id = :id"; $sub = $DB->get_record_sql($sql, array('id' => $subscriptionorid), MUST_EXIST); return new subscription($sub); }
php
public static function get_subscription($subscriptionorid) { global $DB; if (is_object($subscriptionorid)) { return new subscription($subscriptionorid); } $sql = self::get_subscription_join_rule_sql(); $sql .= "WHERE s.id = :id"; $sub = $DB->get_record_sql($sql, array('id' => $subscriptionorid), MUST_EXIST); return new subscription($sub); }
[ "public", "static", "function", "get_subscription", "(", "$", "subscriptionorid", ")", "{", "global", "$", "DB", ";", "if", "(", "is_object", "(", "$", "subscriptionorid", ")", ")", "{", "return", "new", "subscription", "(", "$", "subscriptionorid", ")", ";", "}", "$", "sql", "=", "self", "::", "get_subscription_join_rule_sql", "(", ")", ";", "$", "sql", ".=", "\"WHERE s.id = :id\"", ";", "$", "sub", "=", "$", "DB", "->", "get_record_sql", "(", "$", "sql", ",", "array", "(", "'id'", "=>", "$", "subscriptionorid", ")", ",", "MUST_EXIST", ")", ";", "return", "new", "subscription", "(", "$", "sub", ")", ";", "}" ]
Get a subscription instance for an given subscription id. @param subscription|int $subscriptionorid an instance of subscription class or id. @return subscription returns a instance of subscription class.
[ "Get", "a", "subscription", "instance", "for", "an", "given", "subscription", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L258-L269
219,561
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.get_user_subscriptions_for_course
public static function get_user_subscriptions_for_course($courseid, $limitfrom = 0, $limitto = 0, $userid = 0, $order = 's.timecreated DESC' ) { global $DB, $USER; if ($userid == 0) { $userid = $USER->id; } $sql = self::get_subscription_join_rule_sql(); $sql .= "WHERE s.courseid = :courseid AND s.userid = :userid ORDER BY $order"; return self::get_instances($DB->get_records_sql($sql, array('courseid' => $courseid, 'userid' => $userid), $limitfrom, $limitto)); }
php
public static function get_user_subscriptions_for_course($courseid, $limitfrom = 0, $limitto = 0, $userid = 0, $order = 's.timecreated DESC' ) { global $DB, $USER; if ($userid == 0) { $userid = $USER->id; } $sql = self::get_subscription_join_rule_sql(); $sql .= "WHERE s.courseid = :courseid AND s.userid = :userid ORDER BY $order"; return self::get_instances($DB->get_records_sql($sql, array('courseid' => $courseid, 'userid' => $userid), $limitfrom, $limitto)); }
[ "public", "static", "function", "get_user_subscriptions_for_course", "(", "$", "courseid", ",", "$", "limitfrom", "=", "0", ",", "$", "limitto", "=", "0", ",", "$", "userid", "=", "0", ",", "$", "order", "=", "'s.timecreated DESC'", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "if", "(", "$", "userid", "==", "0", ")", "{", "$", "userid", "=", "$", "USER", "->", "id", ";", "}", "$", "sql", "=", "self", "::", "get_subscription_join_rule_sql", "(", ")", ";", "$", "sql", ".=", "\"WHERE s.courseid = :courseid AND s.userid = :userid ORDER BY $order\"", ";", "return", "self", "::", "get_instances", "(", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "array", "(", "'courseid'", "=>", "$", "courseid", ",", "'userid'", "=>", "$", "userid", ")", ",", "$", "limitfrom", ",", "$", "limitto", ")", ")", ";", "}" ]
Get an array of subscriptions for a given user in a given course. @param int $courseid course id. @param int $limitfrom Limit from which to fetch rules. @param int $limitto Limit to which rules need to be fetched. @param int $userid Id of the user for which the subscription needs to be fetched. Defaults to $USER; @param string $order Order to sort the subscriptions. @return array list of subscriptions
[ "Get", "an", "array", "of", "subscriptions", "for", "a", "given", "user", "in", "a", "given", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L282-L293
219,562
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.count_user_subscriptions_for_course
public static function count_user_subscriptions_for_course($courseid, $userid = 0) { global $DB, $USER; if ($userid == 0) { $userid = $USER->id; } $sql = self::get_subscription_join_rule_sql(true); $sql .= "WHERE s.courseid = :courseid AND s.userid = :userid"; return $DB->count_records_sql($sql, array('courseid' => $courseid, 'userid' => $userid)); }
php
public static function count_user_subscriptions_for_course($courseid, $userid = 0) { global $DB, $USER; if ($userid == 0) { $userid = $USER->id; } $sql = self::get_subscription_join_rule_sql(true); $sql .= "WHERE s.courseid = :courseid AND s.userid = :userid"; return $DB->count_records_sql($sql, array('courseid' => $courseid, 'userid' => $userid)); }
[ "public", "static", "function", "count_user_subscriptions_for_course", "(", "$", "courseid", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "if", "(", "$", "userid", "==", "0", ")", "{", "$", "userid", "=", "$", "USER", "->", "id", ";", "}", "$", "sql", "=", "self", "::", "get_subscription_join_rule_sql", "(", "true", ")", ";", "$", "sql", ".=", "\"WHERE s.courseid = :courseid AND s.userid = :userid\"", ";", "return", "$", "DB", "->", "count_records_sql", "(", "$", "sql", ",", "array", "(", "'courseid'", "=>", "$", "courseid", ",", "'userid'", "=>", "$", "userid", ")", ")", ";", "}" ]
Get count of subscriptions for a given user in a given course. @param int $courseid course id. @param int $userid Id of the user for which the subscription needs to be fetched. Defaults to $USER; @return int number of subscriptions
[ "Get", "count", "of", "subscriptions", "for", "a", "given", "user", "in", "a", "given", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L303-L312
219,563
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.count_user_subscriptions
public static function count_user_subscriptions($userid = 0) { global $DB, $USER;; if ($userid == 0) { $userid = $USER->id; } $sql = self::get_subscription_join_rule_sql(true); $sql .= "WHERE s.userid = :userid"; return $DB->count_records_sql($sql, array('userid' => $userid)); }
php
public static function count_user_subscriptions($userid = 0) { global $DB, $USER;; if ($userid == 0) { $userid = $USER->id; } $sql = self::get_subscription_join_rule_sql(true); $sql .= "WHERE s.userid = :userid"; return $DB->count_records_sql($sql, array('userid' => $userid)); }
[ "public", "static", "function", "count_user_subscriptions", "(", "$", "userid", "=", "0", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", ";", "if", "(", "$", "userid", "==", "0", ")", "{", "$", "userid", "=", "$", "USER", "->", "id", ";", "}", "$", "sql", "=", "self", "::", "get_subscription_join_rule_sql", "(", "true", ")", ";", "$", "sql", ".=", "\"WHERE s.userid = :userid\"", ";", "return", "$", "DB", "->", "count_records_sql", "(", "$", "sql", ",", "array", "(", "'userid'", "=>", "$", "userid", ")", ")", ";", "}" ]
Get count of subscriptions for a given user. @param int $userid Id of the user for which the subscription needs to be fetched. Defaults to $USER; @return int number of subscriptions
[ "Get", "count", "of", "subscriptions", "for", "a", "given", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L343-L352
219,564
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.get_subscriptions_by_event
public static function get_subscriptions_by_event(\stdClass $event) { global $DB; $sql = self::get_subscription_join_rule_sql(); if ($event->contextlevel == CONTEXT_MODULE && $event->contextinstanceid != 0) { $sql .= "WHERE r.eventname = :eventname AND s.courseid = :courseid AND (s.cmid = :cmid OR s.cmid = 0)"; $params = array('eventname' => $event->eventname, 'courseid' => $event->courseid, 'cmid' => $event->contextinstanceid); } else { $sql .= "WHERE r.eventname = :eventname AND (s.courseid = :courseid OR s.courseid = 0)"; $params = array('eventname' => $event->eventname, 'courseid' => $event->courseid); } return self::get_instances($DB->get_records_sql($sql, $params)); }
php
public static function get_subscriptions_by_event(\stdClass $event) { global $DB; $sql = self::get_subscription_join_rule_sql(); if ($event->contextlevel == CONTEXT_MODULE && $event->contextinstanceid != 0) { $sql .= "WHERE r.eventname = :eventname AND s.courseid = :courseid AND (s.cmid = :cmid OR s.cmid = 0)"; $params = array('eventname' => $event->eventname, 'courseid' => $event->courseid, 'cmid' => $event->contextinstanceid); } else { $sql .= "WHERE r.eventname = :eventname AND (s.courseid = :courseid OR s.courseid = 0)"; $params = array('eventname' => $event->eventname, 'courseid' => $event->courseid); } return self::get_instances($DB->get_records_sql($sql, $params)); }
[ "public", "static", "function", "get_subscriptions_by_event", "(", "\\", "stdClass", "$", "event", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "self", "::", "get_subscription_join_rule_sql", "(", ")", ";", "if", "(", "$", "event", "->", "contextlevel", "==", "CONTEXT_MODULE", "&&", "$", "event", "->", "contextinstanceid", "!=", "0", ")", "{", "$", "sql", ".=", "\"WHERE r.eventname = :eventname AND s.courseid = :courseid AND (s.cmid = :cmid OR s.cmid = 0)\"", ";", "$", "params", "=", "array", "(", "'eventname'", "=>", "$", "event", "->", "eventname", ",", "'courseid'", "=>", "$", "event", "->", "courseid", ",", "'cmid'", "=>", "$", "event", "->", "contextinstanceid", ")", ";", "}", "else", "{", "$", "sql", ".=", "\"WHERE r.eventname = :eventname AND (s.courseid = :courseid OR s.courseid = 0)\"", ";", "$", "params", "=", "array", "(", "'eventname'", "=>", "$", "event", "->", "eventname", ",", "'courseid'", "=>", "$", "event", "->", "courseid", ")", ";", "}", "return", "self", "::", "get_instances", "(", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ")", ";", "}" ]
Return a list of subscriptions for a given event. @param \stdClass $event the event object. @return array
[ "Return", "a", "list", "of", "subscriptions", "for", "a", "given", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L361-L373
219,565
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.count_rule_subscriptions
public static function count_rule_subscriptions($ruleid) { global $DB; $sql = self::get_subscription_join_rule_sql(true); $sql .= "WHERE s.ruleid = :ruleid"; return $DB->count_records_sql($sql, array('ruleid' => $ruleid)); }
php
public static function count_rule_subscriptions($ruleid) { global $DB; $sql = self::get_subscription_join_rule_sql(true); $sql .= "WHERE s.ruleid = :ruleid"; return $DB->count_records_sql($sql, array('ruleid' => $ruleid)); }
[ "public", "static", "function", "count_rule_subscriptions", "(", "$", "ruleid", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "self", "::", "get_subscription_join_rule_sql", "(", "true", ")", ";", "$", "sql", ".=", "\"WHERE s.ruleid = :ruleid\"", ";", "return", "$", "DB", "->", "count_records_sql", "(", "$", "sql", ",", "array", "(", "'ruleid'", "=>", "$", "ruleid", ")", ")", ";", "}" ]
Get count of subscriptions for a given rule. @param int $ruleid rule id of the subscription. @return int number of subscriptions
[ "Get", "count", "of", "subscriptions", "for", "a", "given", "rule", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L418-L424
219,566
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.event_has_subscriptions
public static function event_has_subscriptions($eventname, $courseid) { global $DB; // Check if we can return these from cache. $cache = \cache::make('tool_monitor', 'eventsubscriptions'); // The SQL we will be using to fill the cache if it is empty. $sql = "SELECT DISTINCT(r.eventname) FROM {tool_monitor_subscriptions} s INNER JOIN {tool_monitor_rules} r ON s.ruleid = r.id WHERE s.courseid = :courseid"; $sitesubscriptions = $cache->get(0); // If we do not have the site subscriptions in the cache then return them from the DB. if ($sitesubscriptions === false) { // Set the array for the cache. $sitesubscriptions = array(); if ($subscriptions = $DB->get_records_sql($sql, array('courseid' => 0))) { foreach ($subscriptions as $subscription) { $sitesubscriptions[$subscription->eventname] = true; } } $cache->set(0, $sitesubscriptions); } // Check if a subscription exists for this event site wide. if (isset($sitesubscriptions[$eventname])) { return true; } // If the course id is for the site, and we reached here then there is no site wide subscription for this event. if (empty($courseid)) { return false; } $coursesubscriptions = $cache->get($courseid); // If we do not have the course subscriptions in the cache then return them from the DB. if ($coursesubscriptions === false) { // Set the array for the cache. $coursesubscriptions = array(); if ($subscriptions = $DB->get_records_sql($sql, array('courseid' => $courseid))) { foreach ($subscriptions as $subscription) { $coursesubscriptions[$subscription->eventname] = true; } } $cache->set($courseid, $coursesubscriptions); } // Check if a subscription exists for this event in this course. if (isset($coursesubscriptions[$eventname])) { return true; } return false; }
php
public static function event_has_subscriptions($eventname, $courseid) { global $DB; // Check if we can return these from cache. $cache = \cache::make('tool_monitor', 'eventsubscriptions'); // The SQL we will be using to fill the cache if it is empty. $sql = "SELECT DISTINCT(r.eventname) FROM {tool_monitor_subscriptions} s INNER JOIN {tool_monitor_rules} r ON s.ruleid = r.id WHERE s.courseid = :courseid"; $sitesubscriptions = $cache->get(0); // If we do not have the site subscriptions in the cache then return them from the DB. if ($sitesubscriptions === false) { // Set the array for the cache. $sitesubscriptions = array(); if ($subscriptions = $DB->get_records_sql($sql, array('courseid' => 0))) { foreach ($subscriptions as $subscription) { $sitesubscriptions[$subscription->eventname] = true; } } $cache->set(0, $sitesubscriptions); } // Check if a subscription exists for this event site wide. if (isset($sitesubscriptions[$eventname])) { return true; } // If the course id is for the site, and we reached here then there is no site wide subscription for this event. if (empty($courseid)) { return false; } $coursesubscriptions = $cache->get($courseid); // If we do not have the course subscriptions in the cache then return them from the DB. if ($coursesubscriptions === false) { // Set the array for the cache. $coursesubscriptions = array(); if ($subscriptions = $DB->get_records_sql($sql, array('courseid' => $courseid))) { foreach ($subscriptions as $subscription) { $coursesubscriptions[$subscription->eventname] = true; } } $cache->set($courseid, $coursesubscriptions); } // Check if a subscription exists for this event in this course. if (isset($coursesubscriptions[$eventname])) { return true; } return false; }
[ "public", "static", "function", "event_has_subscriptions", "(", "$", "eventname", ",", "$", "courseid", ")", "{", "global", "$", "DB", ";", "// Check if we can return these from cache.", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'tool_monitor'", ",", "'eventsubscriptions'", ")", ";", "// The SQL we will be using to fill the cache if it is empty.", "$", "sql", "=", "\"SELECT DISTINCT(r.eventname)\n FROM {tool_monitor_subscriptions} s\n INNER JOIN {tool_monitor_rules} r\n ON s.ruleid = r.id\n WHERE s.courseid = :courseid\"", ";", "$", "sitesubscriptions", "=", "$", "cache", "->", "get", "(", "0", ")", ";", "// If we do not have the site subscriptions in the cache then return them from the DB.", "if", "(", "$", "sitesubscriptions", "===", "false", ")", "{", "// Set the array for the cache.", "$", "sitesubscriptions", "=", "array", "(", ")", ";", "if", "(", "$", "subscriptions", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "array", "(", "'courseid'", "=>", "0", ")", ")", ")", "{", "foreach", "(", "$", "subscriptions", "as", "$", "subscription", ")", "{", "$", "sitesubscriptions", "[", "$", "subscription", "->", "eventname", "]", "=", "true", ";", "}", "}", "$", "cache", "->", "set", "(", "0", ",", "$", "sitesubscriptions", ")", ";", "}", "// Check if a subscription exists for this event site wide.", "if", "(", "isset", "(", "$", "sitesubscriptions", "[", "$", "eventname", "]", ")", ")", "{", "return", "true", ";", "}", "// If the course id is for the site, and we reached here then there is no site wide subscription for this event.", "if", "(", "empty", "(", "$", "courseid", ")", ")", "{", "return", "false", ";", "}", "$", "coursesubscriptions", "=", "$", "cache", "->", "get", "(", "$", "courseid", ")", ";", "// If we do not have the course subscriptions in the cache then return them from the DB.", "if", "(", "$", "coursesubscriptions", "===", "false", ")", "{", "// Set the array for the cache.", "$", "coursesubscriptions", "=", "array", "(", ")", ";", "if", "(", "$", "subscriptions", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "array", "(", "'courseid'", "=>", "$", "courseid", ")", ")", ")", "{", "foreach", "(", "$", "subscriptions", "as", "$", "subscription", ")", "{", "$", "coursesubscriptions", "[", "$", "subscription", "->", "eventname", "]", "=", "true", ";", "}", "}", "$", "cache", "->", "set", "(", "$", "courseid", ",", "$", "coursesubscriptions", ")", ";", "}", "// Check if a subscription exists for this event in this course.", "if", "(", "isset", "(", "$", "coursesubscriptions", "[", "$", "eventname", "]", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Returns true if an event in a particular course has a subscription. @param string $eventname the name of the event @param int $courseid the course id @return bool returns true if the event has subscriptions in a given course, false otherwise.
[ "Returns", "true", "if", "an", "event", "in", "a", "particular", "course", "has", "a", "subscription", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L433-L488
219,567
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.activate_subscriptions
public static function activate_subscriptions(array $ids) { global $DB; if (!empty($ids)) { list($sql, $params) = $DB->get_in_or_equal($ids); $success = $DB->set_field_select('tool_monitor_subscriptions', 'inactivedate', '0', 'id ' . $sql, $params); return $success; } return false; }
php
public static function activate_subscriptions(array $ids) { global $DB; if (!empty($ids)) { list($sql, $params) = $DB->get_in_or_equal($ids); $success = $DB->set_field_select('tool_monitor_subscriptions', 'inactivedate', '0', 'id ' . $sql, $params); return $success; } return false; }
[ "public", "static", "function", "activate_subscriptions", "(", "array", "$", "ids", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "empty", "(", "$", "ids", ")", ")", "{", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "ids", ")", ";", "$", "success", "=", "$", "DB", "->", "set_field_select", "(", "'tool_monitor_subscriptions'", ",", "'inactivedate'", ",", "'0'", ",", "'id '", ".", "$", "sql", ",", "$", "params", ")", ";", "return", "$", "success", ";", "}", "return", "false", ";", "}" ]
Activates a group of subscriptions based on an input array of ids. @since 3.2.0 @param array $ids of subscription ids. @return bool true if the operation was successful, false otherwise.
[ "Activates", "a", "group", "of", "subscriptions", "based", "on", "an", "input", "array", "of", "ids", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L497-L505
219,568
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.deactivate_subscriptions
public static function deactivate_subscriptions(array $ids) { global $DB; if (!empty($ids)) { $inactivedate = time(); list($sql, $params) = $DB->get_in_or_equal($ids); $success = $DB->set_field_select('tool_monitor_subscriptions', 'inactivedate', $inactivedate, 'id ' . $sql, $params); return $success; } return false; }
php
public static function deactivate_subscriptions(array $ids) { global $DB; if (!empty($ids)) { $inactivedate = time(); list($sql, $params) = $DB->get_in_or_equal($ids); $success = $DB->set_field_select('tool_monitor_subscriptions', 'inactivedate', $inactivedate, 'id ' . $sql, $params); return $success; } return false; }
[ "public", "static", "function", "deactivate_subscriptions", "(", "array", "$", "ids", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "empty", "(", "$", "ids", ")", ")", "{", "$", "inactivedate", "=", "time", "(", ")", ";", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "ids", ")", ";", "$", "success", "=", "$", "DB", "->", "set_field_select", "(", "'tool_monitor_subscriptions'", ",", "'inactivedate'", ",", "$", "inactivedate", ",", "'id '", ".", "$", "sql", ",", "$", "params", ")", ";", "return", "$", "success", ";", "}", "return", "false", ";", "}" ]
Deactivates a group of subscriptions based on an input array of ids. @since 3.2.0 @param array $ids of subscription ids. @return bool true if the operation was successful, false otherwise.
[ "Deactivates", "a", "group", "of", "subscriptions", "based", "on", "an", "input", "array", "of", "ids", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L514-L524
219,569
moodle/moodle
admin/tool/monitor/classes/subscription_manager.php
subscription_manager.delete_stale_subscriptions
public static function delete_stale_subscriptions($userid = 0) { global $DB; // Get the expiry duration, in days. $cutofftime = strtotime("-" . self::INACTIVE_SUBSCRIPTION_LIFESPAN_IN_DAYS . " days", time()); if (!empty($userid)) { // Remove any stale subscriptions for the desired user only. $success = $DB->delete_records_select('tool_monitor_subscriptions', 'userid = ? AND inactivedate < ? AND inactivedate <> 0', array($userid, $cutofftime)); } else { // Remove all stale subscriptions. $success = $DB->delete_records_select('tool_monitor_subscriptions', 'inactivedate < ? AND inactivedate <> 0', array($cutofftime)); } return $success; }
php
public static function delete_stale_subscriptions($userid = 0) { global $DB; // Get the expiry duration, in days. $cutofftime = strtotime("-" . self::INACTIVE_SUBSCRIPTION_LIFESPAN_IN_DAYS . " days", time()); if (!empty($userid)) { // Remove any stale subscriptions for the desired user only. $success = $DB->delete_records_select('tool_monitor_subscriptions', 'userid = ? AND inactivedate < ? AND inactivedate <> 0', array($userid, $cutofftime)); } else { // Remove all stale subscriptions. $success = $DB->delete_records_select('tool_monitor_subscriptions', 'inactivedate < ? AND inactivedate <> 0', array($cutofftime)); } return $success; }
[ "public", "static", "function", "delete_stale_subscriptions", "(", "$", "userid", "=", "0", ")", "{", "global", "$", "DB", ";", "// Get the expiry duration, in days.", "$", "cutofftime", "=", "strtotime", "(", "\"-\"", ".", "self", "::", "INACTIVE_SUBSCRIPTION_LIFESPAN_IN_DAYS", ".", "\" days\"", ",", "time", "(", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "userid", ")", ")", "{", "// Remove any stale subscriptions for the desired user only.", "$", "success", "=", "$", "DB", "->", "delete_records_select", "(", "'tool_monitor_subscriptions'", ",", "'userid = ? AND inactivedate < ? AND inactivedate <> 0'", ",", "array", "(", "$", "userid", ",", "$", "cutofftime", ")", ")", ";", "}", "else", "{", "// Remove all stale subscriptions.", "$", "success", "=", "$", "DB", "->", "delete_records_select", "(", "'tool_monitor_subscriptions'", ",", "'inactivedate < ? AND inactivedate <> 0'", ",", "array", "(", "$", "cutofftime", ")", ")", ";", "}", "return", "$", "success", ";", "}" ]
Deletes subscriptions which have been inactive for a period of time. @since 3.2.0 @param int $userid if provided, only this user's stale subscriptions will be deleted. @return bool true if the operation was successful, false otherwise.
[ "Deletes", "subscriptions", "which", "have", "been", "inactive", "for", "a", "period", "of", "time", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription_manager.php#L533-L551
219,570
moodle/moodle
lib/htmlpurifier/HTMLPurifier/PercentEncoder.php
HTMLPurifier_PercentEncoder.encode
public function encode($string) { $ret = ''; for ($i = 0, $c = strlen($string); $i < $c; $i++) { if ($string[$i] !== '%' && !isset($this->preserve[$int = ord($string[$i])])) { $ret .= '%' . sprintf('%02X', $int); } else { $ret .= $string[$i]; } } return $ret; }
php
public function encode($string) { $ret = ''; for ($i = 0, $c = strlen($string); $i < $c; $i++) { if ($string[$i] !== '%' && !isset($this->preserve[$int = ord($string[$i])])) { $ret .= '%' . sprintf('%02X', $int); } else { $ret .= $string[$i]; } } return $ret; }
[ "public", "function", "encode", "(", "$", "string", ")", "{", "$", "ret", "=", "''", ";", "for", "(", "$", "i", "=", "0", ",", "$", "c", "=", "strlen", "(", "$", "string", ")", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "if", "(", "$", "string", "[", "$", "i", "]", "!==", "'%'", "&&", "!", "isset", "(", "$", "this", "->", "preserve", "[", "$", "int", "=", "ord", "(", "$", "string", "[", "$", "i", "]", ")", "]", ")", ")", "{", "$", "ret", ".=", "'%'", ".", "sprintf", "(", "'%02X'", ",", "$", "int", ")", ";", "}", "else", "{", "$", "ret", ".=", "$", "string", "[", "$", "i", "]", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Our replacement for urlencode, it encodes all non-reserved characters, as well as any extra characters that were instructed to be preserved. @note Assumes that the string has already been normalized, making any and all percent escape sequences valid. Percents will not be re-escaped, regardless of their status in $preserve @param string $string String to be encoded @return string Encoded string.
[ "Our", "replacement", "for", "urlencode", "it", "encodes", "all", "non", "-", "reserved", "characters", "as", "well", "as", "any", "extra", "characters", "that", "were", "instructed", "to", "be", "preserved", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/PercentEncoder.php#L59-L70
219,571
moodle/moodle
customfield/field/textarea/classes/data_controller.php
data_controller.value_editor_options
protected function value_editor_options() { /** @var field_controller $field */ $field = $this->get_field(); return $field->value_editor_options($this->get('id') ? $this->get_context() : null); }
php
protected function value_editor_options() { /** @var field_controller $field */ $field = $this->get_field(); return $field->value_editor_options($this->get('id') ? $this->get_context() : null); }
[ "protected", "function", "value_editor_options", "(", ")", "{", "/** @var field_controller $field */", "$", "field", "=", "$", "this", "->", "get_field", "(", ")", ";", "return", "$", "field", "->", "value_editor_options", "(", "$", "this", "->", "get", "(", "'id'", ")", "?", "$", "this", "->", "get_context", "(", ")", ":", "null", ")", ";", "}" ]
Options for the editor @return array
[ "Options", "for", "the", "editor" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/field/textarea/classes/data_controller.php#L51-L55
219,572
moodle/moodle
backup/util/ui/base_ui_stage.class.php
base_ui_stage.display
public function display(core_backup_renderer $renderer) { $form = $this->initialise_stage_form(); // A nasty hack follows to work around the sad fact that moodle quickforms // do not allow to actually return the HTML content, just to echo it. flush(); ob_start(); $form->display(); $output = ob_get_contents(); ob_end_clean(); return $output; }
php
public function display(core_backup_renderer $renderer) { $form = $this->initialise_stage_form(); // A nasty hack follows to work around the sad fact that moodle quickforms // do not allow to actually return the HTML content, just to echo it. flush(); ob_start(); $form->display(); $output = ob_get_contents(); ob_end_clean(); return $output; }
[ "public", "function", "display", "(", "core_backup_renderer", "$", "renderer", ")", "{", "$", "form", "=", "$", "this", "->", "initialise_stage_form", "(", ")", ";", "// A nasty hack follows to work around the sad fact that moodle quickforms", "// do not allow to actually return the HTML content, just to echo it.", "flush", "(", ")", ";", "ob_start", "(", ")", ";", "$", "form", "->", "display", "(", ")", ";", "$", "output", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "return", "$", "output", ";", "}" ]
Displays the stage. By default this involves instantiating the form for the stage and the calling it to display. @param core_backup_renderer $renderer @return string HTML code to echo
[ "Displays", "the", "stage", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_ui_stage.class.php#L135-L147
219,573
moodle/moodle
backup/moodle2/backup_qtype_plugin.class.php
backup_qtype_plugin.get_components_and_fileareas
public static function get_components_and_fileareas($filter = null) { $components = array(); // Get all the plugins of this type $qtypes = core_component::get_plugin_list('qtype'); foreach ($qtypes as $name => $path) { // Apply filter if specified if (!is_null($filter) && $filter != $name) { continue; } // Calculate the componentname $componentname = 'qtype_' . $name; // Get the plugin fileareas (all them MUST belong to the same component) $classname = 'backup_qtype_' . $name . '_plugin'; if (class_exists($classname)) { $elements = call_user_func(array($classname, 'get_qtype_fileareas')); if ($elements) { // If there are elements, add them to $components $components[$componentname] = $elements; } } } return $components; }
php
public static function get_components_and_fileareas($filter = null) { $components = array(); // Get all the plugins of this type $qtypes = core_component::get_plugin_list('qtype'); foreach ($qtypes as $name => $path) { // Apply filter if specified if (!is_null($filter) && $filter != $name) { continue; } // Calculate the componentname $componentname = 'qtype_' . $name; // Get the plugin fileareas (all them MUST belong to the same component) $classname = 'backup_qtype_' . $name . '_plugin'; if (class_exists($classname)) { $elements = call_user_func(array($classname, 'get_qtype_fileareas')); if ($elements) { // If there are elements, add them to $components $components[$componentname] = $elements; } } } return $components; }
[ "public", "static", "function", "get_components_and_fileareas", "(", "$", "filter", "=", "null", ")", "{", "$", "components", "=", "array", "(", ")", ";", "// Get all the plugins of this type", "$", "qtypes", "=", "core_component", "::", "get_plugin_list", "(", "'qtype'", ")", ";", "foreach", "(", "$", "qtypes", "as", "$", "name", "=>", "$", "path", ")", "{", "// Apply filter if specified", "if", "(", "!", "is_null", "(", "$", "filter", ")", "&&", "$", "filter", "!=", "$", "name", ")", "{", "continue", ";", "}", "// Calculate the componentname", "$", "componentname", "=", "'qtype_'", ".", "$", "name", ";", "// Get the plugin fileareas (all them MUST belong to the same component)", "$", "classname", "=", "'backup_qtype_'", ".", "$", "name", ".", "'_plugin'", ";", "if", "(", "class_exists", "(", "$", "classname", ")", ")", "{", "$", "elements", "=", "call_user_func", "(", "array", "(", "$", "classname", ",", "'get_qtype_fileareas'", ")", ")", ";", "if", "(", "$", "elements", ")", "{", "// If there are elements, add them to $components", "$", "components", "[", "$", "componentname", "]", "=", "$", "elements", ";", "}", "}", "}", "return", "$", "components", ";", "}" ]
Returns all the components and fileareas used by all the installed qtypes The method introspects each qtype, asking it about fileareas used. Then, one 2-level array is returned. 1st level is the component name (qtype_xxxx) and 2nd level is one array of filearea => mappings to look Note that this function is used both in backup and restore, so it is important to use the same mapping names (usually, name of the table in singular) always TODO: Surely this can be promoted to backup_plugin easily and make it to work for ANY plugin, not only qtypes (but we don't need it for now)
[ "Returns", "all", "the", "components", "and", "fileareas", "used", "by", "all", "the", "installed", "qtypes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_qtype_plugin.class.php#L176-L198
219,574
moodle/moodle
repository/upload/lib.php
repository_upload.upload
public function upload($saveas_filename, $maxbytes) { global $CFG; $types = optional_param_array('accepted_types', '*', PARAM_RAW); $savepath = optional_param('savepath', '/', PARAM_PATH); $itemid = optional_param('itemid', 0, PARAM_INT); $license = optional_param('license', $CFG->sitedefaultlicense, PARAM_TEXT); $author = optional_param('author', '', PARAM_TEXT); $areamaxbytes = optional_param('areamaxbytes', FILE_AREA_MAX_BYTES_UNLIMITED, PARAM_INT); $overwriteexisting = optional_param('overwrite', false, PARAM_BOOL); return $this->process_upload($saveas_filename, $maxbytes, $types, $savepath, $itemid, $license, $author, $overwriteexisting, $areamaxbytes); }
php
public function upload($saveas_filename, $maxbytes) { global $CFG; $types = optional_param_array('accepted_types', '*', PARAM_RAW); $savepath = optional_param('savepath', '/', PARAM_PATH); $itemid = optional_param('itemid', 0, PARAM_INT); $license = optional_param('license', $CFG->sitedefaultlicense, PARAM_TEXT); $author = optional_param('author', '', PARAM_TEXT); $areamaxbytes = optional_param('areamaxbytes', FILE_AREA_MAX_BYTES_UNLIMITED, PARAM_INT); $overwriteexisting = optional_param('overwrite', false, PARAM_BOOL); return $this->process_upload($saveas_filename, $maxbytes, $types, $savepath, $itemid, $license, $author, $overwriteexisting, $areamaxbytes); }
[ "public", "function", "upload", "(", "$", "saveas_filename", ",", "$", "maxbytes", ")", "{", "global", "$", "CFG", ";", "$", "types", "=", "optional_param_array", "(", "'accepted_types'", ",", "'*'", ",", "PARAM_RAW", ")", ";", "$", "savepath", "=", "optional_param", "(", "'savepath'", ",", "'/'", ",", "PARAM_PATH", ")", ";", "$", "itemid", "=", "optional_param", "(", "'itemid'", ",", "0", ",", "PARAM_INT", ")", ";", "$", "license", "=", "optional_param", "(", "'license'", ",", "$", "CFG", "->", "sitedefaultlicense", ",", "PARAM_TEXT", ")", ";", "$", "author", "=", "optional_param", "(", "'author'", ",", "''", ",", "PARAM_TEXT", ")", ";", "$", "areamaxbytes", "=", "optional_param", "(", "'areamaxbytes'", ",", "FILE_AREA_MAX_BYTES_UNLIMITED", ",", "PARAM_INT", ")", ";", "$", "overwriteexisting", "=", "optional_param", "(", "'overwrite'", ",", "false", ",", "PARAM_BOOL", ")", ";", "return", "$", "this", "->", "process_upload", "(", "$", "saveas_filename", ",", "$", "maxbytes", ",", "$", "types", ",", "$", "savepath", ",", "$", "itemid", ",", "$", "license", ",", "$", "author", ",", "$", "overwriteexisting", ",", "$", "areamaxbytes", ")", ";", "}" ]
Process uploaded file @return array|bool
[ "Process", "uploaded", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/upload/lib.php#L52-L64
219,575
moodle/moodle
repository/upload/lib.php
repository_upload.get_listing
public function get_listing($path = '', $page = '') { global $CFG; $ret = array(); $ret['nologin'] = true; $ret['nosearch'] = true; $ret['norefresh'] = true; $ret['list'] = array(); $ret['dynload'] = false; $ret['upload'] = array('label'=>get_string('attachment', 'repository'), 'id'=>'repo-form'); $ret['allowcaching'] = true; // indicates that result of get_listing() can be cached in filepicker.js return $ret; }
php
public function get_listing($path = '', $page = '') { global $CFG; $ret = array(); $ret['nologin'] = true; $ret['nosearch'] = true; $ret['norefresh'] = true; $ret['list'] = array(); $ret['dynload'] = false; $ret['upload'] = array('label'=>get_string('attachment', 'repository'), 'id'=>'repo-form'); $ret['allowcaching'] = true; // indicates that result of get_listing() can be cached in filepicker.js return $ret; }
[ "public", "function", "get_listing", "(", "$", "path", "=", "''", ",", "$", "page", "=", "''", ")", "{", "global", "$", "CFG", ";", "$", "ret", "=", "array", "(", ")", ";", "$", "ret", "[", "'nologin'", "]", "=", "true", ";", "$", "ret", "[", "'nosearch'", "]", "=", "true", ";", "$", "ret", "[", "'norefresh'", "]", "=", "true", ";", "$", "ret", "[", "'list'", "]", "=", "array", "(", ")", ";", "$", "ret", "[", "'dynload'", "]", "=", "false", ";", "$", "ret", "[", "'upload'", "]", "=", "array", "(", "'label'", "=>", "get_string", "(", "'attachment'", ",", "'repository'", ")", ",", "'id'", "=>", "'repo-form'", ")", ";", "$", "ret", "[", "'allowcaching'", "]", "=", "true", ";", "// indicates that result of get_listing() can be cached in filepicker.js", "return", "$", "ret", ";", "}" ]
Return a upload form @return array
[ "Return", "a", "upload", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/upload/lib.php#L269-L280
219,576
moodle/moodle
mod/assign/feedbackplugin.php
assign_feedback_plugin.is_feedback_modified
public function is_feedback_modified(stdClass $grade, stdClass $data) { debugging('This plugin (' . $this->get_name() . ') has not overwritten the is_feedback_modified() method. Please add this method to your plugin', DEBUG_DEVELOPER); return true; }
php
public function is_feedback_modified(stdClass $grade, stdClass $data) { debugging('This plugin (' . $this->get_name() . ') has not overwritten the is_feedback_modified() method. Please add this method to your plugin', DEBUG_DEVELOPER); return true; }
[ "public", "function", "is_feedback_modified", "(", "stdClass", "$", "grade", ",", "stdClass", "$", "data", ")", "{", "debugging", "(", "'This plugin ('", ".", "$", "this", "->", "get_name", "(", ")", ".", "') has not overwritten the is_feedback_modified() method.\n Please add this method to your plugin'", ",", "DEBUG_DEVELOPER", ")", ";", "return", "true", ";", "}" ]
Has the plugin form element been modified in the current submission? @param stdClass $grade The grade. @param stdClass $data Form data from the feedback form. @return boolean - True if the form element has been modified.
[ "Has", "the", "plugin", "form", "element", "been", "modified", "in", "the", "current", "submission?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedbackplugin.php#L144-L148
219,577
moodle/moodle
user/filters/lib.php
user_filtering.get_sql_filter
public function get_sql_filter($extra='', array $params=null) { global $SESSION; $sqls = array(); if ($extra != '') { $sqls[] = $extra; } $params = (array)$params; if (!empty($SESSION->user_filtering)) { foreach ($SESSION->user_filtering as $fname => $datas) { if (!array_key_exists($fname, $this->_fields)) { continue; // Filter not used. } $field = $this->_fields[$fname]; foreach ($datas as $i => $data) { list($s, $p) = $field->get_sql_filter($data); $sqls[] = $s; $params = $params + $p; } } } if (empty($sqls)) { return array('', array()); } else { $sqls = implode(' AND ', $sqls); return array($sqls, $params); } }
php
public function get_sql_filter($extra='', array $params=null) { global $SESSION; $sqls = array(); if ($extra != '') { $sqls[] = $extra; } $params = (array)$params; if (!empty($SESSION->user_filtering)) { foreach ($SESSION->user_filtering as $fname => $datas) { if (!array_key_exists($fname, $this->_fields)) { continue; // Filter not used. } $field = $this->_fields[$fname]; foreach ($datas as $i => $data) { list($s, $p) = $field->get_sql_filter($data); $sqls[] = $s; $params = $params + $p; } } } if (empty($sqls)) { return array('', array()); } else { $sqls = implode(' AND ', $sqls); return array($sqls, $params); } }
[ "public", "function", "get_sql_filter", "(", "$", "extra", "=", "''", ",", "array", "$", "params", "=", "null", ")", "{", "global", "$", "SESSION", ";", "$", "sqls", "=", "array", "(", ")", ";", "if", "(", "$", "extra", "!=", "''", ")", "{", "$", "sqls", "[", "]", "=", "$", "extra", ";", "}", "$", "params", "=", "(", "array", ")", "$", "params", ";", "if", "(", "!", "empty", "(", "$", "SESSION", "->", "user_filtering", ")", ")", "{", "foreach", "(", "$", "SESSION", "->", "user_filtering", "as", "$", "fname", "=>", "$", "datas", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "fname", ",", "$", "this", "->", "_fields", ")", ")", "{", "continue", ";", "// Filter not used.", "}", "$", "field", "=", "$", "this", "->", "_fields", "[", "$", "fname", "]", ";", "foreach", "(", "$", "datas", "as", "$", "i", "=>", "$", "data", ")", "{", "list", "(", "$", "s", ",", "$", "p", ")", "=", "$", "field", "->", "get_sql_filter", "(", "$", "data", ")", ";", "$", "sqls", "[", "]", "=", "$", "s", ";", "$", "params", "=", "$", "params", "+", "$", "p", ";", "}", "}", "}", "if", "(", "empty", "(", "$", "sqls", ")", ")", "{", "return", "array", "(", "''", ",", "array", "(", ")", ")", ";", "}", "else", "{", "$", "sqls", "=", "implode", "(", "' AND '", ",", "$", "sqls", ")", ";", "return", "array", "(", "$", "sqls", ",", "$", "params", ")", ";", "}", "}" ]
Returns sql where statement based on active user filters @param string $extra sql @param array $params named params (recommended prefix ex) @return array sql string and $params
[ "Returns", "sql", "where", "statement", "based", "on", "active", "user", "filters" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/filters/lib.php#L204-L233
219,578
moodle/moodle
grade/grading/form/guide/edit_form.php
gradingform_guide_editguide.definition
public function definition() { $form = $this->_form; $form->addElement('hidden', 'areaid'); $form->setType('areaid', PARAM_INT); $form->addElement('hidden', 'returnurl'); $form->setType('returnurl', PARAM_LOCALURL); // Name. $form->addElement('text', 'name', get_string('name', 'gradingform_guide'), array('size' => 52, 'maxlength' => 255)); $form->addRule('name', get_string('required'), 'required', null, 'client'); $form->setType('name', PARAM_TEXT); $form->addRule('name', null, 'maxlength', 255, 'client'); // Description. $options = gradingform_guide_controller::description_form_field_options($this->_customdata['context']); $form->addElement('editor', 'description_editor', get_string('description'), null, $options); $form->setType('description_editor', PARAM_RAW); // Guide completion status. $choices = array(); $choices[gradingform_controller::DEFINITION_STATUS_DRAFT] = html_writer::tag('span', get_string('statusdraft', 'core_grading'), array('class' => 'status draft')); $choices[gradingform_controller::DEFINITION_STATUS_READY] = html_writer::tag('span', get_string('statusready', 'core_grading'), array('class' => 'status ready')); $form->addElement('select', 'status', get_string('guidestatus', 'gradingform_guide'), $choices)->freeze(); // Guide editor. $element = $form->addElement('guideeditor', 'guide', get_string('pluginname', 'gradingform_guide')); $form->setType('guide', PARAM_RAW); $buttonarray = array(); $buttonarray[] = &$form->createElement('submit', 'saveguide', get_string('saveguide', 'gradingform_guide')); if ($this->_customdata['allowdraft']) { $buttonarray[] = &$form->createElement('submit', 'saveguidedraft', get_string('saveguidedraft', 'gradingform_guide')); } $editbutton = &$form->createElement('submit', 'editguide', ' '); $editbutton->freeze(); $buttonarray[] = &$editbutton; $buttonarray[] = &$form->createElement('cancel'); $form->addGroup($buttonarray, 'buttonar', '', array(' '), false); $form->closeHeaderBefore('buttonar'); }
php
public function definition() { $form = $this->_form; $form->addElement('hidden', 'areaid'); $form->setType('areaid', PARAM_INT); $form->addElement('hidden', 'returnurl'); $form->setType('returnurl', PARAM_LOCALURL); // Name. $form->addElement('text', 'name', get_string('name', 'gradingform_guide'), array('size' => 52, 'maxlength' => 255)); $form->addRule('name', get_string('required'), 'required', null, 'client'); $form->setType('name', PARAM_TEXT); $form->addRule('name', null, 'maxlength', 255, 'client'); // Description. $options = gradingform_guide_controller::description_form_field_options($this->_customdata['context']); $form->addElement('editor', 'description_editor', get_string('description'), null, $options); $form->setType('description_editor', PARAM_RAW); // Guide completion status. $choices = array(); $choices[gradingform_controller::DEFINITION_STATUS_DRAFT] = html_writer::tag('span', get_string('statusdraft', 'core_grading'), array('class' => 'status draft')); $choices[gradingform_controller::DEFINITION_STATUS_READY] = html_writer::tag('span', get_string('statusready', 'core_grading'), array('class' => 'status ready')); $form->addElement('select', 'status', get_string('guidestatus', 'gradingform_guide'), $choices)->freeze(); // Guide editor. $element = $form->addElement('guideeditor', 'guide', get_string('pluginname', 'gradingform_guide')); $form->setType('guide', PARAM_RAW); $buttonarray = array(); $buttonarray[] = &$form->createElement('submit', 'saveguide', get_string('saveguide', 'gradingform_guide')); if ($this->_customdata['allowdraft']) { $buttonarray[] = &$form->createElement('submit', 'saveguidedraft', get_string('saveguidedraft', 'gradingform_guide')); } $editbutton = &$form->createElement('submit', 'editguide', ' '); $editbutton->freeze(); $buttonarray[] = &$editbutton; $buttonarray[] = &$form->createElement('cancel'); $form->addGroup($buttonarray, 'buttonar', '', array(' '), false); $form->closeHeaderBefore('buttonar'); }
[ "public", "function", "definition", "(", ")", "{", "$", "form", "=", "$", "this", "->", "_form", ";", "$", "form", "->", "addElement", "(", "'hidden'", ",", "'areaid'", ")", ";", "$", "form", "->", "setType", "(", "'areaid'", ",", "PARAM_INT", ")", ";", "$", "form", "->", "addElement", "(", "'hidden'", ",", "'returnurl'", ")", ";", "$", "form", "->", "setType", "(", "'returnurl'", ",", "PARAM_LOCALURL", ")", ";", "// Name.", "$", "form", "->", "addElement", "(", "'text'", ",", "'name'", ",", "get_string", "(", "'name'", ",", "'gradingform_guide'", ")", ",", "array", "(", "'size'", "=>", "52", ",", "'maxlength'", "=>", "255", ")", ")", ";", "$", "form", "->", "addRule", "(", "'name'", ",", "get_string", "(", "'required'", ")", ",", "'required'", ",", "null", ",", "'client'", ")", ";", "$", "form", "->", "setType", "(", "'name'", ",", "PARAM_TEXT", ")", ";", "$", "form", "->", "addRule", "(", "'name'", ",", "null", ",", "'maxlength'", ",", "255", ",", "'client'", ")", ";", "// Description.", "$", "options", "=", "gradingform_guide_controller", "::", "description_form_field_options", "(", "$", "this", "->", "_customdata", "[", "'context'", "]", ")", ";", "$", "form", "->", "addElement", "(", "'editor'", ",", "'description_editor'", ",", "get_string", "(", "'description'", ")", ",", "null", ",", "$", "options", ")", ";", "$", "form", "->", "setType", "(", "'description_editor'", ",", "PARAM_RAW", ")", ";", "// Guide completion status.", "$", "choices", "=", "array", "(", ")", ";", "$", "choices", "[", "gradingform_controller", "::", "DEFINITION_STATUS_DRAFT", "]", "=", "html_writer", "::", "tag", "(", "'span'", ",", "get_string", "(", "'statusdraft'", ",", "'core_grading'", ")", ",", "array", "(", "'class'", "=>", "'status draft'", ")", ")", ";", "$", "choices", "[", "gradingform_controller", "::", "DEFINITION_STATUS_READY", "]", "=", "html_writer", "::", "tag", "(", "'span'", ",", "get_string", "(", "'statusready'", ",", "'core_grading'", ")", ",", "array", "(", "'class'", "=>", "'status ready'", ")", ")", ";", "$", "form", "->", "addElement", "(", "'select'", ",", "'status'", ",", "get_string", "(", "'guidestatus'", ",", "'gradingform_guide'", ")", ",", "$", "choices", ")", "->", "freeze", "(", ")", ";", "// Guide editor.", "$", "element", "=", "$", "form", "->", "addElement", "(", "'guideeditor'", ",", "'guide'", ",", "get_string", "(", "'pluginname'", ",", "'gradingform_guide'", ")", ")", ";", "$", "form", "->", "setType", "(", "'guide'", ",", "PARAM_RAW", ")", ";", "$", "buttonarray", "=", "array", "(", ")", ";", "$", "buttonarray", "[", "]", "=", "&", "$", "form", "->", "createElement", "(", "'submit'", ",", "'saveguide'", ",", "get_string", "(", "'saveguide'", ",", "'gradingform_guide'", ")", ")", ";", "if", "(", "$", "this", "->", "_customdata", "[", "'allowdraft'", "]", ")", "{", "$", "buttonarray", "[", "]", "=", "&", "$", "form", "->", "createElement", "(", "'submit'", ",", "'saveguidedraft'", ",", "get_string", "(", "'saveguidedraft'", ",", "'gradingform_guide'", ")", ")", ";", "}", "$", "editbutton", "=", "&", "$", "form", "->", "createElement", "(", "'submit'", ",", "'editguide'", ",", "' '", ")", ";", "$", "editbutton", "->", "freeze", "(", ")", ";", "$", "buttonarray", "[", "]", "=", "&", "$", "editbutton", ";", "$", "buttonarray", "[", "]", "=", "&", "$", "form", "->", "createElement", "(", "'cancel'", ")", ";", "$", "form", "->", "addGroup", "(", "$", "buttonarray", ",", "'buttonar'", ",", "''", ",", "array", "(", "' '", ")", ",", "false", ")", ";", "$", "form", "->", "closeHeaderBefore", "(", "'buttonar'", ")", ";", "}" ]
Form element definition
[ "Form", "element", "definition" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/edit_form.php#L44-L88
219,579
moodle/moodle
grade/grading/form/guide/edit_form.php
gradingform_guide_editguide.need_confirm_regrading
public function need_confirm_regrading($controller) { $data = $this->get_data(); if (isset($data->guide['regrade'])) { // We have already displayed the confirmation on the previous step. return false; } if (!isset($data->saveguide) || !$data->saveguide) { // We only need confirmation when button 'Save guide' is pressed. return false; } if (!$controller->has_active_instances()) { // Nothing to re-grade, confirmation not needed. return false; } $changelevel = $controller->update_or_check_guide($data); if ($changelevel == 0) { // No changes in the guide, no confirmation needed. return false; } // Freeze form elements and pass the values in hidden fields. // TODO description_editor does not freeze the normal way! $form = $this->_form; foreach (array('guide', 'name'/*, 'description_editor'*/) as $fieldname) { $el =& $form->getElement($fieldname); $el->freeze(); $el->setPersistantFreeze(true); if ($fieldname == 'guide') { $el->add_regrade_confirmation($changelevel); } } // Replace button text 'saveguide' and unfreeze 'Back to edit' button. $this->findbutton('saveguide')->setValue(get_string('continue')); $el =& $this->findbutton('editguide'); $el->setValue(get_string('backtoediting', 'gradingform_guide')); $el->unfreeze(); return true; }
php
public function need_confirm_regrading($controller) { $data = $this->get_data(); if (isset($data->guide['regrade'])) { // We have already displayed the confirmation on the previous step. return false; } if (!isset($data->saveguide) || !$data->saveguide) { // We only need confirmation when button 'Save guide' is pressed. return false; } if (!$controller->has_active_instances()) { // Nothing to re-grade, confirmation not needed. return false; } $changelevel = $controller->update_or_check_guide($data); if ($changelevel == 0) { // No changes in the guide, no confirmation needed. return false; } // Freeze form elements and pass the values in hidden fields. // TODO description_editor does not freeze the normal way! $form = $this->_form; foreach (array('guide', 'name'/*, 'description_editor'*/) as $fieldname) { $el =& $form->getElement($fieldname); $el->freeze(); $el->setPersistantFreeze(true); if ($fieldname == 'guide') { $el->add_regrade_confirmation($changelevel); } } // Replace button text 'saveguide' and unfreeze 'Back to edit' button. $this->findbutton('saveguide')->setValue(get_string('continue')); $el =& $this->findbutton('editguide'); $el->setValue(get_string('backtoediting', 'gradingform_guide')); $el->unfreeze(); return true; }
[ "public", "function", "need_confirm_regrading", "(", "$", "controller", ")", "{", "$", "data", "=", "$", "this", "->", "get_data", "(", ")", ";", "if", "(", "isset", "(", "$", "data", "->", "guide", "[", "'regrade'", "]", ")", ")", "{", "// We have already displayed the confirmation on the previous step.", "return", "false", ";", "}", "if", "(", "!", "isset", "(", "$", "data", "->", "saveguide", ")", "||", "!", "$", "data", "->", "saveguide", ")", "{", "// We only need confirmation when button 'Save guide' is pressed.", "return", "false", ";", "}", "if", "(", "!", "$", "controller", "->", "has_active_instances", "(", ")", ")", "{", "// Nothing to re-grade, confirmation not needed.", "return", "false", ";", "}", "$", "changelevel", "=", "$", "controller", "->", "update_or_check_guide", "(", "$", "data", ")", ";", "if", "(", "$", "changelevel", "==", "0", ")", "{", "// No changes in the guide, no confirmation needed.", "return", "false", ";", "}", "// Freeze form elements and pass the values in hidden fields.", "// TODO description_editor does not freeze the normal way!", "$", "form", "=", "$", "this", "->", "_form", ";", "foreach", "(", "array", "(", "'guide'", ",", "'name'", "/*, 'description_editor'*/", ")", "as", "$", "fieldname", ")", "{", "$", "el", "=", "&", "$", "form", "->", "getElement", "(", "$", "fieldname", ")", ";", "$", "el", "->", "freeze", "(", ")", ";", "$", "el", "->", "setPersistantFreeze", "(", "true", ")", ";", "if", "(", "$", "fieldname", "==", "'guide'", ")", "{", "$", "el", "->", "add_regrade_confirmation", "(", "$", "changelevel", ")", ";", "}", "}", "// Replace button text 'saveguide' and unfreeze 'Back to edit' button.", "$", "this", "->", "findbutton", "(", "'saveguide'", ")", "->", "setValue", "(", "get_string", "(", "'continue'", ")", ")", ";", "$", "el", "=", "&", "$", "this", "->", "findbutton", "(", "'editguide'", ")", ";", "$", "el", "->", "setValue", "(", "get_string", "(", "'backtoediting'", ",", "'gradingform_guide'", ")", ")", ";", "$", "el", "->", "unfreeze", "(", ")", ";", "return", "true", ";", "}" ]
Check if there are changes in the guide and it is needed to ask user whether to mark the current grades for re-grading. User may confirm re-grading and continue, return to editing or cancel the changes @param gradingform_guide_controller $controller
[ "Check", "if", "there", "are", "changes", "in", "the", "guide", "and", "it", "is", "needed", "to", "ask", "user", "whether", "to", "mark", "the", "current", "grades", "for", "re", "-", "grading", ".", "User", "may", "confirm", "re", "-", "grading", "and", "continue", "return", "to", "editing", "or", "cancel", "the", "changes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/edit_form.php#L165-L204
219,580
moodle/moodle
question/type/numerical/backup/moodle1/lib.php
moodle1_qtype_numerical_handler.process_question
public function process_question(array $data, array $raw) { // Convert and write the answers first. if (isset($data['answers'])) { $this->write_answers($data['answers'], $this->pluginname); } // Convert and write the numerical units and numerical options. if (isset($data['numerical'][0]['numerical_units'])) { $numericalunits = $data['numerical'][0]['numerical_units']; } else { $numericalunits = array(); } $numericaloptions = $this->get_default_numerical_options( $data['oldquestiontextformat'], $numericalunits); $this->write_numerical_units($numericalunits); $this->write_numerical_options($numericaloptions); // And finally numerical_records. $this->xmlwriter->begin_tag('numerical_records'); foreach ($data['numerical'] as $numericalrecord) { // We do not use write_xml() here because $numericalrecords contains more than we want. $this->xmlwriter->begin_tag('numerical_record', array('id' => $this->converter->get_nextid())); $this->xmlwriter->full_tag('answer', $numericalrecord['answer']); $this->xmlwriter->full_tag('tolerance', $numericalrecord['tolerance']); $this->xmlwriter->end_tag('numerical_record'); } $this->xmlwriter->end_tag('numerical_records'); }
php
public function process_question(array $data, array $raw) { // Convert and write the answers first. if (isset($data['answers'])) { $this->write_answers($data['answers'], $this->pluginname); } // Convert and write the numerical units and numerical options. if (isset($data['numerical'][0]['numerical_units'])) { $numericalunits = $data['numerical'][0]['numerical_units']; } else { $numericalunits = array(); } $numericaloptions = $this->get_default_numerical_options( $data['oldquestiontextformat'], $numericalunits); $this->write_numerical_units($numericalunits); $this->write_numerical_options($numericaloptions); // And finally numerical_records. $this->xmlwriter->begin_tag('numerical_records'); foreach ($data['numerical'] as $numericalrecord) { // We do not use write_xml() here because $numericalrecords contains more than we want. $this->xmlwriter->begin_tag('numerical_record', array('id' => $this->converter->get_nextid())); $this->xmlwriter->full_tag('answer', $numericalrecord['answer']); $this->xmlwriter->full_tag('tolerance', $numericalrecord['tolerance']); $this->xmlwriter->end_tag('numerical_record'); } $this->xmlwriter->end_tag('numerical_records'); }
[ "public", "function", "process_question", "(", "array", "$", "data", ",", "array", "$", "raw", ")", "{", "// Convert and write the answers first.", "if", "(", "isset", "(", "$", "data", "[", "'answers'", "]", ")", ")", "{", "$", "this", "->", "write_answers", "(", "$", "data", "[", "'answers'", "]", ",", "$", "this", "->", "pluginname", ")", ";", "}", "// Convert and write the numerical units and numerical options.", "if", "(", "isset", "(", "$", "data", "[", "'numerical'", "]", "[", "0", "]", "[", "'numerical_units'", "]", ")", ")", "{", "$", "numericalunits", "=", "$", "data", "[", "'numerical'", "]", "[", "0", "]", "[", "'numerical_units'", "]", ";", "}", "else", "{", "$", "numericalunits", "=", "array", "(", ")", ";", "}", "$", "numericaloptions", "=", "$", "this", "->", "get_default_numerical_options", "(", "$", "data", "[", "'oldquestiontextformat'", "]", ",", "$", "numericalunits", ")", ";", "$", "this", "->", "write_numerical_units", "(", "$", "numericalunits", ")", ";", "$", "this", "->", "write_numerical_options", "(", "$", "numericaloptions", ")", ";", "// And finally numerical_records.", "$", "this", "->", "xmlwriter", "->", "begin_tag", "(", "'numerical_records'", ")", ";", "foreach", "(", "$", "data", "[", "'numerical'", "]", "as", "$", "numericalrecord", ")", "{", "// We do not use write_xml() here because $numericalrecords contains more than we want.", "$", "this", "->", "xmlwriter", "->", "begin_tag", "(", "'numerical_record'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "converter", "->", "get_nextid", "(", ")", ")", ")", ";", "$", "this", "->", "xmlwriter", "->", "full_tag", "(", "'answer'", ",", "$", "numericalrecord", "[", "'answer'", "]", ")", ";", "$", "this", "->", "xmlwriter", "->", "full_tag", "(", "'tolerance'", ",", "$", "numericalrecord", "[", "'tolerance'", "]", ")", ";", "$", "this", "->", "xmlwriter", "->", "end_tag", "(", "'numerical_record'", ")", ";", "}", "$", "this", "->", "xmlwriter", "->", "end_tag", "(", "'numerical_records'", ")", ";", "}" ]
Appends the numerical specific information to the question
[ "Appends", "the", "numerical", "specific", "information", "to", "the", "question" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/numerical/backup/moodle1/lib.php#L45-L74
219,581
moodle/moodle
admin/tool/monitor/classes/privacy/provider.php
provider.export_user_data
public static function export_user_data(approved_contextlist $contextlist) { global $DB; // Export rules. $context = \context_user::instance($contextlist->get_user()->id); $rules = $DB->get_records('tool_monitor_rules', ['userid' => $contextlist->get_user()->id]); if ($rules) { static::export_monitor_rules($rules, $context); } // Export subscriptions. $subscriptions = subscription_manager::get_user_subscriptions(0, 0, $contextlist->get_user()->id); if ($subscriptions) { static::export_monitor_subscriptions($subscriptions, $context); } }
php
public static function export_user_data(approved_contextlist $contextlist) { global $DB; // Export rules. $context = \context_user::instance($contextlist->get_user()->id); $rules = $DB->get_records('tool_monitor_rules', ['userid' => $contextlist->get_user()->id]); if ($rules) { static::export_monitor_rules($rules, $context); } // Export subscriptions. $subscriptions = subscription_manager::get_user_subscriptions(0, 0, $contextlist->get_user()->id); if ($subscriptions) { static::export_monitor_subscriptions($subscriptions, $context); } }
[ "public", "static", "function", "export_user_data", "(", "approved_contextlist", "$", "contextlist", ")", "{", "global", "$", "DB", ";", "// Export rules.", "$", "context", "=", "\\", "context_user", "::", "instance", "(", "$", "contextlist", "->", "get_user", "(", ")", "->", "id", ")", ";", "$", "rules", "=", "$", "DB", "->", "get_records", "(", "'tool_monitor_rules'", ",", "[", "'userid'", "=>", "$", "contextlist", "->", "get_user", "(", ")", "->", "id", "]", ")", ";", "if", "(", "$", "rules", ")", "{", "static", "::", "export_monitor_rules", "(", "$", "rules", ",", "$", "context", ")", ";", "}", "// Export subscriptions.", "$", "subscriptions", "=", "subscription_manager", "::", "get_user_subscriptions", "(", "0", ",", "0", ",", "$", "contextlist", "->", "get_user", "(", ")", "->", "id", ")", ";", "if", "(", "$", "subscriptions", ")", "{", "static", "::", "export_monitor_subscriptions", "(", "$", "subscriptions", ",", "$", "context", ")", ";", "}", "}" ]
Export all event monitor information for the list of contexts and this user. @param approved_contextlist $contextlist The list of approved contexts for a user.
[ "Export", "all", "event", "monitor", "information", "for", "the", "list", "of", "contexts", "and", "this", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/privacy/provider.php#L135-L148
219,582
moodle/moodle
admin/tool/monitor/classes/privacy/provider.php
provider.delete_user_data
protected static function delete_user_data(int $userid) { global $DB; // Delete this user's subscriptions first. subscription_manager::delete_user_subscriptions($userid); // Because we only use user contexts the instance ID is the user ID. // Get the rules and check if this user has the capability to delete them. $rules = $DB->get_records('tool_monitor_rules', ['userid' => $userid]); foreach ($rules as $ruledata) { $rule = rule_manager::get_rule($ruledata); // If no-one is suscribed to the rule then it is safe to delete. if ($rule->can_manage_rule($userid) && subscription_manager::count_rule_subscriptions($rule->id) == 0) { $rule->delete_rule(); } } }
php
protected static function delete_user_data(int $userid) { global $DB; // Delete this user's subscriptions first. subscription_manager::delete_user_subscriptions($userid); // Because we only use user contexts the instance ID is the user ID. // Get the rules and check if this user has the capability to delete them. $rules = $DB->get_records('tool_monitor_rules', ['userid' => $userid]); foreach ($rules as $ruledata) { $rule = rule_manager::get_rule($ruledata); // If no-one is suscribed to the rule then it is safe to delete. if ($rule->can_manage_rule($userid) && subscription_manager::count_rule_subscriptions($rule->id) == 0) { $rule->delete_rule(); } } }
[ "protected", "static", "function", "delete_user_data", "(", "int", "$", "userid", ")", "{", "global", "$", "DB", ";", "// Delete this user's subscriptions first.", "subscription_manager", "::", "delete_user_subscriptions", "(", "$", "userid", ")", ";", "// Because we only use user contexts the instance ID is the user ID.", "// Get the rules and check if this user has the capability to delete them.", "$", "rules", "=", "$", "DB", "->", "get_records", "(", "'tool_monitor_rules'", ",", "[", "'userid'", "=>", "$", "userid", "]", ")", ";", "foreach", "(", "$", "rules", "as", "$", "ruledata", ")", "{", "$", "rule", "=", "rule_manager", "::", "get_rule", "(", "$", "ruledata", ")", ";", "// If no-one is suscribed to the rule then it is safe to delete.", "if", "(", "$", "rule", "->", "can_manage_rule", "(", "$", "userid", ")", "&&", "subscription_manager", "::", "count_rule_subscriptions", "(", "$", "rule", "->", "id", ")", "==", "0", ")", "{", "$", "rule", "->", "delete_rule", "(", ")", ";", "}", "}", "}" ]
This does the deletion of user data for the event monitor. @param int $userid The user ID
[ "This", "does", "the", "deletion", "of", "user", "data", "for", "the", "event", "monitor", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/privacy/provider.php#L192-L206
219,583
moodle/moodle
admin/tool/monitor/classes/privacy/provider.php
provider.export_monitor_rules
protected static function export_monitor_rules(array $rules, \context_user $context) { foreach ($rules as $rule) { $rule = rule_manager::get_rule($rule); $ruledata = new \stdClass(); $ruledata->name = $rule->name; $ruledata->eventname = $rule->get_event_name(); $ruledata->description = $rule->get_description($context); $ruledata->plugin = $rule->get_plugin_name(); $ruledata->template = $rule->template; $ruledata->frequency = $rule->get_filters_description(); $ruledata->course = $rule->get_course_name($context); $ruledata->timecreated = transform::datetime($rule->timecreated); $ruledata->timemodified = transform::datetime($rule->timemodified); writer::with_context($context)->export_data([get_string('privacy:createdrules', 'tool_monitor'), $rule->name . '_' . $rule->id], $ruledata); } }
php
protected static function export_monitor_rules(array $rules, \context_user $context) { foreach ($rules as $rule) { $rule = rule_manager::get_rule($rule); $ruledata = new \stdClass(); $ruledata->name = $rule->name; $ruledata->eventname = $rule->get_event_name(); $ruledata->description = $rule->get_description($context); $ruledata->plugin = $rule->get_plugin_name(); $ruledata->template = $rule->template; $ruledata->frequency = $rule->get_filters_description(); $ruledata->course = $rule->get_course_name($context); $ruledata->timecreated = transform::datetime($rule->timecreated); $ruledata->timemodified = transform::datetime($rule->timemodified); writer::with_context($context)->export_data([get_string('privacy:createdrules', 'tool_monitor'), $rule->name . '_' . $rule->id], $ruledata); } }
[ "protected", "static", "function", "export_monitor_rules", "(", "array", "$", "rules", ",", "\\", "context_user", "$", "context", ")", "{", "foreach", "(", "$", "rules", "as", "$", "rule", ")", "{", "$", "rule", "=", "rule_manager", "::", "get_rule", "(", "$", "rule", ")", ";", "$", "ruledata", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "ruledata", "->", "name", "=", "$", "rule", "->", "name", ";", "$", "ruledata", "->", "eventname", "=", "$", "rule", "->", "get_event_name", "(", ")", ";", "$", "ruledata", "->", "description", "=", "$", "rule", "->", "get_description", "(", "$", "context", ")", ";", "$", "ruledata", "->", "plugin", "=", "$", "rule", "->", "get_plugin_name", "(", ")", ";", "$", "ruledata", "->", "template", "=", "$", "rule", "->", "template", ";", "$", "ruledata", "->", "frequency", "=", "$", "rule", "->", "get_filters_description", "(", ")", ";", "$", "ruledata", "->", "course", "=", "$", "rule", "->", "get_course_name", "(", "$", "context", ")", ";", "$", "ruledata", "->", "timecreated", "=", "transform", "::", "datetime", "(", "$", "rule", "->", "timecreated", ")", ";", "$", "ruledata", "->", "timemodified", "=", "transform", "::", "datetime", "(", "$", "rule", "->", "timemodified", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "[", "get_string", "(", "'privacy:createdrules'", ",", "'tool_monitor'", ")", ",", "$", "rule", "->", "name", ".", "'_'", ".", "$", "rule", "->", "id", "]", ",", "$", "ruledata", ")", ";", "}", "}" ]
This formats and then exports the monitor rules. @param array $rules The monitor rules. @param context_user $context The user context
[ "This", "formats", "and", "then", "exports", "the", "monitor", "rules", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/privacy/provider.php#L214-L230
219,584
moodle/moodle
admin/tool/monitor/classes/privacy/provider.php
provider.export_monitor_subscriptions
protected static function export_monitor_subscriptions(array $subscriptions, \context_user $context) { foreach ($subscriptions as $subscription) { $subscriptiondata = new \stdClass(); $subscriptiondata->instancename = $subscription->get_instance_name(); $subscriptiondata->eventname = $subscription->get_event_name(); $subscriptiondata->frequency = $subscription->get_filters_description(); $subscriptiondata->name = $subscription->get_name($context); $subscriptiondata->description = $subscription->get_description($context); $subscriptiondata->pluginname = $subscription->get_plugin_name(); $subscriptiondata->course = $subscription->get_course_name($context); $subscriptiondata->timecreated = transform::datetime($subscription->timecreated); $subscriptiondata->lastnotificationsent = transform::datetime($subscription->lastnotificationsent); writer::with_context($context)->export_data([get_string('privacy:subscriptions', 'tool_monitor'), $subscriptiondata->name . '_' . $subscription->id, $subscriptiondata->course, $subscriptiondata->instancename], $subscriptiondata); } }
php
protected static function export_monitor_subscriptions(array $subscriptions, \context_user $context) { foreach ($subscriptions as $subscription) { $subscriptiondata = new \stdClass(); $subscriptiondata->instancename = $subscription->get_instance_name(); $subscriptiondata->eventname = $subscription->get_event_name(); $subscriptiondata->frequency = $subscription->get_filters_description(); $subscriptiondata->name = $subscription->get_name($context); $subscriptiondata->description = $subscription->get_description($context); $subscriptiondata->pluginname = $subscription->get_plugin_name(); $subscriptiondata->course = $subscription->get_course_name($context); $subscriptiondata->timecreated = transform::datetime($subscription->timecreated); $subscriptiondata->lastnotificationsent = transform::datetime($subscription->lastnotificationsent); writer::with_context($context)->export_data([get_string('privacy:subscriptions', 'tool_monitor'), $subscriptiondata->name . '_' . $subscription->id, $subscriptiondata->course, $subscriptiondata->instancename], $subscriptiondata); } }
[ "protected", "static", "function", "export_monitor_subscriptions", "(", "array", "$", "subscriptions", ",", "\\", "context_user", "$", "context", ")", "{", "foreach", "(", "$", "subscriptions", "as", "$", "subscription", ")", "{", "$", "subscriptiondata", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "subscriptiondata", "->", "instancename", "=", "$", "subscription", "->", "get_instance_name", "(", ")", ";", "$", "subscriptiondata", "->", "eventname", "=", "$", "subscription", "->", "get_event_name", "(", ")", ";", "$", "subscriptiondata", "->", "frequency", "=", "$", "subscription", "->", "get_filters_description", "(", ")", ";", "$", "subscriptiondata", "->", "name", "=", "$", "subscription", "->", "get_name", "(", "$", "context", ")", ";", "$", "subscriptiondata", "->", "description", "=", "$", "subscription", "->", "get_description", "(", "$", "context", ")", ";", "$", "subscriptiondata", "->", "pluginname", "=", "$", "subscription", "->", "get_plugin_name", "(", ")", ";", "$", "subscriptiondata", "->", "course", "=", "$", "subscription", "->", "get_course_name", "(", "$", "context", ")", ";", "$", "subscriptiondata", "->", "timecreated", "=", "transform", "::", "datetime", "(", "$", "subscription", "->", "timecreated", ")", ";", "$", "subscriptiondata", "->", "lastnotificationsent", "=", "transform", "::", "datetime", "(", "$", "subscription", "->", "lastnotificationsent", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "[", "get_string", "(", "'privacy:subscriptions'", ",", "'tool_monitor'", ")", ",", "$", "subscriptiondata", "->", "name", ".", "'_'", ".", "$", "subscription", "->", "id", ",", "$", "subscriptiondata", "->", "course", ",", "$", "subscriptiondata", "->", "instancename", "]", ",", "$", "subscriptiondata", ")", ";", "}", "}" ]
This formats and then exports the event monitor subscriptions. @param array $subscriptions Subscriptions @param \context_user $context The user context
[ "This", "formats", "and", "then", "exports", "the", "event", "monitor", "subscriptions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/privacy/provider.php#L238-L254
219,585
moodle/moodle
lib/spout/src/Spout/Reader/Common/XMLProcessor.php
XMLProcessor.readUntilStopped
public function readUntilStopped() { while ($this->xmlReader->read()) { $nodeType = $this->xmlReader->nodeType; $nodeNamePossiblyWithPrefix = $this->xmlReader->name; $nodeNameWithoutPrefix = $this->xmlReader->localName; $callbackData = $this->getRegisteredCallbackData($nodeNamePossiblyWithPrefix, $nodeNameWithoutPrefix, $nodeType); if ($callbackData !== null) { $callbackResponse = $this->invokeCallback($callbackData, [$this->xmlReader]); if ($callbackResponse === self::PROCESSING_STOP) { // stop reading break; } } } }
php
public function readUntilStopped() { while ($this->xmlReader->read()) { $nodeType = $this->xmlReader->nodeType; $nodeNamePossiblyWithPrefix = $this->xmlReader->name; $nodeNameWithoutPrefix = $this->xmlReader->localName; $callbackData = $this->getRegisteredCallbackData($nodeNamePossiblyWithPrefix, $nodeNameWithoutPrefix, $nodeType); if ($callbackData !== null) { $callbackResponse = $this->invokeCallback($callbackData, [$this->xmlReader]); if ($callbackResponse === self::PROCESSING_STOP) { // stop reading break; } } } }
[ "public", "function", "readUntilStopped", "(", ")", "{", "while", "(", "$", "this", "->", "xmlReader", "->", "read", "(", ")", ")", "{", "$", "nodeType", "=", "$", "this", "->", "xmlReader", "->", "nodeType", ";", "$", "nodeNamePossiblyWithPrefix", "=", "$", "this", "->", "xmlReader", "->", "name", ";", "$", "nodeNameWithoutPrefix", "=", "$", "this", "->", "xmlReader", "->", "localName", ";", "$", "callbackData", "=", "$", "this", "->", "getRegisteredCallbackData", "(", "$", "nodeNamePossiblyWithPrefix", ",", "$", "nodeNameWithoutPrefix", ",", "$", "nodeType", ")", ";", "if", "(", "$", "callbackData", "!==", "null", ")", "{", "$", "callbackResponse", "=", "$", "this", "->", "invokeCallback", "(", "$", "callbackData", ",", "[", "$", "this", "->", "xmlReader", "]", ")", ";", "if", "(", "$", "callbackResponse", "===", "self", "::", "PROCESSING_STOP", ")", "{", "// stop reading", "break", ";", "}", "}", "}", "}" ]
Resumes the reading of the XML file where it was left off. Stops whenever a callback indicates that reading should stop or at the end of the file. @return void @throws \Box\Spout\Reader\Exception\XMLProcessingException
[ "Resumes", "the", "reading", "of", "the", "XML", "file", "where", "it", "was", "left", "off", ".", "Stops", "whenever", "a", "callback", "indicates", "that", "reading", "should", "stop", "or", "at", "the", "end", "of", "the", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/Common/XMLProcessor.php#L96-L114
219,586
moodle/moodle
lib/portfolio/caller.php
portfolio_caller_base.expected_time_file
public function expected_time_file() { if ($this->multifiles) { return portfolio_expected_time_file($this->multifiles); } else if ($this->singlefile) { return portfolio_expected_time_file($this->singlefile); } return PORTFOLIO_TIME_LOW; }
php
public function expected_time_file() { if ($this->multifiles) { return portfolio_expected_time_file($this->multifiles); } else if ($this->singlefile) { return portfolio_expected_time_file($this->singlefile); } return PORTFOLIO_TIME_LOW; }
[ "public", "function", "expected_time_file", "(", ")", "{", "if", "(", "$", "this", "->", "multifiles", ")", "{", "return", "portfolio_expected_time_file", "(", "$", "this", "->", "multifiles", ")", ";", "}", "else", "if", "(", "$", "this", "->", "singlefile", ")", "{", "return", "portfolio_expected_time_file", "(", "$", "this", "->", "singlefile", ")", ";", "}", "return", "PORTFOLIO_TIME_LOW", ";", "}" ]
Helper method to calculate expected time for multi or single file exports @return string file time expectation
[ "Helper", "method", "to", "calculate", "expected", "time", "for", "multi", "or", "single", "file", "exports" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/caller.php#L130-L138
219,587
moodle/moodle
lib/portfolio/caller.php
portfolio_caller_base.get_sha1_file
public function get_sha1_file() { if (empty($this->singlefile) && empty($this->multifiles)) { throw new portfolio_caller_exception('invalidsha1file', 'portfolio', $this->get_return_url()); } if ($this->singlefile) { return $this->singlefile->get_contenthash(); } $sha1s = array(); foreach ($this->multifiles as $file) { $sha1s[] = $file->get_contenthash(); } asort($sha1s); return sha1(implode('', $sha1s)); }
php
public function get_sha1_file() { if (empty($this->singlefile) && empty($this->multifiles)) { throw new portfolio_caller_exception('invalidsha1file', 'portfolio', $this->get_return_url()); } if ($this->singlefile) { return $this->singlefile->get_contenthash(); } $sha1s = array(); foreach ($this->multifiles as $file) { $sha1s[] = $file->get_contenthash(); } asort($sha1s); return sha1(implode('', $sha1s)); }
[ "public", "function", "get_sha1_file", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "singlefile", ")", "&&", "empty", "(", "$", "this", "->", "multifiles", ")", ")", "{", "throw", "new", "portfolio_caller_exception", "(", "'invalidsha1file'", ",", "'portfolio'", ",", "$", "this", "->", "get_return_url", "(", ")", ")", ";", "}", "if", "(", "$", "this", "->", "singlefile", ")", "{", "return", "$", "this", "->", "singlefile", "->", "get_contenthash", "(", ")", ";", "}", "$", "sha1s", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "multifiles", "as", "$", "file", ")", "{", "$", "sha1s", "[", "]", "=", "$", "file", "->", "get_contenthash", "(", ")", ";", "}", "asort", "(", "$", "sha1s", ")", ";", "return", "sha1", "(", "implode", "(", "''", ",", "$", "sha1s", ")", ")", ";", "}" ]
Helper function to calculate the sha1 for multi or single file exports @return string sha1 file exports
[ "Helper", "function", "to", "calculate", "the", "sha1", "for", "multi", "or", "single", "file", "exports" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/caller.php#L155-L168
219,588
moodle/moodle
lib/portfolio/caller.php
portfolio_caller_base.prepare_package_file
public function prepare_package_file() { if (empty($this->singlefile) && empty($this->multifiles)) { throw new portfolio_caller_exception('invalidpreparepackagefile', 'portfolio', $this->get_return_url()); } if ($this->singlefile) { return $this->exporter->copy_existing_file($this->singlefile); } foreach ($this->multifiles as $file) { $this->exporter->copy_existing_file($file); } }
php
public function prepare_package_file() { if (empty($this->singlefile) && empty($this->multifiles)) { throw new portfolio_caller_exception('invalidpreparepackagefile', 'portfolio', $this->get_return_url()); } if ($this->singlefile) { return $this->exporter->copy_existing_file($this->singlefile); } foreach ($this->multifiles as $file) { $this->exporter->copy_existing_file($file); } }
[ "public", "function", "prepare_package_file", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "singlefile", ")", "&&", "empty", "(", "$", "this", "->", "multifiles", ")", ")", "{", "throw", "new", "portfolio_caller_exception", "(", "'invalidpreparepackagefile'", ",", "'portfolio'", ",", "$", "this", "->", "get_return_url", "(", ")", ")", ";", "}", "if", "(", "$", "this", "->", "singlefile", ")", "{", "return", "$", "this", "->", "exporter", "->", "copy_existing_file", "(", "$", "this", "->", "singlefile", ")", ";", "}", "foreach", "(", "$", "this", "->", "multifiles", "as", "$", "file", ")", "{", "$", "this", "->", "exporter", "->", "copy_existing_file", "(", "$", "file", ")", ";", "}", "}" ]
Helper function to copy files into the temp area for single or multi file exports. @return stored_file|bool
[ "Helper", "function", "to", "copy", "files", "into", "the", "temp", "area", "for", "single", "or", "multi", "file", "exports", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/caller.php#L295-L305
219,589
moodle/moodle
lib/portfolio/caller.php
portfolio_caller_base.supported_formats
public final function supported_formats() { $basic = $this->base_supported_formats(); if (empty($this->supportedformats)) { $specific = array(); } else if (!is_array($this->supportedformats)) { debugging(get_class($this) . ' has set a non array value of member variable supported formats - working around but should be fixed in code'); $specific = array($this->supportedformats); } else { $specific = $this->supportedformats; } return portfolio_most_specific_formats($specific, $basic); }
php
public final function supported_formats() { $basic = $this->base_supported_formats(); if (empty($this->supportedformats)) { $specific = array(); } else if (!is_array($this->supportedformats)) { debugging(get_class($this) . ' has set a non array value of member variable supported formats - working around but should be fixed in code'); $specific = array($this->supportedformats); } else { $specific = $this->supportedformats; } return portfolio_most_specific_formats($specific, $basic); }
[ "public", "final", "function", "supported_formats", "(", ")", "{", "$", "basic", "=", "$", "this", "->", "base_supported_formats", "(", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "supportedformats", ")", ")", "{", "$", "specific", "=", "array", "(", ")", ";", "}", "else", "if", "(", "!", "is_array", "(", "$", "this", "->", "supportedformats", ")", ")", "{", "debugging", "(", "get_class", "(", "$", "this", ")", ".", "' has set a non array value of member variable supported formats - working around but should be fixed in code'", ")", ";", "$", "specific", "=", "array", "(", "$", "this", "->", "supportedformats", ")", ";", "}", "else", "{", "$", "specific", "=", "$", "this", "->", "supportedformats", ";", "}", "return", "portfolio_most_specific_formats", "(", "$", "specific", ",", "$", "basic", ")", ";", "}" ]
Array of formats this caller supports. @return array list of formats
[ "Array", "of", "formats", "this", "caller", "supports", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/caller.php#L312-L323
219,590
moodle/moodle
lib/portfolio/caller.php
portfolio_caller_base.set_formats_from_button
public function set_formats_from_button($formats) { $base = $this->base_supported_formats(); if (count($base) != count($formats) || count($base) != count(array_intersect($base, $formats))) { $this->supportedformats = portfolio_most_specific_formats($formats, $base); return; } // in the case where the button hasn't actually set anything, // we need to run through again and resolve conflicts // TODO revisit this comment - it looks to me like it's lying $this->supportedformats = portfolio_most_specific_formats($formats, $formats); }
php
public function set_formats_from_button($formats) { $base = $this->base_supported_formats(); if (count($base) != count($formats) || count($base) != count(array_intersect($base, $formats))) { $this->supportedformats = portfolio_most_specific_formats($formats, $base); return; } // in the case where the button hasn't actually set anything, // we need to run through again and resolve conflicts // TODO revisit this comment - it looks to me like it's lying $this->supportedformats = portfolio_most_specific_formats($formats, $formats); }
[ "public", "function", "set_formats_from_button", "(", "$", "formats", ")", "{", "$", "base", "=", "$", "this", "->", "base_supported_formats", "(", ")", ";", "if", "(", "count", "(", "$", "base", ")", "!=", "count", "(", "$", "formats", ")", "||", "count", "(", "$", "base", ")", "!=", "count", "(", "array_intersect", "(", "$", "base", ",", "$", "formats", ")", ")", ")", "{", "$", "this", "->", "supportedformats", "=", "portfolio_most_specific_formats", "(", "$", "formats", ",", "$", "base", ")", ";", "return", ";", "}", "// in the case where the button hasn't actually set anything,", "// we need to run through again and resolve conflicts", "// TODO revisit this comment - it looks to me like it's lying", "$", "this", "->", "supportedformats", "=", "portfolio_most_specific_formats", "(", "$", "formats", ",", "$", "formats", ")", ";", "}" ]
The button-location always knows best what the formats are... so it should be trusted. @todo MDL-31298 - re-analyze set_formats_from_button comment @param array $formats array of PORTFOLIO_FORMAT_XX @return void
[ "The", "button", "-", "location", "always", "knows", "best", "what", "the", "formats", "are", "...", "so", "it", "should", "be", "trusted", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/caller.php#L425-L436
219,591
moodle/moodle
lib/portfolio/caller.php
portfolio_caller_base.add_format
protected function add_format($format) { if (in_array($format, $this->supportedformats)) { return; } $this->supportedformats = portfolio_most_specific_formats(array($format), $this->supportedformats); }
php
protected function add_format($format) { if (in_array($format, $this->supportedformats)) { return; } $this->supportedformats = portfolio_most_specific_formats(array($format), $this->supportedformats); }
[ "protected", "function", "add_format", "(", "$", "format", ")", "{", "if", "(", "in_array", "(", "$", "format", ",", "$", "this", "->", "supportedformats", ")", ")", "{", "return", ";", "}", "$", "this", "->", "supportedformats", "=", "portfolio_most_specific_formats", "(", "array", "(", "$", "format", ")", ",", "$", "this", "->", "supportedformats", ")", ";", "}" ]
Adds a new format to the list of supported formats. This functions also handles removing conflicting and less specific formats at the same time. @param string $format one of PORTFOLIO_FORMAT_XX @return void
[ "Adds", "a", "new", "format", "to", "the", "list", "of", "supported", "formats", ".", "This", "functions", "also", "handles", "removing", "conflicting", "and", "less", "specific", "formats", "at", "the", "same", "time", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/caller.php#L446-L451
219,592
moodle/moodle
lib/portfolio/caller.php
portfolio_module_caller_base.get_return_url
public function get_return_url() { global $CFG; return $CFG->wwwroot . '/mod/' . $this->cm->modname . '/view.php?id=' . $this->cm->id; }
php
public function get_return_url() { global $CFG; return $CFG->wwwroot . '/mod/' . $this->cm->modname . '/view.php?id=' . $this->cm->id; }
[ "public", "function", "get_return_url", "(", ")", "{", "global", "$", "CFG", ";", "return", "$", "CFG", "->", "wwwroot", ".", "'/mod/'", ".", "$", "this", "->", "cm", "->", "modname", ".", "'/view.php?id='", ".", "$", "this", "->", "cm", "->", "id", ";", "}" ]
The url to return to after export or on cancel. Defaults value is set to the module 'view' page. Override this if it's deeper inside the module. @return string
[ "The", "url", "to", "return", "to", "after", "export", "or", "on", "cancel", ".", "Defaults", "value", "is", "set", "to", "the", "module", "view", "page", ".", "Override", "this", "if", "it", "s", "deeper", "inside", "the", "module", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/caller.php#L533-L536
219,593
moodle/moodle
lib/portfolio/caller.php
portfolio_module_caller_base.get
public function get($key) { if ($key != 'course') { return parent::get($key); } global $DB; if (empty($this->course)) { $this->course = $DB->get_record('course', array('id' => $this->cm->course)); } return $this->course; }
php
public function get($key) { if ($key != 'course') { return parent::get($key); } global $DB; if (empty($this->course)) { $this->course = $DB->get_record('course', array('id' => $this->cm->course)); } return $this->course; }
[ "public", "function", "get", "(", "$", "key", ")", "{", "if", "(", "$", "key", "!=", "'course'", ")", "{", "return", "parent", "::", "get", "(", "$", "key", ")", ";", "}", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "this", "->", "course", ")", ")", "{", "$", "this", "->", "course", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "cm", "->", "course", ")", ")", ";", "}", "return", "$", "this", "->", "course", ";", "}" ]
Override the parent get function to make sure when we're asked for a course, We retrieve the object from the database as needed. @param string $key the name of get function @return stdClass
[ "Override", "the", "parent", "get", "function", "to", "make", "sure", "when", "we", "re", "asked", "for", "a", "course", "We", "retrieve", "the", "object", "from", "the", "database", "as", "needed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/caller.php#L546-L555
219,594
moodle/moodle
mod/label/classes/search/activity.php
activity.get_doc_url
public function get_doc_url(\core_search\document $doc) { // Get correct URL to section that contains label, from course format. $cminfo = $this->get_cm($this->get_module_name(), strval($doc->get('itemid')), $doc->get('courseid')); $format = course_get_format($cminfo->get_course()); $url = $format->get_view_url($cminfo->sectionnum); // Add the ID of the label to the section URL. $url->set_anchor('module-' . $cminfo->id); return $url; }
php
public function get_doc_url(\core_search\document $doc) { // Get correct URL to section that contains label, from course format. $cminfo = $this->get_cm($this->get_module_name(), strval($doc->get('itemid')), $doc->get('courseid')); $format = course_get_format($cminfo->get_course()); $url = $format->get_view_url($cminfo->sectionnum); // Add the ID of the label to the section URL. $url->set_anchor('module-' . $cminfo->id); return $url; }
[ "public", "function", "get_doc_url", "(", "\\", "core_search", "\\", "document", "$", "doc", ")", "{", "// Get correct URL to section that contains label, from course format.", "$", "cminfo", "=", "$", "this", "->", "get_cm", "(", "$", "this", "->", "get_module_name", "(", ")", ",", "strval", "(", "$", "doc", "->", "get", "(", "'itemid'", ")", ")", ",", "$", "doc", "->", "get", "(", "'courseid'", ")", ")", ";", "$", "format", "=", "course_get_format", "(", "$", "cminfo", "->", "get_course", "(", ")", ")", ";", "$", "url", "=", "$", "format", "->", "get_view_url", "(", "$", "cminfo", "->", "sectionnum", ")", ";", "// Add the ID of the label to the section URL.", "$", "url", "->", "set_anchor", "(", "'module-'", ".", "$", "cminfo", "->", "id", ")", ";", "return", "$", "url", ";", "}" ]
Overwritten as labels are displayed in-course. @param \core_search\document $doc @return \moodle_url
[ "Overwritten", "as", "labels", "are", "displayed", "in", "-", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/label/classes/search/activity.php#L56-L65
219,595
moodle/moodle
report/eventlist/classes/list_generator.php
report_eventlist_list_generator.get_all_events_list
public static function get_all_events_list($detail = true) { return array_merge(self::get_core_events_list($detail), self::get_non_core_event_list($detail)); }
php
public static function get_all_events_list($detail = true) { return array_merge(self::get_core_events_list($detail), self::get_non_core_event_list($detail)); }
[ "public", "static", "function", "get_all_events_list", "(", "$", "detail", "=", "true", ")", "{", "return", "array_merge", "(", "self", "::", "get_core_events_list", "(", "$", "detail", ")", ",", "self", "::", "get_non_core_event_list", "(", "$", "detail", ")", ")", ";", "}" ]
Convenience method. Returns all of the core events either with or without details. @param bool $detail True will return details, but no abstract classes, False will return all events, but no details. @return array All events.
[ "Convenience", "method", ".", "Returns", "all", "of", "the", "core", "events", "either", "with", "or", "without", "details", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/eventlist/classes/list_generator.php#L42-L44
219,596
moodle/moodle
report/eventlist/classes/list_generator.php
report_eventlist_list_generator.get_edulevel_string
public static function get_edulevel_string($edulevel) { switch ($edulevel) { case \core\event\base::LEVEL_PARTICIPATING: return get_string('participating', 'report_eventlist'); break; case \core\event\base::LEVEL_TEACHING: return get_string('teaching', 'report_eventlist'); break; case \core\event\base::LEVEL_OTHER: default: return get_string('other', 'report_eventlist'); break; } }
php
public static function get_edulevel_string($edulevel) { switch ($edulevel) { case \core\event\base::LEVEL_PARTICIPATING: return get_string('participating', 'report_eventlist'); break; case \core\event\base::LEVEL_TEACHING: return get_string('teaching', 'report_eventlist'); break; case \core\event\base::LEVEL_OTHER: default: return get_string('other', 'report_eventlist'); break; } }
[ "public", "static", "function", "get_edulevel_string", "(", "$", "edulevel", ")", "{", "switch", "(", "$", "edulevel", ")", "{", "case", "\\", "core", "\\", "event", "\\", "base", "::", "LEVEL_PARTICIPATING", ":", "return", "get_string", "(", "'participating'", ",", "'report_eventlist'", ")", ";", "break", ";", "case", "\\", "core", "\\", "event", "\\", "base", "::", "LEVEL_TEACHING", ":", "return", "get_string", "(", "'teaching'", ",", "'report_eventlist'", ")", ";", "break", ";", "case", "\\", "core", "\\", "event", "\\", "base", "::", "LEVEL_OTHER", ":", "default", ":", "return", "get_string", "(", "'other'", ",", "'report_eventlist'", ")", ";", "break", ";", "}", "}" ]
Returns the appropriate string for the event education level. @param int $edulevel Takes either the edulevel constant or string. @return string get_string for the specific education level.
[ "Returns", "the", "appropriate", "string", "for", "the", "event", "education", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/eventlist/classes/list_generator.php#L126-L141
219,597
moodle/moodle
report/eventlist/classes/list_generator.php
report_eventlist_list_generator.get_observer_list
public static function get_observer_list() { $events = \core\event\manager::get_all_observers(); foreach ($events as $key => $observers) { foreach ($observers as $observerskey => $observer) { $events[$key][$observerskey]->parentplugin = \core_plugin_manager::instance()->get_parent_of_subplugin($observer->plugintype); } } return $events; }
php
public static function get_observer_list() { $events = \core\event\manager::get_all_observers(); foreach ($events as $key => $observers) { foreach ($observers as $observerskey => $observer) { $events[$key][$observerskey]->parentplugin = \core_plugin_manager::instance()->get_parent_of_subplugin($observer->plugintype); } } return $events; }
[ "public", "static", "function", "get_observer_list", "(", ")", "{", "$", "events", "=", "\\", "core", "\\", "event", "\\", "manager", "::", "get_all_observers", "(", ")", ";", "foreach", "(", "$", "events", "as", "$", "key", "=>", "$", "observers", ")", "{", "foreach", "(", "$", "observers", "as", "$", "observerskey", "=>", "$", "observer", ")", "{", "$", "events", "[", "$", "key", "]", "[", "$", "observerskey", "]", "->", "parentplugin", "=", "\\", "core_plugin_manager", "::", "instance", "(", ")", "->", "get_parent_of_subplugin", "(", "$", "observer", "->", "plugintype", ")", ";", "}", "}", "return", "$", "events", ";", "}" ]
Get the full list of observers for the system. @return array An array of observers in the system.
[ "Get", "the", "full", "list", "of", "observers", "for", "the", "system", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/eventlist/classes/list_generator.php#L223-L232
219,598
moodle/moodle
report/eventlist/classes/list_generator.php
report_eventlist_list_generator.format_data
private static function format_data($eventdata, $eventfullpath) { // Get general event information. $eventdata[$eventfullpath] = $eventfullpath::get_static_info(); // Create a link for further event detail. $url = new \moodle_url('eventdetail.php', array('eventname' => $eventfullpath)); $link = \html_writer::link($url, $eventfullpath::get_name_with_info()); $eventdata[$eventfullpath]['fulleventname'] = \html_writer::span($link); $eventdata[$eventfullpath]['fulleventname'] .= \html_writer::empty_tag('br'); $eventdata[$eventfullpath]['fulleventname'] .= \html_writer::span($eventdata[$eventfullpath]['eventname'], 'report-eventlist-name'); $eventdata[$eventfullpath]['crud'] = self::get_crud_string($eventdata[$eventfullpath]['crud']); $eventdata[$eventfullpath]['edulevel'] = self::get_edulevel_string($eventdata[$eventfullpath]['edulevel']); $eventdata[$eventfullpath]['legacyevent'] = $eventfullpath::get_legacy_eventname(); // Mess around getting since information. $ref = new \ReflectionClass($eventdata[$eventfullpath]['eventname']); $eventdocbloc = $ref->getDocComment(); $sincepattern = "/since\s*Moodle\s([0-9]+.[0-9]+)/i"; preg_match($sincepattern, $eventdocbloc, $result); if (isset($result[1])) { $eventdata[$eventfullpath]['since'] = $result[1]; } else { $eventdata[$eventfullpath]['since'] = null; } // Human readable plugin information to go with the component. $pluginstring = explode('\\', $eventfullpath); if ($pluginstring[1] !== 'core') { $component = $eventdata[$eventfullpath]['component']; $manager = get_string_manager(); if ($manager->string_exists('pluginname', $pluginstring[1])) { $eventdata[$eventfullpath]['component'] = \html_writer::span(get_string('pluginname', $pluginstring[1])); } } // Raw event data to be used to sort the "Event name" column. $eventdata[$eventfullpath]['raweventname'] = $eventfullpath::get_name_with_info() . ' ' . $eventdata[$eventfullpath]['eventname']; // Unset information that is not currently required. unset($eventdata[$eventfullpath]['action']); unset($eventdata[$eventfullpath]['target']); return $eventdata; }
php
private static function format_data($eventdata, $eventfullpath) { // Get general event information. $eventdata[$eventfullpath] = $eventfullpath::get_static_info(); // Create a link for further event detail. $url = new \moodle_url('eventdetail.php', array('eventname' => $eventfullpath)); $link = \html_writer::link($url, $eventfullpath::get_name_with_info()); $eventdata[$eventfullpath]['fulleventname'] = \html_writer::span($link); $eventdata[$eventfullpath]['fulleventname'] .= \html_writer::empty_tag('br'); $eventdata[$eventfullpath]['fulleventname'] .= \html_writer::span($eventdata[$eventfullpath]['eventname'], 'report-eventlist-name'); $eventdata[$eventfullpath]['crud'] = self::get_crud_string($eventdata[$eventfullpath]['crud']); $eventdata[$eventfullpath]['edulevel'] = self::get_edulevel_string($eventdata[$eventfullpath]['edulevel']); $eventdata[$eventfullpath]['legacyevent'] = $eventfullpath::get_legacy_eventname(); // Mess around getting since information. $ref = new \ReflectionClass($eventdata[$eventfullpath]['eventname']); $eventdocbloc = $ref->getDocComment(); $sincepattern = "/since\s*Moodle\s([0-9]+.[0-9]+)/i"; preg_match($sincepattern, $eventdocbloc, $result); if (isset($result[1])) { $eventdata[$eventfullpath]['since'] = $result[1]; } else { $eventdata[$eventfullpath]['since'] = null; } // Human readable plugin information to go with the component. $pluginstring = explode('\\', $eventfullpath); if ($pluginstring[1] !== 'core') { $component = $eventdata[$eventfullpath]['component']; $manager = get_string_manager(); if ($manager->string_exists('pluginname', $pluginstring[1])) { $eventdata[$eventfullpath]['component'] = \html_writer::span(get_string('pluginname', $pluginstring[1])); } } // Raw event data to be used to sort the "Event name" column. $eventdata[$eventfullpath]['raweventname'] = $eventfullpath::get_name_with_info() . ' ' . $eventdata[$eventfullpath]['eventname']; // Unset information that is not currently required. unset($eventdata[$eventfullpath]['action']); unset($eventdata[$eventfullpath]['target']); return $eventdata; }
[ "private", "static", "function", "format_data", "(", "$", "eventdata", ",", "$", "eventfullpath", ")", "{", "// Get general event information.", "$", "eventdata", "[", "$", "eventfullpath", "]", "=", "$", "eventfullpath", "::", "get_static_info", "(", ")", ";", "// Create a link for further event detail.", "$", "url", "=", "new", "\\", "moodle_url", "(", "'eventdetail.php'", ",", "array", "(", "'eventname'", "=>", "$", "eventfullpath", ")", ")", ";", "$", "link", "=", "\\", "html_writer", "::", "link", "(", "$", "url", ",", "$", "eventfullpath", "::", "get_name_with_info", "(", ")", ")", ";", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'fulleventname'", "]", "=", "\\", "html_writer", "::", "span", "(", "$", "link", ")", ";", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'fulleventname'", "]", ".=", "\\", "html_writer", "::", "empty_tag", "(", "'br'", ")", ";", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'fulleventname'", "]", ".=", "\\", "html_writer", "::", "span", "(", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'eventname'", "]", ",", "'report-eventlist-name'", ")", ";", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'crud'", "]", "=", "self", "::", "get_crud_string", "(", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'crud'", "]", ")", ";", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'edulevel'", "]", "=", "self", "::", "get_edulevel_string", "(", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'edulevel'", "]", ")", ";", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'legacyevent'", "]", "=", "$", "eventfullpath", "::", "get_legacy_eventname", "(", ")", ";", "// Mess around getting since information.", "$", "ref", "=", "new", "\\", "ReflectionClass", "(", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'eventname'", "]", ")", ";", "$", "eventdocbloc", "=", "$", "ref", "->", "getDocComment", "(", ")", ";", "$", "sincepattern", "=", "\"/since\\s*Moodle\\s([0-9]+.[0-9]+)/i\"", ";", "preg_match", "(", "$", "sincepattern", ",", "$", "eventdocbloc", ",", "$", "result", ")", ";", "if", "(", "isset", "(", "$", "result", "[", "1", "]", ")", ")", "{", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'since'", "]", "=", "$", "result", "[", "1", "]", ";", "}", "else", "{", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'since'", "]", "=", "null", ";", "}", "// Human readable plugin information to go with the component.", "$", "pluginstring", "=", "explode", "(", "'\\\\'", ",", "$", "eventfullpath", ")", ";", "if", "(", "$", "pluginstring", "[", "1", "]", "!==", "'core'", ")", "{", "$", "component", "=", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'component'", "]", ";", "$", "manager", "=", "get_string_manager", "(", ")", ";", "if", "(", "$", "manager", "->", "string_exists", "(", "'pluginname'", ",", "$", "pluginstring", "[", "1", "]", ")", ")", "{", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'component'", "]", "=", "\\", "html_writer", "::", "span", "(", "get_string", "(", "'pluginname'", ",", "$", "pluginstring", "[", "1", "]", ")", ")", ";", "}", "}", "// Raw event data to be used to sort the \"Event name\" column.", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'raweventname'", "]", "=", "$", "eventfullpath", "::", "get_name_with_info", "(", ")", ".", "' '", ".", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'eventname'", "]", ";", "// Unset information that is not currently required.", "unset", "(", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'action'", "]", ")", ";", "unset", "(", "$", "eventdata", "[", "$", "eventfullpath", "]", "[", "'target'", "]", ")", ";", "return", "$", "eventdata", ";", "}" ]
Returns the event data list section with url links and other formatting. @param array $eventdata The event data list section. @param string $eventfullpath Full path to the events for this plugin / subplugin. @return array The event data list section with additional formatting.
[ "Returns", "the", "event", "data", "list", "section", "with", "url", "links", "and", "other", "formatting", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/eventlist/classes/list_generator.php#L241-L284
219,599
moodle/moodle
enrol/lti/backup/moodle2/backup_enrol_lti_plugin.class.php
backup_enrol_lti_plugin.define_enrol_plugin_structure
public function define_enrol_plugin_structure() { // Get the parent we will be adding these elements to. $plugin = $this->get_plugin_element(); // Define our elements. $tool = new backup_nested_element('tool', array('id'), array( 'enrolid', 'contextid', 'institution', 'lang', 'timezone', 'maxenrolled', 'maildisplay', 'city', 'country', 'gradesync', 'gradesynccompletion', 'membersync', 'membersyncmode', 'roleinstructor', 'rolelearner', 'secret', 'timecreated', 'timemodified')); $users = new backup_nested_element('users'); $user = new backup_nested_element('user', array('id'), array( 'userid', 'toolid', 'serviceurl', 'sourceid', 'consumerkey', 'consumersecret', 'membershipurl', 'membershipsid')); // Build elements hierarchy. $plugin->add_child($tool); $tool->add_child($users); $users->add_child($user); // Set sources to populate the data. $tool->set_source_table('enrol_lti_tools', array('enrolid' => backup::VAR_PARENTID)); // Users are only added only if users included. if ($this->task->get_setting_value('users')) { $user->set_source_table('enrol_lti_users', array('toolid' => backup::VAR_PARENTID)); } }
php
public function define_enrol_plugin_structure() { // Get the parent we will be adding these elements to. $plugin = $this->get_plugin_element(); // Define our elements. $tool = new backup_nested_element('tool', array('id'), array( 'enrolid', 'contextid', 'institution', 'lang', 'timezone', 'maxenrolled', 'maildisplay', 'city', 'country', 'gradesync', 'gradesynccompletion', 'membersync', 'membersyncmode', 'roleinstructor', 'rolelearner', 'secret', 'timecreated', 'timemodified')); $users = new backup_nested_element('users'); $user = new backup_nested_element('user', array('id'), array( 'userid', 'toolid', 'serviceurl', 'sourceid', 'consumerkey', 'consumersecret', 'membershipurl', 'membershipsid')); // Build elements hierarchy. $plugin->add_child($tool); $tool->add_child($users); $users->add_child($user); // Set sources to populate the data. $tool->set_source_table('enrol_lti_tools', array('enrolid' => backup::VAR_PARENTID)); // Users are only added only if users included. if ($this->task->get_setting_value('users')) { $user->set_source_table('enrol_lti_users', array('toolid' => backup::VAR_PARENTID)); } }
[ "public", "function", "define_enrol_plugin_structure", "(", ")", "{", "// Get the parent we will be adding these elements to.", "$", "plugin", "=", "$", "this", "->", "get_plugin_element", "(", ")", ";", "// Define our elements.", "$", "tool", "=", "new", "backup_nested_element", "(", "'tool'", ",", "array", "(", "'id'", ")", ",", "array", "(", "'enrolid'", ",", "'contextid'", ",", "'institution'", ",", "'lang'", ",", "'timezone'", ",", "'maxenrolled'", ",", "'maildisplay'", ",", "'city'", ",", "'country'", ",", "'gradesync'", ",", "'gradesynccompletion'", ",", "'membersync'", ",", "'membersyncmode'", ",", "'roleinstructor'", ",", "'rolelearner'", ",", "'secret'", ",", "'timecreated'", ",", "'timemodified'", ")", ")", ";", "$", "users", "=", "new", "backup_nested_element", "(", "'users'", ")", ";", "$", "user", "=", "new", "backup_nested_element", "(", "'user'", ",", "array", "(", "'id'", ")", ",", "array", "(", "'userid'", ",", "'toolid'", ",", "'serviceurl'", ",", "'sourceid'", ",", "'consumerkey'", ",", "'consumersecret'", ",", "'membershipurl'", ",", "'membershipsid'", ")", ")", ";", "// Build elements hierarchy.", "$", "plugin", "->", "add_child", "(", "$", "tool", ")", ";", "$", "tool", "->", "add_child", "(", "$", "users", ")", ";", "$", "users", "->", "add_child", "(", "$", "user", ")", ";", "// Set sources to populate the data.", "$", "tool", "->", "set_source_table", "(", "'enrol_lti_tools'", ",", "array", "(", "'enrolid'", "=>", "backup", "::", "VAR_PARENTID", ")", ")", ";", "// Users are only added only if users included.", "if", "(", "$", "this", "->", "task", "->", "get_setting_value", "(", "'users'", ")", ")", "{", "$", "user", "->", "set_source_table", "(", "'enrol_lti_users'", ",", "array", "(", "'toolid'", "=>", "backup", "::", "VAR_PARENTID", ")", ")", ";", "}", "}" ]
Defines the other LTI enrolment structures to append. @return backup_plugin_element
[ "Defines", "the", "other", "LTI", "enrolment", "structures", "to", "append", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/backup/moodle2/backup_enrol_lti_plugin.class.php#L41-L70