id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
219,300
moodle/moodle
admin/tool/dataprivacy/classes/output/renderer.php
renderer.render_summary_page
public function render_summary_page(summary_page $page) { $data = $page->export_for_template($this); return parent::render_from_template('tool_dataprivacy/summary', $data); }
php
public function render_summary_page(summary_page $page) { $data = $page->export_for_template($this); return parent::render_from_template('tool_dataprivacy/summary', $data); }
[ "public", "function", "render_summary_page", "(", "summary_page", "$", "page", ")", "{", "$", "data", "=", "$", "page", "->", "export_for_template", "(", "$", "this", ")", ";", "return", "parent", "::", "render_from_template", "(", "'tool_dataprivacy/summary'", ",", "$", "data", ")", ";", "}" ]
Render the user data retention summary page. @param summary_page $page @return string html for the page.
[ "Render", "the", "user", "data", "retention", "summary", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/output/renderer.php#L149-L152
219,301
moodle/moodle
lib/tcpdf/include/tcpdf_colors.php
TCPDF_COLORS.getSpotColor
public static function getSpotColor($name, &$spotc) { if (isset($spotc[$name])) { return $spotc[$name]; } $color = preg_replace('/[\s]*/', '', $name); // remove extra spaces $color = strtolower($color); if (isset(self::$spotcolor[$color])) { if (!isset($spotc[$name])) { $i = (1 + count($spotc)); $spotc[$name] = array('C' => self::$spotcolor[$color][0], 'M' => self::$spotcolor[$color][1], 'Y' => self::$spotcolor[$color][2], 'K' => self::$spotcolor[$color][3], 'name' => self::$spotcolor[$color][4], 'i' => $i); } return $spotc[self::$spotcolor[$color][4]]; } return false; }
php
public static function getSpotColor($name, &$spotc) { if (isset($spotc[$name])) { return $spotc[$name]; } $color = preg_replace('/[\s]*/', '', $name); // remove extra spaces $color = strtolower($color); if (isset(self::$spotcolor[$color])) { if (!isset($spotc[$name])) { $i = (1 + count($spotc)); $spotc[$name] = array('C' => self::$spotcolor[$color][0], 'M' => self::$spotcolor[$color][1], 'Y' => self::$spotcolor[$color][2], 'K' => self::$spotcolor[$color][3], 'name' => self::$spotcolor[$color][4], 'i' => $i); } return $spotc[self::$spotcolor[$color][4]]; } return false; }
[ "public", "static", "function", "getSpotColor", "(", "$", "name", ",", "&", "$", "spotc", ")", "{", "if", "(", "isset", "(", "$", "spotc", "[", "$", "name", "]", ")", ")", "{", "return", "$", "spotc", "[", "$", "name", "]", ";", "}", "$", "color", "=", "preg_replace", "(", "'/[\\s]*/'", ",", "''", ",", "$", "name", ")", ";", "// remove extra spaces", "$", "color", "=", "strtolower", "(", "$", "color", ")", ";", "if", "(", "isset", "(", "self", "::", "$", "spotcolor", "[", "$", "color", "]", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "spotc", "[", "$", "name", "]", ")", ")", "{", "$", "i", "=", "(", "1", "+", "count", "(", "$", "spotc", ")", ")", ";", "$", "spotc", "[", "$", "name", "]", "=", "array", "(", "'C'", "=>", "self", "::", "$", "spotcolor", "[", "$", "color", "]", "[", "0", "]", ",", "'M'", "=>", "self", "::", "$", "spotcolor", "[", "$", "color", "]", "[", "1", "]", ",", "'Y'", "=>", "self", "::", "$", "spotcolor", "[", "$", "color", "]", "[", "2", "]", ",", "'K'", "=>", "self", "::", "$", "spotcolor", "[", "$", "color", "]", "[", "3", "]", ",", "'name'", "=>", "self", "::", "$", "spotcolor", "[", "$", "color", "]", "[", "4", "]", ",", "'i'", "=>", "$", "i", ")", ";", "}", "return", "$", "spotc", "[", "self", "::", "$", "spotcolor", "[", "$", "color", "]", "[", "4", "]", "]", ";", "}", "return", "false", ";", "}" ]
Return the Spot color array. @param $name (string) Name of the spot color. @param $spotc (array) Reference to an array of spot colors. @return (array) Spot color array or false if not defined. @since 5.9.125 (2011-10-03) @public static
[ "Return", "the", "Spot", "color", "array", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tcpdf/include/tcpdf_colors.php#L249-L263
219,302
moodle/moodle
lib/horde/framework/Horde/Socket/Client.php
Client.startTls
public function startTls() { if ($this->connected && !$this->secure) { if (defined('STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT')) { $mode = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; } else { $mode = STREAM_CRYPTO_METHOD_TLS_CLIENT; } if (@stream_socket_enable_crypto($this->_stream, true, $mode) === true) { $this->_secure = true; return true; } } return false; }
php
public function startTls() { if ($this->connected && !$this->secure) { if (defined('STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT')) { $mode = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; } else { $mode = STREAM_CRYPTO_METHOD_TLS_CLIENT; } if (@stream_socket_enable_crypto($this->_stream, true, $mode) === true) { $this->_secure = true; return true; } } return false; }
[ "public", "function", "startTls", "(", ")", "{", "if", "(", "$", "this", "->", "connected", "&&", "!", "$", "this", "->", "secure", ")", "{", "if", "(", "defined", "(", "'STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT'", ")", ")", "{", "$", "mode", "=", "STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT", "|", "STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT", "|", "STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT", ";", "}", "else", "{", "$", "mode", "=", "STREAM_CRYPTO_METHOD_TLS_CLIENT", ";", "}", "if", "(", "@", "stream_socket_enable_crypto", "(", "$", "this", "->", "_stream", ",", "true", ",", "$", "mode", ")", "===", "true", ")", "{", "$", "this", "->", "_secure", "=", "true", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Start a TLS connection. @return boolean Whether TLS was successfully started.
[ "Start", "a", "TLS", "connection", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Socket/Client.php#L143-L160
219,303
moodle/moodle
lib/horde/framework/Horde/Socket/Client.php
Client.close
public function close() { if ($this->connected) { @fclose($this->_stream); $this->_connected = $this->_secure = false; $this->_stream = null; } }
php
public function close() { if ($this->connected) { @fclose($this->_stream); $this->_connected = $this->_secure = false; $this->_stream = null; } }
[ "public", "function", "close", "(", ")", "{", "if", "(", "$", "this", "->", "connected", ")", "{", "@", "fclose", "(", "$", "this", "->", "_stream", ")", ";", "$", "this", "->", "_connected", "=", "$", "this", "->", "_secure", "=", "false", ";", "$", "this", "->", "_stream", "=", "null", ";", "}", "}" ]
Close the connection.
[ "Close", "the", "connection", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Socket/Client.php#L165-L172
219,304
moodle/moodle
lib/horde/framework/Horde/Socket/Client.php
Client.gets
public function gets($size) { $this->_checkStream(); $data = @fgets($this->_stream, $size); if ($data === false) { throw new Client\Exception('Error reading data from socket'); } return $data; }
php
public function gets($size) { $this->_checkStream(); $data = @fgets($this->_stream, $size); if ($data === false) { throw new Client\Exception('Error reading data from socket'); } return $data; }
[ "public", "function", "gets", "(", "$", "size", ")", "{", "$", "this", "->", "_checkStream", "(", ")", ";", "$", "data", "=", "@", "fgets", "(", "$", "this", "->", "_stream", ",", "$", "size", ")", ";", "if", "(", "$", "data", "===", "false", ")", "{", "throw", "new", "Client", "\\", "Exception", "(", "'Error reading data from socket'", ")", ";", "}", "return", "$", "data", ";", "}" ]
Returns a line of data. @param int $size Reading ends when $size - 1 bytes have been read, or a newline or an EOF (whichever comes first). @throws Horde\Socket\Client\Exception @return string $size bytes of data from the socket
[ "Returns", "a", "line", "of", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Socket/Client.php#L201-L209
219,305
moodle/moodle
lib/horde/framework/Horde/Socket/Client.php
Client.read
public function read($size) { $this->_checkStream(); $data = @fread($this->_stream, $size); if ($data === false) { throw new Client\Exception('Error reading data from socket'); } return $data; }
php
public function read($size) { $this->_checkStream(); $data = @fread($this->_stream, $size); if ($data === false) { throw new Client\Exception('Error reading data from socket'); } return $data; }
[ "public", "function", "read", "(", "$", "size", ")", "{", "$", "this", "->", "_checkStream", "(", ")", ";", "$", "data", "=", "@", "fread", "(", "$", "this", "->", "_stream", ",", "$", "size", ")", ";", "if", "(", "$", "data", "===", "false", ")", "{", "throw", "new", "Client", "\\", "Exception", "(", "'Error reading data from socket'", ")", ";", "}", "return", "$", "data", ";", "}" ]
Returns a specified amount of data. @param integer $size The number of bytes to read from the socket. @throws Horde\Socket\Client\Exception @return string $size bytes of data from the socket.
[ "Returns", "a", "specified", "amount", "of", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Socket/Client.php#L219-L227
219,306
moodle/moodle
lib/horde/framework/Horde/Socket/Client.php
Client._connect
protected function _connect( $host, $port, $timeout, $secure, $context, $retries = 0 ) { $conn = ''; if (!strpos($host, '://')) { switch (strval($secure)) { case 'ssl': case 'sslv2': case 'sslv3': $conn = $secure . '://'; $this->_secure = true; break; case 'tlsv1': $conn = 'tls://'; $this->_secure = true; break; case 'tls': default: $conn = 'tcp://'; break; } } $conn .= $host; if ($port) { $conn .= ':' . $port; } $this->_stream = @stream_socket_client( $conn, $error_number, $error_string, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($context) ); if ($this->_stream === false) { /* From stream_socket_client() page: a function return of false, * with an error code of 0, indicates a "problem initializing the * socket". These kind of issues are seen on the same server * (and even the same user account) as sucessful connections, so * these are likely transient issues. Retry up to 3 times in these * instances. */ if (!$error_number && ($retries < 3)) { return $this->_connect($host, $port, $timeout, $secure, ++$retries, $context); } $e = new Client\Exception( 'Error connecting to server.' ); $e->details = sprintf("[%u] %s", $error_number, $error_string); throw $e; } stream_set_timeout($this->_stream, $timeout); if (function_exists('stream_set_read_buffer')) { stream_set_read_buffer($this->_stream, 0); } stream_set_write_buffer($this->_stream, 0); $this->_connected = true; }
php
protected function _connect( $host, $port, $timeout, $secure, $context, $retries = 0 ) { $conn = ''; if (!strpos($host, '://')) { switch (strval($secure)) { case 'ssl': case 'sslv2': case 'sslv3': $conn = $secure . '://'; $this->_secure = true; break; case 'tlsv1': $conn = 'tls://'; $this->_secure = true; break; case 'tls': default: $conn = 'tcp://'; break; } } $conn .= $host; if ($port) { $conn .= ':' . $port; } $this->_stream = @stream_socket_client( $conn, $error_number, $error_string, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($context) ); if ($this->_stream === false) { /* From stream_socket_client() page: a function return of false, * with an error code of 0, indicates a "problem initializing the * socket". These kind of issues are seen on the same server * (and even the same user account) as sucessful connections, so * these are likely transient issues. Retry up to 3 times in these * instances. */ if (!$error_number && ($retries < 3)) { return $this->_connect($host, $port, $timeout, $secure, ++$retries, $context); } $e = new Client\Exception( 'Error connecting to server.' ); $e->details = sprintf("[%u] %s", $error_number, $error_string); throw $e; } stream_set_timeout($this->_stream, $timeout); if (function_exists('stream_set_read_buffer')) { stream_set_read_buffer($this->_stream, 0); } stream_set_write_buffer($this->_stream, 0); $this->_connected = true; }
[ "protected", "function", "_connect", "(", "$", "host", ",", "$", "port", ",", "$", "timeout", ",", "$", "secure", ",", "$", "context", ",", "$", "retries", "=", "0", ")", "{", "$", "conn", "=", "''", ";", "if", "(", "!", "strpos", "(", "$", "host", ",", "'://'", ")", ")", "{", "switch", "(", "strval", "(", "$", "secure", ")", ")", "{", "case", "'ssl'", ":", "case", "'sslv2'", ":", "case", "'sslv3'", ":", "$", "conn", "=", "$", "secure", ".", "'://'", ";", "$", "this", "->", "_secure", "=", "true", ";", "break", ";", "case", "'tlsv1'", ":", "$", "conn", "=", "'tls://'", ";", "$", "this", "->", "_secure", "=", "true", ";", "break", ";", "case", "'tls'", ":", "default", ":", "$", "conn", "=", "'tcp://'", ";", "break", ";", "}", "}", "$", "conn", ".=", "$", "host", ";", "if", "(", "$", "port", ")", "{", "$", "conn", ".=", "':'", ".", "$", "port", ";", "}", "$", "this", "->", "_stream", "=", "@", "stream_socket_client", "(", "$", "conn", ",", "$", "error_number", ",", "$", "error_string", ",", "$", "timeout", ",", "STREAM_CLIENT_CONNECT", ",", "stream_context_create", "(", "$", "context", ")", ")", ";", "if", "(", "$", "this", "->", "_stream", "===", "false", ")", "{", "/* From stream_socket_client() page: a function return of false,\n * with an error code of 0, indicates a \"problem initializing the\n * socket\". These kind of issues are seen on the same server\n * (and even the same user account) as sucessful connections, so\n * these are likely transient issues. Retry up to 3 times in these\n * instances. */", "if", "(", "!", "$", "error_number", "&&", "(", "$", "retries", "<", "3", ")", ")", "{", "return", "$", "this", "->", "_connect", "(", "$", "host", ",", "$", "port", ",", "$", "timeout", ",", "$", "secure", ",", "++", "$", "retries", ",", "$", "context", ")", ";", "}", "$", "e", "=", "new", "Client", "\\", "Exception", "(", "'Error connecting to server.'", ")", ";", "$", "e", "->", "details", "=", "sprintf", "(", "\"[%u] %s\"", ",", "$", "error_number", ",", "$", "error_string", ")", ";", "throw", "$", "e", ";", "}", "stream_set_timeout", "(", "$", "this", "->", "_stream", ",", "$", "timeout", ")", ";", "if", "(", "function_exists", "(", "'stream_set_read_buffer'", ")", ")", "{", "stream_set_read_buffer", "(", "$", "this", "->", "_stream", ",", "0", ")", ";", "}", "stream_set_write_buffer", "(", "$", "this", "->", "_stream", ",", "0", ")", ";", "$", "this", "->", "_connected", "=", "true", ";", "}" ]
Connect to the remote server. @see __construct() @throws Horde\Socket\Client\Exception
[ "Connect", "to", "the", "remote", "server", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Socket/Client.php#L257-L322
219,307
moodle/moodle
mod/forum/classes/local/renderers/discussion.php
discussion.render
public function render( stdClass $user, post_entity $firstpost, array $replies ) : string { global $CFG; $displaymode = $this->displaymode; $capabilitymanager = $this->capabilitymanager; // Make sure we can render. if (!$capabilitymanager->can_view_discussions($user)) { throw new moodle_exception('noviewdiscussionspermission', 'mod_forum'); } $posts = array_merge([$firstpost], array_values($replies)); if ($this->postprocessfortemplate !== null) { $exporteddiscussion = ($this->postprocessfortemplate) ($this->discussion, $user, $this->forum); } else { $exporteddiscussion = $this->get_exported_discussion($user); } $exporteddiscussion = array_merge($exporteddiscussion, [ 'notifications' => $this->get_notifications($user), 'html' => [ 'posts' => $this->postsrenderer->render($user, [$this->forum], [$this->discussion], $posts), 'modeselectorform' => $this->get_display_mode_selector_html($displaymode), 'subscribe' => null, 'movediscussion' => null, 'pindiscussion' => null, 'neighbourlinks' => $this->get_neighbour_links_html(), 'exportdiscussion' => !empty($CFG->enableportfolios) ? $this->get_export_discussion_html() : null ] ]); $capabilities = (array) $exporteddiscussion['capabilities']; if ($capabilities['subscribe']) { $exporteddiscussion['html']['subscribe'] = $this->get_subscription_button_html(); } if ($capabilities['move']) { $exporteddiscussion['html']['movediscussion'] = $this->get_move_discussion_html(); } return $this->renderer->render_from_template('mod_forum/forum_discussion', $exporteddiscussion); }
php
public function render( stdClass $user, post_entity $firstpost, array $replies ) : string { global $CFG; $displaymode = $this->displaymode; $capabilitymanager = $this->capabilitymanager; // Make sure we can render. if (!$capabilitymanager->can_view_discussions($user)) { throw new moodle_exception('noviewdiscussionspermission', 'mod_forum'); } $posts = array_merge([$firstpost], array_values($replies)); if ($this->postprocessfortemplate !== null) { $exporteddiscussion = ($this->postprocessfortemplate) ($this->discussion, $user, $this->forum); } else { $exporteddiscussion = $this->get_exported_discussion($user); } $exporteddiscussion = array_merge($exporteddiscussion, [ 'notifications' => $this->get_notifications($user), 'html' => [ 'posts' => $this->postsrenderer->render($user, [$this->forum], [$this->discussion], $posts), 'modeselectorform' => $this->get_display_mode_selector_html($displaymode), 'subscribe' => null, 'movediscussion' => null, 'pindiscussion' => null, 'neighbourlinks' => $this->get_neighbour_links_html(), 'exportdiscussion' => !empty($CFG->enableportfolios) ? $this->get_export_discussion_html() : null ] ]); $capabilities = (array) $exporteddiscussion['capabilities']; if ($capabilities['subscribe']) { $exporteddiscussion['html']['subscribe'] = $this->get_subscription_button_html(); } if ($capabilities['move']) { $exporteddiscussion['html']['movediscussion'] = $this->get_move_discussion_html(); } return $this->renderer->render_from_template('mod_forum/forum_discussion', $exporteddiscussion); }
[ "public", "function", "render", "(", "stdClass", "$", "user", ",", "post_entity", "$", "firstpost", ",", "array", "$", "replies", ")", ":", "string", "{", "global", "$", "CFG", ";", "$", "displaymode", "=", "$", "this", "->", "displaymode", ";", "$", "capabilitymanager", "=", "$", "this", "->", "capabilitymanager", ";", "// Make sure we can render.", "if", "(", "!", "$", "capabilitymanager", "->", "can_view_discussions", "(", "$", "user", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'noviewdiscussionspermission'", ",", "'mod_forum'", ")", ";", "}", "$", "posts", "=", "array_merge", "(", "[", "$", "firstpost", "]", ",", "array_values", "(", "$", "replies", ")", ")", ";", "if", "(", "$", "this", "->", "postprocessfortemplate", "!==", "null", ")", "{", "$", "exporteddiscussion", "=", "(", "$", "this", "->", "postprocessfortemplate", ")", "(", "$", "this", "->", "discussion", ",", "$", "user", ",", "$", "this", "->", "forum", ")", ";", "}", "else", "{", "$", "exporteddiscussion", "=", "$", "this", "->", "get_exported_discussion", "(", "$", "user", ")", ";", "}", "$", "exporteddiscussion", "=", "array_merge", "(", "$", "exporteddiscussion", ",", "[", "'notifications'", "=>", "$", "this", "->", "get_notifications", "(", "$", "user", ")", ",", "'html'", "=>", "[", "'posts'", "=>", "$", "this", "->", "postsrenderer", "->", "render", "(", "$", "user", ",", "[", "$", "this", "->", "forum", "]", ",", "[", "$", "this", "->", "discussion", "]", ",", "$", "posts", ")", ",", "'modeselectorform'", "=>", "$", "this", "->", "get_display_mode_selector_html", "(", "$", "displaymode", ")", ",", "'subscribe'", "=>", "null", ",", "'movediscussion'", "=>", "null", ",", "'pindiscussion'", "=>", "null", ",", "'neighbourlinks'", "=>", "$", "this", "->", "get_neighbour_links_html", "(", ")", ",", "'exportdiscussion'", "=>", "!", "empty", "(", "$", "CFG", "->", "enableportfolios", ")", "?", "$", "this", "->", "get_export_discussion_html", "(", ")", ":", "null", "]", "]", ")", ";", "$", "capabilities", "=", "(", "array", ")", "$", "exporteddiscussion", "[", "'capabilities'", "]", ";", "if", "(", "$", "capabilities", "[", "'subscribe'", "]", ")", "{", "$", "exporteddiscussion", "[", "'html'", "]", "[", "'subscribe'", "]", "=", "$", "this", "->", "get_subscription_button_html", "(", ")", ";", "}", "if", "(", "$", "capabilities", "[", "'move'", "]", ")", "{", "$", "exporteddiscussion", "[", "'html'", "]", "[", "'movediscussion'", "]", "=", "$", "this", "->", "get_move_discussion_html", "(", ")", ";", "}", "return", "$", "this", "->", "renderer", "->", "render_from_template", "(", "'mod_forum/forum_discussion'", ",", "$", "exporteddiscussion", ")", ";", "}" ]
Render the discussion for the given user in the specified display mode. @param stdClass $user The user viewing the discussion @param post_entity $firstpost The first post in the discussion @param array $replies List of replies to the first post @return string HTML for the discussion
[ "Render", "the", "discussion", "for", "the", "given", "user", "in", "the", "specified", "display", "mode", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/renderers/discussion.php#L163-L210
219,308
moodle/moodle
mod/forum/classes/local/renderers/discussion.php
discussion.get_groups_available_in_forum
private function get_groups_available_in_forum() : array { $course = $this->forum->get_course_record(); $coursemodule = $this->forum->get_course_module_record(); return groups_get_all_groups($course->id, 0, $coursemodule->groupingid); }
php
private function get_groups_available_in_forum() : array { $course = $this->forum->get_course_record(); $coursemodule = $this->forum->get_course_module_record(); return groups_get_all_groups($course->id, 0, $coursemodule->groupingid); }
[ "private", "function", "get_groups_available_in_forum", "(", ")", ":", "array", "{", "$", "course", "=", "$", "this", "->", "forum", "->", "get_course_record", "(", ")", ";", "$", "coursemodule", "=", "$", "this", "->", "forum", "->", "get_course_module_record", "(", ")", ";", "return", "groups_get_all_groups", "(", "$", "course", "->", "id", ",", "0", ",", "$", "coursemodule", "->", "groupingid", ")", ";", "}" ]
Get the groups details for all groups available to the forum. @return stdClass[]
[ "Get", "the", "groups", "details", "for", "all", "groups", "available", "to", "the", "forum", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/renderers/discussion.php#L217-L222
219,309
moodle/moodle
mod/forum/classes/local/renderers/discussion.php
discussion.get_exported_discussion
private function get_exported_discussion(stdClass $user) : array { $discussionexporter = $this->exporterfactory->get_discussion_exporter( $user, $this->forum, $this->discussion, $this->get_groups_available_in_forum() ); return (array) $discussionexporter->export($this->renderer); }
php
private function get_exported_discussion(stdClass $user) : array { $discussionexporter = $this->exporterfactory->get_discussion_exporter( $user, $this->forum, $this->discussion, $this->get_groups_available_in_forum() ); return (array) $discussionexporter->export($this->renderer); }
[ "private", "function", "get_exported_discussion", "(", "stdClass", "$", "user", ")", ":", "array", "{", "$", "discussionexporter", "=", "$", "this", "->", "exporterfactory", "->", "get_discussion_exporter", "(", "$", "user", ",", "$", "this", "->", "forum", ",", "$", "this", "->", "discussion", ",", "$", "this", "->", "get_groups_available_in_forum", "(", ")", ")", ";", "return", "(", "array", ")", "$", "discussionexporter", "->", "export", "(", "$", "this", "->", "renderer", ")", ";", "}" ]
Get the exported discussion. @param stdClass $user The user viewing the discussion @return array
[ "Get", "the", "exported", "discussion", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/renderers/discussion.php#L230-L239
219,310
moodle/moodle
mod/forum/classes/local/renderers/discussion.php
discussion.get_display_mode_selector_html
private function get_display_mode_selector_html(int $displaymode) : string { $baseurl = $this->baseurl; $select = new single_select( $baseurl, 'mode', forum_get_layout_modes(), $displaymode, null, 'mode' ); $select->set_label(get_string('displaymode', 'forum'), ['class' => 'accesshide']); return $this->renderer->render($select); }
php
private function get_display_mode_selector_html(int $displaymode) : string { $baseurl = $this->baseurl; $select = new single_select( $baseurl, 'mode', forum_get_layout_modes(), $displaymode, null, 'mode' ); $select->set_label(get_string('displaymode', 'forum'), ['class' => 'accesshide']); return $this->renderer->render($select); }
[ "private", "function", "get_display_mode_selector_html", "(", "int", "$", "displaymode", ")", ":", "string", "{", "$", "baseurl", "=", "$", "this", "->", "baseurl", ";", "$", "select", "=", "new", "single_select", "(", "$", "baseurl", ",", "'mode'", ",", "forum_get_layout_modes", "(", ")", ",", "$", "displaymode", ",", "null", ",", "'mode'", ")", ";", "$", "select", "->", "set_label", "(", "get_string", "(", "'displaymode'", ",", "'forum'", ")", ",", "[", "'class'", "=>", "'accesshide'", "]", ")", ";", "return", "$", "this", "->", "renderer", "->", "render", "(", "$", "select", ")", ";", "}" ]
Get the HTML for the display mode selector. @param int $displaymode The current display mode @return string
[ "Get", "the", "HTML", "for", "the", "display", "mode", "selector", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/renderers/discussion.php#L247-L260
219,311
moodle/moodle
mod/forum/classes/local/renderers/discussion.php
discussion.get_subscription_button_html
private function get_subscription_button_html() : string { global $PAGE; $forumrecord = $this->forumrecord; $discussion = $this->discussion; $html = html_writer::div( forum_get_discussion_subscription_icon($forumrecord, $discussion->get_id(), null, true), 'discussionsubscription' ); $html .= forum_get_discussion_subscription_icon_preloaders(); // Add the subscription toggle JS. $PAGE->requires->yui_module('moodle-mod_forum-subscriptiontoggle', 'Y.M.mod_forum.subscriptiontoggle.init'); return $html; }
php
private function get_subscription_button_html() : string { global $PAGE; $forumrecord = $this->forumrecord; $discussion = $this->discussion; $html = html_writer::div( forum_get_discussion_subscription_icon($forumrecord, $discussion->get_id(), null, true), 'discussionsubscription' ); $html .= forum_get_discussion_subscription_icon_preloaders(); // Add the subscription toggle JS. $PAGE->requires->yui_module('moodle-mod_forum-subscriptiontoggle', 'Y.M.mod_forum.subscriptiontoggle.init'); return $html; }
[ "private", "function", "get_subscription_button_html", "(", ")", ":", "string", "{", "global", "$", "PAGE", ";", "$", "forumrecord", "=", "$", "this", "->", "forumrecord", ";", "$", "discussion", "=", "$", "this", "->", "discussion", ";", "$", "html", "=", "html_writer", "::", "div", "(", "forum_get_discussion_subscription_icon", "(", "$", "forumrecord", ",", "$", "discussion", "->", "get_id", "(", ")", ",", "null", ",", "true", ")", ",", "'discussionsubscription'", ")", ";", "$", "html", ".=", "forum_get_discussion_subscription_icon_preloaders", "(", ")", ";", "// Add the subscription toggle JS.", "$", "PAGE", "->", "requires", "->", "yui_module", "(", "'moodle-mod_forum-subscriptiontoggle'", ",", "'Y.M.mod_forum.subscriptiontoggle.init'", ")", ";", "return", "$", "html", ";", "}" ]
Get the HTML to render the subscription button. @return string
[ "Get", "the", "HTML", "to", "render", "the", "subscription", "button", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/renderers/discussion.php#L267-L280
219,312
moodle/moodle
mod/forum/classes/local/renderers/discussion.php
discussion.get_move_discussion_html
private function get_move_discussion_html() : ?string { global $DB; $forum = $this->forum; $discussion = $this->discussion; $courseid = $forum->get_course_id(); // Popup menu to move discussions to other forums. The discussion in a // single discussion forum can't be moved. $modinfo = get_fast_modinfo($courseid); if (isset($modinfo->instances['forum'])) { $forummenu = []; // Check forum types and eliminate simple discussions. $forumcheck = $DB->get_records('forum', ['course' => $courseid], '', 'id, type'); foreach ($modinfo->instances['forum'] as $forumcm) { if (!$forumcm->uservisible || !has_capability('mod/forum:startdiscussion', context_module::instance($forumcm->id))) { continue; } $section = $forumcm->sectionnum; $sectionname = get_section_name($courseid, $section); if (empty($forummenu[$section])) { $forummenu[$section] = [$sectionname => []]; } $forumidcompare = $forumcm->instance != $forum->get_id(); $forumtypecheck = $forumcheck[$forumcm->instance]->type !== 'single'; if ($forumidcompare and $forumtypecheck) { $url = "/mod/forum/discuss.php?d={$discussion->get_id()}&move=$forumcm->instance&sesskey=".sesskey(); $forummenu[$section][$sectionname][$url] = format_string($forumcm->name); } } if (!empty($forummenu)) { $html = '<div class="movediscussionoption">'; $select = new url_select($forummenu, '', ['/mod/forum/discuss.php?d=' . $discussion->get_id() => get_string("movethisdiscussionto", "forum")], 'forummenu', get_string('move')); $html .= $this->renderer->render($select); $html .= "</div>"; return $html; } } return null; }
php
private function get_move_discussion_html() : ?string { global $DB; $forum = $this->forum; $discussion = $this->discussion; $courseid = $forum->get_course_id(); // Popup menu to move discussions to other forums. The discussion in a // single discussion forum can't be moved. $modinfo = get_fast_modinfo($courseid); if (isset($modinfo->instances['forum'])) { $forummenu = []; // Check forum types and eliminate simple discussions. $forumcheck = $DB->get_records('forum', ['course' => $courseid], '', 'id, type'); foreach ($modinfo->instances['forum'] as $forumcm) { if (!$forumcm->uservisible || !has_capability('mod/forum:startdiscussion', context_module::instance($forumcm->id))) { continue; } $section = $forumcm->sectionnum; $sectionname = get_section_name($courseid, $section); if (empty($forummenu[$section])) { $forummenu[$section] = [$sectionname => []]; } $forumidcompare = $forumcm->instance != $forum->get_id(); $forumtypecheck = $forumcheck[$forumcm->instance]->type !== 'single'; if ($forumidcompare and $forumtypecheck) { $url = "/mod/forum/discuss.php?d={$discussion->get_id()}&move=$forumcm->instance&sesskey=".sesskey(); $forummenu[$section][$sectionname][$url] = format_string($forumcm->name); } } if (!empty($forummenu)) { $html = '<div class="movediscussionoption">'; $select = new url_select($forummenu, '', ['/mod/forum/discuss.php?d=' . $discussion->get_id() => get_string("movethisdiscussionto", "forum")], 'forummenu', get_string('move')); $html .= $this->renderer->render($select); $html .= "</div>"; return $html; } } return null; }
[ "private", "function", "get_move_discussion_html", "(", ")", ":", "?", "string", "{", "global", "$", "DB", ";", "$", "forum", "=", "$", "this", "->", "forum", ";", "$", "discussion", "=", "$", "this", "->", "discussion", ";", "$", "courseid", "=", "$", "forum", "->", "get_course_id", "(", ")", ";", "// Popup menu to move discussions to other forums. The discussion in a", "// single discussion forum can't be moved.", "$", "modinfo", "=", "get_fast_modinfo", "(", "$", "courseid", ")", ";", "if", "(", "isset", "(", "$", "modinfo", "->", "instances", "[", "'forum'", "]", ")", ")", "{", "$", "forummenu", "=", "[", "]", ";", "// Check forum types and eliminate simple discussions.", "$", "forumcheck", "=", "$", "DB", "->", "get_records", "(", "'forum'", ",", "[", "'course'", "=>", "$", "courseid", "]", ",", "''", ",", "'id, type'", ")", ";", "foreach", "(", "$", "modinfo", "->", "instances", "[", "'forum'", "]", "as", "$", "forumcm", ")", "{", "if", "(", "!", "$", "forumcm", "->", "uservisible", "||", "!", "has_capability", "(", "'mod/forum:startdiscussion'", ",", "context_module", "::", "instance", "(", "$", "forumcm", "->", "id", ")", ")", ")", "{", "continue", ";", "}", "$", "section", "=", "$", "forumcm", "->", "sectionnum", ";", "$", "sectionname", "=", "get_section_name", "(", "$", "courseid", ",", "$", "section", ")", ";", "if", "(", "empty", "(", "$", "forummenu", "[", "$", "section", "]", ")", ")", "{", "$", "forummenu", "[", "$", "section", "]", "=", "[", "$", "sectionname", "=>", "[", "]", "]", ";", "}", "$", "forumidcompare", "=", "$", "forumcm", "->", "instance", "!=", "$", "forum", "->", "get_id", "(", ")", ";", "$", "forumtypecheck", "=", "$", "forumcheck", "[", "$", "forumcm", "->", "instance", "]", "->", "type", "!==", "'single'", ";", "if", "(", "$", "forumidcompare", "and", "$", "forumtypecheck", ")", "{", "$", "url", "=", "\"/mod/forum/discuss.php?d={$discussion->get_id()}&move=$forumcm->instance&sesskey=\"", ".", "sesskey", "(", ")", ";", "$", "forummenu", "[", "$", "section", "]", "[", "$", "sectionname", "]", "[", "$", "url", "]", "=", "format_string", "(", "$", "forumcm", "->", "name", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "forummenu", ")", ")", "{", "$", "html", "=", "'<div class=\"movediscussionoption\">'", ";", "$", "select", "=", "new", "url_select", "(", "$", "forummenu", ",", "''", ",", "[", "'/mod/forum/discuss.php?d='", ".", "$", "discussion", "->", "get_id", "(", ")", "=>", "get_string", "(", "\"movethisdiscussionto\"", ",", "\"forum\"", ")", "]", ",", "'forummenu'", ",", "get_string", "(", "'move'", ")", ")", ";", "$", "html", ".=", "$", "this", "->", "renderer", "->", "render", "(", "$", "select", ")", ";", "$", "html", ".=", "\"</div>\"", ";", "return", "$", "html", ";", "}", "}", "return", "null", ";", "}" ]
Get the HTML to render the move discussion selector and button. @return string
[ "Get", "the", "HTML", "to", "render", "the", "move", "discussion", "selector", "and", "button", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/renderers/discussion.php#L287-L331
219,313
moodle/moodle
mod/forum/classes/local/renderers/discussion.php
discussion.get_export_discussion_html
private function get_export_discussion_html() : ?string { global $CFG; require_once($CFG->libdir . '/portfoliolib.php'); $discussion = $this->discussion; $button = new \portfolio_add_button(); $button->set_callback_options('forum_portfolio_caller', ['discussionid' => $discussion->get_id()], 'mod_forum'); $button = $button->to_html(PORTFOLIO_ADD_FULL_FORM, get_string('exportdiscussion', 'mod_forum')); return $button ?: null; }
php
private function get_export_discussion_html() : ?string { global $CFG; require_once($CFG->libdir . '/portfoliolib.php'); $discussion = $this->discussion; $button = new \portfolio_add_button(); $button->set_callback_options('forum_portfolio_caller', ['discussionid' => $discussion->get_id()], 'mod_forum'); $button = $button->to_html(PORTFOLIO_ADD_FULL_FORM, get_string('exportdiscussion', 'mod_forum')); return $button ?: null; }
[ "private", "function", "get_export_discussion_html", "(", ")", ":", "?", "string", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/portfoliolib.php'", ")", ";", "$", "discussion", "=", "$", "this", "->", "discussion", ";", "$", "button", "=", "new", "\\", "portfolio_add_button", "(", ")", ";", "$", "button", "->", "set_callback_options", "(", "'forum_portfolio_caller'", ",", "[", "'discussionid'", "=>", "$", "discussion", "->", "get_id", "(", ")", "]", ",", "'mod_forum'", ")", ";", "$", "button", "=", "$", "button", "->", "to_html", "(", "PORTFOLIO_ADD_FULL_FORM", ",", "get_string", "(", "'exportdiscussion'", ",", "'mod_forum'", ")", ")", ";", "return", "$", "button", "?", ":", "null", ";", "}" ]
Get the HTML to render the export discussion button. @return string|null
[ "Get", "the", "HTML", "to", "render", "the", "export", "discussion", "button", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/renderers/discussion.php#L338-L347
219,314
moodle/moodle
mod/forum/classes/local/renderers/discussion.php
discussion.get_notifications
private function get_notifications($user) : array { $notifications = $this->notifications; $discussion = $this->discussion; $forum = $this->forum; $renderer = $this->renderer; if ($forum->is_cutoff_date_reached()) { $notifications[] = (new notification( get_string('cutoffdatereached', 'forum'), notification::NOTIFY_INFO ))->set_show_closebutton(); } else if ($forum->is_due_date_reached()) { $notifications[] = (new notification( get_string('thisforumisdue', 'forum', userdate($forum->get_due_date())), notification::NOTIFY_INFO ))->set_show_closebutton(); } else if ($forum->has_due_date()) { $notifications[] = (new notification( get_string('thisforumhasduedate', 'forum', userdate($forum->get_due_date())), notification::NOTIFY_INFO ))->set_show_closebutton(); } if ($forum->is_discussion_locked($discussion)) { $notifications[] = (new notification( get_string('discussionlocked', 'forum'), notification::NOTIFY_INFO )) ->set_extra_classes(['discussionlocked']) ->set_show_closebutton(); } if ($forum->get_type() == 'qanda') { if ($this->capabilitymanager->must_post_before_viewing_discussion($user, $discussion)) { $notifications[] = (new notification( get_string('qandanotify', 'forum') ))->set_show_closebutton(true); } } if ($forum->has_blocking_enabled()) { $notifications[] = (new notification( get_string('thisforumisthrottled', 'forum', [ 'blockafter' => $forum->get_block_after(), 'blockperiod' => get_string('secondstotime' . $forum->get_block_period()) ]) ))->set_show_closebutton(); } return array_map(function($notification) { return $notification->export_for_template($this->renderer); }, $notifications); }
php
private function get_notifications($user) : array { $notifications = $this->notifications; $discussion = $this->discussion; $forum = $this->forum; $renderer = $this->renderer; if ($forum->is_cutoff_date_reached()) { $notifications[] = (new notification( get_string('cutoffdatereached', 'forum'), notification::NOTIFY_INFO ))->set_show_closebutton(); } else if ($forum->is_due_date_reached()) { $notifications[] = (new notification( get_string('thisforumisdue', 'forum', userdate($forum->get_due_date())), notification::NOTIFY_INFO ))->set_show_closebutton(); } else if ($forum->has_due_date()) { $notifications[] = (new notification( get_string('thisforumhasduedate', 'forum', userdate($forum->get_due_date())), notification::NOTIFY_INFO ))->set_show_closebutton(); } if ($forum->is_discussion_locked($discussion)) { $notifications[] = (new notification( get_string('discussionlocked', 'forum'), notification::NOTIFY_INFO )) ->set_extra_classes(['discussionlocked']) ->set_show_closebutton(); } if ($forum->get_type() == 'qanda') { if ($this->capabilitymanager->must_post_before_viewing_discussion($user, $discussion)) { $notifications[] = (new notification( get_string('qandanotify', 'forum') ))->set_show_closebutton(true); } } if ($forum->has_blocking_enabled()) { $notifications[] = (new notification( get_string('thisforumisthrottled', 'forum', [ 'blockafter' => $forum->get_block_after(), 'blockperiod' => get_string('secondstotime' . $forum->get_block_period()) ]) ))->set_show_closebutton(); } return array_map(function($notification) { return $notification->export_for_template($this->renderer); }, $notifications); }
[ "private", "function", "get_notifications", "(", "$", "user", ")", ":", "array", "{", "$", "notifications", "=", "$", "this", "->", "notifications", ";", "$", "discussion", "=", "$", "this", "->", "discussion", ";", "$", "forum", "=", "$", "this", "->", "forum", ";", "$", "renderer", "=", "$", "this", "->", "renderer", ";", "if", "(", "$", "forum", "->", "is_cutoff_date_reached", "(", ")", ")", "{", "$", "notifications", "[", "]", "=", "(", "new", "notification", "(", "get_string", "(", "'cutoffdatereached'", ",", "'forum'", ")", ",", "notification", "::", "NOTIFY_INFO", ")", ")", "->", "set_show_closebutton", "(", ")", ";", "}", "else", "if", "(", "$", "forum", "->", "is_due_date_reached", "(", ")", ")", "{", "$", "notifications", "[", "]", "=", "(", "new", "notification", "(", "get_string", "(", "'thisforumisdue'", ",", "'forum'", ",", "userdate", "(", "$", "forum", "->", "get_due_date", "(", ")", ")", ")", ",", "notification", "::", "NOTIFY_INFO", ")", ")", "->", "set_show_closebutton", "(", ")", ";", "}", "else", "if", "(", "$", "forum", "->", "has_due_date", "(", ")", ")", "{", "$", "notifications", "[", "]", "=", "(", "new", "notification", "(", "get_string", "(", "'thisforumhasduedate'", ",", "'forum'", ",", "userdate", "(", "$", "forum", "->", "get_due_date", "(", ")", ")", ")", ",", "notification", "::", "NOTIFY_INFO", ")", ")", "->", "set_show_closebutton", "(", ")", ";", "}", "if", "(", "$", "forum", "->", "is_discussion_locked", "(", "$", "discussion", ")", ")", "{", "$", "notifications", "[", "]", "=", "(", "new", "notification", "(", "get_string", "(", "'discussionlocked'", ",", "'forum'", ")", ",", "notification", "::", "NOTIFY_INFO", ")", ")", "->", "set_extra_classes", "(", "[", "'discussionlocked'", "]", ")", "->", "set_show_closebutton", "(", ")", ";", "}", "if", "(", "$", "forum", "->", "get_type", "(", ")", "==", "'qanda'", ")", "{", "if", "(", "$", "this", "->", "capabilitymanager", "->", "must_post_before_viewing_discussion", "(", "$", "user", ",", "$", "discussion", ")", ")", "{", "$", "notifications", "[", "]", "=", "(", "new", "notification", "(", "get_string", "(", "'qandanotify'", ",", "'forum'", ")", ")", ")", "->", "set_show_closebutton", "(", "true", ")", ";", "}", "}", "if", "(", "$", "forum", "->", "has_blocking_enabled", "(", ")", ")", "{", "$", "notifications", "[", "]", "=", "(", "new", "notification", "(", "get_string", "(", "'thisforumisthrottled'", ",", "'forum'", ",", "[", "'blockafter'", "=>", "$", "forum", "->", "get_block_after", "(", ")", ",", "'blockperiod'", "=>", "get_string", "(", "'secondstotime'", ".", "$", "forum", "->", "get_block_period", "(", ")", ")", "]", ")", ")", ")", "->", "set_show_closebutton", "(", ")", ";", "}", "return", "array_map", "(", "function", "(", "$", "notification", ")", "{", "return", "$", "notification", "->", "export_for_template", "(", "$", "this", "->", "renderer", ")", ";", "}", ",", "$", "notifications", ")", ";", "}" ]
Get a list of notification HTML to render in the page. @param stdClass $user The user viewing the discussion @return string[]
[ "Get", "a", "list", "of", "notification", "HTML", "to", "render", "in", "the", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/renderers/discussion.php#L355-L407
219,315
moodle/moodle
mod/forum/classes/local/renderers/discussion.php
discussion.get_neighbour_links_html
private function get_neighbour_links_html() : string { $forum = $this->forum; $coursemodule = $forum->get_course_module_record(); $neighbours = forum_get_discussion_neighbours($coursemodule, $this->discussionrecord, $this->forumrecord); return $this->renderer->neighbouring_discussion_navigation($neighbours['prev'], $neighbours['next']); }
php
private function get_neighbour_links_html() : string { $forum = $this->forum; $coursemodule = $forum->get_course_module_record(); $neighbours = forum_get_discussion_neighbours($coursemodule, $this->discussionrecord, $this->forumrecord); return $this->renderer->neighbouring_discussion_navigation($neighbours['prev'], $neighbours['next']); }
[ "private", "function", "get_neighbour_links_html", "(", ")", ":", "string", "{", "$", "forum", "=", "$", "this", "->", "forum", ";", "$", "coursemodule", "=", "$", "forum", "->", "get_course_module_record", "(", ")", ";", "$", "neighbours", "=", "forum_get_discussion_neighbours", "(", "$", "coursemodule", ",", "$", "this", "->", "discussionrecord", ",", "$", "this", "->", "forumrecord", ")", ";", "return", "$", "this", "->", "renderer", "->", "neighbouring_discussion_navigation", "(", "$", "neighbours", "[", "'prev'", "]", ",", "$", "neighbours", "[", "'next'", "]", ")", ";", "}" ]
Get HTML to display the neighbour links. @return string
[ "Get", "HTML", "to", "display", "the", "neighbour", "links", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/renderers/discussion.php#L414-L419
219,316
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.get_imap_client
protected function get_imap_client() { global $CFG; if (!\core\message\inbound\manager::is_enabled()) { // E-mail processing not set up. mtrace("Inbound Message not fully configured - exiting early."); return false; } mtrace("Connecting to {$CFG->messageinbound_host} as {$CFG->messageinbound_hostuser}..."); $configuration = array( 'username' => $CFG->messageinbound_hostuser, 'password' => $CFG->messageinbound_hostpass, 'hostspec' => $CFG->messageinbound_host, 'secure' => $CFG->messageinbound_hostssl, 'debug' => empty($CFG->debugimap) ? null : fopen('php://stderr', 'w'), ); if (strpos($configuration['hostspec'], ':')) { $hostdata = explode(':', $configuration['hostspec']); if (count($hostdata) === 2) { // A hostname in the format hostname:port has been provided. $configuration['hostspec'] = $hostdata[0]; $configuration['port'] = $hostdata[1]; } } $this->client = new \Horde_Imap_Client_Socket($configuration); try { $this->client->login(); mtrace("Connection established."); // Ensure that mailboxes exist. $this->ensure_mailboxes_exist(); return true; } catch (\Horde_Imap_Client_Exception $e) { $message = $e->getMessage(); throw new \moodle_exception('imapconnectfailure', 'tool_messageinbound', '', null, $message); } }
php
protected function get_imap_client() { global $CFG; if (!\core\message\inbound\manager::is_enabled()) { // E-mail processing not set up. mtrace("Inbound Message not fully configured - exiting early."); return false; } mtrace("Connecting to {$CFG->messageinbound_host} as {$CFG->messageinbound_hostuser}..."); $configuration = array( 'username' => $CFG->messageinbound_hostuser, 'password' => $CFG->messageinbound_hostpass, 'hostspec' => $CFG->messageinbound_host, 'secure' => $CFG->messageinbound_hostssl, 'debug' => empty($CFG->debugimap) ? null : fopen('php://stderr', 'w'), ); if (strpos($configuration['hostspec'], ':')) { $hostdata = explode(':', $configuration['hostspec']); if (count($hostdata) === 2) { // A hostname in the format hostname:port has been provided. $configuration['hostspec'] = $hostdata[0]; $configuration['port'] = $hostdata[1]; } } $this->client = new \Horde_Imap_Client_Socket($configuration); try { $this->client->login(); mtrace("Connection established."); // Ensure that mailboxes exist. $this->ensure_mailboxes_exist(); return true; } catch (\Horde_Imap_Client_Exception $e) { $message = $e->getMessage(); throw new \moodle_exception('imapconnectfailure', 'tool_messageinbound', '', null, $message); } }
[ "protected", "function", "get_imap_client", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "\\", "core", "\\", "message", "\\", "inbound", "\\", "manager", "::", "is_enabled", "(", ")", ")", "{", "// E-mail processing not set up.", "mtrace", "(", "\"Inbound Message not fully configured - exiting early.\"", ")", ";", "return", "false", ";", "}", "mtrace", "(", "\"Connecting to {$CFG->messageinbound_host} as {$CFG->messageinbound_hostuser}...\"", ")", ";", "$", "configuration", "=", "array", "(", "'username'", "=>", "$", "CFG", "->", "messageinbound_hostuser", ",", "'password'", "=>", "$", "CFG", "->", "messageinbound_hostpass", ",", "'hostspec'", "=>", "$", "CFG", "->", "messageinbound_host", ",", "'secure'", "=>", "$", "CFG", "->", "messageinbound_hostssl", ",", "'debug'", "=>", "empty", "(", "$", "CFG", "->", "debugimap", ")", "?", "null", ":", "fopen", "(", "'php://stderr'", ",", "'w'", ")", ",", ")", ";", "if", "(", "strpos", "(", "$", "configuration", "[", "'hostspec'", "]", ",", "':'", ")", ")", "{", "$", "hostdata", "=", "explode", "(", "':'", ",", "$", "configuration", "[", "'hostspec'", "]", ")", ";", "if", "(", "count", "(", "$", "hostdata", ")", "===", "2", ")", "{", "// A hostname in the format hostname:port has been provided.", "$", "configuration", "[", "'hostspec'", "]", "=", "$", "hostdata", "[", "0", "]", ";", "$", "configuration", "[", "'port'", "]", "=", "$", "hostdata", "[", "1", "]", ";", "}", "}", "$", "this", "->", "client", "=", "new", "\\", "Horde_Imap_Client_Socket", "(", "$", "configuration", ")", ";", "try", "{", "$", "this", "->", "client", "->", "login", "(", ")", ";", "mtrace", "(", "\"Connection established.\"", ")", ";", "// Ensure that mailboxes exist.", "$", "this", "->", "ensure_mailboxes_exist", "(", ")", ";", "return", "true", ";", "}", "catch", "(", "\\", "Horde_Imap_Client_Exception", "$", "e", ")", "{", "$", "message", "=", "$", "e", "->", "getMessage", "(", ")", ";", "throw", "new", "\\", "moodle_exception", "(", "'imapconnectfailure'", ",", "'tool_messageinbound'", ",", "''", ",", "null", ",", "$", "message", ")", ";", "}", "}" ]
Retrieve the connection to the IMAP client. @return bool Whether a connection was successfully established.
[ "Retrieve", "the", "connection", "to", "the", "IMAP", "client", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L87-L130
219,317
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.get_confirmation_folder
protected function get_confirmation_folder() { if ($this->imapnamespace === null) { if ($this->client->queryCapability('NAMESPACE')) { $namespaces = $this->client->getNamespaces(array(), array('ob_return' => true)); $this->imapnamespace = $namespaces->getNamespace('INBOX'); } else { $this->imapnamespace = ''; } } return $this->imapnamespace . self::CONFIRMATIONFOLDER; }
php
protected function get_confirmation_folder() { if ($this->imapnamespace === null) { if ($this->client->queryCapability('NAMESPACE')) { $namespaces = $this->client->getNamespaces(array(), array('ob_return' => true)); $this->imapnamespace = $namespaces->getNamespace('INBOX'); } else { $this->imapnamespace = ''; } } return $this->imapnamespace . self::CONFIRMATIONFOLDER; }
[ "protected", "function", "get_confirmation_folder", "(", ")", "{", "if", "(", "$", "this", "->", "imapnamespace", "===", "null", ")", "{", "if", "(", "$", "this", "->", "client", "->", "queryCapability", "(", "'NAMESPACE'", ")", ")", "{", "$", "namespaces", "=", "$", "this", "->", "client", "->", "getNamespaces", "(", "array", "(", ")", ",", "array", "(", "'ob_return'", "=>", "true", ")", ")", ";", "$", "this", "->", "imapnamespace", "=", "$", "namespaces", "->", "getNamespace", "(", "'INBOX'", ")", ";", "}", "else", "{", "$", "this", "->", "imapnamespace", "=", "''", ";", "}", "}", "return", "$", "this", "->", "imapnamespace", ".", "self", "::", "CONFIRMATIONFOLDER", ";", "}" ]
Get the confirmation folder imap name @return string
[ "Get", "the", "confirmation", "folder", "imap", "name" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L147-L159
219,318
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.get_mailbox
protected function get_mailbox() { // Get the current mailbox. $mailbox = $this->client->currentMailbox(); if (isset($mailbox['mailbox'])) { return $mailbox['mailbox']; } else { throw new \core\message\inbound\processing_failed_exception('couldnotopenmailbox', 'tool_messageinbound'); } }
php
protected function get_mailbox() { // Get the current mailbox. $mailbox = $this->client->currentMailbox(); if (isset($mailbox['mailbox'])) { return $mailbox['mailbox']; } else { throw new \core\message\inbound\processing_failed_exception('couldnotopenmailbox', 'tool_messageinbound'); } }
[ "protected", "function", "get_mailbox", "(", ")", "{", "// Get the current mailbox.", "$", "mailbox", "=", "$", "this", "->", "client", "->", "currentMailbox", "(", ")", ";", "if", "(", "isset", "(", "$", "mailbox", "[", "'mailbox'", "]", ")", ")", "{", "return", "$", "mailbox", "[", "'mailbox'", "]", ";", "}", "else", "{", "throw", "new", "\\", "core", "\\", "message", "\\", "inbound", "\\", "processing_failed_exception", "(", "'couldnotopenmailbox'", ",", "'tool_messageinbound'", ")", ";", "}", "}" ]
Get the current mailbox information. @return \Horde_Imap_Client_Mailbox @throws \core\message\inbound\processing_failed_exception if the mailbox could not be opened.
[ "Get", "the", "current", "mailbox", "information", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L167-L176
219,319
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.pickup_messages
public function pickup_messages() { if (!$this->get_imap_client()) { return false; } // Restrict results to messages which are unseen, and have not been flagged. $search = new \Horde_Imap_Client_Search_Query(); $search->flag(self::MESSAGE_SEEN, false); $search->flag(self::MESSAGE_FLAGGED, false); mtrace("Searching for Unseen, Unflagged email in the folder '" . self::MAILBOX . "'"); $results = $this->client->search(self::MAILBOX, $search); // We require the envelope data and structure of each message. $query = new \Horde_Imap_Client_Fetch_Query(); $query->envelope(); $query->structure(); // Retrieve the message id. $messages = $this->client->fetch(self::MAILBOX, $query, array('ids' => $results['match'])); mtrace("Found " . $messages->count() . " messages to parse. Parsing..."); $this->addressmanager = new \core\message\inbound\address_manager(); foreach ($messages as $message) { $this->process_message($message); } // Close the client connection. $this->close_connection(); return true; }
php
public function pickup_messages() { if (!$this->get_imap_client()) { return false; } // Restrict results to messages which are unseen, and have not been flagged. $search = new \Horde_Imap_Client_Search_Query(); $search->flag(self::MESSAGE_SEEN, false); $search->flag(self::MESSAGE_FLAGGED, false); mtrace("Searching for Unseen, Unflagged email in the folder '" . self::MAILBOX . "'"); $results = $this->client->search(self::MAILBOX, $search); // We require the envelope data and structure of each message. $query = new \Horde_Imap_Client_Fetch_Query(); $query->envelope(); $query->structure(); // Retrieve the message id. $messages = $this->client->fetch(self::MAILBOX, $query, array('ids' => $results['match'])); mtrace("Found " . $messages->count() . " messages to parse. Parsing..."); $this->addressmanager = new \core\message\inbound\address_manager(); foreach ($messages as $message) { $this->process_message($message); } // Close the client connection. $this->close_connection(); return true; }
[ "public", "function", "pickup_messages", "(", ")", "{", "if", "(", "!", "$", "this", "->", "get_imap_client", "(", ")", ")", "{", "return", "false", ";", "}", "// Restrict results to messages which are unseen, and have not been flagged.", "$", "search", "=", "new", "\\", "Horde_Imap_Client_Search_Query", "(", ")", ";", "$", "search", "->", "flag", "(", "self", "::", "MESSAGE_SEEN", ",", "false", ")", ";", "$", "search", "->", "flag", "(", "self", "::", "MESSAGE_FLAGGED", ",", "false", ")", ";", "mtrace", "(", "\"Searching for Unseen, Unflagged email in the folder '\"", ".", "self", "::", "MAILBOX", ".", "\"'\"", ")", ";", "$", "results", "=", "$", "this", "->", "client", "->", "search", "(", "self", "::", "MAILBOX", ",", "$", "search", ")", ";", "// We require the envelope data and structure of each message.", "$", "query", "=", "new", "\\", "Horde_Imap_Client_Fetch_Query", "(", ")", ";", "$", "query", "->", "envelope", "(", ")", ";", "$", "query", "->", "structure", "(", ")", ";", "// Retrieve the message id.", "$", "messages", "=", "$", "this", "->", "client", "->", "fetch", "(", "self", "::", "MAILBOX", ",", "$", "query", ",", "array", "(", "'ids'", "=>", "$", "results", "[", "'match'", "]", ")", ")", ";", "mtrace", "(", "\"Found \"", ".", "$", "messages", "->", "count", "(", ")", ".", "\" messages to parse. Parsing...\"", ")", ";", "$", "this", "->", "addressmanager", "=", "new", "\\", "core", "\\", "message", "\\", "inbound", "\\", "address_manager", "(", ")", ";", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "$", "this", "->", "process_message", "(", "$", "message", ")", ";", "}", "// Close the client connection.", "$", "this", "->", "close_connection", "(", ")", ";", "return", "true", ";", "}" ]
Execute the main Inbound Message pickup task. @return bool
[ "Execute", "the", "main", "Inbound", "Message", "pickup", "task", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L183-L213
219,320
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.tidy_old_messages
public function tidy_old_messages() { // Grab the new IMAP client. if (!$this->get_imap_client()) { return false; } // Open the mailbox. mtrace("Searching for messages older than 24 hours in the '" . $this->get_confirmation_folder() . "' folder."); $this->client->openMailbox($this->get_confirmation_folder()); $mailbox = $this->get_mailbox(); // Build the search. $search = new \Horde_Imap_Client_Search_Query(); // Delete messages older than 24 hours old. $search->intervalSearch(DAYSECS, \Horde_Imap_Client_Search_Query::INTERVAL_OLDER); $results = $this->client->search($mailbox, $search); // Build the base query. $query = new \Horde_Imap_Client_Fetch_Query(); $query->envelope(); // Retrieve the messages and mark them for removal. $messages = $this->client->fetch($mailbox, $query, array('ids' => $results['match'])); mtrace("Found " . $messages->count() . " messages for removal."); foreach ($messages as $message) { $this->add_flag_to_message($message->getUid(), self::MESSAGE_DELETED); } mtrace("Finished removing messages."); $this->close_connection(); return true; }
php
public function tidy_old_messages() { // Grab the new IMAP client. if (!$this->get_imap_client()) { return false; } // Open the mailbox. mtrace("Searching for messages older than 24 hours in the '" . $this->get_confirmation_folder() . "' folder."); $this->client->openMailbox($this->get_confirmation_folder()); $mailbox = $this->get_mailbox(); // Build the search. $search = new \Horde_Imap_Client_Search_Query(); // Delete messages older than 24 hours old. $search->intervalSearch(DAYSECS, \Horde_Imap_Client_Search_Query::INTERVAL_OLDER); $results = $this->client->search($mailbox, $search); // Build the base query. $query = new \Horde_Imap_Client_Fetch_Query(); $query->envelope(); // Retrieve the messages and mark them for removal. $messages = $this->client->fetch($mailbox, $query, array('ids' => $results['match'])); mtrace("Found " . $messages->count() . " messages for removal."); foreach ($messages as $message) { $this->add_flag_to_message($message->getUid(), self::MESSAGE_DELETED); } mtrace("Finished removing messages."); $this->close_connection(); return true; }
[ "public", "function", "tidy_old_messages", "(", ")", "{", "// Grab the new IMAP client.", "if", "(", "!", "$", "this", "->", "get_imap_client", "(", ")", ")", "{", "return", "false", ";", "}", "// Open the mailbox.", "mtrace", "(", "\"Searching for messages older than 24 hours in the '\"", ".", "$", "this", "->", "get_confirmation_folder", "(", ")", ".", "\"' folder.\"", ")", ";", "$", "this", "->", "client", "->", "openMailbox", "(", "$", "this", "->", "get_confirmation_folder", "(", ")", ")", ";", "$", "mailbox", "=", "$", "this", "->", "get_mailbox", "(", ")", ";", "// Build the search.", "$", "search", "=", "new", "\\", "Horde_Imap_Client_Search_Query", "(", ")", ";", "// Delete messages older than 24 hours old.", "$", "search", "->", "intervalSearch", "(", "DAYSECS", ",", "\\", "Horde_Imap_Client_Search_Query", "::", "INTERVAL_OLDER", ")", ";", "$", "results", "=", "$", "this", "->", "client", "->", "search", "(", "$", "mailbox", ",", "$", "search", ")", ";", "// Build the base query.", "$", "query", "=", "new", "\\", "Horde_Imap_Client_Fetch_Query", "(", ")", ";", "$", "query", "->", "envelope", "(", ")", ";", "// Retrieve the messages and mark them for removal.", "$", "messages", "=", "$", "this", "->", "client", "->", "fetch", "(", "$", "mailbox", ",", "$", "query", ",", "array", "(", "'ids'", "=>", "$", "results", "[", "'match'", "]", ")", ")", ";", "mtrace", "(", "\"Found \"", ".", "$", "messages", "->", "count", "(", ")", ".", "\" messages for removal.\"", ")", ";", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "$", "this", "->", "add_flag_to_message", "(", "$", "message", "->", "getUid", "(", ")", ",", "self", "::", "MESSAGE_DELETED", ")", ";", "}", "mtrace", "(", "\"Finished removing messages.\"", ")", ";", "$", "this", "->", "close_connection", "(", ")", ";", "return", "true", ";", "}" ]
Tidy up old messages in the confirmation folder. @return bool Whether tidying occurred successfully.
[ "Tidy", "up", "old", "messages", "in", "the", "confirmation", "folder", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L275-L311
219,321
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.process_message_data
private function process_message_data( \Horde_Imap_Client_Data_Envelope $envelope, \Horde_Imap_Client_Data_Fetch $basemessagedata, $messageid) { // Get the current mailbox. $mailbox = $this->get_mailbox(); // We need the structure at various points below. $structure = $basemessagedata->getStructure(); // Now fetch the rest of the message content. $query = new \Horde_Imap_Client_Fetch_Query(); $query->imapDate(); // Fetch the message header. $query->headerText(); // Retrieve the message with the above components. $messagedata = $this->client->fetch($mailbox, $query, array('ids' => $messageid))->first(); if (!$messagedata) { // Message was not found! Somehow it has been removed or is no longer returned. return null; } // The message ID should always be in the first part. $data = new \stdClass(); $data->messageid = $messagedata->getHeaderText(0, \Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->getValue('Message-ID'); $data->subject = $envelope->subject; $data->timestamp = $messagedata->getImapDate()->__toString(); $data->envelope = $envelope; $data->data = $this->addressmanager->get_data(); $data->headers = $messagedata->getHeaderText(); $this->currentmessagedata = $data; return $this->currentmessagedata; }
php
private function process_message_data( \Horde_Imap_Client_Data_Envelope $envelope, \Horde_Imap_Client_Data_Fetch $basemessagedata, $messageid) { // Get the current mailbox. $mailbox = $this->get_mailbox(); // We need the structure at various points below. $structure = $basemessagedata->getStructure(); // Now fetch the rest of the message content. $query = new \Horde_Imap_Client_Fetch_Query(); $query->imapDate(); // Fetch the message header. $query->headerText(); // Retrieve the message with the above components. $messagedata = $this->client->fetch($mailbox, $query, array('ids' => $messageid))->first(); if (!$messagedata) { // Message was not found! Somehow it has been removed or is no longer returned. return null; } // The message ID should always be in the first part. $data = new \stdClass(); $data->messageid = $messagedata->getHeaderText(0, \Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->getValue('Message-ID'); $data->subject = $envelope->subject; $data->timestamp = $messagedata->getImapDate()->__toString(); $data->envelope = $envelope; $data->data = $this->addressmanager->get_data(); $data->headers = $messagedata->getHeaderText(); $this->currentmessagedata = $data; return $this->currentmessagedata; }
[ "private", "function", "process_message_data", "(", "\\", "Horde_Imap_Client_Data_Envelope", "$", "envelope", ",", "\\", "Horde_Imap_Client_Data_Fetch", "$", "basemessagedata", ",", "$", "messageid", ")", "{", "// Get the current mailbox.", "$", "mailbox", "=", "$", "this", "->", "get_mailbox", "(", ")", ";", "// We need the structure at various points below.", "$", "structure", "=", "$", "basemessagedata", "->", "getStructure", "(", ")", ";", "// Now fetch the rest of the message content.", "$", "query", "=", "new", "\\", "Horde_Imap_Client_Fetch_Query", "(", ")", ";", "$", "query", "->", "imapDate", "(", ")", ";", "// Fetch the message header.", "$", "query", "->", "headerText", "(", ")", ";", "// Retrieve the message with the above components.", "$", "messagedata", "=", "$", "this", "->", "client", "->", "fetch", "(", "$", "mailbox", ",", "$", "query", ",", "array", "(", "'ids'", "=>", "$", "messageid", ")", ")", "->", "first", "(", ")", ";", "if", "(", "!", "$", "messagedata", ")", "{", "// Message was not found! Somehow it has been removed or is no longer returned.", "return", "null", ";", "}", "// The message ID should always be in the first part.", "$", "data", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "data", "->", "messageid", "=", "$", "messagedata", "->", "getHeaderText", "(", "0", ",", "\\", "Horde_Imap_Client_Data_Fetch", "::", "HEADER_PARSE", ")", "->", "getValue", "(", "'Message-ID'", ")", ";", "$", "data", "->", "subject", "=", "$", "envelope", "->", "subject", ";", "$", "data", "->", "timestamp", "=", "$", "messagedata", "->", "getImapDate", "(", ")", "->", "__toString", "(", ")", ";", "$", "data", "->", "envelope", "=", "$", "envelope", ";", "$", "data", "->", "data", "=", "$", "this", "->", "addressmanager", "->", "get_data", "(", ")", ";", "$", "data", "->", "headers", "=", "$", "messagedata", "->", "getHeaderText", "(", ")", ";", "$", "this", "->", "currentmessagedata", "=", "$", "data", ";", "return", "$", "this", "->", "currentmessagedata", ";", "}" ]
Process a message to retrieve it's header data without body and attachemnts. @param \Horde_Imap_Client_Data_Envelope $envelope The Envelope of the message @param \Horde_Imap_Client_Data_Fetch $basemessagedata The structure and part of the message body @param string|\Horde_Imap_Client_Ids $messageid The Hore message Uid @return \stdClass The current value of the messagedata
[ "Process", "a", "message", "to", "retrieve", "it", "s", "header", "data", "without", "body", "and", "attachemnts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L503-L541
219,322
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.process_message_part_body
private function process_message_part_body($messagedata, $partdata, $part) { // This is a content section for the main body. // Get the string version of it. $content = $messagedata->getBodyPart($part); if (!$messagedata->getBodyPartDecode($part)) { // Decode the content. $partdata->setContents($content); $content = $partdata->getContents(); } // Convert the text from the current encoding to UTF8. $content = \core_text::convert($content, $partdata->getCharset()); // Fix any invalid UTF8 characters. // Note: XSS cleaning is not the responsibility of this code. It occurs immediately before display when // format_text is called. $content = clean_param($content, PARAM_RAW); return $content; }
php
private function process_message_part_body($messagedata, $partdata, $part) { // This is a content section for the main body. // Get the string version of it. $content = $messagedata->getBodyPart($part); if (!$messagedata->getBodyPartDecode($part)) { // Decode the content. $partdata->setContents($content); $content = $partdata->getContents(); } // Convert the text from the current encoding to UTF8. $content = \core_text::convert($content, $partdata->getCharset()); // Fix any invalid UTF8 characters. // Note: XSS cleaning is not the responsibility of this code. It occurs immediately before display when // format_text is called. $content = clean_param($content, PARAM_RAW); return $content; }
[ "private", "function", "process_message_part_body", "(", "$", "messagedata", ",", "$", "partdata", ",", "$", "part", ")", "{", "// This is a content section for the main body.", "// Get the string version of it.", "$", "content", "=", "$", "messagedata", "->", "getBodyPart", "(", "$", "part", ")", ";", "if", "(", "!", "$", "messagedata", "->", "getBodyPartDecode", "(", "$", "part", ")", ")", "{", "// Decode the content.", "$", "partdata", "->", "setContents", "(", "$", "content", ")", ";", "$", "content", "=", "$", "partdata", "->", "getContents", "(", ")", ";", "}", "// Convert the text from the current encoding to UTF8.", "$", "content", "=", "\\", "core_text", "::", "convert", "(", "$", "content", ",", "$", "partdata", "->", "getCharset", "(", ")", ")", ";", "// Fix any invalid UTF8 characters.", "// Note: XSS cleaning is not the responsibility of this code. It occurs immediately before display when", "// format_text is called.", "$", "content", "=", "clean_param", "(", "$", "content", ",", "PARAM_RAW", ")", ";", "return", "$", "content", ";", "}" ]
Process the messagedata and part data to extract the content of this part. @param \Horde_Imap_Client_Data_Fetch $messagedata The structure and part of the message body @param \Horde_Mime_Part $partdata The part data @param string $part The part ID @return string
[ "Process", "the", "messagedata", "and", "part", "data", "to", "extract", "the", "content", "of", "this", "part", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L632-L652
219,323
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.passes_key_validation
private function passes_key_validation($status, $messageid) { // The validation result is tested in a bitwise operation. if (( $status & ~ \core\message\inbound\address_manager::VALIDATION_SUCCESS & ~ \core\message\inbound\address_manager::VALIDATION_UNKNOWN_DATAKEY & ~ \core\message\inbound\address_manager::VALIDATION_EXPIRED_DATAKEY & ~ \core\message\inbound\address_manager::VALIDATION_INVALID_HASH & ~ \core\message\inbound\address_manager::VALIDATION_ADDRESS_MISMATCH) !== 0) { // One of the above bits was found in the status - fail the validation. return false; } return true; }
php
private function passes_key_validation($status, $messageid) { // The validation result is tested in a bitwise operation. if (( $status & ~ \core\message\inbound\address_manager::VALIDATION_SUCCESS & ~ \core\message\inbound\address_manager::VALIDATION_UNKNOWN_DATAKEY & ~ \core\message\inbound\address_manager::VALIDATION_EXPIRED_DATAKEY & ~ \core\message\inbound\address_manager::VALIDATION_INVALID_HASH & ~ \core\message\inbound\address_manager::VALIDATION_ADDRESS_MISMATCH) !== 0) { // One of the above bits was found in the status - fail the validation. return false; } return true; }
[ "private", "function", "passes_key_validation", "(", "$", "status", ",", "$", "messageid", ")", "{", "// The validation result is tested in a bitwise operation.", "if", "(", "(", "$", "status", "&", "~", "\\", "core", "\\", "message", "\\", "inbound", "\\", "address_manager", "::", "VALIDATION_SUCCESS", "&", "~", "\\", "core", "\\", "message", "\\", "inbound", "\\", "address_manager", "::", "VALIDATION_UNKNOWN_DATAKEY", "&", "~", "\\", "core", "\\", "message", "\\", "inbound", "\\", "address_manager", "::", "VALIDATION_EXPIRED_DATAKEY", "&", "~", "\\", "core", "\\", "message", "\\", "inbound", "\\", "address_manager", "::", "VALIDATION_INVALID_HASH", "&", "~", "\\", "core", "\\", "message", "\\", "inbound", "\\", "address_manager", "::", "VALIDATION_ADDRESS_MISMATCH", ")", "!==", "0", ")", "{", "// One of the above bits was found in the status - fail the validation.", "return", "false", ";", "}", "return", "true", ";", "}" ]
Check whether the key provided is valid. @param bool $status @param mixed $messageid The Hore message Uid @return bool
[ "Check", "whether", "the", "key", "provided", "is", "valid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L699-L712
219,324
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.add_flag_to_message
private function add_flag_to_message($messageid, $flag) { // Get the current mailbox. $mailbox = $this->get_mailbox(); // Mark it as read to lock the message. $this->client->store($mailbox, array( 'ids' => new \Horde_Imap_Client_Ids($messageid), 'add' => $flag, )); }
php
private function add_flag_to_message($messageid, $flag) { // Get the current mailbox. $mailbox = $this->get_mailbox(); // Mark it as read to lock the message. $this->client->store($mailbox, array( 'ids' => new \Horde_Imap_Client_Ids($messageid), 'add' => $flag, )); }
[ "private", "function", "add_flag_to_message", "(", "$", "messageid", ",", "$", "flag", ")", "{", "// Get the current mailbox.", "$", "mailbox", "=", "$", "this", "->", "get_mailbox", "(", ")", ";", "// Mark it as read to lock the message.", "$", "this", "->", "client", "->", "store", "(", "$", "mailbox", ",", "array", "(", "'ids'", "=>", "new", "\\", "Horde_Imap_Client_Ids", "(", "$", "messageid", ")", ",", "'add'", "=>", "$", "flag", ",", ")", ")", ";", "}" ]
Add the specified flag to the message. @param mixed $messageid @param string $flag The flag to add
[ "Add", "the", "specified", "flag", "to", "the", "message", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L720-L729
219,325
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.remove_flag_from_message
private function remove_flag_from_message($messageid, $flag) { // Get the current mailbox. $mailbox = $this->get_mailbox(); // Mark it as read to lock the message. $this->client->store($mailbox, array( 'ids' => $messageid, 'delete' => $flag, )); }
php
private function remove_flag_from_message($messageid, $flag) { // Get the current mailbox. $mailbox = $this->get_mailbox(); // Mark it as read to lock the message. $this->client->store($mailbox, array( 'ids' => $messageid, 'delete' => $flag, )); }
[ "private", "function", "remove_flag_from_message", "(", "$", "messageid", ",", "$", "flag", ")", "{", "// Get the current mailbox.", "$", "mailbox", "=", "$", "this", "->", "get_mailbox", "(", ")", ";", "// Mark it as read to lock the message.", "$", "this", "->", "client", "->", "store", "(", "$", "mailbox", ",", "array", "(", "'ids'", "=>", "$", "messageid", ",", "'delete'", "=>", "$", "flag", ",", ")", ")", ";", "}" ]
Remove the specified flag from the message. @param mixed $messageid @param string $flag The flag to remove
[ "Remove", "the", "specified", "flag", "from", "the", "message", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L737-L746
219,326
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.message_has_flag
private function message_has_flag($messageid, $flag) { // Get the current mailbox. $mailbox = $this->get_mailbox(); // Grab messagedata including flags. $query = new \Horde_Imap_Client_Fetch_Query(); $query->flags(); $query->structure(); $messagedata = $this->client->fetch($mailbox, $query, array( 'ids' => $messageid, ))->first(); $flags = $messagedata->getFlags(); return in_array($flag, $flags); }
php
private function message_has_flag($messageid, $flag) { // Get the current mailbox. $mailbox = $this->get_mailbox(); // Grab messagedata including flags. $query = new \Horde_Imap_Client_Fetch_Query(); $query->flags(); $query->structure(); $messagedata = $this->client->fetch($mailbox, $query, array( 'ids' => $messageid, ))->first(); $flags = $messagedata->getFlags(); return in_array($flag, $flags); }
[ "private", "function", "message_has_flag", "(", "$", "messageid", ",", "$", "flag", ")", "{", "// Get the current mailbox.", "$", "mailbox", "=", "$", "this", "->", "get_mailbox", "(", ")", ";", "// Grab messagedata including flags.", "$", "query", "=", "new", "\\", "Horde_Imap_Client_Fetch_Query", "(", ")", ";", "$", "query", "->", "flags", "(", ")", ";", "$", "query", "->", "structure", "(", ")", ";", "$", "messagedata", "=", "$", "this", "->", "client", "->", "fetch", "(", "$", "mailbox", ",", "$", "query", ",", "array", "(", "'ids'", "=>", "$", "messageid", ",", ")", ")", "->", "first", "(", ")", ";", "$", "flags", "=", "$", "messagedata", "->", "getFlags", "(", ")", ";", "return", "in_array", "(", "$", "flag", ",", "$", "flags", ")", ";", "}" ]
Check whether the message has the specified flag @param mixed $messageid @param string $flag The flag to check @return bool
[ "Check", "whether", "the", "message", "has", "the", "specified", "flag" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L755-L769
219,327
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.ensure_mailboxes_exist
private function ensure_mailboxes_exist() { $requiredmailboxes = array( self::MAILBOX, $this->get_confirmation_folder(), ); $existingmailboxes = $this->client->listMailboxes($requiredmailboxes); foreach ($requiredmailboxes as $mailbox) { if (isset($existingmailboxes[$mailbox])) { // This mailbox was found. continue; } mtrace("Unable to find the '{$mailbox}' mailbox - creating it."); $this->client->createMailbox($mailbox); } }
php
private function ensure_mailboxes_exist() { $requiredmailboxes = array( self::MAILBOX, $this->get_confirmation_folder(), ); $existingmailboxes = $this->client->listMailboxes($requiredmailboxes); foreach ($requiredmailboxes as $mailbox) { if (isset($existingmailboxes[$mailbox])) { // This mailbox was found. continue; } mtrace("Unable to find the '{$mailbox}' mailbox - creating it."); $this->client->createMailbox($mailbox); } }
[ "private", "function", "ensure_mailboxes_exist", "(", ")", "{", "$", "requiredmailboxes", "=", "array", "(", "self", "::", "MAILBOX", ",", "$", "this", "->", "get_confirmation_folder", "(", ")", ",", ")", ";", "$", "existingmailboxes", "=", "$", "this", "->", "client", "->", "listMailboxes", "(", "$", "requiredmailboxes", ")", ";", "foreach", "(", "$", "requiredmailboxes", "as", "$", "mailbox", ")", "{", "if", "(", "isset", "(", "$", "existingmailboxes", "[", "$", "mailbox", "]", ")", ")", "{", "// This mailbox was found.", "continue", ";", "}", "mtrace", "(", "\"Unable to find the '{$mailbox}' mailbox - creating it.\"", ")", ";", "$", "this", "->", "client", "->", "createMailbox", "(", "$", "mailbox", ")", ";", "}", "}" ]
Ensure that all mailboxes exist.
[ "Ensure", "that", "all", "mailboxes", "exist", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L774-L791
219,328
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.send_to_handler
private function send_to_handler() { try { mtrace("--> Passing to Inbound Message handler {$this->addressmanager->get_handler()->classname}"); if ($result = $this->addressmanager->handle_message($this->currentmessagedata)) { $this->inform_user_of_success($this->currentmessagedata, $result); // Request that this message be marked for deletion. return true; } } catch (\core\message\inbound\processing_failed_exception $e) { mtrace("-> The Inbound Message handler threw an exception. Unable to process this message. The user has been informed."); mtrace("--> " . $e->getMessage()); // Throw the exception again, with additional data. $error = new \stdClass(); $error->subject = $this->currentmessagedata->envelope->subject; $error->message = $e->getMessage(); throw new \core\message\inbound\processing_failed_exception('messageprocessingfailed', 'tool_messageinbound', $error); } catch (\Exception $e) { mtrace("-> The Inbound Message handler threw an exception. Unable to process this message. User informed."); mtrace("--> " . $e->getMessage()); // An unknown error occurred. Still inform the user but, this time do not include the specific // message information. $error = new \stdClass(); $error->subject = $this->currentmessagedata->envelope->subject; throw new \core\message\inbound\processing_failed_exception('messageprocessingfailedunknown', 'tool_messageinbound', $error); } // Something went wrong and the message was not handled well in the Inbound Message handler. mtrace("-> The Inbound Message handler reported an error. The message may not have been processed."); // It is the responsiblity of the handler to throw an appropriate exception if the message was not processed. // Do not inform the user at this point. return false; }
php
private function send_to_handler() { try { mtrace("--> Passing to Inbound Message handler {$this->addressmanager->get_handler()->classname}"); if ($result = $this->addressmanager->handle_message($this->currentmessagedata)) { $this->inform_user_of_success($this->currentmessagedata, $result); // Request that this message be marked for deletion. return true; } } catch (\core\message\inbound\processing_failed_exception $e) { mtrace("-> The Inbound Message handler threw an exception. Unable to process this message. The user has been informed."); mtrace("--> " . $e->getMessage()); // Throw the exception again, with additional data. $error = new \stdClass(); $error->subject = $this->currentmessagedata->envelope->subject; $error->message = $e->getMessage(); throw new \core\message\inbound\processing_failed_exception('messageprocessingfailed', 'tool_messageinbound', $error); } catch (\Exception $e) { mtrace("-> The Inbound Message handler threw an exception. Unable to process this message. User informed."); mtrace("--> " . $e->getMessage()); // An unknown error occurred. Still inform the user but, this time do not include the specific // message information. $error = new \stdClass(); $error->subject = $this->currentmessagedata->envelope->subject; throw new \core\message\inbound\processing_failed_exception('messageprocessingfailedunknown', 'tool_messageinbound', $error); } // Something went wrong and the message was not handled well in the Inbound Message handler. mtrace("-> The Inbound Message handler reported an error. The message may not have been processed."); // It is the responsiblity of the handler to throw an appropriate exception if the message was not processed. // Do not inform the user at this point. return false; }
[ "private", "function", "send_to_handler", "(", ")", "{", "try", "{", "mtrace", "(", "\"--> Passing to Inbound Message handler {$this->addressmanager->get_handler()->classname}\"", ")", ";", "if", "(", "$", "result", "=", "$", "this", "->", "addressmanager", "->", "handle_message", "(", "$", "this", "->", "currentmessagedata", ")", ")", "{", "$", "this", "->", "inform_user_of_success", "(", "$", "this", "->", "currentmessagedata", ",", "$", "result", ")", ";", "// Request that this message be marked for deletion.", "return", "true", ";", "}", "}", "catch", "(", "\\", "core", "\\", "message", "\\", "inbound", "\\", "processing_failed_exception", "$", "e", ")", "{", "mtrace", "(", "\"-> The Inbound Message handler threw an exception. Unable to process this message. The user has been informed.\"", ")", ";", "mtrace", "(", "\"--> \"", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "// Throw the exception again, with additional data.", "$", "error", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "error", "->", "subject", "=", "$", "this", "->", "currentmessagedata", "->", "envelope", "->", "subject", ";", "$", "error", "->", "message", "=", "$", "e", "->", "getMessage", "(", ")", ";", "throw", "new", "\\", "core", "\\", "message", "\\", "inbound", "\\", "processing_failed_exception", "(", "'messageprocessingfailed'", ",", "'tool_messageinbound'", ",", "$", "error", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "mtrace", "(", "\"-> The Inbound Message handler threw an exception. Unable to process this message. User informed.\"", ")", ";", "mtrace", "(", "\"--> \"", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "// An unknown error occurred. Still inform the user but, this time do not include the specific", "// message information.", "$", "error", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "error", "->", "subject", "=", "$", "this", "->", "currentmessagedata", "->", "envelope", "->", "subject", ";", "throw", "new", "\\", "core", "\\", "message", "\\", "inbound", "\\", "processing_failed_exception", "(", "'messageprocessingfailedunknown'", ",", "'tool_messageinbound'", ",", "$", "error", ")", ";", "}", "// Something went wrong and the message was not handled well in the Inbound Message handler.", "mtrace", "(", "\"-> The Inbound Message handler reported an error. The message may not have been processed.\"", ")", ";", "// It is the responsiblity of the handler to throw an appropriate exception if the message was not processed.", "// Do not inform the user at this point.", "return", "false", ";", "}" ]
Send the message to the appropriate handler. @return bool @throws \core\message\inbound\processing_failed_exception if anything goes wrong.
[ "Send", "the", "message", "to", "the", "appropriate", "handler", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L836-L872
219,329
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.handle_verification_failure
private function handle_verification_failure( \Horde_Imap_Client_Ids $messageids, $recipient) { global $DB, $USER; if (!$messageid = $this->currentmessagedata->messageid) { mtrace("---> Warning: Unable to determine the Message-ID of the message."); return false; } // Move the message into a new mailbox. $this->client->copy(self::MAILBOX, $this->get_confirmation_folder(), array( 'create' => true, 'ids' => $messageids, 'move' => true, )); // Store the data from the failed message in the associated table. $record = new \stdClass(); $record->messageid = $messageid; $record->userid = $USER->id; $record->address = $recipient; $record->timecreated = time(); $record->id = $DB->insert_record('messageinbound_messagelist', $record); // Setup the Inbound Message generator for the invalid recipient handler. $addressmanager = new \core\message\inbound\address_manager(); $addressmanager->set_handler('\tool_messageinbound\message\inbound\invalid_recipient_handler'); $addressmanager->set_data($record->id); $eventdata = new \core\message\message(); $eventdata->component = 'tool_messageinbound'; $eventdata->name = 'invalidrecipienthandler'; $userfrom = clone $USER; $userfrom->customheaders = array(); // Adding the In-Reply-To header ensures that it is seen as a reply. $userfrom->customheaders[] = 'In-Reply-To: ' . $messageid; // The message will be sent from the intended user. $eventdata->courseid = SITEID; $eventdata->userfrom = \core_user::get_noreply_user(); $eventdata->userto = $USER; $eventdata->subject = $this->get_reply_subject($this->currentmessagedata->envelope->subject); $eventdata->fullmessage = get_string('invalidrecipientdescription', 'tool_messageinbound', $this->currentmessagedata); $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = get_string('invalidrecipientdescriptionhtml', 'tool_messageinbound', $this->currentmessagedata); $eventdata->smallmessage = $eventdata->fullmessage; $eventdata->notification = 1; $eventdata->replyto = $addressmanager->generate($USER->id); mtrace("--> Sending a message to the user to report an verification failure."); if (!message_send($eventdata)) { mtrace("---> Warning: Message could not be sent."); return false; } return true; }
php
private function handle_verification_failure( \Horde_Imap_Client_Ids $messageids, $recipient) { global $DB, $USER; if (!$messageid = $this->currentmessagedata->messageid) { mtrace("---> Warning: Unable to determine the Message-ID of the message."); return false; } // Move the message into a new mailbox. $this->client->copy(self::MAILBOX, $this->get_confirmation_folder(), array( 'create' => true, 'ids' => $messageids, 'move' => true, )); // Store the data from the failed message in the associated table. $record = new \stdClass(); $record->messageid = $messageid; $record->userid = $USER->id; $record->address = $recipient; $record->timecreated = time(); $record->id = $DB->insert_record('messageinbound_messagelist', $record); // Setup the Inbound Message generator for the invalid recipient handler. $addressmanager = new \core\message\inbound\address_manager(); $addressmanager->set_handler('\tool_messageinbound\message\inbound\invalid_recipient_handler'); $addressmanager->set_data($record->id); $eventdata = new \core\message\message(); $eventdata->component = 'tool_messageinbound'; $eventdata->name = 'invalidrecipienthandler'; $userfrom = clone $USER; $userfrom->customheaders = array(); // Adding the In-Reply-To header ensures that it is seen as a reply. $userfrom->customheaders[] = 'In-Reply-To: ' . $messageid; // The message will be sent from the intended user. $eventdata->courseid = SITEID; $eventdata->userfrom = \core_user::get_noreply_user(); $eventdata->userto = $USER; $eventdata->subject = $this->get_reply_subject($this->currentmessagedata->envelope->subject); $eventdata->fullmessage = get_string('invalidrecipientdescription', 'tool_messageinbound', $this->currentmessagedata); $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = get_string('invalidrecipientdescriptionhtml', 'tool_messageinbound', $this->currentmessagedata); $eventdata->smallmessage = $eventdata->fullmessage; $eventdata->notification = 1; $eventdata->replyto = $addressmanager->generate($USER->id); mtrace("--> Sending a message to the user to report an verification failure."); if (!message_send($eventdata)) { mtrace("---> Warning: Message could not be sent."); return false; } return true; }
[ "private", "function", "handle_verification_failure", "(", "\\", "Horde_Imap_Client_Ids", "$", "messageids", ",", "$", "recipient", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "if", "(", "!", "$", "messageid", "=", "$", "this", "->", "currentmessagedata", "->", "messageid", ")", "{", "mtrace", "(", "\"---> Warning: Unable to determine the Message-ID of the message.\"", ")", ";", "return", "false", ";", "}", "// Move the message into a new mailbox.", "$", "this", "->", "client", "->", "copy", "(", "self", "::", "MAILBOX", ",", "$", "this", "->", "get_confirmation_folder", "(", ")", ",", "array", "(", "'create'", "=>", "true", ",", "'ids'", "=>", "$", "messageids", ",", "'move'", "=>", "true", ",", ")", ")", ";", "// Store the data from the failed message in the associated table.", "$", "record", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "record", "->", "messageid", "=", "$", "messageid", ";", "$", "record", "->", "userid", "=", "$", "USER", "->", "id", ";", "$", "record", "->", "address", "=", "$", "recipient", ";", "$", "record", "->", "timecreated", "=", "time", "(", ")", ";", "$", "record", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'messageinbound_messagelist'", ",", "$", "record", ")", ";", "// Setup the Inbound Message generator for the invalid recipient handler.", "$", "addressmanager", "=", "new", "\\", "core", "\\", "message", "\\", "inbound", "\\", "address_manager", "(", ")", ";", "$", "addressmanager", "->", "set_handler", "(", "'\\tool_messageinbound\\message\\inbound\\invalid_recipient_handler'", ")", ";", "$", "addressmanager", "->", "set_data", "(", "$", "record", "->", "id", ")", ";", "$", "eventdata", "=", "new", "\\", "core", "\\", "message", "\\", "message", "(", ")", ";", "$", "eventdata", "->", "component", "=", "'tool_messageinbound'", ";", "$", "eventdata", "->", "name", "=", "'invalidrecipienthandler'", ";", "$", "userfrom", "=", "clone", "$", "USER", ";", "$", "userfrom", "->", "customheaders", "=", "array", "(", ")", ";", "// Adding the In-Reply-To header ensures that it is seen as a reply.", "$", "userfrom", "->", "customheaders", "[", "]", "=", "'In-Reply-To: '", ".", "$", "messageid", ";", "// The message will be sent from the intended user.", "$", "eventdata", "->", "courseid", "=", "SITEID", ";", "$", "eventdata", "->", "userfrom", "=", "\\", "core_user", "::", "get_noreply_user", "(", ")", ";", "$", "eventdata", "->", "userto", "=", "$", "USER", ";", "$", "eventdata", "->", "subject", "=", "$", "this", "->", "get_reply_subject", "(", "$", "this", "->", "currentmessagedata", "->", "envelope", "->", "subject", ")", ";", "$", "eventdata", "->", "fullmessage", "=", "get_string", "(", "'invalidrecipientdescription'", ",", "'tool_messageinbound'", ",", "$", "this", "->", "currentmessagedata", ")", ";", "$", "eventdata", "->", "fullmessageformat", "=", "FORMAT_PLAIN", ";", "$", "eventdata", "->", "fullmessagehtml", "=", "get_string", "(", "'invalidrecipientdescriptionhtml'", ",", "'tool_messageinbound'", ",", "$", "this", "->", "currentmessagedata", ")", ";", "$", "eventdata", "->", "smallmessage", "=", "$", "eventdata", "->", "fullmessage", ";", "$", "eventdata", "->", "notification", "=", "1", ";", "$", "eventdata", "->", "replyto", "=", "$", "addressmanager", "->", "generate", "(", "$", "USER", "->", "id", ")", ";", "mtrace", "(", "\"--> Sending a message to the user to report an verification failure.\"", ")", ";", "if", "(", "!", "message_send", "(", "$", "eventdata", ")", ")", "{", "mtrace", "(", "\"---> Warning: Message could not be sent.\"", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
Handle failure of sender verification. This will send a notification to the user identified in the Inbound Message address informing them that a message has been stored. The message includes a verification link and reply-to address which is handled by the invalid_recipient_handler. @param \Horde_Imap_Client_Ids $messageids @param string $recipient The message recipient @return bool
[ "Handle", "failure", "of", "sender", "verification", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L885-L943
219,330
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.inform_user_of_error
private function inform_user_of_error($error) { global $USER; // The message will be sent from the intended user. $userfrom = clone $USER; $userfrom->customheaders = array(); if ($messageid = $this->currentmessagedata->messageid) { // Adding the In-Reply-To header ensures that it is seen as a reply and threading is maintained. $userfrom->customheaders[] = 'In-Reply-To: ' . $messageid; } $messagedata = new \stdClass(); $messagedata->subject = $this->currentmessagedata->envelope->subject; $messagedata->error = $error; $eventdata = new \core\message\message(); $eventdata->courseid = SITEID; $eventdata->component = 'tool_messageinbound'; $eventdata->name = 'messageprocessingerror'; $eventdata->userfrom = $userfrom; $eventdata->userto = $USER; $eventdata->subject = self::get_reply_subject($this->currentmessagedata->envelope->subject); $eventdata->fullmessage = get_string('messageprocessingerror', 'tool_messageinbound', $messagedata); $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = get_string('messageprocessingerrorhtml', 'tool_messageinbound', $messagedata); $eventdata->smallmessage = $eventdata->fullmessage; $eventdata->notification = 1; if (message_send($eventdata)) { mtrace("---> Notification sent to {$USER->email}."); } else { mtrace("---> Unable to send notification."); } }
php
private function inform_user_of_error($error) { global $USER; // The message will be sent from the intended user. $userfrom = clone $USER; $userfrom->customheaders = array(); if ($messageid = $this->currentmessagedata->messageid) { // Adding the In-Reply-To header ensures that it is seen as a reply and threading is maintained. $userfrom->customheaders[] = 'In-Reply-To: ' . $messageid; } $messagedata = new \stdClass(); $messagedata->subject = $this->currentmessagedata->envelope->subject; $messagedata->error = $error; $eventdata = new \core\message\message(); $eventdata->courseid = SITEID; $eventdata->component = 'tool_messageinbound'; $eventdata->name = 'messageprocessingerror'; $eventdata->userfrom = $userfrom; $eventdata->userto = $USER; $eventdata->subject = self::get_reply_subject($this->currentmessagedata->envelope->subject); $eventdata->fullmessage = get_string('messageprocessingerror', 'tool_messageinbound', $messagedata); $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = get_string('messageprocessingerrorhtml', 'tool_messageinbound', $messagedata); $eventdata->smallmessage = $eventdata->fullmessage; $eventdata->notification = 1; if (message_send($eventdata)) { mtrace("---> Notification sent to {$USER->email}."); } else { mtrace("---> Unable to send notification."); } }
[ "private", "function", "inform_user_of_error", "(", "$", "error", ")", "{", "global", "$", "USER", ";", "// The message will be sent from the intended user.", "$", "userfrom", "=", "clone", "$", "USER", ";", "$", "userfrom", "->", "customheaders", "=", "array", "(", ")", ";", "if", "(", "$", "messageid", "=", "$", "this", "->", "currentmessagedata", "->", "messageid", ")", "{", "// Adding the In-Reply-To header ensures that it is seen as a reply and threading is maintained.", "$", "userfrom", "->", "customheaders", "[", "]", "=", "'In-Reply-To: '", ".", "$", "messageid", ";", "}", "$", "messagedata", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "messagedata", "->", "subject", "=", "$", "this", "->", "currentmessagedata", "->", "envelope", "->", "subject", ";", "$", "messagedata", "->", "error", "=", "$", "error", ";", "$", "eventdata", "=", "new", "\\", "core", "\\", "message", "\\", "message", "(", ")", ";", "$", "eventdata", "->", "courseid", "=", "SITEID", ";", "$", "eventdata", "->", "component", "=", "'tool_messageinbound'", ";", "$", "eventdata", "->", "name", "=", "'messageprocessingerror'", ";", "$", "eventdata", "->", "userfrom", "=", "$", "userfrom", ";", "$", "eventdata", "->", "userto", "=", "$", "USER", ";", "$", "eventdata", "->", "subject", "=", "self", "::", "get_reply_subject", "(", "$", "this", "->", "currentmessagedata", "->", "envelope", "->", "subject", ")", ";", "$", "eventdata", "->", "fullmessage", "=", "get_string", "(", "'messageprocessingerror'", ",", "'tool_messageinbound'", ",", "$", "messagedata", ")", ";", "$", "eventdata", "->", "fullmessageformat", "=", "FORMAT_PLAIN", ";", "$", "eventdata", "->", "fullmessagehtml", "=", "get_string", "(", "'messageprocessingerrorhtml'", ",", "'tool_messageinbound'", ",", "$", "messagedata", ")", ";", "$", "eventdata", "->", "smallmessage", "=", "$", "eventdata", "->", "fullmessage", ";", "$", "eventdata", "->", "notification", "=", "1", ";", "if", "(", "message_send", "(", "$", "eventdata", ")", ")", "{", "mtrace", "(", "\"---> Notification sent to {$USER->email}.\"", ")", ";", "}", "else", "{", "mtrace", "(", "\"---> Unable to send notification.\"", ")", ";", "}", "}" ]
Inform the identified sender of a processing error. @param string $error The error message
[ "Inform", "the", "identified", "sender", "of", "a", "processing", "error", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L950-L984
219,331
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.inform_user_of_success
private function inform_user_of_success(\stdClass $messagedata, $handlerresult) { global $USER; // Check whether the handler has a success notification. $handler = $this->addressmanager->get_handler(); $message = $handler->get_success_message($messagedata, $handlerresult); if (!$message) { mtrace("---> Handler has not defined a success notification e-mail."); return false; } // Wrap the message in the notification wrapper. $messageparams = new \stdClass(); $messageparams->html = $message->html; $messageparams->plain = $message->plain; $messagepreferencesurl = new \moodle_url("/message/notificationpreferences.php", array('id' => $USER->id)); $messageparams->messagepreferencesurl = $messagepreferencesurl->out(); $htmlmessage = get_string('messageprocessingsuccesshtml', 'tool_messageinbound', $messageparams); $plainmessage = get_string('messageprocessingsuccess', 'tool_messageinbound', $messageparams); // The message will be sent from the intended user. $userfrom = clone $USER; $userfrom->customheaders = array(); if ($messageid = $this->currentmessagedata->messageid) { // Adding the In-Reply-To header ensures that it is seen as a reply and threading is maintained. $userfrom->customheaders[] = 'In-Reply-To: ' . $messageid; } $messagedata = new \stdClass(); $messagedata->subject = $this->currentmessagedata->envelope->subject; $eventdata = new \core\message\message(); $eventdata->courseid = SITEID; $eventdata->component = 'tool_messageinbound'; $eventdata->name = 'messageprocessingsuccess'; $eventdata->userfrom = $userfrom; $eventdata->userto = $USER; $eventdata->subject = self::get_reply_subject($this->currentmessagedata->envelope->subject); $eventdata->fullmessage = $plainmessage; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $htmlmessage; $eventdata->smallmessage = $eventdata->fullmessage; $eventdata->notification = 1; if (message_send($eventdata)) { mtrace("---> Success notification sent to {$USER->email}."); } else { mtrace("---> Unable to send success notification."); } return true; }
php
private function inform_user_of_success(\stdClass $messagedata, $handlerresult) { global $USER; // Check whether the handler has a success notification. $handler = $this->addressmanager->get_handler(); $message = $handler->get_success_message($messagedata, $handlerresult); if (!$message) { mtrace("---> Handler has not defined a success notification e-mail."); return false; } // Wrap the message in the notification wrapper. $messageparams = new \stdClass(); $messageparams->html = $message->html; $messageparams->plain = $message->plain; $messagepreferencesurl = new \moodle_url("/message/notificationpreferences.php", array('id' => $USER->id)); $messageparams->messagepreferencesurl = $messagepreferencesurl->out(); $htmlmessage = get_string('messageprocessingsuccesshtml', 'tool_messageinbound', $messageparams); $plainmessage = get_string('messageprocessingsuccess', 'tool_messageinbound', $messageparams); // The message will be sent from the intended user. $userfrom = clone $USER; $userfrom->customheaders = array(); if ($messageid = $this->currentmessagedata->messageid) { // Adding the In-Reply-To header ensures that it is seen as a reply and threading is maintained. $userfrom->customheaders[] = 'In-Reply-To: ' . $messageid; } $messagedata = new \stdClass(); $messagedata->subject = $this->currentmessagedata->envelope->subject; $eventdata = new \core\message\message(); $eventdata->courseid = SITEID; $eventdata->component = 'tool_messageinbound'; $eventdata->name = 'messageprocessingsuccess'; $eventdata->userfrom = $userfrom; $eventdata->userto = $USER; $eventdata->subject = self::get_reply_subject($this->currentmessagedata->envelope->subject); $eventdata->fullmessage = $plainmessage; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $htmlmessage; $eventdata->smallmessage = $eventdata->fullmessage; $eventdata->notification = 1; if (message_send($eventdata)) { mtrace("---> Success notification sent to {$USER->email}."); } else { mtrace("---> Unable to send success notification."); } return true; }
[ "private", "function", "inform_user_of_success", "(", "\\", "stdClass", "$", "messagedata", ",", "$", "handlerresult", ")", "{", "global", "$", "USER", ";", "// Check whether the handler has a success notification.", "$", "handler", "=", "$", "this", "->", "addressmanager", "->", "get_handler", "(", ")", ";", "$", "message", "=", "$", "handler", "->", "get_success_message", "(", "$", "messagedata", ",", "$", "handlerresult", ")", ";", "if", "(", "!", "$", "message", ")", "{", "mtrace", "(", "\"---> Handler has not defined a success notification e-mail.\"", ")", ";", "return", "false", ";", "}", "// Wrap the message in the notification wrapper.", "$", "messageparams", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "messageparams", "->", "html", "=", "$", "message", "->", "html", ";", "$", "messageparams", "->", "plain", "=", "$", "message", "->", "plain", ";", "$", "messagepreferencesurl", "=", "new", "\\", "moodle_url", "(", "\"/message/notificationpreferences.php\"", ",", "array", "(", "'id'", "=>", "$", "USER", "->", "id", ")", ")", ";", "$", "messageparams", "->", "messagepreferencesurl", "=", "$", "messagepreferencesurl", "->", "out", "(", ")", ";", "$", "htmlmessage", "=", "get_string", "(", "'messageprocessingsuccesshtml'", ",", "'tool_messageinbound'", ",", "$", "messageparams", ")", ";", "$", "plainmessage", "=", "get_string", "(", "'messageprocessingsuccess'", ",", "'tool_messageinbound'", ",", "$", "messageparams", ")", ";", "// The message will be sent from the intended user.", "$", "userfrom", "=", "clone", "$", "USER", ";", "$", "userfrom", "->", "customheaders", "=", "array", "(", ")", ";", "if", "(", "$", "messageid", "=", "$", "this", "->", "currentmessagedata", "->", "messageid", ")", "{", "// Adding the In-Reply-To header ensures that it is seen as a reply and threading is maintained.", "$", "userfrom", "->", "customheaders", "[", "]", "=", "'In-Reply-To: '", ".", "$", "messageid", ";", "}", "$", "messagedata", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "messagedata", "->", "subject", "=", "$", "this", "->", "currentmessagedata", "->", "envelope", "->", "subject", ";", "$", "eventdata", "=", "new", "\\", "core", "\\", "message", "\\", "message", "(", ")", ";", "$", "eventdata", "->", "courseid", "=", "SITEID", ";", "$", "eventdata", "->", "component", "=", "'tool_messageinbound'", ";", "$", "eventdata", "->", "name", "=", "'messageprocessingsuccess'", ";", "$", "eventdata", "->", "userfrom", "=", "$", "userfrom", ";", "$", "eventdata", "->", "userto", "=", "$", "USER", ";", "$", "eventdata", "->", "subject", "=", "self", "::", "get_reply_subject", "(", "$", "this", "->", "currentmessagedata", "->", "envelope", "->", "subject", ")", ";", "$", "eventdata", "->", "fullmessage", "=", "$", "plainmessage", ";", "$", "eventdata", "->", "fullmessageformat", "=", "FORMAT_PLAIN", ";", "$", "eventdata", "->", "fullmessagehtml", "=", "$", "htmlmessage", ";", "$", "eventdata", "->", "smallmessage", "=", "$", "eventdata", "->", "fullmessage", ";", "$", "eventdata", "->", "notification", "=", "1", ";", "if", "(", "message_send", "(", "$", "eventdata", ")", ")", "{", "mtrace", "(", "\"---> Success notification sent to {$USER->email}.\"", ")", ";", "}", "else", "{", "mtrace", "(", "\"---> Unable to send success notification.\"", ")", ";", "}", "return", "true", ";", "}" ]
Inform the identified sender that message processing was successful. @param \stdClass $messagedata The data for the current message being processed. @param mixed $handlerresult The result returned by the handler. @return bool
[ "Inform", "the", "identified", "sender", "that", "message", "processing", "was", "successful", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L993-L1045
219,332
moodle/moodle
admin/tool/messageinbound/classes/manager.php
manager.get_reply_subject
private function get_reply_subject($subject) { $prefix = get_string('replysubjectprefix', 'tool_messageinbound'); if (!(substr($subject, 0, strlen($prefix)) == $prefix)) { $subject = $prefix . ' ' . $subject; } return $subject; }
php
private function get_reply_subject($subject) { $prefix = get_string('replysubjectprefix', 'tool_messageinbound'); if (!(substr($subject, 0, strlen($prefix)) == $prefix)) { $subject = $prefix . ' ' . $subject; } return $subject; }
[ "private", "function", "get_reply_subject", "(", "$", "subject", ")", "{", "$", "prefix", "=", "get_string", "(", "'replysubjectprefix'", ",", "'tool_messageinbound'", ")", ";", "if", "(", "!", "(", "substr", "(", "$", "subject", ",", "0", ",", "strlen", "(", "$", "prefix", ")", ")", "==", "$", "prefix", ")", ")", "{", "$", "subject", "=", "$", "prefix", ".", "' '", ".", "$", "subject", ";", "}", "return", "$", "subject", ";", "}" ]
Return a formatted subject line for replies. @param string $subject The subject string @return string The formatted reply subject
[ "Return", "a", "formatted", "subject", "line", "for", "replies", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/messageinbound/classes/manager.php#L1053-L1060
219,333
moodle/moodle
question/classes/bank/tags_action_column.php
tags_action_column.display_content
protected function display_content($question, $rowclasses) { if (\core_tag_tag::is_enabled('core_question', 'question') && question_has_capability_on($question, 'view')) { $cantag = question_has_capability_on($question, 'tag'); $qbank = $this->qbank; $url = new \moodle_url($qbank->edit_question_url($question->id)); $editingcontext = $qbank->get_most_specific_context(); $this->print_tag_icon($question->id, $url, $cantag, $editingcontext->id); } }
php
protected function display_content($question, $rowclasses) { if (\core_tag_tag::is_enabled('core_question', 'question') && question_has_capability_on($question, 'view')) { $cantag = question_has_capability_on($question, 'tag'); $qbank = $this->qbank; $url = new \moodle_url($qbank->edit_question_url($question->id)); $editingcontext = $qbank->get_most_specific_context(); $this->print_tag_icon($question->id, $url, $cantag, $editingcontext->id); } }
[ "protected", "function", "display_content", "(", "$", "question", ",", "$", "rowclasses", ")", "{", "if", "(", "\\", "core_tag_tag", "::", "is_enabled", "(", "'core_question'", ",", "'question'", ")", "&&", "question_has_capability_on", "(", "$", "question", ",", "'view'", ")", ")", "{", "$", "cantag", "=", "question_has_capability_on", "(", "$", "question", ",", "'tag'", ")", ";", "$", "qbank", "=", "$", "this", "->", "qbank", ";", "$", "url", "=", "new", "\\", "moodle_url", "(", "$", "qbank", "->", "edit_question_url", "(", "$", "question", "->", "id", ")", ")", ";", "$", "editingcontext", "=", "$", "qbank", "->", "get_most_specific_context", "(", ")", ";", "$", "this", "->", "print_tag_icon", "(", "$", "question", "->", "id", ",", "$", "url", ",", "$", "cantag", ",", "$", "editingcontext", "->", "id", ")", ";", "}", "}" ]
Display tags column content. @param object $question The question database record. @param string $rowclasses
[ "Display", "tags", "column", "content", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/bank/tags_action_column.php#L52-L63
219,334
moodle/moodle
question/classes/bank/tags_action_column.php
tags_action_column.print_tag_icon
protected function print_tag_icon($id, \moodle_url $url, $cantag, $contextid) { global $OUTPUT; $params = [ 'data-action' => 'edittags', 'data-cantag' => $cantag, 'data-contextid' => $contextid, 'data-questionid' => $id ]; echo \html_writer::link($url, $OUTPUT->pix_icon('t/tags', get_string('managetags', 'tag')), $params); }
php
protected function print_tag_icon($id, \moodle_url $url, $cantag, $contextid) { global $OUTPUT; $params = [ 'data-action' => 'edittags', 'data-cantag' => $cantag, 'data-contextid' => $contextid, 'data-questionid' => $id ]; echo \html_writer::link($url, $OUTPUT->pix_icon('t/tags', get_string('managetags', 'tag')), $params); }
[ "protected", "function", "print_tag_icon", "(", "$", "id", ",", "\\", "moodle_url", "$", "url", ",", "$", "cantag", ",", "$", "contextid", ")", "{", "global", "$", "OUTPUT", ";", "$", "params", "=", "[", "'data-action'", "=>", "'edittags'", ",", "'data-cantag'", "=>", "$", "cantag", ",", "'data-contextid'", "=>", "$", "contextid", ",", "'data-questionid'", "=>", "$", "id", "]", ";", "echo", "\\", "html_writer", "::", "link", "(", "$", "url", ",", "$", "OUTPUT", "->", "pix_icon", "(", "'t/tags'", ",", "get_string", "(", "'managetags'", ",", "'tag'", ")", ")", ",", "$", "params", ")", ";", "}" ]
Build and print the tags icon. @param int $id The question ID. @param \moodle_url $url Editing question url. @param bool $cantag Whether the user can tag questions or not. @param int $contextid Question category context ID.
[ "Build", "and", "print", "the", "tags", "icon", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/bank/tags_action_column.php#L73-L84
219,335
moodle/moodle
mod/workshop/form/rubric/backup/moodle2/restore_workshopform_rubric_subplugin.class.php
restore_workshopform_rubric_subplugin.process_workshopform_rubric_config
public function process_workshopform_rubric_config($data) { global $DB; $data = (object)$data; $data->workshopid = $this->get_new_parentid('workshop'); $DB->insert_record('workshopform_rubric_config', $data); }
php
public function process_workshopform_rubric_config($data) { global $DB; $data = (object)$data; $data->workshopid = $this->get_new_parentid('workshop'); $DB->insert_record('workshopform_rubric_config', $data); }
[ "public", "function", "process_workshopform_rubric_config", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "data", "->", "workshopid", "=", "$", "this", "->", "get_new_parentid", "(", "'workshop'", ")", ";", "$", "DB", "->", "insert_record", "(", "'workshopform_rubric_config'", ",", "$", "data", ")", ";", "}" ]
Processes the workshopform_rubric_map element
[ "Processes", "the", "workshopform_rubric_map", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/rubric/backup/moodle2/restore_workshopform_rubric_subplugin.class.php#L107-L113
219,336
moodle/moodle
mod/workshop/form/rubric/backup/moodle2/restore_workshopform_rubric_subplugin.class.php
restore_workshopform_rubric_subplugin.process_workshopform_rubric_dimension
public function process_workshopform_rubric_dimension($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->workshopid = $this->get_new_parentid('workshop'); $newitemid = $DB->insert_record('workshopform_rubric', $data); $this->set_mapping($this->get_namefor('dimension'), $oldid, $newitemid, true); // Process files for this workshopform_rubric->id only $this->add_related_files('workshopform_rubric', 'description', $this->get_namefor('dimension'), null, $oldid); }
php
public function process_workshopform_rubric_dimension($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->workshopid = $this->get_new_parentid('workshop'); $newitemid = $DB->insert_record('workshopform_rubric', $data); $this->set_mapping($this->get_namefor('dimension'), $oldid, $newitemid, true); // Process files for this workshopform_rubric->id only $this->add_related_files('workshopform_rubric', 'description', $this->get_namefor('dimension'), null, $oldid); }
[ "public", "function", "process_workshopform_rubric_dimension", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "oldid", "=", "$", "data", "->", "id", ";", "$", "data", "->", "workshopid", "=", "$", "this", "->", "get_new_parentid", "(", "'workshop'", ")", ";", "$", "newitemid", "=", "$", "DB", "->", "insert_record", "(", "'workshopform_rubric'", ",", "$", "data", ")", ";", "$", "this", "->", "set_mapping", "(", "$", "this", "->", "get_namefor", "(", "'dimension'", ")", ",", "$", "oldid", ",", "$", "newitemid", ",", "true", ")", ";", "// Process files for this workshopform_rubric->id only", "$", "this", "->", "add_related_files", "(", "'workshopform_rubric'", ",", "'description'", ",", "$", "this", "->", "get_namefor", "(", "'dimension'", ")", ",", "null", ",", "$", "oldid", ")", ";", "}" ]
Processes the workshopform_rubric_dimension element
[ "Processes", "the", "workshopform_rubric_dimension", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/rubric/backup/moodle2/restore_workshopform_rubric_subplugin.class.php#L118-L131
219,337
moodle/moodle
mod/workshop/form/rubric/backup/moodle2/restore_workshopform_rubric_subplugin.class.php
restore_workshopform_rubric_subplugin.process_workshopform_rubric_level
public function process_workshopform_rubric_level($data) { global $DB; $data = (object)$data; $data->dimensionid = $this->get_new_parentid($this->get_namefor('dimension')); $DB->insert_record('workshopform_rubric_levels', $data); }
php
public function process_workshopform_rubric_level($data) { global $DB; $data = (object)$data; $data->dimensionid = $this->get_new_parentid($this->get_namefor('dimension')); $DB->insert_record('workshopform_rubric_levels', $data); }
[ "public", "function", "process_workshopform_rubric_level", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "data", "->", "dimensionid", "=", "$", "this", "->", "get_new_parentid", "(", "$", "this", "->", "get_namefor", "(", "'dimension'", ")", ")", ";", "$", "DB", "->", "insert_record", "(", "'workshopform_rubric_levels'", ",", "$", "data", ")", ";", "}" ]
Processes the workshopform_rubric_level element
[ "Processes", "the", "workshopform_rubric_level", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/rubric/backup/moodle2/restore_workshopform_rubric_subplugin.class.php#L136-L142
219,338
moodle/moodle
lib/google/src/Google/IO/Exception.php
Google_IO_Exception.allowedRetries
public function allowedRetries() { if (isset($this->retryMap[$this->code])) { return $this->retryMap[$this->code]; } return 0; }
php
public function allowedRetries() { if (isset($this->retryMap[$this->code])) { return $this->retryMap[$this->code]; } return 0; }
[ "public", "function", "allowedRetries", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "retryMap", "[", "$", "this", "->", "code", "]", ")", ")", "{", "return", "$", "this", "->", "retryMap", "[", "$", "this", "->", "code", "]", ";", "}", "return", "0", ";", "}" ]
Gets the number of times the associated task can be retried. NOTE: -1 is returned if the task can be retried indefinitely @return integer
[ "Gets", "the", "number", "of", "times", "the", "associated", "task", "can", "be", "retried", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/IO/Exception.php#L61-L68
219,339
moodle/moodle
lib/htmlpurifier/HTMLPurifier/HTMLModule/Tidy.php
HTMLPurifier_HTMLModule_Tidy.getFixesForLevel
public function getFixesForLevel($level) { if ($level == $this->levels[0]) { return array(); } $activated_levels = array(); for ($i = 1, $c = count($this->levels); $i < $c; $i++) { $activated_levels[] = $this->levels[$i]; if ($this->levels[$i] == $level) { break; } } if ($i == $c) { trigger_error( 'Tidy level ' . htmlspecialchars($level) . ' not recognized', E_USER_WARNING ); return array(); } $ret = array(); foreach ($activated_levels as $level) { foreach ($this->fixesForLevel[$level] as $fix) { $ret[$fix] = true; } } return $ret; }
php
public function getFixesForLevel($level) { if ($level == $this->levels[0]) { return array(); } $activated_levels = array(); for ($i = 1, $c = count($this->levels); $i < $c; $i++) { $activated_levels[] = $this->levels[$i]; if ($this->levels[$i] == $level) { break; } } if ($i == $c) { trigger_error( 'Tidy level ' . htmlspecialchars($level) . ' not recognized', E_USER_WARNING ); return array(); } $ret = array(); foreach ($activated_levels as $level) { foreach ($this->fixesForLevel[$level] as $fix) { $ret[$fix] = true; } } return $ret; }
[ "public", "function", "getFixesForLevel", "(", "$", "level", ")", "{", "if", "(", "$", "level", "==", "$", "this", "->", "levels", "[", "0", "]", ")", "{", "return", "array", "(", ")", ";", "}", "$", "activated_levels", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "1", ",", "$", "c", "=", "count", "(", "$", "this", "->", "levels", ")", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "$", "activated_levels", "[", "]", "=", "$", "this", "->", "levels", "[", "$", "i", "]", ";", "if", "(", "$", "this", "->", "levels", "[", "$", "i", "]", "==", "$", "level", ")", "{", "break", ";", "}", "}", "if", "(", "$", "i", "==", "$", "c", ")", "{", "trigger_error", "(", "'Tidy level '", ".", "htmlspecialchars", "(", "$", "level", ")", ".", "' not recognized'", ",", "E_USER_WARNING", ")", ";", "return", "array", "(", ")", ";", "}", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "activated_levels", "as", "$", "level", ")", "{", "foreach", "(", "$", "this", "->", "fixesForLevel", "[", "$", "level", "]", "as", "$", "fix", ")", "{", "$", "ret", "[", "$", "fix", "]", "=", "true", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Retrieves all fixes per a level, returning fixes for that specific level as well as all levels below it. @param string $level level identifier, see $levels for valid values @return array Lookup up table of fixes
[ "Retrieves", "all", "fixes", "per", "a", "level", "returning", "fixes", "for", "that", "specific", "level", "as", "well", "as", "all", "levels", "below", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/HTMLModule/Tidy.php#L75-L101
219,340
moodle/moodle
lib/simplepie/library/SimplePie/Decode/HTML/Entities.php
SimplePie_Decode_HTML_Entities.consume
public function consume() { if (isset($this->data[$this->position])) { $this->consumed .= $this->data[$this->position]; return $this->data[$this->position++]; } else { return false; } }
php
public function consume() { if (isset($this->data[$this->position])) { $this->consumed .= $this->data[$this->position]; return $this->data[$this->position++]; } else { return false; } }
[ "public", "function", "consume", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "$", "this", "->", "position", "]", ")", ")", "{", "$", "this", "->", "consumed", ".=", "$", "this", "->", "data", "[", "$", "this", "->", "position", "]", ";", "return", "$", "this", "->", "data", "[", "$", "this", "->", "position", "++", "]", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Consume the next byte @access private @return mixed The next byte, or false, if there is no more data
[ "Consume", "the", "next", "byte" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Decode/HTML/Entities.php#L113-L124
219,341
moodle/moodle
lib/simplepie/library/SimplePie/Decode/HTML/Entities.php
SimplePie_Decode_HTML_Entities.consume_range
public function consume_range($chars) { if ($len = strspn($this->data, $chars, $this->position)) { $data = substr($this->data, $this->position, $len); $this->consumed .= $data; $this->position += $len; return $data; } else { return false; } }
php
public function consume_range($chars) { if ($len = strspn($this->data, $chars, $this->position)) { $data = substr($this->data, $this->position, $len); $this->consumed .= $data; $this->position += $len; return $data; } else { return false; } }
[ "public", "function", "consume_range", "(", "$", "chars", ")", "{", "if", "(", "$", "len", "=", "strspn", "(", "$", "this", "->", "data", ",", "$", "chars", ",", "$", "this", "->", "position", ")", ")", "{", "$", "data", "=", "substr", "(", "$", "this", "->", "data", ",", "$", "this", "->", "position", ",", "$", "len", ")", ";", "$", "this", "->", "consumed", ".=", "$", "data", ";", "$", "this", "->", "position", "+=", "$", "len", ";", "return", "$", "data", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Consume a range of characters @access private @param string $chars Characters to consume @return mixed A series of characters that match the range, or false
[ "Consume", "a", "range", "of", "characters" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Decode/HTML/Entities.php#L133-L146
219,342
moodle/moodle
analytics/classes/analysis.php
analysis.run
public function run() { $options = $this->analyser->get_options(); // Time limit control. $modeltimelimit = intval(get_config('analytics', 'modeltimelimit')); if ($this->includetarget) { $action = 'training'; } else { $action = 'prediction'; } $analysables = $this->analyser->get_analysables_iterator($action); $processedanalysables = $this->get_processed_analysables(); $inittime = microtime(true); foreach ($analysables as $analysable) { $processed = false; if (!$analysable) { continue; } $analysableresults = $this->process_analysable($analysable); if ($analysableresults) { $processed = $this->result->add_analysable_results($analysableresults); if (!$processed) { $errors = array(); foreach ($analysableresults as $timesplittingid => $result) { $str = ''; if (count($analysableresults) > 1) { $str .= $timesplittingid . ': '; } $str .= $result->message; $errors[] = $str; } $a = new \stdClass(); $a->analysableid = $analysable->get_name(); $a->errors = implode(', ', $errors); $this->analyser->add_log(get_string('analysablenotused', 'analytics', $a)); } } if (!$options['evaluation']) { if (empty($processedanalysables[$analysable->get_id()]) || $this->analyser->get_target()->always_update_analysis_time() || $processed) { // We store the list of processed analysables even if the target does not always_update_analysis_time(), // what always_update_analysis_time controls is the update of the data. $this->update_analysable_analysed_time($processedanalysables, $analysable->get_id()); } // Apply time limit. $timespent = microtime(true) - $inittime; if ($modeltimelimit <= $timespent) { break; } } } }
php
public function run() { $options = $this->analyser->get_options(); // Time limit control. $modeltimelimit = intval(get_config('analytics', 'modeltimelimit')); if ($this->includetarget) { $action = 'training'; } else { $action = 'prediction'; } $analysables = $this->analyser->get_analysables_iterator($action); $processedanalysables = $this->get_processed_analysables(); $inittime = microtime(true); foreach ($analysables as $analysable) { $processed = false; if (!$analysable) { continue; } $analysableresults = $this->process_analysable($analysable); if ($analysableresults) { $processed = $this->result->add_analysable_results($analysableresults); if (!$processed) { $errors = array(); foreach ($analysableresults as $timesplittingid => $result) { $str = ''; if (count($analysableresults) > 1) { $str .= $timesplittingid . ': '; } $str .= $result->message; $errors[] = $str; } $a = new \stdClass(); $a->analysableid = $analysable->get_name(); $a->errors = implode(', ', $errors); $this->analyser->add_log(get_string('analysablenotused', 'analytics', $a)); } } if (!$options['evaluation']) { if (empty($processedanalysables[$analysable->get_id()]) || $this->analyser->get_target()->always_update_analysis_time() || $processed) { // We store the list of processed analysables even if the target does not always_update_analysis_time(), // what always_update_analysis_time controls is the update of the data. $this->update_analysable_analysed_time($processedanalysables, $analysable->get_id()); } // Apply time limit. $timespent = microtime(true) - $inittime; if ($modeltimelimit <= $timespent) { break; } } } }
[ "public", "function", "run", "(", ")", "{", "$", "options", "=", "$", "this", "->", "analyser", "->", "get_options", "(", ")", ";", "// Time limit control.", "$", "modeltimelimit", "=", "intval", "(", "get_config", "(", "'analytics'", ",", "'modeltimelimit'", ")", ")", ";", "if", "(", "$", "this", "->", "includetarget", ")", "{", "$", "action", "=", "'training'", ";", "}", "else", "{", "$", "action", "=", "'prediction'", ";", "}", "$", "analysables", "=", "$", "this", "->", "analyser", "->", "get_analysables_iterator", "(", "$", "action", ")", ";", "$", "processedanalysables", "=", "$", "this", "->", "get_processed_analysables", "(", ")", ";", "$", "inittime", "=", "microtime", "(", "true", ")", ";", "foreach", "(", "$", "analysables", "as", "$", "analysable", ")", "{", "$", "processed", "=", "false", ";", "if", "(", "!", "$", "analysable", ")", "{", "continue", ";", "}", "$", "analysableresults", "=", "$", "this", "->", "process_analysable", "(", "$", "analysable", ")", ";", "if", "(", "$", "analysableresults", ")", "{", "$", "processed", "=", "$", "this", "->", "result", "->", "add_analysable_results", "(", "$", "analysableresults", ")", ";", "if", "(", "!", "$", "processed", ")", "{", "$", "errors", "=", "array", "(", ")", ";", "foreach", "(", "$", "analysableresults", "as", "$", "timesplittingid", "=>", "$", "result", ")", "{", "$", "str", "=", "''", ";", "if", "(", "count", "(", "$", "analysableresults", ")", ">", "1", ")", "{", "$", "str", ".=", "$", "timesplittingid", ".", "': '", ";", "}", "$", "str", ".=", "$", "result", "->", "message", ";", "$", "errors", "[", "]", "=", "$", "str", ";", "}", "$", "a", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "a", "->", "analysableid", "=", "$", "analysable", "->", "get_name", "(", ")", ";", "$", "a", "->", "errors", "=", "implode", "(", "', '", ",", "$", "errors", ")", ";", "$", "this", "->", "analyser", "->", "add_log", "(", "get_string", "(", "'analysablenotused'", ",", "'analytics'", ",", "$", "a", ")", ")", ";", "}", "}", "if", "(", "!", "$", "options", "[", "'evaluation'", "]", ")", "{", "if", "(", "empty", "(", "$", "processedanalysables", "[", "$", "analysable", "->", "get_id", "(", ")", "]", ")", "||", "$", "this", "->", "analyser", "->", "get_target", "(", ")", "->", "always_update_analysis_time", "(", ")", "||", "$", "processed", ")", "{", "// We store the list of processed analysables even if the target does not always_update_analysis_time(),", "// what always_update_analysis_time controls is the update of the data.", "$", "this", "->", "update_analysable_analysed_time", "(", "$", "processedanalysables", ",", "$", "analysable", "->", "get_id", "(", ")", ")", ";", "}", "// Apply time limit.", "$", "timespent", "=", "microtime", "(", "true", ")", "-", "$", "inittime", ";", "if", "(", "$", "modeltimelimit", "<=", "$", "timespent", ")", "{", "break", ";", "}", "}", "}", "}" ]
Runs the analysis. @return null
[ "Runs", "the", "analysis", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L80-L141
219,343
moodle/moodle
analytics/classes/analysis.php
analysis.get_processed_analysables
protected function get_processed_analysables(): array { global $DB; $params = array('modelid' => $this->analyser->get_modelid()); $params['action'] = ($this->includetarget) ? 'training' : 'prediction'; $select = 'modelid = :modelid and action = :action'; // Weird select fields ordering for performance (analysableid key matching, analysableid is also unique by modelid). return $DB->get_records_select('analytics_used_analysables', $select, $params, 'timeanalysed DESC', 'analysableid, modelid, action, firstanalysis, timeanalysed, id AS primarykey'); }
php
protected function get_processed_analysables(): array { global $DB; $params = array('modelid' => $this->analyser->get_modelid()); $params['action'] = ($this->includetarget) ? 'training' : 'prediction'; $select = 'modelid = :modelid and action = :action'; // Weird select fields ordering for performance (analysableid key matching, analysableid is also unique by modelid). return $DB->get_records_select('analytics_used_analysables', $select, $params, 'timeanalysed DESC', 'analysableid, modelid, action, firstanalysis, timeanalysed, id AS primarykey'); }
[ "protected", "function", "get_processed_analysables", "(", ")", ":", "array", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", "'modelid'", "=>", "$", "this", "->", "analyser", "->", "get_modelid", "(", ")", ")", ";", "$", "params", "[", "'action'", "]", "=", "(", "$", "this", "->", "includetarget", ")", "?", "'training'", ":", "'prediction'", ";", "$", "select", "=", "'modelid = :modelid and action = :action'", ";", "// Weird select fields ordering for performance (analysableid key matching, analysableid is also unique by modelid).", "return", "$", "DB", "->", "get_records_select", "(", "'analytics_used_analysables'", ",", "$", "select", ",", "$", "params", ",", "'timeanalysed DESC'", ",", "'analysableid, modelid, action, firstanalysis, timeanalysed, id AS primarykey'", ")", ";", "}" ]
Get analysables that have been already processed. @return \stdClass[]
[ "Get", "analysables", "that", "have", "been", "already", "processed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L148-L158
219,344
moodle/moodle
analytics/classes/analysis.php
analysis.process_analysable
public function process_analysable(\core_analytics\analysable $analysable): array { // Target instances scope is per-analysable (it can't be lower as calculations run once per // analysable, not time splitting method nor time range). $target = call_user_func(array($this->analyser->get_target(), 'instance')); // We need to check that the analysable is valid for the target even if we don't include targets // as we still need to discard invalid analysables for the target. $isvalidresult = $target->is_valid_analysable($analysable, $this->includetarget); if ($isvalidresult !== true) { $a = new \stdClass(); $a->analysableid = $analysable->get_name(); $a->result = $isvalidresult; $this->analyser->add_log(get_string('analysablenotvalidfortarget', 'analytics', $a)); return array(); } // Process all provided time splitting methods. $results = array(); foreach ($this->analyser->get_timesplittings() as $timesplitting) { $cachedresult = $this->result->retrieve_cached_result($timesplitting, $analysable); if ($cachedresult) { $result = new \stdClass(); $result->result = $cachedresult; $results[$timesplitting->get_id()] = $result; continue; } $results[$timesplitting->get_id()] = $this->process_time_splitting($timesplitting, $analysable, $target); } return $results; }
php
public function process_analysable(\core_analytics\analysable $analysable): array { // Target instances scope is per-analysable (it can't be lower as calculations run once per // analysable, not time splitting method nor time range). $target = call_user_func(array($this->analyser->get_target(), 'instance')); // We need to check that the analysable is valid for the target even if we don't include targets // as we still need to discard invalid analysables for the target. $isvalidresult = $target->is_valid_analysable($analysable, $this->includetarget); if ($isvalidresult !== true) { $a = new \stdClass(); $a->analysableid = $analysable->get_name(); $a->result = $isvalidresult; $this->analyser->add_log(get_string('analysablenotvalidfortarget', 'analytics', $a)); return array(); } // Process all provided time splitting methods. $results = array(); foreach ($this->analyser->get_timesplittings() as $timesplitting) { $cachedresult = $this->result->retrieve_cached_result($timesplitting, $analysable); if ($cachedresult) { $result = new \stdClass(); $result->result = $cachedresult; $results[$timesplitting->get_id()] = $result; continue; } $results[$timesplitting->get_id()] = $this->process_time_splitting($timesplitting, $analysable, $target); } return $results; }
[ "public", "function", "process_analysable", "(", "\\", "core_analytics", "\\", "analysable", "$", "analysable", ")", ":", "array", "{", "// Target instances scope is per-analysable (it can't be lower as calculations run once per", "// analysable, not time splitting method nor time range).", "$", "target", "=", "call_user_func", "(", "array", "(", "$", "this", "->", "analyser", "->", "get_target", "(", ")", ",", "'instance'", ")", ")", ";", "// We need to check that the analysable is valid for the target even if we don't include targets", "// as we still need to discard invalid analysables for the target.", "$", "isvalidresult", "=", "$", "target", "->", "is_valid_analysable", "(", "$", "analysable", ",", "$", "this", "->", "includetarget", ")", ";", "if", "(", "$", "isvalidresult", "!==", "true", ")", "{", "$", "a", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "a", "->", "analysableid", "=", "$", "analysable", "->", "get_name", "(", ")", ";", "$", "a", "->", "result", "=", "$", "isvalidresult", ";", "$", "this", "->", "analyser", "->", "add_log", "(", "get_string", "(", "'analysablenotvalidfortarget'", ",", "'analytics'", ",", "$", "a", ")", ")", ";", "return", "array", "(", ")", ";", "}", "// Process all provided time splitting methods.", "$", "results", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "analyser", "->", "get_timesplittings", "(", ")", "as", "$", "timesplitting", ")", "{", "$", "cachedresult", "=", "$", "this", "->", "result", "->", "retrieve_cached_result", "(", "$", "timesplitting", ",", "$", "analysable", ")", ";", "if", "(", "$", "cachedresult", ")", "{", "$", "result", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "result", "->", "result", "=", "$", "cachedresult", ";", "$", "results", "[", "$", "timesplitting", "->", "get_id", "(", ")", "]", "=", "$", "result", ";", "continue", ";", "}", "$", "results", "[", "$", "timesplitting", "->", "get_id", "(", ")", "]", "=", "$", "this", "->", "process_time_splitting", "(", "$", "timesplitting", ",", "$", "analysable", ",", "$", "target", ")", ";", "}", "return", "$", "results", ";", "}" ]
Processes an analysable This method returns the general analysable status, an array of files by time splitting method and an error message if there is any problem. @param \core_analytics\analysable $analysable @return \stdClass[] Results objects by time splitting method
[ "Processes", "an", "analysable" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L169-L202
219,345
moodle/moodle
analytics/classes/analysis.php
analysis.calculate
public function calculate(\core_analytics\local\time_splitting\base $timesplitting, array &$sampleids, array $ranges, \core_analytics\local\target\base $target): ?array { $calculatedtarget = null; if ($this->includetarget) { // We first calculate the target because analysable data may still be invalid or none // of the analysable samples may be valid. $calculatedtarget = $target->calculate($sampleids, $timesplitting->get_analysable()); // We remove samples we can not calculate their target. $sampleids = array_filter($sampleids, function($sampleid) use ($calculatedtarget) { if (is_null($calculatedtarget[$sampleid])) { return false; } return true; }); } // No need to continue calculating if the target couldn't be calculated for any sample. if (empty($sampleids)) { return null; } $dataset = $this->calculate_indicators($timesplitting, $sampleids, $ranges); if (empty($dataset)) { return null; } // Now that we have the indicators in place we can add the time range indicators (and target if provided) to each of them. $this->fill_dataset($timesplitting, $dataset, $calculatedtarget); $this->add_context_metadata($timesplitting, $dataset, $target); if (!PHPUNIT_TEST && CLI_SCRIPT) { echo PHP_EOL; } return $dataset; }
php
public function calculate(\core_analytics\local\time_splitting\base $timesplitting, array &$sampleids, array $ranges, \core_analytics\local\target\base $target): ?array { $calculatedtarget = null; if ($this->includetarget) { // We first calculate the target because analysable data may still be invalid or none // of the analysable samples may be valid. $calculatedtarget = $target->calculate($sampleids, $timesplitting->get_analysable()); // We remove samples we can not calculate their target. $sampleids = array_filter($sampleids, function($sampleid) use ($calculatedtarget) { if (is_null($calculatedtarget[$sampleid])) { return false; } return true; }); } // No need to continue calculating if the target couldn't be calculated for any sample. if (empty($sampleids)) { return null; } $dataset = $this->calculate_indicators($timesplitting, $sampleids, $ranges); if (empty($dataset)) { return null; } // Now that we have the indicators in place we can add the time range indicators (and target if provided) to each of them. $this->fill_dataset($timesplitting, $dataset, $calculatedtarget); $this->add_context_metadata($timesplitting, $dataset, $target); if (!PHPUNIT_TEST && CLI_SCRIPT) { echo PHP_EOL; } return $dataset; }
[ "public", "function", "calculate", "(", "\\", "core_analytics", "\\", "local", "\\", "time_splitting", "\\", "base", "$", "timesplitting", ",", "array", "&", "$", "sampleids", ",", "array", "$", "ranges", ",", "\\", "core_analytics", "\\", "local", "\\", "target", "\\", "base", "$", "target", ")", ":", "?", "array", "{", "$", "calculatedtarget", "=", "null", ";", "if", "(", "$", "this", "->", "includetarget", ")", "{", "// We first calculate the target because analysable data may still be invalid or none", "// of the analysable samples may be valid.", "$", "calculatedtarget", "=", "$", "target", "->", "calculate", "(", "$", "sampleids", ",", "$", "timesplitting", "->", "get_analysable", "(", ")", ")", ";", "// We remove samples we can not calculate their target.", "$", "sampleids", "=", "array_filter", "(", "$", "sampleids", ",", "function", "(", "$", "sampleid", ")", "use", "(", "$", "calculatedtarget", ")", "{", "if", "(", "is_null", "(", "$", "calculatedtarget", "[", "$", "sampleid", "]", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}", ")", ";", "}", "// No need to continue calculating if the target couldn't be calculated for any sample.", "if", "(", "empty", "(", "$", "sampleids", ")", ")", "{", "return", "null", ";", "}", "$", "dataset", "=", "$", "this", "->", "calculate_indicators", "(", "$", "timesplitting", ",", "$", "sampleids", ",", "$", "ranges", ")", ";", "if", "(", "empty", "(", "$", "dataset", ")", ")", "{", "return", "null", ";", "}", "// Now that we have the indicators in place we can add the time range indicators (and target if provided) to each of them.", "$", "this", "->", "fill_dataset", "(", "$", "timesplitting", ",", "$", "dataset", ",", "$", "calculatedtarget", ")", ";", "$", "this", "->", "add_context_metadata", "(", "$", "timesplitting", ",", "$", "dataset", ",", "$", "target", ")", ";", "if", "(", "!", "PHPUNIT_TEST", "&&", "CLI_SCRIPT", ")", "{", "echo", "PHP_EOL", ";", "}", "return", "$", "dataset", ";", "}" ]
Calculates indicators and targets. @param \core_analytics\local\time_splitting\base $timesplitting @param array $sampleids @param array $ranges @param \core_analytics\local\target\base $target @return array|null
[ "Calculates", "indicators", "and", "targets", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L383-L422
219,346
moodle/moodle
analytics/classes/analysis.php
analysis.fill_dataset
protected function fill_dataset(\core_analytics\local\time_splitting\base $timesplitting, array &$dataset, ?array $calculatedtarget = null) { $nranges = count($timesplitting->get_distinct_ranges()); foreach ($dataset as $uniquesampleid => $unmodified) { list($analysersampleid, $rangeindex) = $timesplitting->infer_sample_info($uniquesampleid); // No need to add range features if this time splitting method only defines one time range. if ($nranges > 1) { // 1 column for each range. $timeindicators = array_fill(0, $nranges, 0); $timeindicators[$rangeindex] = 1; $dataset[$uniquesampleid] = array_merge($timeindicators, $dataset[$uniquesampleid]); } if ($calculatedtarget) { // Add this sampleid's calculated target and the end. $dataset[$uniquesampleid][] = $calculatedtarget[$analysersampleid]; } else { // Add this sampleid, it will be used to identify the prediction that comes back from // the predictions processor. array_unshift($dataset[$uniquesampleid], $uniquesampleid); } } }
php
protected function fill_dataset(\core_analytics\local\time_splitting\base $timesplitting, array &$dataset, ?array $calculatedtarget = null) { $nranges = count($timesplitting->get_distinct_ranges()); foreach ($dataset as $uniquesampleid => $unmodified) { list($analysersampleid, $rangeindex) = $timesplitting->infer_sample_info($uniquesampleid); // No need to add range features if this time splitting method only defines one time range. if ($nranges > 1) { // 1 column for each range. $timeindicators = array_fill(0, $nranges, 0); $timeindicators[$rangeindex] = 1; $dataset[$uniquesampleid] = array_merge($timeindicators, $dataset[$uniquesampleid]); } if ($calculatedtarget) { // Add this sampleid's calculated target and the end. $dataset[$uniquesampleid][] = $calculatedtarget[$analysersampleid]; } else { // Add this sampleid, it will be used to identify the prediction that comes back from // the predictions processor. array_unshift($dataset[$uniquesampleid], $uniquesampleid); } } }
[ "protected", "function", "fill_dataset", "(", "\\", "core_analytics", "\\", "local", "\\", "time_splitting", "\\", "base", "$", "timesplitting", ",", "array", "&", "$", "dataset", ",", "?", "array", "$", "calculatedtarget", "=", "null", ")", "{", "$", "nranges", "=", "count", "(", "$", "timesplitting", "->", "get_distinct_ranges", "(", ")", ")", ";", "foreach", "(", "$", "dataset", "as", "$", "uniquesampleid", "=>", "$", "unmodified", ")", "{", "list", "(", "$", "analysersampleid", ",", "$", "rangeindex", ")", "=", "$", "timesplitting", "->", "infer_sample_info", "(", "$", "uniquesampleid", ")", ";", "// No need to add range features if this time splitting method only defines one time range.", "if", "(", "$", "nranges", ">", "1", ")", "{", "// 1 column for each range.", "$", "timeindicators", "=", "array_fill", "(", "0", ",", "$", "nranges", ",", "0", ")", ";", "$", "timeindicators", "[", "$", "rangeindex", "]", "=", "1", ";", "$", "dataset", "[", "$", "uniquesampleid", "]", "=", "array_merge", "(", "$", "timeindicators", ",", "$", "dataset", "[", "$", "uniquesampleid", "]", ")", ";", "}", "if", "(", "$", "calculatedtarget", ")", "{", "// Add this sampleid's calculated target and the end.", "$", "dataset", "[", "$", "uniquesampleid", "]", "[", "]", "=", "$", "calculatedtarget", "[", "$", "analysersampleid", "]", ";", "}", "else", "{", "// Add this sampleid, it will be used to identify the prediction that comes back from", "// the predictions processor.", "array_unshift", "(", "$", "dataset", "[", "$", "uniquesampleid", "]", ",", "$", "uniquesampleid", ")", ";", "}", "}", "}" ]
Adds time range indicators and the target to each sample. This will identify the sample as belonging to a specific range. @param \core_analytics\local\time_splitting\base $timesplitting @param array $dataset @param array|null $calculatedtarget @return null
[ "Adds", "time", "range", "indicators", "and", "the", "target", "to", "each", "sample", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L555-L585
219,347
moodle/moodle
analytics/classes/analysis.php
analysis.update_analysable_analysed_time
protected function update_analysable_analysed_time(array $processedanalysables, int $analysableid) { global $DB; $now = time(); if (!empty($processedanalysables[$analysableid])) { $obj = $processedanalysables[$analysableid]; $obj->id = $obj->primarykey; unset($obj->primarykey); $obj->timeanalysed = $now; $DB->update_record('analytics_used_analysables', $obj); } else { $obj = new \stdClass(); $obj->modelid = $this->analyser->get_modelid(); $obj->action = ($this->includetarget) ? 'training' : 'prediction'; $obj->analysableid = $analysableid; $obj->firstanalysis = $now; $obj->timeanalysed = $now; $obj->primarykey = $DB->insert_record('analytics_used_analysables', $obj); // Update the cache just in case it is used in the same request. $key = $this->analyser->get_modelid() . '_' . $analysableid; $cache = \cache::make('core', 'modelfirstanalyses'); $cache->set($key, $now); } }
php
protected function update_analysable_analysed_time(array $processedanalysables, int $analysableid) { global $DB; $now = time(); if (!empty($processedanalysables[$analysableid])) { $obj = $processedanalysables[$analysableid]; $obj->id = $obj->primarykey; unset($obj->primarykey); $obj->timeanalysed = $now; $DB->update_record('analytics_used_analysables', $obj); } else { $obj = new \stdClass(); $obj->modelid = $this->analyser->get_modelid(); $obj->action = ($this->includetarget) ? 'training' : 'prediction'; $obj->analysableid = $analysableid; $obj->firstanalysis = $now; $obj->timeanalysed = $now; $obj->primarykey = $DB->insert_record('analytics_used_analysables', $obj); // Update the cache just in case it is used in the same request. $key = $this->analyser->get_modelid() . '_' . $analysableid; $cache = \cache::make('core', 'modelfirstanalyses'); $cache->set($key, $now); } }
[ "protected", "function", "update_analysable_analysed_time", "(", "array", "$", "processedanalysables", ",", "int", "$", "analysableid", ")", "{", "global", "$", "DB", ";", "$", "now", "=", "time", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "processedanalysables", "[", "$", "analysableid", "]", ")", ")", "{", "$", "obj", "=", "$", "processedanalysables", "[", "$", "analysableid", "]", ";", "$", "obj", "->", "id", "=", "$", "obj", "->", "primarykey", ";", "unset", "(", "$", "obj", "->", "primarykey", ")", ";", "$", "obj", "->", "timeanalysed", "=", "$", "now", ";", "$", "DB", "->", "update_record", "(", "'analytics_used_analysables'", ",", "$", "obj", ")", ";", "}", "else", "{", "$", "obj", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "obj", "->", "modelid", "=", "$", "this", "->", "analyser", "->", "get_modelid", "(", ")", ";", "$", "obj", "->", "action", "=", "(", "$", "this", "->", "includetarget", ")", "?", "'training'", ":", "'prediction'", ";", "$", "obj", "->", "analysableid", "=", "$", "analysableid", ";", "$", "obj", "->", "firstanalysis", "=", "$", "now", ";", "$", "obj", "->", "timeanalysed", "=", "$", "now", ";", "$", "obj", "->", "primarykey", "=", "$", "DB", "->", "insert_record", "(", "'analytics_used_analysables'", ",", "$", "obj", ")", ";", "// Update the cache just in case it is used in the same request.", "$", "key", "=", "$", "this", "->", "analyser", "->", "get_modelid", "(", ")", ".", "'_'", ".", "$", "analysableid", ";", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'core'", ",", "'modelfirstanalyses'", ")", ";", "$", "cache", "->", "set", "(", "$", "key", ",", "$", "now", ")", ";", "}", "}" ]
Updates the analysable analysis time. @param array $processedanalysables @param int $analysableid @return null
[ "Updates", "the", "analysable", "analysis", "time", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L594-L625
219,348
moodle/moodle
analytics/classes/analysis.php
analysis.fill_firstanalyses_cache
public static function fill_firstanalyses_cache(int $modelid, ?int $analysableid = null) { global $DB; // Using composed keys instead of cache $identifiers because of MDL-65358. $primarykey = $DB->sql_concat($modelid, "'_'", 'analysableid'); $sql = "SELECT $primarykey AS id, MIN(firstanalysis) AS firstanalysis FROM {analytics_used_analysables} aua WHERE modelid = :modelid"; $params = ['modelid' => $modelid]; if ($analysableid) { $sql .= " AND analysableid = :analysableid"; $params['analysableid'] = $analysableid; } $sql .= " GROUP BY modelid, analysableid ORDER BY analysableid"; $firstanalyses = $DB->get_records_sql($sql, $params); if ($firstanalyses) { $cache = \cache::make('core', 'modelfirstanalyses'); $firstanalyses = array_map(function($record) { return $record->firstanalysis; }, $firstanalyses); $cache->set_many($firstanalyses); } return $firstanalyses; }
php
public static function fill_firstanalyses_cache(int $modelid, ?int $analysableid = null) { global $DB; // Using composed keys instead of cache $identifiers because of MDL-65358. $primarykey = $DB->sql_concat($modelid, "'_'", 'analysableid'); $sql = "SELECT $primarykey AS id, MIN(firstanalysis) AS firstanalysis FROM {analytics_used_analysables} aua WHERE modelid = :modelid"; $params = ['modelid' => $modelid]; if ($analysableid) { $sql .= " AND analysableid = :analysableid"; $params['analysableid'] = $analysableid; } $sql .= " GROUP BY modelid, analysableid ORDER BY analysableid"; $firstanalyses = $DB->get_records_sql($sql, $params); if ($firstanalyses) { $cache = \cache::make('core', 'modelfirstanalyses'); $firstanalyses = array_map(function($record) { return $record->firstanalysis; }, $firstanalyses); $cache->set_many($firstanalyses); } return $firstanalyses; }
[ "public", "static", "function", "fill_firstanalyses_cache", "(", "int", "$", "modelid", ",", "?", "int", "$", "analysableid", "=", "null", ")", "{", "global", "$", "DB", ";", "// Using composed keys instead of cache $identifiers because of MDL-65358.", "$", "primarykey", "=", "$", "DB", "->", "sql_concat", "(", "$", "modelid", ",", "\"'_'\"", ",", "'analysableid'", ")", ";", "$", "sql", "=", "\"SELECT $primarykey AS id, MIN(firstanalysis) AS firstanalysis\n FROM {analytics_used_analysables} aua\n WHERE modelid = :modelid\"", ";", "$", "params", "=", "[", "'modelid'", "=>", "$", "modelid", "]", ";", "if", "(", "$", "analysableid", ")", "{", "$", "sql", ".=", "\" AND analysableid = :analysableid\"", ";", "$", "params", "[", "'analysableid'", "]", "=", "$", "analysableid", ";", "}", "$", "sql", ".=", "\" GROUP BY modelid, analysableid ORDER BY analysableid\"", ";", "$", "firstanalyses", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "if", "(", "$", "firstanalyses", ")", "{", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'core'", ",", "'modelfirstanalyses'", ")", ";", "$", "firstanalyses", "=", "array_map", "(", "function", "(", "$", "record", ")", "{", "return", "$", "record", "->", "firstanalysis", ";", "}", ",", "$", "firstanalyses", ")", ";", "$", "cache", "->", "set_many", "(", "$", "firstanalyses", ")", ";", "}", "return", "$", "firstanalyses", ";", "}" ]
Fills a cache containing the first time each analysable in the provided model was analysed. @param int $modelid @param int|null $analysableid @return null
[ "Fills", "a", "cache", "containing", "the", "first", "time", "each", "analysable", "in", "the", "provided", "model", "was", "analysed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L634-L663
219,349
moodle/moodle
analytics/classes/analysis.php
analysis.add_context_metadata
protected function add_context_metadata(\core_analytics\local\time_splitting\base $timesplitting, array &$dataset, \core_analytics\local\target\base $target) { $headers = $this->get_headers($timesplitting, $target); // This will also reset samples' dataset keys. array_unshift($dataset, $headers); }
php
protected function add_context_metadata(\core_analytics\local\time_splitting\base $timesplitting, array &$dataset, \core_analytics\local\target\base $target) { $headers = $this->get_headers($timesplitting, $target); // This will also reset samples' dataset keys. array_unshift($dataset, $headers); }
[ "protected", "function", "add_context_metadata", "(", "\\", "core_analytics", "\\", "local", "\\", "time_splitting", "\\", "base", "$", "timesplitting", ",", "array", "&", "$", "dataset", ",", "\\", "core_analytics", "\\", "local", "\\", "target", "\\", "base", "$", "target", ")", "{", "$", "headers", "=", "$", "this", "->", "get_headers", "(", "$", "timesplitting", ",", "$", "target", ")", ";", "// This will also reset samples' dataset keys.", "array_unshift", "(", "$", "dataset", ",", "$", "headers", ")", ";", "}" ]
Adds dataset context info. The final dataset document will look like this: ---------------------------------------------------- metadata1,metadata2,metadata3,..... value1, value2, value3,..... header1,header2,header3,header4,..... stud1value1,stud1value2,stud1value3,stud1value4,..... stud2value1,stud2value2,stud2value3,stud2value4,..... ..... ---------------------------------------------------- @param \core_analytics\local\time_splitting\base $timesplitting @param array $dataset @param \core_analytics\local\target\base $target @return null
[ "Adds", "dataset", "context", "info", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L684-L690
219,350
moodle/moodle
analytics/classes/analysis.php
analysis.get_headers
public function get_headers(\core_analytics\local\time_splitting\base $timesplitting, \core_analytics\local\target\base $target): array { // 3rd column will contain the indicator ids. $headers = array(); if (!$this->includetarget) { // The first column is the sampleid. $headers[] = 'sampleid'; } // We always have 1 column for each time splitting method range, it does not depend on how // many ranges we calculated. $ranges = $timesplitting->get_distinct_ranges(); if (count($ranges) > 1) { foreach ($ranges as $rangeindex) { $headers[] = 'range/' . $rangeindex; } } // Model indicators. foreach ($this->analyser->get_indicators() as $indicator) { $headers = array_merge($headers, $indicator::get_feature_headers()); } // The target as well. if ($this->includetarget) { $headers[] = $target->get_id(); } return $headers; }
php
public function get_headers(\core_analytics\local\time_splitting\base $timesplitting, \core_analytics\local\target\base $target): array { // 3rd column will contain the indicator ids. $headers = array(); if (!$this->includetarget) { // The first column is the sampleid. $headers[] = 'sampleid'; } // We always have 1 column for each time splitting method range, it does not depend on how // many ranges we calculated. $ranges = $timesplitting->get_distinct_ranges(); if (count($ranges) > 1) { foreach ($ranges as $rangeindex) { $headers[] = 'range/' . $rangeindex; } } // Model indicators. foreach ($this->analyser->get_indicators() as $indicator) { $headers = array_merge($headers, $indicator::get_feature_headers()); } // The target as well. if ($this->includetarget) { $headers[] = $target->get_id(); } return $headers; }
[ "public", "function", "get_headers", "(", "\\", "core_analytics", "\\", "local", "\\", "time_splitting", "\\", "base", "$", "timesplitting", ",", "\\", "core_analytics", "\\", "local", "\\", "target", "\\", "base", "$", "target", ")", ":", "array", "{", "// 3rd column will contain the indicator ids.", "$", "headers", "=", "array", "(", ")", ";", "if", "(", "!", "$", "this", "->", "includetarget", ")", "{", "// The first column is the sampleid.", "$", "headers", "[", "]", "=", "'sampleid'", ";", "}", "// We always have 1 column for each time splitting method range, it does not depend on how", "// many ranges we calculated.", "$", "ranges", "=", "$", "timesplitting", "->", "get_distinct_ranges", "(", ")", ";", "if", "(", "count", "(", "$", "ranges", ")", ">", "1", ")", "{", "foreach", "(", "$", "ranges", "as", "$", "rangeindex", ")", "{", "$", "headers", "[", "]", "=", "'range/'", ".", "$", "rangeindex", ";", "}", "}", "// Model indicators.", "foreach", "(", "$", "this", "->", "analyser", "->", "get_indicators", "(", ")", "as", "$", "indicator", ")", "{", "$", "headers", "=", "array_merge", "(", "$", "headers", ",", "$", "indicator", "::", "get_feature_headers", "(", ")", ")", ";", "}", "// The target as well.", "if", "(", "$", "this", "->", "includetarget", ")", "{", "$", "headers", "[", "]", "=", "$", "target", "->", "get_id", "(", ")", ";", "}", "return", "$", "headers", ";", "}" ]
Returns the headers for the csv file based on the indicators and the target. @param \core_analytics\local\time_splitting\base $timesplitting @param \core_analytics\local\target\base $target @return string[]
[ "Returns", "the", "headers", "for", "the", "csv", "file", "based", "on", "the", "indicators", "and", "the", "target", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L699-L729
219,351
moodle/moodle
analytics/classes/analysis.php
analysis.filter_out_train_samples
protected function filter_out_train_samples(array &$sampleids, \core_analytics\local\time_splitting\base $timesplitting) { global $DB; $params = array('modelid' => $this->analyser->get_modelid(), 'analysableid' => $timesplitting->get_analysable()->get_id(), 'timesplitting' => $timesplitting->get_id()); $trainingsamples = $DB->get_records('analytics_train_samples', $params); // Skip each file trained samples. foreach ($trainingsamples as $trainingfile) { $usedsamples = json_decode($trainingfile->sampleids, true); if (!empty($usedsamples)) { // Reset $sampleids to $sampleids minus this file's $usedsamples. $sampleids = array_diff_key($sampleids, $usedsamples); } } }
php
protected function filter_out_train_samples(array &$sampleids, \core_analytics\local\time_splitting\base $timesplitting) { global $DB; $params = array('modelid' => $this->analyser->get_modelid(), 'analysableid' => $timesplitting->get_analysable()->get_id(), 'timesplitting' => $timesplitting->get_id()); $trainingsamples = $DB->get_records('analytics_train_samples', $params); // Skip each file trained samples. foreach ($trainingsamples as $trainingfile) { $usedsamples = json_decode($trainingfile->sampleids, true); if (!empty($usedsamples)) { // Reset $sampleids to $sampleids minus this file's $usedsamples. $sampleids = array_diff_key($sampleids, $usedsamples); } } }
[ "protected", "function", "filter_out_train_samples", "(", "array", "&", "$", "sampleids", ",", "\\", "core_analytics", "\\", "local", "\\", "time_splitting", "\\", "base", "$", "timesplitting", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", "'modelid'", "=>", "$", "this", "->", "analyser", "->", "get_modelid", "(", ")", ",", "'analysableid'", "=>", "$", "timesplitting", "->", "get_analysable", "(", ")", "->", "get_id", "(", ")", ",", "'timesplitting'", "=>", "$", "timesplitting", "->", "get_id", "(", ")", ")", ";", "$", "trainingsamples", "=", "$", "DB", "->", "get_records", "(", "'analytics_train_samples'", ",", "$", "params", ")", ";", "// Skip each file trained samples.", "foreach", "(", "$", "trainingsamples", "as", "$", "trainingfile", ")", "{", "$", "usedsamples", "=", "json_decode", "(", "$", "trainingfile", "->", "sampleids", ",", "true", ")", ";", "if", "(", "!", "empty", "(", "$", "usedsamples", ")", ")", "{", "// Reset $sampleids to $sampleids minus this file's $usedsamples.", "$", "sampleids", "=", "array_diff_key", "(", "$", "sampleids", ",", "$", "usedsamples", ")", ";", "}", "}", "}" ]
Filters out samples that have already been used for training. @param int[] $sampleids @param \core_analytics\local\time_splitting\base $timesplitting @return null
[ "Filters", "out", "samples", "that", "have", "already", "been", "used", "for", "training", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L738-L756
219,352
moodle/moodle
analytics/classes/analysis.php
analysis.filter_out_prediction_samples_and_ranges
protected function filter_out_prediction_samples_and_ranges(array &$sampleids, array &$ranges, \core_analytics\local\time_splitting\base $timesplitting) { if (count($ranges) > 1) { throw new \coding_exception('$ranges argument should only contain one range'); } $rangeindex = key($ranges); $predictedrange = $this->get_predict_samples_record($timesplitting, $rangeindex); if (!$predictedrange) { // Nothing to filter out. return null; } $predictedrange->sampleids = json_decode($predictedrange->sampleids, true); $missingsamples = array_diff_key($sampleids, $predictedrange->sampleids); if (count($missingsamples) === 0) { // All samples already calculated. unset($ranges[$rangeindex]); return null; } // Replace the list of samples by the one excluding samples that already got predictions at this range. $sampleids = $missingsamples; return $predictedrange; }
php
protected function filter_out_prediction_samples_and_ranges(array &$sampleids, array &$ranges, \core_analytics\local\time_splitting\base $timesplitting) { if (count($ranges) > 1) { throw new \coding_exception('$ranges argument should only contain one range'); } $rangeindex = key($ranges); $predictedrange = $this->get_predict_samples_record($timesplitting, $rangeindex); if (!$predictedrange) { // Nothing to filter out. return null; } $predictedrange->sampleids = json_decode($predictedrange->sampleids, true); $missingsamples = array_diff_key($sampleids, $predictedrange->sampleids); if (count($missingsamples) === 0) { // All samples already calculated. unset($ranges[$rangeindex]); return null; } // Replace the list of samples by the one excluding samples that already got predictions at this range. $sampleids = $missingsamples; return $predictedrange; }
[ "protected", "function", "filter_out_prediction_samples_and_ranges", "(", "array", "&", "$", "sampleids", ",", "array", "&", "$", "ranges", ",", "\\", "core_analytics", "\\", "local", "\\", "time_splitting", "\\", "base", "$", "timesplitting", ")", "{", "if", "(", "count", "(", "$", "ranges", ")", ">", "1", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'$ranges argument should only contain one range'", ")", ";", "}", "$", "rangeindex", "=", "key", "(", "$", "ranges", ")", ";", "$", "predictedrange", "=", "$", "this", "->", "get_predict_samples_record", "(", "$", "timesplitting", ",", "$", "rangeindex", ")", ";", "if", "(", "!", "$", "predictedrange", ")", "{", "// Nothing to filter out.", "return", "null", ";", "}", "$", "predictedrange", "->", "sampleids", "=", "json_decode", "(", "$", "predictedrange", "->", "sampleids", ",", "true", ")", ";", "$", "missingsamples", "=", "array_diff_key", "(", "$", "sampleids", ",", "$", "predictedrange", "->", "sampleids", ")", ";", "if", "(", "count", "(", "$", "missingsamples", ")", "===", "0", ")", "{", "// All samples already calculated.", "unset", "(", "$", "ranges", "[", "$", "rangeindex", "]", ")", ";", "return", "null", ";", "}", "// Replace the list of samples by the one excluding samples that already got predictions at this range.", "$", "sampleids", "=", "$", "missingsamples", ";", "return", "$", "predictedrange", ";", "}" ]
Filters out samples that have already been used for prediction. @param int[] $sampleids @param array $ranges @param \core_analytics\local\time_splitting\base $timesplitting @return \stdClass|null The analytics_predict_samples record or null
[ "Filters", "out", "samples", "that", "have", "already", "been", "used", "for", "prediction", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L766-L793
219,353
moodle/moodle
analytics/classes/analysis.php
analysis.get_predict_samples_record
private function get_predict_samples_record(\core_analytics\local\time_splitting\base $timesplitting, int $rangeindex) { global $DB; $params = array('modelid' => $this->analyser->get_modelid(), 'analysableid' => $timesplitting->get_analysable()->get_id(), 'timesplitting' => $timesplitting->get_id(), 'rangeindex' => $rangeindex); $predictedrange = $DB->get_record('analytics_predict_samples', $params); return $predictedrange; }
php
private function get_predict_samples_record(\core_analytics\local\time_splitting\base $timesplitting, int $rangeindex) { global $DB; $params = array('modelid' => $this->analyser->get_modelid(), 'analysableid' => $timesplitting->get_analysable()->get_id(), 'timesplitting' => $timesplitting->get_id(), 'rangeindex' => $rangeindex); $predictedrange = $DB->get_record('analytics_predict_samples', $params); return $predictedrange; }
[ "private", "function", "get_predict_samples_record", "(", "\\", "core_analytics", "\\", "local", "\\", "time_splitting", "\\", "base", "$", "timesplitting", ",", "int", "$", "rangeindex", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", "'modelid'", "=>", "$", "this", "->", "analyser", "->", "get_modelid", "(", ")", ",", "'analysableid'", "=>", "$", "timesplitting", "->", "get_analysable", "(", ")", "->", "get_id", "(", ")", ",", "'timesplitting'", "=>", "$", "timesplitting", "->", "get_id", "(", ")", ",", "'rangeindex'", "=>", "$", "rangeindex", ")", ";", "$", "predictedrange", "=", "$", "DB", "->", "get_record", "(", "'analytics_predict_samples'", ",", "$", "params", ")", ";", "return", "$", "predictedrange", ";", "}" ]
Returns a predict samples record. @param \core_analytics\local\time_splitting\base $timesplitting @param int $rangeindex @return \stdClass|false
[ "Returns", "a", "predict", "samples", "record", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L802-L810
219,354
moodle/moodle
analytics/classes/analysis.php
analysis.save_train_samples
protected function save_train_samples(array $sampleids, \core_analytics\local\time_splitting\base $timesplitting) { global $DB; $trainingsamples = new \stdClass(); $trainingsamples->modelid = $this->analyser->get_modelid(); $trainingsamples->analysableid = $timesplitting->get_analysable()->get_id(); $trainingsamples->timesplitting = $timesplitting->get_id(); $trainingsamples->sampleids = json_encode($sampleids); $trainingsamples->timecreated = time(); $DB->insert_record('analytics_train_samples', $trainingsamples); }
php
protected function save_train_samples(array $sampleids, \core_analytics\local\time_splitting\base $timesplitting) { global $DB; $trainingsamples = new \stdClass(); $trainingsamples->modelid = $this->analyser->get_modelid(); $trainingsamples->analysableid = $timesplitting->get_analysable()->get_id(); $trainingsamples->timesplitting = $timesplitting->get_id(); $trainingsamples->sampleids = json_encode($sampleids); $trainingsamples->timecreated = time(); $DB->insert_record('analytics_train_samples', $trainingsamples); }
[ "protected", "function", "save_train_samples", "(", "array", "$", "sampleids", ",", "\\", "core_analytics", "\\", "local", "\\", "time_splitting", "\\", "base", "$", "timesplitting", ")", "{", "global", "$", "DB", ";", "$", "trainingsamples", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "trainingsamples", "->", "modelid", "=", "$", "this", "->", "analyser", "->", "get_modelid", "(", ")", ";", "$", "trainingsamples", "->", "analysableid", "=", "$", "timesplitting", "->", "get_analysable", "(", ")", "->", "get_id", "(", ")", ";", "$", "trainingsamples", "->", "timesplitting", "=", "$", "timesplitting", "->", "get_id", "(", ")", ";", "$", "trainingsamples", "->", "sampleids", "=", "json_encode", "(", "$", "sampleids", ")", ";", "$", "trainingsamples", "->", "timecreated", "=", "time", "(", ")", ";", "$", "DB", "->", "insert_record", "(", "'analytics_train_samples'", ",", "$", "trainingsamples", ")", ";", "}" ]
Saves samples that have just been used for training. @param int[] $sampleids @param \core_analytics\local\time_splitting\base $timesplitting @return null
[ "Saves", "samples", "that", "have", "just", "been", "used", "for", "training", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L819-L831
219,355
moodle/moodle
analytics/classes/analysis.php
analysis.save_prediction_samples
protected function save_prediction_samples(array $sampleids, array $ranges, \core_analytics\local\time_splitting\base $timesplitting, ?\stdClass $predictsamplesrecord = null) { global $DB; if (count($ranges) > 1) { throw new \coding_exception('$ranges argument should only contain one range'); } $rangeindex = key($ranges); if ($predictsamplesrecord) { // Append the new samples used for prediction. $predictsamplesrecord->sampleids = json_encode($predictsamplesrecord->sampleids + $sampleids); $predictsamplesrecord->timemodified = time(); $DB->update_record('analytics_predict_samples', $predictsamplesrecord); } else { $predictsamplesrecord = (object)[ 'modelid' => $this->analyser->get_modelid(), 'analysableid' => $timesplitting->get_analysable()->get_id(), 'timesplitting' => $timesplitting->get_id(), 'rangeindex' => $rangeindex ]; $predictsamplesrecord->sampleids = json_encode($sampleids); $predictsamplesrecord->timecreated = time(); $predictsamplesrecord->timemodified = $predictsamplesrecord->timecreated; $DB->insert_record('analytics_predict_samples', $predictsamplesrecord); } }
php
protected function save_prediction_samples(array $sampleids, array $ranges, \core_analytics\local\time_splitting\base $timesplitting, ?\stdClass $predictsamplesrecord = null) { global $DB; if (count($ranges) > 1) { throw new \coding_exception('$ranges argument should only contain one range'); } $rangeindex = key($ranges); if ($predictsamplesrecord) { // Append the new samples used for prediction. $predictsamplesrecord->sampleids = json_encode($predictsamplesrecord->sampleids + $sampleids); $predictsamplesrecord->timemodified = time(); $DB->update_record('analytics_predict_samples', $predictsamplesrecord); } else { $predictsamplesrecord = (object)[ 'modelid' => $this->analyser->get_modelid(), 'analysableid' => $timesplitting->get_analysable()->get_id(), 'timesplitting' => $timesplitting->get_id(), 'rangeindex' => $rangeindex ]; $predictsamplesrecord->sampleids = json_encode($sampleids); $predictsamplesrecord->timecreated = time(); $predictsamplesrecord->timemodified = $predictsamplesrecord->timecreated; $DB->insert_record('analytics_predict_samples', $predictsamplesrecord); } }
[ "protected", "function", "save_prediction_samples", "(", "array", "$", "sampleids", ",", "array", "$", "ranges", ",", "\\", "core_analytics", "\\", "local", "\\", "time_splitting", "\\", "base", "$", "timesplitting", ",", "?", "\\", "stdClass", "$", "predictsamplesrecord", "=", "null", ")", "{", "global", "$", "DB", ";", "if", "(", "count", "(", "$", "ranges", ")", ">", "1", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'$ranges argument should only contain one range'", ")", ";", "}", "$", "rangeindex", "=", "key", "(", "$", "ranges", ")", ";", "if", "(", "$", "predictsamplesrecord", ")", "{", "// Append the new samples used for prediction.", "$", "predictsamplesrecord", "->", "sampleids", "=", "json_encode", "(", "$", "predictsamplesrecord", "->", "sampleids", "+", "$", "sampleids", ")", ";", "$", "predictsamplesrecord", "->", "timemodified", "=", "time", "(", ")", ";", "$", "DB", "->", "update_record", "(", "'analytics_predict_samples'", ",", "$", "predictsamplesrecord", ")", ";", "}", "else", "{", "$", "predictsamplesrecord", "=", "(", "object", ")", "[", "'modelid'", "=>", "$", "this", "->", "analyser", "->", "get_modelid", "(", ")", ",", "'analysableid'", "=>", "$", "timesplitting", "->", "get_analysable", "(", ")", "->", "get_id", "(", ")", ",", "'timesplitting'", "=>", "$", "timesplitting", "->", "get_id", "(", ")", ",", "'rangeindex'", "=>", "$", "rangeindex", "]", ";", "$", "predictsamplesrecord", "->", "sampleids", "=", "json_encode", "(", "$", "sampleids", ")", ";", "$", "predictsamplesrecord", "->", "timecreated", "=", "time", "(", ")", ";", "$", "predictsamplesrecord", "->", "timemodified", "=", "$", "predictsamplesrecord", "->", "timecreated", ";", "$", "DB", "->", "insert_record", "(", "'analytics_predict_samples'", ",", "$", "predictsamplesrecord", ")", ";", "}", "}" ]
Saves samples that have just been used for prediction. @param int[] $sampleids @param array $ranges @param \core_analytics\local\time_splitting\base $timesplitting @param \stdClass|null $predictsamplesrecord The existing record or null if there is no record yet. @return null
[ "Saves", "samples", "that", "have", "just", "been", "used", "for", "prediction", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L842-L868
219,356
moodle/moodle
analytics/classes/analysis.php
analysis.init_analysable_analysis
private function init_analysable_analysis(string $timesplittingid, int $analysableid) { // Do not include $this->includetarget as we don't want the same analysable to be analysed for training // and prediction at the same time. $lockkey = 'modelid:' . $this->analyser->get_modelid() . '-analysableid:' . $analysableid . '-timesplitting:' . self::clean_time_splitting_id($timesplittingid); // Large timeout as processes may be quite long. $lockfactory = \core\lock\lock_config::get_lock_factory('core_analytics'); // If it is not ready in 10 secs skip this model + analysable + timesplittingmethod combination // it will attempt it again during next cron run. if (!$this->lock = $lockfactory->get_lock($lockkey, 10)) { return false; } return true; }
php
private function init_analysable_analysis(string $timesplittingid, int $analysableid) { // Do not include $this->includetarget as we don't want the same analysable to be analysed for training // and prediction at the same time. $lockkey = 'modelid:' . $this->analyser->get_modelid() . '-analysableid:' . $analysableid . '-timesplitting:' . self::clean_time_splitting_id($timesplittingid); // Large timeout as processes may be quite long. $lockfactory = \core\lock\lock_config::get_lock_factory('core_analytics'); // If it is not ready in 10 secs skip this model + analysable + timesplittingmethod combination // it will attempt it again during next cron run. if (!$this->lock = $lockfactory->get_lock($lockkey, 10)) { return false; } return true; }
[ "private", "function", "init_analysable_analysis", "(", "string", "$", "timesplittingid", ",", "int", "$", "analysableid", ")", "{", "// Do not include $this->includetarget as we don't want the same analysable to be analysed for training", "// and prediction at the same time.", "$", "lockkey", "=", "'modelid:'", ".", "$", "this", "->", "analyser", "->", "get_modelid", "(", ")", ".", "'-analysableid:'", ".", "$", "analysableid", ".", "'-timesplitting:'", ".", "self", "::", "clean_time_splitting_id", "(", "$", "timesplittingid", ")", ";", "// Large timeout as processes may be quite long.", "$", "lockfactory", "=", "\\", "core", "\\", "lock", "\\", "lock_config", "::", "get_lock_factory", "(", "'core_analytics'", ")", ";", "// If it is not ready in 10 secs skip this model + analysable + timesplittingmethod combination", "// it will attempt it again during next cron run.", "if", "(", "!", "$", "this", "->", "lock", "=", "$", "lockfactory", "->", "get_lock", "(", "$", "lockkey", ",", "10", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Flags the analysable element as in-analysis and stores a lock for it. @param string $timesplittingid @param int $analysableid @return bool Success or not
[ "Flags", "the", "analysable", "element", "as", "in", "-", "analysis", "and", "stores", "a", "lock", "for", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L877-L893
219,357
moodle/moodle
analytics/classes/analysis.php
analysis.get_insert_batch_size
private static function get_insert_batch_size(): int { global $DB; $dbconfig = $DB->export_dbconfig(); // 500 is pgsql default so using 1000 is fine, no other db driver uses a hardcoded value. if (empty($dbconfig) || empty($dbconfig->dboptions) || empty($dbconfig->dboptions['bulkinsertsize'])) { return 1000; } $bulkinsert = $dbconfig->dboptions['bulkinsertsize']; if ($bulkinsert < 1000) { return $bulkinsert; } while ($bulkinsert > 1000) { $bulkinsert = round($bulkinsert / 2, 0); } return (int)$bulkinsert; }
php
private static function get_insert_batch_size(): int { global $DB; $dbconfig = $DB->export_dbconfig(); // 500 is pgsql default so using 1000 is fine, no other db driver uses a hardcoded value. if (empty($dbconfig) || empty($dbconfig->dboptions) || empty($dbconfig->dboptions['bulkinsertsize'])) { return 1000; } $bulkinsert = $dbconfig->dboptions['bulkinsertsize']; if ($bulkinsert < 1000) { return $bulkinsert; } while ($bulkinsert > 1000) { $bulkinsert = round($bulkinsert / 2, 0); } return (int)$bulkinsert; }
[ "private", "static", "function", "get_insert_batch_size", "(", ")", ":", "int", "{", "global", "$", "DB", ";", "$", "dbconfig", "=", "$", "DB", "->", "export_dbconfig", "(", ")", ";", "// 500 is pgsql default so using 1000 is fine, no other db driver uses a hardcoded value.", "if", "(", "empty", "(", "$", "dbconfig", ")", "||", "empty", "(", "$", "dbconfig", "->", "dboptions", ")", "||", "empty", "(", "$", "dbconfig", "->", "dboptions", "[", "'bulkinsertsize'", "]", ")", ")", "{", "return", "1000", ";", "}", "$", "bulkinsert", "=", "$", "dbconfig", "->", "dboptions", "[", "'bulkinsertsize'", "]", ";", "if", "(", "$", "bulkinsert", "<", "1000", ")", "{", "return", "$", "bulkinsert", ";", "}", "while", "(", "$", "bulkinsert", ">", "1000", ")", "{", "$", "bulkinsert", "=", "round", "(", "$", "bulkinsert", "/", "2", ",", "0", ")", ";", "}", "return", "(", "int", ")", "$", "bulkinsert", ";", "}" ]
Returns the batch size used for insert_records. This method tries to find the best batch size without getting into dml internals. Maximum 1000 records to save memory. @return int
[ "Returns", "the", "batch", "size", "used", "for", "insert_records", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/analysis.php#L924-L944
219,358
moodle/moodle
grade/export/lib.php
grade_export.deprecated_constructor
protected function deprecated_constructor($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $onlyactive = false, $usercustomfields = false) { debugging('Many argument constructor for class "grade_export" is deprecated. Call the 3 argument version instead.', DEBUG_DEVELOPER); $this->course = $course; $this->groupid = $groupid; $this->grade_items = grade_item::fetch_all(array('courseid'=>$this->course->id)); //Populating the columns here is required by /grade/export/(whatever)/export.php //however index.php, when the form is submitted, will construct the collection here //with an empty $itemlist then reconstruct it in process_form() using $formdata $this->columns = array(); if (!empty($itemlist)) { if ($itemlist=='-1') { //user deselected all items } else { $itemids = explode(',', $itemlist); // remove items that are not requested foreach ($itemids as $itemid) { if (array_key_exists($itemid, $this->grade_items)) { $this->columns[$itemid] =& $this->grade_items[$itemid]; } } } } else { foreach ($this->grade_items as $itemid=>$unused) { $this->columns[$itemid] =& $this->grade_items[$itemid]; } } $this->export_feedback = $export_feedback; $this->userkey = ''; $this->previewrows = false; $this->updatedgradesonly = $updatedgradesonly; $this->displaytype = $displaytype; $this->decimalpoints = $decimalpoints; $this->onlyactive = $onlyactive; $this->usercustomfields = $usercustomfields; }
php
protected function deprecated_constructor($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $onlyactive = false, $usercustomfields = false) { debugging('Many argument constructor for class "grade_export" is deprecated. Call the 3 argument version instead.', DEBUG_DEVELOPER); $this->course = $course; $this->groupid = $groupid; $this->grade_items = grade_item::fetch_all(array('courseid'=>$this->course->id)); //Populating the columns here is required by /grade/export/(whatever)/export.php //however index.php, when the form is submitted, will construct the collection here //with an empty $itemlist then reconstruct it in process_form() using $formdata $this->columns = array(); if (!empty($itemlist)) { if ($itemlist=='-1') { //user deselected all items } else { $itemids = explode(',', $itemlist); // remove items that are not requested foreach ($itemids as $itemid) { if (array_key_exists($itemid, $this->grade_items)) { $this->columns[$itemid] =& $this->grade_items[$itemid]; } } } } else { foreach ($this->grade_items as $itemid=>$unused) { $this->columns[$itemid] =& $this->grade_items[$itemid]; } } $this->export_feedback = $export_feedback; $this->userkey = ''; $this->previewrows = false; $this->updatedgradesonly = $updatedgradesonly; $this->displaytype = $displaytype; $this->decimalpoints = $decimalpoints; $this->onlyactive = $onlyactive; $this->usercustomfields = $usercustomfields; }
[ "protected", "function", "deprecated_constructor", "(", "$", "course", ",", "$", "groupid", "=", "0", ",", "$", "itemlist", "=", "''", ",", "$", "export_feedback", "=", "false", ",", "$", "updatedgradesonly", "=", "false", ",", "$", "displaytype", "=", "GRADE_DISPLAY_TYPE_REAL", ",", "$", "decimalpoints", "=", "2", ",", "$", "onlyactive", "=", "false", ",", "$", "usercustomfields", "=", "false", ")", "{", "debugging", "(", "'Many argument constructor for class \"grade_export\" is deprecated. Call the 3 argument version instead.'", ",", "DEBUG_DEVELOPER", ")", ";", "$", "this", "->", "course", "=", "$", "course", ";", "$", "this", "->", "groupid", "=", "$", "groupid", ";", "$", "this", "->", "grade_items", "=", "grade_item", "::", "fetch_all", "(", "array", "(", "'courseid'", "=>", "$", "this", "->", "course", "->", "id", ")", ")", ";", "//Populating the columns here is required by /grade/export/(whatever)/export.php", "//however index.php, when the form is submitted, will construct the collection here", "//with an empty $itemlist then reconstruct it in process_form() using $formdata", "$", "this", "->", "columns", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "itemlist", ")", ")", "{", "if", "(", "$", "itemlist", "==", "'-1'", ")", "{", "//user deselected all items", "}", "else", "{", "$", "itemids", "=", "explode", "(", "','", ",", "$", "itemlist", ")", ";", "// remove items that are not requested", "foreach", "(", "$", "itemids", "as", "$", "itemid", ")", "{", "if", "(", "array_key_exists", "(", "$", "itemid", ",", "$", "this", "->", "grade_items", ")", ")", "{", "$", "this", "->", "columns", "[", "$", "itemid", "]", "=", "&", "$", "this", "->", "grade_items", "[", "$", "itemid", "]", ";", "}", "}", "}", "}", "else", "{", "foreach", "(", "$", "this", "->", "grade_items", "as", "$", "itemid", "=>", "$", "unused", ")", "{", "$", "this", "->", "columns", "[", "$", "itemid", "]", "=", "&", "$", "this", "->", "grade_items", "[", "$", "itemid", "]", ";", "}", "}", "$", "this", "->", "export_feedback", "=", "$", "export_feedback", ";", "$", "this", "->", "userkey", "=", "''", ";", "$", "this", "->", "previewrows", "=", "false", ";", "$", "this", "->", "updatedgradesonly", "=", "$", "updatedgradesonly", ";", "$", "this", "->", "displaytype", "=", "$", "displaytype", ";", "$", "this", "->", "decimalpoints", "=", "$", "decimalpoints", ";", "$", "this", "->", "onlyactive", "=", "$", "onlyactive", ";", "$", "this", "->", "usercustomfields", "=", "$", "usercustomfields", ";", "}" ]
Old deprecated constructor. This deprecated constructor accepts the individual parameters as separate arguments, in 2.8 this was simplified to just accept the data from the moodle form. @deprecated since 2.8 MDL-46548. Instead call the shortened constructor which accepts the data directly from the grade_export_form.
[ "Old", "deprecated", "constructor", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/lib.php#L94-L141
219,359
moodle/moodle
grade/export/lib.php
grade_export.process_form
function process_form($formdata) { global $USER; $this->columns = array(); if (!empty($formdata->itemids)) { if ($formdata->itemids=='-1') { //user deselected all items } else { foreach ($formdata->itemids as $itemid=>$selected) { if ($selected and array_key_exists($itemid, $this->grade_items)) { $this->columns[$itemid] =& $this->grade_items[$itemid]; } } } } else { foreach ($this->grade_items as $itemid=>$unused) { $this->columns[$itemid] =& $this->grade_items[$itemid]; } } if (isset($formdata->key)) { if ($formdata->key == 1 && isset($formdata->iprestriction) && isset($formdata->validuntil)) { // Create a new key $formdata->key = create_user_key('grade/export', $USER->id, $this->course->id, $formdata->iprestriction, $formdata->validuntil); } $this->userkey = $formdata->key; } if (isset($formdata->decimals)) { $this->decimalpoints = $formdata->decimals; } if (isset($formdata->export_letters)) { $this->export_letters = $formdata->export_letters; } if (isset($formdata->export_feedback)) { $this->export_feedback = $formdata->export_feedback; } if (isset($formdata->export_onlyactive)) { $this->onlyactive = $formdata->export_onlyactive; } if (isset($formdata->previewrows)) { $this->previewrows = $formdata->previewrows; } if (isset($formdata->display)) { $this->displaytype = $formdata->display; // Used by grade exports which accept multiple display types. // If the checkbox value is 0 (unchecked) then remove it. if (is_array($formdata->display)) { $this->displaytype = array_filter($formdata->display); } } if (isset($formdata->updatedgradesonly)) { $this->updatedgradesonly = $formdata->updatedgradesonly; } }
php
function process_form($formdata) { global $USER; $this->columns = array(); if (!empty($formdata->itemids)) { if ($formdata->itemids=='-1') { //user deselected all items } else { foreach ($formdata->itemids as $itemid=>$selected) { if ($selected and array_key_exists($itemid, $this->grade_items)) { $this->columns[$itemid] =& $this->grade_items[$itemid]; } } } } else { foreach ($this->grade_items as $itemid=>$unused) { $this->columns[$itemid] =& $this->grade_items[$itemid]; } } if (isset($formdata->key)) { if ($formdata->key == 1 && isset($formdata->iprestriction) && isset($formdata->validuntil)) { // Create a new key $formdata->key = create_user_key('grade/export', $USER->id, $this->course->id, $formdata->iprestriction, $formdata->validuntil); } $this->userkey = $formdata->key; } if (isset($formdata->decimals)) { $this->decimalpoints = $formdata->decimals; } if (isset($formdata->export_letters)) { $this->export_letters = $formdata->export_letters; } if (isset($formdata->export_feedback)) { $this->export_feedback = $formdata->export_feedback; } if (isset($formdata->export_onlyactive)) { $this->onlyactive = $formdata->export_onlyactive; } if (isset($formdata->previewrows)) { $this->previewrows = $formdata->previewrows; } if (isset($formdata->display)) { $this->displaytype = $formdata->display; // Used by grade exports which accept multiple display types. // If the checkbox value is 0 (unchecked) then remove it. if (is_array($formdata->display)) { $this->displaytype = array_filter($formdata->display); } } if (isset($formdata->updatedgradesonly)) { $this->updatedgradesonly = $formdata->updatedgradesonly; } }
[ "function", "process_form", "(", "$", "formdata", ")", "{", "global", "$", "USER", ";", "$", "this", "->", "columns", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "formdata", "->", "itemids", ")", ")", "{", "if", "(", "$", "formdata", "->", "itemids", "==", "'-1'", ")", "{", "//user deselected all items", "}", "else", "{", "foreach", "(", "$", "formdata", "->", "itemids", "as", "$", "itemid", "=>", "$", "selected", ")", "{", "if", "(", "$", "selected", "and", "array_key_exists", "(", "$", "itemid", ",", "$", "this", "->", "grade_items", ")", ")", "{", "$", "this", "->", "columns", "[", "$", "itemid", "]", "=", "&", "$", "this", "->", "grade_items", "[", "$", "itemid", "]", ";", "}", "}", "}", "}", "else", "{", "foreach", "(", "$", "this", "->", "grade_items", "as", "$", "itemid", "=>", "$", "unused", ")", "{", "$", "this", "->", "columns", "[", "$", "itemid", "]", "=", "&", "$", "this", "->", "grade_items", "[", "$", "itemid", "]", ";", "}", "}", "if", "(", "isset", "(", "$", "formdata", "->", "key", ")", ")", "{", "if", "(", "$", "formdata", "->", "key", "==", "1", "&&", "isset", "(", "$", "formdata", "->", "iprestriction", ")", "&&", "isset", "(", "$", "formdata", "->", "validuntil", ")", ")", "{", "// Create a new key", "$", "formdata", "->", "key", "=", "create_user_key", "(", "'grade/export'", ",", "$", "USER", "->", "id", ",", "$", "this", "->", "course", "->", "id", ",", "$", "formdata", "->", "iprestriction", ",", "$", "formdata", "->", "validuntil", ")", ";", "}", "$", "this", "->", "userkey", "=", "$", "formdata", "->", "key", ";", "}", "if", "(", "isset", "(", "$", "formdata", "->", "decimals", ")", ")", "{", "$", "this", "->", "decimalpoints", "=", "$", "formdata", "->", "decimals", ";", "}", "if", "(", "isset", "(", "$", "formdata", "->", "export_letters", ")", ")", "{", "$", "this", "->", "export_letters", "=", "$", "formdata", "->", "export_letters", ";", "}", "if", "(", "isset", "(", "$", "formdata", "->", "export_feedback", ")", ")", "{", "$", "this", "->", "export_feedback", "=", "$", "formdata", "->", "export_feedback", ";", "}", "if", "(", "isset", "(", "$", "formdata", "->", "export_onlyactive", ")", ")", "{", "$", "this", "->", "onlyactive", "=", "$", "formdata", "->", "export_onlyactive", ";", "}", "if", "(", "isset", "(", "$", "formdata", "->", "previewrows", ")", ")", "{", "$", "this", "->", "previewrows", "=", "$", "formdata", "->", "previewrows", ";", "}", "if", "(", "isset", "(", "$", "formdata", "->", "display", ")", ")", "{", "$", "this", "->", "displaytype", "=", "$", "formdata", "->", "display", ";", "// Used by grade exports which accept multiple display types.", "// If the checkbox value is 0 (unchecked) then remove it.", "if", "(", "is_array", "(", "$", "formdata", "->", "display", ")", ")", "{", "$", "this", "->", "displaytype", "=", "array_filter", "(", "$", "formdata", "->", "display", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "formdata", "->", "updatedgradesonly", ")", ")", "{", "$", "this", "->", "updatedgradesonly", "=", "$", "formdata", "->", "updatedgradesonly", ";", "}", "}" ]
Init object based using data from form @param object $formdata
[ "Init", "object", "based", "using", "data", "from", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/lib.php#L147-L208
219,360
moodle/moodle
grade/export/lib.php
grade_export.track_exports
public function track_exports() { global $CFG; /// Whether this plugin is entitled to update export time if ($expplugins = explode(",", $CFG->gradeexport)) { if (in_array($this->plugin, $expplugins)) { return true; } else { return false; } } else { return false; } }
php
public function track_exports() { global $CFG; /// Whether this plugin is entitled to update export time if ($expplugins = explode(",", $CFG->gradeexport)) { if (in_array($this->plugin, $expplugins)) { return true; } else { return false; } } else { return false; } }
[ "public", "function", "track_exports", "(", ")", "{", "global", "$", "CFG", ";", "/// Whether this plugin is entitled to update export time", "if", "(", "$", "expplugins", "=", "explode", "(", "\",\"", ",", "$", "CFG", "->", "gradeexport", ")", ")", "{", "if", "(", "in_array", "(", "$", "this", "->", "plugin", ",", "$", "expplugins", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}" ]
Update exported field in grade_grades table @return boolean
[ "Update", "exported", "field", "in", "grade_grades", "table" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/lib.php#L214-L227
219,361
moodle/moodle
grade/export/lib.php
grade_export.format_grade
public function format_grade($grade, $gradedisplayconst = null) { $displaytype = $this->displaytype; if (is_array($this->displaytype) && !is_null($gradedisplayconst)) { $displaytype = $gradedisplayconst; } $gradeitem = $this->grade_items[$grade->itemid]; // We are going to store the min and max so that we can "reset" the grade_item for later. $grademax = $gradeitem->grademax; $grademin = $gradeitem->grademin; // Updating grade_item with this grade_grades min and max. $gradeitem->grademax = $grade->get_grade_max(); $gradeitem->grademin = $grade->get_grade_min(); $formattedgrade = grade_format_gradevalue($grade->finalgrade, $gradeitem, false, $displaytype, $this->decimalpoints); // Resetting the grade item in case it is reused. $gradeitem->grademax = $grademax; $gradeitem->grademin = $grademin; return $formattedgrade; }
php
public function format_grade($grade, $gradedisplayconst = null) { $displaytype = $this->displaytype; if (is_array($this->displaytype) && !is_null($gradedisplayconst)) { $displaytype = $gradedisplayconst; } $gradeitem = $this->grade_items[$grade->itemid]; // We are going to store the min and max so that we can "reset" the grade_item for later. $grademax = $gradeitem->grademax; $grademin = $gradeitem->grademin; // Updating grade_item with this grade_grades min and max. $gradeitem->grademax = $grade->get_grade_max(); $gradeitem->grademin = $grade->get_grade_min(); $formattedgrade = grade_format_gradevalue($grade->finalgrade, $gradeitem, false, $displaytype, $this->decimalpoints); // Resetting the grade item in case it is reused. $gradeitem->grademax = $grademax; $gradeitem->grademin = $grademin; return $formattedgrade; }
[ "public", "function", "format_grade", "(", "$", "grade", ",", "$", "gradedisplayconst", "=", "null", ")", "{", "$", "displaytype", "=", "$", "this", "->", "displaytype", ";", "if", "(", "is_array", "(", "$", "this", "->", "displaytype", ")", "&&", "!", "is_null", "(", "$", "gradedisplayconst", ")", ")", "{", "$", "displaytype", "=", "$", "gradedisplayconst", ";", "}", "$", "gradeitem", "=", "$", "this", "->", "grade_items", "[", "$", "grade", "->", "itemid", "]", ";", "// We are going to store the min and max so that we can \"reset\" the grade_item for later.", "$", "grademax", "=", "$", "gradeitem", "->", "grademax", ";", "$", "grademin", "=", "$", "gradeitem", "->", "grademin", ";", "// Updating grade_item with this grade_grades min and max.", "$", "gradeitem", "->", "grademax", "=", "$", "grade", "->", "get_grade_max", "(", ")", ";", "$", "gradeitem", "->", "grademin", "=", "$", "grade", "->", "get_grade_min", "(", ")", ";", "$", "formattedgrade", "=", "grade_format_gradevalue", "(", "$", "grade", "->", "finalgrade", ",", "$", "gradeitem", ",", "false", ",", "$", "displaytype", ",", "$", "this", "->", "decimalpoints", ")", ";", "// Resetting the grade item in case it is reused.", "$", "gradeitem", "->", "grademax", "=", "$", "grademax", ";", "$", "gradeitem", "->", "grademin", "=", "$", "grademin", ";", "return", "$", "formattedgrade", ";", "}" ]
Returns string representation of final grade @param object $grade instance of grade_grade class @param integer $gradedisplayconst grade display type constant. @return string
[ "Returns", "string", "representation", "of", "final", "grade" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/lib.php#L235-L258
219,362
moodle/moodle
grade/export/lib.php
grade_export.format_column_name
public function format_column_name($grade_item, $feedback=false, $gradedisplayname = null) { $column = new stdClass(); if ($grade_item->itemtype == 'mod') { $column->name = get_string('modulename', $grade_item->itemmodule).get_string('labelsep', 'langconfig').$grade_item->get_name(); } else { $column->name = $grade_item->get_name(true); } // We can't have feedback and display type at the same time. $column->extra = ($feedback) ? get_string('feedback') : get_string($gradedisplayname, 'grades'); return html_to_text(get_string('gradeexportcolumntype', 'grades', $column), 0, false); }
php
public function format_column_name($grade_item, $feedback=false, $gradedisplayname = null) { $column = new stdClass(); if ($grade_item->itemtype == 'mod') { $column->name = get_string('modulename', $grade_item->itemmodule).get_string('labelsep', 'langconfig').$grade_item->get_name(); } else { $column->name = $grade_item->get_name(true); } // We can't have feedback and display type at the same time. $column->extra = ($feedback) ? get_string('feedback') : get_string($gradedisplayname, 'grades'); return html_to_text(get_string('gradeexportcolumntype', 'grades', $column), 0, false); }
[ "public", "function", "format_column_name", "(", "$", "grade_item", ",", "$", "feedback", "=", "false", ",", "$", "gradedisplayname", "=", "null", ")", "{", "$", "column", "=", "new", "stdClass", "(", ")", ";", "if", "(", "$", "grade_item", "->", "itemtype", "==", "'mod'", ")", "{", "$", "column", "->", "name", "=", "get_string", "(", "'modulename'", ",", "$", "grade_item", "->", "itemmodule", ")", ".", "get_string", "(", "'labelsep'", ",", "'langconfig'", ")", ".", "$", "grade_item", "->", "get_name", "(", ")", ";", "}", "else", "{", "$", "column", "->", "name", "=", "$", "grade_item", "->", "get_name", "(", "true", ")", ";", "}", "// We can't have feedback and display type at the same time.", "$", "column", "->", "extra", "=", "(", "$", "feedback", ")", "?", "get_string", "(", "'feedback'", ")", ":", "get_string", "(", "$", "gradedisplayname", ",", "'grades'", ")", ";", "return", "html_to_text", "(", "get_string", "(", "'gradeexportcolumntype'", ",", "'grades'", ",", "$", "column", ")", ",", "0", ",", "false", ")", ";", "}" ]
Returns the name of column in export @param object $grade_item @param boolean $feedback feedback colum @param string $gradedisplayname grade display name. @return string
[ "Returns", "the", "name", "of", "column", "in", "export" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/lib.php#L267-L280
219,363
moodle/moodle
grade/export/lib.php
grade_export.format_feedback
public function format_feedback($feedback, $grade = null) { $string = $feedback->feedback; if (!empty($grade)) { // Rewrite links to get the export working for 36, refer MDL-63488. $string = file_rewrite_pluginfile_urls( $feedback->feedback, 'pluginfile.php', $grade->get_context()->id, GRADE_FILE_COMPONENT, GRADE_FEEDBACK_FILEAREA, $grade->id ); } return strip_tags(format_text($string, $feedback->feedbackformat)); }
php
public function format_feedback($feedback, $grade = null) { $string = $feedback->feedback; if (!empty($grade)) { // Rewrite links to get the export working for 36, refer MDL-63488. $string = file_rewrite_pluginfile_urls( $feedback->feedback, 'pluginfile.php', $grade->get_context()->id, GRADE_FILE_COMPONENT, GRADE_FEEDBACK_FILEAREA, $grade->id ); } return strip_tags(format_text($string, $feedback->feedbackformat)); }
[ "public", "function", "format_feedback", "(", "$", "feedback", ",", "$", "grade", "=", "null", ")", "{", "$", "string", "=", "$", "feedback", "->", "feedback", ";", "if", "(", "!", "empty", "(", "$", "grade", ")", ")", "{", "// Rewrite links to get the export working for 36, refer MDL-63488.", "$", "string", "=", "file_rewrite_pluginfile_urls", "(", "$", "feedback", "->", "feedback", ",", "'pluginfile.php'", ",", "$", "grade", "->", "get_context", "(", ")", "->", "id", ",", "GRADE_FILE_COMPONENT", ",", "GRADE_FEEDBACK_FILEAREA", ",", "$", "grade", "->", "id", ")", ";", "}", "return", "strip_tags", "(", "format_text", "(", "$", "string", ",", "$", "feedback", "->", "feedbackformat", ")", ")", ";", "}" ]
Returns formatted grade feedback @param object $feedback object with properties feedback and feedbackformat @param object $grade Grade object with grade properties @return string
[ "Returns", "formatted", "grade", "feedback" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/lib.php#L288-L303
219,364
moodle/moodle
grade/export/lib.php
grade_export.get_export_params
public function get_export_params() { $itemids = array_keys($this->columns); $itemidsparam = implode(',', $itemids); if (empty($itemidsparam)) { $itemidsparam = '-1'; } // We have a single grade display type constant. if (!is_array($this->displaytype)) { $displaytypes = $this->displaytype; } else { // Implode the grade display types array as moodle_url function doesn't accept arrays. $displaytypes = implode(',', $this->displaytype); } if (!empty($this->updatedgradesonly)) { $updatedgradesonly = $this->updatedgradesonly; } else { $updatedgradesonly = 0; } $params = array('id' => $this->course->id, 'groupid' => $this->groupid, 'itemids' => $itemidsparam, 'export_letters' => $this->export_letters, 'export_feedback' => $this->export_feedback, 'updatedgradesonly' => $updatedgradesonly, 'decimalpoints' => $this->decimalpoints, 'export_onlyactive' => $this->onlyactive, 'usercustomfields' => $this->usercustomfields, 'displaytype' => $displaytypes, 'key' => $this->userkey); return $params; }
php
public function get_export_params() { $itemids = array_keys($this->columns); $itemidsparam = implode(',', $itemids); if (empty($itemidsparam)) { $itemidsparam = '-1'; } // We have a single grade display type constant. if (!is_array($this->displaytype)) { $displaytypes = $this->displaytype; } else { // Implode the grade display types array as moodle_url function doesn't accept arrays. $displaytypes = implode(',', $this->displaytype); } if (!empty($this->updatedgradesonly)) { $updatedgradesonly = $this->updatedgradesonly; } else { $updatedgradesonly = 0; } $params = array('id' => $this->course->id, 'groupid' => $this->groupid, 'itemids' => $itemidsparam, 'export_letters' => $this->export_letters, 'export_feedback' => $this->export_feedback, 'updatedgradesonly' => $updatedgradesonly, 'decimalpoints' => $this->decimalpoints, 'export_onlyactive' => $this->onlyactive, 'usercustomfields' => $this->usercustomfields, 'displaytype' => $displaytypes, 'key' => $this->userkey); return $params; }
[ "public", "function", "get_export_params", "(", ")", "{", "$", "itemids", "=", "array_keys", "(", "$", "this", "->", "columns", ")", ";", "$", "itemidsparam", "=", "implode", "(", "','", ",", "$", "itemids", ")", ";", "if", "(", "empty", "(", "$", "itemidsparam", ")", ")", "{", "$", "itemidsparam", "=", "'-1'", ";", "}", "// We have a single grade display type constant.", "if", "(", "!", "is_array", "(", "$", "this", "->", "displaytype", ")", ")", "{", "$", "displaytypes", "=", "$", "this", "->", "displaytype", ";", "}", "else", "{", "// Implode the grade display types array as moodle_url function doesn't accept arrays.", "$", "displaytypes", "=", "implode", "(", "','", ",", "$", "this", "->", "displaytype", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "updatedgradesonly", ")", ")", "{", "$", "updatedgradesonly", "=", "$", "this", "->", "updatedgradesonly", ";", "}", "else", "{", "$", "updatedgradesonly", "=", "0", ";", "}", "$", "params", "=", "array", "(", "'id'", "=>", "$", "this", "->", "course", "->", "id", ",", "'groupid'", "=>", "$", "this", "->", "groupid", ",", "'itemids'", "=>", "$", "itemidsparam", ",", "'export_letters'", "=>", "$", "this", "->", "export_letters", ",", "'export_feedback'", "=>", "$", "this", "->", "export_feedback", ",", "'updatedgradesonly'", "=>", "$", "updatedgradesonly", ",", "'decimalpoints'", "=>", "$", "this", "->", "decimalpoints", ",", "'export_onlyactive'", "=>", "$", "this", "->", "onlyactive", ",", "'usercustomfields'", "=>", "$", "this", "->", "usercustomfields", ",", "'displaytype'", "=>", "$", "displaytypes", ",", "'key'", "=>", "$", "this", "->", "userkey", ")", ";", "return", "$", "params", ";", "}" ]
Returns array of parameters used by dump.php and export.php. @return array
[ "Returns", "array", "of", "parameters", "used", "by", "dump", ".", "php", "and", "export", ".", "php", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/lib.php#L410-L443
219,365
moodle/moodle
grade/export/lib.php
grade_export.print_continue
public function print_continue() { global $CFG, $OUTPUT; debugging('function grade_export::print_continue is deprecated.', DEBUG_DEVELOPER); $params = $this->get_export_params(); echo $OUTPUT->heading(get_string('export', 'grades')); echo $OUTPUT->container_start('gradeexportlink'); if (!$this->userkey) { // This button should trigger a download prompt. $url = new moodle_url('/grade/export/'.$this->plugin.'/export.php', $params); echo $OUTPUT->single_button($url, get_string('download', 'admin')); } else { $paramstr = ''; $sep = '?'; foreach($params as $name=>$value) { $paramstr .= $sep.$name.'='.$value; $sep = '&'; } $link = $CFG->wwwroot.'/grade/export/'.$this->plugin.'/dump.php'.$paramstr.'&key='.$this->userkey; echo get_string('download', 'admin').': ' . html_writer::link($link, $link); } echo $OUTPUT->container_end(); return; }
php
public function print_continue() { global $CFG, $OUTPUT; debugging('function grade_export::print_continue is deprecated.', DEBUG_DEVELOPER); $params = $this->get_export_params(); echo $OUTPUT->heading(get_string('export', 'grades')); echo $OUTPUT->container_start('gradeexportlink'); if (!$this->userkey) { // This button should trigger a download prompt. $url = new moodle_url('/grade/export/'.$this->plugin.'/export.php', $params); echo $OUTPUT->single_button($url, get_string('download', 'admin')); } else { $paramstr = ''; $sep = '?'; foreach($params as $name=>$value) { $paramstr .= $sep.$name.'='.$value; $sep = '&'; } $link = $CFG->wwwroot.'/grade/export/'.$this->plugin.'/dump.php'.$paramstr.'&key='.$this->userkey; echo get_string('download', 'admin').': ' . html_writer::link($link, $link); } echo $OUTPUT->container_end(); return; }
[ "public", "function", "print_continue", "(", ")", "{", "global", "$", "CFG", ",", "$", "OUTPUT", ";", "debugging", "(", "'function grade_export::print_continue is deprecated.'", ",", "DEBUG_DEVELOPER", ")", ";", "$", "params", "=", "$", "this", "->", "get_export_params", "(", ")", ";", "echo", "$", "OUTPUT", "->", "heading", "(", "get_string", "(", "'export'", ",", "'grades'", ")", ")", ";", "echo", "$", "OUTPUT", "->", "container_start", "(", "'gradeexportlink'", ")", ";", "if", "(", "!", "$", "this", "->", "userkey", ")", "{", "// This button should trigger a download prompt.", "$", "url", "=", "new", "moodle_url", "(", "'/grade/export/'", ".", "$", "this", "->", "plugin", ".", "'/export.php'", ",", "$", "params", ")", ";", "echo", "$", "OUTPUT", "->", "single_button", "(", "$", "url", ",", "get_string", "(", "'download'", ",", "'admin'", ")", ")", ";", "}", "else", "{", "$", "paramstr", "=", "''", ";", "$", "sep", "=", "'?'", ";", "foreach", "(", "$", "params", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "paramstr", ".=", "$", "sep", ".", "$", "name", ".", "'='", ".", "$", "value", ";", "$", "sep", "=", "'&'", ";", "}", "$", "link", "=", "$", "CFG", "->", "wwwroot", ".", "'/grade/export/'", ".", "$", "this", "->", "plugin", ".", "'/dump.php'", ".", "$", "paramstr", ".", "'&key='", ".", "$", "this", "->", "userkey", ";", "echo", "get_string", "(", "'download'", ",", "'admin'", ")", ".", "': '", ".", "html_writer", "::", "link", "(", "$", "link", ",", "$", "link", ")", ";", "}", "echo", "$", "OUTPUT", "->", "container_end", "(", ")", ";", "return", ";", "}" ]
Either prints a "Export" box, which will redirect the user to the download page, or prints the URL for the published data. @deprecated since 2.8 MDL-46548. Call get_export_url and set the action of the grade_export_form instead. @return void
[ "Either", "prints", "a", "Export", "box", "which", "will", "redirect", "the", "user", "to", "the", "download", "page", "or", "prints", "the", "URL", "for", "the", "published", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/lib.php#L453-L483
219,366
moodle/moodle
grade/export/lib.php
grade_export.convert_flat_displaytypes_to_array
public static function convert_flat_displaytypes_to_array($displaytypes) { $types = array(); // We have a single grade display type constant. if (is_int($displaytypes)) { $displaytype = clean_param($displaytypes, PARAM_INT); // Let's set a default value, will be replaced below by the grade display type constant. $display[$displaytype] = 1; } else { // Multiple grade display types constants. $display = array_flip(explode(',', $displaytypes)); } // Now, create the array in the required format by grade exporting class. foreach ($display as $type => $value) { $type = clean_param($type, PARAM_INT); if ($type == GRADE_DISPLAY_TYPE_LETTER) { $types['letter'] = GRADE_DISPLAY_TYPE_LETTER; } else if ($type == GRADE_DISPLAY_TYPE_PERCENTAGE) { $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE; } else if ($type == GRADE_DISPLAY_TYPE_REAL) { $types['real'] = GRADE_DISPLAY_TYPE_REAL; } else if ($type == GRADE_DISPLAY_TYPE_REAL_PERCENTAGE) { $types['real'] = GRADE_DISPLAY_TYPE_REAL; $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE; } else if ($type == GRADE_DISPLAY_TYPE_REAL_LETTER) { $types['real'] = GRADE_DISPLAY_TYPE_REAL; $types['letter'] = GRADE_DISPLAY_TYPE_LETTER; } else if ($type == GRADE_DISPLAY_TYPE_LETTER_REAL) { $types['letter'] = GRADE_DISPLAY_TYPE_LETTER; $types['real'] = GRADE_DISPLAY_TYPE_REAL; } else if ($type == GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE) { $types['letter'] = GRADE_DISPLAY_TYPE_LETTER; $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE; } else if ($type == GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER) { $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE; $types['letter'] = GRADE_DISPLAY_TYPE_LETTER; } else if ($type == GRADE_DISPLAY_TYPE_PERCENTAGE_REAL) { $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE; $types['real'] = GRADE_DISPLAY_TYPE_REAL; } } return $types; }
php
public static function convert_flat_displaytypes_to_array($displaytypes) { $types = array(); // We have a single grade display type constant. if (is_int($displaytypes)) { $displaytype = clean_param($displaytypes, PARAM_INT); // Let's set a default value, will be replaced below by the grade display type constant. $display[$displaytype] = 1; } else { // Multiple grade display types constants. $display = array_flip(explode(',', $displaytypes)); } // Now, create the array in the required format by grade exporting class. foreach ($display as $type => $value) { $type = clean_param($type, PARAM_INT); if ($type == GRADE_DISPLAY_TYPE_LETTER) { $types['letter'] = GRADE_DISPLAY_TYPE_LETTER; } else if ($type == GRADE_DISPLAY_TYPE_PERCENTAGE) { $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE; } else if ($type == GRADE_DISPLAY_TYPE_REAL) { $types['real'] = GRADE_DISPLAY_TYPE_REAL; } else if ($type == GRADE_DISPLAY_TYPE_REAL_PERCENTAGE) { $types['real'] = GRADE_DISPLAY_TYPE_REAL; $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE; } else if ($type == GRADE_DISPLAY_TYPE_REAL_LETTER) { $types['real'] = GRADE_DISPLAY_TYPE_REAL; $types['letter'] = GRADE_DISPLAY_TYPE_LETTER; } else if ($type == GRADE_DISPLAY_TYPE_LETTER_REAL) { $types['letter'] = GRADE_DISPLAY_TYPE_LETTER; $types['real'] = GRADE_DISPLAY_TYPE_REAL; } else if ($type == GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE) { $types['letter'] = GRADE_DISPLAY_TYPE_LETTER; $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE; } else if ($type == GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER) { $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE; $types['letter'] = GRADE_DISPLAY_TYPE_LETTER; } else if ($type == GRADE_DISPLAY_TYPE_PERCENTAGE_REAL) { $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE; $types['real'] = GRADE_DISPLAY_TYPE_REAL; } } return $types; }
[ "public", "static", "function", "convert_flat_displaytypes_to_array", "(", "$", "displaytypes", ")", "{", "$", "types", "=", "array", "(", ")", ";", "// We have a single grade display type constant.", "if", "(", "is_int", "(", "$", "displaytypes", ")", ")", "{", "$", "displaytype", "=", "clean_param", "(", "$", "displaytypes", ",", "PARAM_INT", ")", ";", "// Let's set a default value, will be replaced below by the grade display type constant.", "$", "display", "[", "$", "displaytype", "]", "=", "1", ";", "}", "else", "{", "// Multiple grade display types constants.", "$", "display", "=", "array_flip", "(", "explode", "(", "','", ",", "$", "displaytypes", ")", ")", ";", "}", "// Now, create the array in the required format by grade exporting class.", "foreach", "(", "$", "display", "as", "$", "type", "=>", "$", "value", ")", "{", "$", "type", "=", "clean_param", "(", "$", "type", ",", "PARAM_INT", ")", ";", "if", "(", "$", "type", "==", "GRADE_DISPLAY_TYPE_LETTER", ")", "{", "$", "types", "[", "'letter'", "]", "=", "GRADE_DISPLAY_TYPE_LETTER", ";", "}", "else", "if", "(", "$", "type", "==", "GRADE_DISPLAY_TYPE_PERCENTAGE", ")", "{", "$", "types", "[", "'percentage'", "]", "=", "GRADE_DISPLAY_TYPE_PERCENTAGE", ";", "}", "else", "if", "(", "$", "type", "==", "GRADE_DISPLAY_TYPE_REAL", ")", "{", "$", "types", "[", "'real'", "]", "=", "GRADE_DISPLAY_TYPE_REAL", ";", "}", "else", "if", "(", "$", "type", "==", "GRADE_DISPLAY_TYPE_REAL_PERCENTAGE", ")", "{", "$", "types", "[", "'real'", "]", "=", "GRADE_DISPLAY_TYPE_REAL", ";", "$", "types", "[", "'percentage'", "]", "=", "GRADE_DISPLAY_TYPE_PERCENTAGE", ";", "}", "else", "if", "(", "$", "type", "==", "GRADE_DISPLAY_TYPE_REAL_LETTER", ")", "{", "$", "types", "[", "'real'", "]", "=", "GRADE_DISPLAY_TYPE_REAL", ";", "$", "types", "[", "'letter'", "]", "=", "GRADE_DISPLAY_TYPE_LETTER", ";", "}", "else", "if", "(", "$", "type", "==", "GRADE_DISPLAY_TYPE_LETTER_REAL", ")", "{", "$", "types", "[", "'letter'", "]", "=", "GRADE_DISPLAY_TYPE_LETTER", ";", "$", "types", "[", "'real'", "]", "=", "GRADE_DISPLAY_TYPE_REAL", ";", "}", "else", "if", "(", "$", "type", "==", "GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE", ")", "{", "$", "types", "[", "'letter'", "]", "=", "GRADE_DISPLAY_TYPE_LETTER", ";", "$", "types", "[", "'percentage'", "]", "=", "GRADE_DISPLAY_TYPE_PERCENTAGE", ";", "}", "else", "if", "(", "$", "type", "==", "GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER", ")", "{", "$", "types", "[", "'percentage'", "]", "=", "GRADE_DISPLAY_TYPE_PERCENTAGE", ";", "$", "types", "[", "'letter'", "]", "=", "GRADE_DISPLAY_TYPE_LETTER", ";", "}", "else", "if", "(", "$", "type", "==", "GRADE_DISPLAY_TYPE_PERCENTAGE_REAL", ")", "{", "$", "types", "[", "'percentage'", "]", "=", "GRADE_DISPLAY_TYPE_PERCENTAGE", ";", "$", "types", "[", "'real'", "]", "=", "GRADE_DISPLAY_TYPE_REAL", ";", "}", "}", "return", "$", "types", ";", "}" ]
Convert the grade display types parameter into the required array to grade exporting class. In order to export, the array key must be the display type name and the value must be the grade display type constant. Note: Added support for combined display types constants like the (GRADE_DISPLAY_TYPE_PERCENTAGE_REAL) as the $CFG->grade_export_displaytype config is still used on 2.7 in case of missing displaytype url param. In these cases, the file will be exported with a column for each display type. @param string $displaytypes can be a single or multiple display type constants comma separated. @return array $types
[ "Convert", "the", "grade", "display", "types", "parameter", "into", "the", "required", "array", "to", "grade", "exporting", "class", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/lib.php#L509-L553
219,367
moodle/moodle
grade/export/lib.php
grade_export.convert_flat_itemids_to_array
public static function convert_flat_itemids_to_array($itemids) { $items = array(); // We just have one single item id. if (is_int($itemids)) { $itemid = clean_param($itemids, PARAM_INT); $items[$itemid] = 1; } else { // Few grade items. $items = array_flip(explode(',', $itemids)); foreach ($items as $itemid => $value) { $itemid = clean_param($itemid, PARAM_INT); $items[$itemid] = 1; } } return $items; }
php
public static function convert_flat_itemids_to_array($itemids) { $items = array(); // We just have one single item id. if (is_int($itemids)) { $itemid = clean_param($itemids, PARAM_INT); $items[$itemid] = 1; } else { // Few grade items. $items = array_flip(explode(',', $itemids)); foreach ($items as $itemid => $value) { $itemid = clean_param($itemid, PARAM_INT); $items[$itemid] = 1; } } return $items; }
[ "public", "static", "function", "convert_flat_itemids_to_array", "(", "$", "itemids", ")", "{", "$", "items", "=", "array", "(", ")", ";", "// We just have one single item id.", "if", "(", "is_int", "(", "$", "itemids", ")", ")", "{", "$", "itemid", "=", "clean_param", "(", "$", "itemids", ",", "PARAM_INT", ")", ";", "$", "items", "[", "$", "itemid", "]", "=", "1", ";", "}", "else", "{", "// Few grade items.", "$", "items", "=", "array_flip", "(", "explode", "(", "','", ",", "$", "itemids", ")", ")", ";", "foreach", "(", "$", "items", "as", "$", "itemid", "=>", "$", "value", ")", "{", "$", "itemid", "=", "clean_param", "(", "$", "itemid", ",", "PARAM_INT", ")", ";", "$", "items", "[", "$", "itemid", "]", "=", "1", ";", "}", "}", "return", "$", "items", ";", "}" ]
Convert the item ids parameter into the required array to grade exporting class. In order to export, the array key must be the grade item id and all values must be one. @param string $itemids can be a single item id or many item ids comma separated. @return array $items correctly formatted array.
[ "Convert", "the", "item", "ids", "parameter", "into", "the", "required", "array", "to", "grade", "exporting", "class", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/lib.php#L563-L579
219,368
moodle/moodle
grade/export/lib.php
grade_export.get_grade_publishing_url
public function get_grade_publishing_url() { $url = $this->get_export_url(); $output = html_writer::start_div(); $output .= html_writer::tag('p', get_string('gradepublishinglink', 'grades', html_writer::link($url, $url))); $output .= html_writer::end_div(); return $output; }
php
public function get_grade_publishing_url() { $url = $this->get_export_url(); $output = html_writer::start_div(); $output .= html_writer::tag('p', get_string('gradepublishinglink', 'grades', html_writer::link($url, $url))); $output .= html_writer::end_div(); return $output; }
[ "public", "function", "get_grade_publishing_url", "(", ")", "{", "$", "url", "=", "$", "this", "->", "get_export_url", "(", ")", ";", "$", "output", "=", "html_writer", "::", "start_div", "(", ")", ";", "$", "output", ".=", "html_writer", "::", "tag", "(", "'p'", ",", "get_string", "(", "'gradepublishinglink'", ",", "'grades'", ",", "html_writer", "::", "link", "(", "$", "url", ",", "$", "url", ")", ")", ")", ";", "$", "output", ".=", "html_writer", "::", "end_div", "(", ")", ";", "return", "$", "output", ";", "}" ]
Create the html code of the grade publishing feature. @return string $output html code of the grade publishing.
[ "Create", "the", "html", "code", "of", "the", "grade", "publishing", "feature", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/lib.php#L586-L592
219,369
moodle/moodle
grade/export/lib.php
grade_export.export_bulk_export_data
public static function export_bulk_export_data($id, $itemids, $exportfeedback, $onlyactive, $displaytype, $decimalpoints, $updatedgradesonly = null, $separator = null) { $formdata = new \stdClass(); $formdata->id = $id; $formdata->itemids = self::convert_flat_itemids_to_array($itemids); $formdata->exportfeedback = $exportfeedback; $formdata->export_onlyactive = $onlyactive; $formdata->display = self::convert_flat_displaytypes_to_array($displaytype); $formdata->decimals = $decimalpoints; if (!empty($updatedgradesonly)) { $formdata->updatedgradesonly = $updatedgradesonly; } if (!empty($separator)) { $formdata->separator = $separator; } return $formdata; }
php
public static function export_bulk_export_data($id, $itemids, $exportfeedback, $onlyactive, $displaytype, $decimalpoints, $updatedgradesonly = null, $separator = null) { $formdata = new \stdClass(); $formdata->id = $id; $formdata->itemids = self::convert_flat_itemids_to_array($itemids); $formdata->exportfeedback = $exportfeedback; $formdata->export_onlyactive = $onlyactive; $formdata->display = self::convert_flat_displaytypes_to_array($displaytype); $formdata->decimals = $decimalpoints; if (!empty($updatedgradesonly)) { $formdata->updatedgradesonly = $updatedgradesonly; } if (!empty($separator)) { $formdata->separator = $separator; } return $formdata; }
[ "public", "static", "function", "export_bulk_export_data", "(", "$", "id", ",", "$", "itemids", ",", "$", "exportfeedback", ",", "$", "onlyactive", ",", "$", "displaytype", ",", "$", "decimalpoints", ",", "$", "updatedgradesonly", "=", "null", ",", "$", "separator", "=", "null", ")", "{", "$", "formdata", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "formdata", "->", "id", "=", "$", "id", ";", "$", "formdata", "->", "itemids", "=", "self", "::", "convert_flat_itemids_to_array", "(", "$", "itemids", ")", ";", "$", "formdata", "->", "exportfeedback", "=", "$", "exportfeedback", ";", "$", "formdata", "->", "export_onlyactive", "=", "$", "onlyactive", ";", "$", "formdata", "->", "display", "=", "self", "::", "convert_flat_displaytypes_to_array", "(", "$", "displaytype", ")", ";", "$", "formdata", "->", "decimals", "=", "$", "decimalpoints", ";", "if", "(", "!", "empty", "(", "$", "updatedgradesonly", ")", ")", "{", "$", "formdata", "->", "updatedgradesonly", "=", "$", "updatedgradesonly", ";", "}", "if", "(", "!", "empty", "(", "$", "separator", ")", ")", "{", "$", "formdata", "->", "separator", "=", "$", "separator", ";", "}", "return", "$", "formdata", ";", "}" ]
Create a stdClass object from URL parameters to be used by grade_export class. @param int $id course id. @param string $itemids grade items comma separated. @param bool $exportfeedback export feedback option. @param bool $onlyactive only enrolled active students. @param string $displaytype grade display type constants comma separated. @param int $decimalpoints grade decimal points. @param null $updatedgradesonly recently updated grades only (Used by XML exporting only). @param null $separator separator character: tab, comma, colon and semicolon (Used by TXT exporting only). @return stdClass $formdata
[ "Create", "a", "stdClass", "object", "from", "URL", "parameters", "to", "be", "used", "by", "grade_export", "class", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/lib.php#L608-L628
219,370
moodle/moodle
grade/export/lib.php
grade_export_update_buffer.track
public function track($grade_grade) { if (empty($grade_grade->exported) or empty($grade_grade->timemodified)) { if (is_null($grade_grade->finalgrade)) { // grade does not exist yet $status = 'unknown'; } else { $status = 'new'; $this->update_list[] = $grade_grade->id; } } else if ($grade_grade->exported < $grade_grade->timemodified) { $status = 'regrade'; $this->update_list[] = $grade_grade->id; } else if ($grade_grade->exported >= $grade_grade->timemodified) { $status = 'nochange'; } else { // something is wrong? $status = 'unknown'; } $this->flush(100); return $status; }
php
public function track($grade_grade) { if (empty($grade_grade->exported) or empty($grade_grade->timemodified)) { if (is_null($grade_grade->finalgrade)) { // grade does not exist yet $status = 'unknown'; } else { $status = 'new'; $this->update_list[] = $grade_grade->id; } } else if ($grade_grade->exported < $grade_grade->timemodified) { $status = 'regrade'; $this->update_list[] = $grade_grade->id; } else if ($grade_grade->exported >= $grade_grade->timemodified) { $status = 'nochange'; } else { // something is wrong? $status = 'unknown'; } $this->flush(100); return $status; }
[ "public", "function", "track", "(", "$", "grade_grade", ")", "{", "if", "(", "empty", "(", "$", "grade_grade", "->", "exported", ")", "or", "empty", "(", "$", "grade_grade", "->", "timemodified", ")", ")", "{", "if", "(", "is_null", "(", "$", "grade_grade", "->", "finalgrade", ")", ")", "{", "// grade does not exist yet", "$", "status", "=", "'unknown'", ";", "}", "else", "{", "$", "status", "=", "'new'", ";", "$", "this", "->", "update_list", "[", "]", "=", "$", "grade_grade", "->", "id", ";", "}", "}", "else", "if", "(", "$", "grade_grade", "->", "exported", "<", "$", "grade_grade", "->", "timemodified", ")", "{", "$", "status", "=", "'regrade'", ";", "$", "this", "->", "update_list", "[", "]", "=", "$", "grade_grade", "->", "id", ";", "}", "else", "if", "(", "$", "grade_grade", "->", "exported", ">=", "$", "grade_grade", "->", "timemodified", ")", "{", "$", "status", "=", "'nochange'", ";", "}", "else", "{", "// something is wrong?", "$", "status", "=", "'unknown'", ";", "}", "$", "this", "->", "flush", "(", "100", ")", ";", "return", "$", "status", ";", "}" ]
Track grade export status @param object $grade_grade @return string $status (unknow, new, regrade, nochange)
[ "Track", "grade", "export", "status" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/lib.php#L675-L701
219,371
moodle/moodle
lib/horde/framework/Horde/Domhtml.php
Horde_Domhtml.getHead
public function getHead() { $head = $this->dom->getElementsByTagName('head'); if ($head->length) { return $head->item(0); } $headelt = $this->dom->createElement('head'); $this->dom->documentElement->insertBefore($headelt, $this->dom->documentElement->firstChild); return $headelt; }
php
public function getHead() { $head = $this->dom->getElementsByTagName('head'); if ($head->length) { return $head->item(0); } $headelt = $this->dom->createElement('head'); $this->dom->documentElement->insertBefore($headelt, $this->dom->documentElement->firstChild); return $headelt; }
[ "public", "function", "getHead", "(", ")", "{", "$", "head", "=", "$", "this", "->", "dom", "->", "getElementsByTagName", "(", "'head'", ")", ";", "if", "(", "$", "head", "->", "length", ")", "{", "return", "$", "head", "->", "item", "(", "0", ")", ";", "}", "$", "headelt", "=", "$", "this", "->", "dom", "->", "createElement", "(", "'head'", ")", ";", "$", "this", "->", "dom", "->", "documentElement", "->", "insertBefore", "(", "$", "headelt", ",", "$", "this", "->", "dom", "->", "documentElement", "->", "firstChild", ")", ";", "return", "$", "headelt", ";", "}" ]
Returns the HEAD element, or creates one if it doesn't exist. @return DOMElement HEAD element.
[ "Returns", "the", "HEAD", "element", "or", "creates", "one", "if", "it", "doesn", "t", "exist", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Domhtml.php#L124-L135
219,372
moodle/moodle
lib/horde/framework/Horde/Domhtml.php
Horde_Domhtml.getBody
public function getBody() { $body = $this->dom->getElementsByTagName('body'); if ($body->length) { return $body->item(0); } $bodyelt = $this->dom->createElement('body'); $this->dom->documentElement->appendChild($bodyelt); return $bodyelt; }
php
public function getBody() { $body = $this->dom->getElementsByTagName('body'); if ($body->length) { return $body->item(0); } $bodyelt = $this->dom->createElement('body'); $this->dom->documentElement->appendChild($bodyelt); return $bodyelt; }
[ "public", "function", "getBody", "(", ")", "{", "$", "body", "=", "$", "this", "->", "dom", "->", "getElementsByTagName", "(", "'body'", ")", ";", "if", "(", "$", "body", "->", "length", ")", "{", "return", "$", "body", "->", "item", "(", "0", ")", ";", "}", "$", "bodyelt", "=", "$", "this", "->", "dom", "->", "createElement", "(", "'body'", ")", ";", "$", "this", "->", "dom", "->", "documentElement", "->", "appendChild", "(", "$", "bodyelt", ")", ";", "return", "$", "bodyelt", ";", "}" ]
Returns the BODY element, or creates one if it doesn't exist. @since 2.2.0 @return DOMElement BODY element.
[ "Returns", "the", "BODY", "element", "or", "creates", "one", "if", "it", "doesn", "t", "exist", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Domhtml.php#L144-L155
219,373
moodle/moodle
lib/horde/framework/Horde/Domhtml.php
Horde_Domhtml.returnHtml
public function returnHtml(array $opts = array()) { $curr_charset = $this->getCharset(); if (strcasecmp($curr_charset, 'US-ASCII') === 0) { $curr_charset = 'UTF-8'; } $charset = array_key_exists('charset', $opts) ? (empty($opts['charset']) ? $curr_charset : $opts['charset']) : $this->_origCharset; if (empty($opts['metacharset'])) { $text = $this->dom->saveHTML(); } else { /* Add placeholder for META tag. Can't add charset yet because DOM * extension will alter output if it exists. */ $meta = $this->dom->createElement('meta'); $meta->setAttribute('http-equiv', 'content-type'); $meta->setAttribute('horde_dom_html_charset', ''); $head = $this->getHead(); $head->insertBefore($meta, $head->firstChild); $text = str_replace( 'horde_dom_html_charset=""', 'content="text/html; charset=' . $charset . '"', $this->dom->saveHTML() ); $head->removeChild($meta); } if (strcasecmp($curr_charset, $charset) !== 0) { $text = Horde_String::convertCharset($text, $curr_charset, $charset); } if (!$this->_xmlencoding || (($pos = strpos($text, $this->_xmlencoding)) === false)) { return $text; } return substr_replace($text, '', $pos, strlen($this->_xmlencoding)); }
php
public function returnHtml(array $opts = array()) { $curr_charset = $this->getCharset(); if (strcasecmp($curr_charset, 'US-ASCII') === 0) { $curr_charset = 'UTF-8'; } $charset = array_key_exists('charset', $opts) ? (empty($opts['charset']) ? $curr_charset : $opts['charset']) : $this->_origCharset; if (empty($opts['metacharset'])) { $text = $this->dom->saveHTML(); } else { /* Add placeholder for META tag. Can't add charset yet because DOM * extension will alter output if it exists. */ $meta = $this->dom->createElement('meta'); $meta->setAttribute('http-equiv', 'content-type'); $meta->setAttribute('horde_dom_html_charset', ''); $head = $this->getHead(); $head->insertBefore($meta, $head->firstChild); $text = str_replace( 'horde_dom_html_charset=""', 'content="text/html; charset=' . $charset . '"', $this->dom->saveHTML() ); $head->removeChild($meta); } if (strcasecmp($curr_charset, $charset) !== 0) { $text = Horde_String::convertCharset($text, $curr_charset, $charset); } if (!$this->_xmlencoding || (($pos = strpos($text, $this->_xmlencoding)) === false)) { return $text; } return substr_replace($text, '', $pos, strlen($this->_xmlencoding)); }
[ "public", "function", "returnHtml", "(", "array", "$", "opts", "=", "array", "(", ")", ")", "{", "$", "curr_charset", "=", "$", "this", "->", "getCharset", "(", ")", ";", "if", "(", "strcasecmp", "(", "$", "curr_charset", ",", "'US-ASCII'", ")", "===", "0", ")", "{", "$", "curr_charset", "=", "'UTF-8'", ";", "}", "$", "charset", "=", "array_key_exists", "(", "'charset'", ",", "$", "opts", ")", "?", "(", "empty", "(", "$", "opts", "[", "'charset'", "]", ")", "?", "$", "curr_charset", ":", "$", "opts", "[", "'charset'", "]", ")", ":", "$", "this", "->", "_origCharset", ";", "if", "(", "empty", "(", "$", "opts", "[", "'metacharset'", "]", ")", ")", "{", "$", "text", "=", "$", "this", "->", "dom", "->", "saveHTML", "(", ")", ";", "}", "else", "{", "/* Add placeholder for META tag. Can't add charset yet because DOM\n * extension will alter output if it exists. */", "$", "meta", "=", "$", "this", "->", "dom", "->", "createElement", "(", "'meta'", ")", ";", "$", "meta", "->", "setAttribute", "(", "'http-equiv'", ",", "'content-type'", ")", ";", "$", "meta", "->", "setAttribute", "(", "'horde_dom_html_charset'", ",", "''", ")", ";", "$", "head", "=", "$", "this", "->", "getHead", "(", ")", ";", "$", "head", "->", "insertBefore", "(", "$", "meta", ",", "$", "head", "->", "firstChild", ")", ";", "$", "text", "=", "str_replace", "(", "'horde_dom_html_charset=\"\"'", ",", "'content=\"text/html; charset='", ".", "$", "charset", ".", "'\"'", ",", "$", "this", "->", "dom", "->", "saveHTML", "(", ")", ")", ";", "$", "head", "->", "removeChild", "(", "$", "meta", ")", ";", "}", "if", "(", "strcasecmp", "(", "$", "curr_charset", ",", "$", "charset", ")", "!==", "0", ")", "{", "$", "text", "=", "Horde_String", "::", "convertCharset", "(", "$", "text", ",", "$", "curr_charset", ",", "$", "charset", ")", ";", "}", "if", "(", "!", "$", "this", "->", "_xmlencoding", "||", "(", "(", "$", "pos", "=", "strpos", "(", "$", "text", ",", "$", "this", "->", "_xmlencoding", ")", ")", "===", "false", ")", ")", "{", "return", "$", "text", ";", "}", "return", "substr_replace", "(", "$", "text", ",", "''", ",", "$", "pos", ",", "strlen", "(", "$", "this", "->", "_xmlencoding", ")", ")", ";", "}" ]
Returns the full HTML text in the original charset. @param array $opts Additional options: (since 2.1.0) - charset: (string) Return using this charset. If set but empty, will return as currently stored in the DOM object. - metacharset: (boolean) If true, will add a META tag containing the charset information. @return string HTML text.
[ "Returns", "the", "full", "HTML", "text", "in", "the", "original", "charset", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Domhtml.php#L168-L209
219,374
moodle/moodle
lib/horde/framework/Horde/Domhtml.php
Horde_Domhtml.returnBody
public function returnBody() { $body = $this->getBody(); $text = ''; if ($body->hasChildNodes()) { foreach ($body->childNodes as $child) { $text .= $this->dom->saveXML($child); } } return Horde_String::convertCharset($text, 'UTF-8', $this->_origCharset); }
php
public function returnBody() { $body = $this->getBody(); $text = ''; if ($body->hasChildNodes()) { foreach ($body->childNodes as $child) { $text .= $this->dom->saveXML($child); } } return Horde_String::convertCharset($text, 'UTF-8', $this->_origCharset); }
[ "public", "function", "returnBody", "(", ")", "{", "$", "body", "=", "$", "this", "->", "getBody", "(", ")", ";", "$", "text", "=", "''", ";", "if", "(", "$", "body", "->", "hasChildNodes", "(", ")", ")", "{", "foreach", "(", "$", "body", "->", "childNodes", "as", "$", "child", ")", "{", "$", "text", ".=", "$", "this", "->", "dom", "->", "saveXML", "(", "$", "child", ")", ";", "}", "}", "return", "Horde_String", "::", "convertCharset", "(", "$", "text", ",", "'UTF-8'", ",", "$", "this", "->", "_origCharset", ")", ";", "}" ]
Returns the body text in the original charset. @return string HTML text.
[ "Returns", "the", "body", "text", "in", "the", "original", "charset", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Domhtml.php#L216-L228
219,375
moodle/moodle
lib/horde/framework/Horde/Domhtml.php
Horde_Domhtml.getCharset
public function getCharset() { return $this->dom->encoding ? $this->dom->encoding : ($this->_xmlencoding ? 'UTF-8' : $this->_origCharset); }
php
public function getCharset() { return $this->dom->encoding ? $this->dom->encoding : ($this->_xmlencoding ? 'UTF-8' : $this->_origCharset); }
[ "public", "function", "getCharset", "(", ")", "{", "return", "$", "this", "->", "dom", "->", "encoding", "?", "$", "this", "->", "dom", "->", "encoding", ":", "(", "$", "this", "->", "_xmlencoding", "?", "'UTF-8'", ":", "$", "this", "->", "_origCharset", ")", ";", "}" ]
Get the charset of the DOM data. @since 2.1.0 @return string Charset of DOM data.
[ "Get", "the", "charset", "of", "the", "DOM", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Domhtml.php#L237-L242
219,376
moodle/moodle
lib/horde/framework/Horde/Domhtml.php
Horde_Domhtml._loadHTML
protected function _loadHTML($html) { if (version_compare(PHP_VERSION, '5.4', '>=')) { $mask = defined('LIBXML_PARSEHUGE') ? LIBXML_PARSEHUGE : 0; $mask |= defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0; $this->dom->loadHTML($html, $mask); } else { $this->dom->loadHTML($html); } }
php
protected function _loadHTML($html) { if (version_compare(PHP_VERSION, '5.4', '>=')) { $mask = defined('LIBXML_PARSEHUGE') ? LIBXML_PARSEHUGE : 0; $mask |= defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0; $this->dom->loadHTML($html, $mask); } else { $this->dom->loadHTML($html); } }
[ "protected", "function", "_loadHTML", "(", "$", "html", ")", "{", "if", "(", "version_compare", "(", "PHP_VERSION", ",", "'5.4'", ",", "'>='", ")", ")", "{", "$", "mask", "=", "defined", "(", "'LIBXML_PARSEHUGE'", ")", "?", "LIBXML_PARSEHUGE", ":", "0", ";", "$", "mask", "|=", "defined", "(", "'LIBXML_COMPACT'", ")", "?", "LIBXML_COMPACT", ":", "0", ";", "$", "this", "->", "dom", "->", "loadHTML", "(", "$", "html", ",", "$", "mask", ")", ";", "}", "else", "{", "$", "this", "->", "dom", "->", "loadHTML", "(", "$", "html", ")", ";", "}", "}" ]
Loads the HTML data. @param string $html HTML data.
[ "Loads", "the", "HTML", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Domhtml.php#L249-L262
219,377
moodle/moodle
lib/moodlelib.php
emoticon_manager.get_emoticons
public function get_emoticons($selectable = false) { global $CFG; $notselectable = ['martin', 'egg']; if (empty($CFG->emoticons)) { return array(); } $emoticons = $this->decode_stored_config($CFG->emoticons); if (!is_array($emoticons)) { // Something is wrong with the format of stored setting. debugging('Invalid format of emoticons setting, please resave the emoticons settings form', DEBUG_NORMAL); return array(); } if ($selectable) { foreach ($emoticons as $index => $emote) { if (in_array($emote->altidentifier, $notselectable)) { // Skip this one. unset($emoticons[$index]); } } } return $emoticons; }
php
public function get_emoticons($selectable = false) { global $CFG; $notselectable = ['martin', 'egg']; if (empty($CFG->emoticons)) { return array(); } $emoticons = $this->decode_stored_config($CFG->emoticons); if (!is_array($emoticons)) { // Something is wrong with the format of stored setting. debugging('Invalid format of emoticons setting, please resave the emoticons settings form', DEBUG_NORMAL); return array(); } if ($selectable) { foreach ($emoticons as $index => $emote) { if (in_array($emote->altidentifier, $notselectable)) { // Skip this one. unset($emoticons[$index]); } } } return $emoticons; }
[ "public", "function", "get_emoticons", "(", "$", "selectable", "=", "false", ")", "{", "global", "$", "CFG", ";", "$", "notselectable", "=", "[", "'martin'", ",", "'egg'", "]", ";", "if", "(", "empty", "(", "$", "CFG", "->", "emoticons", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "emoticons", "=", "$", "this", "->", "decode_stored_config", "(", "$", "CFG", "->", "emoticons", ")", ";", "if", "(", "!", "is_array", "(", "$", "emoticons", ")", ")", "{", "// Something is wrong with the format of stored setting.", "debugging", "(", "'Invalid format of emoticons setting, please resave the emoticons settings form'", ",", "DEBUG_NORMAL", ")", ";", "return", "array", "(", ")", ";", "}", "if", "(", "$", "selectable", ")", "{", "foreach", "(", "$", "emoticons", "as", "$", "index", "=>", "$", "emote", ")", "{", "if", "(", "in_array", "(", "$", "emote", "->", "altidentifier", ",", "$", "notselectable", ")", ")", "{", "// Skip this one.", "unset", "(", "$", "emoticons", "[", "$", "index", "]", ")", ";", "}", "}", "}", "return", "$", "emoticons", ";", "}" ]
Returns the currently enabled emoticons @param boolean $selectable - If true, only return emoticons that should be selectable from a list. @return array of emoticon objects
[ "Returns", "the", "currently", "enabled", "emoticons" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/moodlelib.php#L7392-L7417
219,378
moodle/moodle
lib/moodlelib.php
emoticon_manager.prepare_renderable_emoticon
public function prepare_renderable_emoticon(stdClass $emoticon, array $attributes = array()) { $stringmanager = get_string_manager(); if ($stringmanager->string_exists($emoticon->altidentifier, $emoticon->altcomponent)) { $alt = get_string($emoticon->altidentifier, $emoticon->altcomponent); } else { $alt = s($emoticon->text); } return new pix_emoticon($emoticon->imagename, $alt, $emoticon->imagecomponent, $attributes); }
php
public function prepare_renderable_emoticon(stdClass $emoticon, array $attributes = array()) { $stringmanager = get_string_manager(); if ($stringmanager->string_exists($emoticon->altidentifier, $emoticon->altcomponent)) { $alt = get_string($emoticon->altidentifier, $emoticon->altcomponent); } else { $alt = s($emoticon->text); } return new pix_emoticon($emoticon->imagename, $alt, $emoticon->imagecomponent, $attributes); }
[ "public", "function", "prepare_renderable_emoticon", "(", "stdClass", "$", "emoticon", ",", "array", "$", "attributes", "=", "array", "(", ")", ")", "{", "$", "stringmanager", "=", "get_string_manager", "(", ")", ";", "if", "(", "$", "stringmanager", "->", "string_exists", "(", "$", "emoticon", "->", "altidentifier", ",", "$", "emoticon", "->", "altcomponent", ")", ")", "{", "$", "alt", "=", "get_string", "(", "$", "emoticon", "->", "altidentifier", ",", "$", "emoticon", "->", "altcomponent", ")", ";", "}", "else", "{", "$", "alt", "=", "s", "(", "$", "emoticon", "->", "text", ")", ";", "}", "return", "new", "pix_emoticon", "(", "$", "emoticon", "->", "imagename", ",", "$", "alt", ",", "$", "emoticon", "->", "imagecomponent", ",", "$", "attributes", ")", ";", "}" ]
Converts emoticon object into renderable pix_emoticon object @param stdClass $emoticon emoticon object @param array $attributes explicit HTML attributes to set @return pix_emoticon
[ "Converts", "emoticon", "object", "into", "renderable", "pix_emoticon", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/moodlelib.php#L7426-L7434
219,379
moodle/moodle
lib/moodlelib.php
emoticon_manager.default_emoticons
public function default_emoticons() { return array( $this->prepare_emoticon_object(":-)", 's/smiley', 'smiley'), $this->prepare_emoticon_object(":)", 's/smiley', 'smiley'), $this->prepare_emoticon_object(":-D", 's/biggrin', 'biggrin'), $this->prepare_emoticon_object(";-)", 's/wink', 'wink'), $this->prepare_emoticon_object(":-/", 's/mixed', 'mixed'), $this->prepare_emoticon_object("V-.", 's/thoughtful', 'thoughtful'), $this->prepare_emoticon_object(":-P", 's/tongueout', 'tongueout'), $this->prepare_emoticon_object(":-p", 's/tongueout', 'tongueout'), $this->prepare_emoticon_object("B-)", 's/cool', 'cool'), $this->prepare_emoticon_object("^-)", 's/approve', 'approve'), $this->prepare_emoticon_object("8-)", 's/wideeyes', 'wideeyes'), $this->prepare_emoticon_object(":o)", 's/clown', 'clown'), $this->prepare_emoticon_object(":-(", 's/sad', 'sad'), $this->prepare_emoticon_object(":(", 's/sad', 'sad'), $this->prepare_emoticon_object("8-.", 's/shy', 'shy'), $this->prepare_emoticon_object(":-I", 's/blush', 'blush'), $this->prepare_emoticon_object(":-X", 's/kiss', 'kiss'), $this->prepare_emoticon_object("8-o", 's/surprise', 'surprise'), $this->prepare_emoticon_object("P-|", 's/blackeye', 'blackeye'), $this->prepare_emoticon_object("8-[", 's/angry', 'angry'), $this->prepare_emoticon_object("(grr)", 's/angry', 'angry'), $this->prepare_emoticon_object("xx-P", 's/dead', 'dead'), $this->prepare_emoticon_object("|-.", 's/sleepy', 'sleepy'), $this->prepare_emoticon_object("}-]", 's/evil', 'evil'), $this->prepare_emoticon_object("(h)", 's/heart', 'heart'), $this->prepare_emoticon_object("(heart)", 's/heart', 'heart'), $this->prepare_emoticon_object("(y)", 's/yes', 'yes', 'core'), $this->prepare_emoticon_object("(n)", 's/no', 'no', 'core'), $this->prepare_emoticon_object("(martin)", 's/martin', 'martin'), $this->prepare_emoticon_object("( )", 's/egg', 'egg'), ); }
php
public function default_emoticons() { return array( $this->prepare_emoticon_object(":-)", 's/smiley', 'smiley'), $this->prepare_emoticon_object(":)", 's/smiley', 'smiley'), $this->prepare_emoticon_object(":-D", 's/biggrin', 'biggrin'), $this->prepare_emoticon_object(";-)", 's/wink', 'wink'), $this->prepare_emoticon_object(":-/", 's/mixed', 'mixed'), $this->prepare_emoticon_object("V-.", 's/thoughtful', 'thoughtful'), $this->prepare_emoticon_object(":-P", 's/tongueout', 'tongueout'), $this->prepare_emoticon_object(":-p", 's/tongueout', 'tongueout'), $this->prepare_emoticon_object("B-)", 's/cool', 'cool'), $this->prepare_emoticon_object("^-)", 's/approve', 'approve'), $this->prepare_emoticon_object("8-)", 's/wideeyes', 'wideeyes'), $this->prepare_emoticon_object(":o)", 's/clown', 'clown'), $this->prepare_emoticon_object(":-(", 's/sad', 'sad'), $this->prepare_emoticon_object(":(", 's/sad', 'sad'), $this->prepare_emoticon_object("8-.", 's/shy', 'shy'), $this->prepare_emoticon_object(":-I", 's/blush', 'blush'), $this->prepare_emoticon_object(":-X", 's/kiss', 'kiss'), $this->prepare_emoticon_object("8-o", 's/surprise', 'surprise'), $this->prepare_emoticon_object("P-|", 's/blackeye', 'blackeye'), $this->prepare_emoticon_object("8-[", 's/angry', 'angry'), $this->prepare_emoticon_object("(grr)", 's/angry', 'angry'), $this->prepare_emoticon_object("xx-P", 's/dead', 'dead'), $this->prepare_emoticon_object("|-.", 's/sleepy', 'sleepy'), $this->prepare_emoticon_object("}-]", 's/evil', 'evil'), $this->prepare_emoticon_object("(h)", 's/heart', 'heart'), $this->prepare_emoticon_object("(heart)", 's/heart', 'heart'), $this->prepare_emoticon_object("(y)", 's/yes', 'yes', 'core'), $this->prepare_emoticon_object("(n)", 's/no', 'no', 'core'), $this->prepare_emoticon_object("(martin)", 's/martin', 'martin'), $this->prepare_emoticon_object("( )", 's/egg', 'egg'), ); }
[ "public", "function", "default_emoticons", "(", ")", "{", "return", "array", "(", "$", "this", "->", "prepare_emoticon_object", "(", "\":-)\"", ",", "'s/smiley'", ",", "'smiley'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\":)\"", ",", "'s/smiley'", ",", "'smiley'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\":-D\"", ",", "'s/biggrin'", ",", "'biggrin'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\";-)\"", ",", "'s/wink'", ",", "'wink'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\":-/\"", ",", "'s/mixed'", ",", "'mixed'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"V-.\"", ",", "'s/thoughtful'", ",", "'thoughtful'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\":-P\"", ",", "'s/tongueout'", ",", "'tongueout'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\":-p\"", ",", "'s/tongueout'", ",", "'tongueout'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"B-)\"", ",", "'s/cool'", ",", "'cool'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"^-)\"", ",", "'s/approve'", ",", "'approve'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"8-)\"", ",", "'s/wideeyes'", ",", "'wideeyes'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\":o)\"", ",", "'s/clown'", ",", "'clown'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\":-(\"", ",", "'s/sad'", ",", "'sad'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\":(\"", ",", "'s/sad'", ",", "'sad'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"8-.\"", ",", "'s/shy'", ",", "'shy'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\":-I\"", ",", "'s/blush'", ",", "'blush'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\":-X\"", ",", "'s/kiss'", ",", "'kiss'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"8-o\"", ",", "'s/surprise'", ",", "'surprise'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"P-|\"", ",", "'s/blackeye'", ",", "'blackeye'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"8-[\"", ",", "'s/angry'", ",", "'angry'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"(grr)\"", ",", "'s/angry'", ",", "'angry'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"xx-P\"", ",", "'s/dead'", ",", "'dead'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"|-.\"", ",", "'s/sleepy'", ",", "'sleepy'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"}-]\"", ",", "'s/evil'", ",", "'evil'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"(h)\"", ",", "'s/heart'", ",", "'heart'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"(heart)\"", ",", "'s/heart'", ",", "'heart'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"(y)\"", ",", "'s/yes'", ",", "'yes'", ",", "'core'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"(n)\"", ",", "'s/no'", ",", "'no'", ",", "'core'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"(martin)\"", ",", "'s/martin'", ",", "'martin'", ")", ",", "$", "this", "->", "prepare_emoticon_object", "(", "\"( )\"", ",", "'s/egg'", ",", "'egg'", ")", ",", ")", ";", "}" ]
Returns default set of emoticons supported by Moodle @return array of sdtClasses
[ "Returns", "default", "set", "of", "emoticons", "supported", "by", "Moodle" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/moodlelib.php#L7467-L7500
219,380
moodle/moodle
lib/moodlelib.php
emoticon_manager.prepare_emoticon_object
protected function prepare_emoticon_object($text, $imagename, $altidentifier = null, $altcomponent = 'core_pix', $imagecomponent = 'core') { return (object)array( 'text' => $text, 'imagename' => $imagename, 'imagecomponent' => $imagecomponent, 'altidentifier' => $altidentifier, 'altcomponent' => $altcomponent, ); }
php
protected function prepare_emoticon_object($text, $imagename, $altidentifier = null, $altcomponent = 'core_pix', $imagecomponent = 'core') { return (object)array( 'text' => $text, 'imagename' => $imagename, 'imagecomponent' => $imagecomponent, 'altidentifier' => $altidentifier, 'altcomponent' => $altcomponent, ); }
[ "protected", "function", "prepare_emoticon_object", "(", "$", "text", ",", "$", "imagename", ",", "$", "altidentifier", "=", "null", ",", "$", "altcomponent", "=", "'core_pix'", ",", "$", "imagecomponent", "=", "'core'", ")", "{", "return", "(", "object", ")", "array", "(", "'text'", "=>", "$", "text", ",", "'imagename'", "=>", "$", "imagename", ",", "'imagecomponent'", "=>", "$", "imagecomponent", ",", "'altidentifier'", "=>", "$", "altidentifier", ",", "'altcomponent'", "=>", "$", "altcomponent", ",", ")", ";", "}" ]
Helper method preparing the stdClass with the emoticon properties @param string|array $text or array of strings @param string $imagename to be used by {@link pix_emoticon} @param string $altidentifier alternative string identifier, null for no alt @param string $altcomponent where the alternative string is defined @param string $imagecomponent to be used by {@link pix_emoticon} @return stdClass
[ "Helper", "method", "preparing", "the", "stdClass", "with", "the", "emoticon", "properties" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/moodlelib.php#L7512-L7521
219,381
moodle/moodle
lib/moodlelib.php
lang_string.get_string
protected function get_string() { global $CFG; // Check if we need to process the string. if ($this->string === null) { // Check the quality of the identifier. if ($CFG->debugdeveloper && clean_param($this->identifier, PARAM_STRINGID) === '') { throw new coding_exception('Invalid string identifier. Most probably some illegal character is part of the string identifier. Please check your string definition', DEBUG_DEVELOPER); } // Process the string. $this->string = get_string_manager()->get_string($this->identifier, $this->component, $this->a, $this->lang); // Debugging feature lets you display string identifier and component. if (isset($CFG->debugstringids) && $CFG->debugstringids && optional_param('strings', 0, PARAM_INT)) { $this->string .= ' {' . $this->identifier . '/' . $this->component . '}'; } } // Return the string. return $this->string; }
php
protected function get_string() { global $CFG; // Check if we need to process the string. if ($this->string === null) { // Check the quality of the identifier. if ($CFG->debugdeveloper && clean_param($this->identifier, PARAM_STRINGID) === '') { throw new coding_exception('Invalid string identifier. Most probably some illegal character is part of the string identifier. Please check your string definition', DEBUG_DEVELOPER); } // Process the string. $this->string = get_string_manager()->get_string($this->identifier, $this->component, $this->a, $this->lang); // Debugging feature lets you display string identifier and component. if (isset($CFG->debugstringids) && $CFG->debugstringids && optional_param('strings', 0, PARAM_INT)) { $this->string .= ' {' . $this->identifier . '/' . $this->component . '}'; } } // Return the string. return $this->string; }
[ "protected", "function", "get_string", "(", ")", "{", "global", "$", "CFG", ";", "// Check if we need to process the string.", "if", "(", "$", "this", "->", "string", "===", "null", ")", "{", "// Check the quality of the identifier.", "if", "(", "$", "CFG", "->", "debugdeveloper", "&&", "clean_param", "(", "$", "this", "->", "identifier", ",", "PARAM_STRINGID", ")", "===", "''", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid string identifier. Most probably some illegal character is part of the string identifier. Please check your string definition'", ",", "DEBUG_DEVELOPER", ")", ";", "}", "// Process the string.", "$", "this", "->", "string", "=", "get_string_manager", "(", ")", "->", "get_string", "(", "$", "this", "->", "identifier", ",", "$", "this", "->", "component", ",", "$", "this", "->", "a", ",", "$", "this", "->", "lang", ")", ";", "// Debugging feature lets you display string identifier and component.", "if", "(", "isset", "(", "$", "CFG", "->", "debugstringids", ")", "&&", "$", "CFG", "->", "debugstringids", "&&", "optional_param", "(", "'strings'", ",", "0", ",", "PARAM_INT", ")", ")", "{", "$", "this", "->", "string", ".=", "' {'", ".", "$", "this", "->", "identifier", ".", "'/'", ".", "$", "this", "->", "component", ".", "'}'", ";", "}", "}", "// Return the string.", "return", "$", "this", "->", "string", ";", "}" ]
Processes the string. This function actually processes the string, stores it in the string property and then returns it. You will notice that this function is VERY similar to the get_string method. That is because it is pretty much doing the same thing. However as this function is an upgrade it isn't as tolerant to backwards compatibility. @return string @throws coding_exception
[ "Processes", "the", "string", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/moodlelib.php#L10227-L10246
219,382
moodle/moodle
lib/moodlelib.php
lang_string.out
public function out($lang = null) { if ($lang !== null && $lang != $this->lang && ($this->lang == null && $lang != current_language())) { if ($this->forcedstring) { debugging('lang_string objects that have been used cannot be printed in another language. ('.$this->lang.' used)', DEBUG_DEVELOPER); return $this->get_string(); } $translatedstring = new lang_string($this->identifier, $this->component, $this->a, $lang); return $translatedstring->out(); } return $this->get_string(); }
php
public function out($lang = null) { if ($lang !== null && $lang != $this->lang && ($this->lang == null && $lang != current_language())) { if ($this->forcedstring) { debugging('lang_string objects that have been used cannot be printed in another language. ('.$this->lang.' used)', DEBUG_DEVELOPER); return $this->get_string(); } $translatedstring = new lang_string($this->identifier, $this->component, $this->a, $lang); return $translatedstring->out(); } return $this->get_string(); }
[ "public", "function", "out", "(", "$", "lang", "=", "null", ")", "{", "if", "(", "$", "lang", "!==", "null", "&&", "$", "lang", "!=", "$", "this", "->", "lang", "&&", "(", "$", "this", "->", "lang", "==", "null", "&&", "$", "lang", "!=", "current_language", "(", ")", ")", ")", "{", "if", "(", "$", "this", "->", "forcedstring", ")", "{", "debugging", "(", "'lang_string objects that have been used cannot be printed in another language. ('", ".", "$", "this", "->", "lang", ".", "' used)'", ",", "DEBUG_DEVELOPER", ")", ";", "return", "$", "this", "->", "get_string", "(", ")", ";", "}", "$", "translatedstring", "=", "new", "lang_string", "(", "$", "this", "->", "identifier", ",", "$", "this", "->", "component", ",", "$", "this", "->", "a", ",", "$", "lang", ")", ";", "return", "$", "translatedstring", "->", "out", "(", ")", ";", "}", "return", "$", "this", "->", "get_string", "(", ")", ";", "}" ]
Returns the string @param string $lang The langauge to use when processing the string @return string
[ "Returns", "the", "string" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/moodlelib.php#L10254-L10264
219,383
moodle/moodle
admin/tool/monitor/classes/eventobservers.php
eventobservers.course_deleted
public static function course_deleted(\core\event\course_deleted $event) { // Delete rules defined inside this course and associated subscriptions. $rules = rule_manager::get_rules_by_courseid($event->courseid, 0, 0, false); foreach ($rules as $rule) { rule_manager::delete_rule($rule->id, $event->get_context()); } // Delete remaining subscriptions inside this course (from site-wide rules). subscription_manager::remove_all_subscriptions_in_course($event->get_context()); }
php
public static function course_deleted(\core\event\course_deleted $event) { // Delete rules defined inside this course and associated subscriptions. $rules = rule_manager::get_rules_by_courseid($event->courseid, 0, 0, false); foreach ($rules as $rule) { rule_manager::delete_rule($rule->id, $event->get_context()); } // Delete remaining subscriptions inside this course (from site-wide rules). subscription_manager::remove_all_subscriptions_in_course($event->get_context()); }
[ "public", "static", "function", "course_deleted", "(", "\\", "core", "\\", "event", "\\", "course_deleted", "$", "event", ")", "{", "// Delete rules defined inside this course and associated subscriptions.", "$", "rules", "=", "rule_manager", "::", "get_rules_by_courseid", "(", "$", "event", "->", "courseid", ",", "0", ",", "0", ",", "false", ")", ";", "foreach", "(", "$", "rules", "as", "$", "rule", ")", "{", "rule_manager", "::", "delete_rule", "(", "$", "rule", "->", "id", ",", "$", "event", "->", "get_context", "(", ")", ")", ";", "}", "// Delete remaining subscriptions inside this course (from site-wide rules).", "subscription_manager", "::", "remove_all_subscriptions_in_course", "(", "$", "event", "->", "get_context", "(", ")", ")", ";", "}" ]
Course delete event observer. This observer monitors course delete event, and when a course is deleted it deletes any rules and subscriptions associated with it, so no orphan data is left behind. @param \core\event\course_deleted $event The course deleted event.
[ "Course", "delete", "event", "observer", ".", "This", "observer", "monitors", "course", "delete", "event", "and", "when", "a", "course", "is", "deleted", "it", "deletes", "any", "rules", "and", "subscriptions", "associated", "with", "it", "so", "no", "orphan", "data", "is", "left", "behind", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/eventobservers.php#L55-L63
219,384
moodle/moodle
admin/tool/monitor/classes/eventobservers.php
eventobservers.process_event
public static function process_event(\core\event\base $event) { if (!get_config('tool_monitor', 'enablemonitor')) { return; // The tool is disabled. Nothing to do. } if (empty(self::$instance)) { self::$instance = new static(); // Register shutdown handler - this is useful for buffering, processing events, etc. \core_shutdown_manager::register_function(array(self::$instance, 'process_buffer')); } self::$instance->buffer_event($event); if (PHPUNIT_TEST) { // Process buffer after every event when unit testing. self::$instance->process_buffer(); } }
php
public static function process_event(\core\event\base $event) { if (!get_config('tool_monitor', 'enablemonitor')) { return; // The tool is disabled. Nothing to do. } if (empty(self::$instance)) { self::$instance = new static(); // Register shutdown handler - this is useful for buffering, processing events, etc. \core_shutdown_manager::register_function(array(self::$instance, 'process_buffer')); } self::$instance->buffer_event($event); if (PHPUNIT_TEST) { // Process buffer after every event when unit testing. self::$instance->process_buffer(); } }
[ "public", "static", "function", "process_event", "(", "\\", "core", "\\", "event", "\\", "base", "$", "event", ")", "{", "if", "(", "!", "get_config", "(", "'tool_monitor'", ",", "'enablemonitor'", ")", ")", "{", "return", ";", "// The tool is disabled. Nothing to do.", "}", "if", "(", "empty", "(", "self", "::", "$", "instance", ")", ")", "{", "self", "::", "$", "instance", "=", "new", "static", "(", ")", ";", "// Register shutdown handler - this is useful for buffering, processing events, etc.", "\\", "core_shutdown_manager", "::", "register_function", "(", "array", "(", "self", "::", "$", "instance", ",", "'process_buffer'", ")", ")", ";", "}", "self", "::", "$", "instance", "->", "buffer_event", "(", "$", "event", ")", ";", "if", "(", "PHPUNIT_TEST", ")", "{", "// Process buffer after every event when unit testing.", "self", "::", "$", "instance", "->", "process_buffer", "(", ")", ";", "}", "}" ]
The observer monitoring all the events. This observers puts small event objects in buffer for later writing to the database. At the end of the request the buffer is cleaned up and all data dumped into the tool_monitor_events table. @param \core\event\base $event event object
[ "The", "observer", "monitoring", "all", "the", "events", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/eventobservers.php#L73-L91
219,385
moodle/moodle
admin/tool/monitor/classes/eventobservers.php
eventobservers.buffer_event
protected function buffer_event(\core\event\base $event) { // If there are no subscriptions for this event do not buffer it. if (!\tool_monitor\subscription_manager::event_has_subscriptions($event->eventname, $event->courseid)) { return; } $eventdata = $event->get_data(); $eventobj = new \stdClass(); $eventobj->eventname = $eventdata['eventname']; $eventobj->contextid = $eventdata['contextid']; $eventobj->contextlevel = $eventdata['contextlevel']; $eventobj->contextinstanceid = $eventdata['contextinstanceid']; if ($event->get_url()) { // Get link url if exists. $eventobj->link = $event->get_url()->out(); } else { $eventobj->link = ''; } $eventobj->courseid = $eventdata['courseid']; $eventobj->timecreated = $eventdata['timecreated']; $this->buffer[] = $eventobj; $this->count++; }
php
protected function buffer_event(\core\event\base $event) { // If there are no subscriptions for this event do not buffer it. if (!\tool_monitor\subscription_manager::event_has_subscriptions($event->eventname, $event->courseid)) { return; } $eventdata = $event->get_data(); $eventobj = new \stdClass(); $eventobj->eventname = $eventdata['eventname']; $eventobj->contextid = $eventdata['contextid']; $eventobj->contextlevel = $eventdata['contextlevel']; $eventobj->contextinstanceid = $eventdata['contextinstanceid']; if ($event->get_url()) { // Get link url if exists. $eventobj->link = $event->get_url()->out(); } else { $eventobj->link = ''; } $eventobj->courseid = $eventdata['courseid']; $eventobj->timecreated = $eventdata['timecreated']; $this->buffer[] = $eventobj; $this->count++; }
[ "protected", "function", "buffer_event", "(", "\\", "core", "\\", "event", "\\", "base", "$", "event", ")", "{", "// If there are no subscriptions for this event do not buffer it.", "if", "(", "!", "\\", "tool_monitor", "\\", "subscription_manager", "::", "event_has_subscriptions", "(", "$", "event", "->", "eventname", ",", "$", "event", "->", "courseid", ")", ")", "{", "return", ";", "}", "$", "eventdata", "=", "$", "event", "->", "get_data", "(", ")", ";", "$", "eventobj", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "eventobj", "->", "eventname", "=", "$", "eventdata", "[", "'eventname'", "]", ";", "$", "eventobj", "->", "contextid", "=", "$", "eventdata", "[", "'contextid'", "]", ";", "$", "eventobj", "->", "contextlevel", "=", "$", "eventdata", "[", "'contextlevel'", "]", ";", "$", "eventobj", "->", "contextinstanceid", "=", "$", "eventdata", "[", "'contextinstanceid'", "]", ";", "if", "(", "$", "event", "->", "get_url", "(", ")", ")", "{", "// Get link url if exists.", "$", "eventobj", "->", "link", "=", "$", "event", "->", "get_url", "(", ")", "->", "out", "(", ")", ";", "}", "else", "{", "$", "eventobj", "->", "link", "=", "''", ";", "}", "$", "eventobj", "->", "courseid", "=", "$", "eventdata", "[", "'courseid'", "]", ";", "$", "eventobj", "->", "timecreated", "=", "$", "eventdata", "[", "'timecreated'", "]", ";", "$", "this", "->", "buffer", "[", "]", "=", "$", "eventobj", ";", "$", "this", "->", "count", "++", ";", "}" ]
Api to buffer events to store, to reduce db queries. @param \core\event\base $event
[ "Api", "to", "buffer", "events", "to", "store", "to", "reduce", "db", "queries", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/eventobservers.php#L98-L122
219,386
moodle/moodle
admin/tool/monitor/classes/eventobservers.php
eventobservers.flush
protected function flush() { global $DB; // Flush the buffer to the db. $events = $this->buffer; $DB->insert_records('tool_monitor_events', $events); // Insert the whole chunk into the database. $this->buffer = array(); $this->count = 0; return $events; }
php
protected function flush() { global $DB; // Flush the buffer to the db. $events = $this->buffer; $DB->insert_records('tool_monitor_events', $events); // Insert the whole chunk into the database. $this->buffer = array(); $this->count = 0; return $events; }
[ "protected", "function", "flush", "(", ")", "{", "global", "$", "DB", ";", "// Flush the buffer to the db.", "$", "events", "=", "$", "this", "->", "buffer", ";", "$", "DB", "->", "insert_records", "(", "'tool_monitor_events'", ",", "$", "events", ")", ";", "// Insert the whole chunk into the database.", "$", "this", "->", "buffer", "=", "array", "(", ")", ";", "$", "this", "->", "count", "=", "0", ";", "return", "$", "events", ";", "}" ]
Protected method that flushes the buffer of events and writes them to the database. @return array a copy of the events buffer.
[ "Protected", "method", "that", "flushes", "the", "buffer", "of", "events", "and", "writes", "them", "to", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/eventobservers.php#L230-L239
219,387
moodle/moodle
admin/tool/monitor/classes/eventobservers.php
eventobservers.user_deleted
public static function user_deleted(\core\event\user_deleted $event) { $userid = $event->objectid; subscription_manager::delete_user_subscriptions($userid); }
php
public static function user_deleted(\core\event\user_deleted $event) { $userid = $event->objectid; subscription_manager::delete_user_subscriptions($userid); }
[ "public", "static", "function", "user_deleted", "(", "\\", "core", "\\", "event", "\\", "user_deleted", "$", "event", ")", "{", "$", "userid", "=", "$", "event", "->", "objectid", ";", "subscription_manager", "::", "delete_user_subscriptions", "(", "$", "userid", ")", ";", "}" ]
Observer that monitors user deleted event and delete user subscriptions. @param \core\event\user_deleted $event the event object.
[ "Observer", "that", "monitors", "user", "deleted", "event", "and", "delete", "user", "subscriptions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/eventobservers.php#L246-L249
219,388
moodle/moodle
admin/tool/monitor/classes/eventobservers.php
eventobservers.course_module_deleted
public static function course_module_deleted(\core\event\course_module_deleted $event) { $cmid = $event->contextinstanceid; subscription_manager::delete_cm_subscriptions($cmid); }
php
public static function course_module_deleted(\core\event\course_module_deleted $event) { $cmid = $event->contextinstanceid; subscription_manager::delete_cm_subscriptions($cmid); }
[ "public", "static", "function", "course_module_deleted", "(", "\\", "core", "\\", "event", "\\", "course_module_deleted", "$", "event", ")", "{", "$", "cmid", "=", "$", "event", "->", "contextinstanceid", ";", "subscription_manager", "::", "delete_cm_subscriptions", "(", "$", "cmid", ")", ";", "}" ]
Observer that monitors course module deleted event and delete user subscriptions. @param \core\event\course_module_deleted $event the event object.
[ "Observer", "that", "monitors", "course", "module", "deleted", "event", "and", "delete", "user", "subscriptions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/eventobservers.php#L256-L259
219,389
moodle/moodle
grade/grading/form/guide/lib.php
gradingform_guide_controller.extend_settings_navigation
public function extend_settings_navigation(settings_navigation $settingsnav, navigation_node $node=null) { $node->add(get_string('definemarkingguide', 'gradingform_guide'), $this->get_editor_url(), settings_navigation::TYPE_CUSTOM, null, null, new pix_icon('icon', '', 'gradingform_guide')); }
php
public function extend_settings_navigation(settings_navigation $settingsnav, navigation_node $node=null) { $node->add(get_string('definemarkingguide', 'gradingform_guide'), $this->get_editor_url(), settings_navigation::TYPE_CUSTOM, null, null, new pix_icon('icon', '', 'gradingform_guide')); }
[ "public", "function", "extend_settings_navigation", "(", "settings_navigation", "$", "settingsnav", ",", "navigation_node", "$", "node", "=", "null", ")", "{", "$", "node", "->", "add", "(", "get_string", "(", "'definemarkingguide'", ",", "'gradingform_guide'", ")", ",", "$", "this", "->", "get_editor_url", "(", ")", ",", "settings_navigation", "::", "TYPE_CUSTOM", ",", "null", ",", "null", ",", "new", "pix_icon", "(", "'icon'", ",", "''", ",", "'gradingform_guide'", ")", ")", ";", "}" ]
Extends the module settings navigation with the guide grading settings This function is called when the context for the page is an activity module with the FEATURE_ADVANCED_GRADING, the user has the permission moodle/grade:managegradingforms and there is an area with the active grading method set to 'guide'. @param settings_navigation $settingsnav {@link settings_navigation} @param navigation_node $node {@link navigation_node}
[ "Extends", "the", "module", "settings", "navigation", "with", "the", "guide", "grading", "settings" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/lib.php#L68-L72
219,390
moodle/moodle
grade/grading/form/guide/lib.php
gradingform_guide_controller.extend_navigation
public function extend_navigation(global_navigation $navigation, navigation_node $node=null) { if (has_capability('moodle/grade:managegradingforms', $this->get_context())) { // No need for preview if user can manage forms, he will have link to manage.php in settings instead. return; } if ($this->is_form_defined() && ($options = $this->get_options()) && !empty($options['alwaysshowdefinition'])) { $node->add(get_string('gradingof', 'gradingform_guide', get_grading_manager($this->get_areaid())->get_area_title()), new moodle_url('/grade/grading/form/'.$this->get_method_name().'/preview.php', array('areaid' => $this->get_areaid())), settings_navigation::TYPE_CUSTOM); } }
php
public function extend_navigation(global_navigation $navigation, navigation_node $node=null) { if (has_capability('moodle/grade:managegradingforms', $this->get_context())) { // No need for preview if user can manage forms, he will have link to manage.php in settings instead. return; } if ($this->is_form_defined() && ($options = $this->get_options()) && !empty($options['alwaysshowdefinition'])) { $node->add(get_string('gradingof', 'gradingform_guide', get_grading_manager($this->get_areaid())->get_area_title()), new moodle_url('/grade/grading/form/'.$this->get_method_name().'/preview.php', array('areaid' => $this->get_areaid())), settings_navigation::TYPE_CUSTOM); } }
[ "public", "function", "extend_navigation", "(", "global_navigation", "$", "navigation", ",", "navigation_node", "$", "node", "=", "null", ")", "{", "if", "(", "has_capability", "(", "'moodle/grade:managegradingforms'", ",", "$", "this", "->", "get_context", "(", ")", ")", ")", "{", "// No need for preview if user can manage forms, he will have link to manage.php in settings instead.", "return", ";", "}", "if", "(", "$", "this", "->", "is_form_defined", "(", ")", "&&", "(", "$", "options", "=", "$", "this", "->", "get_options", "(", ")", ")", "&&", "!", "empty", "(", "$", "options", "[", "'alwaysshowdefinition'", "]", ")", ")", "{", "$", "node", "->", "add", "(", "get_string", "(", "'gradingof'", ",", "'gradingform_guide'", ",", "get_grading_manager", "(", "$", "this", "->", "get_areaid", "(", ")", ")", "->", "get_area_title", "(", ")", ")", ",", "new", "moodle_url", "(", "'/grade/grading/form/'", ".", "$", "this", "->", "get_method_name", "(", ")", ".", "'/preview.php'", ",", "array", "(", "'areaid'", "=>", "$", "this", "->", "get_areaid", "(", ")", ")", ")", ",", "settings_navigation", "::", "TYPE_CUSTOM", ")", ";", "}", "}" ]
Extends the module navigation This function is called when the context for the page is an activity module with the FEATURE_ADVANCED_GRADING and there is an area with the active grading method set to the given plugin. @param global_navigation $navigation {@link global_navigation} @param navigation_node $node {@link navigation_node} @return void
[ "Extends", "the", "module", "navigation" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/lib.php#L84-L94
219,391
moodle/moodle
grade/grading/form/guide/lib.php
gradingform_guide_controller.update_definition
public function update_definition(stdClass $newdefinition, $usermodified = null) { $this->update_or_check_guide($newdefinition, $usermodified, true); if (isset($newdefinition->guide['regrade']) && $newdefinition->guide['regrade']) { $this->mark_for_regrade(); } }
php
public function update_definition(stdClass $newdefinition, $usermodified = null) { $this->update_or_check_guide($newdefinition, $usermodified, true); if (isset($newdefinition->guide['regrade']) && $newdefinition->guide['regrade']) { $this->mark_for_regrade(); } }
[ "public", "function", "update_definition", "(", "stdClass", "$", "newdefinition", ",", "$", "usermodified", "=", "null", ")", "{", "$", "this", "->", "update_or_check_guide", "(", "$", "newdefinition", ",", "$", "usermodified", ",", "true", ")", ";", "if", "(", "isset", "(", "$", "newdefinition", "->", "guide", "[", "'regrade'", "]", ")", "&&", "$", "newdefinition", "->", "guide", "[", "'regrade'", "]", ")", "{", "$", "this", "->", "mark_for_regrade", "(", ")", ";", "}", "}" ]
Saves the guide definition into the database @see parent::update_definition() @param stdClass $newdefinition guide definition data as coming from gradingform_guide_editguide::get_data() @param int $usermodified optional userid of the author of the definition, defaults to the current user
[ "Saves", "the", "guide", "definition", "into", "the", "database" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/lib.php#L103-L108
219,392
moodle/moodle
grade/grading/form/guide/lib.php
gradingform_guide_controller.mark_for_regrade
public function mark_for_regrade() { global $DB; if ($this->has_active_instances()) { $conditions = array('definitionid' => $this->definition->id, 'status' => gradingform_instance::INSTANCE_STATUS_ACTIVE); $DB->set_field('grading_instances', 'status', gradingform_instance::INSTANCE_STATUS_NEEDUPDATE, $conditions); } }
php
public function mark_for_regrade() { global $DB; if ($this->has_active_instances()) { $conditions = array('definitionid' => $this->definition->id, 'status' => gradingform_instance::INSTANCE_STATUS_ACTIVE); $DB->set_field('grading_instances', 'status', gradingform_instance::INSTANCE_STATUS_NEEDUPDATE, $conditions); } }
[ "public", "function", "mark_for_regrade", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "has_active_instances", "(", ")", ")", "{", "$", "conditions", "=", "array", "(", "'definitionid'", "=>", "$", "this", "->", "definition", "->", "id", ",", "'status'", "=>", "gradingform_instance", "::", "INSTANCE_STATUS_ACTIVE", ")", ";", "$", "DB", "->", "set_field", "(", "'grading_instances'", ",", "'status'", ",", "gradingform_instance", "::", "INSTANCE_STATUS_NEEDUPDATE", ",", "$", "conditions", ")", ";", "}", "}" ]
Marks all instances filled with this guide with the status INSTANCE_STATUS_NEEDUPDATE
[ "Marks", "all", "instances", "filled", "with", "this", "guide", "with", "the", "status", "INSTANCE_STATUS_NEEDUPDATE" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/lib.php#L282-L289
219,393
moodle/moodle
grade/grading/form/guide/lib.php
gradingform_guide_controller.load_definition
protected function load_definition() { global $DB; // Check to see if the user prefs have changed - putting here as this function is called on post even when // validation on the page fails. - hard to find a better place to locate this as it is specific to the guide. $showdesc = optional_param('showmarkerdesc', null, PARAM_BOOL); // Check if we need to change pref. $showdescstudent = optional_param('showstudentdesc', null, PARAM_BOOL); // Check if we need to change pref. if ($showdesc !== null) { set_user_preference('gradingform_guide-showmarkerdesc', $showdesc); } if ($showdescstudent !== null) { set_user_preference('gradingform_guide-showstudentdesc', $showdescstudent); } // Get definition. $definition = $DB->get_record('grading_definitions', array('areaid' => $this->areaid, 'method' => $this->get_method_name()), '*'); if (!$definition) { // The definition doesn't have to exist. It may be that we are only now creating it. $this->definition = false; return false; } $this->definition = $definition; // Now get criteria. $this->definition->guide_criteria = array(); $this->definition->guide_comments = array(); $criteria = $DB->get_recordset('gradingform_guide_criteria', array('definitionid' => $this->definition->id), 'sortorder'); foreach ($criteria as $criterion) { foreach (array('id', 'sortorder', 'description', 'descriptionformat', 'maxscore', 'descriptionmarkers', 'descriptionmarkersformat', 'shortname') as $fieldname) { if ($fieldname == 'maxscore') { // Strip any trailing 0. $this->definition->guide_criteria[$criterion->id][$fieldname] = (float)$criterion->{$fieldname}; } else { $this->definition->guide_criteria[$criterion->id][$fieldname] = $criterion->{$fieldname}; } } } $criteria->close(); // Now get comments. $comments = $DB->get_recordset('gradingform_guide_comments', array('definitionid' => $this->definition->id), 'sortorder'); foreach ($comments as $comment) { foreach (array('id', 'sortorder', 'description', 'descriptionformat') as $fieldname) { $this->definition->guide_comments[$comment->id][$fieldname] = $comment->{$fieldname}; } } $comments->close(); if (empty($this->moduleinstance)) { // Only set if empty. $modulename = $this->get_component(); $context = $this->get_context(); if (strpos($modulename, 'mod_') === 0) { $dbman = $DB->get_manager(); $modulename = substr($modulename, 4); if ($dbman->table_exists($modulename)) { $cm = get_coursemodule_from_id($modulename, $context->instanceid); if (!empty($cm)) { // This should only occur when the course is being deleted. $this->moduleinstance = $DB->get_record($modulename, array("id"=>$cm->instance)); } } } } }
php
protected function load_definition() { global $DB; // Check to see if the user prefs have changed - putting here as this function is called on post even when // validation on the page fails. - hard to find a better place to locate this as it is specific to the guide. $showdesc = optional_param('showmarkerdesc', null, PARAM_BOOL); // Check if we need to change pref. $showdescstudent = optional_param('showstudentdesc', null, PARAM_BOOL); // Check if we need to change pref. if ($showdesc !== null) { set_user_preference('gradingform_guide-showmarkerdesc', $showdesc); } if ($showdescstudent !== null) { set_user_preference('gradingform_guide-showstudentdesc', $showdescstudent); } // Get definition. $definition = $DB->get_record('grading_definitions', array('areaid' => $this->areaid, 'method' => $this->get_method_name()), '*'); if (!$definition) { // The definition doesn't have to exist. It may be that we are only now creating it. $this->definition = false; return false; } $this->definition = $definition; // Now get criteria. $this->definition->guide_criteria = array(); $this->definition->guide_comments = array(); $criteria = $DB->get_recordset('gradingform_guide_criteria', array('definitionid' => $this->definition->id), 'sortorder'); foreach ($criteria as $criterion) { foreach (array('id', 'sortorder', 'description', 'descriptionformat', 'maxscore', 'descriptionmarkers', 'descriptionmarkersformat', 'shortname') as $fieldname) { if ($fieldname == 'maxscore') { // Strip any trailing 0. $this->definition->guide_criteria[$criterion->id][$fieldname] = (float)$criterion->{$fieldname}; } else { $this->definition->guide_criteria[$criterion->id][$fieldname] = $criterion->{$fieldname}; } } } $criteria->close(); // Now get comments. $comments = $DB->get_recordset('gradingform_guide_comments', array('definitionid' => $this->definition->id), 'sortorder'); foreach ($comments as $comment) { foreach (array('id', 'sortorder', 'description', 'descriptionformat') as $fieldname) { $this->definition->guide_comments[$comment->id][$fieldname] = $comment->{$fieldname}; } } $comments->close(); if (empty($this->moduleinstance)) { // Only set if empty. $modulename = $this->get_component(); $context = $this->get_context(); if (strpos($modulename, 'mod_') === 0) { $dbman = $DB->get_manager(); $modulename = substr($modulename, 4); if ($dbman->table_exists($modulename)) { $cm = get_coursemodule_from_id($modulename, $context->instanceid); if (!empty($cm)) { // This should only occur when the course is being deleted. $this->moduleinstance = $DB->get_record($modulename, array("id"=>$cm->instance)); } } } } }
[ "protected", "function", "load_definition", "(", ")", "{", "global", "$", "DB", ";", "// Check to see if the user prefs have changed - putting here as this function is called on post even when", "// validation on the page fails. - hard to find a better place to locate this as it is specific to the guide.", "$", "showdesc", "=", "optional_param", "(", "'showmarkerdesc'", ",", "null", ",", "PARAM_BOOL", ")", ";", "// Check if we need to change pref.", "$", "showdescstudent", "=", "optional_param", "(", "'showstudentdesc'", ",", "null", ",", "PARAM_BOOL", ")", ";", "// Check if we need to change pref.", "if", "(", "$", "showdesc", "!==", "null", ")", "{", "set_user_preference", "(", "'gradingform_guide-showmarkerdesc'", ",", "$", "showdesc", ")", ";", "}", "if", "(", "$", "showdescstudent", "!==", "null", ")", "{", "set_user_preference", "(", "'gradingform_guide-showstudentdesc'", ",", "$", "showdescstudent", ")", ";", "}", "// Get definition.", "$", "definition", "=", "$", "DB", "->", "get_record", "(", "'grading_definitions'", ",", "array", "(", "'areaid'", "=>", "$", "this", "->", "areaid", ",", "'method'", "=>", "$", "this", "->", "get_method_name", "(", ")", ")", ",", "'*'", ")", ";", "if", "(", "!", "$", "definition", ")", "{", "// The definition doesn't have to exist. It may be that we are only now creating it.", "$", "this", "->", "definition", "=", "false", ";", "return", "false", ";", "}", "$", "this", "->", "definition", "=", "$", "definition", ";", "// Now get criteria.", "$", "this", "->", "definition", "->", "guide_criteria", "=", "array", "(", ")", ";", "$", "this", "->", "definition", "->", "guide_comments", "=", "array", "(", ")", ";", "$", "criteria", "=", "$", "DB", "->", "get_recordset", "(", "'gradingform_guide_criteria'", ",", "array", "(", "'definitionid'", "=>", "$", "this", "->", "definition", "->", "id", ")", ",", "'sortorder'", ")", ";", "foreach", "(", "$", "criteria", "as", "$", "criterion", ")", "{", "foreach", "(", "array", "(", "'id'", ",", "'sortorder'", ",", "'description'", ",", "'descriptionformat'", ",", "'maxscore'", ",", "'descriptionmarkers'", ",", "'descriptionmarkersformat'", ",", "'shortname'", ")", "as", "$", "fieldname", ")", "{", "if", "(", "$", "fieldname", "==", "'maxscore'", ")", "{", "// Strip any trailing 0.", "$", "this", "->", "definition", "->", "guide_criteria", "[", "$", "criterion", "->", "id", "]", "[", "$", "fieldname", "]", "=", "(", "float", ")", "$", "criterion", "->", "{", "$", "fieldname", "}", ";", "}", "else", "{", "$", "this", "->", "definition", "->", "guide_criteria", "[", "$", "criterion", "->", "id", "]", "[", "$", "fieldname", "]", "=", "$", "criterion", "->", "{", "$", "fieldname", "}", ";", "}", "}", "}", "$", "criteria", "->", "close", "(", ")", ";", "// Now get comments.", "$", "comments", "=", "$", "DB", "->", "get_recordset", "(", "'gradingform_guide_comments'", ",", "array", "(", "'definitionid'", "=>", "$", "this", "->", "definition", "->", "id", ")", ",", "'sortorder'", ")", ";", "foreach", "(", "$", "comments", "as", "$", "comment", ")", "{", "foreach", "(", "array", "(", "'id'", ",", "'sortorder'", ",", "'description'", ",", "'descriptionformat'", ")", "as", "$", "fieldname", ")", "{", "$", "this", "->", "definition", "->", "guide_comments", "[", "$", "comment", "->", "id", "]", "[", "$", "fieldname", "]", "=", "$", "comment", "->", "{", "$", "fieldname", "}", ";", "}", "}", "$", "comments", "->", "close", "(", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "moduleinstance", ")", ")", "{", "// Only set if empty.", "$", "modulename", "=", "$", "this", "->", "get_component", "(", ")", ";", "$", "context", "=", "$", "this", "->", "get_context", "(", ")", ";", "if", "(", "strpos", "(", "$", "modulename", ",", "'mod_'", ")", "===", "0", ")", "{", "$", "dbman", "=", "$", "DB", "->", "get_manager", "(", ")", ";", "$", "modulename", "=", "substr", "(", "$", "modulename", ",", "4", ")", ";", "if", "(", "$", "dbman", "->", "table_exists", "(", "$", "modulename", ")", ")", "{", "$", "cm", "=", "get_coursemodule_from_id", "(", "$", "modulename", ",", "$", "context", "->", "instanceid", ")", ";", "if", "(", "!", "empty", "(", "$", "cm", ")", ")", "{", "// This should only occur when the course is being deleted.", "$", "this", "->", "moduleinstance", "=", "$", "DB", "->", "get_record", "(", "$", "modulename", ",", "array", "(", "\"id\"", "=>", "$", "cm", "->", "instance", ")", ")", ";", "}", "}", "}", "}", "}" ]
Loads the guide form definition if it exists There is a new array called 'guide_criteria' appended to the list of parent's definition properties.
[ "Loads", "the", "guide", "form", "definition", "if", "it", "exists" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/lib.php#L296-L358
219,394
moodle/moodle
grade/grading/form/guide/lib.php
gradingform_guide_controller.delete_plugin_definition
protected function delete_plugin_definition() { global $DB; // Get the list of instances. $instances = array_keys($DB->get_records('grading_instances', array('definitionid' => $this->definition->id), '', 'id')); // Delete all fillings. $DB->delete_records_list('gradingform_guide_fillings', 'instanceid', $instances); // Delete instances. $DB->delete_records_list('grading_instances', 'id', $instances); // Get the list of criteria records. $criteria = array_keys($DB->get_records('gradingform_guide_criteria', array('definitionid' => $this->definition->id), '', 'id')); // Delete critera. $DB->delete_records_list('gradingform_guide_criteria', 'id', $criteria); // Delete comments. $DB->delete_records('gradingform_guide_comments', array('definitionid' => $this->definition->id)); }
php
protected function delete_plugin_definition() { global $DB; // Get the list of instances. $instances = array_keys($DB->get_records('grading_instances', array('definitionid' => $this->definition->id), '', 'id')); // Delete all fillings. $DB->delete_records_list('gradingform_guide_fillings', 'instanceid', $instances); // Delete instances. $DB->delete_records_list('grading_instances', 'id', $instances); // Get the list of criteria records. $criteria = array_keys($DB->get_records('gradingform_guide_criteria', array('definitionid' => $this->definition->id), '', 'id')); // Delete critera. $DB->delete_records_list('gradingform_guide_criteria', 'id', $criteria); // Delete comments. $DB->delete_records('gradingform_guide_comments', array('definitionid' => $this->definition->id)); }
[ "protected", "function", "delete_plugin_definition", "(", ")", "{", "global", "$", "DB", ";", "// Get the list of instances.", "$", "instances", "=", "array_keys", "(", "$", "DB", "->", "get_records", "(", "'grading_instances'", ",", "array", "(", "'definitionid'", "=>", "$", "this", "->", "definition", "->", "id", ")", ",", "''", ",", "'id'", ")", ")", ";", "// Delete all fillings.", "$", "DB", "->", "delete_records_list", "(", "'gradingform_guide_fillings'", ",", "'instanceid'", ",", "$", "instances", ")", ";", "// Delete instances.", "$", "DB", "->", "delete_records_list", "(", "'grading_instances'", ",", "'id'", ",", "$", "instances", ")", ";", "// Get the list of criteria records.", "$", "criteria", "=", "array_keys", "(", "$", "DB", "->", "get_records", "(", "'gradingform_guide_criteria'", ",", "array", "(", "'definitionid'", "=>", "$", "this", "->", "definition", "->", "id", ")", ",", "''", ",", "'id'", ")", ")", ";", "// Delete critera.", "$", "DB", "->", "delete_records_list", "(", "'gradingform_guide_criteria'", ",", "'id'", ",", "$", "criteria", ")", ";", "// Delete comments.", "$", "DB", "->", "delete_records", "(", "'gradingform_guide_comments'", ",", "array", "(", "'definitionid'", "=>", "$", "this", "->", "definition", "->", "id", ")", ")", ";", "}" ]
Deletes the guide definition and all the associated information
[ "Deletes", "the", "guide", "definition", "and", "all", "the", "associated", "information" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/lib.php#L539-L555
219,395
moodle/moodle
grade/grading/form/guide/lib.php
gradingform_guide_controller.render_grade
public function render_grade($page, $itemid, $gradinginfo, $defaultcontent, $cangrade) { return $this->get_renderer($page)->display_instances($this->get_active_instances($itemid), $defaultcontent, $cangrade); }
php
public function render_grade($page, $itemid, $gradinginfo, $defaultcontent, $cangrade) { return $this->get_renderer($page)->display_instances($this->get_active_instances($itemid), $defaultcontent, $cangrade); }
[ "public", "function", "render_grade", "(", "$", "page", ",", "$", "itemid", ",", "$", "gradinginfo", ",", "$", "defaultcontent", ",", "$", "cangrade", ")", "{", "return", "$", "this", "->", "get_renderer", "(", "$", "page", ")", "->", "display_instances", "(", "$", "this", "->", "get_active_instances", "(", "$", "itemid", ")", ",", "$", "defaultcontent", ",", "$", "cangrade", ")", ";", "}" ]
Returns html code to be included in student's feedback. @param moodle_page $page @param int $itemid @param array $gradinginfo result of function grade_get_grades @param string $defaultcontent default string to be returned if no active grading is found @param bool $cangrade whether current user has capability to grade in this context @return string
[ "Returns", "html", "code", "to", "be", "included", "in", "student", "s", "feedback", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/lib.php#L600-L602
219,396
moodle/moodle
grade/grading/form/guide/lib.php
gradingform_guide_instance.validate_grading_element
public function validate_grading_element($elementvalue) { $criteria = $this->get_controller()->get_definition()->guide_criteria; if (!isset($elementvalue['criteria']) || !is_array($elementvalue['criteria']) || count($elementvalue['criteria']) < count($criteria)) { return false; } // Reset validation errors. $this->validationerrors = null; foreach ($criteria as $id => $criterion) { if (!isset($elementvalue['criteria'][$id]['score']) || $criterion['maxscore'] < $elementvalue['criteria'][$id]['score'] || !is_numeric($elementvalue['criteria'][$id]['score']) || $elementvalue['criteria'][$id]['score'] < 0) { $this->validationerrors[$id]['score'] = $elementvalue['criteria'][$id]['score']; } } if (!empty($this->validationerrors)) { return false; } return true; }
php
public function validate_grading_element($elementvalue) { $criteria = $this->get_controller()->get_definition()->guide_criteria; if (!isset($elementvalue['criteria']) || !is_array($elementvalue['criteria']) || count($elementvalue['criteria']) < count($criteria)) { return false; } // Reset validation errors. $this->validationerrors = null; foreach ($criteria as $id => $criterion) { if (!isset($elementvalue['criteria'][$id]['score']) || $criterion['maxscore'] < $elementvalue['criteria'][$id]['score'] || !is_numeric($elementvalue['criteria'][$id]['score']) || $elementvalue['criteria'][$id]['score'] < 0) { $this->validationerrors[$id]['score'] = $elementvalue['criteria'][$id]['score']; } } if (!empty($this->validationerrors)) { return false; } return true; }
[ "public", "function", "validate_grading_element", "(", "$", "elementvalue", ")", "{", "$", "criteria", "=", "$", "this", "->", "get_controller", "(", ")", "->", "get_definition", "(", ")", "->", "guide_criteria", ";", "if", "(", "!", "isset", "(", "$", "elementvalue", "[", "'criteria'", "]", ")", "||", "!", "is_array", "(", "$", "elementvalue", "[", "'criteria'", "]", ")", "||", "count", "(", "$", "elementvalue", "[", "'criteria'", "]", ")", "<", "count", "(", "$", "criteria", ")", ")", "{", "return", "false", ";", "}", "// Reset validation errors.", "$", "this", "->", "validationerrors", "=", "null", ";", "foreach", "(", "$", "criteria", "as", "$", "id", "=>", "$", "criterion", ")", "{", "if", "(", "!", "isset", "(", "$", "elementvalue", "[", "'criteria'", "]", "[", "$", "id", "]", "[", "'score'", "]", ")", "||", "$", "criterion", "[", "'maxscore'", "]", "<", "$", "elementvalue", "[", "'criteria'", "]", "[", "$", "id", "]", "[", "'score'", "]", "||", "!", "is_numeric", "(", "$", "elementvalue", "[", "'criteria'", "]", "[", "$", "id", "]", "[", "'score'", "]", ")", "||", "$", "elementvalue", "[", "'criteria'", "]", "[", "$", "id", "]", "[", "'score'", "]", "<", "0", ")", "{", "$", "this", "->", "validationerrors", "[", "$", "id", "]", "[", "'score'", "]", "=", "$", "elementvalue", "[", "'criteria'", "]", "[", "$", "id", "]", "[", "'score'", "]", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "validationerrors", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Validates that guide is fully completed and contains valid grade on each criterion @param array $elementvalue value of element as came in form submit @return boolean true if the form data is validated and contains no errors
[ "Validates", "that", "guide", "is", "fully", "completed", "and", "contains", "valid", "grade", "on", "each", "criterion" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/lib.php#L795-L815
219,397
moodle/moodle
grade/grading/form/guide/lib.php
gradingform_guide_instance.get_guide_filling
public function get_guide_filling($force = false) { global $DB; if ($this->guide === null || $force) { $records = $DB->get_records('gradingform_guide_fillings', array('instanceid' => $this->get_id())); $this->guide = array('criteria' => array()); foreach ($records as $record) { $record->score = (float)$record->score; // Strip trailing 0. $this->guide['criteria'][$record->criterionid] = (array)$record; } } return $this->guide; }
php
public function get_guide_filling($force = false) { global $DB; if ($this->guide === null || $force) { $records = $DB->get_records('gradingform_guide_fillings', array('instanceid' => $this->get_id())); $this->guide = array('criteria' => array()); foreach ($records as $record) { $record->score = (float)$record->score; // Strip trailing 0. $this->guide['criteria'][$record->criterionid] = (array)$record; } } return $this->guide; }
[ "public", "function", "get_guide_filling", "(", "$", "force", "=", "false", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "guide", "===", "null", "||", "$", "force", ")", "{", "$", "records", "=", "$", "DB", "->", "get_records", "(", "'gradingform_guide_fillings'", ",", "array", "(", "'instanceid'", "=>", "$", "this", "->", "get_id", "(", ")", ")", ")", ";", "$", "this", "->", "guide", "=", "array", "(", "'criteria'", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "record", "->", "score", "=", "(", "float", ")", "$", "record", "->", "score", ";", "// Strip trailing 0.", "$", "this", "->", "guide", "[", "'criteria'", "]", "[", "$", "record", "->", "criterionid", "]", "=", "(", "array", ")", "$", "record", ";", "}", "}", "return", "$", "this", "->", "guide", ";", "}" ]
Retrieves from DB and returns the data how this guide was filled @param bool $force whether to force DB query even if the data is cached @return array
[ "Retrieves", "from", "DB", "and", "returns", "the", "data", "how", "this", "guide", "was", "filled" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/lib.php#L823-L834
219,398
moodle/moodle
message/output/airnotifier/classes/privacy/provider.php
provider.delete_data
protected static function delete_data(int $userid) { global $DB; foreach (static::get_records($userid) as $record) { $DB->delete_records('message_airnotifier_devices', ['id' => $record->id]); } }
php
protected static function delete_data(int $userid) { global $DB; foreach (static::get_records($userid) as $record) { $DB->delete_records('message_airnotifier_devices', ['id' => $record->id]); } }
[ "protected", "static", "function", "delete_data", "(", "int", "$", "userid", ")", "{", "global", "$", "DB", ";", "foreach", "(", "static", "::", "get_records", "(", "$", "userid", ")", "as", "$", "record", ")", "{", "$", "DB", "->", "delete_records", "(", "'message_airnotifier_devices'", ",", "[", "'id'", "=>", "$", "record", "->", "id", "]", ")", ";", "}", "}" ]
Delete data related to a userid. @param int $userid The user ID
[ "Delete", "data", "related", "to", "a", "userid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/output/airnotifier/classes/privacy/provider.php#L184-L190
219,399
moodle/moodle
lib/form/float.php
MoodleQuickForm_float.getValue
public function getValue() { $value = parent::getValue(); if ($value) { $value = unformat_float($value, true); } return $value; }
php
public function getValue() { $value = parent::getValue(); if ($value) { $value = unformat_float($value, true); } return $value; }
[ "public", "function", "getValue", "(", ")", "{", "$", "value", "=", "parent", "::", "getValue", "(", ")", ";", "if", "(", "$", "value", ")", "{", "$", "value", "=", "unformat_float", "(", "$", "value", ",", "true", ")", ";", "}", "return", "$", "value", ";", "}" ]
Returns the value of the form element. @return false|float
[ "Returns", "the", "value", "of", "the", "form", "element", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/float.php#L119-L125