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,400
moodle/moodle
mod/forum/classes/local/vaults/discussion_list.php
discussion_list.from_db_records
protected function from_db_records(array $results) { $entityfactory = $this->get_entity_factory(); return array_map(function(array $result) use ($entityfactory) { [ 'discussion' => $discussion, 'firstpost' => $firstpost, 'firstpostauthor' => $firstpostauthor, 'latestpostauthor' => $latestpostauthor, ] = $result; return $entityfactory->get_discussion_summary_from_stdclass( $discussion, $firstpost, $firstpostauthor, $latestpostauthor ); }, $results); }
php
protected function from_db_records(array $results) { $entityfactory = $this->get_entity_factory(); return array_map(function(array $result) use ($entityfactory) { [ 'discussion' => $discussion, 'firstpost' => $firstpost, 'firstpostauthor' => $firstpostauthor, 'latestpostauthor' => $latestpostauthor, ] = $result; return $entityfactory->get_discussion_summary_from_stdclass( $discussion, $firstpost, $firstpostauthor, $latestpostauthor ); }, $results); }
[ "protected", "function", "from_db_records", "(", "array", "$", "results", ")", "{", "$", "entityfactory", "=", "$", "this", "->", "get_entity_factory", "(", ")", ";", "return", "array_map", "(", "function", "(", "array", "$", "result", ")", "use", "(", "$", "entityfactory", ")", "{", "[", "'discussion'", "=>", "$", "discussion", ",", "'firstpost'", "=>", "$", "firstpost", ",", "'firstpostauthor'", "=>", "$", "firstpostauthor", ",", "'latestpostauthor'", "=>", "$", "latestpostauthor", ",", "]", "=", "$", "result", ";", "return", "$", "entityfactory", "->", "get_discussion_summary_from_stdclass", "(", "$", "discussion", ",", "$", "firstpost", ",", "$", "firstpostauthor", ",", "$", "latestpostauthor", ")", ";", "}", ",", "$", "results", ")", ";", "}" ]
Convert the DB records into discussion list entities. @param array $results The DB records @return discussion_list[]
[ "Convert", "the", "DB", "records", "into", "discussion", "list", "entities", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/discussion_list.php#L203-L220
215,401
moodle/moodle
mod/forum/classes/local/vaults/discussion_list.php
discussion_list.get_keyfield
protected function get_keyfield(?int $sortmethod) : string { switch ($sortmethod) { case self::SORTORDER_CREATED_DESC: case self::SORTORDER_CREATED_ASC: return 'fp.created'; case self::SORTORDER_REPLIES_DESC: case self::SORTORDER_REPLIES_ASC: return 'replycount'; default: global $CFG; $alias = $this->get_table_alias(); $field = "{$alias}.timemodified"; if (!empty($CFG->forum_enabletimedposts)) { return "CASE WHEN {$field} < {$alias}.timestart THEN {$alias}.timestart ELSE {$field} END"; } return $field; } }
php
protected function get_keyfield(?int $sortmethod) : string { switch ($sortmethod) { case self::SORTORDER_CREATED_DESC: case self::SORTORDER_CREATED_ASC: return 'fp.created'; case self::SORTORDER_REPLIES_DESC: case self::SORTORDER_REPLIES_ASC: return 'replycount'; default: global $CFG; $alias = $this->get_table_alias(); $field = "{$alias}.timemodified"; if (!empty($CFG->forum_enabletimedposts)) { return "CASE WHEN {$field} < {$alias}.timestart THEN {$alias}.timestart ELSE {$field} END"; } return $field; } }
[ "protected", "function", "get_keyfield", "(", "?", "int", "$", "sortmethod", ")", ":", "string", "{", "switch", "(", "$", "sortmethod", ")", "{", "case", "self", "::", "SORTORDER_CREATED_DESC", ":", "case", "self", "::", "SORTORDER_CREATED_ASC", ":", "return", "'fp.created'", ";", "case", "self", "::", "SORTORDER_REPLIES_DESC", ":", "case", "self", "::", "SORTORDER_REPLIES_ASC", ":", "return", "'replycount'", ";", "default", ":", "global", "$", "CFG", ";", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "$", "field", "=", "\"{$alias}.timemodified\"", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "forum_enabletimedposts", ")", ")", "{", "return", "\"CASE WHEN {$field} < {$alias}.timestart THEN {$alias}.timestart ELSE {$field} END\"", ";", "}", "return", "$", "field", ";", "}", "}" ]
Get the field to sort by. @param int|null $sortmethod @return string
[ "Get", "the", "field", "to", "sort", "by", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/discussion_list.php#L228-L245
215,402
moodle/moodle
mod/forum/classes/local/vaults/discussion_list.php
discussion_list.get_sort_direction
protected function get_sort_direction(?int $sortmethod) : string { switch ($sortmethod) { case self::SORTORDER_LASTPOST_ASC: case self::SORTORDER_CREATED_ASC: case self::SORTORDER_REPLIES_ASC: return "ASC"; case self::SORTORDER_LASTPOST_DESC: case self::SORTORDER_CREATED_DESC: case self::SORTORDER_REPLIES_DESC: return "DESC"; default: return "DESC"; } }
php
protected function get_sort_direction(?int $sortmethod) : string { switch ($sortmethod) { case self::SORTORDER_LASTPOST_ASC: case self::SORTORDER_CREATED_ASC: case self::SORTORDER_REPLIES_ASC: return "ASC"; case self::SORTORDER_LASTPOST_DESC: case self::SORTORDER_CREATED_DESC: case self::SORTORDER_REPLIES_DESC: return "DESC"; default: return "DESC"; } }
[ "protected", "function", "get_sort_direction", "(", "?", "int", "$", "sortmethod", ")", ":", "string", "{", "switch", "(", "$", "sortmethod", ")", "{", "case", "self", "::", "SORTORDER_LASTPOST_ASC", ":", "case", "self", "::", "SORTORDER_CREATED_ASC", ":", "case", "self", "::", "SORTORDER_REPLIES_ASC", ":", "return", "\"ASC\"", ";", "case", "self", "::", "SORTORDER_LASTPOST_DESC", ":", "case", "self", "::", "SORTORDER_CREATED_DESC", ":", "case", "self", "::", "SORTORDER_REPLIES_DESC", ":", "return", "\"DESC\"", ";", "default", ":", "return", "\"DESC\"", ";", "}", "}" ]
Get the sort direction. @param int|null $sortmethod @return string
[ "Get", "the", "sort", "direction", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/discussion_list.php#L253-L266
215,403
moodle/moodle
mod/forum/classes/local/vaults/discussion_list.php
discussion_list.get_sort_order
private function get_sort_order(?int $sortmethod, bool $includefavourites = true) : string { $alias = $this->get_table_alias(); // TODO consider user favourites... $keyfield = $this->get_keyfield($sortmethod); $direction = $this->get_sort_direction($sortmethod); $favouritesort = ''; if ($includefavourites) { $favalias = $this->get_favourite_alias(); // Since we're joining on the favourite table any discussion that isn't favourited will have // null in the favourite columns. Nulls behave differently in the sorting for different databases. // We can ensure consistency between databases by explicitly deprioritising any null favourite field // using a case statement. $favouritesort = ", CASE WHEN {$favalias}.id IS NULL THEN 0 ELSE 1 END DESC"; // After the null favourite fields are deprioritised and appear below the favourited discussions we // need to order the favourited discussions by id so that the most recently favourited discussions // appear at the top of the list. $favouritesort .= ", {$favalias}.itemtype DESC"; } return "{$alias}.pinned DESC $favouritesort , {$keyfield} {$direction}"; }
php
private function get_sort_order(?int $sortmethod, bool $includefavourites = true) : string { $alias = $this->get_table_alias(); // TODO consider user favourites... $keyfield = $this->get_keyfield($sortmethod); $direction = $this->get_sort_direction($sortmethod); $favouritesort = ''; if ($includefavourites) { $favalias = $this->get_favourite_alias(); // Since we're joining on the favourite table any discussion that isn't favourited will have // null in the favourite columns. Nulls behave differently in the sorting for different databases. // We can ensure consistency between databases by explicitly deprioritising any null favourite field // using a case statement. $favouritesort = ", CASE WHEN {$favalias}.id IS NULL THEN 0 ELSE 1 END DESC"; // After the null favourite fields are deprioritised and appear below the favourited discussions we // need to order the favourited discussions by id so that the most recently favourited discussions // appear at the top of the list. $favouritesort .= ", {$favalias}.itemtype DESC"; } return "{$alias}.pinned DESC $favouritesort , {$keyfield} {$direction}"; }
[ "private", "function", "get_sort_order", "(", "?", "int", "$", "sortmethod", ",", "bool", "$", "includefavourites", "=", "true", ")", ":", "string", "{", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "// TODO consider user favourites...", "$", "keyfield", "=", "$", "this", "->", "get_keyfield", "(", "$", "sortmethod", ")", ";", "$", "direction", "=", "$", "this", "->", "get_sort_direction", "(", "$", "sortmethod", ")", ";", "$", "favouritesort", "=", "''", ";", "if", "(", "$", "includefavourites", ")", "{", "$", "favalias", "=", "$", "this", "->", "get_favourite_alias", "(", ")", ";", "// Since we're joining on the favourite table any discussion that isn't favourited will have", "// null in the favourite columns. Nulls behave differently in the sorting for different databases.", "// We can ensure consistency between databases by explicitly deprioritising any null favourite field", "// using a case statement.", "$", "favouritesort", "=", "\", CASE WHEN {$favalias}.id IS NULL THEN 0 ELSE 1 END DESC\"", ";", "// After the null favourite fields are deprioritised and appear below the favourited discussions we", "// need to order the favourited discussions by id so that the most recently favourited discussions", "// appear at the top of the list.", "$", "favouritesort", ".=", "\", {$favalias}.itemtype DESC\"", ";", "}", "return", "\"{$alias}.pinned DESC $favouritesort , {$keyfield} {$direction}\"", ";", "}" ]
Get the sort order SQL for a sort method. @param int|null $sortmethod @param bool|null $includefavourites @return string
[ "Get", "the", "sort", "order", "SQL", "for", "a", "sort", "method", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/discussion_list.php#L275-L297
215,404
moodle/moodle
mod/forum/classes/local/vaults/discussion_list.php
discussion_list.get_hidden_post_sql
protected function get_hidden_post_sql(bool $includehiddendiscussions, ?int $includepostsforuser) { $wheresql = ''; $params = []; if (!$includehiddendiscussions) { $now = time(); $wheresql = " AND ((d.timestart <= :timestart AND (d.timeend = 0 OR d.timeend > :timeend))"; $params['timestart'] = $now; $params['timeend'] = $now; if (null !== $includepostsforuser) { $wheresql .= " OR d.userid = :byuser"; $params['byuser'] = $includepostsforuser; } $wheresql .= ")"; } return [ 'wheresql' => $wheresql, 'params' => $params, ]; }
php
protected function get_hidden_post_sql(bool $includehiddendiscussions, ?int $includepostsforuser) { $wheresql = ''; $params = []; if (!$includehiddendiscussions) { $now = time(); $wheresql = " AND ((d.timestart <= :timestart AND (d.timeend = 0 OR d.timeend > :timeend))"; $params['timestart'] = $now; $params['timeend'] = $now; if (null !== $includepostsforuser) { $wheresql .= " OR d.userid = :byuser"; $params['byuser'] = $includepostsforuser; } $wheresql .= ")"; } return [ 'wheresql' => $wheresql, 'params' => $params, ]; }
[ "protected", "function", "get_hidden_post_sql", "(", "bool", "$", "includehiddendiscussions", ",", "?", "int", "$", "includepostsforuser", ")", "{", "$", "wheresql", "=", "''", ";", "$", "params", "=", "[", "]", ";", "if", "(", "!", "$", "includehiddendiscussions", ")", "{", "$", "now", "=", "time", "(", ")", ";", "$", "wheresql", "=", "\" AND ((d.timestart <= :timestart AND (d.timeend = 0 OR d.timeend > :timeend))\"", ";", "$", "params", "[", "'timestart'", "]", "=", "$", "now", ";", "$", "params", "[", "'timeend'", "]", "=", "$", "now", ";", "if", "(", "null", "!==", "$", "includepostsforuser", ")", "{", "$", "wheresql", ".=", "\" OR d.userid = :byuser\"", ";", "$", "params", "[", "'byuser'", "]", "=", "$", "includepostsforuser", ";", "}", "$", "wheresql", ".=", "\")\"", ";", "}", "return", "[", "'wheresql'", "=>", "$", "wheresql", ",", "'params'", "=>", "$", "params", ",", "]", ";", "}" ]
Fetch any required SQL to respect timed posts. @param bool $includehiddendiscussions Whether to include hidden discussions or not @param int|null $includepostsforuser Which user to include posts for, if any @return array The SQL and parameters to include
[ "Fetch", "any", "required", "SQL", "to", "respect", "timed", "posts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/discussion_list.php#L306-L325
215,405
moodle/moodle
mod/forum/classes/local/vaults/discussion_list.php
discussion_list.get_from_forum_id
public function get_from_forum_id( int $forumid, bool $includehiddendiscussions, ?int $includepostsforuser, ?int $sortorder, int $limit, int $offset ) { $alias = $this->get_table_alias(); $wheresql = "{$alias}.forum = :forumid"; [ 'wheresql' => $hiddensql, 'params' => $hiddenparams ] = $this->get_hidden_post_sql($includehiddendiscussions, $includepostsforuser); $wheresql .= $hiddensql; $params = array_merge($hiddenparams, [ 'forumid' => $forumid, ]); $includefavourites = $includepostsforuser ? true : false; $sql = $this->generate_get_records_sql($wheresql, $this->get_sort_order($sortorder, $includefavourites), $includepostsforuser); $records = $this->get_db()->get_records_sql($sql, $params, $offset, $limit); return $this->transform_db_records_to_entities($records); }
php
public function get_from_forum_id( int $forumid, bool $includehiddendiscussions, ?int $includepostsforuser, ?int $sortorder, int $limit, int $offset ) { $alias = $this->get_table_alias(); $wheresql = "{$alias}.forum = :forumid"; [ 'wheresql' => $hiddensql, 'params' => $hiddenparams ] = $this->get_hidden_post_sql($includehiddendiscussions, $includepostsforuser); $wheresql .= $hiddensql; $params = array_merge($hiddenparams, [ 'forumid' => $forumid, ]); $includefavourites = $includepostsforuser ? true : false; $sql = $this->generate_get_records_sql($wheresql, $this->get_sort_order($sortorder, $includefavourites), $includepostsforuser); $records = $this->get_db()->get_records_sql($sql, $params, $offset, $limit); return $this->transform_db_records_to_entities($records); }
[ "public", "function", "get_from_forum_id", "(", "int", "$", "forumid", ",", "bool", "$", "includehiddendiscussions", ",", "?", "int", "$", "includepostsforuser", ",", "?", "int", "$", "sortorder", ",", "int", "$", "limit", ",", "int", "$", "offset", ")", "{", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "$", "wheresql", "=", "\"{$alias}.forum = :forumid\"", ";", "[", "'wheresql'", "=>", "$", "hiddensql", ",", "'params'", "=>", "$", "hiddenparams", "]", "=", "$", "this", "->", "get_hidden_post_sql", "(", "$", "includehiddendiscussions", ",", "$", "includepostsforuser", ")", ";", "$", "wheresql", ".=", "$", "hiddensql", ";", "$", "params", "=", "array_merge", "(", "$", "hiddenparams", ",", "[", "'forumid'", "=>", "$", "forumid", ",", "]", ")", ";", "$", "includefavourites", "=", "$", "includepostsforuser", "?", "true", ":", "false", ";", "$", "sql", "=", "$", "this", "->", "generate_get_records_sql", "(", "$", "wheresql", ",", "$", "this", "->", "get_sort_order", "(", "$", "sortorder", ",", "$", "includefavourites", ")", ",", "$", "includepostsforuser", ")", ";", "$", "records", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ",", "$", "offset", ",", "$", "limit", ")", ";", "return", "$", "this", "->", "transform_db_records_to_entities", "(", "$", "records", ")", ";", "}" ]
Get each discussion, first post, first and last post author for the given forum, considering timed posts, and pagination. @param int $forumid The forum to fetch the discussion set for @param bool $includehiddendiscussions Whether to include hidden discussions or not @param int|null $includepostsforuser Which user to include posts for, if any @param int $sortorder The sort order to use @param int $limit The number of discussions to fetch @param int $offset The record offset @return array The set of data fetched
[ "Get", "each", "discussion", "first", "post", "first", "and", "last", "post", "author", "for", "the", "given", "forum", "considering", "timed", "posts", "and", "pagination", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/discussion_list.php#L339-L365
215,406
moodle/moodle
mod/forum/classes/local/vaults/discussion_list.php
discussion_list.get_from_forum_id_and_group_id
public function get_from_forum_id_and_group_id( int $forumid, array $groupids, bool $includehiddendiscussions, ?int $includepostsforuser, ?int $sortorder, int $limit, int $offset ) { $alias = $this->get_table_alias(); $wheresql = "{$alias}.forum = :forumid AND "; $groupparams = []; if (empty($groupids)) { $wheresql .= "{$alias}.groupid = :allgroupsid"; } else { list($insql, $groupparams) = $this->get_db()->get_in_or_equal($groupids, SQL_PARAMS_NAMED, 'gid'); $wheresql .= "({$alias}.groupid = :allgroupsid OR {$alias}.groupid {$insql})"; } [ 'wheresql' => $hiddensql, 'params' => $hiddenparams ] = $this->get_hidden_post_sql($includehiddendiscussions, $includepostsforuser); $wheresql .= $hiddensql; $params = array_merge($hiddenparams, $groupparams, [ 'forumid' => $forumid, 'allgroupsid' => -1, ]); $includefavourites = $includepostsforuser ? true : false; $sql = $this->generate_get_records_sql($wheresql, $this->get_sort_order($sortorder, $includefavourites), $includepostsforuser); $records = $this->get_db()->get_records_sql($sql, $params, $offset, $limit); return $this->transform_db_records_to_entities($records); }
php
public function get_from_forum_id_and_group_id( int $forumid, array $groupids, bool $includehiddendiscussions, ?int $includepostsforuser, ?int $sortorder, int $limit, int $offset ) { $alias = $this->get_table_alias(); $wheresql = "{$alias}.forum = :forumid AND "; $groupparams = []; if (empty($groupids)) { $wheresql .= "{$alias}.groupid = :allgroupsid"; } else { list($insql, $groupparams) = $this->get_db()->get_in_or_equal($groupids, SQL_PARAMS_NAMED, 'gid'); $wheresql .= "({$alias}.groupid = :allgroupsid OR {$alias}.groupid {$insql})"; } [ 'wheresql' => $hiddensql, 'params' => $hiddenparams ] = $this->get_hidden_post_sql($includehiddendiscussions, $includepostsforuser); $wheresql .= $hiddensql; $params = array_merge($hiddenparams, $groupparams, [ 'forumid' => $forumid, 'allgroupsid' => -1, ]); $includefavourites = $includepostsforuser ? true : false; $sql = $this->generate_get_records_sql($wheresql, $this->get_sort_order($sortorder, $includefavourites), $includepostsforuser); $records = $this->get_db()->get_records_sql($sql, $params, $offset, $limit); return $this->transform_db_records_to_entities($records); }
[ "public", "function", "get_from_forum_id_and_group_id", "(", "int", "$", "forumid", ",", "array", "$", "groupids", ",", "bool", "$", "includehiddendiscussions", ",", "?", "int", "$", "includepostsforuser", ",", "?", "int", "$", "sortorder", ",", "int", "$", "limit", ",", "int", "$", "offset", ")", "{", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "$", "wheresql", "=", "\"{$alias}.forum = :forumid AND \"", ";", "$", "groupparams", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "groupids", ")", ")", "{", "$", "wheresql", ".=", "\"{$alias}.groupid = :allgroupsid\"", ";", "}", "else", "{", "list", "(", "$", "insql", ",", "$", "groupparams", ")", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_in_or_equal", "(", "$", "groupids", ",", "SQL_PARAMS_NAMED", ",", "'gid'", ")", ";", "$", "wheresql", ".=", "\"({$alias}.groupid = :allgroupsid OR {$alias}.groupid {$insql})\"", ";", "}", "[", "'wheresql'", "=>", "$", "hiddensql", ",", "'params'", "=>", "$", "hiddenparams", "]", "=", "$", "this", "->", "get_hidden_post_sql", "(", "$", "includehiddendiscussions", ",", "$", "includepostsforuser", ")", ";", "$", "wheresql", ".=", "$", "hiddensql", ";", "$", "params", "=", "array_merge", "(", "$", "hiddenparams", ",", "$", "groupparams", ",", "[", "'forumid'", "=>", "$", "forumid", ",", "'allgroupsid'", "=>", "-", "1", ",", "]", ")", ";", "$", "includefavourites", "=", "$", "includepostsforuser", "?", "true", ":", "false", ";", "$", "sql", "=", "$", "this", "->", "generate_get_records_sql", "(", "$", "wheresql", ",", "$", "this", "->", "get_sort_order", "(", "$", "sortorder", ",", "$", "includefavourites", ")", ",", "$", "includepostsforuser", ")", ";", "$", "records", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ",", "$", "offset", ",", "$", "limit", ")", ";", "return", "$", "this", "->", "transform_db_records_to_entities", "(", "$", "records", ")", ";", "}" ]
Get each discussion, first post, first and last post author for the given forum, and the set of groups to display considering timed posts, and pagination. @param int $forumid The forum to fetch the discussion set for @param int[] $groupids The list of real groups to filter on @param bool $includehiddendiscussions Whether to include hidden discussions or not @param int|null $includepostsforuser Which user to include posts for, if any @param int $sortorder The sort order to use @param int $limit The number of discussions to fetch @param int $offset The record offset @return array The set of data fetched
[ "Get", "each", "discussion", "first", "post", "first", "and", "last", "post", "author", "for", "the", "given", "forum", "and", "the", "set", "of", "groups", "to", "display", "considering", "timed", "posts", "and", "pagination", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/discussion_list.php#L380-L417
215,407
moodle/moodle
mod/forum/classes/local/vaults/discussion_list.php
discussion_list.get_total_discussion_count_from_forum_id
public function get_total_discussion_count_from_forum_id( int $forumid, bool $includehiddendiscussions, ?int $includepostsforuser ) { $alias = $this->get_table_alias(); $wheresql = "{$alias}.forum = :forumid"; [ 'wheresql' => $hiddensql, 'params' => $hiddenparams ] = $this->get_hidden_post_sql($includehiddendiscussions, $includepostsforuser); $wheresql .= $hiddensql; $params = array_merge($hiddenparams, [ 'forumid' => $forumid, ]); return $this->get_db()->count_records_sql($this->generate_count_records_sql($wheresql), $params); }
php
public function get_total_discussion_count_from_forum_id( int $forumid, bool $includehiddendiscussions, ?int $includepostsforuser ) { $alias = $this->get_table_alias(); $wheresql = "{$alias}.forum = :forumid"; [ 'wheresql' => $hiddensql, 'params' => $hiddenparams ] = $this->get_hidden_post_sql($includehiddendiscussions, $includepostsforuser); $wheresql .= $hiddensql; $params = array_merge($hiddenparams, [ 'forumid' => $forumid, ]); return $this->get_db()->count_records_sql($this->generate_count_records_sql($wheresql), $params); }
[ "public", "function", "get_total_discussion_count_from_forum_id", "(", "int", "$", "forumid", ",", "bool", "$", "includehiddendiscussions", ",", "?", "int", "$", "includepostsforuser", ")", "{", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "$", "wheresql", "=", "\"{$alias}.forum = :forumid\"", ";", "[", "'wheresql'", "=>", "$", "hiddensql", ",", "'params'", "=>", "$", "hiddenparams", "]", "=", "$", "this", "->", "get_hidden_post_sql", "(", "$", "includehiddendiscussions", ",", "$", "includepostsforuser", ")", ";", "$", "wheresql", ".=", "$", "hiddensql", ";", "$", "params", "=", "array_merge", "(", "$", "hiddenparams", ",", "[", "'forumid'", "=>", "$", "forumid", ",", "]", ")", ";", "return", "$", "this", "->", "get_db", "(", ")", "->", "count_records_sql", "(", "$", "this", "->", "generate_count_records_sql", "(", "$", "wheresql", ")", ",", "$", "params", ")", ";", "}" ]
Count the number of discussions in the forum. @param int $forumid Id of the forum to count discussions in @param bool $includehiddendiscussions Include hidden dicussions in the count? @param int|null $includepostsforuser Include discussions created by this user in the count (only works if not including hidden discussions). @return int
[ "Count", "the", "number", "of", "discussions", "in", "the", "forum", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/discussion_list.php#L428-L448
215,408
moodle/moodle
mod/forum/classes/local/vaults/discussion_list.php
discussion_list.get_total_discussion_count_from_forum_id_and_group_id
public function get_total_discussion_count_from_forum_id_and_group_id( int $forumid, array $groupids, bool $includehiddendiscussions, ?int $includepostsforuser ) { $alias = $this->get_table_alias(); $wheresql = "{$alias}.forum = :forumid AND "; $groupparams = []; if (empty($groupids)) { $wheresql .= "{$alias}.groupid = :allgroupsid"; } else { list($insql, $groupparams) = $this->get_db()->get_in_or_equal($groupids, SQL_PARAMS_NAMED, 'gid'); $wheresql .= "({$alias}.groupid = :allgroupsid OR {$alias}.groupid {$insql})"; } [ 'wheresql' => $hiddensql, 'params' => $hiddenparams ] = $this->get_hidden_post_sql($includehiddendiscussions, $includepostsforuser); $wheresql .= $hiddensql; $params = array_merge($hiddenparams, $groupparams, [ 'forumid' => $forumid, 'allgroupsid' => -1, ]); return $this->get_db()->count_records_sql($this->generate_count_records_sql($wheresql), $params); }
php
public function get_total_discussion_count_from_forum_id_and_group_id( int $forumid, array $groupids, bool $includehiddendiscussions, ?int $includepostsforuser ) { $alias = $this->get_table_alias(); $wheresql = "{$alias}.forum = :forumid AND "; $groupparams = []; if (empty($groupids)) { $wheresql .= "{$alias}.groupid = :allgroupsid"; } else { list($insql, $groupparams) = $this->get_db()->get_in_or_equal($groupids, SQL_PARAMS_NAMED, 'gid'); $wheresql .= "({$alias}.groupid = :allgroupsid OR {$alias}.groupid {$insql})"; } [ 'wheresql' => $hiddensql, 'params' => $hiddenparams ] = $this->get_hidden_post_sql($includehiddendiscussions, $includepostsforuser); $wheresql .= $hiddensql; $params = array_merge($hiddenparams, $groupparams, [ 'forumid' => $forumid, 'allgroupsid' => -1, ]); return $this->get_db()->count_records_sql($this->generate_count_records_sql($wheresql), $params); }
[ "public", "function", "get_total_discussion_count_from_forum_id_and_group_id", "(", "int", "$", "forumid", ",", "array", "$", "groupids", ",", "bool", "$", "includehiddendiscussions", ",", "?", "int", "$", "includepostsforuser", ")", "{", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "$", "wheresql", "=", "\"{$alias}.forum = :forumid AND \"", ";", "$", "groupparams", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "groupids", ")", ")", "{", "$", "wheresql", ".=", "\"{$alias}.groupid = :allgroupsid\"", ";", "}", "else", "{", "list", "(", "$", "insql", ",", "$", "groupparams", ")", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_in_or_equal", "(", "$", "groupids", ",", "SQL_PARAMS_NAMED", ",", "'gid'", ")", ";", "$", "wheresql", ".=", "\"({$alias}.groupid = :allgroupsid OR {$alias}.groupid {$insql})\"", ";", "}", "[", "'wheresql'", "=>", "$", "hiddensql", ",", "'params'", "=>", "$", "hiddenparams", "]", "=", "$", "this", "->", "get_hidden_post_sql", "(", "$", "includehiddendiscussions", ",", "$", "includepostsforuser", ")", ";", "$", "wheresql", ".=", "$", "hiddensql", ";", "$", "params", "=", "array_merge", "(", "$", "hiddenparams", ",", "$", "groupparams", ",", "[", "'forumid'", "=>", "$", "forumid", ",", "'allgroupsid'", "=>", "-", "1", ",", "]", ")", ";", "return", "$", "this", "->", "get_db", "(", ")", "->", "count_records_sql", "(", "$", "this", "->", "generate_count_records_sql", "(", "$", "wheresql", ")", ",", "$", "params", ")", ";", "}" ]
Count the number of discussions in all groups and the list of groups provided. @param int $forumid Id of the forum to count discussions in @param int[] $groupids List of group ids to include in the count (discussions in all groups will always be counted) @param bool $includehiddendiscussions Include hidden dicussions in the count? @param int|null $includepostsforuser Include discussions created by this user in the count (only works if not including hidden discussions). @return int
[ "Count", "the", "number", "of", "discussions", "in", "all", "groups", "and", "the", "list", "of", "groups", "provided", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/discussion_list.php#L460-L489
215,409
moodle/moodle
mod/forum/classes/local/vaults/discussion_list.php
discussion_list.get_favourite_sql
private function get_favourite_sql(int $userid): array { $usercontext = \context_user::instance($userid); $alias = $this->get_table_alias(); $ufservice = \core_favourites\service_factory::get_service_for_user_context($usercontext); list($favsql, $favparams) = $ufservice->get_join_sql_by_type('mod_forum', 'discussions', $this->get_favourite_alias(), "$alias.id"); return [$favsql, $favparams]; }
php
private function get_favourite_sql(int $userid): array { $usercontext = \context_user::instance($userid); $alias = $this->get_table_alias(); $ufservice = \core_favourites\service_factory::get_service_for_user_context($usercontext); list($favsql, $favparams) = $ufservice->get_join_sql_by_type('mod_forum', 'discussions', $this->get_favourite_alias(), "$alias.id"); return [$favsql, $favparams]; }
[ "private", "function", "get_favourite_sql", "(", "int", "$", "userid", ")", ":", "array", "{", "$", "usercontext", "=", "\\", "context_user", "::", "instance", "(", "$", "userid", ")", ";", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "$", "ufservice", "=", "\\", "core_favourites", "\\", "service_factory", "::", "get_service_for_user_context", "(", "$", "usercontext", ")", ";", "list", "(", "$", "favsql", ",", "$", "favparams", ")", "=", "$", "ufservice", "->", "get_join_sql_by_type", "(", "'mod_forum'", ",", "'discussions'", ",", "$", "this", "->", "get_favourite_alias", "(", ")", ",", "\"$alias.id\"", ")", ";", "return", "[", "$", "favsql", ",", "$", "favparams", "]", ";", "}" ]
Get the standard favouriting sql. @param int $userid The ID of the user we are getting the sql for @return [$sql, $params] An array comprising of the sql and any associated params
[ "Get", "the", "standard", "favouriting", "sql", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/discussion_list.php#L497-L506
215,410
moodle/moodle
lib/classes/date.php
core_date.get_list_of_timezones
public static function get_list_of_timezones($currentvalue = null, $include99 = false) { self::init_zones(); // Localise first. $timezones = array(); foreach (self::$goodzones as $tzkey => $ignored) { $timezones[$tzkey] = self::get_localised_timezone($tzkey); } core_collator::asort($timezones); // Add '99' if requested. if ($include99 or $currentvalue == 99) { $timezones['99'] = self::get_localised_timezone('99'); } if (!isset($currentvalue) or isset($timezones[$currentvalue])) { return $timezones; } if (is_numeric($currentvalue)) { // UTC offset. if ($currentvalue == 0) { $a = 'UTC'; } else { $modifier = ($currentvalue > 0) ? '+' : ''; $a = 'UTC' . $modifier . number_format($currentvalue, 1); } $timezones[$currentvalue] = get_string('timezoneinvalid', 'core_admin', $a); } else { // Some string we don't recognise. $timezones[$currentvalue] = get_string('timezoneinvalid', 'core_admin', $currentvalue); } return $timezones; }
php
public static function get_list_of_timezones($currentvalue = null, $include99 = false) { self::init_zones(); // Localise first. $timezones = array(); foreach (self::$goodzones as $tzkey => $ignored) { $timezones[$tzkey] = self::get_localised_timezone($tzkey); } core_collator::asort($timezones); // Add '99' if requested. if ($include99 or $currentvalue == 99) { $timezones['99'] = self::get_localised_timezone('99'); } if (!isset($currentvalue) or isset($timezones[$currentvalue])) { return $timezones; } if (is_numeric($currentvalue)) { // UTC offset. if ($currentvalue == 0) { $a = 'UTC'; } else { $modifier = ($currentvalue > 0) ? '+' : ''; $a = 'UTC' . $modifier . number_format($currentvalue, 1); } $timezones[$currentvalue] = get_string('timezoneinvalid', 'core_admin', $a); } else { // Some string we don't recognise. $timezones[$currentvalue] = get_string('timezoneinvalid', 'core_admin', $currentvalue); } return $timezones; }
[ "public", "static", "function", "get_list_of_timezones", "(", "$", "currentvalue", "=", "null", ",", "$", "include99", "=", "false", ")", "{", "self", "::", "init_zones", "(", ")", ";", "// Localise first.", "$", "timezones", "=", "array", "(", ")", ";", "foreach", "(", "self", "::", "$", "goodzones", "as", "$", "tzkey", "=>", "$", "ignored", ")", "{", "$", "timezones", "[", "$", "tzkey", "]", "=", "self", "::", "get_localised_timezone", "(", "$", "tzkey", ")", ";", "}", "core_collator", "::", "asort", "(", "$", "timezones", ")", ";", "// Add '99' if requested.", "if", "(", "$", "include99", "or", "$", "currentvalue", "==", "99", ")", "{", "$", "timezones", "[", "'99'", "]", "=", "self", "::", "get_localised_timezone", "(", "'99'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "currentvalue", ")", "or", "isset", "(", "$", "timezones", "[", "$", "currentvalue", "]", ")", ")", "{", "return", "$", "timezones", ";", "}", "if", "(", "is_numeric", "(", "$", "currentvalue", ")", ")", "{", "// UTC offset.", "if", "(", "$", "currentvalue", "==", "0", ")", "{", "$", "a", "=", "'UTC'", ";", "}", "else", "{", "$", "modifier", "=", "(", "$", "currentvalue", ">", "0", ")", "?", "'+'", ":", "''", ";", "$", "a", "=", "'UTC'", ".", "$", "modifier", ".", "number_format", "(", "$", "currentvalue", ",", "1", ")", ";", "}", "$", "timezones", "[", "$", "currentvalue", "]", "=", "get_string", "(", "'timezoneinvalid'", ",", "'core_admin'", ",", "$", "a", ")", ";", "}", "else", "{", "// Some string we don't recognise.", "$", "timezones", "[", "$", "currentvalue", "]", "=", "get_string", "(", "'timezoneinvalid'", ",", "'core_admin'", ",", "$", "currentvalue", ")", ";", "}", "return", "$", "timezones", ";", "}" ]
Returns a localised list of timezones. @param string $currentvalue @param bool $include99 should the server timezone info be included? @return array
[ "Returns", "a", "localised", "list", "of", "timezones", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/date.php#L54-L88
215,411
moodle/moodle
lib/classes/date.php
core_date.get_localised_timezone
public static function get_localised_timezone($tz) { if ($tz == 99) { $tz = self::get_server_timezone(); $tz = self::get_localised_timezone($tz); return get_string('timezoneserver', 'core_admin', $tz); } if (get_string_manager()->string_exists(strtolower($tz), 'core_timezones')) { $tz = get_string(strtolower($tz), 'core_timezones'); } else if ($tz === 'GMT' or $tz === 'Etc/GMT' or $tz === 'Etc/UTC') { $tz = 'UTC'; } else if (preg_match('|^Etc/GMT([+-])([0-9]+)$|', $tz, $matches)) { $sign = $matches[1] === '+' ? '-' : '+'; $tz = 'UTC' . $sign . $matches[2]; } return $tz; }
php
public static function get_localised_timezone($tz) { if ($tz == 99) { $tz = self::get_server_timezone(); $tz = self::get_localised_timezone($tz); return get_string('timezoneserver', 'core_admin', $tz); } if (get_string_manager()->string_exists(strtolower($tz), 'core_timezones')) { $tz = get_string(strtolower($tz), 'core_timezones'); } else if ($tz === 'GMT' or $tz === 'Etc/GMT' or $tz === 'Etc/UTC') { $tz = 'UTC'; } else if (preg_match('|^Etc/GMT([+-])([0-9]+)$|', $tz, $matches)) { $sign = $matches[1] === '+' ? '-' : '+'; $tz = 'UTC' . $sign . $matches[2]; } return $tz; }
[ "public", "static", "function", "get_localised_timezone", "(", "$", "tz", ")", "{", "if", "(", "$", "tz", "==", "99", ")", "{", "$", "tz", "=", "self", "::", "get_server_timezone", "(", ")", ";", "$", "tz", "=", "self", "::", "get_localised_timezone", "(", "$", "tz", ")", ";", "return", "get_string", "(", "'timezoneserver'", ",", "'core_admin'", ",", "$", "tz", ")", ";", "}", "if", "(", "get_string_manager", "(", ")", "->", "string_exists", "(", "strtolower", "(", "$", "tz", ")", ",", "'core_timezones'", ")", ")", "{", "$", "tz", "=", "get_string", "(", "strtolower", "(", "$", "tz", ")", ",", "'core_timezones'", ")", ";", "}", "else", "if", "(", "$", "tz", "===", "'GMT'", "or", "$", "tz", "===", "'Etc/GMT'", "or", "$", "tz", "===", "'Etc/UTC'", ")", "{", "$", "tz", "=", "'UTC'", ";", "}", "else", "if", "(", "preg_match", "(", "'|^Etc/GMT([+-])([0-9]+)$|'", ",", "$", "tz", ",", "$", "matches", ")", ")", "{", "$", "sign", "=", "$", "matches", "[", "1", "]", "===", "'+'", "?", "'-'", ":", "'+'", ";", "$", "tz", "=", "'UTC'", ".", "$", "sign", ".", "$", "matches", "[", "2", "]", ";", "}", "return", "$", "tz", ";", "}" ]
Returns localised timezone name. @param string $tz @return string
[ "Returns", "localised", "timezone", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/date.php#L95-L112
215,412
moodle/moodle
lib/classes/date.php
core_date.get_server_timezone
public static function get_server_timezone() { global $CFG; if (!isset($CFG->timezone) or $CFG->timezone == 99 or $CFG->timezone === '') { return self::get_default_php_timezone(); } return self::normalise_timezone($CFG->timezone); }
php
public static function get_server_timezone() { global $CFG; if (!isset($CFG->timezone) or $CFG->timezone == 99 or $CFG->timezone === '') { return self::get_default_php_timezone(); } return self::normalise_timezone($CFG->timezone); }
[ "public", "static", "function", "get_server_timezone", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "isset", "(", "$", "CFG", "->", "timezone", ")", "or", "$", "CFG", "->", "timezone", "==", "99", "or", "$", "CFG", "->", "timezone", "===", "''", ")", "{", "return", "self", "::", "get_default_php_timezone", "(", ")", ";", "}", "return", "self", "::", "normalise_timezone", "(", "$", "CFG", "->", "timezone", ")", ";", "}" ]
Returns server timezone. @return string normalised timezone name compatible with PHP
[ "Returns", "server", "timezone", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/date.php#L170-L178
215,413
moodle/moodle
lib/classes/date.php
core_date.get_user_timezone
public static function get_user_timezone($userorforcedtz = null) { global $USER, $CFG; if ($userorforcedtz instanceof DateTimeZone) { return $userorforcedtz->getName(); } if (isset($userorforcedtz) and !is_object($userorforcedtz) and $userorforcedtz != 99) { // Legacy code is forcing timezone in legacy API. return self::normalise_timezone($userorforcedtz); } if (isset($CFG->forcetimezone) and $CFG->forcetimezone != 99) { // Override any user timezone. return self::normalise_timezone($CFG->forcetimezone); } if ($userorforcedtz === null) { $tz = isset($USER->timezone) ? $USER->timezone : 99; } else if (is_object($userorforcedtz)) { $tz = isset($userorforcedtz->timezone) ? $userorforcedtz->timezone : 99; } else { if ($userorforcedtz == 99) { $tz = isset($USER->timezone) ? $USER->timezone : 99; } else { $tz = $userorforcedtz; } } if ($tz == 99) { return self::get_server_timezone(); } return self::normalise_timezone($tz); }
php
public static function get_user_timezone($userorforcedtz = null) { global $USER, $CFG; if ($userorforcedtz instanceof DateTimeZone) { return $userorforcedtz->getName(); } if (isset($userorforcedtz) and !is_object($userorforcedtz) and $userorforcedtz != 99) { // Legacy code is forcing timezone in legacy API. return self::normalise_timezone($userorforcedtz); } if (isset($CFG->forcetimezone) and $CFG->forcetimezone != 99) { // Override any user timezone. return self::normalise_timezone($CFG->forcetimezone); } if ($userorforcedtz === null) { $tz = isset($USER->timezone) ? $USER->timezone : 99; } else if (is_object($userorforcedtz)) { $tz = isset($userorforcedtz->timezone) ? $userorforcedtz->timezone : 99; } else { if ($userorforcedtz == 99) { $tz = isset($USER->timezone) ? $USER->timezone : 99; } else { $tz = $userorforcedtz; } } if ($tz == 99) { return self::get_server_timezone(); } return self::normalise_timezone($tz); }
[ "public", "static", "function", "get_user_timezone", "(", "$", "userorforcedtz", "=", "null", ")", "{", "global", "$", "USER", ",", "$", "CFG", ";", "if", "(", "$", "userorforcedtz", "instanceof", "DateTimeZone", ")", "{", "return", "$", "userorforcedtz", "->", "getName", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "userorforcedtz", ")", "and", "!", "is_object", "(", "$", "userorforcedtz", ")", "and", "$", "userorforcedtz", "!=", "99", ")", "{", "// Legacy code is forcing timezone in legacy API.", "return", "self", "::", "normalise_timezone", "(", "$", "userorforcedtz", ")", ";", "}", "if", "(", "isset", "(", "$", "CFG", "->", "forcetimezone", ")", "and", "$", "CFG", "->", "forcetimezone", "!=", "99", ")", "{", "// Override any user timezone.", "return", "self", "::", "normalise_timezone", "(", "$", "CFG", "->", "forcetimezone", ")", ";", "}", "if", "(", "$", "userorforcedtz", "===", "null", ")", "{", "$", "tz", "=", "isset", "(", "$", "USER", "->", "timezone", ")", "?", "$", "USER", "->", "timezone", ":", "99", ";", "}", "else", "if", "(", "is_object", "(", "$", "userorforcedtz", ")", ")", "{", "$", "tz", "=", "isset", "(", "$", "userorforcedtz", "->", "timezone", ")", "?", "$", "userorforcedtz", "->", "timezone", ":", "99", ";", "}", "else", "{", "if", "(", "$", "userorforcedtz", "==", "99", ")", "{", "$", "tz", "=", "isset", "(", "$", "USER", "->", "timezone", ")", "?", "$", "USER", "->", "timezone", ":", "99", ";", "}", "else", "{", "$", "tz", "=", "$", "userorforcedtz", ";", "}", "}", "if", "(", "$", "tz", "==", "99", ")", "{", "return", "self", "::", "get_server_timezone", "(", ")", ";", "}", "return", "self", "::", "normalise_timezone", "(", "$", "tz", ")", ";", "}" ]
Returns user timezone. Ideally the parameter should be a real user record, unfortunately the legacy code is using 99 for both server and default value. Example of using legacy API: // Date for other user via legacy API. $datestr = userdate($time, core_date::get_user_timezone($user)); The coding style rules in Moodle are moronic, why cannot the parameter names have underscores in them? @param mixed $userorforcedtz user object or legacy forced timezone string or tz object @return string normalised timezone name compatible with PHP
[ "Returns", "user", "timezone", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/date.php#L237-L273
215,414
moodle/moodle
grade/report/singleview/classes/local/screen/user.php
user.options
public function options() { $result = array(); foreach ($this->items as $itemid => $item) { $result[$itemid] = $item->get_name(); } return $result; }
php
public function options() { $result = array(); foreach ($this->items as $itemid => $item) { $result[$itemid] = $item->get_name(); } return $result; }
[ "public", "function", "options", "(", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "items", "as", "$", "itemid", "=>", "$", "item", ")", "{", "$", "result", "[", "$", "itemid", "]", "=", "$", "item", "->", "get_name", "(", ")", ";", "}", "return", "$", "result", ";", "}" ]
Convert the list of items to a list of options. @return array
[ "Convert", "the", "list", "of", "items", "to", "a", "list", "of", "options", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/user.php#L77-L83
215,415
moodle/moodle
grade/report/singleview/classes/local/screen/user.php
user.init
public function init($selfitemisempty = false) { global $DB; if (!$selfitemisempty) { $validusers = $this->load_users(); if (!isset($validusers[$this->itemid])) { // If the passed user id is not valid, show the first user from the list instead. $this->item = reset($validusers); $this->itemid = $this->item->id; } else { $this->item = $validusers[$this->itemid]; } } $params = array('courseid' => $this->courseid); $seq = new grade_seq($this->courseid, true); $this->items = array(); foreach ($seq->items as $itemid => $item) { if (grade::filter($item)) { $this->items[$itemid] = $item; } } $this->requirespaging = count($this->items) > $this->perpage; $this->setup_structure(); $this->definition = array( 'finalgrade', 'feedback', 'override', 'exclude' ); $this->set_headers($this->original_headers()); }
php
public function init($selfitemisempty = false) { global $DB; if (!$selfitemisempty) { $validusers = $this->load_users(); if (!isset($validusers[$this->itemid])) { // If the passed user id is not valid, show the first user from the list instead. $this->item = reset($validusers); $this->itemid = $this->item->id; } else { $this->item = $validusers[$this->itemid]; } } $params = array('courseid' => $this->courseid); $seq = new grade_seq($this->courseid, true); $this->items = array(); foreach ($seq->items as $itemid => $item) { if (grade::filter($item)) { $this->items[$itemid] = $item; } } $this->requirespaging = count($this->items) > $this->perpage; $this->setup_structure(); $this->definition = array( 'finalgrade', 'feedback', 'override', 'exclude' ); $this->set_headers($this->original_headers()); }
[ "public", "function", "init", "(", "$", "selfitemisempty", "=", "false", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "$", "selfitemisempty", ")", "{", "$", "validusers", "=", "$", "this", "->", "load_users", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "validusers", "[", "$", "this", "->", "itemid", "]", ")", ")", "{", "// If the passed user id is not valid, show the first user from the list instead.", "$", "this", "->", "item", "=", "reset", "(", "$", "validusers", ")", ";", "$", "this", "->", "itemid", "=", "$", "this", "->", "item", "->", "id", ";", "}", "else", "{", "$", "this", "->", "item", "=", "$", "validusers", "[", "$", "this", "->", "itemid", "]", ";", "}", "}", "$", "params", "=", "array", "(", "'courseid'", "=>", "$", "this", "->", "courseid", ")", ";", "$", "seq", "=", "new", "grade_seq", "(", "$", "this", "->", "courseid", ",", "true", ")", ";", "$", "this", "->", "items", "=", "array", "(", ")", ";", "foreach", "(", "$", "seq", "->", "items", "as", "$", "itemid", "=>", "$", "item", ")", "{", "if", "(", "grade", "::", "filter", "(", "$", "item", ")", ")", "{", "$", "this", "->", "items", "[", "$", "itemid", "]", "=", "$", "item", ";", "}", "}", "$", "this", "->", "requirespaging", "=", "count", "(", "$", "this", "->", "items", ")", ">", "$", "this", "->", "perpage", ";", "$", "this", "->", "setup_structure", "(", ")", ";", "$", "this", "->", "definition", "=", "array", "(", "'finalgrade'", ",", "'feedback'", ",", "'override'", ",", "'exclude'", ")", ";", "$", "this", "->", "set_headers", "(", "$", "this", "->", "original_headers", "(", ")", ")", ";", "}" ]
Init the screen @param bool $selfitemisempty Have we selected an item yet?
[ "Init", "the", "screen" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/user.php#L99-L132
215,416
moodle/moodle
grade/report/singleview/classes/local/screen/user.php
user.original_headers
public function original_headers() { return array( '', // For filter icon. get_string('assessmentname', 'gradereport_singleview'), get_string('gradecategory', 'grades'), get_string('range', 'grades'), get_string('grade', 'grades'), get_string('feedback', 'grades'), $this->make_toggle_links('override'), $this->make_toggle_links('exclude') ); }
php
public function original_headers() { return array( '', // For filter icon. get_string('assessmentname', 'gradereport_singleview'), get_string('gradecategory', 'grades'), get_string('range', 'grades'), get_string('grade', 'grades'), get_string('feedback', 'grades'), $this->make_toggle_links('override'), $this->make_toggle_links('exclude') ); }
[ "public", "function", "original_headers", "(", ")", "{", "return", "array", "(", "''", ",", "// For filter icon.", "get_string", "(", "'assessmentname'", ",", "'gradereport_singleview'", ")", ",", "get_string", "(", "'gradecategory'", ",", "'grades'", ")", ",", "get_string", "(", "'range'", ",", "'grades'", ")", ",", "get_string", "(", "'grade'", ",", "'grades'", ")", ",", "get_string", "(", "'feedback'", ",", "'grades'", ")", ",", "$", "this", "->", "make_toggle_links", "(", "'override'", ")", ",", "$", "this", "->", "make_toggle_links", "(", "'exclude'", ")", ")", ";", "}" ]
Get the list of headers for the table. @return array List of headers
[ "Get", "the", "list", "of", "headers", "for", "the", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/user.php#L139-L150
215,417
moodle/moodle
grade/report/singleview/classes/local/screen/user.php
user.format_line
public function format_line($item) { global $OUTPUT; $grade = $this->fetch_grade_or_default($item, $this->item->id); $lockicon = ''; $lockeditem = $lockeditemgrade = 0; if (!empty($grade->locked)) { $lockeditem = 1; } if (!empty($grade->grade_item->locked)) { $lockeditemgrade = 1; } // Check both grade and grade item. if ($lockeditem || $lockeditemgrade) { $lockicon = $OUTPUT->pix_icon('t/locked', 'grade is locked'); } $iconstring = get_string('filtergrades', 'gradereport_singleview', $item->get_name()); // Create a fake gradetreeitem so we can call get_element_header(). // The type logic below is from grade_category->_get_children_recursion(). $gradetreeitem = array(); if (in_array($item->itemtype, array('course', 'category'))) { $gradetreeitem['type'] = $item->itemtype.'item'; } else { $gradetreeitem['type'] = 'item'; } $gradetreeitem['object'] = $item; $gradetreeitem['userid'] = $this->item->id; $itemlabel = $this->structure->get_element_header($gradetreeitem, true, false, false, false, true); $grade->label = $item->get_name(); $line = array( $OUTPUT->action_icon($this->format_link('grade', $item->id), new pix_icon('t/editstring', $iconstring)), $this->format_icon($item) . $lockicon . $itemlabel, $this->category($item), new range($item) ); $lineclasses = array( "action", "gradeitem", "category", "range" ); $outputline = array(); $i = 0; foreach ($line as $key => $value) { $cell = new \html_table_cell($value); if ($isheader = $i == 1) { $cell->header = $isheader; $cell->scope = "row"; } if (array_key_exists($key, $lineclasses)) { $cell->attributes['class'] = $lineclasses[$key]; } $outputline[] = $cell; $i++; } return $this->format_definition($outputline, $grade); }
php
public function format_line($item) { global $OUTPUT; $grade = $this->fetch_grade_or_default($item, $this->item->id); $lockicon = ''; $lockeditem = $lockeditemgrade = 0; if (!empty($grade->locked)) { $lockeditem = 1; } if (!empty($grade->grade_item->locked)) { $lockeditemgrade = 1; } // Check both grade and grade item. if ($lockeditem || $lockeditemgrade) { $lockicon = $OUTPUT->pix_icon('t/locked', 'grade is locked'); } $iconstring = get_string('filtergrades', 'gradereport_singleview', $item->get_name()); // Create a fake gradetreeitem so we can call get_element_header(). // The type logic below is from grade_category->_get_children_recursion(). $gradetreeitem = array(); if (in_array($item->itemtype, array('course', 'category'))) { $gradetreeitem['type'] = $item->itemtype.'item'; } else { $gradetreeitem['type'] = 'item'; } $gradetreeitem['object'] = $item; $gradetreeitem['userid'] = $this->item->id; $itemlabel = $this->structure->get_element_header($gradetreeitem, true, false, false, false, true); $grade->label = $item->get_name(); $line = array( $OUTPUT->action_icon($this->format_link('grade', $item->id), new pix_icon('t/editstring', $iconstring)), $this->format_icon($item) . $lockicon . $itemlabel, $this->category($item), new range($item) ); $lineclasses = array( "action", "gradeitem", "category", "range" ); $outputline = array(); $i = 0; foreach ($line as $key => $value) { $cell = new \html_table_cell($value); if ($isheader = $i == 1) { $cell->header = $isheader; $cell->scope = "row"; } if (array_key_exists($key, $lineclasses)) { $cell->attributes['class'] = $lineclasses[$key]; } $outputline[] = $cell; $i++; } return $this->format_definition($outputline, $grade); }
[ "public", "function", "format_line", "(", "$", "item", ")", "{", "global", "$", "OUTPUT", ";", "$", "grade", "=", "$", "this", "->", "fetch_grade_or_default", "(", "$", "item", ",", "$", "this", "->", "item", "->", "id", ")", ";", "$", "lockicon", "=", "''", ";", "$", "lockeditem", "=", "$", "lockeditemgrade", "=", "0", ";", "if", "(", "!", "empty", "(", "$", "grade", "->", "locked", ")", ")", "{", "$", "lockeditem", "=", "1", ";", "}", "if", "(", "!", "empty", "(", "$", "grade", "->", "grade_item", "->", "locked", ")", ")", "{", "$", "lockeditemgrade", "=", "1", ";", "}", "// Check both grade and grade item.", "if", "(", "$", "lockeditem", "||", "$", "lockeditemgrade", ")", "{", "$", "lockicon", "=", "$", "OUTPUT", "->", "pix_icon", "(", "'t/locked'", ",", "'grade is locked'", ")", ";", "}", "$", "iconstring", "=", "get_string", "(", "'filtergrades'", ",", "'gradereport_singleview'", ",", "$", "item", "->", "get_name", "(", ")", ")", ";", "// Create a fake gradetreeitem so we can call get_element_header().", "// The type logic below is from grade_category->_get_children_recursion().", "$", "gradetreeitem", "=", "array", "(", ")", ";", "if", "(", "in_array", "(", "$", "item", "->", "itemtype", ",", "array", "(", "'course'", ",", "'category'", ")", ")", ")", "{", "$", "gradetreeitem", "[", "'type'", "]", "=", "$", "item", "->", "itemtype", ".", "'item'", ";", "}", "else", "{", "$", "gradetreeitem", "[", "'type'", "]", "=", "'item'", ";", "}", "$", "gradetreeitem", "[", "'object'", "]", "=", "$", "item", ";", "$", "gradetreeitem", "[", "'userid'", "]", "=", "$", "this", "->", "item", "->", "id", ";", "$", "itemlabel", "=", "$", "this", "->", "structure", "->", "get_element_header", "(", "$", "gradetreeitem", ",", "true", ",", "false", ",", "false", ",", "false", ",", "true", ")", ";", "$", "grade", "->", "label", "=", "$", "item", "->", "get_name", "(", ")", ";", "$", "line", "=", "array", "(", "$", "OUTPUT", "->", "action_icon", "(", "$", "this", "->", "format_link", "(", "'grade'", ",", "$", "item", "->", "id", ")", ",", "new", "pix_icon", "(", "'t/editstring'", ",", "$", "iconstring", ")", ")", ",", "$", "this", "->", "format_icon", "(", "$", "item", ")", ".", "$", "lockicon", ".", "$", "itemlabel", ",", "$", "this", "->", "category", "(", "$", "item", ")", ",", "new", "range", "(", "$", "item", ")", ")", ";", "$", "lineclasses", "=", "array", "(", "\"action\"", ",", "\"gradeitem\"", ",", "\"category\"", ",", "\"range\"", ")", ";", "$", "outputline", "=", "array", "(", ")", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "line", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "cell", "=", "new", "\\", "html_table_cell", "(", "$", "value", ")", ";", "if", "(", "$", "isheader", "=", "$", "i", "==", "1", ")", "{", "$", "cell", "->", "header", "=", "$", "isheader", ";", "$", "cell", "->", "scope", "=", "\"row\"", ";", "}", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "lineclasses", ")", ")", "{", "$", "cell", "->", "attributes", "[", "'class'", "]", "=", "$", "lineclasses", "[", "$", "key", "]", ";", "}", "$", "outputline", "[", "]", "=", "$", "cell", ";", "$", "i", "++", ";", "}", "return", "$", "this", "->", "format_definition", "(", "$", "outputline", ",", "$", "grade", ")", ";", "}" ]
Format each row of the table. @param grade_item $item @return string
[ "Format", "each", "row", "of", "the", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/user.php#L158-L221
215,418
moodle/moodle
grade/report/singleview/classes/local/screen/user.php
user.category
private function category($item) { global $DB; if (empty($item->categoryid)) { if ($item->itemtype == 'course') { return $this->course->fullname; } $params = array('id' => $item->iteminstance); $elem = $DB->get_record('grade_categories', $params); return $elem->fullname; } if (!isset($this->categories[$item->categoryid])) { $category = $item->get_parent_category(); $this->categories[$category->id] = $category; } return $this->categories[$item->categoryid]->get_name(); }
php
private function category($item) { global $DB; if (empty($item->categoryid)) { if ($item->itemtype == 'course') { return $this->course->fullname; } $params = array('id' => $item->iteminstance); $elem = $DB->get_record('grade_categories', $params); return $elem->fullname; } if (!isset($this->categories[$item->categoryid])) { $category = $item->get_parent_category(); $this->categories[$category->id] = $category; } return $this->categories[$item->categoryid]->get_name(); }
[ "private", "function", "category", "(", "$", "item", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "item", "->", "categoryid", ")", ")", "{", "if", "(", "$", "item", "->", "itemtype", "==", "'course'", ")", "{", "return", "$", "this", "->", "course", "->", "fullname", ";", "}", "$", "params", "=", "array", "(", "'id'", "=>", "$", "item", "->", "iteminstance", ")", ";", "$", "elem", "=", "$", "DB", "->", "get_record", "(", "'grade_categories'", ",", "$", "params", ")", ";", "return", "$", "elem", "->", "fullname", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "categories", "[", "$", "item", "->", "categoryid", "]", ")", ")", "{", "$", "category", "=", "$", "item", "->", "get_parent_category", "(", ")", ";", "$", "this", "->", "categories", "[", "$", "category", "->", "id", "]", "=", "$", "category", ";", "}", "return", "$", "this", "->", "categories", "[", "$", "item", "->", "categoryid", "]", "->", "get_name", "(", ")", ";", "}" ]
Helper to get the category for an item. @param grade_item $item @return grade_category
[ "Helper", "to", "get", "the", "category", "for", "an", "item", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/user.php#L240-L262
215,419
moodle/moodle
grade/report/singleview/classes/local/screen/user.php
user.process
public function process($data) { $bulk = new bulk_insert($this->item); // Bulk insert messages the data to be passed in // ie: for all grades of empty grades apply the specified value. if ($bulk->is_applied($data)) { $filter = $bulk->get_type($data); $insertvalue = $bulk->get_insert_value($data); $userid = $this->item->id; foreach ($this->items as $gradeitemid => $gradeitem) { $null = $gradeitem->gradetype == GRADE_TYPE_SCALE ? -1 : ''; $field = "finalgrade_{$gradeitem->id}_{$this->itemid}"; if (isset($data->$field)) { continue; } $oldfinalgradefield = "oldfinalgrade_{$gradeitem->id}_{$this->itemid}"; // Bulk grade changes for all grades need to be processed and shouldn't be skipped if they had a previous grade. if ($gradeitem->is_course_item() || ($filter != 'all' && !empty($data->$oldfinalgradefield))) { if ($gradeitem->is_course_item()) { // The course total should not be overridden. unset($data->$field); unset($data->oldfinalgradefield); $oldoverride = "oldoverride_{$gradeitem->id}_{$this->itemid}"; unset($data->$oldoverride); $oldfeedback = "oldfeedback_{$gradeitem->id}_{$this->itemid}"; unset($data->$oldfeedback); } continue; } $grade = grade_grade::fetch(array( 'itemid' => $gradeitemid, 'userid' => $userid )); $data->$field = empty($grade) ? $null : $grade->finalgrade; $data->{"old$field"} = $data->$field; } foreach ($data as $varname => $value) { if (preg_match('/^oldoverride_(\d+)_(\d+)/', $varname, $matches)) { // If we've selected overriding all grades. if ($filter == 'all') { $override = "override_{$matches[1]}_{$matches[2]}"; $data->$override = '1'; } } if (!preg_match('/^finalgrade_(\d+)_(\d+)/', $varname, $matches)) { continue; } $gradeitem = grade_item::fetch(array( 'courseid' => $this->courseid, 'id' => $matches[1] )); $isscale = ($gradeitem->gradetype == GRADE_TYPE_SCALE); $empties = (trim($value) === '' or ($isscale and $value == -1)); if ($filter == 'all' or $empties) { $data->$varname = ($isscale and empty($insertvalue)) ? -1 : $insertvalue; } } } return parent::process($data); }
php
public function process($data) { $bulk = new bulk_insert($this->item); // Bulk insert messages the data to be passed in // ie: for all grades of empty grades apply the specified value. if ($bulk->is_applied($data)) { $filter = $bulk->get_type($data); $insertvalue = $bulk->get_insert_value($data); $userid = $this->item->id; foreach ($this->items as $gradeitemid => $gradeitem) { $null = $gradeitem->gradetype == GRADE_TYPE_SCALE ? -1 : ''; $field = "finalgrade_{$gradeitem->id}_{$this->itemid}"; if (isset($data->$field)) { continue; } $oldfinalgradefield = "oldfinalgrade_{$gradeitem->id}_{$this->itemid}"; // Bulk grade changes for all grades need to be processed and shouldn't be skipped if they had a previous grade. if ($gradeitem->is_course_item() || ($filter != 'all' && !empty($data->$oldfinalgradefield))) { if ($gradeitem->is_course_item()) { // The course total should not be overridden. unset($data->$field); unset($data->oldfinalgradefield); $oldoverride = "oldoverride_{$gradeitem->id}_{$this->itemid}"; unset($data->$oldoverride); $oldfeedback = "oldfeedback_{$gradeitem->id}_{$this->itemid}"; unset($data->$oldfeedback); } continue; } $grade = grade_grade::fetch(array( 'itemid' => $gradeitemid, 'userid' => $userid )); $data->$field = empty($grade) ? $null : $grade->finalgrade; $data->{"old$field"} = $data->$field; } foreach ($data as $varname => $value) { if (preg_match('/^oldoverride_(\d+)_(\d+)/', $varname, $matches)) { // If we've selected overriding all grades. if ($filter == 'all') { $override = "override_{$matches[1]}_{$matches[2]}"; $data->$override = '1'; } } if (!preg_match('/^finalgrade_(\d+)_(\d+)/', $varname, $matches)) { continue; } $gradeitem = grade_item::fetch(array( 'courseid' => $this->courseid, 'id' => $matches[1] )); $isscale = ($gradeitem->gradetype == GRADE_TYPE_SCALE); $empties = (trim($value) === '' or ($isscale and $value == -1)); if ($filter == 'all' or $empties) { $data->$varname = ($isscale and empty($insertvalue)) ? -1 : $insertvalue; } } } return parent::process($data); }
[ "public", "function", "process", "(", "$", "data", ")", "{", "$", "bulk", "=", "new", "bulk_insert", "(", "$", "this", "->", "item", ")", ";", "// Bulk insert messages the data to be passed in", "// ie: for all grades of empty grades apply the specified value.", "if", "(", "$", "bulk", "->", "is_applied", "(", "$", "data", ")", ")", "{", "$", "filter", "=", "$", "bulk", "->", "get_type", "(", "$", "data", ")", ";", "$", "insertvalue", "=", "$", "bulk", "->", "get_insert_value", "(", "$", "data", ")", ";", "$", "userid", "=", "$", "this", "->", "item", "->", "id", ";", "foreach", "(", "$", "this", "->", "items", "as", "$", "gradeitemid", "=>", "$", "gradeitem", ")", "{", "$", "null", "=", "$", "gradeitem", "->", "gradetype", "==", "GRADE_TYPE_SCALE", "?", "-", "1", ":", "''", ";", "$", "field", "=", "\"finalgrade_{$gradeitem->id}_{$this->itemid}\"", ";", "if", "(", "isset", "(", "$", "data", "->", "$", "field", ")", ")", "{", "continue", ";", "}", "$", "oldfinalgradefield", "=", "\"oldfinalgrade_{$gradeitem->id}_{$this->itemid}\"", ";", "// Bulk grade changes for all grades need to be processed and shouldn't be skipped if they had a previous grade.", "if", "(", "$", "gradeitem", "->", "is_course_item", "(", ")", "||", "(", "$", "filter", "!=", "'all'", "&&", "!", "empty", "(", "$", "data", "->", "$", "oldfinalgradefield", ")", ")", ")", "{", "if", "(", "$", "gradeitem", "->", "is_course_item", "(", ")", ")", "{", "// The course total should not be overridden.", "unset", "(", "$", "data", "->", "$", "field", ")", ";", "unset", "(", "$", "data", "->", "oldfinalgradefield", ")", ";", "$", "oldoverride", "=", "\"oldoverride_{$gradeitem->id}_{$this->itemid}\"", ";", "unset", "(", "$", "data", "->", "$", "oldoverride", ")", ";", "$", "oldfeedback", "=", "\"oldfeedback_{$gradeitem->id}_{$this->itemid}\"", ";", "unset", "(", "$", "data", "->", "$", "oldfeedback", ")", ";", "}", "continue", ";", "}", "$", "grade", "=", "grade_grade", "::", "fetch", "(", "array", "(", "'itemid'", "=>", "$", "gradeitemid", ",", "'userid'", "=>", "$", "userid", ")", ")", ";", "$", "data", "->", "$", "field", "=", "empty", "(", "$", "grade", ")", "?", "$", "null", ":", "$", "grade", "->", "finalgrade", ";", "$", "data", "->", "{", "\"old$field\"", "}", "=", "$", "data", "->", "$", "field", ";", "}", "foreach", "(", "$", "data", "as", "$", "varname", "=>", "$", "value", ")", "{", "if", "(", "preg_match", "(", "'/^oldoverride_(\\d+)_(\\d+)/'", ",", "$", "varname", ",", "$", "matches", ")", ")", "{", "// If we've selected overriding all grades.", "if", "(", "$", "filter", "==", "'all'", ")", "{", "$", "override", "=", "\"override_{$matches[1]}_{$matches[2]}\"", ";", "$", "data", "->", "$", "override", "=", "'1'", ";", "}", "}", "if", "(", "!", "preg_match", "(", "'/^finalgrade_(\\d+)_(\\d+)/'", ",", "$", "varname", ",", "$", "matches", ")", ")", "{", "continue", ";", "}", "$", "gradeitem", "=", "grade_item", "::", "fetch", "(", "array", "(", "'courseid'", "=>", "$", "this", "->", "courseid", ",", "'id'", "=>", "$", "matches", "[", "1", "]", ")", ")", ";", "$", "isscale", "=", "(", "$", "gradeitem", "->", "gradetype", "==", "GRADE_TYPE_SCALE", ")", ";", "$", "empties", "=", "(", "trim", "(", "$", "value", ")", "===", "''", "or", "(", "$", "isscale", "and", "$", "value", "==", "-", "1", ")", ")", ";", "if", "(", "$", "filter", "==", "'all'", "or", "$", "empties", ")", "{", "$", "data", "->", "$", "varname", "=", "(", "$", "isscale", "and", "empty", "(", "$", "insertvalue", ")", ")", "?", "-", "1", ":", "$", "insertvalue", ";", "}", "}", "}", "return", "parent", "::", "process", "(", "$", "data", ")", ";", "}" ]
Process the data from the form. @param array $data @return array of warnings
[ "Process", "the", "data", "from", "the", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/user.php#L322-L389
215,420
moodle/moodle
mod/quiz/backup/moodle2/backup_quiz_activity_task.class.php
backup_quiz_activity_task.define_my_steps
protected function define_my_steps() { // Generate the quiz.xml file containing all the quiz information // and annotating used questions. $this->add_step(new backup_quiz_activity_structure_step('quiz_structure', 'quiz.xml')); // Note: Following steps must be present // in all the activities using question banks (only quiz for now) // TODO: Specialise these step to a new subclass of backup_activity_task. // Process all the annotated questions to calculate the question // categories needing to be included in backup for this activity // plus the categories belonging to the activity context itself. $this->add_step(new backup_calculate_question_categories('activity_question_categories')); // Clean backup_temp_ids table from questions. We already // have used them to detect question_categories and aren't // needed anymore. $this->add_step(new backup_delete_temp_questions('clean_temp_questions')); }
php
protected function define_my_steps() { // Generate the quiz.xml file containing all the quiz information // and annotating used questions. $this->add_step(new backup_quiz_activity_structure_step('quiz_structure', 'quiz.xml')); // Note: Following steps must be present // in all the activities using question banks (only quiz for now) // TODO: Specialise these step to a new subclass of backup_activity_task. // Process all the annotated questions to calculate the question // categories needing to be included in backup for this activity // plus the categories belonging to the activity context itself. $this->add_step(new backup_calculate_question_categories('activity_question_categories')); // Clean backup_temp_ids table from questions. We already // have used them to detect question_categories and aren't // needed anymore. $this->add_step(new backup_delete_temp_questions('clean_temp_questions')); }
[ "protected", "function", "define_my_steps", "(", ")", "{", "// Generate the quiz.xml file containing all the quiz information", "// and annotating used questions.", "$", "this", "->", "add_step", "(", "new", "backup_quiz_activity_structure_step", "(", "'quiz_structure'", ",", "'quiz.xml'", ")", ")", ";", "// Note: Following steps must be present", "// in all the activities using question banks (only quiz for now)", "// TODO: Specialise these step to a new subclass of backup_activity_task.", "// Process all the annotated questions to calculate the question", "// categories needing to be included in backup for this activity", "// plus the categories belonging to the activity context itself.", "$", "this", "->", "add_step", "(", "new", "backup_calculate_question_categories", "(", "'activity_question_categories'", ")", ")", ";", "// Clean backup_temp_ids table from questions. We already", "// have used them to detect question_categories and aren't", "// needed anymore.", "$", "this", "->", "add_step", "(", "new", "backup_delete_temp_questions", "(", "'clean_temp_questions'", ")", ")", ";", "}" ]
Defines backup steps to store the instance data and required questions
[ "Defines", "backup", "steps", "to", "store", "the", "instance", "data", "and", "required", "questions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/backup/moodle2/backup_quiz_activity_task.class.php#L47-L65
215,421
moodle/moodle
cache/stores/mongodb/MongoDB/Collection.php
Collection.bulkWrite
public function bulkWrite(array $operations, array $options = []) { if ( ! isset($options['writeConcern'])) { $options['writeConcern'] = $this->writeConcern; } $operation = new BulkWrite($this->databaseName, $this->collectionName, $operations, $options); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $operation->execute($server); }
php
public function bulkWrite(array $operations, array $options = []) { if ( ! isset($options['writeConcern'])) { $options['writeConcern'] = $this->writeConcern; } $operation = new BulkWrite($this->databaseName, $this->collectionName, $operations, $options); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $operation->execute($server); }
[ "public", "function", "bulkWrite", "(", "array", "$", "operations", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'writeConcern'", "]", ")", ")", "{", "$", "options", "[", "'writeConcern'", "]", "=", "$", "this", "->", "writeConcern", ";", "}", "$", "operation", "=", "new", "BulkWrite", "(", "$", "this", "->", "databaseName", ",", "$", "this", "->", "collectionName", ",", "$", "operations", ",", "$", "options", ")", ";", "$", "server", "=", "$", "this", "->", "manager", "->", "selectServer", "(", "new", "ReadPreference", "(", "ReadPreference", "::", "RP_PRIMARY", ")", ")", ";", "return", "$", "operation", "->", "execute", "(", "$", "server", ")", ";", "}" ]
Executes multiple write operations. @see BulkWrite::__construct() for supported options @param array[] $operations List of write operations @param array $options Command options @return BulkWriteResult @throws UnsupportedException if options are not supported by the selected server @throws InvalidArgumentException for parameter/option parsing errors @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Executes", "multiple", "write", "operations", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Collection.php#L237-L247
215,422
moodle/moodle
cache/stores/mongodb/MongoDB/Collection.php
Collection.createIndex
public function createIndex($key, array $options = []) { $commandOptionKeys = ['maxTimeMS' => 1, 'session' => 1, 'writeConcern' => 1]; $indexOptions = array_diff_key($options, $commandOptionKeys); $commandOptions = array_intersect_key($options, $commandOptionKeys); return current($this->createIndexes([['key' => $key] + $indexOptions], $commandOptions)); }
php
public function createIndex($key, array $options = []) { $commandOptionKeys = ['maxTimeMS' => 1, 'session' => 1, 'writeConcern' => 1]; $indexOptions = array_diff_key($options, $commandOptionKeys); $commandOptions = array_intersect_key($options, $commandOptionKeys); return current($this->createIndexes([['key' => $key] + $indexOptions], $commandOptions)); }
[ "public", "function", "createIndex", "(", "$", "key", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "commandOptionKeys", "=", "[", "'maxTimeMS'", "=>", "1", ",", "'session'", "=>", "1", ",", "'writeConcern'", "=>", "1", "]", ";", "$", "indexOptions", "=", "array_diff_key", "(", "$", "options", ",", "$", "commandOptionKeys", ")", ";", "$", "commandOptions", "=", "array_intersect_key", "(", "$", "options", ",", "$", "commandOptionKeys", ")", ";", "return", "current", "(", "$", "this", "->", "createIndexes", "(", "[", "[", "'key'", "=>", "$", "key", "]", "+", "$", "indexOptions", "]", ",", "$", "commandOptions", ")", ")", ";", "}" ]
Create a single index for the collection. @see Collection::createIndexes() @see CreateIndexes::__construct() for supported command options @param array|object $key Document containing fields mapped to values, which denote order or an index type @param array $options Index and command options @return string The name of the created index @throws UnsupportedException if options are not supported by the selected server @throws InvalidArgumentException for parameter/option parsing errors @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Create", "a", "single", "index", "for", "the", "collection", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Collection.php#L322-L329
215,423
moodle/moodle
cache/stores/mongodb/MongoDB/Collection.php
Collection.createIndexes
public function createIndexes(array $indexes, array $options = []) { $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); if ( ! isset($options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern)) { $options['writeConcern'] = $this->writeConcern; } $operation = new CreateIndexes($this->databaseName, $this->collectionName, $indexes, $options); return $operation->execute($server); }
php
public function createIndexes(array $indexes, array $options = []) { $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); if ( ! isset($options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern)) { $options['writeConcern'] = $this->writeConcern; } $operation = new CreateIndexes($this->databaseName, $this->collectionName, $indexes, $options); return $operation->execute($server); }
[ "public", "function", "createIndexes", "(", "array", "$", "indexes", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "server", "=", "$", "this", "->", "manager", "->", "selectServer", "(", "new", "ReadPreference", "(", "ReadPreference", "::", "RP_PRIMARY", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "options", "[", "'writeConcern'", "]", ")", "&&", "\\", "MongoDB", "\\", "server_supports_feature", "(", "$", "server", ",", "self", "::", "$", "wireVersionForWritableCommandWriteConcern", ")", ")", "{", "$", "options", "[", "'writeConcern'", "]", "=", "$", "this", "->", "writeConcern", ";", "}", "$", "operation", "=", "new", "CreateIndexes", "(", "$", "this", "->", "databaseName", ",", "$", "this", "->", "collectionName", ",", "$", "indexes", ",", "$", "options", ")", ";", "return", "$", "operation", "->", "execute", "(", "$", "server", ")", ";", "}" ]
Create one or more indexes for the collection. Each element in the $indexes array must have a "key" document, which contains fields mapped to an order or type. Other options may follow. For example: $indexes = [ // Create a unique index on the "username" field [ 'key' => [ 'username' => 1 ], 'unique' => true ], // Create a 2dsphere index on the "loc" field with a custom name [ 'key' => [ 'loc' => '2dsphere' ], 'name' => 'geo' ], ]; If the "name" option is unspecified, a name will be generated from the "key" document. @see http://docs.mongodb.org/manual/reference/command/createIndexes/ @see http://docs.mongodb.org/manual/reference/method/db.collection.createIndex/ @see CreateIndexes::__construct() for supported command options @param array[] $indexes List of index specifications @param array $options Command options @return string[] The names of the created indexes @throws UnsupportedException if options are not supported by the selected server @throws InvalidArgumentException for parameter/option parsing errors @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Create", "one", "or", "more", "indexes", "for", "the", "collection", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Collection.php#L358-L369
215,424
moodle/moodle
cache/stores/mongodb/MongoDB/Collection.php
Collection.deleteMany
public function deleteMany($filter, array $options = []) { if ( ! isset($options['writeConcern'])) { $options['writeConcern'] = $this->writeConcern; } $operation = new DeleteMany($this->databaseName, $this->collectionName, $filter, $options); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $operation->execute($server); }
php
public function deleteMany($filter, array $options = []) { if ( ! isset($options['writeConcern'])) { $options['writeConcern'] = $this->writeConcern; } $operation = new DeleteMany($this->databaseName, $this->collectionName, $filter, $options); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $operation->execute($server); }
[ "public", "function", "deleteMany", "(", "$", "filter", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'writeConcern'", "]", ")", ")", "{", "$", "options", "[", "'writeConcern'", "]", "=", "$", "this", "->", "writeConcern", ";", "}", "$", "operation", "=", "new", "DeleteMany", "(", "$", "this", "->", "databaseName", ",", "$", "this", "->", "collectionName", ",", "$", "filter", ",", "$", "options", ")", ";", "$", "server", "=", "$", "this", "->", "manager", "->", "selectServer", "(", "new", "ReadPreference", "(", "ReadPreference", "::", "RP_PRIMARY", ")", ")", ";", "return", "$", "operation", "->", "execute", "(", "$", "server", ")", ";", "}" ]
Deletes all documents matching the filter. @see DeleteMany::__construct() for supported options @see http://docs.mongodb.org/manual/reference/command/delete/ @param array|object $filter Query by which to delete documents @param array $options Command options @return DeleteResult @throws UnsupportedException if options are not supported by the selected server @throws InvalidArgumentException for parameter/option parsing errors @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Deletes", "all", "documents", "matching", "the", "filter", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Collection.php#L383-L393
215,425
moodle/moodle
cache/stores/mongodb/MongoDB/Collection.php
Collection.deleteOne
public function deleteOne($filter, array $options = []) { if ( ! isset($options['writeConcern'])) { $options['writeConcern'] = $this->writeConcern; } $operation = new DeleteOne($this->databaseName, $this->collectionName, $filter, $options); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $operation->execute($server); }
php
public function deleteOne($filter, array $options = []) { if ( ! isset($options['writeConcern'])) { $options['writeConcern'] = $this->writeConcern; } $operation = new DeleteOne($this->databaseName, $this->collectionName, $filter, $options); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $operation->execute($server); }
[ "public", "function", "deleteOne", "(", "$", "filter", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'writeConcern'", "]", ")", ")", "{", "$", "options", "[", "'writeConcern'", "]", "=", "$", "this", "->", "writeConcern", ";", "}", "$", "operation", "=", "new", "DeleteOne", "(", "$", "this", "->", "databaseName", ",", "$", "this", "->", "collectionName", ",", "$", "filter", ",", "$", "options", ")", ";", "$", "server", "=", "$", "this", "->", "manager", "->", "selectServer", "(", "new", "ReadPreference", "(", "ReadPreference", "::", "RP_PRIMARY", ")", ")", ";", "return", "$", "operation", "->", "execute", "(", "$", "server", ")", ";", "}" ]
Deletes at most one document matching the filter. @see DeleteOne::__construct() for supported options @see http://docs.mongodb.org/manual/reference/command/delete/ @param array|object $filter Query by which to delete documents @param array $options Command options @return DeleteResult @throws UnsupportedException if options are not supported by the selected server @throws InvalidArgumentException for parameter/option parsing errors @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Deletes", "at", "most", "one", "document", "matching", "the", "filter", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Collection.php#L407-L417
215,426
moodle/moodle
cache/stores/mongodb/MongoDB/Collection.php
Collection.explain
public function explain(Explainable $explainable, array $options = []) { if ( ! isset($options['readPreference'])) { $options['readPreference'] = $this->readPreference; } if ( ! isset($options['typeMap'])) { $options['typeMap'] = $this->typeMap; } $server = $this->manager->selectServer($options['readPreference']); $operation = new Explain($this->databaseName, $explainable, $options); return $operation->execute($server); }
php
public function explain(Explainable $explainable, array $options = []) { if ( ! isset($options['readPreference'])) { $options['readPreference'] = $this->readPreference; } if ( ! isset($options['typeMap'])) { $options['typeMap'] = $this->typeMap; } $server = $this->manager->selectServer($options['readPreference']); $operation = new Explain($this->databaseName, $explainable, $options); return $operation->execute($server); }
[ "public", "function", "explain", "(", "Explainable", "$", "explainable", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'readPreference'", "]", ")", ")", "{", "$", "options", "[", "'readPreference'", "]", "=", "$", "this", "->", "readPreference", ";", "}", "if", "(", "!", "isset", "(", "$", "options", "[", "'typeMap'", "]", ")", ")", "{", "$", "options", "[", "'typeMap'", "]", "=", "$", "this", "->", "typeMap", ";", "}", "$", "server", "=", "$", "this", "->", "manager", "->", "selectServer", "(", "$", "options", "[", "'readPreference'", "]", ")", ";", "$", "operation", "=", "new", "Explain", "(", "$", "this", "->", "databaseName", ",", "$", "explainable", ",", "$", "options", ")", ";", "return", "$", "operation", "->", "execute", "(", "$", "server", ")", ";", "}" ]
Explains explainable commands. @see Explain::__construct() for supported options @see http://docs.mongodb.org/manual/reference/command/explain/ @param Explainable $explainable Command on which to run explain @param array $options Additional options @return array|object @throws UnsupportedException if explainable or options are not supported by the selected server @throws InvalidArgumentException for parameter/option parsing errors @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Explains", "explainable", "commands", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Collection.php#L577-L592
215,427
moodle/moodle
cache/stores/mongodb/MongoDB/Collection.php
Collection.find
public function find($filter = [], array $options = []) { if ( ! isset($options['readPreference'])) { $options['readPreference'] = $this->readPreference; } $server = $this->manager->selectServer($options['readPreference']); if ( ! isset($options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) { $options['readConcern'] = $this->readConcern; } if ( ! isset($options['typeMap'])) { $options['typeMap'] = $this->typeMap; } $operation = new Find($this->databaseName, $this->collectionName, $filter, $options); return $operation->execute($server); }
php
public function find($filter = [], array $options = []) { if ( ! isset($options['readPreference'])) { $options['readPreference'] = $this->readPreference; } $server = $this->manager->selectServer($options['readPreference']); if ( ! isset($options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) { $options['readConcern'] = $this->readConcern; } if ( ! isset($options['typeMap'])) { $options['typeMap'] = $this->typeMap; } $operation = new Find($this->databaseName, $this->collectionName, $filter, $options); return $operation->execute($server); }
[ "public", "function", "find", "(", "$", "filter", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'readPreference'", "]", ")", ")", "{", "$", "options", "[", "'readPreference'", "]", "=", "$", "this", "->", "readPreference", ";", "}", "$", "server", "=", "$", "this", "->", "manager", "->", "selectServer", "(", "$", "options", "[", "'readPreference'", "]", ")", ";", "if", "(", "!", "isset", "(", "$", "options", "[", "'readConcern'", "]", ")", "&&", "\\", "MongoDB", "\\", "server_supports_feature", "(", "$", "server", ",", "self", "::", "$", "wireVersionForReadConcern", ")", ")", "{", "$", "options", "[", "'readConcern'", "]", "=", "$", "this", "->", "readConcern", ";", "}", "if", "(", "!", "isset", "(", "$", "options", "[", "'typeMap'", "]", ")", ")", "{", "$", "options", "[", "'typeMap'", "]", "=", "$", "this", "->", "typeMap", ";", "}", "$", "operation", "=", "new", "Find", "(", "$", "this", "->", "databaseName", ",", "$", "this", "->", "collectionName", ",", "$", "filter", ",", "$", "options", ")", ";", "return", "$", "operation", "->", "execute", "(", "$", "server", ")", ";", "}" ]
Finds documents matching the query. @see Find::__construct() for supported options @see http://docs.mongodb.org/manual/core/read-operations-introduction/ @param array|object $filter Query by which to filter documents @param array $options Additional options @return Cursor @throws UnsupportedException if options are not supported by the selected server @throws InvalidArgumentException for parameter/option parsing errors @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Finds", "documents", "matching", "the", "query", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Collection.php#L606-L625
215,428
moodle/moodle
cache/stores/mongodb/MongoDB/Collection.php
Collection.findOneAndReplace
public function findOneAndReplace($filter, $replacement, array $options = []) { $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); if ( ! isset($options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForFindAndModifyWriteConcern)) { $options['writeConcern'] = $this->writeConcern; } if ( ! isset($options['typeMap'])) { $options['typeMap'] = $this->typeMap; } $operation = new FindOneAndReplace($this->databaseName, $this->collectionName, $filter, $replacement, $options); return $operation->execute($server); }
php
public function findOneAndReplace($filter, $replacement, array $options = []) { $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); if ( ! isset($options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForFindAndModifyWriteConcern)) { $options['writeConcern'] = $this->writeConcern; } if ( ! isset($options['typeMap'])) { $options['typeMap'] = $this->typeMap; } $operation = new FindOneAndReplace($this->databaseName, $this->collectionName, $filter, $replacement, $options); return $operation->execute($server); }
[ "public", "function", "findOneAndReplace", "(", "$", "filter", ",", "$", "replacement", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "server", "=", "$", "this", "->", "manager", "->", "selectServer", "(", "new", "ReadPreference", "(", "ReadPreference", "::", "RP_PRIMARY", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "options", "[", "'writeConcern'", "]", ")", "&&", "\\", "MongoDB", "\\", "server_supports_feature", "(", "$", "server", ",", "self", "::", "$", "wireVersionForFindAndModifyWriteConcern", ")", ")", "{", "$", "options", "[", "'writeConcern'", "]", "=", "$", "this", "->", "writeConcern", ";", "}", "if", "(", "!", "isset", "(", "$", "options", "[", "'typeMap'", "]", ")", ")", "{", "$", "options", "[", "'typeMap'", "]", "=", "$", "this", "->", "typeMap", ";", "}", "$", "operation", "=", "new", "FindOneAndReplace", "(", "$", "this", "->", "databaseName", ",", "$", "this", "->", "collectionName", ",", "$", "filter", ",", "$", "replacement", ",", "$", "options", ")", ";", "return", "$", "operation", "->", "execute", "(", "$", "server", ")", ";", "}" ]
Finds a single document and replaces it, returning either the original or the replaced document. The document to return may be null if no document matched the filter. By default, the original document is returned. Specify FindOneAndReplace::RETURN_DOCUMENT_AFTER for the "returnDocument" option to return the updated document. @see FindOneAndReplace::__construct() for supported options @see http://docs.mongodb.org/manual/reference/command/findAndModify/ @param array|object $filter Query by which to filter documents @param array|object $replacement Replacement document @param array $options Command options @return array|object|null @throws UnexpectedValueException if the command response was malformed @throws UnsupportedException if options are not supported by the selected server @throws InvalidArgumentException for parameter/option parsing errors @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Finds", "a", "single", "document", "and", "replaces", "it", "returning", "either", "the", "original", "or", "the", "replaced", "document", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Collection.php#L712-L727
215,429
moodle/moodle
cache/stores/mongodb/MongoDB/Collection.php
Collection.listIndexes
public function listIndexes(array $options = []) { $operation = new ListIndexes($this->databaseName, $this->collectionName, $options); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $operation->execute($server); }
php
public function listIndexes(array $options = []) { $operation = new ListIndexes($this->databaseName, $this->collectionName, $options); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $operation->execute($server); }
[ "public", "function", "listIndexes", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "operation", "=", "new", "ListIndexes", "(", "$", "this", "->", "databaseName", ",", "$", "this", "->", "collectionName", ",", "$", "options", ")", ";", "$", "server", "=", "$", "this", "->", "manager", "->", "selectServer", "(", "new", "ReadPreference", "(", "ReadPreference", "::", "RP_PRIMARY", ")", ")", ";", "return", "$", "operation", "->", "execute", "(", "$", "server", ")", ";", "}" ]
Returns information for all indexes for the collection. @see ListIndexes::__construct() for supported options @return IndexInfoIterator @throws InvalidArgumentException for parameter/option parsing errors @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Returns", "information", "for", "all", "indexes", "for", "the", "collection", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Collection.php#L903-L909
215,430
moodle/moodle
cache/stores/mongodb/MongoDB/Collection.php
Collection.replaceOne
public function replaceOne($filter, $replacement, array $options = []) { if ( ! isset($options['writeConcern'])) { $options['writeConcern'] = $this->writeConcern; } $operation = new ReplaceOne($this->databaseName, $this->collectionName, $filter, $replacement, $options); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $operation->execute($server); }
php
public function replaceOne($filter, $replacement, array $options = []) { if ( ! isset($options['writeConcern'])) { $options['writeConcern'] = $this->writeConcern; } $operation = new ReplaceOne($this->databaseName, $this->collectionName, $filter, $replacement, $options); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $operation->execute($server); }
[ "public", "function", "replaceOne", "(", "$", "filter", ",", "$", "replacement", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'writeConcern'", "]", ")", ")", "{", "$", "options", "[", "'writeConcern'", "]", "=", "$", "this", "->", "writeConcern", ";", "}", "$", "operation", "=", "new", "ReplaceOne", "(", "$", "this", "->", "databaseName", ",", "$", "this", "->", "collectionName", ",", "$", "filter", ",", "$", "replacement", ",", "$", "options", ")", ";", "$", "server", "=", "$", "this", "->", "manager", "->", "selectServer", "(", "new", "ReadPreference", "(", "ReadPreference", "::", "RP_PRIMARY", ")", ")", ";", "return", "$", "operation", "->", "execute", "(", "$", "server", ")", ";", "}" ]
Replaces at most one document matching the filter. @see ReplaceOne::__construct() for supported options @see http://docs.mongodb.org/manual/reference/command/update/ @param array|object $filter Query by which to filter documents @param array|object $replacement Replacement document @param array $options Command options @return UpdateResult @throws UnsupportedException if options are not supported by the selected server @throws InvalidArgumentException for parameter/option parsing errors @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Replaces", "at", "most", "one", "document", "matching", "the", "filter", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Collection.php#L974-L984
215,431
moodle/moodle
cache/stores/mongodb/MongoDB/Collection.php
Collection.updateMany
public function updateMany($filter, $update, array $options = []) { if ( ! isset($options['writeConcern'])) { $options['writeConcern'] = $this->writeConcern; } $operation = new UpdateMany($this->databaseName, $this->collectionName, $filter, $update, $options); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $operation->execute($server); }
php
public function updateMany($filter, $update, array $options = []) { if ( ! isset($options['writeConcern'])) { $options['writeConcern'] = $this->writeConcern; } $operation = new UpdateMany($this->databaseName, $this->collectionName, $filter, $update, $options); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $operation->execute($server); }
[ "public", "function", "updateMany", "(", "$", "filter", ",", "$", "update", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'writeConcern'", "]", ")", ")", "{", "$", "options", "[", "'writeConcern'", "]", "=", "$", "this", "->", "writeConcern", ";", "}", "$", "operation", "=", "new", "UpdateMany", "(", "$", "this", "->", "databaseName", ",", "$", "this", "->", "collectionName", ",", "$", "filter", ",", "$", "update", ",", "$", "options", ")", ";", "$", "server", "=", "$", "this", "->", "manager", "->", "selectServer", "(", "new", "ReadPreference", "(", "ReadPreference", "::", "RP_PRIMARY", ")", ")", ";", "return", "$", "operation", "->", "execute", "(", "$", "server", ")", ";", "}" ]
Updates all documents matching the filter. @see UpdateMany::__construct() for supported options @see http://docs.mongodb.org/manual/reference/command/update/ @param array|object $filter Query by which to filter documents @param array|object $update Update to apply to the matched documents @param array $options Command options @return UpdateResult @throws UnsupportedException if options are not supported by the selected server @throws InvalidArgumentException for parameter/option parsing errors @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Updates", "all", "documents", "matching", "the", "filter", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Collection.php#L999-L1009
215,432
moodle/moodle
lib/ltiprovider/src/ToolProvider/ToolProxy.php
ToolProxy.initialize
public function initialize() { $this->id = null; $this->recordId = null; $this->toolProxy = null; $this->created = null; $this->updated = null; }
php
public function initialize() { $this->id = null; $this->recordId = null; $this->toolProxy = null; $this->created = null; $this->updated = null; }
[ "public", "function", "initialize", "(", ")", "{", "$", "this", "->", "id", "=", "null", ";", "$", "this", "->", "recordId", "=", "null", ";", "$", "this", "->", "toolProxy", "=", "null", ";", "$", "this", "->", "created", "=", "null", ";", "$", "this", "->", "updated", "=", "null", ";", "}" ]
Initialise the tool proxy.
[ "Initialise", "the", "tool", "proxy", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/ToolProxy.php#L80-L89
215,433
moodle/moodle
lib/ltiprovider/src/ToolProvider/ToolProxy.php
ToolProxy.load
private function load($id) { $this->initialize(); $this->id = $id; $ok = $this->dataConnector->loadToolProxy($this); if (!$ok) { $this->enabled = $autoEnable; } return $ok; }
php
private function load($id) { $this->initialize(); $this->id = $id; $ok = $this->dataConnector->loadToolProxy($this); if (!$ok) { $this->enabled = $autoEnable; } return $ok; }
[ "private", "function", "load", "(", "$", "id", ")", "{", "$", "this", "->", "initialize", "(", ")", ";", "$", "this", "->", "id", "=", "$", "id", ";", "$", "ok", "=", "$", "this", "->", "dataConnector", "->", "loadToolProxy", "(", "$", "this", ")", ";", "if", "(", "!", "$", "ok", ")", "{", "$", "this", "->", "enabled", "=", "$", "autoEnable", ";", "}", "return", "$", "ok", ";", "}" ]
Load the tool proxy from the database. @param string $id The tool proxy id value @return boolean True if the tool proxy was successfully loaded
[ "Load", "the", "tool", "proxy", "from", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/ToolProxy.php#L180-L192
215,434
moodle/moodle
cache/stores/mongodb/lib.php
cachestore_mongodb.get_supported_features
public static function get_supported_features(array $configuration = array()) { $supports = self::SUPPORTS_DATA_GUARANTEE + self::DEREFERENCES_OBJECTS; if (array_key_exists('extendedmode', $configuration) && $configuration['extendedmode']) { $supports += self::SUPPORTS_MULTIPLE_IDENTIFIERS; } return $supports; }
php
public static function get_supported_features(array $configuration = array()) { $supports = self::SUPPORTS_DATA_GUARANTEE + self::DEREFERENCES_OBJECTS; if (array_key_exists('extendedmode', $configuration) && $configuration['extendedmode']) { $supports += self::SUPPORTS_MULTIPLE_IDENTIFIERS; } return $supports; }
[ "public", "static", "function", "get_supported_features", "(", "array", "$", "configuration", "=", "array", "(", ")", ")", "{", "$", "supports", "=", "self", "::", "SUPPORTS_DATA_GUARANTEE", "+", "self", "::", "DEREFERENCES_OBJECTS", ";", "if", "(", "array_key_exists", "(", "'extendedmode'", ",", "$", "configuration", ")", "&&", "$", "configuration", "[", "'extendedmode'", "]", ")", "{", "$", "supports", "+=", "self", "::", "SUPPORTS_MULTIPLE_IDENTIFIERS", ";", "}", "return", "$", "supports", ";", "}" ]
Returns the supported features. @param array $configuration @return int
[ "Returns", "the", "supported", "features", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/lib.php#L169-L175
215,435
moodle/moodle
cache/stores/mongodb/lib.php
cachestore_mongodb.initialise
public function initialise(cache_definition $definition) { if ($this->is_initialised()) { throw new coding_exception('This mongodb instance has already been initialised.'); } $this->database = $this->connection->selectDatabase($this->databasename); $this->definitionhash = 'm'.$definition->generate_definition_hash(); $this->collection = $this->database->selectCollection($this->definitionhash); $options = array('name' => 'idx_key'); $w = $this->usesafe ? 1 : 0; $wc = new MongoDB\Driver\WriteConcern($w); $options['writeConcern'] = $wc; $this->collection->createIndex(array('key' => 1), $options); }
php
public function initialise(cache_definition $definition) { if ($this->is_initialised()) { throw new coding_exception('This mongodb instance has already been initialised.'); } $this->database = $this->connection->selectDatabase($this->databasename); $this->definitionhash = 'm'.$definition->generate_definition_hash(); $this->collection = $this->database->selectCollection($this->definitionhash); $options = array('name' => 'idx_key'); $w = $this->usesafe ? 1 : 0; $wc = new MongoDB\Driver\WriteConcern($w); $options['writeConcern'] = $wc; $this->collection->createIndex(array('key' => 1), $options); }
[ "public", "function", "initialise", "(", "cache_definition", "$", "definition", ")", "{", "if", "(", "$", "this", "->", "is_initialised", "(", ")", ")", "{", "throw", "new", "coding_exception", "(", "'This mongodb instance has already been initialised.'", ")", ";", "}", "$", "this", "->", "database", "=", "$", "this", "->", "connection", "->", "selectDatabase", "(", "$", "this", "->", "databasename", ")", ";", "$", "this", "->", "definitionhash", "=", "'m'", ".", "$", "definition", "->", "generate_definition_hash", "(", ")", ";", "$", "this", "->", "collection", "=", "$", "this", "->", "database", "->", "selectCollection", "(", "$", "this", "->", "definitionhash", ")", ";", "$", "options", "=", "array", "(", "'name'", "=>", "'idx_key'", ")", ";", "$", "w", "=", "$", "this", "->", "usesafe", "?", "1", ":", "0", ";", "$", "wc", "=", "new", "MongoDB", "\\", "Driver", "\\", "WriteConcern", "(", "$", "w", ")", ";", "$", "options", "[", "'writeConcern'", "]", "=", "$", "wc", ";", "$", "this", "->", "collection", "->", "createIndex", "(", "array", "(", "'key'", "=>", "1", ")", ",", "$", "options", ")", ";", "}" ]
Initialises the store instance for use. Once this has been done the cache is all set to be used. @param cache_definition $definition @throws coding_exception
[ "Initialises", "the", "store", "instance", "for", "use", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/lib.php#L194-L210
215,436
moodle/moodle
cache/stores/mongodb/lib.php
cachestore_mongodb.config_get_configuration_array
public static function config_get_configuration_array($data) { $return = array( 'server' => $data->server, 'database' => $data->database, 'extendedmode' => (!empty($data->extendedmode)) ); if (!empty($data->username)) { $return['username'] = $data->username; } if (!empty($data->password)) { $return['password'] = $data->password; } if (!empty($data->replicaset)) { $return['replicaset'] = $data->replicaset; } if (!empty($data->usesafe)) { $return['usesafe'] = true; if (!empty($data->usesafevalue)) { $return['usesafe'] = (int)$data->usesafevalue; $return['usesafevalue'] = $return['usesafe']; } } return $return; }
php
public static function config_get_configuration_array($data) { $return = array( 'server' => $data->server, 'database' => $data->database, 'extendedmode' => (!empty($data->extendedmode)) ); if (!empty($data->username)) { $return['username'] = $data->username; } if (!empty($data->password)) { $return['password'] = $data->password; } if (!empty($data->replicaset)) { $return['replicaset'] = $data->replicaset; } if (!empty($data->usesafe)) { $return['usesafe'] = true; if (!empty($data->usesafevalue)) { $return['usesafe'] = (int)$data->usesafevalue; $return['usesafevalue'] = $return['usesafe']; } } return $return; }
[ "public", "static", "function", "config_get_configuration_array", "(", "$", "data", ")", "{", "$", "return", "=", "array", "(", "'server'", "=>", "$", "data", "->", "server", ",", "'database'", "=>", "$", "data", "->", "database", ",", "'extendedmode'", "=>", "(", "!", "empty", "(", "$", "data", "->", "extendedmode", ")", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "data", "->", "username", ")", ")", "{", "$", "return", "[", "'username'", "]", "=", "$", "data", "->", "username", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "->", "password", ")", ")", "{", "$", "return", "[", "'password'", "]", "=", "$", "data", "->", "password", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "->", "replicaset", ")", ")", "{", "$", "return", "[", "'replicaset'", "]", "=", "$", "data", "->", "replicaset", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "->", "usesafe", ")", ")", "{", "$", "return", "[", "'usesafe'", "]", "=", "true", ";", "if", "(", "!", "empty", "(", "$", "data", "->", "usesafevalue", ")", ")", "{", "$", "return", "[", "'usesafe'", "]", "=", "(", "int", ")", "$", "data", "->", "usesafevalue", ";", "$", "return", "[", "'usesafevalue'", "]", "=", "$", "return", "[", "'usesafe'", "]", ";", "}", "}", "return", "$", "return", ";", "}" ]
Takes the object from the add instance store and creates a configuration array that can be used to initialise an instance. @param stdClass $data @return array
[ "Takes", "the", "object", "from", "the", "add", "instance", "store", "and", "creates", "a", "configuration", "array", "that", "can", "be", "used", "to", "initialise", "an", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/lib.php#L420-L443
215,437
moodle/moodle
availability/condition/date/classes/condition.php
condition.get_either_description
protected function get_either_description($not, $standalone) { $direction = $this->get_logical_direction($not); $midnight = self::is_midnight($this->time); $midnighttag = $midnight ? '_date' : ''; $satag = $standalone ? 'short_' : 'full_'; switch ($direction) { case self::DIRECTION_FROM: return get_string($satag . 'from' . $midnighttag, 'availability_date', self::show_time($this->time, $midnight, false)); case self::DIRECTION_UNTIL: return get_string($satag . 'until' . $midnighttag, 'availability_date', self::show_time($this->time, $midnight, true)); } }
php
protected function get_either_description($not, $standalone) { $direction = $this->get_logical_direction($not); $midnight = self::is_midnight($this->time); $midnighttag = $midnight ? '_date' : ''; $satag = $standalone ? 'short_' : 'full_'; switch ($direction) { case self::DIRECTION_FROM: return get_string($satag . 'from' . $midnighttag, 'availability_date', self::show_time($this->time, $midnight, false)); case self::DIRECTION_UNTIL: return get_string($satag . 'until' . $midnighttag, 'availability_date', self::show_time($this->time, $midnight, true)); } }
[ "protected", "function", "get_either_description", "(", "$", "not", ",", "$", "standalone", ")", "{", "$", "direction", "=", "$", "this", "->", "get_logical_direction", "(", "$", "not", ")", ";", "$", "midnight", "=", "self", "::", "is_midnight", "(", "$", "this", "->", "time", ")", ";", "$", "midnighttag", "=", "$", "midnight", "?", "'_date'", ":", "''", ";", "$", "satag", "=", "$", "standalone", "?", "'short_'", ":", "'full_'", ";", "switch", "(", "$", "direction", ")", "{", "case", "self", "::", "DIRECTION_FROM", ":", "return", "get_string", "(", "$", "satag", ".", "'from'", ".", "$", "midnighttag", ",", "'availability_date'", ",", "self", "::", "show_time", "(", "$", "this", "->", "time", ",", "$", "midnight", ",", "false", ")", ")", ";", "case", "self", "::", "DIRECTION_UNTIL", ":", "return", "get_string", "(", "$", "satag", ".", "'until'", ".", "$", "midnighttag", ",", "'availability_date'", ",", "self", "::", "show_time", "(", "$", "this", "->", "time", ",", "$", "midnight", ",", "true", ")", ")", ";", "}", "}" ]
Shows the description using the different lang strings for the standalone version or the full one. @param bool $not True if NOT is in force @param bool $standalone True to use standalone lang strings
[ "Shows", "the", "description", "using", "the", "different", "lang", "strings", "for", "the", "standalone", "version", "or", "the", "full", "one", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/date/classes/condition.php#L152-L165
215,438
moodle/moodle
availability/condition/date/classes/condition.php
condition.show_time
protected function show_time($time, $dateonly, $until = false) { // For 'until' dates that are at midnight, e.g. midnight 5 March, it // is better to word the text as 'until end 4 March'. $daybefore = false; if ($until && $dateonly) { $daybefore = true; $time = strtotime('-1 day', $time); } return userdate($time, get_string($dateonly ? 'strftimedate' : 'strftimedatetime', 'langconfig')); }
php
protected function show_time($time, $dateonly, $until = false) { // For 'until' dates that are at midnight, e.g. midnight 5 March, it // is better to word the text as 'until end 4 March'. $daybefore = false; if ($until && $dateonly) { $daybefore = true; $time = strtotime('-1 day', $time); } return userdate($time, get_string($dateonly ? 'strftimedate' : 'strftimedatetime', 'langconfig')); }
[ "protected", "function", "show_time", "(", "$", "time", ",", "$", "dateonly", ",", "$", "until", "=", "false", ")", "{", "// For 'until' dates that are at midnight, e.g. midnight 5 March, it", "// is better to word the text as 'until end 4 March'.", "$", "daybefore", "=", "false", ";", "if", "(", "$", "until", "&&", "$", "dateonly", ")", "{", "$", "daybefore", "=", "true", ";", "$", "time", "=", "strtotime", "(", "'-1 day'", ",", "$", "time", ")", ";", "}", "return", "userdate", "(", "$", "time", ",", "get_string", "(", "$", "dateonly", "?", "'strftimedate'", ":", "'strftimedatetime'", ",", "'langconfig'", ")", ")", ";", "}" ]
Shows a time either as a date or a full date and time, according to user's timezone. @param int $time Time @param bool $dateonly If true, uses date only @param bool $until If true, and if using date only, shows previous date @return string Date
[ "Shows", "a", "time", "either", "as", "a", "date", "or", "a", "full", "date", "and", "time", "according", "to", "user", "s", "timezone", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/date/classes/condition.php#L204-L214
215,439
moodle/moodle
availability/condition/date/classes/condition.php
condition.update_all_dates
public static function update_all_dates($courseid, $timeshift) { global $DB; $modinfo = get_fast_modinfo($courseid); $anychanged = false; // Adjust dates from all course modules. foreach ($modinfo->cms as $cm) { if (!$cm->availability) { continue; } $info = new \core_availability\info_module($cm); $tree = $info->get_availability_tree(); $dates = $tree->get_all_children('availability_date\condition'); $changed = false; foreach ($dates as $date) { $date->time += $timeshift; $changed = true; } // Save the updated course module. if ($changed) { $DB->set_field('course_modules', 'availability', json_encode($tree->save()), array('id' => $cm->id)); $anychanged = true; } } // Adjust dates from all course sections. foreach ($modinfo->get_section_info_all() as $section) { if (!$section->availability) { continue; } $info = new \core_availability\info_section($section); $tree = $info->get_availability_tree(); $dates = $tree->get_all_children('availability_date\condition'); $changed = false; foreach ($dates as $date) { $date->time += $timeshift; $changed = true; } // Save the updated course module. if ($changed) { $updatesection = new \stdClass(); $updatesection->id = $section->id; $updatesection->availability = json_encode($tree->save()); $updatesection->timemodified = time(); $DB->update_record('course_sections', $updatesection); $anychanged = true; } } // Ensure course cache is cleared if required. if ($anychanged) { rebuild_course_cache($courseid, true); } }
php
public static function update_all_dates($courseid, $timeshift) { global $DB; $modinfo = get_fast_modinfo($courseid); $anychanged = false; // Adjust dates from all course modules. foreach ($modinfo->cms as $cm) { if (!$cm->availability) { continue; } $info = new \core_availability\info_module($cm); $tree = $info->get_availability_tree(); $dates = $tree->get_all_children('availability_date\condition'); $changed = false; foreach ($dates as $date) { $date->time += $timeshift; $changed = true; } // Save the updated course module. if ($changed) { $DB->set_field('course_modules', 'availability', json_encode($tree->save()), array('id' => $cm->id)); $anychanged = true; } } // Adjust dates from all course sections. foreach ($modinfo->get_section_info_all() as $section) { if (!$section->availability) { continue; } $info = new \core_availability\info_section($section); $tree = $info->get_availability_tree(); $dates = $tree->get_all_children('availability_date\condition'); $changed = false; foreach ($dates as $date) { $date->time += $timeshift; $changed = true; } // Save the updated course module. if ($changed) { $updatesection = new \stdClass(); $updatesection->id = $section->id; $updatesection->availability = json_encode($tree->save()); $updatesection->timemodified = time(); $DB->update_record('course_sections', $updatesection); $anychanged = true; } } // Ensure course cache is cleared if required. if ($anychanged) { rebuild_course_cache($courseid, true); } }
[ "public", "static", "function", "update_all_dates", "(", "$", "courseid", ",", "$", "timeshift", ")", "{", "global", "$", "DB", ";", "$", "modinfo", "=", "get_fast_modinfo", "(", "$", "courseid", ")", ";", "$", "anychanged", "=", "false", ";", "// Adjust dates from all course modules.", "foreach", "(", "$", "modinfo", "->", "cms", "as", "$", "cm", ")", "{", "if", "(", "!", "$", "cm", "->", "availability", ")", "{", "continue", ";", "}", "$", "info", "=", "new", "\\", "core_availability", "\\", "info_module", "(", "$", "cm", ")", ";", "$", "tree", "=", "$", "info", "->", "get_availability_tree", "(", ")", ";", "$", "dates", "=", "$", "tree", "->", "get_all_children", "(", "'availability_date\\condition'", ")", ";", "$", "changed", "=", "false", ";", "foreach", "(", "$", "dates", "as", "$", "date", ")", "{", "$", "date", "->", "time", "+=", "$", "timeshift", ";", "$", "changed", "=", "true", ";", "}", "// Save the updated course module.", "if", "(", "$", "changed", ")", "{", "$", "DB", "->", "set_field", "(", "'course_modules'", ",", "'availability'", ",", "json_encode", "(", "$", "tree", "->", "save", "(", ")", ")", ",", "array", "(", "'id'", "=>", "$", "cm", "->", "id", ")", ")", ";", "$", "anychanged", "=", "true", ";", "}", "}", "// Adjust dates from all course sections.", "foreach", "(", "$", "modinfo", "->", "get_section_info_all", "(", ")", "as", "$", "section", ")", "{", "if", "(", "!", "$", "section", "->", "availability", ")", "{", "continue", ";", "}", "$", "info", "=", "new", "\\", "core_availability", "\\", "info_section", "(", "$", "section", ")", ";", "$", "tree", "=", "$", "info", "->", "get_availability_tree", "(", ")", ";", "$", "dates", "=", "$", "tree", "->", "get_all_children", "(", "'availability_date\\condition'", ")", ";", "$", "changed", "=", "false", ";", "foreach", "(", "$", "dates", "as", "$", "date", ")", "{", "$", "date", "->", "time", "+=", "$", "timeshift", ";", "$", "changed", "=", "true", ";", "}", "// Save the updated course module.", "if", "(", "$", "changed", ")", "{", "$", "updatesection", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "updatesection", "->", "id", "=", "$", "section", "->", "id", ";", "$", "updatesection", "->", "availability", "=", "json_encode", "(", "$", "tree", "->", "save", "(", ")", ")", ";", "$", "updatesection", "->", "timemodified", "=", "time", "(", ")", ";", "$", "DB", "->", "update_record", "(", "'course_sections'", ",", "$", "updatesection", ")", ";", "$", "anychanged", "=", "true", ";", "}", "}", "// Ensure course cache is cleared if required.", "if", "(", "$", "anychanged", ")", "{", "rebuild_course_cache", "(", "$", "courseid", ",", "true", ")", ";", "}", "}" ]
Changes all date restrictions on a course by the specified shift amount. Used by the course reset feature. @param int $courseid Course id @param int $timeshift Offset in seconds
[ "Changes", "all", "date", "restrictions", "on", "a", "course", "by", "the", "specified", "shift", "amount", ".", "Used", "by", "the", "course", "reset", "feature", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/date/classes/condition.php#L245-L304
215,440
moodle/moodle
lib/google/src/Google/Service/Webmasters.php
Google_Service_Webmasters_Searchanalytics_Resource.query
public function query($siteUrl, Google_Service_Webmasters_SearchAnalyticsQueryRequest $postBody, $optParams = array()) { $params = array('siteUrl' => $siteUrl, 'postBody' => $postBody); $params = array_merge($params, $optParams); return $this->call('query', array($params), "Google_Service_Webmasters_SearchAnalyticsQueryResponse"); }
php
public function query($siteUrl, Google_Service_Webmasters_SearchAnalyticsQueryRequest $postBody, $optParams = array()) { $params = array('siteUrl' => $siteUrl, 'postBody' => $postBody); $params = array_merge($params, $optParams); return $this->call('query', array($params), "Google_Service_Webmasters_SearchAnalyticsQueryResponse"); }
[ "public", "function", "query", "(", "$", "siteUrl", ",", "Google_Service_Webmasters_SearchAnalyticsQueryRequest", "$", "postBody", ",", "$", "optParams", "=", "array", "(", ")", ")", "{", "$", "params", "=", "array", "(", "'siteUrl'", "=>", "$", "siteUrl", ",", "'postBody'", "=>", "$", "postBody", ")", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "optParams", ")", ";", "return", "$", "this", "->", "call", "(", "'query'", ",", "array", "(", "$", "params", ")", ",", "\"Google_Service_Webmasters_SearchAnalyticsQueryResponse\"", ")", ";", "}" ]
Query your data with filters and parameters that you define. Returns zero or more rows grouped by the row keys that you define. You must define a date range of one or more days. When date is one of the group by values, any days without data are omitted from the result list. If you need to know which days have data, issue a broad date range query grouped by date for any metric, and see which day rows are returned. (searchanalytics.query) @param string $siteUrl The site's URL, including protocol. For example: http://www.example.com/ @param Google_SearchAnalyticsQueryRequest $postBody @param array $optParams Optional parameters. @return Google_Service_Webmasters_SearchAnalyticsQueryResponse
[ "Query", "your", "data", "with", "filters", "and", "parameters", "that", "you", "define", ".", "Returns", "zero", "or", "more", "rows", "grouped", "by", "the", "row", "keys", "that", "you", "define", ".", "You", "must", "define", "a", "date", "range", "of", "one", "or", "more", "days", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Service/Webmasters.php#L336-L341
215,441
moodle/moodle
mod/quiz/report/attemptsreport_table.php
quiz_attempts_report_table.col_picture
public function col_picture($attempt) { global $OUTPUT; $user = new stdClass(); $additionalfields = explode(',', user_picture::fields()); $user = username_load_fields_from_object($user, $attempt, null, $additionalfields); $user->id = $attempt->userid; return $OUTPUT->user_picture($user); }
php
public function col_picture($attempt) { global $OUTPUT; $user = new stdClass(); $additionalfields = explode(',', user_picture::fields()); $user = username_load_fields_from_object($user, $attempt, null, $additionalfields); $user->id = $attempt->userid; return $OUTPUT->user_picture($user); }
[ "public", "function", "col_picture", "(", "$", "attempt", ")", "{", "global", "$", "OUTPUT", ";", "$", "user", "=", "new", "stdClass", "(", ")", ";", "$", "additionalfields", "=", "explode", "(", "','", ",", "user_picture", "::", "fields", "(", ")", ")", ";", "$", "user", "=", "username_load_fields_from_object", "(", "$", "user", ",", "$", "attempt", ",", "null", ",", "$", "additionalfields", ")", ";", "$", "user", "->", "id", "=", "$", "attempt", "->", "userid", ";", "return", "$", "OUTPUT", "->", "user_picture", "(", "$", "user", ")", ";", "}" ]
Generate the display of the user's picture column. @param object $attempt the table row being output. @return string HTML content to go inside the td.
[ "Generate", "the", "display", "of", "the", "user", "s", "picture", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/attemptsreport_table.php#L123-L130
215,442
moodle/moodle
mod/quiz/report/attemptsreport_table.php
quiz_attempts_report_table.col_fullname
public function col_fullname($attempt) { $html = parent::col_fullname($attempt); if ($this->is_downloading() || empty($attempt->attempt)) { return $html; } return $html . html_writer::empty_tag('br') . html_writer::link( new moodle_url('/mod/quiz/review.php', array('attempt' => $attempt->attempt)), get_string('reviewattempt', 'quiz'), array('class' => 'reviewlink')); }
php
public function col_fullname($attempt) { $html = parent::col_fullname($attempt); if ($this->is_downloading() || empty($attempt->attempt)) { return $html; } return $html . html_writer::empty_tag('br') . html_writer::link( new moodle_url('/mod/quiz/review.php', array('attempt' => $attempt->attempt)), get_string('reviewattempt', 'quiz'), array('class' => 'reviewlink')); }
[ "public", "function", "col_fullname", "(", "$", "attempt", ")", "{", "$", "html", "=", "parent", "::", "col_fullname", "(", "$", "attempt", ")", ";", "if", "(", "$", "this", "->", "is_downloading", "(", ")", "||", "empty", "(", "$", "attempt", "->", "attempt", ")", ")", "{", "return", "$", "html", ";", "}", "return", "$", "html", ".", "html_writer", "::", "empty_tag", "(", "'br'", ")", ".", "html_writer", "::", "link", "(", "new", "moodle_url", "(", "'/mod/quiz/review.php'", ",", "array", "(", "'attempt'", "=>", "$", "attempt", "->", "attempt", ")", ")", ",", "get_string", "(", "'reviewattempt'", ",", "'quiz'", ")", ",", "array", "(", "'class'", "=>", "'reviewlink'", ")", ")", ";", "}" ]
Generate the display of the user's full name column. @param object $attempt the table row being output. @return string HTML content to go inside the td.
[ "Generate", "the", "display", "of", "the", "user", "s", "full", "name", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/attemptsreport_table.php#L137-L146
215,443
moodle/moodle
mod/quiz/report/attemptsreport_table.php
quiz_attempts_report_table.col_timefinish
public function col_timefinish($attempt) { if ($attempt->attempt && $attempt->timefinish) { return userdate($attempt->timefinish, $this->strtimeformat); } else { return '-'; } }
php
public function col_timefinish($attempt) { if ($attempt->attempt && $attempt->timefinish) { return userdate($attempt->timefinish, $this->strtimeformat); } else { return '-'; } }
[ "public", "function", "col_timefinish", "(", "$", "attempt", ")", "{", "if", "(", "$", "attempt", "->", "attempt", "&&", "$", "attempt", "->", "timefinish", ")", "{", "return", "userdate", "(", "$", "attempt", "->", "timefinish", ",", "$", "this", "->", "strtimeformat", ")", ";", "}", "else", "{", "return", "'-'", ";", "}", "}" ]
Generate the display of the finish time column. @param object $attempt the table row being output. @return string HTML content to go inside the td.
[ "Generate", "the", "display", "of", "the", "finish", "time", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/attemptsreport_table.php#L179-L185
215,444
moodle/moodle
mod/quiz/report/attemptsreport_table.php
quiz_attempts_report_table.col_feedbacktext
public function col_feedbacktext($attempt) { if ($attempt->state != quiz_attempt::FINISHED) { return '-'; } $feedback = quiz_report_feedback_for_grade( quiz_rescale_grade($attempt->sumgrades, $this->quiz, false), $this->quiz->id, $this->context); if ($this->is_downloading()) { $feedback = strip_tags($feedback); } return $feedback; }
php
public function col_feedbacktext($attempt) { if ($attempt->state != quiz_attempt::FINISHED) { return '-'; } $feedback = quiz_report_feedback_for_grade( quiz_rescale_grade($attempt->sumgrades, $this->quiz, false), $this->quiz->id, $this->context); if ($this->is_downloading()) { $feedback = strip_tags($feedback); } return $feedback; }
[ "public", "function", "col_feedbacktext", "(", "$", "attempt", ")", "{", "if", "(", "$", "attempt", "->", "state", "!=", "quiz_attempt", "::", "FINISHED", ")", "{", "return", "'-'", ";", "}", "$", "feedback", "=", "quiz_report_feedback_for_grade", "(", "quiz_rescale_grade", "(", "$", "attempt", "->", "sumgrades", ",", "$", "this", "->", "quiz", ",", "false", ")", ",", "$", "this", "->", "quiz", "->", "id", ",", "$", "this", "->", "context", ")", ";", "if", "(", "$", "this", "->", "is_downloading", "(", ")", ")", "{", "$", "feedback", "=", "strip_tags", "(", "$", "feedback", ")", ";", "}", "return", "$", "feedback", ";", "}" ]
Generate the display of the feedback column. @param object $attempt the table row being output. @return string HTML content to go inside the td.
[ "Generate", "the", "display", "of", "the", "feedback", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/attemptsreport_table.php#L205-L219
215,445
moodle/moodle
mod/quiz/report/attemptsreport_table.php
quiz_attempts_report_table.make_review_link
public function make_review_link($data, $attempt, $slot) { global $OUTPUT; $flag = ''; if ($this->is_flagged($attempt->usageid, $slot)) { $flag = $OUTPUT->pix_icon('i/flagged', get_string('flagged', 'question'), 'moodle', array('class' => 'questionflag')); } $feedbackimg = ''; $state = $this->slot_state($attempt, $slot); if ($state->is_finished() && $state != question_state::$needsgrading) { $feedbackimg = $this->icon_for_fraction($this->slot_fraction($attempt, $slot)); } $output = html_writer::tag('span', $feedbackimg . html_writer::tag('span', $data, array('class' => $state->get_state_class(true))) . $flag, array('class' => 'que')); $reviewparams = array('attempt' => $attempt->attempt, 'slot' => $slot); if (isset($attempt->try)) { $reviewparams['step'] = $this->step_no_for_try($attempt->usageid, $slot, $attempt->try); } $url = new moodle_url('/mod/quiz/reviewquestion.php', $reviewparams); $output = $OUTPUT->action_link($url, $output, new popup_action('click', $url, 'reviewquestion', array('height' => 450, 'width' => 650)), array('title' => get_string('reviewresponse', 'quiz'))); return $output; }
php
public function make_review_link($data, $attempt, $slot) { global $OUTPUT; $flag = ''; if ($this->is_flagged($attempt->usageid, $slot)) { $flag = $OUTPUT->pix_icon('i/flagged', get_string('flagged', 'question'), 'moodle', array('class' => 'questionflag')); } $feedbackimg = ''; $state = $this->slot_state($attempt, $slot); if ($state->is_finished() && $state != question_state::$needsgrading) { $feedbackimg = $this->icon_for_fraction($this->slot_fraction($attempt, $slot)); } $output = html_writer::tag('span', $feedbackimg . html_writer::tag('span', $data, array('class' => $state->get_state_class(true))) . $flag, array('class' => 'que')); $reviewparams = array('attempt' => $attempt->attempt, 'slot' => $slot); if (isset($attempt->try)) { $reviewparams['step'] = $this->step_no_for_try($attempt->usageid, $slot, $attempt->try); } $url = new moodle_url('/mod/quiz/reviewquestion.php', $reviewparams); $output = $OUTPUT->action_link($url, $output, new popup_action('click', $url, 'reviewquestion', array('height' => 450, 'width' => 650)), array('title' => get_string('reviewresponse', 'quiz'))); return $output; }
[ "public", "function", "make_review_link", "(", "$", "data", ",", "$", "attempt", ",", "$", "slot", ")", "{", "global", "$", "OUTPUT", ";", "$", "flag", "=", "''", ";", "if", "(", "$", "this", "->", "is_flagged", "(", "$", "attempt", "->", "usageid", ",", "$", "slot", ")", ")", "{", "$", "flag", "=", "$", "OUTPUT", "->", "pix_icon", "(", "'i/flagged'", ",", "get_string", "(", "'flagged'", ",", "'question'", ")", ",", "'moodle'", ",", "array", "(", "'class'", "=>", "'questionflag'", ")", ")", ";", "}", "$", "feedbackimg", "=", "''", ";", "$", "state", "=", "$", "this", "->", "slot_state", "(", "$", "attempt", ",", "$", "slot", ")", ";", "if", "(", "$", "state", "->", "is_finished", "(", ")", "&&", "$", "state", "!=", "question_state", "::", "$", "needsgrading", ")", "{", "$", "feedbackimg", "=", "$", "this", "->", "icon_for_fraction", "(", "$", "this", "->", "slot_fraction", "(", "$", "attempt", ",", "$", "slot", ")", ")", ";", "}", "$", "output", "=", "html_writer", "::", "tag", "(", "'span'", ",", "$", "feedbackimg", ".", "html_writer", "::", "tag", "(", "'span'", ",", "$", "data", ",", "array", "(", "'class'", "=>", "$", "state", "->", "get_state_class", "(", "true", ")", ")", ")", ".", "$", "flag", ",", "array", "(", "'class'", "=>", "'que'", ")", ")", ";", "$", "reviewparams", "=", "array", "(", "'attempt'", "=>", "$", "attempt", "->", "attempt", ",", "'slot'", "=>", "$", "slot", ")", ";", "if", "(", "isset", "(", "$", "attempt", "->", "try", ")", ")", "{", "$", "reviewparams", "[", "'step'", "]", "=", "$", "this", "->", "step_no_for_try", "(", "$", "attempt", "->", "usageid", ",", "$", "slot", ",", "$", "attempt", "->", "try", ")", ";", "}", "$", "url", "=", "new", "moodle_url", "(", "'/mod/quiz/reviewquestion.php'", ",", "$", "reviewparams", ")", ";", "$", "output", "=", "$", "OUTPUT", "->", "action_link", "(", "$", "url", ",", "$", "output", ",", "new", "popup_action", "(", "'click'", ",", "$", "url", ",", "'reviewquestion'", ",", "array", "(", "'height'", "=>", "450", ",", "'width'", "=>", "650", ")", ")", ",", "array", "(", "'title'", "=>", "get_string", "(", "'reviewresponse'", ",", "'quiz'", ")", ")", ")", ";", "return", "$", "output", ";", "}" ]
Make a link to review an individual question in a popup window. @param string $data HTML fragment. The text to make into the link. @param object $attempt data for the row of the table being output. @param int $slot the number used to identify this question within this usage.
[ "Make", "a", "link", "to", "review", "an", "individual", "question", "in", "a", "popup", "window", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/attemptsreport_table.php#L236-L265
215,446
moodle/moodle
mod/quiz/report/attemptsreport_table.php
quiz_attempts_report_table.base_sql
public function base_sql(\core\dml\sql_join $allowedstudentsjoins) { global $DB; // Please note this uniqueid column is not the same as quiza.uniqueid. $fields = 'DISTINCT ' . $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') . ' AS uniqueid,'; if ($this->qmsubselect) { $fields .= "\n(CASE WHEN $this->qmsubselect THEN 1 ELSE 0 END) AS gradedattempt,"; } $extrafields = get_extra_user_fields_sql($this->context, 'u', '', array('id', 'idnumber', 'firstname', 'lastname', 'picture', 'imagealt', 'institution', 'department', 'email')); $allnames = get_all_user_name_fields(true, 'u'); $fields .= ' quiza.uniqueid AS usageid, quiza.id AS attempt, u.id AS userid, u.idnumber, ' . $allnames . ', u.picture, u.imagealt, u.institution, u.department, u.email' . $extrafields . ', quiza.state, quiza.sumgrades, quiza.timefinish, quiza.timestart, CASE WHEN quiza.timefinish = 0 THEN null WHEN quiza.timefinish > quiza.timestart THEN quiza.timefinish - quiza.timestart ELSE 0 END AS duration'; // To explain that last bit, timefinish can be non-zero and less // than timestart when you have two load-balanced servers with very // badly synchronised clocks, and a student does a really quick attempt. // This part is the same for all cases. Join the users and quiz_attempts tables. $from = " {user} u"; $from .= "\nLEFT JOIN {quiz_attempts} quiza ON quiza.userid = u.id AND quiza.quiz = :quizid"; $params = array('quizid' => $this->quiz->id); if ($this->qmsubselect && $this->options->onlygraded) { $from .= " AND (quiza.state <> :finishedstate OR $this->qmsubselect)"; $params['finishedstate'] = quiz_attempt::FINISHED; } switch ($this->options->attempts) { case quiz_attempts_report::ALL_WITH: // Show all attempts, including students who are no longer in the course. $where = 'quiza.id IS NOT NULL AND quiza.preview = 0'; break; case quiz_attempts_report::ENROLLED_WITH: // Show only students with attempts. $from .= "\n" . $allowedstudentsjoins->joins; $where = "quiza.preview = 0 AND quiza.id IS NOT NULL AND " . $allowedstudentsjoins->wheres; $params = array_merge($params, $allowedstudentsjoins->params); break; case quiz_attempts_report::ENROLLED_WITHOUT: // Show only students without attempts. $from .= "\n" . $allowedstudentsjoins->joins; $where = "quiza.id IS NULL AND " . $allowedstudentsjoins->wheres; $params = array_merge($params, $allowedstudentsjoins->params); break; case quiz_attempts_report::ENROLLED_ALL: // Show all students with or without attempts. $from .= "\n" . $allowedstudentsjoins->joins; $where = "(quiza.preview = 0 OR quiza.preview IS NULL) AND " . $allowedstudentsjoins->wheres; $params = array_merge($params, $allowedstudentsjoins->params); break; } if ($this->options->states) { list($statesql, $stateparams) = $DB->get_in_or_equal($this->options->states, SQL_PARAMS_NAMED, 'state'); $params += $stateparams; $where .= " AND (quiza.state $statesql OR quiza.state IS NULL)"; } return array($fields, $from, $where, $params); }
php
public function base_sql(\core\dml\sql_join $allowedstudentsjoins) { global $DB; // Please note this uniqueid column is not the same as quiza.uniqueid. $fields = 'DISTINCT ' . $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') . ' AS uniqueid,'; if ($this->qmsubselect) { $fields .= "\n(CASE WHEN $this->qmsubselect THEN 1 ELSE 0 END) AS gradedattempt,"; } $extrafields = get_extra_user_fields_sql($this->context, 'u', '', array('id', 'idnumber', 'firstname', 'lastname', 'picture', 'imagealt', 'institution', 'department', 'email')); $allnames = get_all_user_name_fields(true, 'u'); $fields .= ' quiza.uniqueid AS usageid, quiza.id AS attempt, u.id AS userid, u.idnumber, ' . $allnames . ', u.picture, u.imagealt, u.institution, u.department, u.email' . $extrafields . ', quiza.state, quiza.sumgrades, quiza.timefinish, quiza.timestart, CASE WHEN quiza.timefinish = 0 THEN null WHEN quiza.timefinish > quiza.timestart THEN quiza.timefinish - quiza.timestart ELSE 0 END AS duration'; // To explain that last bit, timefinish can be non-zero and less // than timestart when you have two load-balanced servers with very // badly synchronised clocks, and a student does a really quick attempt. // This part is the same for all cases. Join the users and quiz_attempts tables. $from = " {user} u"; $from .= "\nLEFT JOIN {quiz_attempts} quiza ON quiza.userid = u.id AND quiza.quiz = :quizid"; $params = array('quizid' => $this->quiz->id); if ($this->qmsubselect && $this->options->onlygraded) { $from .= " AND (quiza.state <> :finishedstate OR $this->qmsubselect)"; $params['finishedstate'] = quiz_attempt::FINISHED; } switch ($this->options->attempts) { case quiz_attempts_report::ALL_WITH: // Show all attempts, including students who are no longer in the course. $where = 'quiza.id IS NOT NULL AND quiza.preview = 0'; break; case quiz_attempts_report::ENROLLED_WITH: // Show only students with attempts. $from .= "\n" . $allowedstudentsjoins->joins; $where = "quiza.preview = 0 AND quiza.id IS NOT NULL AND " . $allowedstudentsjoins->wheres; $params = array_merge($params, $allowedstudentsjoins->params); break; case quiz_attempts_report::ENROLLED_WITHOUT: // Show only students without attempts. $from .= "\n" . $allowedstudentsjoins->joins; $where = "quiza.id IS NULL AND " . $allowedstudentsjoins->wheres; $params = array_merge($params, $allowedstudentsjoins->params); break; case quiz_attempts_report::ENROLLED_ALL: // Show all students with or without attempts. $from .= "\n" . $allowedstudentsjoins->joins; $where = "(quiza.preview = 0 OR quiza.preview IS NULL) AND " . $allowedstudentsjoins->wheres; $params = array_merge($params, $allowedstudentsjoins->params); break; } if ($this->options->states) { list($statesql, $stateparams) = $DB->get_in_or_equal($this->options->states, SQL_PARAMS_NAMED, 'state'); $params += $stateparams; $where .= " AND (quiza.state $statesql OR quiza.state IS NULL)"; } return array($fields, $from, $where, $params); }
[ "public", "function", "base_sql", "(", "\\", "core", "\\", "dml", "\\", "sql_join", "$", "allowedstudentsjoins", ")", "{", "global", "$", "DB", ";", "// Please note this uniqueid column is not the same as quiza.uniqueid.", "$", "fields", "=", "'DISTINCT '", ".", "$", "DB", "->", "sql_concat", "(", "'u.id'", ",", "\"'#'\"", ",", "'COALESCE(quiza.attempt, 0)'", ")", ".", "' AS uniqueid,'", ";", "if", "(", "$", "this", "->", "qmsubselect", ")", "{", "$", "fields", ".=", "\"\\n(CASE WHEN $this->qmsubselect THEN 1 ELSE 0 END) AS gradedattempt,\"", ";", "}", "$", "extrafields", "=", "get_extra_user_fields_sql", "(", "$", "this", "->", "context", ",", "'u'", ",", "''", ",", "array", "(", "'id'", ",", "'idnumber'", ",", "'firstname'", ",", "'lastname'", ",", "'picture'", ",", "'imagealt'", ",", "'institution'", ",", "'department'", ",", "'email'", ")", ")", ";", "$", "allnames", "=", "get_all_user_name_fields", "(", "true", ",", "'u'", ")", ";", "$", "fields", ".=", "'\n quiza.uniqueid AS usageid,\n quiza.id AS attempt,\n u.id AS userid,\n u.idnumber, '", ".", "$", "allnames", ".", "',\n u.picture,\n u.imagealt,\n u.institution,\n u.department,\n u.email'", ".", "$", "extrafields", ".", "',\n quiza.state,\n quiza.sumgrades,\n quiza.timefinish,\n quiza.timestart,\n CASE WHEN quiza.timefinish = 0 THEN null\n WHEN quiza.timefinish > quiza.timestart THEN quiza.timefinish - quiza.timestart\n ELSE 0 END AS duration'", ";", "// To explain that last bit, timefinish can be non-zero and less", "// than timestart when you have two load-balanced servers with very", "// badly synchronised clocks, and a student does a really quick attempt.", "// This part is the same for all cases. Join the users and quiz_attempts tables.", "$", "from", "=", "\" {user} u\"", ";", "$", "from", ".=", "\"\\nLEFT JOIN {quiz_attempts} quiza ON\n quiza.userid = u.id AND quiza.quiz = :quizid\"", ";", "$", "params", "=", "array", "(", "'quizid'", "=>", "$", "this", "->", "quiz", "->", "id", ")", ";", "if", "(", "$", "this", "->", "qmsubselect", "&&", "$", "this", "->", "options", "->", "onlygraded", ")", "{", "$", "from", ".=", "\" AND (quiza.state <> :finishedstate OR $this->qmsubselect)\"", ";", "$", "params", "[", "'finishedstate'", "]", "=", "quiz_attempt", "::", "FINISHED", ";", "}", "switch", "(", "$", "this", "->", "options", "->", "attempts", ")", "{", "case", "quiz_attempts_report", "::", "ALL_WITH", ":", "// Show all attempts, including students who are no longer in the course.", "$", "where", "=", "'quiza.id IS NOT NULL AND quiza.preview = 0'", ";", "break", ";", "case", "quiz_attempts_report", "::", "ENROLLED_WITH", ":", "// Show only students with attempts.", "$", "from", ".=", "\"\\n\"", ".", "$", "allowedstudentsjoins", "->", "joins", ";", "$", "where", "=", "\"quiza.preview = 0 AND quiza.id IS NOT NULL AND \"", ".", "$", "allowedstudentsjoins", "->", "wheres", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "allowedstudentsjoins", "->", "params", ")", ";", "break", ";", "case", "quiz_attempts_report", "::", "ENROLLED_WITHOUT", ":", "// Show only students without attempts.", "$", "from", ".=", "\"\\n\"", ".", "$", "allowedstudentsjoins", "->", "joins", ";", "$", "where", "=", "\"quiza.id IS NULL AND \"", ".", "$", "allowedstudentsjoins", "->", "wheres", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "allowedstudentsjoins", "->", "params", ")", ";", "break", ";", "case", "quiz_attempts_report", "::", "ENROLLED_ALL", ":", "// Show all students with or without attempts.", "$", "from", ".=", "\"\\n\"", ".", "$", "allowedstudentsjoins", "->", "joins", ";", "$", "where", "=", "\"(quiza.preview = 0 OR quiza.preview IS NULL) AND \"", ".", "$", "allowedstudentsjoins", "->", "wheres", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "allowedstudentsjoins", "->", "params", ")", ";", "break", ";", "}", "if", "(", "$", "this", "->", "options", "->", "states", ")", "{", "list", "(", "$", "statesql", ",", "$", "stateparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "this", "->", "options", "->", "states", ",", "SQL_PARAMS_NAMED", ",", "'state'", ")", ";", "$", "params", "+=", "$", "stateparams", ";", "$", "where", ".=", "\" AND (quiza.state $statesql OR quiza.state IS NULL)\"", ";", "}", "return", "array", "(", "$", "fields", ",", "$", "from", ",", "$", "where", ",", "$", "params", ")", ";", "}" ]
Contruct all the parts of the main database query. @param \core\dml\sql_join $allowedstudentsjoins (joins, wheres, params) defines allowed users for the report. @return array with 4 elements ($fields, $from, $where, $params) that can be used to build the actual database query.
[ "Contruct", "all", "the", "parts", "of", "the", "main", "database", "query", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/attemptsreport_table.php#L389-L468
215,447
moodle/moodle
mod/quiz/report/attemptsreport_table.php
quiz_attempts_report_table.get_qubaids_condition
protected function get_qubaids_condition() { if (is_null($this->rawdata)) { throw new coding_exception( 'Cannot call get_qubaids_condition until the main data has been loaded.'); } if ($this->is_downloading()) { // We want usages for all attempts. return new qubaid_join("( SELECT DISTINCT quiza.uniqueid FROM " . $this->sql->from . " WHERE " . $this->sql->where . " ) quizasubquery", 'quizasubquery.uniqueid', "1 = 1", $this->sql->params); } $qubaids = array(); foreach ($this->rawdata as $attempt) { if ($attempt->usageid > 0) { $qubaids[] = $attempt->usageid; } } return new qubaid_list($qubaids); }
php
protected function get_qubaids_condition() { if (is_null($this->rawdata)) { throw new coding_exception( 'Cannot call get_qubaids_condition until the main data has been loaded.'); } if ($this->is_downloading()) { // We want usages for all attempts. return new qubaid_join("( SELECT DISTINCT quiza.uniqueid FROM " . $this->sql->from . " WHERE " . $this->sql->where . " ) quizasubquery", 'quizasubquery.uniqueid', "1 = 1", $this->sql->params); } $qubaids = array(); foreach ($this->rawdata as $attempt) { if ($attempt->usageid > 0) { $qubaids[] = $attempt->usageid; } } return new qubaid_list($qubaids); }
[ "protected", "function", "get_qubaids_condition", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "rawdata", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Cannot call get_qubaids_condition until the main data has been loaded.'", ")", ";", "}", "if", "(", "$", "this", "->", "is_downloading", "(", ")", ")", "{", "// We want usages for all attempts.", "return", "new", "qubaid_join", "(", "\"(\n SELECT DISTINCT quiza.uniqueid\n FROM \"", ".", "$", "this", "->", "sql", "->", "from", ".", "\"\n WHERE \"", ".", "$", "this", "->", "sql", "->", "where", ".", "\"\n ) quizasubquery\"", ",", "'quizasubquery.uniqueid'", ",", "\"1 = 1\"", ",", "$", "this", "->", "sql", "->", "params", ")", ";", "}", "$", "qubaids", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "rawdata", "as", "$", "attempt", ")", "{", "if", "(", "$", "attempt", "->", "usageid", ">", "0", ")", "{", "$", "qubaids", "[", "]", "=", "$", "attempt", "->", "usageid", ";", "}", "}", "return", "new", "qubaid_list", "(", "$", "qubaids", ")", ";", "}" ]
Get an appropriate qubaid_condition for loading more data about the attempts we are displaying. @return qubaid_condition
[ "Get", "an", "appropriate", "qubaid_condition", "for", "loading", "more", "data", "about", "the", "attempts", "we", "are", "displaying", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/attemptsreport_table.php#L539-L563
215,448
moodle/moodle
mod/scorm/report/basic/classes/privacy/provider.php
provider.get_and_export_user_preference
protected static function get_and_export_user_preference(int $userid, string $userpreference, $transform = false) { $prefvalue = get_user_preferences($userpreference, null, $userid); if ($prefvalue !== null) { if ($transform) { $transformedvalue = transform::yesno($prefvalue); } else { $transformedvalue = $prefvalue; } writer::export_user_preference( 'scormreport_basic', $userpreference, $transformedvalue, get_string('privacy:metadata:preference:'.$userpreference, 'scormreport_basic') ); } }
php
protected static function get_and_export_user_preference(int $userid, string $userpreference, $transform = false) { $prefvalue = get_user_preferences($userpreference, null, $userid); if ($prefvalue !== null) { if ($transform) { $transformedvalue = transform::yesno($prefvalue); } else { $transformedvalue = $prefvalue; } writer::export_user_preference( 'scormreport_basic', $userpreference, $transformedvalue, get_string('privacy:metadata:preference:'.$userpreference, 'scormreport_basic') ); } }
[ "protected", "static", "function", "get_and_export_user_preference", "(", "int", "$", "userid", ",", "string", "$", "userpreference", ",", "$", "transform", "=", "false", ")", "{", "$", "prefvalue", "=", "get_user_preferences", "(", "$", "userpreference", ",", "null", ",", "$", "userid", ")", ";", "if", "(", "$", "prefvalue", "!==", "null", ")", "{", "if", "(", "$", "transform", ")", "{", "$", "transformedvalue", "=", "transform", "::", "yesno", "(", "$", "prefvalue", ")", ";", "}", "else", "{", "$", "transformedvalue", "=", "$", "prefvalue", ";", "}", "writer", "::", "export_user_preference", "(", "'scormreport_basic'", ",", "$", "userpreference", ",", "$", "transformedvalue", ",", "get_string", "(", "'privacy:metadata:preference:'", ".", "$", "userpreference", ",", "'scormreport_basic'", ")", ")", ";", "}", "}" ]
Get and export a user preference. @param int $userid The userid of the user whose data is to be exported. @param string $userpreference The user preference to export. @param boolean $transform If true, transform value to yesno.
[ "Get", "and", "export", "a", "user", "preference", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/report/basic/classes/privacy/provider.php#L76-L91
215,449
moodle/moodle
cache/stores/mongodb/MongoDB/Operation/Find.php
Find.createCommandDocument
private function createCommandDocument() { $cmd = ['find' => $this->collectionName, 'filter' => (object) $this->filter]; $options = $this->createQueryOptions(); if (empty($options)) { return $cmd; } // maxAwaitTimeMS is a Query level option so should not be considered here unset($options['maxAwaitTimeMS']); $modifierFallback = [ ['allowPartialResults', 'partial'], ['comment', '$comment'], ['hint', '$hint'], ['maxScan', '$maxScan'], ['max', '$max'], ['maxTimeMS', '$maxTimeMS'], ['min', '$min'], ['returnKey', '$returnKey'], ['showRecordId', '$showDiskLoc'], ['sort', '$orderby'], ['snapshot', '$snapshot'], ]; foreach ($modifierFallback as $modifier) { if ( ! isset($options[$modifier[0]]) && isset($options['modifiers'][$modifier[1]])) { $options[$modifier[0]] = $options['modifiers'][$modifier[1]]; } } unset($options['modifiers']); return $cmd + $options; }
php
private function createCommandDocument() { $cmd = ['find' => $this->collectionName, 'filter' => (object) $this->filter]; $options = $this->createQueryOptions(); if (empty($options)) { return $cmd; } // maxAwaitTimeMS is a Query level option so should not be considered here unset($options['maxAwaitTimeMS']); $modifierFallback = [ ['allowPartialResults', 'partial'], ['comment', '$comment'], ['hint', '$hint'], ['maxScan', '$maxScan'], ['max', '$max'], ['maxTimeMS', '$maxTimeMS'], ['min', '$min'], ['returnKey', '$returnKey'], ['showRecordId', '$showDiskLoc'], ['sort', '$orderby'], ['snapshot', '$snapshot'], ]; foreach ($modifierFallback as $modifier) { if ( ! isset($options[$modifier[0]]) && isset($options['modifiers'][$modifier[1]])) { $options[$modifier[0]] = $options['modifiers'][$modifier[1]]; } } unset($options['modifiers']); return $cmd + $options; }
[ "private", "function", "createCommandDocument", "(", ")", "{", "$", "cmd", "=", "[", "'find'", "=>", "$", "this", "->", "collectionName", ",", "'filter'", "=>", "(", "object", ")", "$", "this", "->", "filter", "]", ";", "$", "options", "=", "$", "this", "->", "createQueryOptions", "(", ")", ";", "if", "(", "empty", "(", "$", "options", ")", ")", "{", "return", "$", "cmd", ";", "}", "// maxAwaitTimeMS is a Query level option so should not be considered here", "unset", "(", "$", "options", "[", "'maxAwaitTimeMS'", "]", ")", ";", "$", "modifierFallback", "=", "[", "[", "'allowPartialResults'", ",", "'partial'", "]", ",", "[", "'comment'", ",", "'$comment'", "]", ",", "[", "'hint'", ",", "'$hint'", "]", ",", "[", "'maxScan'", ",", "'$maxScan'", "]", ",", "[", "'max'", ",", "'$max'", "]", ",", "[", "'maxTimeMS'", ",", "'$maxTimeMS'", "]", ",", "[", "'min'", ",", "'$min'", "]", ",", "[", "'returnKey'", ",", "'$returnKey'", "]", ",", "[", "'showRecordId'", ",", "'$showDiskLoc'", "]", ",", "[", "'sort'", ",", "'$orderby'", "]", ",", "[", "'snapshot'", ",", "'$snapshot'", "]", ",", "]", ";", "foreach", "(", "$", "modifierFallback", "as", "$", "modifier", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "$", "modifier", "[", "0", "]", "]", ")", "&&", "isset", "(", "$", "options", "[", "'modifiers'", "]", "[", "$", "modifier", "[", "1", "]", "]", ")", ")", "{", "$", "options", "[", "$", "modifier", "[", "0", "]", "]", "=", "$", "options", "[", "'modifiers'", "]", "[", "$", "modifier", "[", "1", "]", "]", ";", "}", "}", "unset", "(", "$", "options", "[", "'modifiers'", "]", ")", ";", "return", "$", "cmd", "+", "$", "options", ";", "}" ]
Construct a command document for Find
[ "Construct", "a", "command", "document", "for", "Find" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Operation/Find.php#L316-L351
215,450
moodle/moodle
cache/stores/mongodb/MongoDB/Operation/Find.php
Find.createQueryOptions
private function createQueryOptions() { $options = []; if (isset($this->options['cursorType'])) { if ($this->options['cursorType'] === self::TAILABLE) { $options['tailable'] = true; } if ($this->options['cursorType'] === self::TAILABLE_AWAIT) { $options['tailable'] = true; $options['awaitData'] = true; } } foreach (['allowPartialResults', 'batchSize', 'comment', 'hint', 'limit', 'maxAwaitTimeMS', 'maxScan', 'maxTimeMS', 'noCursorTimeout', 'oplogReplay', 'projection', 'readConcern', 'returnKey', 'showRecordId', 'skip', 'snapshot', 'sort'] as $option) { if (isset($this->options[$option])) { $options[$option] = $this->options[$option]; } } foreach (['collation', 'max', 'min'] as $option) { if (isset($this->options[$option])) { $options[$option] = (object) $this->options[$option]; } } $modifiers = empty($this->options['modifiers']) ? [] : (array) $this->options['modifiers']; if ( ! empty($modifiers)) { $options['modifiers'] = $modifiers; } return $options; }
php
private function createQueryOptions() { $options = []; if (isset($this->options['cursorType'])) { if ($this->options['cursorType'] === self::TAILABLE) { $options['tailable'] = true; } if ($this->options['cursorType'] === self::TAILABLE_AWAIT) { $options['tailable'] = true; $options['awaitData'] = true; } } foreach (['allowPartialResults', 'batchSize', 'comment', 'hint', 'limit', 'maxAwaitTimeMS', 'maxScan', 'maxTimeMS', 'noCursorTimeout', 'oplogReplay', 'projection', 'readConcern', 'returnKey', 'showRecordId', 'skip', 'snapshot', 'sort'] as $option) { if (isset($this->options[$option])) { $options[$option] = $this->options[$option]; } } foreach (['collation', 'max', 'min'] as $option) { if (isset($this->options[$option])) { $options[$option] = (object) $this->options[$option]; } } $modifiers = empty($this->options['modifiers']) ? [] : (array) $this->options['modifiers']; if ( ! empty($modifiers)) { $options['modifiers'] = $modifiers; } return $options; }
[ "private", "function", "createQueryOptions", "(", ")", "{", "$", "options", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'cursorType'", "]", ")", ")", "{", "if", "(", "$", "this", "->", "options", "[", "'cursorType'", "]", "===", "self", "::", "TAILABLE", ")", "{", "$", "options", "[", "'tailable'", "]", "=", "true", ";", "}", "if", "(", "$", "this", "->", "options", "[", "'cursorType'", "]", "===", "self", "::", "TAILABLE_AWAIT", ")", "{", "$", "options", "[", "'tailable'", "]", "=", "true", ";", "$", "options", "[", "'awaitData'", "]", "=", "true", ";", "}", "}", "foreach", "(", "[", "'allowPartialResults'", ",", "'batchSize'", ",", "'comment'", ",", "'hint'", ",", "'limit'", ",", "'maxAwaitTimeMS'", ",", "'maxScan'", ",", "'maxTimeMS'", ",", "'noCursorTimeout'", ",", "'oplogReplay'", ",", "'projection'", ",", "'readConcern'", ",", "'returnKey'", ",", "'showRecordId'", ",", "'skip'", ",", "'snapshot'", ",", "'sort'", "]", "as", "$", "option", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "$", "option", "]", ")", ")", "{", "$", "options", "[", "$", "option", "]", "=", "$", "this", "->", "options", "[", "$", "option", "]", ";", "}", "}", "foreach", "(", "[", "'collation'", ",", "'max'", ",", "'min'", "]", "as", "$", "option", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "$", "option", "]", ")", ")", "{", "$", "options", "[", "$", "option", "]", "=", "(", "object", ")", "$", "this", "->", "options", "[", "$", "option", "]", ";", "}", "}", "$", "modifiers", "=", "empty", "(", "$", "this", "->", "options", "[", "'modifiers'", "]", ")", "?", "[", "]", ":", "(", "array", ")", "$", "this", "->", "options", "[", "'modifiers'", "]", ";", "if", "(", "!", "empty", "(", "$", "modifiers", ")", ")", "{", "$", "options", "[", "'modifiers'", "]", "=", "$", "modifiers", ";", "}", "return", "$", "options", ";", "}" ]
Create options for the find query. Note that these are separate from the options for executing the command, which are created in createExecuteOptions(). @return array
[ "Create", "options", "for", "the", "find", "query", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Operation/Find.php#L382-L415
215,451
moodle/moodle
enrol/guest/lib.php
enrol_guest_plugin.enrol_user
public function enrol_user(stdClass $instance, $userid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null) { // no real enrolments here! return; }
php
public function enrol_user(stdClass $instance, $userid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null) { // no real enrolments here! return; }
[ "public", "function", "enrol_user", "(", "stdClass", "$", "instance", ",", "$", "userid", ",", "$", "roleid", "=", "null", ",", "$", "timestart", "=", "0", ",", "$", "timeend", "=", "0", ",", "$", "status", "=", "null", ",", "$", "recovergrades", "=", "null", ")", "{", "// no real enrolments here!", "return", ";", "}" ]
Enrol a user using a given enrolment instance. @param stdClass $instance @param int $userid @param null $roleid @param int $timestart @param int $timeend @param null $status @param null $recovergrades
[ "Enrol", "a", "user", "using", "a", "given", "enrolment", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/guest/lib.php#L71-L74
215,452
moodle/moodle
enrol/guest/lib.php
enrol_guest_plugin.try_guestaccess
public function try_guestaccess(stdClass $instance) { global $USER, $CFG; $allow = false; if ($instance->password === '') { $allow = true; } else if (isset($USER->enrol_guest_passwords[$instance->id])) { // this is a hack, ideally we should not add stuff to $USER... if ($USER->enrol_guest_passwords[$instance->id] === $instance->password) { $allow = true; } } if ($allow) { // Temporarily assign them some guest role for this context $context = context_course::instance($instance->courseid); load_temp_course_role($context, $CFG->guestroleid); return ENROL_MAX_TIMESTAMP; } return false; }
php
public function try_guestaccess(stdClass $instance) { global $USER, $CFG; $allow = false; if ($instance->password === '') { $allow = true; } else if (isset($USER->enrol_guest_passwords[$instance->id])) { // this is a hack, ideally we should not add stuff to $USER... if ($USER->enrol_guest_passwords[$instance->id] === $instance->password) { $allow = true; } } if ($allow) { // Temporarily assign them some guest role for this context $context = context_course::instance($instance->courseid); load_temp_course_role($context, $CFG->guestroleid); return ENROL_MAX_TIMESTAMP; } return false; }
[ "public", "function", "try_guestaccess", "(", "stdClass", "$", "instance", ")", "{", "global", "$", "USER", ",", "$", "CFG", ";", "$", "allow", "=", "false", ";", "if", "(", "$", "instance", "->", "password", "===", "''", ")", "{", "$", "allow", "=", "true", ";", "}", "else", "if", "(", "isset", "(", "$", "USER", "->", "enrol_guest_passwords", "[", "$", "instance", "->", "id", "]", ")", ")", "{", "// this is a hack, ideally we should not add stuff to $USER...", "if", "(", "$", "USER", "->", "enrol_guest_passwords", "[", "$", "instance", "->", "id", "]", "===", "$", "instance", "->", "password", ")", "{", "$", "allow", "=", "true", ";", "}", "}", "if", "(", "$", "allow", ")", "{", "// Temporarily assign them some guest role for this context", "$", "context", "=", "context_course", "::", "instance", "(", "$", "instance", "->", "courseid", ")", ";", "load_temp_course_role", "(", "$", "context", ",", "$", "CFG", "->", "guestroleid", ")", ";", "return", "ENROL_MAX_TIMESTAMP", ";", "}", "return", "false", ";", "}" ]
Attempt to automatically gain temporary guest access to course, calling code has to make sure the plugin and instance are active. @param stdClass $instance course enrol instance @return bool|int false means no guest access, integer means end of cached time
[ "Attempt", "to", "automatically", "gain", "temporary", "guest", "access", "to", "course", "calling", "code", "has", "to", "make", "sure", "the", "plugin", "and", "instance", "are", "active", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/guest/lib.php#L94-L116
215,453
moodle/moodle
lib/spout/src/Spout/Writer/ODS/Writer.php
Writer.openWriter
protected function openWriter() { $tempFolder = ($this->tempFolder) ? : sys_get_temp_dir(); $this->book = new Workbook($tempFolder, $this->shouldCreateNewSheetsAutomatically, $this->defaultRowStyle); $this->book->addNewSheetAndMakeItCurrent(); }
php
protected function openWriter() { $tempFolder = ($this->tempFolder) ? : sys_get_temp_dir(); $this->book = new Workbook($tempFolder, $this->shouldCreateNewSheetsAutomatically, $this->defaultRowStyle); $this->book->addNewSheetAndMakeItCurrent(); }
[ "protected", "function", "openWriter", "(", ")", "{", "$", "tempFolder", "=", "(", "$", "this", "->", "tempFolder", ")", "?", ":", "sys_get_temp_dir", "(", ")", ";", "$", "this", "->", "book", "=", "new", "Workbook", "(", "$", "tempFolder", ",", "$", "this", "->", "shouldCreateNewSheetsAutomatically", ",", "$", "this", "->", "defaultRowStyle", ")", ";", "$", "this", "->", "book", "->", "addNewSheetAndMakeItCurrent", "(", ")", ";", "}" ]
Configures the write and sets the current sheet pointer to a new sheet. @return void @throws \Box\Spout\Common\Exception\IOException If unable to open the file for writing
[ "Configures", "the", "write", "and", "sets", "the", "current", "sheet", "pointer", "to", "a", "new", "sheet", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/ODS/Writer.php#L49-L54
215,454
moodle/moodle
lib/spout/src/Spout/Writer/ODS/Writer.php
Writer.addRowToWriter
protected function addRowToWriter(array $dataRow, $style) { $this->throwIfBookIsNotAvailable(); $this->book->addRowToCurrentWorksheet($dataRow, $style); }
php
protected function addRowToWriter(array $dataRow, $style) { $this->throwIfBookIsNotAvailable(); $this->book->addRowToCurrentWorksheet($dataRow, $style); }
[ "protected", "function", "addRowToWriter", "(", "array", "$", "dataRow", ",", "$", "style", ")", "{", "$", "this", "->", "throwIfBookIsNotAvailable", "(", ")", ";", "$", "this", "->", "book", "->", "addRowToCurrentWorksheet", "(", "$", "dataRow", ",", "$", "style", ")", ";", "}" ]
Adds data to the currently opened writer. If shouldCreateNewSheetsAutomatically option is set to true, it will handle pagination with the creation of new worksheets if one worksheet has reached its maximum capicity. @param array $dataRow Array containing data to be written. Example $dataRow = ['data1', 1234, null, '', 'data5']; @param \Box\Spout\Writer\Style\Style $style Style to be applied to the row. @return void @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the book is not created yet @throws \Box\Spout\Common\Exception\IOException If unable to write data
[ "Adds", "data", "to", "the", "currently", "opened", "writer", ".", "If", "shouldCreateNewSheetsAutomatically", "option", "is", "set", "to", "true", "it", "will", "handle", "pagination", "with", "the", "creation", "of", "new", "worksheets", "if", "one", "worksheet", "has", "reached", "its", "maximum", "capicity", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/ODS/Writer.php#L76-L80
215,455
moodle/moodle
lib/ltiprovider/src/ToolProvider/ToolConsumer.php
ToolConsumer.save
public function save() { $ok = $this->dataConnector->saveToolConsumer($this); if ($ok) { $this->settingsChanged = false; } return $ok; }
php
public function save() { $ok = $this->dataConnector->saveToolConsumer($this); if ($ok) { $this->settingsChanged = false; } return $ok; }
[ "public", "function", "save", "(", ")", "{", "$", "ok", "=", "$", "this", "->", "dataConnector", "->", "saveToolConsumer", "(", "$", "this", ")", ";", "if", "(", "$", "ok", ")", "{", "$", "this", "->", "settingsChanged", "=", "false", ";", "}", "return", "$", "ok", ";", "}" ]
Save the tool consumer to the database. @return boolean True if the object was successfully saved
[ "Save", "the", "tool", "consumer", "to", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/ToolConsumer.php#L226-L236
215,456
moodle/moodle
lib/ltiprovider/src/ToolProvider/ToolConsumer.php
ToolConsumer.setToolSettings
public function setToolSettings($settings = array()) { $url = $this->getSetting('custom_system_setting_url'); $service = new Service\ToolSettings($this, $url); $response = $service->set($settings); return $response; }
php
public function setToolSettings($settings = array()) { $url = $this->getSetting('custom_system_setting_url'); $service = new Service\ToolSettings($this, $url); $response = $service->set($settings); return $response; }
[ "public", "function", "setToolSettings", "(", "$", "settings", "=", "array", "(", ")", ")", "{", "$", "url", "=", "$", "this", "->", "getSetting", "(", "'custom_system_setting_url'", ")", ";", "$", "service", "=", "new", "Service", "\\", "ToolSettings", "(", "$", "this", ",", "$", "url", ")", ";", "$", "response", "=", "$", "service", "->", "set", "(", "$", "settings", ")", ";", "return", "$", "response", ";", "}" ]
Perform a Tool Settings service request. @param array $settings An associative array of settings (optional, default is none) @return boolean True if action was successful, otherwise false
[ "Perform", "a", "Tool", "Settings", "service", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/ToolConsumer.php#L455-L464
215,457
moodle/moodle
lib/ltiprovider/src/ToolProvider/ToolConsumer.php
ToolConsumer.addSignature
public static function addSignature($endpoint, $consumerKey, $consumerSecret, $data, $method = 'POST', $type = null) { $params = array(); if (is_array($data)) { $params = $data; } // Check for query parameters which need to be included in the signature $queryParams = array(); $queryString = parse_url($endpoint, PHP_URL_QUERY); if (!is_null($queryString)) { $queryItems = explode('&', $queryString); foreach ($queryItems as $item) { if (strpos($item, '=') !== false) { list($name, $value) = explode('=', $item); $queryParams[urldecode($name)] = urldecode($value); } else { $queryParams[urldecode($item)] = ''; } } $params = $params + $queryParams; } if (!is_array($data)) { // Calculate body hash $hash = base64_encode(sha1($data, true)); $params['oauth_body_hash'] = $hash; } // Add OAuth signature $hmacMethod = new OAuth\OAuthSignatureMethod_HMAC_SHA1(); $oauthConsumer = new OAuth\OAuthConsumer($consumerKey, $consumerSecret, null); $oauthReq = OAuth\OAuthRequest::from_consumer_and_token($oauthConsumer, null, $method, $endpoint, $params); $oauthReq->sign_request($hmacMethod, $oauthConsumer, null); $params = $oauthReq->get_parameters(); // Remove parameters being passed on the query string foreach (array_keys($queryParams) as $name) { unset($params[$name]); } if (!is_array($data)) { $header = $oauthReq->to_header(); if (empty($data)) { if (!empty($type)) { $header .= "\nAccept: {$type}"; } } else if (isset($type)) { $header .= "\nContent-Type: {$type}"; $header .= "\nContent-Length: " . strlen($data); } return $header; } else { return $params; } }
php
public static function addSignature($endpoint, $consumerKey, $consumerSecret, $data, $method = 'POST', $type = null) { $params = array(); if (is_array($data)) { $params = $data; } // Check for query parameters which need to be included in the signature $queryParams = array(); $queryString = parse_url($endpoint, PHP_URL_QUERY); if (!is_null($queryString)) { $queryItems = explode('&', $queryString); foreach ($queryItems as $item) { if (strpos($item, '=') !== false) { list($name, $value) = explode('=', $item); $queryParams[urldecode($name)] = urldecode($value); } else { $queryParams[urldecode($item)] = ''; } } $params = $params + $queryParams; } if (!is_array($data)) { // Calculate body hash $hash = base64_encode(sha1($data, true)); $params['oauth_body_hash'] = $hash; } // Add OAuth signature $hmacMethod = new OAuth\OAuthSignatureMethod_HMAC_SHA1(); $oauthConsumer = new OAuth\OAuthConsumer($consumerKey, $consumerSecret, null); $oauthReq = OAuth\OAuthRequest::from_consumer_and_token($oauthConsumer, null, $method, $endpoint, $params); $oauthReq->sign_request($hmacMethod, $oauthConsumer, null); $params = $oauthReq->get_parameters(); // Remove parameters being passed on the query string foreach (array_keys($queryParams) as $name) { unset($params[$name]); } if (!is_array($data)) { $header = $oauthReq->to_header(); if (empty($data)) { if (!empty($type)) { $header .= "\nAccept: {$type}"; } } else if (isset($type)) { $header .= "\nContent-Type: {$type}"; $header .= "\nContent-Length: " . strlen($data); } return $header; } else { return $params; } }
[ "public", "static", "function", "addSignature", "(", "$", "endpoint", ",", "$", "consumerKey", ",", "$", "consumerSecret", ",", "$", "data", ",", "$", "method", "=", "'POST'", ",", "$", "type", "=", "null", ")", "{", "$", "params", "=", "array", "(", ")", ";", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "$", "params", "=", "$", "data", ";", "}", "// Check for query parameters which need to be included in the signature", "$", "queryParams", "=", "array", "(", ")", ";", "$", "queryString", "=", "parse_url", "(", "$", "endpoint", ",", "PHP_URL_QUERY", ")", ";", "if", "(", "!", "is_null", "(", "$", "queryString", ")", ")", "{", "$", "queryItems", "=", "explode", "(", "'&'", ",", "$", "queryString", ")", ";", "foreach", "(", "$", "queryItems", "as", "$", "item", ")", "{", "if", "(", "strpos", "(", "$", "item", ",", "'='", ")", "!==", "false", ")", "{", "list", "(", "$", "name", ",", "$", "value", ")", "=", "explode", "(", "'='", ",", "$", "item", ")", ";", "$", "queryParams", "[", "urldecode", "(", "$", "name", ")", "]", "=", "urldecode", "(", "$", "value", ")", ";", "}", "else", "{", "$", "queryParams", "[", "urldecode", "(", "$", "item", ")", "]", "=", "''", ";", "}", "}", "$", "params", "=", "$", "params", "+", "$", "queryParams", ";", "}", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "// Calculate body hash", "$", "hash", "=", "base64_encode", "(", "sha1", "(", "$", "data", ",", "true", ")", ")", ";", "$", "params", "[", "'oauth_body_hash'", "]", "=", "$", "hash", ";", "}", "// Add OAuth signature", "$", "hmacMethod", "=", "new", "OAuth", "\\", "OAuthSignatureMethod_HMAC_SHA1", "(", ")", ";", "$", "oauthConsumer", "=", "new", "OAuth", "\\", "OAuthConsumer", "(", "$", "consumerKey", ",", "$", "consumerSecret", ",", "null", ")", ";", "$", "oauthReq", "=", "OAuth", "\\", "OAuthRequest", "::", "from_consumer_and_token", "(", "$", "oauthConsumer", ",", "null", ",", "$", "method", ",", "$", "endpoint", ",", "$", "params", ")", ";", "$", "oauthReq", "->", "sign_request", "(", "$", "hmacMethod", ",", "$", "oauthConsumer", ",", "null", ")", ";", "$", "params", "=", "$", "oauthReq", "->", "get_parameters", "(", ")", ";", "// Remove parameters being passed on the query string", "foreach", "(", "array_keys", "(", "$", "queryParams", ")", "as", "$", "name", ")", "{", "unset", "(", "$", "params", "[", "$", "name", "]", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "$", "header", "=", "$", "oauthReq", "->", "to_header", "(", ")", ";", "if", "(", "empty", "(", "$", "data", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "type", ")", ")", "{", "$", "header", ".=", "\"\\nAccept: {$type}\"", ";", "}", "}", "else", "if", "(", "isset", "(", "$", "type", ")", ")", "{", "$", "header", ".=", "\"\\nContent-Type: {$type}\"", ";", "$", "header", ".=", "\"\\nContent-Length: \"", ".", "strlen", "(", "$", "data", ")", ";", "}", "return", "$", "header", ";", "}", "else", "{", "return", "$", "params", ";", "}", "}" ]
Add the OAuth signature to an array of message parameters or to a header string. @return mixed Array of signed message parameters or header string
[ "Add", "the", "OAuth", "signature", "to", "an", "array", "of", "message", "parameters", "or", "to", "a", "header", "string", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/ToolConsumer.php#L520-L575
215,458
moodle/moodle
lib/ltiprovider/src/ToolProvider/ToolConsumer.php
ToolConsumer.doServiceRequest
public function doServiceRequest($service, $method, $format, $data) { $header = ToolConsumer::addSignature($service->endpoint, $this->getKey(), $this->secret, $data, $method, $format); // Connect to tool consumer $http = new HTTPMessage($service->endpoint, $method, $data, $header); // Parse JSON response if ($http->send() && !empty($http->response)) { $http->responseJson = json_decode($http->response); $http->ok = !is_null($http->responseJson); } return $http; }
php
public function doServiceRequest($service, $method, $format, $data) { $header = ToolConsumer::addSignature($service->endpoint, $this->getKey(), $this->secret, $data, $method, $format); // Connect to tool consumer $http = new HTTPMessage($service->endpoint, $method, $data, $header); // Parse JSON response if ($http->send() && !empty($http->response)) { $http->responseJson = json_decode($http->response); $http->ok = !is_null($http->responseJson); } return $http; }
[ "public", "function", "doServiceRequest", "(", "$", "service", ",", "$", "method", ",", "$", "format", ",", "$", "data", ")", "{", "$", "header", "=", "ToolConsumer", "::", "addSignature", "(", "$", "service", "->", "endpoint", ",", "$", "this", "->", "getKey", "(", ")", ",", "$", "this", "->", "secret", ",", "$", "data", ",", "$", "method", ",", "$", "format", ")", ";", "// Connect to tool consumer", "$", "http", "=", "new", "HTTPMessage", "(", "$", "service", "->", "endpoint", ",", "$", "method", ",", "$", "data", ",", "$", "header", ")", ";", "// Parse JSON response", "if", "(", "$", "http", "->", "send", "(", ")", "&&", "!", "empty", "(", "$", "http", "->", "response", ")", ")", "{", "$", "http", "->", "responseJson", "=", "json_decode", "(", "$", "http", "->", "response", ")", ";", "$", "http", "->", "ok", "=", "!", "is_null", "(", "$", "http", "->", "responseJson", ")", ";", "}", "return", "$", "http", ";", "}" ]
Perform a service request @param object $service Service object to be executed @param string $method HTTP action @param string $format Media type @param mixed $data Array of parameters or body string @return HTTPMessage HTTP object containing request and response details
[ "Perform", "a", "service", "request" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/ToolConsumer.php#L587-L602
215,459
moodle/moodle
lib/ltiprovider/src/ToolProvider/ToolConsumer.php
ToolConsumer.fromRecordId
public static function fromRecordId($id, $dataConnector) { $toolConsumer = new ToolConsumer(null, $dataConnector); $toolConsumer->initialize(); $toolConsumer->setRecordId($id); if (!$dataConnector->loadToolConsumer($toolConsumer)) { $toolConsumer->initialize(); } return $toolConsumer; }
php
public static function fromRecordId($id, $dataConnector) { $toolConsumer = new ToolConsumer(null, $dataConnector); $toolConsumer->initialize(); $toolConsumer->setRecordId($id); if (!$dataConnector->loadToolConsumer($toolConsumer)) { $toolConsumer->initialize(); } return $toolConsumer; }
[ "public", "static", "function", "fromRecordId", "(", "$", "id", ",", "$", "dataConnector", ")", "{", "$", "toolConsumer", "=", "new", "ToolConsumer", "(", "null", ",", "$", "dataConnector", ")", ";", "$", "toolConsumer", "->", "initialize", "(", ")", ";", "$", "toolConsumer", "->", "setRecordId", "(", "$", "id", ")", ";", "if", "(", "!", "$", "dataConnector", "->", "loadToolConsumer", "(", "$", "toolConsumer", ")", ")", "{", "$", "toolConsumer", "->", "initialize", "(", ")", ";", "}", "return", "$", "toolConsumer", ";", "}" ]
Load the tool consumer from the database by its record ID. @param string $id The consumer key record ID @param DataConnector $dataConnector Database connection object @return object ToolConsumer The tool consumer object
[ "Load", "the", "tool", "consumer", "from", "the", "database", "by", "its", "record", "ID", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/ToolConsumer.php#L612-L625
215,460
moodle/moodle
lib/mustache/src/Mustache/Loader/ArrayLoader.php
Mustache_Loader_ArrayLoader.load
public function load($name) { if (!isset($this->templates[$name])) { throw new Mustache_Exception_UnknownTemplateException($name); } return $this->templates[$name]; }
php
public function load($name) { if (!isset($this->templates[$name])) { throw new Mustache_Exception_UnknownTemplateException($name); } return $this->templates[$name]; }
[ "public", "function", "load", "(", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "templates", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "Mustache_Exception_UnknownTemplateException", "(", "$", "name", ")", ";", "}", "return", "$", "this", "->", "templates", "[", "$", "name", "]", ";", "}" ]
Load a Template. @throws Mustache_Exception_UnknownTemplateException If a template file is not found @param string $name @return string Mustache Template source
[ "Load", "a", "Template", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Loader/ArrayLoader.php#L50-L57
215,461
moodle/moodle
grade/report/singleview/classes/local/ui/finalgrade.php
finalgrade.get_value
public function get_value() { $this->label = $this->grade->grade_item->itemname; $val = $this->grade->finalgrade; if ($this->grade->grade_item->scaleid) { return $val ? (int)$val : -1; } else { return $val ? format_float($val, $this->grade->grade_item->get_decimals()) : ''; } }
php
public function get_value() { $this->label = $this->grade->grade_item->itemname; $val = $this->grade->finalgrade; if ($this->grade->grade_item->scaleid) { return $val ? (int)$val : -1; } else { return $val ? format_float($val, $this->grade->grade_item->get_decimals()) : ''; } }
[ "public", "function", "get_value", "(", ")", "{", "$", "this", "->", "label", "=", "$", "this", "->", "grade", "->", "grade_item", "->", "itemname", ";", "$", "val", "=", "$", "this", "->", "grade", "->", "finalgrade", ";", "if", "(", "$", "this", "->", "grade", "->", "grade_item", "->", "scaleid", ")", "{", "return", "$", "val", "?", "(", "int", ")", "$", "val", ":", "-", "1", ";", "}", "else", "{", "return", "$", "val", "?", "format_float", "(", "$", "val", ",", "$", "this", "->", "grade", "->", "grade_item", "->", "get_decimals", "(", ")", ")", ":", "''", ";", "}", "}" ]
Get the value for this input. @return string The value based on the grade_grade.
[ "Get", "the", "value", "for", "this", "input", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/finalgrade.php#L47-L56
215,462
moodle/moodle
grade/report/singleview/classes/local/ui/finalgrade.php
finalgrade.determine_format
public function determine_format() { if ($this->grade->grade_item->load_scale()) { $scale = $this->grade->grade_item->load_scale(); $options = array(-1 => get_string('nograde')); foreach ($scale->scale_items as $i => $name) { $options[$i + 1] = $name; } return new dropdown_attribute( $this->get_name(), $options, $this->get_label(), $this->get_value(), $this->is_disabled() ); } else { return new text_attribute( $this->get_name(), $this->get_value(), $this->get_label(), $this->is_disabled() ); } }
php
public function determine_format() { if ($this->grade->grade_item->load_scale()) { $scale = $this->grade->grade_item->load_scale(); $options = array(-1 => get_string('nograde')); foreach ($scale->scale_items as $i => $name) { $options[$i + 1] = $name; } return new dropdown_attribute( $this->get_name(), $options, $this->get_label(), $this->get_value(), $this->is_disabled() ); } else { return new text_attribute( $this->get_name(), $this->get_value(), $this->get_label(), $this->is_disabled() ); } }
[ "public", "function", "determine_format", "(", ")", "{", "if", "(", "$", "this", "->", "grade", "->", "grade_item", "->", "load_scale", "(", ")", ")", "{", "$", "scale", "=", "$", "this", "->", "grade", "->", "grade_item", "->", "load_scale", "(", ")", ";", "$", "options", "=", "array", "(", "-", "1", "=>", "get_string", "(", "'nograde'", ")", ")", ";", "foreach", "(", "$", "scale", "->", "scale_items", "as", "$", "i", "=>", "$", "name", ")", "{", "$", "options", "[", "$", "i", "+", "1", "]", "=", "$", "name", ";", "}", "return", "new", "dropdown_attribute", "(", "$", "this", "->", "get_name", "(", ")", ",", "$", "options", ",", "$", "this", "->", "get_label", "(", ")", ",", "$", "this", "->", "get_value", "(", ")", ",", "$", "this", "->", "is_disabled", "(", ")", ")", ";", "}", "else", "{", "return", "new", "text_attribute", "(", "$", "this", "->", "get_name", "(", ")", ",", "$", "this", "->", "get_value", "(", ")", ",", "$", "this", "->", "get_label", "(", ")", ",", "$", "this", "->", "is_disabled", "(", ")", ")", ";", "}", "}" ]
Create the element for this column. @return element
[ "Create", "the", "element", "for", "this", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/finalgrade.php#L102-L127
215,463
moodle/moodle
grade/report/singleview/classes/local/ui/finalgrade.php
finalgrade.set
public function set($value) { global $DB; $userid = $this->grade->userid; $gradeitem = $this->grade->grade_item; $feedback = false; $feedbackformat = false; if ($gradeitem->gradetype == GRADE_TYPE_SCALE) { if ($value == -1) { $finalgrade = null; } else { $finalgrade = $value; } } else { $finalgrade = unformat_float($value); } $errorstr = ''; if ($finalgrade) { $bounded = $gradeitem->bounded_grade($finalgrade); if ($bounded > $finalgrade) { $errorstr = 'lessthanmin'; } else if ($bounded < $finalgrade) { $errorstr = 'morethanmax'; } } if ($errorstr) { $user = $DB->get_record('user', array('id' => $userid), 'id, firstname, alternatename, lastname'); $gradestr = new stdClass; if (!empty($user->alternatename)) { $gradestr->username = $user->alternatename . ' (' . $user->firstname . ') ' . $user->lastname; } else { $gradestr->username = $user->firstname . ' ' . $user->lastname; } $gradestr->itemname = $this->grade->grade_item->get_name(); $errorstr = get_string($errorstr, 'grades', $gradestr); return $errorstr; } // Only update grades if there are no errors. $gradeitem->update_final_grade($userid, $finalgrade, 'singleview', $feedback, FORMAT_MOODLE); return ''; }
php
public function set($value) { global $DB; $userid = $this->grade->userid; $gradeitem = $this->grade->grade_item; $feedback = false; $feedbackformat = false; if ($gradeitem->gradetype == GRADE_TYPE_SCALE) { if ($value == -1) { $finalgrade = null; } else { $finalgrade = $value; } } else { $finalgrade = unformat_float($value); } $errorstr = ''; if ($finalgrade) { $bounded = $gradeitem->bounded_grade($finalgrade); if ($bounded > $finalgrade) { $errorstr = 'lessthanmin'; } else if ($bounded < $finalgrade) { $errorstr = 'morethanmax'; } } if ($errorstr) { $user = $DB->get_record('user', array('id' => $userid), 'id, firstname, alternatename, lastname'); $gradestr = new stdClass; if (!empty($user->alternatename)) { $gradestr->username = $user->alternatename . ' (' . $user->firstname . ') ' . $user->lastname; } else { $gradestr->username = $user->firstname . ' ' . $user->lastname; } $gradestr->itemname = $this->grade->grade_item->get_name(); $errorstr = get_string($errorstr, 'grades', $gradestr); return $errorstr; } // Only update grades if there are no errors. $gradeitem->update_final_grade($userid, $finalgrade, 'singleview', $feedback, FORMAT_MOODLE); return ''; }
[ "public", "function", "set", "(", "$", "value", ")", "{", "global", "$", "DB", ";", "$", "userid", "=", "$", "this", "->", "grade", "->", "userid", ";", "$", "gradeitem", "=", "$", "this", "->", "grade", "->", "grade_item", ";", "$", "feedback", "=", "false", ";", "$", "feedbackformat", "=", "false", ";", "if", "(", "$", "gradeitem", "->", "gradetype", "==", "GRADE_TYPE_SCALE", ")", "{", "if", "(", "$", "value", "==", "-", "1", ")", "{", "$", "finalgrade", "=", "null", ";", "}", "else", "{", "$", "finalgrade", "=", "$", "value", ";", "}", "}", "else", "{", "$", "finalgrade", "=", "unformat_float", "(", "$", "value", ")", ";", "}", "$", "errorstr", "=", "''", ";", "if", "(", "$", "finalgrade", ")", "{", "$", "bounded", "=", "$", "gradeitem", "->", "bounded_grade", "(", "$", "finalgrade", ")", ";", "if", "(", "$", "bounded", ">", "$", "finalgrade", ")", "{", "$", "errorstr", "=", "'lessthanmin'", ";", "}", "else", "if", "(", "$", "bounded", "<", "$", "finalgrade", ")", "{", "$", "errorstr", "=", "'morethanmax'", ";", "}", "}", "if", "(", "$", "errorstr", ")", "{", "$", "user", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "userid", ")", ",", "'id, firstname, alternatename, lastname'", ")", ";", "$", "gradestr", "=", "new", "stdClass", ";", "if", "(", "!", "empty", "(", "$", "user", "->", "alternatename", ")", ")", "{", "$", "gradestr", "->", "username", "=", "$", "user", "->", "alternatename", ".", "' ('", ".", "$", "user", "->", "firstname", ".", "') '", ".", "$", "user", "->", "lastname", ";", "}", "else", "{", "$", "gradestr", "->", "username", "=", "$", "user", "->", "firstname", ".", "' '", ".", "$", "user", "->", "lastname", ";", "}", "$", "gradestr", "->", "itemname", "=", "$", "this", "->", "grade", "->", "grade_item", "->", "get_name", "(", ")", ";", "$", "errorstr", "=", "get_string", "(", "$", "errorstr", ",", "'grades'", ",", "$", "gradestr", ")", ";", "return", "$", "errorstr", ";", "}", "// Only update grades if there are no errors.", "$", "gradeitem", "->", "update_final_grade", "(", "$", "userid", ",", "$", "finalgrade", ",", "'singleview'", ",", "$", "feedback", ",", "FORMAT_MOODLE", ")", ";", "return", "''", ";", "}" ]
Save the altered value for this field. @param string $value The new value. @return string Any error string
[ "Save", "the", "altered", "value", "for", "this", "field", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/finalgrade.php#L135-L179
215,464
moodle/moodle
question/type/numerical/edit_numerical_form.php
qtype_numerical_edit_form.add_unit_options
protected function add_unit_options($mform) { $mform->addElement('header', 'unithandling', get_string('unithandling', 'qtype_numerical')); $unitoptions = array( qtype_numerical::UNITNONE => get_string('onlynumerical', 'qtype_numerical'), qtype_numerical::UNITOPTIONAL => get_string('manynumerical', 'qtype_numerical'), qtype_numerical::UNITGRADED => get_string('unitgraded', 'qtype_numerical'), ); $mform->addElement('select', 'unitrole', get_string('unithandling', 'qtype_numerical'), $unitoptions); $penaltygrp = array(); $penaltygrp[] = $mform->createElement('float', 'unitpenalty', get_string('unitpenalty', 'qtype_numerical'), array('size' => 6)); $mform->setDefault('unitpenalty', 0.1000000); $unitgradingtypes = array( qtype_numerical::UNITGRADEDOUTOFMARK => get_string('decfractionofresponsegrade', 'qtype_numerical'), qtype_numerical::UNITGRADEDOUTOFMAX => get_string('decfractionofquestiongrade', 'qtype_numerical'), ); $penaltygrp[] = $mform->createElement('select', 'unitgradingtypes', '', $unitgradingtypes); $mform->setDefault('unitgradingtypes', 1); $mform->addGroup($penaltygrp, 'penaltygrp', get_string('unitpenalty', 'qtype_numerical'), ' ', false); $mform->addHelpButton('penaltygrp', 'unitpenalty', 'qtype_numerical'); $unitinputoptions = array( qtype_numerical::UNITINPUT => get_string('editableunittext', 'qtype_numerical'), qtype_numerical::UNITRADIO => get_string('unitchoice', 'qtype_numerical'), qtype_numerical::UNITSELECT => get_string('unitselect', 'qtype_numerical'), ); $mform->addElement('select', 'multichoicedisplay', get_string('studentunitanswer', 'qtype_numerical'), $unitinputoptions); $unitsleftoptions = array( 0 => get_string('rightexample', 'qtype_numerical'), 1 => get_string('leftexample', 'qtype_numerical') ); $mform->addElement('select', 'unitsleft', get_string('unitposition', 'qtype_numerical'), $unitsleftoptions); $mform->setDefault('unitsleft', 0); $mform->disabledIf('penaltygrp', 'unitrole', 'eq', qtype_numerical::UNITNONE); $mform->disabledIf('penaltygrp', 'unitrole', 'eq', qtype_numerical::UNITOPTIONAL); $mform->disabledIf('unitsleft', 'unitrole', 'eq', qtype_numerical::UNITNONE); $mform->disabledIf('multichoicedisplay', 'unitrole', 'eq', qtype_numerical::UNITNONE); $mform->disabledIf('multichoicedisplay', 'unitrole', 'eq', qtype_numerical::UNITOPTIONAL); }
php
protected function add_unit_options($mform) { $mform->addElement('header', 'unithandling', get_string('unithandling', 'qtype_numerical')); $unitoptions = array( qtype_numerical::UNITNONE => get_string('onlynumerical', 'qtype_numerical'), qtype_numerical::UNITOPTIONAL => get_string('manynumerical', 'qtype_numerical'), qtype_numerical::UNITGRADED => get_string('unitgraded', 'qtype_numerical'), ); $mform->addElement('select', 'unitrole', get_string('unithandling', 'qtype_numerical'), $unitoptions); $penaltygrp = array(); $penaltygrp[] = $mform->createElement('float', 'unitpenalty', get_string('unitpenalty', 'qtype_numerical'), array('size' => 6)); $mform->setDefault('unitpenalty', 0.1000000); $unitgradingtypes = array( qtype_numerical::UNITGRADEDOUTOFMARK => get_string('decfractionofresponsegrade', 'qtype_numerical'), qtype_numerical::UNITGRADEDOUTOFMAX => get_string('decfractionofquestiongrade', 'qtype_numerical'), ); $penaltygrp[] = $mform->createElement('select', 'unitgradingtypes', '', $unitgradingtypes); $mform->setDefault('unitgradingtypes', 1); $mform->addGroup($penaltygrp, 'penaltygrp', get_string('unitpenalty', 'qtype_numerical'), ' ', false); $mform->addHelpButton('penaltygrp', 'unitpenalty', 'qtype_numerical'); $unitinputoptions = array( qtype_numerical::UNITINPUT => get_string('editableunittext', 'qtype_numerical'), qtype_numerical::UNITRADIO => get_string('unitchoice', 'qtype_numerical'), qtype_numerical::UNITSELECT => get_string('unitselect', 'qtype_numerical'), ); $mform->addElement('select', 'multichoicedisplay', get_string('studentunitanswer', 'qtype_numerical'), $unitinputoptions); $unitsleftoptions = array( 0 => get_string('rightexample', 'qtype_numerical'), 1 => get_string('leftexample', 'qtype_numerical') ); $mform->addElement('select', 'unitsleft', get_string('unitposition', 'qtype_numerical'), $unitsleftoptions); $mform->setDefault('unitsleft', 0); $mform->disabledIf('penaltygrp', 'unitrole', 'eq', qtype_numerical::UNITNONE); $mform->disabledIf('penaltygrp', 'unitrole', 'eq', qtype_numerical::UNITOPTIONAL); $mform->disabledIf('unitsleft', 'unitrole', 'eq', qtype_numerical::UNITNONE); $mform->disabledIf('multichoicedisplay', 'unitrole', 'eq', qtype_numerical::UNITNONE); $mform->disabledIf('multichoicedisplay', 'unitrole', 'eq', qtype_numerical::UNITOPTIONAL); }
[ "protected", "function", "add_unit_options", "(", "$", "mform", ")", "{", "$", "mform", "->", "addElement", "(", "'header'", ",", "'unithandling'", ",", "get_string", "(", "'unithandling'", ",", "'qtype_numerical'", ")", ")", ";", "$", "unitoptions", "=", "array", "(", "qtype_numerical", "::", "UNITNONE", "=>", "get_string", "(", "'onlynumerical'", ",", "'qtype_numerical'", ")", ",", "qtype_numerical", "::", "UNITOPTIONAL", "=>", "get_string", "(", "'manynumerical'", ",", "'qtype_numerical'", ")", ",", "qtype_numerical", "::", "UNITGRADED", "=>", "get_string", "(", "'unitgraded'", ",", "'qtype_numerical'", ")", ",", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'unitrole'", ",", "get_string", "(", "'unithandling'", ",", "'qtype_numerical'", ")", ",", "$", "unitoptions", ")", ";", "$", "penaltygrp", "=", "array", "(", ")", ";", "$", "penaltygrp", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'float'", ",", "'unitpenalty'", ",", "get_string", "(", "'unitpenalty'", ",", "'qtype_numerical'", ")", ",", "array", "(", "'size'", "=>", "6", ")", ")", ";", "$", "mform", "->", "setDefault", "(", "'unitpenalty'", ",", "0.1000000", ")", ";", "$", "unitgradingtypes", "=", "array", "(", "qtype_numerical", "::", "UNITGRADEDOUTOFMARK", "=>", "get_string", "(", "'decfractionofresponsegrade'", ",", "'qtype_numerical'", ")", ",", "qtype_numerical", "::", "UNITGRADEDOUTOFMAX", "=>", "get_string", "(", "'decfractionofquestiongrade'", ",", "'qtype_numerical'", ")", ",", ")", ";", "$", "penaltygrp", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'select'", ",", "'unitgradingtypes'", ",", "''", ",", "$", "unitgradingtypes", ")", ";", "$", "mform", "->", "setDefault", "(", "'unitgradingtypes'", ",", "1", ")", ";", "$", "mform", "->", "addGroup", "(", "$", "penaltygrp", ",", "'penaltygrp'", ",", "get_string", "(", "'unitpenalty'", ",", "'qtype_numerical'", ")", ",", "' '", ",", "false", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'penaltygrp'", ",", "'unitpenalty'", ",", "'qtype_numerical'", ")", ";", "$", "unitinputoptions", "=", "array", "(", "qtype_numerical", "::", "UNITINPUT", "=>", "get_string", "(", "'editableunittext'", ",", "'qtype_numerical'", ")", ",", "qtype_numerical", "::", "UNITRADIO", "=>", "get_string", "(", "'unitchoice'", ",", "'qtype_numerical'", ")", ",", "qtype_numerical", "::", "UNITSELECT", "=>", "get_string", "(", "'unitselect'", ",", "'qtype_numerical'", ")", ",", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'multichoicedisplay'", ",", "get_string", "(", "'studentunitanswer'", ",", "'qtype_numerical'", ")", ",", "$", "unitinputoptions", ")", ";", "$", "unitsleftoptions", "=", "array", "(", "0", "=>", "get_string", "(", "'rightexample'", ",", "'qtype_numerical'", ")", ",", "1", "=>", "get_string", "(", "'leftexample'", ",", "'qtype_numerical'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'unitsleft'", ",", "get_string", "(", "'unitposition'", ",", "'qtype_numerical'", ")", ",", "$", "unitsleftoptions", ")", ";", "$", "mform", "->", "setDefault", "(", "'unitsleft'", ",", "0", ")", ";", "$", "mform", "->", "disabledIf", "(", "'penaltygrp'", ",", "'unitrole'", ",", "'eq'", ",", "qtype_numerical", "::", "UNITNONE", ")", ";", "$", "mform", "->", "disabledIf", "(", "'penaltygrp'", ",", "'unitrole'", ",", "'eq'", ",", "qtype_numerical", "::", "UNITOPTIONAL", ")", ";", "$", "mform", "->", "disabledIf", "(", "'unitsleft'", ",", "'unitrole'", ",", "'eq'", ",", "qtype_numerical", "::", "UNITNONE", ")", ";", "$", "mform", "->", "disabledIf", "(", "'multichoicedisplay'", ",", "'unitrole'", ",", "'eq'", ",", "qtype_numerical", "::", "UNITNONE", ")", ";", "$", "mform", "->", "disabledIf", "(", "'multichoicedisplay'", ",", "'unitrole'", ",", "'eq'", ",", "qtype_numerical", "::", "UNITOPTIONAL", ")", ";", "}" ]
Add the unit handling options to the form. @param object $mform the form being built.
[ "Add", "the", "unit", "handling", "options", "to", "the", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/numerical/edit_numerical_form.php#L79-L133
215,465
moodle/moodle
question/type/numerical/edit_numerical_form.php
qtype_numerical_edit_form.add_unit_fields
protected function add_unit_fields($mform) { $mform->addElement('header', 'unithdr', get_string('units', 'qtype_numerical'), ''); $unitfields = array($mform->createElement('group', 'units', get_string('unitx', 'qtype_numerical'), $this->unit_group($mform), null, false)); $repeatedoptions['unit']['disabledif'] = array('unitrole', 'eq', qtype_numerical::UNITNONE); $repeatedoptions['unit']['type'] = PARAM_NOTAGS; $repeatedoptions['multiplier']['disabledif'] = array('unitrole', 'eq', qtype_numerical::UNITNONE); $mform->disabledIf('addunits', 'unitrole', 'eq', qtype_numerical::UNITNONE); if (isset($this->question->options->units)) { $repeatsatstart = max(count($this->question->options->units), self::UNITS_MIN_REPEATS); } else { $repeatsatstart = self::UNITS_MIN_REPEATS; } $this->repeat_elements($unitfields, $repeatsatstart, $repeatedoptions, 'nounits', 'addunits', self::UNITS_TO_ADD, get_string('addmoreunitblanks', 'qtype_numerical', '{no}'), true); // The following strange-looking if statement is to do with when the // form is used to move questions between categories. See MDL-15159. if ($mform->elementExists('units[0]')) { $firstunit = $mform->getElement('units[0]'); $elements = $firstunit->getElements(); foreach ($elements as $element) { if ($element->getName() != 'multiplier[0]') { continue; } $element->freeze(); $element->setValue('1.0'); $element->setPersistantFreeze(true); } $mform->addHelpButton('units[0]', 'numericalmultiplier', 'qtype_numerical'); } }
php
protected function add_unit_fields($mform) { $mform->addElement('header', 'unithdr', get_string('units', 'qtype_numerical'), ''); $unitfields = array($mform->createElement('group', 'units', get_string('unitx', 'qtype_numerical'), $this->unit_group($mform), null, false)); $repeatedoptions['unit']['disabledif'] = array('unitrole', 'eq', qtype_numerical::UNITNONE); $repeatedoptions['unit']['type'] = PARAM_NOTAGS; $repeatedoptions['multiplier']['disabledif'] = array('unitrole', 'eq', qtype_numerical::UNITNONE); $mform->disabledIf('addunits', 'unitrole', 'eq', qtype_numerical::UNITNONE); if (isset($this->question->options->units)) { $repeatsatstart = max(count($this->question->options->units), self::UNITS_MIN_REPEATS); } else { $repeatsatstart = self::UNITS_MIN_REPEATS; } $this->repeat_elements($unitfields, $repeatsatstart, $repeatedoptions, 'nounits', 'addunits', self::UNITS_TO_ADD, get_string('addmoreunitblanks', 'qtype_numerical', '{no}'), true); // The following strange-looking if statement is to do with when the // form is used to move questions between categories. See MDL-15159. if ($mform->elementExists('units[0]')) { $firstunit = $mform->getElement('units[0]'); $elements = $firstunit->getElements(); foreach ($elements as $element) { if ($element->getName() != 'multiplier[0]') { continue; } $element->freeze(); $element->setValue('1.0'); $element->setPersistantFreeze(true); } $mform->addHelpButton('units[0]', 'numericalmultiplier', 'qtype_numerical'); } }
[ "protected", "function", "add_unit_fields", "(", "$", "mform", ")", "{", "$", "mform", "->", "addElement", "(", "'header'", ",", "'unithdr'", ",", "get_string", "(", "'units'", ",", "'qtype_numerical'", ")", ",", "''", ")", ";", "$", "unitfields", "=", "array", "(", "$", "mform", "->", "createElement", "(", "'group'", ",", "'units'", ",", "get_string", "(", "'unitx'", ",", "'qtype_numerical'", ")", ",", "$", "this", "->", "unit_group", "(", "$", "mform", ")", ",", "null", ",", "false", ")", ")", ";", "$", "repeatedoptions", "[", "'unit'", "]", "[", "'disabledif'", "]", "=", "array", "(", "'unitrole'", ",", "'eq'", ",", "qtype_numerical", "::", "UNITNONE", ")", ";", "$", "repeatedoptions", "[", "'unit'", "]", "[", "'type'", "]", "=", "PARAM_NOTAGS", ";", "$", "repeatedoptions", "[", "'multiplier'", "]", "[", "'disabledif'", "]", "=", "array", "(", "'unitrole'", ",", "'eq'", ",", "qtype_numerical", "::", "UNITNONE", ")", ";", "$", "mform", "->", "disabledIf", "(", "'addunits'", ",", "'unitrole'", ",", "'eq'", ",", "qtype_numerical", "::", "UNITNONE", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "question", "->", "options", "->", "units", ")", ")", "{", "$", "repeatsatstart", "=", "max", "(", "count", "(", "$", "this", "->", "question", "->", "options", "->", "units", ")", ",", "self", "::", "UNITS_MIN_REPEATS", ")", ";", "}", "else", "{", "$", "repeatsatstart", "=", "self", "::", "UNITS_MIN_REPEATS", ";", "}", "$", "this", "->", "repeat_elements", "(", "$", "unitfields", ",", "$", "repeatsatstart", ",", "$", "repeatedoptions", ",", "'nounits'", ",", "'addunits'", ",", "self", "::", "UNITS_TO_ADD", ",", "get_string", "(", "'addmoreunitblanks'", ",", "'qtype_numerical'", ",", "'{no}'", ")", ",", "true", ")", ";", "// The following strange-looking if statement is to do with when the", "// form is used to move questions between categories. See MDL-15159.", "if", "(", "$", "mform", "->", "elementExists", "(", "'units[0]'", ")", ")", "{", "$", "firstunit", "=", "$", "mform", "->", "getElement", "(", "'units[0]'", ")", ";", "$", "elements", "=", "$", "firstunit", "->", "getElements", "(", ")", ";", "foreach", "(", "$", "elements", "as", "$", "element", ")", "{", "if", "(", "$", "element", "->", "getName", "(", ")", "!=", "'multiplier[0]'", ")", "{", "continue", ";", "}", "$", "element", "->", "freeze", "(", ")", ";", "$", "element", "->", "setValue", "(", "'1.0'", ")", ";", "$", "element", "->", "setPersistantFreeze", "(", "true", ")", ";", "}", "$", "mform", "->", "addHelpButton", "(", "'units[0]'", ",", "'numericalmultiplier'", ",", "'qtype_numerical'", ")", ";", "}", "}" ]
Add the input areas for each unit. @param object $mform the form being built.
[ "Add", "the", "input", "areas", "for", "each", "unit", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/numerical/edit_numerical_form.php#L139-L176
215,466
moodle/moodle
question/type/numerical/edit_numerical_form.php
qtype_numerical_edit_form.unit_group
protected function unit_group($mform) { $grouparray = array(); $grouparray[] = $mform->createElement('text', 'unit', get_string('unit', 'qtype_numerical'), array('size'=>10)); $grouparray[] = $mform->createElement('float', 'multiplier', get_string('multiplier', 'qtype_numerical'), array('size'=>10)); return $grouparray; }
php
protected function unit_group($mform) { $grouparray = array(); $grouparray[] = $mform->createElement('text', 'unit', get_string('unit', 'qtype_numerical'), array('size'=>10)); $grouparray[] = $mform->createElement('float', 'multiplier', get_string('multiplier', 'qtype_numerical'), array('size'=>10)); return $grouparray; }
[ "protected", "function", "unit_group", "(", "$", "mform", ")", "{", "$", "grouparray", "=", "array", "(", ")", ";", "$", "grouparray", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'text'", ",", "'unit'", ",", "get_string", "(", "'unit'", ",", "'qtype_numerical'", ")", ",", "array", "(", "'size'", "=>", "10", ")", ")", ";", "$", "grouparray", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'float'", ",", "'multiplier'", ",", "get_string", "(", "'multiplier'", ",", "'qtype_numerical'", ")", ",", "array", "(", "'size'", "=>", "10", ")", ")", ";", "return", "$", "grouparray", ";", "}" ]
Get the form fields needed to edit one unit. @param MoodleQuickForm $mform the form being built. @return array of form fields.
[ "Get", "the", "form", "fields", "needed", "to", "edit", "one", "unit", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/numerical/edit_numerical_form.php#L183-L190
215,467
moodle/moodle
backup/cc/cc_lib/cc_organization.php
cc_organization.add_item
public function add_item(cc_i_item &$item) { if (is_null($this->itemlist)) { $this->itemlist = array(); } $this->itemlist[$item->identifier] = $item; }
php
public function add_item(cc_i_item &$item) { if (is_null($this->itemlist)) { $this->itemlist = array(); } $this->itemlist[$item->identifier] = $item; }
[ "public", "function", "add_item", "(", "cc_i_item", "&", "$", "item", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "itemlist", ")", ")", "{", "$", "this", "->", "itemlist", "=", "array", "(", ")", ";", "}", "$", "this", "->", "itemlist", "[", "$", "item", "->", "identifier", "]", "=", "$", "item", ";", "}" ]
Add one Item into the Organization @param cc_i_item $item
[ "Add", "one", "Item", "into", "the", "Organization" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/cc/cc_lib/cc_organization.php#L60-L65
215,468
moodle/moodle
backup/cc/cc_lib/cc_organization.php
cc_organization.add_new_item
public function add_new_item($title='') { $nitem = new cc_item(); $nitem->title = $title; $this->add_item($nitem); return $nitem; }
php
public function add_new_item($title='') { $nitem = new cc_item(); $nitem->title = $title; $this->add_item($nitem); return $nitem; }
[ "public", "function", "add_new_item", "(", "$", "title", "=", "''", ")", "{", "$", "nitem", "=", "new", "cc_item", "(", ")", ";", "$", "nitem", "->", "title", "=", "$", "title", ";", "$", "this", "->", "add_item", "(", "$", "nitem", ")", ";", "return", "$", "nitem", ";", "}" ]
Add new Item into the Organization @param string $title @return cc_i_item
[ "Add", "new", "Item", "into", "the", "Organization" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/cc/cc_lib/cc_organization.php#L73-L78
215,469
moodle/moodle
backup/cc/cc_lib/cc_organization.php
cc_item.add_child_item
public function add_child_item(cc_i_item &$item) { if (is_null($this->childitems)) { $this->childitems = array(); } $this->childitems[$item->identifier] = $item; }
php
public function add_child_item(cc_i_item &$item) { if (is_null($this->childitems)) { $this->childitems = array(); } $this->childitems[$item->identifier] = $item; }
[ "public", "function", "add_child_item", "(", "cc_i_item", "&", "$", "item", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "childitems", ")", ")", "{", "$", "this", "->", "childitems", "=", "array", "(", ")", ";", "}", "$", "this", "->", "childitems", "[", "$", "item", "->", "identifier", "]", "=", "$", "item", ";", "}" ]
Add one Child Item @param cc_i_item $item
[ "Add", "one", "Child", "Item" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/cc/cc_lib/cc_organization.php#L201-L206
215,470
moodle/moodle
backup/cc/cc_lib/cc_organization.php
cc_item.add_new_child_item
public function add_new_child_item($title='') { $sc = new cc_item(); $sc->title = $title; $this->add_child_item($sc); return $sc; }
php
public function add_new_child_item($title='') { $sc = new cc_item(); $sc->title = $title; $this->add_child_item($sc); return $sc; }
[ "public", "function", "add_new_child_item", "(", "$", "title", "=", "''", ")", "{", "$", "sc", "=", "new", "cc_item", "(", ")", ";", "$", "sc", "->", "title", "=", "$", "title", ";", "$", "this", "->", "add_child_item", "(", "$", "sc", ")", ";", "return", "$", "sc", ";", "}" ]
Add new child Item @param string $title @return cc_i_item
[ "Add", "new", "child", "Item" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/cc/cc_lib/cc_organization.php#L215-L220
215,471
moodle/moodle
lib/grade/grade_scale.php
grade_scale.delete
public function delete($source=null) { global $DB; // Trigger the scale deleted event. if (!empty($this->standard)) { $eventcontext = context_system::instance(); } else { if (!empty($this->courseid)) { $eventcontext = context_course::instance($this->courseid); } else { $eventcontext = context_system::instance(); } } $event = \core\event\scale_deleted::create(array( 'objectid' => $this->id, 'context' => $eventcontext )); $event->trigger(); if (parent::delete($source)) { $context = context_system::instance(); $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'grade', 'scale', $this->id); foreach ($files as $file) { $file->delete(); } return true; } return false; }
php
public function delete($source=null) { global $DB; // Trigger the scale deleted event. if (!empty($this->standard)) { $eventcontext = context_system::instance(); } else { if (!empty($this->courseid)) { $eventcontext = context_course::instance($this->courseid); } else { $eventcontext = context_system::instance(); } } $event = \core\event\scale_deleted::create(array( 'objectid' => $this->id, 'context' => $eventcontext )); $event->trigger(); if (parent::delete($source)) { $context = context_system::instance(); $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'grade', 'scale', $this->id); foreach ($files as $file) { $file->delete(); } return true; } return false; }
[ "public", "function", "delete", "(", "$", "source", "=", "null", ")", "{", "global", "$", "DB", ";", "// Trigger the scale deleted event.", "if", "(", "!", "empty", "(", "$", "this", "->", "standard", ")", ")", "{", "$", "eventcontext", "=", "context_system", "::", "instance", "(", ")", ";", "}", "else", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "courseid", ")", ")", "{", "$", "eventcontext", "=", "context_course", "::", "instance", "(", "$", "this", "->", "courseid", ")", ";", "}", "else", "{", "$", "eventcontext", "=", "context_system", "::", "instance", "(", ")", ";", "}", "}", "$", "event", "=", "\\", "core", "\\", "event", "\\", "scale_deleted", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "this", "->", "id", ",", "'context'", "=>", "$", "eventcontext", ")", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "if", "(", "parent", "::", "delete", "(", "$", "source", ")", ")", "{", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'grade'", ",", "'scale'", ",", "$", "this", "->", "id", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "file", "->", "delete", "(", ")", ";", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
Deletes this scale from the database. @param string $source from where was the object deleted (mod/forum, manual, etc.) @return bool success
[ "Deletes", "this", "scale", "from", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_scale.php#L180-L208
215,472
moodle/moodle
lib/grade/grade_scale.php
grade_scale.get_name
public function get_name() { // Grade scales can be created at site or course context, so set the filter context appropriately. $context = empty($this->courseid) ? context_system::instance() : context_course::instance($this->courseid); return format_string($this->name, false, ['context' => $context]); }
php
public function get_name() { // Grade scales can be created at site or course context, so set the filter context appropriately. $context = empty($this->courseid) ? context_system::instance() : context_course::instance($this->courseid); return format_string($this->name, false, ['context' => $context]); }
[ "public", "function", "get_name", "(", ")", "{", "// Grade scales can be created at site or course context, so set the filter context appropriately.", "$", "context", "=", "empty", "(", "$", "this", "->", "courseid", ")", "?", "context_system", "::", "instance", "(", ")", ":", "context_course", "::", "instance", "(", "$", "this", "->", "courseid", ")", ";", "return", "format_string", "(", "$", "this", "->", "name", ",", "false", ",", "[", "'context'", "=>", "$", "context", "]", ")", ";", "}" ]
Returns the most descriptive field for this object. This is a standard method used when we do not know the exact type of an object. @return string name
[ "Returns", "the", "most", "descriptive", "field", "for", "this", "object", ".", "This", "is", "a", "standard", "method", "used", "when", "we", "do", "not", "know", "the", "exact", "type", "of", "an", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_scale.php#L216-L220
215,473
moodle/moodle
lib/grade/grade_scale.php
grade_scale.is_used
public function is_used() { global $DB; global $CFG; // count grade items excluding the $params = array($this->id); $sql = "SELECT COUNT(id) FROM {grade_items} WHERE scaleid = ? AND outcomeid IS NULL"; if ($DB->count_records_sql($sql, $params)) { return true; } // count outcomes $sql = "SELECT COUNT(id) FROM {grade_outcomes} WHERE scaleid = ?"; if ($DB->count_records_sql($sql, $params)) { return true; } // Ask the competency subsystem. if (\core_competency\api::is_scale_used_anywhere($this->id)) { return true; } // Ask all plugins if the scale is used anywhere. $pluginsfunction = get_plugins_with_function('scale_used_anywhere'); foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { if ($pluginfunction($this->id)) { return true; } } } return false; }
php
public function is_used() { global $DB; global $CFG; // count grade items excluding the $params = array($this->id); $sql = "SELECT COUNT(id) FROM {grade_items} WHERE scaleid = ? AND outcomeid IS NULL"; if ($DB->count_records_sql($sql, $params)) { return true; } // count outcomes $sql = "SELECT COUNT(id) FROM {grade_outcomes} WHERE scaleid = ?"; if ($DB->count_records_sql($sql, $params)) { return true; } // Ask the competency subsystem. if (\core_competency\api::is_scale_used_anywhere($this->id)) { return true; } // Ask all plugins if the scale is used anywhere. $pluginsfunction = get_plugins_with_function('scale_used_anywhere'); foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { if ($pluginfunction($this->id)) { return true; } } } return false; }
[ "public", "function", "is_used", "(", ")", "{", "global", "$", "DB", ";", "global", "$", "CFG", ";", "// count grade items excluding the", "$", "params", "=", "array", "(", "$", "this", "->", "id", ")", ";", "$", "sql", "=", "\"SELECT COUNT(id) FROM {grade_items} WHERE scaleid = ? AND outcomeid IS NULL\"", ";", "if", "(", "$", "DB", "->", "count_records_sql", "(", "$", "sql", ",", "$", "params", ")", ")", "{", "return", "true", ";", "}", "// count outcomes", "$", "sql", "=", "\"SELECT COUNT(id) FROM {grade_outcomes} WHERE scaleid = ?\"", ";", "if", "(", "$", "DB", "->", "count_records_sql", "(", "$", "sql", ",", "$", "params", ")", ")", "{", "return", "true", ";", "}", "// Ask the competency subsystem.", "if", "(", "\\", "core_competency", "\\", "api", "::", "is_scale_used_anywhere", "(", "$", "this", "->", "id", ")", ")", "{", "return", "true", ";", "}", "// Ask all plugins if the scale is used anywhere.", "$", "pluginsfunction", "=", "get_plugins_with_function", "(", "'scale_used_anywhere'", ")", ";", "foreach", "(", "$", "pluginsfunction", "as", "$", "plugintype", "=>", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "pluginfunction", ")", "{", "if", "(", "$", "pluginfunction", "(", "$", "this", "->", "id", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Returns if scale used anywhere - activities, grade items, outcomes, etc. @return bool
[ "Returns", "if", "scale", "used", "anywhere", "-", "activities", "grade", "items", "outcomes", "etc", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_scale.php#L340-L373
215,474
moodle/moodle
lib/grade/grade_scale.php
grade_scale.get_description
public function get_description() { global $CFG; require_once($CFG->libdir . '/filelib.php'); $systemcontext = context_system::instance(); $options = new stdClass; $options->noclean = true; $description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', $systemcontext->id, 'grade', 'scale', $this->id); return format_text($description, $this->descriptionformat, $options); }
php
public function get_description() { global $CFG; require_once($CFG->libdir . '/filelib.php'); $systemcontext = context_system::instance(); $options = new stdClass; $options->noclean = true; $description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', $systemcontext->id, 'grade', 'scale', $this->id); return format_text($description, $this->descriptionformat, $options); }
[ "public", "function", "get_description", "(", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/filelib.php'", ")", ";", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "options", "=", "new", "stdClass", ";", "$", "options", "->", "noclean", "=", "true", ";", "$", "description", "=", "file_rewrite_pluginfile_urls", "(", "$", "this", "->", "description", ",", "'pluginfile.php'", ",", "$", "systemcontext", "->", "id", ",", "'grade'", ",", "'scale'", ",", "$", "this", "->", "id", ")", ";", "return", "format_text", "(", "$", "description", ",", "$", "this", "->", "descriptionformat", ",", "$", "options", ")", ";", "}" ]
Returns the formatted grade description with URLs converted @return string
[ "Returns", "the", "formatted", "grade", "description", "with", "URLs", "converted" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_scale.php#L380-L389
215,475
moodle/moodle
enrol/mnet/enrol.php
enrol_mnet_mnetservice_enrol.available_courses
public function available_courses() { global $CFG, $DB; require_once($CFG->libdir.'/filelib.php'); if (!$client = get_mnet_remote_client()) { die('Callable via XML-RPC only'); } // we call our id as 'remoteid' because it will be sent to the peer // the column aliases are required by MNet protocol API for clients 1.x and 2.0 $sql = "SELECT c.id AS remoteid, c.fullname, c.shortname, c.idnumber, c.summary, c.summaryformat, c.sortorder, c.startdate, cat.id AS cat_id, cat.name AS cat_name, cat.description AS cat_description, cat.descriptionformat AS cat_descriptionformat, e.cost, e.currency, e.roleid AS defaultroleid, r.name AS defaultrolename, e.customint1 FROM {enrol} e INNER JOIN {course} c ON c.id = e.courseid INNER JOIN {course_categories} cat ON cat.id = c.category INNER JOIN {role} r ON r.id = e.roleid WHERE e.enrol = 'mnet' AND (e.customint1 = 0 OR e.customint1 = ?) AND c.visible = 1 ORDER BY cat.sortorder, c.sortorder, c.shortname"; $rs = $DB->get_recordset_sql($sql, array($client->id)); $courses = array(); foreach ($rs as $course) { // use the record if it does not exist yet or is host-specific if (empty($courses[$course->remoteid]) or ($course->customint1 > 0)) { unset($course->customint1); // the client does not need to know this $context = context_course::instance($course->remoteid); // Rewrite file URLs so that they are correct $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', false); $courses[$course->remoteid] = $course; } } $rs->close(); return array_values($courses); // can not use keys for backward compatibility }
php
public function available_courses() { global $CFG, $DB; require_once($CFG->libdir.'/filelib.php'); if (!$client = get_mnet_remote_client()) { die('Callable via XML-RPC only'); } // we call our id as 'remoteid' because it will be sent to the peer // the column aliases are required by MNet protocol API for clients 1.x and 2.0 $sql = "SELECT c.id AS remoteid, c.fullname, c.shortname, c.idnumber, c.summary, c.summaryformat, c.sortorder, c.startdate, cat.id AS cat_id, cat.name AS cat_name, cat.description AS cat_description, cat.descriptionformat AS cat_descriptionformat, e.cost, e.currency, e.roleid AS defaultroleid, r.name AS defaultrolename, e.customint1 FROM {enrol} e INNER JOIN {course} c ON c.id = e.courseid INNER JOIN {course_categories} cat ON cat.id = c.category INNER JOIN {role} r ON r.id = e.roleid WHERE e.enrol = 'mnet' AND (e.customint1 = 0 OR e.customint1 = ?) AND c.visible = 1 ORDER BY cat.sortorder, c.sortorder, c.shortname"; $rs = $DB->get_recordset_sql($sql, array($client->id)); $courses = array(); foreach ($rs as $course) { // use the record if it does not exist yet or is host-specific if (empty($courses[$course->remoteid]) or ($course->customint1 > 0)) { unset($course->customint1); // the client does not need to know this $context = context_course::instance($course->remoteid); // Rewrite file URLs so that they are correct $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', false); $courses[$course->remoteid] = $course; } } $rs->close(); return array_values($courses); // can not use keys for backward compatibility }
[ "public", "function", "available_courses", "(", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/filelib.php'", ")", ";", "if", "(", "!", "$", "client", "=", "get_mnet_remote_client", "(", ")", ")", "{", "die", "(", "'Callable via XML-RPC only'", ")", ";", "}", "// we call our id as 'remoteid' because it will be sent to the peer", "// the column aliases are required by MNet protocol API for clients 1.x and 2.0", "$", "sql", "=", "\"SELECT c.id AS remoteid, c.fullname, c.shortname, c.idnumber, c.summary, c.summaryformat,\n c.sortorder, c.startdate, cat.id AS cat_id, cat.name AS cat_name,\n cat.description AS cat_description, cat.descriptionformat AS cat_descriptionformat,\n e.cost, e.currency, e.roleid AS defaultroleid, r.name AS defaultrolename,\n e.customint1\n FROM {enrol} e\n INNER JOIN {course} c ON c.id = e.courseid\n INNER JOIN {course_categories} cat ON cat.id = c.category\n INNER JOIN {role} r ON r.id = e.roleid\n WHERE e.enrol = 'mnet'\n AND (e.customint1 = 0 OR e.customint1 = ?)\n AND c.visible = 1\n ORDER BY cat.sortorder, c.sortorder, c.shortname\"", ";", "$", "rs", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "array", "(", "$", "client", "->", "id", ")", ")", ";", "$", "courses", "=", "array", "(", ")", ";", "foreach", "(", "$", "rs", "as", "$", "course", ")", "{", "// use the record if it does not exist yet or is host-specific", "if", "(", "empty", "(", "$", "courses", "[", "$", "course", "->", "remoteid", "]", ")", "or", "(", "$", "course", "->", "customint1", ">", "0", ")", ")", "{", "unset", "(", "$", "course", "->", "customint1", ")", ";", "// the client does not need to know this", "$", "context", "=", "context_course", "::", "instance", "(", "$", "course", "->", "remoteid", ")", ";", "// Rewrite file URLs so that they are correct", "$", "course", "->", "summary", "=", "file_rewrite_pluginfile_urls", "(", "$", "course", "->", "summary", ",", "'pluginfile.php'", ",", "$", "context", "->", "id", ",", "'course'", ",", "'summary'", ",", "false", ")", ";", "$", "courses", "[", "$", "course", "->", "remoteid", "]", "=", "$", "course", ";", "}", "}", "$", "rs", "->", "close", "(", ")", ";", "return", "array_values", "(", "$", "courses", ")", ";", "// can not use keys for backward compatibility", "}" ]
Returns list of courses that we offer to the caller for remote enrolment of their users Since Moodle 2.0, courses are made available for MNet peers by creating an instance of enrol_mnet plugin for the course. Hidden courses are not returned. If there are two instances - one specific for the host and one for 'All hosts', the setting of the specific one is used. The id of the peer is kept in customint1, no other custom fields are used. @uses mnet_remote_client Callable via XML-RPC only @return array
[ "Returns", "list", "of", "courses", "that", "we", "offer", "to", "the", "caller", "for", "remote", "enrolment", "of", "their", "users" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/mnet/enrol.php#L58-L98
215,476
moodle/moodle
enrol/mnet/enrol.php
enrol_mnet_mnetservice_enrol.enrol_user
public function enrol_user(array $userdata, $courseid) { global $CFG, $DB; require_once(__DIR__.'/lib.php'); if (!$client = get_mnet_remote_client()) { die('Callable via XML-RPC only'); } if (empty($userdata['username'])) { throw new mnet_server_exception(5021, 'emptyusername', 'enrol_mnet'); } // do we know the remote user? $user = $DB->get_record('user', array('username'=>$userdata['username'], 'mnethostid'=>$client->id)); if ($user === false) { // here we could check the setting if the enrol_mnet is allowed to auto-register // users {@link http://tracker.moodle.org/browse/MDL-21327} $user = mnet_strip_user((object)$userdata, mnet_fields_to_import($client)); $user->mnethostid = $client->id; $user->auth = 'mnet'; $user->confirmed = 1; try { $user->id = $DB->insert_record('user', $user); } catch (Exception $e) { throw new mnet_server_exception(5011, 'couldnotcreateuser', 'enrol_mnet'); } } if (! $course = $DB->get_record('course', array('id'=>$courseid))) { throw new mnet_server_exception(5012, 'coursenotfound', 'enrol_mnet'); } $courses = $this->available_courses(); $isavailable = false; foreach ($courses as $available) { if ($available->remoteid == $course->id) { $isavailable = true; break; } } if (!$isavailable) { throw new mnet_server_exception(5013, 'courseunavailable', 'enrol_mnet'); } // try to load host specific enrol_mnet instance first $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'mnet', 'customint1'=>$client->id), '*', IGNORE_MISSING); if ($instance === false) { // if not found, try to load instance for all hosts $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'mnet', 'customint1'=>0), '*', IGNORE_MISSING); } if ($instance === false) { // this should not happen as the course was returned by {@see self::available_courses()} throw new mnet_server_exception(5017, 'noenrolinstance', 'enrol_mnet'); } if (!$enrol = enrol_get_plugin('mnet')) { throw new mnet_server_exception(5018, 'couldnotinstantiate', 'enrol_mnet'); } try { $enrol->enrol_user($instance, $user->id, $instance->roleid, time()); } catch (Exception $e) { throw new mnet_server_exception(5019, 'couldnotenrol', 'enrol_mnet', $e->getMessage()); } return true; }
php
public function enrol_user(array $userdata, $courseid) { global $CFG, $DB; require_once(__DIR__.'/lib.php'); if (!$client = get_mnet_remote_client()) { die('Callable via XML-RPC only'); } if (empty($userdata['username'])) { throw new mnet_server_exception(5021, 'emptyusername', 'enrol_mnet'); } // do we know the remote user? $user = $DB->get_record('user', array('username'=>$userdata['username'], 'mnethostid'=>$client->id)); if ($user === false) { // here we could check the setting if the enrol_mnet is allowed to auto-register // users {@link http://tracker.moodle.org/browse/MDL-21327} $user = mnet_strip_user((object)$userdata, mnet_fields_to_import($client)); $user->mnethostid = $client->id; $user->auth = 'mnet'; $user->confirmed = 1; try { $user->id = $DB->insert_record('user', $user); } catch (Exception $e) { throw new mnet_server_exception(5011, 'couldnotcreateuser', 'enrol_mnet'); } } if (! $course = $DB->get_record('course', array('id'=>$courseid))) { throw new mnet_server_exception(5012, 'coursenotfound', 'enrol_mnet'); } $courses = $this->available_courses(); $isavailable = false; foreach ($courses as $available) { if ($available->remoteid == $course->id) { $isavailable = true; break; } } if (!$isavailable) { throw new mnet_server_exception(5013, 'courseunavailable', 'enrol_mnet'); } // try to load host specific enrol_mnet instance first $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'mnet', 'customint1'=>$client->id), '*', IGNORE_MISSING); if ($instance === false) { // if not found, try to load instance for all hosts $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'mnet', 'customint1'=>0), '*', IGNORE_MISSING); } if ($instance === false) { // this should not happen as the course was returned by {@see self::available_courses()} throw new mnet_server_exception(5017, 'noenrolinstance', 'enrol_mnet'); } if (!$enrol = enrol_get_plugin('mnet')) { throw new mnet_server_exception(5018, 'couldnotinstantiate', 'enrol_mnet'); } try { $enrol->enrol_user($instance, $user->id, $instance->roleid, time()); } catch (Exception $e) { throw new mnet_server_exception(5019, 'couldnotenrol', 'enrol_mnet', $e->getMessage()); } return true; }
[ "public", "function", "enrol_user", "(", "array", "$", "userdata", ",", "$", "courseid", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "require_once", "(", "__DIR__", ".", "'/lib.php'", ")", ";", "if", "(", "!", "$", "client", "=", "get_mnet_remote_client", "(", ")", ")", "{", "die", "(", "'Callable via XML-RPC only'", ")", ";", "}", "if", "(", "empty", "(", "$", "userdata", "[", "'username'", "]", ")", ")", "{", "throw", "new", "mnet_server_exception", "(", "5021", ",", "'emptyusername'", ",", "'enrol_mnet'", ")", ";", "}", "// do we know the remote user?", "$", "user", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'username'", "=>", "$", "userdata", "[", "'username'", "]", ",", "'mnethostid'", "=>", "$", "client", "->", "id", ")", ")", ";", "if", "(", "$", "user", "===", "false", ")", "{", "// here we could check the setting if the enrol_mnet is allowed to auto-register", "// users {@link http://tracker.moodle.org/browse/MDL-21327}", "$", "user", "=", "mnet_strip_user", "(", "(", "object", ")", "$", "userdata", ",", "mnet_fields_to_import", "(", "$", "client", ")", ")", ";", "$", "user", "->", "mnethostid", "=", "$", "client", "->", "id", ";", "$", "user", "->", "auth", "=", "'mnet'", ";", "$", "user", "->", "confirmed", "=", "1", ";", "try", "{", "$", "user", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'user'", ",", "$", "user", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "mnet_server_exception", "(", "5011", ",", "'couldnotcreateuser'", ",", "'enrol_mnet'", ")", ";", "}", "}", "if", "(", "!", "$", "course", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "array", "(", "'id'", "=>", "$", "courseid", ")", ")", ")", "{", "throw", "new", "mnet_server_exception", "(", "5012", ",", "'coursenotfound'", ",", "'enrol_mnet'", ")", ";", "}", "$", "courses", "=", "$", "this", "->", "available_courses", "(", ")", ";", "$", "isavailable", "=", "false", ";", "foreach", "(", "$", "courses", "as", "$", "available", ")", "{", "if", "(", "$", "available", "->", "remoteid", "==", "$", "course", "->", "id", ")", "{", "$", "isavailable", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "$", "isavailable", ")", "{", "throw", "new", "mnet_server_exception", "(", "5013", ",", "'courseunavailable'", ",", "'enrol_mnet'", ")", ";", "}", "// try to load host specific enrol_mnet instance first", "$", "instance", "=", "$", "DB", "->", "get_record", "(", "'enrol'", ",", "array", "(", "'courseid'", "=>", "$", "course", "->", "id", ",", "'enrol'", "=>", "'mnet'", ",", "'customint1'", "=>", "$", "client", "->", "id", ")", ",", "'*'", ",", "IGNORE_MISSING", ")", ";", "if", "(", "$", "instance", "===", "false", ")", "{", "// if not found, try to load instance for all hosts", "$", "instance", "=", "$", "DB", "->", "get_record", "(", "'enrol'", ",", "array", "(", "'courseid'", "=>", "$", "course", "->", "id", ",", "'enrol'", "=>", "'mnet'", ",", "'customint1'", "=>", "0", ")", ",", "'*'", ",", "IGNORE_MISSING", ")", ";", "}", "if", "(", "$", "instance", "===", "false", ")", "{", "// this should not happen as the course was returned by {@see self::available_courses()}", "throw", "new", "mnet_server_exception", "(", "5017", ",", "'noenrolinstance'", ",", "'enrol_mnet'", ")", ";", "}", "if", "(", "!", "$", "enrol", "=", "enrol_get_plugin", "(", "'mnet'", ")", ")", "{", "throw", "new", "mnet_server_exception", "(", "5018", ",", "'couldnotinstantiate'", ",", "'enrol_mnet'", ")", ";", "}", "try", "{", "$", "enrol", "->", "enrol_user", "(", "$", "instance", ",", "$", "user", "->", "id", ",", "$", "instance", "->", "roleid", ",", "time", "(", ")", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "mnet_server_exception", "(", "5019", ",", "'couldnotenrol'", ",", "'enrol_mnet'", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "return", "true", ";", "}" ]
Enrol remote user to our course If we do not have local record for the remote user in our database, it gets created here. @uses mnet_remote_client Callable via XML-RPC only @param array $userdata user details {@see mnet_fields_to_import()} @param int $courseid our local course id @return bool true if the enrolment has been successful, throws exception otherwise
[ "Enrol", "remote", "user", "to", "our", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/mnet/enrol.php#L126-L196
215,477
moodle/moodle
enrol/mnet/enrol.php
enrol_mnet_mnetservice_enrol.unenrol_user
public function unenrol_user($username, $courseid) { global $CFG, $DB; if (!$client = get_mnet_remote_client()) { die('Callable via XML-RPC only'); } $user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$client->id)); if ($user === false) { throw new mnet_server_exception(5014, 'usernotfound', 'enrol_mnet'); } if (! $course = $DB->get_record('course', array('id'=>$courseid))) { throw new mnet_server_exception(5012, 'coursenotfound', 'enrol_mnet'); } $courses = $this->available_courses(); $isavailable = false; foreach ($courses as $available) { if ($available->remoteid == $course->id) { $isavailable = true; break; } } if (!$isavailable) { // if they can not enrol, they can not unenrol throw new mnet_server_exception(5013, 'courseunavailable', 'enrol_mnet'); } // try to load host specific enrol_mnet instance first $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'mnet', 'customint1'=>$client->id), '*', IGNORE_MISSING); if ($instance === false) { // if not found, try to load instance for all hosts $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'mnet', 'customint1'=>0), '*', IGNORE_MISSING); $instanceforall = true; } if ($instance === false) { // this should not happen as the course was returned by {@see self::available_courses()} throw new mnet_server_exception(5017, 'noenrolinstance', 'enrol_mnet'); } if (!$enrol = enrol_get_plugin('mnet')) { throw new mnet_server_exception(5018, 'couldnotinstantiate', 'enrol_mnet'); } if ($DB->record_exists('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$user->id))) { try { $enrol->unenrol_user($instance, $user->id); } catch (Exception $e) { throw new mnet_server_exception(5020, 'couldnotunenrol', 'enrol_mnet', $e->getMessage()); } } if (empty($instanceforall)) { // if the user was enrolled via 'All hosts' instance and the specific one // was created after that, the first enrolment would be kept. $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'mnet', 'customint1'=>0), '*', IGNORE_MISSING); if ($instance) { // repeat the same procedure for 'All hosts' instance, too. Note that as the host specific // instance exists, it will be used for the future enrolments if ($DB->record_exists('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$user->id))) { try { $enrol->unenrol_user($instance, $user->id); } catch (Exception $e) { throw new mnet_server_exception(5020, 'couldnotunenrol', 'enrol_mnet', $e->getMessage()); } } } } return true; }
php
public function unenrol_user($username, $courseid) { global $CFG, $DB; if (!$client = get_mnet_remote_client()) { die('Callable via XML-RPC only'); } $user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$client->id)); if ($user === false) { throw new mnet_server_exception(5014, 'usernotfound', 'enrol_mnet'); } if (! $course = $DB->get_record('course', array('id'=>$courseid))) { throw new mnet_server_exception(5012, 'coursenotfound', 'enrol_mnet'); } $courses = $this->available_courses(); $isavailable = false; foreach ($courses as $available) { if ($available->remoteid == $course->id) { $isavailable = true; break; } } if (!$isavailable) { // if they can not enrol, they can not unenrol throw new mnet_server_exception(5013, 'courseunavailable', 'enrol_mnet'); } // try to load host specific enrol_mnet instance first $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'mnet', 'customint1'=>$client->id), '*', IGNORE_MISSING); if ($instance === false) { // if not found, try to load instance for all hosts $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'mnet', 'customint1'=>0), '*', IGNORE_MISSING); $instanceforall = true; } if ($instance === false) { // this should not happen as the course was returned by {@see self::available_courses()} throw new mnet_server_exception(5017, 'noenrolinstance', 'enrol_mnet'); } if (!$enrol = enrol_get_plugin('mnet')) { throw new mnet_server_exception(5018, 'couldnotinstantiate', 'enrol_mnet'); } if ($DB->record_exists('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$user->id))) { try { $enrol->unenrol_user($instance, $user->id); } catch (Exception $e) { throw new mnet_server_exception(5020, 'couldnotunenrol', 'enrol_mnet', $e->getMessage()); } } if (empty($instanceforall)) { // if the user was enrolled via 'All hosts' instance and the specific one // was created after that, the first enrolment would be kept. $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'mnet', 'customint1'=>0), '*', IGNORE_MISSING); if ($instance) { // repeat the same procedure for 'All hosts' instance, too. Note that as the host specific // instance exists, it will be used for the future enrolments if ($DB->record_exists('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$user->id))) { try { $enrol->unenrol_user($instance, $user->id); } catch (Exception $e) { throw new mnet_server_exception(5020, 'couldnotunenrol', 'enrol_mnet', $e->getMessage()); } } } } return true; }
[ "public", "function", "unenrol_user", "(", "$", "username", ",", "$", "courseid", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "if", "(", "!", "$", "client", "=", "get_mnet_remote_client", "(", ")", ")", "{", "die", "(", "'Callable via XML-RPC only'", ")", ";", "}", "$", "user", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'username'", "=>", "$", "username", ",", "'mnethostid'", "=>", "$", "client", "->", "id", ")", ")", ";", "if", "(", "$", "user", "===", "false", ")", "{", "throw", "new", "mnet_server_exception", "(", "5014", ",", "'usernotfound'", ",", "'enrol_mnet'", ")", ";", "}", "if", "(", "!", "$", "course", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "array", "(", "'id'", "=>", "$", "courseid", ")", ")", ")", "{", "throw", "new", "mnet_server_exception", "(", "5012", ",", "'coursenotfound'", ",", "'enrol_mnet'", ")", ";", "}", "$", "courses", "=", "$", "this", "->", "available_courses", "(", ")", ";", "$", "isavailable", "=", "false", ";", "foreach", "(", "$", "courses", "as", "$", "available", ")", "{", "if", "(", "$", "available", "->", "remoteid", "==", "$", "course", "->", "id", ")", "{", "$", "isavailable", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "$", "isavailable", ")", "{", "// if they can not enrol, they can not unenrol", "throw", "new", "mnet_server_exception", "(", "5013", ",", "'courseunavailable'", ",", "'enrol_mnet'", ")", ";", "}", "// try to load host specific enrol_mnet instance first", "$", "instance", "=", "$", "DB", "->", "get_record", "(", "'enrol'", ",", "array", "(", "'courseid'", "=>", "$", "course", "->", "id", ",", "'enrol'", "=>", "'mnet'", ",", "'customint1'", "=>", "$", "client", "->", "id", ")", ",", "'*'", ",", "IGNORE_MISSING", ")", ";", "if", "(", "$", "instance", "===", "false", ")", "{", "// if not found, try to load instance for all hosts", "$", "instance", "=", "$", "DB", "->", "get_record", "(", "'enrol'", ",", "array", "(", "'courseid'", "=>", "$", "course", "->", "id", ",", "'enrol'", "=>", "'mnet'", ",", "'customint1'", "=>", "0", ")", ",", "'*'", ",", "IGNORE_MISSING", ")", ";", "$", "instanceforall", "=", "true", ";", "}", "if", "(", "$", "instance", "===", "false", ")", "{", "// this should not happen as the course was returned by {@see self::available_courses()}", "throw", "new", "mnet_server_exception", "(", "5017", ",", "'noenrolinstance'", ",", "'enrol_mnet'", ")", ";", "}", "if", "(", "!", "$", "enrol", "=", "enrol_get_plugin", "(", "'mnet'", ")", ")", "{", "throw", "new", "mnet_server_exception", "(", "5018", ",", "'couldnotinstantiate'", ",", "'enrol_mnet'", ")", ";", "}", "if", "(", "$", "DB", "->", "record_exists", "(", "'user_enrolments'", ",", "array", "(", "'enrolid'", "=>", "$", "instance", "->", "id", ",", "'userid'", "=>", "$", "user", "->", "id", ")", ")", ")", "{", "try", "{", "$", "enrol", "->", "unenrol_user", "(", "$", "instance", ",", "$", "user", "->", "id", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "mnet_server_exception", "(", "5020", ",", "'couldnotunenrol'", ",", "'enrol_mnet'", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "instanceforall", ")", ")", "{", "// if the user was enrolled via 'All hosts' instance and the specific one", "// was created after that, the first enrolment would be kept.", "$", "instance", "=", "$", "DB", "->", "get_record", "(", "'enrol'", ",", "array", "(", "'courseid'", "=>", "$", "course", "->", "id", ",", "'enrol'", "=>", "'mnet'", ",", "'customint1'", "=>", "0", ")", ",", "'*'", ",", "IGNORE_MISSING", ")", ";", "if", "(", "$", "instance", ")", "{", "// repeat the same procedure for 'All hosts' instance, too. Note that as the host specific", "// instance exists, it will be used for the future enrolments", "if", "(", "$", "DB", "->", "record_exists", "(", "'user_enrolments'", ",", "array", "(", "'enrolid'", "=>", "$", "instance", "->", "id", ",", "'userid'", "=>", "$", "user", "->", "id", ")", ")", ")", "{", "try", "{", "$", "enrol", "->", "unenrol_user", "(", "$", "instance", ",", "$", "user", "->", "id", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "mnet_server_exception", "(", "5020", ",", "'couldnotunenrol'", ",", "'enrol_mnet'", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}", "}", "}", "return", "true", ";", "}" ]
Unenrol remote user from our course Only users enrolled via enrol_mnet plugin can be unenrolled remotely. If the remote user is enrolled into the local course via some other enrol plugin (enrol_manual for example), the remote host can't touch such enrolment. Please do not report this behaviour as bug, it is a feature ;-) @uses mnet_remote_client Callable via XML-RPC only @param string $username of the remote user @param int $courseid of our local course @return bool true if the unenrolment has been successful, throws exception otherwise
[ "Unenrol", "remote", "user", "from", "our", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/mnet/enrol.php#L211-L289
215,478
moodle/moodle
enrol/mnet/enrol.php
enrol_mnet_mnetservice_enrol.course_enrolments
public function course_enrolments($courseid, $roles=null) { global $DB, $CFG; if (!$client = get_mnet_remote_client()) { die('Callable via XML-RPC only'); } $sql = "SELECT u.username, r.shortname, r.name, e.enrol, ue.timemodified FROM {user_enrolments} ue JOIN {user} u ON ue.userid = u.id JOIN {enrol} e ON ue.enrolid = e.id JOIN {role} r ON e.roleid = r.id WHERE u.mnethostid = :mnethostid AND e.courseid = :courseid AND u.id <> :guestid AND u.confirmed = 1 AND u.deleted = 0"; $params['mnethostid'] = $client->id; $params['courseid'] = $courseid; $params['guestid'] = $CFG->siteguest; if (!is_null($roles)) { if (!is_array($roles)) { $roles = explode(',', $roles); } $roles = array_map('trim', $roles); list($rsql, $rparams) = $DB->get_in_or_equal($roles, SQL_PARAMS_NAMED); $sql .= " AND r.shortname $rsql"; $params = array_merge($params, $rparams); } list($sort, $sortparams) = users_order_by_sql('u'); $sql .= " ORDER BY $sort"; $rs = $DB->get_recordset_sql($sql, array_merge($params, $sortparams)); $list = array(); foreach ($rs as $record) { $list[] = $record; } $rs->close(); return $list; }
php
public function course_enrolments($courseid, $roles=null) { global $DB, $CFG; if (!$client = get_mnet_remote_client()) { die('Callable via XML-RPC only'); } $sql = "SELECT u.username, r.shortname, r.name, e.enrol, ue.timemodified FROM {user_enrolments} ue JOIN {user} u ON ue.userid = u.id JOIN {enrol} e ON ue.enrolid = e.id JOIN {role} r ON e.roleid = r.id WHERE u.mnethostid = :mnethostid AND e.courseid = :courseid AND u.id <> :guestid AND u.confirmed = 1 AND u.deleted = 0"; $params['mnethostid'] = $client->id; $params['courseid'] = $courseid; $params['guestid'] = $CFG->siteguest; if (!is_null($roles)) { if (!is_array($roles)) { $roles = explode(',', $roles); } $roles = array_map('trim', $roles); list($rsql, $rparams) = $DB->get_in_or_equal($roles, SQL_PARAMS_NAMED); $sql .= " AND r.shortname $rsql"; $params = array_merge($params, $rparams); } list($sort, $sortparams) = users_order_by_sql('u'); $sql .= " ORDER BY $sort"; $rs = $DB->get_recordset_sql($sql, array_merge($params, $sortparams)); $list = array(); foreach ($rs as $record) { $list[] = $record; } $rs->close(); return $list; }
[ "public", "function", "course_enrolments", "(", "$", "courseid", ",", "$", "roles", "=", "null", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "if", "(", "!", "$", "client", "=", "get_mnet_remote_client", "(", ")", ")", "{", "die", "(", "'Callable via XML-RPC only'", ")", ";", "}", "$", "sql", "=", "\"SELECT u.username, r.shortname, r.name, e.enrol, ue.timemodified\n FROM {user_enrolments} ue\n JOIN {user} u ON ue.userid = u.id\n JOIN {enrol} e ON ue.enrolid = e.id\n JOIN {role} r ON e.roleid = r.id\n WHERE u.mnethostid = :mnethostid\n AND e.courseid = :courseid\n AND u.id <> :guestid\n AND u.confirmed = 1\n AND u.deleted = 0\"", ";", "$", "params", "[", "'mnethostid'", "]", "=", "$", "client", "->", "id", ";", "$", "params", "[", "'courseid'", "]", "=", "$", "courseid", ";", "$", "params", "[", "'guestid'", "]", "=", "$", "CFG", "->", "siteguest", ";", "if", "(", "!", "is_null", "(", "$", "roles", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "roles", ")", ")", "{", "$", "roles", "=", "explode", "(", "','", ",", "$", "roles", ")", ";", "}", "$", "roles", "=", "array_map", "(", "'trim'", ",", "$", "roles", ")", ";", "list", "(", "$", "rsql", ",", "$", "rparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "roles", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sql", ".=", "\" AND r.shortname $rsql\"", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "rparams", ")", ";", "}", "list", "(", "$", "sort", ",", "$", "sortparams", ")", "=", "users_order_by_sql", "(", "'u'", ")", ";", "$", "sql", ".=", "\" ORDER BY $sort\"", ";", "$", "rs", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "array_merge", "(", "$", "params", ",", "$", "sortparams", ")", ")", ";", "$", "list", "=", "array", "(", ")", ";", "foreach", "(", "$", "rs", "as", "$", "record", ")", "{", "$", "list", "[", "]", "=", "$", "record", ";", "}", "$", "rs", "->", "close", "(", ")", ";", "return", "$", "list", ";", "}" ]
Returns a list of users from the client server who are enrolled in our course Suitable instance of enrol_mnet must be created in the course. This method will not return any information about the enrolments in courses that are not available for remote enrolment, even if their users are enrolled into them via other plugin (note the difference from {@link self::user_enrolments()}). This method will return enrolment information for users from hosts regardless the enrolment plugin. It does not matter if the user was enrolled remotely by their admin or locally. Once the course is available for remote enrolments, we will tell them everything about their users. In Moodle 1.x the returned array used to be indexed by username. The side effect of MDL-19219 fix is that we do not need to use such index and therefore we can return all enrolment records. MNet clients 1.x will only use the last record for the student, if she is enrolled via multiple plugins. @uses mnet_remote_client Callable via XML-RPC only @param int $courseid ID of our course @param string|array $roles comma separated list of role shortnames (or array of them) @return array
[ "Returns", "a", "list", "of", "users", "from", "the", "client", "server", "who", "are", "enrolled", "in", "our", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/mnet/enrol.php#L314-L356
215,479
moodle/moodle
question/classes/statistics/responses/analysis_for_actual_response.php
analysis_for_actual_response.increment_count
public function increment_count($try = 0) { $this->totalcount++; if ($try != 0) { if ($try > analyser::MAX_TRY_COUNTED) { $try = analyser::MAX_TRY_COUNTED; } if (!isset($this->trycount[$try])) { $this->trycount[$try] = 0; } $this->trycount[$try]++; } }
php
public function increment_count($try = 0) { $this->totalcount++; if ($try != 0) { if ($try > analyser::MAX_TRY_COUNTED) { $try = analyser::MAX_TRY_COUNTED; } if (!isset($this->trycount[$try])) { $this->trycount[$try] = 0; } $this->trycount[$try]++; } }
[ "public", "function", "increment_count", "(", "$", "try", "=", "0", ")", "{", "$", "this", "->", "totalcount", "++", ";", "if", "(", "$", "try", "!=", "0", ")", "{", "if", "(", "$", "try", ">", "analyser", "::", "MAX_TRY_COUNTED", ")", "{", "$", "try", "=", "analyser", "::", "MAX_TRY_COUNTED", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "trycount", "[", "$", "try", "]", ")", ")", "{", "$", "this", "->", "trycount", "[", "$", "try", "]", "=", "0", ";", "}", "$", "this", "->", "trycount", "[", "$", "try", "]", "++", ";", "}", "}" ]
Used to count the occurrences of response sub parts. @param int $try the try number, or 0 if only keeping one count, not a count for each try.
[ "Used", "to", "count", "the", "occurrences", "of", "response", "sub", "parts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/responses/analysis_for_actual_response.php#L80-L92
215,480
moodle/moodle
question/classes/statistics/responses/analysis_for_actual_response.php
analysis_for_actual_response.set_count
public function set_count($try, $count) { $this->totalcount = $this->totalcount + $count; $this->trycount[$try] = $count; }
php
public function set_count($try, $count) { $this->totalcount = $this->totalcount + $count; $this->trycount[$try] = $count; }
[ "public", "function", "set_count", "(", "$", "try", ",", "$", "count", ")", "{", "$", "this", "->", "totalcount", "=", "$", "this", "->", "totalcount", "+", "$", "count", ";", "$", "this", "->", "trycount", "[", "$", "try", "]", "=", "$", "count", ";", "}" ]
Used to set the count of occurrences of response sub parts, when loading count from cache. @param int $try the try number, or 0 if only keeping one count, not a count for each try. @param int $count
[ "Used", "to", "set", "the", "count", "of", "occurrences", "of", "response", "sub", "parts", "when", "loading", "count", "from", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/responses/analysis_for_actual_response.php#L100-L103
215,481
moodle/moodle
question/classes/statistics/responses/analysis_for_actual_response.php
analysis_for_actual_response.data_for_question_response_table
public function data_for_question_response_table($partid, $modelresponse) { $rowdata = new \stdClass(); $rowdata->part = $partid; $rowdata->responseclass = $modelresponse; $rowdata->response = $this->response; $rowdata->fraction = $this->fraction; $rowdata->totalcount = $this->totalcount; $rowdata->trycount = $this->trycount; return $rowdata; }
php
public function data_for_question_response_table($partid, $modelresponse) { $rowdata = new \stdClass(); $rowdata->part = $partid; $rowdata->responseclass = $modelresponse; $rowdata->response = $this->response; $rowdata->fraction = $this->fraction; $rowdata->totalcount = $this->totalcount; $rowdata->trycount = $this->trycount; return $rowdata; }
[ "public", "function", "data_for_question_response_table", "(", "$", "partid", ",", "$", "modelresponse", ")", "{", "$", "rowdata", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "rowdata", "->", "part", "=", "$", "partid", ";", "$", "rowdata", "->", "responseclass", "=", "$", "modelresponse", ";", "$", "rowdata", "->", "response", "=", "$", "this", "->", "response", ";", "$", "rowdata", "->", "fraction", "=", "$", "this", "->", "fraction", ";", "$", "rowdata", "->", "totalcount", "=", "$", "this", "->", "totalcount", ";", "$", "rowdata", "->", "trycount", "=", "$", "this", "->", "trycount", ";", "return", "$", "rowdata", ";", "}" ]
Returns an object with a property for each column of the question response analysis table. @param string $partid @param string $modelresponse @return object
[ "Returns", "an", "object", "with", "a", "property", "for", "each", "column", "of", "the", "question", "response", "analysis", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/responses/analysis_for_actual_response.php#L156-L165
215,482
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.get_edit_step_link
public static function get_edit_step_link($tourid, $stepid = null, $targettype = null) { $link = new \moodle_url('/admin/tool/usertours/configure.php'); if ($stepid) { $link->param('action', manager::ACTION_EDITSTEP); $link->param('id', $stepid); } else { $link->param('action', manager::ACTION_NEWSTEP); $link->param('tourid', $tourid); } return $link; }
php
public static function get_edit_step_link($tourid, $stepid = null, $targettype = null) { $link = new \moodle_url('/admin/tool/usertours/configure.php'); if ($stepid) { $link->param('action', manager::ACTION_EDITSTEP); $link->param('id', $stepid); } else { $link->param('action', manager::ACTION_NEWSTEP); $link->param('tourid', $tourid); } return $link; }
[ "public", "static", "function", "get_edit_step_link", "(", "$", "tourid", ",", "$", "stepid", "=", "null", ",", "$", "targettype", "=", "null", ")", "{", "$", "link", "=", "new", "\\", "moodle_url", "(", "'/admin/tool/usertours/configure.php'", ")", ";", "if", "(", "$", "stepid", ")", "{", "$", "link", "->", "param", "(", "'action'", ",", "manager", "::", "ACTION_EDITSTEP", ")", ";", "$", "link", "->", "param", "(", "'id'", ",", "$", "stepid", ")", ";", "}", "else", "{", "$", "link", "->", "param", "(", "'action'", ",", "manager", "::", "ACTION_NEWSTEP", ")", ";", "$", "link", "->", "param", "(", "'tourid'", ",", "$", "tourid", ")", ";", "}", "return", "$", "link", ";", "}" ]
Get the link to edit the step. If no stepid is specified, then a link to create a new step is provided. The $targettype must be specified in this case. @param int $tourid The tour that the step belongs to. @param int $stepid The step ID. @param int $targettype The type of step. @return moodle_url
[ "Get", "the", "link", "to", "edit", "the", "step", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L63-L75
215,483
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.get_move_tour_link
public static function get_move_tour_link($tourid, $direction = self::MOVE_DOWN) { $link = new \moodle_url('/admin/tool/usertours/configure.php'); $link->param('action', manager::ACTION_MOVETOUR); $link->param('id', $tourid); $link->param('direction', $direction); $link->param('sesskey', sesskey()); return $link; }
php
public static function get_move_tour_link($tourid, $direction = self::MOVE_DOWN) { $link = new \moodle_url('/admin/tool/usertours/configure.php'); $link->param('action', manager::ACTION_MOVETOUR); $link->param('id', $tourid); $link->param('direction', $direction); $link->param('sesskey', sesskey()); return $link; }
[ "public", "static", "function", "get_move_tour_link", "(", "$", "tourid", ",", "$", "direction", "=", "self", "::", "MOVE_DOWN", ")", "{", "$", "link", "=", "new", "\\", "moodle_url", "(", "'/admin/tool/usertours/configure.php'", ")", ";", "$", "link", "->", "param", "(", "'action'", ",", "manager", "::", "ACTION_MOVETOUR", ")", ";", "$", "link", "->", "param", "(", "'id'", ",", "$", "tourid", ")", ";", "$", "link", "->", "param", "(", "'direction'", ",", "$", "direction", ")", ";", "$", "link", "->", "param", "(", "'sesskey'", ",", "sesskey", "(", ")", ")", ";", "return", "$", "link", ";", "}" ]
Get the link to move the tour. @param int $tourid The tour ID. @param int $direction The direction to move in @return moodle_url
[ "Get", "the", "link", "to", "move", "the", "tour", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L85-L94
215,484
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.get_move_step_link
public static function get_move_step_link($stepid, $direction = self::MOVE_DOWN) { $link = new \moodle_url('/admin/tool/usertours/configure.php'); $link->param('action', manager::ACTION_MOVESTEP); $link->param('id', $stepid); $link->param('direction', $direction); $link->param('sesskey', sesskey()); return $link; }
php
public static function get_move_step_link($stepid, $direction = self::MOVE_DOWN) { $link = new \moodle_url('/admin/tool/usertours/configure.php'); $link->param('action', manager::ACTION_MOVESTEP); $link->param('id', $stepid); $link->param('direction', $direction); $link->param('sesskey', sesskey()); return $link; }
[ "public", "static", "function", "get_move_step_link", "(", "$", "stepid", ",", "$", "direction", "=", "self", "::", "MOVE_DOWN", ")", "{", "$", "link", "=", "new", "\\", "moodle_url", "(", "'/admin/tool/usertours/configure.php'", ")", ";", "$", "link", "->", "param", "(", "'action'", ",", "manager", "::", "ACTION_MOVESTEP", ")", ";", "$", "link", "->", "param", "(", "'id'", ",", "$", "stepid", ")", ";", "$", "link", "->", "param", "(", "'direction'", ",", "$", "direction", ")", ";", "$", "link", "->", "param", "(", "'sesskey'", ",", "sesskey", "(", ")", ")", ";", "return", "$", "link", ";", "}" ]
Get the link to move the step. @param int $stepid The step ID. @param int $direction The direction to move in @return moodle_url
[ "Get", "the", "link", "to", "move", "the", "step", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L104-L113
215,485
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.get_new_step_link
public static function get_new_step_link($tourid, $targettype = null) { $link = new \moodle_url('/admin/tool/usertours/configure.php'); $link->param('action', manager::ACTION_NEWSTEP); $link->param('tourid', $tourid); $link->param('targettype', $targettype); return $link; }
php
public static function get_new_step_link($tourid, $targettype = null) { $link = new \moodle_url('/admin/tool/usertours/configure.php'); $link->param('action', manager::ACTION_NEWSTEP); $link->param('tourid', $tourid); $link->param('targettype', $targettype); return $link; }
[ "public", "static", "function", "get_new_step_link", "(", "$", "tourid", ",", "$", "targettype", "=", "null", ")", "{", "$", "link", "=", "new", "\\", "moodle_url", "(", "'/admin/tool/usertours/configure.php'", ")", ";", "$", "link", "->", "param", "(", "'action'", ",", "manager", "::", "ACTION_NEWSTEP", ")", ";", "$", "link", "->", "param", "(", "'tourid'", ",", "$", "tourid", ")", ";", "$", "link", "->", "param", "(", "'targettype'", ",", "$", "targettype", ")", ";", "return", "$", "link", ";", "}" ]
Get the link ot create a new step. @param int $tourid The ID of the tour to attach this step to. @param int $targettype The type of target. @return moodle_url The required URL.
[ "Get", "the", "link", "ot", "create", "a", "new", "step", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L123-L130
215,486
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.get_edit_tour_link
public static function get_edit_tour_link($tourid = null) { $link = new \moodle_url('/admin/tool/usertours/configure.php'); if ($tourid) { $link->param('action', manager::ACTION_EDITTOUR); $link->param('id', $tourid); } else { $link->param('action', manager::ACTION_NEWTOUR); } return $link; }
php
public static function get_edit_tour_link($tourid = null) { $link = new \moodle_url('/admin/tool/usertours/configure.php'); if ($tourid) { $link->param('action', manager::ACTION_EDITTOUR); $link->param('id', $tourid); } else { $link->param('action', manager::ACTION_NEWTOUR); } return $link; }
[ "public", "static", "function", "get_edit_tour_link", "(", "$", "tourid", "=", "null", ")", "{", "$", "link", "=", "new", "\\", "moodle_url", "(", "'/admin/tool/usertours/configure.php'", ")", ";", "if", "(", "$", "tourid", ")", "{", "$", "link", "->", "param", "(", "'action'", ",", "manager", "::", "ACTION_EDITTOUR", ")", ";", "$", "link", "->", "param", "(", "'id'", ",", "$", "tourid", ")", ";", "}", "else", "{", "$", "link", "->", "param", "(", "'action'", ",", "manager", "::", "ACTION_NEWTOUR", ")", ";", "}", "return", "$", "link", ";", "}" ]
Get the link used to edit the tour. @param int $tourid The ID of the tour to edit. @return moodle_url The URL.
[ "Get", "the", "link", "used", "to", "edit", "the", "tour", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L165-L176
215,487
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.format_icon_link
public static function format_icon_link($url, $icon, $alt, $iconcomponent = 'moodle', $options = array()) { global $OUTPUT; return $OUTPUT->action_icon( $url, new \pix_icon($icon, $alt, $iconcomponent, [ 'title' => $alt, ]), null, $options ); }
php
public static function format_icon_link($url, $icon, $alt, $iconcomponent = 'moodle', $options = array()) { global $OUTPUT; return $OUTPUT->action_icon( $url, new \pix_icon($icon, $alt, $iconcomponent, [ 'title' => $alt, ]), null, $options ); }
[ "public", "static", "function", "format_icon_link", "(", "$", "url", ",", "$", "icon", ",", "$", "alt", ",", "$", "iconcomponent", "=", "'moodle'", ",", "$", "options", "=", "array", "(", ")", ")", "{", "global", "$", "OUTPUT", ";", "return", "$", "OUTPUT", "->", "action_icon", "(", "$", "url", ",", "new", "\\", "pix_icon", "(", "$", "icon", ",", "$", "alt", ",", "$", "iconcomponent", ",", "[", "'title'", "=>", "$", "alt", ",", "]", ")", ",", "null", ",", "$", "options", ")", ";", "}" ]
Get a filler icon for display in the actions column of a table. @param string $url The URL for the icon. @param string $icon The icon identifier. @param string $alt The alt text for the icon. @param string $iconcomponent The icon component. @param array $options Display options. @return string
[ "Get", "a", "filler", "icon", "for", "display", "in", "the", "actions", "column", "of", "a", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L242-L254
215,488
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.render_tourname_inplace_editable
public static function render_tourname_inplace_editable(tour $tour) { return new \core\output\inplace_editable( 'tool_usertours', 'tourname', $tour->get_id(), true, \html_writer::link( $tour->get_view_link(), $tour->get_name() ), $tour->get_name() ); }
php
public static function render_tourname_inplace_editable(tour $tour) { return new \core\output\inplace_editable( 'tool_usertours', 'tourname', $tour->get_id(), true, \html_writer::link( $tour->get_view_link(), $tour->get_name() ), $tour->get_name() ); }
[ "public", "static", "function", "render_tourname_inplace_editable", "(", "tour", "$", "tour", ")", "{", "return", "new", "\\", "core", "\\", "output", "\\", "inplace_editable", "(", "'tool_usertours'", ",", "'tourname'", ",", "$", "tour", "->", "get_id", "(", ")", ",", "true", ",", "\\", "html_writer", "::", "link", "(", "$", "tour", "->", "get_view_link", "(", ")", ",", "$", "tour", "->", "get_name", "(", ")", ")", ",", "$", "tour", "->", "get_name", "(", ")", ")", ";", "}" ]
Render the inplace editable used to edit the tour name. @param tour $tour The tour to edit. @return string
[ "Render", "the", "inplace", "editable", "used", "to", "edit", "the", "tour", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L291-L303
215,489
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.render_tourdescription_inplace_editable
public static function render_tourdescription_inplace_editable(tour $tour) { return new \core\output\inplace_editable( 'tool_usertours', 'tourdescription', $tour->get_id(), true, $tour->get_description(), $tour->get_description() ); }
php
public static function render_tourdescription_inplace_editable(tour $tour) { return new \core\output\inplace_editable( 'tool_usertours', 'tourdescription', $tour->get_id(), true, $tour->get_description(), $tour->get_description() ); }
[ "public", "static", "function", "render_tourdescription_inplace_editable", "(", "tour", "$", "tour", ")", "{", "return", "new", "\\", "core", "\\", "output", "\\", "inplace_editable", "(", "'tool_usertours'", ",", "'tourdescription'", ",", "$", "tour", "->", "get_id", "(", ")", ",", "true", ",", "$", "tour", "->", "get_description", "(", ")", ",", "$", "tour", "->", "get_description", "(", ")", ")", ";", "}" ]
Render the inplace editable used to edit the tour description. @param tour $tour The tour to edit. @return string
[ "Render", "the", "inplace", "editable", "used", "to", "edit", "the", "tour", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L311-L320
215,490
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.render_tourenabled_inplace_editable
public static function render_tourenabled_inplace_editable(tour $tour) { global $OUTPUT; if ($tour->is_enabled()) { $icon = 't/hide'; $alt = get_string('disable'); $value = 1; } else { $icon = 't/show'; $alt = get_string('enable'); $value = 0; } $editable = new \core\output\inplace_editable( 'tool_usertours', 'tourenabled', $tour->get_id(), true, $OUTPUT->pix_icon($icon, $alt, 'moodle', [ 'title' => $alt, ]), $value ); $editable->set_type_toggle(); return $editable; }
php
public static function render_tourenabled_inplace_editable(tour $tour) { global $OUTPUT; if ($tour->is_enabled()) { $icon = 't/hide'; $alt = get_string('disable'); $value = 1; } else { $icon = 't/show'; $alt = get_string('enable'); $value = 0; } $editable = new \core\output\inplace_editable( 'tool_usertours', 'tourenabled', $tour->get_id(), true, $OUTPUT->pix_icon($icon, $alt, 'moodle', [ 'title' => $alt, ]), $value ); $editable->set_type_toggle(); return $editable; }
[ "public", "static", "function", "render_tourenabled_inplace_editable", "(", "tour", "$", "tour", ")", "{", "global", "$", "OUTPUT", ";", "if", "(", "$", "tour", "->", "is_enabled", "(", ")", ")", "{", "$", "icon", "=", "'t/hide'", ";", "$", "alt", "=", "get_string", "(", "'disable'", ")", ";", "$", "value", "=", "1", ";", "}", "else", "{", "$", "icon", "=", "'t/show'", ";", "$", "alt", "=", "get_string", "(", "'enable'", ")", ";", "$", "value", "=", "0", ";", "}", "$", "editable", "=", "new", "\\", "core", "\\", "output", "\\", "inplace_editable", "(", "'tool_usertours'", ",", "'tourenabled'", ",", "$", "tour", "->", "get_id", "(", ")", ",", "true", ",", "$", "OUTPUT", "->", "pix_icon", "(", "$", "icon", ",", "$", "alt", ",", "'moodle'", ",", "[", "'title'", "=>", "$", "alt", ",", "]", ")", ",", "$", "value", ")", ";", "$", "editable", "->", "set_type_toggle", "(", ")", ";", "return", "$", "editable", ";", "}" ]
Render the inplace editable used to edit the tour enable state. @param tour $tour The tour to edit. @return string
[ "Render", "the", "inplace", "editable", "used", "to", "edit", "the", "tour", "enable", "state", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L328-L354
215,491
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.render_stepname_inplace_editable
public static function render_stepname_inplace_editable(step $step) { $title = format_text(step::get_string_from_input($step->get_title()), FORMAT_HTML); return new \core\output\inplace_editable( 'tool_usertours', 'stepname', $step->get_id(), true, \html_writer::link( $step->get_edit_link(), $title ), $step->get_title() ); }
php
public static function render_stepname_inplace_editable(step $step) { $title = format_text(step::get_string_from_input($step->get_title()), FORMAT_HTML); return new \core\output\inplace_editable( 'tool_usertours', 'stepname', $step->get_id(), true, \html_writer::link( $step->get_edit_link(), $title ), $step->get_title() ); }
[ "public", "static", "function", "render_stepname_inplace_editable", "(", "step", "$", "step", ")", "{", "$", "title", "=", "format_text", "(", "step", "::", "get_string_from_input", "(", "$", "step", "->", "get_title", "(", ")", ")", ",", "FORMAT_HTML", ")", ";", "return", "new", "\\", "core", "\\", "output", "\\", "inplace_editable", "(", "'tool_usertours'", ",", "'stepname'", ",", "$", "step", "->", "get_id", "(", ")", ",", "true", ",", "\\", "html_writer", "::", "link", "(", "$", "step", "->", "get_edit_link", "(", ")", ",", "$", "title", ")", ",", "$", "step", "->", "get_title", "(", ")", ")", ";", "}" ]
Render the inplace editable used to edit the step name. @param step $step The step to edit. @return string
[ "Render", "the", "inplace", "editable", "used", "to", "edit", "the", "step", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L362-L376
215,492
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.get_tours
public static function get_tours() { global $DB; $tours = $DB->get_records('tool_usertours_tours', array(), 'sortorder ASC'); $return = []; foreach ($tours as $tour) { $return[$tour->id] = tour::load_from_record($tour); } return $return; }
php
public static function get_tours() { global $DB; $tours = $DB->get_records('tool_usertours_tours', array(), 'sortorder ASC'); $return = []; foreach ($tours as $tour) { $return[$tour->id] = tour::load_from_record($tour); } return $return; }
[ "public", "static", "function", "get_tours", "(", ")", "{", "global", "$", "DB", ";", "$", "tours", "=", "$", "DB", "->", "get_records", "(", "'tool_usertours_tours'", ",", "array", "(", ")", ",", "'sortorder ASC'", ")", ";", "$", "return", "=", "[", "]", ";", "foreach", "(", "$", "tours", "as", "$", "tour", ")", "{", "$", "return", "[", "$", "tour", "->", "id", "]", "=", "tour", "::", "load_from_record", "(", "$", "tour", ")", ";", "}", "return", "$", "return", ";", "}" ]
Get all of the tours. @return stdClass[]
[ "Get", "all", "of", "the", "tours", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L383-L392
215,493
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.get_tour_from_sortorder
public static function get_tour_from_sortorder($sortorder) { global $DB; $tour = $DB->get_record('tool_usertours_tours', array('sortorder' => $sortorder)); return tour::load_from_record($tour); }
php
public static function get_tour_from_sortorder($sortorder) { global $DB; $tour = $DB->get_record('tool_usertours_tours', array('sortorder' => $sortorder)); return tour::load_from_record($tour); }
[ "public", "static", "function", "get_tour_from_sortorder", "(", "$", "sortorder", ")", "{", "global", "$", "DB", ";", "$", "tour", "=", "$", "DB", "->", "get_record", "(", "'tool_usertours_tours'", ",", "array", "(", "'sortorder'", "=>", "$", "sortorder", ")", ")", ";", "return", "tour", "::", "load_from_record", "(", "$", "tour", ")", ";", "}" ]
Fetch the tour with the specified sortorder. @param int $sortorder The sortorder of the tour. @return tour
[ "Fetch", "the", "tour", "with", "the", "specified", "sortorder", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L410-L415
215,494
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.reset_tour_sortorder
public static function reset_tour_sortorder() { global $DB; $tours = $DB->get_records('tool_usertours_tours', null, 'sortorder ASC, pathmatch DESC', 'id, sortorder'); $index = 0; foreach ($tours as $tour) { if ($tour->sortorder != $index) { $DB->set_field('tool_usertours_tours', 'sortorder', $index, array('id' => $tour->id)); } $index++; } // Notify the cache that a tour has changed. // Tours are only stored in the cache if there are steps. // If there step count has changed for some reason, this will change the potential cache results. cache::notify_tour_change(); }
php
public static function reset_tour_sortorder() { global $DB; $tours = $DB->get_records('tool_usertours_tours', null, 'sortorder ASC, pathmatch DESC', 'id, sortorder'); $index = 0; foreach ($tours as $tour) { if ($tour->sortorder != $index) { $DB->set_field('tool_usertours_tours', 'sortorder', $index, array('id' => $tour->id)); } $index++; } // Notify the cache that a tour has changed. // Tours are only stored in the cache if there are steps. // If there step count has changed for some reason, this will change the potential cache results. cache::notify_tour_change(); }
[ "public", "static", "function", "reset_tour_sortorder", "(", ")", "{", "global", "$", "DB", ";", "$", "tours", "=", "$", "DB", "->", "get_records", "(", "'tool_usertours_tours'", ",", "null", ",", "'sortorder ASC, pathmatch DESC'", ",", "'id, sortorder'", ")", ";", "$", "index", "=", "0", ";", "foreach", "(", "$", "tours", "as", "$", "tour", ")", "{", "if", "(", "$", "tour", "->", "sortorder", "!=", "$", "index", ")", "{", "$", "DB", "->", "set_field", "(", "'tool_usertours_tours'", ",", "'sortorder'", ",", "$", "index", ",", "array", "(", "'id'", "=>", "$", "tour", "->", "id", ")", ")", ";", "}", "$", "index", "++", ";", "}", "// Notify the cache that a tour has changed.", "// Tours are only stored in the cache if there are steps.", "// If there step count has changed for some reason, this will change the potential cache results.", "cache", "::", "notify_tour_change", "(", ")", ";", "}" ]
Reset the sortorder for all tours.
[ "Reset", "the", "sortorder", "for", "all", "tours", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L431-L447
215,495
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.get_steps
public static function get_steps($tourid) { $steps = cache::get_stepdata($tourid); $return = []; foreach ($steps as $step) { $return[$step->id] = step::load_from_record($step); } return $return; }
php
public static function get_steps($tourid) { $steps = cache::get_stepdata($tourid); $return = []; foreach ($steps as $step) { $return[$step->id] = step::load_from_record($step); } return $return; }
[ "public", "static", "function", "get_steps", "(", "$", "tourid", ")", "{", "$", "steps", "=", "cache", "::", "get_stepdata", "(", "$", "tourid", ")", ";", "$", "return", "=", "[", "]", ";", "foreach", "(", "$", "steps", "as", "$", "step", ")", "{", "$", "return", "[", "$", "step", "->", "id", "]", "=", "step", "::", "load_from_record", "(", "$", "step", ")", ";", "}", "return", "$", "return", ";", "}" ]
Get all of the steps in the tour. @param int $tourid The tour that the step belongs to. @return stdClass[]
[ "Get", "all", "of", "the", "steps", "in", "the", "tour", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L456-L464
215,496
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.get_step_from_sortorder
public static function get_step_from_sortorder($tourid, $sortorder) { global $DB; $step = $DB->get_record('tool_usertours_steps', array('tourid' => $tourid, 'sortorder' => $sortorder)); return step::load_from_record($step); }
php
public static function get_step_from_sortorder($tourid, $sortorder) { global $DB; $step = $DB->get_record('tool_usertours_steps', array('tourid' => $tourid, 'sortorder' => $sortorder)); return step::load_from_record($step); }
[ "public", "static", "function", "get_step_from_sortorder", "(", "$", "tourid", ",", "$", "sortorder", ")", "{", "global", "$", "DB", ";", "$", "step", "=", "$", "DB", "->", "get_record", "(", "'tool_usertours_steps'", ",", "array", "(", "'tourid'", "=>", "$", "tourid", ",", "'sortorder'", "=>", "$", "sortorder", ")", ")", ";", "return", "step", "::", "load_from_record", "(", "$", "step", ")", ";", "}" ]
Fetch the step with the specified sortorder. @param int $tourid The tour that the step belongs to. @param int $sortorder The sortorder of the step. @return step
[ "Fetch", "the", "step", "with", "the", "specified", "sortorder", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L483-L488
215,497
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.bootstrap
public static function bootstrap() { global $PAGE; if (!isloggedin() || isguestuser()) { return; } if (in_array($PAGE->pagelayout, ['maintenance', 'print', 'redirect'])) { // Do not try to show user tours inside iframe, in maintenance mode, // when printing, or during redirects. return; } if (self::$bootstrapped) { return; } self::$bootstrapped = true; if ($tour = manager::get_current_tour()) { $PAGE->requires->js_call_amd('tool_usertours/usertours', 'init', [ $tour->get_id(), $tour->should_show_for_user(), $PAGE->context->id, ]); } }
php
public static function bootstrap() { global $PAGE; if (!isloggedin() || isguestuser()) { return; } if (in_array($PAGE->pagelayout, ['maintenance', 'print', 'redirect'])) { // Do not try to show user tours inside iframe, in maintenance mode, // when printing, or during redirects. return; } if (self::$bootstrapped) { return; } self::$bootstrapped = true; if ($tour = manager::get_current_tour()) { $PAGE->requires->js_call_amd('tool_usertours/usertours', 'init', [ $tour->get_id(), $tour->should_show_for_user(), $PAGE->context->id, ]); } }
[ "public", "static", "function", "bootstrap", "(", ")", "{", "global", "$", "PAGE", ";", "if", "(", "!", "isloggedin", "(", ")", "||", "isguestuser", "(", ")", ")", "{", "return", ";", "}", "if", "(", "in_array", "(", "$", "PAGE", "->", "pagelayout", ",", "[", "'maintenance'", ",", "'print'", ",", "'redirect'", "]", ")", ")", "{", "// Do not try to show user tours inside iframe, in maintenance mode,", "// when printing, or during redirects.", "return", ";", "}", "if", "(", "self", "::", "$", "bootstrapped", ")", "{", "return", ";", "}", "self", "::", "$", "bootstrapped", "=", "true", ";", "if", "(", "$", "tour", "=", "manager", "::", "get_current_tour", "(", ")", ")", "{", "$", "PAGE", "->", "requires", "->", "js_call_amd", "(", "'tool_usertours/usertours'", ",", "'init'", ",", "[", "$", "tour", "->", "get_id", "(", ")", ",", "$", "tour", "->", "should_show_for_user", "(", ")", ",", "$", "PAGE", "->", "context", "->", "id", ",", "]", ")", ";", "}", "}" ]
Handle addition of the tour into the current page.
[ "Handle", "addition", "of", "the", "tour", "into", "the", "current", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L493-L518
215,498
moodle/moodle
admin/tool/usertours/classes/helper.php
helper.get_all_filters
public static function get_all_filters() { $filters = \core_component::get_component_classes_in_namespace('tool_usertours', 'local\filter'); $filters = array_keys($filters); $filters = array_filter($filters, function($filterclass) { $rc = new \ReflectionClass($filterclass); return $rc->isInstantiable(); }); return $filters; }
php
public static function get_all_filters() { $filters = \core_component::get_component_classes_in_namespace('tool_usertours', 'local\filter'); $filters = array_keys($filters); $filters = array_filter($filters, function($filterclass) { $rc = new \ReflectionClass($filterclass); return $rc->isInstantiable(); }); return $filters; }
[ "public", "static", "function", "get_all_filters", "(", ")", "{", "$", "filters", "=", "\\", "core_component", "::", "get_component_classes_in_namespace", "(", "'tool_usertours'", ",", "'local\\filter'", ")", ";", "$", "filters", "=", "array_keys", "(", "$", "filters", ")", ";", "$", "filters", "=", "array_filter", "(", "$", "filters", ",", "function", "(", "$", "filterclass", ")", "{", "$", "rc", "=", "new", "\\", "ReflectionClass", "(", "$", "filterclass", ")", ";", "return", "$", "rc", "->", "isInstantiable", "(", ")", ";", "}", ")", ";", "return", "$", "filters", ";", "}" ]
Get a list of all possible filters. @return array
[ "Get", "a", "list", "of", "all", "possible", "filters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/helper.php#L536-L546
215,499
moodle/moodle
message/classes/task/migrate_message_data.php
migrate_message_data.execute
public function execute() { global $DB; $userid = $this->get_custom_data()->userid; // Get the user's preference. $hasbeenmigrated = get_user_preferences('core_message_migrate_data', false, $userid); if (!$hasbeenmigrated) { // To determine if we should update the preference. $updatepreference = true; // Get all the users the current user has received a message from. $sql = "SELECT DISTINCT(useridfrom) FROM {message} m WHERE useridto = ? UNION SELECT DISTINCT(useridfrom) FROM {message_read} m WHERE useridto = ?"; $users = $DB->get_records_sql($sql, [$userid, $userid]); // Get all the users the current user has messaged. $sql = "SELECT DISTINCT(useridto) FROM {message} m WHERE useridfrom = ? UNION SELECT DISTINCT(useridto) FROM {message_read} m WHERE useridfrom = ?"; $users = $users + $DB->get_records_sql($sql, [$userid, $userid]); if (!empty($users)) { // Loop through each user and migrate the data. foreach ($users as $otheruserid => $user) { $ids = [$userid, $otheruserid]; sort($ids); $key = implode('_', $ids); // Set the lock data. $timeout = 5; // In seconds. $locktype = 'core_message_migrate_data'; // Get an instance of the currently configured lock factory. $lockfactory = \core\lock\lock_config::get_lock_factory($locktype); // See if we can grab this lock. if ($lock = $lockfactory->get_lock($key, $timeout)) { try { $transaction = $DB->start_delegated_transaction(); $this->migrate_data($userid, $otheruserid); $transaction->allow_commit(); } catch (\Throwable $e) { throw $e; } finally { $lock->release(); } } else { // Couldn't get a lock, move on to next user but make sure we don't update user preference so // we still try again. $updatepreference = false; continue; } } } if ($updatepreference) { set_user_preference('core_message_migrate_data', true, $userid); } else { // Throwing an exception in the task will mean that it isn't removed from the queue and is tried again. throw new \moodle_exception('Task failed.'); } } }
php
public function execute() { global $DB; $userid = $this->get_custom_data()->userid; // Get the user's preference. $hasbeenmigrated = get_user_preferences('core_message_migrate_data', false, $userid); if (!$hasbeenmigrated) { // To determine if we should update the preference. $updatepreference = true; // Get all the users the current user has received a message from. $sql = "SELECT DISTINCT(useridfrom) FROM {message} m WHERE useridto = ? UNION SELECT DISTINCT(useridfrom) FROM {message_read} m WHERE useridto = ?"; $users = $DB->get_records_sql($sql, [$userid, $userid]); // Get all the users the current user has messaged. $sql = "SELECT DISTINCT(useridto) FROM {message} m WHERE useridfrom = ? UNION SELECT DISTINCT(useridto) FROM {message_read} m WHERE useridfrom = ?"; $users = $users + $DB->get_records_sql($sql, [$userid, $userid]); if (!empty($users)) { // Loop through each user and migrate the data. foreach ($users as $otheruserid => $user) { $ids = [$userid, $otheruserid]; sort($ids); $key = implode('_', $ids); // Set the lock data. $timeout = 5; // In seconds. $locktype = 'core_message_migrate_data'; // Get an instance of the currently configured lock factory. $lockfactory = \core\lock\lock_config::get_lock_factory($locktype); // See if we can grab this lock. if ($lock = $lockfactory->get_lock($key, $timeout)) { try { $transaction = $DB->start_delegated_transaction(); $this->migrate_data($userid, $otheruserid); $transaction->allow_commit(); } catch (\Throwable $e) { throw $e; } finally { $lock->release(); } } else { // Couldn't get a lock, move on to next user but make sure we don't update user preference so // we still try again. $updatepreference = false; continue; } } } if ($updatepreference) { set_user_preference('core_message_migrate_data', true, $userid); } else { // Throwing an exception in the task will mean that it isn't removed from the queue and is tried again. throw new \moodle_exception('Task failed.'); } } }
[ "public", "function", "execute", "(", ")", "{", "global", "$", "DB", ";", "$", "userid", "=", "$", "this", "->", "get_custom_data", "(", ")", "->", "userid", ";", "// Get the user's preference.", "$", "hasbeenmigrated", "=", "get_user_preferences", "(", "'core_message_migrate_data'", ",", "false", ",", "$", "userid", ")", ";", "if", "(", "!", "$", "hasbeenmigrated", ")", "{", "// To determine if we should update the preference.", "$", "updatepreference", "=", "true", ";", "// Get all the users the current user has received a message from.", "$", "sql", "=", "\"SELECT DISTINCT(useridfrom)\n FROM {message} m\n WHERE useridto = ?\n UNION\n SELECT DISTINCT(useridfrom)\n FROM {message_read} m\n WHERE useridto = ?\"", ";", "$", "users", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "[", "$", "userid", ",", "$", "userid", "]", ")", ";", "// Get all the users the current user has messaged.", "$", "sql", "=", "\"SELECT DISTINCT(useridto)\n FROM {message} m\n WHERE useridfrom = ?\n UNION\n SELECT DISTINCT(useridto)\n FROM {message_read} m\n WHERE useridfrom = ?\"", ";", "$", "users", "=", "$", "users", "+", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "[", "$", "userid", ",", "$", "userid", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "users", ")", ")", "{", "// Loop through each user and migrate the data.", "foreach", "(", "$", "users", "as", "$", "otheruserid", "=>", "$", "user", ")", "{", "$", "ids", "=", "[", "$", "userid", ",", "$", "otheruserid", "]", ";", "sort", "(", "$", "ids", ")", ";", "$", "key", "=", "implode", "(", "'_'", ",", "$", "ids", ")", ";", "// Set the lock data.", "$", "timeout", "=", "5", ";", "// In seconds.", "$", "locktype", "=", "'core_message_migrate_data'", ";", "// Get an instance of the currently configured lock factory.", "$", "lockfactory", "=", "\\", "core", "\\", "lock", "\\", "lock_config", "::", "get_lock_factory", "(", "$", "locktype", ")", ";", "// See if we can grab this lock.", "if", "(", "$", "lock", "=", "$", "lockfactory", "->", "get_lock", "(", "$", "key", ",", "$", "timeout", ")", ")", "{", "try", "{", "$", "transaction", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "$", "this", "->", "migrate_data", "(", "$", "userid", ",", "$", "otheruserid", ")", ";", "$", "transaction", "->", "allow_commit", "(", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "throw", "$", "e", ";", "}", "finally", "{", "$", "lock", "->", "release", "(", ")", ";", "}", "}", "else", "{", "// Couldn't get a lock, move on to next user but make sure we don't update user preference so", "// we still try again.", "$", "updatepreference", "=", "false", ";", "continue", ";", "}", "}", "}", "if", "(", "$", "updatepreference", ")", "{", "set_user_preference", "(", "'core_message_migrate_data'", ",", "true", ",", "$", "userid", ")", ";", "}", "else", "{", "// Throwing an exception in the task will mean that it isn't removed from the queue and is tried again.", "throw", "new", "\\", "moodle_exception", "(", "'Task failed.'", ")", ";", "}", "}", "}" ]
Run the migration task.
[ "Run", "the", "migration", "task", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/task/migrate_message_data.php#L41-L113