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
211,800
moodle/moodle
mod/forum/locallib.php
forum_portfolio_caller.prepare_post_leap2a
private function prepare_post_leap2a(portfolio_format_leap2a_writer $leapwriter, $post, $posthtml) { $entry = new portfolio_format_leap2a_entry('forumpost' . $post->id, $post->subject, 'resource', $posthtml); $entry->published = $post->created; $entry->updated = $post->modified; $entry->author = $post->author; if (is_array($this->keyedfiles) && array_key_exists($post->id, $this->keyedfiles) && is_array($this->keyedfiles[$post->id])) { $leapwriter->link_files($entry, $this->keyedfiles[$post->id], 'forumpost' . $post->id . 'attachment'); } $entry->add_category('web', 'resource_type'); $leapwriter->add_entry($entry); return $entry->id; }
php
private function prepare_post_leap2a(portfolio_format_leap2a_writer $leapwriter, $post, $posthtml) { $entry = new portfolio_format_leap2a_entry('forumpost' . $post->id, $post->subject, 'resource', $posthtml); $entry->published = $post->created; $entry->updated = $post->modified; $entry->author = $post->author; if (is_array($this->keyedfiles) && array_key_exists($post->id, $this->keyedfiles) && is_array($this->keyedfiles[$post->id])) { $leapwriter->link_files($entry, $this->keyedfiles[$post->id], 'forumpost' . $post->id . 'attachment'); } $entry->add_category('web', 'resource_type'); $leapwriter->add_entry($entry); return $entry->id; }
[ "private", "function", "prepare_post_leap2a", "(", "portfolio_format_leap2a_writer", "$", "leapwriter", ",", "$", "post", ",", "$", "posthtml", ")", "{", "$", "entry", "=", "new", "portfolio_format_leap2a_entry", "(", "'forumpost'", ".", "$", "post", "->", "id", ",", "$", "post", "->", "subject", ",", "'resource'", ",", "$", "posthtml", ")", ";", "$", "entry", "->", "published", "=", "$", "post", "->", "created", ";", "$", "entry", "->", "updated", "=", "$", "post", "->", "modified", ";", "$", "entry", "->", "author", "=", "$", "post", "->", "author", ";", "if", "(", "is_array", "(", "$", "this", "->", "keyedfiles", ")", "&&", "array_key_exists", "(", "$", "post", "->", "id", ",", "$", "this", "->", "keyedfiles", ")", "&&", "is_array", "(", "$", "this", "->", "keyedfiles", "[", "$", "post", "->", "id", "]", ")", ")", "{", "$", "leapwriter", "->", "link_files", "(", "$", "entry", ",", "$", "this", "->", "keyedfiles", "[", "$", "post", "->", "id", "]", ",", "'forumpost'", ".", "$", "post", "->", "id", ".", "'attachment'", ")", ";", "}", "$", "entry", "->", "add_category", "(", "'web'", ",", "'resource_type'", ")", ";", "$", "leapwriter", "->", "add_entry", "(", "$", "entry", ")", ";", "return", "$", "entry", "->", "id", ";", "}" ]
helper function to add a leap2a entry element that corresponds to a single forum post, including any attachments the entry/ies are added directly to the leapwriter, which is passed by ref @param portfolio_format_leap2a_writer $leapwriter writer object to add entries to @param object $post the stdclass object representing the database record @param string $posthtml the content of the post (prepared by {@link prepare_post} @return int id of new entry
[ "helper", "function", "to", "add", "a", "leap2a", "entry", "element", "that", "corresponds", "to", "a", "single", "forum", "post", "including", "any", "attachments" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/locallib.php#L256-L267
211,801
moodle/moodle
mod/forum/locallib.php
forum_portfolio_caller.prepare_post
private function prepare_post($post, $fileoutputextras=null) { global $DB; static $users; if (empty($users)) { $users = array($this->user->id => $this->user); } if (!array_key_exists($post->userid, $users)) { $users[$post->userid] = $DB->get_record('user', array('id' => $post->userid)); } // add the user object on to the post so we can pass it to the leap writer if necessary $post->author = $users[$post->userid]; $viewfullnames = true; // format the post body $options = portfolio_format_text_options(); $format = $this->get('exporter')->get('format'); $formattedtext = format_text($post->message, $post->messageformat, $options, $this->get('course')->id); $formattedtext = portfolio_rewrite_pluginfile_urls($formattedtext, $this->modcontext->id, 'mod_forum', 'post', $post->id, $format); $output = '<table border="0" cellpadding="3" cellspacing="0" class="forumpost">'; $output .= '<tr class="header"><td>';// can't print picture. $output .= '</td>'; if ($post->parent) { $output .= '<td class="topic">'; } else { $output .= '<td class="topic starter">'; } $output .= '<div class="subject">'.format_string($post->subject).'</div>'; $fullname = fullname($users[$post->userid], $viewfullnames); $by = new stdClass(); $by->name = $fullname; $by->date = userdate($post->modified, '', core_date::get_user_timezone($this->user)); $output .= '<div class="author">'.get_string('bynameondate', 'forum', $by).'</div>'; $output .= '</td></tr>'; $output .= '<tr><td class="left side" valign="top">'; $output .= '</td><td class="content">'; $output .= $formattedtext; if (is_array($this->keyedfiles) && array_key_exists($post->id, $this->keyedfiles) && is_array($this->keyedfiles[$post->id]) && count($this->keyedfiles[$post->id]) > 0) { $output .= '<div class="attachments">'; $output .= '<br /><b>' . get_string('attachments', 'forum') . '</b>:<br /><br />'; foreach ($this->keyedfiles[$post->id] as $file) { $output .= $format->file_output($file) . '<br/ >'; } $output .= "</div>"; } $output .= '</td></tr></table>'."\n\n"; return $output; }
php
private function prepare_post($post, $fileoutputextras=null) { global $DB; static $users; if (empty($users)) { $users = array($this->user->id => $this->user); } if (!array_key_exists($post->userid, $users)) { $users[$post->userid] = $DB->get_record('user', array('id' => $post->userid)); } // add the user object on to the post so we can pass it to the leap writer if necessary $post->author = $users[$post->userid]; $viewfullnames = true; // format the post body $options = portfolio_format_text_options(); $format = $this->get('exporter')->get('format'); $formattedtext = format_text($post->message, $post->messageformat, $options, $this->get('course')->id); $formattedtext = portfolio_rewrite_pluginfile_urls($formattedtext, $this->modcontext->id, 'mod_forum', 'post', $post->id, $format); $output = '<table border="0" cellpadding="3" cellspacing="0" class="forumpost">'; $output .= '<tr class="header"><td>';// can't print picture. $output .= '</td>'; if ($post->parent) { $output .= '<td class="topic">'; } else { $output .= '<td class="topic starter">'; } $output .= '<div class="subject">'.format_string($post->subject).'</div>'; $fullname = fullname($users[$post->userid], $viewfullnames); $by = new stdClass(); $by->name = $fullname; $by->date = userdate($post->modified, '', core_date::get_user_timezone($this->user)); $output .= '<div class="author">'.get_string('bynameondate', 'forum', $by).'</div>'; $output .= '</td></tr>'; $output .= '<tr><td class="left side" valign="top">'; $output .= '</td><td class="content">'; $output .= $formattedtext; if (is_array($this->keyedfiles) && array_key_exists($post->id, $this->keyedfiles) && is_array($this->keyedfiles[$post->id]) && count($this->keyedfiles[$post->id]) > 0) { $output .= '<div class="attachments">'; $output .= '<br /><b>' . get_string('attachments', 'forum') . '</b>:<br /><br />'; foreach ($this->keyedfiles[$post->id] as $file) { $output .= $format->file_output($file) . '<br/ >'; } $output .= "</div>"; } $output .= '</td></tr></table>'."\n\n"; return $output; }
[ "private", "function", "prepare_post", "(", "$", "post", ",", "$", "fileoutputextras", "=", "null", ")", "{", "global", "$", "DB", ";", "static", "$", "users", ";", "if", "(", "empty", "(", "$", "users", ")", ")", "{", "$", "users", "=", "array", "(", "$", "this", "->", "user", "->", "id", "=>", "$", "this", "->", "user", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "post", "->", "userid", ",", "$", "users", ")", ")", "{", "$", "users", "[", "$", "post", "->", "userid", "]", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "post", "->", "userid", ")", ")", ";", "}", "// add the user object on to the post so we can pass it to the leap writer if necessary", "$", "post", "->", "author", "=", "$", "users", "[", "$", "post", "->", "userid", "]", ";", "$", "viewfullnames", "=", "true", ";", "// format the post body", "$", "options", "=", "portfolio_format_text_options", "(", ")", ";", "$", "format", "=", "$", "this", "->", "get", "(", "'exporter'", ")", "->", "get", "(", "'format'", ")", ";", "$", "formattedtext", "=", "format_text", "(", "$", "post", "->", "message", ",", "$", "post", "->", "messageformat", ",", "$", "options", ",", "$", "this", "->", "get", "(", "'course'", ")", "->", "id", ")", ";", "$", "formattedtext", "=", "portfolio_rewrite_pluginfile_urls", "(", "$", "formattedtext", ",", "$", "this", "->", "modcontext", "->", "id", ",", "'mod_forum'", ",", "'post'", ",", "$", "post", "->", "id", ",", "$", "format", ")", ";", "$", "output", "=", "'<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" class=\"forumpost\">'", ";", "$", "output", ".=", "'<tr class=\"header\"><td>'", ";", "// can't print picture.", "$", "output", ".=", "'</td>'", ";", "if", "(", "$", "post", "->", "parent", ")", "{", "$", "output", ".=", "'<td class=\"topic\">'", ";", "}", "else", "{", "$", "output", ".=", "'<td class=\"topic starter\">'", ";", "}", "$", "output", ".=", "'<div class=\"subject\">'", ".", "format_string", "(", "$", "post", "->", "subject", ")", ".", "'</div>'", ";", "$", "fullname", "=", "fullname", "(", "$", "users", "[", "$", "post", "->", "userid", "]", ",", "$", "viewfullnames", ")", ";", "$", "by", "=", "new", "stdClass", "(", ")", ";", "$", "by", "->", "name", "=", "$", "fullname", ";", "$", "by", "->", "date", "=", "userdate", "(", "$", "post", "->", "modified", ",", "''", ",", "core_date", "::", "get_user_timezone", "(", "$", "this", "->", "user", ")", ")", ";", "$", "output", ".=", "'<div class=\"author\">'", ".", "get_string", "(", "'bynameondate'", ",", "'forum'", ",", "$", "by", ")", ".", "'</div>'", ";", "$", "output", ".=", "'</td></tr>'", ";", "$", "output", ".=", "'<tr><td class=\"left side\" valign=\"top\">'", ";", "$", "output", ".=", "'</td><td class=\"content\">'", ";", "$", "output", ".=", "$", "formattedtext", ";", "if", "(", "is_array", "(", "$", "this", "->", "keyedfiles", ")", "&&", "array_key_exists", "(", "$", "post", "->", "id", ",", "$", "this", "->", "keyedfiles", ")", "&&", "is_array", "(", "$", "this", "->", "keyedfiles", "[", "$", "post", "->", "id", "]", ")", "&&", "count", "(", "$", "this", "->", "keyedfiles", "[", "$", "post", "->", "id", "]", ")", ">", "0", ")", "{", "$", "output", ".=", "'<div class=\"attachments\">'", ";", "$", "output", ".=", "'<br /><b>'", ".", "get_string", "(", "'attachments'", ",", "'forum'", ")", ".", "'</b>:<br /><br />'", ";", "foreach", "(", "$", "this", "->", "keyedfiles", "[", "$", "post", "->", "id", "]", "as", "$", "file", ")", "{", "$", "output", ".=", "$", "format", "->", "file_output", "(", "$", "file", ")", ".", "'<br/ >'", ";", "}", "$", "output", ".=", "\"</div>\"", ";", "}", "$", "output", ".=", "'</td></tr></table>'", ".", "\"\\n\\n\"", ";", "return", "$", "output", ";", "}" ]
this is a very cut down version of what is in forum_make_mail_post @global object @param int $post @return string
[ "this", "is", "a", "very", "cut", "down", "version", "of", "what", "is", "in", "forum_make_mail_post" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/locallib.php#L295-L351
211,802
moodle/moodle
auth/nologin/auth.php
auth_plugin_nologin.get_password_change_info
public function get_password_change_info(stdClass $user) : array { $site = get_site(); $data = new stdClass(); $data->firstname = $user->firstname; $data->lastname = $user->lastname; $data->username = $user->username; $data->sitename = format_string($site->fullname); $data->admin = generate_email_signoff(); $message = get_string('emailpasswordchangeinfodisabled', '', $data); $subject = get_string('emailpasswordchangeinfosubject', '', format_string($site->fullname)); return [ 'subject' => $subject, 'message' => $message ]; }
php
public function get_password_change_info(stdClass $user) : array { $site = get_site(); $data = new stdClass(); $data->firstname = $user->firstname; $data->lastname = $user->lastname; $data->username = $user->username; $data->sitename = format_string($site->fullname); $data->admin = generate_email_signoff(); $message = get_string('emailpasswordchangeinfodisabled', '', $data); $subject = get_string('emailpasswordchangeinfosubject', '', format_string($site->fullname)); return [ 'subject' => $subject, 'message' => $message ]; }
[ "public", "function", "get_password_change_info", "(", "stdClass", "$", "user", ")", ":", "array", "{", "$", "site", "=", "get_site", "(", ")", ";", "$", "data", "=", "new", "stdClass", "(", ")", ";", "$", "data", "->", "firstname", "=", "$", "user", "->", "firstname", ";", "$", "data", "->", "lastname", "=", "$", "user", "->", "lastname", ";", "$", "data", "->", "username", "=", "$", "user", "->", "username", ";", "$", "data", "->", "sitename", "=", "format_string", "(", "$", "site", "->", "fullname", ")", ";", "$", "data", "->", "admin", "=", "generate_email_signoff", "(", ")", ";", "$", "message", "=", "get_string", "(", "'emailpasswordchangeinfodisabled'", ",", "''", ",", "$", "data", ")", ";", "$", "subject", "=", "get_string", "(", "'emailpasswordchangeinfosubject'", ",", "''", ",", "format_string", "(", "$", "site", "->", "fullname", ")", ")", ";", "return", "[", "'subject'", "=>", "$", "subject", ",", "'message'", "=>", "$", "message", "]", ";", "}" ]
Returns information on how the specified user can change their password. User accounts with authentication type set to nologin are disabled accounts. They cannot change their password. @param stdClass $user A user object @return string[] An array of strings with keys subject and message
[ "Returns", "information", "on", "how", "the", "specified", "user", "can", "change", "their", "password", ".", "User", "accounts", "with", "authentication", "type", "set", "to", "nologin", "are", "disabled", "accounts", ".", "They", "cannot", "change", "their", "password", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/nologin/auth.php#L115-L132
211,803
moodle/moodle
availability/classes/tree.php
tree.get_logic_flags
public function get_logic_flags($not) { // Work out which type of logic to use for the group. switch($this->op) { case self::OP_AND: case self::OP_OR: $negative = false; break; case self::OP_NOT_AND: case self::OP_NOT_OR: $negative = true; break; default: throw new \coding_exception('Unknown operator'); } switch($this->op) { case self::OP_AND: case self::OP_NOT_AND: $andoperator = true; break; case self::OP_OR: case self::OP_NOT_OR: $andoperator = false; break; default: throw new \coding_exception('Unknown operator'); } // Select NOT (or not) for children. It flips if this is a 'not' group. $innernot = $negative ? !$not : $not; // Select operator to use for this group. If flips for negative, because: // NOT (a AND b) = (NOT a) OR (NOT b) // NOT (a OR b) = (NOT a) AND (NOT b). if ($innernot) { $andoperator = !$andoperator; } return array($innernot, $andoperator); }
php
public function get_logic_flags($not) { // Work out which type of logic to use for the group. switch($this->op) { case self::OP_AND: case self::OP_OR: $negative = false; break; case self::OP_NOT_AND: case self::OP_NOT_OR: $negative = true; break; default: throw new \coding_exception('Unknown operator'); } switch($this->op) { case self::OP_AND: case self::OP_NOT_AND: $andoperator = true; break; case self::OP_OR: case self::OP_NOT_OR: $andoperator = false; break; default: throw new \coding_exception('Unknown operator'); } // Select NOT (or not) for children. It flips if this is a 'not' group. $innernot = $negative ? !$not : $not; // Select operator to use for this group. If flips for negative, because: // NOT (a AND b) = (NOT a) OR (NOT b) // NOT (a OR b) = (NOT a) AND (NOT b). if ($innernot) { $andoperator = !$andoperator; } return array($innernot, $andoperator); }
[ "public", "function", "get_logic_flags", "(", "$", "not", ")", "{", "// Work out which type of logic to use for the group.", "switch", "(", "$", "this", "->", "op", ")", "{", "case", "self", "::", "OP_AND", ":", "case", "self", "::", "OP_OR", ":", "$", "negative", "=", "false", ";", "break", ";", "case", "self", "::", "OP_NOT_AND", ":", "case", "self", "::", "OP_NOT_OR", ":", "$", "negative", "=", "true", ";", "break", ";", "default", ":", "throw", "new", "\\", "coding_exception", "(", "'Unknown operator'", ")", ";", "}", "switch", "(", "$", "this", "->", "op", ")", "{", "case", "self", "::", "OP_AND", ":", "case", "self", "::", "OP_NOT_AND", ":", "$", "andoperator", "=", "true", ";", "break", ";", "case", "self", "::", "OP_OR", ":", "case", "self", "::", "OP_NOT_OR", ":", "$", "andoperator", "=", "false", ";", "break", ";", "default", ":", "throw", "new", "\\", "coding_exception", "(", "'Unknown operator'", ")", ";", "}", "// Select NOT (or not) for children. It flips if this is a 'not' group.", "$", "innernot", "=", "$", "negative", "?", "!", "$", "not", ":", "$", "not", ";", "// Select operator to use for this group. If flips for negative, because:", "// NOT (a AND b) = (NOT a) OR (NOT b)", "// NOT (a OR b) = (NOT a) AND (NOT b).", "if", "(", "$", "innernot", ")", "{", "$", "andoperator", "=", "!", "$", "andoperator", ";", "}", "return", "array", "(", "$", "innernot", ",", "$", "andoperator", ")", ";", "}" ]
Converts the operator for the tree into two flags used for computing the result. The 2 flags are $innernot (whether to set $not when calling for children) and $andoperator (whether to use AND or OR operator to combine children). @param bool $not Not flag passed to this tree @return array Array of the 2 flags ($innernot, $andoperator)
[ "Converts", "the", "operator", "for", "the", "tree", "into", "two", "flags", "used", "for", "computing", "the", "result", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/classes/tree.php#L579-L616
211,804
moodle/moodle
availability/classes/tree.php
tree.recursive_get_all_children
protected function recursive_get_all_children($classname, array &$result) { foreach ($this->children as $child) { if (is_a($child, $classname)) { $result[] = $child; } if ($child instanceof tree) { $child->recursive_get_all_children($classname, $result); } } }
php
protected function recursive_get_all_children($classname, array &$result) { foreach ($this->children as $child) { if (is_a($child, $classname)) { $result[] = $child; } if ($child instanceof tree) { $child->recursive_get_all_children($classname, $result); } } }
[ "protected", "function", "recursive_get_all_children", "(", "$", "classname", ",", "array", "&", "$", "result", ")", "{", "foreach", "(", "$", "this", "->", "children", "as", "$", "child", ")", "{", "if", "(", "is_a", "(", "$", "child", ",", "$", "classname", ")", ")", "{", "$", "result", "[", "]", "=", "$", "child", ";", "}", "if", "(", "$", "child", "instanceof", "tree", ")", "{", "$", "child", "->", "recursive_get_all_children", "(", "$", "classname", ",", "$", "result", ")", ";", "}", "}", "}" ]
Internal function that implements get_all_children efficiently. @param string $classname Full class name e.g. core_availability\condition @param array $result Output array of nodes
[ "Internal", "function", "that", "implements", "get_all_children", "efficiently", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/classes/tree.php#L664-L673
211,805
moodle/moodle
availability/classes/tree.php
tree.get_nested_json
public static function get_nested_json(array $children, $op = self::OP_AND) { // Check $op and work out its type. switch($op) { case self::OP_AND: case self::OP_NOT_OR: case self::OP_OR: case self::OP_NOT_AND: break; default: throw new \coding_exception('Invalid $op'); } // Do simple tree. $result = new \stdClass(); $result->op = $op; $result->c = $children; return $result; }
php
public static function get_nested_json(array $children, $op = self::OP_AND) { // Check $op and work out its type. switch($op) { case self::OP_AND: case self::OP_NOT_OR: case self::OP_OR: case self::OP_NOT_AND: break; default: throw new \coding_exception('Invalid $op'); } // Do simple tree. $result = new \stdClass(); $result->op = $op; $result->c = $children; return $result; }
[ "public", "static", "function", "get_nested_json", "(", "array", "$", "children", ",", "$", "op", "=", "self", "::", "OP_AND", ")", "{", "// Check $op and work out its type.", "switch", "(", "$", "op", ")", "{", "case", "self", "::", "OP_AND", ":", "case", "self", "::", "OP_NOT_OR", ":", "case", "self", "::", "OP_OR", ":", "case", "self", "::", "OP_NOT_AND", ":", "break", ";", "default", ":", "throw", "new", "\\", "coding_exception", "(", "'Invalid $op'", ")", ";", "}", "// Do simple tree.", "$", "result", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "result", "->", "op", "=", "$", "op", ";", "$", "result", "->", "c", "=", "$", "children", ";", "return", "$", "result", ";", "}" ]
Returns a JSON object which corresponds to a tree. Intended for unit testing, as normally the JSON values are constructed by JavaScript code. This function generates 'nested' (i.e. not root-level) trees. @param array $children Array of JSON objects from component children @param string $op Operator (tree::OP_xx) @return stdClass JSON object @throws coding_exception If you get parameters wrong
[ "Returns", "a", "JSON", "object", "which", "corresponds", "to", "a", "tree", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/classes/tree.php#L716-L734
211,806
moodle/moodle
availability/classes/tree.php
tree.get_root_json
public static function get_root_json(array $children, $op = self::OP_AND, $show = true) { // Get the basic object. $result = self::get_nested_json($children, $op); // Check $op type. switch($op) { case self::OP_AND: case self::OP_NOT_OR: $multishow = true; break; case self::OP_OR: case self::OP_NOT_AND: $multishow = false; break; } // Add show options depending on operator. if ($multishow) { if (is_bool($show)) { $result->showc = array_pad(array(), count($result->c), $show); } else if (is_array($show)) { // The JSON will break if anything isn't an actual bool, so check. foreach ($show as $item) { if (!is_bool($item)) { throw new \coding_exception('$show array members must be bool'); } } // Check the size matches. if (count($show) != count($result->c)) { throw new \coding_exception('$show array size does not match $children'); } $result->showc = $show; } else { throw new \coding_exception('$show must be bool or array'); } } else { if (!is_bool($show)) { throw new \coding_exception('For this operator, $show must be bool'); } $result->show = $show; } return $result; }
php
public static function get_root_json(array $children, $op = self::OP_AND, $show = true) { // Get the basic object. $result = self::get_nested_json($children, $op); // Check $op type. switch($op) { case self::OP_AND: case self::OP_NOT_OR: $multishow = true; break; case self::OP_OR: case self::OP_NOT_AND: $multishow = false; break; } // Add show options depending on operator. if ($multishow) { if (is_bool($show)) { $result->showc = array_pad(array(), count($result->c), $show); } else if (is_array($show)) { // The JSON will break if anything isn't an actual bool, so check. foreach ($show as $item) { if (!is_bool($item)) { throw new \coding_exception('$show array members must be bool'); } } // Check the size matches. if (count($show) != count($result->c)) { throw new \coding_exception('$show array size does not match $children'); } $result->showc = $show; } else { throw new \coding_exception('$show must be bool or array'); } } else { if (!is_bool($show)) { throw new \coding_exception('For this operator, $show must be bool'); } $result->show = $show; } return $result; }
[ "public", "static", "function", "get_root_json", "(", "array", "$", "children", ",", "$", "op", "=", "self", "::", "OP_AND", ",", "$", "show", "=", "true", ")", "{", "// Get the basic object.", "$", "result", "=", "self", "::", "get_nested_json", "(", "$", "children", ",", "$", "op", ")", ";", "// Check $op type.", "switch", "(", "$", "op", ")", "{", "case", "self", "::", "OP_AND", ":", "case", "self", "::", "OP_NOT_OR", ":", "$", "multishow", "=", "true", ";", "break", ";", "case", "self", "::", "OP_OR", ":", "case", "self", "::", "OP_NOT_AND", ":", "$", "multishow", "=", "false", ";", "break", ";", "}", "// Add show options depending on operator.", "if", "(", "$", "multishow", ")", "{", "if", "(", "is_bool", "(", "$", "show", ")", ")", "{", "$", "result", "->", "showc", "=", "array_pad", "(", "array", "(", ")", ",", "count", "(", "$", "result", "->", "c", ")", ",", "$", "show", ")", ";", "}", "else", "if", "(", "is_array", "(", "$", "show", ")", ")", "{", "// The JSON will break if anything isn't an actual bool, so check.", "foreach", "(", "$", "show", "as", "$", "item", ")", "{", "if", "(", "!", "is_bool", "(", "$", "item", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'$show array members must be bool'", ")", ";", "}", "}", "// Check the size matches.", "if", "(", "count", "(", "$", "show", ")", "!=", "count", "(", "$", "result", "->", "c", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'$show array size does not match $children'", ")", ";", "}", "$", "result", "->", "showc", "=", "$", "show", ";", "}", "else", "{", "throw", "new", "\\", "coding_exception", "(", "'$show must be bool or array'", ")", ";", "}", "}", "else", "{", "if", "(", "!", "is_bool", "(", "$", "show", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'For this operator, $show must be bool'", ")", ";", "}", "$", "result", "->", "show", "=", "$", "show", ";", "}", "return", "$", "result", ";", "}" ]
Returns a JSON object which corresponds to a tree at root level. Intended for unit testing, as normally the JSON values are constructed by JavaScript code. The $show parameter can be a boolean for all OP_xx options. For OP_AND and OP_NOT_OR where you have individual show options, you can specify a boolean (same for all) or an array. @param array $children Array of JSON objects from component children @param string $op Operator (tree::OP_xx) @param bool|array $show Whether 'show' option is turned on (see above) @return stdClass JSON object ready for encoding @throws coding_exception If you get parameters wrong
[ "Returns", "a", "JSON", "object", "which", "corresponds", "to", "a", "tree", "at", "root", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/classes/tree.php#L752-L796
211,807
moodle/moodle
cache/stores/mongodb/MongoDB/Operation/ListIndexes.php
ListIndexes.executeCommand
private function executeCommand(Server $server) { $cmd = ['listIndexes' => $this->collectionName]; if (isset($this->options['maxTimeMS'])) { $cmd['maxTimeMS'] = $this->options['maxTimeMS']; } try { $cursor = $server->executeCommand($this->databaseName, new Command($cmd), $this->createOptions()); } catch (DriverRuntimeException $e) { /* The server may return an error if the collection does not exist. * Check for possible error codes (see: SERVER-20463) and return an * empty iterator instead of throwing. */ if ($e->getCode() === self::$errorCodeNamespaceNotFound || $e->getCode() === self::$errorCodeDatabaseNotFound) { return new IndexInfoIteratorIterator(new EmptyIterator); } throw $e; } $cursor->setTypeMap(['root' => 'array', 'document' => 'array']); return new IndexInfoIteratorIterator(new CachingIterator($cursor)); }
php
private function executeCommand(Server $server) { $cmd = ['listIndexes' => $this->collectionName]; if (isset($this->options['maxTimeMS'])) { $cmd['maxTimeMS'] = $this->options['maxTimeMS']; } try { $cursor = $server->executeCommand($this->databaseName, new Command($cmd), $this->createOptions()); } catch (DriverRuntimeException $e) { /* The server may return an error if the collection does not exist. * Check for possible error codes (see: SERVER-20463) and return an * empty iterator instead of throwing. */ if ($e->getCode() === self::$errorCodeNamespaceNotFound || $e->getCode() === self::$errorCodeDatabaseNotFound) { return new IndexInfoIteratorIterator(new EmptyIterator); } throw $e; } $cursor->setTypeMap(['root' => 'array', 'document' => 'array']); return new IndexInfoIteratorIterator(new CachingIterator($cursor)); }
[ "private", "function", "executeCommand", "(", "Server", "$", "server", ")", "{", "$", "cmd", "=", "[", "'listIndexes'", "=>", "$", "this", "->", "collectionName", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'maxTimeMS'", "]", ")", ")", "{", "$", "cmd", "[", "'maxTimeMS'", "]", "=", "$", "this", "->", "options", "[", "'maxTimeMS'", "]", ";", "}", "try", "{", "$", "cursor", "=", "$", "server", "->", "executeCommand", "(", "$", "this", "->", "databaseName", ",", "new", "Command", "(", "$", "cmd", ")", ",", "$", "this", "->", "createOptions", "(", ")", ")", ";", "}", "catch", "(", "DriverRuntimeException", "$", "e", ")", "{", "/* The server may return an error if the collection does not exist.\n * Check for possible error codes (see: SERVER-20463) and return an\n * empty iterator instead of throwing.\n */", "if", "(", "$", "e", "->", "getCode", "(", ")", "===", "self", "::", "$", "errorCodeNamespaceNotFound", "||", "$", "e", "->", "getCode", "(", ")", "===", "self", "::", "$", "errorCodeDatabaseNotFound", ")", "{", "return", "new", "IndexInfoIteratorIterator", "(", "new", "EmptyIterator", ")", ";", "}", "throw", "$", "e", ";", "}", "$", "cursor", "->", "setTypeMap", "(", "[", "'root'", "=>", "'array'", ",", "'document'", "=>", "'array'", "]", ")", ";", "return", "new", "IndexInfoIteratorIterator", "(", "new", "CachingIterator", "(", "$", "cursor", ")", ")", ";", "}" ]
Returns information for all indexes for this collection using the listIndexes command. @param Server $server @return IndexInfoIteratorIterator @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Returns", "information", "for", "all", "indexes", "for", "this", "collection", "using", "the", "listIndexes", "command", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Operation/ListIndexes.php#L120-L145
211,808
moodle/moodle
lib/outputfactories.php
renderer_factory_base.get_target_suffix
protected function get_target_suffix($target) { if (empty($target) || $target === RENDERER_TARGET_MAINTENANCE) { // If the target hasn't been specified we need to guess the defaults. // We also override the target with the default if the maintenance target has been provided. // This ensures we don't use the maintenance renderer if we are processing a special target. if (defined('PREFERRED_RENDERER_TARGET')) { $target = PREFERRED_RENDERER_TARGET; } else if (CLI_SCRIPT) { $target = RENDERER_TARGET_CLI; } else if (AJAX_SCRIPT) { $target = RENDERER_TARGET_AJAX; } } switch ($target) { case RENDERER_TARGET_CLI: $suffix = '_cli'; break; case RENDERER_TARGET_AJAX: $suffix = '_ajax'; break; case RENDERER_TARGET_TEXTEMAIL: $suffix = '_textemail'; break; case RENDERER_TARGET_HTMLEMAIL: $suffix = '_htmlemail'; break; case RENDERER_TARGET_MAINTENANCE: $suffix = '_maintenance'; break; default: $target = RENDERER_TARGET_GENERAL; $suffix = ''; } return array($target, $suffix); }
php
protected function get_target_suffix($target) { if (empty($target) || $target === RENDERER_TARGET_MAINTENANCE) { // If the target hasn't been specified we need to guess the defaults. // We also override the target with the default if the maintenance target has been provided. // This ensures we don't use the maintenance renderer if we are processing a special target. if (defined('PREFERRED_RENDERER_TARGET')) { $target = PREFERRED_RENDERER_TARGET; } else if (CLI_SCRIPT) { $target = RENDERER_TARGET_CLI; } else if (AJAX_SCRIPT) { $target = RENDERER_TARGET_AJAX; } } switch ($target) { case RENDERER_TARGET_CLI: $suffix = '_cli'; break; case RENDERER_TARGET_AJAX: $suffix = '_ajax'; break; case RENDERER_TARGET_TEXTEMAIL: $suffix = '_textemail'; break; case RENDERER_TARGET_HTMLEMAIL: $suffix = '_htmlemail'; break; case RENDERER_TARGET_MAINTENANCE: $suffix = '_maintenance'; break; default: $target = RENDERER_TARGET_GENERAL; $suffix = ''; } return array($target, $suffix); }
[ "protected", "function", "get_target_suffix", "(", "$", "target", ")", "{", "if", "(", "empty", "(", "$", "target", ")", "||", "$", "target", "===", "RENDERER_TARGET_MAINTENANCE", ")", "{", "// If the target hasn't been specified we need to guess the defaults.", "// We also override the target with the default if the maintenance target has been provided.", "// This ensures we don't use the maintenance renderer if we are processing a special target.", "if", "(", "defined", "(", "'PREFERRED_RENDERER_TARGET'", ")", ")", "{", "$", "target", "=", "PREFERRED_RENDERER_TARGET", ";", "}", "else", "if", "(", "CLI_SCRIPT", ")", "{", "$", "target", "=", "RENDERER_TARGET_CLI", ";", "}", "else", "if", "(", "AJAX_SCRIPT", ")", "{", "$", "target", "=", "RENDERER_TARGET_AJAX", ";", "}", "}", "switch", "(", "$", "target", ")", "{", "case", "RENDERER_TARGET_CLI", ":", "$", "suffix", "=", "'_cli'", ";", "break", ";", "case", "RENDERER_TARGET_AJAX", ":", "$", "suffix", "=", "'_ajax'", ";", "break", ";", "case", "RENDERER_TARGET_TEXTEMAIL", ":", "$", "suffix", "=", "'_textemail'", ";", "break", ";", "case", "RENDERER_TARGET_HTMLEMAIL", ":", "$", "suffix", "=", "'_htmlemail'", ";", "break", ";", "case", "RENDERER_TARGET_MAINTENANCE", ":", "$", "suffix", "=", "'_maintenance'", ";", "break", ";", "default", ":", "$", "target", "=", "RENDERER_TARGET_GENERAL", ";", "$", "suffix", "=", "''", ";", "}", "return", "array", "(", "$", "target", ",", "$", "suffix", ")", ";", "}" ]
Returns suffix of renderer class expected for given target. @param string $target one of the renderer target constants, target is guessed if null used @return array two element array, first element is target, second the target suffix string
[ "Returns", "suffix", "of", "renderer", "class", "expected", "for", "given", "target", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputfactories.php#L135-L159
211,809
moodle/moodle
lib/outputfactories.php
renderer_factory_base.standard_renderer_classnames
protected function standard_renderer_classnames($component, $subtype = null) { global $CFG; // Needed in included files. $classnames = array(); // Standardize component name ala frankenstyle. list($plugin, $type) = core_component::normalize_component($component); if ($type === null) { $component = $plugin; } else { $component = $plugin.'_'.$type; } if ($component !== 'core') { // Renderers are stored in renderer.php files. if (!$compdirectory = core_component::get_component_directory($component)) { throw new coding_exception('Invalid component specified in renderer request', $component); } $rendererfile = $compdirectory . '/renderer.php'; if (file_exists($rendererfile)) { include_once($rendererfile); } } else if (!empty($subtype)) { $coresubsystems = core_component::get_core_subsystems(); if (!array_key_exists($subtype, $coresubsystems)) { // There may be nulls. throw new coding_exception('Invalid core subtype "' . $subtype . '" in renderer request', $subtype); } if ($coresubsystems[$subtype]) { $rendererfile = $coresubsystems[$subtype] . '/renderer.php'; if (file_exists($rendererfile)) { include_once($rendererfile); } } } if (empty($subtype)) { // Theme specific auto-loaded name (only valid when prefixed with the theme name). $classnames[] = array( 'validwithprefix' => true, 'validwithoutprefix' => false, 'autoloaded' => true, 'classname' => '\\output\\' . $component . '_renderer' ); // Standard autoloaded plugin name (not valid with a prefix). $classnames[] = array( 'validwithprefix' => false, 'validwithoutprefix' => true, 'autoloaded' => true, 'classname' => '\\' . $component . '\\output\\renderer' ); // Legacy class name - (valid with or without a prefix). $classnames[] = array( 'validwithprefix' => true, 'validwithoutprefix' => true, 'autoloaded' => false, 'classname' => $component . '_renderer' ); } else { // Theme specific auto-loaded name (only valid when prefixed with the theme name). $classnames[] = array( 'validwithprefix' => true, 'validwithoutprefix' => false, 'autoloaded' => true, 'classname' => '\\output\\' . $component . '\\' . $subtype . '_renderer' ); // Version of the above with subtype being a namespace level on it's own. $classnames[] = array( 'validwithprefix' => true, 'validwithoutprefix' => false, 'autoloaded' => true, 'classname' => '\\output\\' . $component . '\\' . $subtype . '\\renderer' ); // Standard autoloaded plugin name (not valid with a prefix). $classnames[] = array( 'validwithprefix' => false, 'validwithoutprefix' => true, 'autoloaded' => true, 'classname' => '\\' . $component . '\\output\\' . $subtype . '_renderer' ); // Version of the above with subtype being a namespace level on it's own. $classnames[] = array( 'validwithprefix' => false, 'validwithoutprefix' => true, 'autoloaded' => true, 'classname' => '\\' . $component . '\\output\\' . $subtype . '\\renderer' ); // Legacy class name - (valid with or without a prefix). $classnames[] = array( 'validwithprefix' => true, 'validwithoutprefix' => true, 'autoloaded' => false, 'classname' => $component . '_' . $subtype . '_renderer' ); } return $classnames; }
php
protected function standard_renderer_classnames($component, $subtype = null) { global $CFG; // Needed in included files. $classnames = array(); // Standardize component name ala frankenstyle. list($plugin, $type) = core_component::normalize_component($component); if ($type === null) { $component = $plugin; } else { $component = $plugin.'_'.$type; } if ($component !== 'core') { // Renderers are stored in renderer.php files. if (!$compdirectory = core_component::get_component_directory($component)) { throw new coding_exception('Invalid component specified in renderer request', $component); } $rendererfile = $compdirectory . '/renderer.php'; if (file_exists($rendererfile)) { include_once($rendererfile); } } else if (!empty($subtype)) { $coresubsystems = core_component::get_core_subsystems(); if (!array_key_exists($subtype, $coresubsystems)) { // There may be nulls. throw new coding_exception('Invalid core subtype "' . $subtype . '" in renderer request', $subtype); } if ($coresubsystems[$subtype]) { $rendererfile = $coresubsystems[$subtype] . '/renderer.php'; if (file_exists($rendererfile)) { include_once($rendererfile); } } } if (empty($subtype)) { // Theme specific auto-loaded name (only valid when prefixed with the theme name). $classnames[] = array( 'validwithprefix' => true, 'validwithoutprefix' => false, 'autoloaded' => true, 'classname' => '\\output\\' . $component . '_renderer' ); // Standard autoloaded plugin name (not valid with a prefix). $classnames[] = array( 'validwithprefix' => false, 'validwithoutprefix' => true, 'autoloaded' => true, 'classname' => '\\' . $component . '\\output\\renderer' ); // Legacy class name - (valid with or without a prefix). $classnames[] = array( 'validwithprefix' => true, 'validwithoutprefix' => true, 'autoloaded' => false, 'classname' => $component . '_renderer' ); } else { // Theme specific auto-loaded name (only valid when prefixed with the theme name). $classnames[] = array( 'validwithprefix' => true, 'validwithoutprefix' => false, 'autoloaded' => true, 'classname' => '\\output\\' . $component . '\\' . $subtype . '_renderer' ); // Version of the above with subtype being a namespace level on it's own. $classnames[] = array( 'validwithprefix' => true, 'validwithoutprefix' => false, 'autoloaded' => true, 'classname' => '\\output\\' . $component . '\\' . $subtype . '\\renderer' ); // Standard autoloaded plugin name (not valid with a prefix). $classnames[] = array( 'validwithprefix' => false, 'validwithoutprefix' => true, 'autoloaded' => true, 'classname' => '\\' . $component . '\\output\\' . $subtype . '_renderer' ); // Version of the above with subtype being a namespace level on it's own. $classnames[] = array( 'validwithprefix' => false, 'validwithoutprefix' => true, 'autoloaded' => true, 'classname' => '\\' . $component . '\\output\\' . $subtype . '\\renderer' ); // Legacy class name - (valid with or without a prefix). $classnames[] = array( 'validwithprefix' => true, 'validwithoutprefix' => true, 'autoloaded' => false, 'classname' => $component . '_' . $subtype . '_renderer' ); } return $classnames; }
[ "protected", "function", "standard_renderer_classnames", "(", "$", "component", ",", "$", "subtype", "=", "null", ")", "{", "global", "$", "CFG", ";", "// Needed in included files.", "$", "classnames", "=", "array", "(", ")", ";", "// Standardize component name ala frankenstyle.", "list", "(", "$", "plugin", ",", "$", "type", ")", "=", "core_component", "::", "normalize_component", "(", "$", "component", ")", ";", "if", "(", "$", "type", "===", "null", ")", "{", "$", "component", "=", "$", "plugin", ";", "}", "else", "{", "$", "component", "=", "$", "plugin", ".", "'_'", ".", "$", "type", ";", "}", "if", "(", "$", "component", "!==", "'core'", ")", "{", "// Renderers are stored in renderer.php files.", "if", "(", "!", "$", "compdirectory", "=", "core_component", "::", "get_component_directory", "(", "$", "component", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid component specified in renderer request'", ",", "$", "component", ")", ";", "}", "$", "rendererfile", "=", "$", "compdirectory", ".", "'/renderer.php'", ";", "if", "(", "file_exists", "(", "$", "rendererfile", ")", ")", "{", "include_once", "(", "$", "rendererfile", ")", ";", "}", "}", "else", "if", "(", "!", "empty", "(", "$", "subtype", ")", ")", "{", "$", "coresubsystems", "=", "core_component", "::", "get_core_subsystems", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "subtype", ",", "$", "coresubsystems", ")", ")", "{", "// There may be nulls.", "throw", "new", "coding_exception", "(", "'Invalid core subtype \"'", ".", "$", "subtype", ".", "'\" in renderer request'", ",", "$", "subtype", ")", ";", "}", "if", "(", "$", "coresubsystems", "[", "$", "subtype", "]", ")", "{", "$", "rendererfile", "=", "$", "coresubsystems", "[", "$", "subtype", "]", ".", "'/renderer.php'", ";", "if", "(", "file_exists", "(", "$", "rendererfile", ")", ")", "{", "include_once", "(", "$", "rendererfile", ")", ";", "}", "}", "}", "if", "(", "empty", "(", "$", "subtype", ")", ")", "{", "// Theme specific auto-loaded name (only valid when prefixed with the theme name).", "$", "classnames", "[", "]", "=", "array", "(", "'validwithprefix'", "=>", "true", ",", "'validwithoutprefix'", "=>", "false", ",", "'autoloaded'", "=>", "true", ",", "'classname'", "=>", "'\\\\output\\\\'", ".", "$", "component", ".", "'_renderer'", ")", ";", "// Standard autoloaded plugin name (not valid with a prefix).", "$", "classnames", "[", "]", "=", "array", "(", "'validwithprefix'", "=>", "false", ",", "'validwithoutprefix'", "=>", "true", ",", "'autoloaded'", "=>", "true", ",", "'classname'", "=>", "'\\\\'", ".", "$", "component", ".", "'\\\\output\\\\renderer'", ")", ";", "// Legacy class name - (valid with or without a prefix).", "$", "classnames", "[", "]", "=", "array", "(", "'validwithprefix'", "=>", "true", ",", "'validwithoutprefix'", "=>", "true", ",", "'autoloaded'", "=>", "false", ",", "'classname'", "=>", "$", "component", ".", "'_renderer'", ")", ";", "}", "else", "{", "// Theme specific auto-loaded name (only valid when prefixed with the theme name).", "$", "classnames", "[", "]", "=", "array", "(", "'validwithprefix'", "=>", "true", ",", "'validwithoutprefix'", "=>", "false", ",", "'autoloaded'", "=>", "true", ",", "'classname'", "=>", "'\\\\output\\\\'", ".", "$", "component", ".", "'\\\\'", ".", "$", "subtype", ".", "'_renderer'", ")", ";", "// Version of the above with subtype being a namespace level on it's own.", "$", "classnames", "[", "]", "=", "array", "(", "'validwithprefix'", "=>", "true", ",", "'validwithoutprefix'", "=>", "false", ",", "'autoloaded'", "=>", "true", ",", "'classname'", "=>", "'\\\\output\\\\'", ".", "$", "component", ".", "'\\\\'", ".", "$", "subtype", ".", "'\\\\renderer'", ")", ";", "// Standard autoloaded plugin name (not valid with a prefix).", "$", "classnames", "[", "]", "=", "array", "(", "'validwithprefix'", "=>", "false", ",", "'validwithoutprefix'", "=>", "true", ",", "'autoloaded'", "=>", "true", ",", "'classname'", "=>", "'\\\\'", ".", "$", "component", ".", "'\\\\output\\\\'", ".", "$", "subtype", ".", "'_renderer'", ")", ";", "// Version of the above with subtype being a namespace level on it's own.", "$", "classnames", "[", "]", "=", "array", "(", "'validwithprefix'", "=>", "false", ",", "'validwithoutprefix'", "=>", "true", ",", "'autoloaded'", "=>", "true", ",", "'classname'", "=>", "'\\\\'", ".", "$", "component", ".", "'\\\\output\\\\'", ".", "$", "subtype", ".", "'\\\\renderer'", ")", ";", "// Legacy class name - (valid with or without a prefix).", "$", "classnames", "[", "]", "=", "array", "(", "'validwithprefix'", "=>", "true", ",", "'validwithoutprefix'", "=>", "true", ",", "'autoloaded'", "=>", "false", ",", "'classname'", "=>", "$", "component", ".", "'_'", ".", "$", "subtype", ".", "'_renderer'", ")", ";", "}", "return", "$", "classnames", ";", "}" ]
For a given module name, return the possible class names that defines the renderer interface for that module. Newer auto-loaded class names are returned as well as the old style _renderable classnames. Also, if it exists, include the renderer.php file for that module, so the class definition of the default renderer has been loaded. @param string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'. @param string $subtype optional subtype such as 'news' resulting to: '\mod_forum\output\news_renderer' or '\mod_forum\output\news\renderer' or non-autoloaded 'mod_forum_news' @return array[] Each element of the array is an array with keys: classname - The class name to search autoloaded - Does this classname assume autoloading? validwithprefix - Is this class name valid when a prefix is added to it? validwithoutprefix - Is this class name valid when no prefix is added to it? @throws coding_exception
[ "For", "a", "given", "module", "name", "return", "the", "possible", "class", "names", "that", "defines", "the", "renderer", "interface", "for", "that", "module", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputfactories.php#L182-L278
211,810
moodle/moodle
mnet/service/enrol/locallib.php
mnetservice_enrol.get_remote_subscribers
public function get_remote_subscribers() { global $DB; if (is_null($this->cachesubscribers)) { $sql = "SELECT DISTINCT h.id, h.name AS hostname, h.wwwroot AS hosturl, a.display_name AS appname FROM {mnet_host} h JOIN {mnet_host2service} hs ON h.id = hs.hostid JOIN {mnet_service} s ON hs.serviceid = s.id JOIN {mnet_application} a ON h.applicationid = a.id WHERE s.name = 'mnet_enrol' AND h.deleted = 0 AND hs.publish = 1"; $this->cachesubscribers = $DB->get_records_sql($sql); } return $this->cachesubscribers; }
php
public function get_remote_subscribers() { global $DB; if (is_null($this->cachesubscribers)) { $sql = "SELECT DISTINCT h.id, h.name AS hostname, h.wwwroot AS hosturl, a.display_name AS appname FROM {mnet_host} h JOIN {mnet_host2service} hs ON h.id = hs.hostid JOIN {mnet_service} s ON hs.serviceid = s.id JOIN {mnet_application} a ON h.applicationid = a.id WHERE s.name = 'mnet_enrol' AND h.deleted = 0 AND hs.publish = 1"; $this->cachesubscribers = $DB->get_records_sql($sql); } return $this->cachesubscribers; }
[ "public", "function", "get_remote_subscribers", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "is_null", "(", "$", "this", "->", "cachesubscribers", ")", ")", "{", "$", "sql", "=", "\"SELECT DISTINCT h.id, h.name AS hostname, h.wwwroot AS hosturl,\n a.display_name AS appname\n FROM {mnet_host} h\n JOIN {mnet_host2service} hs ON h.id = hs.hostid\n JOIN {mnet_service} s ON hs.serviceid = s.id\n JOIN {mnet_application} a ON h.applicationid = a.id\n WHERE s.name = 'mnet_enrol'\n AND h.deleted = 0\n AND hs.publish = 1\"", ";", "$", "this", "->", "cachesubscribers", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ")", ";", "}", "return", "$", "this", "->", "cachesubscribers", ";", "}" ]
Returns a list of remote servers that can enrol their users into our courses We must publish MNet service 'mnet_enrol' for the peers to allow them to enrol their users into our courses. @todo once the MNet core is refactored this may be part of a parent class @todo the name of the service should be changed to the name of this plugin @return array
[ "Returns", "a", "list", "of", "remote", "servers", "that", "can", "enrol", "their", "users", "into", "our", "courses" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mnet/service/enrol/locallib.php#L93-L110
211,811
moodle/moodle
mnet/service/enrol/locallib.php
mnetservice_enrol.get_remote_publishers
public function get_remote_publishers() { global $DB; if (is_null($this->cachepublishers)) { $sql = "SELECT DISTINCT h.id, h.name AS hostname, h.wwwroot AS hosturl, a.display_name AS appname FROM {mnet_host} h JOIN {mnet_host2service} hs ON h.id = hs.hostid JOIN {mnet_service} s ON hs.serviceid = s.id JOIN {mnet_application} a ON h.applicationid = a.id WHERE s.name = 'mnet_enrol' AND h.deleted = 0 AND hs.subscribe = 1"; $this->cachepublishers = $DB->get_records_sql($sql); } return $this->cachepublishers; }
php
public function get_remote_publishers() { global $DB; if (is_null($this->cachepublishers)) { $sql = "SELECT DISTINCT h.id, h.name AS hostname, h.wwwroot AS hosturl, a.display_name AS appname FROM {mnet_host} h JOIN {mnet_host2service} hs ON h.id = hs.hostid JOIN {mnet_service} s ON hs.serviceid = s.id JOIN {mnet_application} a ON h.applicationid = a.id WHERE s.name = 'mnet_enrol' AND h.deleted = 0 AND hs.subscribe = 1"; $this->cachepublishers = $DB->get_records_sql($sql); } return $this->cachepublishers; }
[ "public", "function", "get_remote_publishers", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "is_null", "(", "$", "this", "->", "cachepublishers", ")", ")", "{", "$", "sql", "=", "\"SELECT DISTINCT h.id, h.name AS hostname, h.wwwroot AS hosturl,\n a.display_name AS appname\n FROM {mnet_host} h\n JOIN {mnet_host2service} hs ON h.id = hs.hostid\n JOIN {mnet_service} s ON hs.serviceid = s.id\n JOIN {mnet_application} a ON h.applicationid = a.id\n WHERE s.name = 'mnet_enrol'\n AND h.deleted = 0\n AND hs.subscribe = 1\"", ";", "$", "this", "->", "cachepublishers", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ")", ";", "}", "return", "$", "this", "->", "cachepublishers", ";", "}" ]
Returns a list of remote servers that offer their courses for our users We must subscribe MNet service 'mnet_enrol' for the peers to allow our users to enrol into their courses. @todo once the MNet core is refactored this may be part of a parent class @todo the name of the service should be changed to the name of this plugin @return array
[ "Returns", "a", "list", "of", "remote", "servers", "that", "offer", "their", "courses", "for", "our", "users" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mnet/service/enrol/locallib.php#L122-L139
211,812
moodle/moodle
mnet/service/enrol/locallib.php
mnetservice_enrol.req_enrol_user
public function req_enrol_user(stdclass $user, stdclass $remotecourse) { global $CFG, $DB; require_once($CFG->dirroot.'/mnet/xmlrpc/client.php'); $peer = new mnet_peer(); $peer->set_id($remotecourse->hostid); $request = new mnet_xmlrpc_client(); $request->set_method('enrol/mnet/enrol.php/enrol_user'); $request->add_param(mnet_strip_user((array)$user, mnet_fields_to_send($peer))); $request->add_param($remotecourse->remoteid); if ($request->send($peer) === true) { if ($request->response === true) { // cache the enrolment information in our table $enrolment = new stdclass(); $enrolment->hostid = $peer->id; $enrolment->userid = $user->id; $enrolment->remotecourseid = $remotecourse->remoteid; $enrolment->enroltype = 'mnet'; // $enrolment->rolename not known now, must be re-fetched // $enrolment->enroltime not known now, must be re-fetched $DB->insert_record('mnetservice_enrol_enrolments', $enrolment); return true; } else { return serialize(array('invalid response: '.print_r($request->response, true))); } } else { return serialize($request->error); } }
php
public function req_enrol_user(stdclass $user, stdclass $remotecourse) { global $CFG, $DB; require_once($CFG->dirroot.'/mnet/xmlrpc/client.php'); $peer = new mnet_peer(); $peer->set_id($remotecourse->hostid); $request = new mnet_xmlrpc_client(); $request->set_method('enrol/mnet/enrol.php/enrol_user'); $request->add_param(mnet_strip_user((array)$user, mnet_fields_to_send($peer))); $request->add_param($remotecourse->remoteid); if ($request->send($peer) === true) { if ($request->response === true) { // cache the enrolment information in our table $enrolment = new stdclass(); $enrolment->hostid = $peer->id; $enrolment->userid = $user->id; $enrolment->remotecourseid = $remotecourse->remoteid; $enrolment->enroltype = 'mnet'; // $enrolment->rolename not known now, must be re-fetched // $enrolment->enroltime not known now, must be re-fetched $DB->insert_record('mnetservice_enrol_enrolments', $enrolment); return true; } else { return serialize(array('invalid response: '.print_r($request->response, true))); } } else { return serialize($request->error); } }
[ "public", "function", "req_enrol_user", "(", "stdclass", "$", "user", ",", "stdclass", "$", "remotecourse", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mnet/xmlrpc/client.php'", ")", ";", "$", "peer", "=", "new", "mnet_peer", "(", ")", ";", "$", "peer", "->", "set_id", "(", "$", "remotecourse", "->", "hostid", ")", ";", "$", "request", "=", "new", "mnet_xmlrpc_client", "(", ")", ";", "$", "request", "->", "set_method", "(", "'enrol/mnet/enrol.php/enrol_user'", ")", ";", "$", "request", "->", "add_param", "(", "mnet_strip_user", "(", "(", "array", ")", "$", "user", ",", "mnet_fields_to_send", "(", "$", "peer", ")", ")", ")", ";", "$", "request", "->", "add_param", "(", "$", "remotecourse", "->", "remoteid", ")", ";", "if", "(", "$", "request", "->", "send", "(", "$", "peer", ")", "===", "true", ")", "{", "if", "(", "$", "request", "->", "response", "===", "true", ")", "{", "// cache the enrolment information in our table", "$", "enrolment", "=", "new", "stdclass", "(", ")", ";", "$", "enrolment", "->", "hostid", "=", "$", "peer", "->", "id", ";", "$", "enrolment", "->", "userid", "=", "$", "user", "->", "id", ";", "$", "enrolment", "->", "remotecourseid", "=", "$", "remotecourse", "->", "remoteid", ";", "$", "enrolment", "->", "enroltype", "=", "'mnet'", ";", "// $enrolment->rolename not known now, must be re-fetched", "// $enrolment->enroltime not known now, must be re-fetched", "$", "DB", "->", "insert_record", "(", "'mnetservice_enrol_enrolments'", ",", "$", "enrolment", ")", ";", "return", "true", ";", "}", "else", "{", "return", "serialize", "(", "array", "(", "'invalid response: '", ".", "print_r", "(", "$", "request", "->", "response", ",", "true", ")", ")", ")", ";", "}", "}", "else", "{", "return", "serialize", "(", "$", "request", "->", "error", ")", ";", "}", "}" ]
Send request to enrol our user to the remote course Updates our remote enrolments cache if the enrolment was successful. @uses mnet_xmlrpc_client Invokes XML-RPC request @param object $user our user @param object $remotecourse record from mnetservice_enrol_courses table @return true|string true if success, error message from the remote host otherwise
[ "Send", "request", "to", "enrol", "our", "user", "to", "the", "remote", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mnet/service/enrol/locallib.php#L367-L399
211,813
moodle/moodle
mnet/service/enrol/locallib.php
mnetservice_enrol.req_unenrol_user
public function req_unenrol_user(stdclass $user, stdclass $remotecourse) { global $CFG, $DB; require_once($CFG->dirroot.'/mnet/xmlrpc/client.php'); $peer = new mnet_peer(); $peer->set_id($remotecourse->hostid); $request = new mnet_xmlrpc_client(); $request->set_method('enrol/mnet/enrol.php/unenrol_user'); $request->add_param($user->username); $request->add_param($remotecourse->remoteid); if ($request->send($peer) === true) { if ($request->response === true) { // clear the cached information $DB->delete_records('mnetservice_enrol_enrolments', array('hostid'=>$peer->id, 'userid'=>$user->id, 'remotecourseid'=>$remotecourse->remoteid, 'enroltype'=>'mnet')); return true; } else { return serialize(array('invalid response: '.print_r($request->response, true))); } } else { return serialize($request->error); } }
php
public function req_unenrol_user(stdclass $user, stdclass $remotecourse) { global $CFG, $DB; require_once($CFG->dirroot.'/mnet/xmlrpc/client.php'); $peer = new mnet_peer(); $peer->set_id($remotecourse->hostid); $request = new mnet_xmlrpc_client(); $request->set_method('enrol/mnet/enrol.php/unenrol_user'); $request->add_param($user->username); $request->add_param($remotecourse->remoteid); if ($request->send($peer) === true) { if ($request->response === true) { // clear the cached information $DB->delete_records('mnetservice_enrol_enrolments', array('hostid'=>$peer->id, 'userid'=>$user->id, 'remotecourseid'=>$remotecourse->remoteid, 'enroltype'=>'mnet')); return true; } else { return serialize(array('invalid response: '.print_r($request->response, true))); } } else { return serialize($request->error); } }
[ "public", "function", "req_unenrol_user", "(", "stdclass", "$", "user", ",", "stdclass", "$", "remotecourse", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mnet/xmlrpc/client.php'", ")", ";", "$", "peer", "=", "new", "mnet_peer", "(", ")", ";", "$", "peer", "->", "set_id", "(", "$", "remotecourse", "->", "hostid", ")", ";", "$", "request", "=", "new", "mnet_xmlrpc_client", "(", ")", ";", "$", "request", "->", "set_method", "(", "'enrol/mnet/enrol.php/unenrol_user'", ")", ";", "$", "request", "->", "add_param", "(", "$", "user", "->", "username", ")", ";", "$", "request", "->", "add_param", "(", "$", "remotecourse", "->", "remoteid", ")", ";", "if", "(", "$", "request", "->", "send", "(", "$", "peer", ")", "===", "true", ")", "{", "if", "(", "$", "request", "->", "response", "===", "true", ")", "{", "// clear the cached information", "$", "DB", "->", "delete_records", "(", "'mnetservice_enrol_enrolments'", ",", "array", "(", "'hostid'", "=>", "$", "peer", "->", "id", ",", "'userid'", "=>", "$", "user", "->", "id", ",", "'remotecourseid'", "=>", "$", "remotecourse", "->", "remoteid", ",", "'enroltype'", "=>", "'mnet'", ")", ")", ";", "return", "true", ";", "}", "else", "{", "return", "serialize", "(", "array", "(", "'invalid response: '", ".", "print_r", "(", "$", "request", "->", "response", ",", "true", ")", ")", ")", ";", "}", "}", "else", "{", "return", "serialize", "(", "$", "request", "->", "error", ")", ";", "}", "}" ]
Send request to unenrol our user from the remote course Updates our remote enrolments cache if the unenrolment was successful. @uses mnet_xmlrpc_client Invokes XML-RPC request @param object $user our user @param object $remotecourse record from mnetservice_enrol_courses table @return true|string true if success, error message from the remote host otherwise
[ "Send", "request", "to", "unenrol", "our", "user", "from", "the", "remote", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mnet/service/enrol/locallib.php#L411-L437
211,814
moodle/moodle
mnet/service/enrol/locallib.php
mnetservice_enrol_potential_users_selector.find_users
public function find_users($search) { global $CFG, $DB; $systemcontext = context_system::instance(); $userids = get_users_by_capability($systemcontext, 'moodle/site:mnetlogintoremote', 'u.id'); if (empty($userids)) { return array(); } list($usql, $uparams) = $DB->get_in_or_equal(array_keys($userids), SQL_PARAMS_NAMED, 'uid'); list($wherecondition, $params) = $this->search_sql($search, 'u'); $params = array_merge($params, $uparams); $params['hostid'] = $this->hostid; $params['remotecourseid'] = $this->remotecourseid; $params['mnetlocalhostid'] = $CFG->mnet_localhost_id; $fields = "SELECT ".$this->required_fields_sql("u"); $countfields = "SELECT COUNT(1)"; $sql = " FROM {user} u WHERE $wherecondition AND u.mnethostid = :mnetlocalhostid AND u.id $usql AND u.id NOT IN (SELECT e.userid FROM {mnetservice_enrol_enrolments} e WHERE (e.hostid = :hostid AND e.remotecourseid = :remotecourseid))"; list($sort, $sortparams) = users_order_by_sql('u'); $order = " ORDER BY $sort"; if (!$this->is_validating()) { $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params); if ($potentialmemberscount > 100) { return $this->too_many_results($search, $potentialmemberscount); } } $availableusers = $DB->get_records_sql($fields . $sql . $order, array_merge($params, $sortparams)); if (empty($availableusers)) { return array(); } if ($search) { $groupname = get_string('enrolcandidatesmatching', 'enrol', $search); } else { $groupname = get_string('enrolcandidates', 'enrol'); } return array($groupname => $availableusers); }
php
public function find_users($search) { global $CFG, $DB; $systemcontext = context_system::instance(); $userids = get_users_by_capability($systemcontext, 'moodle/site:mnetlogintoremote', 'u.id'); if (empty($userids)) { return array(); } list($usql, $uparams) = $DB->get_in_or_equal(array_keys($userids), SQL_PARAMS_NAMED, 'uid'); list($wherecondition, $params) = $this->search_sql($search, 'u'); $params = array_merge($params, $uparams); $params['hostid'] = $this->hostid; $params['remotecourseid'] = $this->remotecourseid; $params['mnetlocalhostid'] = $CFG->mnet_localhost_id; $fields = "SELECT ".$this->required_fields_sql("u"); $countfields = "SELECT COUNT(1)"; $sql = " FROM {user} u WHERE $wherecondition AND u.mnethostid = :mnetlocalhostid AND u.id $usql AND u.id NOT IN (SELECT e.userid FROM {mnetservice_enrol_enrolments} e WHERE (e.hostid = :hostid AND e.remotecourseid = :remotecourseid))"; list($sort, $sortparams) = users_order_by_sql('u'); $order = " ORDER BY $sort"; if (!$this->is_validating()) { $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params); if ($potentialmemberscount > 100) { return $this->too_many_results($search, $potentialmemberscount); } } $availableusers = $DB->get_records_sql($fields . $sql . $order, array_merge($params, $sortparams)); if (empty($availableusers)) { return array(); } if ($search) { $groupname = get_string('enrolcandidatesmatching', 'enrol', $search); } else { $groupname = get_string('enrolcandidates', 'enrol'); } return array($groupname => $availableusers); }
[ "public", "function", "find_users", "(", "$", "search", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "userids", "=", "get_users_by_capability", "(", "$", "systemcontext", ",", "'moodle/site:mnetlogintoremote'", ",", "'u.id'", ")", ";", "if", "(", "empty", "(", "$", "userids", ")", ")", "{", "return", "array", "(", ")", ";", "}", "list", "(", "$", "usql", ",", "$", "uparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "array_keys", "(", "$", "userids", ")", ",", "SQL_PARAMS_NAMED", ",", "'uid'", ")", ";", "list", "(", "$", "wherecondition", ",", "$", "params", ")", "=", "$", "this", "->", "search_sql", "(", "$", "search", ",", "'u'", ")", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "uparams", ")", ";", "$", "params", "[", "'hostid'", "]", "=", "$", "this", "->", "hostid", ";", "$", "params", "[", "'remotecourseid'", "]", "=", "$", "this", "->", "remotecourseid", ";", "$", "params", "[", "'mnetlocalhostid'", "]", "=", "$", "CFG", "->", "mnet_localhost_id", ";", "$", "fields", "=", "\"SELECT \"", ".", "$", "this", "->", "required_fields_sql", "(", "\"u\"", ")", ";", "$", "countfields", "=", "\"SELECT COUNT(1)\"", ";", "$", "sql", "=", "\" FROM {user} u\n WHERE $wherecondition\n AND u.mnethostid = :mnetlocalhostid\n AND u.id $usql\n AND u.id NOT IN (SELECT e.userid\n FROM {mnetservice_enrol_enrolments} e\n WHERE (e.hostid = :hostid AND e.remotecourseid = :remotecourseid))\"", ";", "list", "(", "$", "sort", ",", "$", "sortparams", ")", "=", "users_order_by_sql", "(", "'u'", ")", ";", "$", "order", "=", "\" ORDER BY $sort\"", ";", "if", "(", "!", "$", "this", "->", "is_validating", "(", ")", ")", "{", "$", "potentialmemberscount", "=", "$", "DB", "->", "count_records_sql", "(", "$", "countfields", ".", "$", "sql", ",", "$", "params", ")", ";", "if", "(", "$", "potentialmemberscount", ">", "100", ")", "{", "return", "$", "this", "->", "too_many_results", "(", "$", "search", ",", "$", "potentialmemberscount", ")", ";", "}", "}", "$", "availableusers", "=", "$", "DB", "->", "get_records_sql", "(", "$", "fields", ".", "$", "sql", ".", "$", "order", ",", "array_merge", "(", "$", "params", ",", "$", "sortparams", ")", ")", ";", "if", "(", "empty", "(", "$", "availableusers", ")", ")", "{", "return", "array", "(", ")", ";", "}", "if", "(", "$", "search", ")", "{", "$", "groupname", "=", "get_string", "(", "'enrolcandidatesmatching'", ",", "'enrol'", ",", "$", "search", ")", ";", "}", "else", "{", "$", "groupname", "=", "get_string", "(", "'enrolcandidates'", ",", "'enrol'", ")", ";", "}", "return", "array", "(", "$", "groupname", "=>", "$", "availableusers", ")", ";", "}" ]
Find our users who could be enrolled into the remote course Our users must have 'moodle/site:mnetlogintoremote' capability assigned. Remote users, guests, deleted and not confirmed users are not returned. @param string $search @return array
[ "Find", "our", "users", "who", "could", "be", "enrolled", "into", "the", "remote", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mnet/service/enrol/locallib.php#L552-L605
211,815
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Language.php
HTMLPurifier_Language.getErrorName
public function getErrorName($int) { if (!$this->_loaded) { $this->load(); } if (!isset($this->errorNames[$int])) { return "[Error: $int]"; } return $this->errorNames[$int]; }
php
public function getErrorName($int) { if (!$this->_loaded) { $this->load(); } if (!isset($this->errorNames[$int])) { return "[Error: $int]"; } return $this->errorNames[$int]; }
[ "public", "function", "getErrorName", "(", "$", "int", ")", "{", "if", "(", "!", "$", "this", "->", "_loaded", ")", "{", "$", "this", "->", "load", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "errorNames", "[", "$", "int", "]", ")", ")", "{", "return", "\"[Error: $int]\"", ";", "}", "return", "$", "this", "->", "errorNames", "[", "$", "int", "]", ";", "}" ]
Retrieves a localised error name. @param int $int error number, corresponding to PHP's error reporting @return string localised message
[ "Retrieves", "a", "localised", "error", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Language.php#L107-L116
211,816
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Language.php
HTMLPurifier_Language.listify
public function listify($array) { $sep = $this->getMessage('Item separator'); $sep_last = $this->getMessage('Item separator last'); $ret = ''; for ($i = 0, $c = count($array); $i < $c; $i++) { if ($i == 0) { } elseif ($i + 1 < $c) { $ret .= $sep; } else { $ret .= $sep_last; } $ret .= $array[$i]; } return $ret; }
php
public function listify($array) { $sep = $this->getMessage('Item separator'); $sep_last = $this->getMessage('Item separator last'); $ret = ''; for ($i = 0, $c = count($array); $i < $c; $i++) { if ($i == 0) { } elseif ($i + 1 < $c) { $ret .= $sep; } else { $ret .= $sep_last; } $ret .= $array[$i]; } return $ret; }
[ "public", "function", "listify", "(", "$", "array", ")", "{", "$", "sep", "=", "$", "this", "->", "getMessage", "(", "'Item separator'", ")", ";", "$", "sep_last", "=", "$", "this", "->", "getMessage", "(", "'Item separator last'", ")", ";", "$", "ret", "=", "''", ";", "for", "(", "$", "i", "=", "0", ",", "$", "c", "=", "count", "(", "$", "array", ")", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "if", "(", "$", "i", "==", "0", ")", "{", "}", "elseif", "(", "$", "i", "+", "1", "<", "$", "c", ")", "{", "$", "ret", ".=", "$", "sep", ";", "}", "else", "{", "$", "ret", ".=", "$", "sep_last", ";", "}", "$", "ret", ".=", "$", "array", "[", "$", "i", "]", ";", "}", "return", "$", "ret", ";", "}" ]
Converts an array list into a string readable representation @param array $array @return string
[ "Converts", "an", "array", "list", "into", "a", "string", "readable", "representation" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Language.php#L123-L138
211,817
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Language.php
HTMLPurifier_Language.formatMessage
public function formatMessage($key, $args = array()) { if (!$this->_loaded) { $this->load(); } if (!isset($this->messages[$key])) { return "[$key]"; } $raw = $this->messages[$key]; $subst = array(); $generator = false; foreach ($args as $i => $value) { if (is_object($value)) { if ($value instanceof HTMLPurifier_Token) { // factor this out some time if (!$generator) { $generator = $this->context->get('Generator'); } if (isset($value->name)) { $subst['$'.$i.'.Name'] = $value->name; } if (isset($value->data)) { $subst['$'.$i.'.Data'] = $value->data; } $subst['$'.$i.'.Compact'] = $subst['$'.$i.'.Serialized'] = $generator->generateFromToken($value); // a more complex algorithm for compact representation // could be introduced for all types of tokens. This // may need to be factored out into a dedicated class if (!empty($value->attr)) { $stripped_token = clone $value; $stripped_token->attr = array(); $subst['$'.$i.'.Compact'] = $generator->generateFromToken($stripped_token); } $subst['$'.$i.'.Line'] = $value->line ? $value->line : 'unknown'; } continue; } elseif (is_array($value)) { $keys = array_keys($value); if (array_keys($keys) === $keys) { // list $subst['$'.$i] = $this->listify($value); } else { // associative array // no $i implementation yet, sorry $subst['$'.$i.'.Keys'] = $this->listify($keys); $subst['$'.$i.'.Values'] = $this->listify(array_values($value)); } continue; } $subst['$' . $i] = $value; } return strtr($raw, $subst); }
php
public function formatMessage($key, $args = array()) { if (!$this->_loaded) { $this->load(); } if (!isset($this->messages[$key])) { return "[$key]"; } $raw = $this->messages[$key]; $subst = array(); $generator = false; foreach ($args as $i => $value) { if (is_object($value)) { if ($value instanceof HTMLPurifier_Token) { // factor this out some time if (!$generator) { $generator = $this->context->get('Generator'); } if (isset($value->name)) { $subst['$'.$i.'.Name'] = $value->name; } if (isset($value->data)) { $subst['$'.$i.'.Data'] = $value->data; } $subst['$'.$i.'.Compact'] = $subst['$'.$i.'.Serialized'] = $generator->generateFromToken($value); // a more complex algorithm for compact representation // could be introduced for all types of tokens. This // may need to be factored out into a dedicated class if (!empty($value->attr)) { $stripped_token = clone $value; $stripped_token->attr = array(); $subst['$'.$i.'.Compact'] = $generator->generateFromToken($stripped_token); } $subst['$'.$i.'.Line'] = $value->line ? $value->line : 'unknown'; } continue; } elseif (is_array($value)) { $keys = array_keys($value); if (array_keys($keys) === $keys) { // list $subst['$'.$i] = $this->listify($value); } else { // associative array // no $i implementation yet, sorry $subst['$'.$i.'.Keys'] = $this->listify($keys); $subst['$'.$i.'.Values'] = $this->listify(array_values($value)); } continue; } $subst['$' . $i] = $value; } return strtr($raw, $subst); }
[ "public", "function", "formatMessage", "(", "$", "key", ",", "$", "args", "=", "array", "(", ")", ")", "{", "if", "(", "!", "$", "this", "->", "_loaded", ")", "{", "$", "this", "->", "load", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "messages", "[", "$", "key", "]", ")", ")", "{", "return", "\"[$key]\"", ";", "}", "$", "raw", "=", "$", "this", "->", "messages", "[", "$", "key", "]", ";", "$", "subst", "=", "array", "(", ")", ";", "$", "generator", "=", "false", ";", "foreach", "(", "$", "args", "as", "$", "i", "=>", "$", "value", ")", "{", "if", "(", "is_object", "(", "$", "value", ")", ")", "{", "if", "(", "$", "value", "instanceof", "HTMLPurifier_Token", ")", "{", "// factor this out some time", "if", "(", "!", "$", "generator", ")", "{", "$", "generator", "=", "$", "this", "->", "context", "->", "get", "(", "'Generator'", ")", ";", "}", "if", "(", "isset", "(", "$", "value", "->", "name", ")", ")", "{", "$", "subst", "[", "'$'", ".", "$", "i", ".", "'.Name'", "]", "=", "$", "value", "->", "name", ";", "}", "if", "(", "isset", "(", "$", "value", "->", "data", ")", ")", "{", "$", "subst", "[", "'$'", ".", "$", "i", ".", "'.Data'", "]", "=", "$", "value", "->", "data", ";", "}", "$", "subst", "[", "'$'", ".", "$", "i", ".", "'.Compact'", "]", "=", "$", "subst", "[", "'$'", ".", "$", "i", ".", "'.Serialized'", "]", "=", "$", "generator", "->", "generateFromToken", "(", "$", "value", ")", ";", "// a more complex algorithm for compact representation", "// could be introduced for all types of tokens. This", "// may need to be factored out into a dedicated class", "if", "(", "!", "empty", "(", "$", "value", "->", "attr", ")", ")", "{", "$", "stripped_token", "=", "clone", "$", "value", ";", "$", "stripped_token", "->", "attr", "=", "array", "(", ")", ";", "$", "subst", "[", "'$'", ".", "$", "i", ".", "'.Compact'", "]", "=", "$", "generator", "->", "generateFromToken", "(", "$", "stripped_token", ")", ";", "}", "$", "subst", "[", "'$'", ".", "$", "i", ".", "'.Line'", "]", "=", "$", "value", "->", "line", "?", "$", "value", "->", "line", ":", "'unknown'", ";", "}", "continue", ";", "}", "elseif", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "value", ")", ";", "if", "(", "array_keys", "(", "$", "keys", ")", "===", "$", "keys", ")", "{", "// list", "$", "subst", "[", "'$'", ".", "$", "i", "]", "=", "$", "this", "->", "listify", "(", "$", "value", ")", ";", "}", "else", "{", "// associative array", "// no $i implementation yet, sorry", "$", "subst", "[", "'$'", ".", "$", "i", ".", "'.Keys'", "]", "=", "$", "this", "->", "listify", "(", "$", "keys", ")", ";", "$", "subst", "[", "'$'", ".", "$", "i", ".", "'.Values'", "]", "=", "$", "this", "->", "listify", "(", "array_values", "(", "$", "value", ")", ")", ";", "}", "continue", ";", "}", "$", "subst", "[", "'$'", ".", "$", "i", "]", "=", "$", "value", ";", "}", "return", "strtr", "(", "$", "raw", ",", "$", "subst", ")", ";", "}" ]
Formats a localised message with passed parameters @param string $key string identifier of message @param array $args Parameters to substitute in @return string localised message @todo Implement conditionals? Right now, some messages make reference to line numbers, but those aren't always available
[ "Formats", "a", "localised", "message", "with", "passed", "parameters" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Language.php#L148-L201
211,818
moodle/moodle
privacy/classes/local/request/contextlist.php
contextlist.add_from_sql
public function add_from_sql(string $sql, array $params) : contextlist { global $DB; $fields = \context_helper::get_preload_record_columns_sql('ctx'); if ($fieldname = $this->guess_id_field_from_sql($sql)) { if (is_numeric($fieldname)) { $wrapper = " SELECT {$fields} FROM {context} ctx WHERE ctx.id = :fieldvalue"; $params = ['fieldvalue' => $fieldname]; } else { // Able to guess a field name. $wrapper = " SELECT {$fields} FROM {context} ctx JOIN ({$sql}) target ON ctx.id = target.{$fieldname}"; } } else { // No field name available. Fall back on a potentially slower version. $wrapper = " SELECT {$fields} FROM {context} ctx WHERE ctx.id IN ({$sql})"; } $contexts = $DB->get_recordset_sql($wrapper, $params); $contextids = []; foreach ($contexts as $context) { $contextids[] = $context->ctxid; \context_helper::preload_from_record($context); } $contexts->close(); $this->set_contextids(array_merge($this->get_contextids(), $contextids)); return $this; }
php
public function add_from_sql(string $sql, array $params) : contextlist { global $DB; $fields = \context_helper::get_preload_record_columns_sql('ctx'); if ($fieldname = $this->guess_id_field_from_sql($sql)) { if (is_numeric($fieldname)) { $wrapper = " SELECT {$fields} FROM {context} ctx WHERE ctx.id = :fieldvalue"; $params = ['fieldvalue' => $fieldname]; } else { // Able to guess a field name. $wrapper = " SELECT {$fields} FROM {context} ctx JOIN ({$sql}) target ON ctx.id = target.{$fieldname}"; } } else { // No field name available. Fall back on a potentially slower version. $wrapper = " SELECT {$fields} FROM {context} ctx WHERE ctx.id IN ({$sql})"; } $contexts = $DB->get_recordset_sql($wrapper, $params); $contextids = []; foreach ($contexts as $context) { $contextids[] = $context->ctxid; \context_helper::preload_from_record($context); } $contexts->close(); $this->set_contextids(array_merge($this->get_contextids(), $contextids)); return $this; }
[ "public", "function", "add_from_sql", "(", "string", "$", "sql", ",", "array", "$", "params", ")", ":", "contextlist", "{", "global", "$", "DB", ";", "$", "fields", "=", "\\", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ";", "if", "(", "$", "fieldname", "=", "$", "this", "->", "guess_id_field_from_sql", "(", "$", "sql", ")", ")", "{", "if", "(", "is_numeric", "(", "$", "fieldname", ")", ")", "{", "$", "wrapper", "=", "\"\n SELECT {$fields}\n FROM {context} ctx\n WHERE ctx.id = :fieldvalue\"", ";", "$", "params", "=", "[", "'fieldvalue'", "=>", "$", "fieldname", "]", ";", "}", "else", "{", "// Able to guess a field name.", "$", "wrapper", "=", "\"\n SELECT {$fields}\n FROM {context} ctx\n JOIN ({$sql}) target ON ctx.id = target.{$fieldname}\"", ";", "}", "}", "else", "{", "// No field name available. Fall back on a potentially slower version.", "$", "wrapper", "=", "\"\n SELECT {$fields}\n FROM {context} ctx\n WHERE ctx.id IN ({$sql})\"", ";", "}", "$", "contexts", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "wrapper", ",", "$", "params", ")", ";", "$", "contextids", "=", "[", "]", ";", "foreach", "(", "$", "contexts", "as", "$", "context", ")", "{", "$", "contextids", "[", "]", "=", "$", "context", "->", "ctxid", ";", "\\", "context_helper", "::", "preload_from_record", "(", "$", "context", ")", ";", "}", "$", "contexts", "->", "close", "(", ")", ";", "$", "this", "->", "set_contextids", "(", "array_merge", "(", "$", "this", "->", "get_contextids", "(", ")", ",", "$", "contextids", ")", ")", ";", "return", "$", "this", ";", "}" ]
Add a set of contexts from SQL. The SQL should only return a list of context IDs. @param string $sql The SQL which will fetch the list of * context IDs @param array $params The set of SQL parameters @return $this
[ "Add", "a", "set", "of", "contexts", "from", "SQL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/contextlist.php#L46-L83
211,819
moodle/moodle
privacy/classes/local/request/contextlist.php
contextlist.add_user_context
public function add_user_context(int $userid) : contextlist { $sql = "SELECT DISTINCT ctx.id FROM {context} ctx WHERE ctx.contextlevel = :contextlevel AND ctx.instanceid = :instanceid"; return $this->add_from_sql($sql, ['contextlevel' => CONTEXT_USER, 'instanceid' => $userid]); }
php
public function add_user_context(int $userid) : contextlist { $sql = "SELECT DISTINCT ctx.id FROM {context} ctx WHERE ctx.contextlevel = :contextlevel AND ctx.instanceid = :instanceid"; return $this->add_from_sql($sql, ['contextlevel' => CONTEXT_USER, 'instanceid' => $userid]); }
[ "public", "function", "add_user_context", "(", "int", "$", "userid", ")", ":", "contextlist", "{", "$", "sql", "=", "\"SELECT DISTINCT ctx.id\n FROM {context} ctx\n WHERE ctx.contextlevel = :contextlevel\n AND ctx.instanceid = :instanceid\"", ";", "return", "$", "this", "->", "add_from_sql", "(", "$", "sql", ",", "[", "'contextlevel'", "=>", "CONTEXT_USER", ",", "'instanceid'", "=>", "$", "userid", "]", ")", ";", "}" ]
Adds the user context for a given user. @param int $userid @return $this
[ "Adds", "the", "user", "context", "for", "a", "given", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/contextlist.php#L100-L106
211,820
moodle/moodle
privacy/classes/local/request/contextlist.php
contextlist.add_user_contexts
public function add_user_contexts(array $userids) : contextlist { global $DB; list($useridsql, $useridparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); $sql = "SELECT DISTINCT ctx.id FROM {context} ctx WHERE ctx.contextlevel = :contextlevel AND ctx.instanceid $useridsql"; return $this->add_from_sql($sql, ['contextlevel' => CONTEXT_USER] + $useridparams); }
php
public function add_user_contexts(array $userids) : contextlist { global $DB; list($useridsql, $useridparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); $sql = "SELECT DISTINCT ctx.id FROM {context} ctx WHERE ctx.contextlevel = :contextlevel AND ctx.instanceid $useridsql"; return $this->add_from_sql($sql, ['contextlevel' => CONTEXT_USER] + $useridparams); }
[ "public", "function", "add_user_contexts", "(", "array", "$", "userids", ")", ":", "contextlist", "{", "global", "$", "DB", ";", "list", "(", "$", "useridsql", ",", "$", "useridparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "userids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sql", "=", "\"SELECT DISTINCT ctx.id\n FROM {context} ctx\n WHERE ctx.contextlevel = :contextlevel\n AND ctx.instanceid $useridsql\"", ";", "return", "$", "this", "->", "add_from_sql", "(", "$", "sql", ",", "[", "'contextlevel'", "=>", "CONTEXT_USER", "]", "+", "$", "useridparams", ")", ";", "}" ]
Adds the user contexts for given users. @param array $userids @return $this
[ "Adds", "the", "user", "contexts", "for", "given", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/contextlist.php#L114-L123
211,821
moodle/moodle
privacy/classes/local/request/contextlist.php
contextlist.guess_id_field_from_sql
protected function guess_id_field_from_sql(string $sql) : string { // We are not interested in any subquery/view/conditions for the purpose of this method, so // let's reduce the query to the interesting parts by recursively cleaning all // contents within parenthesis. If there are problems (null), we keep the text unmodified. // So just top-level sql will remain after the reduction. $recursiveregexp = '/\((([^()]*|(?R))*)\)/'; $sql = (preg_replace($recursiveregexp, '', $sql) ?: $sql); // Get the list of relevant words from the SQL Query. // We explode the SQL by the space character, then trim any extra whitespace (e.g. newlines), before we filter // empty value, and finally we re-index the array. $sql = rtrim($sql, ';'); $words = array_map('trim', preg_split('/\s+/', $sql)); $words = array_filter($words, function($word) { return $word !== ''; }); $words = array_values($words); $uwords = array_map('strtoupper', $words); // Uppercase all them. // If the query has boolean operators (UNION, it is the only one we support cross-db) // then we cannot guarantee whats coming after the first query, it can be anything. if (array_search('UNION', $uwords)) { return ''; } if ($firstfrom = array_search('FROM', $uwords)) { // Found a FROM keyword. // Select the previous word. $fieldname = $words[$firstfrom - 1]; if (is_numeric($fieldname)) { return $fieldname; } if ($hasdot = strpos($fieldname, '.')) { // This field is against a table alias. Take off the alias. $fieldname = substr($fieldname, $hasdot + 1); } return $fieldname; } else if ((count($words) == 1) && (is_numeric($words[0]))) { // Not a real SQL, just a single numerical value - such as one returned by {@link self::add_system_context()}. return $words[0]; } else if ((count($words) == 2) && (strtoupper($words[0]) === 'SELECT') && (is_numeric($words[1]))) { // SQL returning a constant numerical value. return $words[1]; } return ''; }
php
protected function guess_id_field_from_sql(string $sql) : string { // We are not interested in any subquery/view/conditions for the purpose of this method, so // let's reduce the query to the interesting parts by recursively cleaning all // contents within parenthesis. If there are problems (null), we keep the text unmodified. // So just top-level sql will remain after the reduction. $recursiveregexp = '/\((([^()]*|(?R))*)\)/'; $sql = (preg_replace($recursiveregexp, '', $sql) ?: $sql); // Get the list of relevant words from the SQL Query. // We explode the SQL by the space character, then trim any extra whitespace (e.g. newlines), before we filter // empty value, and finally we re-index the array. $sql = rtrim($sql, ';'); $words = array_map('trim', preg_split('/\s+/', $sql)); $words = array_filter($words, function($word) { return $word !== ''; }); $words = array_values($words); $uwords = array_map('strtoupper', $words); // Uppercase all them. // If the query has boolean operators (UNION, it is the only one we support cross-db) // then we cannot guarantee whats coming after the first query, it can be anything. if (array_search('UNION', $uwords)) { return ''; } if ($firstfrom = array_search('FROM', $uwords)) { // Found a FROM keyword. // Select the previous word. $fieldname = $words[$firstfrom - 1]; if (is_numeric($fieldname)) { return $fieldname; } if ($hasdot = strpos($fieldname, '.')) { // This field is against a table alias. Take off the alias. $fieldname = substr($fieldname, $hasdot + 1); } return $fieldname; } else if ((count($words) == 1) && (is_numeric($words[0]))) { // Not a real SQL, just a single numerical value - such as one returned by {@link self::add_system_context()}. return $words[0]; } else if ((count($words) == 2) && (strtoupper($words[0]) === 'SELECT') && (is_numeric($words[1]))) { // SQL returning a constant numerical value. return $words[1]; } return ''; }
[ "protected", "function", "guess_id_field_from_sql", "(", "string", "$", "sql", ")", ":", "string", "{", "// We are not interested in any subquery/view/conditions for the purpose of this method, so", "// let's reduce the query to the interesting parts by recursively cleaning all", "// contents within parenthesis. If there are problems (null), we keep the text unmodified.", "// So just top-level sql will remain after the reduction.", "$", "recursiveregexp", "=", "'/\\((([^()]*|(?R))*)\\)/'", ";", "$", "sql", "=", "(", "preg_replace", "(", "$", "recursiveregexp", ",", "''", ",", "$", "sql", ")", "?", ":", "$", "sql", ")", ";", "// Get the list of relevant words from the SQL Query.", "// We explode the SQL by the space character, then trim any extra whitespace (e.g. newlines), before we filter", "// empty value, and finally we re-index the array.", "$", "sql", "=", "rtrim", "(", "$", "sql", ",", "';'", ")", ";", "$", "words", "=", "array_map", "(", "'trim'", ",", "preg_split", "(", "'/\\s+/'", ",", "$", "sql", ")", ")", ";", "$", "words", "=", "array_filter", "(", "$", "words", ",", "function", "(", "$", "word", ")", "{", "return", "$", "word", "!==", "''", ";", "}", ")", ";", "$", "words", "=", "array_values", "(", "$", "words", ")", ";", "$", "uwords", "=", "array_map", "(", "'strtoupper'", ",", "$", "words", ")", ";", "// Uppercase all them.", "// If the query has boolean operators (UNION, it is the only one we support cross-db)", "// then we cannot guarantee whats coming after the first query, it can be anything.", "if", "(", "array_search", "(", "'UNION'", ",", "$", "uwords", ")", ")", "{", "return", "''", ";", "}", "if", "(", "$", "firstfrom", "=", "array_search", "(", "'FROM'", ",", "$", "uwords", ")", ")", "{", "// Found a FROM keyword.", "// Select the previous word.", "$", "fieldname", "=", "$", "words", "[", "$", "firstfrom", "-", "1", "]", ";", "if", "(", "is_numeric", "(", "$", "fieldname", ")", ")", "{", "return", "$", "fieldname", ";", "}", "if", "(", "$", "hasdot", "=", "strpos", "(", "$", "fieldname", ",", "'.'", ")", ")", "{", "// This field is against a table alias. Take off the alias.", "$", "fieldname", "=", "substr", "(", "$", "fieldname", ",", "$", "hasdot", "+", "1", ")", ";", "}", "return", "$", "fieldname", ";", "}", "else", "if", "(", "(", "count", "(", "$", "words", ")", "==", "1", ")", "&&", "(", "is_numeric", "(", "$", "words", "[", "0", "]", ")", ")", ")", "{", "// Not a real SQL, just a single numerical value - such as one returned by {@link self::add_system_context()}.", "return", "$", "words", "[", "0", "]", ";", "}", "else", "if", "(", "(", "count", "(", "$", "words", ")", "==", "2", ")", "&&", "(", "strtoupper", "(", "$", "words", "[", "0", "]", ")", "===", "'SELECT'", ")", "&&", "(", "is_numeric", "(", "$", "words", "[", "1", "]", ")", ")", ")", "{", "// SQL returning a constant numerical value.", "return", "$", "words", "[", "1", "]", ";", "}", "return", "''", ";", "}" ]
Guess the name of the contextid field from the supplied SQL. @param string $sql The SQL to guess from @return string The field name or a numeric value representing the context id
[ "Guess", "the", "name", "of", "the", "contextid", "field", "from", "the", "supplied", "SQL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/contextlist.php#L140-L189
211,822
moodle/moodle
lib/filestorage/stored_file.php
stored_file.delete_reference
public function delete_reference() { global $DB; if (!$this->is_external_file()) { throw new coding_exception('An attempt to unlink a non-reference file.'); } $transaction = $DB->start_delegated_transaction(); // Are we the only one referring to the original file? If so, delete the // referenced file record. Note we do not use file_storage::search_references_count() // here because we want to count draft files too and we are at a bit lower access level here. $countlinks = $DB->count_records('files', array('referencefileid' => $this->file_record->referencefileid)); if ($countlinks == 1) { $DB->delete_records('files_reference', array('id' => $this->file_record->referencefileid)); } // Update the underlying record in the database. $update = new stdClass(); $update->referencefileid = null; $this->update($update); $transaction->allow_commit(); // Update our properties and the record in the memory. $this->repository = null; $this->file_record->repositoryid = null; $this->file_record->reference = null; $this->file_record->referencefileid = null; $this->file_record->referencelastsync = null; }
php
public function delete_reference() { global $DB; if (!$this->is_external_file()) { throw new coding_exception('An attempt to unlink a non-reference file.'); } $transaction = $DB->start_delegated_transaction(); // Are we the only one referring to the original file? If so, delete the // referenced file record. Note we do not use file_storage::search_references_count() // here because we want to count draft files too and we are at a bit lower access level here. $countlinks = $DB->count_records('files', array('referencefileid' => $this->file_record->referencefileid)); if ($countlinks == 1) { $DB->delete_records('files_reference', array('id' => $this->file_record->referencefileid)); } // Update the underlying record in the database. $update = new stdClass(); $update->referencefileid = null; $this->update($update); $transaction->allow_commit(); // Update our properties and the record in the memory. $this->repository = null; $this->file_record->repositoryid = null; $this->file_record->reference = null; $this->file_record->referencefileid = null; $this->file_record->referencelastsync = null; }
[ "public", "function", "delete_reference", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "$", "this", "->", "is_external_file", "(", ")", ")", "{", "throw", "new", "coding_exception", "(", "'An attempt to unlink a non-reference file.'", ")", ";", "}", "$", "transaction", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "// Are we the only one referring to the original file? If so, delete the", "// referenced file record. Note we do not use file_storage::search_references_count()", "// here because we want to count draft files too and we are at a bit lower access level here.", "$", "countlinks", "=", "$", "DB", "->", "count_records", "(", "'files'", ",", "array", "(", "'referencefileid'", "=>", "$", "this", "->", "file_record", "->", "referencefileid", ")", ")", ";", "if", "(", "$", "countlinks", "==", "1", ")", "{", "$", "DB", "->", "delete_records", "(", "'files_reference'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "file_record", "->", "referencefileid", ")", ")", ";", "}", "// Update the underlying record in the database.", "$", "update", "=", "new", "stdClass", "(", ")", ";", "$", "update", "->", "referencefileid", "=", "null", ";", "$", "this", "->", "update", "(", "$", "update", ")", ";", "$", "transaction", "->", "allow_commit", "(", ")", ";", "// Update our properties and the record in the memory.", "$", "this", "->", "repository", "=", "null", ";", "$", "this", "->", "file_record", "->", "repositoryid", "=", "null", ";", "$", "this", "->", "file_record", "->", "reference", "=", "null", ";", "$", "this", "->", "file_record", "->", "referencefileid", "=", "null", ";", "$", "this", "->", "file_record", "->", "referencelastsync", "=", "null", ";", "}" ]
Unlink the stored file from the referenced file This methods destroys the link to the record in files_reference table. This effectively turns the stored file from being an alias to a plain copy. However, the caller has to make sure that the actual file's content has beed synced prior to calling this method.
[ "Unlink", "the", "stored", "file", "from", "the", "referenced", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/stored_file.php#L319-L350
211,823
moodle/moodle
lib/filestorage/stored_file.php
stored_file.delete
public function delete() { global $DB; if ($this->is_directory()) { // Directories can not be referenced, just delete the record. $DB->delete_records('files', array('id'=>$this->file_record->id)); } else { $transaction = $DB->start_delegated_transaction(); // If there are other files referring to this file, convert them to copies. if ($files = $this->fs->get_references_by_storedfile($this)) { foreach ($files as $file) { $this->fs->import_external_file($file); } } // If this file is a reference (alias) to another file, unlink it first. if ($this->is_external_file()) { $this->delete_reference(); } // Now delete the file record. $DB->delete_records('files', array('id'=>$this->file_record->id)); $transaction->allow_commit(); if (!$this->is_directory()) { // Callback for file deletion. if ($pluginsfunction = get_plugins_with_function('after_file_deleted')) { foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { $pluginfunction($this->file_record); } } } } } // Move pool file to trash if content not needed any more. $this->filesystem->remove_file($this->file_record->contenthash); return true; // BC only }
php
public function delete() { global $DB; if ($this->is_directory()) { // Directories can not be referenced, just delete the record. $DB->delete_records('files', array('id'=>$this->file_record->id)); } else { $transaction = $DB->start_delegated_transaction(); // If there are other files referring to this file, convert them to copies. if ($files = $this->fs->get_references_by_storedfile($this)) { foreach ($files as $file) { $this->fs->import_external_file($file); } } // If this file is a reference (alias) to another file, unlink it first. if ($this->is_external_file()) { $this->delete_reference(); } // Now delete the file record. $DB->delete_records('files', array('id'=>$this->file_record->id)); $transaction->allow_commit(); if (!$this->is_directory()) { // Callback for file deletion. if ($pluginsfunction = get_plugins_with_function('after_file_deleted')) { foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { $pluginfunction($this->file_record); } } } } } // Move pool file to trash if content not needed any more. $this->filesystem->remove_file($this->file_record->contenthash); return true; // BC only }
[ "public", "function", "delete", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "is_directory", "(", ")", ")", "{", "// Directories can not be referenced, just delete the record.", "$", "DB", "->", "delete_records", "(", "'files'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "file_record", "->", "id", ")", ")", ";", "}", "else", "{", "$", "transaction", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "// If there are other files referring to this file, convert them to copies.", "if", "(", "$", "files", "=", "$", "this", "->", "fs", "->", "get_references_by_storedfile", "(", "$", "this", ")", ")", "{", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "this", "->", "fs", "->", "import_external_file", "(", "$", "file", ")", ";", "}", "}", "// If this file is a reference (alias) to another file, unlink it first.", "if", "(", "$", "this", "->", "is_external_file", "(", ")", ")", "{", "$", "this", "->", "delete_reference", "(", ")", ";", "}", "// Now delete the file record.", "$", "DB", "->", "delete_records", "(", "'files'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "file_record", "->", "id", ")", ")", ";", "$", "transaction", "->", "allow_commit", "(", ")", ";", "if", "(", "!", "$", "this", "->", "is_directory", "(", ")", ")", "{", "// Callback for file deletion.", "if", "(", "$", "pluginsfunction", "=", "get_plugins_with_function", "(", "'after_file_deleted'", ")", ")", "{", "foreach", "(", "$", "pluginsfunction", "as", "$", "plugintype", "=>", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "pluginfunction", ")", "{", "$", "pluginfunction", "(", "$", "this", "->", "file_record", ")", ";", "}", "}", "}", "}", "}", "// Move pool file to trash if content not needed any more.", "$", "this", "->", "filesystem", "->", "remove_file", "(", "$", "this", "->", "file_record", "->", "contenthash", ")", ";", "return", "true", ";", "// BC only", "}" ]
Delete file from files table. The content of files stored in sha1 pool is reclaimed later - the occupied disk space is reclaimed much later. @return bool always true or exception if error occurred
[ "Delete", "file", "from", "files", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/stored_file.php#L373-L415
211,824
moodle/moodle
lib/filestorage/stored_file.php
stored_file.copy_content_to_temp
public function copy_content_to_temp($dir = 'files', $fileprefix = 'tempup_') { $tempfile = false; if (!$dir = make_temp_directory($dir)) { return false; } if (!$tempfile = tempnam($dir, $fileprefix)) { return false; } if (!$this->copy_content_to($tempfile)) { // something went wrong @unlink($tempfile); return false; } return $tempfile; }
php
public function copy_content_to_temp($dir = 'files', $fileprefix = 'tempup_') { $tempfile = false; if (!$dir = make_temp_directory($dir)) { return false; } if (!$tempfile = tempnam($dir, $fileprefix)) { return false; } if (!$this->copy_content_to($tempfile)) { // something went wrong @unlink($tempfile); return false; } return $tempfile; }
[ "public", "function", "copy_content_to_temp", "(", "$", "dir", "=", "'files'", ",", "$", "fileprefix", "=", "'tempup_'", ")", "{", "$", "tempfile", "=", "false", ";", "if", "(", "!", "$", "dir", "=", "make_temp_directory", "(", "$", "dir", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "tempfile", "=", "tempnam", "(", "$", "dir", ",", "$", "fileprefix", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "copy_content_to", "(", "$", "tempfile", ")", ")", "{", "// something went wrong", "@", "unlink", "(", "$", "tempfile", ")", ";", "return", "false", ";", "}", "return", "$", "tempfile", ";", "}" ]
Copy content of file to temporary folder and returns file path @param string $dir name of the temporary directory @param string $fileprefix prefix of temporary file. @return string|bool path of temporary file or false.
[ "Copy", "content", "of", "file", "to", "temporary", "folder", "and", "returns", "file", "path" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/stored_file.php#L473-L487
211,825
moodle/moodle
lib/filestorage/stored_file.php
stored_file.is_valid_image
public function is_valid_image() { $mimetype = $this->get_mimetype(); if (!file_mimetype_in_typegroup($mimetype, 'web_image')) { return false; } if (!$info = $this->get_imageinfo()) { return false; } if ($info['mimetype'] !== $mimetype) { return false; } // ok, GD likes this image return true; }
php
public function is_valid_image() { $mimetype = $this->get_mimetype(); if (!file_mimetype_in_typegroup($mimetype, 'web_image')) { return false; } if (!$info = $this->get_imageinfo()) { return false; } if ($info['mimetype'] !== $mimetype) { return false; } // ok, GD likes this image return true; }
[ "public", "function", "is_valid_image", "(", ")", "{", "$", "mimetype", "=", "$", "this", "->", "get_mimetype", "(", ")", ";", "if", "(", "!", "file_mimetype_in_typegroup", "(", "$", "mimetype", ",", "'web_image'", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "info", "=", "$", "this", "->", "get_imageinfo", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "info", "[", "'mimetype'", "]", "!==", "$", "mimetype", ")", "{", "return", "false", ";", "}", "// ok, GD likes this image", "return", "true", ";", "}" ]
Verifies the file is a valid web image - gif, png and jpeg only. It should be ok to serve this image from server without any other security workarounds. @return bool true if file ok
[ "Verifies", "the", "file", "is", "a", "valid", "web", "image", "-", "gif", "png", "and", "jpeg", "only", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/stored_file.php#L572-L585
211,826
moodle/moodle
lib/filestorage/stored_file.php
stored_file.get_parent_directory
public function get_parent_directory() { if ($this->file_record->filepath === '/' and $this->file_record->filename === '.') { //root dir does not have parent return null; } if ($this->file_record->filename !== '.') { return $this->fs->create_directory($this->file_record->contextid, $this->file_record->component, $this->file_record->filearea, $this->file_record->itemid, $this->file_record->filepath); } $filepath = $this->file_record->filepath; $filepath = trim($filepath, '/'); $dirs = explode('/', $filepath); array_pop($dirs); $filepath = implode('/', $dirs); $filepath = ($filepath === '') ? '/' : "/$filepath/"; return $this->fs->create_directory($this->file_record->contextid, $this->file_record->component, $this->file_record->filearea, $this->file_record->itemid, $filepath); }
php
public function get_parent_directory() { if ($this->file_record->filepath === '/' and $this->file_record->filename === '.') { //root dir does not have parent return null; } if ($this->file_record->filename !== '.') { return $this->fs->create_directory($this->file_record->contextid, $this->file_record->component, $this->file_record->filearea, $this->file_record->itemid, $this->file_record->filepath); } $filepath = $this->file_record->filepath; $filepath = trim($filepath, '/'); $dirs = explode('/', $filepath); array_pop($dirs); $filepath = implode('/', $dirs); $filepath = ($filepath === '') ? '/' : "/$filepath/"; return $this->fs->create_directory($this->file_record->contextid, $this->file_record->component, $this->file_record->filearea, $this->file_record->itemid, $filepath); }
[ "public", "function", "get_parent_directory", "(", ")", "{", "if", "(", "$", "this", "->", "file_record", "->", "filepath", "===", "'/'", "and", "$", "this", "->", "file_record", "->", "filename", "===", "'.'", ")", "{", "//root dir does not have parent", "return", "null", ";", "}", "if", "(", "$", "this", "->", "file_record", "->", "filename", "!==", "'.'", ")", "{", "return", "$", "this", "->", "fs", "->", "create_directory", "(", "$", "this", "->", "file_record", "->", "contextid", ",", "$", "this", "->", "file_record", "->", "component", ",", "$", "this", "->", "file_record", "->", "filearea", ",", "$", "this", "->", "file_record", "->", "itemid", ",", "$", "this", "->", "file_record", "->", "filepath", ")", ";", "}", "$", "filepath", "=", "$", "this", "->", "file_record", "->", "filepath", ";", "$", "filepath", "=", "trim", "(", "$", "filepath", ",", "'/'", ")", ";", "$", "dirs", "=", "explode", "(", "'/'", ",", "$", "filepath", ")", ";", "array_pop", "(", "$", "dirs", ")", ";", "$", "filepath", "=", "implode", "(", "'/'", ",", "$", "dirs", ")", ";", "$", "filepath", "=", "(", "$", "filepath", "===", "''", ")", "?", "'/'", ":", "\"/$filepath/\"", ";", "return", "$", "this", "->", "fs", "->", "create_directory", "(", "$", "this", "->", "file_record", "->", "contextid", ",", "$", "this", "->", "file_record", "->", "component", ",", "$", "this", "->", "file_record", "->", "filearea", ",", "$", "this", "->", "file_record", "->", "itemid", ",", "$", "filepath", ")", ";", "}" ]
Returns parent directory, creates missing parents if needed. @return stored_file
[ "Returns", "parent", "directory", "creates", "missing", "parents", "if", "needed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/stored_file.php#L592-L610
211,827
moodle/moodle
lib/filestorage/stored_file.php
stored_file.set_sortorder
public function set_sortorder($sortorder) { $oldorder = $this->file_record->sortorder; $filerecord = new stdClass; $filerecord->sortorder = $sortorder; $this->update($filerecord); if (!$this->is_directory()) { // Callback for file sort order change. if ($pluginsfunction = get_plugins_with_function('after_file_sorted')) { foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { $pluginfunction($this->file_record, $oldorder, $sortorder); } } } } }
php
public function set_sortorder($sortorder) { $oldorder = $this->file_record->sortorder; $filerecord = new stdClass; $filerecord->sortorder = $sortorder; $this->update($filerecord); if (!$this->is_directory()) { // Callback for file sort order change. if ($pluginsfunction = get_plugins_with_function('after_file_sorted')) { foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { $pluginfunction($this->file_record, $oldorder, $sortorder); } } } } }
[ "public", "function", "set_sortorder", "(", "$", "sortorder", ")", "{", "$", "oldorder", "=", "$", "this", "->", "file_record", "->", "sortorder", ";", "$", "filerecord", "=", "new", "stdClass", ";", "$", "filerecord", "->", "sortorder", "=", "$", "sortorder", ";", "$", "this", "->", "update", "(", "$", "filerecord", ")", ";", "if", "(", "!", "$", "this", "->", "is_directory", "(", ")", ")", "{", "// Callback for file sort order change.", "if", "(", "$", "pluginsfunction", "=", "get_plugins_with_function", "(", "'after_file_sorted'", ")", ")", "{", "foreach", "(", "$", "pluginsfunction", "as", "$", "plugintype", "=>", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "pluginfunction", ")", "{", "$", "pluginfunction", "(", "$", "this", "->", "file_record", ",", "$", "oldorder", ",", "$", "sortorder", ")", ";", "}", "}", "}", "}", "}" ]
Set file sort order @param int $sortorder @return int
[ "Set", "file", "sort", "order" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/stored_file.php#L879-L894
211,828
moodle/moodle
lib/filestorage/stored_file.php
stored_file.set_synchronized
public function set_synchronized($contenthash, $filesize, $status = 0, $timemodified = null) { if (!$this->is_external_file()) { return; } $now = time(); if ($contenthash === null) { $contenthash = $this->file_record->contenthash; } if ($contenthash != $this->file_record->contenthash) { $oldcontenthash = $this->file_record->contenthash; } // this will update all entries in {files} that have the same filereference id $this->fs->update_references($this->file_record->referencefileid, $now, null, $contenthash, $filesize, $status, $timemodified); // we don't need to call update() for this object, just set the values of changed fields $this->file_record->contenthash = $contenthash; $this->file_record->filesize = $filesize; $this->file_record->status = $status; $this->file_record->referencelastsync = $now; if ($timemodified) { $this->file_record->timemodified = $timemodified; } if (isset($oldcontenthash)) { $this->filesystem->remove_file($oldcontenthash); } }
php
public function set_synchronized($contenthash, $filesize, $status = 0, $timemodified = null) { if (!$this->is_external_file()) { return; } $now = time(); if ($contenthash === null) { $contenthash = $this->file_record->contenthash; } if ($contenthash != $this->file_record->contenthash) { $oldcontenthash = $this->file_record->contenthash; } // this will update all entries in {files} that have the same filereference id $this->fs->update_references($this->file_record->referencefileid, $now, null, $contenthash, $filesize, $status, $timemodified); // we don't need to call update() for this object, just set the values of changed fields $this->file_record->contenthash = $contenthash; $this->file_record->filesize = $filesize; $this->file_record->status = $status; $this->file_record->referencelastsync = $now; if ($timemodified) { $this->file_record->timemodified = $timemodified; } if (isset($oldcontenthash)) { $this->filesystem->remove_file($oldcontenthash); } }
[ "public", "function", "set_synchronized", "(", "$", "contenthash", ",", "$", "filesize", ",", "$", "status", "=", "0", ",", "$", "timemodified", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "is_external_file", "(", ")", ")", "{", "return", ";", "}", "$", "now", "=", "time", "(", ")", ";", "if", "(", "$", "contenthash", "===", "null", ")", "{", "$", "contenthash", "=", "$", "this", "->", "file_record", "->", "contenthash", ";", "}", "if", "(", "$", "contenthash", "!=", "$", "this", "->", "file_record", "->", "contenthash", ")", "{", "$", "oldcontenthash", "=", "$", "this", "->", "file_record", "->", "contenthash", ";", "}", "// this will update all entries in {files} that have the same filereference id", "$", "this", "->", "fs", "->", "update_references", "(", "$", "this", "->", "file_record", "->", "referencefileid", ",", "$", "now", ",", "null", ",", "$", "contenthash", ",", "$", "filesize", ",", "$", "status", ",", "$", "timemodified", ")", ";", "// we don't need to call update() for this object, just set the values of changed fields", "$", "this", "->", "file_record", "->", "contenthash", "=", "$", "contenthash", ";", "$", "this", "->", "file_record", "->", "filesize", "=", "$", "filesize", ";", "$", "this", "->", "file_record", "->", "status", "=", "$", "status", ";", "$", "this", "->", "file_record", "->", "referencelastsync", "=", "$", "now", ";", "if", "(", "$", "timemodified", ")", "{", "$", "this", "->", "file_record", "->", "timemodified", "=", "$", "timemodified", ";", "}", "if", "(", "isset", "(", "$", "oldcontenthash", ")", ")", "{", "$", "this", "->", "filesystem", "->", "remove_file", "(", "$", "oldcontenthash", ")", ";", "}", "}" ]
Called after reference-file has been synchronized with the repository We update contenthash, filesize and status in files table if changed and we always update lastsync in files_reference table @param null|string $contenthash if set to null contenthash is not changed @param int $filesize new size of the file @param int $status new status of the file (0 means OK, 666 - source missing) @param int $timemodified last time modified of the source, if known
[ "Called", "after", "reference", "-", "file", "has", "been", "synchronized", "with", "the", "repository" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/stored_file.php#L982-L1006
211,829
moodle/moodle
lib/filestorage/stored_file.php
stored_file.send_file
public function send_file($lifetime, $filter, $forcedownload, $options) { $this->repository->send_file($this, $lifetime, $filter, $forcedownload, $options); }
php
public function send_file($lifetime, $filter, $forcedownload, $options) { $this->repository->send_file($this, $lifetime, $filter, $forcedownload, $options); }
[ "public", "function", "send_file", "(", "$", "lifetime", ",", "$", "filter", ",", "$", "forcedownload", ",", "$", "options", ")", "{", "$", "this", "->", "repository", "->", "send_file", "(", "$", "this", ",", "$", "lifetime", ",", "$", "filter", ",", "$", "forcedownload", ",", "$", "options", ")", ";", "}" ]
Send file references @param int $lifetime Number of seconds before the file should expire from caches (default 24 hours) @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin @param array $options additional options affecting the file serving
[ "Send", "file", "references" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/stored_file.php#L1023-L1025
211,830
moodle/moodle
lib/filestorage/stored_file.php
stored_file.generate_image_thumbnail
public function generate_image_thumbnail($width, $height) { global $CFG; require_once($CFG->libdir . '/gdlib.php'); if (empty($width) or empty($height)) { return false; } $content = $this->get_content(); // Fetch the image information for this image. $imageinfo = @getimagesizefromstring($content); if (empty($imageinfo)) { return false; } // Create a new image from the file. $original = @imagecreatefromstring($content); // Generate the thumbnail. return generate_image_thumbnail_from_image($original, $imageinfo, $width, $height); }
php
public function generate_image_thumbnail($width, $height) { global $CFG; require_once($CFG->libdir . '/gdlib.php'); if (empty($width) or empty($height)) { return false; } $content = $this->get_content(); // Fetch the image information for this image. $imageinfo = @getimagesizefromstring($content); if (empty($imageinfo)) { return false; } // Create a new image from the file. $original = @imagecreatefromstring($content); // Generate the thumbnail. return generate_image_thumbnail_from_image($original, $imageinfo, $width, $height); }
[ "public", "function", "generate_image_thumbnail", "(", "$", "width", ",", "$", "height", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/gdlib.php'", ")", ";", "if", "(", "empty", "(", "$", "width", ")", "or", "empty", "(", "$", "height", ")", ")", "{", "return", "false", ";", "}", "$", "content", "=", "$", "this", "->", "get_content", "(", ")", ";", "// Fetch the image information for this image.", "$", "imageinfo", "=", "@", "getimagesizefromstring", "(", "$", "content", ")", ";", "if", "(", "empty", "(", "$", "imageinfo", ")", ")", "{", "return", "false", ";", "}", "// Create a new image from the file.", "$", "original", "=", "@", "imagecreatefromstring", "(", "$", "content", ")", ";", "// Generate the thumbnail.", "return", "generate_image_thumbnail_from_image", "(", "$", "original", ",", "$", "imageinfo", ",", "$", "width", ",", "$", "height", ")", ";", "}" ]
Generates a thumbnail for this stored_file. If the GD library has at least version 2 and PNG support is available, the returned data is the content of a transparent PNG file containing the thumbnail. Otherwise, the function returns contents of a JPEG file with black background containing the thumbnail. @param int $width the width of the requested thumbnail @param int $height the height of the requested thumbnail @return string|bool false if a problem occurs, the thumbnail image data otherwise
[ "Generates", "a", "thumbnail", "for", "this", "stored_file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/stored_file.php#L1065-L1086
211,831
moodle/moodle
lib/filestorage/stored_file.php
stored_file.resize_image
public function resize_image($width, $height) { global $CFG; require_once($CFG->libdir . '/gdlib.php'); $content = $this->get_content(); // Fetch the image information for this image. $imageinfo = @getimagesizefromstring($content); if (empty($imageinfo)) { return false; } // Create a new image from the file. $original = @imagecreatefromstring($content); // Generate the resized image. return resize_image_from_image($original, $imageinfo, $width, $height); }
php
public function resize_image($width, $height) { global $CFG; require_once($CFG->libdir . '/gdlib.php'); $content = $this->get_content(); // Fetch the image information for this image. $imageinfo = @getimagesizefromstring($content); if (empty($imageinfo)) { return false; } // Create a new image from the file. $original = @imagecreatefromstring($content); // Generate the resized image. return resize_image_from_image($original, $imageinfo, $width, $height); }
[ "public", "function", "resize_image", "(", "$", "width", ",", "$", "height", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/gdlib.php'", ")", ";", "$", "content", "=", "$", "this", "->", "get_content", "(", ")", ";", "// Fetch the image information for this image.", "$", "imageinfo", "=", "@", "getimagesizefromstring", "(", "$", "content", ")", ";", "if", "(", "empty", "(", "$", "imageinfo", ")", ")", "{", "return", "false", ";", "}", "// Create a new image from the file.", "$", "original", "=", "@", "imagecreatefromstring", "(", "$", "content", ")", ";", "// Generate the resized image.", "return", "resize_image_from_image", "(", "$", "original", ",", "$", "imageinfo", ",", "$", "width", ",", "$", "height", ")", ";", "}" ]
Generate a resized image for this stored_file. @param int|null $width The desired width, or null to only use the height. @param int|null $height The desired height, or null to only use the width. @return string|false False when a problem occurs, else the image data.
[ "Generate", "a", "resized", "image", "for", "this", "stored_file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/stored_file.php#L1095-L1112
211,832
moodle/moodle
completion/criteria/completion_criteria_role.php
completion_criteria_role.get_title
public function get_title() { global $DB; $role = $DB->get_record('role', array('id' => $this->role)); if (!$role) { return '['.get_string('roleidnotfound', 'completion', $this->role).']'; } return role_get_name($role, context_course::instance($this->course)); }
php
public function get_title() { global $DB; $role = $DB->get_record('role', array('id' => $this->role)); if (!$role) { return '['.get_string('roleidnotfound', 'completion', $this->role).']'; } return role_get_name($role, context_course::instance($this->course)); }
[ "public", "function", "get_title", "(", ")", "{", "global", "$", "DB", ";", "$", "role", "=", "$", "DB", "->", "get_record", "(", "'role'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "role", ")", ")", ";", "if", "(", "!", "$", "role", ")", "{", "return", "'['", ".", "get_string", "(", "'roleidnotfound'", ",", "'completion'", ",", "$", "this", "->", "role", ")", ".", "']'", ";", "}", "return", "role_get_name", "(", "$", "role", ",", "context_course", "::", "instance", "(", "$", "this", "->", "course", ")", ")", ";", "}" ]
Return criteria title for display in reports @return string
[ "Return", "criteria", "title", "for", "display", "in", "reports" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/criteria/completion_criteria_role.php#L123-L130
211,833
moodle/moodle
cache/stores/mongodb/MongoDB/Operation/Delete.php
Delete.createDeleteOptions
private function createDeleteOptions() { $deleteOptions = ['limit' => $this->limit]; if (isset($this->options['collation'])) { $deleteOptions['collation'] = (object) $this->options['collation']; } return $deleteOptions; }
php
private function createDeleteOptions() { $deleteOptions = ['limit' => $this->limit]; if (isset($this->options['collation'])) { $deleteOptions['collation'] = (object) $this->options['collation']; } return $deleteOptions; }
[ "private", "function", "createDeleteOptions", "(", ")", "{", "$", "deleteOptions", "=", "[", "'limit'", "=>", "$", "this", "->", "limit", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'collation'", "]", ")", ")", "{", "$", "deleteOptions", "[", "'collation'", "]", "=", "(", "object", ")", "$", "this", "->", "options", "[", "'collation'", "]", ";", "}", "return", "$", "deleteOptions", ";", "}" ]
Create options for the delete command. Note that these options are different from the bulk write options, which are created in createExecuteOptions(). @return array
[ "Create", "options", "for", "the", "delete", "command", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Operation/Delete.php#L147-L156
211,834
moodle/moodle
cache/stores/mongodb/MongoDB/Operation/Delete.php
Delete.createExecuteOptions
private function createExecuteOptions() { $options = []; if (isset($this->options['session'])) { $options['session'] = $this->options['session']; } if (isset($this->options['writeConcern'])) { $options['writeConcern'] = $this->options['writeConcern']; } return $options; }
php
private function createExecuteOptions() { $options = []; if (isset($this->options['session'])) { $options['session'] = $this->options['session']; } if (isset($this->options['writeConcern'])) { $options['writeConcern'] = $this->options['writeConcern']; } return $options; }
[ "private", "function", "createExecuteOptions", "(", ")", "{", "$", "options", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'session'", "]", ")", ")", "{", "$", "options", "[", "'session'", "]", "=", "$", "this", "->", "options", "[", "'session'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'writeConcern'", "]", ")", ")", "{", "$", "options", "[", "'writeConcern'", "]", "=", "$", "this", "->", "options", "[", "'writeConcern'", "]", ";", "}", "return", "$", "options", ";", "}" ]
Create options for executing the bulk write. @see http://php.net/manual/en/mongodb-driver-server.executebulkwrite.php @return array
[ "Create", "options", "for", "executing", "the", "bulk", "write", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Operation/Delete.php#L164-L177
211,835
moodle/moodle
competency/classes/template_cohort.php
template_cohort.get_missing_plans
public static function get_missing_plans($templateid, $cohortid, $unlinkedaremissing = false) { global $DB; $skipsql = ''; $skipparams = array(); if (!$unlinkedaremissing) { $skipsql = 'OR p.origtemplateid = :origtemplateid'; $skipparams = array('origtemplateid' => $templateid); } $sql = "SELECT cm.userid FROM {cohort_members} cm LEFT JOIN {" . plan::TABLE . "} p ON p.userid = cm.userid AND (p.templateid = :templateid $skipsql) WHERE cm.cohortid = :cohortid AND p.id IS NULL"; $params = array('templateid' => $templateid, 'cohortid' => $cohortid) + $skipparams; return $DB->get_fieldset_sql($sql, $params); }
php
public static function get_missing_plans($templateid, $cohortid, $unlinkedaremissing = false) { global $DB; $skipsql = ''; $skipparams = array(); if (!$unlinkedaremissing) { $skipsql = 'OR p.origtemplateid = :origtemplateid'; $skipparams = array('origtemplateid' => $templateid); } $sql = "SELECT cm.userid FROM {cohort_members} cm LEFT JOIN {" . plan::TABLE . "} p ON p.userid = cm.userid AND (p.templateid = :templateid $skipsql) WHERE cm.cohortid = :cohortid AND p.id IS NULL"; $params = array('templateid' => $templateid, 'cohortid' => $cohortid) + $skipparams; return $DB->get_fieldset_sql($sql, $params); }
[ "public", "static", "function", "get_missing_plans", "(", "$", "templateid", ",", "$", "cohortid", ",", "$", "unlinkedaremissing", "=", "false", ")", "{", "global", "$", "DB", ";", "$", "skipsql", "=", "''", ";", "$", "skipparams", "=", "array", "(", ")", ";", "if", "(", "!", "$", "unlinkedaremissing", ")", "{", "$", "skipsql", "=", "'OR p.origtemplateid = :origtemplateid'", ";", "$", "skipparams", "=", "array", "(", "'origtemplateid'", "=>", "$", "templateid", ")", ";", "}", "$", "sql", "=", "\"SELECT cm.userid\n FROM {cohort_members} cm\n LEFT JOIN {\"", ".", "plan", "::", "TABLE", ".", "\"} p\n ON p.userid = cm.userid\n AND (p.templateid = :templateid\n $skipsql)\n WHERE cm.cohortid = :cohortid\n AND p.id IS NULL\"", ";", "$", "params", "=", "array", "(", "'templateid'", "=>", "$", "templateid", ",", "'cohortid'", "=>", "$", "cohortid", ")", "+", "$", "skipparams", ";", "return", "$", "DB", "->", "get_fieldset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Return an array of user IDs for which the plans are missing. Plans are considered as missing when a member of a cohort does not have a plan created. When the parameter $unlinkedaremissing is set to false, plans that were unlinked from their template will be ignored so that we do not recreate unlinked plans endlessly. This method ignores the due date of the template. @param int $templateid The template ID. @param int $cohortid The cohort ID. @param boolean $unlinkedaremissing When true, unlinked plans are considered as missing. @return int[] User IDs.
[ "Return", "an", "array", "of", "user", "IDs", "for", "which", "the", "plans", "are", "missing", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/template_cohort.php#L102-L123
211,836
moodle/moodle
competency/classes/template_cohort.php
template_cohort.get_relations_by_templateid
public static function get_relations_by_templateid($templateid) { global $DB; $params = array( 'templateid' => $templateid ); $relations = array(); $records = $DB->get_records(self::TABLE, $params); foreach ($records as $record) { $relations[] = new template_cohort(0, $record); } return $relations; }
php
public static function get_relations_by_templateid($templateid) { global $DB; $params = array( 'templateid' => $templateid ); $relations = array(); $records = $DB->get_records(self::TABLE, $params); foreach ($records as $record) { $relations[] = new template_cohort(0, $record); } return $relations; }
[ "public", "static", "function", "get_relations_by_templateid", "(", "$", "templateid", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", "'templateid'", "=>", "$", "templateid", ")", ";", "$", "relations", "=", "array", "(", ")", ";", "$", "records", "=", "$", "DB", "->", "get_records", "(", "self", "::", "TABLE", ",", "$", "params", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "relations", "[", "]", "=", "new", "template_cohort", "(", "0", ",", "$", "record", ")", ";", "}", "return", "$", "relations", ";", "}" ]
Get a relations by templateid. This does not perform any validation on the data passed. If the relation exists in the database then it is loaded in a the model, if not then it is up to the developer to save the model. @param int $templateid @return template_cohort[] array of template cohort
[ "Get", "a", "relations", "by", "templateid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/template_cohort.php#L160-L174
211,837
moodle/moodle
competency/classes/template_cohort.php
template_cohort.get_all_missing_plans
public static function get_all_missing_plans($lastruntime = 0, $unlinkedaremissing = false) { global $DB; $planwhereclause = " WHERE (p.id is NULL AND (cm.timeadded >= :lastruntime1 OR tc.timecreated >= :lastruntime3 OR t.timemodified >= :lastruntime4))"; if ($unlinkedaremissing) { $planwhereclause .= " OR (p.origtemplateid IS NOT NULL AND cm.timeadded < :lastruntime2)"; } $sql = "SELECT " . $DB->sql_concat('cm.userid', 'tc.templateid') . " as uniqueid, cm.userid, t.* FROM {cohort_members} cm JOIN {" . self::TABLE . "} tc ON cm.cohortid = tc.cohortid JOIN {" . template::TABLE . "} t ON (tc.templateid = t.id AND t.visible = 1) AND (t.duedate = 0 OR t.duedate > :time1) LEFT JOIN {" . plan::TABLE . "} p ON (cm.userid = p.userid AND (t.id = p.templateid OR t.id = p.origtemplateid)) $planwhereclause ORDER BY t.id"; $params = array('time1' => time(), 'time2' => time(), 'lastruntime1' => $lastruntime, 'lastruntime2' => $lastruntime, 'lastruntime3' => $lastruntime, 'lastruntime4' => $lastruntime); $results = $DB->get_records_sql($sql, $params); $missingplans = array(); foreach ($results as $usertemplate) { $userid = $usertemplate->userid; // Check if template already exist in the array. if (isset($missingplans[$usertemplate->id])) { $missingplans[$usertemplate->id]['userids'][] = $userid; } else { unset($usertemplate->userid); unset($usertemplate->uniqueid); $template = new template(0, $usertemplate); $missingplans[$template->get('id')]['template'] = $template; $missingplans[$template->get('id')]['userids'][] = $userid; } } return array_values($missingplans); }
php
public static function get_all_missing_plans($lastruntime = 0, $unlinkedaremissing = false) { global $DB; $planwhereclause = " WHERE (p.id is NULL AND (cm.timeadded >= :lastruntime1 OR tc.timecreated >= :lastruntime3 OR t.timemodified >= :lastruntime4))"; if ($unlinkedaremissing) { $planwhereclause .= " OR (p.origtemplateid IS NOT NULL AND cm.timeadded < :lastruntime2)"; } $sql = "SELECT " . $DB->sql_concat('cm.userid', 'tc.templateid') . " as uniqueid, cm.userid, t.* FROM {cohort_members} cm JOIN {" . self::TABLE . "} tc ON cm.cohortid = tc.cohortid JOIN {" . template::TABLE . "} t ON (tc.templateid = t.id AND t.visible = 1) AND (t.duedate = 0 OR t.duedate > :time1) LEFT JOIN {" . plan::TABLE . "} p ON (cm.userid = p.userid AND (t.id = p.templateid OR t.id = p.origtemplateid)) $planwhereclause ORDER BY t.id"; $params = array('time1' => time(), 'time2' => time(), 'lastruntime1' => $lastruntime, 'lastruntime2' => $lastruntime, 'lastruntime3' => $lastruntime, 'lastruntime4' => $lastruntime); $results = $DB->get_records_sql($sql, $params); $missingplans = array(); foreach ($results as $usertemplate) { $userid = $usertemplate->userid; // Check if template already exist in the array. if (isset($missingplans[$usertemplate->id])) { $missingplans[$usertemplate->id]['userids'][] = $userid; } else { unset($usertemplate->userid); unset($usertemplate->uniqueid); $template = new template(0, $usertemplate); $missingplans[$template->get('id')]['template'] = $template; $missingplans[$template->get('id')]['userids'][] = $userid; } } return array_values($missingplans); }
[ "public", "static", "function", "get_all_missing_plans", "(", "$", "lastruntime", "=", "0", ",", "$", "unlinkedaremissing", "=", "false", ")", "{", "global", "$", "DB", ";", "$", "planwhereclause", "=", "\" WHERE (p.id is NULL\n AND (cm.timeadded >= :lastruntime1\n OR tc.timecreated >= :lastruntime3\n OR t.timemodified >= :lastruntime4))\"", ";", "if", "(", "$", "unlinkedaremissing", ")", "{", "$", "planwhereclause", ".=", "\" OR (p.origtemplateid IS NOT NULL AND cm.timeadded < :lastruntime2)\"", ";", "}", "$", "sql", "=", "\"SELECT \"", ".", "$", "DB", "->", "sql_concat", "(", "'cm.userid'", ",", "'tc.templateid'", ")", ".", "\" as uniqueid, cm.userid, t.*\n FROM {cohort_members} cm\n JOIN {\"", ".", "self", "::", "TABLE", ".", "\"} tc ON cm.cohortid = tc.cohortid\n JOIN {\"", ".", "template", "::", "TABLE", ".", "\"} t\n ON (tc.templateid = t.id AND t.visible = 1)\n AND (t.duedate = 0 OR t.duedate > :time1)\n LEFT JOIN {\"", ".", "plan", "::", "TABLE", ".", "\"} p ON (cm.userid = p.userid AND (t.id = p.templateid OR t.id = p.origtemplateid))\n $planwhereclause\n ORDER BY t.id\"", ";", "$", "params", "=", "array", "(", "'time1'", "=>", "time", "(", ")", ",", "'time2'", "=>", "time", "(", ")", ",", "'lastruntime1'", "=>", "$", "lastruntime", ",", "'lastruntime2'", "=>", "$", "lastruntime", ",", "'lastruntime3'", "=>", "$", "lastruntime", ",", "'lastruntime4'", "=>", "$", "lastruntime", ")", ";", "$", "results", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "missingplans", "=", "array", "(", ")", ";", "foreach", "(", "$", "results", "as", "$", "usertemplate", ")", "{", "$", "userid", "=", "$", "usertemplate", "->", "userid", ";", "// Check if template already exist in the array.", "if", "(", "isset", "(", "$", "missingplans", "[", "$", "usertemplate", "->", "id", "]", ")", ")", "{", "$", "missingplans", "[", "$", "usertemplate", "->", "id", "]", "[", "'userids'", "]", "[", "]", "=", "$", "userid", ";", "}", "else", "{", "unset", "(", "$", "usertemplate", "->", "userid", ")", ";", "unset", "(", "$", "usertemplate", "->", "uniqueid", ")", ";", "$", "template", "=", "new", "template", "(", "0", ",", "$", "usertemplate", ")", ";", "$", "missingplans", "[", "$", "template", "->", "get", "(", "'id'", ")", "]", "[", "'template'", "]", "=", "$", "template", ";", "$", "missingplans", "[", "$", "template", "->", "get", "(", "'id'", ")", "]", "[", "'userids'", "]", "[", "]", "=", "$", "userid", ";", "}", "}", "return", "array_values", "(", "$", "missingplans", ")", ";", "}" ]
Return an array of templates persistent with their missing userids. Note that only cohorts associated with visible templates are considered, as well as only templates with a due date in the future, or no due date. @param int $lastruntime The last time the Cohort ssync task ran. @param bool $unlinkedaremissing When true, unlinked plans are considered as missing. @return array( array( 'template' => \core_competency\template, 'userids' => array ))
[ "Return", "an", "array", "of", "templates", "persistent", "with", "their", "missing", "userids", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/template_cohort.php#L189-L232
211,838
moodle/moodle
admin/tool/dataprivacy/classes/purpose_override.php
purpose_override.get_overrides_for_purpose
public static function get_overrides_for_purpose(purpose $purpose) : array { $cache = \cache::make('tool_dataprivacy', 'purpose_overrides'); $overrides = []; $alldata = $cache->get($purpose->get('id')); if (false === $alldata) { $tocache = []; foreach (self::get_records(['purposeid' => $purpose->get('id')]) as $override) { $tocache[] = $override->to_record(); $overrides[$override->get('roleid')] = $override; } $cache->set($purpose->get('id'), $tocache); } else { foreach ($alldata as $data) { $override = new self(0, $data); $overrides[$override->get('roleid')] = $override; } } return $overrides; }
php
public static function get_overrides_for_purpose(purpose $purpose) : array { $cache = \cache::make('tool_dataprivacy', 'purpose_overrides'); $overrides = []; $alldata = $cache->get($purpose->get('id')); if (false === $alldata) { $tocache = []; foreach (self::get_records(['purposeid' => $purpose->get('id')]) as $override) { $tocache[] = $override->to_record(); $overrides[$override->get('roleid')] = $override; } $cache->set($purpose->get('id'), $tocache); } else { foreach ($alldata as $data) { $override = new self(0, $data); $overrides[$override->get('roleid')] = $override; } } return $overrides; }
[ "public", "static", "function", "get_overrides_for_purpose", "(", "purpose", "$", "purpose", ")", ":", "array", "{", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'tool_dataprivacy'", ",", "'purpose_overrides'", ")", ";", "$", "overrides", "=", "[", "]", ";", "$", "alldata", "=", "$", "cache", "->", "get", "(", "$", "purpose", "->", "get", "(", "'id'", ")", ")", ";", "if", "(", "false", "===", "$", "alldata", ")", "{", "$", "tocache", "=", "[", "]", ";", "foreach", "(", "self", "::", "get_records", "(", "[", "'purposeid'", "=>", "$", "purpose", "->", "get", "(", "'id'", ")", "]", ")", "as", "$", "override", ")", "{", "$", "tocache", "[", "]", "=", "$", "override", "->", "to_record", "(", ")", ";", "$", "overrides", "[", "$", "override", "->", "get", "(", "'roleid'", ")", "]", "=", "$", "override", ";", "}", "$", "cache", "->", "set", "(", "$", "purpose", "->", "get", "(", "'id'", ")", ",", "$", "tocache", ")", ";", "}", "else", "{", "foreach", "(", "$", "alldata", "as", "$", "data", ")", "{", "$", "override", "=", "new", "self", "(", "0", ",", "$", "data", ")", ";", "$", "overrides", "[", "$", "override", "->", "get", "(", "'roleid'", ")", "]", "=", "$", "override", ";", "}", "}", "return", "$", "overrides", ";", "}" ]
Get all role overrides for the purpose. @param purpose $purpose @return array
[ "Get", "all", "role", "overrides", "for", "the", "purpose", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/purpose_override.php#L91-L111
211,839
moodle/moodle
lib/simplepie/library/SimplePie/Cache/Memcached.php
SimplePie_Cache_Memcached.setData
private function setData($data) { if ($data !== false) { $this->cache->set($this->name . '_mtime', time(), (int)$this->options['extras']['timeout']); return $this->cache->set($this->name, $data, (int)$this->options['extras']['timeout']); } return false; }
php
private function setData($data) { if ($data !== false) { $this->cache->set($this->name . '_mtime', time(), (int)$this->options['extras']['timeout']); return $this->cache->set($this->name, $data, (int)$this->options['extras']['timeout']); } return false; }
[ "private", "function", "setData", "(", "$", "data", ")", "{", "if", "(", "$", "data", "!==", "false", ")", "{", "$", "this", "->", "cache", "->", "set", "(", "$", "this", "->", "name", ".", "'_mtime'", ",", "time", "(", ")", ",", "(", "int", ")", "$", "this", "->", "options", "[", "'extras'", "]", "[", "'timeout'", "]", ")", ";", "return", "$", "this", "->", "cache", "->", "set", "(", "$", "this", "->", "name", ",", "$", "data", ",", "(", "int", ")", "$", "this", "->", "options", "[", "'extras'", "]", "[", "'timeout'", "]", ")", ";", "}", "return", "false", ";", "}" ]
Set the last modified time and data to Memcached @return bool Success status
[ "Set", "the", "last", "modified", "time", "and", "data", "to", "Memcached" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Cache/Memcached.php#L157-L165
211,840
moodle/moodle
message/output/jabber/message_output_jabber.php
message_output_jabber.send_message
function send_message($eventdata){ global $CFG; // Skip any messaging of suspended and deleted users. if ($eventdata->userto->auth === 'nologin' or $eventdata->userto->suspended or $eventdata->userto->deleted) { return true; } if (!empty($CFG->noemailever)) { // hidden setting for development sites, set in config.php if needed debugging('$CFG->noemailever is active, no jabber message sent.', DEBUG_MINIMAL); return true; } if (PHPUNIT_TEST) { // No connection to external servers allowed in phpunit tests. return true; } //hold onto jabber id preference because /admin/cron.php sends a lot of messages at once static $jabberaddresses = array(); if (!array_key_exists($eventdata->userto->id, $jabberaddresses)) { $jabberaddresses[$eventdata->userto->id] = get_user_preferences('message_processor_jabber_jabberid', null, $eventdata->userto->id); } $jabberaddress = $jabberaddresses[$eventdata->userto->id]; //calling s() on smallmessage causes Jabber to display things like &lt; Jabber != a browser $jabbermessage = fullname($eventdata->userfrom).': '.$eventdata->smallmessage; if (!empty($eventdata->contexturl)) { $jabbermessage .= "\n".get_string('view').': '.$eventdata->contexturl; } $jabbermessage .= "\n(".get_string('noreply','message').')'; $conn = new XMPPHP_XMPP($CFG->jabberhost,$CFG->jabberport,$CFG->jabberusername,$CFG->jabberpassword,'moodle',$CFG->jabberserver); // No need to track the presence during the sending message process. $conn->track_presence = false; try { //$conn->useEncryption(false); $conn->connect(); $conn->processUntil('session_start'); $conn->presence(); $conn->message($jabberaddress, $jabbermessage); $conn->disconnect(); } catch(XMPPHP_Exception $e) { debugging($e->getMessage()); return false; } return true; }
php
function send_message($eventdata){ global $CFG; // Skip any messaging of suspended and deleted users. if ($eventdata->userto->auth === 'nologin' or $eventdata->userto->suspended or $eventdata->userto->deleted) { return true; } if (!empty($CFG->noemailever)) { // hidden setting for development sites, set in config.php if needed debugging('$CFG->noemailever is active, no jabber message sent.', DEBUG_MINIMAL); return true; } if (PHPUNIT_TEST) { // No connection to external servers allowed in phpunit tests. return true; } //hold onto jabber id preference because /admin/cron.php sends a lot of messages at once static $jabberaddresses = array(); if (!array_key_exists($eventdata->userto->id, $jabberaddresses)) { $jabberaddresses[$eventdata->userto->id] = get_user_preferences('message_processor_jabber_jabberid', null, $eventdata->userto->id); } $jabberaddress = $jabberaddresses[$eventdata->userto->id]; //calling s() on smallmessage causes Jabber to display things like &lt; Jabber != a browser $jabbermessage = fullname($eventdata->userfrom).': '.$eventdata->smallmessage; if (!empty($eventdata->contexturl)) { $jabbermessage .= "\n".get_string('view').': '.$eventdata->contexturl; } $jabbermessage .= "\n(".get_string('noreply','message').')'; $conn = new XMPPHP_XMPP($CFG->jabberhost,$CFG->jabberport,$CFG->jabberusername,$CFG->jabberpassword,'moodle',$CFG->jabberserver); // No need to track the presence during the sending message process. $conn->track_presence = false; try { //$conn->useEncryption(false); $conn->connect(); $conn->processUntil('session_start'); $conn->presence(); $conn->message($jabberaddress, $jabbermessage); $conn->disconnect(); } catch(XMPPHP_Exception $e) { debugging($e->getMessage()); return false; } return true; }
[ "function", "send_message", "(", "$", "eventdata", ")", "{", "global", "$", "CFG", ";", "// Skip any messaging of suspended and deleted users.", "if", "(", "$", "eventdata", "->", "userto", "->", "auth", "===", "'nologin'", "or", "$", "eventdata", "->", "userto", "->", "suspended", "or", "$", "eventdata", "->", "userto", "->", "deleted", ")", "{", "return", "true", ";", "}", "if", "(", "!", "empty", "(", "$", "CFG", "->", "noemailever", ")", ")", "{", "// hidden setting for development sites, set in config.php if needed", "debugging", "(", "'$CFG->noemailever is active, no jabber message sent.'", ",", "DEBUG_MINIMAL", ")", ";", "return", "true", ";", "}", "if", "(", "PHPUNIT_TEST", ")", "{", "// No connection to external servers allowed in phpunit tests.", "return", "true", ";", "}", "//hold onto jabber id preference because /admin/cron.php sends a lot of messages at once", "static", "$", "jabberaddresses", "=", "array", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "eventdata", "->", "userto", "->", "id", ",", "$", "jabberaddresses", ")", ")", "{", "$", "jabberaddresses", "[", "$", "eventdata", "->", "userto", "->", "id", "]", "=", "get_user_preferences", "(", "'message_processor_jabber_jabberid'", ",", "null", ",", "$", "eventdata", "->", "userto", "->", "id", ")", ";", "}", "$", "jabberaddress", "=", "$", "jabberaddresses", "[", "$", "eventdata", "->", "userto", "->", "id", "]", ";", "//calling s() on smallmessage causes Jabber to display things like &lt; Jabber != a browser", "$", "jabbermessage", "=", "fullname", "(", "$", "eventdata", "->", "userfrom", ")", ".", "': '", ".", "$", "eventdata", "->", "smallmessage", ";", "if", "(", "!", "empty", "(", "$", "eventdata", "->", "contexturl", ")", ")", "{", "$", "jabbermessage", ".=", "\"\\n\"", ".", "get_string", "(", "'view'", ")", ".", "': '", ".", "$", "eventdata", "->", "contexturl", ";", "}", "$", "jabbermessage", ".=", "\"\\n(\"", ".", "get_string", "(", "'noreply'", ",", "'message'", ")", ".", "')'", ";", "$", "conn", "=", "new", "XMPPHP_XMPP", "(", "$", "CFG", "->", "jabberhost", ",", "$", "CFG", "->", "jabberport", ",", "$", "CFG", "->", "jabberusername", ",", "$", "CFG", "->", "jabberpassword", ",", "'moodle'", ",", "$", "CFG", "->", "jabberserver", ")", ";", "// No need to track the presence during the sending message process.", "$", "conn", "->", "track_presence", "=", "false", ";", "try", "{", "//$conn->useEncryption(false);", "$", "conn", "->", "connect", "(", ")", ";", "$", "conn", "->", "processUntil", "(", "'session_start'", ")", ";", "$", "conn", "->", "presence", "(", ")", ";", "$", "conn", "->", "message", "(", "$", "jabberaddress", ",", "$", "jabbermessage", ")", ";", "$", "conn", "->", "disconnect", "(", ")", ";", "}", "catch", "(", "XMPPHP_Exception", "$", "e", ")", "{", "debugging", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
Processes the message and sends a notification via jabber @param stdClass $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid @return true if ok, false if error
[ "Processes", "the", "message", "and", "sends", "a", "notification", "via", "jabber" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/output/jabber/message_output_jabber.php#L43-L96
211,841
moodle/moodle
message/output/jabber/message_output_jabber.php
message_output_jabber.is_system_configured
function is_system_configured() { global $CFG; return (!empty($CFG->jabberhost) && !empty($CFG->jabberport) && !empty($CFG->jabberusername) && !empty($CFG->jabberpassword)); }
php
function is_system_configured() { global $CFG; return (!empty($CFG->jabberhost) && !empty($CFG->jabberport) && !empty($CFG->jabberusername) && !empty($CFG->jabberpassword)); }
[ "function", "is_system_configured", "(", ")", "{", "global", "$", "CFG", ";", "return", "(", "!", "empty", "(", "$", "CFG", "->", "jabberhost", ")", "&&", "!", "empty", "(", "$", "CFG", "->", "jabberport", ")", "&&", "!", "empty", "(", "$", "CFG", "->", "jabberusername", ")", "&&", "!", "empty", "(", "$", "CFG", "->", "jabberpassword", ")", ")", ";", "}" ]
Tests whether the Jabber settings have been configured @return boolean true if Jabber is configured
[ "Tests", "whether", "the", "Jabber", "settings", "have", "been", "configured" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/output/jabber/message_output_jabber.php#L139-L142
211,842
moodle/moodle
message/output/jabber/message_output_jabber.php
message_output_jabber.is_user_configured
function is_user_configured($user = null) { global $USER; if (is_null($user)) { $user = $USER; } return (bool)get_user_preferences('message_processor_jabber_jabberid', null, $user->id); }
php
function is_user_configured($user = null) { global $USER; if (is_null($user)) { $user = $USER; } return (bool)get_user_preferences('message_processor_jabber_jabberid', null, $user->id); }
[ "function", "is_user_configured", "(", "$", "user", "=", "null", ")", "{", "global", "$", "USER", ";", "if", "(", "is_null", "(", "$", "user", ")", ")", "{", "$", "user", "=", "$", "USER", ";", "}", "return", "(", "bool", ")", "get_user_preferences", "(", "'message_processor_jabber_jabberid'", ",", "null", ",", "$", "user", "->", "id", ")", ";", "}" ]
Tests whether the Jabber settings have been configured on user level @param object $user the user object, defaults to $USER. @return bool has the user made all the necessary settings in their profile to allow this plugin to be used.
[ "Tests", "whether", "the", "Jabber", "settings", "have", "been", "configured", "on", "user", "level" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/output/jabber/message_output_jabber.php#L150-L157
211,843
moodle/moodle
lib/classes/form/persistent.php
persistent.after_definition
protected function after_definition() { parent::after_definition(); $mform = $this->_form; $class = static::$persistentclass; $properties = $class::properties_definition(); foreach ($mform->_elements as $element) { $name = $element->getName(); if (isset($mform->_types[$name])) { // We already have a PARAM_* type for this field. continue; } else if (!isset($properties[$name]) || in_array($name, static::$fieldstoremove) || in_array($name, static::$foreignfields)) { // Ignoring foreign and unknown fields. continue; } // Set the type on the element. switch ($element->getType()) { case 'hidden': case 'text': case 'url': $mform->setType($name, $properties[$name]['type']); break; } } }
php
protected function after_definition() { parent::after_definition(); $mform = $this->_form; $class = static::$persistentclass; $properties = $class::properties_definition(); foreach ($mform->_elements as $element) { $name = $element->getName(); if (isset($mform->_types[$name])) { // We already have a PARAM_* type for this field. continue; } else if (!isset($properties[$name]) || in_array($name, static::$fieldstoremove) || in_array($name, static::$foreignfields)) { // Ignoring foreign and unknown fields. continue; } // Set the type on the element. switch ($element->getType()) { case 'hidden': case 'text': case 'url': $mform->setType($name, $properties[$name]['type']); break; } } }
[ "protected", "function", "after_definition", "(", ")", "{", "parent", "::", "after_definition", "(", ")", ";", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "class", "=", "static", "::", "$", "persistentclass", ";", "$", "properties", "=", "$", "class", "::", "properties_definition", "(", ")", ";", "foreach", "(", "$", "mform", "->", "_elements", "as", "$", "element", ")", "{", "$", "name", "=", "$", "element", "->", "getName", "(", ")", ";", "if", "(", "isset", "(", "$", "mform", "->", "_types", "[", "$", "name", "]", ")", ")", "{", "// We already have a PARAM_* type for this field.", "continue", ";", "}", "else", "if", "(", "!", "isset", "(", "$", "properties", "[", "$", "name", "]", ")", "||", "in_array", "(", "$", "name", ",", "static", "::", "$", "fieldstoremove", ")", "||", "in_array", "(", "$", "name", ",", "static", "::", "$", "foreignfields", ")", ")", "{", "// Ignoring foreign and unknown fields.", "continue", ";", "}", "// Set the type on the element.", "switch", "(", "$", "element", "->", "getType", "(", ")", ")", "{", "case", "'hidden'", ":", "case", "'text'", ":", "case", "'url'", ":", "$", "mform", "->", "setType", "(", "$", "name", ",", "$", "properties", "[", "$", "name", "]", "[", "'type'", "]", ")", ";", "break", ";", "}", "}", "}" ]
After definition hook. Automatically try to set the types of simple fields using the persistent properties definition. This only applies to hidden, text and url types. Groups are also ignored as they are most likely custom. @return void
[ "After", "definition", "hook", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/form/persistent.php#L146-L175
211,844
moodle/moodle
lib/classes/form/persistent.php
persistent.get_data
public function get_data() { $data = parent::get_data(); if (is_object($data)) { foreach (static::$fieldstoremove as $field) { unset($data->{$field}); } $data = static::convert_fields($data); // Ensure that the ID is set. $data->id = $this->persistent->get('id'); } return $data; }
php
public function get_data() { $data = parent::get_data(); if (is_object($data)) { foreach (static::$fieldstoremove as $field) { unset($data->{$field}); } $data = static::convert_fields($data); // Ensure that the ID is set. $data->id = $this->persistent->get('id'); } return $data; }
[ "public", "function", "get_data", "(", ")", "{", "$", "data", "=", "parent", "::", "get_data", "(", ")", ";", "if", "(", "is_object", "(", "$", "data", ")", ")", "{", "foreach", "(", "static", "::", "$", "fieldstoremove", "as", "$", "field", ")", "{", "unset", "(", "$", "data", "->", "{", "$", "field", "}", ")", ";", "}", "$", "data", "=", "static", "::", "convert_fields", "(", "$", "data", ")", ";", "// Ensure that the ID is set.", "$", "data", "->", "id", "=", "$", "this", "->", "persistent", "->", "get", "(", "'id'", ")", ";", "}", "return", "$", "data", ";", "}" ]
Get form data. Conveniently removes non-desired properties and add the ID property. @return object|null
[ "Get", "form", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/form/persistent.php#L254-L266
211,845
moodle/moodle
lib/classes/form/persistent.php
persistent.get_submitted_data
public function get_submitted_data() { $data = parent::get_submitted_data(); if (is_object($data)) { foreach (static::$fieldstoremove as $field) { unset($data->{$field}); } $data = static::convert_fields($data); } return $data; }
php
public function get_submitted_data() { $data = parent::get_submitted_data(); if (is_object($data)) { foreach (static::$fieldstoremove as $field) { unset($data->{$field}); } $data = static::convert_fields($data); } return $data; }
[ "public", "function", "get_submitted_data", "(", ")", "{", "$", "data", "=", "parent", "::", "get_submitted_data", "(", ")", ";", "if", "(", "is_object", "(", "$", "data", ")", ")", "{", "foreach", "(", "static", "::", "$", "fieldstoremove", "as", "$", "field", ")", "{", "unset", "(", "$", "data", "->", "{", "$", "field", "}", ")", ";", "}", "$", "data", "=", "static", "::", "convert_fields", "(", "$", "data", ")", ";", "}", "return", "$", "data", ";", "}" ]
Get the submitted form data. Conveniently removes non-desired properties. @return object|null
[ "Get", "the", "submitted", "form", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/form/persistent.php#L284-L293
211,846
moodle/moodle
competency/classes/user_competency_plan.php
user_competency_plan.create_relation
public static function create_relation($userid, $competencyid, $planid) { $relation = new user_competency_plan(0, (object) array('userid' => $userid, 'competencyid' => $competencyid, 'planid' => $planid)); return $relation; }
php
public static function create_relation($userid, $competencyid, $planid) { $relation = new user_competency_plan(0, (object) array('userid' => $userid, 'competencyid' => $competencyid, 'planid' => $planid)); return $relation; }
[ "public", "static", "function", "create_relation", "(", "$", "userid", ",", "$", "competencyid", ",", "$", "planid", ")", "{", "$", "relation", "=", "new", "user_competency_plan", "(", "0", ",", "(", "object", ")", "array", "(", "'userid'", "=>", "$", "userid", ",", "'competencyid'", "=>", "$", "competencyid", ",", "'planid'", "=>", "$", "planid", ")", ")", ";", "return", "$", "relation", ";", "}" ]
Create a new user_competency_plan object. Note, this is intended to be used to create a blank relation, for instance when the record was not found in the database. This does not save the model. @param int $userid The user ID. @param int $competencyid The competency ID. @param int $planid The plan ID. @return \core_competency\user_competency_plan
[ "Create", "a", "new", "user_competency_plan", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency_plan.php#L170-L174
211,847
moodle/moodle
competency/classes/user_competency_plan.php
user_competency_plan.list_competencies
public static function list_competencies($planid, $userid) { global $DB; $sql = 'SELECT c.* FROM {' . competency::TABLE . '} c JOIN {' . self::TABLE . '} ucp ON ucp.competencyid = c.id AND ucp.userid = :userid WHERE ucp.planid = :planid ORDER BY ucp.sortorder ASC, ucp.id ASC'; $params = array('userid' => $userid, 'planid' => $planid); $results = $DB->get_recordset_sql($sql, $params); $instances = array(); foreach ($results as $key => $result) { $instances[$key] = new competency(0, $result); } $results->close(); return $instances; }
php
public static function list_competencies($planid, $userid) { global $DB; $sql = 'SELECT c.* FROM {' . competency::TABLE . '} c JOIN {' . self::TABLE . '} ucp ON ucp.competencyid = c.id AND ucp.userid = :userid WHERE ucp.planid = :planid ORDER BY ucp.sortorder ASC, ucp.id ASC'; $params = array('userid' => $userid, 'planid' => $planid); $results = $DB->get_recordset_sql($sql, $params); $instances = array(); foreach ($results as $key => $result) { $instances[$key] = new competency(0, $result); } $results->close(); return $instances; }
[ "public", "static", "function", "list_competencies", "(", "$", "planid", ",", "$", "userid", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "'SELECT c.*\n FROM {'", ".", "competency", "::", "TABLE", ".", "'} c\n JOIN {'", ".", "self", "::", "TABLE", ".", "'} ucp\n ON ucp.competencyid = c.id\n AND ucp.userid = :userid\n WHERE ucp.planid = :planid\n ORDER BY ucp.sortorder ASC,\n ucp.id ASC'", ";", "$", "params", "=", "array", "(", "'userid'", "=>", "$", "userid", ",", "'planid'", "=>", "$", "planid", ")", ";", "$", "results", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "instances", "=", "array", "(", ")", ";", "foreach", "(", "$", "results", "as", "$", "key", "=>", "$", "result", ")", "{", "$", "instances", "[", "$", "key", "]", "=", "new", "competency", "(", "0", ",", "$", "result", ")", ";", "}", "$", "results", "->", "close", "(", ")", ";", "return", "$", "instances", ";", "}" ]
List the competencies in this plan. @param int $planid The plan ID @param int $userid The user ID @return competency[]
[ "List", "the", "competencies", "in", "this", "plan", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency_plan.php#L183-L204
211,848
moodle/moodle
competency/classes/user_competency_plan.php
user_competency_plan.get_competency_by_planid
public static function get_competency_by_planid($planid, $competencyid) { global $DB; $sql = "SELECT c.* FROM {" . self::TABLE . "} ucp JOIN {" . competency::TABLE . "} c ON c.id = ucp.competencyid WHERE ucp.planid = ? AND ucp.competencyid = ?"; $record = $DB->get_record_sql($sql, array($planid, $competencyid)); if (!$record) { throw new \coding_exception('The competency does not belong to this plan: ' . $competencyid . ', ' . $planid); } return new competency(0, $record); }
php
public static function get_competency_by_planid($planid, $competencyid) { global $DB; $sql = "SELECT c.* FROM {" . self::TABLE . "} ucp JOIN {" . competency::TABLE . "} c ON c.id = ucp.competencyid WHERE ucp.planid = ? AND ucp.competencyid = ?"; $record = $DB->get_record_sql($sql, array($planid, $competencyid)); if (!$record) { throw new \coding_exception('The competency does not belong to this plan: ' . $competencyid . ', ' . $planid); } return new competency(0, $record); }
[ "public", "static", "function", "get_competency_by_planid", "(", "$", "planid", ",", "$", "competencyid", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT c.*\n FROM {\"", ".", "self", "::", "TABLE", ".", "\"} ucp\n JOIN {\"", ".", "competency", "::", "TABLE", ".", "\"} c\n ON c.id = ucp.competencyid\n WHERE ucp.planid = ?\n AND ucp.competencyid = ?\"", ";", "$", "record", "=", "$", "DB", "->", "get_record_sql", "(", "$", "sql", ",", "array", "(", "$", "planid", ",", "$", "competencyid", ")", ")", ";", "if", "(", "!", "$", "record", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'The competency does not belong to this plan: '", ".", "$", "competencyid", ".", "', '", ".", "$", "planid", ")", ";", "}", "return", "new", "competency", "(", "0", ",", "$", "record", ")", ";", "}" ]
Fetch a competency by plan ID. @param int $id The plan ID. @return competency
[ "Fetch", "a", "competency", "by", "plan", "ID", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency_plan.php#L212-L228
211,849
moodle/moodle
competency/classes/user_competency_plan.php
user_competency_plan.has_records_for_competencies
public static function has_records_for_competencies($competencyids) { global $DB; list($insql, $params) = $DB->get_in_or_equal($competencyids, SQL_PARAMS_NAMED); return self::record_exists_select("competencyid $insql", $params); }
php
public static function has_records_for_competencies($competencyids) { global $DB; list($insql, $params) = $DB->get_in_or_equal($competencyids, SQL_PARAMS_NAMED); return self::record_exists_select("competencyid $insql", $params); }
[ "public", "static", "function", "has_records_for_competencies", "(", "$", "competencyids", ")", "{", "global", "$", "DB", ";", "list", "(", "$", "insql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "competencyids", ",", "SQL_PARAMS_NAMED", ")", ";", "return", "self", "::", "record_exists_select", "(", "\"competencyid $insql\"", ",", "$", "params", ")", ";", "}" ]
Check if user competency plan has records for competencies. @param array $competencyids The competences IDs @return boolean
[ "Check", "if", "user", "competency", "plan", "has", "records", "for", "competencies", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency_plan.php#L301-L305
211,850
moodle/moodle
competency/classes/user_competency_plan.php
user_competency_plan.count_records_for_template
public static function count_records_for_template($templateid, $proficiency=null) { global $DB; $params = array('templateid' => $templateid); $sql = 'SELECT ' . " COUNT('x') " . 'FROM {' . self::TABLE . '} ucp JOIN {' . plan::TABLE . '} p ON ucp.planid = p.id WHERE p.templateid = :templateid'; if ($proficiency === true) { $sql .= ' AND ucp.proficiency = :proficiency'; $params['proficiency'] = true; } else if ($proficiency === false) { $sql .= ' AND (ucp.proficiency = :proficiency OR ucp.proficiency IS NULL)'; $params['proficiency'] = false; } return $DB->count_records_sql($sql, $params); }
php
public static function count_records_for_template($templateid, $proficiency=null) { global $DB; $params = array('templateid' => $templateid); $sql = 'SELECT ' . " COUNT('x') " . 'FROM {' . self::TABLE . '} ucp JOIN {' . plan::TABLE . '} p ON ucp.planid = p.id WHERE p.templateid = :templateid'; if ($proficiency === true) { $sql .= ' AND ucp.proficiency = :proficiency'; $params['proficiency'] = true; } else if ($proficiency === false) { $sql .= ' AND (ucp.proficiency = :proficiency OR ucp.proficiency IS NULL)'; $params['proficiency'] = false; } return $DB->count_records_sql($sql, $params); }
[ "public", "static", "function", "count_records_for_template", "(", "$", "templateid", ",", "$", "proficiency", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", "'templateid'", "=>", "$", "templateid", ")", ";", "$", "sql", "=", "'SELECT '", ".", "\" COUNT('x') \"", ".", "'FROM {'", ".", "self", "::", "TABLE", ".", "'} ucp\n JOIN {'", ".", "plan", "::", "TABLE", ".", "'} p\n ON ucp.planid = p.id\n WHERE p.templateid = :templateid'", ";", "if", "(", "$", "proficiency", "===", "true", ")", "{", "$", "sql", ".=", "' AND ucp.proficiency = :proficiency'", ";", "$", "params", "[", "'proficiency'", "]", "=", "true", ";", "}", "else", "if", "(", "$", "proficiency", "===", "false", ")", "{", "$", "sql", ".=", "' AND (ucp.proficiency = :proficiency OR ucp.proficiency IS NULL)'", ";", "$", "params", "[", "'proficiency'", "]", "=", "false", ";", "}", "return", "$", "DB", "->", "count_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Count the number of records matching a specific template, optionally filtered by proficient values. @param int $templateid @param mixed $proficiency - If true - filter by proficiency, if false filter by not proficient, if null - do not filter. @return int
[ "Count", "the", "number", "of", "records", "matching", "a", "specific", "template", "optionally", "filtered", "by", "proficient", "values", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency_plan.php#L314-L332
211,851
moodle/moodle
lib/phpexcel/PHPExcel/Shared/Escher/DgContainer/SpgrContainer/SpContainer.php
PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer.getOPT
public function getOPT($property) { if (isset($this->OPT[$property])) { return $this->OPT[$property]; } return null; }
php
public function getOPT($property) { if (isset($this->OPT[$property])) { return $this->OPT[$property]; } return null; }
[ "public", "function", "getOPT", "(", "$", "property", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "OPT", "[", "$", "property", "]", ")", ")", "{", "return", "$", "this", "->", "OPT", "[", "$", "property", "]", ";", "}", "return", "null", ";", "}" ]
Get an option for the Shape Group Container @param int $property The number specifies the option @return mixed
[ "Get", "an", "option", "for", "the", "Shape", "Group", "Container" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/Escher/DgContainer/SpgrContainer/SpContainer.php#L231-L237
211,852
moodle/moodle
lib/phpexcel/PHPExcel/Shared/Escher/DgContainer/SpgrContainer/SpContainer.php
PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer.getNestingLevel
public function getNestingLevel() { $nestingLevel = 0; $parent = $this->getParent(); while ($parent instanceof PHPExcel_Shared_Escher_DgContainer_SpgrContainer) { ++$nestingLevel; $parent = $parent->getParent(); } return $nestingLevel; }
php
public function getNestingLevel() { $nestingLevel = 0; $parent = $this->getParent(); while ($parent instanceof PHPExcel_Shared_Escher_DgContainer_SpgrContainer) { ++$nestingLevel; $parent = $parent->getParent(); } return $nestingLevel; }
[ "public", "function", "getNestingLevel", "(", ")", "{", "$", "nestingLevel", "=", "0", ";", "$", "parent", "=", "$", "this", "->", "getParent", "(", ")", ";", "while", "(", "$", "parent", "instanceof", "PHPExcel_Shared_Escher_DgContainer_SpgrContainer", ")", "{", "++", "$", "nestingLevel", ";", "$", "parent", "=", "$", "parent", "->", "getParent", "(", ")", ";", "}", "return", "$", "nestingLevel", ";", "}" ]
Get the nesting level of this spContainer. This is the number of spgrContainers between this spContainer and the dgContainer. A value of 1 = immediately within first spgrContainer Higher nesting level occurs if and only if spContainer is part of a shape group @return int Nesting level
[ "Get", "the", "nesting", "level", "of", "this", "spContainer", ".", "This", "is", "the", "number", "of", "spgrContainers", "between", "this", "spContainer", "and", "the", "dgContainer", ".", "A", "value", "of", "1", "=", "immediately", "within", "first", "spgrContainer", "Higher", "nesting", "level", "occurs", "if", "and", "only", "if", "spContainer", "is", "part", "of", "a", "shape", "group" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/Escher/DgContainer/SpgrContainer/SpContainer.php#L376-L387
211,853
moodle/moodle
lib/adodb/datadict/datadict-postgres.inc.php
ADODB2_postgres.AddColumnSQL
function AddColumnSQL($tabname, $flds) { $tabname = $this->TableName ($tabname); $sql = array(); $not_null = false; list($lines,$pkey) = $this->_GenFields($flds); $alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' '; foreach($lines as $v) { if (($not_null = preg_match('/NOT NULL/i',$v))) { $v = preg_replace('/NOT NULL/i','',$v); } if (preg_match('/^([^ ]+) .*DEFAULT (\'[^\']+\'|\"[^\"]+\"|[^ ]+)/',$v,$matches)) { list(,$colname,$default) = $matches; $sql[] = $alter . str_replace('DEFAULT '.$default,'',$v); $sql[] = 'UPDATE '.$tabname.' SET '.$colname.'='.$default; $sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET DEFAULT ' . $default; } else { $sql[] = $alter . $v; } if ($not_null) { list($colname) = explode(' ',$v); $sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET NOT NULL'; } } return $sql; }
php
function AddColumnSQL($tabname, $flds) { $tabname = $this->TableName ($tabname); $sql = array(); $not_null = false; list($lines,$pkey) = $this->_GenFields($flds); $alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' '; foreach($lines as $v) { if (($not_null = preg_match('/NOT NULL/i',$v))) { $v = preg_replace('/NOT NULL/i','',$v); } if (preg_match('/^([^ ]+) .*DEFAULT (\'[^\']+\'|\"[^\"]+\"|[^ ]+)/',$v,$matches)) { list(,$colname,$default) = $matches; $sql[] = $alter . str_replace('DEFAULT '.$default,'',$v); $sql[] = 'UPDATE '.$tabname.' SET '.$colname.'='.$default; $sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET DEFAULT ' . $default; } else { $sql[] = $alter . $v; } if ($not_null) { list($colname) = explode(' ',$v); $sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET NOT NULL'; } } return $sql; }
[ "function", "AddColumnSQL", "(", "$", "tabname", ",", "$", "flds", ")", "{", "$", "tabname", "=", "$", "this", "->", "TableName", "(", "$", "tabname", ")", ";", "$", "sql", "=", "array", "(", ")", ";", "$", "not_null", "=", "false", ";", "list", "(", "$", "lines", ",", "$", "pkey", ")", "=", "$", "this", "->", "_GenFields", "(", "$", "flds", ")", ";", "$", "alter", "=", "'ALTER TABLE '", ".", "$", "tabname", ".", "$", "this", "->", "addCol", ".", "' '", ";", "foreach", "(", "$", "lines", "as", "$", "v", ")", "{", "if", "(", "(", "$", "not_null", "=", "preg_match", "(", "'/NOT NULL/i'", ",", "$", "v", ")", ")", ")", "{", "$", "v", "=", "preg_replace", "(", "'/NOT NULL/i'", ",", "''", ",", "$", "v", ")", ";", "}", "if", "(", "preg_match", "(", "'/^([^ ]+) .*DEFAULT (\\'[^\\']+\\'|\\\"[^\\\"]+\\\"|[^ ]+)/'", ",", "$", "v", ",", "$", "matches", ")", ")", "{", "list", "(", ",", "$", "colname", ",", "$", "default", ")", "=", "$", "matches", ";", "$", "sql", "[", "]", "=", "$", "alter", ".", "str_replace", "(", "'DEFAULT '", ".", "$", "default", ",", "''", ",", "$", "v", ")", ";", "$", "sql", "[", "]", "=", "'UPDATE '", ".", "$", "tabname", ".", "' SET '", ".", "$", "colname", ".", "'='", ".", "$", "default", ";", "$", "sql", "[", "]", "=", "'ALTER TABLE '", ".", "$", "tabname", ".", "' ALTER COLUMN '", ".", "$", "colname", ".", "' SET DEFAULT '", ".", "$", "default", ";", "}", "else", "{", "$", "sql", "[", "]", "=", "$", "alter", ".", "$", "v", ";", "}", "if", "(", "$", "not_null", ")", "{", "list", "(", "$", "colname", ")", "=", "explode", "(", "' '", ",", "$", "v", ")", ";", "$", "sql", "[", "]", "=", "'ALTER TABLE '", ".", "$", "tabname", ".", "' ALTER COLUMN '", ".", "$", "colname", ".", "' SET NOT NULL'", ";", "}", "}", "return", "$", "sql", ";", "}" ]
Adding a new Column reimplementation of the default function as postgres does NOT allow to set the default in the same statement @param string $tabname table-name @param string $flds column-names and types for the changed columns @return array with SQL strings
[ "Adding", "a", "new", "Column" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/datadict/datadict-postgres.inc.php#L131-L156
211,854
moodle/moodle
lib/adodb/datadict/datadict-postgres.inc.php
ADODB2_postgres._recreate_copy_table
function _recreate_copy_table($tabname,$dropflds,$tableflds,$tableoptions='') { if ($dropflds && !is_array($dropflds)) $dropflds = explode(',',$dropflds); $copyflds = array(); foreach($this->MetaColumns($tabname) as $fld) { if (!$dropflds || !in_array($fld->name,$dropflds)) { // we need to explicit convert varchar to a number to be able to do an AlterColumn of a char column to a nummeric one if (preg_match('/'.$fld->name.' (I|I2|I4|I8|N|F)/i',$tableflds,$matches) && in_array($fld->type,array('varchar','char','text','bytea'))) { $copyflds[] = "to_number($fld->name,'S9999999999999D99')"; } else { $copyflds[] = $fld->name; } // identify the sequence name and the fld its on if ($fld->primary_key && $fld->has_default && preg_match("/nextval\('([^']+)'::text\)/",$fld->default_value,$matches)) { $seq_name = $matches[1]; $seq_fld = $fld->name; } } } $copyflds = implode(', ',$copyflds); $tempname = $tabname.'_tmp'; $aSql[] = 'BEGIN'; // we use a transaction, to make sure not to loose the content of the table $aSql[] = "SELECT * INTO TEMPORARY TABLE $tempname FROM $tabname"; $aSql = array_merge($aSql,$this->DropTableSQL($tabname)); $aSql = array_merge($aSql,$this->CreateTableSQL($tabname,$tableflds,$tableoptions)); $aSql[] = "INSERT INTO $tabname SELECT $copyflds FROM $tempname"; if ($seq_name && $seq_fld) { // if we have a sequence we need to set it again $seq_name = $tabname.'_'.$seq_fld.'_seq'; // has to be the name of the new implicit sequence $aSql[] = "SELECT setval('$seq_name',MAX($seq_fld)) FROM $tabname"; } $aSql[] = "DROP TABLE $tempname"; // recreate the indexes, if they not contain one of the droped columns foreach($this->MetaIndexes($tabname) as $idx_name => $idx_data) { if (substr($idx_name,-5) != '_pkey' && (!$dropflds || !count(array_intersect($dropflds,$idx_data['columns'])))) { $aSql = array_merge($aSql,$this->CreateIndexSQL($idx_name,$tabname,$idx_data['columns'], $idx_data['unique'] ? array('UNIQUE') : False)); } } $aSql[] = 'COMMIT'; return $aSql; }
php
function _recreate_copy_table($tabname,$dropflds,$tableflds,$tableoptions='') { if ($dropflds && !is_array($dropflds)) $dropflds = explode(',',$dropflds); $copyflds = array(); foreach($this->MetaColumns($tabname) as $fld) { if (!$dropflds || !in_array($fld->name,$dropflds)) { // we need to explicit convert varchar to a number to be able to do an AlterColumn of a char column to a nummeric one if (preg_match('/'.$fld->name.' (I|I2|I4|I8|N|F)/i',$tableflds,$matches) && in_array($fld->type,array('varchar','char','text','bytea'))) { $copyflds[] = "to_number($fld->name,'S9999999999999D99')"; } else { $copyflds[] = $fld->name; } // identify the sequence name and the fld its on if ($fld->primary_key && $fld->has_default && preg_match("/nextval\('([^']+)'::text\)/",$fld->default_value,$matches)) { $seq_name = $matches[1]; $seq_fld = $fld->name; } } } $copyflds = implode(', ',$copyflds); $tempname = $tabname.'_tmp'; $aSql[] = 'BEGIN'; // we use a transaction, to make sure not to loose the content of the table $aSql[] = "SELECT * INTO TEMPORARY TABLE $tempname FROM $tabname"; $aSql = array_merge($aSql,$this->DropTableSQL($tabname)); $aSql = array_merge($aSql,$this->CreateTableSQL($tabname,$tableflds,$tableoptions)); $aSql[] = "INSERT INTO $tabname SELECT $copyflds FROM $tempname"; if ($seq_name && $seq_fld) { // if we have a sequence we need to set it again $seq_name = $tabname.'_'.$seq_fld.'_seq'; // has to be the name of the new implicit sequence $aSql[] = "SELECT setval('$seq_name',MAX($seq_fld)) FROM $tabname"; } $aSql[] = "DROP TABLE $tempname"; // recreate the indexes, if they not contain one of the droped columns foreach($this->MetaIndexes($tabname) as $idx_name => $idx_data) { if (substr($idx_name,-5) != '_pkey' && (!$dropflds || !count(array_intersect($dropflds,$idx_data['columns'])))) { $aSql = array_merge($aSql,$this->CreateIndexSQL($idx_name,$tabname,$idx_data['columns'], $idx_data['unique'] ? array('UNIQUE') : False)); } } $aSql[] = 'COMMIT'; return $aSql; }
[ "function", "_recreate_copy_table", "(", "$", "tabname", ",", "$", "dropflds", ",", "$", "tableflds", ",", "$", "tableoptions", "=", "''", ")", "{", "if", "(", "$", "dropflds", "&&", "!", "is_array", "(", "$", "dropflds", ")", ")", "$", "dropflds", "=", "explode", "(", "','", ",", "$", "dropflds", ")", ";", "$", "copyflds", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "MetaColumns", "(", "$", "tabname", ")", "as", "$", "fld", ")", "{", "if", "(", "!", "$", "dropflds", "||", "!", "in_array", "(", "$", "fld", "->", "name", ",", "$", "dropflds", ")", ")", "{", "// we need to explicit convert varchar to a number to be able to do an AlterColumn of a char column to a nummeric one", "if", "(", "preg_match", "(", "'/'", ".", "$", "fld", "->", "name", ".", "' (I|I2|I4|I8|N|F)/i'", ",", "$", "tableflds", ",", "$", "matches", ")", "&&", "in_array", "(", "$", "fld", "->", "type", ",", "array", "(", "'varchar'", ",", "'char'", ",", "'text'", ",", "'bytea'", ")", ")", ")", "{", "$", "copyflds", "[", "]", "=", "\"to_number($fld->name,'S9999999999999D99')\"", ";", "}", "else", "{", "$", "copyflds", "[", "]", "=", "$", "fld", "->", "name", ";", "}", "// identify the sequence name and the fld its on", "if", "(", "$", "fld", "->", "primary_key", "&&", "$", "fld", "->", "has_default", "&&", "preg_match", "(", "\"/nextval\\('([^']+)'::text\\)/\"", ",", "$", "fld", "->", "default_value", ",", "$", "matches", ")", ")", "{", "$", "seq_name", "=", "$", "matches", "[", "1", "]", ";", "$", "seq_fld", "=", "$", "fld", "->", "name", ";", "}", "}", "}", "$", "copyflds", "=", "implode", "(", "', '", ",", "$", "copyflds", ")", ";", "$", "tempname", "=", "$", "tabname", ".", "'_tmp'", ";", "$", "aSql", "[", "]", "=", "'BEGIN'", ";", "// we use a transaction, to make sure not to loose the content of the table", "$", "aSql", "[", "]", "=", "\"SELECT * INTO TEMPORARY TABLE $tempname FROM $tabname\"", ";", "$", "aSql", "=", "array_merge", "(", "$", "aSql", ",", "$", "this", "->", "DropTableSQL", "(", "$", "tabname", ")", ")", ";", "$", "aSql", "=", "array_merge", "(", "$", "aSql", ",", "$", "this", "->", "CreateTableSQL", "(", "$", "tabname", ",", "$", "tableflds", ",", "$", "tableoptions", ")", ")", ";", "$", "aSql", "[", "]", "=", "\"INSERT INTO $tabname SELECT $copyflds FROM $tempname\"", ";", "if", "(", "$", "seq_name", "&&", "$", "seq_fld", ")", "{", "// if we have a sequence we need to set it again", "$", "seq_name", "=", "$", "tabname", ".", "'_'", ".", "$", "seq_fld", ".", "'_seq'", ";", "// has to be the name of the new implicit sequence", "$", "aSql", "[", "]", "=", "\"SELECT setval('$seq_name',MAX($seq_fld)) FROM $tabname\"", ";", "}", "$", "aSql", "[", "]", "=", "\"DROP TABLE $tempname\"", ";", "// recreate the indexes, if they not contain one of the droped columns", "foreach", "(", "$", "this", "->", "MetaIndexes", "(", "$", "tabname", ")", "as", "$", "idx_name", "=>", "$", "idx_data", ")", "{", "if", "(", "substr", "(", "$", "idx_name", ",", "-", "5", ")", "!=", "'_pkey'", "&&", "(", "!", "$", "dropflds", "||", "!", "count", "(", "array_intersect", "(", "$", "dropflds", ",", "$", "idx_data", "[", "'columns'", "]", ")", ")", ")", ")", "{", "$", "aSql", "=", "array_merge", "(", "$", "aSql", ",", "$", "this", "->", "CreateIndexSQL", "(", "$", "idx_name", ",", "$", "tabname", ",", "$", "idx_data", "[", "'columns'", "]", ",", "$", "idx_data", "[", "'unique'", "]", "?", "array", "(", "'UNIQUE'", ")", ":", "False", ")", ")", ";", "}", "}", "$", "aSql", "[", "]", "=", "'COMMIT'", ";", "return", "$", "aSql", ";", "}" ]
Save the content into a temp. table, drop and recreate the original table and copy the content back in We also take care to set the values of the sequenz and recreate the indexes. All this is done in a transaction, to not loose the content of the table, if something went wrong! @internal @param string $tabname table-name @param string $dropflds column-names to drop @param string $tableflds complete defintion of the new table, eg. for postgres @param array/string $tableoptions options for the new table see CreateTableSQL, default '' @return array with SQL strings
[ "Save", "the", "content", "into", "a", "temp", ".", "table", "drop", "and", "recreate", "the", "original", "table", "and", "copy", "the", "content", "back", "in" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/datadict/datadict-postgres.inc.php#L310-L354
211,855
moodle/moodle
lib/adodb/datadict/datadict-postgres.inc.php
ADODB2_postgres._DropAutoIncrement
function _DropAutoIncrement($tabname) { $tabname = $this->connection->quote('%'.$tabname.'%'); $seq = $this->connection->GetOne("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relname LIKE $tabname AND relkind='S'"); // check if a tables depends on the sequenz and it therefor cant and dont need to be droped separatly if (!$seq || $this->connection->GetOne("SELECT relname FROM pg_class JOIN pg_depend ON pg_class.relfilenode=pg_depend.objid WHERE relname='$seq' AND relkind='S' AND deptype='i'")) { return False; } return "DROP SEQUENCE ".$seq; }
php
function _DropAutoIncrement($tabname) { $tabname = $this->connection->quote('%'.$tabname.'%'); $seq = $this->connection->GetOne("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relname LIKE $tabname AND relkind='S'"); // check if a tables depends on the sequenz and it therefor cant and dont need to be droped separatly if (!$seq || $this->connection->GetOne("SELECT relname FROM pg_class JOIN pg_depend ON pg_class.relfilenode=pg_depend.objid WHERE relname='$seq' AND relkind='S' AND deptype='i'")) { return False; } return "DROP SEQUENCE ".$seq; }
[ "function", "_DropAutoIncrement", "(", "$", "tabname", ")", "{", "$", "tabname", "=", "$", "this", "->", "connection", "->", "quote", "(", "'%'", ".", "$", "tabname", ".", "'%'", ")", ";", "$", "seq", "=", "$", "this", "->", "connection", "->", "GetOne", "(", "\"SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relname LIKE $tabname AND relkind='S'\"", ")", ";", "// check if a tables depends on the sequenz and it therefor cant and dont need to be droped separatly", "if", "(", "!", "$", "seq", "||", "$", "this", "->", "connection", "->", "GetOne", "(", "\"SELECT relname FROM pg_class JOIN pg_depend ON pg_class.relfilenode=pg_depend.objid WHERE relname='$seq' AND relkind='S' AND deptype='i'\"", ")", ")", "{", "return", "False", ";", "}", "return", "\"DROP SEQUENCE \"", ".", "$", "seq", ";", "}" ]
this is still necessary if postgres < 7.3 or the SERIAL was created on an earlier version!!!
[ "this", "is", "still", "necessary", "if", "postgres", "<", "7", ".", "3", "or", "the", "SERIAL", "was", "created", "on", "an", "earlier", "version!!!" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/datadict/datadict-postgres.inc.php#L383-L394
211,856
moodle/moodle
mod/forum/classes/local/exporters/post.php
post.get_message
private function get_message(post_entity $post) : string { global $CFG; $message = $post->get_message(); if (!empty($CFG->enableplagiarism)) { require_once($CFG->libdir . '/plagiarismlib.php'); $forum = $this->related['forum']; $message .= plagiarism_get_links([ 'userid' => $post->get_author_id(), 'content' => $message, 'cmid' => $forum->get_course_module_record()->id, 'course' => $forum->get_course_id(), 'forum' => $forum->get_id() ]); } return $message; }
php
private function get_message(post_entity $post) : string { global $CFG; $message = $post->get_message(); if (!empty($CFG->enableplagiarism)) { require_once($CFG->libdir . '/plagiarismlib.php'); $forum = $this->related['forum']; $message .= plagiarism_get_links([ 'userid' => $post->get_author_id(), 'content' => $message, 'cmid' => $forum->get_course_module_record()->id, 'course' => $forum->get_course_id(), 'forum' => $forum->get_id() ]); } return $message; }
[ "private", "function", "get_message", "(", "post_entity", "$", "post", ")", ":", "string", "{", "global", "$", "CFG", ";", "$", "message", "=", "$", "post", "->", "get_message", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "enableplagiarism", ")", ")", "{", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/plagiarismlib.php'", ")", ";", "$", "forum", "=", "$", "this", "->", "related", "[", "'forum'", "]", ";", "$", "message", ".=", "plagiarism_get_links", "(", "[", "'userid'", "=>", "$", "post", "->", "get_author_id", "(", ")", ",", "'content'", "=>", "$", "message", ",", "'cmid'", "=>", "$", "forum", "->", "get_course_module_record", "(", ")", "->", "id", ",", "'course'", "=>", "$", "forum", "->", "get_course_id", "(", ")", ",", "'forum'", "=>", "$", "forum", "->", "get_id", "(", ")", "]", ")", ";", "}", "return", "$", "message", ";", "}" ]
Get the message text from a post. @param post_entity $post The post @return string
[ "Get", "the", "message", "text", "from", "a", "post", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/exporters/post.php#L493-L511
211,857
moodle/moodle
mod/forum/classes/local/exporters/post.php
post.export_attachments
private function export_attachments(array $attachments, post_entity $post, renderer_base $output, bool $canexport) : array { global $CFG; $urlfactory = $this->related['urlfactory']; $enableplagiarism = $CFG->enableplagiarism; $forum = $this->related['forum']; $context = $this->related['context']; if ($enableplagiarism) { require_once($CFG->libdir . '/plagiarismlib.php' ); } return array_map(function($attachment) use ( $output, $enableplagiarism, $canexport, $context, $forum, $post, $urlfactory ) { $exporter = new stored_file_exporter($attachment, ['context' => $context]); $exportedattachment = $exporter->export($output); $exporturl = $canexport ? $urlfactory->get_export_attachment_url_from_post_and_attachment($post, $attachment) : null; if ($enableplagiarism) { $plagiarismhtml = plagiarism_get_links([ 'userid' => $post->get_author_id(), 'file' => $attachment, 'cmid' => $forum->get_course_module_record()->id, 'course' => $forum->get_course_id(), 'forum' => $forum->get_id() ]); } else { $plagiarismhtml = null; } $exportedattachment->urls = [ 'export' => $exporturl ? $exporturl->out(false) : null ]; $exportedattachment->html = [ 'plagiarism' => $plagiarismhtml ]; return $exportedattachment; }, $attachments); }
php
private function export_attachments(array $attachments, post_entity $post, renderer_base $output, bool $canexport) : array { global $CFG; $urlfactory = $this->related['urlfactory']; $enableplagiarism = $CFG->enableplagiarism; $forum = $this->related['forum']; $context = $this->related['context']; if ($enableplagiarism) { require_once($CFG->libdir . '/plagiarismlib.php' ); } return array_map(function($attachment) use ( $output, $enableplagiarism, $canexport, $context, $forum, $post, $urlfactory ) { $exporter = new stored_file_exporter($attachment, ['context' => $context]); $exportedattachment = $exporter->export($output); $exporturl = $canexport ? $urlfactory->get_export_attachment_url_from_post_and_attachment($post, $attachment) : null; if ($enableplagiarism) { $plagiarismhtml = plagiarism_get_links([ 'userid' => $post->get_author_id(), 'file' => $attachment, 'cmid' => $forum->get_course_module_record()->id, 'course' => $forum->get_course_id(), 'forum' => $forum->get_id() ]); } else { $plagiarismhtml = null; } $exportedattachment->urls = [ 'export' => $exporturl ? $exporturl->out(false) : null ]; $exportedattachment->html = [ 'plagiarism' => $plagiarismhtml ]; return $exportedattachment; }, $attachments); }
[ "private", "function", "export_attachments", "(", "array", "$", "attachments", ",", "post_entity", "$", "post", ",", "renderer_base", "$", "output", ",", "bool", "$", "canexport", ")", ":", "array", "{", "global", "$", "CFG", ";", "$", "urlfactory", "=", "$", "this", "->", "related", "[", "'urlfactory'", "]", ";", "$", "enableplagiarism", "=", "$", "CFG", "->", "enableplagiarism", ";", "$", "forum", "=", "$", "this", "->", "related", "[", "'forum'", "]", ";", "$", "context", "=", "$", "this", "->", "related", "[", "'context'", "]", ";", "if", "(", "$", "enableplagiarism", ")", "{", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/plagiarismlib.php'", ")", ";", "}", "return", "array_map", "(", "function", "(", "$", "attachment", ")", "use", "(", "$", "output", ",", "$", "enableplagiarism", ",", "$", "canexport", ",", "$", "context", ",", "$", "forum", ",", "$", "post", ",", "$", "urlfactory", ")", "{", "$", "exporter", "=", "new", "stored_file_exporter", "(", "$", "attachment", ",", "[", "'context'", "=>", "$", "context", "]", ")", ";", "$", "exportedattachment", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "$", "exporturl", "=", "$", "canexport", "?", "$", "urlfactory", "->", "get_export_attachment_url_from_post_and_attachment", "(", "$", "post", ",", "$", "attachment", ")", ":", "null", ";", "if", "(", "$", "enableplagiarism", ")", "{", "$", "plagiarismhtml", "=", "plagiarism_get_links", "(", "[", "'userid'", "=>", "$", "post", "->", "get_author_id", "(", ")", ",", "'file'", "=>", "$", "attachment", ",", "'cmid'", "=>", "$", "forum", "->", "get_course_module_record", "(", ")", "->", "id", ",", "'course'", "=>", "$", "forum", "->", "get_course_id", "(", ")", ",", "'forum'", "=>", "$", "forum", "->", "get_id", "(", ")", "]", ")", ";", "}", "else", "{", "$", "plagiarismhtml", "=", "null", ";", "}", "$", "exportedattachment", "->", "urls", "=", "[", "'export'", "=>", "$", "exporturl", "?", "$", "exporturl", "->", "out", "(", "false", ")", ":", "null", "]", ";", "$", "exportedattachment", "->", "html", "=", "[", "'plagiarism'", "=>", "$", "plagiarismhtml", "]", ";", "return", "$", "exportedattachment", ";", "}", ",", "$", "attachments", ")", ";", "}" ]
Get the exported attachments for a post. @param stored_file[] $attachments The list of attachments for the post @param post_entity $post The post being exported @param renderer_base $output Renderer base @param bool $canexport If the user can export the post (relates to portfolios not exporters like this class) @return array
[ "Get", "the", "exported", "attachments", "for", "a", "post", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/exporters/post.php#L522-L568
211,858
moodle/moodle
mod/forum/classes/local/exporters/post.php
post.export_tags
private function export_tags(array $tags) : array { $user = $this->related['user']; $context = $this->related['context']; $capabilitymanager = $this->related['capabilitymanager']; $canmanagetags = $capabilitymanager->can_manage_tags($user); return array_values(array_map(function($tag) use ($context, $canmanagetags) { $viewurl = core_tag_tag::make_url($tag->tagcollid, $tag->rawname, 0, $context->id); return [ 'id' => $tag->taginstanceid, 'tagid' => $tag->id, 'isstandard' => $tag->isstandard, 'displayname' => $tag->get_display_name(), 'flag' => $canmanagetags && !empty($tag->flag), 'urls' => [ 'view' => $viewurl->out(false) ] ]; }, $tags)); }
php
private function export_tags(array $tags) : array { $user = $this->related['user']; $context = $this->related['context']; $capabilitymanager = $this->related['capabilitymanager']; $canmanagetags = $capabilitymanager->can_manage_tags($user); return array_values(array_map(function($tag) use ($context, $canmanagetags) { $viewurl = core_tag_tag::make_url($tag->tagcollid, $tag->rawname, 0, $context->id); return [ 'id' => $tag->taginstanceid, 'tagid' => $tag->id, 'isstandard' => $tag->isstandard, 'displayname' => $tag->get_display_name(), 'flag' => $canmanagetags && !empty($tag->flag), 'urls' => [ 'view' => $viewurl->out(false) ] ]; }, $tags)); }
[ "private", "function", "export_tags", "(", "array", "$", "tags", ")", ":", "array", "{", "$", "user", "=", "$", "this", "->", "related", "[", "'user'", "]", ";", "$", "context", "=", "$", "this", "->", "related", "[", "'context'", "]", ";", "$", "capabilitymanager", "=", "$", "this", "->", "related", "[", "'capabilitymanager'", "]", ";", "$", "canmanagetags", "=", "$", "capabilitymanager", "->", "can_manage_tags", "(", "$", "user", ")", ";", "return", "array_values", "(", "array_map", "(", "function", "(", "$", "tag", ")", "use", "(", "$", "context", ",", "$", "canmanagetags", ")", "{", "$", "viewurl", "=", "core_tag_tag", "::", "make_url", "(", "$", "tag", "->", "tagcollid", ",", "$", "tag", "->", "rawname", ",", "0", ",", "$", "context", "->", "id", ")", ";", "return", "[", "'id'", "=>", "$", "tag", "->", "taginstanceid", ",", "'tagid'", "=>", "$", "tag", "->", "id", ",", "'isstandard'", "=>", "$", "tag", "->", "isstandard", ",", "'displayname'", "=>", "$", "tag", "->", "get_display_name", "(", ")", ",", "'flag'", "=>", "$", "canmanagetags", "&&", "!", "empty", "(", "$", "tag", "->", "flag", ")", ",", "'urls'", "=>", "[", "'view'", "=>", "$", "viewurl", "->", "out", "(", "false", ")", "]", "]", ";", "}", ",", "$", "tags", ")", ")", ";", "}" ]
Export the list of tags. @param core_tag_tag[] $tags List of tags to export @return array
[ "Export", "the", "list", "of", "tags", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/exporters/post.php#L576-L595
211,859
moodle/moodle
mod/forum/classes/local/exporters/post.php
post.get_author_subheading_html
private function get_author_subheading_html(stdClass $exportedauthor, int $timecreated) : string { $fullname = $exportedauthor->fullname; $profileurl = $exportedauthor->urls['profile'] ?? null; $formatteddate = userdate($timecreated, get_string('strftimedaydatetime', 'core_langconfig')); $name = $profileurl ? "<a href=\"{$profileurl}\">{$fullname}</a>" : $fullname; $date = "<time>{$formatteddate}</time>"; return get_string('bynameondate', 'mod_forum', ['name' => $name, 'date' => $date]); }
php
private function get_author_subheading_html(stdClass $exportedauthor, int $timecreated) : string { $fullname = $exportedauthor->fullname; $profileurl = $exportedauthor->urls['profile'] ?? null; $formatteddate = userdate($timecreated, get_string('strftimedaydatetime', 'core_langconfig')); $name = $profileurl ? "<a href=\"{$profileurl}\">{$fullname}</a>" : $fullname; $date = "<time>{$formatteddate}</time>"; return get_string('bynameondate', 'mod_forum', ['name' => $name, 'date' => $date]); }
[ "private", "function", "get_author_subheading_html", "(", "stdClass", "$", "exportedauthor", ",", "int", "$", "timecreated", ")", ":", "string", "{", "$", "fullname", "=", "$", "exportedauthor", "->", "fullname", ";", "$", "profileurl", "=", "$", "exportedauthor", "->", "urls", "[", "'profile'", "]", "??", "null", ";", "$", "formatteddate", "=", "userdate", "(", "$", "timecreated", ",", "get_string", "(", "'strftimedaydatetime'", ",", "'core_langconfig'", ")", ")", ";", "$", "name", "=", "$", "profileurl", "?", "\"<a href=\\\"{$profileurl}\\\">{$fullname}</a>\"", ":", "$", "fullname", ";", "$", "date", "=", "\"<time>{$formatteddate}</time>\"", ";", "return", "get_string", "(", "'bynameondate'", ",", "'mod_forum'", ",", "[", "'name'", "=>", "$", "name", ",", "'date'", "=>", "$", "date", "]", ")", ";", "}" ]
Get the HTML to display as a subheading in a post. @param stdClass $exportedauthor The exported author object @param int $timecreated The post time created timestamp if it's to be displayed @return string
[ "Get", "the", "HTML", "to", "display", "as", "a", "subheading", "in", "a", "post", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/exporters/post.php#L604-L611
211,860
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.render_workshop_message
protected function render_workshop_message(workshop_message $message) { $text = $message->get_message(); $url = $message->get_action_url(); $label = $message->get_action_label(); if (empty($text) and empty($label)) { return ''; } switch ($message->get_type()) { case workshop_message::TYPE_OK: $sty = 'ok'; break; case workshop_message::TYPE_ERROR: $sty = 'error'; break; default: $sty = 'info'; } $o = html_writer::tag('span', $message->get_message()); if (!is_null($url) and !is_null($label)) { $o .= $this->output->single_button($url, $label, 'get'); } return $this->output->container($o, array('message', $sty)); }
php
protected function render_workshop_message(workshop_message $message) { $text = $message->get_message(); $url = $message->get_action_url(); $label = $message->get_action_label(); if (empty($text) and empty($label)) { return ''; } switch ($message->get_type()) { case workshop_message::TYPE_OK: $sty = 'ok'; break; case workshop_message::TYPE_ERROR: $sty = 'error'; break; default: $sty = 'info'; } $o = html_writer::tag('span', $message->get_message()); if (!is_null($url) and !is_null($label)) { $o .= $this->output->single_button($url, $label, 'get'); } return $this->output->container($o, array('message', $sty)); }
[ "protected", "function", "render_workshop_message", "(", "workshop_message", "$", "message", ")", "{", "$", "text", "=", "$", "message", "->", "get_message", "(", ")", ";", "$", "url", "=", "$", "message", "->", "get_action_url", "(", ")", ";", "$", "label", "=", "$", "message", "->", "get_action_label", "(", ")", ";", "if", "(", "empty", "(", "$", "text", ")", "and", "empty", "(", "$", "label", ")", ")", "{", "return", "''", ";", "}", "switch", "(", "$", "message", "->", "get_type", "(", ")", ")", "{", "case", "workshop_message", "::", "TYPE_OK", ":", "$", "sty", "=", "'ok'", ";", "break", ";", "case", "workshop_message", "::", "TYPE_ERROR", ":", "$", "sty", "=", "'error'", ";", "break", ";", "default", ":", "$", "sty", "=", "'info'", ";", "}", "$", "o", "=", "html_writer", "::", "tag", "(", "'span'", ",", "$", "message", "->", "get_message", "(", ")", ")", ";", "if", "(", "!", "is_null", "(", "$", "url", ")", "and", "!", "is_null", "(", "$", "label", ")", ")", "{", "$", "o", ".=", "$", "this", "->", "output", "->", "single_button", "(", "$", "url", ",", "$", "label", ",", "'get'", ")", ";", "}", "return", "$", "this", "->", "output", "->", "container", "(", "$", "o", ",", "array", "(", "'message'", ",", "$", "sty", ")", ")", ";", "}" ]
Renders workshop message @param workshop_message $message to display @return string html code
[ "Renders", "workshop", "message" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L46-L74
211,861
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.render_workshop_submission_summary
protected function render_workshop_submission_summary(workshop_submission_summary $summary) { $o = ''; // output HTML code $anonymous = $summary->is_anonymous(); $classes = 'submission-summary'; if ($anonymous) { $classes .= ' anonymous'; } $gradestatus = ''; if ($summary->status == 'notgraded') { $classes .= ' notgraded'; $gradestatus = $this->output->container(get_string('nogradeyet', 'workshop'), 'grade-status'); } else if ($summary->status == 'graded') { $classes .= ' graded'; $gradestatus = $this->output->container(get_string('alreadygraded', 'workshop'), 'grade-status'); } $o .= $this->output->container_start($classes); // main wrapper $o .= html_writer::link($summary->url, format_string($summary->title), array('class' => 'title')); if (!$anonymous) { $author = new stdClass(); $additionalfields = explode(',', user_picture::fields()); $author = username_load_fields_from_object($author, $summary, 'author', $additionalfields); $userpic = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 35)); $userurl = new moodle_url('/user/view.php', array('id' => $author->id, 'course' => $this->page->course->id)); $a = new stdClass(); $a->name = fullname($author); $a->url = $userurl->out(); $byfullname = get_string('byfullname', 'workshop', $a); $oo = $this->output->container($userpic, 'picture'); $oo .= $this->output->container($byfullname, 'fullname'); $o .= $this->output->container($oo, 'author'); } $created = get_string('userdatecreated', 'workshop', userdate($summary->timecreated)); $o .= $this->output->container($created, 'userdate created'); if ($summary->timemodified > $summary->timecreated) { $modified = get_string('userdatemodified', 'workshop', userdate($summary->timemodified)); $o .= $this->output->container($modified, 'userdate modified'); } $o .= $gradestatus; $o .= $this->output->container_end(); // end of the main wrapper return $o; }
php
protected function render_workshop_submission_summary(workshop_submission_summary $summary) { $o = ''; // output HTML code $anonymous = $summary->is_anonymous(); $classes = 'submission-summary'; if ($anonymous) { $classes .= ' anonymous'; } $gradestatus = ''; if ($summary->status == 'notgraded') { $classes .= ' notgraded'; $gradestatus = $this->output->container(get_string('nogradeyet', 'workshop'), 'grade-status'); } else if ($summary->status == 'graded') { $classes .= ' graded'; $gradestatus = $this->output->container(get_string('alreadygraded', 'workshop'), 'grade-status'); } $o .= $this->output->container_start($classes); // main wrapper $o .= html_writer::link($summary->url, format_string($summary->title), array('class' => 'title')); if (!$anonymous) { $author = new stdClass(); $additionalfields = explode(',', user_picture::fields()); $author = username_load_fields_from_object($author, $summary, 'author', $additionalfields); $userpic = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 35)); $userurl = new moodle_url('/user/view.php', array('id' => $author->id, 'course' => $this->page->course->id)); $a = new stdClass(); $a->name = fullname($author); $a->url = $userurl->out(); $byfullname = get_string('byfullname', 'workshop', $a); $oo = $this->output->container($userpic, 'picture'); $oo .= $this->output->container($byfullname, 'fullname'); $o .= $this->output->container($oo, 'author'); } $created = get_string('userdatecreated', 'workshop', userdate($summary->timecreated)); $o .= $this->output->container($created, 'userdate created'); if ($summary->timemodified > $summary->timecreated) { $modified = get_string('userdatemodified', 'workshop', userdate($summary->timemodified)); $o .= $this->output->container($modified, 'userdate modified'); } $o .= $gradestatus; $o .= $this->output->container_end(); // end of the main wrapper return $o; }
[ "protected", "function", "render_workshop_submission_summary", "(", "workshop_submission_summary", "$", "summary", ")", "{", "$", "o", "=", "''", ";", "// output HTML code", "$", "anonymous", "=", "$", "summary", "->", "is_anonymous", "(", ")", ";", "$", "classes", "=", "'submission-summary'", ";", "if", "(", "$", "anonymous", ")", "{", "$", "classes", ".=", "' anonymous'", ";", "}", "$", "gradestatus", "=", "''", ";", "if", "(", "$", "summary", "->", "status", "==", "'notgraded'", ")", "{", "$", "classes", ".=", "' notgraded'", ";", "$", "gradestatus", "=", "$", "this", "->", "output", "->", "container", "(", "get_string", "(", "'nogradeyet'", ",", "'workshop'", ")", ",", "'grade-status'", ")", ";", "}", "else", "if", "(", "$", "summary", "->", "status", "==", "'graded'", ")", "{", "$", "classes", ".=", "' graded'", ";", "$", "gradestatus", "=", "$", "this", "->", "output", "->", "container", "(", "get_string", "(", "'alreadygraded'", ",", "'workshop'", ")", ",", "'grade-status'", ")", ";", "}", "$", "o", ".=", "$", "this", "->", "output", "->", "container_start", "(", "$", "classes", ")", ";", "// main wrapper", "$", "o", ".=", "html_writer", "::", "link", "(", "$", "summary", "->", "url", ",", "format_string", "(", "$", "summary", "->", "title", ")", ",", "array", "(", "'class'", "=>", "'title'", ")", ")", ";", "if", "(", "!", "$", "anonymous", ")", "{", "$", "author", "=", "new", "stdClass", "(", ")", ";", "$", "additionalfields", "=", "explode", "(", "','", ",", "user_picture", "::", "fields", "(", ")", ")", ";", "$", "author", "=", "username_load_fields_from_object", "(", "$", "author", ",", "$", "summary", ",", "'author'", ",", "$", "additionalfields", ")", ";", "$", "userpic", "=", "$", "this", "->", "output", "->", "user_picture", "(", "$", "author", ",", "array", "(", "'courseid'", "=>", "$", "this", "->", "page", "->", "course", "->", "id", ",", "'size'", "=>", "35", ")", ")", ";", "$", "userurl", "=", "new", "moodle_url", "(", "'/user/view.php'", ",", "array", "(", "'id'", "=>", "$", "author", "->", "id", ",", "'course'", "=>", "$", "this", "->", "page", "->", "course", "->", "id", ")", ")", ";", "$", "a", "=", "new", "stdClass", "(", ")", ";", "$", "a", "->", "name", "=", "fullname", "(", "$", "author", ")", ";", "$", "a", "->", "url", "=", "$", "userurl", "->", "out", "(", ")", ";", "$", "byfullname", "=", "get_string", "(", "'byfullname'", ",", "'workshop'", ",", "$", "a", ")", ";", "$", "oo", "=", "$", "this", "->", "output", "->", "container", "(", "$", "userpic", ",", "'picture'", ")", ";", "$", "oo", ".=", "$", "this", "->", "output", "->", "container", "(", "$", "byfullname", ",", "'fullname'", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "$", "oo", ",", "'author'", ")", ";", "}", "$", "created", "=", "get_string", "(", "'userdatecreated'", ",", "'workshop'", ",", "userdate", "(", "$", "summary", "->", "timecreated", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "$", "created", ",", "'userdate created'", ")", ";", "if", "(", "$", "summary", "->", "timemodified", ">", "$", "summary", "->", "timecreated", ")", "{", "$", "modified", "=", "get_string", "(", "'userdatemodified'", ",", "'workshop'", ",", "userdate", "(", "$", "summary", "->", "timemodified", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "$", "modified", ",", "'userdate modified'", ")", ";", "}", "$", "o", ".=", "$", "gradestatus", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container_end", "(", ")", ";", "// end of the main wrapper", "return", "$", "o", ";", "}" ]
Renders short summary of the submission @param workshop_submission_summary $summary @return string text to be echo'ed
[ "Renders", "short", "summary", "of", "the", "submission" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L157-L209
211,862
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.render_workshop_example_submission
protected function render_workshop_example_submission(workshop_example_submission $example) { $o = ''; // output HTML code $classes = 'submission-full example'; $o .= $this->output->container_start($classes); $o .= $this->output->container_start('header'); $o .= $this->output->container(format_string($example->title), array('class' => 'title')); $o .= $this->output->container_end(); // end of header $content = file_rewrite_pluginfile_urls($example->content, 'pluginfile.php', $this->page->context->id, 'mod_workshop', 'submission_content', $example->id); $content = format_text($content, $example->contentformat, array('overflowdiv'=>true)); $o .= $this->output->container($content, 'content'); $o .= $this->helper_submission_attachments($example->id, 'html'); $o .= $this->output->container_end(); // end of submission-full return $o; }
php
protected function render_workshop_example_submission(workshop_example_submission $example) { $o = ''; // output HTML code $classes = 'submission-full example'; $o .= $this->output->container_start($classes); $o .= $this->output->container_start('header'); $o .= $this->output->container(format_string($example->title), array('class' => 'title')); $o .= $this->output->container_end(); // end of header $content = file_rewrite_pluginfile_urls($example->content, 'pluginfile.php', $this->page->context->id, 'mod_workshop', 'submission_content', $example->id); $content = format_text($content, $example->contentformat, array('overflowdiv'=>true)); $o .= $this->output->container($content, 'content'); $o .= $this->helper_submission_attachments($example->id, 'html'); $o .= $this->output->container_end(); // end of submission-full return $o; }
[ "protected", "function", "render_workshop_example_submission", "(", "workshop_example_submission", "$", "example", ")", "{", "$", "o", "=", "''", ";", "// output HTML code", "$", "classes", "=", "'submission-full example'", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container_start", "(", "$", "classes", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container_start", "(", "'header'", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "format_string", "(", "$", "example", "->", "title", ")", ",", "array", "(", "'class'", "=>", "'title'", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container_end", "(", ")", ";", "// end of header", "$", "content", "=", "file_rewrite_pluginfile_urls", "(", "$", "example", "->", "content", ",", "'pluginfile.php'", ",", "$", "this", "->", "page", "->", "context", "->", "id", ",", "'mod_workshop'", ",", "'submission_content'", ",", "$", "example", "->", "id", ")", ";", "$", "content", "=", "format_text", "(", "$", "content", ",", "$", "example", "->", "contentformat", ",", "array", "(", "'overflowdiv'", "=>", "true", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "$", "content", ",", "'content'", ")", ";", "$", "o", ".=", "$", "this", "->", "helper_submission_attachments", "(", "$", "example", "->", "id", ",", "'html'", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container_end", "(", ")", ";", "// end of submission-full", "return", "$", "o", ";", "}" ]
Renders full workshop example submission @param workshop_example_submission $example @return string HTML
[ "Renders", "full", "workshop", "example", "submission" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L217-L236
211,863
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.render_workshop_example_submission_summary
protected function render_workshop_example_submission_summary(workshop_example_submission_summary $summary) { $o = ''; // output HTML code // wrapping box $o .= $this->output->box_start('generalbox example-summary ' . $summary->status); // title $o .= $this->output->container_start('example-title'); $o .= html_writer::link($summary->url, format_string($summary->title), array('class' => 'title')); if ($summary->editable) { $o .= $this->output->action_icon($summary->editurl, new pix_icon('i/edit', get_string('edit'))); } $o .= $this->output->container_end(); // additional info if ($summary->status == 'notgraded') { $o .= $this->output->container(get_string('nogradeyet', 'workshop'), 'example-info nograde'); } else { $o .= $this->output->container(get_string('gradeinfo', 'workshop' , $summary->gradeinfo), 'example-info grade'); } // button to assess $button = new single_button($summary->assessurl, $summary->assesslabel, 'get'); $o .= $this->output->container($this->output->render($button), 'example-actions'); // end of wrapping box $o .= $this->output->box_end(); return $o; }
php
protected function render_workshop_example_submission_summary(workshop_example_submission_summary $summary) { $o = ''; // output HTML code // wrapping box $o .= $this->output->box_start('generalbox example-summary ' . $summary->status); // title $o .= $this->output->container_start('example-title'); $o .= html_writer::link($summary->url, format_string($summary->title), array('class' => 'title')); if ($summary->editable) { $o .= $this->output->action_icon($summary->editurl, new pix_icon('i/edit', get_string('edit'))); } $o .= $this->output->container_end(); // additional info if ($summary->status == 'notgraded') { $o .= $this->output->container(get_string('nogradeyet', 'workshop'), 'example-info nograde'); } else { $o .= $this->output->container(get_string('gradeinfo', 'workshop' , $summary->gradeinfo), 'example-info grade'); } // button to assess $button = new single_button($summary->assessurl, $summary->assesslabel, 'get'); $o .= $this->output->container($this->output->render($button), 'example-actions'); // end of wrapping box $o .= $this->output->box_end(); return $o; }
[ "protected", "function", "render_workshop_example_submission_summary", "(", "workshop_example_submission_summary", "$", "summary", ")", "{", "$", "o", "=", "''", ";", "// output HTML code", "// wrapping box", "$", "o", ".=", "$", "this", "->", "output", "->", "box_start", "(", "'generalbox example-summary '", ".", "$", "summary", "->", "status", ")", ";", "// title", "$", "o", ".=", "$", "this", "->", "output", "->", "container_start", "(", "'example-title'", ")", ";", "$", "o", ".=", "html_writer", "::", "link", "(", "$", "summary", "->", "url", ",", "format_string", "(", "$", "summary", "->", "title", ")", ",", "array", "(", "'class'", "=>", "'title'", ")", ")", ";", "if", "(", "$", "summary", "->", "editable", ")", "{", "$", "o", ".=", "$", "this", "->", "output", "->", "action_icon", "(", "$", "summary", "->", "editurl", ",", "new", "pix_icon", "(", "'i/edit'", ",", "get_string", "(", "'edit'", ")", ")", ")", ";", "}", "$", "o", ".=", "$", "this", "->", "output", "->", "container_end", "(", ")", ";", "// additional info", "if", "(", "$", "summary", "->", "status", "==", "'notgraded'", ")", "{", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "get_string", "(", "'nogradeyet'", ",", "'workshop'", ")", ",", "'example-info nograde'", ")", ";", "}", "else", "{", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "get_string", "(", "'gradeinfo'", ",", "'workshop'", ",", "$", "summary", "->", "gradeinfo", ")", ",", "'example-info grade'", ")", ";", "}", "// button to assess", "$", "button", "=", "new", "single_button", "(", "$", "summary", "->", "assessurl", ",", "$", "summary", "->", "assesslabel", ",", "'get'", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "$", "this", "->", "output", "->", "render", "(", "$", "button", ")", ",", "'example-actions'", ")", ";", "// end of wrapping box", "$", "o", ".=", "$", "this", "->", "output", "->", "box_end", "(", ")", ";", "return", "$", "o", ";", "}" ]
Renders short summary of the example submission @param workshop_example_submission_summary $summary @return string text to be echo'ed
[ "Renders", "short", "summary", "of", "the", "example", "submission" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L244-L275
211,864
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.render_workshop_user_plan
protected function render_workshop_user_plan(workshop_user_plan $plan) { $o = ''; // Output HTML code. $numberofphases = count($plan->phases); $o .= html_writer::start_tag('div', array( 'class' => 'userplan', 'aria-labelledby' => 'mod_workshop-userplanheading', 'aria-describedby' => 'mod_workshop-userplanaccessibilitytitle', )); $o .= html_writer::span(get_string('userplanaccessibilitytitle', 'workshop', $numberofphases), 'accesshide', array('id' => 'mod_workshop-userplanaccessibilitytitle')); $o .= html_writer::link('#mod_workshop-userplancurrenttasks', get_string('userplanaccessibilityskip', 'workshop'), array('class' => 'accesshide')); foreach ($plan->phases as $phasecode => $phase) { $o .= html_writer::start_tag('dl', array('class' => 'phase')); $actions = ''; if ($phase->active) { // Mark the section as the current one. $icon = $this->output->pix_icon('i/marked', '', 'moodle', ['role' => 'presentation']); $actions .= get_string('userplancurrentphase', 'workshop').' '.$icon; } else { // Display a control widget to switch to the given phase or mark the phase as the current one. foreach ($phase->actions as $action) { if ($action->type === 'switchphase') { if ($phasecode == workshop::PHASE_ASSESSMENT && $plan->workshop->phase == workshop::PHASE_SUBMISSION && $plan->workshop->phaseswitchassessment) { $icon = new pix_icon('i/scheduled', get_string('switchphaseauto', 'mod_workshop')); } else { $icon = new pix_icon('i/marker', get_string('switchphase'.$phasecode, 'mod_workshop')); } $actions .= $this->output->action_icon($action->url, $icon, null, null, true); } } } if (!empty($actions)) { $actions = $this->output->container($actions, 'actions'); } $classes = 'phase' . $phasecode; if ($phase->active) { $title = html_writer::span($phase->title, 'phasetitle', ['id' => 'mod_workshop-userplancurrenttasks']); $classes .= ' active'; } else { $title = html_writer::span($phase->title, 'phasetitle'); $classes .= ' nonactive'; } $o .= html_writer::start_tag('dt', array('class' => $classes)); $o .= $this->output->container($title . $actions); $o .= html_writer::start_tag('dd', array('class' => $classes. ' phasetasks')); $o .= $this->helper_user_plan_tasks($phase->tasks); $o .= html_writer::end_tag('dd'); $o .= html_writer::end_tag('dl'); } $o .= html_writer::end_tag('div'); return $o; }
php
protected function render_workshop_user_plan(workshop_user_plan $plan) { $o = ''; // Output HTML code. $numberofphases = count($plan->phases); $o .= html_writer::start_tag('div', array( 'class' => 'userplan', 'aria-labelledby' => 'mod_workshop-userplanheading', 'aria-describedby' => 'mod_workshop-userplanaccessibilitytitle', )); $o .= html_writer::span(get_string('userplanaccessibilitytitle', 'workshop', $numberofphases), 'accesshide', array('id' => 'mod_workshop-userplanaccessibilitytitle')); $o .= html_writer::link('#mod_workshop-userplancurrenttasks', get_string('userplanaccessibilityskip', 'workshop'), array('class' => 'accesshide')); foreach ($plan->phases as $phasecode => $phase) { $o .= html_writer::start_tag('dl', array('class' => 'phase')); $actions = ''; if ($phase->active) { // Mark the section as the current one. $icon = $this->output->pix_icon('i/marked', '', 'moodle', ['role' => 'presentation']); $actions .= get_string('userplancurrentphase', 'workshop').' '.$icon; } else { // Display a control widget to switch to the given phase or mark the phase as the current one. foreach ($phase->actions as $action) { if ($action->type === 'switchphase') { if ($phasecode == workshop::PHASE_ASSESSMENT && $plan->workshop->phase == workshop::PHASE_SUBMISSION && $plan->workshop->phaseswitchassessment) { $icon = new pix_icon('i/scheduled', get_string('switchphaseauto', 'mod_workshop')); } else { $icon = new pix_icon('i/marker', get_string('switchphase'.$phasecode, 'mod_workshop')); } $actions .= $this->output->action_icon($action->url, $icon, null, null, true); } } } if (!empty($actions)) { $actions = $this->output->container($actions, 'actions'); } $classes = 'phase' . $phasecode; if ($phase->active) { $title = html_writer::span($phase->title, 'phasetitle', ['id' => 'mod_workshop-userplancurrenttasks']); $classes .= ' active'; } else { $title = html_writer::span($phase->title, 'phasetitle'); $classes .= ' nonactive'; } $o .= html_writer::start_tag('dt', array('class' => $classes)); $o .= $this->output->container($title . $actions); $o .= html_writer::start_tag('dd', array('class' => $classes. ' phasetasks')); $o .= $this->helper_user_plan_tasks($phase->tasks); $o .= html_writer::end_tag('dd'); $o .= html_writer::end_tag('dl'); } $o .= html_writer::end_tag('div'); return $o; }
[ "protected", "function", "render_workshop_user_plan", "(", "workshop_user_plan", "$", "plan", ")", "{", "$", "o", "=", "''", ";", "// Output HTML code.", "$", "numberofphases", "=", "count", "(", "$", "plan", "->", "phases", ")", ";", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'userplan'", ",", "'aria-labelledby'", "=>", "'mod_workshop-userplanheading'", ",", "'aria-describedby'", "=>", "'mod_workshop-userplanaccessibilitytitle'", ",", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "span", "(", "get_string", "(", "'userplanaccessibilitytitle'", ",", "'workshop'", ",", "$", "numberofphases", ")", ",", "'accesshide'", ",", "array", "(", "'id'", "=>", "'mod_workshop-userplanaccessibilitytitle'", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "link", "(", "'#mod_workshop-userplancurrenttasks'", ",", "get_string", "(", "'userplanaccessibilityskip'", ",", "'workshop'", ")", ",", "array", "(", "'class'", "=>", "'accesshide'", ")", ")", ";", "foreach", "(", "$", "plan", "->", "phases", "as", "$", "phasecode", "=>", "$", "phase", ")", "{", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'dl'", ",", "array", "(", "'class'", "=>", "'phase'", ")", ")", ";", "$", "actions", "=", "''", ";", "if", "(", "$", "phase", "->", "active", ")", "{", "// Mark the section as the current one.", "$", "icon", "=", "$", "this", "->", "output", "->", "pix_icon", "(", "'i/marked'", ",", "''", ",", "'moodle'", ",", "[", "'role'", "=>", "'presentation'", "]", ")", ";", "$", "actions", ".=", "get_string", "(", "'userplancurrentphase'", ",", "'workshop'", ")", ".", "' '", ".", "$", "icon", ";", "}", "else", "{", "// Display a control widget to switch to the given phase or mark the phase as the current one.", "foreach", "(", "$", "phase", "->", "actions", "as", "$", "action", ")", "{", "if", "(", "$", "action", "->", "type", "===", "'switchphase'", ")", "{", "if", "(", "$", "phasecode", "==", "workshop", "::", "PHASE_ASSESSMENT", "&&", "$", "plan", "->", "workshop", "->", "phase", "==", "workshop", "::", "PHASE_SUBMISSION", "&&", "$", "plan", "->", "workshop", "->", "phaseswitchassessment", ")", "{", "$", "icon", "=", "new", "pix_icon", "(", "'i/scheduled'", ",", "get_string", "(", "'switchphaseauto'", ",", "'mod_workshop'", ")", ")", ";", "}", "else", "{", "$", "icon", "=", "new", "pix_icon", "(", "'i/marker'", ",", "get_string", "(", "'switchphase'", ".", "$", "phasecode", ",", "'mod_workshop'", ")", ")", ";", "}", "$", "actions", ".=", "$", "this", "->", "output", "->", "action_icon", "(", "$", "action", "->", "url", ",", "$", "icon", ",", "null", ",", "null", ",", "true", ")", ";", "}", "}", "}", "if", "(", "!", "empty", "(", "$", "actions", ")", ")", "{", "$", "actions", "=", "$", "this", "->", "output", "->", "container", "(", "$", "actions", ",", "'actions'", ")", ";", "}", "$", "classes", "=", "'phase'", ".", "$", "phasecode", ";", "if", "(", "$", "phase", "->", "active", ")", "{", "$", "title", "=", "html_writer", "::", "span", "(", "$", "phase", "->", "title", ",", "'phasetitle'", ",", "[", "'id'", "=>", "'mod_workshop-userplancurrenttasks'", "]", ")", ";", "$", "classes", ".=", "' active'", ";", "}", "else", "{", "$", "title", "=", "html_writer", "::", "span", "(", "$", "phase", "->", "title", ",", "'phasetitle'", ")", ";", "$", "classes", ".=", "' nonactive'", ";", "}", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'dt'", ",", "array", "(", "'class'", "=>", "$", "classes", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "$", "title", ".", "$", "actions", ")", ";", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'dd'", ",", "array", "(", "'class'", "=>", "$", "classes", ".", "' phasetasks'", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "helper_user_plan_tasks", "(", "$", "phase", "->", "tasks", ")", ";", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'dd'", ")", ";", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'dl'", ")", ";", "}", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "return", "$", "o", ";", "}" ]
Renders the user plannner tool @param workshop_user_plan $plan prepared for the user @return string html code to be displayed
[ "Renders", "the", "user", "plannner", "tool" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L283-L339
211,865
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.render_workshop_allocation_result
protected function render_workshop_allocation_result(workshop_allocation_result $result) { global $CFG; $status = $result->get_status(); if (is_null($status) or $status == workshop_allocation_result::STATUS_VOID) { debugging('Attempt to render workshop_allocation_result with empty status', DEBUG_DEVELOPER); return ''; } switch ($status) { case workshop_allocation_result::STATUS_FAILED: if ($message = $result->get_message()) { $message = new workshop_message($message, workshop_message::TYPE_ERROR); } else { $message = new workshop_message(get_string('allocationerror', 'workshop'), workshop_message::TYPE_ERROR); } break; case workshop_allocation_result::STATUS_CONFIGURED: if ($message = $result->get_message()) { $message = new workshop_message($message, workshop_message::TYPE_INFO); } else { $message = new workshop_message(get_string('allocationconfigured', 'workshop'), workshop_message::TYPE_INFO); } break; case workshop_allocation_result::STATUS_EXECUTED: if ($message = $result->get_message()) { $message = new workshop_message($message, workshop_message::TYPE_OK); } else { $message = new workshop_message(get_string('allocationdone', 'workshop'), workshop_message::TYPE_OK); } break; default: throw new coding_exception('Unknown allocation result status', $status); } // start with the message $o = $this->render($message); // display the details about the process if available $logs = $result->get_logs(); if (is_array($logs) and !empty($logs)) { $o .= html_writer::start_tag('ul', array('class' => 'allocation-init-results')); foreach ($logs as $log) { if ($log->type == 'debug' and !$CFG->debugdeveloper) { // display allocation debugging messages for developers only continue; } $class = $log->type; if ($log->indent) { $class .= ' indent'; } $o .= html_writer::tag('li', $log->message, array('class' => $class)).PHP_EOL; } $o .= html_writer::end_tag('ul'); } return $o; }
php
protected function render_workshop_allocation_result(workshop_allocation_result $result) { global $CFG; $status = $result->get_status(); if (is_null($status) or $status == workshop_allocation_result::STATUS_VOID) { debugging('Attempt to render workshop_allocation_result with empty status', DEBUG_DEVELOPER); return ''; } switch ($status) { case workshop_allocation_result::STATUS_FAILED: if ($message = $result->get_message()) { $message = new workshop_message($message, workshop_message::TYPE_ERROR); } else { $message = new workshop_message(get_string('allocationerror', 'workshop'), workshop_message::TYPE_ERROR); } break; case workshop_allocation_result::STATUS_CONFIGURED: if ($message = $result->get_message()) { $message = new workshop_message($message, workshop_message::TYPE_INFO); } else { $message = new workshop_message(get_string('allocationconfigured', 'workshop'), workshop_message::TYPE_INFO); } break; case workshop_allocation_result::STATUS_EXECUTED: if ($message = $result->get_message()) { $message = new workshop_message($message, workshop_message::TYPE_OK); } else { $message = new workshop_message(get_string('allocationdone', 'workshop'), workshop_message::TYPE_OK); } break; default: throw new coding_exception('Unknown allocation result status', $status); } // start with the message $o = $this->render($message); // display the details about the process if available $logs = $result->get_logs(); if (is_array($logs) and !empty($logs)) { $o .= html_writer::start_tag('ul', array('class' => 'allocation-init-results')); foreach ($logs as $log) { if ($log->type == 'debug' and !$CFG->debugdeveloper) { // display allocation debugging messages for developers only continue; } $class = $log->type; if ($log->indent) { $class .= ' indent'; } $o .= html_writer::tag('li', $log->message, array('class' => $class)).PHP_EOL; } $o .= html_writer::end_tag('ul'); } return $o; }
[ "protected", "function", "render_workshop_allocation_result", "(", "workshop_allocation_result", "$", "result", ")", "{", "global", "$", "CFG", ";", "$", "status", "=", "$", "result", "->", "get_status", "(", ")", ";", "if", "(", "is_null", "(", "$", "status", ")", "or", "$", "status", "==", "workshop_allocation_result", "::", "STATUS_VOID", ")", "{", "debugging", "(", "'Attempt to render workshop_allocation_result with empty status'", ",", "DEBUG_DEVELOPER", ")", ";", "return", "''", ";", "}", "switch", "(", "$", "status", ")", "{", "case", "workshop_allocation_result", "::", "STATUS_FAILED", ":", "if", "(", "$", "message", "=", "$", "result", "->", "get_message", "(", ")", ")", "{", "$", "message", "=", "new", "workshop_message", "(", "$", "message", ",", "workshop_message", "::", "TYPE_ERROR", ")", ";", "}", "else", "{", "$", "message", "=", "new", "workshop_message", "(", "get_string", "(", "'allocationerror'", ",", "'workshop'", ")", ",", "workshop_message", "::", "TYPE_ERROR", ")", ";", "}", "break", ";", "case", "workshop_allocation_result", "::", "STATUS_CONFIGURED", ":", "if", "(", "$", "message", "=", "$", "result", "->", "get_message", "(", ")", ")", "{", "$", "message", "=", "new", "workshop_message", "(", "$", "message", ",", "workshop_message", "::", "TYPE_INFO", ")", ";", "}", "else", "{", "$", "message", "=", "new", "workshop_message", "(", "get_string", "(", "'allocationconfigured'", ",", "'workshop'", ")", ",", "workshop_message", "::", "TYPE_INFO", ")", ";", "}", "break", ";", "case", "workshop_allocation_result", "::", "STATUS_EXECUTED", ":", "if", "(", "$", "message", "=", "$", "result", "->", "get_message", "(", ")", ")", "{", "$", "message", "=", "new", "workshop_message", "(", "$", "message", ",", "workshop_message", "::", "TYPE_OK", ")", ";", "}", "else", "{", "$", "message", "=", "new", "workshop_message", "(", "get_string", "(", "'allocationdone'", ",", "'workshop'", ")", ",", "workshop_message", "::", "TYPE_OK", ")", ";", "}", "break", ";", "default", ":", "throw", "new", "coding_exception", "(", "'Unknown allocation result status'", ",", "$", "status", ")", ";", "}", "// start with the message", "$", "o", "=", "$", "this", "->", "render", "(", "$", "message", ")", ";", "// display the details about the process if available", "$", "logs", "=", "$", "result", "->", "get_logs", "(", ")", ";", "if", "(", "is_array", "(", "$", "logs", ")", "and", "!", "empty", "(", "$", "logs", ")", ")", "{", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'ul'", ",", "array", "(", "'class'", "=>", "'allocation-init-results'", ")", ")", ";", "foreach", "(", "$", "logs", "as", "$", "log", ")", "{", "if", "(", "$", "log", "->", "type", "==", "'debug'", "and", "!", "$", "CFG", "->", "debugdeveloper", ")", "{", "// display allocation debugging messages for developers only", "continue", ";", "}", "$", "class", "=", "$", "log", "->", "type", ";", "if", "(", "$", "log", "->", "indent", ")", "{", "$", "class", ".=", "' indent'", ";", "}", "$", "o", ".=", "html_writer", "::", "tag", "(", "'li'", ",", "$", "log", "->", "message", ",", "array", "(", "'class'", "=>", "$", "class", ")", ")", ".", "PHP_EOL", ";", "}", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'ul'", ")", ";", "}", "return", "$", "o", ";", "}" ]
Renders the result of the submissions allocation process @param workshop_allocation_result $result as returned by the allocator's init() method @return string HTML to be echoed
[ "Renders", "the", "result", "of", "the", "submissions", "allocation", "process" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L347-L408
211,866
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.helper_render_feedback
private function helper_render_feedback($feedback) { $o = ''; // output HTML code $o .= $this->output->container_start('feedback feedbackforauthor'); $o .= $this->output->container_start('header'); $o .= $this->output->heading(get_string('feedbackby', 'workshop', s(fullname($feedback->get_provider()))), 3, 'title'); $userpic = $this->output->user_picture($feedback->get_provider(), array('courseid' => $this->page->course->id, 'size' => 32)); $o .= $this->output->container($userpic, 'picture'); $o .= $this->output->container_end(); // end of header $content = format_text($feedback->get_content(), $feedback->get_format(), array('overflowdiv' => true)); $o .= $this->output->container($content, 'content'); $o .= $this->output->container_end(); return $o; }
php
private function helper_render_feedback($feedback) { $o = ''; // output HTML code $o .= $this->output->container_start('feedback feedbackforauthor'); $o .= $this->output->container_start('header'); $o .= $this->output->heading(get_string('feedbackby', 'workshop', s(fullname($feedback->get_provider()))), 3, 'title'); $userpic = $this->output->user_picture($feedback->get_provider(), array('courseid' => $this->page->course->id, 'size' => 32)); $o .= $this->output->container($userpic, 'picture'); $o .= $this->output->container_end(); // end of header $content = format_text($feedback->get_content(), $feedback->get_format(), array('overflowdiv' => true)); $o .= $this->output->container($content, 'content'); $o .= $this->output->container_end(); return $o; }
[ "private", "function", "helper_render_feedback", "(", "$", "feedback", ")", "{", "$", "o", "=", "''", ";", "// output HTML code", "$", "o", ".=", "$", "this", "->", "output", "->", "container_start", "(", "'feedback feedbackforauthor'", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container_start", "(", "'header'", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "heading", "(", "get_string", "(", "'feedbackby'", ",", "'workshop'", ",", "s", "(", "fullname", "(", "$", "feedback", "->", "get_provider", "(", ")", ")", ")", ")", ",", "3", ",", "'title'", ")", ";", "$", "userpic", "=", "$", "this", "->", "output", "->", "user_picture", "(", "$", "feedback", "->", "get_provider", "(", ")", ",", "array", "(", "'courseid'", "=>", "$", "this", "->", "page", "->", "course", "->", "id", ",", "'size'", "=>", "32", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "$", "userpic", ",", "'picture'", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container_end", "(", ")", ";", "// end of header", "$", "content", "=", "format_text", "(", "$", "feedback", "->", "get_content", "(", ")", ",", "$", "feedback", "->", "get_format", "(", ")", ",", "array", "(", "'overflowdiv'", "=>", "true", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "$", "content", ",", "'content'", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container_end", "(", ")", ";", "return", "$", "o", ";", "}" ]
Helper method to rendering feedback @param workshop_feedback_author|workshop_feedback_reviewer $feedback @return string HTML
[ "Helper", "method", "to", "rendering", "feedback" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L599-L616
211,867
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.overall_feedback
protected function overall_feedback(workshop_assessment $assessment) { $content = $assessment->get_overall_feedback_content(); if ($content === false) { return ''; } $o = ''; if (!is_null($content)) { $o .= $this->output->container($content, 'content'); } $attachments = $assessment->get_overall_feedback_attachments(); if (!empty($attachments)) { $o .= $this->output->container_start('attachments'); $images = ''; $files = ''; foreach ($attachments as $attachment) { $icon = $this->output->pix_icon(file_file_icon($attachment), get_mimetype_description($attachment), 'moodle', array('class' => 'icon')); $link = html_writer::link($attachment->fileurl, $icon.' '.substr($attachment->filepath.$attachment->filename, 1)); if (file_mimetype_in_typegroup($attachment->mimetype, 'web_image')) { $preview = html_writer::empty_tag('img', array('src' => $attachment->previewurl, 'alt' => '', 'class' => 'preview')); $preview = html_writer::tag('a', $preview, array('href' => $attachment->fileurl)); $images .= $this->output->container($preview); } else { $files .= html_writer::tag('li', $link, array('class' => $attachment->mimetype)); } } if ($images) { $images = $this->output->container($images, 'images'); } if ($files) { $files = html_writer::tag('ul', $files, array('class' => 'files')); } $o .= $images.$files; $o .= $this->output->container_end(); } if ($o === '') { return ''; } $o = $this->output->box($o, 'overallfeedback'); $o = print_collapsible_region($o, 'overall-feedback-wrapper', uniqid('workshop-overall-feedback'), get_string('overallfeedback', 'workshop'), '', false, true); return $o; }
php
protected function overall_feedback(workshop_assessment $assessment) { $content = $assessment->get_overall_feedback_content(); if ($content === false) { return ''; } $o = ''; if (!is_null($content)) { $o .= $this->output->container($content, 'content'); } $attachments = $assessment->get_overall_feedback_attachments(); if (!empty($attachments)) { $o .= $this->output->container_start('attachments'); $images = ''; $files = ''; foreach ($attachments as $attachment) { $icon = $this->output->pix_icon(file_file_icon($attachment), get_mimetype_description($attachment), 'moodle', array('class' => 'icon')); $link = html_writer::link($attachment->fileurl, $icon.' '.substr($attachment->filepath.$attachment->filename, 1)); if (file_mimetype_in_typegroup($attachment->mimetype, 'web_image')) { $preview = html_writer::empty_tag('img', array('src' => $attachment->previewurl, 'alt' => '', 'class' => 'preview')); $preview = html_writer::tag('a', $preview, array('href' => $attachment->fileurl)); $images .= $this->output->container($preview); } else { $files .= html_writer::tag('li', $link, array('class' => $attachment->mimetype)); } } if ($images) { $images = $this->output->container($images, 'images'); } if ($files) { $files = html_writer::tag('ul', $files, array('class' => 'files')); } $o .= $images.$files; $o .= $this->output->container_end(); } if ($o === '') { return ''; } $o = $this->output->box($o, 'overallfeedback'); $o = print_collapsible_region($o, 'overall-feedback-wrapper', uniqid('workshop-overall-feedback'), get_string('overallfeedback', 'workshop'), '', false, true); return $o; }
[ "protected", "function", "overall_feedback", "(", "workshop_assessment", "$", "assessment", ")", "{", "$", "content", "=", "$", "assessment", "->", "get_overall_feedback_content", "(", ")", ";", "if", "(", "$", "content", "===", "false", ")", "{", "return", "''", ";", "}", "$", "o", "=", "''", ";", "if", "(", "!", "is_null", "(", "$", "content", ")", ")", "{", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "$", "content", ",", "'content'", ")", ";", "}", "$", "attachments", "=", "$", "assessment", "->", "get_overall_feedback_attachments", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "attachments", ")", ")", "{", "$", "o", ".=", "$", "this", "->", "output", "->", "container_start", "(", "'attachments'", ")", ";", "$", "images", "=", "''", ";", "$", "files", "=", "''", ";", "foreach", "(", "$", "attachments", "as", "$", "attachment", ")", "{", "$", "icon", "=", "$", "this", "->", "output", "->", "pix_icon", "(", "file_file_icon", "(", "$", "attachment", ")", ",", "get_mimetype_description", "(", "$", "attachment", ")", ",", "'moodle'", ",", "array", "(", "'class'", "=>", "'icon'", ")", ")", ";", "$", "link", "=", "html_writer", "::", "link", "(", "$", "attachment", "->", "fileurl", ",", "$", "icon", ".", "' '", ".", "substr", "(", "$", "attachment", "->", "filepath", ".", "$", "attachment", "->", "filename", ",", "1", ")", ")", ";", "if", "(", "file_mimetype_in_typegroup", "(", "$", "attachment", "->", "mimetype", ",", "'web_image'", ")", ")", "{", "$", "preview", "=", "html_writer", "::", "empty_tag", "(", "'img'", ",", "array", "(", "'src'", "=>", "$", "attachment", "->", "previewurl", ",", "'alt'", "=>", "''", ",", "'class'", "=>", "'preview'", ")", ")", ";", "$", "preview", "=", "html_writer", "::", "tag", "(", "'a'", ",", "$", "preview", ",", "array", "(", "'href'", "=>", "$", "attachment", "->", "fileurl", ")", ")", ";", "$", "images", ".=", "$", "this", "->", "output", "->", "container", "(", "$", "preview", ")", ";", "}", "else", "{", "$", "files", ".=", "html_writer", "::", "tag", "(", "'li'", ",", "$", "link", ",", "array", "(", "'class'", "=>", "$", "attachment", "->", "mimetype", ")", ")", ";", "}", "}", "if", "(", "$", "images", ")", "{", "$", "images", "=", "$", "this", "->", "output", "->", "container", "(", "$", "images", ",", "'images'", ")", ";", "}", "if", "(", "$", "files", ")", "{", "$", "files", "=", "html_writer", "::", "tag", "(", "'ul'", ",", "$", "files", ",", "array", "(", "'class'", "=>", "'files'", ")", ")", ";", "}", "$", "o", ".=", "$", "images", ".", "$", "files", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container_end", "(", ")", ";", "}", "if", "(", "$", "o", "===", "''", ")", "{", "return", "''", ";", "}", "$", "o", "=", "$", "this", "->", "output", "->", "box", "(", "$", "o", ",", "'overallfeedback'", ")", ";", "$", "o", "=", "print_collapsible_region", "(", "$", "o", ",", "'overall-feedback-wrapper'", ",", "uniqid", "(", "'workshop-overall-feedback'", ")", ",", "get_string", "(", "'overallfeedback'", ",", "'workshop'", ")", ",", "''", ",", "false", ",", "true", ")", ";", "return", "$", "o", ";", "}" ]
Renders the overall feedback for the author of the submission @param workshop_assessment $assessment @return string HTML
[ "Renders", "the", "overall", "feedback", "for", "the", "author", "of", "the", "submission" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L735-L788
211,868
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.perpage_selector
public function perpage_selector($current=10) { $options = array(); foreach (array(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 1000) as $option) { if ($option != $current) { $options[$option] = $option; } } $select = new single_select($this->page->url, 'perpage', $options, '', array('' => get_string('showingperpagechange', 'mod_workshop'))); $select->label = get_string('showingperpage', 'mod_workshop', $current); $select->method = 'post'; return $this->output->container($this->output->render($select), 'perpagewidget'); }
php
public function perpage_selector($current=10) { $options = array(); foreach (array(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 1000) as $option) { if ($option != $current) { $options[$option] = $option; } } $select = new single_select($this->page->url, 'perpage', $options, '', array('' => get_string('showingperpagechange', 'mod_workshop'))); $select->label = get_string('showingperpage', 'mod_workshop', $current); $select->method = 'post'; return $this->output->container($this->output->render($select), 'perpagewidget'); }
[ "public", "function", "perpage_selector", "(", "$", "current", "=", "10", ")", "{", "$", "options", "=", "array", "(", ")", ";", "foreach", "(", "array", "(", "10", ",", "20", ",", "30", ",", "40", ",", "50", ",", "60", ",", "70", ",", "80", ",", "90", ",", "100", ",", "200", ",", "300", ",", "400", ",", "500", ",", "1000", ")", "as", "$", "option", ")", "{", "if", "(", "$", "option", "!=", "$", "current", ")", "{", "$", "options", "[", "$", "option", "]", "=", "$", "option", ";", "}", "}", "$", "select", "=", "new", "single_select", "(", "$", "this", "->", "page", "->", "url", ",", "'perpage'", ",", "$", "options", ",", "''", ",", "array", "(", "''", "=>", "get_string", "(", "'showingperpagechange'", ",", "'mod_workshop'", ")", ")", ")", ";", "$", "select", "->", "label", "=", "get_string", "(", "'showingperpage'", ",", "'mod_workshop'", ",", "$", "current", ")", ";", "$", "select", "->", "method", "=", "'post'", ";", "return", "$", "this", "->", "output", "->", "container", "(", "$", "this", "->", "output", "->", "render", "(", "$", "select", ")", ",", "'perpagewidget'", ")", ";", "}" ]
Renders a perpage selector for workshop listings The scripts using this have to define the $PAGE->url prior to calling this and deal with eventually submitted value themselves. @param int $current current value of the perpage parameter @return string HTML
[ "Renders", "a", "perpage", "selector", "for", "workshop", "listings" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L799-L812
211,869
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.render_workshop_final_grades
protected function render_workshop_final_grades(workshop_final_grades $grades) { $out = html_writer::start_tag('div', array('class' => 'finalgrades')); if (!empty($grades->submissiongrade)) { $cssclass = 'grade submissiongrade'; if ($grades->submissiongrade->hidden) { $cssclass .= ' hiddengrade'; } $out .= html_writer::tag( 'div', html_writer::tag('div', get_string('submissiongrade', 'mod_workshop'), array('class' => 'gradetype')) . html_writer::tag('div', $grades->submissiongrade->str_long_grade, array('class' => 'gradevalue')), array('class' => $cssclass) ); } if (!empty($grades->assessmentgrade)) { $cssclass = 'grade assessmentgrade'; if ($grades->assessmentgrade->hidden) { $cssclass .= ' hiddengrade'; } $out .= html_writer::tag( 'div', html_writer::tag('div', get_string('gradinggrade', 'mod_workshop'), array('class' => 'gradetype')) . html_writer::tag('div', $grades->assessmentgrade->str_long_grade, array('class' => 'gradevalue')), array('class' => $cssclass) ); } $out .= html_writer::end_tag('div'); return $out; }
php
protected function render_workshop_final_grades(workshop_final_grades $grades) { $out = html_writer::start_tag('div', array('class' => 'finalgrades')); if (!empty($grades->submissiongrade)) { $cssclass = 'grade submissiongrade'; if ($grades->submissiongrade->hidden) { $cssclass .= ' hiddengrade'; } $out .= html_writer::tag( 'div', html_writer::tag('div', get_string('submissiongrade', 'mod_workshop'), array('class' => 'gradetype')) . html_writer::tag('div', $grades->submissiongrade->str_long_grade, array('class' => 'gradevalue')), array('class' => $cssclass) ); } if (!empty($grades->assessmentgrade)) { $cssclass = 'grade assessmentgrade'; if ($grades->assessmentgrade->hidden) { $cssclass .= ' hiddengrade'; } $out .= html_writer::tag( 'div', html_writer::tag('div', get_string('gradinggrade', 'mod_workshop'), array('class' => 'gradetype')) . html_writer::tag('div', $grades->assessmentgrade->str_long_grade, array('class' => 'gradevalue')), array('class' => $cssclass) ); } $out .= html_writer::end_tag('div'); return $out; }
[ "protected", "function", "render_workshop_final_grades", "(", "workshop_final_grades", "$", "grades", ")", "{", "$", "out", "=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'finalgrades'", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "grades", "->", "submissiongrade", ")", ")", "{", "$", "cssclass", "=", "'grade submissiongrade'", ";", "if", "(", "$", "grades", "->", "submissiongrade", "->", "hidden", ")", "{", "$", "cssclass", ".=", "' hiddengrade'", ";", "}", "$", "out", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "html_writer", "::", "tag", "(", "'div'", ",", "get_string", "(", "'submissiongrade'", ",", "'mod_workshop'", ")", ",", "array", "(", "'class'", "=>", "'gradetype'", ")", ")", ".", "html_writer", "::", "tag", "(", "'div'", ",", "$", "grades", "->", "submissiongrade", "->", "str_long_grade", ",", "array", "(", "'class'", "=>", "'gradevalue'", ")", ")", ",", "array", "(", "'class'", "=>", "$", "cssclass", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "grades", "->", "assessmentgrade", ")", ")", "{", "$", "cssclass", "=", "'grade assessmentgrade'", ";", "if", "(", "$", "grades", "->", "assessmentgrade", "->", "hidden", ")", "{", "$", "cssclass", ".=", "' hiddengrade'", ";", "}", "$", "out", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "html_writer", "::", "tag", "(", "'div'", ",", "get_string", "(", "'gradinggrade'", ",", "'mod_workshop'", ")", ",", "array", "(", "'class'", "=>", "'gradetype'", ")", ")", ".", "html_writer", "::", "tag", "(", "'div'", ",", "$", "grades", "->", "assessmentgrade", "->", "str_long_grade", ",", "array", "(", "'class'", "=>", "'gradevalue'", ")", ")", ",", "array", "(", "'class'", "=>", "$", "cssclass", ")", ")", ";", "}", "$", "out", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "return", "$", "out", ";", "}" ]
Renders the user's final grades @param workshop_final_grades $grades with the info about grades in the gradebook @return string HTML
[ "Renders", "the", "user", "s", "final", "grades" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L820-L853
211,870
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.helper_user_plan_tasks
protected function helper_user_plan_tasks(array $tasks) { $out = ''; foreach ($tasks as $taskcode => $task) { $classes = ''; $accessibilitytext = ''; $icon = null; if ($task->completed === true) { $classes .= ' completed'; $accessibilitytext .= get_string('taskdone', 'workshop') . ' '; } else if ($task->completed === false) { $classes .= ' fail'; $accessibilitytext .= get_string('taskfail', 'workshop') . ' '; } else if ($task->completed === 'info') { $classes .= ' info'; $accessibilitytext .= get_string('taskinfo', 'workshop') . ' '; } else { $accessibilitytext .= get_string('tasktodo', 'workshop') . ' '; } if (is_null($task->link)) { $title = html_writer::tag('span', $accessibilitytext, array('class' => 'accesshide')); $title .= $task->title; } else { $title = html_writer::tag('span', $accessibilitytext, array('class' => 'accesshide')); $title .= html_writer::link($task->link, $task->title); } $title = $this->output->container($title, 'title'); $details = $this->output->container($task->details, 'details'); $out .= html_writer::tag('li', $title . $details, array('class' => $classes)); } if ($out) { $out = html_writer::tag('ul', $out, array('class' => 'tasks')); } return $out; }
php
protected function helper_user_plan_tasks(array $tasks) { $out = ''; foreach ($tasks as $taskcode => $task) { $classes = ''; $accessibilitytext = ''; $icon = null; if ($task->completed === true) { $classes .= ' completed'; $accessibilitytext .= get_string('taskdone', 'workshop') . ' '; } else if ($task->completed === false) { $classes .= ' fail'; $accessibilitytext .= get_string('taskfail', 'workshop') . ' '; } else if ($task->completed === 'info') { $classes .= ' info'; $accessibilitytext .= get_string('taskinfo', 'workshop') . ' '; } else { $accessibilitytext .= get_string('tasktodo', 'workshop') . ' '; } if (is_null($task->link)) { $title = html_writer::tag('span', $accessibilitytext, array('class' => 'accesshide')); $title .= $task->title; } else { $title = html_writer::tag('span', $accessibilitytext, array('class' => 'accesshide')); $title .= html_writer::link($task->link, $task->title); } $title = $this->output->container($title, 'title'); $details = $this->output->container($task->details, 'details'); $out .= html_writer::tag('li', $title . $details, array('class' => $classes)); } if ($out) { $out = html_writer::tag('ul', $out, array('class' => 'tasks')); } return $out; }
[ "protected", "function", "helper_user_plan_tasks", "(", "array", "$", "tasks", ")", "{", "$", "out", "=", "''", ";", "foreach", "(", "$", "tasks", "as", "$", "taskcode", "=>", "$", "task", ")", "{", "$", "classes", "=", "''", ";", "$", "accessibilitytext", "=", "''", ";", "$", "icon", "=", "null", ";", "if", "(", "$", "task", "->", "completed", "===", "true", ")", "{", "$", "classes", ".=", "' completed'", ";", "$", "accessibilitytext", ".=", "get_string", "(", "'taskdone'", ",", "'workshop'", ")", ".", "' '", ";", "}", "else", "if", "(", "$", "task", "->", "completed", "===", "false", ")", "{", "$", "classes", ".=", "' fail'", ";", "$", "accessibilitytext", ".=", "get_string", "(", "'taskfail'", ",", "'workshop'", ")", ".", "' '", ";", "}", "else", "if", "(", "$", "task", "->", "completed", "===", "'info'", ")", "{", "$", "classes", ".=", "' info'", ";", "$", "accessibilitytext", ".=", "get_string", "(", "'taskinfo'", ",", "'workshop'", ")", ".", "' '", ";", "}", "else", "{", "$", "accessibilitytext", ".=", "get_string", "(", "'tasktodo'", ",", "'workshop'", ")", ".", "' '", ";", "}", "if", "(", "is_null", "(", "$", "task", "->", "link", ")", ")", "{", "$", "title", "=", "html_writer", "::", "tag", "(", "'span'", ",", "$", "accessibilitytext", ",", "array", "(", "'class'", "=>", "'accesshide'", ")", ")", ";", "$", "title", ".=", "$", "task", "->", "title", ";", "}", "else", "{", "$", "title", "=", "html_writer", "::", "tag", "(", "'span'", ",", "$", "accessibilitytext", ",", "array", "(", "'class'", "=>", "'accesshide'", ")", ")", ";", "$", "title", ".=", "html_writer", "::", "link", "(", "$", "task", "->", "link", ",", "$", "task", "->", "title", ")", ";", "}", "$", "title", "=", "$", "this", "->", "output", "->", "container", "(", "$", "title", ",", "'title'", ")", ";", "$", "details", "=", "$", "this", "->", "output", "->", "container", "(", "$", "task", "->", "details", ",", "'details'", ")", ";", "$", "out", ".=", "html_writer", "::", "tag", "(", "'li'", ",", "$", "title", ".", "$", "details", ",", "array", "(", "'class'", "=>", "$", "classes", ")", ")", ";", "}", "if", "(", "$", "out", ")", "{", "$", "out", "=", "html_writer", "::", "tag", "(", "'ul'", ",", "$", "out", ",", "array", "(", "'class'", "=>", "'tasks'", ")", ")", ";", "}", "return", "$", "out", ";", "}" ]
Renders the tasks for the single phase in the user plan @param stdClass $tasks @return string html code
[ "Renders", "the", "tasks", "for", "the", "single", "phase", "in", "the", "user", "plan" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L943-L976
211,871
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.helper_grading_report_grade
protected function helper_grading_report_grade($grade, $over=null) { $a = new stdclass(); $a->grade = is_null($grade) ? get_string('nullgrade', 'workshop') : $grade; if (is_null($over)) { $text = get_string('formataggregatedgrade', 'workshop', $a); } else { $a->over = is_null($over) ? get_string('nullgrade', 'workshop') : $over; $text = get_string('formataggregatedgradeover', 'workshop', $a); } return $text; }
php
protected function helper_grading_report_grade($grade, $over=null) { $a = new stdclass(); $a->grade = is_null($grade) ? get_string('nullgrade', 'workshop') : $grade; if (is_null($over)) { $text = get_string('formataggregatedgrade', 'workshop', $a); } else { $a->over = is_null($over) ? get_string('nullgrade', 'workshop') : $over; $text = get_string('formataggregatedgradeover', 'workshop', $a); } return $text; }
[ "protected", "function", "helper_grading_report_grade", "(", "$", "grade", ",", "$", "over", "=", "null", ")", "{", "$", "a", "=", "new", "stdclass", "(", ")", ";", "$", "a", "->", "grade", "=", "is_null", "(", "$", "grade", ")", "?", "get_string", "(", "'nullgrade'", ",", "'workshop'", ")", ":", "$", "grade", ";", "if", "(", "is_null", "(", "$", "over", ")", ")", "{", "$", "text", "=", "get_string", "(", "'formataggregatedgrade'", ",", "'workshop'", ",", "$", "a", ")", ";", "}", "else", "{", "$", "a", "->", "over", "=", "is_null", "(", "$", "over", ")", "?", "get_string", "(", "'nullgrade'", ",", "'workshop'", ")", ":", "$", "over", ";", "$", "text", "=", "get_string", "(", "'formataggregatedgradeover'", ",", "'workshop'", ",", "$", "a", ")", ";", "}", "return", "$", "text", ";", "}" ]
Formats the aggreagated grades
[ "Formats", "the", "aggreagated", "grades" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L1097-L1107
211,872
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.moodleform
protected static function moodleform(moodleform $mform) { ob_start(); $mform->display(); $o = ob_get_contents(); ob_end_clean(); return $o; }
php
protected static function moodleform(moodleform $mform) { ob_start(); $mform->display(); $o = ob_get_contents(); ob_end_clean(); return $o; }
[ "protected", "static", "function", "moodleform", "(", "moodleform", "$", "mform", ")", "{", "ob_start", "(", ")", ";", "$", "mform", "->", "display", "(", ")", ";", "$", "o", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "return", "$", "o", ";", "}" ]
Helper method dealing with the fact we can not just fetch the output of moodleforms @param moodleform $mform @return string HTML
[ "Helper", "method", "dealing", "with", "the", "fact", "we", "can", "not", "just", "fetch", "the", "output", "of", "moodleforms" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L1119-L1127
211,873
moodle/moodle
mod/workshop/renderer.php
mod_workshop_renderer.array_nth
protected static function array_nth(array $a, $n) { $keys = array_keys($a); if ($n < 0 or $n > count($keys) - 1) { return null; } $key = $keys[$n]; return $a[$key]; }
php
protected static function array_nth(array $a, $n) { $keys = array_keys($a); if ($n < 0 or $n > count($keys) - 1) { return null; } $key = $keys[$n]; return $a[$key]; }
[ "protected", "static", "function", "array_nth", "(", "array", "$", "a", ",", "$", "n", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "a", ")", ";", "if", "(", "$", "n", "<", "0", "or", "$", "n", ">", "count", "(", "$", "keys", ")", "-", "1", ")", "{", "return", "null", ";", "}", "$", "key", "=", "$", "keys", "[", "$", "n", "]", ";", "return", "$", "a", "[", "$", "key", "]", ";", "}" ]
Helper function returning the n-th item of the array @param array $a @param int $n from 0 to m, where m is th number of items in the array @return mixed the $n-th element of $a
[ "Helper", "function", "returning", "the", "n", "-", "th", "item", "of", "the", "array" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/renderer.php#L1136-L1143
211,874
moodle/moodle
availability/condition/date/classes/frontend.php
frontend.get_time_from_fields
public static function get_time_from_fields($year, $month, $day, $hour, $minute) { $calendartype = \core_calendar\type_factory::get_calendar_instance(); $gregoriandate = $calendartype->convert_to_gregorian( $year, $month, $day, $hour, $minute); return make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], $gregoriandate['minute'], 0); }
php
public static function get_time_from_fields($year, $month, $day, $hour, $minute) { $calendartype = \core_calendar\type_factory::get_calendar_instance(); $gregoriandate = $calendartype->convert_to_gregorian( $year, $month, $day, $hour, $minute); return make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], $gregoriandate['minute'], 0); }
[ "public", "static", "function", "get_time_from_fields", "(", "$", "year", ",", "$", "month", ",", "$", "day", ",", "$", "hour", ",", "$", "minute", ")", "{", "$", "calendartype", "=", "\\", "core_calendar", "\\", "type_factory", "::", "get_calendar_instance", "(", ")", ";", "$", "gregoriandate", "=", "$", "calendartype", "->", "convert_to_gregorian", "(", "$", "year", ",", "$", "month", ",", "$", "day", ",", "$", "hour", ",", "$", "minute", ")", ";", "return", "make_timestamp", "(", "$", "gregoriandate", "[", "'year'", "]", ",", "$", "gregoriandate", "[", "'month'", "]", ",", "$", "gregoriandate", "[", "'day'", "]", ",", "$", "gregoriandate", "[", "'hour'", "]", ",", "$", "gregoriandate", "[", "'minute'", "]", ",", "0", ")", ";", "}" ]
Given field values, obtains the corresponding timestamp. @param int $year Year @param int $month Month @param int $day Day @param int $hour Hour @param int $minute Minute @return int Timestamp
[ "Given", "field", "values", "obtains", "the", "corresponding", "timestamp", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/date/classes/frontend.php#L65-L71
211,875
moodle/moodle
availability/condition/date/classes/frontend.php
frontend.get_fields_from_time
public static function get_fields_from_time($time) { $calendartype = \core_calendar\type_factory::get_calendar_instance(); $wrongfields = $calendartype->timestamp_to_date_array($time); return array('day' => $wrongfields['mday'], 'month' => $wrongfields['mon'], 'year' => $wrongfields['year'], 'hour' => $wrongfields['hours'], 'minute' => $wrongfields['minutes']); }
php
public static function get_fields_from_time($time) { $calendartype = \core_calendar\type_factory::get_calendar_instance(); $wrongfields = $calendartype->timestamp_to_date_array($time); return array('day' => $wrongfields['mday'], 'month' => $wrongfields['mon'], 'year' => $wrongfields['year'], 'hour' => $wrongfields['hours'], 'minute' => $wrongfields['minutes']); }
[ "public", "static", "function", "get_fields_from_time", "(", "$", "time", ")", "{", "$", "calendartype", "=", "\\", "core_calendar", "\\", "type_factory", "::", "get_calendar_instance", "(", ")", ";", "$", "wrongfields", "=", "$", "calendartype", "->", "timestamp_to_date_array", "(", "$", "time", ")", ";", "return", "array", "(", "'day'", "=>", "$", "wrongfields", "[", "'mday'", "]", ",", "'month'", "=>", "$", "wrongfields", "[", "'mon'", "]", ",", "'year'", "=>", "$", "wrongfields", "[", "'year'", "]", ",", "'hour'", "=>", "$", "wrongfields", "[", "'hours'", "]", ",", "'minute'", "=>", "$", "wrongfields", "[", "'minutes'", "]", ")", ";", "}" ]
Given a timestamp, obtains corresponding field values. @param int $time Timestamp @return \stdClass Object with fields for year, month, day, hour, minute
[ "Given", "a", "timestamp", "obtains", "corresponding", "field", "values", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/date/classes/frontend.php#L79-L85
211,876
moodle/moodle
backup/controller/backup_controller.class.php
backup_controller.execute_plan
public function execute_plan() { // Basic/initial prevention against time/memory limits core_php_time_limit::raise(1 * 60 * 60); // 1 hour for 1 course initially granted raise_memory_limit(MEMORY_EXTRA); // If this is not a course backup, or single activity backup (e.g. duplicate) inform the plan we are not // including all the activities for sure. This will affect any // task/step executed conditionally to stop including information // for section and activity backup. MDL-28180. if ($this->get_type() !== backup::TYPE_1COURSE && $this->get_type() !== backup::TYPE_1ACTIVITY) { $this->log('notifying plan about excluded activities by type', backup::LOG_DEBUG); $this->plan->set_excluding_activities(); } return $this->plan->execute(); }
php
public function execute_plan() { // Basic/initial prevention against time/memory limits core_php_time_limit::raise(1 * 60 * 60); // 1 hour for 1 course initially granted raise_memory_limit(MEMORY_EXTRA); // If this is not a course backup, or single activity backup (e.g. duplicate) inform the plan we are not // including all the activities for sure. This will affect any // task/step executed conditionally to stop including information // for section and activity backup. MDL-28180. if ($this->get_type() !== backup::TYPE_1COURSE && $this->get_type() !== backup::TYPE_1ACTIVITY) { $this->log('notifying plan about excluded activities by type', backup::LOG_DEBUG); $this->plan->set_excluding_activities(); } return $this->plan->execute(); }
[ "public", "function", "execute_plan", "(", ")", "{", "// Basic/initial prevention against time/memory limits", "core_php_time_limit", "::", "raise", "(", "1", "*", "60", "*", "60", ")", ";", "// 1 hour for 1 course initially granted", "raise_memory_limit", "(", "MEMORY_EXTRA", ")", ";", "// If this is not a course backup, or single activity backup (e.g. duplicate) inform the plan we are not", "// including all the activities for sure. This will affect any", "// task/step executed conditionally to stop including information", "// for section and activity backup. MDL-28180.", "if", "(", "$", "this", "->", "get_type", "(", ")", "!==", "backup", "::", "TYPE_1COURSE", "&&", "$", "this", "->", "get_type", "(", ")", "!==", "backup", "::", "TYPE_1ACTIVITY", ")", "{", "$", "this", "->", "log", "(", "'notifying plan about excluded activities by type'", ",", "backup", "::", "LOG_DEBUG", ")", ";", "$", "this", "->", "plan", "->", "set_excluding_activities", "(", ")", ";", "}", "return", "$", "this", "->", "plan", "->", "execute", "(", ")", ";", "}" ]
Executes the backup @return void Throws and exception of completes
[ "Executes", "the", "backup" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/controller/backup_controller.class.php#L325-L338
211,877
moodle/moodle
backup/controller/backup_controller.class.php
backup_controller.set_include_files
protected function set_include_files() { // We normally include files. $includefiles = true; // In an import, we don't need to include files. if ($this->get_mode() === backup::MODE_IMPORT) { $includefiles = false; } // When a backup is intended for the same site, we don't need to include the files. // Note, this setting is only used for duplication of an entire course. if ($this->get_mode() === backup::MODE_SAMESITE) { $includefiles = false; } $this->includefiles = (int) $includefiles; $this->log("setting file inclusion to {$this->includefiles}", backup::LOG_DEBUG); return $this->includefiles; }
php
protected function set_include_files() { // We normally include files. $includefiles = true; // In an import, we don't need to include files. if ($this->get_mode() === backup::MODE_IMPORT) { $includefiles = false; } // When a backup is intended for the same site, we don't need to include the files. // Note, this setting is only used for duplication of an entire course. if ($this->get_mode() === backup::MODE_SAMESITE) { $includefiles = false; } $this->includefiles = (int) $includefiles; $this->log("setting file inclusion to {$this->includefiles}", backup::LOG_DEBUG); return $this->includefiles; }
[ "protected", "function", "set_include_files", "(", ")", "{", "// We normally include files.", "$", "includefiles", "=", "true", ";", "// In an import, we don't need to include files.", "if", "(", "$", "this", "->", "get_mode", "(", ")", "===", "backup", "::", "MODE_IMPORT", ")", "{", "$", "includefiles", "=", "false", ";", "}", "// When a backup is intended for the same site, we don't need to include the files.", "// Note, this setting is only used for duplication of an entire course.", "if", "(", "$", "this", "->", "get_mode", "(", ")", "===", "backup", "::", "MODE_SAMESITE", ")", "{", "$", "includefiles", "=", "false", ";", "}", "$", "this", "->", "includefiles", "=", "(", "int", ")", "$", "includefiles", ";", "$", "this", "->", "log", "(", "\"setting file inclusion to {$this->includefiles}\"", ",", "backup", "::", "LOG_DEBUG", ")", ";", "return", "$", "this", "->", "includefiles", ";", "}" ]
Set the initial value for the include_files setting. @see backup_controller::get_include_files for further information on the purpose of this setting. @return int Indicates whether files should be included in backups.
[ "Set", "the", "initial", "value", "for", "the", "include_files", "setting", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/controller/backup_controller.class.php#L398-L416
211,878
moodle/moodle
mod/forum/classes/local/vaults/author.php
author.get_authors_for_posts
public function get_authors_for_posts(array $posts) : array { $authorids = array_reduce($posts, function($carry, $post) { $carry[$post->get_author_id()] = true; return $carry; }, []); $authorids = array_keys($authorids); return $this->get_from_ids($authorids); }
php
public function get_authors_for_posts(array $posts) : array { $authorids = array_reduce($posts, function($carry, $post) { $carry[$post->get_author_id()] = true; return $carry; }, []); $authorids = array_keys($authorids); return $this->get_from_ids($authorids); }
[ "public", "function", "get_authors_for_posts", "(", "array", "$", "posts", ")", ":", "array", "{", "$", "authorids", "=", "array_reduce", "(", "$", "posts", ",", "function", "(", "$", "carry", ",", "$", "post", ")", "{", "$", "carry", "[", "$", "post", "->", "get_author_id", "(", ")", "]", "=", "true", ";", "return", "$", "carry", ";", "}", ",", "[", "]", ")", ";", "$", "authorids", "=", "array_keys", "(", "$", "authorids", ")", ";", "return", "$", "this", "->", "get_from_ids", "(", "$", "authorids", ")", ";", "}" ]
Get the authors for the given posts. Returns a distinct list of authors indexed by author id. @param post_entity[] $posts The list of posts @return author_entity[]
[ "Get", "the", "authors", "for", "the", "given", "posts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/author.php#L94-L101
211,879
moodle/moodle
mod/forum/classes/local/vaults/author.php
author.get_context_ids_for_author_ids
public function get_context_ids_for_author_ids(array $authorids) : array { $db = $this->get_db(); [$insql, $params] = $db->get_in_or_equal($authorids); $sql = "SELECT instanceid, id FROM {context} WHERE contextlevel = ? AND instanceid {$insql}"; $records = $db->get_records_sql($sql, array_merge([CONTEXT_USER], $params)); return array_reduce($authorids, function($carry, $id) use ($records) { $carry[$id] = isset($records[$id]) ? (int) $records[$id]->id : null; return $carry; }, []); }
php
public function get_context_ids_for_author_ids(array $authorids) : array { $db = $this->get_db(); [$insql, $params] = $db->get_in_or_equal($authorids); $sql = "SELECT instanceid, id FROM {context} WHERE contextlevel = ? AND instanceid {$insql}"; $records = $db->get_records_sql($sql, array_merge([CONTEXT_USER], $params)); return array_reduce($authorids, function($carry, $id) use ($records) { $carry[$id] = isset($records[$id]) ? (int) $records[$id]->id : null; return $carry; }, []); }
[ "public", "function", "get_context_ids_for_author_ids", "(", "array", "$", "authorids", ")", ":", "array", "{", "$", "db", "=", "$", "this", "->", "get_db", "(", ")", ";", "[", "$", "insql", ",", "$", "params", "]", "=", "$", "db", "->", "get_in_or_equal", "(", "$", "authorids", ")", ";", "$", "sql", "=", "\"SELECT instanceid, id FROM {context} WHERE contextlevel = ? AND instanceid {$insql}\"", ";", "$", "records", "=", "$", "db", "->", "get_records_sql", "(", "$", "sql", ",", "array_merge", "(", "[", "CONTEXT_USER", "]", ",", "$", "params", ")", ")", ";", "return", "array_reduce", "(", "$", "authorids", ",", "function", "(", "$", "carry", ",", "$", "id", ")", "use", "(", "$", "records", ")", "{", "$", "carry", "[", "$", "id", "]", "=", "isset", "(", "$", "records", "[", "$", "id", "]", ")", "?", "(", "int", ")", "$", "records", "[", "$", "id", "]", "->", "id", ":", "null", ";", "return", "$", "carry", ";", "}", ",", "[", "]", ")", ";", "}" ]
Get the context ids for a set of author ids. The results are indexed by the author id. @param int[] $authorids The list of author ids to fetch. @return int[] Results indexed by author id.
[ "Get", "the", "context", "ids", "for", "a", "set", "of", "author", "ids", ".", "The", "results", "are", "indexed", "by", "the", "author", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/author.php#L110-L119
211,880
moodle/moodle
lib/classes/event/course_module_updated.php
course_module_updated.create_from_cm
public static final function create_from_cm($cm, $modcontext = null) { // If not set, get the module context. if (empty($modcontext)) { $modcontext = \context_module::instance($cm->id); } // Create event object for course module update action. $event = static::create(array( 'context' => $modcontext, 'objectid' => $cm->id, 'other' => array( 'modulename' => $cm->modname, 'instanceid' => $cm->instance, 'name' => $cm->name, ) )); return $event; }
php
public static final function create_from_cm($cm, $modcontext = null) { // If not set, get the module context. if (empty($modcontext)) { $modcontext = \context_module::instance($cm->id); } // Create event object for course module update action. $event = static::create(array( 'context' => $modcontext, 'objectid' => $cm->id, 'other' => array( 'modulename' => $cm->modname, 'instanceid' => $cm->instance, 'name' => $cm->name, ) )); return $event; }
[ "public", "static", "final", "function", "create_from_cm", "(", "$", "cm", ",", "$", "modcontext", "=", "null", ")", "{", "// If not set, get the module context.", "if", "(", "empty", "(", "$", "modcontext", ")", ")", "{", "$", "modcontext", "=", "\\", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "}", "// Create event object for course module update action.", "$", "event", "=", "static", "::", "create", "(", "array", "(", "'context'", "=>", "$", "modcontext", ",", "'objectid'", "=>", "$", "cm", "->", "id", ",", "'other'", "=>", "array", "(", "'modulename'", "=>", "$", "cm", "->", "modname", ",", "'instanceid'", "=>", "$", "cm", "->", "instance", ",", "'name'", "=>", "$", "cm", "->", "name", ",", ")", ")", ")", ";", "return", "$", "event", ";", "}" ]
Set data to create new event from course module. @param \cm_info|\stdClass $cm course module instance, as returned by {@link get_coursemodule_from_id} or {@link get_coursemodule_from_instance}. @param \context_module $modcontext module context instance @return \core\event\base returns instance of new event
[ "Set", "data", "to", "create", "new", "event", "from", "course", "module", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/course_module_updated.php#L148-L165
211,881
moodle/moodle
lib/htmlpurifier/HTMLPurifier/HTMLDefinition.php
HTMLPurifier_HTMLDefinition.addAttribute
public function addAttribute($element_name, $attr_name, $def) { $module = $this->getAnonymousModule(); if (!isset($module->info[$element_name])) { $element = $module->addBlankElement($element_name); } else { $element = $module->info[$element_name]; } $element->attr[$attr_name] = $def; }
php
public function addAttribute($element_name, $attr_name, $def) { $module = $this->getAnonymousModule(); if (!isset($module->info[$element_name])) { $element = $module->addBlankElement($element_name); } else { $element = $module->info[$element_name]; } $element->attr[$attr_name] = $def; }
[ "public", "function", "addAttribute", "(", "$", "element_name", ",", "$", "attr_name", ",", "$", "def", ")", "{", "$", "module", "=", "$", "this", "->", "getAnonymousModule", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "module", "->", "info", "[", "$", "element_name", "]", ")", ")", "{", "$", "element", "=", "$", "module", "->", "addBlankElement", "(", "$", "element_name", ")", ";", "}", "else", "{", "$", "element", "=", "$", "module", "->", "info", "[", "$", "element_name", "]", ";", "}", "$", "element", "->", "attr", "[", "$", "attr_name", "]", "=", "$", "def", ";", "}" ]
Adds a custom attribute to a pre-existing element @note This is strictly convenience, and does not have a corresponding method in HTMLPurifier_HTMLModule @param string $element_name Element name to add attribute to @param string $attr_name Name of attribute @param mixed $def Attribute definition, can be string or object, see HTMLPurifier_AttrTypes for details
[ "Adds", "a", "custom", "attribute", "to", "a", "pre", "-", "existing", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/HTMLDefinition.php#L113-L122
211,882
moodle/moodle
lib/htmlpurifier/HTMLPurifier/HTMLDefinition.php
HTMLPurifier_HTMLDefinition.addElement
public function addElement($element_name, $type, $contents, $attr_collections, $attributes = array()) { $module = $this->getAnonymousModule(); // assume that if the user is calling this, the element // is safe. This may not be a good idea $element = $module->addElement($element_name, $type, $contents, $attr_collections, $attributes); return $element; }
php
public function addElement($element_name, $type, $contents, $attr_collections, $attributes = array()) { $module = $this->getAnonymousModule(); // assume that if the user is calling this, the element // is safe. This may not be a good idea $element = $module->addElement($element_name, $type, $contents, $attr_collections, $attributes); return $element; }
[ "public", "function", "addElement", "(", "$", "element_name", ",", "$", "type", ",", "$", "contents", ",", "$", "attr_collections", ",", "$", "attributes", "=", "array", "(", ")", ")", "{", "$", "module", "=", "$", "this", "->", "getAnonymousModule", "(", ")", ";", "// assume that if the user is calling this, the element", "// is safe. This may not be a good idea", "$", "element", "=", "$", "module", "->", "addElement", "(", "$", "element_name", ",", "$", "type", ",", "$", "contents", ",", "$", "attr_collections", ",", "$", "attributes", ")", ";", "return", "$", "element", ";", "}" ]
Adds a custom element to your HTML definition @see HTMLPurifier_HTMLModule::addElement() for detailed parameter and return value descriptions.
[ "Adds", "a", "custom", "element", "to", "your", "HTML", "definition" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/HTMLDefinition.php#L129-L136
211,883
moodle/moodle
lib/htmlpurifier/HTMLPurifier/HTMLDefinition.php
HTMLPurifier_HTMLDefinition.addBlankElement
public function addBlankElement($element_name) { $module = $this->getAnonymousModule(); $element = $module->addBlankElement($element_name); return $element; }
php
public function addBlankElement($element_name) { $module = $this->getAnonymousModule(); $element = $module->addBlankElement($element_name); return $element; }
[ "public", "function", "addBlankElement", "(", "$", "element_name", ")", "{", "$", "module", "=", "$", "this", "->", "getAnonymousModule", "(", ")", ";", "$", "element", "=", "$", "module", "->", "addBlankElement", "(", "$", "element_name", ")", ";", "return", "$", "element", ";", "}" ]
Adds a blank element to your HTML definition, for overriding existing behavior @param string $element_name @return HTMLPurifier_ElementDef @see HTMLPurifier_HTMLModule::addBlankElement() for detailed parameter and return value descriptions.
[ "Adds", "a", "blank", "element", "to", "your", "HTML", "definition", "for", "overriding", "existing", "behavior" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/HTMLDefinition.php#L146-L151
211,884
moodle/moodle
lib/htmlpurifier/HTMLPurifier/HTMLDefinition.php
HTMLPurifier_HTMLDefinition.getAnonymousModule
public function getAnonymousModule() { if (!$this->_anonModule) { $this->_anonModule = new HTMLPurifier_HTMLModule(); $this->_anonModule->name = 'Anonymous'; } return $this->_anonModule; }
php
public function getAnonymousModule() { if (!$this->_anonModule) { $this->_anonModule = new HTMLPurifier_HTMLModule(); $this->_anonModule->name = 'Anonymous'; } return $this->_anonModule; }
[ "public", "function", "getAnonymousModule", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_anonModule", ")", "{", "$", "this", "->", "_anonModule", "=", "new", "HTMLPurifier_HTMLModule", "(", ")", ";", "$", "this", "->", "_anonModule", "->", "name", "=", "'Anonymous'", ";", "}", "return", "$", "this", "->", "_anonModule", ";", "}" ]
Retrieves a reference to the anonymous module, so you can bust out advanced features without having to make your own module. @return HTMLPurifier_HTMLModule
[ "Retrieves", "a", "reference", "to", "the", "anonymous", "module", "so", "you", "can", "bust", "out", "advanced", "features", "without", "having", "to", "make", "your", "own", "module", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/HTMLDefinition.php#L159-L166
211,885
moodle/moodle
grade/report/grader/lib.php
grade_report_grader.setup_sortitemid
private function setup_sortitemid() { global $SESSION; if (!isset($SESSION->gradeuserreport)) { $SESSION->gradeuserreport = new stdClass(); } if ($this->sortitemid) { if (!isset($SESSION->gradeuserreport->sort)) { if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') { $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC'; } else { $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC'; } } else { // this is the first sort, i.e. by last name if (!isset($SESSION->gradeuserreport->sortitemid)) { if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') { $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC'; } else { $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC'; } } else if ($SESSION->gradeuserreport->sortitemid == $this->sortitemid) { // same as last sort if ($SESSION->gradeuserreport->sort == 'ASC') { $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC'; } else { $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC'; } } else { if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') { $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC'; } else { $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC'; } } } $SESSION->gradeuserreport->sortitemid = $this->sortitemid; } else { // not requesting sort, use last setting (for paging) if (isset($SESSION->gradeuserreport->sortitemid)) { $this->sortitemid = $SESSION->gradeuserreport->sortitemid; } else { $this->sortitemid = 'lastname'; } if (isset($SESSION->gradeuserreport->sort)) { $this->sortorder = $SESSION->gradeuserreport->sort; } else { $this->sortorder = 'ASC'; } } }
php
private function setup_sortitemid() { global $SESSION; if (!isset($SESSION->gradeuserreport)) { $SESSION->gradeuserreport = new stdClass(); } if ($this->sortitemid) { if (!isset($SESSION->gradeuserreport->sort)) { if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') { $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC'; } else { $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC'; } } else { // this is the first sort, i.e. by last name if (!isset($SESSION->gradeuserreport->sortitemid)) { if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') { $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC'; } else { $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC'; } } else if ($SESSION->gradeuserreport->sortitemid == $this->sortitemid) { // same as last sort if ($SESSION->gradeuserreport->sort == 'ASC') { $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC'; } else { $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC'; } } else { if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') { $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC'; } else { $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC'; } } } $SESSION->gradeuserreport->sortitemid = $this->sortitemid; } else { // not requesting sort, use last setting (for paging) if (isset($SESSION->gradeuserreport->sortitemid)) { $this->sortitemid = $SESSION->gradeuserreport->sortitemid; } else { $this->sortitemid = 'lastname'; } if (isset($SESSION->gradeuserreport->sort)) { $this->sortorder = $SESSION->gradeuserreport->sort; } else { $this->sortorder = 'ASC'; } } }
[ "private", "function", "setup_sortitemid", "(", ")", "{", "global", "$", "SESSION", ";", "if", "(", "!", "isset", "(", "$", "SESSION", "->", "gradeuserreport", ")", ")", "{", "$", "SESSION", "->", "gradeuserreport", "=", "new", "stdClass", "(", ")", ";", "}", "if", "(", "$", "this", "->", "sortitemid", ")", "{", "if", "(", "!", "isset", "(", "$", "SESSION", "->", "gradeuserreport", "->", "sort", ")", ")", "{", "if", "(", "$", "this", "->", "sortitemid", "==", "'firstname'", "||", "$", "this", "->", "sortitemid", "==", "'lastname'", ")", "{", "$", "this", "->", "sortorder", "=", "$", "SESSION", "->", "gradeuserreport", "->", "sort", "=", "'ASC'", ";", "}", "else", "{", "$", "this", "->", "sortorder", "=", "$", "SESSION", "->", "gradeuserreport", "->", "sort", "=", "'DESC'", ";", "}", "}", "else", "{", "// this is the first sort, i.e. by last name", "if", "(", "!", "isset", "(", "$", "SESSION", "->", "gradeuserreport", "->", "sortitemid", ")", ")", "{", "if", "(", "$", "this", "->", "sortitemid", "==", "'firstname'", "||", "$", "this", "->", "sortitemid", "==", "'lastname'", ")", "{", "$", "this", "->", "sortorder", "=", "$", "SESSION", "->", "gradeuserreport", "->", "sort", "=", "'ASC'", ";", "}", "else", "{", "$", "this", "->", "sortorder", "=", "$", "SESSION", "->", "gradeuserreport", "->", "sort", "=", "'DESC'", ";", "}", "}", "else", "if", "(", "$", "SESSION", "->", "gradeuserreport", "->", "sortitemid", "==", "$", "this", "->", "sortitemid", ")", "{", "// same as last sort", "if", "(", "$", "SESSION", "->", "gradeuserreport", "->", "sort", "==", "'ASC'", ")", "{", "$", "this", "->", "sortorder", "=", "$", "SESSION", "->", "gradeuserreport", "->", "sort", "=", "'DESC'", ";", "}", "else", "{", "$", "this", "->", "sortorder", "=", "$", "SESSION", "->", "gradeuserreport", "->", "sort", "=", "'ASC'", ";", "}", "}", "else", "{", "if", "(", "$", "this", "->", "sortitemid", "==", "'firstname'", "||", "$", "this", "->", "sortitemid", "==", "'lastname'", ")", "{", "$", "this", "->", "sortorder", "=", "$", "SESSION", "->", "gradeuserreport", "->", "sort", "=", "'ASC'", ";", "}", "else", "{", "$", "this", "->", "sortorder", "=", "$", "SESSION", "->", "gradeuserreport", "->", "sort", "=", "'DESC'", ";", "}", "}", "}", "$", "SESSION", "->", "gradeuserreport", "->", "sortitemid", "=", "$", "this", "->", "sortitemid", ";", "}", "else", "{", "// not requesting sort, use last setting (for paging)", "if", "(", "isset", "(", "$", "SESSION", "->", "gradeuserreport", "->", "sortitemid", ")", ")", "{", "$", "this", "->", "sortitemid", "=", "$", "SESSION", "->", "gradeuserreport", "->", "sortitemid", ";", "}", "else", "{", "$", "this", "->", "sortitemid", "=", "'lastname'", ";", "}", "if", "(", "isset", "(", "$", "SESSION", "->", "gradeuserreport", "->", "sort", ")", ")", "{", "$", "this", "->", "sortorder", "=", "$", "SESSION", "->", "gradeuserreport", "->", "sort", ";", "}", "else", "{", "$", "this", "->", "sortorder", "=", "'ASC'", ";", "}", "}", "}" ]
Setting the sort order, this depends on last state all this should be in the new table class that we might need to use for displaying grades.
[ "Setting", "the", "sort", "order", "this", "depends", "on", "last", "state", "all", "this", "should", "be", "in", "the", "new", "table", "class", "that", "we", "might", "need", "to", "use", "for", "displaying", "grades", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/grader/lib.php#L360-L414
211,886
moodle/moodle
grade/report/grader/lib.php
grade_report_grader.get_allgradeitems
protected function get_allgradeitems() { if (!empty($this->allgradeitems)) { return $this->allgradeitems; } $allgradeitems = grade_item::fetch_all(array('courseid' => $this->courseid)); // But hang on - don't include ones which are set to not show the grade at all. $this->allgradeitems = array_filter($allgradeitems, function($item) { return $item->gradetype != GRADE_TYPE_NONE; }); return $this->allgradeitems; }
php
protected function get_allgradeitems() { if (!empty($this->allgradeitems)) { return $this->allgradeitems; } $allgradeitems = grade_item::fetch_all(array('courseid' => $this->courseid)); // But hang on - don't include ones which are set to not show the grade at all. $this->allgradeitems = array_filter($allgradeitems, function($item) { return $item->gradetype != GRADE_TYPE_NONE; }); return $this->allgradeitems; }
[ "protected", "function", "get_allgradeitems", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "allgradeitems", ")", ")", "{", "return", "$", "this", "->", "allgradeitems", ";", "}", "$", "allgradeitems", "=", "grade_item", "::", "fetch_all", "(", "array", "(", "'courseid'", "=>", "$", "this", "->", "courseid", ")", ")", ";", "// But hang on - don't include ones which are set to not show the grade at all.", "$", "this", "->", "allgradeitems", "=", "array_filter", "(", "$", "allgradeitems", ",", "function", "(", "$", "item", ")", "{", "return", "$", "item", "->", "gradetype", "!=", "GRADE_TYPE_NONE", ";", "}", ")", ";", "return", "$", "this", "->", "allgradeitems", ";", "}" ]
Load all grade items.
[ "Load", "all", "grade", "items", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/grader/lib.php#L533-L544
211,887
moodle/moodle
grade/report/grader/lib.php
grade_report_grader.get_left_icons_row
public function get_left_icons_row($rows=array(), $colspan=1) { global $USER; if ($USER->gradeediting[$this->courseid]) { $controlsrow = new html_table_row(); $controlsrow->attributes['class'] = 'controls'; $controlscell = new html_table_cell(); $controlscell->attributes['class'] = 'header controls'; $controlscell->colspan = $colspan; $controlscell->text = $this->get_lang_string('controls', 'grades'); $controlsrow->cells[] = $controlscell; $rows[] = $controlsrow; } return $rows; }
php
public function get_left_icons_row($rows=array(), $colspan=1) { global $USER; if ($USER->gradeediting[$this->courseid]) { $controlsrow = new html_table_row(); $controlsrow->attributes['class'] = 'controls'; $controlscell = new html_table_cell(); $controlscell->attributes['class'] = 'header controls'; $controlscell->colspan = $colspan; $controlscell->text = $this->get_lang_string('controls', 'grades'); $controlsrow->cells[] = $controlscell; $rows[] = $controlsrow; } return $rows; }
[ "public", "function", "get_left_icons_row", "(", "$", "rows", "=", "array", "(", ")", ",", "$", "colspan", "=", "1", ")", "{", "global", "$", "USER", ";", "if", "(", "$", "USER", "->", "gradeediting", "[", "$", "this", "->", "courseid", "]", ")", "{", "$", "controlsrow", "=", "new", "html_table_row", "(", ")", ";", "$", "controlsrow", "->", "attributes", "[", "'class'", "]", "=", "'controls'", ";", "$", "controlscell", "=", "new", "html_table_cell", "(", ")", ";", "$", "controlscell", "->", "attributes", "[", "'class'", "]", "=", "'header controls'", ";", "$", "controlscell", "->", "colspan", "=", "$", "colspan", ";", "$", "controlscell", "->", "text", "=", "$", "this", "->", "get_lang_string", "(", "'controls'", ",", "'grades'", ")", ";", "$", "controlsrow", "->", "cells", "[", "]", "=", "$", "controlscell", ";", "$", "rows", "[", "]", "=", "$", "controlsrow", ";", "}", "return", "$", "rows", ";", "}" ]
Builds and return the row of icons for the left side of the report. It only has one cell that says "Controls" @param array $rows The Array of rows for the left part of the report @param int $colspan The number of columns this cell has to span @return array Array of rows for the left part of the report
[ "Builds", "and", "return", "the", "row", "of", "icons", "for", "the", "left", "side", "of", "the", "report", ".", "It", "only", "has", "one", "cell", "that", "says", "Controls" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/grader/lib.php#L1286-L1301
211,888
moodle/moodle
grade/report/grader/lib.php
grade_report_grader.get_left_range_row
public function get_left_range_row($rows=array(), $colspan=1) { global $CFG, $USER; if ($this->get_pref('showranges')) { $rangerow = new html_table_row(); $rangerow->attributes['class'] = 'range r'.$this->rowcount++; $rangecell = new html_table_cell(); $rangecell->attributes['class'] = 'header range'; $rangecell->colspan = $colspan; $rangecell->header = true; $rangecell->scope = 'row'; $rangecell->text = $this->get_lang_string('range', 'grades'); $rangerow->cells[] = $rangecell; $rows[] = $rangerow; } return $rows; }
php
public function get_left_range_row($rows=array(), $colspan=1) { global $CFG, $USER; if ($this->get_pref('showranges')) { $rangerow = new html_table_row(); $rangerow->attributes['class'] = 'range r'.$this->rowcount++; $rangecell = new html_table_cell(); $rangecell->attributes['class'] = 'header range'; $rangecell->colspan = $colspan; $rangecell->header = true; $rangecell->scope = 'row'; $rangecell->text = $this->get_lang_string('range', 'grades'); $rangerow->cells[] = $rangecell; $rows[] = $rangerow; } return $rows; }
[ "public", "function", "get_left_range_row", "(", "$", "rows", "=", "array", "(", ")", ",", "$", "colspan", "=", "1", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "if", "(", "$", "this", "->", "get_pref", "(", "'showranges'", ")", ")", "{", "$", "rangerow", "=", "new", "html_table_row", "(", ")", ";", "$", "rangerow", "->", "attributes", "[", "'class'", "]", "=", "'range r'", ".", "$", "this", "->", "rowcount", "++", ";", "$", "rangecell", "=", "new", "html_table_cell", "(", ")", ";", "$", "rangecell", "->", "attributes", "[", "'class'", "]", "=", "'header range'", ";", "$", "rangecell", "->", "colspan", "=", "$", "colspan", ";", "$", "rangecell", "->", "header", "=", "true", ";", "$", "rangecell", "->", "scope", "=", "'row'", ";", "$", "rangecell", "->", "text", "=", "$", "this", "->", "get_lang_string", "(", "'range'", ",", "'grades'", ")", ";", "$", "rangerow", "->", "cells", "[", "]", "=", "$", "rangecell", ";", "$", "rows", "[", "]", "=", "$", "rangerow", ";", "}", "return", "$", "rows", ";", "}" ]
Builds and return the header for the row of ranges, for the left part of the grader report. @param array $rows The Array of rows for the left part of the report @param int $colspan The number of columns this cell has to span @return array Array of rows for the left part of the report
[ "Builds", "and", "return", "the", "header", "for", "the", "row", "of", "ranges", "for", "the", "left", "part", "of", "the", "grader", "report", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/grader/lib.php#L1309-L1326
211,889
moodle/moodle
grade/report/grader/lib.php
grade_report_grader.get_left_avg_row
public function get_left_avg_row($rows=array(), $colspan=1, $groupavg=false) { if (!$this->canviewhidden) { // totals might be affected by hiding, if user can not see hidden grades the aggregations might be altered // better not show them at all if user can not see all hideen grades return $rows; } $showaverages = $this->get_pref('showaverages'); $showaveragesgroup = $this->currentgroup && $showaverages; $straveragegroup = get_string('groupavg', 'grades'); if ($groupavg) { if ($showaveragesgroup) { $groupavgrow = new html_table_row(); $groupavgrow->attributes['class'] = 'groupavg r'.$this->rowcount++; $groupavgcell = new html_table_cell(); $groupavgcell->attributes['class'] = 'header range'; $groupavgcell->colspan = $colspan; $groupavgcell->header = true; $groupavgcell->scope = 'row'; $groupavgcell->text = $straveragegroup; $groupavgrow->cells[] = $groupavgcell; $rows[] = $groupavgrow; } } else { $straverage = get_string('overallaverage', 'grades'); if ($showaverages) { $avgrow = new html_table_row(); $avgrow->attributes['class'] = 'avg r'.$this->rowcount++; $avgcell = new html_table_cell(); $avgcell->attributes['class'] = 'header range'; $avgcell->colspan = $colspan; $avgcell->header = true; $avgcell->scope = 'row'; $avgcell->text = $straverage; $avgrow->cells[] = $avgcell; $rows[] = $avgrow; } } return $rows; }
php
public function get_left_avg_row($rows=array(), $colspan=1, $groupavg=false) { if (!$this->canviewhidden) { // totals might be affected by hiding, if user can not see hidden grades the aggregations might be altered // better not show them at all if user can not see all hideen grades return $rows; } $showaverages = $this->get_pref('showaverages'); $showaveragesgroup = $this->currentgroup && $showaverages; $straveragegroup = get_string('groupavg', 'grades'); if ($groupavg) { if ($showaveragesgroup) { $groupavgrow = new html_table_row(); $groupavgrow->attributes['class'] = 'groupavg r'.$this->rowcount++; $groupavgcell = new html_table_cell(); $groupavgcell->attributes['class'] = 'header range'; $groupavgcell->colspan = $colspan; $groupavgcell->header = true; $groupavgcell->scope = 'row'; $groupavgcell->text = $straveragegroup; $groupavgrow->cells[] = $groupavgcell; $rows[] = $groupavgrow; } } else { $straverage = get_string('overallaverage', 'grades'); if ($showaverages) { $avgrow = new html_table_row(); $avgrow->attributes['class'] = 'avg r'.$this->rowcount++; $avgcell = new html_table_cell(); $avgcell->attributes['class'] = 'header range'; $avgcell->colspan = $colspan; $avgcell->header = true; $avgcell->scope = 'row'; $avgcell->text = $straverage; $avgrow->cells[] = $avgcell; $rows[] = $avgrow; } } return $rows; }
[ "public", "function", "get_left_avg_row", "(", "$", "rows", "=", "array", "(", ")", ",", "$", "colspan", "=", "1", ",", "$", "groupavg", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "canviewhidden", ")", "{", "// totals might be affected by hiding, if user can not see hidden grades the aggregations might be altered", "// better not show them at all if user can not see all hideen grades", "return", "$", "rows", ";", "}", "$", "showaverages", "=", "$", "this", "->", "get_pref", "(", "'showaverages'", ")", ";", "$", "showaveragesgroup", "=", "$", "this", "->", "currentgroup", "&&", "$", "showaverages", ";", "$", "straveragegroup", "=", "get_string", "(", "'groupavg'", ",", "'grades'", ")", ";", "if", "(", "$", "groupavg", ")", "{", "if", "(", "$", "showaveragesgroup", ")", "{", "$", "groupavgrow", "=", "new", "html_table_row", "(", ")", ";", "$", "groupavgrow", "->", "attributes", "[", "'class'", "]", "=", "'groupavg r'", ".", "$", "this", "->", "rowcount", "++", ";", "$", "groupavgcell", "=", "new", "html_table_cell", "(", ")", ";", "$", "groupavgcell", "->", "attributes", "[", "'class'", "]", "=", "'header range'", ";", "$", "groupavgcell", "->", "colspan", "=", "$", "colspan", ";", "$", "groupavgcell", "->", "header", "=", "true", ";", "$", "groupavgcell", "->", "scope", "=", "'row'", ";", "$", "groupavgcell", "->", "text", "=", "$", "straveragegroup", ";", "$", "groupavgrow", "->", "cells", "[", "]", "=", "$", "groupavgcell", ";", "$", "rows", "[", "]", "=", "$", "groupavgrow", ";", "}", "}", "else", "{", "$", "straverage", "=", "get_string", "(", "'overallaverage'", ",", "'grades'", ")", ";", "if", "(", "$", "showaverages", ")", "{", "$", "avgrow", "=", "new", "html_table_row", "(", ")", ";", "$", "avgrow", "->", "attributes", "[", "'class'", "]", "=", "'avg r'", ".", "$", "this", "->", "rowcount", "++", ";", "$", "avgcell", "=", "new", "html_table_cell", "(", ")", ";", "$", "avgcell", "->", "attributes", "[", "'class'", "]", "=", "'header range'", ";", "$", "avgcell", "->", "colspan", "=", "$", "colspan", ";", "$", "avgcell", "->", "header", "=", "true", ";", "$", "avgcell", "->", "scope", "=", "'row'", ";", "$", "avgcell", "->", "text", "=", "$", "straverage", ";", "$", "avgrow", "->", "cells", "[", "]", "=", "$", "avgcell", ";", "$", "rows", "[", "]", "=", "$", "avgrow", ";", "}", "}", "return", "$", "rows", ";", "}" ]
Builds and return the headers for the rows of averages, for the left part of the grader report. @param array $rows The Array of rows for the left part of the report @param int $colspan The number of columns this cell has to span @param bool $groupavg If true, returns the row for group averages, otherwise for overall averages @return array Array of rows for the left part of the report
[ "Builds", "and", "return", "the", "headers", "for", "the", "rows", "of", "averages", "for", "the", "left", "part", "of", "the", "grader", "report", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/grader/lib.php#L1335-L1377
211,890
moodle/moodle
grade/report/grader/lib.php
grade_report_grader.get_right_icons_row
public function get_right_icons_row($rows=array()) { global $USER; if ($USER->gradeediting[$this->courseid]) { $iconsrow = new html_table_row(); $iconsrow->attributes['class'] = 'controls'; foreach ($this->gtree->items as $itemid => $unused) { // emulate grade element $item = $this->gtree->get_item($itemid); $eid = $this->gtree->get_item_eid($item); $element = $this->gtree->locate_element($eid); $itemcell = new html_table_cell(); $itemcell->attributes['class'] = 'controls icons i'.$itemid; $itemcell->text = $this->get_icons($element); $iconsrow->cells[] = $itemcell; } $rows[] = $iconsrow; } return $rows; }
php
public function get_right_icons_row($rows=array()) { global $USER; if ($USER->gradeediting[$this->courseid]) { $iconsrow = new html_table_row(); $iconsrow->attributes['class'] = 'controls'; foreach ($this->gtree->items as $itemid => $unused) { // emulate grade element $item = $this->gtree->get_item($itemid); $eid = $this->gtree->get_item_eid($item); $element = $this->gtree->locate_element($eid); $itemcell = new html_table_cell(); $itemcell->attributes['class'] = 'controls icons i'.$itemid; $itemcell->text = $this->get_icons($element); $iconsrow->cells[] = $itemcell; } $rows[] = $iconsrow; } return $rows; }
[ "public", "function", "get_right_icons_row", "(", "$", "rows", "=", "array", "(", ")", ")", "{", "global", "$", "USER", ";", "if", "(", "$", "USER", "->", "gradeediting", "[", "$", "this", "->", "courseid", "]", ")", "{", "$", "iconsrow", "=", "new", "html_table_row", "(", ")", ";", "$", "iconsrow", "->", "attributes", "[", "'class'", "]", "=", "'controls'", ";", "foreach", "(", "$", "this", "->", "gtree", "->", "items", "as", "$", "itemid", "=>", "$", "unused", ")", "{", "// emulate grade element", "$", "item", "=", "$", "this", "->", "gtree", "->", "get_item", "(", "$", "itemid", ")", ";", "$", "eid", "=", "$", "this", "->", "gtree", "->", "get_item_eid", "(", "$", "item", ")", ";", "$", "element", "=", "$", "this", "->", "gtree", "->", "locate_element", "(", "$", "eid", ")", ";", "$", "itemcell", "=", "new", "html_table_cell", "(", ")", ";", "$", "itemcell", "->", "attributes", "[", "'class'", "]", "=", "'controls icons i'", ".", "$", "itemid", ";", "$", "itemcell", "->", "text", "=", "$", "this", "->", "get_icons", "(", "$", "element", ")", ";", "$", "iconsrow", "->", "cells", "[", "]", "=", "$", "itemcell", ";", "}", "$", "rows", "[", "]", "=", "$", "iconsrow", ";", "}", "return", "$", "rows", ";", "}" ]
Builds and return the row of icons when editing is on, for the right part of the grader report. @param array $rows The Array of rows for the right part of the report @return array Array of rows for the right part of the report
[ "Builds", "and", "return", "the", "row", "of", "icons", "when", "editing", "is", "on", "for", "the", "right", "part", "of", "the", "grader", "report", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/grader/lib.php#L1384-L1404
211,891
moodle/moodle
grade/report/grader/lib.php
grade_report_grader.get_right_range_row
public function get_right_range_row($rows=array()) { global $OUTPUT; if ($this->get_pref('showranges')) { $rangesdisplaytype = $this->get_pref('rangesdisplaytype'); $rangesdecimalpoints = $this->get_pref('rangesdecimalpoints'); $rangerow = new html_table_row(); $rangerow->attributes['class'] = 'heading range'; foreach ($this->gtree->items as $itemid => $unused) { $item =& $this->gtree->items[$itemid]; $itemcell = new html_table_cell(); $itemcell->attributes['class'] .= ' range i'. $itemid; $hidden = ''; if ($item->is_hidden()) { $hidden = ' dimmed_text '; } $formattedrange = $item->get_formatted_range($rangesdisplaytype, $rangesdecimalpoints); $itemcell->text = $OUTPUT->container($formattedrange, 'rangevalues'.$hidden); $rangerow->cells[] = $itemcell; } $rows[] = $rangerow; } return $rows; }
php
public function get_right_range_row($rows=array()) { global $OUTPUT; if ($this->get_pref('showranges')) { $rangesdisplaytype = $this->get_pref('rangesdisplaytype'); $rangesdecimalpoints = $this->get_pref('rangesdecimalpoints'); $rangerow = new html_table_row(); $rangerow->attributes['class'] = 'heading range'; foreach ($this->gtree->items as $itemid => $unused) { $item =& $this->gtree->items[$itemid]; $itemcell = new html_table_cell(); $itemcell->attributes['class'] .= ' range i'. $itemid; $hidden = ''; if ($item->is_hidden()) { $hidden = ' dimmed_text '; } $formattedrange = $item->get_formatted_range($rangesdisplaytype, $rangesdecimalpoints); $itemcell->text = $OUTPUT->container($formattedrange, 'rangevalues'.$hidden); $rangerow->cells[] = $itemcell; } $rows[] = $rangerow; } return $rows; }
[ "public", "function", "get_right_range_row", "(", "$", "rows", "=", "array", "(", ")", ")", "{", "global", "$", "OUTPUT", ";", "if", "(", "$", "this", "->", "get_pref", "(", "'showranges'", ")", ")", "{", "$", "rangesdisplaytype", "=", "$", "this", "->", "get_pref", "(", "'rangesdisplaytype'", ")", ";", "$", "rangesdecimalpoints", "=", "$", "this", "->", "get_pref", "(", "'rangesdecimalpoints'", ")", ";", "$", "rangerow", "=", "new", "html_table_row", "(", ")", ";", "$", "rangerow", "->", "attributes", "[", "'class'", "]", "=", "'heading range'", ";", "foreach", "(", "$", "this", "->", "gtree", "->", "items", "as", "$", "itemid", "=>", "$", "unused", ")", "{", "$", "item", "=", "&", "$", "this", "->", "gtree", "->", "items", "[", "$", "itemid", "]", ";", "$", "itemcell", "=", "new", "html_table_cell", "(", ")", ";", "$", "itemcell", "->", "attributes", "[", "'class'", "]", ".=", "' range i'", ".", "$", "itemid", ";", "$", "hidden", "=", "''", ";", "if", "(", "$", "item", "->", "is_hidden", "(", ")", ")", "{", "$", "hidden", "=", "' dimmed_text '", ";", "}", "$", "formattedrange", "=", "$", "item", "->", "get_formatted_range", "(", "$", "rangesdisplaytype", ",", "$", "rangesdecimalpoints", ")", ";", "$", "itemcell", "->", "text", "=", "$", "OUTPUT", "->", "container", "(", "$", "formattedrange", ",", "'rangevalues'", ".", "$", "hidden", ")", ";", "$", "rangerow", "->", "cells", "[", "]", "=", "$", "itemcell", ";", "}", "$", "rows", "[", "]", "=", "$", "rangerow", ";", "}", "return", "$", "rows", ";", "}" ]
Builds and return the row of ranges for the right part of the grader report. @param array $rows The Array of rows for the right part of the report @return array Array of rows for the right part of the report
[ "Builds", "and", "return", "the", "row", "of", "ranges", "for", "the", "right", "part", "of", "the", "grader", "report", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/grader/lib.php#L1411-L1438
211,892
moodle/moodle
grade/report/grader/lib.php
grade_report_grader.get_course_header
protected function get_course_header($element) { global $OUTPUT; $icon = ''; // If object is a category, display expand/contract icon. if ($element['type'] == 'category') { // Load language strings. $strswitchminus = $this->get_lang_string('aggregatesonly', 'grades'); $strswitchplus = $this->get_lang_string('gradesonly', 'grades'); $strswitchwhole = $this->get_lang_string('fullmode', 'grades'); $url = new moodle_url($this->gpr->get_return_url(null, array('target' => $element['eid'], 'sesskey' => sesskey()))); if (in_array($element['object']->id, $this->collapsed['aggregatesonly'])) { $url->param('action', 'switch_plus'); $icon = $OUTPUT->action_icon($url, new pix_icon('t/switch_plus', $strswitchplus), null, null); $showing = get_string('showingaggregatesonly', 'grades'); } else if (in_array($element['object']->id, $this->collapsed['gradesonly'])) { $url->param('action', 'switch_whole'); $icon = $OUTPUT->action_icon($url, new pix_icon('t/switch_whole', $strswitchwhole), null, null); $showing = get_string('showinggradesonly', 'grades'); } else { $url->param('action', 'switch_minus'); $icon = $OUTPUT->action_icon($url, new pix_icon('t/switch_minus', $strswitchminus), null, null); $showing = get_string('showingfullmode', 'grades'); } } $name = $element['object']->get_name(); $courseheaderid = 'courseheader_' . clean_param($name, PARAM_ALPHANUMEXT); $courseheader = html_writer::tag('span', $name, array('id' => $courseheaderid, 'title' => $name, 'class' => 'gradeitemheader')); $courseheader .= html_writer::label($showing, $courseheaderid, false, array('class' => 'accesshide')); $courseheader .= $icon; return $courseheader; }
php
protected function get_course_header($element) { global $OUTPUT; $icon = ''; // If object is a category, display expand/contract icon. if ($element['type'] == 'category') { // Load language strings. $strswitchminus = $this->get_lang_string('aggregatesonly', 'grades'); $strswitchplus = $this->get_lang_string('gradesonly', 'grades'); $strswitchwhole = $this->get_lang_string('fullmode', 'grades'); $url = new moodle_url($this->gpr->get_return_url(null, array('target' => $element['eid'], 'sesskey' => sesskey()))); if (in_array($element['object']->id, $this->collapsed['aggregatesonly'])) { $url->param('action', 'switch_plus'); $icon = $OUTPUT->action_icon($url, new pix_icon('t/switch_plus', $strswitchplus), null, null); $showing = get_string('showingaggregatesonly', 'grades'); } else if (in_array($element['object']->id, $this->collapsed['gradesonly'])) { $url->param('action', 'switch_whole'); $icon = $OUTPUT->action_icon($url, new pix_icon('t/switch_whole', $strswitchwhole), null, null); $showing = get_string('showinggradesonly', 'grades'); } else { $url->param('action', 'switch_minus'); $icon = $OUTPUT->action_icon($url, new pix_icon('t/switch_minus', $strswitchminus), null, null); $showing = get_string('showingfullmode', 'grades'); } } $name = $element['object']->get_name(); $courseheaderid = 'courseheader_' . clean_param($name, PARAM_ALPHANUMEXT); $courseheader = html_writer::tag('span', $name, array('id' => $courseheaderid, 'title' => $name, 'class' => 'gradeitemheader')); $courseheader .= html_writer::label($showing, $courseheaderid, false, array('class' => 'accesshide')); $courseheader .= $icon; return $courseheader; }
[ "protected", "function", "get_course_header", "(", "$", "element", ")", "{", "global", "$", "OUTPUT", ";", "$", "icon", "=", "''", ";", "// If object is a category, display expand/contract icon.", "if", "(", "$", "element", "[", "'type'", "]", "==", "'category'", ")", "{", "// Load language strings.", "$", "strswitchminus", "=", "$", "this", "->", "get_lang_string", "(", "'aggregatesonly'", ",", "'grades'", ")", ";", "$", "strswitchplus", "=", "$", "this", "->", "get_lang_string", "(", "'gradesonly'", ",", "'grades'", ")", ";", "$", "strswitchwhole", "=", "$", "this", "->", "get_lang_string", "(", "'fullmode'", ",", "'grades'", ")", ";", "$", "url", "=", "new", "moodle_url", "(", "$", "this", "->", "gpr", "->", "get_return_url", "(", "null", ",", "array", "(", "'target'", "=>", "$", "element", "[", "'eid'", "]", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ")", ";", "if", "(", "in_array", "(", "$", "element", "[", "'object'", "]", "->", "id", ",", "$", "this", "->", "collapsed", "[", "'aggregatesonly'", "]", ")", ")", "{", "$", "url", "->", "param", "(", "'action'", ",", "'switch_plus'", ")", ";", "$", "icon", "=", "$", "OUTPUT", "->", "action_icon", "(", "$", "url", ",", "new", "pix_icon", "(", "'t/switch_plus'", ",", "$", "strswitchplus", ")", ",", "null", ",", "null", ")", ";", "$", "showing", "=", "get_string", "(", "'showingaggregatesonly'", ",", "'grades'", ")", ";", "}", "else", "if", "(", "in_array", "(", "$", "element", "[", "'object'", "]", "->", "id", ",", "$", "this", "->", "collapsed", "[", "'gradesonly'", "]", ")", ")", "{", "$", "url", "->", "param", "(", "'action'", ",", "'switch_whole'", ")", ";", "$", "icon", "=", "$", "OUTPUT", "->", "action_icon", "(", "$", "url", ",", "new", "pix_icon", "(", "'t/switch_whole'", ",", "$", "strswitchwhole", ")", ",", "null", ",", "null", ")", ";", "$", "showing", "=", "get_string", "(", "'showinggradesonly'", ",", "'grades'", ")", ";", "}", "else", "{", "$", "url", "->", "param", "(", "'action'", ",", "'switch_minus'", ")", ";", "$", "icon", "=", "$", "OUTPUT", "->", "action_icon", "(", "$", "url", ",", "new", "pix_icon", "(", "'t/switch_minus'", ",", "$", "strswitchminus", ")", ",", "null", ",", "null", ")", ";", "$", "showing", "=", "get_string", "(", "'showingfullmode'", ",", "'grades'", ")", ";", "}", "}", "$", "name", "=", "$", "element", "[", "'object'", "]", "->", "get_name", "(", ")", ";", "$", "courseheaderid", "=", "'courseheader_'", ".", "clean_param", "(", "$", "name", ",", "PARAM_ALPHANUMEXT", ")", ";", "$", "courseheader", "=", "html_writer", "::", "tag", "(", "'span'", ",", "$", "name", ",", "array", "(", "'id'", "=>", "$", "courseheaderid", ",", "'title'", "=>", "$", "name", ",", "'class'", "=>", "'gradeitemheader'", ")", ")", ";", "$", "courseheader", ".=", "html_writer", "::", "label", "(", "$", "showing", ",", "$", "courseheaderid", ",", "false", ",", "array", "(", "'class'", "=>", "'accesshide'", ")", ")", ";", "$", "courseheader", ".=", "$", "icon", ";", "return", "$", "courseheader", ";", "}" ]
Given element category, create a collapsible icon and course header. @param array $element @return string HTML
[ "Given", "element", "category", "create", "a", "collapsible", "icon", "and", "course", "header", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/grader/lib.php#L1621-L1657
211,893
moodle/moodle
grade/report/grader/lib.php
grade_report_grader.get_icons
protected function get_icons($element) { global $CFG, $USER, $OUTPUT; if (!$USER->gradeediting[$this->courseid]) { return '<div class="grade_icons" />'; } // Init all icons $editicon = ''; $editable = true; if ($element['type'] == 'grade') { $item = $element['object']->grade_item; if ($item->is_course_item() or $item->is_category_item()) { $editable = $this->overridecat; } } if ($element['type'] != 'categoryitem' && $element['type'] != 'courseitem' && $editable) { $editicon = $this->gtree->get_edit_icon($element, $this->gpr); } $editcalculationicon = ''; $showhideicon = ''; $lockunlockicon = ''; if (has_capability('moodle/grade:manage', $this->context)) { if ($this->get_pref('showcalculations')) { $editcalculationicon = $this->gtree->get_calculation_icon($element, $this->gpr); } if ($this->get_pref('showeyecons')) { $showhideicon = $this->gtree->get_hiding_icon($element, $this->gpr); } if ($this->get_pref('showlocks')) { $lockunlockicon = $this->gtree->get_locking_icon($element, $this->gpr); } } $gradeanalysisicon = ''; if ($this->get_pref('showanalysisicon') && $element['type'] == 'grade') { $gradeanalysisicon .= $this->gtree->get_grade_analysis_icon($element['object']); } return $OUTPUT->container($editicon.$editcalculationicon.$showhideicon.$lockunlockicon.$gradeanalysisicon, 'grade_icons'); }
php
protected function get_icons($element) { global $CFG, $USER, $OUTPUT; if (!$USER->gradeediting[$this->courseid]) { return '<div class="grade_icons" />'; } // Init all icons $editicon = ''; $editable = true; if ($element['type'] == 'grade') { $item = $element['object']->grade_item; if ($item->is_course_item() or $item->is_category_item()) { $editable = $this->overridecat; } } if ($element['type'] != 'categoryitem' && $element['type'] != 'courseitem' && $editable) { $editicon = $this->gtree->get_edit_icon($element, $this->gpr); } $editcalculationicon = ''; $showhideicon = ''; $lockunlockicon = ''; if (has_capability('moodle/grade:manage', $this->context)) { if ($this->get_pref('showcalculations')) { $editcalculationicon = $this->gtree->get_calculation_icon($element, $this->gpr); } if ($this->get_pref('showeyecons')) { $showhideicon = $this->gtree->get_hiding_icon($element, $this->gpr); } if ($this->get_pref('showlocks')) { $lockunlockicon = $this->gtree->get_locking_icon($element, $this->gpr); } } $gradeanalysisicon = ''; if ($this->get_pref('showanalysisicon') && $element['type'] == 'grade') { $gradeanalysisicon .= $this->gtree->get_grade_analysis_icon($element['object']); } return $OUTPUT->container($editicon.$editcalculationicon.$showhideicon.$lockunlockicon.$gradeanalysisicon, 'grade_icons'); }
[ "protected", "function", "get_icons", "(", "$", "element", ")", "{", "global", "$", "CFG", ",", "$", "USER", ",", "$", "OUTPUT", ";", "if", "(", "!", "$", "USER", "->", "gradeediting", "[", "$", "this", "->", "courseid", "]", ")", "{", "return", "'<div class=\"grade_icons\" />'", ";", "}", "// Init all icons", "$", "editicon", "=", "''", ";", "$", "editable", "=", "true", ";", "if", "(", "$", "element", "[", "'type'", "]", "==", "'grade'", ")", "{", "$", "item", "=", "$", "element", "[", "'object'", "]", "->", "grade_item", ";", "if", "(", "$", "item", "->", "is_course_item", "(", ")", "or", "$", "item", "->", "is_category_item", "(", ")", ")", "{", "$", "editable", "=", "$", "this", "->", "overridecat", ";", "}", "}", "if", "(", "$", "element", "[", "'type'", "]", "!=", "'categoryitem'", "&&", "$", "element", "[", "'type'", "]", "!=", "'courseitem'", "&&", "$", "editable", ")", "{", "$", "editicon", "=", "$", "this", "->", "gtree", "->", "get_edit_icon", "(", "$", "element", ",", "$", "this", "->", "gpr", ")", ";", "}", "$", "editcalculationicon", "=", "''", ";", "$", "showhideicon", "=", "''", ";", "$", "lockunlockicon", "=", "''", ";", "if", "(", "has_capability", "(", "'moodle/grade:manage'", ",", "$", "this", "->", "context", ")", ")", "{", "if", "(", "$", "this", "->", "get_pref", "(", "'showcalculations'", ")", ")", "{", "$", "editcalculationicon", "=", "$", "this", "->", "gtree", "->", "get_calculation_icon", "(", "$", "element", ",", "$", "this", "->", "gpr", ")", ";", "}", "if", "(", "$", "this", "->", "get_pref", "(", "'showeyecons'", ")", ")", "{", "$", "showhideicon", "=", "$", "this", "->", "gtree", "->", "get_hiding_icon", "(", "$", "element", ",", "$", "this", "->", "gpr", ")", ";", "}", "if", "(", "$", "this", "->", "get_pref", "(", "'showlocks'", ")", ")", "{", "$", "lockunlockicon", "=", "$", "this", "->", "gtree", "->", "get_locking_icon", "(", "$", "element", ",", "$", "this", "->", "gpr", ")", ";", "}", "}", "$", "gradeanalysisicon", "=", "''", ";", "if", "(", "$", "this", "->", "get_pref", "(", "'showanalysisicon'", ")", "&&", "$", "element", "[", "'type'", "]", "==", "'grade'", ")", "{", "$", "gradeanalysisicon", ".=", "$", "this", "->", "gtree", "->", "get_grade_analysis_icon", "(", "$", "element", "[", "'object'", "]", ")", ";", "}", "return", "$", "OUTPUT", "->", "container", "(", "$", "editicon", ".", "$", "editcalculationicon", ".", "$", "showhideicon", ".", "$", "lockunlockicon", ".", "$", "gradeanalysisicon", ",", "'grade_icons'", ")", ";", "}" ]
Given a grade_category, grade_item or grade_grade, this function figures out the state of the object and builds then returns a div with the icons needed for the grader report. @param array $element @return string HTML
[ "Given", "a", "grade_category", "grade_item", "or", "grade_grade", "this", "function", "figures", "out", "the", "state", "of", "the", "object", "and", "builds", "then", "returns", "a", "div", "with", "the", "icons", "needed", "for", "the", "grader", "report", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/grader/lib.php#L1667-L1715
211,894
moodle/moodle
grade/report/grader/lib.php
grade_report_grader.filter_collapsed_categories
protected static function filter_collapsed_categories($courseid, $collapsed) { global $DB; if (empty($collapsed)) { $collapsed = array('aggregatesonly' => array(), 'gradesonly' => array()); } if (empty($collapsed['aggregatesonly']) && empty($collapsed['gradesonly'])) { return $collapsed; } $cats = $DB->get_fieldset_select('grade_categories', 'id', 'courseid = ?', array($courseid)); $collapsed['aggregatesonly'] = array_values(array_intersect($collapsed['aggregatesonly'], $cats)); $collapsed['gradesonly'] = array_values(array_intersect($collapsed['gradesonly'], $cats)); return $collapsed; }
php
protected static function filter_collapsed_categories($courseid, $collapsed) { global $DB; if (empty($collapsed)) { $collapsed = array('aggregatesonly' => array(), 'gradesonly' => array()); } if (empty($collapsed['aggregatesonly']) && empty($collapsed['gradesonly'])) { return $collapsed; } $cats = $DB->get_fieldset_select('grade_categories', 'id', 'courseid = ?', array($courseid)); $collapsed['aggregatesonly'] = array_values(array_intersect($collapsed['aggregatesonly'], $cats)); $collapsed['gradesonly'] = array_values(array_intersect($collapsed['gradesonly'], $cats)); return $collapsed; }
[ "protected", "static", "function", "filter_collapsed_categories", "(", "$", "courseid", ",", "$", "collapsed", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "collapsed", ")", ")", "{", "$", "collapsed", "=", "array", "(", "'aggregatesonly'", "=>", "array", "(", ")", ",", "'gradesonly'", "=>", "array", "(", ")", ")", ";", "}", "if", "(", "empty", "(", "$", "collapsed", "[", "'aggregatesonly'", "]", ")", "&&", "empty", "(", "$", "collapsed", "[", "'gradesonly'", "]", ")", ")", "{", "return", "$", "collapsed", ";", "}", "$", "cats", "=", "$", "DB", "->", "get_fieldset_select", "(", "'grade_categories'", ",", "'id'", ",", "'courseid = ?'", ",", "array", "(", "$", "courseid", ")", ")", ";", "$", "collapsed", "[", "'aggregatesonly'", "]", "=", "array_values", "(", "array_intersect", "(", "$", "collapsed", "[", "'aggregatesonly'", "]", ",", "$", "cats", ")", ")", ";", "$", "collapsed", "[", "'gradesonly'", "]", "=", "array_values", "(", "array_intersect", "(", "$", "collapsed", "[", "'gradesonly'", "]", ",", "$", "cats", ")", ")", ";", "return", "$", "collapsed", ";", "}" ]
From the list of categories that this user prefers to collapse choose ones that belong to the current course. This function serves two purposes. Mainly it helps migrating from user preference style when all courses were stored in one preference. Also it helps to remove the settings for categories that were removed if the array for one course grows too big. @param int $courseid @param array $collapsed @return array
[ "From", "the", "list", "of", "categories", "that", "this", "user", "prefers", "to", "collapse", "choose", "ones", "that", "belong", "to", "the", "current", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/grader/lib.php#L1747-L1759
211,895
moodle/moodle
grade/report/grader/lib.php
grade_report_grader.get_collapsed_preferences
protected static function get_collapsed_preferences($courseid) { if ($collapsed = get_user_preferences('grade_report_grader_collapsed_categories'.$courseid)) { return json_decode($collapsed, true); } // Try looking for old location of user setting that used to store all courses in one serialized user preference. if (($oldcollapsedpref = get_user_preferences('grade_report_grader_collapsed_categories')) !== null) { if ($collapsedall = unserialize_array($oldcollapsedpref)) { // We found the old-style preference, filter out only categories that belong to this course and update the prefs. $collapsed = static::filter_collapsed_categories($courseid, $collapsedall); if (!empty($collapsed['aggregatesonly']) || !empty($collapsed['gradesonly'])) { static::set_collapsed_preferences($courseid, $collapsed); $collapsedall['aggregatesonly'] = array_diff($collapsedall['aggregatesonly'], $collapsed['aggregatesonly']); $collapsedall['gradesonly'] = array_diff($collapsedall['gradesonly'], $collapsed['gradesonly']); if (!empty($collapsedall['aggregatesonly']) || !empty($collapsedall['gradesonly'])) { set_user_preference('grade_report_grader_collapsed_categories', serialize($collapsedall)); } else { unset_user_preference('grade_report_grader_collapsed_categories'); } } } else { // We found the old-style preference, but it is unreadable, discard it. unset_user_preference('grade_report_grader_collapsed_categories'); } } else { $collapsed = array('aggregatesonly' => array(), 'gradesonly' => array()); } return $collapsed; }
php
protected static function get_collapsed_preferences($courseid) { if ($collapsed = get_user_preferences('grade_report_grader_collapsed_categories'.$courseid)) { return json_decode($collapsed, true); } // Try looking for old location of user setting that used to store all courses in one serialized user preference. if (($oldcollapsedpref = get_user_preferences('grade_report_grader_collapsed_categories')) !== null) { if ($collapsedall = unserialize_array($oldcollapsedpref)) { // We found the old-style preference, filter out only categories that belong to this course and update the prefs. $collapsed = static::filter_collapsed_categories($courseid, $collapsedall); if (!empty($collapsed['aggregatesonly']) || !empty($collapsed['gradesonly'])) { static::set_collapsed_preferences($courseid, $collapsed); $collapsedall['aggregatesonly'] = array_diff($collapsedall['aggregatesonly'], $collapsed['aggregatesonly']); $collapsedall['gradesonly'] = array_diff($collapsedall['gradesonly'], $collapsed['gradesonly']); if (!empty($collapsedall['aggregatesonly']) || !empty($collapsedall['gradesonly'])) { set_user_preference('grade_report_grader_collapsed_categories', serialize($collapsedall)); } else { unset_user_preference('grade_report_grader_collapsed_categories'); } } } else { // We found the old-style preference, but it is unreadable, discard it. unset_user_preference('grade_report_grader_collapsed_categories'); } } else { $collapsed = array('aggregatesonly' => array(), 'gradesonly' => array()); } return $collapsed; }
[ "protected", "static", "function", "get_collapsed_preferences", "(", "$", "courseid", ")", "{", "if", "(", "$", "collapsed", "=", "get_user_preferences", "(", "'grade_report_grader_collapsed_categories'", ".", "$", "courseid", ")", ")", "{", "return", "json_decode", "(", "$", "collapsed", ",", "true", ")", ";", "}", "// Try looking for old location of user setting that used to store all courses in one serialized user preference.", "if", "(", "(", "$", "oldcollapsedpref", "=", "get_user_preferences", "(", "'grade_report_grader_collapsed_categories'", ")", ")", "!==", "null", ")", "{", "if", "(", "$", "collapsedall", "=", "unserialize_array", "(", "$", "oldcollapsedpref", ")", ")", "{", "// We found the old-style preference, filter out only categories that belong to this course and update the prefs.", "$", "collapsed", "=", "static", "::", "filter_collapsed_categories", "(", "$", "courseid", ",", "$", "collapsedall", ")", ";", "if", "(", "!", "empty", "(", "$", "collapsed", "[", "'aggregatesonly'", "]", ")", "||", "!", "empty", "(", "$", "collapsed", "[", "'gradesonly'", "]", ")", ")", "{", "static", "::", "set_collapsed_preferences", "(", "$", "courseid", ",", "$", "collapsed", ")", ";", "$", "collapsedall", "[", "'aggregatesonly'", "]", "=", "array_diff", "(", "$", "collapsedall", "[", "'aggregatesonly'", "]", ",", "$", "collapsed", "[", "'aggregatesonly'", "]", ")", ";", "$", "collapsedall", "[", "'gradesonly'", "]", "=", "array_diff", "(", "$", "collapsedall", "[", "'gradesonly'", "]", ",", "$", "collapsed", "[", "'gradesonly'", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "collapsedall", "[", "'aggregatesonly'", "]", ")", "||", "!", "empty", "(", "$", "collapsedall", "[", "'gradesonly'", "]", ")", ")", "{", "set_user_preference", "(", "'grade_report_grader_collapsed_categories'", ",", "serialize", "(", "$", "collapsedall", ")", ")", ";", "}", "else", "{", "unset_user_preference", "(", "'grade_report_grader_collapsed_categories'", ")", ";", "}", "}", "}", "else", "{", "// We found the old-style preference, but it is unreadable, discard it.", "unset_user_preference", "(", "'grade_report_grader_collapsed_categories'", ")", ";", "}", "}", "else", "{", "$", "collapsed", "=", "array", "(", "'aggregatesonly'", "=>", "array", "(", ")", ",", "'gradesonly'", "=>", "array", "(", ")", ")", ";", "}", "return", "$", "collapsed", ";", "}" ]
Returns the list of categories that this user wants to collapse or display aggregatesonly This method also migrates on request from the old format of storing user preferences when they were stored in one preference for all courses causing DB error when trying to insert very big value. @param int $courseid @return array
[ "Returns", "the", "list", "of", "categories", "that", "this", "user", "wants", "to", "collapse", "or", "display", "aggregatesonly" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/grader/lib.php#L1770-L1798
211,896
moodle/moodle
grade/report/grader/lib.php
grade_report_grader.set_collapsed_preferences
protected static function set_collapsed_preferences($courseid, $collapsed) { global $DB; // In an unlikely case that the list of collapsed categories for one course is too big for the user preference size, // try to filter the list of categories since array may contain categories that were deleted. if (strlen(json_encode($collapsed)) >= 1333) { $collapsed = static::filter_collapsed_categories($courseid, $collapsed); } // If this did not help, "forget" about some of the collapsed categories. Still better than to loose all information. while (strlen(json_encode($collapsed)) >= 1333) { if (count($collapsed['aggregatesonly'])) { array_pop($collapsed['aggregatesonly']); } if (count($collapsed['gradesonly'])) { array_pop($collapsed['gradesonly']); } } if (!empty($collapsed['aggregatesonly']) || !empty($collapsed['gradesonly'])) { set_user_preference('grade_report_grader_collapsed_categories'.$courseid, json_encode($collapsed)); } else { unset_user_preference('grade_report_grader_collapsed_categories'.$courseid); } }
php
protected static function set_collapsed_preferences($courseid, $collapsed) { global $DB; // In an unlikely case that the list of collapsed categories for one course is too big for the user preference size, // try to filter the list of categories since array may contain categories that were deleted. if (strlen(json_encode($collapsed)) >= 1333) { $collapsed = static::filter_collapsed_categories($courseid, $collapsed); } // If this did not help, "forget" about some of the collapsed categories. Still better than to loose all information. while (strlen(json_encode($collapsed)) >= 1333) { if (count($collapsed['aggregatesonly'])) { array_pop($collapsed['aggregatesonly']); } if (count($collapsed['gradesonly'])) { array_pop($collapsed['gradesonly']); } } if (!empty($collapsed['aggregatesonly']) || !empty($collapsed['gradesonly'])) { set_user_preference('grade_report_grader_collapsed_categories'.$courseid, json_encode($collapsed)); } else { unset_user_preference('grade_report_grader_collapsed_categories'.$courseid); } }
[ "protected", "static", "function", "set_collapsed_preferences", "(", "$", "courseid", ",", "$", "collapsed", ")", "{", "global", "$", "DB", ";", "// In an unlikely case that the list of collapsed categories for one course is too big for the user preference size,", "// try to filter the list of categories since array may contain categories that were deleted.", "if", "(", "strlen", "(", "json_encode", "(", "$", "collapsed", ")", ")", ">=", "1333", ")", "{", "$", "collapsed", "=", "static", "::", "filter_collapsed_categories", "(", "$", "courseid", ",", "$", "collapsed", ")", ";", "}", "// If this did not help, \"forget\" about some of the collapsed categories. Still better than to loose all information.", "while", "(", "strlen", "(", "json_encode", "(", "$", "collapsed", ")", ")", ">=", "1333", ")", "{", "if", "(", "count", "(", "$", "collapsed", "[", "'aggregatesonly'", "]", ")", ")", "{", "array_pop", "(", "$", "collapsed", "[", "'aggregatesonly'", "]", ")", ";", "}", "if", "(", "count", "(", "$", "collapsed", "[", "'gradesonly'", "]", ")", ")", "{", "array_pop", "(", "$", "collapsed", "[", "'gradesonly'", "]", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "collapsed", "[", "'aggregatesonly'", "]", ")", "||", "!", "empty", "(", "$", "collapsed", "[", "'gradesonly'", "]", ")", ")", "{", "set_user_preference", "(", "'grade_report_grader_collapsed_categories'", ".", "$", "courseid", ",", "json_encode", "(", "$", "collapsed", ")", ")", ";", "}", "else", "{", "unset_user_preference", "(", "'grade_report_grader_collapsed_categories'", ".", "$", "courseid", ")", ";", "}", "}" ]
Sets the list of categories that user wants to see collapsed in user preferences This method may filter or even trim the list if it does not fit in DB field. @param int $courseid @param array $collapsed
[ "Sets", "the", "list", "of", "categories", "that", "user", "wants", "to", "see", "collapsed", "in", "user", "preferences" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/grader/lib.php#L1808-L1831
211,897
moodle/moodle
grade/report/grader/lib.php
grade_report_grader.get_sort_arrows
public function get_sort_arrows(array $extrafields = array()) { global $OUTPUT, $CFG; $arrows = array(); $strsortasc = $this->get_lang_string('sortasc', 'grades'); $strsortdesc = $this->get_lang_string('sortdesc', 'grades'); $iconasc = $OUTPUT->pix_icon('t/sort_asc', $strsortasc, '', array('class' => 'iconsmall sorticon')); $icondesc = $OUTPUT->pix_icon('t/sort_desc', $strsortdesc, '', array('class' => 'iconsmall sorticon')); // Sourced from tablelib.php // Check the full name display for sortable fields. if (has_capability('moodle/site:viewfullnames', $this->context)) { $nameformat = $CFG->alternativefullnameformat; } else { $nameformat = $CFG->fullnamedisplay; } if ($nameformat == 'language') { $nameformat = get_string('fullnamedisplay'); } $arrows['studentname'] = ''; $requirednames = order_in_string(get_all_user_name_fields(), $nameformat); if (!empty($requirednames)) { foreach ($requirednames as $name) { $arrows['studentname'] .= html_writer::link( new moodle_url($this->baseurl, array('sortitemid' => $name)), $this->get_lang_string($name) ); if ($this->sortitemid == $name) { $arrows['studentname'] .= $this->sortorder == 'ASC' ? $iconasc : $icondesc; } $arrows['studentname'] .= ' / '; } $arrows['studentname'] = substr($arrows['studentname'], 0, -3); } foreach ($extrafields as $field) { $fieldlink = html_writer::link(new moodle_url($this->baseurl, array('sortitemid'=>$field)), get_user_field_name($field)); $arrows[$field] = $fieldlink; if ($field == $this->sortitemid) { if ($this->sortorder == 'ASC') { $arrows[$field] .= $iconasc; } else { $arrows[$field] .= $icondesc; } } } return $arrows; }
php
public function get_sort_arrows(array $extrafields = array()) { global $OUTPUT, $CFG; $arrows = array(); $strsortasc = $this->get_lang_string('sortasc', 'grades'); $strsortdesc = $this->get_lang_string('sortdesc', 'grades'); $iconasc = $OUTPUT->pix_icon('t/sort_asc', $strsortasc, '', array('class' => 'iconsmall sorticon')); $icondesc = $OUTPUT->pix_icon('t/sort_desc', $strsortdesc, '', array('class' => 'iconsmall sorticon')); // Sourced from tablelib.php // Check the full name display for sortable fields. if (has_capability('moodle/site:viewfullnames', $this->context)) { $nameformat = $CFG->alternativefullnameformat; } else { $nameformat = $CFG->fullnamedisplay; } if ($nameformat == 'language') { $nameformat = get_string('fullnamedisplay'); } $arrows['studentname'] = ''; $requirednames = order_in_string(get_all_user_name_fields(), $nameformat); if (!empty($requirednames)) { foreach ($requirednames as $name) { $arrows['studentname'] .= html_writer::link( new moodle_url($this->baseurl, array('sortitemid' => $name)), $this->get_lang_string($name) ); if ($this->sortitemid == $name) { $arrows['studentname'] .= $this->sortorder == 'ASC' ? $iconasc : $icondesc; } $arrows['studentname'] .= ' / '; } $arrows['studentname'] = substr($arrows['studentname'], 0, -3); } foreach ($extrafields as $field) { $fieldlink = html_writer::link(new moodle_url($this->baseurl, array('sortitemid'=>$field)), get_user_field_name($field)); $arrows[$field] = $fieldlink; if ($field == $this->sortitemid) { if ($this->sortorder == 'ASC') { $arrows[$field] .= $iconasc; } else { $arrows[$field] .= $icondesc; } } } return $arrows; }
[ "public", "function", "get_sort_arrows", "(", "array", "$", "extrafields", "=", "array", "(", ")", ")", "{", "global", "$", "OUTPUT", ",", "$", "CFG", ";", "$", "arrows", "=", "array", "(", ")", ";", "$", "strsortasc", "=", "$", "this", "->", "get_lang_string", "(", "'sortasc'", ",", "'grades'", ")", ";", "$", "strsortdesc", "=", "$", "this", "->", "get_lang_string", "(", "'sortdesc'", ",", "'grades'", ")", ";", "$", "iconasc", "=", "$", "OUTPUT", "->", "pix_icon", "(", "'t/sort_asc'", ",", "$", "strsortasc", ",", "''", ",", "array", "(", "'class'", "=>", "'iconsmall sorticon'", ")", ")", ";", "$", "icondesc", "=", "$", "OUTPUT", "->", "pix_icon", "(", "'t/sort_desc'", ",", "$", "strsortdesc", ",", "''", ",", "array", "(", "'class'", "=>", "'iconsmall sorticon'", ")", ")", ";", "// Sourced from tablelib.php", "// Check the full name display for sortable fields.", "if", "(", "has_capability", "(", "'moodle/site:viewfullnames'", ",", "$", "this", "->", "context", ")", ")", "{", "$", "nameformat", "=", "$", "CFG", "->", "alternativefullnameformat", ";", "}", "else", "{", "$", "nameformat", "=", "$", "CFG", "->", "fullnamedisplay", ";", "}", "if", "(", "$", "nameformat", "==", "'language'", ")", "{", "$", "nameformat", "=", "get_string", "(", "'fullnamedisplay'", ")", ";", "}", "$", "arrows", "[", "'studentname'", "]", "=", "''", ";", "$", "requirednames", "=", "order_in_string", "(", "get_all_user_name_fields", "(", ")", ",", "$", "nameformat", ")", ";", "if", "(", "!", "empty", "(", "$", "requirednames", ")", ")", "{", "foreach", "(", "$", "requirednames", "as", "$", "name", ")", "{", "$", "arrows", "[", "'studentname'", "]", ".=", "html_writer", "::", "link", "(", "new", "moodle_url", "(", "$", "this", "->", "baseurl", ",", "array", "(", "'sortitemid'", "=>", "$", "name", ")", ")", ",", "$", "this", "->", "get_lang_string", "(", "$", "name", ")", ")", ";", "if", "(", "$", "this", "->", "sortitemid", "==", "$", "name", ")", "{", "$", "arrows", "[", "'studentname'", "]", ".=", "$", "this", "->", "sortorder", "==", "'ASC'", "?", "$", "iconasc", ":", "$", "icondesc", ";", "}", "$", "arrows", "[", "'studentname'", "]", ".=", "' / '", ";", "}", "$", "arrows", "[", "'studentname'", "]", "=", "substr", "(", "$", "arrows", "[", "'studentname'", "]", ",", "0", ",", "-", "3", ")", ";", "}", "foreach", "(", "$", "extrafields", "as", "$", "field", ")", "{", "$", "fieldlink", "=", "html_writer", "::", "link", "(", "new", "moodle_url", "(", "$", "this", "->", "baseurl", ",", "array", "(", "'sortitemid'", "=>", "$", "field", ")", ")", ",", "get_user_field_name", "(", "$", "field", ")", ")", ";", "$", "arrows", "[", "$", "field", "]", "=", "$", "fieldlink", ";", "if", "(", "$", "field", "==", "$", "this", "->", "sortitemid", ")", "{", "if", "(", "$", "this", "->", "sortorder", "==", "'ASC'", ")", "{", "$", "arrows", "[", "$", "field", "]", ".=", "$", "iconasc", ";", "}", "else", "{", "$", "arrows", "[", "$", "field", "]", ".=", "$", "icondesc", ";", "}", "}", "}", "return", "$", "arrows", ";", "}" ]
Refactored function for generating HTML of sorting links with matching arrows. Returns an array with 'studentname' and 'idnumber' as keys, with HTML ready to inject into a table header cell. @param array $extrafields Array of extra fields being displayed, such as user idnumber @return array An associative array of HTML sorting links+arrows
[ "Refactored", "function", "for", "generating", "HTML", "of", "sorting", "links", "with", "matching", "arrows", ".", "Returns", "an", "array", "with", "studentname", "and", "idnumber", "as", "keys", "with", "HTML", "ready", "to", "inject", "into", "a", "table", "header", "cell", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/grader/lib.php#L1903-L1955
211,898
moodle/moodle
lib/classes/event/question_base.php
question_base.create_from_question_instance
public static function create_from_question_instance($question, $context = null, $other = null) { $params = ['objectid' => $question->id, 'other' => ['categoryid' => $question->category]]; if (!empty($question->contextid)) { $params['contextid'] = $question->contextid; } $params['context'] = $context; if (!empty($other)) { $params['other'] = $other; } $event = self::create($params); return $event; }
php
public static function create_from_question_instance($question, $context = null, $other = null) { $params = ['objectid' => $question->id, 'other' => ['categoryid' => $question->category]]; if (!empty($question->contextid)) { $params['contextid'] = $question->contextid; } $params['context'] = $context; if (!empty($other)) { $params['other'] = $other; } $event = self::create($params); return $event; }
[ "public", "static", "function", "create_from_question_instance", "(", "$", "question", ",", "$", "context", "=", "null", ",", "$", "other", "=", "null", ")", "{", "$", "params", "=", "[", "'objectid'", "=>", "$", "question", "->", "id", ",", "'other'", "=>", "[", "'categoryid'", "=>", "$", "question", "->", "category", "]", "]", ";", "if", "(", "!", "empty", "(", "$", "question", "->", "contextid", ")", ")", "{", "$", "params", "[", "'contextid'", "]", "=", "$", "question", "->", "contextid", ";", "}", "$", "params", "[", "'context'", "]", "=", "$", "context", ";", "if", "(", "!", "empty", "(", "$", "other", ")", ")", "{", "$", "params", "[", "'other'", "]", "=", "$", "other", ";", "}", "$", "event", "=", "self", "::", "create", "(", "$", "params", ")", ";", "return", "$", "event", ";", "}" ]
Create a event from question object @param object $question @param object|null $context @param array|null $other will override the categoryid pre-filled out on the first line. @return base @throws \coding_exception
[ "Create", "a", "event", "from", "question", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/question_base.php#L111-L127
211,899
moodle/moodle
portfolio/boxnet/lib.php
portfolio_plugin_boxnet.get_folder_list
protected function get_folder_list() { if (empty($this->folders)) { $folders = array(); $result = $this->boxclient->get_folder_items(); foreach ($result->entries as $item) { if ($item->type != 'folder') { continue; } $folders[$item->id] = $item->name; if (!empty($item->shared)) { $folders[$item->id] .= ' (' . get_string('sharedfolder', 'portfolio_boxnet') . ')'; } } $this->folders = $folders; } return $this->folders; }
php
protected function get_folder_list() { if (empty($this->folders)) { $folders = array(); $result = $this->boxclient->get_folder_items(); foreach ($result->entries as $item) { if ($item->type != 'folder') { continue; } $folders[$item->id] = $item->name; if (!empty($item->shared)) { $folders[$item->id] .= ' (' . get_string('sharedfolder', 'portfolio_boxnet') . ')'; } } $this->folders = $folders; } return $this->folders; }
[ "protected", "function", "get_folder_list", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "folders", ")", ")", "{", "$", "folders", "=", "array", "(", ")", ";", "$", "result", "=", "$", "this", "->", "boxclient", "->", "get_folder_items", "(", ")", ";", "foreach", "(", "$", "result", "->", "entries", "as", "$", "item", ")", "{", "if", "(", "$", "item", "->", "type", "!=", "'folder'", ")", "{", "continue", ";", "}", "$", "folders", "[", "$", "item", "->", "id", "]", "=", "$", "item", "->", "name", ";", "if", "(", "!", "empty", "(", "$", "item", "->", "shared", ")", ")", "{", "$", "folders", "[", "$", "item", "->", "id", "]", ".=", "' ('", ".", "get_string", "(", "'sharedfolder'", ",", "'portfolio_boxnet'", ")", ".", "')'", ";", "}", "}", "$", "this", "->", "folders", "=", "$", "folders", ";", "}", "return", "$", "this", "->", "folders", ";", "}" ]
Get the folder list. This is limited to the folders in the root folder. @return array of folders.
[ "Get", "the", "folder", "list", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/portfolio/boxnet/lib.php#L153-L169