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
215,600
moodle/moodle
lib/mlbackend/php/phpml/src/Phpml/Math/Statistic/Covariance.php
Covariance.fromDataset
public static function fromDataset(array $data, int $i, int $k, bool $sample = true, float $meanX = null, float $meanY = null) { if (empty($data)) { throw InvalidArgumentException::arrayCantBeEmpty(); } $n = count($data); if ($sample && $n === 1) { throw InvalidArgumentException::arraySizeToSmall(2); } if ($i < 0 || $k < 0 || $i >= $n || $k >= $n) { throw new \Exception("Given indices i and k do not match with the dimensionality of data"); } if ($meanX === null || $meanY === null) { $x = array_column($data, $i); $y = array_column($data, $k); $meanX = Mean::arithmetic($x); $meanY = Mean::arithmetic($y); $sum = 0.0; foreach ($x as $index => $xi) { $yi = $y[$index]; $sum += ($xi - $meanX) * ($yi - $meanY); } } else { // In the case, whole dataset given along with dimension indices, i and k, // we would like to avoid getting column data with array_column and operate // over this extra copy of column data for memory efficiency purposes. // // Instead we traverse through the whole data and get what we actually need // without copying the data. This way, memory use will be reduced // with a slight cost of CPU utilization. $sum = 0.0; foreach ($data as $row) { $val = []; foreach ($row as $index => $col) { if ($index == $i) { $val[0] = $col - $meanX; } if ($index == $k) { $val[1] = $col - $meanY; } } $sum += $val[0] * $val[1]; } } if ($sample) { --$n; } return $sum / $n; }
php
public static function fromDataset(array $data, int $i, int $k, bool $sample = true, float $meanX = null, float $meanY = null) { if (empty($data)) { throw InvalidArgumentException::arrayCantBeEmpty(); } $n = count($data); if ($sample && $n === 1) { throw InvalidArgumentException::arraySizeToSmall(2); } if ($i < 0 || $k < 0 || $i >= $n || $k >= $n) { throw new \Exception("Given indices i and k do not match with the dimensionality of data"); } if ($meanX === null || $meanY === null) { $x = array_column($data, $i); $y = array_column($data, $k); $meanX = Mean::arithmetic($x); $meanY = Mean::arithmetic($y); $sum = 0.0; foreach ($x as $index => $xi) { $yi = $y[$index]; $sum += ($xi - $meanX) * ($yi - $meanY); } } else { // In the case, whole dataset given along with dimension indices, i and k, // we would like to avoid getting column data with array_column and operate // over this extra copy of column data for memory efficiency purposes. // // Instead we traverse through the whole data and get what we actually need // without copying the data. This way, memory use will be reduced // with a slight cost of CPU utilization. $sum = 0.0; foreach ($data as $row) { $val = []; foreach ($row as $index => $col) { if ($index == $i) { $val[0] = $col - $meanX; } if ($index == $k) { $val[1] = $col - $meanY; } } $sum += $val[0] * $val[1]; } } if ($sample) { --$n; } return $sum / $n; }
[ "public", "static", "function", "fromDataset", "(", "array", "$", "data", ",", "int", "$", "i", ",", "int", "$", "k", ",", "bool", "$", "sample", "=", "true", ",", "float", "$", "meanX", "=", "null", ",", "float", "$", "meanY", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "data", ")", ")", "{", "throw", "InvalidArgumentException", "::", "arrayCantBeEmpty", "(", ")", ";", "}", "$", "n", "=", "count", "(", "$", "data", ")", ";", "if", "(", "$", "sample", "&&", "$", "n", "===", "1", ")", "{", "throw", "InvalidArgumentException", "::", "arraySizeToSmall", "(", "2", ")", ";", "}", "if", "(", "$", "i", "<", "0", "||", "$", "k", "<", "0", "||", "$", "i", ">=", "$", "n", "||", "$", "k", ">=", "$", "n", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Given indices i and k do not match with the dimensionality of data\"", ")", ";", "}", "if", "(", "$", "meanX", "===", "null", "||", "$", "meanY", "===", "null", ")", "{", "$", "x", "=", "array_column", "(", "$", "data", ",", "$", "i", ")", ";", "$", "y", "=", "array_column", "(", "$", "data", ",", "$", "k", ")", ";", "$", "meanX", "=", "Mean", "::", "arithmetic", "(", "$", "x", ")", ";", "$", "meanY", "=", "Mean", "::", "arithmetic", "(", "$", "y", ")", ";", "$", "sum", "=", "0.0", ";", "foreach", "(", "$", "x", "as", "$", "index", "=>", "$", "xi", ")", "{", "$", "yi", "=", "$", "y", "[", "$", "index", "]", ";", "$", "sum", "+=", "(", "$", "xi", "-", "$", "meanX", ")", "*", "(", "$", "yi", "-", "$", "meanY", ")", ";", "}", "}", "else", "{", "// In the case, whole dataset given along with dimension indices, i and k,", "// we would like to avoid getting column data with array_column and operate", "// over this extra copy of column data for memory efficiency purposes.", "//", "// Instead we traverse through the whole data and get what we actually need", "// without copying the data. This way, memory use will be reduced", "// with a slight cost of CPU utilization.", "$", "sum", "=", "0.0", ";", "foreach", "(", "$", "data", "as", "$", "row", ")", "{", "$", "val", "=", "[", "]", ";", "foreach", "(", "$", "row", "as", "$", "index", "=>", "$", "col", ")", "{", "if", "(", "$", "index", "==", "$", "i", ")", "{", "$", "val", "[", "0", "]", "=", "$", "col", "-", "$", "meanX", ";", "}", "if", "(", "$", "index", "==", "$", "k", ")", "{", "$", "val", "[", "1", "]", "=", "$", "col", "-", "$", "meanY", ";", "}", "}", "$", "sum", "+=", "$", "val", "[", "0", "]", "*", "$", "val", "[", "1", "]", ";", "}", "}", "if", "(", "$", "sample", ")", "{", "--", "$", "n", ";", "}", "return", "$", "sum", "/", "$", "n", ";", "}" ]
Calculates covariance of two dimensions, i and k in the given data. @param array $data @param int $i @param int $k @param bool $sample @param float $meanX @param float $meanY @return float @throws InvalidArgumentException @throws \Exception
[ "Calculates", "covariance", "of", "two", "dimensions", "i", "and", "k", "in", "the", "given", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Math/Statistic/Covariance.php#L71-L125
215,601
moodle/moodle
lib/horde/framework/Horde/Support/Inflector.php
Horde_Support_Inflector.pluralize
public function pluralize($word) { if ($plural = $this->getCache($word, 'pluralize')) { return $plural; } if (isset($this->_uncountables_keys[$word])) { return $word; } foreach ($this->_pluralizationRules as $regexp => $replacement) { $plural = preg_replace($regexp, $replacement, $word, -1, $matches); if ($matches > 0) { return $this->setCache($word, 'pluralize', $plural); } } return $this->setCache($word, 'pluralize', $word); }
php
public function pluralize($word) { if ($plural = $this->getCache($word, 'pluralize')) { return $plural; } if (isset($this->_uncountables_keys[$word])) { return $word; } foreach ($this->_pluralizationRules as $regexp => $replacement) { $plural = preg_replace($regexp, $replacement, $word, -1, $matches); if ($matches > 0) { return $this->setCache($word, 'pluralize', $plural); } } return $this->setCache($word, 'pluralize', $word); }
[ "public", "function", "pluralize", "(", "$", "word", ")", "{", "if", "(", "$", "plural", "=", "$", "this", "->", "getCache", "(", "$", "word", ",", "'pluralize'", ")", ")", "{", "return", "$", "plural", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "_uncountables_keys", "[", "$", "word", "]", ")", ")", "{", "return", "$", "word", ";", "}", "foreach", "(", "$", "this", "->", "_pluralizationRules", "as", "$", "regexp", "=>", "$", "replacement", ")", "{", "$", "plural", "=", "preg_replace", "(", "$", "regexp", ",", "$", "replacement", ",", "$", "word", ",", "-", "1", ",", "$", "matches", ")", ";", "if", "(", "$", "matches", ">", "0", ")", "{", "return", "$", "this", "->", "setCache", "(", "$", "word", ",", "'pluralize'", ",", "$", "plural", ")", ";", "}", "}", "return", "$", "this", "->", "setCache", "(", "$", "word", ",", "'pluralize'", ",", "$", "word", ")", ";", "}" ]
Singular English word to pluralize. @param string $word Word to pluralize. @return string Plural form of $word.
[ "Singular", "English", "word", "to", "pluralize", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Inflector.php#L149-L167
215,602
moodle/moodle
lib/horde/framework/Horde/Support/Inflector.php
Horde_Support_Inflector.singularize
public function singularize($word) { if ($singular = $this->getCache($word, 'singularize')) { return $singular; } if (isset($this->_uncountables_keys[$word])) { return $word; } foreach ($this->_singularizationRules as $regexp => $replacement) { $singular = preg_replace($regexp, $replacement, $word, -1, $matches); if ($matches > 0) { return $this->setCache($word, 'singularize', $singular); } } return $this->setCache($word, 'singularize', $word); }
php
public function singularize($word) { if ($singular = $this->getCache($word, 'singularize')) { return $singular; } if (isset($this->_uncountables_keys[$word])) { return $word; } foreach ($this->_singularizationRules as $regexp => $replacement) { $singular = preg_replace($regexp, $replacement, $word, -1, $matches); if ($matches > 0) { return $this->setCache($word, 'singularize', $singular); } } return $this->setCache($word, 'singularize', $word); }
[ "public", "function", "singularize", "(", "$", "word", ")", "{", "if", "(", "$", "singular", "=", "$", "this", "->", "getCache", "(", "$", "word", ",", "'singularize'", ")", ")", "{", "return", "$", "singular", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "_uncountables_keys", "[", "$", "word", "]", ")", ")", "{", "return", "$", "word", ";", "}", "foreach", "(", "$", "this", "->", "_singularizationRules", "as", "$", "regexp", "=>", "$", "replacement", ")", "{", "$", "singular", "=", "preg_replace", "(", "$", "regexp", ",", "$", "replacement", ",", "$", "word", ",", "-", "1", ",", "$", "matches", ")", ";", "if", "(", "$", "matches", ">", "0", ")", "{", "return", "$", "this", "->", "setCache", "(", "$", "word", ",", "'singularize'", ",", "$", "singular", ")", ";", "}", "}", "return", "$", "this", "->", "setCache", "(", "$", "word", ",", "'singularize'", ",", "$", "word", ")", ";", "}" ]
Plural English word to singularize. @param string $word Word to singularize. @return string Singular form of $word.
[ "Plural", "English", "word", "to", "singularize", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Inflector.php#L176-L194
215,603
moodle/moodle
lib/horde/framework/Horde/Support/Inflector.php
Horde_Support_Inflector.camelize
public function camelize($word, $firstLetter = 'upper') { if ($camelized = $this->getCache($word, 'camelize' . $firstLetter)) { return $camelized; } $camelized = $word; if (Horde_String::lower($camelized) != $camelized && strpos($camelized, '_') !== false) { $camelized = str_replace('_', '/', $camelized); } if (strpos($camelized, '/') !== false) { $camelized = str_replace('/', '/ ', $camelized); } if (strpos($camelized, '_') !== false) { $camelized = strtr($camelized, '_', ' '); } $camelized = str_replace(' ', '', Horde_String::ucwords($camelized)); if ($firstLetter == 'lower') { $parts = array(); foreach (explode('/', $camelized) as $part) { $part[0] = Horde_String::lower($part[0]); $parts[] = $part; } $camelized = implode('/', $parts); } return $this->setCache($word, 'camelize' . $firstLetter, $camelized); }
php
public function camelize($word, $firstLetter = 'upper') { if ($camelized = $this->getCache($word, 'camelize' . $firstLetter)) { return $camelized; } $camelized = $word; if (Horde_String::lower($camelized) != $camelized && strpos($camelized, '_') !== false) { $camelized = str_replace('_', '/', $camelized); } if (strpos($camelized, '/') !== false) { $camelized = str_replace('/', '/ ', $camelized); } if (strpos($camelized, '_') !== false) { $camelized = strtr($camelized, '_', ' '); } $camelized = str_replace(' ', '', Horde_String::ucwords($camelized)); if ($firstLetter == 'lower') { $parts = array(); foreach (explode('/', $camelized) as $part) { $part[0] = Horde_String::lower($part[0]); $parts[] = $part; } $camelized = implode('/', $parts); } return $this->setCache($word, 'camelize' . $firstLetter, $camelized); }
[ "public", "function", "camelize", "(", "$", "word", ",", "$", "firstLetter", "=", "'upper'", ")", "{", "if", "(", "$", "camelized", "=", "$", "this", "->", "getCache", "(", "$", "word", ",", "'camelize'", ".", "$", "firstLetter", ")", ")", "{", "return", "$", "camelized", ";", "}", "$", "camelized", "=", "$", "word", ";", "if", "(", "Horde_String", "::", "lower", "(", "$", "camelized", ")", "!=", "$", "camelized", "&&", "strpos", "(", "$", "camelized", ",", "'_'", ")", "!==", "false", ")", "{", "$", "camelized", "=", "str_replace", "(", "'_'", ",", "'/'", ",", "$", "camelized", ")", ";", "}", "if", "(", "strpos", "(", "$", "camelized", ",", "'/'", ")", "!==", "false", ")", "{", "$", "camelized", "=", "str_replace", "(", "'/'", ",", "'/ '", ",", "$", "camelized", ")", ";", "}", "if", "(", "strpos", "(", "$", "camelized", ",", "'_'", ")", "!==", "false", ")", "{", "$", "camelized", "=", "strtr", "(", "$", "camelized", ",", "'_'", ",", "' '", ")", ";", "}", "$", "camelized", "=", "str_replace", "(", "' '", ",", "''", ",", "Horde_String", "::", "ucwords", "(", "$", "camelized", ")", ")", ";", "if", "(", "$", "firstLetter", "==", "'lower'", ")", "{", "$", "parts", "=", "array", "(", ")", ";", "foreach", "(", "explode", "(", "'/'", ",", "$", "camelized", ")", "as", "$", "part", ")", "{", "$", "part", "[", "0", "]", "=", "Horde_String", "::", "lower", "(", "$", "part", "[", "0", "]", ")", ";", "$", "parts", "[", "]", "=", "$", "part", ";", "}", "$", "camelized", "=", "implode", "(", "'/'", ",", "$", "parts", ")", ";", "}", "return", "$", "this", "->", "setCache", "(", "$", "word", ",", "'camelize'", ".", "$", "firstLetter", ",", "$", "camelized", ")", ";", "}" ]
Camel-cases a word. @todo Do we want locale-specific or locale-independent camel casing? @param string $word The word to camel-case. @param string $firstLetter Whether to upper or lower case the first. letter of each slash-separated section. @return string Camelized $word
[ "Camel", "-", "cases", "a", "word", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Inflector.php#L207-L237
215,604
moodle/moodle
lib/horde/framework/Horde/Support/Inflector.php
Horde_Support_Inflector.dasherize
public function dasherize($underscoredWord) { if ($result = $this->getCache($underscoredWord, 'dasherize')) { return $result; } $result = str_replace('_', '-', $this->underscore($underscoredWord)); return $this->setCache($underscoredWord, 'dasherize', $result); }
php
public function dasherize($underscoredWord) { if ($result = $this->getCache($underscoredWord, 'dasherize')) { return $result; } $result = str_replace('_', '-', $this->underscore($underscoredWord)); return $this->setCache($underscoredWord, 'dasherize', $result); }
[ "public", "function", "dasherize", "(", "$", "underscoredWord", ")", "{", "if", "(", "$", "result", "=", "$", "this", "->", "getCache", "(", "$", "underscoredWord", ",", "'dasherize'", ")", ")", "{", "return", "$", "result", ";", "}", "$", "result", "=", "str_replace", "(", "'_'", ",", "'-'", ",", "$", "this", "->", "underscore", "(", "$", "underscoredWord", ")", ")", ";", "return", "$", "this", "->", "setCache", "(", "$", "underscoredWord", ",", "'dasherize'", ",", "$", "result", ")", ";", "}" ]
Replaces underscores with dashes in the string. Example: 1. dasherize("puni_puni") => "puni-puni"
[ "Replaces", "underscores", "with", "dashes", "in", "the", "string", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Inflector.php#L285-L293
215,605
moodle/moodle
lib/horde/framework/Horde/Support/Inflector.php
Horde_Support_Inflector.humanize
public function humanize($lowerCaseAndUnderscoredWord) { $word = $lowerCaseAndUnderscoredWord; if ($result = $this->getCache($word, 'humanize')) { return $result; } $result = ucfirst(str_replace('_', ' ', $this->underscore($word))); if (substr($result, -3, 3) == ' id') { $result = str_replace(' id', '', $result); } return $this->setCache($word, 'humanize', $result); }
php
public function humanize($lowerCaseAndUnderscoredWord) { $word = $lowerCaseAndUnderscoredWord; if ($result = $this->getCache($word, 'humanize')) { return $result; } $result = ucfirst(str_replace('_', ' ', $this->underscore($word))); if (substr($result, -3, 3) == ' id') { $result = str_replace(' id', '', $result); } return $this->setCache($word, 'humanize', $result); }
[ "public", "function", "humanize", "(", "$", "lowerCaseAndUnderscoredWord", ")", "{", "$", "word", "=", "$", "lowerCaseAndUnderscoredWord", ";", "if", "(", "$", "result", "=", "$", "this", "->", "getCache", "(", "$", "word", ",", "'humanize'", ")", ")", "{", "return", "$", "result", ";", "}", "$", "result", "=", "ucfirst", "(", "str_replace", "(", "'_'", ",", "' '", ",", "$", "this", "->", "underscore", "(", "$", "word", ")", ")", ")", ";", "if", "(", "substr", "(", "$", "result", ",", "-", "3", ",", "3", ")", "==", "' id'", ")", "{", "$", "result", "=", "str_replace", "(", "' id'", ",", "''", ",", "$", "result", ")", ";", "}", "return", "$", "this", "->", "setCache", "(", "$", "word", ",", "'humanize'", ",", "$", "result", ")", ";", "}" ]
Capitalizes the first word and turns underscores into spaces and strips _id. Like titleize(), this is meant for creating pretty output. Examples: 1. humanize("employee_salary") => "Employee salary" 2. humanize("author_id") => "Author"
[ "Capitalizes", "the", "first", "word", "and", "turns", "underscores", "into", "spaces", "and", "strips", "_id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Inflector.php#L305-L317
215,606
moodle/moodle
lib/horde/framework/Horde/Support/Inflector.php
Horde_Support_Inflector.tableize
public function tableize($className) { if ($result = $this->getCache($className, 'tableize')) { return $result; } $result = $this->pluralize($this->underscore($className)); $result = str_replace('/', '_', $result); return $this->setCache($className, 'tableize', $result); }
php
public function tableize($className) { if ($result = $this->getCache($className, 'tableize')) { return $result; } $result = $this->pluralize($this->underscore($className)); $result = str_replace('/', '_', $result); return $this->setCache($className, 'tableize', $result); }
[ "public", "function", "tableize", "(", "$", "className", ")", "{", "if", "(", "$", "result", "=", "$", "this", "->", "getCache", "(", "$", "className", ",", "'tableize'", ")", ")", "{", "return", "$", "result", ";", "}", "$", "result", "=", "$", "this", "->", "pluralize", "(", "$", "this", "->", "underscore", "(", "$", "className", ")", ")", ";", "$", "result", "=", "str_replace", "(", "'/'", ",", "'_'", ",", "$", "result", ")", ";", "return", "$", "this", "->", "setCache", "(", "$", "className", ",", "'tableize'", ",", "$", "result", ")", ";", "}" ]
Creates the name of a table like Rails does for models to table names. This method uses the pluralize() method on the last word in the string. Examples: 1. tableize("RawScaledScorer") => "raw_scaled_scorers" 2. tableize("egg_and_ham") => "egg_and_hams" 3. tableize("fancyCategory") => "fancy_categories"
[ "Creates", "the", "name", "of", "a", "table", "like", "Rails", "does", "for", "models", "to", "table", "names", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Inflector.php#L342-L351
215,607
moodle/moodle
lib/horde/framework/Horde/Support/Inflector.php
Horde_Support_Inflector.classify
public function classify($tableName) { if ($result = $this->getCache($tableName, 'classify')) { return $result; } $result = $this->camelize($this->singularize($tableName)); // classes use underscores instead of slashes for namespaces $result = str_replace('/', '_', $result); return $this->setCache($tableName, 'classify', $result); }
php
public function classify($tableName) { if ($result = $this->getCache($tableName, 'classify')) { return $result; } $result = $this->camelize($this->singularize($tableName)); // classes use underscores instead of slashes for namespaces $result = str_replace('/', '_', $result); return $this->setCache($tableName, 'classify', $result); }
[ "public", "function", "classify", "(", "$", "tableName", ")", "{", "if", "(", "$", "result", "=", "$", "this", "->", "getCache", "(", "$", "tableName", ",", "'classify'", ")", ")", "{", "return", "$", "result", ";", "}", "$", "result", "=", "$", "this", "->", "camelize", "(", "$", "this", "->", "singularize", "(", "$", "tableName", ")", ")", ";", "// classes use underscores instead of slashes for namespaces", "$", "result", "=", "str_replace", "(", "'/'", ",", "'_'", ",", "$", "result", ")", ";", "return", "$", "this", "->", "setCache", "(", "$", "tableName", ",", "'classify'", ",", "$", "result", ")", ";", "}" ]
Creates a class name from a table name like Rails does for table names to models. Examples: 1. classify("egg_and_hams") => "EggAndHam" 2. classify("post") => "Post"
[ "Creates", "a", "class", "name", "from", "a", "table", "name", "like", "Rails", "does", "for", "table", "names", "to", "models", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Inflector.php#L361-L371
215,608
moodle/moodle
lib/horde/framework/Horde/Support/Inflector.php
Horde_Support_Inflector.getCache
public function getCache($word, $rule) { return isset($this->_cache[$word . '|' . $rule]) ? $this->_cache[$word . '|' . $rule] : false; }
php
public function getCache($word, $rule) { return isset($this->_cache[$word . '|' . $rule]) ? $this->_cache[$word . '|' . $rule] : false; }
[ "public", "function", "getCache", "(", "$", "word", ",", "$", "rule", ")", "{", "return", "isset", "(", "$", "this", "->", "_cache", "[", "$", "word", ".", "'|'", ".", "$", "rule", "]", ")", "?", "$", "this", "->", "_cache", "[", "$", "word", ".", "'|'", ".", "$", "rule", "]", ":", "false", ";", "}" ]
Retuns a cached inflection. @return string | false
[ "Retuns", "a", "cached", "inflection", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Inflector.php#L417-L421
215,609
moodle/moodle
lib/horde/framework/Horde/Support/Inflector.php
Horde_Support_Inflector.setCache
public function setCache($word, $rule, $value) { $this->_cache[$word . '|' . $rule] = $value; return $value; }
php
public function setCache($word, $rule, $value) { $this->_cache[$word . '|' . $rule] = $value; return $value; }
[ "public", "function", "setCache", "(", "$", "word", ",", "$", "rule", ",", "$", "value", ")", "{", "$", "this", "->", "_cache", "[", "$", "word", ".", "'|'", ".", "$", "rule", "]", "=", "$", "value", ";", "return", "$", "value", ";", "}" ]
Caches an inflection. @param string $word The word being inflected. @param string $rule The inflection rule. @param string $value The inflected value of $word. @return string The inflected value
[ "Caches", "an", "inflection", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Inflector.php#L432-L436
215,610
moodle/moodle
mod/forum/classes/local/vaults/preprocessors/extract_user.php
extract_user.execute
public function execute(array $records) : array { $idalias = $this->idalias; $alias = $this->alias; return array_map(function($record) use ($idalias, $alias) { return user_picture::unalias($record, null, $idalias, $alias); }, $records); }
php
public function execute(array $records) : array { $idalias = $this->idalias; $alias = $this->alias; return array_map(function($record) use ($idalias, $alias) { return user_picture::unalias($record, null, $idalias, $alias); }, $records); }
[ "public", "function", "execute", "(", "array", "$", "records", ")", ":", "array", "{", "$", "idalias", "=", "$", "this", "->", "idalias", ";", "$", "alias", "=", "$", "this", "->", "alias", ";", "return", "array_map", "(", "function", "(", "$", "record", ")", "use", "(", "$", "idalias", ",", "$", "alias", ")", "{", "return", "user_picture", "::", "unalias", "(", "$", "record", ",", "null", ",", "$", "idalias", ",", "$", "alias", ")", ";", "}", ",", "$", "records", ")", ";", "}" ]
Extract the user records from a list of DB records. @param stdClass[] $records The DB records @return stdClass[] The list of extracted users
[ "Extract", "the", "user", "records", "from", "a", "list", "of", "DB", "records", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/preprocessors/extract_user.php#L63-L70
215,611
moodle/moodle
search/classes/engine.php
engine.get_course
protected function get_course($courseid) { if (!empty($this->cachedcourses[$courseid])) { return $this->cachedcourses[$courseid]; } // No need to clone, only read. $this->cachedcourses[$courseid] = get_course($courseid, false); return $this->cachedcourses[$courseid]; }
php
protected function get_course($courseid) { if (!empty($this->cachedcourses[$courseid])) { return $this->cachedcourses[$courseid]; } // No need to clone, only read. $this->cachedcourses[$courseid] = get_course($courseid, false); return $this->cachedcourses[$courseid]; }
[ "protected", "function", "get_course", "(", "$", "courseid", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "cachedcourses", "[", "$", "courseid", "]", ")", ")", "{", "return", "$", "this", "->", "cachedcourses", "[", "$", "courseid", "]", ";", "}", "// No need to clone, only read.", "$", "this", "->", "cachedcourses", "[", "$", "courseid", "]", "=", "get_course", "(", "$", "courseid", ",", "false", ")", ";", "return", "$", "this", "->", "cachedcourses", "[", "$", "courseid", "]", ";", "}" ]
Returns a course instance checking internal caching. @param int $courseid @return stdClass
[ "Returns", "a", "course", "instance", "checking", "internal", "caching", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/engine.php#L113-L122
215,612
moodle/moodle
search/classes/engine.php
engine.get_user
public function get_user($userid) { global $DB; if (empty(self::$cachedusers[$userid])) { $fields = get_all_user_name_fields(true); self::$cachedusers[$userid] = $DB->get_record('user', array('id' => $userid), 'id, ' . $fields); } return self::$cachedusers[$userid]; }
php
public function get_user($userid) { global $DB; if (empty(self::$cachedusers[$userid])) { $fields = get_all_user_name_fields(true); self::$cachedusers[$userid] = $DB->get_record('user', array('id' => $userid), 'id, ' . $fields); } return self::$cachedusers[$userid]; }
[ "public", "function", "get_user", "(", "$", "userid", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "self", "::", "$", "cachedusers", "[", "$", "userid", "]", ")", ")", "{", "$", "fields", "=", "get_all_user_name_fields", "(", "true", ")", ";", "self", "::", "$", "cachedusers", "[", "$", "userid", "]", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "userid", ")", ",", "'id, '", ".", "$", "fields", ")", ";", "}", "return", "self", "::", "$", "cachedusers", "[", "$", "userid", "]", ";", "}" ]
Returns user data checking the internal static cache. Including here the minimum required user information as this may grow big. @param int $userid @return stdClass
[ "Returns", "user", "data", "checking", "the", "internal", "static", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/engine.php#L132-L140
215,613
moodle/moodle
search/classes/engine.php
engine.get_search_area
protected function get_search_area($areaid) { if (isset($this->cachedareas[$areaid]) && $this->cachedareas[$areaid] === false) { // We already checked that area and it is not available. return false; } if (!isset($this->cachedareas[$areaid])) { // First result that matches this area. $this->cachedareas[$areaid] = \core_search\manager::get_search_area($areaid); if ($this->cachedareas[$areaid] === false) { // The area does not exist or it is not available any more. $this->cachedareas[$areaid] = false; return false; } if (!$this->cachedareas[$areaid]->is_enabled()) { // We skip the area if it is not enabled. // Marking it as false so next time we don' need to check it again. $this->cachedareas[$areaid] = false; return false; } } return $this->cachedareas[$areaid]; }
php
protected function get_search_area($areaid) { if (isset($this->cachedareas[$areaid]) && $this->cachedareas[$areaid] === false) { // We already checked that area and it is not available. return false; } if (!isset($this->cachedareas[$areaid])) { // First result that matches this area. $this->cachedareas[$areaid] = \core_search\manager::get_search_area($areaid); if ($this->cachedareas[$areaid] === false) { // The area does not exist or it is not available any more. $this->cachedareas[$areaid] = false; return false; } if (!$this->cachedareas[$areaid]->is_enabled()) { // We skip the area if it is not enabled. // Marking it as false so next time we don' need to check it again. $this->cachedareas[$areaid] = false; return false; } } return $this->cachedareas[$areaid]; }
[ "protected", "function", "get_search_area", "(", "$", "areaid", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "cachedareas", "[", "$", "areaid", "]", ")", "&&", "$", "this", "->", "cachedareas", "[", "$", "areaid", "]", "===", "false", ")", "{", "// We already checked that area and it is not available.", "return", "false", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "cachedareas", "[", "$", "areaid", "]", ")", ")", "{", "// First result that matches this area.", "$", "this", "->", "cachedareas", "[", "$", "areaid", "]", "=", "\\", "core_search", "\\", "manager", "::", "get_search_area", "(", "$", "areaid", ")", ";", "if", "(", "$", "this", "->", "cachedareas", "[", "$", "areaid", "]", "===", "false", ")", "{", "// The area does not exist or it is not available any more.", "$", "this", "->", "cachedareas", "[", "$", "areaid", "]", "=", "false", ";", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "cachedareas", "[", "$", "areaid", "]", "->", "is_enabled", "(", ")", ")", "{", "// We skip the area if it is not enabled.", "// Marking it as false so next time we don' need to check it again.", "$", "this", "->", "cachedareas", "[", "$", "areaid", "]", "=", "false", ";", "return", "false", ";", "}", "}", "return", "$", "this", "->", "cachedareas", "[", "$", "areaid", "]", ";", "}" ]
Returns a search instance of the specified area checking internal caching. @param string $areaid Area id @return \core_search\base
[ "Returns", "a", "search", "instance", "of", "the", "specified", "area", "checking", "internal", "caching", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/engine.php#L157-L186
215,614
moodle/moodle
search/classes/engine.php
engine.to_document
protected function to_document(\core_search\base $searcharea, $docdata) { list($componentname, $areaname) = \core_search\manager::extract_areaid_parts($docdata['areaid']); $doc = \core_search\document_factory::instance($docdata['itemid'], $componentname, $areaname, $this); $doc->set_data_from_engine($docdata); $doc->set_doc_url($searcharea->get_doc_url($doc)); $doc->set_context_url($searcharea->get_context_url($doc)); $doc->set_doc_icon($searcharea->get_doc_icon($doc)); // Uses the internal caches to get required data needed to render the document later. $course = $this->get_course($doc->get('courseid')); $doc->set_extra('coursefullname', $course->fullname); if ($doc->is_set('userid')) { $user = $this->get_user($doc->get('userid')); $doc->set_extra('userfullname', fullname($user)); } return $doc; }
php
protected function to_document(\core_search\base $searcharea, $docdata) { list($componentname, $areaname) = \core_search\manager::extract_areaid_parts($docdata['areaid']); $doc = \core_search\document_factory::instance($docdata['itemid'], $componentname, $areaname, $this); $doc->set_data_from_engine($docdata); $doc->set_doc_url($searcharea->get_doc_url($doc)); $doc->set_context_url($searcharea->get_context_url($doc)); $doc->set_doc_icon($searcharea->get_doc_icon($doc)); // Uses the internal caches to get required data needed to render the document later. $course = $this->get_course($doc->get('courseid')); $doc->set_extra('coursefullname', $course->fullname); if ($doc->is_set('userid')) { $user = $this->get_user($doc->get('userid')); $doc->set_extra('userfullname', fullname($user)); } return $doc; }
[ "protected", "function", "to_document", "(", "\\", "core_search", "\\", "base", "$", "searcharea", ",", "$", "docdata", ")", "{", "list", "(", "$", "componentname", ",", "$", "areaname", ")", "=", "\\", "core_search", "\\", "manager", "::", "extract_areaid_parts", "(", "$", "docdata", "[", "'areaid'", "]", ")", ";", "$", "doc", "=", "\\", "core_search", "\\", "document_factory", "::", "instance", "(", "$", "docdata", "[", "'itemid'", "]", ",", "$", "componentname", ",", "$", "areaname", ",", "$", "this", ")", ";", "$", "doc", "->", "set_data_from_engine", "(", "$", "docdata", ")", ";", "$", "doc", "->", "set_doc_url", "(", "$", "searcharea", "->", "get_doc_url", "(", "$", "doc", ")", ")", ";", "$", "doc", "->", "set_context_url", "(", "$", "searcharea", "->", "get_context_url", "(", "$", "doc", ")", ")", ";", "$", "doc", "->", "set_doc_icon", "(", "$", "searcharea", "->", "get_doc_icon", "(", "$", "doc", ")", ")", ";", "// Uses the internal caches to get required data needed to render the document later.", "$", "course", "=", "$", "this", "->", "get_course", "(", "$", "doc", "->", "get", "(", "'courseid'", ")", ")", ";", "$", "doc", "->", "set_extra", "(", "'coursefullname'", ",", "$", "course", "->", "fullname", ")", ";", "if", "(", "$", "doc", "->", "is_set", "(", "'userid'", ")", ")", "{", "$", "user", "=", "$", "this", "->", "get_user", "(", "$", "doc", "->", "get", "(", "'userid'", ")", ")", ";", "$", "doc", "->", "set_extra", "(", "'userfullname'", ",", "fullname", "(", "$", "user", ")", ")", ";", "}", "return", "$", "doc", ";", "}" ]
Returns a document instance prepared to be rendered. @param \core_search\base $searcharea @param array $docdata @return \core_search\document
[ "Returns", "a", "document", "instance", "prepared", "to", "be", "rendered", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/engine.php#L195-L214
215,615
moodle/moodle
search/classes/engine.php
engine.add_documents
public function add_documents($iterator, $searcharea, $options) { $numrecords = 0; $numdocs = 0; $numdocsignored = 0; $lastindexeddoc = 0; $firstindexeddoc = 0; $partial = false; $lastprogress = manager::get_current_time(); foreach ($iterator as $document) { // Stop if we have exceeded the time limit (and there are still more items). Always // do at least one second's worth of documents otherwise it will never make progress. if ($lastindexeddoc !== $firstindexeddoc && !empty($options['stopat']) && manager::get_current_time() >= $options['stopat']) { $partial = true; break; } if (!$document instanceof \core_search\document) { continue; } if (isset($options['lastindexedtime']) && $options['lastindexedtime'] == 0) { // If we have never indexed this area before, it must be new. $document->set_is_new(true); } if ($options['indexfiles']) { // Attach files if we are indexing. $searcharea->attach_files($document); } if ($this->add_document($document, $options['indexfiles'])) { $numdocs++; } else { $numdocsignored++; } $lastindexeddoc = $document->get('modified'); if (!$firstindexeddoc) { $firstindexeddoc = $lastindexeddoc; } $numrecords++; // If indexing the area takes a long time, periodically output progress information. if (isset($options['progress'])) { $now = manager::get_current_time(); if ($now - $lastprogress >= manager::DISPLAY_INDEXING_PROGRESS_EVERY) { $lastprogress = $now; // The first date format is the same used in cron_trace_time_and_memory(). $options['progress']->output(date('H:i:s', $now) . ': Done to ' . userdate( $lastindexeddoc, get_string('strftimedatetimeshort', 'langconfig')), 1); } } } return array($numrecords, $numdocs, $numdocsignored, $lastindexeddoc, $partial); }
php
public function add_documents($iterator, $searcharea, $options) { $numrecords = 0; $numdocs = 0; $numdocsignored = 0; $lastindexeddoc = 0; $firstindexeddoc = 0; $partial = false; $lastprogress = manager::get_current_time(); foreach ($iterator as $document) { // Stop if we have exceeded the time limit (and there are still more items). Always // do at least one second's worth of documents otherwise it will never make progress. if ($lastindexeddoc !== $firstindexeddoc && !empty($options['stopat']) && manager::get_current_time() >= $options['stopat']) { $partial = true; break; } if (!$document instanceof \core_search\document) { continue; } if (isset($options['lastindexedtime']) && $options['lastindexedtime'] == 0) { // If we have never indexed this area before, it must be new. $document->set_is_new(true); } if ($options['indexfiles']) { // Attach files if we are indexing. $searcharea->attach_files($document); } if ($this->add_document($document, $options['indexfiles'])) { $numdocs++; } else { $numdocsignored++; } $lastindexeddoc = $document->get('modified'); if (!$firstindexeddoc) { $firstindexeddoc = $lastindexeddoc; } $numrecords++; // If indexing the area takes a long time, periodically output progress information. if (isset($options['progress'])) { $now = manager::get_current_time(); if ($now - $lastprogress >= manager::DISPLAY_INDEXING_PROGRESS_EVERY) { $lastprogress = $now; // The first date format is the same used in cron_trace_time_and_memory(). $options['progress']->output(date('H:i:s', $now) . ': Done to ' . userdate( $lastindexeddoc, get_string('strftimedatetimeshort', 'langconfig')), 1); } } } return array($numrecords, $numdocs, $numdocsignored, $lastindexeddoc, $partial); }
[ "public", "function", "add_documents", "(", "$", "iterator", ",", "$", "searcharea", ",", "$", "options", ")", "{", "$", "numrecords", "=", "0", ";", "$", "numdocs", "=", "0", ";", "$", "numdocsignored", "=", "0", ";", "$", "lastindexeddoc", "=", "0", ";", "$", "firstindexeddoc", "=", "0", ";", "$", "partial", "=", "false", ";", "$", "lastprogress", "=", "manager", "::", "get_current_time", "(", ")", ";", "foreach", "(", "$", "iterator", "as", "$", "document", ")", "{", "// Stop if we have exceeded the time limit (and there are still more items). Always", "// do at least one second's worth of documents otherwise it will never make progress.", "if", "(", "$", "lastindexeddoc", "!==", "$", "firstindexeddoc", "&&", "!", "empty", "(", "$", "options", "[", "'stopat'", "]", ")", "&&", "manager", "::", "get_current_time", "(", ")", ">=", "$", "options", "[", "'stopat'", "]", ")", "{", "$", "partial", "=", "true", ";", "break", ";", "}", "if", "(", "!", "$", "document", "instanceof", "\\", "core_search", "\\", "document", ")", "{", "continue", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'lastindexedtime'", "]", ")", "&&", "$", "options", "[", "'lastindexedtime'", "]", "==", "0", ")", "{", "// If we have never indexed this area before, it must be new.", "$", "document", "->", "set_is_new", "(", "true", ")", ";", "}", "if", "(", "$", "options", "[", "'indexfiles'", "]", ")", "{", "// Attach files if we are indexing.", "$", "searcharea", "->", "attach_files", "(", "$", "document", ")", ";", "}", "if", "(", "$", "this", "->", "add_document", "(", "$", "document", ",", "$", "options", "[", "'indexfiles'", "]", ")", ")", "{", "$", "numdocs", "++", ";", "}", "else", "{", "$", "numdocsignored", "++", ";", "}", "$", "lastindexeddoc", "=", "$", "document", "->", "get", "(", "'modified'", ")", ";", "if", "(", "!", "$", "firstindexeddoc", ")", "{", "$", "firstindexeddoc", "=", "$", "lastindexeddoc", ";", "}", "$", "numrecords", "++", ";", "// If indexing the area takes a long time, periodically output progress information.", "if", "(", "isset", "(", "$", "options", "[", "'progress'", "]", ")", ")", "{", "$", "now", "=", "manager", "::", "get_current_time", "(", ")", ";", "if", "(", "$", "now", "-", "$", "lastprogress", ">=", "manager", "::", "DISPLAY_INDEXING_PROGRESS_EVERY", ")", "{", "$", "lastprogress", "=", "$", "now", ";", "// The first date format is the same used in cron_trace_time_and_memory().", "$", "options", "[", "'progress'", "]", "->", "output", "(", "date", "(", "'H:i:s'", ",", "$", "now", ")", ".", "': Done to '", ".", "userdate", "(", "$", "lastindexeddoc", ",", "get_string", "(", "'strftimedatetimeshort'", ",", "'langconfig'", ")", ")", ",", "1", ")", ";", "}", "}", "}", "return", "array", "(", "$", "numrecords", ",", "$", "numdocs", ",", "$", "numdocsignored", ",", "$", "lastindexeddoc", ",", "$", "partial", ")", ";", "}" ]
Loop through given iterator of search documents and and have the search engine back end add them to the index. @param iterator $iterator the iterator of documents to index @param searcharea $searcharea the area for the documents to index @param array $options document indexing options @return array Processed document counts
[ "Loop", "through", "given", "iterator", "of", "search", "documents", "and", "and", "have", "the", "search", "engine", "back", "end", "add", "them", "to", "the", "index", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/engine.php#L226-L283
215,616
moodle/moodle
lib/classes/hub/site_registration_form.php
site_registration_form.get_data
public function get_data() { if ($data = parent::get_data()) { // Never return '*newemail' checkboxes, always return 'emailalertemail' and 'commnewsemail' even if not applicable. if (empty($data->emailalert) || empty($data->emailalertnewemail)) { $data->emailalertemail = null; } unset($data->emailalertnewemail); if (empty($data->commnews) || empty($data->commnewsnewemail)) { $data->commnewsemail = null; } unset($data->commnewsnewemail); // Always return 'contactable'. $data->contactable = empty($data->contactable) ? 0 : 1; if (debugging('', DEBUG_DEVELOPER)) { // Display debugging message for developers who added fields to the form and forgot to add them to registration::FORM_FIELDS. $keys = array_diff(array_keys((array)$data), ['returnurl', 'mform_isexpanded_id_sitestats', 'submitbutton', 'update']); if ($extrafields = array_diff($keys, registration::FORM_FIELDS)) { debugging('Found extra fields in the form results: ' . join(', ', $extrafields), DEBUG_DEVELOPER); } if ($missingfields = array_diff(registration::FORM_FIELDS, $keys)) { debugging('Some fields are missing in the form results: ' . join(', ', $missingfields), DEBUG_DEVELOPER); } } } return $data; }
php
public function get_data() { if ($data = parent::get_data()) { // Never return '*newemail' checkboxes, always return 'emailalertemail' and 'commnewsemail' even if not applicable. if (empty($data->emailalert) || empty($data->emailalertnewemail)) { $data->emailalertemail = null; } unset($data->emailalertnewemail); if (empty($data->commnews) || empty($data->commnewsnewemail)) { $data->commnewsemail = null; } unset($data->commnewsnewemail); // Always return 'contactable'. $data->contactable = empty($data->contactable) ? 0 : 1; if (debugging('', DEBUG_DEVELOPER)) { // Display debugging message for developers who added fields to the form and forgot to add them to registration::FORM_FIELDS. $keys = array_diff(array_keys((array)$data), ['returnurl', 'mform_isexpanded_id_sitestats', 'submitbutton', 'update']); if ($extrafields = array_diff($keys, registration::FORM_FIELDS)) { debugging('Found extra fields in the form results: ' . join(', ', $extrafields), DEBUG_DEVELOPER); } if ($missingfields = array_diff(registration::FORM_FIELDS, $keys)) { debugging('Some fields are missing in the form results: ' . join(', ', $missingfields), DEBUG_DEVELOPER); } } } return $data; }
[ "public", "function", "get_data", "(", ")", "{", "if", "(", "$", "data", "=", "parent", "::", "get_data", "(", ")", ")", "{", "// Never return '*newemail' checkboxes, always return 'emailalertemail' and 'commnewsemail' even if not applicable.", "if", "(", "empty", "(", "$", "data", "->", "emailalert", ")", "||", "empty", "(", "$", "data", "->", "emailalertnewemail", ")", ")", "{", "$", "data", "->", "emailalertemail", "=", "null", ";", "}", "unset", "(", "$", "data", "->", "emailalertnewemail", ")", ";", "if", "(", "empty", "(", "$", "data", "->", "commnews", ")", "||", "empty", "(", "$", "data", "->", "commnewsnewemail", ")", ")", "{", "$", "data", "->", "commnewsemail", "=", "null", ";", "}", "unset", "(", "$", "data", "->", "commnewsnewemail", ")", ";", "// Always return 'contactable'.", "$", "data", "->", "contactable", "=", "empty", "(", "$", "data", "->", "contactable", ")", "?", "0", ":", "1", ";", "if", "(", "debugging", "(", "''", ",", "DEBUG_DEVELOPER", ")", ")", "{", "// Display debugging message for developers who added fields to the form and forgot to add them to registration::FORM_FIELDS.", "$", "keys", "=", "array_diff", "(", "array_keys", "(", "(", "array", ")", "$", "data", ")", ",", "[", "'returnurl'", ",", "'mform_isexpanded_id_sitestats'", ",", "'submitbutton'", ",", "'update'", "]", ")", ";", "if", "(", "$", "extrafields", "=", "array_diff", "(", "$", "keys", ",", "registration", "::", "FORM_FIELDS", ")", ")", "{", "debugging", "(", "'Found extra fields in the form results: '", ".", "join", "(", "', '", ",", "$", "extrafields", ")", ",", "DEBUG_DEVELOPER", ")", ";", "}", "if", "(", "$", "missingfields", "=", "array_diff", "(", "registration", "::", "FORM_FIELDS", ",", "$", "keys", ")", ")", "{", "debugging", "(", "'Some fields are missing in the form results: '", ".", "join", "(", "', '", ",", "$", "missingfields", ")", ",", "DEBUG_DEVELOPER", ")", ";", "}", "}", "}", "return", "$", "data", ";", "}" ]
Returns the form data @return stdClass
[ "Returns", "the", "form", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/site_registration_form.php#L256-L283
215,617
moodle/moodle
backup/util/helper/backup_anonymizer_helper.class.php
backup_anonymizer_helper.is_anonymous_user
public static function is_anonymous_user($user) { if (preg_match('/^anon\d*$/', $user->username)) { $match = preg_match('/^anonfirstname\d*$/', $user->firstname); $match = $match && preg_match('/^anonlastname\d*$/', $user->lastname); // Check .com for backwards compatibility. $emailmatch = preg_match('/^anon\d*@doesntexist\.com$/', $user->email) || preg_match('/^anon\d*@doesntexist\.invalid$/', $user->email); if ($match && $emailmatch) { return true; } } return false; }
php
public static function is_anonymous_user($user) { if (preg_match('/^anon\d*$/', $user->username)) { $match = preg_match('/^anonfirstname\d*$/', $user->firstname); $match = $match && preg_match('/^anonlastname\d*$/', $user->lastname); // Check .com for backwards compatibility. $emailmatch = preg_match('/^anon\d*@doesntexist\.com$/', $user->email) || preg_match('/^anon\d*@doesntexist\.invalid$/', $user->email); if ($match && $emailmatch) { return true; } } return false; }
[ "public", "static", "function", "is_anonymous_user", "(", "$", "user", ")", "{", "if", "(", "preg_match", "(", "'/^anon\\d*$/'", ",", "$", "user", "->", "username", ")", ")", "{", "$", "match", "=", "preg_match", "(", "'/^anonfirstname\\d*$/'", ",", "$", "user", "->", "firstname", ")", ";", "$", "match", "=", "$", "match", "&&", "preg_match", "(", "'/^anonlastname\\d*$/'", ",", "$", "user", "->", "lastname", ")", ";", "// Check .com for backwards compatibility.", "$", "emailmatch", "=", "preg_match", "(", "'/^anon\\d*@doesntexist\\.com$/'", ",", "$", "user", "->", "email", ")", "||", "preg_match", "(", "'/^anon\\d*@doesntexist\\.invalid$/'", ",", "$", "user", "->", "email", ")", ";", "if", "(", "$", "match", "&&", "$", "emailmatch", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Determine if the given user is an 'anonymous' user, based on their username, firstname, lastname and email address. @param stdClass $user the user record to test @return bool true if this is an 'anonymous' user
[ "Determine", "if", "the", "given", "user", "is", "an", "anonymous", "user", "based", "on", "their", "username", "firstname", "lastname", "and", "email", "address", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/backup_anonymizer_helper.class.php#L55-L67
215,618
moodle/moodle
webservice/soap/locallib.php
webservice_soap_server.run
public function run() { // We will probably need a lot of memory in some functions. raise_memory_limit(MEMORY_EXTRA); // Set some longer timeout since operations may need longer time to finish. external_api::set_timeout(); // Set up exception handler. set_exception_handler(array($this, 'exception_handler')); // Init all properties from the request data. $this->parse_request(); // Authenticate user, this has to be done after the request parsing. This also sets up $USER and $SESSION. $this->authenticate_user(); // Make a list of all functions user is allowed to execute. $this->init_service_class(); if ($this->wsdlmode) { // Generate the WSDL. $this->generate_wsdl(); } // Log the web service request. $params = array( 'other' => array( 'function' => 'unknown' ) ); $event = \core\event\webservice_function_called::create($params); $logdataparams = array(SITEID, 'webservice_soap', '', '', $this->serviceclass . ' ' . getremoteaddr(), 0, $this->userid); $event->set_legacy_logdata($logdataparams); $event->trigger(); // Handle the SOAP request. $this->handle(); // Session cleanup. $this->session_cleanup(); die; }
php
public function run() { // We will probably need a lot of memory in some functions. raise_memory_limit(MEMORY_EXTRA); // Set some longer timeout since operations may need longer time to finish. external_api::set_timeout(); // Set up exception handler. set_exception_handler(array($this, 'exception_handler')); // Init all properties from the request data. $this->parse_request(); // Authenticate user, this has to be done after the request parsing. This also sets up $USER and $SESSION. $this->authenticate_user(); // Make a list of all functions user is allowed to execute. $this->init_service_class(); if ($this->wsdlmode) { // Generate the WSDL. $this->generate_wsdl(); } // Log the web service request. $params = array( 'other' => array( 'function' => 'unknown' ) ); $event = \core\event\webservice_function_called::create($params); $logdataparams = array(SITEID, 'webservice_soap', '', '', $this->serviceclass . ' ' . getremoteaddr(), 0, $this->userid); $event->set_legacy_logdata($logdataparams); $event->trigger(); // Handle the SOAP request. $this->handle(); // Session cleanup. $this->session_cleanup(); die; }
[ "public", "function", "run", "(", ")", "{", "// We will probably need a lot of memory in some functions.", "raise_memory_limit", "(", "MEMORY_EXTRA", ")", ";", "// Set some longer timeout since operations may need longer time to finish.", "external_api", "::", "set_timeout", "(", ")", ";", "// Set up exception handler.", "set_exception_handler", "(", "array", "(", "$", "this", ",", "'exception_handler'", ")", ")", ";", "// Init all properties from the request data.", "$", "this", "->", "parse_request", "(", ")", ";", "// Authenticate user, this has to be done after the request parsing. This also sets up $USER and $SESSION.", "$", "this", "->", "authenticate_user", "(", ")", ";", "// Make a list of all functions user is allowed to execute.", "$", "this", "->", "init_service_class", "(", ")", ";", "if", "(", "$", "this", "->", "wsdlmode", ")", "{", "// Generate the WSDL.", "$", "this", "->", "generate_wsdl", "(", ")", ";", "}", "// Log the web service request.", "$", "params", "=", "array", "(", "'other'", "=>", "array", "(", "'function'", "=>", "'unknown'", ")", ")", ";", "$", "event", "=", "\\", "core", "\\", "event", "\\", "webservice_function_called", "::", "create", "(", "$", "params", ")", ";", "$", "logdataparams", "=", "array", "(", "SITEID", ",", "'webservice_soap'", ",", "''", ",", "''", ",", "$", "this", "->", "serviceclass", ".", "' '", ".", "getremoteaddr", "(", ")", ",", "0", ",", "$", "this", "->", "userid", ")", ";", "$", "event", "->", "set_legacy_logdata", "(", "$", "logdataparams", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "// Handle the SOAP request.", "$", "this", "->", "handle", "(", ")", ";", "// Session cleanup.", "$", "this", "->", "session_cleanup", "(", ")", ";", "die", ";", "}" ]
Runs the SOAP web service. @throws coding_exception @throws moodle_exception @throws webservice_access_exception
[ "Runs", "the", "SOAP", "web", "service", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/soap/locallib.php#L112-L153
215,619
moodle/moodle
webservice/soap/locallib.php
webservice_soap_server.generate_wsdl
protected function generate_wsdl() { // Initialise WSDL. $this->wsdl = new wsdl($this->serviceclass, $this->serverurl); // Register service struct classes as complex types. foreach ($this->servicestructs as $structinfo) { $this->wsdl->add_complex_type($structinfo->classname, $structinfo->properties); } // Register the method for the WSDL generation. foreach ($this->servicemethods as $methodinfo) { $this->wsdl->register($methodinfo->name, $methodinfo->inputparams, $methodinfo->outputparams, $methodinfo->description); } }
php
protected function generate_wsdl() { // Initialise WSDL. $this->wsdl = new wsdl($this->serviceclass, $this->serverurl); // Register service struct classes as complex types. foreach ($this->servicestructs as $structinfo) { $this->wsdl->add_complex_type($structinfo->classname, $structinfo->properties); } // Register the method for the WSDL generation. foreach ($this->servicemethods as $methodinfo) { $this->wsdl->register($methodinfo->name, $methodinfo->inputparams, $methodinfo->outputparams, $methodinfo->description); } }
[ "protected", "function", "generate_wsdl", "(", ")", "{", "// Initialise WSDL.", "$", "this", "->", "wsdl", "=", "new", "wsdl", "(", "$", "this", "->", "serviceclass", ",", "$", "this", "->", "serverurl", ")", ";", "// Register service struct classes as complex types.", "foreach", "(", "$", "this", "->", "servicestructs", "as", "$", "structinfo", ")", "{", "$", "this", "->", "wsdl", "->", "add_complex_type", "(", "$", "structinfo", "->", "classname", ",", "$", "structinfo", "->", "properties", ")", ";", "}", "// Register the method for the WSDL generation.", "foreach", "(", "$", "this", "->", "servicemethods", "as", "$", "methodinfo", ")", "{", "$", "this", "->", "wsdl", "->", "register", "(", "$", "methodinfo", "->", "name", ",", "$", "methodinfo", "->", "inputparams", ",", "$", "methodinfo", "->", "outputparams", ",", "$", "methodinfo", "->", "description", ")", ";", "}", "}" ]
Generates the WSDL.
[ "Generates", "the", "WSDL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/soap/locallib.php#L158-L169
215,620
moodle/moodle
webservice/soap/locallib.php
webservice_soap_server.handle
protected function handle() { if ($this->wsdlmode) { // Prepare the response. $this->response = $this->wsdl->to_xml(); // Send the results back in correct format. $this->send_response(); } else { $wsdlurl = clone($this->serverurl); $wsdlurl->param('wsdl', 1); $options = array( 'uri' => $this->serverurl->out(false) ); // Initialise the SOAP server. $this->soapserver = new SoapServer($wsdlurl->out(false), $options); if (!empty($this->serviceclass)) { $this->soapserver->setClass($this->serviceclass); // Get all the methods for the generated service class then register to the SOAP server. $functions = get_class_methods($this->serviceclass); $this->soapserver->addFunction($functions); } // Get soap request from raw POST data. $soaprequest = file_get_contents('php://input'); // Handle the request. try { $this->soapserver->handle($soaprequest); } catch (Exception $e) { $this->fault($e); } } }
php
protected function handle() { if ($this->wsdlmode) { // Prepare the response. $this->response = $this->wsdl->to_xml(); // Send the results back in correct format. $this->send_response(); } else { $wsdlurl = clone($this->serverurl); $wsdlurl->param('wsdl', 1); $options = array( 'uri' => $this->serverurl->out(false) ); // Initialise the SOAP server. $this->soapserver = new SoapServer($wsdlurl->out(false), $options); if (!empty($this->serviceclass)) { $this->soapserver->setClass($this->serviceclass); // Get all the methods for the generated service class then register to the SOAP server. $functions = get_class_methods($this->serviceclass); $this->soapserver->addFunction($functions); } // Get soap request from raw POST data. $soaprequest = file_get_contents('php://input'); // Handle the request. try { $this->soapserver->handle($soaprequest); } catch (Exception $e) { $this->fault($e); } } }
[ "protected", "function", "handle", "(", ")", "{", "if", "(", "$", "this", "->", "wsdlmode", ")", "{", "// Prepare the response.", "$", "this", "->", "response", "=", "$", "this", "->", "wsdl", "->", "to_xml", "(", ")", ";", "// Send the results back in correct format.", "$", "this", "->", "send_response", "(", ")", ";", "}", "else", "{", "$", "wsdlurl", "=", "clone", "(", "$", "this", "->", "serverurl", ")", ";", "$", "wsdlurl", "->", "param", "(", "'wsdl'", ",", "1", ")", ";", "$", "options", "=", "array", "(", "'uri'", "=>", "$", "this", "->", "serverurl", "->", "out", "(", "false", ")", ")", ";", "// Initialise the SOAP server.", "$", "this", "->", "soapserver", "=", "new", "SoapServer", "(", "$", "wsdlurl", "->", "out", "(", "false", ")", ",", "$", "options", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "serviceclass", ")", ")", "{", "$", "this", "->", "soapserver", "->", "setClass", "(", "$", "this", "->", "serviceclass", ")", ";", "// Get all the methods for the generated service class then register to the SOAP server.", "$", "functions", "=", "get_class_methods", "(", "$", "this", "->", "serviceclass", ")", ";", "$", "this", "->", "soapserver", "->", "addFunction", "(", "$", "functions", ")", ";", "}", "// Get soap request from raw POST data.", "$", "soaprequest", "=", "file_get_contents", "(", "'php://input'", ")", ";", "// Handle the request.", "try", "{", "$", "this", "->", "soapserver", "->", "handle", "(", "$", "soaprequest", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "this", "->", "fault", "(", "$", "e", ")", ";", "}", "}", "}" ]
Handles the web service function call.
[ "Handles", "the", "web", "service", "function", "call", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/soap/locallib.php#L174-L206
215,621
moodle/moodle
webservice/soap/locallib.php
webservice_soap_server.send_error
protected function send_error($ex = null) { if ($ex) { $info = $ex->getMessage(); if (debugging() and isset($ex->debuginfo)) { $info .= ' - '.$ex->debuginfo; } } else { $info = 'Unknown error'; } // Initialise new DOM document object. $dom = new DOMDocument('1.0', 'UTF-8'); // Fault node. $fault = $dom->createElement('SOAP-ENV:Fault'); // Faultcode node. $fault->appendChild($dom->createElement('faultcode', 'MOODLE:error')); // Faultstring node. $fault->appendChild($dom->createElement('faultstring', $info)); // Body node. $body = $dom->createElement('SOAP-ENV:Body'); $body->appendChild($fault); // Envelope node. $envelope = $dom->createElement('SOAP-ENV:Envelope'); $envelope->setAttribute('xmlns:SOAP-ENV', 'http://schemas.xmlsoap.org/soap/envelope/'); $envelope->appendChild($body); $dom->appendChild($envelope); $this->response = $dom->saveXML(); $this->send_response(); }
php
protected function send_error($ex = null) { if ($ex) { $info = $ex->getMessage(); if (debugging() and isset($ex->debuginfo)) { $info .= ' - '.$ex->debuginfo; } } else { $info = 'Unknown error'; } // Initialise new DOM document object. $dom = new DOMDocument('1.0', 'UTF-8'); // Fault node. $fault = $dom->createElement('SOAP-ENV:Fault'); // Faultcode node. $fault->appendChild($dom->createElement('faultcode', 'MOODLE:error')); // Faultstring node. $fault->appendChild($dom->createElement('faultstring', $info)); // Body node. $body = $dom->createElement('SOAP-ENV:Body'); $body->appendChild($fault); // Envelope node. $envelope = $dom->createElement('SOAP-ENV:Envelope'); $envelope->setAttribute('xmlns:SOAP-ENV', 'http://schemas.xmlsoap.org/soap/envelope/'); $envelope->appendChild($body); $dom->appendChild($envelope); $this->response = $dom->saveXML(); $this->send_response(); }
[ "protected", "function", "send_error", "(", "$", "ex", "=", "null", ")", "{", "if", "(", "$", "ex", ")", "{", "$", "info", "=", "$", "ex", "->", "getMessage", "(", ")", ";", "if", "(", "debugging", "(", ")", "and", "isset", "(", "$", "ex", "->", "debuginfo", ")", ")", "{", "$", "info", ".=", "' - '", ".", "$", "ex", "->", "debuginfo", ";", "}", "}", "else", "{", "$", "info", "=", "'Unknown error'", ";", "}", "// Initialise new DOM document object.", "$", "dom", "=", "new", "DOMDocument", "(", "'1.0'", ",", "'UTF-8'", ")", ";", "// Fault node.", "$", "fault", "=", "$", "dom", "->", "createElement", "(", "'SOAP-ENV:Fault'", ")", ";", "// Faultcode node.", "$", "fault", "->", "appendChild", "(", "$", "dom", "->", "createElement", "(", "'faultcode'", ",", "'MOODLE:error'", ")", ")", ";", "// Faultstring node.", "$", "fault", "->", "appendChild", "(", "$", "dom", "->", "createElement", "(", "'faultstring'", ",", "$", "info", ")", ")", ";", "// Body node.", "$", "body", "=", "$", "dom", "->", "createElement", "(", "'SOAP-ENV:Body'", ")", ";", "$", "body", "->", "appendChild", "(", "$", "fault", ")", ";", "// Envelope node.", "$", "envelope", "=", "$", "dom", "->", "createElement", "(", "'SOAP-ENV:Envelope'", ")", ";", "$", "envelope", "->", "setAttribute", "(", "'xmlns:SOAP-ENV'", ",", "'http://schemas.xmlsoap.org/soap/envelope/'", ")", ";", "$", "envelope", "->", "appendChild", "(", "$", "body", ")", ";", "$", "dom", "->", "appendChild", "(", "$", "envelope", ")", ";", "$", "this", "->", "response", "=", "$", "dom", "->", "saveXML", "(", ")", ";", "$", "this", "->", "send_response", "(", ")", ";", "}" ]
Send the error information to the WS client formatted as an XML document. @param Exception $ex the exception to send back
[ "Send", "the", "error", "information", "to", "the", "WS", "client", "formatted", "as", "an", "XML", "document", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/soap/locallib.php#L213-L245
215,622
moodle/moodle
webservice/soap/locallib.php
webservice_soap_server.fault
public function fault($fault = null, $code = 'Receiver') { $allowedfaultmodes = array( 'VersionMismatch', 'MustUnderstand', 'DataEncodingUnknown', 'Sender', 'Receiver', 'Server' ); if (!in_array($code, $allowedfaultmodes)) { $code = 'Receiver'; } // Intercept any exceptions and add the errorcode and debuginfo (optional). $actor = null; $details = null; $errorcode = 'unknownerror'; $message = get_string($errorcode); if ($fault instanceof Exception) { // Add the debuginfo to the exception message if debuginfo must be returned. $actor = isset($fault->errorcode) ? $fault->errorcode : null; $errorcode = $actor; if (debugging()) { $message = $fault->getMessage(); $details = isset($fault->debuginfo) ? $fault->debuginfo : null; } } else if (is_string($fault)) { $message = $fault; } $this->soapserver->fault($code, $message . ' | ERRORCODE: ' . $errorcode, $actor, $details); }
php
public function fault($fault = null, $code = 'Receiver') { $allowedfaultmodes = array( 'VersionMismatch', 'MustUnderstand', 'DataEncodingUnknown', 'Sender', 'Receiver', 'Server' ); if (!in_array($code, $allowedfaultmodes)) { $code = 'Receiver'; } // Intercept any exceptions and add the errorcode and debuginfo (optional). $actor = null; $details = null; $errorcode = 'unknownerror'; $message = get_string($errorcode); if ($fault instanceof Exception) { // Add the debuginfo to the exception message if debuginfo must be returned. $actor = isset($fault->errorcode) ? $fault->errorcode : null; $errorcode = $actor; if (debugging()) { $message = $fault->getMessage(); $details = isset($fault->debuginfo) ? $fault->debuginfo : null; } } else if (is_string($fault)) { $message = $fault; } $this->soapserver->fault($code, $message . ' | ERRORCODE: ' . $errorcode, $actor, $details); }
[ "public", "function", "fault", "(", "$", "fault", "=", "null", ",", "$", "code", "=", "'Receiver'", ")", "{", "$", "allowedfaultmodes", "=", "array", "(", "'VersionMismatch'", ",", "'MustUnderstand'", ",", "'DataEncodingUnknown'", ",", "'Sender'", ",", "'Receiver'", ",", "'Server'", ")", ";", "if", "(", "!", "in_array", "(", "$", "code", ",", "$", "allowedfaultmodes", ")", ")", "{", "$", "code", "=", "'Receiver'", ";", "}", "// Intercept any exceptions and add the errorcode and debuginfo (optional).", "$", "actor", "=", "null", ";", "$", "details", "=", "null", ";", "$", "errorcode", "=", "'unknownerror'", ";", "$", "message", "=", "get_string", "(", "$", "errorcode", ")", ";", "if", "(", "$", "fault", "instanceof", "Exception", ")", "{", "// Add the debuginfo to the exception message if debuginfo must be returned.", "$", "actor", "=", "isset", "(", "$", "fault", "->", "errorcode", ")", "?", "$", "fault", "->", "errorcode", ":", "null", ";", "$", "errorcode", "=", "$", "actor", ";", "if", "(", "debugging", "(", ")", ")", "{", "$", "message", "=", "$", "fault", "->", "getMessage", "(", ")", ";", "$", "details", "=", "isset", "(", "$", "fault", "->", "debuginfo", ")", "?", "$", "fault", "->", "debuginfo", ":", "null", ";", "}", "}", "else", "if", "(", "is_string", "(", "$", "fault", ")", ")", "{", "$", "message", "=", "$", "fault", ";", "}", "$", "this", "->", "soapserver", "->", "fault", "(", "$", "code", ",", "$", "message", ".", "' | ERRORCODE: '", ".", "$", "errorcode", ",", "$", "actor", ",", "$", "details", ")", ";", "}" ]
Generate a server fault. Note that the parameter order is the reverse of SoapFault's constructor parameters. Moodle note: basically we return the faultactor (errorcode) and faultdetails (debuginfo). If an exception is passed as the first argument, its message and code will be used to create the fault object. @link http://www.w3.org/TR/soap12-part1/#faultcodes @param string|Exception $fault @param string $code SOAP Fault Codes
[ "Generate", "a", "server", "fault", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/soap/locallib.php#L282-L309
215,623
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_lesson_summary_for_exporter
protected static function get_lesson_summary_for_exporter($lessonrecord, $password = '') { global $USER; $lesson = new lesson($lessonrecord); $lesson->update_effective_access($USER->id); $lessonavailable = $lesson->get_time_restriction_status() === false; $lessonavailable = $lessonavailable && $lesson->get_password_restriction_status($password) === false; $lessonavailable = $lessonavailable && $lesson->get_dependencies_restriction_status() === false; $canmanage = $lesson->can_manage(); if (!$canmanage && !$lessonavailable) { $fields = array('intro', 'introfiles', 'mediafiles', 'practice', 'modattempts', 'usepassword', 'grade', 'custom', 'ongoing', 'usemaxgrade', 'maxanswers', 'maxattempts', 'review', 'nextpagedefault', 'feedback', 'minquestions', 'maxpages', 'timelimit', 'retake', 'mediafile', 'mediaheight', 'mediawidth', 'mediaclose', 'slideshow', 'width', 'height', 'bgcolor', 'displayleft', 'displayleftif', 'progressbar'); foreach ($fields as $field) { unset($lessonrecord->{$field}); } } // Fields only for managers. if (!$canmanage) { $fields = array('password', 'dependency', 'conditions', 'activitylink', 'available', 'deadline', 'timemodified', 'completionendreached', 'completiontimespent'); foreach ($fields as $field) { unset($lessonrecord->{$field}); } } return $lessonrecord; }
php
protected static function get_lesson_summary_for_exporter($lessonrecord, $password = '') { global $USER; $lesson = new lesson($lessonrecord); $lesson->update_effective_access($USER->id); $lessonavailable = $lesson->get_time_restriction_status() === false; $lessonavailable = $lessonavailable && $lesson->get_password_restriction_status($password) === false; $lessonavailable = $lessonavailable && $lesson->get_dependencies_restriction_status() === false; $canmanage = $lesson->can_manage(); if (!$canmanage && !$lessonavailable) { $fields = array('intro', 'introfiles', 'mediafiles', 'practice', 'modattempts', 'usepassword', 'grade', 'custom', 'ongoing', 'usemaxgrade', 'maxanswers', 'maxattempts', 'review', 'nextpagedefault', 'feedback', 'minquestions', 'maxpages', 'timelimit', 'retake', 'mediafile', 'mediaheight', 'mediawidth', 'mediaclose', 'slideshow', 'width', 'height', 'bgcolor', 'displayleft', 'displayleftif', 'progressbar'); foreach ($fields as $field) { unset($lessonrecord->{$field}); } } // Fields only for managers. if (!$canmanage) { $fields = array('password', 'dependency', 'conditions', 'activitylink', 'available', 'deadline', 'timemodified', 'completionendreached', 'completiontimespent'); foreach ($fields as $field) { unset($lessonrecord->{$field}); } } return $lessonrecord; }
[ "protected", "static", "function", "get_lesson_summary_for_exporter", "(", "$", "lessonrecord", ",", "$", "password", "=", "''", ")", "{", "global", "$", "USER", ";", "$", "lesson", "=", "new", "lesson", "(", "$", "lessonrecord", ")", ";", "$", "lesson", "->", "update_effective_access", "(", "$", "USER", "->", "id", ")", ";", "$", "lessonavailable", "=", "$", "lesson", "->", "get_time_restriction_status", "(", ")", "===", "false", ";", "$", "lessonavailable", "=", "$", "lessonavailable", "&&", "$", "lesson", "->", "get_password_restriction_status", "(", "$", "password", ")", "===", "false", ";", "$", "lessonavailable", "=", "$", "lessonavailable", "&&", "$", "lesson", "->", "get_dependencies_restriction_status", "(", ")", "===", "false", ";", "$", "canmanage", "=", "$", "lesson", "->", "can_manage", "(", ")", ";", "if", "(", "!", "$", "canmanage", "&&", "!", "$", "lessonavailable", ")", "{", "$", "fields", "=", "array", "(", "'intro'", ",", "'introfiles'", ",", "'mediafiles'", ",", "'practice'", ",", "'modattempts'", ",", "'usepassword'", ",", "'grade'", ",", "'custom'", ",", "'ongoing'", ",", "'usemaxgrade'", ",", "'maxanswers'", ",", "'maxattempts'", ",", "'review'", ",", "'nextpagedefault'", ",", "'feedback'", ",", "'minquestions'", ",", "'maxpages'", ",", "'timelimit'", ",", "'retake'", ",", "'mediafile'", ",", "'mediaheight'", ",", "'mediawidth'", ",", "'mediaclose'", ",", "'slideshow'", ",", "'width'", ",", "'height'", ",", "'bgcolor'", ",", "'displayleft'", ",", "'displayleftif'", ",", "'progressbar'", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "unset", "(", "$", "lessonrecord", "->", "{", "$", "field", "}", ")", ";", "}", "}", "// Fields only for managers.", "if", "(", "!", "$", "canmanage", ")", "{", "$", "fields", "=", "array", "(", "'password'", ",", "'dependency'", ",", "'conditions'", ",", "'activitylink'", ",", "'available'", ",", "'deadline'", ",", "'timemodified'", ",", "'completionendreached'", ",", "'completiontimespent'", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "unset", "(", "$", "lessonrecord", "->", "{", "$", "field", "}", ")", ";", "}", "}", "return", "$", "lessonrecord", ";", "}" ]
Return a lesson record ready for being exported. @param stdClass $lessonrecord lesson record @param string $password lesson password @return stdClass the lesson record ready for exporting.
[ "Return", "a", "lesson", "record", "ready", "for", "being", "exported", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L52-L85
215,624
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_lessons_by_courses
public static function get_lessons_by_courses($courseids = array()) { global $PAGE; $warnings = array(); $returnedlessons = array(); $params = array( 'courseids' => $courseids, ); $params = self::validate_parameters(self::get_lessons_by_courses_parameters(), $params); $mycourses = array(); if (empty($params['courseids'])) { $mycourses = enrol_get_my_courses(); $params['courseids'] = array_keys($mycourses); } // Ensure there are courseids to loop through. if (!empty($params['courseids'])) { list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses); // Get the lessons in this course, this function checks users visibility permissions. // We can avoid then additional validate_context calls. $lessons = get_all_instances_in_courses("lesson", $courses); foreach ($lessons as $lessonrecord) { $context = context_module::instance($lessonrecord->coursemodule); // Remove fields added by get_all_instances_in_courses. unset($lessonrecord->coursemodule, $lessonrecord->section, $lessonrecord->visible, $lessonrecord->groupmode, $lessonrecord->groupingid); $lessonrecord = self::get_lesson_summary_for_exporter($lessonrecord); $exporter = new lesson_summary_exporter($lessonrecord, array('context' => $context)); $returnedlessons[] = $exporter->export($PAGE->get_renderer('core')); } } $result = array(); $result['lessons'] = $returnedlessons; $result['warnings'] = $warnings; return $result; }
php
public static function get_lessons_by_courses($courseids = array()) { global $PAGE; $warnings = array(); $returnedlessons = array(); $params = array( 'courseids' => $courseids, ); $params = self::validate_parameters(self::get_lessons_by_courses_parameters(), $params); $mycourses = array(); if (empty($params['courseids'])) { $mycourses = enrol_get_my_courses(); $params['courseids'] = array_keys($mycourses); } // Ensure there are courseids to loop through. if (!empty($params['courseids'])) { list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses); // Get the lessons in this course, this function checks users visibility permissions. // We can avoid then additional validate_context calls. $lessons = get_all_instances_in_courses("lesson", $courses); foreach ($lessons as $lessonrecord) { $context = context_module::instance($lessonrecord->coursemodule); // Remove fields added by get_all_instances_in_courses. unset($lessonrecord->coursemodule, $lessonrecord->section, $lessonrecord->visible, $lessonrecord->groupmode, $lessonrecord->groupingid); $lessonrecord = self::get_lesson_summary_for_exporter($lessonrecord); $exporter = new lesson_summary_exporter($lessonrecord, array('context' => $context)); $returnedlessons[] = $exporter->export($PAGE->get_renderer('core')); } } $result = array(); $result['lessons'] = $returnedlessons; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_lessons_by_courses", "(", "$", "courseids", "=", "array", "(", ")", ")", "{", "global", "$", "PAGE", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "returnedlessons", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'courseids'", "=>", "$", "courseids", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_lessons_by_courses_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "mycourses", "=", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "params", "[", "'courseids'", "]", ")", ")", "{", "$", "mycourses", "=", "enrol_get_my_courses", "(", ")", ";", "$", "params", "[", "'courseids'", "]", "=", "array_keys", "(", "$", "mycourses", ")", ";", "}", "// Ensure there are courseids to loop through.", "if", "(", "!", "empty", "(", "$", "params", "[", "'courseids'", "]", ")", ")", "{", "list", "(", "$", "courses", ",", "$", "warnings", ")", "=", "external_util", "::", "validate_courses", "(", "$", "params", "[", "'courseids'", "]", ",", "$", "mycourses", ")", ";", "// Get the lessons in this course, this function checks users visibility permissions.", "// We can avoid then additional validate_context calls.", "$", "lessons", "=", "get_all_instances_in_courses", "(", "\"lesson\"", ",", "$", "courses", ")", ";", "foreach", "(", "$", "lessons", "as", "$", "lessonrecord", ")", "{", "$", "context", "=", "context_module", "::", "instance", "(", "$", "lessonrecord", "->", "coursemodule", ")", ";", "// Remove fields added by get_all_instances_in_courses.", "unset", "(", "$", "lessonrecord", "->", "coursemodule", ",", "$", "lessonrecord", "->", "section", ",", "$", "lessonrecord", "->", "visible", ",", "$", "lessonrecord", "->", "groupmode", ",", "$", "lessonrecord", "->", "groupingid", ")", ";", "$", "lessonrecord", "=", "self", "::", "get_lesson_summary_for_exporter", "(", "$", "lessonrecord", ")", ";", "$", "exporter", "=", "new", "lesson_summary_exporter", "(", "$", "lessonrecord", ",", "array", "(", "'context'", "=>", "$", "context", ")", ")", ";", "$", "returnedlessons", "[", "]", "=", "$", "exporter", "->", "export", "(", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ")", ";", "}", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'lessons'", "]", "=", "$", "returnedlessons", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Returns a list of lessons in a provided list of courses, if no list is provided all lessons that the user can view will be returned. @param array $courseids Array of course ids @return array of lessons details @since Moodle 3.3
[ "Returns", "a", "list", "of", "lessons", "in", "a", "provided", "list", "of", "courses", "if", "no", "list", "is", "provided", "all", "lessons", "that", "the", "user", "can", "view", "will", "be", "returned", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L111-L153
215,625
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.validate_lesson
protected static function validate_lesson($lessonid) { global $DB, $USER; // Request and permission validation. $lessonrecord = $DB->get_record('lesson', array('id' => $lessonid), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($lessonrecord, 'lesson'); $lesson = new lesson($lessonrecord, $cm, $course); $lesson->update_effective_access($USER->id); $context = $lesson->context; self::validate_context($context); return array($lesson, $course, $cm, $context, $lessonrecord); }
php
protected static function validate_lesson($lessonid) { global $DB, $USER; // Request and permission validation. $lessonrecord = $DB->get_record('lesson', array('id' => $lessonid), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($lessonrecord, 'lesson'); $lesson = new lesson($lessonrecord, $cm, $course); $lesson->update_effective_access($USER->id); $context = $lesson->context; self::validate_context($context); return array($lesson, $course, $cm, $context, $lessonrecord); }
[ "protected", "static", "function", "validate_lesson", "(", "$", "lessonid", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "// Request and permission validation.", "$", "lessonrecord", "=", "$", "DB", "->", "get_record", "(", "'lesson'", ",", "array", "(", "'id'", "=>", "$", "lessonid", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "list", "(", "$", "course", ",", "$", "cm", ")", "=", "get_course_and_cm_from_instance", "(", "$", "lessonrecord", ",", "'lesson'", ")", ";", "$", "lesson", "=", "new", "lesson", "(", "$", "lessonrecord", ",", "$", "cm", ",", "$", "course", ")", ";", "$", "lesson", "->", "update_effective_access", "(", "$", "USER", "->", "id", ")", ";", "$", "context", "=", "$", "lesson", "->", "context", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "return", "array", "(", "$", "lesson", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ",", "$", "lessonrecord", ")", ";", "}" ]
Utility function for validating a lesson. @param int $lessonid lesson instance id @return array array containing the lesson, course, context and course module objects @since Moodle 3.3
[ "Utility", "function", "for", "validating", "a", "lesson", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L179-L193
215,626
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_lesson_access_information
public static function get_lesson_access_information($lessonid) { global $DB, $USER; $warnings = array(); $params = array( 'lessonid' => $lessonid ); $params = self::validate_parameters(self::get_lesson_access_information_parameters(), $params); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); $result = array(); // Capabilities first. $result['canmanage'] = $lesson->can_manage(); $result['cangrade'] = has_capability('mod/lesson:grade', $context); $result['canviewreports'] = has_capability('mod/lesson:viewreports', $context); // Status information. $result['reviewmode'] = $lesson->is_in_review_mode(); $result['attemptscount'] = $lesson->count_user_retries($USER->id); $lastpageseen = $lesson->get_last_page_seen($result['attemptscount']); $result['lastpageseen'] = ($lastpageseen !== false) ? $lastpageseen : 0; $result['leftduringtimedsession'] = $lesson->left_during_timed_session($result['attemptscount']); // To avoid multiple calls, store the magic property firstpage. $lessonfirstpage = $lesson->firstpage; $result['firstpageid'] = $lessonfirstpage ? $lessonfirstpage->id : 0; // Access restrictions now, we emulate a new attempt access to get the possible warnings. $result['preventaccessreasons'] = []; $validationerrors = self::validate_attempt($lesson, ['password' => ''], true); foreach ($validationerrors as $reason => $data) { $result['preventaccessreasons'][] = [ 'reason' => $reason, 'data' => $data, 'message' => get_string($reason, 'lesson', $data), ]; } $result['warnings'] = $warnings; return $result; }
php
public static function get_lesson_access_information($lessonid) { global $DB, $USER; $warnings = array(); $params = array( 'lessonid' => $lessonid ); $params = self::validate_parameters(self::get_lesson_access_information_parameters(), $params); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); $result = array(); // Capabilities first. $result['canmanage'] = $lesson->can_manage(); $result['cangrade'] = has_capability('mod/lesson:grade', $context); $result['canviewreports'] = has_capability('mod/lesson:viewreports', $context); // Status information. $result['reviewmode'] = $lesson->is_in_review_mode(); $result['attemptscount'] = $lesson->count_user_retries($USER->id); $lastpageseen = $lesson->get_last_page_seen($result['attemptscount']); $result['lastpageseen'] = ($lastpageseen !== false) ? $lastpageseen : 0; $result['leftduringtimedsession'] = $lesson->left_during_timed_session($result['attemptscount']); // To avoid multiple calls, store the magic property firstpage. $lessonfirstpage = $lesson->firstpage; $result['firstpageid'] = $lessonfirstpage ? $lessonfirstpage->id : 0; // Access restrictions now, we emulate a new attempt access to get the possible warnings. $result['preventaccessreasons'] = []; $validationerrors = self::validate_attempt($lesson, ['password' => ''], true); foreach ($validationerrors as $reason => $data) { $result['preventaccessreasons'][] = [ 'reason' => $reason, 'data' => $data, 'message' => get_string($reason, 'lesson', $data), ]; } $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_lesson_access_information", "(", "$", "lessonid", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'lessonid'", "=>", "$", "lessonid", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_lesson_access_information_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "lesson", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ",", "$", "lessonrecord", ")", "=", "self", "::", "validate_lesson", "(", "$", "params", "[", "'lessonid'", "]", ")", ";", "$", "result", "=", "array", "(", ")", ";", "// Capabilities first.", "$", "result", "[", "'canmanage'", "]", "=", "$", "lesson", "->", "can_manage", "(", ")", ";", "$", "result", "[", "'cangrade'", "]", "=", "has_capability", "(", "'mod/lesson:grade'", ",", "$", "context", ")", ";", "$", "result", "[", "'canviewreports'", "]", "=", "has_capability", "(", "'mod/lesson:viewreports'", ",", "$", "context", ")", ";", "// Status information.", "$", "result", "[", "'reviewmode'", "]", "=", "$", "lesson", "->", "is_in_review_mode", "(", ")", ";", "$", "result", "[", "'attemptscount'", "]", "=", "$", "lesson", "->", "count_user_retries", "(", "$", "USER", "->", "id", ")", ";", "$", "lastpageseen", "=", "$", "lesson", "->", "get_last_page_seen", "(", "$", "result", "[", "'attemptscount'", "]", ")", ";", "$", "result", "[", "'lastpageseen'", "]", "=", "(", "$", "lastpageseen", "!==", "false", ")", "?", "$", "lastpageseen", ":", "0", ";", "$", "result", "[", "'leftduringtimedsession'", "]", "=", "$", "lesson", "->", "left_during_timed_session", "(", "$", "result", "[", "'attemptscount'", "]", ")", ";", "// To avoid multiple calls, store the magic property firstpage.", "$", "lessonfirstpage", "=", "$", "lesson", "->", "firstpage", ";", "$", "result", "[", "'firstpageid'", "]", "=", "$", "lessonfirstpage", "?", "$", "lessonfirstpage", "->", "id", ":", "0", ";", "// Access restrictions now, we emulate a new attempt access to get the possible warnings.", "$", "result", "[", "'preventaccessreasons'", "]", "=", "[", "]", ";", "$", "validationerrors", "=", "self", "::", "validate_attempt", "(", "$", "lesson", ",", "[", "'password'", "=>", "''", "]", ",", "true", ")", ";", "foreach", "(", "$", "validationerrors", "as", "$", "reason", "=>", "$", "data", ")", "{", "$", "result", "[", "'preventaccessreasons'", "]", "[", "]", "=", "[", "'reason'", "=>", "$", "reason", ",", "'data'", "=>", "$", "data", ",", "'message'", "=>", "get_string", "(", "$", "reason", ",", "'lesson'", ",", "$", "data", ")", ",", "]", ";", "}", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Return access information for a given lesson. @param int $lessonid lesson instance id @return array of warnings and the access information @since Moodle 3.3 @throws moodle_exception
[ "Return", "access", "information", "for", "a", "given", "lesson", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L350-L390
215,627
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_lesson_access_information_returns
public static function get_lesson_access_information_returns() { return new external_single_structure( array( 'canmanage' => new external_value(PARAM_BOOL, 'Whether the user can manage the lesson or not.'), 'cangrade' => new external_value(PARAM_BOOL, 'Whether the user can grade the lesson or not.'), 'canviewreports' => new external_value(PARAM_BOOL, 'Whether the user can view the lesson reports or not.'), 'reviewmode' => new external_value(PARAM_BOOL, 'Whether the lesson is in review mode for the current user.'), 'attemptscount' => new external_value(PARAM_INT, 'The number of attempts done by the user.'), 'lastpageseen' => new external_value(PARAM_INT, 'The last page seen id.'), 'leftduringtimedsession' => new external_value(PARAM_BOOL, 'Whether the user left during a timed session.'), 'firstpageid' => new external_value(PARAM_INT, 'The lesson first page id.'), 'preventaccessreasons' => new external_multiple_structure( new external_single_structure( array( 'reason' => new external_value(PARAM_ALPHANUMEXT, 'Reason lang string code'), 'data' => new external_value(PARAM_RAW, 'Additional data'), 'message' => new external_value(PARAM_RAW, 'Complete html message'), ), 'The reasons why the user cannot attempt the lesson' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_lesson_access_information_returns() { return new external_single_structure( array( 'canmanage' => new external_value(PARAM_BOOL, 'Whether the user can manage the lesson or not.'), 'cangrade' => new external_value(PARAM_BOOL, 'Whether the user can grade the lesson or not.'), 'canviewreports' => new external_value(PARAM_BOOL, 'Whether the user can view the lesson reports or not.'), 'reviewmode' => new external_value(PARAM_BOOL, 'Whether the lesson is in review mode for the current user.'), 'attemptscount' => new external_value(PARAM_INT, 'The number of attempts done by the user.'), 'lastpageseen' => new external_value(PARAM_INT, 'The last page seen id.'), 'leftduringtimedsession' => new external_value(PARAM_BOOL, 'Whether the user left during a timed session.'), 'firstpageid' => new external_value(PARAM_INT, 'The lesson first page id.'), 'preventaccessreasons' => new external_multiple_structure( new external_single_structure( array( 'reason' => new external_value(PARAM_ALPHANUMEXT, 'Reason lang string code'), 'data' => new external_value(PARAM_RAW, 'Additional data'), 'message' => new external_value(PARAM_RAW, 'Complete html message'), ), 'The reasons why the user cannot attempt the lesson' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_lesson_access_information_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'canmanage'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether the user can manage the lesson or not.'", ")", ",", "'cangrade'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether the user can grade the lesson or not.'", ")", ",", "'canviewreports'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether the user can view the lesson reports or not.'", ")", ",", "'reviewmode'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether the lesson is in review mode for the current user.'", ")", ",", "'attemptscount'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The number of attempts done by the user.'", ")", ",", "'lastpageseen'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The last page seen id.'", ")", ",", "'leftduringtimedsession'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether the user left during a timed session.'", ")", ",", "'firstpageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The lesson first page id.'", ")", ",", "'preventaccessreasons'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'reason'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'Reason lang string code'", ")", ",", "'data'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Additional data'", ")", ",", "'message'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Complete html message'", ")", ",", ")", ",", "'The reasons why the user cannot attempt the lesson'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_lesson_access_information return value. @return external_single_structure @since Moodle 3.3
[ "Describes", "the", "get_lesson_access_information", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L398-L422
215,628
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_questions_attempts_parameters
public static function get_questions_attempts_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'lesson instance id'), 'attempt' => new external_value(PARAM_INT, 'lesson attempt number'), 'correct' => new external_value(PARAM_BOOL, 'only fetch correct attempts', VALUE_DEFAULT, false), 'pageid' => new external_value(PARAM_INT, 'only fetch attempts at the given page', VALUE_DEFAULT, null), 'userid' => new external_value(PARAM_INT, 'only fetch attempts of the given user', VALUE_DEFAULT, null), ) ); }
php
public static function get_questions_attempts_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'lesson instance id'), 'attempt' => new external_value(PARAM_INT, 'lesson attempt number'), 'correct' => new external_value(PARAM_BOOL, 'only fetch correct attempts', VALUE_DEFAULT, false), 'pageid' => new external_value(PARAM_INT, 'only fetch attempts at the given page', VALUE_DEFAULT, null), 'userid' => new external_value(PARAM_INT, 'only fetch attempts of the given user', VALUE_DEFAULT, null), ) ); }
[ "public", "static", "function", "get_questions_attempts_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'lessonid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'lesson instance id'", ")", ",", "'attempt'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'lesson attempt number'", ")", ",", "'correct'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'only fetch correct attempts'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", "'pageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'only fetch attempts at the given page'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'only fetch attempts of the given user'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for get_questions_attempts. @return external_function_parameters @since Moodle 3.3
[ "Describes", "the", "parameters", "for", "get_questions_attempts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L507-L517
215,629
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_questions_attempts
public static function get_questions_attempts($lessonid, $attempt, $correct = false, $pageid = null, $userid = null) { global $DB, $USER; $params = array( 'lessonid' => $lessonid, 'attempt' => $attempt, 'correct' => $correct, 'pageid' => $pageid, 'userid' => $userid, ); $params = self::validate_parameters(self::get_questions_attempts_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $params['userid']) { self::check_can_view_user_data($params['userid'], $course, $cm, $context); } $result = array(); $result['attempts'] = $lesson->get_attempts($params['attempt'], $params['correct'], $params['pageid'], $params['userid']); $result['warnings'] = $warnings; return $result; }
php
public static function get_questions_attempts($lessonid, $attempt, $correct = false, $pageid = null, $userid = null) { global $DB, $USER; $params = array( 'lessonid' => $lessonid, 'attempt' => $attempt, 'correct' => $correct, 'pageid' => $pageid, 'userid' => $userid, ); $params = self::validate_parameters(self::get_questions_attempts_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $params['userid']) { self::check_can_view_user_data($params['userid'], $course, $cm, $context); } $result = array(); $result['attempts'] = $lesson->get_attempts($params['attempt'], $params['correct'], $params['pageid'], $params['userid']); $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_questions_attempts", "(", "$", "lessonid", ",", "$", "attempt", ",", "$", "correct", "=", "false", ",", "$", "pageid", "=", "null", ",", "$", "userid", "=", "null", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "params", "=", "array", "(", "'lessonid'", "=>", "$", "lessonid", ",", "'attempt'", "=>", "$", "attempt", ",", "'correct'", "=>", "$", "correct", ",", "'pageid'", "=>", "$", "pageid", ",", "'userid'", "=>", "$", "userid", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_questions_attempts_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "list", "(", "$", "lesson", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ",", "$", "lessonrecord", ")", "=", "self", "::", "validate_lesson", "(", "$", "params", "[", "'lessonid'", "]", ")", ";", "// Default value for userid.", "if", "(", "empty", "(", "$", "params", "[", "'userid'", "]", ")", ")", "{", "$", "params", "[", "'userid'", "]", "=", "$", "USER", "->", "id", ";", "}", "// Extra checks so only users with permissions can view other users attempts.", "if", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "{", "self", "::", "check_can_view_user_data", "(", "$", "params", "[", "'userid'", "]", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'attempts'", "]", "=", "$", "lesson", "->", "get_attempts", "(", "$", "params", "[", "'attempt'", "]", ",", "$", "params", "[", "'correct'", "]", ",", "$", "params", "[", "'pageid'", "]", ",", "$", "params", "[", "'userid'", "]", ")", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Return the list of page question attempts in a given lesson. @param int $lessonid lesson instance id @param int $attempt the lesson attempt number @param bool $correct only fetch correct attempts @param int $pageid only fetch attempts at the given page @param int $userid only fetch attempts of the given user @return array of warnings and page attempts @since Moodle 3.3 @throws moodle_exception
[ "Return", "the", "list", "of", "page", "question", "attempts", "in", "a", "given", "lesson", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L531-L560
215,630
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_questions_attempts_returns
public static function get_questions_attempts_returns() { return new external_single_structure( array( 'attempts' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The attempt id'), 'lessonid' => new external_value(PARAM_INT, 'The attempt lessonid'), 'pageid' => new external_value(PARAM_INT, 'The attempt pageid'), 'userid' => new external_value(PARAM_INT, 'The user who did the attempt'), 'answerid' => new external_value(PARAM_INT, 'The attempt answerid'), 'retry' => new external_value(PARAM_INT, 'The lesson attempt number'), 'correct' => new external_value(PARAM_INT, 'If it was the correct answer'), 'useranswer' => new external_value(PARAM_RAW, 'The complete user answer'), 'timeseen' => new external_value(PARAM_INT, 'The time the question was seen'), ), 'The question page attempts' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_questions_attempts_returns() { return new external_single_structure( array( 'attempts' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The attempt id'), 'lessonid' => new external_value(PARAM_INT, 'The attempt lessonid'), 'pageid' => new external_value(PARAM_INT, 'The attempt pageid'), 'userid' => new external_value(PARAM_INT, 'The user who did the attempt'), 'answerid' => new external_value(PARAM_INT, 'The attempt answerid'), 'retry' => new external_value(PARAM_INT, 'The lesson attempt number'), 'correct' => new external_value(PARAM_INT, 'If it was the correct answer'), 'useranswer' => new external_value(PARAM_RAW, 'The complete user answer'), 'timeseen' => new external_value(PARAM_INT, 'The time the question was seen'), ), 'The question page attempts' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_questions_attempts_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'attempts'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The attempt id'", ")", ",", "'lessonid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The attempt lessonid'", ")", ",", "'pageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The attempt pageid'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The user who did the attempt'", ")", ",", "'answerid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The attempt answerid'", ")", ",", "'retry'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The lesson attempt number'", ")", ",", "'correct'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'If it was the correct answer'", ")", ",", "'useranswer'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The complete user answer'", ")", ",", "'timeseen'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The time the question was seen'", ")", ",", ")", ",", "'The question page attempts'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_questions_attempts return value. @return external_single_structure @since Moodle 3.3
[ "Describes", "the", "get_questions_attempts", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L568-L590
215,631
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_user_grade
public static function get_user_grade($lessonid, $userid = null) { global $CFG, $USER; require_once($CFG->libdir . '/gradelib.php'); $params = array( 'lessonid' => $lessonid, 'userid' => $userid, ); $params = self::validate_parameters(self::get_user_grade_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $params['userid']) { self::check_can_view_user_data($params['userid'], $course, $cm, $context); } $grade = null; $formattedgrade = null; $grades = lesson_get_user_grades($lesson, $params['userid']); if (!empty($grades)) { $grade = $grades[$params['userid']]->rawgrade; $params = array( 'itemtype' => 'mod', 'itemmodule' => 'lesson', 'iteminstance' => $lesson->id, 'courseid' => $course->id, 'itemnumber' => 0 ); $gradeitem = grade_item::fetch($params); $formattedgrade = grade_format_gradevalue($grade, $gradeitem); } $result = array(); $result['grade'] = $grade; $result['formattedgrade'] = $formattedgrade; $result['warnings'] = $warnings; return $result; }
php
public static function get_user_grade($lessonid, $userid = null) { global $CFG, $USER; require_once($CFG->libdir . '/gradelib.php'); $params = array( 'lessonid' => $lessonid, 'userid' => $userid, ); $params = self::validate_parameters(self::get_user_grade_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $params['userid']) { self::check_can_view_user_data($params['userid'], $course, $cm, $context); } $grade = null; $formattedgrade = null; $grades = lesson_get_user_grades($lesson, $params['userid']); if (!empty($grades)) { $grade = $grades[$params['userid']]->rawgrade; $params = array( 'itemtype' => 'mod', 'itemmodule' => 'lesson', 'iteminstance' => $lesson->id, 'courseid' => $course->id, 'itemnumber' => 0 ); $gradeitem = grade_item::fetch($params); $formattedgrade = grade_format_gradevalue($grade, $gradeitem); } $result = array(); $result['grade'] = $grade; $result['formattedgrade'] = $formattedgrade; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_user_grade", "(", "$", "lessonid", ",", "$", "userid", "=", "null", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/gradelib.php'", ")", ";", "$", "params", "=", "array", "(", "'lessonid'", "=>", "$", "lessonid", ",", "'userid'", "=>", "$", "userid", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_user_grade_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "list", "(", "$", "lesson", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ",", "$", "lessonrecord", ")", "=", "self", "::", "validate_lesson", "(", "$", "params", "[", "'lessonid'", "]", ")", ";", "// Default value for userid.", "if", "(", "empty", "(", "$", "params", "[", "'userid'", "]", ")", ")", "{", "$", "params", "[", "'userid'", "]", "=", "$", "USER", "->", "id", ";", "}", "// Extra checks so only users with permissions can view other users attempts.", "if", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "{", "self", "::", "check_can_view_user_data", "(", "$", "params", "[", "'userid'", "]", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", ";", "}", "$", "grade", "=", "null", ";", "$", "formattedgrade", "=", "null", ";", "$", "grades", "=", "lesson_get_user_grades", "(", "$", "lesson", ",", "$", "params", "[", "'userid'", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "grades", ")", ")", "{", "$", "grade", "=", "$", "grades", "[", "$", "params", "[", "'userid'", "]", "]", "->", "rawgrade", ";", "$", "params", "=", "array", "(", "'itemtype'", "=>", "'mod'", ",", "'itemmodule'", "=>", "'lesson'", ",", "'iteminstance'", "=>", "$", "lesson", "->", "id", ",", "'courseid'", "=>", "$", "course", "->", "id", ",", "'itemnumber'", "=>", "0", ")", ";", "$", "gradeitem", "=", "grade_item", "::", "fetch", "(", "$", "params", ")", ";", "$", "formattedgrade", "=", "grade_format_gradevalue", "(", "$", "grade", ",", "$", "gradeitem", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'grade'", "]", "=", "$", "grade", ";", "$", "result", "[", "'formattedgrade'", "]", "=", "$", "formattedgrade", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Return the final grade in the lesson for the given user. @param int $lessonid lesson instance id @param int $userid only fetch grades of this user @return array of warnings and page attempts @since Moodle 3.3 @throws moodle_exception
[ "Return", "the", "final", "grade", "in", "the", "lesson", "for", "the", "given", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L616-L660
215,632
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_user_attempt_grade_structure
protected static function get_user_attempt_grade_structure($required = VALUE_REQUIRED) { $data = array( 'nquestions' => new external_value(PARAM_INT, 'Number of questions answered'), 'attempts' => new external_value(PARAM_INT, 'Number of question attempts'), 'total' => new external_value(PARAM_FLOAT, 'Max points possible'), 'earned' => new external_value(PARAM_FLOAT, 'Points earned by student'), 'grade' => new external_value(PARAM_FLOAT, 'Calculated percentage grade'), 'nmanual' => new external_value(PARAM_INT, 'Number of manually graded questions'), 'manualpoints' => new external_value(PARAM_FLOAT, 'Point value for manually graded questions'), ); return new external_single_structure( $data, 'Attempt grade', $required ); }
php
protected static function get_user_attempt_grade_structure($required = VALUE_REQUIRED) { $data = array( 'nquestions' => new external_value(PARAM_INT, 'Number of questions answered'), 'attempts' => new external_value(PARAM_INT, 'Number of question attempts'), 'total' => new external_value(PARAM_FLOAT, 'Max points possible'), 'earned' => new external_value(PARAM_FLOAT, 'Points earned by student'), 'grade' => new external_value(PARAM_FLOAT, 'Calculated percentage grade'), 'nmanual' => new external_value(PARAM_INT, 'Number of manually graded questions'), 'manualpoints' => new external_value(PARAM_FLOAT, 'Point value for manually graded questions'), ); return new external_single_structure( $data, 'Attempt grade', $required ); }
[ "protected", "static", "function", "get_user_attempt_grade_structure", "(", "$", "required", "=", "VALUE_REQUIRED", ")", "{", "$", "data", "=", "array", "(", "'nquestions'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Number of questions answered'", ")", ",", "'attempts'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Number of question attempts'", ")", ",", "'total'", "=>", "new", "external_value", "(", "PARAM_FLOAT", ",", "'Max points possible'", ")", ",", "'earned'", "=>", "new", "external_value", "(", "PARAM_FLOAT", ",", "'Points earned by student'", ")", ",", "'grade'", "=>", "new", "external_value", "(", "PARAM_FLOAT", ",", "'Calculated percentage grade'", ")", ",", "'nmanual'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Number of manually graded questions'", ")", ",", "'manualpoints'", "=>", "new", "external_value", "(", "PARAM_FLOAT", ",", "'Point value for manually graded questions'", ")", ",", ")", ";", "return", "new", "external_single_structure", "(", "$", "data", ",", "'Attempt grade'", ",", "$", "required", ")", ";", "}" ]
Describes an attempt grade structure. @param int $required if the structure is required or optional @return external_single_structure the structure @since Moodle 3.3
[ "Describes", "an", "attempt", "grade", "structure", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L685-L698
215,633
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_user_attempt_grade_parameters
public static function get_user_attempt_grade_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'lesson instance id'), 'lessonattempt' => new external_value(PARAM_INT, 'lesson attempt number'), 'userid' => new external_value(PARAM_INT, 'the user id (empty for current user)', VALUE_DEFAULT, null), ) ); }
php
public static function get_user_attempt_grade_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'lesson instance id'), 'lessonattempt' => new external_value(PARAM_INT, 'lesson attempt number'), 'userid' => new external_value(PARAM_INT, 'the user id (empty for current user)', VALUE_DEFAULT, null), ) ); }
[ "public", "static", "function", "get_user_attempt_grade_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'lessonid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'lesson instance id'", ")", ",", "'lessonattempt'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'lesson attempt number'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'the user id (empty for current user)'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for get_user_attempt_grade. @return external_function_parameters @since Moodle 3.3
[ "Describes", "the", "parameters", "for", "get_user_attempt_grade", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L706-L714
215,634
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_user_attempt_grade
public static function get_user_attempt_grade($lessonid, $lessonattempt, $userid = null) { global $CFG, $USER; require_once($CFG->libdir . '/gradelib.php'); $params = array( 'lessonid' => $lessonid, 'lessonattempt' => $lessonattempt, 'userid' => $userid, ); $params = self::validate_parameters(self::get_user_attempt_grade_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $params['userid']) { self::check_can_view_user_data($params['userid'], $course, $cm, $context); } $result = array(); $result['grade'] = (array) lesson_grade($lesson, $params['lessonattempt'], $params['userid']); $result['warnings'] = $warnings; return $result; }
php
public static function get_user_attempt_grade($lessonid, $lessonattempt, $userid = null) { global $CFG, $USER; require_once($CFG->libdir . '/gradelib.php'); $params = array( 'lessonid' => $lessonid, 'lessonattempt' => $lessonattempt, 'userid' => $userid, ); $params = self::validate_parameters(self::get_user_attempt_grade_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $params['userid']) { self::check_can_view_user_data($params['userid'], $course, $cm, $context); } $result = array(); $result['grade'] = (array) lesson_grade($lesson, $params['lessonattempt'], $params['userid']); $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_user_attempt_grade", "(", "$", "lessonid", ",", "$", "lessonattempt", ",", "$", "userid", "=", "null", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/gradelib.php'", ")", ";", "$", "params", "=", "array", "(", "'lessonid'", "=>", "$", "lessonid", ",", "'lessonattempt'", "=>", "$", "lessonattempt", ",", "'userid'", "=>", "$", "userid", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_user_attempt_grade_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "list", "(", "$", "lesson", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ",", "$", "lessonrecord", ")", "=", "self", "::", "validate_lesson", "(", "$", "params", "[", "'lessonid'", "]", ")", ";", "// Default value for userid.", "if", "(", "empty", "(", "$", "params", "[", "'userid'", "]", ")", ")", "{", "$", "params", "[", "'userid'", "]", "=", "$", "USER", "->", "id", ";", "}", "// Extra checks so only users with permissions can view other users attempts.", "if", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "{", "self", "::", "check_can_view_user_data", "(", "$", "params", "[", "'userid'", "]", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'grade'", "]", "=", "(", "array", ")", "lesson_grade", "(", "$", "lesson", ",", "$", "params", "[", "'lessonattempt'", "]", ",", "$", "params", "[", "'userid'", "]", ")", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Return grade information in the attempt for a given user. @param int $lessonid lesson instance id @param int $lessonattempt lesson attempt number @param int $userid only fetch attempts of the given user @return array of warnings and page attempts @since Moodle 3.3 @throws moodle_exception
[ "Return", "grade", "information", "in", "the", "attempt", "for", "a", "given", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L726-L754
215,635
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_content_pages_viewed_parameters
public static function get_content_pages_viewed_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'lesson instance id'), 'lessonattempt' => new external_value(PARAM_INT, 'lesson attempt number'), 'userid' => new external_value(PARAM_INT, 'the user id (empty for current user)', VALUE_DEFAULT, null), ) ); }
php
public static function get_content_pages_viewed_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'lesson instance id'), 'lessonattempt' => new external_value(PARAM_INT, 'lesson attempt number'), 'userid' => new external_value(PARAM_INT, 'the user id (empty for current user)', VALUE_DEFAULT, null), ) ); }
[ "public", "static", "function", "get_content_pages_viewed_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'lessonid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'lesson instance id'", ")", ",", "'lessonattempt'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'lesson attempt number'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'the user id (empty for current user)'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for get_content_pages_viewed. @return external_function_parameters @since Moodle 3.3
[ "Describes", "the", "parameters", "for", "get_content_pages_viewed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L777-L785
215,636
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_content_pages_viewed
public static function get_content_pages_viewed($lessonid, $lessonattempt, $userid = null) { global $USER; $params = array( 'lessonid' => $lessonid, 'lessonattempt' => $lessonattempt, 'userid' => $userid, ); $params = self::validate_parameters(self::get_content_pages_viewed_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $params['userid']) { self::check_can_view_user_data($params['userid'], $course, $cm, $context); } $pages = $lesson->get_content_pages_viewed($params['lessonattempt'], $params['userid']); $result = array(); $result['pages'] = $pages; $result['warnings'] = $warnings; return $result; }
php
public static function get_content_pages_viewed($lessonid, $lessonattempt, $userid = null) { global $USER; $params = array( 'lessonid' => $lessonid, 'lessonattempt' => $lessonattempt, 'userid' => $userid, ); $params = self::validate_parameters(self::get_content_pages_viewed_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $params['userid']) { self::check_can_view_user_data($params['userid'], $course, $cm, $context); } $pages = $lesson->get_content_pages_viewed($params['lessonattempt'], $params['userid']); $result = array(); $result['pages'] = $pages; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_content_pages_viewed", "(", "$", "lessonid", ",", "$", "lessonattempt", ",", "$", "userid", "=", "null", ")", "{", "global", "$", "USER", ";", "$", "params", "=", "array", "(", "'lessonid'", "=>", "$", "lessonid", ",", "'lessonattempt'", "=>", "$", "lessonattempt", ",", "'userid'", "=>", "$", "userid", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_content_pages_viewed_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "list", "(", "$", "lesson", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ",", "$", "lessonrecord", ")", "=", "self", "::", "validate_lesson", "(", "$", "params", "[", "'lessonid'", "]", ")", ";", "// Default value for userid.", "if", "(", "empty", "(", "$", "params", "[", "'userid'", "]", ")", ")", "{", "$", "params", "[", "'userid'", "]", "=", "$", "USER", "->", "id", ";", "}", "// Extra checks so only users with permissions can view other users attempts.", "if", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "{", "self", "::", "check_can_view_user_data", "(", "$", "params", "[", "'userid'", "]", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", ";", "}", "$", "pages", "=", "$", "lesson", "->", "get_content_pages_viewed", "(", "$", "params", "[", "'lessonattempt'", "]", ",", "$", "params", "[", "'userid'", "]", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'pages'", "]", "=", "$", "pages", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Return the list of content pages viewed by a user during a lesson attempt. @param int $lessonid lesson instance id @param int $lessonattempt lesson attempt number @param int $userid only fetch attempts of the given user @return array of warnings and page attempts @since Moodle 3.3 @throws moodle_exception
[ "Return", "the", "list", "of", "content", "pages", "viewed", "by", "a", "user", "during", "a", "lesson", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L797-L826
215,637
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_content_pages_viewed_returns
public static function get_content_pages_viewed_returns() { return new external_single_structure( array( 'pages' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The attempt id.'), 'lessonid' => new external_value(PARAM_INT, 'The lesson id.'), 'pageid' => new external_value(PARAM_INT, 'The page id.'), 'userid' => new external_value(PARAM_INT, 'The user who viewed the page.'), 'retry' => new external_value(PARAM_INT, 'The lesson attempt number.'), 'flag' => new external_value(PARAM_INT, '1 if the next page was calculated randomly.'), 'timeseen' => new external_value(PARAM_INT, 'The time the page was seen.'), 'nextpageid' => new external_value(PARAM_INT, 'The next page chosen id.'), ), 'The content pages viewed.' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_content_pages_viewed_returns() { return new external_single_structure( array( 'pages' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The attempt id.'), 'lessonid' => new external_value(PARAM_INT, 'The lesson id.'), 'pageid' => new external_value(PARAM_INT, 'The page id.'), 'userid' => new external_value(PARAM_INT, 'The user who viewed the page.'), 'retry' => new external_value(PARAM_INT, 'The lesson attempt number.'), 'flag' => new external_value(PARAM_INT, '1 if the next page was calculated randomly.'), 'timeseen' => new external_value(PARAM_INT, 'The time the page was seen.'), 'nextpageid' => new external_value(PARAM_INT, 'The next page chosen id.'), ), 'The content pages viewed.' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_content_pages_viewed_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'pages'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The attempt id.'", ")", ",", "'lessonid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The lesson id.'", ")", ",", "'pageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The page id.'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The user who viewed the page.'", ")", ",", "'retry'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The lesson attempt number.'", ")", ",", "'flag'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'1 if the next page was calculated randomly.'", ")", ",", "'timeseen'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The time the page was seen.'", ")", ",", "'nextpageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The next page chosen id.'", ")", ",", ")", ",", "'The content pages viewed.'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_content_pages_viewed return value. @return external_single_structure @since Moodle 3.3
[ "Describes", "the", "get_content_pages_viewed", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L834-L855
215,638
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_user_timers_returns
public static function get_user_timers_returns() { return new external_single_structure( array( 'timers' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The attempt id'), 'lessonid' => new external_value(PARAM_INT, 'The lesson id'), 'userid' => new external_value(PARAM_INT, 'The user id'), 'starttime' => new external_value(PARAM_INT, 'First access time for a new timer session'), 'lessontime' => new external_value(PARAM_INT, 'Last access time to the lesson during the timer session'), 'completed' => new external_value(PARAM_INT, 'If the lesson for this timer was completed'), 'timemodifiedoffline' => new external_value(PARAM_INT, 'Last modified time via webservices.'), ), 'The timers' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_user_timers_returns() { return new external_single_structure( array( 'timers' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The attempt id'), 'lessonid' => new external_value(PARAM_INT, 'The lesson id'), 'userid' => new external_value(PARAM_INT, 'The user id'), 'starttime' => new external_value(PARAM_INT, 'First access time for a new timer session'), 'lessontime' => new external_value(PARAM_INT, 'Last access time to the lesson during the timer session'), 'completed' => new external_value(PARAM_INT, 'If the lesson for this timer was completed'), 'timemodifiedoffline' => new external_value(PARAM_INT, 'Last modified time via webservices.'), ), 'The timers' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_user_timers_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'timers'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The attempt id'", ")", ",", "'lessonid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The lesson id'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The user id'", ")", ",", "'starttime'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'First access time for a new timer session'", ")", ",", "'lessontime'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Last access time to the lesson during the timer session'", ")", ",", "'completed'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'If the lesson for this timer was completed'", ")", ",", "'timemodifiedoffline'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Last modified time via webservices.'", ")", ",", ")", ",", "'The timers'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_user_timers return value. @return external_single_structure @since Moodle 3.3
[ "Describes", "the", "get_user_timers", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L917-L937
215,639
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_page_structure
protected static function get_page_structure($required = VALUE_REQUIRED) { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The id of this lesson page'), 'lessonid' => new external_value(PARAM_INT, 'The id of the lesson this page belongs to'), 'prevpageid' => new external_value(PARAM_INT, 'The id of the page before this one'), 'nextpageid' => new external_value(PARAM_INT, 'The id of the next page in the page sequence'), 'qtype' => new external_value(PARAM_INT, 'Identifies the page type of this page'), 'qoption' => new external_value(PARAM_INT, 'Used to record page type specific options'), 'layout' => new external_value(PARAM_INT, 'Used to record page specific layout selections'), 'display' => new external_value(PARAM_INT, 'Used to record page specific display selections'), 'timecreated' => new external_value(PARAM_INT, 'Timestamp for when the page was created'), 'timemodified' => new external_value(PARAM_INT, 'Timestamp for when the page was last modified'), 'title' => new external_value(PARAM_RAW, 'The title of this page', VALUE_OPTIONAL), 'contents' => new external_value(PARAM_RAW, 'The contents of this page', VALUE_OPTIONAL), 'contentsformat' => new external_format_value('contents', VALUE_OPTIONAL), 'displayinmenublock' => new external_value(PARAM_BOOL, 'Toggles display in the left menu block'), 'type' => new external_value(PARAM_INT, 'The type of the page [question | structure]'), 'typeid' => new external_value(PARAM_INT, 'The unique identifier for the page type'), 'typestring' => new external_value(PARAM_RAW, 'The string that describes this page type'), ), 'Page fields', $required ); }
php
protected static function get_page_structure($required = VALUE_REQUIRED) { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The id of this lesson page'), 'lessonid' => new external_value(PARAM_INT, 'The id of the lesson this page belongs to'), 'prevpageid' => new external_value(PARAM_INT, 'The id of the page before this one'), 'nextpageid' => new external_value(PARAM_INT, 'The id of the next page in the page sequence'), 'qtype' => new external_value(PARAM_INT, 'Identifies the page type of this page'), 'qoption' => new external_value(PARAM_INT, 'Used to record page type specific options'), 'layout' => new external_value(PARAM_INT, 'Used to record page specific layout selections'), 'display' => new external_value(PARAM_INT, 'Used to record page specific display selections'), 'timecreated' => new external_value(PARAM_INT, 'Timestamp for when the page was created'), 'timemodified' => new external_value(PARAM_INT, 'Timestamp for when the page was last modified'), 'title' => new external_value(PARAM_RAW, 'The title of this page', VALUE_OPTIONAL), 'contents' => new external_value(PARAM_RAW, 'The contents of this page', VALUE_OPTIONAL), 'contentsformat' => new external_format_value('contents', VALUE_OPTIONAL), 'displayinmenublock' => new external_value(PARAM_BOOL, 'Toggles display in the left menu block'), 'type' => new external_value(PARAM_INT, 'The type of the page [question | structure]'), 'typeid' => new external_value(PARAM_INT, 'The unique identifier for the page type'), 'typestring' => new external_value(PARAM_RAW, 'The string that describes this page type'), ), 'Page fields', $required ); }
[ "protected", "static", "function", "get_page_structure", "(", "$", "required", "=", "VALUE_REQUIRED", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of this lesson page'", ")", ",", "'lessonid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the lesson this page belongs to'", ")", ",", "'prevpageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the page before this one'", ")", ",", "'nextpageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the next page in the page sequence'", ")", ",", "'qtype'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Identifies the page type of this page'", ")", ",", "'qoption'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Used to record page type specific options'", ")", ",", "'layout'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Used to record page specific layout selections'", ")", ",", "'display'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Used to record page specific display selections'", ")", ",", "'timecreated'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Timestamp for when the page was created'", ")", ",", "'timemodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Timestamp for when the page was last modified'", ")", ",", "'title'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The title of this page'", ",", "VALUE_OPTIONAL", ")", ",", "'contents'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The contents of this page'", ",", "VALUE_OPTIONAL", ")", ",", "'contentsformat'", "=>", "new", "external_format_value", "(", "'contents'", ",", "VALUE_OPTIONAL", ")", ",", "'displayinmenublock'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Toggles display in the left menu block'", ")", ",", "'type'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The type of the page [question | structure]'", ")", ",", "'typeid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The unique identifier for the page type'", ")", ",", "'typestring'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The string that describes this page type'", ")", ",", ")", ",", "'Page fields'", ",", "$", "required", ")", ";", "}" ]
Describes the external structure for a lesson page. @return external_single_structure @since Moodle 3.3
[ "Describes", "the", "external", "structure", "for", "a", "lesson", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L945-L968
215,640
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_page_fields
protected static function get_page_fields(lesson_page $page, $returncontents = false) { $lesson = $page->lesson; $context = $lesson->context; $pagedata = new stdClass; // Contains the data that will be returned by the WS. // Return the visible data. $visibleproperties = array('id', 'lessonid', 'prevpageid', 'nextpageid', 'qtype', 'qoption', 'layout', 'display', 'displayinmenublock', 'type', 'typeid', 'typestring', 'timecreated', 'timemodified'); foreach ($visibleproperties as $prop) { $pagedata->{$prop} = $page->{$prop}; } // Check if we can see title (contents required custom rendering, we won't returning it here @see get_page_data). $canmanage = $lesson->can_manage(); // If we are managers or the menu block is enabled and is a content page visible always return contents. if ($returncontents || $canmanage || (lesson_displayleftif($lesson) && $page->displayinmenublock && $page->display)) { $pagedata->title = external_format_string($page->title, $context->id); $options = array('noclean' => true); list($pagedata->contents, $pagedata->contentsformat) = external_format_text($page->contents, $page->contentsformat, $context->id, 'mod_lesson', 'page_contents', $page->id, $options); } return $pagedata; }
php
protected static function get_page_fields(lesson_page $page, $returncontents = false) { $lesson = $page->lesson; $context = $lesson->context; $pagedata = new stdClass; // Contains the data that will be returned by the WS. // Return the visible data. $visibleproperties = array('id', 'lessonid', 'prevpageid', 'nextpageid', 'qtype', 'qoption', 'layout', 'display', 'displayinmenublock', 'type', 'typeid', 'typestring', 'timecreated', 'timemodified'); foreach ($visibleproperties as $prop) { $pagedata->{$prop} = $page->{$prop}; } // Check if we can see title (contents required custom rendering, we won't returning it here @see get_page_data). $canmanage = $lesson->can_manage(); // If we are managers or the menu block is enabled and is a content page visible always return contents. if ($returncontents || $canmanage || (lesson_displayleftif($lesson) && $page->displayinmenublock && $page->display)) { $pagedata->title = external_format_string($page->title, $context->id); $options = array('noclean' => true); list($pagedata->contents, $pagedata->contentsformat) = external_format_text($page->contents, $page->contentsformat, $context->id, 'mod_lesson', 'page_contents', $page->id, $options); } return $pagedata; }
[ "protected", "static", "function", "get_page_fields", "(", "lesson_page", "$", "page", ",", "$", "returncontents", "=", "false", ")", "{", "$", "lesson", "=", "$", "page", "->", "lesson", ";", "$", "context", "=", "$", "lesson", "->", "context", ";", "$", "pagedata", "=", "new", "stdClass", ";", "// Contains the data that will be returned by the WS.", "// Return the visible data.", "$", "visibleproperties", "=", "array", "(", "'id'", ",", "'lessonid'", ",", "'prevpageid'", ",", "'nextpageid'", ",", "'qtype'", ",", "'qoption'", ",", "'layout'", ",", "'display'", ",", "'displayinmenublock'", ",", "'type'", ",", "'typeid'", ",", "'typestring'", ",", "'timecreated'", ",", "'timemodified'", ")", ";", "foreach", "(", "$", "visibleproperties", "as", "$", "prop", ")", "{", "$", "pagedata", "->", "{", "$", "prop", "}", "=", "$", "page", "->", "{", "$", "prop", "}", ";", "}", "// Check if we can see title (contents required custom rendering, we won't returning it here @see get_page_data).", "$", "canmanage", "=", "$", "lesson", "->", "can_manage", "(", ")", ";", "// If we are managers or the menu block is enabled and is a content page visible always return contents.", "if", "(", "$", "returncontents", "||", "$", "canmanage", "||", "(", "lesson_displayleftif", "(", "$", "lesson", ")", "&&", "$", "page", "->", "displayinmenublock", "&&", "$", "page", "->", "display", ")", ")", "{", "$", "pagedata", "->", "title", "=", "external_format_string", "(", "$", "page", "->", "title", ",", "$", "context", "->", "id", ")", ";", "$", "options", "=", "array", "(", "'noclean'", "=>", "true", ")", ";", "list", "(", "$", "pagedata", "->", "contents", ",", "$", "pagedata", "->", "contentsformat", ")", "=", "external_format_text", "(", "$", "page", "->", "contents", ",", "$", "page", "->", "contentsformat", ",", "$", "context", "->", "id", ",", "'mod_lesson'", ",", "'page_contents'", ",", "$", "page", "->", "id", ",", "$", "options", ")", ";", "}", "return", "$", "pagedata", ";", "}" ]
Returns the fields of a page object @param lesson_page $page the lesson page @param bool $returncontents whether to return the page title and contents @return stdClass the fields matching the external page structure @since Moodle 3.3
[ "Returns", "the", "fields", "of", "a", "page", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L977-L1003
215,641
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_pages_returns
public static function get_pages_returns() { return new external_single_structure( array( 'pages' => new external_multiple_structure( new external_single_structure( array( 'page' => self::get_page_structure(), 'answerids' => new external_multiple_structure( new external_value(PARAM_INT, 'Answer id'), 'List of answers ids (empty for content pages in Moodle 1.9)' ), 'jumps' => new external_multiple_structure( new external_value(PARAM_INT, 'Page to jump id'), 'List of possible page jumps' ), 'filescount' => new external_value(PARAM_INT, 'The total number of files attached to the page'), 'filessizetotal' => new external_value(PARAM_INT, 'The total size of the files'), ), 'The lesson pages' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_pages_returns() { return new external_single_structure( array( 'pages' => new external_multiple_structure( new external_single_structure( array( 'page' => self::get_page_structure(), 'answerids' => new external_multiple_structure( new external_value(PARAM_INT, 'Answer id'), 'List of answers ids (empty for content pages in Moodle 1.9)' ), 'jumps' => new external_multiple_structure( new external_value(PARAM_INT, 'Page to jump id'), 'List of possible page jumps' ), 'filescount' => new external_value(PARAM_INT, 'The total number of files attached to the page'), 'filessizetotal' => new external_value(PARAM_INT, 'The total size of the files'), ), 'The lesson pages' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_pages_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'pages'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'page'", "=>", "self", "::", "get_page_structure", "(", ")", ",", "'answerids'", "=>", "new", "external_multiple_structure", "(", "new", "external_value", "(", "PARAM_INT", ",", "'Answer id'", ")", ",", "'List of answers ids (empty for content pages in Moodle 1.9)'", ")", ",", "'jumps'", "=>", "new", "external_multiple_structure", "(", "new", "external_value", "(", "PARAM_INT", ",", "'Page to jump id'", ")", ",", "'List of possible page jumps'", ")", ",", "'filescount'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The total number of files attached to the page'", ")", ",", "'filessizetotal'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The total size of the files'", ")", ",", ")", ",", "'The lesson pages'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_pages return value. @return external_single_structure @since Moodle 3.3
[ "Describes", "the", "get_pages", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1084-L1106
215,642
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.launch_attempt_parameters
public static function launch_attempt_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'lesson instance id'), 'password' => new external_value(PARAM_RAW, 'optional password (the lesson may be protected)', VALUE_DEFAULT, ''), 'pageid' => new external_value(PARAM_INT, 'page id to continue from (only when continuing an attempt)', VALUE_DEFAULT, 0), 'review' => new external_value(PARAM_BOOL, 'if we want to review just after finishing', VALUE_DEFAULT, false), ) ); }
php
public static function launch_attempt_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'lesson instance id'), 'password' => new external_value(PARAM_RAW, 'optional password (the lesson may be protected)', VALUE_DEFAULT, ''), 'pageid' => new external_value(PARAM_INT, 'page id to continue from (only when continuing an attempt)', VALUE_DEFAULT, 0), 'review' => new external_value(PARAM_BOOL, 'if we want to review just after finishing', VALUE_DEFAULT, false), ) ); }
[ "public", "static", "function", "launch_attempt_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'lessonid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'lesson instance id'", ")", ",", "'password'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'optional password (the lesson may be protected)'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", "'pageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'page id to continue from (only when continuing an attempt)'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'review'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'if we want to review just after finishing'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for launch_attempt. @return external_function_parameters @since Moodle 3.3
[ "Describes", "the", "parameters", "for", "launch_attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1114-L1123
215,643
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.format_lesson_messages
protected static function format_lesson_messages($lesson) { $messages = array(); foreach ($lesson->messages as $message) { $messages[] = array( 'message' => $message[0], 'type' => $message[1], ); } return $messages; }
php
protected static function format_lesson_messages($lesson) { $messages = array(); foreach ($lesson->messages as $message) { $messages[] = array( 'message' => $message[0], 'type' => $message[1], ); } return $messages; }
[ "protected", "static", "function", "format_lesson_messages", "(", "$", "lesson", ")", "{", "$", "messages", "=", "array", "(", ")", ";", "foreach", "(", "$", "lesson", "->", "messages", "as", "$", "message", ")", "{", "$", "messages", "[", "]", "=", "array", "(", "'message'", "=>", "$", "message", "[", "0", "]", ",", "'type'", "=>", "$", "message", "[", "1", "]", ",", ")", ";", "}", "return", "$", "messages", ";", "}" ]
Return lesson messages formatted according the external_messages structure @param lesson $lesson lesson instance @return array messages formatted @since Moodle 3.3
[ "Return", "lesson", "messages", "formatted", "according", "the", "external_messages", "structure" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1132-L1141
215,644
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.launch_attempt
public static function launch_attempt($lessonid, $password = '', $pageid = 0, $review = false) { global $CFG, $USER; $params = array('lessonid' => $lessonid, 'password' => $password, 'pageid' => $pageid, 'review' => $review); $params = self::validate_parameters(self::launch_attempt_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); self::validate_attempt($lesson, $params); $newpageid = 0; // Starting a new lesson attempt. if (empty($params['pageid'])) { // Check if there is a recent timer created during the active session. $alreadystarted = false; if ($timers = $lesson->get_user_timers($USER->id, 'starttime DESC', '*', 0, 1)) { $timer = array_shift($timers); $endtime = $lesson->timelimit > 0 ? min($CFG->sessiontimeout, $lesson->timelimit) : $CFG->sessiontimeout; if (!$timer->completed && $timer->starttime > time() - $endtime) { $alreadystarted = true; } } if (!$alreadystarted && !$lesson->can_manage()) { $lesson->start_timer(); } } else { if ($params['pageid'] == LESSON_EOL) { throw new moodle_exception('endoflesson', 'lesson'); } $timer = $lesson->update_timer(true, true); if (!$lesson->check_time($timer)) { throw new moodle_exception('eolstudentoutoftime', 'lesson'); } } $messages = self::format_lesson_messages($lesson); $result = array( 'status' => true, 'messages' => $messages, 'warnings' => $warnings, ); return $result; }
php
public static function launch_attempt($lessonid, $password = '', $pageid = 0, $review = false) { global $CFG, $USER; $params = array('lessonid' => $lessonid, 'password' => $password, 'pageid' => $pageid, 'review' => $review); $params = self::validate_parameters(self::launch_attempt_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); self::validate_attempt($lesson, $params); $newpageid = 0; // Starting a new lesson attempt. if (empty($params['pageid'])) { // Check if there is a recent timer created during the active session. $alreadystarted = false; if ($timers = $lesson->get_user_timers($USER->id, 'starttime DESC', '*', 0, 1)) { $timer = array_shift($timers); $endtime = $lesson->timelimit > 0 ? min($CFG->sessiontimeout, $lesson->timelimit) : $CFG->sessiontimeout; if (!$timer->completed && $timer->starttime > time() - $endtime) { $alreadystarted = true; } } if (!$alreadystarted && !$lesson->can_manage()) { $lesson->start_timer(); } } else { if ($params['pageid'] == LESSON_EOL) { throw new moodle_exception('endoflesson', 'lesson'); } $timer = $lesson->update_timer(true, true); if (!$lesson->check_time($timer)) { throw new moodle_exception('eolstudentoutoftime', 'lesson'); } } $messages = self::format_lesson_messages($lesson); $result = array( 'status' => true, 'messages' => $messages, 'warnings' => $warnings, ); return $result; }
[ "public", "static", "function", "launch_attempt", "(", "$", "lessonid", ",", "$", "password", "=", "''", ",", "$", "pageid", "=", "0", ",", "$", "review", "=", "false", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "$", "params", "=", "array", "(", "'lessonid'", "=>", "$", "lessonid", ",", "'password'", "=>", "$", "password", ",", "'pageid'", "=>", "$", "pageid", ",", "'review'", "=>", "$", "review", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "launch_attempt_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "list", "(", "$", "lesson", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ",", "$", "lessonrecord", ")", "=", "self", "::", "validate_lesson", "(", "$", "params", "[", "'lessonid'", "]", ")", ";", "self", "::", "validate_attempt", "(", "$", "lesson", ",", "$", "params", ")", ";", "$", "newpageid", "=", "0", ";", "// Starting a new lesson attempt.", "if", "(", "empty", "(", "$", "params", "[", "'pageid'", "]", ")", ")", "{", "// Check if there is a recent timer created during the active session.", "$", "alreadystarted", "=", "false", ";", "if", "(", "$", "timers", "=", "$", "lesson", "->", "get_user_timers", "(", "$", "USER", "->", "id", ",", "'starttime DESC'", ",", "'*'", ",", "0", ",", "1", ")", ")", "{", "$", "timer", "=", "array_shift", "(", "$", "timers", ")", ";", "$", "endtime", "=", "$", "lesson", "->", "timelimit", ">", "0", "?", "min", "(", "$", "CFG", "->", "sessiontimeout", ",", "$", "lesson", "->", "timelimit", ")", ":", "$", "CFG", "->", "sessiontimeout", ";", "if", "(", "!", "$", "timer", "->", "completed", "&&", "$", "timer", "->", "starttime", ">", "time", "(", ")", "-", "$", "endtime", ")", "{", "$", "alreadystarted", "=", "true", ";", "}", "}", "if", "(", "!", "$", "alreadystarted", "&&", "!", "$", "lesson", "->", "can_manage", "(", ")", ")", "{", "$", "lesson", "->", "start_timer", "(", ")", ";", "}", "}", "else", "{", "if", "(", "$", "params", "[", "'pageid'", "]", "==", "LESSON_EOL", ")", "{", "throw", "new", "moodle_exception", "(", "'endoflesson'", ",", "'lesson'", ")", ";", "}", "$", "timer", "=", "$", "lesson", "->", "update_timer", "(", "true", ",", "true", ")", ";", "if", "(", "!", "$", "lesson", "->", "check_time", "(", "$", "timer", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'eolstudentoutoftime'", ",", "'lesson'", ")", ";", "}", "}", "$", "messages", "=", "self", "::", "format_lesson_messages", "(", "$", "lesson", ")", ";", "$", "result", "=", "array", "(", "'status'", "=>", "true", ",", "'messages'", "=>", "$", "messages", ",", "'warnings'", "=>", "$", "warnings", ",", ")", ";", "return", "$", "result", ";", "}" ]
Starts a new attempt or continues an existing one. @param int $lessonid lesson instance id @param string $password optional password (the lesson may be protected) @param int $pageid page id to continue from (only when continuing an attempt) @param bool $review if we want to review just after finishing @return array of warnings and status result @since Moodle 3.3 @throws moodle_exception
[ "Starts", "a", "new", "attempt", "or", "continues", "an", "existing", "one", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1172-L1214
215,645
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_page_data_parameters
public static function get_page_data_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'lesson instance id'), 'pageid' => new external_value(PARAM_INT, 'the page id'), 'password' => new external_value(PARAM_RAW, 'optional password (the lesson may be protected)', VALUE_DEFAULT, ''), 'review' => new external_value(PARAM_BOOL, 'if we want to review just after finishing (1 hour margin)', VALUE_DEFAULT, false), 'returncontents' => new external_value(PARAM_BOOL, 'if we must return the complete page contents once rendered', VALUE_DEFAULT, false), ) ); }
php
public static function get_page_data_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'lesson instance id'), 'pageid' => new external_value(PARAM_INT, 'the page id'), 'password' => new external_value(PARAM_RAW, 'optional password (the lesson may be protected)', VALUE_DEFAULT, ''), 'review' => new external_value(PARAM_BOOL, 'if we want to review just after finishing (1 hour margin)', VALUE_DEFAULT, false), 'returncontents' => new external_value(PARAM_BOOL, 'if we must return the complete page contents once rendered', VALUE_DEFAULT, false), ) ); }
[ "public", "static", "function", "get_page_data_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'lessonid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'lesson instance id'", ")", ",", "'pageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'the page id'", ")", ",", "'password'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'optional password (the lesson may be protected)'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", "'review'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'if we want to review just after finishing (1 hour margin)'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", "'returncontents'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'if we must return the complete page contents once rendered'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for get_page_data. @return external_function_parameters @since Moodle 3.3
[ "Describes", "the", "parameters", "for", "get_page_data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1237-L1249
215,646
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_page_data_returns
public static function get_page_data_returns() { return new external_single_structure( array( 'page' => self::get_page_structure(VALUE_OPTIONAL), 'newpageid' => new external_value(PARAM_INT, 'New page id (if a jump was made)'), 'pagecontent' => new external_value(PARAM_RAW, 'Page html content', VALUE_OPTIONAL), 'ongoingscore' => new external_value(PARAM_TEXT, 'The ongoing score message'), 'progress' => new external_value(PARAM_INT, 'Progress percentage in the lesson'), 'contentfiles' => new external_files(), 'answers' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The ID of this answer in the database'), 'answerfiles' => new external_files(), 'responsefiles' => new external_files(), 'jumpto' => new external_value(PARAM_INT, 'Identifies where the user goes upon completing a page with this answer', VALUE_OPTIONAL), 'grade' => new external_value(PARAM_INT, 'The grade this answer is worth', VALUE_OPTIONAL), 'score' => new external_value(PARAM_INT, 'The score this answer will give', VALUE_OPTIONAL), 'flags' => new external_value(PARAM_INT, 'Used to store options for the answer', VALUE_OPTIONAL), 'timecreated' => new external_value(PARAM_INT, 'A timestamp of when the answer was created', VALUE_OPTIONAL), 'timemodified' => new external_value(PARAM_INT, 'A timestamp of when the answer was modified', VALUE_OPTIONAL), 'answer' => new external_value(PARAM_RAW, 'Possible answer text', VALUE_OPTIONAL), 'answerformat' => new external_format_value('answer', VALUE_OPTIONAL), 'response' => new external_value(PARAM_RAW, 'Response text for the answer', VALUE_OPTIONAL), 'responseformat' => new external_format_value('response', VALUE_OPTIONAL), ), 'The page answers' ) ), 'messages' => self::external_messages(), 'displaymenu' => new external_value(PARAM_BOOL, 'Whether we should display the menu or not in this page.'), 'warnings' => new external_warnings(), ) ); }
php
public static function get_page_data_returns() { return new external_single_structure( array( 'page' => self::get_page_structure(VALUE_OPTIONAL), 'newpageid' => new external_value(PARAM_INT, 'New page id (if a jump was made)'), 'pagecontent' => new external_value(PARAM_RAW, 'Page html content', VALUE_OPTIONAL), 'ongoingscore' => new external_value(PARAM_TEXT, 'The ongoing score message'), 'progress' => new external_value(PARAM_INT, 'Progress percentage in the lesson'), 'contentfiles' => new external_files(), 'answers' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The ID of this answer in the database'), 'answerfiles' => new external_files(), 'responsefiles' => new external_files(), 'jumpto' => new external_value(PARAM_INT, 'Identifies where the user goes upon completing a page with this answer', VALUE_OPTIONAL), 'grade' => new external_value(PARAM_INT, 'The grade this answer is worth', VALUE_OPTIONAL), 'score' => new external_value(PARAM_INT, 'The score this answer will give', VALUE_OPTIONAL), 'flags' => new external_value(PARAM_INT, 'Used to store options for the answer', VALUE_OPTIONAL), 'timecreated' => new external_value(PARAM_INT, 'A timestamp of when the answer was created', VALUE_OPTIONAL), 'timemodified' => new external_value(PARAM_INT, 'A timestamp of when the answer was modified', VALUE_OPTIONAL), 'answer' => new external_value(PARAM_RAW, 'Possible answer text', VALUE_OPTIONAL), 'answerformat' => new external_format_value('answer', VALUE_OPTIONAL), 'response' => new external_value(PARAM_RAW, 'Response text for the answer', VALUE_OPTIONAL), 'responseformat' => new external_format_value('response', VALUE_OPTIONAL), ), 'The page answers' ) ), 'messages' => self::external_messages(), 'displaymenu' => new external_value(PARAM_BOOL, 'Whether we should display the menu or not in this page.'), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_page_data_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'page'", "=>", "self", "::", "get_page_structure", "(", "VALUE_OPTIONAL", ")", ",", "'newpageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'New page id (if a jump was made)'", ")", ",", "'pagecontent'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Page html content'", ",", "VALUE_OPTIONAL", ")", ",", "'ongoingscore'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'The ongoing score message'", ")", ",", "'progress'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Progress percentage in the lesson'", ")", ",", "'contentfiles'", "=>", "new", "external_files", "(", ")", ",", "'answers'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The ID of this answer in the database'", ")", ",", "'answerfiles'", "=>", "new", "external_files", "(", ")", ",", "'responsefiles'", "=>", "new", "external_files", "(", ")", ",", "'jumpto'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Identifies where the user goes upon completing a page with this answer'", ",", "VALUE_OPTIONAL", ")", ",", "'grade'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The grade this answer is worth'", ",", "VALUE_OPTIONAL", ")", ",", "'score'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The score this answer will give'", ",", "VALUE_OPTIONAL", ")", ",", "'flags'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Used to store options for the answer'", ",", "VALUE_OPTIONAL", ")", ",", "'timecreated'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'A timestamp of when the answer was created'", ",", "VALUE_OPTIONAL", ")", ",", "'timemodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'A timestamp of when the answer was modified'", ",", "VALUE_OPTIONAL", ")", ",", "'answer'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Possible answer text'", ",", "VALUE_OPTIONAL", ")", ",", "'answerformat'", "=>", "new", "external_format_value", "(", "'answer'", ",", "VALUE_OPTIONAL", ")", ",", "'response'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Response text for the answer'", ",", "VALUE_OPTIONAL", ")", ",", "'responseformat'", "=>", "new", "external_format_value", "(", "'response'", ",", "VALUE_OPTIONAL", ")", ",", ")", ",", "'The page answers'", ")", ")", ",", "'messages'", "=>", "self", "::", "external_messages", "(", ")", ",", "'displaymenu'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether we should display the menu or not in this page.'", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_page_data return value. @return external_single_structure @since Moodle 3.3
[ "Describes", "the", "get_page_data", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1366-L1401
215,647
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.process_page_parameters
public static function process_page_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'lesson instance id'), 'pageid' => new external_value(PARAM_INT, 'the page id'), 'data' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_RAW, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'the data to be saved' ), 'password' => new external_value(PARAM_RAW, 'optional password (the lesson may be protected)', VALUE_DEFAULT, ''), 'review' => new external_value(PARAM_BOOL, 'if we want to review just after finishing (1 hour margin)', VALUE_DEFAULT, false), ) ); }
php
public static function process_page_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'lesson instance id'), 'pageid' => new external_value(PARAM_INT, 'the page id'), 'data' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_RAW, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'the data to be saved' ), 'password' => new external_value(PARAM_RAW, 'optional password (the lesson may be protected)', VALUE_DEFAULT, ''), 'review' => new external_value(PARAM_BOOL, 'if we want to review just after finishing (1 hour margin)', VALUE_DEFAULT, false), ) ); }
[ "public", "static", "function", "process_page_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'lessonid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'lesson instance id'", ")", ",", "'pageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'the page id'", ")", ",", "'data'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'name'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'data name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'data value'", ")", ",", ")", ")", ",", "'the data to be saved'", ")", ",", "'password'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'optional password (the lesson may be protected)'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", "'review'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'if we want to review just after finishing (1 hour margin)'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for process_page. @return external_function_parameters @since Moodle 3.3
[ "Describes", "the", "parameters", "for", "process_page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1409-L1427
215,648
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.finish_attempt_parameters
public static function finish_attempt_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'Lesson instance id.'), 'password' => new external_value(PARAM_RAW, 'Optional password (the lesson may be protected).', VALUE_DEFAULT, ''), 'outoftime' => new external_value(PARAM_BOOL, 'If the user run out of time.', VALUE_DEFAULT, false), 'review' => new external_value(PARAM_BOOL, 'If we want to review just after finishing (1 hour margin).', VALUE_DEFAULT, false), ) ); }
php
public static function finish_attempt_parameters() { return new external_function_parameters ( array( 'lessonid' => new external_value(PARAM_INT, 'Lesson instance id.'), 'password' => new external_value(PARAM_RAW, 'Optional password (the lesson may be protected).', VALUE_DEFAULT, ''), 'outoftime' => new external_value(PARAM_BOOL, 'If the user run out of time.', VALUE_DEFAULT, false), 'review' => new external_value(PARAM_BOOL, 'If we want to review just after finishing (1 hour margin).', VALUE_DEFAULT, false), ) ); }
[ "public", "static", "function", "finish_attempt_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'lessonid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Lesson instance id.'", ")", ",", "'password'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Optional password (the lesson may be protected).'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", "'outoftime'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'If the user run out of time.'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", "'review'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'If we want to review just after finishing (1 hour margin).'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for finish_attempt. @return external_function_parameters @since Moodle 3.3
[ "Describes", "the", "parameters", "for", "finish_attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1551-L1561
215,649
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.finish_attempt
public static function finish_attempt($lessonid, $password = '', $outoftime = false, $review = false) { $params = array('lessonid' => $lessonid, 'password' => $password, 'outoftime' => $outoftime, 'review' => $review); $params = self::validate_parameters(self::finish_attempt_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); // Update timer so the validation can check the time restrictions. $timer = $lesson->update_timer(); // Return the validation to avoid exceptions in case the user is out of time. $params['pageid'] = LESSON_EOL; $validation = self::validate_attempt($lesson, $params, true); if (array_key_exists('eolstudentoutoftime', $validation)) { // Maybe we run out of time just now. $params['outoftime'] = true; unset($validation['eolstudentoutoftime']); } // Check if there are more errors. if (!empty($validation)) { reset($validation); throw new moodle_exception(key($validation), 'lesson', '', current($validation)); // Throw first error. } // Set out of time to normal (it is the only existing mode). $outoftimemode = $params['outoftime'] ? 'normal' : ''; $result = $lesson->process_eol_page($outoftimemode); // Return the data. $validmessages = array( 'notenoughtimespent', 'numberofpagesviewed', 'youshouldview', 'numberofcorrectanswers', 'displayscorewithessays', 'displayscorewithoutessays', 'yourcurrentgradeisoutof', 'eolstudentoutoftimenoanswers', 'welldone', 'displayofgrade', 'modattemptsnoteacher', 'progresscompleted'); $data = array(); foreach ($result as $el => $value) { if ($value !== false) { $message = ''; if (in_array($el, $validmessages)) { // Check if the data comes with an informative message. $a = (is_bool($value)) ? null : $value; $message = get_string($el, 'lesson', $a); } // Return the data. $data[] = array( 'name' => $el, 'value' => (is_bool($value)) ? 1 : json_encode($value), // The data can be a php object. 'message' => $message ); } } $result = array( 'data' => $data, 'messages' => self::format_lesson_messages($lesson), 'warnings' => $warnings, ); return $result; }
php
public static function finish_attempt($lessonid, $password = '', $outoftime = false, $review = false) { $params = array('lessonid' => $lessonid, 'password' => $password, 'outoftime' => $outoftime, 'review' => $review); $params = self::validate_parameters(self::finish_attempt_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); // Update timer so the validation can check the time restrictions. $timer = $lesson->update_timer(); // Return the validation to avoid exceptions in case the user is out of time. $params['pageid'] = LESSON_EOL; $validation = self::validate_attempt($lesson, $params, true); if (array_key_exists('eolstudentoutoftime', $validation)) { // Maybe we run out of time just now. $params['outoftime'] = true; unset($validation['eolstudentoutoftime']); } // Check if there are more errors. if (!empty($validation)) { reset($validation); throw new moodle_exception(key($validation), 'lesson', '', current($validation)); // Throw first error. } // Set out of time to normal (it is the only existing mode). $outoftimemode = $params['outoftime'] ? 'normal' : ''; $result = $lesson->process_eol_page($outoftimemode); // Return the data. $validmessages = array( 'notenoughtimespent', 'numberofpagesviewed', 'youshouldview', 'numberofcorrectanswers', 'displayscorewithessays', 'displayscorewithoutessays', 'yourcurrentgradeisoutof', 'eolstudentoutoftimenoanswers', 'welldone', 'displayofgrade', 'modattemptsnoteacher', 'progresscompleted'); $data = array(); foreach ($result as $el => $value) { if ($value !== false) { $message = ''; if (in_array($el, $validmessages)) { // Check if the data comes with an informative message. $a = (is_bool($value)) ? null : $value; $message = get_string($el, 'lesson', $a); } // Return the data. $data[] = array( 'name' => $el, 'value' => (is_bool($value)) ? 1 : json_encode($value), // The data can be a php object. 'message' => $message ); } } $result = array( 'data' => $data, 'messages' => self::format_lesson_messages($lesson), 'warnings' => $warnings, ); return $result; }
[ "public", "static", "function", "finish_attempt", "(", "$", "lessonid", ",", "$", "password", "=", "''", ",", "$", "outoftime", "=", "false", ",", "$", "review", "=", "false", ")", "{", "$", "params", "=", "array", "(", "'lessonid'", "=>", "$", "lessonid", ",", "'password'", "=>", "$", "password", ",", "'outoftime'", "=>", "$", "outoftime", ",", "'review'", "=>", "$", "review", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "finish_attempt_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "list", "(", "$", "lesson", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ",", "$", "lessonrecord", ")", "=", "self", "::", "validate_lesson", "(", "$", "params", "[", "'lessonid'", "]", ")", ";", "// Update timer so the validation can check the time restrictions.", "$", "timer", "=", "$", "lesson", "->", "update_timer", "(", ")", ";", "// Return the validation to avoid exceptions in case the user is out of time.", "$", "params", "[", "'pageid'", "]", "=", "LESSON_EOL", ";", "$", "validation", "=", "self", "::", "validate_attempt", "(", "$", "lesson", ",", "$", "params", ",", "true", ")", ";", "if", "(", "array_key_exists", "(", "'eolstudentoutoftime'", ",", "$", "validation", ")", ")", "{", "// Maybe we run out of time just now.", "$", "params", "[", "'outoftime'", "]", "=", "true", ";", "unset", "(", "$", "validation", "[", "'eolstudentoutoftime'", "]", ")", ";", "}", "// Check if there are more errors.", "if", "(", "!", "empty", "(", "$", "validation", ")", ")", "{", "reset", "(", "$", "validation", ")", ";", "throw", "new", "moodle_exception", "(", "key", "(", "$", "validation", ")", ",", "'lesson'", ",", "''", ",", "current", "(", "$", "validation", ")", ")", ";", "// Throw first error.", "}", "// Set out of time to normal (it is the only existing mode).", "$", "outoftimemode", "=", "$", "params", "[", "'outoftime'", "]", "?", "'normal'", ":", "''", ";", "$", "result", "=", "$", "lesson", "->", "process_eol_page", "(", "$", "outoftimemode", ")", ";", "// Return the data.", "$", "validmessages", "=", "array", "(", "'notenoughtimespent'", ",", "'numberofpagesviewed'", ",", "'youshouldview'", ",", "'numberofcorrectanswers'", ",", "'displayscorewithessays'", ",", "'displayscorewithoutessays'", ",", "'yourcurrentgradeisoutof'", ",", "'eolstudentoutoftimenoanswers'", ",", "'welldone'", ",", "'displayofgrade'", ",", "'modattemptsnoteacher'", ",", "'progresscompleted'", ")", ";", "$", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "result", "as", "$", "el", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "!==", "false", ")", "{", "$", "message", "=", "''", ";", "if", "(", "in_array", "(", "$", "el", ",", "$", "validmessages", ")", ")", "{", "// Check if the data comes with an informative message.", "$", "a", "=", "(", "is_bool", "(", "$", "value", ")", ")", "?", "null", ":", "$", "value", ";", "$", "message", "=", "get_string", "(", "$", "el", ",", "'lesson'", ",", "$", "a", ")", ";", "}", "// Return the data.", "$", "data", "[", "]", "=", "array", "(", "'name'", "=>", "$", "el", ",", "'value'", "=>", "(", "is_bool", "(", "$", "value", ")", ")", "?", "1", ":", "json_encode", "(", "$", "value", ")", ",", "// The data can be a php object.", "'message'", "=>", "$", "message", ")", ";", "}", "}", "$", "result", "=", "array", "(", "'data'", "=>", "$", "data", ",", "'messages'", "=>", "self", "::", "format_lesson_messages", "(", "$", "lesson", ")", ",", "'warnings'", "=>", "$", "warnings", ",", ")", ";", "return", "$", "result", ";", "}" ]
Finishes the current attempt. @param int $lessonid lesson instance id @param string $password optional password (the lesson may be protected) @param bool $outoftime optional if the user run out of time @param bool $review if we want to review just after finishing (1 hour margin) @return array of warnings and information about the finished attempt @since Moodle 3.3 @throws moodle_exception
[ "Finishes", "the", "current", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1574-L1634
215,650
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.finish_attempt_returns
public static function finish_attempt_returns() { return new external_single_structure( array( 'data' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'Data name.'), 'value' => new external_value(PARAM_RAW, 'Data value.'), 'message' => new external_value(PARAM_RAW, 'Data message (translated string).'), ) ), 'The EOL page information data.' ), 'messages' => self::external_messages(), 'warnings' => new external_warnings(), ) ); }
php
public static function finish_attempt_returns() { return new external_single_structure( array( 'data' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'Data name.'), 'value' => new external_value(PARAM_RAW, 'Data value.'), 'message' => new external_value(PARAM_RAW, 'Data message (translated string).'), ) ), 'The EOL page information data.' ), 'messages' => self::external_messages(), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "finish_attempt_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'data'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'name'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'Data name.'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Data value.'", ")", ",", "'message'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Data message (translated string).'", ")", ",", ")", ")", ",", "'The EOL page information data.'", ")", ",", "'messages'", "=>", "self", "::", "external_messages", "(", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the finish_attempt return value. @return external_single_structure @since Moodle 3.3
[ "Describes", "the", "finish_attempt", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1642-L1658
215,651
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_attempts_overview
public static function get_attempts_overview($lessonid, $groupid = 0) { $params = array('lessonid' => $lessonid, 'groupid' => $groupid); $params = self::validate_parameters(self::get_attempts_overview_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); require_capability('mod/lesson:viewreports', $context); if (!empty($params['groupid'])) { $groupid = $params['groupid']; // Determine is the group is visible to user. if (!groups_group_visible($groupid, $course, $cm)) { throw new moodle_exception('notingroup'); } } else { // Check to see if groups are being used here. if ($groupmode = groups_get_activity_groupmode($cm)) { $groupid = groups_get_activity_group($cm); // Determine is the group is visible to user (this is particullary for the group 0 -> all groups). if (!groups_group_visible($groupid, $course, $cm)) { throw new moodle_exception('notingroup'); } } else { $groupid = 0; } } $result = array( 'warnings' => $warnings ); list($table, $data) = lesson_get_overview_report_table_and_data($lesson, $groupid); if ($data !== false) { $result['data'] = $data; } return $result; }
php
public static function get_attempts_overview($lessonid, $groupid = 0) { $params = array('lessonid' => $lessonid, 'groupid' => $groupid); $params = self::validate_parameters(self::get_attempts_overview_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); require_capability('mod/lesson:viewreports', $context); if (!empty($params['groupid'])) { $groupid = $params['groupid']; // Determine is the group is visible to user. if (!groups_group_visible($groupid, $course, $cm)) { throw new moodle_exception('notingroup'); } } else { // Check to see if groups are being used here. if ($groupmode = groups_get_activity_groupmode($cm)) { $groupid = groups_get_activity_group($cm); // Determine is the group is visible to user (this is particullary for the group 0 -> all groups). if (!groups_group_visible($groupid, $course, $cm)) { throw new moodle_exception('notingroup'); } } else { $groupid = 0; } } $result = array( 'warnings' => $warnings ); list($table, $data) = lesson_get_overview_report_table_and_data($lesson, $groupid); if ($data !== false) { $result['data'] = $data; } return $result; }
[ "public", "static", "function", "get_attempts_overview", "(", "$", "lessonid", ",", "$", "groupid", "=", "0", ")", "{", "$", "params", "=", "array", "(", "'lessonid'", "=>", "$", "lessonid", ",", "'groupid'", "=>", "$", "groupid", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_attempts_overview_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "list", "(", "$", "lesson", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ",", "$", "lessonrecord", ")", "=", "self", "::", "validate_lesson", "(", "$", "params", "[", "'lessonid'", "]", ")", ";", "require_capability", "(", "'mod/lesson:viewreports'", ",", "$", "context", ")", ";", "if", "(", "!", "empty", "(", "$", "params", "[", "'groupid'", "]", ")", ")", "{", "$", "groupid", "=", "$", "params", "[", "'groupid'", "]", ";", "// Determine is the group is visible to user.", "if", "(", "!", "groups_group_visible", "(", "$", "groupid", ",", "$", "course", ",", "$", "cm", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'notingroup'", ")", ";", "}", "}", "else", "{", "// Check to see if groups are being used here.", "if", "(", "$", "groupmode", "=", "groups_get_activity_groupmode", "(", "$", "cm", ")", ")", "{", "$", "groupid", "=", "groups_get_activity_group", "(", "$", "cm", ")", ";", "// Determine is the group is visible to user (this is particullary for the group 0 -> all groups).", "if", "(", "!", "groups_group_visible", "(", "$", "groupid", ",", "$", "course", ",", "$", "cm", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'notingroup'", ")", ";", "}", "}", "else", "{", "$", "groupid", "=", "0", ";", "}", "}", "$", "result", "=", "array", "(", "'warnings'", "=>", "$", "warnings", ")", ";", "list", "(", "$", "table", ",", "$", "data", ")", "=", "lesson_get_overview_report_table_and_data", "(", "$", "lesson", ",", "$", "groupid", ")", ";", "if", "(", "$", "data", "!==", "false", ")", "{", "$", "result", "[", "'data'", "]", "=", "$", "data", ";", "}", "return", "$", "result", ";", "}" ]
Get a list of all the attempts made by users in a lesson. @param int $lessonid lesson instance id @param int $groupid group id, 0 means that the function will determine the user group @return array of warnings and status result @since Moodle 3.3 @throws moodle_exception
[ "Get", "a", "list", "of", "all", "the", "attempts", "made", "by", "users", "in", "a", "lesson", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1685-L1723
215,652
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_attempts_overview_returns
public static function get_attempts_overview_returns() { return new external_single_structure( array( 'data' => new external_single_structure( array( 'lessonscored' => new external_value(PARAM_BOOL, 'True if the lesson was scored.'), 'numofattempts' => new external_value(PARAM_INT, 'Number of attempts.'), 'avescore' => new external_value(PARAM_FLOAT, 'Average score.'), 'highscore' => new external_value(PARAM_FLOAT, 'High score.'), 'lowscore' => new external_value(PARAM_FLOAT, 'Low score.'), 'avetime' => new external_value(PARAM_INT, 'Average time (spent in taking the lesson).'), 'hightime' => new external_value(PARAM_INT, 'High time.'), 'lowtime' => new external_value(PARAM_INT, 'Low time.'), 'students' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'User id.'), 'fullname' => new external_value(PARAM_TEXT, 'User full name.'), 'bestgrade' => new external_value(PARAM_FLOAT, 'Best grade.'), 'attempts' => new external_multiple_structure( new external_single_structure( array( 'try' => new external_value(PARAM_INT, 'Attempt number.'), 'grade' => new external_value(PARAM_FLOAT, 'Attempt grade.'), 'timestart' => new external_value(PARAM_INT, 'Attempt time started.'), 'timeend' => new external_value(PARAM_INT, 'Attempt last time continued.'), 'end' => new external_value(PARAM_INT, 'Attempt time ended.'), ) ) ) ) ), 'Students data, including attempts.', VALUE_OPTIONAL ), ), 'Attempts overview data (empty for no attemps).', VALUE_OPTIONAL ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_attempts_overview_returns() { return new external_single_structure( array( 'data' => new external_single_structure( array( 'lessonscored' => new external_value(PARAM_BOOL, 'True if the lesson was scored.'), 'numofattempts' => new external_value(PARAM_INT, 'Number of attempts.'), 'avescore' => new external_value(PARAM_FLOAT, 'Average score.'), 'highscore' => new external_value(PARAM_FLOAT, 'High score.'), 'lowscore' => new external_value(PARAM_FLOAT, 'Low score.'), 'avetime' => new external_value(PARAM_INT, 'Average time (spent in taking the lesson).'), 'hightime' => new external_value(PARAM_INT, 'High time.'), 'lowtime' => new external_value(PARAM_INT, 'Low time.'), 'students' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'User id.'), 'fullname' => new external_value(PARAM_TEXT, 'User full name.'), 'bestgrade' => new external_value(PARAM_FLOAT, 'Best grade.'), 'attempts' => new external_multiple_structure( new external_single_structure( array( 'try' => new external_value(PARAM_INT, 'Attempt number.'), 'grade' => new external_value(PARAM_FLOAT, 'Attempt grade.'), 'timestart' => new external_value(PARAM_INT, 'Attempt time started.'), 'timeend' => new external_value(PARAM_INT, 'Attempt last time continued.'), 'end' => new external_value(PARAM_INT, 'Attempt time ended.'), ) ) ) ) ), 'Students data, including attempts.', VALUE_OPTIONAL ), ), 'Attempts overview data (empty for no attemps).', VALUE_OPTIONAL ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_attempts_overview_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'data'", "=>", "new", "external_single_structure", "(", "array", "(", "'lessonscored'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'True if the lesson was scored.'", ")", ",", "'numofattempts'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Number of attempts.'", ")", ",", "'avescore'", "=>", "new", "external_value", "(", "PARAM_FLOAT", ",", "'Average score.'", ")", ",", "'highscore'", "=>", "new", "external_value", "(", "PARAM_FLOAT", ",", "'High score.'", ")", ",", "'lowscore'", "=>", "new", "external_value", "(", "PARAM_FLOAT", ",", "'Low score.'", ")", ",", "'avetime'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Average time (spent in taking the lesson).'", ")", ",", "'hightime'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'High time.'", ")", ",", "'lowtime'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Low time.'", ")", ",", "'students'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User id.'", ")", ",", "'fullname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'User full name.'", ")", ",", "'bestgrade'", "=>", "new", "external_value", "(", "PARAM_FLOAT", ",", "'Best grade.'", ")", ",", "'attempts'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'try'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Attempt number.'", ")", ",", "'grade'", "=>", "new", "external_value", "(", "PARAM_FLOAT", ",", "'Attempt grade.'", ")", ",", "'timestart'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Attempt time started.'", ")", ",", "'timeend'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Attempt last time continued.'", ")", ",", "'end'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Attempt time ended.'", ")", ",", ")", ")", ")", ")", ")", ",", "'Students data, including attempts.'", ",", "VALUE_OPTIONAL", ")", ",", ")", ",", "'Attempts overview data (empty for no attemps).'", ",", "VALUE_OPTIONAL", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_attempts_overview return value. @return external_single_structure @since Moodle 3.3
[ "Describes", "the", "get_attempts_overview", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1731-L1770
215,653
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_user_attempt_returns
public static function get_user_attempt_returns() { return new external_single_structure( array( 'answerpages' => new external_multiple_structure( new external_single_structure( array( 'page' => self::get_page_structure(VALUE_OPTIONAL), 'title' => new external_value(PARAM_RAW, 'Page title.'), 'contents' => new external_value(PARAM_RAW, 'Page contents.'), 'qtype' => new external_value(PARAM_TEXT, 'Identifies the page type of this page.'), 'grayout' => new external_value(PARAM_INT, 'If is required to apply a grayout.'), 'answerdata' => new external_single_structure( array( 'score' => new external_value(PARAM_TEXT, 'The score (text version).'), 'response' => new external_value(PARAM_RAW, 'The response text.'), 'responseformat' => new external_format_value('response.'), 'answers' => new external_multiple_structure( new external_multiple_structure(new external_value(PARAM_RAW, 'Possible answers and info.')), 'User answers', VALUE_OPTIONAL ), ), 'Answer data (empty in content pages created in Moodle 1.x).', VALUE_OPTIONAL ) ) ) ), 'userstats' => new external_single_structure( array( 'grade' => new external_value(PARAM_FLOAT, 'Attempt final grade.'), 'completed' => new external_value(PARAM_INT, 'Time completed.'), 'timetotake' => new external_value(PARAM_INT, 'Time taken.'), 'gradeinfo' => self::get_user_attempt_grade_structure(VALUE_OPTIONAL) ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_user_attempt_returns() { return new external_single_structure( array( 'answerpages' => new external_multiple_structure( new external_single_structure( array( 'page' => self::get_page_structure(VALUE_OPTIONAL), 'title' => new external_value(PARAM_RAW, 'Page title.'), 'contents' => new external_value(PARAM_RAW, 'Page contents.'), 'qtype' => new external_value(PARAM_TEXT, 'Identifies the page type of this page.'), 'grayout' => new external_value(PARAM_INT, 'If is required to apply a grayout.'), 'answerdata' => new external_single_structure( array( 'score' => new external_value(PARAM_TEXT, 'The score (text version).'), 'response' => new external_value(PARAM_RAW, 'The response text.'), 'responseformat' => new external_format_value('response.'), 'answers' => new external_multiple_structure( new external_multiple_structure(new external_value(PARAM_RAW, 'Possible answers and info.')), 'User answers', VALUE_OPTIONAL ), ), 'Answer data (empty in content pages created in Moodle 1.x).', VALUE_OPTIONAL ) ) ) ), 'userstats' => new external_single_structure( array( 'grade' => new external_value(PARAM_FLOAT, 'Attempt final grade.'), 'completed' => new external_value(PARAM_INT, 'Time completed.'), 'timetotake' => new external_value(PARAM_INT, 'Time taken.'), 'gradeinfo' => self::get_user_attempt_grade_structure(VALUE_OPTIONAL) ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_user_attempt_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'answerpages'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'page'", "=>", "self", "::", "get_page_structure", "(", "VALUE_OPTIONAL", ")", ",", "'title'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Page title.'", ")", ",", "'contents'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Page contents.'", ")", ",", "'qtype'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Identifies the page type of this page.'", ")", ",", "'grayout'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'If is required to apply a grayout.'", ")", ",", "'answerdata'", "=>", "new", "external_single_structure", "(", "array", "(", "'score'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'The score (text version).'", ")", ",", "'response'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The response text.'", ")", ",", "'responseformat'", "=>", "new", "external_format_value", "(", "'response.'", ")", ",", "'answers'", "=>", "new", "external_multiple_structure", "(", "new", "external_multiple_structure", "(", "new", "external_value", "(", "PARAM_RAW", ",", "'Possible answers and info.'", ")", ")", ",", "'User answers'", ",", "VALUE_OPTIONAL", ")", ",", ")", ",", "'Answer data (empty in content pages created in Moodle 1.x).'", ",", "VALUE_OPTIONAL", ")", ")", ")", ")", ",", "'userstats'", "=>", "new", "external_single_structure", "(", "array", "(", "'grade'", "=>", "new", "external_value", "(", "PARAM_FLOAT", ",", "'Attempt final grade.'", ")", ",", "'completed'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time completed.'", ")", ",", "'timetotake'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time taken.'", ")", ",", "'gradeinfo'", "=>", "self", "::", "get_user_attempt_grade_structure", "(", "VALUE_OPTIONAL", ")", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_user_attempt return value. @return external_single_structure @since Moodle 3.3
[ "Describes", "the", "get_user_attempt", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1841-L1878
215,654
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_pages_possible_jumps
public static function get_pages_possible_jumps($lessonid) { global $USER; $params = array('lessonid' => $lessonid); $params = self::validate_parameters(self::get_pages_possible_jumps_parameters(), $params); $warnings = $jumps = array(); list($lesson, $course, $cm, $context) = self::validate_lesson($params['lessonid']); // Only return for managers or if offline attempts are enabled. if ($lesson->can_manage() || $lesson->allowofflineattempts) { $lessonpages = $lesson->load_all_pages(); foreach ($lessonpages as $page) { $jump = array(); $jump['pageid'] = $page->id; $answers = $page->get_answers(); if (count($answers) > 0) { foreach ($answers as $answer) { $jump['answerid'] = $answer->id; $jump['jumpto'] = $answer->jumpto; $jump['calculatedjump'] = $lesson->calculate_new_page_on_jump($page, $answer->jumpto); // Special case, only applies to branch/end of branch. if ($jump['calculatedjump'] == LESSON_RANDOMBRANCH) { $jump['calculatedjump'] = lesson_unseen_branch_jump($lesson, $USER->id); } $jumps[] = $jump; } } else { // Imported lessons from 1.x. $jump['answerid'] = 0; $jump['jumpto'] = $page->nextpageid; $jump['calculatedjump'] = $lesson->calculate_new_page_on_jump($page, $page->nextpageid); $jumps[] = $jump; } } } $result = array( 'jumps' => $jumps, 'warnings' => $warnings, ); return $result; }
php
public static function get_pages_possible_jumps($lessonid) { global $USER; $params = array('lessonid' => $lessonid); $params = self::validate_parameters(self::get_pages_possible_jumps_parameters(), $params); $warnings = $jumps = array(); list($lesson, $course, $cm, $context) = self::validate_lesson($params['lessonid']); // Only return for managers or if offline attempts are enabled. if ($lesson->can_manage() || $lesson->allowofflineattempts) { $lessonpages = $lesson->load_all_pages(); foreach ($lessonpages as $page) { $jump = array(); $jump['pageid'] = $page->id; $answers = $page->get_answers(); if (count($answers) > 0) { foreach ($answers as $answer) { $jump['answerid'] = $answer->id; $jump['jumpto'] = $answer->jumpto; $jump['calculatedjump'] = $lesson->calculate_new_page_on_jump($page, $answer->jumpto); // Special case, only applies to branch/end of branch. if ($jump['calculatedjump'] == LESSON_RANDOMBRANCH) { $jump['calculatedjump'] = lesson_unseen_branch_jump($lesson, $USER->id); } $jumps[] = $jump; } } else { // Imported lessons from 1.x. $jump['answerid'] = 0; $jump['jumpto'] = $page->nextpageid; $jump['calculatedjump'] = $lesson->calculate_new_page_on_jump($page, $page->nextpageid); $jumps[] = $jump; } } } $result = array( 'jumps' => $jumps, 'warnings' => $warnings, ); return $result; }
[ "public", "static", "function", "get_pages_possible_jumps", "(", "$", "lessonid", ")", "{", "global", "$", "USER", ";", "$", "params", "=", "array", "(", "'lessonid'", "=>", "$", "lessonid", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_pages_possible_jumps_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "warnings", "=", "$", "jumps", "=", "array", "(", ")", ";", "list", "(", "$", "lesson", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_lesson", "(", "$", "params", "[", "'lessonid'", "]", ")", ";", "// Only return for managers or if offline attempts are enabled.", "if", "(", "$", "lesson", "->", "can_manage", "(", ")", "||", "$", "lesson", "->", "allowofflineattempts", ")", "{", "$", "lessonpages", "=", "$", "lesson", "->", "load_all_pages", "(", ")", ";", "foreach", "(", "$", "lessonpages", "as", "$", "page", ")", "{", "$", "jump", "=", "array", "(", ")", ";", "$", "jump", "[", "'pageid'", "]", "=", "$", "page", "->", "id", ";", "$", "answers", "=", "$", "page", "->", "get_answers", "(", ")", ";", "if", "(", "count", "(", "$", "answers", ")", ">", "0", ")", "{", "foreach", "(", "$", "answers", "as", "$", "answer", ")", "{", "$", "jump", "[", "'answerid'", "]", "=", "$", "answer", "->", "id", ";", "$", "jump", "[", "'jumpto'", "]", "=", "$", "answer", "->", "jumpto", ";", "$", "jump", "[", "'calculatedjump'", "]", "=", "$", "lesson", "->", "calculate_new_page_on_jump", "(", "$", "page", ",", "$", "answer", "->", "jumpto", ")", ";", "// Special case, only applies to branch/end of branch.", "if", "(", "$", "jump", "[", "'calculatedjump'", "]", "==", "LESSON_RANDOMBRANCH", ")", "{", "$", "jump", "[", "'calculatedjump'", "]", "=", "lesson_unseen_branch_jump", "(", "$", "lesson", ",", "$", "USER", "->", "id", ")", ";", "}", "$", "jumps", "[", "]", "=", "$", "jump", ";", "}", "}", "else", "{", "// Imported lessons from 1.x.", "$", "jump", "[", "'answerid'", "]", "=", "0", ";", "$", "jump", "[", "'jumpto'", "]", "=", "$", "page", "->", "nextpageid", ";", "$", "jump", "[", "'calculatedjump'", "]", "=", "$", "lesson", "->", "calculate_new_page_on_jump", "(", "$", "page", ",", "$", "page", "->", "nextpageid", ")", ";", "$", "jumps", "[", "]", "=", "$", "jump", ";", "}", "}", "}", "$", "result", "=", "array", "(", "'jumps'", "=>", "$", "jumps", ",", "'warnings'", "=>", "$", "warnings", ",", ")", ";", "return", "$", "result", ";", "}" ]
Return all the possible jumps for the pages in a given lesson. You may expect different results on consecutive executions due to the random nature of the lesson module. @param int $lessonid lesson instance id @return array of warnings and possible jumps @since Moodle 3.3 @throws moodle_exception
[ "Return", "all", "the", "possible", "jumps", "for", "the", "pages", "in", "a", "given", "lesson", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1904-L1949
215,655
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_pages_possible_jumps_returns
public static function get_pages_possible_jumps_returns() { return new external_single_structure( array( 'jumps' => new external_multiple_structure( new external_single_structure( array( 'pageid' => new external_value(PARAM_INT, 'The page id'), 'answerid' => new external_value(PARAM_INT, 'The answer id'), 'jumpto' => new external_value(PARAM_INT, 'The jump (page id or type of jump)'), 'calculatedjump' => new external_value(PARAM_INT, 'The real page id (or EOL) to jump'), ), 'Jump for a page answer' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_pages_possible_jumps_returns() { return new external_single_structure( array( 'jumps' => new external_multiple_structure( new external_single_structure( array( 'pageid' => new external_value(PARAM_INT, 'The page id'), 'answerid' => new external_value(PARAM_INT, 'The answer id'), 'jumpto' => new external_value(PARAM_INT, 'The jump (page id or type of jump)'), 'calculatedjump' => new external_value(PARAM_INT, 'The real page id (or EOL) to jump'), ), 'Jump for a page answer' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_pages_possible_jumps_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'jumps'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'pageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The page id'", ")", ",", "'answerid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The answer id'", ")", ",", "'jumpto'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The jump (page id or type of jump)'", ")", ",", "'calculatedjump'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The real page id (or EOL) to jump'", ")", ",", ")", ",", "'Jump for a page answer'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_pages_possible_jumps return value. @return external_single_structure @since Moodle 3.3
[ "Describes", "the", "get_pages_possible_jumps", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1957-L1973
215,656
moodle/moodle
mod/lesson/classes/external.php
mod_lesson_external.get_lesson
public static function get_lesson($lessonid, $password = '') { global $PAGE; $params = array('lessonid' => $lessonid, 'password' => $password); $params = self::validate_parameters(self::get_lesson_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); $lessonrecord = self::get_lesson_summary_for_exporter($lessonrecord, $params['password']); $exporter = new lesson_summary_exporter($lessonrecord, array('context' => $context)); $result = array(); $result['lesson'] = $exporter->export($PAGE->get_renderer('core')); $result['warnings'] = $warnings; return $result; }
php
public static function get_lesson($lessonid, $password = '') { global $PAGE; $params = array('lessonid' => $lessonid, 'password' => $password); $params = self::validate_parameters(self::get_lesson_parameters(), $params); $warnings = array(); list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']); $lessonrecord = self::get_lesson_summary_for_exporter($lessonrecord, $params['password']); $exporter = new lesson_summary_exporter($lessonrecord, array('context' => $context)); $result = array(); $result['lesson'] = $exporter->export($PAGE->get_renderer('core')); $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_lesson", "(", "$", "lessonid", ",", "$", "password", "=", "''", ")", "{", "global", "$", "PAGE", ";", "$", "params", "=", "array", "(", "'lessonid'", "=>", "$", "lessonid", ",", "'password'", "=>", "$", "password", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_lesson_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "list", "(", "$", "lesson", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ",", "$", "lessonrecord", ")", "=", "self", "::", "validate_lesson", "(", "$", "params", "[", "'lessonid'", "]", ")", ";", "$", "lessonrecord", "=", "self", "::", "get_lesson_summary_for_exporter", "(", "$", "lessonrecord", ",", "$", "params", "[", "'password'", "]", ")", ";", "$", "exporter", "=", "new", "lesson_summary_exporter", "(", "$", "lessonrecord", ",", "array", "(", "'context'", "=>", "$", "context", ")", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'lesson'", "]", "=", "$", "exporter", "->", "export", "(", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ")", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Return information of a given lesson. @param int $lessonid lesson instance id @param string $password optional password (the lesson may be protected) @return array of warnings and status result @since Moodle 3.3 @throws moodle_exception
[ "Return", "information", "of", "a", "given", "lesson", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/classes/external.php#L1999-L2015
215,657
moodle/moodle
question/type/randomsamatch/backup/moodle2/restore_qtype_randomsamatch_plugin.class.php
restore_qtype_randomsamatch_plugin.recode_legacy_state_answer
public function recode_legacy_state_answer($state) { $answer = $state->answer; $resultarr = array(); foreach (explode(',', $answer) as $pair) { $pairarr = explode('-', $pair); $questionid = $pairarr[0]; $answerid = $pairarr[1]; $newquestionid = $questionid ? $this->get_mappingid('question', $questionid) : 0; $newanswerid = $answerid ? $this->get_mappingid('question_answer', $answerid) : 0; $resultarr[] = implode('-', array($newquestionid, $newanswerid)); } return implode(',', $resultarr); }
php
public function recode_legacy_state_answer($state) { $answer = $state->answer; $resultarr = array(); foreach (explode(',', $answer) as $pair) { $pairarr = explode('-', $pair); $questionid = $pairarr[0]; $answerid = $pairarr[1]; $newquestionid = $questionid ? $this->get_mappingid('question', $questionid) : 0; $newanswerid = $answerid ? $this->get_mappingid('question_answer', $answerid) : 0; $resultarr[] = implode('-', array($newquestionid, $newanswerid)); } return implode(',', $resultarr); }
[ "public", "function", "recode_legacy_state_answer", "(", "$", "state", ")", "{", "$", "answer", "=", "$", "state", "->", "answer", ";", "$", "resultarr", "=", "array", "(", ")", ";", "foreach", "(", "explode", "(", "','", ",", "$", "answer", ")", "as", "$", "pair", ")", "{", "$", "pairarr", "=", "explode", "(", "'-'", ",", "$", "pair", ")", ";", "$", "questionid", "=", "$", "pairarr", "[", "0", "]", ";", "$", "answerid", "=", "$", "pairarr", "[", "1", "]", ";", "$", "newquestionid", "=", "$", "questionid", "?", "$", "this", "->", "get_mappingid", "(", "'question'", ",", "$", "questionid", ")", ":", "0", ";", "$", "newanswerid", "=", "$", "answerid", "?", "$", "this", "->", "get_mappingid", "(", "'question_answer'", ",", "$", "answerid", ")", ":", "0", ";", "$", "resultarr", "[", "]", "=", "implode", "(", "'-'", ",", "array", "(", "$", "newquestionid", ",", "$", "newanswerid", ")", ")", ";", "}", "return", "implode", "(", "','", ",", "$", "resultarr", ")", ";", "}" ]
Given one question_states record, return the answer recoded pointing to all the restored stuff for randomsamatch questions answer is one comma separated list of hypen separated pairs containing question->id and question_answers->id
[ "Given", "one", "question_states", "record", "return", "the", "answer", "recoded", "pointing", "to", "all", "the", "restored", "stuff", "for", "randomsamatch", "questions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/randomsamatch/backup/moodle2/restore_qtype_randomsamatch_plugin.class.php#L107-L119
215,658
moodle/moodle
mod/workshop/classes/portfolio_caller.php
mod_workshop_portfolio_caller.load_data
public function load_data() { global $DB, $USER; // Note that require_login() is normally called later as a part of // portfolio_export_pagesetup() in the portfolio/add.php file. But we // load various data depending of capabilities so it makes sense to // call it explicitly here, too. require_login($this->get('course'), false, $this->cm, false, true); if (isguestuser()) { throw new portfolio_caller_exception('guestsarenotallowed', 'core_error'); } $workshoprecord = $DB->get_record('workshop', ['id' => $this->cm->instance], '*', MUST_EXIST); $this->workshop = new workshop($workshoprecord, $this->cm, $this->get('course')); $this->submission = $this->workshop->get_submission_by_id($this->submissionid); // Is the user exporting her/his own submission? $ownsubmission = $this->submission->authorid == $USER->id; // Does the user have permission to see all submissions (aka is it a teacher)? $canviewallsubmissions = has_capability('mod/workshop:viewallsubmissions', $this->workshop->context); $canviewallsubmissions = $canviewallsubmissions && $this->workshop->check_group_membership($this->submission->authorid); // Is the user exporting a submission that she/he has peer-assessed? $userassessment = $this->workshop->get_assessment_of_submission_by_user($this->submission->id, $USER->id); if ($userassessment) { $this->assessments[$userassessment->id] = $userassessment; $isreviewer = true; } if (!$ownsubmission and !$canviewallsubmissions and !$isreviewer) { throw new portfolio_caller_exception('nopermissions', 'core_error'); } // Does the user have permission to see all assessments (aka is it a teacher)? $canviewallassessments = has_capability('mod/workshop:viewallassessments', $this->workshop->context); // Load other assessments eventually if the user can see them. if ($canviewallassessments or ($ownsubmission and $this->workshop->assessments_available())) { foreach ($this->workshop->get_assessments_of_submission($this->submission->id) as $assessment) { if ($assessment->reviewerid == $USER->id) { // User's own assessment is already loaded. continue; } if (is_null($assessment->grade) and !$canviewallassessments) { // Students do not see peer-assessment that are not graded. continue; } $this->assessments[$assessment->id] = $assessment; } } // Prepare embedded and attached files for the export. $this->multifiles = []; $this->add_area_files('submission_content', $this->submission->id); $this->add_area_files('submission_attachment', $this->submission->id); foreach ($this->assessments as $assessment) { $this->add_area_files('overallfeedback_content', $assessment->id); $this->add_area_files('overallfeedback_attachment', $assessment->id); } $this->add_area_files('instructauthors', 0); // If there are no files to be exported, we can offer plain HTML file export. if (empty($this->multifiles)) { $this->add_format(PORTFOLIO_FORMAT_PLAINHTML); } }
php
public function load_data() { global $DB, $USER; // Note that require_login() is normally called later as a part of // portfolio_export_pagesetup() in the portfolio/add.php file. But we // load various data depending of capabilities so it makes sense to // call it explicitly here, too. require_login($this->get('course'), false, $this->cm, false, true); if (isguestuser()) { throw new portfolio_caller_exception('guestsarenotallowed', 'core_error'); } $workshoprecord = $DB->get_record('workshop', ['id' => $this->cm->instance], '*', MUST_EXIST); $this->workshop = new workshop($workshoprecord, $this->cm, $this->get('course')); $this->submission = $this->workshop->get_submission_by_id($this->submissionid); // Is the user exporting her/his own submission? $ownsubmission = $this->submission->authorid == $USER->id; // Does the user have permission to see all submissions (aka is it a teacher)? $canviewallsubmissions = has_capability('mod/workshop:viewallsubmissions', $this->workshop->context); $canviewallsubmissions = $canviewallsubmissions && $this->workshop->check_group_membership($this->submission->authorid); // Is the user exporting a submission that she/he has peer-assessed? $userassessment = $this->workshop->get_assessment_of_submission_by_user($this->submission->id, $USER->id); if ($userassessment) { $this->assessments[$userassessment->id] = $userassessment; $isreviewer = true; } if (!$ownsubmission and !$canviewallsubmissions and !$isreviewer) { throw new portfolio_caller_exception('nopermissions', 'core_error'); } // Does the user have permission to see all assessments (aka is it a teacher)? $canviewallassessments = has_capability('mod/workshop:viewallassessments', $this->workshop->context); // Load other assessments eventually if the user can see them. if ($canviewallassessments or ($ownsubmission and $this->workshop->assessments_available())) { foreach ($this->workshop->get_assessments_of_submission($this->submission->id) as $assessment) { if ($assessment->reviewerid == $USER->id) { // User's own assessment is already loaded. continue; } if (is_null($assessment->grade) and !$canviewallassessments) { // Students do not see peer-assessment that are not graded. continue; } $this->assessments[$assessment->id] = $assessment; } } // Prepare embedded and attached files for the export. $this->multifiles = []; $this->add_area_files('submission_content', $this->submission->id); $this->add_area_files('submission_attachment', $this->submission->id); foreach ($this->assessments as $assessment) { $this->add_area_files('overallfeedback_content', $assessment->id); $this->add_area_files('overallfeedback_attachment', $assessment->id); } $this->add_area_files('instructauthors', 0); // If there are no files to be exported, we can offer plain HTML file export. if (empty($this->multifiles)) { $this->add_format(PORTFOLIO_FORMAT_PLAINHTML); } }
[ "public", "function", "load_data", "(", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "// Note that require_login() is normally called later as a part of", "// portfolio_export_pagesetup() in the portfolio/add.php file. But we", "// load various data depending of capabilities so it makes sense to", "// call it explicitly here, too.", "require_login", "(", "$", "this", "->", "get", "(", "'course'", ")", ",", "false", ",", "$", "this", "->", "cm", ",", "false", ",", "true", ")", ";", "if", "(", "isguestuser", "(", ")", ")", "{", "throw", "new", "portfolio_caller_exception", "(", "'guestsarenotallowed'", ",", "'core_error'", ")", ";", "}", "$", "workshoprecord", "=", "$", "DB", "->", "get_record", "(", "'workshop'", ",", "[", "'id'", "=>", "$", "this", "->", "cm", "->", "instance", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "this", "->", "workshop", "=", "new", "workshop", "(", "$", "workshoprecord", ",", "$", "this", "->", "cm", ",", "$", "this", "->", "get", "(", "'course'", ")", ")", ";", "$", "this", "->", "submission", "=", "$", "this", "->", "workshop", "->", "get_submission_by_id", "(", "$", "this", "->", "submissionid", ")", ";", "// Is the user exporting her/his own submission?", "$", "ownsubmission", "=", "$", "this", "->", "submission", "->", "authorid", "==", "$", "USER", "->", "id", ";", "// Does the user have permission to see all submissions (aka is it a teacher)?", "$", "canviewallsubmissions", "=", "has_capability", "(", "'mod/workshop:viewallsubmissions'", ",", "$", "this", "->", "workshop", "->", "context", ")", ";", "$", "canviewallsubmissions", "=", "$", "canviewallsubmissions", "&&", "$", "this", "->", "workshop", "->", "check_group_membership", "(", "$", "this", "->", "submission", "->", "authorid", ")", ";", "// Is the user exporting a submission that she/he has peer-assessed?", "$", "userassessment", "=", "$", "this", "->", "workshop", "->", "get_assessment_of_submission_by_user", "(", "$", "this", "->", "submission", "->", "id", ",", "$", "USER", "->", "id", ")", ";", "if", "(", "$", "userassessment", ")", "{", "$", "this", "->", "assessments", "[", "$", "userassessment", "->", "id", "]", "=", "$", "userassessment", ";", "$", "isreviewer", "=", "true", ";", "}", "if", "(", "!", "$", "ownsubmission", "and", "!", "$", "canviewallsubmissions", "and", "!", "$", "isreviewer", ")", "{", "throw", "new", "portfolio_caller_exception", "(", "'nopermissions'", ",", "'core_error'", ")", ";", "}", "// Does the user have permission to see all assessments (aka is it a teacher)?", "$", "canviewallassessments", "=", "has_capability", "(", "'mod/workshop:viewallassessments'", ",", "$", "this", "->", "workshop", "->", "context", ")", ";", "// Load other assessments eventually if the user can see them.", "if", "(", "$", "canviewallassessments", "or", "(", "$", "ownsubmission", "and", "$", "this", "->", "workshop", "->", "assessments_available", "(", ")", ")", ")", "{", "foreach", "(", "$", "this", "->", "workshop", "->", "get_assessments_of_submission", "(", "$", "this", "->", "submission", "->", "id", ")", "as", "$", "assessment", ")", "{", "if", "(", "$", "assessment", "->", "reviewerid", "==", "$", "USER", "->", "id", ")", "{", "// User's own assessment is already loaded.", "continue", ";", "}", "if", "(", "is_null", "(", "$", "assessment", "->", "grade", ")", "and", "!", "$", "canviewallassessments", ")", "{", "// Students do not see peer-assessment that are not graded.", "continue", ";", "}", "$", "this", "->", "assessments", "[", "$", "assessment", "->", "id", "]", "=", "$", "assessment", ";", "}", "}", "// Prepare embedded and attached files for the export.", "$", "this", "->", "multifiles", "=", "[", "]", ";", "$", "this", "->", "add_area_files", "(", "'submission_content'", ",", "$", "this", "->", "submission", "->", "id", ")", ";", "$", "this", "->", "add_area_files", "(", "'submission_attachment'", ",", "$", "this", "->", "submission", "->", "id", ")", ";", "foreach", "(", "$", "this", "->", "assessments", "as", "$", "assessment", ")", "{", "$", "this", "->", "add_area_files", "(", "'overallfeedback_content'", ",", "$", "assessment", "->", "id", ")", ";", "$", "this", "->", "add_area_files", "(", "'overallfeedback_attachment'", ",", "$", "assessment", "->", "id", ")", ";", "}", "$", "this", "->", "add_area_files", "(", "'instructauthors'", ",", "0", ")", ";", "// If there are no files to be exported, we can offer plain HTML file export.", "if", "(", "empty", "(", "$", "this", "->", "multifiles", ")", ")", "{", "$", "this", "->", "add_format", "(", "PORTFOLIO_FORMAT_PLAINHTML", ")", ";", "}", "}" ]
Load data required for the export.
[ "Load", "data", "required", "for", "the", "export", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/classes/portfolio_caller.php#L85-L156
215,659
moodle/moodle
mod/workshop/classes/portfolio_caller.php
mod_workshop_portfolio_caller.prepare_package
public function prepare_package() { $canviewauthornames = has_capability('mod/workshop:viewauthornames', $this->workshop->context, $this->get('user')); // Prepare the submission record for rendering. $workshopsubmission = $this->workshop->prepare_submission($this->submission, $canviewauthornames); // Set up the LEAP2A writer if we need it. $writingleap = false; if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) { $leapwriter = $this->exporter->get('format')->leap2a_writer(); $writingleap = true; } // If writing to HTML file, accumulate the exported hypertext here. $html = ''; // If writing LEAP2A, keep track of all entry ids so we can add a selection element. $leapids = []; $html .= $this->export_header($workshopsubmission); $content = $this->export_content($workshopsubmission); // Get rid of the JS relics left by moodleforms. $content = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content); $html .= $content; if ($writingleap) { $leapids[] = $this->export_content_leap2a($leapwriter, $workshopsubmission, $content); } // Export the files. foreach ($this->multifiles as $file) { $this->exporter->copy_existing_file($file); } if ($writingleap) { // Add an extra LEAP2A selection entry. In Mahara, this maps to a journal. $selection = new portfolio_format_leap2a_entry('workshop'.$this->workshop->id, get_string('pluginname', 'mod_workshop').': '.s($this->workshop->name), 'selection'); $leapwriter->add_entry($selection); $leapwriter->make_selection($selection, $leapids, 'Grouping'); $leapxml = $leapwriter->to_xml(); $name = $this->exporter->get('format')->manifest_name(); $this->exporter->write_new_file($leapxml, $name, true); } else { $this->exporter->write_new_file($html, 'submission.html', true); } }
php
public function prepare_package() { $canviewauthornames = has_capability('mod/workshop:viewauthornames', $this->workshop->context, $this->get('user')); // Prepare the submission record for rendering. $workshopsubmission = $this->workshop->prepare_submission($this->submission, $canviewauthornames); // Set up the LEAP2A writer if we need it. $writingleap = false; if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) { $leapwriter = $this->exporter->get('format')->leap2a_writer(); $writingleap = true; } // If writing to HTML file, accumulate the exported hypertext here. $html = ''; // If writing LEAP2A, keep track of all entry ids so we can add a selection element. $leapids = []; $html .= $this->export_header($workshopsubmission); $content = $this->export_content($workshopsubmission); // Get rid of the JS relics left by moodleforms. $content = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content); $html .= $content; if ($writingleap) { $leapids[] = $this->export_content_leap2a($leapwriter, $workshopsubmission, $content); } // Export the files. foreach ($this->multifiles as $file) { $this->exporter->copy_existing_file($file); } if ($writingleap) { // Add an extra LEAP2A selection entry. In Mahara, this maps to a journal. $selection = new portfolio_format_leap2a_entry('workshop'.$this->workshop->id, get_string('pluginname', 'mod_workshop').': '.s($this->workshop->name), 'selection'); $leapwriter->add_entry($selection); $leapwriter->make_selection($selection, $leapids, 'Grouping'); $leapxml = $leapwriter->to_xml(); $name = $this->exporter->get('format')->manifest_name(); $this->exporter->write_new_file($leapxml, $name, true); } else { $this->exporter->write_new_file($html, 'submission.html', true); } }
[ "public", "function", "prepare_package", "(", ")", "{", "$", "canviewauthornames", "=", "has_capability", "(", "'mod/workshop:viewauthornames'", ",", "$", "this", "->", "workshop", "->", "context", ",", "$", "this", "->", "get", "(", "'user'", ")", ")", ";", "// Prepare the submission record for rendering.", "$", "workshopsubmission", "=", "$", "this", "->", "workshop", "->", "prepare_submission", "(", "$", "this", "->", "submission", ",", "$", "canviewauthornames", ")", ";", "// Set up the LEAP2A writer if we need it.", "$", "writingleap", "=", "false", ";", "if", "(", "$", "this", "->", "exporter", "->", "get", "(", "'formatclass'", ")", "==", "PORTFOLIO_FORMAT_LEAP2A", ")", "{", "$", "leapwriter", "=", "$", "this", "->", "exporter", "->", "get", "(", "'format'", ")", "->", "leap2a_writer", "(", ")", ";", "$", "writingleap", "=", "true", ";", "}", "// If writing to HTML file, accumulate the exported hypertext here.", "$", "html", "=", "''", ";", "// If writing LEAP2A, keep track of all entry ids so we can add a selection element.", "$", "leapids", "=", "[", "]", ";", "$", "html", ".=", "$", "this", "->", "export_header", "(", "$", "workshopsubmission", ")", ";", "$", "content", "=", "$", "this", "->", "export_content", "(", "$", "workshopsubmission", ")", ";", "// Get rid of the JS relics left by moodleforms.", "$", "content", "=", "preg_replace", "(", "'#<script(.*?)>(.*?)</script>#is'", ",", "''", ",", "$", "content", ")", ";", "$", "html", ".=", "$", "content", ";", "if", "(", "$", "writingleap", ")", "{", "$", "leapids", "[", "]", "=", "$", "this", "->", "export_content_leap2a", "(", "$", "leapwriter", ",", "$", "workshopsubmission", ",", "$", "content", ")", ";", "}", "// Export the files.", "foreach", "(", "$", "this", "->", "multifiles", "as", "$", "file", ")", "{", "$", "this", "->", "exporter", "->", "copy_existing_file", "(", "$", "file", ")", ";", "}", "if", "(", "$", "writingleap", ")", "{", "// Add an extra LEAP2A selection entry. In Mahara, this maps to a journal.", "$", "selection", "=", "new", "portfolio_format_leap2a_entry", "(", "'workshop'", ".", "$", "this", "->", "workshop", "->", "id", ",", "get_string", "(", "'pluginname'", ",", "'mod_workshop'", ")", ".", "': '", ".", "s", "(", "$", "this", "->", "workshop", "->", "name", ")", ",", "'selection'", ")", ";", "$", "leapwriter", "->", "add_entry", "(", "$", "selection", ")", ";", "$", "leapwriter", "->", "make_selection", "(", "$", "selection", ",", "$", "leapids", ",", "'Grouping'", ")", ";", "$", "leapxml", "=", "$", "leapwriter", "->", "to_xml", "(", ")", ";", "$", "name", "=", "$", "this", "->", "exporter", "->", "get", "(", "'format'", ")", "->", "manifest_name", "(", ")", ";", "$", "this", "->", "exporter", "->", "write_new_file", "(", "$", "leapxml", ",", "$", "name", ",", "true", ")", ";", "}", "else", "{", "$", "this", "->", "exporter", "->", "write_new_file", "(", "$", "html", ",", "'submission.html'", ",", "true", ")", ";", "}", "}" ]
Prepare the package ready to be passed off to the portfolio plugin.
[ "Prepare", "the", "package", "ready", "to", "be", "passed", "off", "to", "the", "portfolio", "plugin", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/classes/portfolio_caller.php#L161-L210
215,660
moodle/moodle
mod/workshop/classes/portfolio_caller.php
mod_workshop_portfolio_caller.export_header
protected function export_header(workshop_submission $workshopsubmission) { $output = ''; $output .= html_writer::tag('h2', get_string('pluginname', 'mod_workshop').': '.s($this->workshop->name)); $output .= html_writer::tag('h3', s($workshopsubmission->title)); $created = get_string('userdatecreated', 'workshop', userdate($workshopsubmission->timecreated)); $created = html_writer::tag('span', $created); if ($workshopsubmission->timemodified > $workshopsubmission->timecreated) { $modified = get_string('userdatemodified', 'workshop', userdate($workshopsubmission->timemodified)); $modified = ' | ' . html_writer::tag('span', $modified); } else { $modified = ''; } $output .= html_writer::div($created.$modified); $output .= html_writer::empty_tag('br'); return $output; }
php
protected function export_header(workshop_submission $workshopsubmission) { $output = ''; $output .= html_writer::tag('h2', get_string('pluginname', 'mod_workshop').': '.s($this->workshop->name)); $output .= html_writer::tag('h3', s($workshopsubmission->title)); $created = get_string('userdatecreated', 'workshop', userdate($workshopsubmission->timecreated)); $created = html_writer::tag('span', $created); if ($workshopsubmission->timemodified > $workshopsubmission->timecreated) { $modified = get_string('userdatemodified', 'workshop', userdate($workshopsubmission->timemodified)); $modified = ' | ' . html_writer::tag('span', $modified); } else { $modified = ''; } $output .= html_writer::div($created.$modified); $output .= html_writer::empty_tag('br'); return $output; }
[ "protected", "function", "export_header", "(", "workshop_submission", "$", "workshopsubmission", ")", "{", "$", "output", "=", "''", ";", "$", "output", ".=", "html_writer", "::", "tag", "(", "'h2'", ",", "get_string", "(", "'pluginname'", ",", "'mod_workshop'", ")", ".", "': '", ".", "s", "(", "$", "this", "->", "workshop", "->", "name", ")", ")", ";", "$", "output", ".=", "html_writer", "::", "tag", "(", "'h3'", ",", "s", "(", "$", "workshopsubmission", "->", "title", ")", ")", ";", "$", "created", "=", "get_string", "(", "'userdatecreated'", ",", "'workshop'", ",", "userdate", "(", "$", "workshopsubmission", "->", "timecreated", ")", ")", ";", "$", "created", "=", "html_writer", "::", "tag", "(", "'span'", ",", "$", "created", ")", ";", "if", "(", "$", "workshopsubmission", "->", "timemodified", ">", "$", "workshopsubmission", "->", "timecreated", ")", "{", "$", "modified", "=", "get_string", "(", "'userdatemodified'", ",", "'workshop'", ",", "userdate", "(", "$", "workshopsubmission", "->", "timemodified", ")", ")", ";", "$", "modified", "=", "' | '", ".", "html_writer", "::", "tag", "(", "'span'", ",", "$", "modified", ")", ";", "}", "else", "{", "$", "modified", "=", "''", ";", "}", "$", "output", ".=", "html_writer", "::", "div", "(", "$", "created", ".", "$", "modified", ")", ";", "$", "output", ".=", "html_writer", "::", "empty_tag", "(", "'br'", ")", ";", "return", "$", "output", ";", "}" ]
Render the header of the exported content. This is mainly used for the HTML output format. In case of LEAP2A export, this is not used as the information is stored in metadata and displayed as a part of the journal and entry title in Mahara. @param workshop_submission $workshopsubmission @return string HTML
[ "Render", "the", "header", "of", "the", "exported", "content", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/classes/portfolio_caller.php#L237-L257
215,661
moodle/moodle
mod/workshop/classes/portfolio_caller.php
mod_workshop_portfolio_caller.export_content
protected function export_content(workshop_submission $workshopsubmission) { $output = ''; if (!$workshopsubmission->is_anonymous()) { $author = username_load_fields_from_object((object)[], $workshopsubmission, 'author'); $output .= html_writer::div(get_string('byfullnamewithoutlink', 'mod_workshop', fullname($author))); } $content = $this->format_exported_text($workshopsubmission->content, $workshopsubmission->contentformat); $content = portfolio_rewrite_pluginfile_urls($content, $this->workshop->context->id, 'mod_workshop', 'submission_content', $workshopsubmission->id, $this->exporter->get('format')); $output .= html_writer::div($content); $output .= $this->export_files_list('submission_attachment'); $strategy = $this->workshop->grading_strategy_instance(); $canviewauthornames = has_capability('mod/workshop:viewauthornames', $this->workshop->context, $this->get('user')); $canviewreviewernames = has_capability('mod/workshop:viewreviewernames', $this->workshop->context, $this->get('user')); foreach ($this->assessments as $assessment) { $mform = $strategy->get_assessment_form(null, 'assessment', $assessment, false); $options = [ 'showreviewer' => $canviewreviewernames, 'showauthor' => $canviewauthornames, 'showform' => true, 'showweight' => true, ]; if ($assessment->reviewerid == $this->get('user')->id) { $options['showreviewer'] = true; } $workshopassessment = $this->workshop->prepare_assessment($assessment, $mform, $options); if ($assessment->reviewerid == $this->get('user')->id) { $workshopassessment->title = get_string('assessmentbyyourself', 'mod_workshop'); } else { $workshopassessment->title = get_string('assessment', 'mod_workshop'); } $output .= html_writer::empty_tag('hr'); $output .= $this->export_assessment($workshopassessment); } if (trim($this->workshop->instructauthors)) { $output .= html_writer::tag('h3', get_string('instructauthors', 'mod_workshop')); $content = $this->format_exported_text($this->workshop->instructauthors, $this->workshop->instructauthorsformat); $content = portfolio_rewrite_pluginfile_urls($content, $this->workshop->context->id, 'mod_workshop', 'instructauthors', 0, $this->exporter->get('format')); $output .= $content; } return html_writer::div($output); }
php
protected function export_content(workshop_submission $workshopsubmission) { $output = ''; if (!$workshopsubmission->is_anonymous()) { $author = username_load_fields_from_object((object)[], $workshopsubmission, 'author'); $output .= html_writer::div(get_string('byfullnamewithoutlink', 'mod_workshop', fullname($author))); } $content = $this->format_exported_text($workshopsubmission->content, $workshopsubmission->contentformat); $content = portfolio_rewrite_pluginfile_urls($content, $this->workshop->context->id, 'mod_workshop', 'submission_content', $workshopsubmission->id, $this->exporter->get('format')); $output .= html_writer::div($content); $output .= $this->export_files_list('submission_attachment'); $strategy = $this->workshop->grading_strategy_instance(); $canviewauthornames = has_capability('mod/workshop:viewauthornames', $this->workshop->context, $this->get('user')); $canviewreviewernames = has_capability('mod/workshop:viewreviewernames', $this->workshop->context, $this->get('user')); foreach ($this->assessments as $assessment) { $mform = $strategy->get_assessment_form(null, 'assessment', $assessment, false); $options = [ 'showreviewer' => $canviewreviewernames, 'showauthor' => $canviewauthornames, 'showform' => true, 'showweight' => true, ]; if ($assessment->reviewerid == $this->get('user')->id) { $options['showreviewer'] = true; } $workshopassessment = $this->workshop->prepare_assessment($assessment, $mform, $options); if ($assessment->reviewerid == $this->get('user')->id) { $workshopassessment->title = get_string('assessmentbyyourself', 'mod_workshop'); } else { $workshopassessment->title = get_string('assessment', 'mod_workshop'); } $output .= html_writer::empty_tag('hr'); $output .= $this->export_assessment($workshopassessment); } if (trim($this->workshop->instructauthors)) { $output .= html_writer::tag('h3', get_string('instructauthors', 'mod_workshop')); $content = $this->format_exported_text($this->workshop->instructauthors, $this->workshop->instructauthorsformat); $content = portfolio_rewrite_pluginfile_urls($content, $this->workshop->context->id, 'mod_workshop', 'instructauthors', 0, $this->exporter->get('format')); $output .= $content; } return html_writer::div($output); }
[ "protected", "function", "export_content", "(", "workshop_submission", "$", "workshopsubmission", ")", "{", "$", "output", "=", "''", ";", "if", "(", "!", "$", "workshopsubmission", "->", "is_anonymous", "(", ")", ")", "{", "$", "author", "=", "username_load_fields_from_object", "(", "(", "object", ")", "[", "]", ",", "$", "workshopsubmission", ",", "'author'", ")", ";", "$", "output", ".=", "html_writer", "::", "div", "(", "get_string", "(", "'byfullnamewithoutlink'", ",", "'mod_workshop'", ",", "fullname", "(", "$", "author", ")", ")", ")", ";", "}", "$", "content", "=", "$", "this", "->", "format_exported_text", "(", "$", "workshopsubmission", "->", "content", ",", "$", "workshopsubmission", "->", "contentformat", ")", ";", "$", "content", "=", "portfolio_rewrite_pluginfile_urls", "(", "$", "content", ",", "$", "this", "->", "workshop", "->", "context", "->", "id", ",", "'mod_workshop'", ",", "'submission_content'", ",", "$", "workshopsubmission", "->", "id", ",", "$", "this", "->", "exporter", "->", "get", "(", "'format'", ")", ")", ";", "$", "output", ".=", "html_writer", "::", "div", "(", "$", "content", ")", ";", "$", "output", ".=", "$", "this", "->", "export_files_list", "(", "'submission_attachment'", ")", ";", "$", "strategy", "=", "$", "this", "->", "workshop", "->", "grading_strategy_instance", "(", ")", ";", "$", "canviewauthornames", "=", "has_capability", "(", "'mod/workshop:viewauthornames'", ",", "$", "this", "->", "workshop", "->", "context", ",", "$", "this", "->", "get", "(", "'user'", ")", ")", ";", "$", "canviewreviewernames", "=", "has_capability", "(", "'mod/workshop:viewreviewernames'", ",", "$", "this", "->", "workshop", "->", "context", ",", "$", "this", "->", "get", "(", "'user'", ")", ")", ";", "foreach", "(", "$", "this", "->", "assessments", "as", "$", "assessment", ")", "{", "$", "mform", "=", "$", "strategy", "->", "get_assessment_form", "(", "null", ",", "'assessment'", ",", "$", "assessment", ",", "false", ")", ";", "$", "options", "=", "[", "'showreviewer'", "=>", "$", "canviewreviewernames", ",", "'showauthor'", "=>", "$", "canviewauthornames", ",", "'showform'", "=>", "true", ",", "'showweight'", "=>", "true", ",", "]", ";", "if", "(", "$", "assessment", "->", "reviewerid", "==", "$", "this", "->", "get", "(", "'user'", ")", "->", "id", ")", "{", "$", "options", "[", "'showreviewer'", "]", "=", "true", ";", "}", "$", "workshopassessment", "=", "$", "this", "->", "workshop", "->", "prepare_assessment", "(", "$", "assessment", ",", "$", "mform", ",", "$", "options", ")", ";", "if", "(", "$", "assessment", "->", "reviewerid", "==", "$", "this", "->", "get", "(", "'user'", ")", "->", "id", ")", "{", "$", "workshopassessment", "->", "title", "=", "get_string", "(", "'assessmentbyyourself'", ",", "'mod_workshop'", ")", ";", "}", "else", "{", "$", "workshopassessment", "->", "title", "=", "get_string", "(", "'assessment'", ",", "'mod_workshop'", ")", ";", "}", "$", "output", ".=", "html_writer", "::", "empty_tag", "(", "'hr'", ")", ";", "$", "output", ".=", "$", "this", "->", "export_assessment", "(", "$", "workshopassessment", ")", ";", "}", "if", "(", "trim", "(", "$", "this", "->", "workshop", "->", "instructauthors", ")", ")", "{", "$", "output", ".=", "html_writer", "::", "tag", "(", "'h3'", ",", "get_string", "(", "'instructauthors'", ",", "'mod_workshop'", ")", ")", ";", "$", "content", "=", "$", "this", "->", "format_exported_text", "(", "$", "this", "->", "workshop", "->", "instructauthors", ",", "$", "this", "->", "workshop", "->", "instructauthorsformat", ")", ";", "$", "content", "=", "portfolio_rewrite_pluginfile_urls", "(", "$", "content", ",", "$", "this", "->", "workshop", "->", "context", "->", "id", ",", "'mod_workshop'", ",", "'instructauthors'", ",", "0", ",", "$", "this", "->", "exporter", "->", "get", "(", "'format'", ")", ")", ";", "$", "output", ".=", "$", "content", ";", "}", "return", "html_writer", "::", "div", "(", "$", "output", ")", ";", "}" ]
Render the content of the submission. @param workshop_submission $workshopsubmission @return string
[ "Render", "the", "content", "of", "the", "submission", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/classes/portfolio_caller.php#L265-L319
215,662
moodle/moodle
mod/workshop/classes/portfolio_caller.php
mod_workshop_portfolio_caller.export_assessment
protected function export_assessment(workshop_assessment $assessment) { $output = ''; if (empty($assessment->title)) { $title = get_string('assessment', 'workshop'); } else { $title = s($assessment->title); } $output .= html_writer::tag('h3', $title); if ($assessment->reviewer) { $output .= html_writer::div(get_string('byfullnamewithoutlink', 'mod_workshop', fullname($assessment->reviewer))); $output .= html_writer::empty_tag('br'); } if ($this->workshop->overallfeedbackmode) { if ($assessment->feedbackauthorattachment or trim($assessment->feedbackauthor) !== '') { $output .= html_writer::tag('h3', get_string('overallfeedback', 'mod_workshop')); $content = $this->format_exported_text($assessment->feedbackauthor, $assessment->feedbackauthorformat); $content = portfolio_rewrite_pluginfile_urls($content, $this->workshop->context->id, 'mod_workshop', 'overallfeedback_content', $assessment->id , $this->exporter->get('format')); $output .= $content; $output .= $this->export_files_list('overallfeedback_attachment'); } } if ($assessment->form) { $output .= $assessment->form->render(); } return $output; }
php
protected function export_assessment(workshop_assessment $assessment) { $output = ''; if (empty($assessment->title)) { $title = get_string('assessment', 'workshop'); } else { $title = s($assessment->title); } $output .= html_writer::tag('h3', $title); if ($assessment->reviewer) { $output .= html_writer::div(get_string('byfullnamewithoutlink', 'mod_workshop', fullname($assessment->reviewer))); $output .= html_writer::empty_tag('br'); } if ($this->workshop->overallfeedbackmode) { if ($assessment->feedbackauthorattachment or trim($assessment->feedbackauthor) !== '') { $output .= html_writer::tag('h3', get_string('overallfeedback', 'mod_workshop')); $content = $this->format_exported_text($assessment->feedbackauthor, $assessment->feedbackauthorformat); $content = portfolio_rewrite_pluginfile_urls($content, $this->workshop->context->id, 'mod_workshop', 'overallfeedback_content', $assessment->id , $this->exporter->get('format')); $output .= $content; $output .= $this->export_files_list('overallfeedback_attachment'); } } if ($assessment->form) { $output .= $assessment->form->render(); } return $output; }
[ "protected", "function", "export_assessment", "(", "workshop_assessment", "$", "assessment", ")", "{", "$", "output", "=", "''", ";", "if", "(", "empty", "(", "$", "assessment", "->", "title", ")", ")", "{", "$", "title", "=", "get_string", "(", "'assessment'", ",", "'workshop'", ")", ";", "}", "else", "{", "$", "title", "=", "s", "(", "$", "assessment", "->", "title", ")", ";", "}", "$", "output", ".=", "html_writer", "::", "tag", "(", "'h3'", ",", "$", "title", ")", ";", "if", "(", "$", "assessment", "->", "reviewer", ")", "{", "$", "output", ".=", "html_writer", "::", "div", "(", "get_string", "(", "'byfullnamewithoutlink'", ",", "'mod_workshop'", ",", "fullname", "(", "$", "assessment", "->", "reviewer", ")", ")", ")", ";", "$", "output", ".=", "html_writer", "::", "empty_tag", "(", "'br'", ")", ";", "}", "if", "(", "$", "this", "->", "workshop", "->", "overallfeedbackmode", ")", "{", "if", "(", "$", "assessment", "->", "feedbackauthorattachment", "or", "trim", "(", "$", "assessment", "->", "feedbackauthor", ")", "!==", "''", ")", "{", "$", "output", ".=", "html_writer", "::", "tag", "(", "'h3'", ",", "get_string", "(", "'overallfeedback'", ",", "'mod_workshop'", ")", ")", ";", "$", "content", "=", "$", "this", "->", "format_exported_text", "(", "$", "assessment", "->", "feedbackauthor", ",", "$", "assessment", "->", "feedbackauthorformat", ")", ";", "$", "content", "=", "portfolio_rewrite_pluginfile_urls", "(", "$", "content", ",", "$", "this", "->", "workshop", "->", "context", "->", "id", ",", "'mod_workshop'", ",", "'overallfeedback_content'", ",", "$", "assessment", "->", "id", ",", "$", "this", "->", "exporter", "->", "get", "(", "'format'", ")", ")", ";", "$", "output", ".=", "$", "content", ";", "$", "output", ".=", "$", "this", "->", "export_files_list", "(", "'overallfeedback_attachment'", ")", ";", "}", "}", "if", "(", "$", "assessment", "->", "form", ")", "{", "$", "output", ".=", "$", "assessment", "->", "form", "->", "render", "(", ")", ";", "}", "return", "$", "output", ";", "}" ]
Render the content of an assessment. @param workshop_assessment $assessment @return string HTML
[ "Render", "the", "content", "of", "an", "assessment", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/classes/portfolio_caller.php#L327-L361
215,663
moodle/moodle
mod/workshop/classes/portfolio_caller.php
mod_workshop_portfolio_caller.export_files_list
protected function export_files_list($filearea) { $output = ''; $files = []; foreach ($this->multifiles as $file) { if ($file->is_directory()) { continue; } if ($file->get_filearea() !== $filearea) { continue; } if ($file->is_valid_image()) { // Not optimal but looks better than original images. $files[] = html_writer::tag('li', $this->exporter->get('format')->file_output($file, ['attributes' => ['style' => 'max-height:24px; max-width:24px']]).' '.s($file->get_filename())); } else { $files[] = html_writer::tag('li', $this->exporter->get('format')->file_output($file)); } } if ($files) { $output .= html_writer::tag('ul', implode('', $files)); } return $output; }
php
protected function export_files_list($filearea) { $output = ''; $files = []; foreach ($this->multifiles as $file) { if ($file->is_directory()) { continue; } if ($file->get_filearea() !== $filearea) { continue; } if ($file->is_valid_image()) { // Not optimal but looks better than original images. $files[] = html_writer::tag('li', $this->exporter->get('format')->file_output($file, ['attributes' => ['style' => 'max-height:24px; max-width:24px']]).' '.s($file->get_filename())); } else { $files[] = html_writer::tag('li', $this->exporter->get('format')->file_output($file)); } } if ($files) { $output .= html_writer::tag('ul', implode('', $files)); } return $output; }
[ "protected", "function", "export_files_list", "(", "$", "filearea", ")", "{", "$", "output", "=", "''", ";", "$", "files", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "multifiles", "as", "$", "file", ")", "{", "if", "(", "$", "file", "->", "is_directory", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "file", "->", "get_filearea", "(", ")", "!==", "$", "filearea", ")", "{", "continue", ";", "}", "if", "(", "$", "file", "->", "is_valid_image", "(", ")", ")", "{", "// Not optimal but looks better than original images.", "$", "files", "[", "]", "=", "html_writer", "::", "tag", "(", "'li'", ",", "$", "this", "->", "exporter", "->", "get", "(", "'format'", ")", "->", "file_output", "(", "$", "file", ",", "[", "'attributes'", "=>", "[", "'style'", "=>", "'max-height:24px; max-width:24px'", "]", "]", ")", ".", "' '", ".", "s", "(", "$", "file", "->", "get_filename", "(", ")", ")", ")", ";", "}", "else", "{", "$", "files", "[", "]", "=", "html_writer", "::", "tag", "(", "'li'", ",", "$", "this", "->", "exporter", "->", "get", "(", "'format'", ")", "->", "file_output", "(", "$", "file", ")", ")", ";", "}", "}", "if", "(", "$", "files", ")", "{", "$", "output", ".=", "html_writer", "::", "tag", "(", "'ul'", ",", "implode", "(", "''", ",", "$", "files", ")", ")", ";", "}", "return", "$", "output", ";", "}" ]
Export the files in the given file area in a list. @param string $filearea @return string HTML
[ "Export", "the", "files", "in", "the", "given", "file", "area", "in", "a", "list", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/classes/portfolio_caller.php#L369-L395
215,664
moodle/moodle
mod/workshop/classes/portfolio_caller.php
mod_workshop_portfolio_caller.export_content_leap2a
protected function export_content_leap2a(portfolio_format_leap2a_writer $leapwriter, workshop_submission $workshopsubmission, $html) { $entry = new portfolio_format_leap2a_entry('workshopsubmission'.$workshopsubmission->id, s($workshopsubmission->title), 'resource', $html); $entry->published = $workshopsubmission->timecreated; $entry->updated = $workshopsubmission->timemodified; $entry->author = (object)[ 'id' => $workshopsubmission->authorid, 'email' => $workshopsubmission->authoremail ]; username_load_fields_from_object($entry->author, $workshopsubmission); $leapwriter->link_files($entry, $this->multifiles); $entry->add_category('web', 'resource_type'); $leapwriter->add_entry($entry); return $entry->id; }
php
protected function export_content_leap2a(portfolio_format_leap2a_writer $leapwriter, workshop_submission $workshopsubmission, $html) { $entry = new portfolio_format_leap2a_entry('workshopsubmission'.$workshopsubmission->id, s($workshopsubmission->title), 'resource', $html); $entry->published = $workshopsubmission->timecreated; $entry->updated = $workshopsubmission->timemodified; $entry->author = (object)[ 'id' => $workshopsubmission->authorid, 'email' => $workshopsubmission->authoremail ]; username_load_fields_from_object($entry->author, $workshopsubmission); $leapwriter->link_files($entry, $this->multifiles); $entry->add_category('web', 'resource_type'); $leapwriter->add_entry($entry); return $entry->id; }
[ "protected", "function", "export_content_leap2a", "(", "portfolio_format_leap2a_writer", "$", "leapwriter", ",", "workshop_submission", "$", "workshopsubmission", ",", "$", "html", ")", "{", "$", "entry", "=", "new", "portfolio_format_leap2a_entry", "(", "'workshopsubmission'", ".", "$", "workshopsubmission", "->", "id", ",", "s", "(", "$", "workshopsubmission", "->", "title", ")", ",", "'resource'", ",", "$", "html", ")", ";", "$", "entry", "->", "published", "=", "$", "workshopsubmission", "->", "timecreated", ";", "$", "entry", "->", "updated", "=", "$", "workshopsubmission", "->", "timemodified", ";", "$", "entry", "->", "author", "=", "(", "object", ")", "[", "'id'", "=>", "$", "workshopsubmission", "->", "authorid", ",", "'email'", "=>", "$", "workshopsubmission", "->", "authoremail", "]", ";", "username_load_fields_from_object", "(", "$", "entry", "->", "author", ",", "$", "workshopsubmission", ")", ";", "$", "leapwriter", "->", "link_files", "(", "$", "entry", ",", "$", "this", "->", "multifiles", ")", ";", "$", "entry", "->", "add_category", "(", "'web'", ",", "'resource_type'", ")", ";", "$", "leapwriter", "->", "add_entry", "(", "$", "entry", ")", ";", "return", "$", "entry", "->", "id", ";", "}" ]
Add a LEAP2A entry element that corresponds to a submission including attachments. @param portfolio_format_leap2a_writer $leapwriter Writer object to add entries to. @param workshop_submission $workshopsubmission @param string $html The exported HTML content of the submission @return int id of new entry
[ "Add", "a", "LEAP2A", "entry", "element", "that", "corresponds", "to", "a", "submission", "including", "attachments", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/classes/portfolio_caller.php#L425-L443
215,665
moodle/moodle
mod/workshop/classes/portfolio_caller.php
mod_workshop_portfolio_caller.get_return_url
public function get_return_url() { $returnurl = new moodle_url('/mod/workshop/submission.php', ['cmid' => $this->cm->id, 'id' => $this->submissionid]); return $returnurl->out(); }
php
public function get_return_url() { $returnurl = new moodle_url('/mod/workshop/submission.php', ['cmid' => $this->cm->id, 'id' => $this->submissionid]); return $returnurl->out(); }
[ "public", "function", "get_return_url", "(", ")", "{", "$", "returnurl", "=", "new", "moodle_url", "(", "'/mod/workshop/submission.php'", ",", "[", "'cmid'", "=>", "$", "this", "->", "cm", "->", "id", ",", "'id'", "=>", "$", "this", "->", "submissionid", "]", ")", ";", "return", "$", "returnurl", "->", "out", "(", ")", ";", "}" ]
Return URL for redirecting the user back to where the export started. @return string
[ "Return", "URL", "for", "redirecting", "the", "user", "back", "to", "where", "the", "export", "started", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/classes/portfolio_caller.php#L450-L454
215,666
moodle/moodle
mod/workshop/classes/portfolio_caller.php
mod_workshop_portfolio_caller.get_sha1
public function get_sha1() { $identifier = 'submission:'.$this->submission->id.'@'.$this->submission->timemodified; if ($this->assessments) { $ids = array_keys($this->assessments); sort($ids); $identifier .= '/assessments:'.implode(',', $ids); } if ($this->multifiles) { $identifier .= '/files:'.$this->get_sha1_file(); } return sha1($identifier); }
php
public function get_sha1() { $identifier = 'submission:'.$this->submission->id.'@'.$this->submission->timemodified; if ($this->assessments) { $ids = array_keys($this->assessments); sort($ids); $identifier .= '/assessments:'.implode(',', $ids); } if ($this->multifiles) { $identifier .= '/files:'.$this->get_sha1_file(); } return sha1($identifier); }
[ "public", "function", "get_sha1", "(", ")", "{", "$", "identifier", "=", "'submission:'", ".", "$", "this", "->", "submission", "->", "id", ".", "'@'", ".", "$", "this", "->", "submission", "->", "timemodified", ";", "if", "(", "$", "this", "->", "assessments", ")", "{", "$", "ids", "=", "array_keys", "(", "$", "this", "->", "assessments", ")", ";", "sort", "(", "$", "ids", ")", ";", "$", "identifier", ".=", "'/assessments:'", ".", "implode", "(", "','", ",", "$", "ids", ")", ";", "}", "if", "(", "$", "this", "->", "multifiles", ")", "{", "$", "identifier", ".=", "'/files:'", ".", "$", "this", "->", "get_sha1_file", "(", ")", ";", "}", "return", "sha1", "(", "$", "identifier", ")", ";", "}" ]
Return the SHA1 hash of the exported content. @return string
[ "Return", "the", "SHA1", "hash", "of", "the", "exported", "content", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/classes/portfolio_caller.php#L493-L508
215,667
moodle/moodle
lib/classes/oauth2/rest.php
rest.call
public function call($functionname, $functionargs, $rawpost = false, $contenttype = false) { $functions = $this->get_api_functions(); $supportedmethods = [ 'get', 'put', 'post', 'patch', 'head', 'delete' ]; if (empty($functions[$functionname])) { throw new coding_exception('unsupported api functionname: ' . $functionname); } $method = $functions[$functionname]['method']; $endpoint = $functions[$functionname]['endpoint']; $responsetype = $functions[$functionname]['response']; if (!in_array($method, $supportedmethods)) { throw new coding_exception('unsupported api method: ' . $method); } $args = $functions[$functionname]['args']; $callargs = []; foreach ($args as $argname => $argtype) { if (isset($functionargs[$argname])) { $callargs[$argname] = clean_param($functionargs[$argname], $argtype); } } // Allow params in the URL path like /me/{parent}/children. foreach ($callargs as $argname => $value) { $newendpoint = str_replace('{' . $argname . '}', $value, $endpoint); if ($newendpoint != $endpoint) { $endpoint = $newendpoint; unset($callargs[$argname]); } } if ($rawpost !== false) { $queryparams = $this->curl->build_post_data($callargs); if (!empty($queryparams)) { $endpoint .= '?' . $queryparams; } $callargs = $rawpost; } if (empty($contenttype)) { $this->curl->setHeader('Content-type: application/json'); } else { $this->curl->setHeader('Content-type: ' . $contenttype); } $response = $this->curl->$method($endpoint, $callargs); if ($this->curl->errno == 0) { if ($responsetype == 'json') { $json = json_decode($response); if (!empty($json->error)) { throw new rest_exception($json->error->code . ': ' . $json->error->message); } return $json; } else if ($responsetype == 'headers') { $response = $this->curl->get_raw_response(); } return $response; } else { throw new rest_exception($this->curl->error, $this->curl->errno); } }
php
public function call($functionname, $functionargs, $rawpost = false, $contenttype = false) { $functions = $this->get_api_functions(); $supportedmethods = [ 'get', 'put', 'post', 'patch', 'head', 'delete' ]; if (empty($functions[$functionname])) { throw new coding_exception('unsupported api functionname: ' . $functionname); } $method = $functions[$functionname]['method']; $endpoint = $functions[$functionname]['endpoint']; $responsetype = $functions[$functionname]['response']; if (!in_array($method, $supportedmethods)) { throw new coding_exception('unsupported api method: ' . $method); } $args = $functions[$functionname]['args']; $callargs = []; foreach ($args as $argname => $argtype) { if (isset($functionargs[$argname])) { $callargs[$argname] = clean_param($functionargs[$argname], $argtype); } } // Allow params in the URL path like /me/{parent}/children. foreach ($callargs as $argname => $value) { $newendpoint = str_replace('{' . $argname . '}', $value, $endpoint); if ($newendpoint != $endpoint) { $endpoint = $newendpoint; unset($callargs[$argname]); } } if ($rawpost !== false) { $queryparams = $this->curl->build_post_data($callargs); if (!empty($queryparams)) { $endpoint .= '?' . $queryparams; } $callargs = $rawpost; } if (empty($contenttype)) { $this->curl->setHeader('Content-type: application/json'); } else { $this->curl->setHeader('Content-type: ' . $contenttype); } $response = $this->curl->$method($endpoint, $callargs); if ($this->curl->errno == 0) { if ($responsetype == 'json') { $json = json_decode($response); if (!empty($json->error)) { throw new rest_exception($json->error->code . ': ' . $json->error->message); } return $json; } else if ($responsetype == 'headers') { $response = $this->curl->get_raw_response(); } return $response; } else { throw new rest_exception($this->curl->error, $this->curl->errno); } }
[ "public", "function", "call", "(", "$", "functionname", ",", "$", "functionargs", ",", "$", "rawpost", "=", "false", ",", "$", "contenttype", "=", "false", ")", "{", "$", "functions", "=", "$", "this", "->", "get_api_functions", "(", ")", ";", "$", "supportedmethods", "=", "[", "'get'", ",", "'put'", ",", "'post'", ",", "'patch'", ",", "'head'", ",", "'delete'", "]", ";", "if", "(", "empty", "(", "$", "functions", "[", "$", "functionname", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "'unsupported api functionname: '", ".", "$", "functionname", ")", ";", "}", "$", "method", "=", "$", "functions", "[", "$", "functionname", "]", "[", "'method'", "]", ";", "$", "endpoint", "=", "$", "functions", "[", "$", "functionname", "]", "[", "'endpoint'", "]", ";", "$", "responsetype", "=", "$", "functions", "[", "$", "functionname", "]", "[", "'response'", "]", ";", "if", "(", "!", "in_array", "(", "$", "method", ",", "$", "supportedmethods", ")", ")", "{", "throw", "new", "coding_exception", "(", "'unsupported api method: '", ".", "$", "method", ")", ";", "}", "$", "args", "=", "$", "functions", "[", "$", "functionname", "]", "[", "'args'", "]", ";", "$", "callargs", "=", "[", "]", ";", "foreach", "(", "$", "args", "as", "$", "argname", "=>", "$", "argtype", ")", "{", "if", "(", "isset", "(", "$", "functionargs", "[", "$", "argname", "]", ")", ")", "{", "$", "callargs", "[", "$", "argname", "]", "=", "clean_param", "(", "$", "functionargs", "[", "$", "argname", "]", ",", "$", "argtype", ")", ";", "}", "}", "// Allow params in the URL path like /me/{parent}/children.", "foreach", "(", "$", "callargs", "as", "$", "argname", "=>", "$", "value", ")", "{", "$", "newendpoint", "=", "str_replace", "(", "'{'", ".", "$", "argname", ".", "'}'", ",", "$", "value", ",", "$", "endpoint", ")", ";", "if", "(", "$", "newendpoint", "!=", "$", "endpoint", ")", "{", "$", "endpoint", "=", "$", "newendpoint", ";", "unset", "(", "$", "callargs", "[", "$", "argname", "]", ")", ";", "}", "}", "if", "(", "$", "rawpost", "!==", "false", ")", "{", "$", "queryparams", "=", "$", "this", "->", "curl", "->", "build_post_data", "(", "$", "callargs", ")", ";", "if", "(", "!", "empty", "(", "$", "queryparams", ")", ")", "{", "$", "endpoint", ".=", "'?'", ".", "$", "queryparams", ";", "}", "$", "callargs", "=", "$", "rawpost", ";", "}", "if", "(", "empty", "(", "$", "contenttype", ")", ")", "{", "$", "this", "->", "curl", "->", "setHeader", "(", "'Content-type: application/json'", ")", ";", "}", "else", "{", "$", "this", "->", "curl", "->", "setHeader", "(", "'Content-type: '", ".", "$", "contenttype", ")", ";", "}", "$", "response", "=", "$", "this", "->", "curl", "->", "$", "method", "(", "$", "endpoint", ",", "$", "callargs", ")", ";", "if", "(", "$", "this", "->", "curl", "->", "errno", "==", "0", ")", "{", "if", "(", "$", "responsetype", "==", "'json'", ")", "{", "$", "json", "=", "json_decode", "(", "$", "response", ")", ";", "if", "(", "!", "empty", "(", "$", "json", "->", "error", ")", ")", "{", "throw", "new", "rest_exception", "(", "$", "json", "->", "error", "->", "code", ".", "': '", ".", "$", "json", "->", "error", "->", "message", ")", ";", "}", "return", "$", "json", ";", "}", "else", "if", "(", "$", "responsetype", "==", "'headers'", ")", "{", "$", "response", "=", "$", "this", "->", "curl", "->", "get_raw_response", "(", ")", ";", "}", "return", "$", "response", ";", "}", "else", "{", "throw", "new", "rest_exception", "(", "$", "this", "->", "curl", "->", "error", ",", "$", "this", "->", "curl", "->", "errno", ")", ";", "}", "}" ]
Call a function from the Api with a set of arguments and optional data. @param string $functionname @param array $functionargs @param string $rawpost Optional param to include in the body of a post. @param string $contenttype The MIME type for the request's Content-Type header. @return string|stdClass
[ "Call", "a", "function", "from", "the", "Api", "with", "a", "set", "of", "arguments", "and", "optional", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/rest.php#L71-L133
215,668
moodle/moodle
lib/classes/files/curl_security_helper.php
curl_security_helper.port_is_blocked
protected function port_is_blocked($port) { $portnum = intval($port); // Intentionally block port 0 and below and check the int cast was valid. if (empty($port) || (string)$portnum !== (string)$port || $port < 0) { return true; } $allowedports = $this->get_whitelisted_ports(); return !empty($allowedports) && !in_array($portnum, $allowedports); }
php
protected function port_is_blocked($port) { $portnum = intval($port); // Intentionally block port 0 and below and check the int cast was valid. if (empty($port) || (string)$portnum !== (string)$port || $port < 0) { return true; } $allowedports = $this->get_whitelisted_ports(); return !empty($allowedports) && !in_array($portnum, $allowedports); }
[ "protected", "function", "port_is_blocked", "(", "$", "port", ")", "{", "$", "portnum", "=", "intval", "(", "$", "port", ")", ";", "// Intentionally block port 0 and below and check the int cast was valid.", "if", "(", "empty", "(", "$", "port", ")", "||", "(", "string", ")", "$", "portnum", "!==", "(", "string", ")", "$", "port", "||", "$", "port", "<", "0", ")", "{", "return", "true", ";", "}", "$", "allowedports", "=", "$", "this", "->", "get_whitelisted_ports", "(", ")", ";", "return", "!", "empty", "(", "$", "allowedports", ")", "&&", "!", "in_array", "(", "$", "portnum", ",", "$", "allowedports", ")", ";", "}" ]
Checks whether the given port is blocked, as determined by its absence on the ports whitelist. Ports are assumed to be blocked unless found in the whitelist. @param integer|string $port the port to check against the ports whitelist. @return bool true if the port is blocked, false otherwise.
[ "Checks", "whether", "the", "given", "port", "is", "blocked", "as", "determined", "by", "its", "absence", "on", "the", "ports", "whitelist", ".", "Ports", "are", "assumed", "to", "be", "blocked", "unless", "found", "in", "the", "whitelist", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/files/curl_security_helper.php#L191-L199
215,669
moodle/moodle
lib/classes/files/curl_security_helper.php
curl_security_helper.address_explicitly_blocked
protected function address_explicitly_blocked($addr) { $blockedhosts = $this->get_blacklisted_hosts_by_category(); $iphostsblocked = array_merge($blockedhosts['ipv4'], $blockedhosts['ipv6']); return address_in_subnet($addr, implode(',', $iphostsblocked)); }
php
protected function address_explicitly_blocked($addr) { $blockedhosts = $this->get_blacklisted_hosts_by_category(); $iphostsblocked = array_merge($blockedhosts['ipv4'], $blockedhosts['ipv6']); return address_in_subnet($addr, implode(',', $iphostsblocked)); }
[ "protected", "function", "address_explicitly_blocked", "(", "$", "addr", ")", "{", "$", "blockedhosts", "=", "$", "this", "->", "get_blacklisted_hosts_by_category", "(", ")", ";", "$", "iphostsblocked", "=", "array_merge", "(", "$", "blockedhosts", "[", "'ipv4'", "]", ",", "$", "blockedhosts", "[", "'ipv6'", "]", ")", ";", "return", "address_in_subnet", "(", "$", "addr", ",", "implode", "(", "','", ",", "$", "iphostsblocked", ")", ")", ";", "}" ]
Checks whether the input address is blocked by at any of the IPv4 or IPv6 address rules. @param string $addr the ip address to check. @return bool true if the address is covered by an entry in the blacklist, false otherwise.
[ "Checks", "whether", "the", "input", "address", "is", "blocked", "by", "at", "any", "of", "the", "IPv4", "or", "IPv6", "address", "rules", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/files/curl_security_helper.php#L217-L221
215,670
moodle/moodle
lib/classes/files/curl_security_helper.php
curl_security_helper.get_blacklisted_hosts_by_category
protected function get_blacklisted_hosts_by_category() { // For each of the admin setting entries, check and place in the correct section of the config array. $config = ['ipv6' => [], 'ipv4' => [], 'domain' => [], 'domainwildcard' => []]; $entries = $this->get_blacklisted_hosts(); foreach ($entries as $entry) { if (ip_utils::is_ipv6_address($entry) || ip_utils::is_ipv6_range($entry)) { $config['ipv6'][] = $entry; } else if (ip_utils::is_ipv4_address($entry) || ip_utils::is_ipv4_range($entry)) { $config['ipv4'][] = $entry; } else if (ip_utils::is_domain_name($entry)) { $config['domain'][] = $entry; } else if (ip_utils::is_domain_matching_pattern($entry)) { $config['domainwildcard'][] = $entry; } } return $config; }
php
protected function get_blacklisted_hosts_by_category() { // For each of the admin setting entries, check and place in the correct section of the config array. $config = ['ipv6' => [], 'ipv4' => [], 'domain' => [], 'domainwildcard' => []]; $entries = $this->get_blacklisted_hosts(); foreach ($entries as $entry) { if (ip_utils::is_ipv6_address($entry) || ip_utils::is_ipv6_range($entry)) { $config['ipv6'][] = $entry; } else if (ip_utils::is_ipv4_address($entry) || ip_utils::is_ipv4_range($entry)) { $config['ipv4'][] = $entry; } else if (ip_utils::is_domain_name($entry)) { $config['domain'][] = $entry; } else if (ip_utils::is_domain_matching_pattern($entry)) { $config['domainwildcard'][] = $entry; } } return $config; }
[ "protected", "function", "get_blacklisted_hosts_by_category", "(", ")", "{", "// For each of the admin setting entries, check and place in the correct section of the config array.", "$", "config", "=", "[", "'ipv6'", "=>", "[", "]", ",", "'ipv4'", "=>", "[", "]", ",", "'domain'", "=>", "[", "]", ",", "'domainwildcard'", "=>", "[", "]", "]", ";", "$", "entries", "=", "$", "this", "->", "get_blacklisted_hosts", "(", ")", ";", "foreach", "(", "$", "entries", "as", "$", "entry", ")", "{", "if", "(", "ip_utils", "::", "is_ipv6_address", "(", "$", "entry", ")", "||", "ip_utils", "::", "is_ipv6_range", "(", "$", "entry", ")", ")", "{", "$", "config", "[", "'ipv6'", "]", "[", "]", "=", "$", "entry", ";", "}", "else", "if", "(", "ip_utils", "::", "is_ipv4_address", "(", "$", "entry", ")", "||", "ip_utils", "::", "is_ipv4_range", "(", "$", "entry", ")", ")", "{", "$", "config", "[", "'ipv4'", "]", "[", "]", "=", "$", "entry", ";", "}", "else", "if", "(", "ip_utils", "::", "is_domain_name", "(", "$", "entry", ")", ")", "{", "$", "config", "[", "'domain'", "]", "[", "]", "=", "$", "entry", ";", "}", "else", "if", "(", "ip_utils", "::", "is_domain_matching_pattern", "(", "$", "entry", ")", ")", "{", "$", "config", "[", "'domainwildcard'", "]", "[", "]", "=", "$", "entry", ";", "}", "}", "return", "$", "config", ";", "}" ]
Helper to get all entries from the admin setting, as an array, sorted by classification. Classifications include 'ipv4', 'ipv6', 'domain', 'domainwildcard'. @return array of host/domain/ip entries from the 'curlsecurityblockedhosts' config.
[ "Helper", "to", "get", "all", "entries", "from", "the", "admin", "setting", "as", "an", "array", "sorted", "by", "classification", ".", "Classifications", "include", "ipv4", "ipv6", "domain", "domainwildcard", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/files/curl_security_helper.php#L241-L257
215,671
moodle/moodle
lib/classes/files/curl_security_helper.php
curl_security_helper.get_whitelisted_ports
protected function get_whitelisted_ports() { global $CFG; if (!isset($CFG->curlsecurityallowedport)) { return []; } return array_filter(array_map('trim', explode("\n", $CFG->curlsecurityallowedport)), function($entry) { return !empty($entry); }); }
php
protected function get_whitelisted_ports() { global $CFG; if (!isset($CFG->curlsecurityallowedport)) { return []; } return array_filter(array_map('trim', explode("\n", $CFG->curlsecurityallowedport)), function($entry) { return !empty($entry); }); }
[ "protected", "function", "get_whitelisted_ports", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "isset", "(", "$", "CFG", "->", "curlsecurityallowedport", ")", ")", "{", "return", "[", "]", ";", "}", "return", "array_filter", "(", "array_map", "(", "'trim'", ",", "explode", "(", "\"\\n\"", ",", "$", "CFG", "->", "curlsecurityallowedport", ")", ")", ",", "function", "(", "$", "entry", ")", "{", "return", "!", "empty", "(", "$", "entry", ")", ";", "}", ")", ";", "}" ]
Helper that returns the whitelisted ports, as defined in the 'curlsecurityallowedport' setting. @return array the array of whitelisted ports.
[ "Helper", "that", "returns", "the", "whitelisted", "ports", "as", "defined", "in", "the", "curlsecurityallowedport", "setting", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/files/curl_security_helper.php#L264-L272
215,672
moodle/moodle
lib/classes/files/curl_security_helper.php
curl_security_helper.get_blacklisted_hosts
protected function get_blacklisted_hosts() { global $CFG; if (!isset($CFG->curlsecurityblockedhosts)) { return []; } return array_filter(array_map('trim', explode("\n", $CFG->curlsecurityblockedhosts)), function($entry) { return !empty($entry); }); }
php
protected function get_blacklisted_hosts() { global $CFG; if (!isset($CFG->curlsecurityblockedhosts)) { return []; } return array_filter(array_map('trim', explode("\n", $CFG->curlsecurityblockedhosts)), function($entry) { return !empty($entry); }); }
[ "protected", "function", "get_blacklisted_hosts", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "isset", "(", "$", "CFG", "->", "curlsecurityblockedhosts", ")", ")", "{", "return", "[", "]", ";", "}", "return", "array_filter", "(", "array_map", "(", "'trim'", ",", "explode", "(", "\"\\n\"", ",", "$", "CFG", "->", "curlsecurityblockedhosts", ")", ")", ",", "function", "(", "$", "entry", ")", "{", "return", "!", "empty", "(", "$", "entry", ")", ";", "}", ")", ";", "}" ]
Helper that returns the blacklisted hosts, as defined in the 'curlsecurityblockedhosts' setting. @return array the array of blacklisted host entries.
[ "Helper", "that", "returns", "the", "blacklisted", "hosts", "as", "defined", "in", "the", "curlsecurityblockedhosts", "setting", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/files/curl_security_helper.php#L279-L287
215,673
moodle/moodle
lib/behat/behat_base.php
behat_base.locate_path
protected function locate_path($path) { $starturl = rtrim($this->getMinkParameter('base_url'), '/') . '/'; return 0 !== strpos($path, 'http') ? $starturl . ltrim($path, '/') : $path; }
php
protected function locate_path($path) { $starturl = rtrim($this->getMinkParameter('base_url'), '/') . '/'; return 0 !== strpos($path, 'http') ? $starturl . ltrim($path, '/') : $path; }
[ "protected", "function", "locate_path", "(", "$", "path", ")", "{", "$", "starturl", "=", "rtrim", "(", "$", "this", "->", "getMinkParameter", "(", "'base_url'", ")", ",", "'/'", ")", ".", "'/'", ";", "return", "0", "!==", "strpos", "(", "$", "path", ",", "'http'", ")", "?", "$", "starturl", ".", "ltrim", "(", "$", "path", ",", "'/'", ")", ":", "$", "path", ";", "}" ]
Locates url, based on provided path. Override to provide custom routing mechanism. @see Behat\MinkExtension\Context\MinkContext @param string $path @return string
[ "Locates", "url", "based", "on", "provided", "path", ".", "Override", "to", "provide", "custom", "routing", "mechanism", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_base.php#L101-L104
215,674
moodle/moodle
lib/behat/behat_base.php
behat_base.find
protected function find($selector, $locator, $exception = false, $node = false, $timeout = false) { // Throw exception, so dev knows it is not supported. if ($selector === 'named') { $exception = 'Using the "named" selector is deprecated as of 3.1. ' .' Use the "named_partial" or use the "named_exact" selector instead.'; throw new ExpectationException($exception, $this->getSession()); } // Returns the first match. $items = $this->find_all($selector, $locator, $exception, $node, $timeout); return count($items) ? reset($items) : null; }
php
protected function find($selector, $locator, $exception = false, $node = false, $timeout = false) { // Throw exception, so dev knows it is not supported. if ($selector === 'named') { $exception = 'Using the "named" selector is deprecated as of 3.1. ' .' Use the "named_partial" or use the "named_exact" selector instead.'; throw new ExpectationException($exception, $this->getSession()); } // Returns the first match. $items = $this->find_all($selector, $locator, $exception, $node, $timeout); return count($items) ? reset($items) : null; }
[ "protected", "function", "find", "(", "$", "selector", ",", "$", "locator", ",", "$", "exception", "=", "false", ",", "$", "node", "=", "false", ",", "$", "timeout", "=", "false", ")", "{", "// Throw exception, so dev knows it is not supported.", "if", "(", "$", "selector", "===", "'named'", ")", "{", "$", "exception", "=", "'Using the \"named\" selector is deprecated as of 3.1. '", ".", "' Use the \"named_partial\" or use the \"named_exact\" selector instead.'", ";", "throw", "new", "ExpectationException", "(", "$", "exception", ",", "$", "this", "->", "getSession", "(", ")", ")", ";", "}", "// Returns the first match.", "$", "items", "=", "$", "this", "->", "find_all", "(", "$", "selector", ",", "$", "locator", ",", "$", "exception", ",", "$", "node", ",", "$", "timeout", ")", ";", "return", "count", "(", "$", "items", ")", "?", "reset", "(", "$", "items", ")", ":", "null", ";", "}" ]
Returns the first matching element. @link http://mink.behat.org/#traverse-the-page-selectors @param string $selector The selector type (css, xpath, named...) @param mixed $locator It depends on the $selector, can be the xpath, a name, a css locator... @param Exception $exception Otherwise we throw exception with generic info @param NodeElement $node Spins around certain DOM node instead of the whole page @param int $timeout Forces a specific time out (in seconds). @return NodeElement
[ "Returns", "the", "first", "matching", "element", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_base.php#L117-L129
215,675
moodle/moodle
lib/behat/behat_base.php
behat_base.find_all
protected function find_all($selector, $locator, $exception = false, $node = false, $timeout = false) { // Throw exception, so dev knows it is not supported. if ($selector === 'named') { $exception = 'Using the "named" selector is deprecated as of 3.1. ' .' Use the "named_partial" or use the "named_exact" selector instead.'; throw new ExpectationException($exception, $this->getSession()); } // Generic info. if (!$exception) { // With named selectors we can be more specific. if (($selector == 'named_exact') || ($selector == 'named_partial')) { $exceptiontype = $locator[0]; $exceptionlocator = $locator[1]; // If we are in a @javascript session all contents would be displayed as HTML characters. if ($this->running_javascript()) { $locator[1] = html_entity_decode($locator[1], ENT_NOQUOTES); } } else { $exceptiontype = $selector; $exceptionlocator = $locator; } $exception = new ElementNotFoundException($this->getSession(), $exceptiontype, null, $exceptionlocator); } $params = array('selector' => $selector, 'locator' => $locator); // Pushing $node if required. if ($node) { $params['node'] = $node; } // How much we will be waiting for the element to appear. if (!$timeout) { $timeout = self::get_timeout(); $microsleep = false; } else { // Spinning each 0.1 seconds if the timeout was forced as we understand // that is a special case and is good to refine the performance as much // as possible. $microsleep = true; } // Waits for the node to appear if it exists, otherwise will timeout and throw the provided exception. return $this->spin( function($context, $args) { // If no DOM node provided look in all the page. if (empty($args['node'])) { return $context->getSession()->getPage()->findAll($args['selector'], $args['locator']); } // For nodes contained in other nodes we can not use the basic named selectors // as they include unions and they would look for matches in the DOM root. $elementxpath = $context->getSession()->getSelectorsHandler()->selectorToXpath($args['selector'], $args['locator']); // Split the xpath in unions and prefix them with the container xpath. $unions = explode('|', $elementxpath); foreach ($unions as $key => $union) { $union = trim($union); // We are in the container node. if (strpos($union, '.') === 0) { $union = substr($union, 1); } else if (strpos($union, '/') !== 0) { // Adding the path separator in case it is not there. $union = '/' . $union; } $unions[$key] = $args['node']->getXpath() . $union; } // We can not use usual Element::find() as it prefixes with DOM root. return $context->getSession()->getDriver()->find(implode('|', $unions)); }, $params, $timeout, $exception, $microsleep ); }
php
protected function find_all($selector, $locator, $exception = false, $node = false, $timeout = false) { // Throw exception, so dev knows it is not supported. if ($selector === 'named') { $exception = 'Using the "named" selector is deprecated as of 3.1. ' .' Use the "named_partial" or use the "named_exact" selector instead.'; throw new ExpectationException($exception, $this->getSession()); } // Generic info. if (!$exception) { // With named selectors we can be more specific. if (($selector == 'named_exact') || ($selector == 'named_partial')) { $exceptiontype = $locator[0]; $exceptionlocator = $locator[1]; // If we are in a @javascript session all contents would be displayed as HTML characters. if ($this->running_javascript()) { $locator[1] = html_entity_decode($locator[1], ENT_NOQUOTES); } } else { $exceptiontype = $selector; $exceptionlocator = $locator; } $exception = new ElementNotFoundException($this->getSession(), $exceptiontype, null, $exceptionlocator); } $params = array('selector' => $selector, 'locator' => $locator); // Pushing $node if required. if ($node) { $params['node'] = $node; } // How much we will be waiting for the element to appear. if (!$timeout) { $timeout = self::get_timeout(); $microsleep = false; } else { // Spinning each 0.1 seconds if the timeout was forced as we understand // that is a special case and is good to refine the performance as much // as possible. $microsleep = true; } // Waits for the node to appear if it exists, otherwise will timeout and throw the provided exception. return $this->spin( function($context, $args) { // If no DOM node provided look in all the page. if (empty($args['node'])) { return $context->getSession()->getPage()->findAll($args['selector'], $args['locator']); } // For nodes contained in other nodes we can not use the basic named selectors // as they include unions and they would look for matches in the DOM root. $elementxpath = $context->getSession()->getSelectorsHandler()->selectorToXpath($args['selector'], $args['locator']); // Split the xpath in unions and prefix them with the container xpath. $unions = explode('|', $elementxpath); foreach ($unions as $key => $union) { $union = trim($union); // We are in the container node. if (strpos($union, '.') === 0) { $union = substr($union, 1); } else if (strpos($union, '/') !== 0) { // Adding the path separator in case it is not there. $union = '/' . $union; } $unions[$key] = $args['node']->getXpath() . $union; } // We can not use usual Element::find() as it prefixes with DOM root. return $context->getSession()->getDriver()->find(implode('|', $unions)); }, $params, $timeout, $exception, $microsleep ); }
[ "protected", "function", "find_all", "(", "$", "selector", ",", "$", "locator", ",", "$", "exception", "=", "false", ",", "$", "node", "=", "false", ",", "$", "timeout", "=", "false", ")", "{", "// Throw exception, so dev knows it is not supported.", "if", "(", "$", "selector", "===", "'named'", ")", "{", "$", "exception", "=", "'Using the \"named\" selector is deprecated as of 3.1. '", ".", "' Use the \"named_partial\" or use the \"named_exact\" selector instead.'", ";", "throw", "new", "ExpectationException", "(", "$", "exception", ",", "$", "this", "->", "getSession", "(", ")", ")", ";", "}", "// Generic info.", "if", "(", "!", "$", "exception", ")", "{", "// With named selectors we can be more specific.", "if", "(", "(", "$", "selector", "==", "'named_exact'", ")", "||", "(", "$", "selector", "==", "'named_partial'", ")", ")", "{", "$", "exceptiontype", "=", "$", "locator", "[", "0", "]", ";", "$", "exceptionlocator", "=", "$", "locator", "[", "1", "]", ";", "// If we are in a @javascript session all contents would be displayed as HTML characters.", "if", "(", "$", "this", "->", "running_javascript", "(", ")", ")", "{", "$", "locator", "[", "1", "]", "=", "html_entity_decode", "(", "$", "locator", "[", "1", "]", ",", "ENT_NOQUOTES", ")", ";", "}", "}", "else", "{", "$", "exceptiontype", "=", "$", "selector", ";", "$", "exceptionlocator", "=", "$", "locator", ";", "}", "$", "exception", "=", "new", "ElementNotFoundException", "(", "$", "this", "->", "getSession", "(", ")", ",", "$", "exceptiontype", ",", "null", ",", "$", "exceptionlocator", ")", ";", "}", "$", "params", "=", "array", "(", "'selector'", "=>", "$", "selector", ",", "'locator'", "=>", "$", "locator", ")", ";", "// Pushing $node if required.", "if", "(", "$", "node", ")", "{", "$", "params", "[", "'node'", "]", "=", "$", "node", ";", "}", "// How much we will be waiting for the element to appear.", "if", "(", "!", "$", "timeout", ")", "{", "$", "timeout", "=", "self", "::", "get_timeout", "(", ")", ";", "$", "microsleep", "=", "false", ";", "}", "else", "{", "// Spinning each 0.1 seconds if the timeout was forced as we understand", "// that is a special case and is good to refine the performance as much", "// as possible.", "$", "microsleep", "=", "true", ";", "}", "// Waits for the node to appear if it exists, otherwise will timeout and throw the provided exception.", "return", "$", "this", "->", "spin", "(", "function", "(", "$", "context", ",", "$", "args", ")", "{", "// If no DOM node provided look in all the page.", "if", "(", "empty", "(", "$", "args", "[", "'node'", "]", ")", ")", "{", "return", "$", "context", "->", "getSession", "(", ")", "->", "getPage", "(", ")", "->", "findAll", "(", "$", "args", "[", "'selector'", "]", ",", "$", "args", "[", "'locator'", "]", ")", ";", "}", "// For nodes contained in other nodes we can not use the basic named selectors", "// as they include unions and they would look for matches in the DOM root.", "$", "elementxpath", "=", "$", "context", "->", "getSession", "(", ")", "->", "getSelectorsHandler", "(", ")", "->", "selectorToXpath", "(", "$", "args", "[", "'selector'", "]", ",", "$", "args", "[", "'locator'", "]", ")", ";", "// Split the xpath in unions and prefix them with the container xpath.", "$", "unions", "=", "explode", "(", "'|'", ",", "$", "elementxpath", ")", ";", "foreach", "(", "$", "unions", "as", "$", "key", "=>", "$", "union", ")", "{", "$", "union", "=", "trim", "(", "$", "union", ")", ";", "// We are in the container node.", "if", "(", "strpos", "(", "$", "union", ",", "'.'", ")", "===", "0", ")", "{", "$", "union", "=", "substr", "(", "$", "union", ",", "1", ")", ";", "}", "else", "if", "(", "strpos", "(", "$", "union", ",", "'/'", ")", "!==", "0", ")", "{", "// Adding the path separator in case it is not there.", "$", "union", "=", "'/'", ".", "$", "union", ";", "}", "$", "unions", "[", "$", "key", "]", "=", "$", "args", "[", "'node'", "]", "->", "getXpath", "(", ")", ".", "$", "union", ";", "}", "// We can not use usual Element::find() as it prefixes with DOM root.", "return", "$", "context", "->", "getSession", "(", ")", "->", "getDriver", "(", ")", "->", "find", "(", "implode", "(", "'|'", ",", "$", "unions", ")", ")", ";", "}", ",", "$", "params", ",", "$", "timeout", ",", "$", "exception", ",", "$", "microsleep", ")", ";", "}" ]
Returns all matching elements. Adapter to Behat\Mink\Element\Element::findAll() using the spin() method. @link http://mink.behat.org/#traverse-the-page-selectors @param string $selector The selector type (css, xpath, named...) @param mixed $locator It depends on the $selector, can be the xpath, a name, a css locator... @param Exception $exception Otherwise we throw expcetion with generic info @param NodeElement $node Spins around certain DOM node instead of the whole page @param int $timeout Forces a specific time out (in seconds). If 0 is provided the default timeout will be applied. @return array NodeElements list
[ "Returns", "all", "matching", "elements", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_base.php#L144-L227
215,676
moodle/moodle
lib/behat/behat_base.php
behat_base.spin
protected function spin($lambda, $args = false, $timeout = false, $exception = false, $microsleep = false) { // Using default timeout which is pretty high. if (!$timeout) { $timeout = self::get_timeout(); } if ($microsleep) { // Will sleep 1/10th of a second by default for self::get_timeout() seconds. $loops = $timeout * 10; } else { // Will sleep for self::get_timeout() seconds. $loops = $timeout; } // DOM will never change on non-javascript case; do not wait or try again. if (!$this->running_javascript()) { $loops = 1; } for ($i = 0; $i < $loops; $i++) { // We catch the exception thrown by the step definition to execute it again. try { // We don't check with !== because most of the time closures will return // direct Behat methods returns and we are not sure it will be always (bool)false // if it just runs the behat method without returning anything $return == null. if ($return = call_user_func($lambda, $this, $args)) { return $return; } } catch (Exception $e) { // We would use the first closure exception if no exception has been provided. if (!$exception) { $exception = $e; } } if ($this->running_javascript()) { if ($microsleep) { usleep(100000); } else { sleep(1); } } } // Using coding_exception as is a development issue if no exception has been provided. if (!$exception) { $exception = new coding_exception('spin method requires an exception if the callback does not throw an exception'); } // Throwing exception to the user. throw $exception; }
php
protected function spin($lambda, $args = false, $timeout = false, $exception = false, $microsleep = false) { // Using default timeout which is pretty high. if (!$timeout) { $timeout = self::get_timeout(); } if ($microsleep) { // Will sleep 1/10th of a second by default for self::get_timeout() seconds. $loops = $timeout * 10; } else { // Will sleep for self::get_timeout() seconds. $loops = $timeout; } // DOM will never change on non-javascript case; do not wait or try again. if (!$this->running_javascript()) { $loops = 1; } for ($i = 0; $i < $loops; $i++) { // We catch the exception thrown by the step definition to execute it again. try { // We don't check with !== because most of the time closures will return // direct Behat methods returns and we are not sure it will be always (bool)false // if it just runs the behat method without returning anything $return == null. if ($return = call_user_func($lambda, $this, $args)) { return $return; } } catch (Exception $e) { // We would use the first closure exception if no exception has been provided. if (!$exception) { $exception = $e; } } if ($this->running_javascript()) { if ($microsleep) { usleep(100000); } else { sleep(1); } } } // Using coding_exception as is a development issue if no exception has been provided. if (!$exception) { $exception = new coding_exception('spin method requires an exception if the callback does not throw an exception'); } // Throwing exception to the user. throw $exception; }
[ "protected", "function", "spin", "(", "$", "lambda", ",", "$", "args", "=", "false", ",", "$", "timeout", "=", "false", ",", "$", "exception", "=", "false", ",", "$", "microsleep", "=", "false", ")", "{", "// Using default timeout which is pretty high.", "if", "(", "!", "$", "timeout", ")", "{", "$", "timeout", "=", "self", "::", "get_timeout", "(", ")", ";", "}", "if", "(", "$", "microsleep", ")", "{", "// Will sleep 1/10th of a second by default for self::get_timeout() seconds.", "$", "loops", "=", "$", "timeout", "*", "10", ";", "}", "else", "{", "// Will sleep for self::get_timeout() seconds.", "$", "loops", "=", "$", "timeout", ";", "}", "// DOM will never change on non-javascript case; do not wait or try again.", "if", "(", "!", "$", "this", "->", "running_javascript", "(", ")", ")", "{", "$", "loops", "=", "1", ";", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "loops", ";", "$", "i", "++", ")", "{", "// We catch the exception thrown by the step definition to execute it again.", "try", "{", "// We don't check with !== because most of the time closures will return", "// direct Behat methods returns and we are not sure it will be always (bool)false", "// if it just runs the behat method without returning anything $return == null.", "if", "(", "$", "return", "=", "call_user_func", "(", "$", "lambda", ",", "$", "this", ",", "$", "args", ")", ")", "{", "return", "$", "return", ";", "}", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// We would use the first closure exception if no exception has been provided.", "if", "(", "!", "$", "exception", ")", "{", "$", "exception", "=", "$", "e", ";", "}", "}", "if", "(", "$", "this", "->", "running_javascript", "(", ")", ")", "{", "if", "(", "$", "microsleep", ")", "{", "usleep", "(", "100000", ")", ";", "}", "else", "{", "sleep", "(", "1", ")", ";", "}", "}", "}", "// Using coding_exception as is a development issue if no exception has been provided.", "if", "(", "!", "$", "exception", ")", "{", "$", "exception", "=", "new", "coding_exception", "(", "'spin method requires an exception if the callback does not throw an exception'", ")", ";", "}", "// Throwing exception to the user.", "throw", "$", "exception", ";", "}" ]
Executes the passed closure until returns true or time outs. In most cases the document.readyState === 'complete' will be enough, but sometimes JS requires more time to be completely loaded or an element to be visible or whatever is required to perform some action on an element; this method receives a closure which should contain the required statements to ensure the step definition actions and assertions have all their needs satisfied and executes it until they are satisfied or it timeouts. Redirects the return of the closure to the caller. The closures requirements to work well with this spin method are: - Must return false, null or '' if something goes wrong - Must return something != false if finishes as expected, this will be the (mixed) value returned by spin() The arguments of the closure are mixed, use $args depending on your needs. You can provide an exception to give more accurate feedback to tests writers, otherwise the closure exception will be used, but you must provide an exception if the closure does not throw an exception. @throws Exception If it timeouts without receiving something != false from the closure @param Function|array|string $lambda The function to execute or an array passed to call_user_func (maps to a class method) @param mixed $args Arguments to pass to the closure @param int $timeout Timeout in seconds @param Exception $exception The exception to throw in case it time outs. @param bool $microsleep If set to true it'll sleep micro seconds rather than seconds. @return mixed The value returned by the closure
[ "Executes", "the", "passed", "closure", "until", "returns", "true", "or", "time", "outs", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_base.php#L319-L370
215,677
moodle/moodle
lib/behat/behat_base.php
behat_base.get_node_in_container
protected function get_node_in_container($selectortype, $element, $containerselectortype, $containerelement) { // Gets the container, it will always be text based. $containernode = $this->get_text_selector_node($containerselectortype, $containerelement); list($selector, $locator) = $this->transform_selector($selectortype, $element); // Specific exception giving info about where can't we find the element. $locatorexceptionmsg = $element . '" in the "' . $containerelement. '" "' . $containerselectortype. '"'; $exception = new ElementNotFoundException($this->getSession(), $selectortype, null, $locatorexceptionmsg); // Looks for the requested node inside the container node. return $this->find($selector, $locator, $exception, $containernode); }
php
protected function get_node_in_container($selectortype, $element, $containerselectortype, $containerelement) { // Gets the container, it will always be text based. $containernode = $this->get_text_selector_node($containerselectortype, $containerelement); list($selector, $locator) = $this->transform_selector($selectortype, $element); // Specific exception giving info about where can't we find the element. $locatorexceptionmsg = $element . '" in the "' . $containerelement. '" "' . $containerselectortype. '"'; $exception = new ElementNotFoundException($this->getSession(), $selectortype, null, $locatorexceptionmsg); // Looks for the requested node inside the container node. return $this->find($selector, $locator, $exception, $containernode); }
[ "protected", "function", "get_node_in_container", "(", "$", "selectortype", ",", "$", "element", ",", "$", "containerselectortype", ",", "$", "containerelement", ")", "{", "// Gets the container, it will always be text based.", "$", "containernode", "=", "$", "this", "->", "get_text_selector_node", "(", "$", "containerselectortype", ",", "$", "containerelement", ")", ";", "list", "(", "$", "selector", ",", "$", "locator", ")", "=", "$", "this", "->", "transform_selector", "(", "$", "selectortype", ",", "$", "element", ")", ";", "// Specific exception giving info about where can't we find the element.", "$", "locatorexceptionmsg", "=", "$", "element", ".", "'\" in the \"'", ".", "$", "containerelement", ".", "'\" \"'", ".", "$", "containerselectortype", ".", "'\"'", ";", "$", "exception", "=", "new", "ElementNotFoundException", "(", "$", "this", "->", "getSession", "(", ")", ",", "$", "selectortype", ",", "null", ",", "$", "locatorexceptionmsg", ")", ";", "// Looks for the requested node inside the container node.", "return", "$", "this", "->", "find", "(", "$", "selector", ",", "$", "locator", ",", "$", "exception", ",", "$", "containernode", ")", ";", "}" ]
Gets the requested element inside the specified container. @throws ElementNotFoundException Thrown by behat_base::find @param mixed $selectortype The element selector type. @param mixed $element The element locator. @param mixed $containerselectortype The container selector type. @param mixed $containerelement The container locator. @return NodeElement
[ "Gets", "the", "requested", "element", "inside", "the", "specified", "container", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_base.php#L418-L431
215,678
moodle/moodle
lib/behat/behat_base.php
behat_base.ensure_element_exists
protected function ensure_element_exists($element, $selectortype) { // Getting the behat selector & locator. list($selector, $locator) = $this->transform_selector($selectortype, $element); // Exception if it timesout and the element is still there. $msg = 'The "' . $element . '" element does not exist and should exist'; $exception = new ExpectationException($msg, $this->getSession()); // It will stop spinning once the find() method returns true. $this->spin( function($context, $args) { // We don't use behat_base::find as it is already spinning. if ($context->getSession()->getPage()->find($args['selector'], $args['locator'])) { return true; } return false; }, array('selector' => $selector, 'locator' => $locator), self::get_extended_timeout(), $exception, true ); }
php
protected function ensure_element_exists($element, $selectortype) { // Getting the behat selector & locator. list($selector, $locator) = $this->transform_selector($selectortype, $element); // Exception if it timesout and the element is still there. $msg = 'The "' . $element . '" element does not exist and should exist'; $exception = new ExpectationException($msg, $this->getSession()); // It will stop spinning once the find() method returns true. $this->spin( function($context, $args) { // We don't use behat_base::find as it is already spinning. if ($context->getSession()->getPage()->find($args['selector'], $args['locator'])) { return true; } return false; }, array('selector' => $selector, 'locator' => $locator), self::get_extended_timeout(), $exception, true ); }
[ "protected", "function", "ensure_element_exists", "(", "$", "element", ",", "$", "selectortype", ")", "{", "// Getting the behat selector & locator.", "list", "(", "$", "selector", ",", "$", "locator", ")", "=", "$", "this", "->", "transform_selector", "(", "$", "selectortype", ",", "$", "element", ")", ";", "// Exception if it timesout and the element is still there.", "$", "msg", "=", "'The \"'", ".", "$", "element", ".", "'\" element does not exist and should exist'", ";", "$", "exception", "=", "new", "ExpectationException", "(", "$", "msg", ",", "$", "this", "->", "getSession", "(", ")", ")", ";", "// It will stop spinning once the find() method returns true.", "$", "this", "->", "spin", "(", "function", "(", "$", "context", ",", "$", "args", ")", "{", "// We don't use behat_base::find as it is already spinning.", "if", "(", "$", "context", "->", "getSession", "(", ")", "->", "getPage", "(", ")", "->", "find", "(", "$", "args", "[", "'selector'", "]", ",", "$", "args", "[", "'locator'", "]", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}", ",", "array", "(", "'selector'", "=>", "$", "selector", ",", "'locator'", "=>", "$", "locator", ")", ",", "self", "::", "get_extended_timeout", "(", ")", ",", "$", "exception", ",", "true", ")", ";", "}" ]
Spins around an element until it exists @throws ExpectationException @param string $element @param string $selectortype @return void
[ "Spins", "around", "an", "element", "until", "it", "exists" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_base.php#L512-L536
215,679
moodle/moodle
lib/behat/behat_base.php
behat_base.ensure_node_is_visible
protected function ensure_node_is_visible($node) { if (!$this->running_javascript()) { return; } // Exception if it timesout and the element is still there. $msg = 'The "' . $node->getXPath() . '" xpath node is not visible and it should be visible'; $exception = new ExpectationException($msg, $this->getSession()); // It will stop spinning once the isVisible() method returns true. $this->spin( function($context, $args) { if ($args->isVisible()) { return true; } return false; }, $node, self::get_extended_timeout(), $exception, true ); }
php
protected function ensure_node_is_visible($node) { if (!$this->running_javascript()) { return; } // Exception if it timesout and the element is still there. $msg = 'The "' . $node->getXPath() . '" xpath node is not visible and it should be visible'; $exception = new ExpectationException($msg, $this->getSession()); // It will stop spinning once the isVisible() method returns true. $this->spin( function($context, $args) { if ($args->isVisible()) { return true; } return false; }, $node, self::get_extended_timeout(), $exception, true ); }
[ "protected", "function", "ensure_node_is_visible", "(", "$", "node", ")", "{", "if", "(", "!", "$", "this", "->", "running_javascript", "(", ")", ")", "{", "return", ";", "}", "// Exception if it timesout and the element is still there.", "$", "msg", "=", "'The \"'", ".", "$", "node", "->", "getXPath", "(", ")", ".", "'\" xpath node is not visible and it should be visible'", ";", "$", "exception", "=", "new", "ExpectationException", "(", "$", "msg", ",", "$", "this", "->", "getSession", "(", ")", ")", ";", "// It will stop spinning once the isVisible() method returns true.", "$", "this", "->", "spin", "(", "function", "(", "$", "context", ",", "$", "args", ")", "{", "if", "(", "$", "args", "->", "isVisible", "(", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}", ",", "$", "node", ",", "self", "::", "get_extended_timeout", "(", ")", ",", "$", "exception", ",", "true", ")", ";", "}" ]
Ensures that the provided node is visible and we can interact with it. @throws ExpectationException @param NodeElement $node @return void Throws an exception if it times out without the element being visible
[ "Ensures", "that", "the", "provided", "node", "is", "visible", "and", "we", "can", "interact", "with", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_base.php#L578-L601
215,680
moodle/moodle
lib/behat/behat_base.php
behat_base.ensure_node_attribute_is_set
protected function ensure_node_attribute_is_set($node, $attribute, $attributevalue) { if (!$this->running_javascript()) { return; } // Exception if it timesout and the element is still there. $msg = 'The "' . $node->getXPath() . '" xpath node is not visible and it should be visible'; $exception = new ExpectationException($msg, $this->getSession()); // It will stop spinning once the $args[1]) == $args[2], and method returns true. $this->spin( function($context, $args) { if ($args[0]->getAttribute($args[1]) == $args[2]) { return true; } return false; }, array($node, $attribute, $attributevalue), self::get_extended_timeout(), $exception, true ); }
php
protected function ensure_node_attribute_is_set($node, $attribute, $attributevalue) { if (!$this->running_javascript()) { return; } // Exception if it timesout and the element is still there. $msg = 'The "' . $node->getXPath() . '" xpath node is not visible and it should be visible'; $exception = new ExpectationException($msg, $this->getSession()); // It will stop spinning once the $args[1]) == $args[2], and method returns true. $this->spin( function($context, $args) { if ($args[0]->getAttribute($args[1]) == $args[2]) { return true; } return false; }, array($node, $attribute, $attributevalue), self::get_extended_timeout(), $exception, true ); }
[ "protected", "function", "ensure_node_attribute_is_set", "(", "$", "node", ",", "$", "attribute", ",", "$", "attributevalue", ")", "{", "if", "(", "!", "$", "this", "->", "running_javascript", "(", ")", ")", "{", "return", ";", "}", "// Exception if it timesout and the element is still there.", "$", "msg", "=", "'The \"'", ".", "$", "node", "->", "getXPath", "(", ")", ".", "'\" xpath node is not visible and it should be visible'", ";", "$", "exception", "=", "new", "ExpectationException", "(", "$", "msg", ",", "$", "this", "->", "getSession", "(", ")", ")", ";", "// It will stop spinning once the $args[1]) == $args[2], and method returns true.", "$", "this", "->", "spin", "(", "function", "(", "$", "context", ",", "$", "args", ")", "{", "if", "(", "$", "args", "[", "0", "]", "->", "getAttribute", "(", "$", "args", "[", "1", "]", ")", "==", "$", "args", "[", "2", "]", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}", ",", "array", "(", "$", "node", ",", "$", "attribute", ",", "$", "attributevalue", ")", ",", "self", "::", "get_extended_timeout", "(", ")", ",", "$", "exception", ",", "true", ")", ";", "}" ]
Ensures that the provided node has a attribute value set. This step can be used to check if specific JS has finished modifying the node. @throws ExpectationException @param NodeElement $node @param string $attribute attribute name @param string $attributevalue attribute value to check. @return void Throws an exception if it times out without the element being visible
[ "Ensures", "that", "the", "provided", "node", "has", "a", "attribute", "value", "set", ".", "This", "step", "can", "be", "used", "to", "check", "if", "specific", "JS", "has", "finished", "modifying", "the", "node", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_base.php#L613-L636
215,681
moodle/moodle
lib/behat/behat_base.php
behat_base.ensure_element_is_visible
protected function ensure_element_is_visible($element, $selectortype) { if (!$this->running_javascript()) { return; } $node = $this->get_selected_node($selectortype, $element); $this->ensure_node_is_visible($node); return $node; }
php
protected function ensure_element_is_visible($element, $selectortype) { if (!$this->running_javascript()) { return; } $node = $this->get_selected_node($selectortype, $element); $this->ensure_node_is_visible($node); return $node; }
[ "protected", "function", "ensure_element_is_visible", "(", "$", "element", ",", "$", "selectortype", ")", "{", "if", "(", "!", "$", "this", "->", "running_javascript", "(", ")", ")", "{", "return", ";", "}", "$", "node", "=", "$", "this", "->", "get_selected_node", "(", "$", "selectortype", ",", "$", "element", ")", ";", "$", "this", "->", "ensure_node_is_visible", "(", "$", "node", ")", ";", "return", "$", "node", ";", "}" ]
Ensures that the provided element is visible and we can interact with it. Returns the node in case other actions are interested in using it. @throws ExpectationException @param string $element @param string $selectortype @return NodeElement Throws an exception if it times out without being visible
[ "Ensures", "that", "the", "provided", "element", "is", "visible", "and", "we", "can", "interact", "with", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_base.php#L648-L658
215,682
moodle/moodle
lib/behat/behat_base.php
behat_base.wait_for_pending_js_in_session
public static function wait_for_pending_js_in_session(Session $session) { // We don't use behat_base::spin() here as we don't want to end up with an exception // if the page & JSs don't finish loading properly. for ($i = 0; $i < self::get_extended_timeout() * 10; $i++) { $pending = ''; try { $jscode = trim(preg_replace('/\s+/', ' ', ' return (function() { if (typeof M === "undefined") { if (document.readyState === "complete") { return ""; } else { return "incomplete"; } } else if (' . self::PAGE_READY_JS . ') { return ""; } else if (typeof M.util !== "undefined") { return M.util.pending_js.join(":"); } else { return "incomplete" } }());')); $pending = $session->evaluateScript($jscode); } catch (NoSuchWindow $nsw) { // We catch an exception here, in case we just closed the window we were interacting with. // No javascript is running if there is no window right? $pending = ''; } catch (UnknownError $e) { // M is not defined when the window or the frame don't exist anymore. if (strstr($e->getMessage(), 'M is not defined') != false) { $pending = ''; } } // If there are no pending JS we stop waiting. if ($pending === '') { return true; } // 0.1 seconds. usleep(100000); } // Timeout waiting for JS to complete. It will be caught and forwarded to behat_hooks::i_look_for_exceptions(). // It is unlikely that Javascript code of a page or an AJAX request needs more than get_extended_timeout() seconds // to be loaded, although when pages contains Javascript errors M.util.js_complete() can not be executed, so the // number of JS pending code and JS completed code will not match and we will reach this point. throw new \Exception('Javascript code and/or AJAX requests are not ready after ' . self::get_extended_timeout() . ' seconds. There is a Javascript error or the code is extremely slow. ' . 'If you are using a slow machine, consider setting $CFG->behat_increasetimeout.'); }
php
public static function wait_for_pending_js_in_session(Session $session) { // We don't use behat_base::spin() here as we don't want to end up with an exception // if the page & JSs don't finish loading properly. for ($i = 0; $i < self::get_extended_timeout() * 10; $i++) { $pending = ''; try { $jscode = trim(preg_replace('/\s+/', ' ', ' return (function() { if (typeof M === "undefined") { if (document.readyState === "complete") { return ""; } else { return "incomplete"; } } else if (' . self::PAGE_READY_JS . ') { return ""; } else if (typeof M.util !== "undefined") { return M.util.pending_js.join(":"); } else { return "incomplete" } }());')); $pending = $session->evaluateScript($jscode); } catch (NoSuchWindow $nsw) { // We catch an exception here, in case we just closed the window we were interacting with. // No javascript is running if there is no window right? $pending = ''; } catch (UnknownError $e) { // M is not defined when the window or the frame don't exist anymore. if (strstr($e->getMessage(), 'M is not defined') != false) { $pending = ''; } } // If there are no pending JS we stop waiting. if ($pending === '') { return true; } // 0.1 seconds. usleep(100000); } // Timeout waiting for JS to complete. It will be caught and forwarded to behat_hooks::i_look_for_exceptions(). // It is unlikely that Javascript code of a page or an AJAX request needs more than get_extended_timeout() seconds // to be loaded, although when pages contains Javascript errors M.util.js_complete() can not be executed, so the // number of JS pending code and JS completed code will not match and we will reach this point. throw new \Exception('Javascript code and/or AJAX requests are not ready after ' . self::get_extended_timeout() . ' seconds. There is a Javascript error or the code is extremely slow. ' . 'If you are using a slow machine, consider setting $CFG->behat_increasetimeout.'); }
[ "public", "static", "function", "wait_for_pending_js_in_session", "(", "Session", "$", "session", ")", "{", "// We don't use behat_base::spin() here as we don't want to end up with an exception", "// if the page & JSs don't finish loading properly.", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "self", "::", "get_extended_timeout", "(", ")", "*", "10", ";", "$", "i", "++", ")", "{", "$", "pending", "=", "''", ";", "try", "{", "$", "jscode", "=", "trim", "(", "preg_replace", "(", "'/\\s+/'", ",", "' '", ",", "'\n return (function() {\n if (typeof M === \"undefined\") {\n if (document.readyState === \"complete\") {\n return \"\";\n } else {\n return \"incomplete\";\n }\n } else if ('", ".", "self", "::", "PAGE_READY_JS", ".", "') {\n return \"\";\n } else if (typeof M.util !== \"undefined\") {\n return M.util.pending_js.join(\":\");\n } else {\n return \"incomplete\"\n }\n }());'", ")", ")", ";", "$", "pending", "=", "$", "session", "->", "evaluateScript", "(", "$", "jscode", ")", ";", "}", "catch", "(", "NoSuchWindow", "$", "nsw", ")", "{", "// We catch an exception here, in case we just closed the window we were interacting with.", "// No javascript is running if there is no window right?", "$", "pending", "=", "''", ";", "}", "catch", "(", "UnknownError", "$", "e", ")", "{", "// M is not defined when the window or the frame don't exist anymore.", "if", "(", "strstr", "(", "$", "e", "->", "getMessage", "(", ")", ",", "'M is not defined'", ")", "!=", "false", ")", "{", "$", "pending", "=", "''", ";", "}", "}", "// If there are no pending JS we stop waiting.", "if", "(", "$", "pending", "===", "''", ")", "{", "return", "true", ";", "}", "// 0.1 seconds.", "usleep", "(", "100000", ")", ";", "}", "// Timeout waiting for JS to complete. It will be caught and forwarded to behat_hooks::i_look_for_exceptions().", "// It is unlikely that Javascript code of a page or an AJAX request needs more than get_extended_timeout() seconds", "// to be loaded, although when pages contains Javascript errors M.util.js_complete() can not be executed, so the", "// number of JS pending code and JS completed code will not match and we will reach this point.", "throw", "new", "\\", "Exception", "(", "'Javascript code and/or AJAX requests are not ready after '", ".", "self", "::", "get_extended_timeout", "(", ")", ".", "' seconds. There is a Javascript error or the code is extremely slow. '", ".", "'If you are using a slow machine, consider setting $CFG->behat_increasetimeout.'", ")", ";", "}" ]
Waits for all the JS to be loaded. @param Session $session The Mink Session where JS can be run @return bool Whether any JS is still pending completion.
[ "Waits", "for", "all", "the", "JS", "to", "be", "loaded", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_base.php#L767-L818
215,683
moodle/moodle
lib/behat/behat_base.php
behat_base.execute
protected function execute($contextapi, $params = array()) { if (!is_array($params)) { $params = array($params); } // Get required context and execute the api. $contextapi = explode("::", $contextapi); $context = behat_context_helper::get($contextapi[0]); call_user_func_array(array($context, $contextapi[1]), $params); // NOTE: Wait for pending js and look for exception are not optional, as this might lead to unexpected results. // Don't make them optional for performance reasons. // Wait for pending js. $this->wait_for_pending_js(); // Look for exceptions. $this->look_for_exceptions(); }
php
protected function execute($contextapi, $params = array()) { if (!is_array($params)) { $params = array($params); } // Get required context and execute the api. $contextapi = explode("::", $contextapi); $context = behat_context_helper::get($contextapi[0]); call_user_func_array(array($context, $contextapi[1]), $params); // NOTE: Wait for pending js and look for exception are not optional, as this might lead to unexpected results. // Don't make them optional for performance reasons. // Wait for pending js. $this->wait_for_pending_js(); // Look for exceptions. $this->look_for_exceptions(); }
[ "protected", "function", "execute", "(", "$", "contextapi", ",", "$", "params", "=", "array", "(", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "params", ")", ")", "{", "$", "params", "=", "array", "(", "$", "params", ")", ";", "}", "// Get required context and execute the api.", "$", "contextapi", "=", "explode", "(", "\"::\"", ",", "$", "contextapi", ")", ";", "$", "context", "=", "behat_context_helper", "::", "get", "(", "$", "contextapi", "[", "0", "]", ")", ";", "call_user_func_array", "(", "array", "(", "$", "context", ",", "$", "contextapi", "[", "1", "]", ")", ",", "$", "params", ")", ";", "// NOTE: Wait for pending js and look for exception are not optional, as this might lead to unexpected results.", "// Don't make them optional for performance reasons.", "// Wait for pending js.", "$", "this", "->", "wait_for_pending_js", "(", ")", ";", "// Look for exceptions.", "$", "this", "->", "look_for_exceptions", "(", ")", ";", "}" ]
Helper function to execute api in a given context. @param string $contextapi context in which api is defined. @param array $params list of params to pass. @throws Exception
[ "Helper", "function", "to", "execute", "api", "in", "a", "given", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_base.php#L957-L975
215,684
moodle/moodle
lib/behat/behat_base.php
behat_base.js_trigger_click
protected function js_trigger_click($node) { if (!$this->running_javascript()) { $node->click(); } $this->ensure_node_is_visible($node); // Ensures hidden elements can't be clicked. $xpath = $node->getXpath(); $driver = $this->getSession()->getDriver(); if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) { $script = "Syn.click({{ELEMENT}})"; $driver->triggerSynScript($xpath, $script); } else { $driver->click($xpath); } }
php
protected function js_trigger_click($node) { if (!$this->running_javascript()) { $node->click(); } $this->ensure_node_is_visible($node); // Ensures hidden elements can't be clicked. $xpath = $node->getXpath(); $driver = $this->getSession()->getDriver(); if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) { $script = "Syn.click({{ELEMENT}})"; $driver->triggerSynScript($xpath, $script); } else { $driver->click($xpath); } }
[ "protected", "function", "js_trigger_click", "(", "$", "node", ")", "{", "if", "(", "!", "$", "this", "->", "running_javascript", "(", ")", ")", "{", "$", "node", "->", "click", "(", ")", ";", "}", "$", "this", "->", "ensure_node_is_visible", "(", "$", "node", ")", ";", "// Ensures hidden elements can't be clicked.", "$", "xpath", "=", "$", "node", "->", "getXpath", "(", ")", ";", "$", "driver", "=", "$", "this", "->", "getSession", "(", ")", "->", "getDriver", "(", ")", ";", "if", "(", "$", "driver", "instanceof", "\\", "Moodle", "\\", "BehatExtension", "\\", "Driver", "\\", "MoodleSelenium2Driver", ")", "{", "$", "script", "=", "\"Syn.click({{ELEMENT}})\"", ";", "$", "driver", "->", "triggerSynScript", "(", "$", "xpath", ",", "$", "script", ")", ";", "}", "else", "{", "$", "driver", "->", "click", "(", "$", "xpath", ")", ";", "}", "}" ]
Trigger click on node via javascript instead of actually clicking on it via pointer. This function resolves the issue of nested elements with click listeners or links - in these cases clicking via the pointer may accidentally cause a click on the wrong element. Example of issue: clicking to expand navigation nodes when the config value linkadmincategories is enabled. @param NodeElement $node
[ "Trigger", "click", "on", "node", "via", "javascript", "instead", "of", "actually", "clicking", "on", "it", "via", "pointer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_base.php#L1032-L1045
215,685
moodle/moodle
lib/behat/behat_base.php
behat_base.get_real_timeout
protected static function get_real_timeout(int $timeout) : int { global $CFG; if (!empty($CFG->behat_increasetimeout)) { return $timeout * $CFG->behat_increasetimeout; } else { return $timeout; } }
php
protected static function get_real_timeout(int $timeout) : int { global $CFG; if (!empty($CFG->behat_increasetimeout)) { return $timeout * $CFG->behat_increasetimeout; } else { return $timeout; } }
[ "protected", "static", "function", "get_real_timeout", "(", "int", "$", "timeout", ")", ":", "int", "{", "global", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "behat_increasetimeout", ")", ")", "{", "return", "$", "timeout", "*", "$", "CFG", "->", "behat_increasetimeout", ";", "}", "else", "{", "return", "$", "timeout", ";", "}", "}" ]
Gets the required timeout in seconds. @param int $timeout One of the TIMEOUT constants @return int Actual timeout (in seconds)
[ "Gets", "the", "required", "timeout", "in", "seconds", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_base.php#L1053-L1060
215,686
moodle/moodle
customfield/classes/privacy/provider.php
provider.get_customfields_data_contexts
public static function get_customfields_data_contexts(string $component, string $area, string $itemidstest = 'IS NOT NULL', string $instanceidstest = 'IS NOT NULL', array $params = []) : contextlist { $sql = "SELECT d.contextid FROM {customfield_category} c JOIN {customfield_field} f ON f.categoryid = c.id JOIN {customfield_data} d ON d.fieldid = f.id AND d.instanceid $instanceidstest WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest"; $contextlist = new contextlist(); $contextlist->add_from_sql($sql, self::get_params($component, $area, $params)); return $contextlist; }
php
public static function get_customfields_data_contexts(string $component, string $area, string $itemidstest = 'IS NOT NULL', string $instanceidstest = 'IS NOT NULL', array $params = []) : contextlist { $sql = "SELECT d.contextid FROM {customfield_category} c JOIN {customfield_field} f ON f.categoryid = c.id JOIN {customfield_data} d ON d.fieldid = f.id AND d.instanceid $instanceidstest WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest"; $contextlist = new contextlist(); $contextlist->add_from_sql($sql, self::get_params($component, $area, $params)); return $contextlist; }
[ "public", "static", "function", "get_customfields_data_contexts", "(", "string", "$", "component", ",", "string", "$", "area", ",", "string", "$", "itemidstest", "=", "'IS NOT NULL'", ",", "string", "$", "instanceidstest", "=", "'IS NOT NULL'", ",", "array", "$", "params", "=", "[", "]", ")", ":", "contextlist", "{", "$", "sql", "=", "\"SELECT d.contextid FROM {customfield_category} c\n JOIN {customfield_field} f ON f.categoryid = c.id\n JOIN {customfield_data} d ON d.fieldid = f.id AND d.instanceid $instanceidstest\n WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest\"", ";", "$", "contextlist", "=", "new", "contextlist", "(", ")", ";", "$", "contextlist", "->", "add_from_sql", "(", "$", "sql", ",", "self", "::", "get_params", "(", "$", "component", ",", "$", "area", ",", "$", "params", ")", ")", ";", "return", "$", "contextlist", ";", "}" ]
Returns contexts that have customfields data To be used in implementations of core_user_data_provider::get_contexts_for_userid Caller needs to transfer the $userid to the select subqueries for customfield_category->itemid and/or customfield_data->instanceid @param string $component @param string $area @param string $itemidstest subquery for selecting customfield_category->itemid @param string $instanceidstest subquery for selecting customfield_data->instanceid @param array $params array of named parameters @return contextlist
[ "Returns", "contexts", "that", "have", "customfields", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/privacy/provider.php#L105-L117
215,687
moodle/moodle
customfield/classes/privacy/provider.php
provider.export_customfields_data
public static function export_customfields_data(approved_contextlist $contextlist, string $component, string $area, string $itemidstest = 'IS NOT NULL', string $instanceidstest = 'IS NOT NULL', array $params = [], array $subcontext = null) { global $DB; // This query is very similar to api::get_instances_fields_data() but also works for multiple itemids // and has a context filter. list($contextidstest, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED, 'cfctx'); $sql = "SELECT d.*, f.type AS fieldtype, f.name as fieldname, f.shortname as fieldshortname, c.itemid FROM {customfield_category} c JOIN {customfield_field} f ON f.categoryid = c.id JOIN {customfield_data} d ON d.fieldid = f.id AND d.instanceid $instanceidstest AND d.contextid $contextidstest WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest ORDER BY c.itemid, c.sortorder, f.sortorder"; $params = self::get_params($component, $area, $params) + $contextparams; $records = $DB->get_recordset_sql($sql, $params); if ($subcontext === null) { $subcontext = [get_string('customfielddata', 'core_customfield')]; } /** @var handler $handler */ $handler = null; $fields = null; foreach ($records as $record) { if (!$handler || $handler->get_itemid() != $record->itemid) { $handler = handler::get_handler($component, $area, $record->itemid); $fields = $handler->get_fields(); } $field = (object)['type' => $record->fieldtype, 'shortname' => $record->fieldshortname, 'name' => $record->fieldname]; unset($record->itemid, $record->fieldtype, $record->fieldshortname, $record->fieldname); try { $field = array_key_exists($record->fieldid, $fields) ? $fields[$record->fieldid] : null; $data = data_controller::create(0, $record, $field); self::export_customfield_data($data, array_merge($subcontext, [$record->id])); } catch (Exception $e) { // We store some data that we can not initialise controller for. We still need to export it. self::export_customfield_data_unknown($record, $field, array_merge($subcontext, [$record->id])); } } $records->close(); }
php
public static function export_customfields_data(approved_contextlist $contextlist, string $component, string $area, string $itemidstest = 'IS NOT NULL', string $instanceidstest = 'IS NOT NULL', array $params = [], array $subcontext = null) { global $DB; // This query is very similar to api::get_instances_fields_data() but also works for multiple itemids // and has a context filter. list($contextidstest, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED, 'cfctx'); $sql = "SELECT d.*, f.type AS fieldtype, f.name as fieldname, f.shortname as fieldshortname, c.itemid FROM {customfield_category} c JOIN {customfield_field} f ON f.categoryid = c.id JOIN {customfield_data} d ON d.fieldid = f.id AND d.instanceid $instanceidstest AND d.contextid $contextidstest WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest ORDER BY c.itemid, c.sortorder, f.sortorder"; $params = self::get_params($component, $area, $params) + $contextparams; $records = $DB->get_recordset_sql($sql, $params); if ($subcontext === null) { $subcontext = [get_string('customfielddata', 'core_customfield')]; } /** @var handler $handler */ $handler = null; $fields = null; foreach ($records as $record) { if (!$handler || $handler->get_itemid() != $record->itemid) { $handler = handler::get_handler($component, $area, $record->itemid); $fields = $handler->get_fields(); } $field = (object)['type' => $record->fieldtype, 'shortname' => $record->fieldshortname, 'name' => $record->fieldname]; unset($record->itemid, $record->fieldtype, $record->fieldshortname, $record->fieldname); try { $field = array_key_exists($record->fieldid, $fields) ? $fields[$record->fieldid] : null; $data = data_controller::create(0, $record, $field); self::export_customfield_data($data, array_merge($subcontext, [$record->id])); } catch (Exception $e) { // We store some data that we can not initialise controller for. We still need to export it. self::export_customfield_data_unknown($record, $field, array_merge($subcontext, [$record->id])); } } $records->close(); }
[ "public", "static", "function", "export_customfields_data", "(", "approved_contextlist", "$", "contextlist", ",", "string", "$", "component", ",", "string", "$", "area", ",", "string", "$", "itemidstest", "=", "'IS NOT NULL'", ",", "string", "$", "instanceidstest", "=", "'IS NOT NULL'", ",", "array", "$", "params", "=", "[", "]", ",", "array", "$", "subcontext", "=", "null", ")", "{", "global", "$", "DB", ";", "// This query is very similar to api::get_instances_fields_data() but also works for multiple itemids", "// and has a context filter.", "list", "(", "$", "contextidstest", ",", "$", "contextparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "contextlist", "->", "get_contextids", "(", ")", ",", "SQL_PARAMS_NAMED", ",", "'cfctx'", ")", ";", "$", "sql", "=", "\"SELECT d.*, f.type AS fieldtype, f.name as fieldname, f.shortname as fieldshortname, c.itemid\n FROM {customfield_category} c\n JOIN {customfield_field} f ON f.categoryid = c.id\n JOIN {customfield_data} d ON d.fieldid = f.id AND d.instanceid $instanceidstest AND d.contextid $contextidstest\n WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest\n ORDER BY c.itemid, c.sortorder, f.sortorder\"", ";", "$", "params", "=", "self", "::", "get_params", "(", "$", "component", ",", "$", "area", ",", "$", "params", ")", "+", "$", "contextparams", ";", "$", "records", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "if", "(", "$", "subcontext", "===", "null", ")", "{", "$", "subcontext", "=", "[", "get_string", "(", "'customfielddata'", ",", "'core_customfield'", ")", "]", ";", "}", "/** @var handler $handler */", "$", "handler", "=", "null", ";", "$", "fields", "=", "null", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "if", "(", "!", "$", "handler", "||", "$", "handler", "->", "get_itemid", "(", ")", "!=", "$", "record", "->", "itemid", ")", "{", "$", "handler", "=", "handler", "::", "get_handler", "(", "$", "component", ",", "$", "area", ",", "$", "record", "->", "itemid", ")", ";", "$", "fields", "=", "$", "handler", "->", "get_fields", "(", ")", ";", "}", "$", "field", "=", "(", "object", ")", "[", "'type'", "=>", "$", "record", "->", "fieldtype", ",", "'shortname'", "=>", "$", "record", "->", "fieldshortname", ",", "'name'", "=>", "$", "record", "->", "fieldname", "]", ";", "unset", "(", "$", "record", "->", "itemid", ",", "$", "record", "->", "fieldtype", ",", "$", "record", "->", "fieldshortname", ",", "$", "record", "->", "fieldname", ")", ";", "try", "{", "$", "field", "=", "array_key_exists", "(", "$", "record", "->", "fieldid", ",", "$", "fields", ")", "?", "$", "fields", "[", "$", "record", "->", "fieldid", "]", ":", "null", ";", "$", "data", "=", "data_controller", "::", "create", "(", "0", ",", "$", "record", ",", "$", "field", ")", ";", "self", "::", "export_customfield_data", "(", "$", "data", ",", "array_merge", "(", "$", "subcontext", ",", "[", "$", "record", "->", "id", "]", ")", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// We store some data that we can not initialise controller for. We still need to export it.", "self", "::", "export_customfield_data_unknown", "(", "$", "record", ",", "$", "field", ",", "array_merge", "(", "$", "subcontext", ",", "[", "$", "record", "->", "id", "]", ")", ")", ";", "}", "}", "$", "records", "->", "close", "(", ")", ";", "}" ]
Exports customfields data To be used in implementations of core_user_data_provider::export_user_data Caller needs to transfer the $userid to the select subqueries for customfield_category->itemid and/or customfield_data->instanceid @param approved_contextlist $contextlist @param string $component @param string $area @param string $itemidstest subquery for selecting customfield_category->itemid @param string $instanceidstest subquery for selecting customfield_data->instanceid @param array $params array of named parameters for itemidstest and instanceidstest subqueries @param array $subcontext subcontext to use in context_writer::export_data, if null (default) the "Custom fields data" will be used; the data id will be appended to the subcontext array.
[ "Exports", "customfields", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/privacy/provider.php#L164-L205
215,688
moodle/moodle
customfield/classes/privacy/provider.php
provider.delete_customfields_data
public static function delete_customfields_data(approved_contextlist $contextlist, string $component, string $area, string $itemidstest = 'IS NOT NULL', string $instanceidstest = 'IS NOT NULL', array $params = []) { global $DB; list($contextidstest, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED, 'cfctx'); $sql = "SELECT d.id FROM {customfield_category} c JOIN {customfield_field} f ON f.categoryid = c.id JOIN {customfield_data} d ON d.fieldid = f.id AND d.instanceid $instanceidstest AND d.contextid $contextidstest WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest"; $params = self::get_params($component, $area, $params) + $contextparams; self::before_delete_data('IN (' . $sql . ') ', $params); $DB->execute("DELETE FROM {customfield_data} WHERE instanceid $instanceidstest AND contextid $contextidstest AND fieldid IN (SELECT f.id FROM {customfield_category} c JOIN {customfield_field} f ON f.categoryid = c.id WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest)", $params); }
php
public static function delete_customfields_data(approved_contextlist $contextlist, string $component, string $area, string $itemidstest = 'IS NOT NULL', string $instanceidstest = 'IS NOT NULL', array $params = []) { global $DB; list($contextidstest, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED, 'cfctx'); $sql = "SELECT d.id FROM {customfield_category} c JOIN {customfield_field} f ON f.categoryid = c.id JOIN {customfield_data} d ON d.fieldid = f.id AND d.instanceid $instanceidstest AND d.contextid $contextidstest WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest"; $params = self::get_params($component, $area, $params) + $contextparams; self::before_delete_data('IN (' . $sql . ') ', $params); $DB->execute("DELETE FROM {customfield_data} WHERE instanceid $instanceidstest AND contextid $contextidstest AND fieldid IN (SELECT f.id FROM {customfield_category} c JOIN {customfield_field} f ON f.categoryid = c.id WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest)", $params); }
[ "public", "static", "function", "delete_customfields_data", "(", "approved_contextlist", "$", "contextlist", ",", "string", "$", "component", ",", "string", "$", "area", ",", "string", "$", "itemidstest", "=", "'IS NOT NULL'", ",", "string", "$", "instanceidstest", "=", "'IS NOT NULL'", ",", "array", "$", "params", "=", "[", "]", ")", "{", "global", "$", "DB", ";", "list", "(", "$", "contextidstest", ",", "$", "contextparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "contextlist", "->", "get_contextids", "(", ")", ",", "SQL_PARAMS_NAMED", ",", "'cfctx'", ")", ";", "$", "sql", "=", "\"SELECT d.id\n FROM {customfield_category} c\n JOIN {customfield_field} f ON f.categoryid = c.id\n JOIN {customfield_data} d ON d.fieldid = f.id AND d.instanceid $instanceidstest AND d.contextid $contextidstest\n WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest\"", ";", "$", "params", "=", "self", "::", "get_params", "(", "$", "component", ",", "$", "area", ",", "$", "params", ")", "+", "$", "contextparams", ";", "self", "::", "before_delete_data", "(", "'IN ('", ".", "$", "sql", ".", "') '", ",", "$", "params", ")", ";", "$", "DB", "->", "execute", "(", "\"DELETE FROM {customfield_data}\n WHERE instanceid $instanceidstest\n AND contextid $contextidstest\n AND fieldid IN (SELECT f.id\n FROM {customfield_category} c\n JOIN {customfield_field} f ON f.categoryid = c.id\n WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest)\"", ",", "$", "params", ")", ";", "}" ]
Deletes customfields data To be used in implementations of core_user_data_provider::delete_data_for_user Caller needs to transfer the $userid to the select subqueries for customfield_category->itemid and/or customfield_data->instanceid @param approved_contextlist $contextlist @param string $component @param string $area @param string $itemidstest subquery for selecting customfield_category->itemid @param string $instanceidstest subquery for selecting customfield_data->instanceid @param array $params array of named parameters for itemidstest and instanceidstest subqueries
[ "Deletes", "customfields", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/privacy/provider.php#L221-L242
215,689
moodle/moodle
customfield/classes/privacy/provider.php
provider.delete_customfields_data_for_context
public static function delete_customfields_data_for_context(string $component, string $area, \context $context) { global $DB; $sql = "SELECT d.id FROM {customfield_category} c JOIN {customfield_field} f ON f.categoryid = c.id JOIN {customfield_data} d ON d.fieldid = f.id JOIN {context} ctx ON ctx.id = d.contextid AND ctx.path LIKE :ctxpath WHERE c.component = :cfcomponent AND c.area = :cfarea"; $params = self::get_params($component, $area, ['ctxpath' => $context->path . '%']); self::before_delete_data('IN (' . $sql . ') ', $params); $DB->execute("DELETE FROM {customfield_data} WHERE fieldid IN (SELECT f.id FROM {customfield_category} c JOIN {customfield_field} f ON f.categoryid = c.id WHERE c.component = :cfcomponent AND c.area = :cfarea) AND contextid IN (SELECT id FROM {context} WHERE path LIKE :ctxpath)", $params); }
php
public static function delete_customfields_data_for_context(string $component, string $area, \context $context) { global $DB; $sql = "SELECT d.id FROM {customfield_category} c JOIN {customfield_field} f ON f.categoryid = c.id JOIN {customfield_data} d ON d.fieldid = f.id JOIN {context} ctx ON ctx.id = d.contextid AND ctx.path LIKE :ctxpath WHERE c.component = :cfcomponent AND c.area = :cfarea"; $params = self::get_params($component, $area, ['ctxpath' => $context->path . '%']); self::before_delete_data('IN (' . $sql . ') ', $params); $DB->execute("DELETE FROM {customfield_data} WHERE fieldid IN (SELECT f.id FROM {customfield_category} c JOIN {customfield_field} f ON f.categoryid = c.id WHERE c.component = :cfcomponent AND c.area = :cfarea) AND contextid IN (SELECT id FROM {context} WHERE path LIKE :ctxpath)", $params); }
[ "public", "static", "function", "delete_customfields_data_for_context", "(", "string", "$", "component", ",", "string", "$", "area", ",", "\\", "context", "$", "context", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT d.id\n FROM {customfield_category} c\n JOIN {customfield_field} f ON f.categoryid = c.id\n JOIN {customfield_data} d ON d.fieldid = f.id\n JOIN {context} ctx ON ctx.id = d.contextid AND ctx.path LIKE :ctxpath\n WHERE c.component = :cfcomponent AND c.area = :cfarea\"", ";", "$", "params", "=", "self", "::", "get_params", "(", "$", "component", ",", "$", "area", ",", "[", "'ctxpath'", "=>", "$", "context", "->", "path", ".", "'%'", "]", ")", ";", "self", "::", "before_delete_data", "(", "'IN ('", ".", "$", "sql", ".", "') '", ",", "$", "params", ")", ";", "$", "DB", "->", "execute", "(", "\"DELETE FROM {customfield_data}\n WHERE fieldid IN (SELECT f.id\n FROM {customfield_category} c\n JOIN {customfield_field} f ON f.categoryid = c.id\n WHERE c.component = :cfcomponent AND c.area = :cfarea)\n AND contextid IN (SELECT id FROM {context} WHERE path LIKE :ctxpath)\"", ",", "$", "params", ")", ";", "}" ]
Deletes all customfields data for the given context To be used in implementations of core_user_data_provider::delete_data_for_all_users_in_context @param string $component @param string $area @param \context $context
[ "Deletes", "all", "customfields", "data", "for", "the", "given", "context" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/privacy/provider.php#L303-L323
215,690
moodle/moodle
customfield/classes/privacy/provider.php
provider.delete_categories
protected static function delete_categories(array $contextids, array $categoriesids) { global $DB; if (!$categoriesids) { return; } list($categoryidstest, $catparams) = $DB->get_in_or_equal($categoriesids, SQL_PARAMS_NAMED, 'cfcat'); $datasql = "SELECT d.id FROM {customfield_data} d JOIN {customfield_field} f ON f.id = d.fieldid " . "WHERE f.categoryid $categoryidstest"; $fieldsql = "SELECT f.id AS fieldid FROM {customfield_field} f WHERE f.categoryid $categoryidstest"; self::before_delete_data("IN ($datasql)", $catparams); self::before_delete_fields($categoryidstest, $catparams); $DB->execute('DELETE FROM {customfield_data} WHERE fieldid IN (' . $fieldsql . ')', $catparams); $DB->execute("DELETE FROM {customfield_field} WHERE categoryid $categoryidstest", $catparams); $DB->execute("DELETE FROM {customfield_category} WHERE id $categoryidstest", $catparams); }
php
protected static function delete_categories(array $contextids, array $categoriesids) { global $DB; if (!$categoriesids) { return; } list($categoryidstest, $catparams) = $DB->get_in_or_equal($categoriesids, SQL_PARAMS_NAMED, 'cfcat'); $datasql = "SELECT d.id FROM {customfield_data} d JOIN {customfield_field} f ON f.id = d.fieldid " . "WHERE f.categoryid $categoryidstest"; $fieldsql = "SELECT f.id AS fieldid FROM {customfield_field} f WHERE f.categoryid $categoryidstest"; self::before_delete_data("IN ($datasql)", $catparams); self::before_delete_fields($categoryidstest, $catparams); $DB->execute('DELETE FROM {customfield_data} WHERE fieldid IN (' . $fieldsql . ')', $catparams); $DB->execute("DELETE FROM {customfield_field} WHERE categoryid $categoryidstest", $catparams); $DB->execute("DELETE FROM {customfield_category} WHERE id $categoryidstest", $catparams); }
[ "protected", "static", "function", "delete_categories", "(", "array", "$", "contextids", ",", "array", "$", "categoriesids", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "$", "categoriesids", ")", "{", "return", ";", "}", "list", "(", "$", "categoryidstest", ",", "$", "catparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "categoriesids", ",", "SQL_PARAMS_NAMED", ",", "'cfcat'", ")", ";", "$", "datasql", "=", "\"SELECT d.id FROM {customfield_data} d JOIN {customfield_field} f ON f.id = d.fieldid \"", ".", "\"WHERE f.categoryid $categoryidstest\"", ";", "$", "fieldsql", "=", "\"SELECT f.id AS fieldid FROM {customfield_field} f WHERE f.categoryid $categoryidstest\"", ";", "self", "::", "before_delete_data", "(", "\"IN ($datasql)\"", ",", "$", "catparams", ")", ";", "self", "::", "before_delete_fields", "(", "$", "categoryidstest", ",", "$", "catparams", ")", ";", "$", "DB", "->", "execute", "(", "'DELETE FROM {customfield_data} WHERE fieldid IN ('", ".", "$", "fieldsql", ".", "')'", ",", "$", "catparams", ")", ";", "$", "DB", "->", "execute", "(", "\"DELETE FROM {customfield_field} WHERE categoryid $categoryidstest\"", ",", "$", "catparams", ")", ";", "$", "DB", "->", "execute", "(", "\"DELETE FROM {customfield_category} WHERE id $categoryidstest\"", ",", "$", "catparams", ")", ";", "}" ]
Delete custom fields categories configurations, all their fields and data @param array $contextids @param array $categoriesids
[ "Delete", "custom", "fields", "categories", "configurations", "all", "their", "fields", "and", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/privacy/provider.php#L348-L367
215,691
moodle/moodle
customfield/classes/privacy/provider.php
provider.export_customfield_data
public static function export_customfield_data(data_controller $data, array $subcontext) { $context = $data->get_context(); $exportdata = $data->to_record(); $exportdata->fieldtype = $data->get_field()->get('type'); $exportdata->fieldshortname = $data->get_field()->get('shortname'); $exportdata->fieldname = $data->get_field()->get_formatted_name(); $exportdata->timecreated = \core_privacy\local\request\transform::datetime($exportdata->timecreated); $exportdata->timemodified = \core_privacy\local\request\transform::datetime($exportdata->timemodified); unset($exportdata->contextid); // Use the "export_value" by default for the 'value' attribute, however the plugins may override it in their callback. $exportdata->value = $data->export_value(); $classname = manager::get_provider_classname_for_component('customfield_' . $data->get_field()->get('type')); if (class_exists($classname) && is_subclass_of($classname, customfield_provider::class)) { component_class_callback($classname, 'export_customfield_data', [$data, $exportdata, $subcontext]); } else { // Custom field plugin does not implement customfield_provider, just export default value. writer::with_context($context)->export_data($subcontext, $exportdata); } }
php
public static function export_customfield_data(data_controller $data, array $subcontext) { $context = $data->get_context(); $exportdata = $data->to_record(); $exportdata->fieldtype = $data->get_field()->get('type'); $exportdata->fieldshortname = $data->get_field()->get('shortname'); $exportdata->fieldname = $data->get_field()->get_formatted_name(); $exportdata->timecreated = \core_privacy\local\request\transform::datetime($exportdata->timecreated); $exportdata->timemodified = \core_privacy\local\request\transform::datetime($exportdata->timemodified); unset($exportdata->contextid); // Use the "export_value" by default for the 'value' attribute, however the plugins may override it in their callback. $exportdata->value = $data->export_value(); $classname = manager::get_provider_classname_for_component('customfield_' . $data->get_field()->get('type')); if (class_exists($classname) && is_subclass_of($classname, customfield_provider::class)) { component_class_callback($classname, 'export_customfield_data', [$data, $exportdata, $subcontext]); } else { // Custom field plugin does not implement customfield_provider, just export default value. writer::with_context($context)->export_data($subcontext, $exportdata); } }
[ "public", "static", "function", "export_customfield_data", "(", "data_controller", "$", "data", ",", "array", "$", "subcontext", ")", "{", "$", "context", "=", "$", "data", "->", "get_context", "(", ")", ";", "$", "exportdata", "=", "$", "data", "->", "to_record", "(", ")", ";", "$", "exportdata", "->", "fieldtype", "=", "$", "data", "->", "get_field", "(", ")", "->", "get", "(", "'type'", ")", ";", "$", "exportdata", "->", "fieldshortname", "=", "$", "data", "->", "get_field", "(", ")", "->", "get", "(", "'shortname'", ")", ";", "$", "exportdata", "->", "fieldname", "=", "$", "data", "->", "get_field", "(", ")", "->", "get_formatted_name", "(", ")", ";", "$", "exportdata", "->", "timecreated", "=", "\\", "core_privacy", "\\", "local", "\\", "request", "\\", "transform", "::", "datetime", "(", "$", "exportdata", "->", "timecreated", ")", ";", "$", "exportdata", "->", "timemodified", "=", "\\", "core_privacy", "\\", "local", "\\", "request", "\\", "transform", "::", "datetime", "(", "$", "exportdata", "->", "timemodified", ")", ";", "unset", "(", "$", "exportdata", "->", "contextid", ")", ";", "// Use the \"export_value\" by default for the 'value' attribute, however the plugins may override it in their callback.", "$", "exportdata", "->", "value", "=", "$", "data", "->", "export_value", "(", ")", ";", "$", "classname", "=", "manager", "::", "get_provider_classname_for_component", "(", "'customfield_'", ".", "$", "data", "->", "get_field", "(", ")", "->", "get", "(", "'type'", ")", ")", ";", "if", "(", "class_exists", "(", "$", "classname", ")", "&&", "is_subclass_of", "(", "$", "classname", ",", "customfield_provider", "::", "class", ")", ")", "{", "component_class_callback", "(", "$", "classname", ",", "'export_customfield_data'", ",", "[", "$", "data", ",", "$", "exportdata", ",", "$", "subcontext", "]", ")", ";", "}", "else", "{", "// Custom field plugin does not implement customfield_provider, just export default value.", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "$", "subcontext", ",", "$", "exportdata", ")", ";", "}", "}" ]
Exports one instance of custom field data @param data_controller $data @param array $subcontext subcontext to pass to content_writer::export_data
[ "Exports", "one", "instance", "of", "custom", "field", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/privacy/provider.php#L451-L471
215,692
moodle/moodle
customfield/classes/privacy/provider.php
provider.export_customfield_data_unknown
protected static function export_customfield_data_unknown(\stdClass $record, \stdClass $field, array $subcontext) { $context = \context::instance_by_id($record->contextid); $record->fieldtype = $field->type; $record->fieldshortname = $field->shortname; $record->fieldname = format_string($field->name); $record->timecreated = \core_privacy\local\request\transform::datetime($record->timecreated); $record->timemodified = \core_privacy\local\request\transform::datetime($record->timemodified); unset($record->contextid); $record->value = format_text($record->value, $record->valueformat, ['context' => $context]); writer::with_context($context)->export_data($subcontext, $record); }
php
protected static function export_customfield_data_unknown(\stdClass $record, \stdClass $field, array $subcontext) { $context = \context::instance_by_id($record->contextid); $record->fieldtype = $field->type; $record->fieldshortname = $field->shortname; $record->fieldname = format_string($field->name); $record->timecreated = \core_privacy\local\request\transform::datetime($record->timecreated); $record->timemodified = \core_privacy\local\request\transform::datetime($record->timemodified); unset($record->contextid); $record->value = format_text($record->value, $record->valueformat, ['context' => $context]); writer::with_context($context)->export_data($subcontext, $record); }
[ "protected", "static", "function", "export_customfield_data_unknown", "(", "\\", "stdClass", "$", "record", ",", "\\", "stdClass", "$", "field", ",", "array", "$", "subcontext", ")", "{", "$", "context", "=", "\\", "context", "::", "instance_by_id", "(", "$", "record", "->", "contextid", ")", ";", "$", "record", "->", "fieldtype", "=", "$", "field", "->", "type", ";", "$", "record", "->", "fieldshortname", "=", "$", "field", "->", "shortname", ";", "$", "record", "->", "fieldname", "=", "format_string", "(", "$", "field", "->", "name", ")", ";", "$", "record", "->", "timecreated", "=", "\\", "core_privacy", "\\", "local", "\\", "request", "\\", "transform", "::", "datetime", "(", "$", "record", "->", "timecreated", ")", ";", "$", "record", "->", "timemodified", "=", "\\", "core_privacy", "\\", "local", "\\", "request", "\\", "transform", "::", "datetime", "(", "$", "record", "->", "timemodified", ")", ";", "unset", "(", "$", "record", "->", "contextid", ")", ";", "$", "record", "->", "value", "=", "format_text", "(", "$", "record", "->", "value", ",", "$", "record", "->", "valueformat", ",", "[", "'context'", "=>", "$", "context", "]", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "$", "subcontext", ",", "$", "record", ")", ";", "}" ]
Export data record of unknown type when we were not able to create instance of data_controller @param \stdClass $record record from db table {customfield_data} @param \stdClass $field field record with at least fields type, shortname, name @param array $subcontext
[ "Export", "data", "record", "of", "unknown", "type", "when", "we", "were", "not", "able", "to", "create", "instance", "of", "data_controller" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/privacy/provider.php#L480-L491
215,693
moodle/moodle
admin/tool/dataprivacy/classes/data_request.php
data_request.is_expired
public static function is_expired(data_request $request) { $result = false; // Only export requests expire. if ($request->get('type') == api::DATAREQUEST_TYPE_EXPORT) { switch ($request->get('status')) { // Expired requests are obviously expired. case api::DATAREQUEST_STATUS_EXPIRED: $result = true; break; // Complete requests are expired if the expiry time has elapsed. case api::DATAREQUEST_STATUS_DOWNLOAD_READY: $expiryseconds = get_config('tool_dataprivacy', 'privacyrequestexpiry'); if ($expiryseconds > 0 && time() >= ($request->get('timemodified') + $expiryseconds)) { $result = true; } break; } } return $result; }
php
public static function is_expired(data_request $request) { $result = false; // Only export requests expire. if ($request->get('type') == api::DATAREQUEST_TYPE_EXPORT) { switch ($request->get('status')) { // Expired requests are obviously expired. case api::DATAREQUEST_STATUS_EXPIRED: $result = true; break; // Complete requests are expired if the expiry time has elapsed. case api::DATAREQUEST_STATUS_DOWNLOAD_READY: $expiryseconds = get_config('tool_dataprivacy', 'privacyrequestexpiry'); if ($expiryseconds > 0 && time() >= ($request->get('timemodified') + $expiryseconds)) { $result = true; } break; } } return $result; }
[ "public", "static", "function", "is_expired", "(", "data_request", "$", "request", ")", "{", "$", "result", "=", "false", ";", "// Only export requests expire.", "if", "(", "$", "request", "->", "get", "(", "'type'", ")", "==", "api", "::", "DATAREQUEST_TYPE_EXPORT", ")", "{", "switch", "(", "$", "request", "->", "get", "(", "'status'", ")", ")", "{", "// Expired requests are obviously expired.", "case", "api", "::", "DATAREQUEST_STATUS_EXPIRED", ":", "$", "result", "=", "true", ";", "break", ";", "// Complete requests are expired if the expiry time has elapsed.", "case", "api", "::", "DATAREQUEST_STATUS_DOWNLOAD_READY", ":", "$", "expiryseconds", "=", "get_config", "(", "'tool_dataprivacy'", ",", "'privacyrequestexpiry'", ")", ";", "if", "(", "$", "expiryseconds", ">", "0", "&&", "time", "(", ")", ">=", "(", "$", "request", "->", "get", "(", "'timemodified'", ")", "+", "$", "expiryseconds", ")", ")", "{", "$", "result", "=", "true", ";", "}", "break", ";", "}", "}", "return", "$", "result", ";", "}" ]
Determines whether a completed data export request has expired. The response will be valid regardless of the expiry scheduled task having run. @param data_request $request the data request object whose expiry will be checked. @return bool true if the request has expired.
[ "Determines", "whether", "a", "completed", "data", "export", "request", "has", "expired", ".", "The", "response", "will", "be", "valid", "regardless", "of", "the", "expiry", "scheduled", "task", "having", "run", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/data_request.php#L139-L160
215,694
moodle/moodle
admin/tool/dataprivacy/classes/data_request.php
data_request.get_expired_requests
public static function get_expired_requests($userid = 0) { global $DB; $expiryseconds = get_config('tool_dataprivacy', 'privacyrequestexpiry'); $expirytime = strtotime("-{$expiryseconds} second"); $table = self::TABLE; $sqlwhere = 'type = :export_type AND status = :completestatus AND timemodified <= :expirytime'; $params = array( 'export_type' => api::DATAREQUEST_TYPE_EXPORT, 'completestatus' => api::DATAREQUEST_STATUS_DOWNLOAD_READY, 'expirytime' => $expirytime, ); $sort = 'id'; $fields = 'id, userid'; // Filter by user ID if specified. if ($userid > 0) { $sqlwhere .= ' AND (userid = :userid OR requestedby = :requestedby)'; $params['userid'] = $userid; $params['requestedby'] = $userid; } return $DB->get_records_select_menu($table, $sqlwhere, $params, $sort, $fields, 0, 2000); }
php
public static function get_expired_requests($userid = 0) { global $DB; $expiryseconds = get_config('tool_dataprivacy', 'privacyrequestexpiry'); $expirytime = strtotime("-{$expiryseconds} second"); $table = self::TABLE; $sqlwhere = 'type = :export_type AND status = :completestatus AND timemodified <= :expirytime'; $params = array( 'export_type' => api::DATAREQUEST_TYPE_EXPORT, 'completestatus' => api::DATAREQUEST_STATUS_DOWNLOAD_READY, 'expirytime' => $expirytime, ); $sort = 'id'; $fields = 'id, userid'; // Filter by user ID if specified. if ($userid > 0) { $sqlwhere .= ' AND (userid = :userid OR requestedby = :requestedby)'; $params['userid'] = $userid; $params['requestedby'] = $userid; } return $DB->get_records_select_menu($table, $sqlwhere, $params, $sort, $fields, 0, 2000); }
[ "public", "static", "function", "get_expired_requests", "(", "$", "userid", "=", "0", ")", "{", "global", "$", "DB", ";", "$", "expiryseconds", "=", "get_config", "(", "'tool_dataprivacy'", ",", "'privacyrequestexpiry'", ")", ";", "$", "expirytime", "=", "strtotime", "(", "\"-{$expiryseconds} second\"", ")", ";", "$", "table", "=", "self", "::", "TABLE", ";", "$", "sqlwhere", "=", "'type = :export_type AND status = :completestatus AND timemodified <= :expirytime'", ";", "$", "params", "=", "array", "(", "'export_type'", "=>", "api", "::", "DATAREQUEST_TYPE_EXPORT", ",", "'completestatus'", "=>", "api", "::", "DATAREQUEST_STATUS_DOWNLOAD_READY", ",", "'expirytime'", "=>", "$", "expirytime", ",", ")", ";", "$", "sort", "=", "'id'", ";", "$", "fields", "=", "'id, userid'", ";", "// Filter by user ID if specified.", "if", "(", "$", "userid", ">", "0", ")", "{", "$", "sqlwhere", ".=", "' AND (userid = :userid OR requestedby = :requestedby)'", ";", "$", "params", "[", "'userid'", "]", "=", "$", "userid", ";", "$", "params", "[", "'requestedby'", "]", "=", "$", "userid", ";", "}", "return", "$", "DB", "->", "get_records_select_menu", "(", "$", "table", ",", "$", "sqlwhere", ",", "$", "params", ",", "$", "sort", ",", "$", "fields", ",", "0", ",", "2000", ")", ";", "}" ]
Fetch completed data requests which are due to expire. @param int $userid Optional user ID to filter by. @return array Details of completed requests which are due to expire.
[ "Fetch", "completed", "data", "requests", "which", "are", "due", "to", "expire", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/data_request.php#L169-L192
215,695
moodle/moodle
admin/tool/dataprivacy/classes/data_request.php
data_request.expire
public static function expire($expiredrequests) { global $DB; $ids = array_keys($expiredrequests); if (count($ids) > 0) { list($insql, $inparams) = $DB->get_in_or_equal($ids); $initialparams = array(api::DATAREQUEST_STATUS_EXPIRED, time()); $params = array_merge($initialparams, $inparams); $update = "UPDATE {" . self::TABLE . "} SET status = ?, timemodified = ? WHERE id $insql"; if ($DB->execute($update, $params)) { $fs = get_file_storage(); foreach ($expiredrequests as $id => $userid) { $usercontext = \context_user::instance($userid); $fs->delete_area_files($usercontext->id, 'tool_dataprivacy', 'export', $id); } } } }
php
public static function expire($expiredrequests) { global $DB; $ids = array_keys($expiredrequests); if (count($ids) > 0) { list($insql, $inparams) = $DB->get_in_or_equal($ids); $initialparams = array(api::DATAREQUEST_STATUS_EXPIRED, time()); $params = array_merge($initialparams, $inparams); $update = "UPDATE {" . self::TABLE . "} SET status = ?, timemodified = ? WHERE id $insql"; if ($DB->execute($update, $params)) { $fs = get_file_storage(); foreach ($expiredrequests as $id => $userid) { $usercontext = \context_user::instance($userid); $fs->delete_area_files($usercontext->id, 'tool_dataprivacy', 'export', $id); } } } }
[ "public", "static", "function", "expire", "(", "$", "expiredrequests", ")", "{", "global", "$", "DB", ";", "$", "ids", "=", "array_keys", "(", "$", "expiredrequests", ")", ";", "if", "(", "count", "(", "$", "ids", ")", ">", "0", ")", "{", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "ids", ")", ";", "$", "initialparams", "=", "array", "(", "api", "::", "DATAREQUEST_STATUS_EXPIRED", ",", "time", "(", ")", ")", ";", "$", "params", "=", "array_merge", "(", "$", "initialparams", ",", "$", "inparams", ")", ";", "$", "update", "=", "\"UPDATE {\"", ".", "self", "::", "TABLE", ".", "\"}\n SET status = ?, timemodified = ?\n WHERE id $insql\"", ";", "if", "(", "$", "DB", "->", "execute", "(", "$", "update", ",", "$", "params", ")", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "foreach", "(", "$", "expiredrequests", "as", "$", "id", "=>", "$", "userid", ")", "{", "$", "usercontext", "=", "\\", "context_user", "::", "instance", "(", "$", "userid", ")", ";", "$", "fs", "->", "delete_area_files", "(", "$", "usercontext", "->", "id", ",", "'tool_dataprivacy'", ",", "'export'", ",", "$", "id", ")", ";", "}", "}", "}", "}" ]
Expire a given set of data requests. Update request status and delete the files. @param array $expiredrequests [requestid => userid] @return void
[ "Expire", "a", "given", "set", "of", "data", "requests", ".", "Update", "request", "status", "and", "delete", "the", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/data_request.php#L202-L225
215,696
moodle/moodle
admin/tool/dataprivacy/classes/data_request.php
data_request.is_active
public function is_active() : bool { $active = [ api::DATAREQUEST_STATUS_APPROVED => true, ]; return isset($active[$this->get('status')]); }
php
public function is_active() : bool { $active = [ api::DATAREQUEST_STATUS_APPROVED => true, ]; return isset($active[$this->get('status')]); }
[ "public", "function", "is_active", "(", ")", ":", "bool", "{", "$", "active", "=", "[", "api", "::", "DATAREQUEST_STATUS_APPROVED", "=>", "true", ",", "]", ";", "return", "isset", "(", "$", "active", "[", "$", "this", "->", "get", "(", "'status'", ")", "]", ")", ";", "}" ]
Whether this request is 'active'. @return bool
[ "Whether", "this", "request", "is", "active", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/data_request.php#L253-L259
215,697
moodle/moodle
admin/tool/dataprivacy/classes/data_request.php
data_request.resubmit_request
public function resubmit_request() : data_request { if ($this->is_active()) { $this->set('status', api::DATAREQUEST_STATUS_REJECTED)->save(); } if (!$this->is_resettable()) { throw new \moodle_exception('cannotreset', 'tool_dataprivacy'); } $currentdata = $this->to_record(); unset($currentdata->id); // Clone the original request, but do not notify. $clone = api::create_data_request( $this->get('userid'), $this->get('type'), $this->get('comments'), $this->get('creationmethod'), false ); $clone->set('comments', $this->get('comments')); $clone->set('dpo', $this->get('dpo')); $clone->set('requestedby', $this->get('requestedby')); $clone->save(); return $clone; }
php
public function resubmit_request() : data_request { if ($this->is_active()) { $this->set('status', api::DATAREQUEST_STATUS_REJECTED)->save(); } if (!$this->is_resettable()) { throw new \moodle_exception('cannotreset', 'tool_dataprivacy'); } $currentdata = $this->to_record(); unset($currentdata->id); // Clone the original request, but do not notify. $clone = api::create_data_request( $this->get('userid'), $this->get('type'), $this->get('comments'), $this->get('creationmethod'), false ); $clone->set('comments', $this->get('comments')); $clone->set('dpo', $this->get('dpo')); $clone->set('requestedby', $this->get('requestedby')); $clone->save(); return $clone; }
[ "public", "function", "resubmit_request", "(", ")", ":", "data_request", "{", "if", "(", "$", "this", "->", "is_active", "(", ")", ")", "{", "$", "this", "->", "set", "(", "'status'", ",", "api", "::", "DATAREQUEST_STATUS_REJECTED", ")", "->", "save", "(", ")", ";", "}", "if", "(", "!", "$", "this", "->", "is_resettable", "(", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'cannotreset'", ",", "'tool_dataprivacy'", ")", ";", "}", "$", "currentdata", "=", "$", "this", "->", "to_record", "(", ")", ";", "unset", "(", "$", "currentdata", "->", "id", ")", ";", "// Clone the original request, but do not notify.", "$", "clone", "=", "api", "::", "create_data_request", "(", "$", "this", "->", "get", "(", "'userid'", ")", ",", "$", "this", "->", "get", "(", "'type'", ")", ",", "$", "this", "->", "get", "(", "'comments'", ")", ",", "$", "this", "->", "get", "(", "'creationmethod'", ")", ",", "false", ")", ";", "$", "clone", "->", "set", "(", "'comments'", ",", "$", "this", "->", "get", "(", "'comments'", ")", ")", ";", "$", "clone", "->", "set", "(", "'dpo'", ",", "$", "this", "->", "get", "(", "'dpo'", ")", ")", ";", "$", "clone", "->", "set", "(", "'requestedby'", ",", "$", "this", "->", "get", "(", "'requestedby'", ")", ")", ";", "$", "clone", "->", "save", "(", ")", ";", "return", "$", "clone", ";", "}" ]
Reject this request and resubmit it as a fresh request. Note: This does not check whether any other completed requests exist for this user. @return self
[ "Reject", "this", "request", "and", "resubmit", "it", "as", "a", "fresh", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/data_request.php#L268-L294
215,698
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Interaction/Command.php
Horde_Imap_Client_Interaction_Command._continuationCheck
protected function _continuationCheck($list) { foreach ($list as $val) { if (($val instanceof Horde_Imap_Client_Interaction_Command_Continuation) || (($val instanceof Horde_Imap_Client_Data_Format_String) && $val->literal())) { return true; } if (($val instanceof Horde_Imap_Client_Data_Format_List) && $this->_continuationCheck($val)) { return true; } } return false; }
php
protected function _continuationCheck($list) { foreach ($list as $val) { if (($val instanceof Horde_Imap_Client_Interaction_Command_Continuation) || (($val instanceof Horde_Imap_Client_Data_Format_String) && $val->literal())) { return true; } if (($val instanceof Horde_Imap_Client_Data_Format_List) && $this->_continuationCheck($val)) { return true; } } return false; }
[ "protected", "function", "_continuationCheck", "(", "$", "list", ")", "{", "foreach", "(", "$", "list", "as", "$", "val", ")", "{", "if", "(", "(", "$", "val", "instanceof", "Horde_Imap_Client_Interaction_Command_Continuation", ")", "||", "(", "(", "$", "val", "instanceof", "Horde_Imap_Client_Data_Format_String", ")", "&&", "$", "val", "->", "literal", "(", ")", ")", ")", "{", "return", "true", ";", "}", "if", "(", "(", "$", "val", "instanceof", "Horde_Imap_Client_Data_Format_List", ")", "&&", "$", "this", "->", "_continuationCheck", "(", "$", "val", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Recursive check for continuation functions.
[ "Recursive", "check", "for", "continuation", "functions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Interaction/Command.php#L166-L182
215,699
moodle/moodle
question/type/multichoice/backup/moodle1/lib.php
moodle1_qtype_multichoice_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 multichoice. if (!isset($data['multichoice'])) { // This should never happen, but it can do if the 1.9 site contained // corrupt data. $data['multichoice'] = array(array( 'single' => 1, 'shuffleanswers' => 1, 'correctfeedback' => '', 'correctfeedbackformat' => FORMAT_HTML, 'partiallycorrectfeedback' => '', 'partiallycorrectfeedbackformat' => FORMAT_HTML, 'incorrectfeedback' => '', 'incorrectfeedbackformat' => FORMAT_HTML, 'answernumbering' => 'abc', )); } $this->write_multichoice($data['multichoice'], $data['oldquestiontextformat'], $data['id']); }
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 multichoice. if (!isset($data['multichoice'])) { // This should never happen, but it can do if the 1.9 site contained // corrupt data. $data['multichoice'] = array(array( 'single' => 1, 'shuffleanswers' => 1, 'correctfeedback' => '', 'correctfeedbackformat' => FORMAT_HTML, 'partiallycorrectfeedback' => '', 'partiallycorrectfeedbackformat' => FORMAT_HTML, 'incorrectfeedback' => '', 'incorrectfeedbackformat' => FORMAT_HTML, 'answernumbering' => 'abc', )); } $this->write_multichoice($data['multichoice'], $data['oldquestiontextformat'], $data['id']); }
[ "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 multichoice.", "if", "(", "!", "isset", "(", "$", "data", "[", "'multichoice'", "]", ")", ")", "{", "// This should never happen, but it can do if the 1.9 site contained", "// corrupt data.", "$", "data", "[", "'multichoice'", "]", "=", "array", "(", "array", "(", "'single'", "=>", "1", ",", "'shuffleanswers'", "=>", "1", ",", "'correctfeedback'", "=>", "''", ",", "'correctfeedbackformat'", "=>", "FORMAT_HTML", ",", "'partiallycorrectfeedback'", "=>", "''", ",", "'partiallycorrectfeedbackformat'", "=>", "FORMAT_HTML", ",", "'incorrectfeedback'", "=>", "''", ",", "'incorrectfeedbackformat'", "=>", "FORMAT_HTML", ",", "'answernumbering'", "=>", "'abc'", ",", ")", ")", ";", "}", "$", "this", "->", "write_multichoice", "(", "$", "data", "[", "'multichoice'", "]", ",", "$", "data", "[", "'oldquestiontextformat'", "]", ",", "$", "data", "[", "'id'", "]", ")", ";", "}" ]
Appends the multichoice specific information to the question
[ "Appends", "the", "multichoice", "specific", "information", "to", "the", "question" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/multichoice/backup/moodle1/lib.php#L44-L68