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
218,200
moodle/moodle
tag/classes/external.php
core_tag_external.get_tag_areas
public static function get_tag_areas() { global $CFG, $PAGE; if (empty($CFG->usetags)) { throw new moodle_exception('tagsaredisabled', 'tag'); } $context = context_system::instance(); self::validate_context($context); $PAGE->set_context($context); // Needed by internal APIs. $output = $PAGE->get_renderer('core'); $areas = core_tag_area::get_areas(); $exportedareas = array(); foreach ($areas as $itemtype => $component) { foreach ($component as $area) { // Move optional fields not part of the DB table to otherdata. $locked = false; if (isset($area->locked)) { $locked = $area->locked; unset($area->locked); } $exporter = new \core_tag\external\tag_area_exporter($area, array('locked' => $locked)); $exportedareas[] = $exporter->export($output); } } return array( 'areas' => $exportedareas, 'warnings' => array(), ); }
php
public static function get_tag_areas() { global $CFG, $PAGE; if (empty($CFG->usetags)) { throw new moodle_exception('tagsaredisabled', 'tag'); } $context = context_system::instance(); self::validate_context($context); $PAGE->set_context($context); // Needed by internal APIs. $output = $PAGE->get_renderer('core'); $areas = core_tag_area::get_areas(); $exportedareas = array(); foreach ($areas as $itemtype => $component) { foreach ($component as $area) { // Move optional fields not part of the DB table to otherdata. $locked = false; if (isset($area->locked)) { $locked = $area->locked; unset($area->locked); } $exporter = new \core_tag\external\tag_area_exporter($area, array('locked' => $locked)); $exportedareas[] = $exporter->export($output); } } return array( 'areas' => $exportedareas, 'warnings' => array(), ); }
[ "public", "static", "function", "get_tag_areas", "(", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ";", "if", "(", "empty", "(", "$", "CFG", "->", "usetags", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'tagsaredisabled'", ",", "'tag'", ")", ";", "}", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "PAGE", "->", "set_context", "(", "$", "context", ")", ";", "// Needed by internal APIs.", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "$", "areas", "=", "core_tag_area", "::", "get_areas", "(", ")", ";", "$", "exportedareas", "=", "array", "(", ")", ";", "foreach", "(", "$", "areas", "as", "$", "itemtype", "=>", "$", "component", ")", "{", "foreach", "(", "$", "component", "as", "$", "area", ")", "{", "// Move optional fields not part of the DB table to otherdata.", "$", "locked", "=", "false", ";", "if", "(", "isset", "(", "$", "area", "->", "locked", ")", ")", "{", "$", "locked", "=", "$", "area", "->", "locked", ";", "unset", "(", "$", "area", "->", "locked", ")", ";", "}", "$", "exporter", "=", "new", "\\", "core_tag", "\\", "external", "\\", "tag_area_exporter", "(", "$", "area", ",", "array", "(", "'locked'", "=>", "$", "locked", ")", ")", ";", "$", "exportedareas", "[", "]", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "}", "}", "return", "array", "(", "'areas'", "=>", "$", "exportedareas", ",", "'warnings'", "=>", "array", "(", ")", ",", ")", ";", "}" ]
Retrieves existing tag areas. @return array an array of warnings and objects containing the plugin information @throws moodle_exception @since Moodle 3.7
[ "Retrieves", "existing", "tag", "areas", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/external.php#L474-L505
218,201
moodle/moodle
tag/classes/external.php
core_tag_external.get_tag_collections
public static function get_tag_collections() { global $CFG, $PAGE; if (empty($CFG->usetags)) { throw new moodle_exception('tagsaredisabled', 'tag'); } $context = context_system::instance(); self::validate_context($context); $PAGE->set_context($context); // Needed by internal APIs. $output = $PAGE->get_renderer('core'); $collections = core_tag_collection::get_collections(); $exportedcollections = array(); foreach ($collections as $collection) { $exporter = new \core_tag\external\tag_collection_exporter($collection); $exportedcollections[] = $exporter->export($output); } return array( 'collections' => $exportedcollections, 'warnings' => array(), ); }
php
public static function get_tag_collections() { global $CFG, $PAGE; if (empty($CFG->usetags)) { throw new moodle_exception('tagsaredisabled', 'tag'); } $context = context_system::instance(); self::validate_context($context); $PAGE->set_context($context); // Needed by internal APIs. $output = $PAGE->get_renderer('core'); $collections = core_tag_collection::get_collections(); $exportedcollections = array(); foreach ($collections as $collection) { $exporter = new \core_tag\external\tag_collection_exporter($collection); $exportedcollections[] = $exporter->export($output); } return array( 'collections' => $exportedcollections, 'warnings' => array(), ); }
[ "public", "static", "function", "get_tag_collections", "(", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ";", "if", "(", "empty", "(", "$", "CFG", "->", "usetags", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'tagsaredisabled'", ",", "'tag'", ")", ";", "}", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "PAGE", "->", "set_context", "(", "$", "context", ")", ";", "// Needed by internal APIs.", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "$", "collections", "=", "core_tag_collection", "::", "get_collections", "(", ")", ";", "$", "exportedcollections", "=", "array", "(", ")", ";", "foreach", "(", "$", "collections", "as", "$", "collection", ")", "{", "$", "exporter", "=", "new", "\\", "core_tag", "\\", "external", "\\", "tag_collection_exporter", "(", "$", "collection", ")", ";", "$", "exportedcollections", "[", "]", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "}", "return", "array", "(", "'collections'", "=>", "$", "exportedcollections", ",", "'warnings'", "=>", "array", "(", ")", ",", ")", ";", "}" ]
Retrieves existing tag collections. @return array an array of warnings and tag collections @throws moodle_exception @since Moodle 3.7
[ "Retrieves", "existing", "tag", "collections", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/external.php#L541-L564
218,202
moodle/moodle
tag/classes/external.php
core_tag_external.get_tag_cloud
public static function get_tag_cloud($tagcollid = 0, $isstandard = false, $limit = 150, $sort = 'name', $search = '', $fromctx = 0, $ctx = 0, $rec = 1) { global $CFG, $PAGE; $params = self::validate_parameters(self::get_tag_cloud_parameters(), array( 'tagcollid' => $tagcollid, 'isstandard' => $isstandard, 'limit' => $limit, 'sort' => $sort, 'search' => $search, 'fromctx' => $fromctx, 'ctx' => $ctx, 'rec' => $rec, ) ); if (empty($CFG->usetags)) { throw new moodle_exception('tagsaredisabled', 'tag'); } $context = context_system::instance(); self::validate_context($context); $PAGE->set_context($context); // Needed by internal APIs. $output = $PAGE->get_renderer('core'); $tagcloud = core_tag_collection::get_tag_cloud($params['tagcollid'], $params['isstandard'], $params['limit'], $params['sort'], $params['search'], $params['fromctx'], $params['ctx'], $params['rec']); $result = $tagcloud->export_for_template($output); $result->warnings = array(); return (array) $result; }
php
public static function get_tag_cloud($tagcollid = 0, $isstandard = false, $limit = 150, $sort = 'name', $search = '', $fromctx = 0, $ctx = 0, $rec = 1) { global $CFG, $PAGE; $params = self::validate_parameters(self::get_tag_cloud_parameters(), array( 'tagcollid' => $tagcollid, 'isstandard' => $isstandard, 'limit' => $limit, 'sort' => $sort, 'search' => $search, 'fromctx' => $fromctx, 'ctx' => $ctx, 'rec' => $rec, ) ); if (empty($CFG->usetags)) { throw new moodle_exception('tagsaredisabled', 'tag'); } $context = context_system::instance(); self::validate_context($context); $PAGE->set_context($context); // Needed by internal APIs. $output = $PAGE->get_renderer('core'); $tagcloud = core_tag_collection::get_tag_cloud($params['tagcollid'], $params['isstandard'], $params['limit'], $params['sort'], $params['search'], $params['fromctx'], $params['ctx'], $params['rec']); $result = $tagcloud->export_for_template($output); $result->warnings = array(); return (array) $result; }
[ "public", "static", "function", "get_tag_cloud", "(", "$", "tagcollid", "=", "0", ",", "$", "isstandard", "=", "false", ",", "$", "limit", "=", "150", ",", "$", "sort", "=", "'name'", ",", "$", "search", "=", "''", ",", "$", "fromctx", "=", "0", ",", "$", "ctx", "=", "0", ",", "$", "rec", "=", "1", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_tag_cloud_parameters", "(", ")", ",", "array", "(", "'tagcollid'", "=>", "$", "tagcollid", ",", "'isstandard'", "=>", "$", "isstandard", ",", "'limit'", "=>", "$", "limit", ",", "'sort'", "=>", "$", "sort", ",", "'search'", "=>", "$", "search", ",", "'fromctx'", "=>", "$", "fromctx", ",", "'ctx'", "=>", "$", "ctx", ",", "'rec'", "=>", "$", "rec", ",", ")", ")", ";", "if", "(", "empty", "(", "$", "CFG", "->", "usetags", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'tagsaredisabled'", ",", "'tag'", ")", ";", "}", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "PAGE", "->", "set_context", "(", "$", "context", ")", ";", "// Needed by internal APIs.", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "$", "tagcloud", "=", "core_tag_collection", "::", "get_tag_cloud", "(", "$", "params", "[", "'tagcollid'", "]", ",", "$", "params", "[", "'isstandard'", "]", ",", "$", "params", "[", "'limit'", "]", ",", "$", "params", "[", "'sort'", "]", ",", "$", "params", "[", "'search'", "]", ",", "$", "params", "[", "'fromctx'", "]", ",", "$", "params", "[", "'ctx'", "]", ",", "$", "params", "[", "'rec'", "]", ")", ";", "$", "result", "=", "$", "tagcloud", "->", "export_for_template", "(", "$", "output", ")", ";", "$", "result", "->", "warnings", "=", "array", "(", ")", ";", "return", "(", "array", ")", "$", "result", ";", "}" ]
Retrieves a tag cloud for display. @param int $tagcollid tag collection id @param bool $isstandard return only standard tags @param int $limit maximum number of tags to retrieve, tags are sorted by the instance count descending here regardless of $sort parameter @param string $sort sort order for display, default 'name' - tags will be sorted after they are retrieved @param string $search search string @param int $fromctx context id where this tag cloud is displayed @param int $ctx only retrieve tag instances in this context @param int $rec retrieve tag instances in the $ctx context and it's children (default 1) @return array an array of warnings and tag cloud information and items @throws moodle_exception @since Moodle 3.7
[ "Retrieves", "a", "tag", "cloud", "for", "display", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/external.php#L622-L655
218,203
moodle/moodle
blocks/glossary_random/block_glossary_random.php
block_glossary_random.get_glossary_cm
protected function get_glossary_cm() { global $DB; if (empty($this->config->glossary)) { // No glossary is configured. return null; } if (!empty($this->glossarycm)) { return $this->glossarycm; } if (!empty($this->page->course->id)) { // First check if glossary belongs to the current course (we don't need to make any DB queries to find it). $modinfo = get_fast_modinfo($this->page->course); if (isset($modinfo->instances['glossary'][$this->config->glossary])) { $this->glossarycm = $modinfo->instances['glossary'][$this->config->glossary]; if ($this->glossarycm->uservisible) { // The glossary is in the same course and is already visible to the current user, // no need to check if it is global, save on DB query. return $this->glossarycm; } } } // Find course module id for the given glossary, only if it is global. $cm = $DB->get_record_sql("SELECT cm.id, cm.visible AS uservisible FROM {course_modules} cm JOIN {modules} md ON md.id = cm.module JOIN {glossary} g ON g.id = cm.instance WHERE g.id = :instance AND md.name = :modulename AND g.globalglossary = 1", ['instance' => $this->config->glossary, 'modulename' => 'glossary']); if ($cm) { // This is a global glossary, create an object with properties 'id' and 'uservisible'. We don't need any // other information so why bother retrieving it. Full access check is skipped for global glossaries for // performance reasons. $this->glossarycm = $cm; } else if (empty($this->glossarycm)) { // Glossary does not exist. Remove it in the config so we don't repeat this check again later. $this->config->glossary = 0; $this->instance_config_commit(); } return $this->glossarycm; }
php
protected function get_glossary_cm() { global $DB; if (empty($this->config->glossary)) { // No glossary is configured. return null; } if (!empty($this->glossarycm)) { return $this->glossarycm; } if (!empty($this->page->course->id)) { // First check if glossary belongs to the current course (we don't need to make any DB queries to find it). $modinfo = get_fast_modinfo($this->page->course); if (isset($modinfo->instances['glossary'][$this->config->glossary])) { $this->glossarycm = $modinfo->instances['glossary'][$this->config->glossary]; if ($this->glossarycm->uservisible) { // The glossary is in the same course and is already visible to the current user, // no need to check if it is global, save on DB query. return $this->glossarycm; } } } // Find course module id for the given glossary, only if it is global. $cm = $DB->get_record_sql("SELECT cm.id, cm.visible AS uservisible FROM {course_modules} cm JOIN {modules} md ON md.id = cm.module JOIN {glossary} g ON g.id = cm.instance WHERE g.id = :instance AND md.name = :modulename AND g.globalglossary = 1", ['instance' => $this->config->glossary, 'modulename' => 'glossary']); if ($cm) { // This is a global glossary, create an object with properties 'id' and 'uservisible'. We don't need any // other information so why bother retrieving it. Full access check is skipped for global glossaries for // performance reasons. $this->glossarycm = $cm; } else if (empty($this->glossarycm)) { // Glossary does not exist. Remove it in the config so we don't repeat this check again later. $this->config->glossary = 0; $this->instance_config_commit(); } return $this->glossarycm; }
[ "protected", "function", "get_glossary_cm", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "this", "->", "config", "->", "glossary", ")", ")", "{", "// No glossary is configured.", "return", "null", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "glossarycm", ")", ")", "{", "return", "$", "this", "->", "glossarycm", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "page", "->", "course", "->", "id", ")", ")", "{", "// First check if glossary belongs to the current course (we don't need to make any DB queries to find it).", "$", "modinfo", "=", "get_fast_modinfo", "(", "$", "this", "->", "page", "->", "course", ")", ";", "if", "(", "isset", "(", "$", "modinfo", "->", "instances", "[", "'glossary'", "]", "[", "$", "this", "->", "config", "->", "glossary", "]", ")", ")", "{", "$", "this", "->", "glossarycm", "=", "$", "modinfo", "->", "instances", "[", "'glossary'", "]", "[", "$", "this", "->", "config", "->", "glossary", "]", ";", "if", "(", "$", "this", "->", "glossarycm", "->", "uservisible", ")", "{", "// The glossary is in the same course and is already visible to the current user,", "// no need to check if it is global, save on DB query.", "return", "$", "this", "->", "glossarycm", ";", "}", "}", "}", "// Find course module id for the given glossary, only if it is global.", "$", "cm", "=", "$", "DB", "->", "get_record_sql", "(", "\"SELECT cm.id, cm.visible AS uservisible\n FROM {course_modules} cm\n JOIN {modules} md ON md.id = cm.module\n JOIN {glossary} g ON g.id = cm.instance\n WHERE g.id = :instance AND md.name = :modulename AND g.globalglossary = 1\"", ",", "[", "'instance'", "=>", "$", "this", "->", "config", "->", "glossary", ",", "'modulename'", "=>", "'glossary'", "]", ")", ";", "if", "(", "$", "cm", ")", "{", "// This is a global glossary, create an object with properties 'id' and 'uservisible'. We don't need any", "// other information so why bother retrieving it. Full access check is skipped for global glossaries for", "// performance reasons.", "$", "this", "->", "glossarycm", "=", "$", "cm", ";", "}", "else", "if", "(", "empty", "(", "$", "this", "->", "glossarycm", ")", ")", "{", "// Glossary does not exist. Remove it in the config so we don't repeat this check again later.", "$", "this", "->", "config", "->", "glossary", "=", "0", ";", "$", "this", "->", "instance_config_commit", "(", ")", ";", "}", "return", "$", "this", "->", "glossarycm", ";", "}" ]
Checks if glossary is available - it should be either located in the same course or be global @return null|cm_info|stdClass object with properties 'id' (course module id) and 'uservisible'
[ "Checks", "if", "glossary", "is", "available", "-", "it", "should", "be", "either", "located", "in", "the", "same", "course", "or", "be", "global" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/glossary_random/block_glossary_random.php#L171-L215
218,204
moodle/moodle
lib/jabber/XMPP/XMPP.php
XMPPHP_XMPP.sasl_success_handler
protected function sasl_success_handler($xml) { $this->log->log("Auth success!"); $this->authed = true; $this->reset(); }
php
protected function sasl_success_handler($xml) { $this->log->log("Auth success!"); $this->authed = true; $this->reset(); }
[ "protected", "function", "sasl_success_handler", "(", "$", "xml", ")", "{", "$", "this", "->", "log", "->", "log", "(", "\"Auth success!\"", ")", ";", "$", "this", "->", "authed", "=", "true", ";", "$", "this", "->", "reset", "(", ")", ";", "}" ]
SASL success handler @param string $xml
[ "SASL", "success", "handler" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/jabber/XMPP/XMPP.php#L295-L299
218,205
moodle/moodle
lib/jabber/XMPP/XMPP.php
XMPPHP_XMPP.resource_bind_handler
protected function resource_bind_handler($xml) { if($xml->attrs['type'] == 'result') { $this->log->log("Bound to " . $xml->sub('bind')->sub('jid')->data); $this->fulljid = $xml->sub('bind')->sub('jid')->data; $jidarray = explode('/',$this->fulljid); $this->jid = $jidarray[0]; } $id = $this->getId(); $this->addIdHandler($id, 'session_start_handler'); $this->send("<iq xmlns='jabber:client' type='set' id='$id'><session xmlns='urn:ietf:params:xml:ns:xmpp-session' /></iq>"); }
php
protected function resource_bind_handler($xml) { if($xml->attrs['type'] == 'result') { $this->log->log("Bound to " . $xml->sub('bind')->sub('jid')->data); $this->fulljid = $xml->sub('bind')->sub('jid')->data; $jidarray = explode('/',$this->fulljid); $this->jid = $jidarray[0]; } $id = $this->getId(); $this->addIdHandler($id, 'session_start_handler'); $this->send("<iq xmlns='jabber:client' type='set' id='$id'><session xmlns='urn:ietf:params:xml:ns:xmpp-session' /></iq>"); }
[ "protected", "function", "resource_bind_handler", "(", "$", "xml", ")", "{", "if", "(", "$", "xml", "->", "attrs", "[", "'type'", "]", "==", "'result'", ")", "{", "$", "this", "->", "log", "->", "log", "(", "\"Bound to \"", ".", "$", "xml", "->", "sub", "(", "'bind'", ")", "->", "sub", "(", "'jid'", ")", "->", "data", ")", ";", "$", "this", "->", "fulljid", "=", "$", "xml", "->", "sub", "(", "'bind'", ")", "->", "sub", "(", "'jid'", ")", "->", "data", ";", "$", "jidarray", "=", "explode", "(", "'/'", ",", "$", "this", "->", "fulljid", ")", ";", "$", "this", "->", "jid", "=", "$", "jidarray", "[", "0", "]", ";", "}", "$", "id", "=", "$", "this", "->", "getId", "(", ")", ";", "$", "this", "->", "addIdHandler", "(", "$", "id", ",", "'session_start_handler'", ")", ";", "$", "this", "->", "send", "(", "\"<iq xmlns='jabber:client' type='set' id='$id'><session xmlns='urn:ietf:params:xml:ns:xmpp-session' /></iq>\"", ")", ";", "}" ]
Resource bind handler @param string $xml
[ "Resource", "bind", "handler" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/jabber/XMPP/XMPP.php#L318-L328
218,206
moodle/moodle
lib/jabber/XMPP/XMPP.php
XMPPHP_XMPP.session_start_handler
protected function session_start_handler($xml) { $this->log->log("Session started"); $this->session_started = true; $this->event('session_start'); }
php
protected function session_start_handler($xml) { $this->log->log("Session started"); $this->session_started = true; $this->event('session_start'); }
[ "protected", "function", "session_start_handler", "(", "$", "xml", ")", "{", "$", "this", "->", "log", "->", "log", "(", "\"Session started\"", ")", ";", "$", "this", "->", "session_started", "=", "true", ";", "$", "this", "->", "event", "(", "'session_start'", ")", ";", "}" ]
Session start handler @param string $xml
[ "Session", "start", "handler" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/jabber/XMPP/XMPP.php#L379-L383
218,207
moodle/moodle
lib/jabber/XMPP/XMPP.php
XMPPHP_XMPP.tls_proceed_handler
protected function tls_proceed_handler($xml) { $this->log->log("Starting TLS encryption"); stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); $this->reset(); }
php
protected function tls_proceed_handler($xml) { $this->log->log("Starting TLS encryption"); stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); $this->reset(); }
[ "protected", "function", "tls_proceed_handler", "(", "$", "xml", ")", "{", "$", "this", "->", "log", "->", "log", "(", "\"Starting TLS encryption\"", ")", ";", "stream_socket_enable_crypto", "(", "$", "this", "->", "socket", ",", "true", ",", "STREAM_CRYPTO_METHOD_SSLv23_CLIENT", ")", ";", "$", "this", "->", "reset", "(", ")", ";", "}" ]
TLS proceed handler @param string $xml
[ "TLS", "proceed", "handler" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/jabber/XMPP/XMPP.php#L390-L394
218,208
moodle/moodle
lib/jabber/XMPP/XMPP.php
XMPPHP_XMPP.getVCard
public function getVCard($jid = Null) { $id = $this->getID(); $this->addIdHandler($id, 'vcard_get_handler'); if($jid) { $this->send("<iq type='get' id='$id' to='$jid'><vCard xmlns='vcard-temp' /></iq>"); } else { $this->send("<iq type='get' id='$id'><vCard xmlns='vcard-temp' /></iq>"); } }
php
public function getVCard($jid = Null) { $id = $this->getID(); $this->addIdHandler($id, 'vcard_get_handler'); if($jid) { $this->send("<iq type='get' id='$id' to='$jid'><vCard xmlns='vcard-temp' /></iq>"); } else { $this->send("<iq type='get' id='$id'><vCard xmlns='vcard-temp' /></iq>"); } }
[ "public", "function", "getVCard", "(", "$", "jid", "=", "Null", ")", "{", "$", "id", "=", "$", "this", "->", "getID", "(", ")", ";", "$", "this", "->", "addIdHandler", "(", "$", "id", ",", "'vcard_get_handler'", ")", ";", "if", "(", "$", "jid", ")", "{", "$", "this", "->", "send", "(", "\"<iq type='get' id='$id' to='$jid'><vCard xmlns='vcard-temp' /></iq>\"", ")", ";", "}", "else", "{", "$", "this", "->", "send", "(", "\"<iq type='get' id='$id'><vCard xmlns='vcard-temp' /></iq>\"", ")", ";", "}", "}" ]
Retrieves the vcard
[ "Retrieves", "the", "vcard" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/jabber/XMPP/XMPP.php#L400-L408
218,209
moodle/moodle
lib/jabber/XMPP/XMPP.php
XMPPHP_XMPP.vcard_get_handler
protected function vcard_get_handler($xml) { $vcard_array = array(); $vcard = $xml->sub('vcard'); // go through all of the sub elements and add them to the vcard array foreach ($vcard->subs as $sub) { if ($sub->subs) { $vcard_array[$sub->name] = array(); foreach ($sub->subs as $sub_child) { $vcard_array[$sub->name][$sub_child->name] = $sub_child->data; } } else { $vcard_array[$sub->name] = $sub->data; } } $vcard_array['from'] = $xml->attrs['from']; $this->event('vcard', $vcard_array); }
php
protected function vcard_get_handler($xml) { $vcard_array = array(); $vcard = $xml->sub('vcard'); // go through all of the sub elements and add them to the vcard array foreach ($vcard->subs as $sub) { if ($sub->subs) { $vcard_array[$sub->name] = array(); foreach ($sub->subs as $sub_child) { $vcard_array[$sub->name][$sub_child->name] = $sub_child->data; } } else { $vcard_array[$sub->name] = $sub->data; } } $vcard_array['from'] = $xml->attrs['from']; $this->event('vcard', $vcard_array); }
[ "protected", "function", "vcard_get_handler", "(", "$", "xml", ")", "{", "$", "vcard_array", "=", "array", "(", ")", ";", "$", "vcard", "=", "$", "xml", "->", "sub", "(", "'vcard'", ")", ";", "// go through all of the sub elements and add them to the vcard array", "foreach", "(", "$", "vcard", "->", "subs", "as", "$", "sub", ")", "{", "if", "(", "$", "sub", "->", "subs", ")", "{", "$", "vcard_array", "[", "$", "sub", "->", "name", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "sub", "->", "subs", "as", "$", "sub_child", ")", "{", "$", "vcard_array", "[", "$", "sub", "->", "name", "]", "[", "$", "sub_child", "->", "name", "]", "=", "$", "sub_child", "->", "data", ";", "}", "}", "else", "{", "$", "vcard_array", "[", "$", "sub", "->", "name", "]", "=", "$", "sub", "->", "data", ";", "}", "}", "$", "vcard_array", "[", "'from'", "]", "=", "$", "xml", "->", "attrs", "[", "'from'", "]", ";", "$", "this", "->", "event", "(", "'vcard'", ",", "$", "vcard_array", ")", ";", "}" ]
VCard retrieval handler @param XML Object $xml
[ "VCard", "retrieval", "handler" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/jabber/XMPP/XMPP.php#L415-L431
218,210
moodle/moodle
admin/tool/recyclebin/classes/category_bin.php
category_bin.get_item
public function get_item($itemid) { global $DB; $item = $DB->get_record('tool_recyclebin_category', array( 'id' => $itemid ), '*', MUST_EXIST); $item->name = get_course_display_name_for_list($item); return $item; }
php
public function get_item($itemid) { global $DB; $item = $DB->get_record('tool_recyclebin_category', array( 'id' => $itemid ), '*', MUST_EXIST); $item->name = get_course_display_name_for_list($item); return $item; }
[ "public", "function", "get_item", "(", "$", "itemid", ")", "{", "global", "$", "DB", ";", "$", "item", "=", "$", "DB", "->", "get_record", "(", "'tool_recyclebin_category'", ",", "array", "(", "'id'", "=>", "$", "itemid", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "item", "->", "name", "=", "get_course_display_name_for_list", "(", "$", "item", ")", ";", "return", "$", "item", ";", "}" ]
Returns an item from the recycle bin. @param int $itemid Item ID to retrieve. @return \stdClass the item.
[ "Returns", "an", "item", "from", "the", "recycle", "bin", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/recyclebin/classes/category_bin.php#L69-L79
218,211
moodle/moodle
admin/tool/recyclebin/classes/category_bin.php
category_bin.get_items
public function get_items() { global $DB; $items = $DB->get_records('tool_recyclebin_category', array( 'categoryid' => $this->_categoryid )); foreach ($items as $item) { $item->name = get_course_display_name_for_list($item); } return $items; }
php
public function get_items() { global $DB; $items = $DB->get_records('tool_recyclebin_category', array( 'categoryid' => $this->_categoryid )); foreach ($items as $item) { $item->name = get_course_display_name_for_list($item); } return $items; }
[ "public", "function", "get_items", "(", ")", "{", "global", "$", "DB", ";", "$", "items", "=", "$", "DB", "->", "get_records", "(", "'tool_recyclebin_category'", ",", "array", "(", "'categoryid'", "=>", "$", "this", "->", "_categoryid", ")", ")", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "item", "->", "name", "=", "get_course_display_name_for_list", "(", "$", "item", ")", ";", "}", "return", "$", "items", ";", "}" ]
Returns a list of items in the recycle bin for this course. @return array the list of items.
[ "Returns", "a", "list", "of", "items", "in", "the", "recycle", "bin", "for", "this", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/recyclebin/classes/category_bin.php#L86-L98
218,212
moodle/moodle
admin/tool/recyclebin/classes/category_bin.php
category_bin.store_item
public function store_item($course) { global $CFG, $DB; require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php'); // As far as recycle bin is using MODE_AUTOMATED, it observes the backup_auto_storage // setting (storing backups @ real location. For recycle bin we want to ensure that // backup files are always stored in Moodle file area. In order to achieve that, we // hack the setting here via $CFG->forced_plugin_settings, so it won't interfere other // operations. See MDL-65218 for more information. // This hack will be removed once recycle bin switches to use its own backup mode, with // own preferences and 100% appart from MODLE_AUTOMATED. // TODO: Remove this as part of MDL-65228. $CFG->forced_plugin_settings['backup'] = ['backup_auto_storage' => 0]; // Backup the course. $user = get_admin(); $controller = new \backup_controller( \backup::TYPE_1COURSE, $course->id, \backup::FORMAT_MOODLE, \backup::INTERACTIVE_NO, \backup::MODE_AUTOMATED, $user->id ); $controller->execute_plan(); // We don't need the forced setting anymore, hence unsetting it. // TODO: Remove this as part of MDL-65228. unset($CFG->forced_plugin_settings['backup']); // Grab the result. $result = $controller->get_results(); if (!isset($result['backup_destination'])) { throw new \moodle_exception('Failed to backup activity prior to deletion.'); } // Have finished with the controller, let's destroy it, freeing mem and resources. $controller->destroy(); // Grab the filename. $file = $result['backup_destination']; if (!$file->get_contenthash()) { throw new \moodle_exception('Failed to backup activity prior to deletion (invalid file).'); } // Record the activity, get an ID. $item = new \stdClass(); $item->categoryid = $course->category; $item->shortname = $course->shortname; $item->fullname = $course->fullname; $item->timecreated = time(); $binid = $DB->insert_record('tool_recyclebin_category', $item); // Create the location we want to copy this file to. $filerecord = array( 'contextid' => \context_coursecat::instance($course->category)->id, 'component' => 'tool_recyclebin', 'filearea' => TOOL_RECYCLEBIN_COURSECAT_BIN_FILEAREA, 'itemid' => $binid, 'timemodified' => time() ); // Move the file to our own special little place. $fs = get_file_storage(); if (!$fs->create_file_from_storedfile($filerecord, $file)) { // Failed, cleanup first. $DB->delete_records('tool_recyclebin_category', array( 'id' => $binid )); throw new \moodle_exception("Failed to copy backup file to recyclebin."); } // Delete the old file. $file->delete(); // Fire event. $event = \tool_recyclebin\event\category_bin_item_created::create(array( 'objectid' => $binid, 'context' => \context_coursecat::instance($course->category) )); $event->trigger(); }
php
public function store_item($course) { global $CFG, $DB; require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php'); // As far as recycle bin is using MODE_AUTOMATED, it observes the backup_auto_storage // setting (storing backups @ real location. For recycle bin we want to ensure that // backup files are always stored in Moodle file area. In order to achieve that, we // hack the setting here via $CFG->forced_plugin_settings, so it won't interfere other // operations. See MDL-65218 for more information. // This hack will be removed once recycle bin switches to use its own backup mode, with // own preferences and 100% appart from MODLE_AUTOMATED. // TODO: Remove this as part of MDL-65228. $CFG->forced_plugin_settings['backup'] = ['backup_auto_storage' => 0]; // Backup the course. $user = get_admin(); $controller = new \backup_controller( \backup::TYPE_1COURSE, $course->id, \backup::FORMAT_MOODLE, \backup::INTERACTIVE_NO, \backup::MODE_AUTOMATED, $user->id ); $controller->execute_plan(); // We don't need the forced setting anymore, hence unsetting it. // TODO: Remove this as part of MDL-65228. unset($CFG->forced_plugin_settings['backup']); // Grab the result. $result = $controller->get_results(); if (!isset($result['backup_destination'])) { throw new \moodle_exception('Failed to backup activity prior to deletion.'); } // Have finished with the controller, let's destroy it, freeing mem and resources. $controller->destroy(); // Grab the filename. $file = $result['backup_destination']; if (!$file->get_contenthash()) { throw new \moodle_exception('Failed to backup activity prior to deletion (invalid file).'); } // Record the activity, get an ID. $item = new \stdClass(); $item->categoryid = $course->category; $item->shortname = $course->shortname; $item->fullname = $course->fullname; $item->timecreated = time(); $binid = $DB->insert_record('tool_recyclebin_category', $item); // Create the location we want to copy this file to. $filerecord = array( 'contextid' => \context_coursecat::instance($course->category)->id, 'component' => 'tool_recyclebin', 'filearea' => TOOL_RECYCLEBIN_COURSECAT_BIN_FILEAREA, 'itemid' => $binid, 'timemodified' => time() ); // Move the file to our own special little place. $fs = get_file_storage(); if (!$fs->create_file_from_storedfile($filerecord, $file)) { // Failed, cleanup first. $DB->delete_records('tool_recyclebin_category', array( 'id' => $binid )); throw new \moodle_exception("Failed to copy backup file to recyclebin."); } // Delete the old file. $file->delete(); // Fire event. $event = \tool_recyclebin\event\category_bin_item_created::create(array( 'objectid' => $binid, 'context' => \context_coursecat::instance($course->category) )); $event->trigger(); }
[ "public", "function", "store_item", "(", "$", "course", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/backup/util/includes/backup_includes.php'", ")", ";", "// As far as recycle bin is using MODE_AUTOMATED, it observes the backup_auto_storage", "// setting (storing backups @ real location. For recycle bin we want to ensure that", "// backup files are always stored in Moodle file area. In order to achieve that, we", "// hack the setting here via $CFG->forced_plugin_settings, so it won't interfere other", "// operations. See MDL-65218 for more information.", "// This hack will be removed once recycle bin switches to use its own backup mode, with", "// own preferences and 100% appart from MODLE_AUTOMATED.", "// TODO: Remove this as part of MDL-65228.", "$", "CFG", "->", "forced_plugin_settings", "[", "'backup'", "]", "=", "[", "'backup_auto_storage'", "=>", "0", "]", ";", "// Backup the course.", "$", "user", "=", "get_admin", "(", ")", ";", "$", "controller", "=", "new", "\\", "backup_controller", "(", "\\", "backup", "::", "TYPE_1COURSE", ",", "$", "course", "->", "id", ",", "\\", "backup", "::", "FORMAT_MOODLE", ",", "\\", "backup", "::", "INTERACTIVE_NO", ",", "\\", "backup", "::", "MODE_AUTOMATED", ",", "$", "user", "->", "id", ")", ";", "$", "controller", "->", "execute_plan", "(", ")", ";", "// We don't need the forced setting anymore, hence unsetting it.", "// TODO: Remove this as part of MDL-65228.", "unset", "(", "$", "CFG", "->", "forced_plugin_settings", "[", "'backup'", "]", ")", ";", "// Grab the result.", "$", "result", "=", "$", "controller", "->", "get_results", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "result", "[", "'backup_destination'", "]", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'Failed to backup activity prior to deletion.'", ")", ";", "}", "// Have finished with the controller, let's destroy it, freeing mem and resources.", "$", "controller", "->", "destroy", "(", ")", ";", "// Grab the filename.", "$", "file", "=", "$", "result", "[", "'backup_destination'", "]", ";", "if", "(", "!", "$", "file", "->", "get_contenthash", "(", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'Failed to backup activity prior to deletion (invalid file).'", ")", ";", "}", "// Record the activity, get an ID.", "$", "item", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "item", "->", "categoryid", "=", "$", "course", "->", "category", ";", "$", "item", "->", "shortname", "=", "$", "course", "->", "shortname", ";", "$", "item", "->", "fullname", "=", "$", "course", "->", "fullname", ";", "$", "item", "->", "timecreated", "=", "time", "(", ")", ";", "$", "binid", "=", "$", "DB", "->", "insert_record", "(", "'tool_recyclebin_category'", ",", "$", "item", ")", ";", "// Create the location we want to copy this file to.", "$", "filerecord", "=", "array", "(", "'contextid'", "=>", "\\", "context_coursecat", "::", "instance", "(", "$", "course", "->", "category", ")", "->", "id", ",", "'component'", "=>", "'tool_recyclebin'", ",", "'filearea'", "=>", "TOOL_RECYCLEBIN_COURSECAT_BIN_FILEAREA", ",", "'itemid'", "=>", "$", "binid", ",", "'timemodified'", "=>", "time", "(", ")", ")", ";", "// Move the file to our own special little place.", "$", "fs", "=", "get_file_storage", "(", ")", ";", "if", "(", "!", "$", "fs", "->", "create_file_from_storedfile", "(", "$", "filerecord", ",", "$", "file", ")", ")", "{", "// Failed, cleanup first.", "$", "DB", "->", "delete_records", "(", "'tool_recyclebin_category'", ",", "array", "(", "'id'", "=>", "$", "binid", ")", ")", ";", "throw", "new", "\\", "moodle_exception", "(", "\"Failed to copy backup file to recyclebin.\"", ")", ";", "}", "// Delete the old file.", "$", "file", "->", "delete", "(", ")", ";", "// Fire event.", "$", "event", "=", "\\", "tool_recyclebin", "\\", "event", "\\", "category_bin_item_created", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "binid", ",", "'context'", "=>", "\\", "context_coursecat", "::", "instance", "(", "$", "course", "->", "category", ")", ")", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Store a course in the recycle bin. @param \stdClass $course Course @throws \moodle_exception
[ "Store", "a", "course", "in", "the", "recycle", "bin", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/recyclebin/classes/category_bin.php#L106-L189
218,213
moodle/moodle
user/classes/participants_table.php
participants_table.out
public function out($pagesize, $useinitialsbar, $downloadhelpbutton = '') { global $PAGE; parent::out($pagesize, $useinitialsbar, $downloadhelpbutton); if (has_capability('moodle/course:enrolreview', $this->context)) { $params = ['contextid' => $this->context->id, 'courseid' => $this->course->id]; $PAGE->requires->js_call_amd('core_user/status_field', 'init', [$params]); } }
php
public function out($pagesize, $useinitialsbar, $downloadhelpbutton = '') { global $PAGE; parent::out($pagesize, $useinitialsbar, $downloadhelpbutton); if (has_capability('moodle/course:enrolreview', $this->context)) { $params = ['contextid' => $this->context->id, 'courseid' => $this->course->id]; $PAGE->requires->js_call_amd('core_user/status_field', 'init', [$params]); } }
[ "public", "function", "out", "(", "$", "pagesize", ",", "$", "useinitialsbar", ",", "$", "downloadhelpbutton", "=", "''", ")", "{", "global", "$", "PAGE", ";", "parent", "::", "out", "(", "$", "pagesize", ",", "$", "useinitialsbar", ",", "$", "downloadhelpbutton", ")", ";", "if", "(", "has_capability", "(", "'moodle/course:enrolreview'", ",", "$", "this", "->", "context", ")", ")", "{", "$", "params", "=", "[", "'contextid'", "=>", "$", "this", "->", "context", "->", "id", ",", "'courseid'", "=>", "$", "this", "->", "course", "->", "id", "]", ";", "$", "PAGE", "->", "requires", "->", "js_call_amd", "(", "'core_user/status_field'", ",", "'init'", ",", "[", "$", "params", "]", ")", ";", "}", "}" ]
Render the participants table. @param int $pagesize Size of page for paginated displayed table. @param bool $useinitialsbar Whether to use the initials bar which will only be used if there is a fullname column defined. @param string $downloadhelpbutton
[ "Render", "the", "participants", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/participants_table.php#L251-L260
218,214
moodle/moodle
user/classes/participants_table.php
participants_table.col_fullname
public function col_fullname($data) { global $OUTPUT; return $OUTPUT->user_picture($data, array('size' => 35, 'courseid' => $this->course->id, 'includefullname' => true)); }
php
public function col_fullname($data) { global $OUTPUT; return $OUTPUT->user_picture($data, array('size' => 35, 'courseid' => $this->course->id, 'includefullname' => true)); }
[ "public", "function", "col_fullname", "(", "$", "data", ")", "{", "global", "$", "OUTPUT", ";", "return", "$", "OUTPUT", "->", "user_picture", "(", "$", "data", ",", "array", "(", "'size'", "=>", "35", ",", "'courseid'", "=>", "$", "this", "->", "course", "->", "id", ",", "'includefullname'", "=>", "true", ")", ")", ";", "}" ]
Generate the fullname column. @param \stdClass $data @return string
[ "Generate", "the", "fullname", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/participants_table.php#L283-L287
218,215
moodle/moodle
user/classes/participants_table.php
participants_table.col_roles
public function col_roles($data) { global $OUTPUT; $roles = isset($this->allroleassignments[$data->id]) ? $this->allroleassignments[$data->id] : []; $editable = new \core_user\output\user_roles_editable($this->course, $this->context, $data, $this->allroles, $this->assignableroles, $this->profileroles, $roles, $this->viewableroles); return $OUTPUT->render_from_template('core/inplace_editable', $editable->export_for_template($OUTPUT)); }
php
public function col_roles($data) { global $OUTPUT; $roles = isset($this->allroleassignments[$data->id]) ? $this->allroleassignments[$data->id] : []; $editable = new \core_user\output\user_roles_editable($this->course, $this->context, $data, $this->allroles, $this->assignableroles, $this->profileroles, $roles, $this->viewableroles); return $OUTPUT->render_from_template('core/inplace_editable', $editable->export_for_template($OUTPUT)); }
[ "public", "function", "col_roles", "(", "$", "data", ")", "{", "global", "$", "OUTPUT", ";", "$", "roles", "=", "isset", "(", "$", "this", "->", "allroleassignments", "[", "$", "data", "->", "id", "]", ")", "?", "$", "this", "->", "allroleassignments", "[", "$", "data", "->", "id", "]", ":", "[", "]", ";", "$", "editable", "=", "new", "\\", "core_user", "\\", "output", "\\", "user_roles_editable", "(", "$", "this", "->", "course", ",", "$", "this", "->", "context", ",", "$", "data", ",", "$", "this", "->", "allroles", ",", "$", "this", "->", "assignableroles", ",", "$", "this", "->", "profileroles", ",", "$", "roles", ",", "$", "this", "->", "viewableroles", ")", ";", "return", "$", "OUTPUT", "->", "render_from_template", "(", "'core/inplace_editable'", ",", "$", "editable", "->", "export_for_template", "(", "$", "OUTPUT", ")", ")", ";", "}" ]
User roles column. @param \stdClass $data @return string
[ "User", "roles", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/participants_table.php#L295-L309
218,216
moodle/moodle
user/classes/participants_table.php
participants_table.col_groups
public function col_groups($data) { global $OUTPUT; $usergroups = []; foreach ($this->groups as $coursegroup) { if (isset($coursegroup->members[$data->id])) { $usergroups[] = $coursegroup->id; } } $editable = new \core_group\output\user_groups_editable($this->course, $this->context, $data, $this->groups, $usergroups); return $OUTPUT->render_from_template('core/inplace_editable', $editable->export_for_template($OUTPUT)); }
php
public function col_groups($data) { global $OUTPUT; $usergroups = []; foreach ($this->groups as $coursegroup) { if (isset($coursegroup->members[$data->id])) { $usergroups[] = $coursegroup->id; } } $editable = new \core_group\output\user_groups_editable($this->course, $this->context, $data, $this->groups, $usergroups); return $OUTPUT->render_from_template('core/inplace_editable', $editable->export_for_template($OUTPUT)); }
[ "public", "function", "col_groups", "(", "$", "data", ")", "{", "global", "$", "OUTPUT", ";", "$", "usergroups", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "groups", "as", "$", "coursegroup", ")", "{", "if", "(", "isset", "(", "$", "coursegroup", "->", "members", "[", "$", "data", "->", "id", "]", ")", ")", "{", "$", "usergroups", "[", "]", "=", "$", "coursegroup", "->", "id", ";", "}", "}", "$", "editable", "=", "new", "\\", "core_group", "\\", "output", "\\", "user_groups_editable", "(", "$", "this", "->", "course", ",", "$", "this", "->", "context", ",", "$", "data", ",", "$", "this", "->", "groups", ",", "$", "usergroups", ")", ";", "return", "$", "OUTPUT", "->", "render_from_template", "(", "'core/inplace_editable'", ",", "$", "editable", "->", "export_for_template", "(", "$", "OUTPUT", ")", ")", ";", "}" ]
Generate the groups column. @param \stdClass $data @return string
[ "Generate", "the", "groups", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/participants_table.php#L317-L328
218,217
moodle/moodle
user/classes/participants_table.php
participants_table.col_status
public function col_status($data) { global $CFG, $OUTPUT, $PAGE; $enrolstatusoutput = ''; $canreviewenrol = has_capability('moodle/course:enrolreview', $this->context); if ($canreviewenrol) { $canviewfullnames = has_capability('moodle/site:viewfullnames', $this->context); $fullname = fullname($data, $canviewfullnames); $coursename = format_string($this->course->fullname, true, array('context' => $this->context)); require_once($CFG->dirroot . '/enrol/locallib.php'); $manager = new \course_enrolment_manager($PAGE, $this->course); $userenrolments = $manager->get_user_enrolments($data->id); foreach ($userenrolments as $ue) { $timestart = $ue->timestart; $timeend = $ue->timeend; $timeenrolled = $ue->timecreated; $actions = $ue->enrolmentplugin->get_user_enrolment_actions($manager, $ue); $instancename = $ue->enrolmentinstancename; // Default status field label and value. $status = get_string('participationactive', 'enrol'); $statusval = status_field::STATUS_ACTIVE; switch ($ue->status) { case ENROL_USER_ACTIVE: $currentdate = new DateTime(); $now = $currentdate->getTimestamp(); $isexpired = $timestart > $now || ($timeend > 0 && $timeend < $now); $enrolmentdisabled = $ue->enrolmentinstance->status == ENROL_INSTANCE_DISABLED; // If user enrolment status has not yet started/already ended or the enrolment instance is disabled. if ($isexpired || $enrolmentdisabled) { $status = get_string('participationnotcurrent', 'enrol'); $statusval = status_field::STATUS_NOT_CURRENT; } break; case ENROL_USER_SUSPENDED: $status = get_string('participationsuspended', 'enrol'); $statusval = status_field::STATUS_SUSPENDED; break; } $statusfield = new status_field($instancename, $coursename, $fullname, $status, $timestart, $timeend, $actions, $timeenrolled); $statusfielddata = $statusfield->set_status($statusval)->export_for_template($OUTPUT); $enrolstatusoutput .= $OUTPUT->render_from_template('core_user/status_field', $statusfielddata); } } return $enrolstatusoutput; }
php
public function col_status($data) { global $CFG, $OUTPUT, $PAGE; $enrolstatusoutput = ''; $canreviewenrol = has_capability('moodle/course:enrolreview', $this->context); if ($canreviewenrol) { $canviewfullnames = has_capability('moodle/site:viewfullnames', $this->context); $fullname = fullname($data, $canviewfullnames); $coursename = format_string($this->course->fullname, true, array('context' => $this->context)); require_once($CFG->dirroot . '/enrol/locallib.php'); $manager = new \course_enrolment_manager($PAGE, $this->course); $userenrolments = $manager->get_user_enrolments($data->id); foreach ($userenrolments as $ue) { $timestart = $ue->timestart; $timeend = $ue->timeend; $timeenrolled = $ue->timecreated; $actions = $ue->enrolmentplugin->get_user_enrolment_actions($manager, $ue); $instancename = $ue->enrolmentinstancename; // Default status field label and value. $status = get_string('participationactive', 'enrol'); $statusval = status_field::STATUS_ACTIVE; switch ($ue->status) { case ENROL_USER_ACTIVE: $currentdate = new DateTime(); $now = $currentdate->getTimestamp(); $isexpired = $timestart > $now || ($timeend > 0 && $timeend < $now); $enrolmentdisabled = $ue->enrolmentinstance->status == ENROL_INSTANCE_DISABLED; // If user enrolment status has not yet started/already ended or the enrolment instance is disabled. if ($isexpired || $enrolmentdisabled) { $status = get_string('participationnotcurrent', 'enrol'); $statusval = status_field::STATUS_NOT_CURRENT; } break; case ENROL_USER_SUSPENDED: $status = get_string('participationsuspended', 'enrol'); $statusval = status_field::STATUS_SUSPENDED; break; } $statusfield = new status_field($instancename, $coursename, $fullname, $status, $timestart, $timeend, $actions, $timeenrolled); $statusfielddata = $statusfield->set_status($statusval)->export_for_template($OUTPUT); $enrolstatusoutput .= $OUTPUT->render_from_template('core_user/status_field', $statusfielddata); } } return $enrolstatusoutput; }
[ "public", "function", "col_status", "(", "$", "data", ")", "{", "global", "$", "CFG", ",", "$", "OUTPUT", ",", "$", "PAGE", ";", "$", "enrolstatusoutput", "=", "''", ";", "$", "canreviewenrol", "=", "has_capability", "(", "'moodle/course:enrolreview'", ",", "$", "this", "->", "context", ")", ";", "if", "(", "$", "canreviewenrol", ")", "{", "$", "canviewfullnames", "=", "has_capability", "(", "'moodle/site:viewfullnames'", ",", "$", "this", "->", "context", ")", ";", "$", "fullname", "=", "fullname", "(", "$", "data", ",", "$", "canviewfullnames", ")", ";", "$", "coursename", "=", "format_string", "(", "$", "this", "->", "course", "->", "fullname", ",", "true", ",", "array", "(", "'context'", "=>", "$", "this", "->", "context", ")", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/enrol/locallib.php'", ")", ";", "$", "manager", "=", "new", "\\", "course_enrolment_manager", "(", "$", "PAGE", ",", "$", "this", "->", "course", ")", ";", "$", "userenrolments", "=", "$", "manager", "->", "get_user_enrolments", "(", "$", "data", "->", "id", ")", ";", "foreach", "(", "$", "userenrolments", "as", "$", "ue", ")", "{", "$", "timestart", "=", "$", "ue", "->", "timestart", ";", "$", "timeend", "=", "$", "ue", "->", "timeend", ";", "$", "timeenrolled", "=", "$", "ue", "->", "timecreated", ";", "$", "actions", "=", "$", "ue", "->", "enrolmentplugin", "->", "get_user_enrolment_actions", "(", "$", "manager", ",", "$", "ue", ")", ";", "$", "instancename", "=", "$", "ue", "->", "enrolmentinstancename", ";", "// Default status field label and value.", "$", "status", "=", "get_string", "(", "'participationactive'", ",", "'enrol'", ")", ";", "$", "statusval", "=", "status_field", "::", "STATUS_ACTIVE", ";", "switch", "(", "$", "ue", "->", "status", ")", "{", "case", "ENROL_USER_ACTIVE", ":", "$", "currentdate", "=", "new", "DateTime", "(", ")", ";", "$", "now", "=", "$", "currentdate", "->", "getTimestamp", "(", ")", ";", "$", "isexpired", "=", "$", "timestart", ">", "$", "now", "||", "(", "$", "timeend", ">", "0", "&&", "$", "timeend", "<", "$", "now", ")", ";", "$", "enrolmentdisabled", "=", "$", "ue", "->", "enrolmentinstance", "->", "status", "==", "ENROL_INSTANCE_DISABLED", ";", "// If user enrolment status has not yet started/already ended or the enrolment instance is disabled.", "if", "(", "$", "isexpired", "||", "$", "enrolmentdisabled", ")", "{", "$", "status", "=", "get_string", "(", "'participationnotcurrent'", ",", "'enrol'", ")", ";", "$", "statusval", "=", "status_field", "::", "STATUS_NOT_CURRENT", ";", "}", "break", ";", "case", "ENROL_USER_SUSPENDED", ":", "$", "status", "=", "get_string", "(", "'participationsuspended'", ",", "'enrol'", ")", ";", "$", "statusval", "=", "status_field", "::", "STATUS_SUSPENDED", ";", "break", ";", "}", "$", "statusfield", "=", "new", "status_field", "(", "$", "instancename", ",", "$", "coursename", ",", "$", "fullname", ",", "$", "status", ",", "$", "timestart", ",", "$", "timeend", ",", "$", "actions", ",", "$", "timeenrolled", ")", ";", "$", "statusfielddata", "=", "$", "statusfield", "->", "set_status", "(", "$", "statusval", ")", "->", "export_for_template", "(", "$", "OUTPUT", ")", ";", "$", "enrolstatusoutput", ".=", "$", "OUTPUT", "->", "render_from_template", "(", "'core_user/status_field'", ",", "$", "statusfielddata", ")", ";", "}", "}", "return", "$", "enrolstatusoutput", ";", "}" ]
Generate the status column. @param \stdClass $data The data object. @return string
[ "Generate", "the", "status", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/participants_table.php#L363-L410
218,218
moodle/moodle
user/classes/participants_table.php
participants_table.other_cols
public function other_cols($colname, $data) { // Do not process if it is not a part of the extra fields. if (!in_array($colname, $this->extrafields)) { return ''; } return s($data->{$colname}); }
php
public function other_cols($colname, $data) { // Do not process if it is not a part of the extra fields. if (!in_array($colname, $this->extrafields)) { return ''; } return s($data->{$colname}); }
[ "public", "function", "other_cols", "(", "$", "colname", ",", "$", "data", ")", "{", "// Do not process if it is not a part of the extra fields.", "if", "(", "!", "in_array", "(", "$", "colname", ",", "$", "this", "->", "extrafields", ")", ")", "{", "return", "''", ";", "}", "return", "s", "(", "$", "data", "->", "{", "$", "colname", "}", ")", ";", "}" ]
This function is used for the extra user fields. These are being dynamically added to the table so there are no functions 'col_<userfieldname>' as the list has the potential to increase in the future and we don't want to have to remember to add a new method to this class. We also don't want to pollute this class with unnecessary methods. @param string $colname The column name @param \stdClass $data @return string
[ "This", "function", "is", "used", "for", "the", "extra", "user", "fields", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/participants_table.php#L423-L430
218,219
moodle/moodle
mod/workshop/form/accumulative/backup/moodle2/restore_workshopform_accumulative_subplugin.class.php
restore_workshopform_accumulative_subplugin.define_referenceassessment_subplugin_structure
protected function define_referenceassessment_subplugin_structure() { $paths = array(); $elename = $this->get_namefor('referencegrade'); $elepath = $this->get_pathfor('/workshopform_accumulative_referencegrade'); // we used get_recommended_name() so this works $paths[] = new restore_path_element($elename, $elepath); return $paths; // And we return the interesting paths }
php
protected function define_referenceassessment_subplugin_structure() { $paths = array(); $elename = $this->get_namefor('referencegrade'); $elepath = $this->get_pathfor('/workshopform_accumulative_referencegrade'); // we used get_recommended_name() so this works $paths[] = new restore_path_element($elename, $elepath); return $paths; // And we return the interesting paths }
[ "protected", "function", "define_referenceassessment_subplugin_structure", "(", ")", "{", "$", "paths", "=", "array", "(", ")", ";", "$", "elename", "=", "$", "this", "->", "get_namefor", "(", "'referencegrade'", ")", ";", "$", "elepath", "=", "$", "this", "->", "get_pathfor", "(", "'/workshopform_accumulative_referencegrade'", ")", ";", "// we used get_recommended_name() so this works", "$", "paths", "[", "]", "=", "new", "restore_path_element", "(", "$", "elename", ",", "$", "elepath", ")", ";", "return", "$", "paths", ";", "// And we return the interesting paths", "}" ]
Returns the paths to be handled by the subplugin at referenceassessment level
[ "Returns", "the", "paths", "to", "be", "handled", "by", "the", "subplugin", "at", "referenceassessment", "level" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/accumulative/backup/moodle2/restore_workshopform_accumulative_subplugin.class.php#L53-L62
218,220
moodle/moodle
mod/workshop/form/accumulative/backup/moodle2/restore_workshopform_accumulative_subplugin.class.php
restore_workshopform_accumulative_subplugin.define_exampleassessment_subplugin_structure
protected function define_exampleassessment_subplugin_structure() { $paths = array(); $elename = $this->get_namefor('examplegrade'); $elepath = $this->get_pathfor('/workshopform_accumulative_examplegrade'); // we used get_recommended_name() so this works $paths[] = new restore_path_element($elename, $elepath); return $paths; // And we return the interesting paths }
php
protected function define_exampleassessment_subplugin_structure() { $paths = array(); $elename = $this->get_namefor('examplegrade'); $elepath = $this->get_pathfor('/workshopform_accumulative_examplegrade'); // we used get_recommended_name() so this works $paths[] = new restore_path_element($elename, $elepath); return $paths; // And we return the interesting paths }
[ "protected", "function", "define_exampleassessment_subplugin_structure", "(", ")", "{", "$", "paths", "=", "array", "(", ")", ";", "$", "elename", "=", "$", "this", "->", "get_namefor", "(", "'examplegrade'", ")", ";", "$", "elepath", "=", "$", "this", "->", "get_pathfor", "(", "'/workshopform_accumulative_examplegrade'", ")", ";", "// we used get_recommended_name() so this works", "$", "paths", "[", "]", "=", "new", "restore_path_element", "(", "$", "elename", ",", "$", "elepath", ")", ";", "return", "$", "paths", ";", "// And we return the interesting paths", "}" ]
Returns the paths to be handled by the subplugin at exampleassessment level
[ "Returns", "the", "paths", "to", "be", "handled", "by", "the", "subplugin", "at", "exampleassessment", "level" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/accumulative/backup/moodle2/restore_workshopform_accumulative_subplugin.class.php#L67-L76
218,221
moodle/moodle
mod/workshop/form/accumulative/backup/moodle2/restore_workshopform_accumulative_subplugin.class.php
restore_workshopform_accumulative_subplugin.define_assessment_subplugin_structure
protected function define_assessment_subplugin_structure() { $paths = array(); $elename = $this->get_namefor('grade'); $elepath = $this->get_pathfor('/workshopform_accumulative_grade'); // we used get_recommended_name() so this works $paths[] = new restore_path_element($elename, $elepath); return $paths; // And we return the interesting paths }
php
protected function define_assessment_subplugin_structure() { $paths = array(); $elename = $this->get_namefor('grade'); $elepath = $this->get_pathfor('/workshopform_accumulative_grade'); // we used get_recommended_name() so this works $paths[] = new restore_path_element($elename, $elepath); return $paths; // And we return the interesting paths }
[ "protected", "function", "define_assessment_subplugin_structure", "(", ")", "{", "$", "paths", "=", "array", "(", ")", ";", "$", "elename", "=", "$", "this", "->", "get_namefor", "(", "'grade'", ")", ";", "$", "elepath", "=", "$", "this", "->", "get_pathfor", "(", "'/workshopform_accumulative_grade'", ")", ";", "// we used get_recommended_name() so this works", "$", "paths", "[", "]", "=", "new", "restore_path_element", "(", "$", "elename", ",", "$", "elepath", ")", ";", "return", "$", "paths", ";", "// And we return the interesting paths", "}" ]
Returns the paths to be handled by the subplugin at assessment level
[ "Returns", "the", "paths", "to", "be", "handled", "by", "the", "subplugin", "at", "assessment", "level" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/accumulative/backup/moodle2/restore_workshopform_accumulative_subplugin.class.php#L81-L90
218,222
moodle/moodle
mod/workshop/form/accumulative/backup/moodle2/restore_workshopform_accumulative_subplugin.class.php
restore_workshopform_accumulative_subplugin.process_workshopform_accumulative_dimension
public function process_workshopform_accumulative_dimension($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->workshopid = $this->get_new_parentid('workshop'); if ($data->grade < 0) { // scale found, get mapping $data->grade = -($this->get_mappingid('scale', abs($data->grade))); } $newitemid = $DB->insert_record('workshopform_accumulative', $data); $this->set_mapping($this->get_namefor('dimension'), $oldid, $newitemid, true); // Process files for this workshopform_accumulative->id only $this->add_related_files('workshopform_accumulative', 'description', $this->get_namefor('dimension'), null, $oldid); }
php
public function process_workshopform_accumulative_dimension($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->workshopid = $this->get_new_parentid('workshop'); if ($data->grade < 0) { // scale found, get mapping $data->grade = -($this->get_mappingid('scale', abs($data->grade))); } $newitemid = $DB->insert_record('workshopform_accumulative', $data); $this->set_mapping($this->get_namefor('dimension'), $oldid, $newitemid, true); // Process files for this workshopform_accumulative->id only $this->add_related_files('workshopform_accumulative', 'description', $this->get_namefor('dimension'), null, $oldid); }
[ "public", "function", "process_workshopform_accumulative_dimension", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "oldid", "=", "$", "data", "->", "id", ";", "$", "data", "->", "workshopid", "=", "$", "this", "->", "get_new_parentid", "(", "'workshop'", ")", ";", "if", "(", "$", "data", "->", "grade", "<", "0", ")", "{", "// scale found, get mapping", "$", "data", "->", "grade", "=", "-", "(", "$", "this", "->", "get_mappingid", "(", "'scale'", ",", "abs", "(", "$", "data", "->", "grade", ")", ")", ")", ";", "}", "$", "newitemid", "=", "$", "DB", "->", "insert_record", "(", "'workshopform_accumulative'", ",", "$", "data", ")", ";", "$", "this", "->", "set_mapping", "(", "$", "this", "->", "get_namefor", "(", "'dimension'", ")", ",", "$", "oldid", ",", "$", "newitemid", ",", "true", ")", ";", "// Process files for this workshopform_accumulative->id only", "$", "this", "->", "add_related_files", "(", "'workshopform_accumulative'", ",", "'description'", ",", "$", "this", "->", "get_namefor", "(", "'dimension'", ")", ",", "null", ",", "$", "oldid", ")", ";", "}" ]
Processes the workshopform_accumulative_dimension element
[ "Processes", "the", "workshopform_accumulative_dimension", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/accumulative/backup/moodle2/restore_workshopform_accumulative_subplugin.class.php#L99-L115
218,223
moodle/moodle
grade/grading/lib.php
grading_manager.set_component
public function set_component($component) { $this->areacache = null; list($type, $name) = core_component::normalize_component($component); $this->component = $type.'_'.$name; }
php
public function set_component($component) { $this->areacache = null; list($type, $name) = core_component::normalize_component($component); $this->component = $type.'_'.$name; }
[ "public", "function", "set_component", "(", "$", "component", ")", "{", "$", "this", "->", "areacache", "=", "null", ";", "list", "(", "$", "type", ",", "$", "name", ")", "=", "core_component", "::", "normalize_component", "(", "$", "component", ")", ";", "$", "this", "->", "component", "=", "$", "type", ".", "'_'", ".", "$", "name", ";", "}" ]
Sets the component the manager operates on @param string $component the frankenstyle name of the component
[ "Sets", "the", "component", "the", "manager", "operates", "on" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L140-L144
218,224
moodle/moodle
grade/grading/lib.php
grading_manager.get_component_title
public function get_component_title() { $this->ensure_isset(array('context', 'component')); if ($this->get_context()->contextlevel == CONTEXT_SYSTEM) { if ($this->get_component() == 'core_grading') { $title = ''; // we are in the bank UI } else { throw new coding_exception('Unsupported component at the system context'); } } else if ($this->get_context()->contextlevel >= CONTEXT_COURSE) { list($context, $course, $cm) = get_context_info_array($this->get_context()->id); if ($cm && strval($cm->name) !== '') { $title = format_string($cm->name, true, array('context' => $context)); } else { debugging('Gradable areas are currently supported at the course module level only', DEBUG_DEVELOPER); $title = $this->get_component(); } } else { throw new coding_exception('Unsupported gradable area context level'); } return $title; }
php
public function get_component_title() { $this->ensure_isset(array('context', 'component')); if ($this->get_context()->contextlevel == CONTEXT_SYSTEM) { if ($this->get_component() == 'core_grading') { $title = ''; // we are in the bank UI } else { throw new coding_exception('Unsupported component at the system context'); } } else if ($this->get_context()->contextlevel >= CONTEXT_COURSE) { list($context, $course, $cm) = get_context_info_array($this->get_context()->id); if ($cm && strval($cm->name) !== '') { $title = format_string($cm->name, true, array('context' => $context)); } else { debugging('Gradable areas are currently supported at the course module level only', DEBUG_DEVELOPER); $title = $this->get_component(); } } else { throw new coding_exception('Unsupported gradable area context level'); } return $title; }
[ "public", "function", "get_component_title", "(", ")", "{", "$", "this", "->", "ensure_isset", "(", "array", "(", "'context'", ",", "'component'", ")", ")", ";", "if", "(", "$", "this", "->", "get_context", "(", ")", "->", "contextlevel", "==", "CONTEXT_SYSTEM", ")", "{", "if", "(", "$", "this", "->", "get_component", "(", ")", "==", "'core_grading'", ")", "{", "$", "title", "=", "''", ";", "// we are in the bank UI", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Unsupported component at the system context'", ")", ";", "}", "}", "else", "if", "(", "$", "this", "->", "get_context", "(", ")", "->", "contextlevel", ">=", "CONTEXT_COURSE", ")", "{", "list", "(", "$", "context", ",", "$", "course", ",", "$", "cm", ")", "=", "get_context_info_array", "(", "$", "this", "->", "get_context", "(", ")", "->", "id", ")", ";", "if", "(", "$", "cm", "&&", "strval", "(", "$", "cm", "->", "name", ")", "!==", "''", ")", "{", "$", "title", "=", "format_string", "(", "$", "cm", "->", "name", ",", "true", ",", "array", "(", "'context'", "=>", "$", "context", ")", ")", ";", "}", "else", "{", "debugging", "(", "'Gradable areas are currently supported at the course module level only'", ",", "DEBUG_DEVELOPER", ")", ";", "$", "title", "=", "$", "this", "->", "get_component", "(", ")", ";", "}", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Unsupported gradable area context level'", ")", ";", "}", "return", "$", "title", ";", "}" ]
Returns a text describing the context and the component At the moment this works for gradable areas in course modules. In the future, this method should be improved so it works for other contexts (blocks, gradebook items etc) or subplugins. @return string
[ "Returns", "a", "text", "describing", "the", "context", "and", "the", "component" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L174-L200
218,225
moodle/moodle
grade/grading/lib.php
grading_manager.get_area_title
public function get_area_title() { if ($this->get_context()->contextlevel == CONTEXT_SYSTEM) { return ''; } else if ($this->get_context()->contextlevel >= CONTEXT_COURSE) { $this->ensure_isset(array('context', 'component', 'area')); $areas = $this->get_available_areas(); if (array_key_exists($this->get_area(), $areas)) { return $areas[$this->get_area()]; } else { debugging('Unknown area!'); return '???'; } } else { throw new coding_exception('Unsupported context level'); } }
php
public function get_area_title() { if ($this->get_context()->contextlevel == CONTEXT_SYSTEM) { return ''; } else if ($this->get_context()->contextlevel >= CONTEXT_COURSE) { $this->ensure_isset(array('context', 'component', 'area')); $areas = $this->get_available_areas(); if (array_key_exists($this->get_area(), $areas)) { return $areas[$this->get_area()]; } else { debugging('Unknown area!'); return '???'; } } else { throw new coding_exception('Unsupported context level'); } }
[ "public", "function", "get_area_title", "(", ")", "{", "if", "(", "$", "this", "->", "get_context", "(", ")", "->", "contextlevel", "==", "CONTEXT_SYSTEM", ")", "{", "return", "''", ";", "}", "else", "if", "(", "$", "this", "->", "get_context", "(", ")", "->", "contextlevel", ">=", "CONTEXT_COURSE", ")", "{", "$", "this", "->", "ensure_isset", "(", "array", "(", "'context'", ",", "'component'", ",", "'area'", ")", ")", ";", "$", "areas", "=", "$", "this", "->", "get_available_areas", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "this", "->", "get_area", "(", ")", ",", "$", "areas", ")", ")", "{", "return", "$", "areas", "[", "$", "this", "->", "get_area", "(", ")", "]", ";", "}", "else", "{", "debugging", "(", "'Unknown area!'", ")", ";", "return", "'???'", ";", "}", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Unsupported context level'", ")", ";", "}", "}" ]
Returns the localized title of the currently set area @return string
[ "Returns", "the", "localized", "title", "of", "the", "currently", "set", "area" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L207-L225
218,226
moodle/moodle
grade/grading/lib.php
grading_manager.load
public function load($areaid) { global $DB; $this->areacache = $DB->get_record('grading_areas', array('id' => $areaid), '*', MUST_EXIST); $this->context = context::instance_by_id($this->areacache->contextid, MUST_EXIST); $this->component = $this->areacache->component; $this->area = $this->areacache->areaname; }
php
public function load($areaid) { global $DB; $this->areacache = $DB->get_record('grading_areas', array('id' => $areaid), '*', MUST_EXIST); $this->context = context::instance_by_id($this->areacache->contextid, MUST_EXIST); $this->component = $this->areacache->component; $this->area = $this->areacache->areaname; }
[ "public", "function", "load", "(", "$", "areaid", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "areacache", "=", "$", "DB", "->", "get_record", "(", "'grading_areas'", ",", "array", "(", "'id'", "=>", "$", "areaid", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "this", "->", "context", "=", "context", "::", "instance_by_id", "(", "$", "this", "->", "areacache", "->", "contextid", ",", "MUST_EXIST", ")", ";", "$", "this", "->", "component", "=", "$", "this", "->", "areacache", "->", "component", ";", "$", "this", "->", "area", "=", "$", "this", "->", "areacache", "->", "areaname", ";", "}" ]
Loads the gradable area info from the database @param int $areaid
[ "Loads", "the", "gradable", "area", "info", "from", "the", "database" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L232-L239
218,227
moodle/moodle
grade/grading/lib.php
grading_manager.available_methods
public static function available_methods($includenone = true) { if ($includenone) { $list = array('' => get_string('gradingmethodnone', 'core_grading')); } else { $list = array(); } foreach (core_component::get_plugin_list('gradingform') as $name => $location) { $list[$name] = get_string('pluginname', 'gradingform_'.$name); } return $list; }
php
public static function available_methods($includenone = true) { if ($includenone) { $list = array('' => get_string('gradingmethodnone', 'core_grading')); } else { $list = array(); } foreach (core_component::get_plugin_list('gradingform') as $name => $location) { $list[$name] = get_string('pluginname', 'gradingform_'.$name); } return $list; }
[ "public", "static", "function", "available_methods", "(", "$", "includenone", "=", "true", ")", "{", "if", "(", "$", "includenone", ")", "{", "$", "list", "=", "array", "(", "''", "=>", "get_string", "(", "'gradingmethodnone'", ",", "'core_grading'", ")", ")", ";", "}", "else", "{", "$", "list", "=", "array", "(", ")", ";", "}", "foreach", "(", "core_component", "::", "get_plugin_list", "(", "'gradingform'", ")", "as", "$", "name", "=>", "$", "location", ")", "{", "$", "list", "[", "$", "name", "]", "=", "get_string", "(", "'pluginname'", ",", "'gradingform_'", ".", "$", "name", ")", ";", "}", "return", "$", "list", ";", "}" ]
Returns the list of installed grading plugins together, optionally extended with a simple direct grading. @param bool $includenone should the 'Simple direct grading' be included @return array of the (string)name => (string)localized title of the method
[ "Returns", "the", "list", "of", "installed", "grading", "plugins", "together", "optionally", "extended", "with", "a", "simple", "direct", "grading", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L248-L261
218,228
moodle/moodle
grade/grading/lib.php
grading_manager.available_areas
public static function available_areas($component) { global $CFG; list($plugintype, $pluginname) = core_component::normalize_component($component); if ($component === 'core_grading') { return array(); } else if ($plugintype === 'mod') { return plugin_callback('mod', $pluginname, 'grading', 'areas_list', null, array()); } else { throw new coding_exception('Unsupported area location'); } }
php
public static function available_areas($component) { global $CFG; list($plugintype, $pluginname) = core_component::normalize_component($component); if ($component === 'core_grading') { return array(); } else if ($plugintype === 'mod') { return plugin_callback('mod', $pluginname, 'grading', 'areas_list', null, array()); } else { throw new coding_exception('Unsupported area location'); } }
[ "public", "static", "function", "available_areas", "(", "$", "component", ")", "{", "global", "$", "CFG", ";", "list", "(", "$", "plugintype", ",", "$", "pluginname", ")", "=", "core_component", "::", "normalize_component", "(", "$", "component", ")", ";", "if", "(", "$", "component", "===", "'core_grading'", ")", "{", "return", "array", "(", ")", ";", "}", "else", "if", "(", "$", "plugintype", "===", "'mod'", ")", "{", "return", "plugin_callback", "(", "'mod'", ",", "$", "pluginname", ",", "'grading'", ",", "'areas_list'", ",", "null", ",", "array", "(", ")", ")", ";", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Unsupported area location'", ")", ";", "}", "}" ]
Returns the list of gradable areas provided by the given component This performs a callback to the library of the relevant plugin to obtain the list of supported areas. @param string $component normalized component name @return array of (string)areacode => (string)localized title of the area
[ "Returns", "the", "list", "of", "gradable", "areas", "provided", "by", "the", "given", "component" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L288-L302
218,229
moodle/moodle
grade/grading/lib.php
grading_manager.get_available_areas
public function get_available_areas() { global $CFG; $this->ensure_isset(array('context', 'component')); if ($this->get_context()->contextlevel == CONTEXT_SYSTEM) { if ($this->get_component() !== 'core_grading') { throw new coding_exception('Unsupported component at the system context'); } else { return array(); } } else if ($this->get_context()->contextlevel == CONTEXT_MODULE) { list($context, $course, $cm) = get_context_info_array($this->get_context()->id); return self::available_areas('mod_'.$cm->modname); } else { throw new coding_exception('Unsupported gradable area context level'); } }
php
public function get_available_areas() { global $CFG; $this->ensure_isset(array('context', 'component')); if ($this->get_context()->contextlevel == CONTEXT_SYSTEM) { if ($this->get_component() !== 'core_grading') { throw new coding_exception('Unsupported component at the system context'); } else { return array(); } } else if ($this->get_context()->contextlevel == CONTEXT_MODULE) { list($context, $course, $cm) = get_context_info_array($this->get_context()->id); return self::available_areas('mod_'.$cm->modname); } else { throw new coding_exception('Unsupported gradable area context level'); } }
[ "public", "function", "get_available_areas", "(", ")", "{", "global", "$", "CFG", ";", "$", "this", "->", "ensure_isset", "(", "array", "(", "'context'", ",", "'component'", ")", ")", ";", "if", "(", "$", "this", "->", "get_context", "(", ")", "->", "contextlevel", "==", "CONTEXT_SYSTEM", ")", "{", "if", "(", "$", "this", "->", "get_component", "(", ")", "!==", "'core_grading'", ")", "{", "throw", "new", "coding_exception", "(", "'Unsupported component at the system context'", ")", ";", "}", "else", "{", "return", "array", "(", ")", ";", "}", "}", "else", "if", "(", "$", "this", "->", "get_context", "(", ")", "->", "contextlevel", "==", "CONTEXT_MODULE", ")", "{", "list", "(", "$", "context", ",", "$", "course", ",", "$", "cm", ")", "=", "get_context_info_array", "(", "$", "this", "->", "get_context", "(", ")", "->", "id", ")", ";", "return", "self", "::", "available_areas", "(", "'mod_'", ".", "$", "cm", "->", "modname", ")", ";", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Unsupported gradable area context level'", ")", ";", "}", "}" ]
Returns the list of gradable areas in the given context and component This performs a callback to the library of the relevant plugin to obtain the list of supported areas. @return array of (string)areacode => (string)localized title of the area
[ "Returns", "the", "list", "of", "gradable", "areas", "in", "the", "given", "context", "and", "component" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L312-L331
218,230
moodle/moodle
grade/grading/lib.php
grading_manager.get_active_method
public function get_active_method() { global $DB; $this->ensure_isset(array('context', 'component', 'area')); // get the current grading area record if it exists if (is_null($this->areacache)) { $this->areacache = $DB->get_record('grading_areas', array( 'contextid' => $this->context->id, 'component' => $this->component, 'areaname' => $this->area), '*', IGNORE_MISSING); } if ($this->areacache === false) { // no area record yet return null; } return $this->areacache->activemethod; }
php
public function get_active_method() { global $DB; $this->ensure_isset(array('context', 'component', 'area')); // get the current grading area record if it exists if (is_null($this->areacache)) { $this->areacache = $DB->get_record('grading_areas', array( 'contextid' => $this->context->id, 'component' => $this->component, 'areaname' => $this->area), '*', IGNORE_MISSING); } if ($this->areacache === false) { // no area record yet return null; } return $this->areacache->activemethod; }
[ "public", "function", "get_active_method", "(", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "ensure_isset", "(", "array", "(", "'context'", ",", "'component'", ",", "'area'", ")", ")", ";", "// get the current grading area record if it exists", "if", "(", "is_null", "(", "$", "this", "->", "areacache", ")", ")", "{", "$", "this", "->", "areacache", "=", "$", "DB", "->", "get_record", "(", "'grading_areas'", ",", "array", "(", "'contextid'", "=>", "$", "this", "->", "context", "->", "id", ",", "'component'", "=>", "$", "this", "->", "component", ",", "'areaname'", "=>", "$", "this", "->", "area", ")", ",", "'*'", ",", "IGNORE_MISSING", ")", ";", "}", "if", "(", "$", "this", "->", "areacache", "===", "false", ")", "{", "// no area record yet", "return", "null", ";", "}", "return", "$", "this", "->", "areacache", "->", "activemethod", ";", "}" ]
Returns the currently active grading method in the gradable area @return string|null the name of the grading plugin of null if it has not been set
[ "Returns", "the", "currently", "active", "grading", "method", "in", "the", "gradable", "area" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L338-L358
218,231
moodle/moodle
grade/grading/lib.php
grading_manager.set_active_method
public function set_active_method($method) { global $DB; $this->ensure_isset(array('context', 'component', 'area')); // make sure the passed method is empty or a valid plugin name if (empty($method)) { $method = null; } else { if ('gradingform_'.$method !== clean_param('gradingform_'.$method, PARAM_COMPONENT)) { throw new moodle_exception('invalid_method_name', 'core_grading'); } $available = $this->get_available_methods(false); if (!array_key_exists($method, $available)) { throw new moodle_exception('invalid_method_name', 'core_grading'); } } // get the current grading area record if it exists if (is_null($this->areacache)) { $this->areacache = $DB->get_record('grading_areas', array( 'contextid' => $this->context->id, 'component' => $this->component, 'areaname' => $this->area), '*', IGNORE_MISSING); } $methodchanged = false; if ($this->areacache === false) { // no area record yet, create one with the active method set $area = array( 'contextid' => $this->context->id, 'component' => $this->component, 'areaname' => $this->area, 'activemethod' => $method); $DB->insert_record('grading_areas', $area); $methodchanged = true; } else { // update the existing record if needed if ($this->areacache->activemethod !== $method) { $DB->set_field('grading_areas', 'activemethod', $method, array('id' => $this->areacache->id)); $methodchanged = true; } } $this->areacache = null; return $methodchanged; }
php
public function set_active_method($method) { global $DB; $this->ensure_isset(array('context', 'component', 'area')); // make sure the passed method is empty or a valid plugin name if (empty($method)) { $method = null; } else { if ('gradingform_'.$method !== clean_param('gradingform_'.$method, PARAM_COMPONENT)) { throw new moodle_exception('invalid_method_name', 'core_grading'); } $available = $this->get_available_methods(false); if (!array_key_exists($method, $available)) { throw new moodle_exception('invalid_method_name', 'core_grading'); } } // get the current grading area record if it exists if (is_null($this->areacache)) { $this->areacache = $DB->get_record('grading_areas', array( 'contextid' => $this->context->id, 'component' => $this->component, 'areaname' => $this->area), '*', IGNORE_MISSING); } $methodchanged = false; if ($this->areacache === false) { // no area record yet, create one with the active method set $area = array( 'contextid' => $this->context->id, 'component' => $this->component, 'areaname' => $this->area, 'activemethod' => $method); $DB->insert_record('grading_areas', $area); $methodchanged = true; } else { // update the existing record if needed if ($this->areacache->activemethod !== $method) { $DB->set_field('grading_areas', 'activemethod', $method, array('id' => $this->areacache->id)); $methodchanged = true; } } $this->areacache = null; return $methodchanged; }
[ "public", "function", "set_active_method", "(", "$", "method", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "ensure_isset", "(", "array", "(", "'context'", ",", "'component'", ",", "'area'", ")", ")", ";", "// make sure the passed method is empty or a valid plugin name", "if", "(", "empty", "(", "$", "method", ")", ")", "{", "$", "method", "=", "null", ";", "}", "else", "{", "if", "(", "'gradingform_'", ".", "$", "method", "!==", "clean_param", "(", "'gradingform_'", ".", "$", "method", ",", "PARAM_COMPONENT", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'invalid_method_name'", ",", "'core_grading'", ")", ";", "}", "$", "available", "=", "$", "this", "->", "get_available_methods", "(", "false", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "method", ",", "$", "available", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'invalid_method_name'", ",", "'core_grading'", ")", ";", "}", "}", "// get the current grading area record if it exists", "if", "(", "is_null", "(", "$", "this", "->", "areacache", ")", ")", "{", "$", "this", "->", "areacache", "=", "$", "DB", "->", "get_record", "(", "'grading_areas'", ",", "array", "(", "'contextid'", "=>", "$", "this", "->", "context", "->", "id", ",", "'component'", "=>", "$", "this", "->", "component", ",", "'areaname'", "=>", "$", "this", "->", "area", ")", ",", "'*'", ",", "IGNORE_MISSING", ")", ";", "}", "$", "methodchanged", "=", "false", ";", "if", "(", "$", "this", "->", "areacache", "===", "false", ")", "{", "// no area record yet, create one with the active method set", "$", "area", "=", "array", "(", "'contextid'", "=>", "$", "this", "->", "context", "->", "id", ",", "'component'", "=>", "$", "this", "->", "component", ",", "'areaname'", "=>", "$", "this", "->", "area", ",", "'activemethod'", "=>", "$", "method", ")", ";", "$", "DB", "->", "insert_record", "(", "'grading_areas'", ",", "$", "area", ")", ";", "$", "methodchanged", "=", "true", ";", "}", "else", "{", "// update the existing record if needed", "if", "(", "$", "this", "->", "areacache", "->", "activemethod", "!==", "$", "method", ")", "{", "$", "DB", "->", "set_field", "(", "'grading_areas'", ",", "'activemethod'", ",", "$", "method", ",", "array", "(", "'id'", "=>", "$", "this", "->", "areacache", "->", "id", ")", ")", ";", "$", "methodchanged", "=", "true", ";", "}", "}", "$", "this", "->", "areacache", "=", "null", ";", "return", "$", "methodchanged", ";", "}" ]
Sets the currently active grading method in the gradable area @param string $method the method name, eg 'rubric' (must be available) @return bool true if the method changed or was just set, false otherwise
[ "Sets", "the", "currently", "active", "grading", "method", "in", "the", "gradable", "area" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L366-L416
218,232
moodle/moodle
grade/grading/lib.php
grading_manager.extend_settings_navigation
public function extend_settings_navigation(settings_navigation $settingsnav, navigation_node $modulenode=null) { $this->ensure_isset(array('context', 'component')); $areas = $this->get_available_areas(); if (empty($areas)) { // no money, no funny return; } else if (count($areas) == 1) { // make just a single node for the management screen $areatitle = reset($areas); $areaname = key($areas); $this->set_area($areaname); $method = $this->get_active_method(); $managementnode = $modulenode->add(get_string('gradingmanagement', 'core_grading'), $this->get_management_url(), settings_navigation::TYPE_CUSTOM); if ($method) { $controller = $this->get_controller($method); $controller->extend_settings_navigation($settingsnav, $managementnode); } } else { // make management screen node for each area $managementnode = $modulenode->add(get_string('gradingmanagement', 'core_grading'), null, settings_navigation::TYPE_CUSTOM); foreach ($areas as $areaname => $areatitle) { $this->set_area($areaname); $method = $this->get_active_method(); $node = $managementnode->add($areatitle, $this->get_management_url(), settings_navigation::TYPE_CUSTOM); if ($method) { $controller = $this->get_controller($method); $controller->extend_settings_navigation($settingsnav, $node); } } } }
php
public function extend_settings_navigation(settings_navigation $settingsnav, navigation_node $modulenode=null) { $this->ensure_isset(array('context', 'component')); $areas = $this->get_available_areas(); if (empty($areas)) { // no money, no funny return; } else if (count($areas) == 1) { // make just a single node for the management screen $areatitle = reset($areas); $areaname = key($areas); $this->set_area($areaname); $method = $this->get_active_method(); $managementnode = $modulenode->add(get_string('gradingmanagement', 'core_grading'), $this->get_management_url(), settings_navigation::TYPE_CUSTOM); if ($method) { $controller = $this->get_controller($method); $controller->extend_settings_navigation($settingsnav, $managementnode); } } else { // make management screen node for each area $managementnode = $modulenode->add(get_string('gradingmanagement', 'core_grading'), null, settings_navigation::TYPE_CUSTOM); foreach ($areas as $areaname => $areatitle) { $this->set_area($areaname); $method = $this->get_active_method(); $node = $managementnode->add($areatitle, $this->get_management_url(), settings_navigation::TYPE_CUSTOM); if ($method) { $controller = $this->get_controller($method); $controller->extend_settings_navigation($settingsnav, $node); } } } }
[ "public", "function", "extend_settings_navigation", "(", "settings_navigation", "$", "settingsnav", ",", "navigation_node", "$", "modulenode", "=", "null", ")", "{", "$", "this", "->", "ensure_isset", "(", "array", "(", "'context'", ",", "'component'", ")", ")", ";", "$", "areas", "=", "$", "this", "->", "get_available_areas", "(", ")", ";", "if", "(", "empty", "(", "$", "areas", ")", ")", "{", "// no money, no funny", "return", ";", "}", "else", "if", "(", "count", "(", "$", "areas", ")", "==", "1", ")", "{", "// make just a single node for the management screen", "$", "areatitle", "=", "reset", "(", "$", "areas", ")", ";", "$", "areaname", "=", "key", "(", "$", "areas", ")", ";", "$", "this", "->", "set_area", "(", "$", "areaname", ")", ";", "$", "method", "=", "$", "this", "->", "get_active_method", "(", ")", ";", "$", "managementnode", "=", "$", "modulenode", "->", "add", "(", "get_string", "(", "'gradingmanagement'", ",", "'core_grading'", ")", ",", "$", "this", "->", "get_management_url", "(", ")", ",", "settings_navigation", "::", "TYPE_CUSTOM", ")", ";", "if", "(", "$", "method", ")", "{", "$", "controller", "=", "$", "this", "->", "get_controller", "(", "$", "method", ")", ";", "$", "controller", "->", "extend_settings_navigation", "(", "$", "settingsnav", ",", "$", "managementnode", ")", ";", "}", "}", "else", "{", "// make management screen node for each area", "$", "managementnode", "=", "$", "modulenode", "->", "add", "(", "get_string", "(", "'gradingmanagement'", ",", "'core_grading'", ")", ",", "null", ",", "settings_navigation", "::", "TYPE_CUSTOM", ")", ";", "foreach", "(", "$", "areas", "as", "$", "areaname", "=>", "$", "areatitle", ")", "{", "$", "this", "->", "set_area", "(", "$", "areaname", ")", ";", "$", "method", "=", "$", "this", "->", "get_active_method", "(", ")", ";", "$", "node", "=", "$", "managementnode", "->", "add", "(", "$", "areatitle", ",", "$", "this", "->", "get_management_url", "(", ")", ",", "settings_navigation", "::", "TYPE_CUSTOM", ")", ";", "if", "(", "$", "method", ")", "{", "$", "controller", "=", "$", "this", "->", "get_controller", "(", "$", "method", ")", ";", "$", "controller", "->", "extend_settings_navigation", "(", "$", "settingsnav", ",", "$", "node", ")", ";", "}", "}", "}", "}" ]
Extends the settings navigation with the grading settings This function is called when the context for the page is an activity module with the FEATURE_ADVANCED_GRADING and the user has the permission moodle/grade:managegradingforms. @param settings_navigation $settingsnav {@link settings_navigation} @param navigation_node $modulenode {@link navigation_node}
[ "Extends", "the", "settings", "navigation", "with", "the", "grading", "settings" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L427-L465
218,233
moodle/moodle
grade/grading/lib.php
grading_manager.extend_navigation
public function extend_navigation(global_navigation $navigation, navigation_node $modulenode=null) { $this->ensure_isset(array('context', 'component')); $areas = $this->get_available_areas(); foreach ($areas as $areaname => $areatitle) { $this->set_area($areaname); if ($controller = $this->get_active_controller()) { $controller->extend_navigation($navigation, $modulenode); } } }
php
public function extend_navigation(global_navigation $navigation, navigation_node $modulenode=null) { $this->ensure_isset(array('context', 'component')); $areas = $this->get_available_areas(); foreach ($areas as $areaname => $areatitle) { $this->set_area($areaname); if ($controller = $this->get_active_controller()) { $controller->extend_navigation($navigation, $modulenode); } } }
[ "public", "function", "extend_navigation", "(", "global_navigation", "$", "navigation", ",", "navigation_node", "$", "modulenode", "=", "null", ")", "{", "$", "this", "->", "ensure_isset", "(", "array", "(", "'context'", ",", "'component'", ")", ")", ";", "$", "areas", "=", "$", "this", "->", "get_available_areas", "(", ")", ";", "foreach", "(", "$", "areas", "as", "$", "areaname", "=>", "$", "areatitle", ")", "{", "$", "this", "->", "set_area", "(", "$", "areaname", ")", ";", "if", "(", "$", "controller", "=", "$", "this", "->", "get_active_controller", "(", ")", ")", "{", "$", "controller", "->", "extend_navigation", "(", "$", "navigation", ",", "$", "modulenode", ")", ";", "}", "}", "}" ]
Extends the module navigation with the advanced grading information This function is called when the context for the page is an activity module with the FEATURE_ADVANCED_GRADING. @param global_navigation $navigation @param navigation_node $modulenode
[ "Extends", "the", "module", "navigation", "with", "the", "advanced", "grading", "information" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L476-L486
218,234
moodle/moodle
grade/grading/lib.php
grading_manager.get_controller
public function get_controller($method) { global $CFG, $DB; $this->ensure_isset(array('context', 'component', 'area')); // make sure the passed method is a valid plugin name if ('gradingform_'.$method !== clean_param('gradingform_'.$method, PARAM_COMPONENT)) { throw new moodle_exception('invalid_method_name', 'core_grading'); } $available = $this->get_available_methods(false); if (!array_key_exists($method, $available)) { throw new moodle_exception('invalid_method_name', 'core_grading'); } // get the current grading area record if it exists if (is_null($this->areacache)) { $this->areacache = $DB->get_record('grading_areas', array( 'contextid' => $this->context->id, 'component' => $this->component, 'areaname' => $this->area), '*', IGNORE_MISSING); } if ($this->areacache === false) { // no area record yet, create one $area = array( 'contextid' => $this->context->id, 'component' => $this->component, 'areaname' => $this->area); $areaid = $DB->insert_record('grading_areas', $area); // reload the cache $this->areacache = $DB->get_record('grading_areas', array('id' => $areaid), '*', MUST_EXIST); } require_once($CFG->dirroot.'/grade/grading/form/'.$method.'/lib.php'); $classname = 'gradingform_'.$method.'_controller'; return new $classname($this->context, $this->component, $this->area, $this->areacache->id); }
php
public function get_controller($method) { global $CFG, $DB; $this->ensure_isset(array('context', 'component', 'area')); // make sure the passed method is a valid plugin name if ('gradingform_'.$method !== clean_param('gradingform_'.$method, PARAM_COMPONENT)) { throw new moodle_exception('invalid_method_name', 'core_grading'); } $available = $this->get_available_methods(false); if (!array_key_exists($method, $available)) { throw new moodle_exception('invalid_method_name', 'core_grading'); } // get the current grading area record if it exists if (is_null($this->areacache)) { $this->areacache = $DB->get_record('grading_areas', array( 'contextid' => $this->context->id, 'component' => $this->component, 'areaname' => $this->area), '*', IGNORE_MISSING); } if ($this->areacache === false) { // no area record yet, create one $area = array( 'contextid' => $this->context->id, 'component' => $this->component, 'areaname' => $this->area); $areaid = $DB->insert_record('grading_areas', $area); // reload the cache $this->areacache = $DB->get_record('grading_areas', array('id' => $areaid), '*', MUST_EXIST); } require_once($CFG->dirroot.'/grade/grading/form/'.$method.'/lib.php'); $classname = 'gradingform_'.$method.'_controller'; return new $classname($this->context, $this->component, $this->area, $this->areacache->id); }
[ "public", "function", "get_controller", "(", "$", "method", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "this", "->", "ensure_isset", "(", "array", "(", "'context'", ",", "'component'", ",", "'area'", ")", ")", ";", "// make sure the passed method is a valid plugin name", "if", "(", "'gradingform_'", ".", "$", "method", "!==", "clean_param", "(", "'gradingform_'", ".", "$", "method", ",", "PARAM_COMPONENT", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'invalid_method_name'", ",", "'core_grading'", ")", ";", "}", "$", "available", "=", "$", "this", "->", "get_available_methods", "(", "false", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "method", ",", "$", "available", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'invalid_method_name'", ",", "'core_grading'", ")", ";", "}", "// get the current grading area record if it exists", "if", "(", "is_null", "(", "$", "this", "->", "areacache", ")", ")", "{", "$", "this", "->", "areacache", "=", "$", "DB", "->", "get_record", "(", "'grading_areas'", ",", "array", "(", "'contextid'", "=>", "$", "this", "->", "context", "->", "id", ",", "'component'", "=>", "$", "this", "->", "component", ",", "'areaname'", "=>", "$", "this", "->", "area", ")", ",", "'*'", ",", "IGNORE_MISSING", ")", ";", "}", "if", "(", "$", "this", "->", "areacache", "===", "false", ")", "{", "// no area record yet, create one", "$", "area", "=", "array", "(", "'contextid'", "=>", "$", "this", "->", "context", "->", "id", ",", "'component'", "=>", "$", "this", "->", "component", ",", "'areaname'", "=>", "$", "this", "->", "area", ")", ";", "$", "areaid", "=", "$", "DB", "->", "insert_record", "(", "'grading_areas'", ",", "$", "area", ")", ";", "// reload the cache", "$", "this", "->", "areacache", "=", "$", "DB", "->", "get_record", "(", "'grading_areas'", ",", "array", "(", "'id'", "=>", "$", "areaid", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "}", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/grade/grading/form/'", ".", "$", "method", ".", "'/lib.php'", ")", ";", "$", "classname", "=", "'gradingform_'", ".", "$", "method", ".", "'_controller'", ";", "return", "new", "$", "classname", "(", "$", "this", "->", "context", ",", "$", "this", "->", "component", ",", "$", "this", "->", "area", ",", "$", "this", "->", "areacache", "->", "id", ")", ";", "}" ]
Returns the given method's controller in the gradable area @param string $method the method name, eg 'rubric' (must be available) @return gradingform_controller
[ "Returns", "the", "given", "method", "s", "controller", "in", "the", "gradable", "area" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L494-L532
218,235
moodle/moodle
grade/grading/lib.php
grading_manager.get_active_controller
public function get_active_controller() { if ($gradingmethod = $this->get_active_method()) { $controller = $this->get_controller($gradingmethod); if ($controller->is_form_available()) { return $controller; } } return null; }
php
public function get_active_controller() { if ($gradingmethod = $this->get_active_method()) { $controller = $this->get_controller($gradingmethod); if ($controller->is_form_available()) { return $controller; } } return null; }
[ "public", "function", "get_active_controller", "(", ")", "{", "if", "(", "$", "gradingmethod", "=", "$", "this", "->", "get_active_method", "(", ")", ")", "{", "$", "controller", "=", "$", "this", "->", "get_controller", "(", "$", "gradingmethod", ")", ";", "if", "(", "$", "controller", "->", "is_form_available", "(", ")", ")", "{", "return", "$", "controller", ";", "}", "}", "return", "null", ";", "}" ]
Returns the controller for the active method if it is available @return null|gradingform_controller
[ "Returns", "the", "controller", "for", "the", "active", "method", "if", "it", "is", "available" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L539-L547
218,236
moodle/moodle
grade/grading/lib.php
grading_manager.get_management_url
public function get_management_url(moodle_url $returnurl = null) { $this->ensure_isset(array('context', 'component')); if ($this->areacache) { $params = array('areaid' => $this->areacache->id); } else { $params = array('contextid' => $this->context->id, 'component' => $this->component); if ($this->area) { $params['area'] = $this->area; } } if (!is_null($returnurl)) { $params['returnurl'] = $returnurl->out(false); } return new moodle_url('/grade/grading/manage.php', $params); }
php
public function get_management_url(moodle_url $returnurl = null) { $this->ensure_isset(array('context', 'component')); if ($this->areacache) { $params = array('areaid' => $this->areacache->id); } else { $params = array('contextid' => $this->context->id, 'component' => $this->component); if ($this->area) { $params['area'] = $this->area; } } if (!is_null($returnurl)) { $params['returnurl'] = $returnurl->out(false); } return new moodle_url('/grade/grading/manage.php', $params); }
[ "public", "function", "get_management_url", "(", "moodle_url", "$", "returnurl", "=", "null", ")", "{", "$", "this", "->", "ensure_isset", "(", "array", "(", "'context'", ",", "'component'", ")", ")", ";", "if", "(", "$", "this", "->", "areacache", ")", "{", "$", "params", "=", "array", "(", "'areaid'", "=>", "$", "this", "->", "areacache", "->", "id", ")", ";", "}", "else", "{", "$", "params", "=", "array", "(", "'contextid'", "=>", "$", "this", "->", "context", "->", "id", ",", "'component'", "=>", "$", "this", "->", "component", ")", ";", "if", "(", "$", "this", "->", "area", ")", "{", "$", "params", "[", "'area'", "]", "=", "$", "this", "->", "area", ";", "}", "}", "if", "(", "!", "is_null", "(", "$", "returnurl", ")", ")", "{", "$", "params", "[", "'returnurl'", "]", "=", "$", "returnurl", "->", "out", "(", "false", ")", ";", "}", "return", "new", "moodle_url", "(", "'/grade/grading/manage.php'", ",", "$", "params", ")", ";", "}" ]
Returns the URL of the grading area management page @param moodle_url $returnurl optional URL of the page where the user should be sent back to @return moodle_url
[ "Returns", "the", "URL", "of", "the", "grading", "area", "management", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L555-L573
218,237
moodle/moodle
grade/grading/lib.php
grading_manager.create_shared_area
public function create_shared_area($method) { global $DB; // generate some unique random name for the new area $name = $method . '_' . sha1(rand().uniqid($method, true)); // create new area record $area = array( 'contextid' => context_system::instance()->id, 'component' => 'core_grading', 'areaname' => $name, 'activemethod' => $method); return $DB->insert_record('grading_areas', $area); }
php
public function create_shared_area($method) { global $DB; // generate some unique random name for the new area $name = $method . '_' . sha1(rand().uniqid($method, true)); // create new area record $area = array( 'contextid' => context_system::instance()->id, 'component' => 'core_grading', 'areaname' => $name, 'activemethod' => $method); return $DB->insert_record('grading_areas', $area); }
[ "public", "function", "create_shared_area", "(", "$", "method", ")", "{", "global", "$", "DB", ";", "// generate some unique random name for the new area", "$", "name", "=", "$", "method", ".", "'_'", ".", "sha1", "(", "rand", "(", ")", ".", "uniqid", "(", "$", "method", ",", "true", ")", ")", ";", "// create new area record", "$", "area", "=", "array", "(", "'contextid'", "=>", "context_system", "::", "instance", "(", ")", "->", "id", ",", "'component'", "=>", "'core_grading'", ",", "'areaname'", "=>", "$", "name", ",", "'activemethod'", "=>", "$", "method", ")", ";", "return", "$", "DB", "->", "insert_record", "(", "'grading_areas'", ",", "$", "area", ")", ";", "}" ]
Creates a new shared area to hold a grading form template Shared area are implemented as virtual gradable areas at the system level context with the component set to core_grading and unique random area name. @param string $method the name of the plugin we create the area for @return int the new area id
[ "Creates", "a", "new", "shared", "area", "to", "hold", "a", "grading", "form", "template" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L584-L596
218,238
moodle/moodle
grade/grading/lib.php
grading_manager.delete_all_for_context
public static function delete_all_for_context($contextid) { global $DB; $areaids = $DB->get_fieldset_select('grading_areas', 'id', 'contextid = ?', array($contextid)); $methods = array_keys(self::available_methods(false)); foreach($areaids as $areaid) { $manager = get_grading_manager($areaid); foreach ($methods as $method) { $controller = $manager->get_controller($method); $controller->delete_definition(); } } $DB->delete_records_list('grading_areas', 'id', $areaids); }
php
public static function delete_all_for_context($contextid) { global $DB; $areaids = $DB->get_fieldset_select('grading_areas', 'id', 'contextid = ?', array($contextid)); $methods = array_keys(self::available_methods(false)); foreach($areaids as $areaid) { $manager = get_grading_manager($areaid); foreach ($methods as $method) { $controller = $manager->get_controller($method); $controller->delete_definition(); } } $DB->delete_records_list('grading_areas', 'id', $areaids); }
[ "public", "static", "function", "delete_all_for_context", "(", "$", "contextid", ")", "{", "global", "$", "DB", ";", "$", "areaids", "=", "$", "DB", "->", "get_fieldset_select", "(", "'grading_areas'", ",", "'id'", ",", "'contextid = ?'", ",", "array", "(", "$", "contextid", ")", ")", ";", "$", "methods", "=", "array_keys", "(", "self", "::", "available_methods", "(", "false", ")", ")", ";", "foreach", "(", "$", "areaids", "as", "$", "areaid", ")", "{", "$", "manager", "=", "get_grading_manager", "(", "$", "areaid", ")", ";", "foreach", "(", "$", "methods", "as", "$", "method", ")", "{", "$", "controller", "=", "$", "manager", "->", "get_controller", "(", "$", "method", ")", ";", "$", "controller", "->", "delete_definition", "(", ")", ";", "}", "}", "$", "DB", "->", "delete_records_list", "(", "'grading_areas'", ",", "'id'", ",", "$", "areaids", ")", ";", "}" ]
Removes all data associated with the given context This is called by {@link context::delete_content()} @param int $contextid context id
[ "Removes", "all", "data", "associated", "with", "the", "given", "context" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L605-L620
218,239
moodle/moodle
grade/grading/lib.php
grading_manager.tokenize
public static function tokenize($needle) { // check if we are searching for the exact phrase if (preg_match('/^[\s]*"[\s]*(.*?)[\s]*"[\s]*$/', $needle, $matches)) { $token = $matches[1]; if ($token === '') { return array(); } else { return array($token); } } // split the needle into smaller parts separated by non-word characters $tokens = preg_split("/\W/u", $needle); // keep just non-empty parts $tokens = array_filter($tokens); // distinct $tokens = array_unique($tokens); // drop one-letter tokens foreach ($tokens as $ix => $token) { if (strlen($token) == 1) { unset($tokens[$ix]); } } return array_values($tokens); }
php
public static function tokenize($needle) { // check if we are searching for the exact phrase if (preg_match('/^[\s]*"[\s]*(.*?)[\s]*"[\s]*$/', $needle, $matches)) { $token = $matches[1]; if ($token === '') { return array(); } else { return array($token); } } // split the needle into smaller parts separated by non-word characters $tokens = preg_split("/\W/u", $needle); // keep just non-empty parts $tokens = array_filter($tokens); // distinct $tokens = array_unique($tokens); // drop one-letter tokens foreach ($tokens as $ix => $token) { if (strlen($token) == 1) { unset($tokens[$ix]); } } return array_values($tokens); }
[ "public", "static", "function", "tokenize", "(", "$", "needle", ")", "{", "// check if we are searching for the exact phrase", "if", "(", "preg_match", "(", "'/^[\\s]*\"[\\s]*(.*?)[\\s]*\"[\\s]*$/'", ",", "$", "needle", ",", "$", "matches", ")", ")", "{", "$", "token", "=", "$", "matches", "[", "1", "]", ";", "if", "(", "$", "token", "===", "''", ")", "{", "return", "array", "(", ")", ";", "}", "else", "{", "return", "array", "(", "$", "token", ")", ";", "}", "}", "// split the needle into smaller parts separated by non-word characters", "$", "tokens", "=", "preg_split", "(", "\"/\\W/u\"", ",", "$", "needle", ")", ";", "// keep just non-empty parts", "$", "tokens", "=", "array_filter", "(", "$", "tokens", ")", ";", "// distinct", "$", "tokens", "=", "array_unique", "(", "$", "tokens", ")", ";", "// drop one-letter tokens", "foreach", "(", "$", "tokens", "as", "$", "ix", "=>", "$", "token", ")", "{", "if", "(", "strlen", "(", "$", "token", ")", "==", "1", ")", "{", "unset", "(", "$", "tokens", "[", "$", "ix", "]", ")", ";", "}", "}", "return", "array_values", "(", "$", "tokens", ")", ";", "}" ]
Helper method to tokenize the given string Splits the given string into smaller strings. This is a helper method for full text searching in grading forms. If the given string is surrounded with double quotes, the resulting array consists of a single item containing the quoted content. Otherwise, string like 'grammar, english language' would be tokenized into the three tokens 'grammar', 'english', 'language'. One-letter tokens like are dropped in non-phrase mode. Repeated tokens are returned just once. @param string $needle @return array
[ "Helper", "method", "to", "tokenize", "the", "given", "string" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L639-L665
218,240
moodle/moodle
grade/grading/lib.php
grading_manager.ensure_isset
private function ensure_isset(array $properties) { foreach ($properties as $property) { if (!isset($this->$property)) { throw new coding_exception('The property "'.$property.'" is not set.'); } } }
php
private function ensure_isset(array $properties) { foreach ($properties as $property) { if (!isset($this->$property)) { throw new coding_exception('The property "'.$property.'" is not set.'); } } }
[ "private", "function", "ensure_isset", "(", "array", "$", "properties", ")", "{", "foreach", "(", "$", "properties", "as", "$", "property", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "$", "property", ")", ")", "{", "throw", "new", "coding_exception", "(", "'The property \"'", ".", "$", "property", ".", "'\" is not set.'", ")", ";", "}", "}", "}" ]
Make sure that the given properties were set to some not-null value @param array $properties the list of properties @throws coding_exception
[ "Make", "sure", "that", "the", "given", "properties", "were", "set", "to", "some", "not", "-", "null", "value" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/lib.php#L675-L681
218,241
moodle/moodle
admin/tool/recyclebin/classes/base_bin.php
base_bin.delete_all_items
public function delete_all_items() { // Cleanup all items. $items = $this->get_items(); foreach ($items as $item) { if ($this->can_delete()) { $this->delete_item($item); } } }
php
public function delete_all_items() { // Cleanup all items. $items = $this->get_items(); foreach ($items as $item) { if ($this->can_delete()) { $this->delete_item($item); } } }
[ "public", "function", "delete_all_items", "(", ")", "{", "// Cleanup all items.", "$", "items", "=", "$", "this", "->", "get_items", "(", ")", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "if", "(", "$", "this", "->", "can_delete", "(", ")", ")", "{", "$", "this", "->", "delete_item", "(", "$", "item", ")", ";", "}", "}", "}" ]
Empty the recycle bin.
[ "Empty", "the", "recycle", "bin", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/recyclebin/classes/base_bin.php#L81-L89
218,242
moodle/moodle
customfield/field/textarea/classes/field_controller.php
field_controller.delete
public function delete() : bool { global $DB; $fs = get_file_storage(); // Delete files in the defaultvalue. $fs->delete_area_files($this->get_handler()->get_configuration_context()->id, 'customfield_textarea', 'defaultvalue', $this->get('id')); // Delete files in the data. We can not use $fs->delete_area_files_select() because context may be different. $params = ['component' => 'customfield_textarea', 'filearea' => 'value', 'fieldid' => $this->get('id')]; $where = "component = :component AND filearea = :filearea AND itemid IN (SELECT cfd.id FROM {customfield_data} cfd WHERE cfd.fieldid = :fieldid)"; $filerecords = $DB->get_recordset_select('files', $where, $params); foreach ($filerecords as $filerecord) { $fs->get_file_instance($filerecord)->delete(); } $filerecords->close(); // Delete data and field. return parent::delete(); }
php
public function delete() : bool { global $DB; $fs = get_file_storage(); // Delete files in the defaultvalue. $fs->delete_area_files($this->get_handler()->get_configuration_context()->id, 'customfield_textarea', 'defaultvalue', $this->get('id')); // Delete files in the data. We can not use $fs->delete_area_files_select() because context may be different. $params = ['component' => 'customfield_textarea', 'filearea' => 'value', 'fieldid' => $this->get('id')]; $where = "component = :component AND filearea = :filearea AND itemid IN (SELECT cfd.id FROM {customfield_data} cfd WHERE cfd.fieldid = :fieldid)"; $filerecords = $DB->get_recordset_select('files', $where, $params); foreach ($filerecords as $filerecord) { $fs->get_file_instance($filerecord)->delete(); } $filerecords->close(); // Delete data and field. return parent::delete(); }
[ "public", "function", "delete", "(", ")", ":", "bool", "{", "global", "$", "DB", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "// Delete files in the defaultvalue.", "$", "fs", "->", "delete_area_files", "(", "$", "this", "->", "get_handler", "(", ")", "->", "get_configuration_context", "(", ")", "->", "id", ",", "'customfield_textarea'", ",", "'defaultvalue'", ",", "$", "this", "->", "get", "(", "'id'", ")", ")", ";", "// Delete files in the data. We can not use $fs->delete_area_files_select() because context may be different.", "$", "params", "=", "[", "'component'", "=>", "'customfield_textarea'", ",", "'filearea'", "=>", "'value'", ",", "'fieldid'", "=>", "$", "this", "->", "get", "(", "'id'", ")", "]", ";", "$", "where", "=", "\"component = :component AND filearea = :filearea\n AND itemid IN (SELECT cfd.id FROM {customfield_data} cfd WHERE cfd.fieldid = :fieldid)\"", ";", "$", "filerecords", "=", "$", "DB", "->", "get_recordset_select", "(", "'files'", ",", "$", "where", ",", "$", "params", ")", ";", "foreach", "(", "$", "filerecords", "as", "$", "filerecord", ")", "{", "$", "fs", "->", "get_file_instance", "(", "$", "filerecord", ")", "->", "delete", "(", ")", ";", "}", "$", "filerecords", "->", "close", "(", ")", ";", "// Delete data and field.", "return", "parent", "::", "delete", "(", ")", ";", "}" ]
Before delete bulk actions
[ "Before", "delete", "bulk", "actions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/field/textarea/classes/field_controller.php#L45-L65
218,243
moodle/moodle
customfield/field/textarea/classes/field_controller.php
field_controller.prepare_for_config_form
public function prepare_for_config_form(\stdClass $formdata) { if (!empty($formdata->configdata['defaultvalue'])) { $textoptions = $this->value_editor_options(); $context = $textoptions['context']; $record = new \stdClass(); $record->defaultvalue = $formdata->configdata['defaultvalue']; $record->defaultvalueformat = $formdata->configdata['defaultvalueformat']; file_prepare_standard_editor($record, 'defaultvalue', $textoptions, $context, 'customfield_textarea', 'defaultvalue', $formdata->id); $formdata->configdata['defaultvalue_editor'] = $record->defaultvalue_editor; } }
php
public function prepare_for_config_form(\stdClass $formdata) { if (!empty($formdata->configdata['defaultvalue'])) { $textoptions = $this->value_editor_options(); $context = $textoptions['context']; $record = new \stdClass(); $record->defaultvalue = $formdata->configdata['defaultvalue']; $record->defaultvalueformat = $formdata->configdata['defaultvalueformat']; file_prepare_standard_editor($record, 'defaultvalue', $textoptions, $context, 'customfield_textarea', 'defaultvalue', $formdata->id); $formdata->configdata['defaultvalue_editor'] = $record->defaultvalue_editor; } }
[ "public", "function", "prepare_for_config_form", "(", "\\", "stdClass", "$", "formdata", ")", "{", "if", "(", "!", "empty", "(", "$", "formdata", "->", "configdata", "[", "'defaultvalue'", "]", ")", ")", "{", "$", "textoptions", "=", "$", "this", "->", "value_editor_options", "(", ")", ";", "$", "context", "=", "$", "textoptions", "[", "'context'", "]", ";", "$", "record", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "record", "->", "defaultvalue", "=", "$", "formdata", "->", "configdata", "[", "'defaultvalue'", "]", ";", "$", "record", "->", "defaultvalueformat", "=", "$", "formdata", "->", "configdata", "[", "'defaultvalueformat'", "]", ";", "file_prepare_standard_editor", "(", "$", "record", ",", "'defaultvalue'", ",", "$", "textoptions", ",", "$", "context", ",", "'customfield_textarea'", ",", "'defaultvalue'", ",", "$", "formdata", "->", "id", ")", ";", "$", "formdata", "->", "configdata", "[", "'defaultvalue_editor'", "]", "=", "$", "record", "->", "defaultvalue_editor", ";", "}", "}" ]
Prepare the field data to set in the configuration form Necessary if some preprocessing required for editor or filemanager fields @param \stdClass $formdata
[ "Prepare", "the", "field", "data", "to", "set", "in", "the", "configuration", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/field/textarea/classes/field_controller.php#L74-L87
218,244
moodle/moodle
customfield/field/textarea/classes/field_controller.php
field_controller.value_editor_options
public function value_editor_options(\context $context = null) { global $CFG; require_once($CFG->libdir.'/formslib.php'); if (!$context) { $context = $this->get_handler()->get_configuration_context(); } return ['maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'context' => $context]; }
php
public function value_editor_options(\context $context = null) { global $CFG; require_once($CFG->libdir.'/formslib.php'); if (!$context) { $context = $this->get_handler()->get_configuration_context(); } return ['maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'context' => $context]; }
[ "public", "function", "value_editor_options", "(", "\\", "context", "$", "context", "=", "null", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/formslib.php'", ")", ";", "if", "(", "!", "$", "context", ")", "{", "$", "context", "=", "$", "this", "->", "get_handler", "(", ")", "->", "get_configuration_context", "(", ")", ";", "}", "return", "[", "'maxfiles'", "=>", "EDITOR_UNLIMITED_FILES", ",", "'maxbytes'", "=>", "$", "CFG", "->", "maxbytes", ",", "'context'", "=>", "$", "context", "]", ";", "}" ]
Options for editor @param \context|null $context context if known, otherwise configuration context will be used @return array
[ "Options", "for", "editor" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/field/textarea/classes/field_controller.php#L110-L117
218,245
moodle/moodle
customfield/field/textarea/classes/field_controller.php
field_controller.save
public function save() { $configdata = $this->get('configdata'); if (!array_key_exists('defaultvalue_editor', $configdata)) { $this->field->save(); return; } if (!$this->get('id')) { $this->field->save(); } // Store files. $textoptions = $this->value_editor_options(); $tempvalue = (object) ['defaultvalue_editor' => $configdata['defaultvalue_editor']]; $tempvalue = file_postupdate_standard_editor($tempvalue, 'defaultvalue', $textoptions, $textoptions['context'], 'customfield_textarea', 'defaultvalue', $this->get('id')); $configdata['defaultvalue'] = $tempvalue->defaultvalue; $configdata['defaultvalueformat'] = $tempvalue->defaultvalueformat; unset($configdata['defaultvalue_editor']); $this->field->set('configdata', json_encode($configdata)); $this->field->save(); }
php
public function save() { $configdata = $this->get('configdata'); if (!array_key_exists('defaultvalue_editor', $configdata)) { $this->field->save(); return; } if (!$this->get('id')) { $this->field->save(); } // Store files. $textoptions = $this->value_editor_options(); $tempvalue = (object) ['defaultvalue_editor' => $configdata['defaultvalue_editor']]; $tempvalue = file_postupdate_standard_editor($tempvalue, 'defaultvalue', $textoptions, $textoptions['context'], 'customfield_textarea', 'defaultvalue', $this->get('id')); $configdata['defaultvalue'] = $tempvalue->defaultvalue; $configdata['defaultvalueformat'] = $tempvalue->defaultvalueformat; unset($configdata['defaultvalue_editor']); $this->field->set('configdata', json_encode($configdata)); $this->field->save(); }
[ "public", "function", "save", "(", ")", "{", "$", "configdata", "=", "$", "this", "->", "get", "(", "'configdata'", ")", ";", "if", "(", "!", "array_key_exists", "(", "'defaultvalue_editor'", ",", "$", "configdata", ")", ")", "{", "$", "this", "->", "field", "->", "save", "(", ")", ";", "return", ";", "}", "if", "(", "!", "$", "this", "->", "get", "(", "'id'", ")", ")", "{", "$", "this", "->", "field", "->", "save", "(", ")", ";", "}", "// Store files.", "$", "textoptions", "=", "$", "this", "->", "value_editor_options", "(", ")", ";", "$", "tempvalue", "=", "(", "object", ")", "[", "'defaultvalue_editor'", "=>", "$", "configdata", "[", "'defaultvalue_editor'", "]", "]", ";", "$", "tempvalue", "=", "file_postupdate_standard_editor", "(", "$", "tempvalue", ",", "'defaultvalue'", ",", "$", "textoptions", ",", "$", "textoptions", "[", "'context'", "]", ",", "'customfield_textarea'", ",", "'defaultvalue'", ",", "$", "this", "->", "get", "(", "'id'", ")", ")", ";", "$", "configdata", "[", "'defaultvalue'", "]", "=", "$", "tempvalue", "->", "defaultvalue", ";", "$", "configdata", "[", "'defaultvalueformat'", "]", "=", "$", "tempvalue", "->", "defaultvalueformat", ";", "unset", "(", "$", "configdata", "[", "'defaultvalue_editor'", "]", ")", ";", "$", "this", "->", "field", "->", "set", "(", "'configdata'", ",", "json_encode", "(", "$", "configdata", ")", ")", ";", "$", "this", "->", "field", "->", "save", "(", ")", ";", "}" ]
Saves the field configuration
[ "Saves", "the", "field", "configuration" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/field/textarea/classes/field_controller.php#L122-L144
218,246
moodle/moodle
competency/classes/external/performance_helper.php
performance_helper.get_context_from_competency
public function get_context_from_competency(competency $competency) { $frameworkid = $competency->get('competencyframeworkid'); if (!isset($this->frameworkscontexts[$frameworkid])) { $framework = $this->get_framework_from_competency($competency); $this->frameworkscontexts[$frameworkid] = $framework->get_context(); } return $this->frameworkscontexts[$frameworkid]; }
php
public function get_context_from_competency(competency $competency) { $frameworkid = $competency->get('competencyframeworkid'); if (!isset($this->frameworkscontexts[$frameworkid])) { $framework = $this->get_framework_from_competency($competency); $this->frameworkscontexts[$frameworkid] = $framework->get_context(); } return $this->frameworkscontexts[$frameworkid]; }
[ "public", "function", "get_context_from_competency", "(", "competency", "$", "competency", ")", "{", "$", "frameworkid", "=", "$", "competency", "->", "get", "(", "'competencyframeworkid'", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "frameworkscontexts", "[", "$", "frameworkid", "]", ")", ")", "{", "$", "framework", "=", "$", "this", "->", "get_framework_from_competency", "(", "$", "competency", ")", ";", "$", "this", "->", "frameworkscontexts", "[", "$", "frameworkid", "]", "=", "$", "framework", "->", "get_context", "(", ")", ";", "}", "return", "$", "this", "->", "frameworkscontexts", "[", "$", "frameworkid", "]", ";", "}" ]
Get the context of a competency. @param competency $competency The competency. @return \context
[ "Get", "the", "context", "of", "a", "competency", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external/performance_helper.php#L63-L70
218,247
moodle/moodle
competency/classes/external/performance_helper.php
performance_helper.get_framework_from_competency
public function get_framework_from_competency(competency $competency) { $frameworkid = $competency->get('competencyframeworkid'); if (!isset($this->frameworks[$frameworkid])) { $this->frameworks[$frameworkid] = $competency->get_framework(); } return $this->frameworks[$frameworkid]; }
php
public function get_framework_from_competency(competency $competency) { $frameworkid = $competency->get('competencyframeworkid'); if (!isset($this->frameworks[$frameworkid])) { $this->frameworks[$frameworkid] = $competency->get_framework(); } return $this->frameworks[$frameworkid]; }
[ "public", "function", "get_framework_from_competency", "(", "competency", "$", "competency", ")", "{", "$", "frameworkid", "=", "$", "competency", "->", "get", "(", "'competencyframeworkid'", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "frameworks", "[", "$", "frameworkid", "]", ")", ")", "{", "$", "this", "->", "frameworks", "[", "$", "frameworkid", "]", "=", "$", "competency", "->", "get_framework", "(", ")", ";", "}", "return", "$", "this", "->", "frameworks", "[", "$", "frameworkid", "]", ";", "}" ]
Get the framework of a competency. @param competency $competency The competency. @return competency_framework
[ "Get", "the", "framework", "of", "a", "competency", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external/performance_helper.php#L78-L84
218,248
moodle/moodle
competency/classes/external/performance_helper.php
performance_helper.get_scale_from_competency
public function get_scale_from_competency(competency $competency) { $scaleid = $competency->get('scaleid'); if ($scaleid !== null && !isset($this->scales[$scaleid])) { $this->scales[$scaleid] = $competency->get_scale(); } else if ($scaleid === null) { $framework = $this->get_framework_from_competency($competency); $scaleid = $framework->get('scaleid'); if (!isset($this->scales[$scaleid])) { $this->scales[$scaleid] = $framework->get_scale(); } } return $this->scales[$scaleid]; }
php
public function get_scale_from_competency(competency $competency) { $scaleid = $competency->get('scaleid'); if ($scaleid !== null && !isset($this->scales[$scaleid])) { $this->scales[$scaleid] = $competency->get_scale(); } else if ($scaleid === null) { $framework = $this->get_framework_from_competency($competency); $scaleid = $framework->get('scaleid'); if (!isset($this->scales[$scaleid])) { $this->scales[$scaleid] = $framework->get_scale(); } } return $this->scales[$scaleid]; }
[ "public", "function", "get_scale_from_competency", "(", "competency", "$", "competency", ")", "{", "$", "scaleid", "=", "$", "competency", "->", "get", "(", "'scaleid'", ")", ";", "if", "(", "$", "scaleid", "!==", "null", "&&", "!", "isset", "(", "$", "this", "->", "scales", "[", "$", "scaleid", "]", ")", ")", "{", "$", "this", "->", "scales", "[", "$", "scaleid", "]", "=", "$", "competency", "->", "get_scale", "(", ")", ";", "}", "else", "if", "(", "$", "scaleid", "===", "null", ")", "{", "$", "framework", "=", "$", "this", "->", "get_framework_from_competency", "(", "$", "competency", ")", ";", "$", "scaleid", "=", "$", "framework", "->", "get", "(", "'scaleid'", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "scales", "[", "$", "scaleid", "]", ")", ")", "{", "$", "this", "->", "scales", "[", "$", "scaleid", "]", "=", "$", "framework", "->", "get_scale", "(", ")", ";", "}", "}", "return", "$", "this", "->", "scales", "[", "$", "scaleid", "]", ";", "}" ]
Get the scale of a competency. /!\ Make sure that this is always kept in sync with: - core_competency\competency::get_scale() - core_competency\competency_framework::get_scale() @param competency $competency The competency. @return \grade_scale
[ "Get", "the", "scale", "of", "a", "competency", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external/performance_helper.php#L96-L110
218,249
moodle/moodle
competency/classes/external/performance_helper.php
performance_helper.ingest_framework
public function ingest_framework(competency_framework $framework) { $id = $framework->get('id'); $this->frameworks[$id] = $framework; }
php
public function ingest_framework(competency_framework $framework) { $id = $framework->get('id'); $this->frameworks[$id] = $framework; }
[ "public", "function", "ingest_framework", "(", "competency_framework", "$", "framework", ")", "{", "$", "id", "=", "$", "framework", "->", "get", "(", "'id'", ")", ";", "$", "this", "->", "frameworks", "[", "$", "id", "]", "=", "$", "framework", ";", "}" ]
Ingest a framework to avoid additional fetching. @param competency_framework $framework The framework. @return void
[ "Ingest", "a", "framework", "to", "avoid", "additional", "fetching", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/external/performance_helper.php#L118-L121
218,250
moodle/moodle
lib/externallib.php
external_api.validate_context
public static function validate_context($context) { global $CFG, $PAGE; if (empty($context)) { throw new invalid_parameter_exception('Context does not exist'); } if (empty(self::$contextrestriction)) { self::$contextrestriction = context_system::instance(); } $rcontext = self::$contextrestriction; if ($rcontext->contextlevel == $context->contextlevel) { if ($rcontext->id != $context->id) { throw new restricted_context_exception(); } } else if ($rcontext->contextlevel > $context->contextlevel) { throw new restricted_context_exception(); } else { $parents = $context->get_parent_context_ids(); if (!in_array($rcontext->id, $parents)) { throw new restricted_context_exception(); } } $PAGE->reset_theme_and_output(); list($unused, $course, $cm) = get_context_info_array($context->id); require_login($course, false, $cm, false, true); $PAGE->set_context($context); }
php
public static function validate_context($context) { global $CFG, $PAGE; if (empty($context)) { throw new invalid_parameter_exception('Context does not exist'); } if (empty(self::$contextrestriction)) { self::$contextrestriction = context_system::instance(); } $rcontext = self::$contextrestriction; if ($rcontext->contextlevel == $context->contextlevel) { if ($rcontext->id != $context->id) { throw new restricted_context_exception(); } } else if ($rcontext->contextlevel > $context->contextlevel) { throw new restricted_context_exception(); } else { $parents = $context->get_parent_context_ids(); if (!in_array($rcontext->id, $parents)) { throw new restricted_context_exception(); } } $PAGE->reset_theme_and_output(); list($unused, $course, $cm) = get_context_info_array($context->id); require_login($course, false, $cm, false, true); $PAGE->set_context($context); }
[ "public", "static", "function", "validate_context", "(", "$", "context", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ";", "if", "(", "empty", "(", "$", "context", ")", ")", "{", "throw", "new", "invalid_parameter_exception", "(", "'Context does not exist'", ")", ";", "}", "if", "(", "empty", "(", "self", "::", "$", "contextrestriction", ")", ")", "{", "self", "::", "$", "contextrestriction", "=", "context_system", "::", "instance", "(", ")", ";", "}", "$", "rcontext", "=", "self", "::", "$", "contextrestriction", ";", "if", "(", "$", "rcontext", "->", "contextlevel", "==", "$", "context", "->", "contextlevel", ")", "{", "if", "(", "$", "rcontext", "->", "id", "!=", "$", "context", "->", "id", ")", "{", "throw", "new", "restricted_context_exception", "(", ")", ";", "}", "}", "else", "if", "(", "$", "rcontext", "->", "contextlevel", ">", "$", "context", "->", "contextlevel", ")", "{", "throw", "new", "restricted_context_exception", "(", ")", ";", "}", "else", "{", "$", "parents", "=", "$", "context", "->", "get_parent_context_ids", "(", ")", ";", "if", "(", "!", "in_array", "(", "$", "rcontext", "->", "id", ",", "$", "parents", ")", ")", "{", "throw", "new", "restricted_context_exception", "(", ")", ";", "}", "}", "$", "PAGE", "->", "reset_theme_and_output", "(", ")", ";", "list", "(", "$", "unused", ",", "$", "course", ",", "$", "cm", ")", "=", "get_context_info_array", "(", "$", "context", "->", "id", ")", ";", "require_login", "(", "$", "course", ",", "false", ",", "$", "cm", ",", "false", ",", "true", ")", ";", "$", "PAGE", "->", "set_context", "(", "$", "context", ")", ";", "}" ]
Makes sure user may execute functions in this context. @param stdClass $context @since Moodle 2.0
[ "Makes", "sure", "user", "may", "execute", "functions", "in", "this", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/externallib.php#L472-L500
218,251
moodle/moodle
lib/externallib.php
external_api.get_context_from_params
protected static function get_context_from_params($param) { $levels = context_helper::get_all_levels(); if (!empty($param['contextid'])) { return context::instance_by_id($param['contextid'], IGNORE_MISSING); } else if (!empty($param['contextlevel']) && isset($param['instanceid'])) { $contextlevel = "context_".$param['contextlevel']; if (!array_search($contextlevel, $levels)) { throw new invalid_parameter_exception('Invalid context level = '.$param['contextlevel']); } return $contextlevel::instance($param['instanceid'], IGNORE_MISSING); } else { // No valid context info was found. throw new invalid_parameter_exception('Missing parameters, please provide either context level with instance id or contextid'); } }
php
protected static function get_context_from_params($param) { $levels = context_helper::get_all_levels(); if (!empty($param['contextid'])) { return context::instance_by_id($param['contextid'], IGNORE_MISSING); } else if (!empty($param['contextlevel']) && isset($param['instanceid'])) { $contextlevel = "context_".$param['contextlevel']; if (!array_search($contextlevel, $levels)) { throw new invalid_parameter_exception('Invalid context level = '.$param['contextlevel']); } return $contextlevel::instance($param['instanceid'], IGNORE_MISSING); } else { // No valid context info was found. throw new invalid_parameter_exception('Missing parameters, please provide either context level with instance id or contextid'); } }
[ "protected", "static", "function", "get_context_from_params", "(", "$", "param", ")", "{", "$", "levels", "=", "context_helper", "::", "get_all_levels", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "param", "[", "'contextid'", "]", ")", ")", "{", "return", "context", "::", "instance_by_id", "(", "$", "param", "[", "'contextid'", "]", ",", "IGNORE_MISSING", ")", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "param", "[", "'contextlevel'", "]", ")", "&&", "isset", "(", "$", "param", "[", "'instanceid'", "]", ")", ")", "{", "$", "contextlevel", "=", "\"context_\"", ".", "$", "param", "[", "'contextlevel'", "]", ";", "if", "(", "!", "array_search", "(", "$", "contextlevel", ",", "$", "levels", ")", ")", "{", "throw", "new", "invalid_parameter_exception", "(", "'Invalid context level = '", ".", "$", "param", "[", "'contextlevel'", "]", ")", ";", "}", "return", "$", "contextlevel", "::", "instance", "(", "$", "param", "[", "'instanceid'", "]", ",", "IGNORE_MISSING", ")", ";", "}", "else", "{", "// No valid context info was found.", "throw", "new", "invalid_parameter_exception", "(", "'Missing parameters, please provide either context level with instance id or contextid'", ")", ";", "}", "}" ]
Get context from passed parameters. The passed array must either contain a contextid or a combination of context level and instance id to fetch the context. For example, the context level can be "course" and instanceid can be courseid. See context_helper::get_all_levels() for a list of valid context levels. @param array $param @since Moodle 2.6 @throws invalid_parameter_exception @return context
[ "Get", "context", "from", "passed", "parameters", ".", "The", "passed", "array", "must", "either", "contain", "a", "contextid", "or", "a", "combination", "of", "context", "level", "and", "instance", "id", "to", "fetch", "the", "context", ".", "For", "example", "the", "context", "level", "can", "be", "course", "and", "instanceid", "can", "be", "courseid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/externallib.php#L514-L528
218,252
moodle/moodle
lib/externallib.php
external_util.validate_courses
public static function validate_courses($courseids, $courses = array(), $addcontext = false) { // Delete duplicates. $courseids = array_unique($courseids); $warnings = array(); // Remove courses which are not even requested. $courses = array_intersect_key($courses, array_flip($courseids)); foreach ($courseids as $cid) { // Check the user can function in this context. try { $context = context_course::instance($cid); external_api::validate_context($context); if (!isset($courses[$cid])) { $courses[$cid] = get_course($cid); } if ($addcontext) { $courses[$cid]->context = $context; } } catch (Exception $e) { unset($courses[$cid]); $warnings[] = array( 'item' => 'course', 'itemid' => $cid, 'warningcode' => '1', 'message' => 'No access rights in course context' ); } } return array($courses, $warnings); }
php
public static function validate_courses($courseids, $courses = array(), $addcontext = false) { // Delete duplicates. $courseids = array_unique($courseids); $warnings = array(); // Remove courses which are not even requested. $courses = array_intersect_key($courses, array_flip($courseids)); foreach ($courseids as $cid) { // Check the user can function in this context. try { $context = context_course::instance($cid); external_api::validate_context($context); if (!isset($courses[$cid])) { $courses[$cid] = get_course($cid); } if ($addcontext) { $courses[$cid]->context = $context; } } catch (Exception $e) { unset($courses[$cid]); $warnings[] = array( 'item' => 'course', 'itemid' => $cid, 'warningcode' => '1', 'message' => 'No access rights in course context' ); } } return array($courses, $warnings); }
[ "public", "static", "function", "validate_courses", "(", "$", "courseids", ",", "$", "courses", "=", "array", "(", ")", ",", "$", "addcontext", "=", "false", ")", "{", "// Delete duplicates.", "$", "courseids", "=", "array_unique", "(", "$", "courseids", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "// Remove courses which are not even requested.", "$", "courses", "=", "array_intersect_key", "(", "$", "courses", ",", "array_flip", "(", "$", "courseids", ")", ")", ";", "foreach", "(", "$", "courseids", "as", "$", "cid", ")", "{", "// Check the user can function in this context.", "try", "{", "$", "context", "=", "context_course", "::", "instance", "(", "$", "cid", ")", ";", "external_api", "::", "validate_context", "(", "$", "context", ")", ";", "if", "(", "!", "isset", "(", "$", "courses", "[", "$", "cid", "]", ")", ")", "{", "$", "courses", "[", "$", "cid", "]", "=", "get_course", "(", "$", "cid", ")", ";", "}", "if", "(", "$", "addcontext", ")", "{", "$", "courses", "[", "$", "cid", "]", "->", "context", "=", "$", "context", ";", "}", "}", "catch", "(", "Exception", "$", "e", ")", "{", "unset", "(", "$", "courses", "[", "$", "cid", "]", ")", ";", "$", "warnings", "[", "]", "=", "array", "(", "'item'", "=>", "'course'", ",", "'itemid'", "=>", "$", "cid", ",", "'warningcode'", "=>", "'1'", ",", "'message'", "=>", "'No access rights in course context'", ")", ";", "}", "}", "return", "array", "(", "$", "courses", ",", "$", "warnings", ")", ";", "}" ]
Validate a list of courses, returning the complete course objects for valid courses. @param array $courseids A list of course ids @param array $courses An array of courses already pre-fetched, indexed by course id. @param bool $addcontext True if the returned course object should include the full context object. @return array An array of courses and the validation warnings
[ "Validate", "a", "list", "of", "courses", "returning", "the", "complete", "course", "objects", "for", "valid", "courses", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/externallib.php#L1342-L1374
218,253
moodle/moodle
lib/externallib.php
external_files.get_properties_for_exporter
public static function get_properties_for_exporter() { return [ 'filename' => array( 'type' => PARAM_FILE, 'description' => 'File name.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'filepath' => array( 'type' => PARAM_PATH, 'description' => 'File path.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'filesize' => array( 'type' => PARAM_INT, 'description' => 'File size.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'fileurl' => array( 'type' => PARAM_URL, 'description' => 'Downloadable file url.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'timemodified' => array( 'type' => PARAM_INT, 'description' => 'Time modified.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'mimetype' => array( 'type' => PARAM_RAW, 'description' => 'File mime type.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'isexternalfile' => array( 'type' => PARAM_BOOL, 'description' => 'Whether is an external file.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'repositorytype' => array( 'type' => PARAM_PLUGIN, 'description' => 'The repository type for the external files.', 'optional' => true, 'null' => NULL_ALLOWED, ), ]; }
php
public static function get_properties_for_exporter() { return [ 'filename' => array( 'type' => PARAM_FILE, 'description' => 'File name.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'filepath' => array( 'type' => PARAM_PATH, 'description' => 'File path.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'filesize' => array( 'type' => PARAM_INT, 'description' => 'File size.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'fileurl' => array( 'type' => PARAM_URL, 'description' => 'Downloadable file url.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'timemodified' => array( 'type' => PARAM_INT, 'description' => 'Time modified.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'mimetype' => array( 'type' => PARAM_RAW, 'description' => 'File mime type.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'isexternalfile' => array( 'type' => PARAM_BOOL, 'description' => 'Whether is an external file.', 'optional' => true, 'null' => NULL_NOT_ALLOWED, ), 'repositorytype' => array( 'type' => PARAM_PLUGIN, 'description' => 'The repository type for the external files.', 'optional' => true, 'null' => NULL_ALLOWED, ), ]; }
[ "public", "static", "function", "get_properties_for_exporter", "(", ")", "{", "return", "[", "'filename'", "=>", "array", "(", "'type'", "=>", "PARAM_FILE", ",", "'description'", "=>", "'File name.'", ",", "'optional'", "=>", "true", ",", "'null'", "=>", "NULL_NOT_ALLOWED", ",", ")", ",", "'filepath'", "=>", "array", "(", "'type'", "=>", "PARAM_PATH", ",", "'description'", "=>", "'File path.'", ",", "'optional'", "=>", "true", ",", "'null'", "=>", "NULL_NOT_ALLOWED", ",", ")", ",", "'filesize'", "=>", "array", "(", "'type'", "=>", "PARAM_INT", ",", "'description'", "=>", "'File size.'", ",", "'optional'", "=>", "true", ",", "'null'", "=>", "NULL_NOT_ALLOWED", ",", ")", ",", "'fileurl'", "=>", "array", "(", "'type'", "=>", "PARAM_URL", ",", "'description'", "=>", "'Downloadable file url.'", ",", "'optional'", "=>", "true", ",", "'null'", "=>", "NULL_NOT_ALLOWED", ",", ")", ",", "'timemodified'", "=>", "array", "(", "'type'", "=>", "PARAM_INT", ",", "'description'", "=>", "'Time modified.'", ",", "'optional'", "=>", "true", ",", "'null'", "=>", "NULL_NOT_ALLOWED", ",", ")", ",", "'mimetype'", "=>", "array", "(", "'type'", "=>", "PARAM_RAW", ",", "'description'", "=>", "'File mime type.'", ",", "'optional'", "=>", "true", ",", "'null'", "=>", "NULL_NOT_ALLOWED", ",", ")", ",", "'isexternalfile'", "=>", "array", "(", "'type'", "=>", "PARAM_BOOL", ",", "'description'", "=>", "'Whether is an external file.'", ",", "'optional'", "=>", "true", ",", "'null'", "=>", "NULL_NOT_ALLOWED", ",", ")", ",", "'repositorytype'", "=>", "array", "(", "'type'", "=>", "PARAM_PLUGIN", ",", "'description'", "=>", "'The repository type for the external files.'", ",", "'optional'", "=>", "true", ",", "'null'", "=>", "NULL_ALLOWED", ",", ")", ",", "]", ";", "}" ]
Return the properties ready to be used by an exporter. @return array properties @since Moodle 3.3
[ "Return", "the", "properties", "ready", "to", "be", "used", "by", "an", "exporter", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/externallib.php#L1455-L1506
218,254
moodle/moodle
lib/ddl/sql_generator.php
sql_generator.getFieldSQL
public function getFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause = NULL, $skip_default_clause = NULL, $skip_notnull_clause = NULL, $specify_nulls_clause = NULL, $specify_field_name = true) { if ($error = $xmldb_field->validateDefinition($xmldb_table)) { throw new coding_exception($error); } $skip_type_clause = is_null($skip_type_clause) ? $this->alter_column_skip_type : $skip_type_clause; $skip_default_clause = is_null($skip_default_clause) ? $this->alter_column_skip_default : $skip_default_clause; $skip_notnull_clause = is_null($skip_notnull_clause) ? $this->alter_column_skip_notnull : $skip_notnull_clause; $specify_nulls_clause = is_null($specify_nulls_clause) ? $this->specify_nulls : $specify_nulls_clause; // First of all, convert integers to numbers if defined if ($this->integer_to_number) { if ($xmldb_field->getType() == XMLDB_TYPE_INTEGER) { $xmldb_field->setType(XMLDB_TYPE_NUMBER); } } // Same for floats if ($this->float_to_number) { if ($xmldb_field->getType() == XMLDB_TYPE_FLOAT) { $xmldb_field->setType(XMLDB_TYPE_NUMBER); } } $field = ''; // Let's accumulate the whole expression based on params and settings // The name if ($specify_field_name) { $field .= $this->getEncQuoted($xmldb_field->getName()); } // The type and length only if we don't want to skip it if (!$skip_type_clause) { // The type and length $field .= ' ' . $this->getTypeSQL($xmldb_field->getType(), $xmldb_field->getLength(), $xmldb_field->getDecimals()); } // note: unsigned is not supported any more since moodle 2.3, all numbers are signed // Calculate the not null clause $notnull = ''; // Only if we don't want to skip it if (!$skip_notnull_clause) { if ($xmldb_field->getNotNull()) { $notnull = ' NOT NULL'; } else { if ($specify_nulls_clause) { $notnull = ' NULL'; } } } // Calculate the default clause $default_clause = ''; if (!$skip_default_clause) { //Only if we don't want to skip it $default_clause = $this->getDefaultClause($xmldb_field); } // Based on default_after_null, set both clauses properly if ($this->default_after_null) { $field .= $notnull . $default_clause; } else { $field .= $default_clause . $notnull; } // The sequence if ($xmldb_field->getSequence()) { if($xmldb_field->getLength()<=9 && $this->sequence_name_small) { $sequencename=$this->sequence_name_small; } else { $sequencename=$this->sequence_name; } $field .= ' ' . $sequencename; if ($this->sequence_only) { // We only want the field name and sequence name to be printed // so, calculate it and return $sql = $this->getEncQuoted($xmldb_field->getName()) . ' ' . $sequencename; return $sql; } } return $field; }
php
public function getFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause = NULL, $skip_default_clause = NULL, $skip_notnull_clause = NULL, $specify_nulls_clause = NULL, $specify_field_name = true) { if ($error = $xmldb_field->validateDefinition($xmldb_table)) { throw new coding_exception($error); } $skip_type_clause = is_null($skip_type_clause) ? $this->alter_column_skip_type : $skip_type_clause; $skip_default_clause = is_null($skip_default_clause) ? $this->alter_column_skip_default : $skip_default_clause; $skip_notnull_clause = is_null($skip_notnull_clause) ? $this->alter_column_skip_notnull : $skip_notnull_clause; $specify_nulls_clause = is_null($specify_nulls_clause) ? $this->specify_nulls : $specify_nulls_clause; // First of all, convert integers to numbers if defined if ($this->integer_to_number) { if ($xmldb_field->getType() == XMLDB_TYPE_INTEGER) { $xmldb_field->setType(XMLDB_TYPE_NUMBER); } } // Same for floats if ($this->float_to_number) { if ($xmldb_field->getType() == XMLDB_TYPE_FLOAT) { $xmldb_field->setType(XMLDB_TYPE_NUMBER); } } $field = ''; // Let's accumulate the whole expression based on params and settings // The name if ($specify_field_name) { $field .= $this->getEncQuoted($xmldb_field->getName()); } // The type and length only if we don't want to skip it if (!$skip_type_clause) { // The type and length $field .= ' ' . $this->getTypeSQL($xmldb_field->getType(), $xmldb_field->getLength(), $xmldb_field->getDecimals()); } // note: unsigned is not supported any more since moodle 2.3, all numbers are signed // Calculate the not null clause $notnull = ''; // Only if we don't want to skip it if (!$skip_notnull_clause) { if ($xmldb_field->getNotNull()) { $notnull = ' NOT NULL'; } else { if ($specify_nulls_clause) { $notnull = ' NULL'; } } } // Calculate the default clause $default_clause = ''; if (!$skip_default_clause) { //Only if we don't want to skip it $default_clause = $this->getDefaultClause($xmldb_field); } // Based on default_after_null, set both clauses properly if ($this->default_after_null) { $field .= $notnull . $default_clause; } else { $field .= $default_clause . $notnull; } // The sequence if ($xmldb_field->getSequence()) { if($xmldb_field->getLength()<=9 && $this->sequence_name_small) { $sequencename=$this->sequence_name_small; } else { $sequencename=$this->sequence_name; } $field .= ' ' . $sequencename; if ($this->sequence_only) { // We only want the field name and sequence name to be printed // so, calculate it and return $sql = $this->getEncQuoted($xmldb_field->getName()) . ' ' . $sequencename; return $sql; } } return $field; }
[ "public", "function", "getFieldSQL", "(", "$", "xmldb_table", ",", "$", "xmldb_field", ",", "$", "skip_type_clause", "=", "NULL", ",", "$", "skip_default_clause", "=", "NULL", ",", "$", "skip_notnull_clause", "=", "NULL", ",", "$", "specify_nulls_clause", "=", "NULL", ",", "$", "specify_field_name", "=", "true", ")", "{", "if", "(", "$", "error", "=", "$", "xmldb_field", "->", "validateDefinition", "(", "$", "xmldb_table", ")", ")", "{", "throw", "new", "coding_exception", "(", "$", "error", ")", ";", "}", "$", "skip_type_clause", "=", "is_null", "(", "$", "skip_type_clause", ")", "?", "$", "this", "->", "alter_column_skip_type", ":", "$", "skip_type_clause", ";", "$", "skip_default_clause", "=", "is_null", "(", "$", "skip_default_clause", ")", "?", "$", "this", "->", "alter_column_skip_default", ":", "$", "skip_default_clause", ";", "$", "skip_notnull_clause", "=", "is_null", "(", "$", "skip_notnull_clause", ")", "?", "$", "this", "->", "alter_column_skip_notnull", ":", "$", "skip_notnull_clause", ";", "$", "specify_nulls_clause", "=", "is_null", "(", "$", "specify_nulls_clause", ")", "?", "$", "this", "->", "specify_nulls", ":", "$", "specify_nulls_clause", ";", "// First of all, convert integers to numbers if defined", "if", "(", "$", "this", "->", "integer_to_number", ")", "{", "if", "(", "$", "xmldb_field", "->", "getType", "(", ")", "==", "XMLDB_TYPE_INTEGER", ")", "{", "$", "xmldb_field", "->", "setType", "(", "XMLDB_TYPE_NUMBER", ")", ";", "}", "}", "// Same for floats", "if", "(", "$", "this", "->", "float_to_number", ")", "{", "if", "(", "$", "xmldb_field", "->", "getType", "(", ")", "==", "XMLDB_TYPE_FLOAT", ")", "{", "$", "xmldb_field", "->", "setType", "(", "XMLDB_TYPE_NUMBER", ")", ";", "}", "}", "$", "field", "=", "''", ";", "// Let's accumulate the whole expression based on params and settings", "// The name", "if", "(", "$", "specify_field_name", ")", "{", "$", "field", ".=", "$", "this", "->", "getEncQuoted", "(", "$", "xmldb_field", "->", "getName", "(", ")", ")", ";", "}", "// The type and length only if we don't want to skip it", "if", "(", "!", "$", "skip_type_clause", ")", "{", "// The type and length", "$", "field", ".=", "' '", ".", "$", "this", "->", "getTypeSQL", "(", "$", "xmldb_field", "->", "getType", "(", ")", ",", "$", "xmldb_field", "->", "getLength", "(", ")", ",", "$", "xmldb_field", "->", "getDecimals", "(", ")", ")", ";", "}", "// note: unsigned is not supported any more since moodle 2.3, all numbers are signed", "// Calculate the not null clause", "$", "notnull", "=", "''", ";", "// Only if we don't want to skip it", "if", "(", "!", "$", "skip_notnull_clause", ")", "{", "if", "(", "$", "xmldb_field", "->", "getNotNull", "(", ")", ")", "{", "$", "notnull", "=", "' NOT NULL'", ";", "}", "else", "{", "if", "(", "$", "specify_nulls_clause", ")", "{", "$", "notnull", "=", "' NULL'", ";", "}", "}", "}", "// Calculate the default clause", "$", "default_clause", "=", "''", ";", "if", "(", "!", "$", "skip_default_clause", ")", "{", "//Only if we don't want to skip it", "$", "default_clause", "=", "$", "this", "->", "getDefaultClause", "(", "$", "xmldb_field", ")", ";", "}", "// Based on default_after_null, set both clauses properly", "if", "(", "$", "this", "->", "default_after_null", ")", "{", "$", "field", ".=", "$", "notnull", ".", "$", "default_clause", ";", "}", "else", "{", "$", "field", ".=", "$", "default_clause", ".", "$", "notnull", ";", "}", "// The sequence", "if", "(", "$", "xmldb_field", "->", "getSequence", "(", ")", ")", "{", "if", "(", "$", "xmldb_field", "->", "getLength", "(", ")", "<=", "9", "&&", "$", "this", "->", "sequence_name_small", ")", "{", "$", "sequencename", "=", "$", "this", "->", "sequence_name_small", ";", "}", "else", "{", "$", "sequencename", "=", "$", "this", "->", "sequence_name", ";", "}", "$", "field", ".=", "' '", ".", "$", "sequencename", ";", "if", "(", "$", "this", "->", "sequence_only", ")", "{", "// We only want the field name and sequence name to be printed", "// so, calculate it and return", "$", "sql", "=", "$", "this", "->", "getEncQuoted", "(", "$", "xmldb_field", "->", "getName", "(", ")", ")", ".", "' '", ".", "$", "sequencename", ";", "return", "$", "sql", ";", "}", "}", "return", "$", "field", ";", "}" ]
Given one correct xmldb_field, returns the complete SQL line to create it. @param xmldb_table $xmldb_table The table related to $xmldb_field. @param xmldb_field $xmldb_field The instance of xmldb_field to create the SQL from. @param string $skip_type_clause The type clause on alter columns, NULL by default. @param string $skip_default_clause The default clause on alter columns, NULL by default. @param string $skip_notnull_clause The null/notnull clause on alter columns, NULL by default. @param string $specify_nulls_clause To force a specific null clause, NULL by default. @param bool $specify_field_name Flag to specify fieldname in return. @return string The field generating SQL statement. @throws coding_exception Thrown when xmldb_field doesn't validate with the xmldb_table.
[ "Given", "one", "correct", "xmldb_field", "returns", "the", "complete", "SQL", "line", "to", "create", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/sql_generator.php#L454-L527
218,255
moodle/moodle
lib/ddl/sql_generator.php
sql_generator.getKeySQL
public function getKeySQL($xmldb_table, $xmldb_key) { $key = ''; switch ($xmldb_key->getType()) { case XMLDB_KEY_PRIMARY: if ($this->primary_keys) { if ($this->primary_key_name !== null) { $key = $this->getEncQuoted($this->primary_key_name); } else { $key = $this->getNameForObject($xmldb_table->getName(), implode(', ', $xmldb_key->getFields()), 'pk'); } $key .= ' PRIMARY KEY (' . implode(', ', $this->getEncQuoted($xmldb_key->getFields())) . ')'; } break; case XMLDB_KEY_UNIQUE: if ($this->unique_keys) { $key = $this->getNameForObject($xmldb_table->getName(), implode(', ', $xmldb_key->getFields()), 'uk'); $key .= ' UNIQUE (' . implode(', ', $this->getEncQuoted($xmldb_key->getFields())) . ')'; } break; case XMLDB_KEY_FOREIGN: case XMLDB_KEY_FOREIGN_UNIQUE: if ($this->foreign_keys) { $key = $this->getNameForObject($xmldb_table->getName(), implode(', ', $xmldb_key->getFields()), 'fk'); $key .= ' FOREIGN KEY (' . implode(', ', $this->getEncQuoted($xmldb_key->getFields())) . ')'; $key .= ' REFERENCES ' . $this->getEncQuoted($this->prefix . $xmldb_key->getRefTable()); $key .= ' (' . implode(', ', $this->getEncQuoted($xmldb_key->getRefFields())) . ')'; } break; } return $key; }
php
public function getKeySQL($xmldb_table, $xmldb_key) { $key = ''; switch ($xmldb_key->getType()) { case XMLDB_KEY_PRIMARY: if ($this->primary_keys) { if ($this->primary_key_name !== null) { $key = $this->getEncQuoted($this->primary_key_name); } else { $key = $this->getNameForObject($xmldb_table->getName(), implode(', ', $xmldb_key->getFields()), 'pk'); } $key .= ' PRIMARY KEY (' . implode(', ', $this->getEncQuoted($xmldb_key->getFields())) . ')'; } break; case XMLDB_KEY_UNIQUE: if ($this->unique_keys) { $key = $this->getNameForObject($xmldb_table->getName(), implode(', ', $xmldb_key->getFields()), 'uk'); $key .= ' UNIQUE (' . implode(', ', $this->getEncQuoted($xmldb_key->getFields())) . ')'; } break; case XMLDB_KEY_FOREIGN: case XMLDB_KEY_FOREIGN_UNIQUE: if ($this->foreign_keys) { $key = $this->getNameForObject($xmldb_table->getName(), implode(', ', $xmldb_key->getFields()), 'fk'); $key .= ' FOREIGN KEY (' . implode(', ', $this->getEncQuoted($xmldb_key->getFields())) . ')'; $key .= ' REFERENCES ' . $this->getEncQuoted($this->prefix . $xmldb_key->getRefTable()); $key .= ' (' . implode(', ', $this->getEncQuoted($xmldb_key->getRefFields())) . ')'; } break; } return $key; }
[ "public", "function", "getKeySQL", "(", "$", "xmldb_table", ",", "$", "xmldb_key", ")", "{", "$", "key", "=", "''", ";", "switch", "(", "$", "xmldb_key", "->", "getType", "(", ")", ")", "{", "case", "XMLDB_KEY_PRIMARY", ":", "if", "(", "$", "this", "->", "primary_keys", ")", "{", "if", "(", "$", "this", "->", "primary_key_name", "!==", "null", ")", "{", "$", "key", "=", "$", "this", "->", "getEncQuoted", "(", "$", "this", "->", "primary_key_name", ")", ";", "}", "else", "{", "$", "key", "=", "$", "this", "->", "getNameForObject", "(", "$", "xmldb_table", "->", "getName", "(", ")", ",", "implode", "(", "', '", ",", "$", "xmldb_key", "->", "getFields", "(", ")", ")", ",", "'pk'", ")", ";", "}", "$", "key", ".=", "' PRIMARY KEY ('", ".", "implode", "(", "', '", ",", "$", "this", "->", "getEncQuoted", "(", "$", "xmldb_key", "->", "getFields", "(", ")", ")", ")", ".", "')'", ";", "}", "break", ";", "case", "XMLDB_KEY_UNIQUE", ":", "if", "(", "$", "this", "->", "unique_keys", ")", "{", "$", "key", "=", "$", "this", "->", "getNameForObject", "(", "$", "xmldb_table", "->", "getName", "(", ")", ",", "implode", "(", "', '", ",", "$", "xmldb_key", "->", "getFields", "(", ")", ")", ",", "'uk'", ")", ";", "$", "key", ".=", "' UNIQUE ('", ".", "implode", "(", "', '", ",", "$", "this", "->", "getEncQuoted", "(", "$", "xmldb_key", "->", "getFields", "(", ")", ")", ")", ".", "')'", ";", "}", "break", ";", "case", "XMLDB_KEY_FOREIGN", ":", "case", "XMLDB_KEY_FOREIGN_UNIQUE", ":", "if", "(", "$", "this", "->", "foreign_keys", ")", "{", "$", "key", "=", "$", "this", "->", "getNameForObject", "(", "$", "xmldb_table", "->", "getName", "(", ")", ",", "implode", "(", "', '", ",", "$", "xmldb_key", "->", "getFields", "(", ")", ")", ",", "'fk'", ")", ";", "$", "key", ".=", "' FOREIGN KEY ('", ".", "implode", "(", "', '", ",", "$", "this", "->", "getEncQuoted", "(", "$", "xmldb_key", "->", "getFields", "(", ")", ")", ")", ".", "')'", ";", "$", "key", ".=", "' REFERENCES '", ".", "$", "this", "->", "getEncQuoted", "(", "$", "this", "->", "prefix", ".", "$", "xmldb_key", "->", "getRefTable", "(", ")", ")", ";", "$", "key", ".=", "' ('", ".", "implode", "(", "', '", ",", "$", "this", "->", "getEncQuoted", "(", "$", "xmldb_key", "->", "getRefFields", "(", ")", ")", ")", ".", "')'", ";", "}", "break", ";", "}", "return", "$", "key", ";", "}" ]
Given one correct xmldb_key, returns its specs. @param xmldb_table $xmldb_table The table related to $xmldb_key. @param xmldb_key $xmldb_key The xmldb_key's specifications requested. @return string SQL statement about the xmldb_key.
[ "Given", "one", "correct", "xmldb_key", "returns", "its", "specs", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/sql_generator.php#L536-L569
218,256
moodle/moodle
lib/ddl/sql_generator.php
sql_generator.getDefaultValue
public function getDefaultValue($xmldb_field) { $default = null; if ($xmldb_field->getDefault() !== NULL) { if ($xmldb_field->getType() == XMLDB_TYPE_CHAR || $xmldb_field->getType() == XMLDB_TYPE_TEXT) { if ($xmldb_field->getDefault() === '') { // If passing empty default, use the $default_for_char one instead $default = "'" . $this->default_for_char . "'"; } else { $default = "'" . $this->addslashes($xmldb_field->getDefault()) . "'"; } } else { $default = $xmldb_field->getDefault(); } } else { // We force default '' for not null char columns without proper default // some day this should be out! if ($this->default_for_char !== NULL && $xmldb_field->getType() == XMLDB_TYPE_CHAR && $xmldb_field->getNotNull()) { $default = "'" . $this->default_for_char . "'"; } else { // If the DB requires to explicity define some clause to drop one default, do it here // never applying defaults to TEXT and BINARY fields if ($this->drop_default_value_required && $xmldb_field->getType() != XMLDB_TYPE_TEXT && $xmldb_field->getType() != XMLDB_TYPE_BINARY && !$xmldb_field->getNotNull()) { $default = $this->drop_default_value; } } } return $default; }
php
public function getDefaultValue($xmldb_field) { $default = null; if ($xmldb_field->getDefault() !== NULL) { if ($xmldb_field->getType() == XMLDB_TYPE_CHAR || $xmldb_field->getType() == XMLDB_TYPE_TEXT) { if ($xmldb_field->getDefault() === '') { // If passing empty default, use the $default_for_char one instead $default = "'" . $this->default_for_char . "'"; } else { $default = "'" . $this->addslashes($xmldb_field->getDefault()) . "'"; } } else { $default = $xmldb_field->getDefault(); } } else { // We force default '' for not null char columns without proper default // some day this should be out! if ($this->default_for_char !== NULL && $xmldb_field->getType() == XMLDB_TYPE_CHAR && $xmldb_field->getNotNull()) { $default = "'" . $this->default_for_char . "'"; } else { // If the DB requires to explicity define some clause to drop one default, do it here // never applying defaults to TEXT and BINARY fields if ($this->drop_default_value_required && $xmldb_field->getType() != XMLDB_TYPE_TEXT && $xmldb_field->getType() != XMLDB_TYPE_BINARY && !$xmldb_field->getNotNull()) { $default = $this->drop_default_value; } } } return $default; }
[ "public", "function", "getDefaultValue", "(", "$", "xmldb_field", ")", "{", "$", "default", "=", "null", ";", "if", "(", "$", "xmldb_field", "->", "getDefault", "(", ")", "!==", "NULL", ")", "{", "if", "(", "$", "xmldb_field", "->", "getType", "(", ")", "==", "XMLDB_TYPE_CHAR", "||", "$", "xmldb_field", "->", "getType", "(", ")", "==", "XMLDB_TYPE_TEXT", ")", "{", "if", "(", "$", "xmldb_field", "->", "getDefault", "(", ")", "===", "''", ")", "{", "// If passing empty default, use the $default_for_char one instead", "$", "default", "=", "\"'\"", ".", "$", "this", "->", "default_for_char", ".", "\"'\"", ";", "}", "else", "{", "$", "default", "=", "\"'\"", ".", "$", "this", "->", "addslashes", "(", "$", "xmldb_field", "->", "getDefault", "(", ")", ")", ".", "\"'\"", ";", "}", "}", "else", "{", "$", "default", "=", "$", "xmldb_field", "->", "getDefault", "(", ")", ";", "}", "}", "else", "{", "// We force default '' for not null char columns without proper default", "// some day this should be out!", "if", "(", "$", "this", "->", "default_for_char", "!==", "NULL", "&&", "$", "xmldb_field", "->", "getType", "(", ")", "==", "XMLDB_TYPE_CHAR", "&&", "$", "xmldb_field", "->", "getNotNull", "(", ")", ")", "{", "$", "default", "=", "\"'\"", ".", "$", "this", "->", "default_for_char", ".", "\"'\"", ";", "}", "else", "{", "// If the DB requires to explicity define some clause to drop one default, do it here", "// never applying defaults to TEXT and BINARY fields", "if", "(", "$", "this", "->", "drop_default_value_required", "&&", "$", "xmldb_field", "->", "getType", "(", ")", "!=", "XMLDB_TYPE_TEXT", "&&", "$", "xmldb_field", "->", "getType", "(", ")", "!=", "XMLDB_TYPE_BINARY", "&&", "!", "$", "xmldb_field", "->", "getNotNull", "(", ")", ")", "{", "$", "default", "=", "$", "this", "->", "drop_default_value", ";", "}", "}", "}", "return", "$", "default", ";", "}" ]
Give one xmldb_field, returns the correct "default value" for the current configuration @param xmldb_field $xmldb_field The field. @return The default value of the field.
[ "Give", "one", "xmldb_field", "returns", "the", "correct", "default", "value", "for", "the", "current", "configuration" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/sql_generator.php#L577-L610
218,257
moodle/moodle
lib/ddl/sql_generator.php
sql_generator.getDefaultClause
public function getDefaultClause($xmldb_field) { $defaultvalue = $this->getDefaultValue ($xmldb_field); if ($defaultvalue !== null) { return ' DEFAULT ' . $defaultvalue; } else { return null; } }
php
public function getDefaultClause($xmldb_field) { $defaultvalue = $this->getDefaultValue ($xmldb_field); if ($defaultvalue !== null) { return ' DEFAULT ' . $defaultvalue; } else { return null; } }
[ "public", "function", "getDefaultClause", "(", "$", "xmldb_field", ")", "{", "$", "defaultvalue", "=", "$", "this", "->", "getDefaultValue", "(", "$", "xmldb_field", ")", ";", "if", "(", "$", "defaultvalue", "!==", "null", ")", "{", "return", "' DEFAULT '", ".", "$", "defaultvalue", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Given one xmldb_field, returns the correct "default clause" for the current configuration. @param xmldb_field $xmldb_field The xmldb_field. @return The SQL clause for generating the default value as in $xmldb_field.
[ "Given", "one", "xmldb_field", "returns", "the", "correct", "default", "clause", "for", "the", "current", "configuration", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/sql_generator.php#L618-L627
218,258
moodle/moodle
lib/ddl/sql_generator.php
sql_generator.getDropFieldSQL
public function getDropFieldSQL($xmldb_table, $xmldb_field) { $results = array(); // Get the quoted name of the table and field $tablename = $this->getTableName($xmldb_table); $fieldname = $this->getEncQuoted($xmldb_field->getName()); // Build the standard alter table drop $results[] = 'ALTER TABLE ' . $tablename . ' DROP COLUMN ' . $fieldname; return $results; }
php
public function getDropFieldSQL($xmldb_table, $xmldb_field) { $results = array(); // Get the quoted name of the table and field $tablename = $this->getTableName($xmldb_table); $fieldname = $this->getEncQuoted($xmldb_field->getName()); // Build the standard alter table drop $results[] = 'ALTER TABLE ' . $tablename . ' DROP COLUMN ' . $fieldname; return $results; }
[ "public", "function", "getDropFieldSQL", "(", "$", "xmldb_table", ",", "$", "xmldb_field", ")", "{", "$", "results", "=", "array", "(", ")", ";", "// Get the quoted name of the table and field", "$", "tablename", "=", "$", "this", "->", "getTableName", "(", "$", "xmldb_table", ")", ";", "$", "fieldname", "=", "$", "this", "->", "getEncQuoted", "(", "$", "xmldb_field", "->", "getName", "(", ")", ")", ";", "// Build the standard alter table drop", "$", "results", "[", "]", "=", "'ALTER TABLE '", ".", "$", "tablename", ".", "' DROP COLUMN '", ".", "$", "fieldname", ";", "return", "$", "results", ";", "}" ]
Given one xmldb_table and one xmldb_field, return the SQL statements needed to drop the field from the table. @param xmldb_table $xmldb_table The table related to $xmldb_field. @param xmldb_field $xmldb_field The instance of xmldb_field to create the SQL from. @return array The SQL statement for dropping a field from the table.
[ "Given", "one", "xmldb_table", "and", "one", "xmldb_field", "return", "the", "SQL", "statements", "needed", "to", "drop", "the", "field", "from", "the", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/sql_generator.php#L719-L731
218,259
moodle/moodle
lib/ddl/sql_generator.php
sql_generator.getRenameIndexSQL
function getRenameIndexSQL($xmldb_table, $xmldb_index, $newname) { // Some DB doesn't support index renaming (MySQL) so this can be empty if (empty($this->rename_index_sql)) { return array(); } // Get the real index name $dbindexname = $this->mdb->get_manager()->find_index_name($xmldb_table, $xmldb_index); // Replace TABLENAME and INDEXNAME as needed $renamesql = str_replace('TABLENAME', $this->getTableName($xmldb_table), $this->rename_index_sql); $renamesql = str_replace('OLDINDEXNAME', $this->getEncQuoted($dbindexname), $renamesql); $renamesql = str_replace('NEWINDEXNAME', $this->getEncQuoted($newname), $renamesql); return array($renamesql); }
php
function getRenameIndexSQL($xmldb_table, $xmldb_index, $newname) { // Some DB doesn't support index renaming (MySQL) so this can be empty if (empty($this->rename_index_sql)) { return array(); } // Get the real index name $dbindexname = $this->mdb->get_manager()->find_index_name($xmldb_table, $xmldb_index); // Replace TABLENAME and INDEXNAME as needed $renamesql = str_replace('TABLENAME', $this->getTableName($xmldb_table), $this->rename_index_sql); $renamesql = str_replace('OLDINDEXNAME', $this->getEncQuoted($dbindexname), $renamesql); $renamesql = str_replace('NEWINDEXNAME', $this->getEncQuoted($newname), $renamesql); return array($renamesql); }
[ "function", "getRenameIndexSQL", "(", "$", "xmldb_table", ",", "$", "xmldb_index", ",", "$", "newname", ")", "{", "// Some DB doesn't support index renaming (MySQL) so this can be empty", "if", "(", "empty", "(", "$", "this", "->", "rename_index_sql", ")", ")", "{", "return", "array", "(", ")", ";", "}", "// Get the real index name", "$", "dbindexname", "=", "$", "this", "->", "mdb", "->", "get_manager", "(", ")", "->", "find_index_name", "(", "$", "xmldb_table", ",", "$", "xmldb_index", ")", ";", "// Replace TABLENAME and INDEXNAME as needed", "$", "renamesql", "=", "str_replace", "(", "'TABLENAME'", ",", "$", "this", "->", "getTableName", "(", "$", "xmldb_table", ")", ",", "$", "this", "->", "rename_index_sql", ")", ";", "$", "renamesql", "=", "str_replace", "(", "'OLDINDEXNAME'", ",", "$", "this", "->", "getEncQuoted", "(", "$", "dbindexname", ")", ",", "$", "renamesql", ")", ";", "$", "renamesql", "=", "str_replace", "(", "'NEWINDEXNAME'", ",", "$", "this", "->", "getEncQuoted", "(", "$", "newname", ")", ",", "$", "renamesql", ")", ";", "return", "array", "(", "$", "renamesql", ")", ";", "}" ]
Given one xmldb_table and one xmldb_index, return the SQL statements needed to rename the index in the table Experimental! Shouldn't be used at all! @param xmldb_table $xmldb_table The xmldb_table instance to rename the index on. @param xmldb_index $xmldb_index The xmldb_index to rename. @param string $newname The xmldb_index's new name. @return array An array of SQL statements to rename the index.
[ "Given", "one", "xmldb_table", "and", "one", "xmldb_index", "return", "the", "SQL", "statements", "needed", "to", "rename", "the", "index", "in", "the", "table", "Experimental!", "Shouldn", "t", "be", "used", "at", "all!" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/sql_generator.php#L1041-L1055
218,260
moodle/moodle
lib/ddl/sql_generator.php
sql_generator.getExecuteInsertSQL
function getExecuteInsertSQL($statement) { $results = array(); //Array where all the sentences will be stored if ($sentences = $statement->getSentences()) { foreach ($sentences as $sentence) { // Get the list of fields $fields = $statement->getFieldsFromInsertSentence($sentence); // Get the values of fields $values = $statement->getValuesFromInsertSentence($sentence); // Look if we have some CONCAT value and transform it dynamically foreach($values as $key => $value) { // Trim single quotes $value = trim($value,"'"); if (stristr($value, 'CONCAT') !== false){ // Look for data between parenthesis preg_match("/CONCAT\s*\((.*)\)$/is", trim($value), $matches); if (isset($matches[1])) { $part = $matches[1]; // Convert the comma separated string to an array $arr = xmldb_object::comma2array($part); if ($arr) { $value = $this->getConcatSQL($arr); } } } // Values to be sent to DB must be properly escaped $value = $this->addslashes($value); // Back trimmed quotes $value = "'" . $value . "'"; // Back to the array $values[$key] = $value; } // Iterate over fields, escaping them if necessary foreach($fields as $key => $field) { $fields[$key] = $this->getEncQuoted($field); } // Build the final SQL sentence and add it to the array of results $sql = 'INSERT INTO ' . $this->getEncQuoted($this->prefix . $statement->getTable()) . '(' . implode(', ', $fields) . ') ' . 'VALUES (' . implode(', ', $values) . ')'; $results[] = $sql; } } return $results; }
php
function getExecuteInsertSQL($statement) { $results = array(); //Array where all the sentences will be stored if ($sentences = $statement->getSentences()) { foreach ($sentences as $sentence) { // Get the list of fields $fields = $statement->getFieldsFromInsertSentence($sentence); // Get the values of fields $values = $statement->getValuesFromInsertSentence($sentence); // Look if we have some CONCAT value and transform it dynamically foreach($values as $key => $value) { // Trim single quotes $value = trim($value,"'"); if (stristr($value, 'CONCAT') !== false){ // Look for data between parenthesis preg_match("/CONCAT\s*\((.*)\)$/is", trim($value), $matches); if (isset($matches[1])) { $part = $matches[1]; // Convert the comma separated string to an array $arr = xmldb_object::comma2array($part); if ($arr) { $value = $this->getConcatSQL($arr); } } } // Values to be sent to DB must be properly escaped $value = $this->addslashes($value); // Back trimmed quotes $value = "'" . $value . "'"; // Back to the array $values[$key] = $value; } // Iterate over fields, escaping them if necessary foreach($fields as $key => $field) { $fields[$key] = $this->getEncQuoted($field); } // Build the final SQL sentence and add it to the array of results $sql = 'INSERT INTO ' . $this->getEncQuoted($this->prefix . $statement->getTable()) . '(' . implode(', ', $fields) . ') ' . 'VALUES (' . implode(', ', $values) . ')'; $results[] = $sql; } } return $results; }
[ "function", "getExecuteInsertSQL", "(", "$", "statement", ")", "{", "$", "results", "=", "array", "(", ")", ";", "//Array where all the sentences will be stored", "if", "(", "$", "sentences", "=", "$", "statement", "->", "getSentences", "(", ")", ")", "{", "foreach", "(", "$", "sentences", "as", "$", "sentence", ")", "{", "// Get the list of fields", "$", "fields", "=", "$", "statement", "->", "getFieldsFromInsertSentence", "(", "$", "sentence", ")", ";", "// Get the values of fields", "$", "values", "=", "$", "statement", "->", "getValuesFromInsertSentence", "(", "$", "sentence", ")", ";", "// Look if we have some CONCAT value and transform it dynamically", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "// Trim single quotes", "$", "value", "=", "trim", "(", "$", "value", ",", "\"'\"", ")", ";", "if", "(", "stristr", "(", "$", "value", ",", "'CONCAT'", ")", "!==", "false", ")", "{", "// Look for data between parenthesis", "preg_match", "(", "\"/CONCAT\\s*\\((.*)\\)$/is\"", ",", "trim", "(", "$", "value", ")", ",", "$", "matches", ")", ";", "if", "(", "isset", "(", "$", "matches", "[", "1", "]", ")", ")", "{", "$", "part", "=", "$", "matches", "[", "1", "]", ";", "// Convert the comma separated string to an array", "$", "arr", "=", "xmldb_object", "::", "comma2array", "(", "$", "part", ")", ";", "if", "(", "$", "arr", ")", "{", "$", "value", "=", "$", "this", "->", "getConcatSQL", "(", "$", "arr", ")", ";", "}", "}", "}", "// Values to be sent to DB must be properly escaped", "$", "value", "=", "$", "this", "->", "addslashes", "(", "$", "value", ")", ";", "// Back trimmed quotes", "$", "value", "=", "\"'\"", ".", "$", "value", ".", "\"'\"", ";", "// Back to the array", "$", "values", "[", "$", "key", "]", "=", "$", "value", ";", "}", "// Iterate over fields, escaping them if necessary", "foreach", "(", "$", "fields", "as", "$", "key", "=>", "$", "field", ")", "{", "$", "fields", "[", "$", "key", "]", "=", "$", "this", "->", "getEncQuoted", "(", "$", "field", ")", ";", "}", "// Build the final SQL sentence and add it to the array of results", "$", "sql", "=", "'INSERT INTO '", ".", "$", "this", "->", "getEncQuoted", "(", "$", "this", "->", "prefix", ".", "$", "statement", "->", "getTable", "(", ")", ")", ".", "'('", ".", "implode", "(", "', '", ",", "$", "fields", ")", ".", "') '", ".", "'VALUES ('", ".", "implode", "(", "', '", ",", "$", "values", ")", ".", "')'", ";", "$", "results", "[", "]", "=", "$", "sql", ";", "}", "}", "return", "$", "results", ";", "}" ]
Given one XMLDB Statement, build the needed SQL insert sentences to execute it. @param string $statement SQL statement. @return array Array of sentences in the SQL statement.
[ "Given", "one", "XMLDB", "Statement", "build", "the", "needed", "SQL", "insert", "sentences", "to", "execute", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/sql_generator.php#L1158-L1205
218,261
moodle/moodle
lib/ddl/sql_generator.php
sql_generator.getAllReservedWords
public static function getAllReservedWords() { global $CFG; $generators = array('mysql', 'postgres', 'oracle', 'mssql'); $reserved_words = array(); foreach($generators as $generator) { $class = $generator . '_sql_generator'; require_once("$CFG->libdir/ddl/$class.php"); foreach (call_user_func(array($class, 'getReservedWords')) as $word) { $reserved_words[$word][] = $generator; } } ksort($reserved_words); return $reserved_words; }
php
public static function getAllReservedWords() { global $CFG; $generators = array('mysql', 'postgres', 'oracle', 'mssql'); $reserved_words = array(); foreach($generators as $generator) { $class = $generator . '_sql_generator'; require_once("$CFG->libdir/ddl/$class.php"); foreach (call_user_func(array($class, 'getReservedWords')) as $word) { $reserved_words[$word][] = $generator; } } ksort($reserved_words); return $reserved_words; }
[ "public", "static", "function", "getAllReservedWords", "(", ")", "{", "global", "$", "CFG", ";", "$", "generators", "=", "array", "(", "'mysql'", ",", "'postgres'", ",", "'oracle'", ",", "'mssql'", ")", ";", "$", "reserved_words", "=", "array", "(", ")", ";", "foreach", "(", "$", "generators", "as", "$", "generator", ")", "{", "$", "class", "=", "$", "generator", ".", "'_sql_generator'", ";", "require_once", "(", "\"$CFG->libdir/ddl/$class.php\"", ")", ";", "foreach", "(", "call_user_func", "(", "array", "(", "$", "class", ",", "'getReservedWords'", ")", ")", "as", "$", "word", ")", "{", "$", "reserved_words", "[", "$", "word", "]", "[", "]", "=", "$", "generator", ";", "}", "}", "ksort", "(", "$", "reserved_words", ")", ";", "return", "$", "reserved_words", ";", "}" ]
Returns all reserved words in supported databases. Reserved words should be lowercase. @return array ('word'=>array(databases))
[ "Returns", "all", "reserved", "words", "in", "supported", "databases", ".", "Reserved", "words", "should", "be", "lowercase", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/sql_generator.php#L1382-L1397
218,262
moodle/moodle
lib/ddl/sql_generator.php
sql_generator.get_nullable_fields_in_index
public function get_nullable_fields_in_index($xmldb_table, $xmldb_index) { global $DB; // If we don't have the field info passed in, we need to query it from the DB. $fieldsfromdb = null; $nullablefields = []; foreach ($xmldb_index->getFields() as $fieldname) { if ($field = $xmldb_table->getField($fieldname)) { // We have the field details in the table definition. if ($field->getNotNull() !== XMLDB_NOTNULL) { $nullablefields[] = $fieldname; } } else { // We don't have the table definition loaded. Need to // inspect the database. if ($fieldsfromdb === null) { $fieldsfromdb = $DB->get_columns($xmldb_table->getName(), false); } if (!isset($fieldsfromdb[$fieldname])) { throw new coding_exception('Unknown field ' . $fieldname . ' in index ' . $xmldb_index->getName()); } if (!$fieldsfromdb[$fieldname]->not_null) { $nullablefields[] = $fieldname; } } } return $nullablefields; }
php
public function get_nullable_fields_in_index($xmldb_table, $xmldb_index) { global $DB; // If we don't have the field info passed in, we need to query it from the DB. $fieldsfromdb = null; $nullablefields = []; foreach ($xmldb_index->getFields() as $fieldname) { if ($field = $xmldb_table->getField($fieldname)) { // We have the field details in the table definition. if ($field->getNotNull() !== XMLDB_NOTNULL) { $nullablefields[] = $fieldname; } } else { // We don't have the table definition loaded. Need to // inspect the database. if ($fieldsfromdb === null) { $fieldsfromdb = $DB->get_columns($xmldb_table->getName(), false); } if (!isset($fieldsfromdb[$fieldname])) { throw new coding_exception('Unknown field ' . $fieldname . ' in index ' . $xmldb_index->getName()); } if (!$fieldsfromdb[$fieldname]->not_null) { $nullablefields[] = $fieldname; } } } return $nullablefields; }
[ "public", "function", "get_nullable_fields_in_index", "(", "$", "xmldb_table", ",", "$", "xmldb_index", ")", "{", "global", "$", "DB", ";", "// If we don't have the field info passed in, we need to query it from the DB.", "$", "fieldsfromdb", "=", "null", ";", "$", "nullablefields", "=", "[", "]", ";", "foreach", "(", "$", "xmldb_index", "->", "getFields", "(", ")", "as", "$", "fieldname", ")", "{", "if", "(", "$", "field", "=", "$", "xmldb_table", "->", "getField", "(", "$", "fieldname", ")", ")", "{", "// We have the field details in the table definition.", "if", "(", "$", "field", "->", "getNotNull", "(", ")", "!==", "XMLDB_NOTNULL", ")", "{", "$", "nullablefields", "[", "]", "=", "$", "fieldname", ";", "}", "}", "else", "{", "// We don't have the table definition loaded. Need to", "// inspect the database.", "if", "(", "$", "fieldsfromdb", "===", "null", ")", "{", "$", "fieldsfromdb", "=", "$", "DB", "->", "get_columns", "(", "$", "xmldb_table", "->", "getName", "(", ")", ",", "false", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "fieldsfromdb", "[", "$", "fieldname", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Unknown field '", ".", "$", "fieldname", ".", "' in index '", ".", "$", "xmldb_index", "->", "getName", "(", ")", ")", ";", "}", "if", "(", "!", "$", "fieldsfromdb", "[", "$", "fieldname", "]", "->", "not_null", ")", "{", "$", "nullablefields", "[", "]", "=", "$", "fieldname", ";", "}", "}", "}", "return", "$", "nullablefields", ";", "}" ]
Get the fields from an index definition that might be null. @param xmldb_table $xmldb_table the table @param xmldb_index $xmldb_index the index @return array list of fields in the index definition that might be null.
[ "Get", "the", "fields", "from", "an", "index", "definition", "that", "might", "be", "null", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/sql_generator.php#L1418-L1450
218,263
moodle/moodle
auth/email/classes/external.php
auth_email_external.get_signup_settings_returns
public static function get_signup_settings_returns() { return new external_single_structure( array( 'namefields' => new external_multiple_structure( new external_value(PARAM_NOTAGS, 'The order of the name fields') ), 'passwordpolicy' => new external_value(PARAM_RAW, 'Password policy', VALUE_OPTIONAL), 'sitepolicy' => new external_value(PARAM_RAW, 'Site policy', VALUE_OPTIONAL), 'sitepolicyhandler' => new external_value(PARAM_PLUGIN, 'Site policy handler', VALUE_OPTIONAL), 'defaultcity' => new external_value(PARAM_NOTAGS, 'Default city', VALUE_OPTIONAL), 'country' => new external_value(PARAM_ALPHA, 'Default country', VALUE_OPTIONAL), 'profilefields' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Profile field id', VALUE_OPTIONAL), 'shortname' => new external_value(PARAM_ALPHANUM, 'Password policy', VALUE_OPTIONAL), 'name' => new external_value(PARAM_TEXT, 'Profield field name', VALUE_OPTIONAL), 'datatype' => new external_value(PARAM_ALPHANUMEXT, 'Profield field datatype', VALUE_OPTIONAL), 'description' => new external_value(PARAM_RAW, 'Profield field description', VALUE_OPTIONAL), 'descriptionformat' => new external_format_value('description'), 'categoryid' => new external_value(PARAM_INT, 'Profield field category id', VALUE_OPTIONAL), 'categoryname' => new external_value(PARAM_TEXT, 'Profield field category name', VALUE_OPTIONAL), 'sortorder' => new external_value(PARAM_INT, 'Profield field sort order', VALUE_OPTIONAL), 'required' => new external_value(PARAM_INT, 'Profield field required', VALUE_OPTIONAL), 'locked' => new external_value(PARAM_INT, 'Profield field locked', VALUE_OPTIONAL), 'visible' => new external_value(PARAM_INT, 'Profield field visible', VALUE_OPTIONAL), 'forceunique' => new external_value(PARAM_INT, 'Profield field unique', VALUE_OPTIONAL), 'signup' => new external_value(PARAM_INT, 'Profield field in signup form', VALUE_OPTIONAL), 'defaultdata' => new external_value(PARAM_RAW, 'Profield field default data', VALUE_OPTIONAL), 'defaultdataformat' => new external_format_value('defaultdata'), 'param1' => new external_value(PARAM_RAW, 'Profield field settings', VALUE_OPTIONAL), 'param2' => new external_value(PARAM_RAW, 'Profield field settings', VALUE_OPTIONAL), 'param3' => new external_value(PARAM_RAW, 'Profield field settings', VALUE_OPTIONAL), 'param4' => new external_value(PARAM_RAW, 'Profield field settings', VALUE_OPTIONAL), 'param5' => new external_value(PARAM_RAW, 'Profield field settings', VALUE_OPTIONAL), ) ), 'Required profile fields', VALUE_OPTIONAL ), 'recaptchapublickey' => new external_value(PARAM_RAW, 'Recaptcha public key', VALUE_OPTIONAL), 'recaptchachallengehash' => new external_value(PARAM_RAW, 'Recaptcha challenge hash', VALUE_OPTIONAL), 'recaptchachallengeimage' => new external_value(PARAM_URL, 'Recaptcha challenge noscript image', VALUE_OPTIONAL), 'recaptchachallengejs' => new external_value(PARAM_URL, 'Recaptcha challenge js url', VALUE_OPTIONAL), 'warnings' => new external_warnings(), ) ); }
php
public static function get_signup_settings_returns() { return new external_single_structure( array( 'namefields' => new external_multiple_structure( new external_value(PARAM_NOTAGS, 'The order of the name fields') ), 'passwordpolicy' => new external_value(PARAM_RAW, 'Password policy', VALUE_OPTIONAL), 'sitepolicy' => new external_value(PARAM_RAW, 'Site policy', VALUE_OPTIONAL), 'sitepolicyhandler' => new external_value(PARAM_PLUGIN, 'Site policy handler', VALUE_OPTIONAL), 'defaultcity' => new external_value(PARAM_NOTAGS, 'Default city', VALUE_OPTIONAL), 'country' => new external_value(PARAM_ALPHA, 'Default country', VALUE_OPTIONAL), 'profilefields' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Profile field id', VALUE_OPTIONAL), 'shortname' => new external_value(PARAM_ALPHANUM, 'Password policy', VALUE_OPTIONAL), 'name' => new external_value(PARAM_TEXT, 'Profield field name', VALUE_OPTIONAL), 'datatype' => new external_value(PARAM_ALPHANUMEXT, 'Profield field datatype', VALUE_OPTIONAL), 'description' => new external_value(PARAM_RAW, 'Profield field description', VALUE_OPTIONAL), 'descriptionformat' => new external_format_value('description'), 'categoryid' => new external_value(PARAM_INT, 'Profield field category id', VALUE_OPTIONAL), 'categoryname' => new external_value(PARAM_TEXT, 'Profield field category name', VALUE_OPTIONAL), 'sortorder' => new external_value(PARAM_INT, 'Profield field sort order', VALUE_OPTIONAL), 'required' => new external_value(PARAM_INT, 'Profield field required', VALUE_OPTIONAL), 'locked' => new external_value(PARAM_INT, 'Profield field locked', VALUE_OPTIONAL), 'visible' => new external_value(PARAM_INT, 'Profield field visible', VALUE_OPTIONAL), 'forceunique' => new external_value(PARAM_INT, 'Profield field unique', VALUE_OPTIONAL), 'signup' => new external_value(PARAM_INT, 'Profield field in signup form', VALUE_OPTIONAL), 'defaultdata' => new external_value(PARAM_RAW, 'Profield field default data', VALUE_OPTIONAL), 'defaultdataformat' => new external_format_value('defaultdata'), 'param1' => new external_value(PARAM_RAW, 'Profield field settings', VALUE_OPTIONAL), 'param2' => new external_value(PARAM_RAW, 'Profield field settings', VALUE_OPTIONAL), 'param3' => new external_value(PARAM_RAW, 'Profield field settings', VALUE_OPTIONAL), 'param4' => new external_value(PARAM_RAW, 'Profield field settings', VALUE_OPTIONAL), 'param5' => new external_value(PARAM_RAW, 'Profield field settings', VALUE_OPTIONAL), ) ), 'Required profile fields', VALUE_OPTIONAL ), 'recaptchapublickey' => new external_value(PARAM_RAW, 'Recaptcha public key', VALUE_OPTIONAL), 'recaptchachallengehash' => new external_value(PARAM_RAW, 'Recaptcha challenge hash', VALUE_OPTIONAL), 'recaptchachallengeimage' => new external_value(PARAM_URL, 'Recaptcha challenge noscript image', VALUE_OPTIONAL), 'recaptchachallengejs' => new external_value(PARAM_URL, 'Recaptcha challenge js url', VALUE_OPTIONAL), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_signup_settings_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'namefields'", "=>", "new", "external_multiple_structure", "(", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'The order of the name fields'", ")", ")", ",", "'passwordpolicy'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Password policy'", ",", "VALUE_OPTIONAL", ")", ",", "'sitepolicy'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Site policy'", ",", "VALUE_OPTIONAL", ")", ",", "'sitepolicyhandler'", "=>", "new", "external_value", "(", "PARAM_PLUGIN", ",", "'Site policy handler'", ",", "VALUE_OPTIONAL", ")", ",", "'defaultcity'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'Default city'", ",", "VALUE_OPTIONAL", ")", ",", "'country'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'Default country'", ",", "VALUE_OPTIONAL", ")", ",", "'profilefields'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Profile field id'", ",", "VALUE_OPTIONAL", ")", ",", "'shortname'", "=>", "new", "external_value", "(", "PARAM_ALPHANUM", ",", "'Password policy'", ",", "VALUE_OPTIONAL", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Profield field name'", ",", "VALUE_OPTIONAL", ")", ",", "'datatype'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'Profield field datatype'", ",", "VALUE_OPTIONAL", ")", ",", "'description'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Profield field description'", ",", "VALUE_OPTIONAL", ")", ",", "'descriptionformat'", "=>", "new", "external_format_value", "(", "'description'", ")", ",", "'categoryid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Profield field category id'", ",", "VALUE_OPTIONAL", ")", ",", "'categoryname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Profield field category name'", ",", "VALUE_OPTIONAL", ")", ",", "'sortorder'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Profield field sort order'", ",", "VALUE_OPTIONAL", ")", ",", "'required'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Profield field required'", ",", "VALUE_OPTIONAL", ")", ",", "'locked'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Profield field locked'", ",", "VALUE_OPTIONAL", ")", ",", "'visible'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Profield field visible'", ",", "VALUE_OPTIONAL", ")", ",", "'forceunique'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Profield field unique'", ",", "VALUE_OPTIONAL", ")", ",", "'signup'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Profield field in signup form'", ",", "VALUE_OPTIONAL", ")", ",", "'defaultdata'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Profield field default data'", ",", "VALUE_OPTIONAL", ")", ",", "'defaultdataformat'", "=>", "new", "external_format_value", "(", "'defaultdata'", ")", ",", "'param1'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Profield field settings'", ",", "VALUE_OPTIONAL", ")", ",", "'param2'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Profield field settings'", ",", "VALUE_OPTIONAL", ")", ",", "'param3'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Profield field settings'", ",", "VALUE_OPTIONAL", ")", ",", "'param4'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Profield field settings'", ",", "VALUE_OPTIONAL", ")", ",", "'param5'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Profield field settings'", ",", "VALUE_OPTIONAL", ")", ",", ")", ")", ",", "'Required profile fields'", ",", "VALUE_OPTIONAL", ")", ",", "'recaptchapublickey'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Recaptcha public key'", ",", "VALUE_OPTIONAL", ")", ",", "'recaptchachallengehash'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Recaptcha challenge hash'", ",", "VALUE_OPTIONAL", ")", ",", "'recaptchachallengeimage'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'Recaptcha challenge noscript image'", ",", "VALUE_OPTIONAL", ")", ",", "'recaptchachallengejs'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'Recaptcha challenge js url'", ",", "VALUE_OPTIONAL", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_signup_settings return value. @return external_single_structure @since Moodle 3.2
[ "Describes", "the", "get_signup_settings", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/email/classes/external.php#L136-L182
218,264
moodle/moodle
auth/email/classes/external.php
auth_email_external.signup_user_parameters
public static function signup_user_parameters() { return new external_function_parameters( array( 'username' => new external_value(core_user::get_property_type('username'), 'Username'), 'password' => new external_value(core_user::get_property_type('password'), 'Plain text password'), 'firstname' => new external_value(core_user::get_property_type('firstname'), 'The first name(s) of the user'), 'lastname' => new external_value(core_user::get_property_type('lastname'), 'The family name of the user'), 'email' => new external_value(core_user::get_property_type('email'), 'A valid and unique email address'), 'city' => new external_value(core_user::get_property_type('city'), 'Home city of the user', VALUE_DEFAULT, ''), 'country' => new external_value(core_user::get_property_type('country'), 'Home country code', VALUE_DEFAULT, ''), 'recaptchachallengehash' => new external_value(PARAM_RAW, 'Recaptcha challenge hash', VALUE_DEFAULT, ''), 'recaptcharesponse' => new external_value(PARAM_NOTAGS, 'Recaptcha response', VALUE_DEFAULT, ''), 'customprofilefields' => new external_multiple_structure( new external_single_structure( array( 'type' => new external_value(PARAM_ALPHANUMEXT, 'The type of the custom field'), 'name' => new external_value(PARAM_ALPHANUMEXT, 'The name of the custom field'), 'value' => new external_value(PARAM_RAW, 'Custom field value, can be an encoded json if required') ) ), 'User custom fields (also known as user profile fields)', VALUE_DEFAULT, array() ), 'redirect' => new external_value(PARAM_LOCALURL, 'Redirect the user to this site url after confirmation.', VALUE_DEFAULT, ''), ) ); }
php
public static function signup_user_parameters() { return new external_function_parameters( array( 'username' => new external_value(core_user::get_property_type('username'), 'Username'), 'password' => new external_value(core_user::get_property_type('password'), 'Plain text password'), 'firstname' => new external_value(core_user::get_property_type('firstname'), 'The first name(s) of the user'), 'lastname' => new external_value(core_user::get_property_type('lastname'), 'The family name of the user'), 'email' => new external_value(core_user::get_property_type('email'), 'A valid and unique email address'), 'city' => new external_value(core_user::get_property_type('city'), 'Home city of the user', VALUE_DEFAULT, ''), 'country' => new external_value(core_user::get_property_type('country'), 'Home country code', VALUE_DEFAULT, ''), 'recaptchachallengehash' => new external_value(PARAM_RAW, 'Recaptcha challenge hash', VALUE_DEFAULT, ''), 'recaptcharesponse' => new external_value(PARAM_NOTAGS, 'Recaptcha response', VALUE_DEFAULT, ''), 'customprofilefields' => new external_multiple_structure( new external_single_structure( array( 'type' => new external_value(PARAM_ALPHANUMEXT, 'The type of the custom field'), 'name' => new external_value(PARAM_ALPHANUMEXT, 'The name of the custom field'), 'value' => new external_value(PARAM_RAW, 'Custom field value, can be an encoded json if required') ) ), 'User custom fields (also known as user profile fields)', VALUE_DEFAULT, array() ), 'redirect' => new external_value(PARAM_LOCALURL, 'Redirect the user to this site url after confirmation.', VALUE_DEFAULT, ''), ) ); }
[ "public", "static", "function", "signup_user_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'username'", "=>", "new", "external_value", "(", "core_user", "::", "get_property_type", "(", "'username'", ")", ",", "'Username'", ")", ",", "'password'", "=>", "new", "external_value", "(", "core_user", "::", "get_property_type", "(", "'password'", ")", ",", "'Plain text password'", ")", ",", "'firstname'", "=>", "new", "external_value", "(", "core_user", "::", "get_property_type", "(", "'firstname'", ")", ",", "'The first name(s) of the user'", ")", ",", "'lastname'", "=>", "new", "external_value", "(", "core_user", "::", "get_property_type", "(", "'lastname'", ")", ",", "'The family name of the user'", ")", ",", "'email'", "=>", "new", "external_value", "(", "core_user", "::", "get_property_type", "(", "'email'", ")", ",", "'A valid and unique email address'", ")", ",", "'city'", "=>", "new", "external_value", "(", "core_user", "::", "get_property_type", "(", "'city'", ")", ",", "'Home city of the user'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", "'country'", "=>", "new", "external_value", "(", "core_user", "::", "get_property_type", "(", "'country'", ")", ",", "'Home country code'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", "'recaptchachallengehash'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Recaptcha challenge hash'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", "'recaptcharesponse'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'Recaptcha response'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", "'customprofilefields'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'type'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'The type of the custom field'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'The name of the custom field'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Custom field value, can be an encoded json if required'", ")", ")", ")", ",", "'User custom fields (also known as user profile fields)'", ",", "VALUE_DEFAULT", ",", "array", "(", ")", ")", ",", "'redirect'", "=>", "new", "external_value", "(", "PARAM_LOCALURL", ",", "'Redirect the user to this site url after confirmation.'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for signup_user. @return external_function_parameters @since Moodle 3.2
[ "Describes", "the", "parameters", "for", "signup_user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/email/classes/external.php#L190-L215
218,265
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php
StreamWrapper.stream_open
public function stream_open($path, $mode, $options, &$openedPath) { $this->initProtocol($path); $this->mode = $mode; if ($mode === 'r') { return $this->initReadableStream(); } if ($mode === 'w') { return $this->initWritableStream(); } return false; }
php
public function stream_open($path, $mode, $options, &$openedPath) { $this->initProtocol($path); $this->mode = $mode; if ($mode === 'r') { return $this->initReadableStream(); } if ($mode === 'w') { return $this->initWritableStream(); } return false; }
[ "public", "function", "stream_open", "(", "$", "path", ",", "$", "mode", ",", "$", "options", ",", "&", "$", "openedPath", ")", "{", "$", "this", "->", "initProtocol", "(", "$", "path", ")", ";", "$", "this", "->", "mode", "=", "$", "mode", ";", "if", "(", "$", "mode", "===", "'r'", ")", "{", "return", "$", "this", "->", "initReadableStream", "(", ")", ";", "}", "if", "(", "$", "mode", "===", "'w'", ")", "{", "return", "$", "this", "->", "initWritableStream", "(", ")", ";", "}", "return", "false", ";", "}" ]
Opens the stream. @see http://php.net/manual/en/streamwrapper.stream-open.php @param string $path Path to the file resource @param string $mode Mode used to open the file (only "r" and "w" are supported) @param integer $options Additional flags set by the streams API @param string $openedPath Not used
[ "Opens", "the", "stream", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php#L100-L114
218,266
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php
StreamWrapper.stream_seek
public function stream_seek($offset, $whence = \SEEK_SET) { $size = $this->stream->getSize(); if ($whence === \SEEK_CUR) { $offset += $this->stream->tell(); } if ($whence === \SEEK_END) { $offset += $size; } // WritableStreams are always positioned at the end of the stream if ($this->stream instanceof WritableStream) { return $offset === $size; } if ($offset < 0 || $offset > $size) { return false; } $this->stream->seek($offset); return true; }
php
public function stream_seek($offset, $whence = \SEEK_SET) { $size = $this->stream->getSize(); if ($whence === \SEEK_CUR) { $offset += $this->stream->tell(); } if ($whence === \SEEK_END) { $offset += $size; } // WritableStreams are always positioned at the end of the stream if ($this->stream instanceof WritableStream) { return $offset === $size; } if ($offset < 0 || $offset > $size) { return false; } $this->stream->seek($offset); return true; }
[ "public", "function", "stream_seek", "(", "$", "offset", ",", "$", "whence", "=", "\\", "SEEK_SET", ")", "{", "$", "size", "=", "$", "this", "->", "stream", "->", "getSize", "(", ")", ";", "if", "(", "$", "whence", "===", "\\", "SEEK_CUR", ")", "{", "$", "offset", "+=", "$", "this", "->", "stream", "->", "tell", "(", ")", ";", "}", "if", "(", "$", "whence", "===", "\\", "SEEK_END", ")", "{", "$", "offset", "+=", "$", "size", ";", "}", "// WritableStreams are always positioned at the end of the stream", "if", "(", "$", "this", "->", "stream", "instanceof", "WritableStream", ")", "{", "return", "$", "offset", "===", "$", "size", ";", "}", "if", "(", "$", "offset", "<", "0", "||", "$", "offset", ">", "$", "size", ")", "{", "return", "false", ";", "}", "$", "this", "->", "stream", "->", "seek", "(", "$", "offset", ")", ";", "return", "true", ";", "}" ]
Return the current position of the stream. @see http://php.net/manual/en/streamwrapper.stream-seek.php @param integer $offset Stream offset to seek to @param integer $whence One of SEEK_SET, SEEK_CUR, or SEEK_END @return boolean True if the position was updated and false otherwise
[ "Return", "the", "current", "position", "of", "the", "stream", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php#L148-L172
218,267
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php
StreamWrapper.stream_stat
public function stream_stat() { $stat = $this->getStatTemplate(); $stat[2] = $stat['mode'] = $this->stream instanceof ReadableStream ? 0100444 // S_IFREG & S_IRUSR & S_IRGRP & S_IROTH : 0100222; // S_IFREG & S_IWUSR & S_IWGRP & S_IWOTH $stat[7] = $stat['size'] = $this->stream->getSize(); $file = $this->stream->getFile(); if (isset($file->uploadDate) && $file->uploadDate instanceof UTCDateTime) { $timestamp = $file->uploadDate->toDateTime()->getTimestamp(); $stat[9] = $stat['mtime'] = $timestamp; $stat[10] = $stat['ctime'] = $timestamp; } if (isset($file->chunkSize) && is_integer($file->chunkSize)) { $stat[11] = $stat['blksize'] = $file->chunkSize; } return $stat; }
php
public function stream_stat() { $stat = $this->getStatTemplate(); $stat[2] = $stat['mode'] = $this->stream instanceof ReadableStream ? 0100444 // S_IFREG & S_IRUSR & S_IRGRP & S_IROTH : 0100222; // S_IFREG & S_IWUSR & S_IWGRP & S_IWOTH $stat[7] = $stat['size'] = $this->stream->getSize(); $file = $this->stream->getFile(); if (isset($file->uploadDate) && $file->uploadDate instanceof UTCDateTime) { $timestamp = $file->uploadDate->toDateTime()->getTimestamp(); $stat[9] = $stat['mtime'] = $timestamp; $stat[10] = $stat['ctime'] = $timestamp; } if (isset($file->chunkSize) && is_integer($file->chunkSize)) { $stat[11] = $stat['blksize'] = $file->chunkSize; } return $stat; }
[ "public", "function", "stream_stat", "(", ")", "{", "$", "stat", "=", "$", "this", "->", "getStatTemplate", "(", ")", ";", "$", "stat", "[", "2", "]", "=", "$", "stat", "[", "'mode'", "]", "=", "$", "this", "->", "stream", "instanceof", "ReadableStream", "?", "0100444", "// S_IFREG & S_IRUSR & S_IRGRP & S_IROTH", ":", "0100222", ";", "// S_IFREG & S_IWUSR & S_IWGRP & S_IWOTH", "$", "stat", "[", "7", "]", "=", "$", "stat", "[", "'size'", "]", "=", "$", "this", "->", "stream", "->", "getSize", "(", ")", ";", "$", "file", "=", "$", "this", "->", "stream", "->", "getFile", "(", ")", ";", "if", "(", "isset", "(", "$", "file", "->", "uploadDate", ")", "&&", "$", "file", "->", "uploadDate", "instanceof", "UTCDateTime", ")", "{", "$", "timestamp", "=", "$", "file", "->", "uploadDate", "->", "toDateTime", "(", ")", "->", "getTimestamp", "(", ")", ";", "$", "stat", "[", "9", "]", "=", "$", "stat", "[", "'mtime'", "]", "=", "$", "timestamp", ";", "$", "stat", "[", "10", "]", "=", "$", "stat", "[", "'ctime'", "]", "=", "$", "timestamp", ";", "}", "if", "(", "isset", "(", "$", "file", "->", "chunkSize", ")", "&&", "is_integer", "(", "$", "file", "->", "chunkSize", ")", ")", "{", "$", "stat", "[", "11", "]", "=", "$", "stat", "[", "'blksize'", "]", "=", "$", "file", "->", "chunkSize", ";", "}", "return", "$", "stat", ";", "}" ]
Return information about the stream. @see http://php.net/manual/en/streamwrapper.stream-stat.php @return array
[ "Return", "information", "about", "the", "stream", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php#L180-L202
218,268
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php
StreamWrapper.initReadableStream
private function initReadableStream() { $context = stream_context_get_options($this->context); $this->stream = new ReadableStream( $context[$this->protocol]['collectionWrapper'], $context[$this->protocol]['file'] ); return true; }
php
private function initReadableStream() { $context = stream_context_get_options($this->context); $this->stream = new ReadableStream( $context[$this->protocol]['collectionWrapper'], $context[$this->protocol]['file'] ); return true; }
[ "private", "function", "initReadableStream", "(", ")", "{", "$", "context", "=", "stream_context_get_options", "(", "$", "this", "->", "context", ")", ";", "$", "this", "->", "stream", "=", "new", "ReadableStream", "(", "$", "context", "[", "$", "this", "->", "protocol", "]", "[", "'collectionWrapper'", "]", ",", "$", "context", "[", "$", "this", "->", "protocol", "]", "[", "'file'", "]", ")", ";", "return", "true", ";", "}" ]
Initialize the internal stream for reading. @see StreamWrapper::stream_open() @return boolean
[ "Initialize", "the", "internal", "stream", "for", "reading", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php#L278-L288
218,269
moodle/moodle
cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php
StreamWrapper.initWritableStream
private function initWritableStream() { $context = stream_context_get_options($this->context); $this->stream = new WritableStream( $context[$this->protocol]['collectionWrapper'], $context[$this->protocol]['filename'], $context[$this->protocol]['options'] ); return true; }
php
private function initWritableStream() { $context = stream_context_get_options($this->context); $this->stream = new WritableStream( $context[$this->protocol]['collectionWrapper'], $context[$this->protocol]['filename'], $context[$this->protocol]['options'] ); return true; }
[ "private", "function", "initWritableStream", "(", ")", "{", "$", "context", "=", "stream_context_get_options", "(", "$", "this", "->", "context", ")", ";", "$", "this", "->", "stream", "=", "new", "WritableStream", "(", "$", "context", "[", "$", "this", "->", "protocol", "]", "[", "'collectionWrapper'", "]", ",", "$", "context", "[", "$", "this", "->", "protocol", "]", "[", "'filename'", "]", ",", "$", "context", "[", "$", "this", "->", "protocol", "]", "[", "'options'", "]", ")", ";", "return", "true", ";", "}" ]
Initialize the internal stream for writing. @see StreamWrapper::stream_open() @return boolean
[ "Initialize", "the", "internal", "stream", "for", "writing", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php#L296-L307
218,270
moodle/moodle
admin/tool/monitor/classes/eventlist.php
eventlist.get_file_list
protected static function get_file_list($directory) { global $CFG; $directoryroot = $CFG->dirroot; $finalfiles = array(); if (is_dir($directory)) { if ($handle = opendir($directory)) { $files = scandir($directory); foreach ($files as $file) { if ($file != '.' && $file != '..') { // Ignore the file if it is external to the system. if (strrpos($directory, $directoryroot) !== false) { $location = substr($directory, strlen($directoryroot)); $name = substr($file, 0, -4); $finalfiles[$name] = $location . '/' . $file; } } } } } return $finalfiles; }
php
protected static function get_file_list($directory) { global $CFG; $directoryroot = $CFG->dirroot; $finalfiles = array(); if (is_dir($directory)) { if ($handle = opendir($directory)) { $files = scandir($directory); foreach ($files as $file) { if ($file != '.' && $file != '..') { // Ignore the file if it is external to the system. if (strrpos($directory, $directoryroot) !== false) { $location = substr($directory, strlen($directoryroot)); $name = substr($file, 0, -4); $finalfiles[$name] = $location . '/' . $file; } } } } } return $finalfiles; }
[ "protected", "static", "function", "get_file_list", "(", "$", "directory", ")", "{", "global", "$", "CFG", ";", "$", "directoryroot", "=", "$", "CFG", "->", "dirroot", ";", "$", "finalfiles", "=", "array", "(", ")", ";", "if", "(", "is_dir", "(", "$", "directory", ")", ")", "{", "if", "(", "$", "handle", "=", "opendir", "(", "$", "directory", ")", ")", "{", "$", "files", "=", "scandir", "(", "$", "directory", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "if", "(", "$", "file", "!=", "'.'", "&&", "$", "file", "!=", "'..'", ")", "{", "// Ignore the file if it is external to the system.", "if", "(", "strrpos", "(", "$", "directory", ",", "$", "directoryroot", ")", "!==", "false", ")", "{", "$", "location", "=", "substr", "(", "$", "directory", ",", "strlen", "(", "$", "directoryroot", ")", ")", ";", "$", "name", "=", "substr", "(", "$", "file", ",", "0", ",", "-", "4", ")", ";", "$", "finalfiles", "[", "$", "name", "]", "=", "$", "location", ".", "'/'", ".", "$", "file", ";", "}", "}", "}", "}", "}", "return", "$", "finalfiles", ";", "}" ]
Returns a list of files with a full directory path in a specified directory. @param string $directory location of files. @return array full location of files from the specified directory.
[ "Returns", "a", "list", "of", "files", "with", "a", "full", "directory", "path", "in", "a", "specified", "directory", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/eventlist.php#L137-L157
218,271
moodle/moodle
admin/tool/monitor/classes/eventlist.php
eventlist.get_all_eventlist
public static function get_all_eventlist($withoutcomponent = false) { if ($withoutcomponent) { $return = array_merge(self::get_core_eventlist(), self::get_non_core_eventlist($withoutcomponent)); array_multisort($return, SORT_NATURAL); } else { $return = array_merge(array('core' => self::get_core_eventlist()), self::get_non_core_eventlist($withoutcomponent = false)); } return $return; }
php
public static function get_all_eventlist($withoutcomponent = false) { if ($withoutcomponent) { $return = array_merge(self::get_core_eventlist(), self::get_non_core_eventlist($withoutcomponent)); array_multisort($return, SORT_NATURAL); } else { $return = array_merge(array('core' => self::get_core_eventlist()), self::get_non_core_eventlist($withoutcomponent = false)); } return $return; }
[ "public", "static", "function", "get_all_eventlist", "(", "$", "withoutcomponent", "=", "false", ")", "{", "if", "(", "$", "withoutcomponent", ")", "{", "$", "return", "=", "array_merge", "(", "self", "::", "get_core_eventlist", "(", ")", ",", "self", "::", "get_non_core_eventlist", "(", "$", "withoutcomponent", ")", ")", ";", "array_multisort", "(", "$", "return", ",", "SORT_NATURAL", ")", ";", "}", "else", "{", "$", "return", "=", "array_merge", "(", "array", "(", "'core'", "=>", "self", "::", "get_core_eventlist", "(", ")", ")", ",", "self", "::", "get_non_core_eventlist", "(", "$", "withoutcomponent", "=", "false", ")", ")", ";", "}", "return", "$", "return", ";", "}" ]
Get a list of events present in the system. @param bool $withoutcomponent Return an eventlist without associated components. @return array list of events present in the system.
[ "Get", "a", "list", "of", "events", "present", "in", "the", "system", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/eventlist.php#L166-L175
218,272
moodle/moodle
admin/tool/monitor/classes/eventlist.php
eventlist.get_plugin_list
public static function get_plugin_list($eventlist = array()) { if (empty($eventlist)) { $eventlist = self::get_all_eventlist(); } $plugins = array_keys($eventlist); $return = array(); foreach ($plugins as $plugin) { if ($plugin === 'core') { $return[$plugin] = get_string('core', 'tool_monitor'); } else if (get_string_manager()->string_exists('pluginname', $plugin)) { $return[$plugin] = get_string('pluginname', $plugin); } else { $return[$plugin] = $plugin; } } return $return; }
php
public static function get_plugin_list($eventlist = array()) { if (empty($eventlist)) { $eventlist = self::get_all_eventlist(); } $plugins = array_keys($eventlist); $return = array(); foreach ($plugins as $plugin) { if ($plugin === 'core') { $return[$plugin] = get_string('core', 'tool_monitor'); } else if (get_string_manager()->string_exists('pluginname', $plugin)) { $return[$plugin] = get_string('pluginname', $plugin); } else { $return[$plugin] = $plugin; } } return $return; }
[ "public", "static", "function", "get_plugin_list", "(", "$", "eventlist", "=", "array", "(", ")", ")", "{", "if", "(", "empty", "(", "$", "eventlist", ")", ")", "{", "$", "eventlist", "=", "self", "::", "get_all_eventlist", "(", ")", ";", "}", "$", "plugins", "=", "array_keys", "(", "$", "eventlist", ")", ";", "$", "return", "=", "array", "(", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", ")", "{", "if", "(", "$", "plugin", "===", "'core'", ")", "{", "$", "return", "[", "$", "plugin", "]", "=", "get_string", "(", "'core'", ",", "'tool_monitor'", ")", ";", "}", "else", "if", "(", "get_string_manager", "(", ")", "->", "string_exists", "(", "'pluginname'", ",", "$", "plugin", ")", ")", "{", "$", "return", "[", "$", "plugin", "]", "=", "get_string", "(", "'pluginname'", ",", "$", "plugin", ")", ";", "}", "else", "{", "$", "return", "[", "$", "plugin", "]", "=", "$", "plugin", ";", "}", "}", "return", "$", "return", ";", "}" ]
Return list of plugins that have events. @param array $eventlist a list of events present in the system {@link eventlist::get_all_eventlist}. @return array list of plugins with human readable name.
[ "Return", "list", "of", "plugins", "that", "have", "events", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/eventlist.php#L184-L201
218,273
moodle/moodle
admin/tool/monitor/classes/eventlist.php
eventlist.validate_event_plugin
public static function validate_event_plugin($plugin, $eventname, $eventlist = array()) { if (empty($eventlist)) { $eventlist = self::get_all_eventlist(); } if (isset($eventlist[$plugin][$eventname])) { return true; } return false; }
php
public static function validate_event_plugin($plugin, $eventname, $eventlist = array()) { if (empty($eventlist)) { $eventlist = self::get_all_eventlist(); } if (isset($eventlist[$plugin][$eventname])) { return true; } return false; }
[ "public", "static", "function", "validate_event_plugin", "(", "$", "plugin", ",", "$", "eventname", ",", "$", "eventlist", "=", "array", "(", ")", ")", "{", "if", "(", "empty", "(", "$", "eventlist", ")", ")", "{", "$", "eventlist", "=", "self", "::", "get_all_eventlist", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "eventlist", "[", "$", "plugin", "]", "[", "$", "eventname", "]", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
validate if the given event belongs to the given plugin. @param string $plugin Frankenstyle name of the plugin. @param string $eventname Full qualified event name. @param array $eventlist List of events generated by {@link eventlist::get_all_eventlist} @return bool Returns true if the selected event belongs to the selected plugin, false otherwise.
[ "validate", "if", "the", "given", "event", "belongs", "to", "the", "given", "plugin", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/eventlist.php#L212-L221
218,274
moodle/moodle
admin/tool/generator/classes/site_backend.php
tool_generator_site_backend.get_size_choices
public static function get_size_choices() { $options = array(); for ($size = self::MIN_SIZE; $size <= self::MAX_SIZE; $size++) { $options[$size] = get_string('sitesize_' . $size, 'tool_generator'); } return $options; }
php
public static function get_size_choices() { $options = array(); for ($size = self::MIN_SIZE; $size <= self::MAX_SIZE; $size++) { $options[$size] = get_string('sitesize_' . $size, 'tool_generator'); } return $options; }
[ "public", "static", "function", "get_size_choices", "(", ")", "{", "$", "options", "=", "array", "(", ")", ";", "for", "(", "$", "size", "=", "self", "::", "MIN_SIZE", ";", "$", "size", "<=", "self", "::", "MAX_SIZE", ";", "$", "size", "++", ")", "{", "$", "options", "[", "$", "size", "]", "=", "get_string", "(", "'sitesize_'", ".", "$", "size", ",", "'tool_generator'", ")", ";", "}", "return", "$", "options", ";", "}" ]
Gets a list of size choices supported by this backend. @return array List of size (int) => text description for display
[ "Gets", "a", "list", "of", "size", "choices", "supported", "by", "this", "backend", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/site_backend.php#L81-L87
218,275
moodle/moodle
admin/tool/generator/classes/site_backend.php
tool_generator_site_backend.run_create_course
protected function run_create_course($shortname, $coursesize) { // We are in $CFG->dirroot. $command = 'php admin/tool/generator/cli/maketestcourse.php'; $options = array( '--shortname="' . $shortname . '"', '--size="' . get_string('shortsize_' . $coursesize, 'tool_generator') . '"' ); if (!$this->progress) { $options[] = '--quiet'; } if ($this->filesizelimit) { $options[] = '--filesizelimit="' . $this->filesizelimit . '"'; } // Extend options. $optionstoextend = array( 'fixeddataset' => 'fixeddataset', 'bypasscheck' => 'bypasscheck', ); // Getting an options string. foreach ($optionstoextend as $attribute => $option) { if (!empty($this->{$attribute})) { $options[] = '--' . $option; } } $options = implode(' ', $options); if ($this->progress) { system($command . ' ' . $options, $exitcode); } else { passthru($command . ' ' . $options, $exitcode); } if ($exitcode != 0) { exit($exitcode); } }
php
protected function run_create_course($shortname, $coursesize) { // We are in $CFG->dirroot. $command = 'php admin/tool/generator/cli/maketestcourse.php'; $options = array( '--shortname="' . $shortname . '"', '--size="' . get_string('shortsize_' . $coursesize, 'tool_generator') . '"' ); if (!$this->progress) { $options[] = '--quiet'; } if ($this->filesizelimit) { $options[] = '--filesizelimit="' . $this->filesizelimit . '"'; } // Extend options. $optionstoextend = array( 'fixeddataset' => 'fixeddataset', 'bypasscheck' => 'bypasscheck', ); // Getting an options string. foreach ($optionstoextend as $attribute => $option) { if (!empty($this->{$attribute})) { $options[] = '--' . $option; } } $options = implode(' ', $options); if ($this->progress) { system($command . ' ' . $options, $exitcode); } else { passthru($command . ' ' . $options, $exitcode); } if ($exitcode != 0) { exit($exitcode); } }
[ "protected", "function", "run_create_course", "(", "$", "shortname", ",", "$", "coursesize", ")", "{", "// We are in $CFG->dirroot.", "$", "command", "=", "'php admin/tool/generator/cli/maketestcourse.php'", ";", "$", "options", "=", "array", "(", "'--shortname=\"'", ".", "$", "shortname", ".", "'\"'", ",", "'--size=\"'", ".", "get_string", "(", "'shortsize_'", ".", "$", "coursesize", ",", "'tool_generator'", ")", ".", "'\"'", ")", ";", "if", "(", "!", "$", "this", "->", "progress", ")", "{", "$", "options", "[", "]", "=", "'--quiet'", ";", "}", "if", "(", "$", "this", "->", "filesizelimit", ")", "{", "$", "options", "[", "]", "=", "'--filesizelimit=\"'", ".", "$", "this", "->", "filesizelimit", ".", "'\"'", ";", "}", "// Extend options.", "$", "optionstoextend", "=", "array", "(", "'fixeddataset'", "=>", "'fixeddataset'", ",", "'bypasscheck'", "=>", "'bypasscheck'", ",", ")", ";", "// Getting an options string.", "foreach", "(", "$", "optionstoextend", "as", "$", "attribute", "=>", "$", "option", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "{", "$", "attribute", "}", ")", ")", "{", "$", "options", "[", "]", "=", "'--'", ".", "$", "option", ";", "}", "}", "$", "options", "=", "implode", "(", "' '", ",", "$", "options", ")", ";", "if", "(", "$", "this", "->", "progress", ")", "{", "system", "(", "$", "command", ".", "' '", ".", "$", "options", ",", "$", "exitcode", ")", ";", "}", "else", "{", "passthru", "(", "$", "command", ".", "' '", ".", "$", "options", ",", "$", "exitcode", ")", ";", "}", "if", "(", "$", "exitcode", "!=", "0", ")", "{", "exit", "(", "$", "exitcode", ")", ";", "}", "}" ]
Creates a course with the specified shortname, coursesize and the provided maketestsite options. @param string $shortname The course shortname @param int $coursesize One of the possible course sizes. @return void
[ "Creates", "a", "course", "with", "the", "specified", "shortname", "coursesize", "and", "the", "provided", "maketestsite", "options", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/site_backend.php#L138-L178
218,276
moodle/moodle
lib/mlbackend/python/classes/processor.php
processor.is_ready
public function is_ready() { if (empty($this->pathtopython)) { $settingurl = new \moodle_url('/admin/settings.php', array('section' => 'systempaths')); return get_string('pythonpathnotdefined', 'mlbackend_python', $settingurl->out()); } // Check the installed pip package version. $cmd = "{$this->pathtopython} -m moodlemlbackend.version"; $output = null; $exitcode = null; // Execute it sending the standard error to $output. $result = exec($cmd . ' 2>&1', $output, $exitcode); $vercheck = self::check_pip_package_version($result); if ($vercheck === 0) { return true; } if ($exitcode != 0) { return get_string('pythonpackagenotinstalled', 'mlbackend_python', $cmd); } if ($result) { $a = [ 'installed' => $result, 'required' => self::REQUIRED_PIP_PACKAGE_VERSION, ]; if ($vercheck < 0) { return get_string('packageinstalledshouldbe', 'mlbackend_python', $a); } else if ($vercheck > 0) { return get_string('packageinstalledtoohigh', 'mlbackend_python', $a); } } return get_string('pythonpackagenotinstalled', 'mlbackend_python', $cmd); }
php
public function is_ready() { if (empty($this->pathtopython)) { $settingurl = new \moodle_url('/admin/settings.php', array('section' => 'systempaths')); return get_string('pythonpathnotdefined', 'mlbackend_python', $settingurl->out()); } // Check the installed pip package version. $cmd = "{$this->pathtopython} -m moodlemlbackend.version"; $output = null; $exitcode = null; // Execute it sending the standard error to $output. $result = exec($cmd . ' 2>&1', $output, $exitcode); $vercheck = self::check_pip_package_version($result); if ($vercheck === 0) { return true; } if ($exitcode != 0) { return get_string('pythonpackagenotinstalled', 'mlbackend_python', $cmd); } if ($result) { $a = [ 'installed' => $result, 'required' => self::REQUIRED_PIP_PACKAGE_VERSION, ]; if ($vercheck < 0) { return get_string('packageinstalledshouldbe', 'mlbackend_python', $a); } else if ($vercheck > 0) { return get_string('packageinstalledtoohigh', 'mlbackend_python', $a); } } return get_string('pythonpackagenotinstalled', 'mlbackend_python', $cmd); }
[ "public", "function", "is_ready", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "pathtopython", ")", ")", "{", "$", "settingurl", "=", "new", "\\", "moodle_url", "(", "'/admin/settings.php'", ",", "array", "(", "'section'", "=>", "'systempaths'", ")", ")", ";", "return", "get_string", "(", "'pythonpathnotdefined'", ",", "'mlbackend_python'", ",", "$", "settingurl", "->", "out", "(", ")", ")", ";", "}", "// Check the installed pip package version.", "$", "cmd", "=", "\"{$this->pathtopython} -m moodlemlbackend.version\"", ";", "$", "output", "=", "null", ";", "$", "exitcode", "=", "null", ";", "// Execute it sending the standard error to $output.", "$", "result", "=", "exec", "(", "$", "cmd", ".", "' 2>&1'", ",", "$", "output", ",", "$", "exitcode", ")", ";", "$", "vercheck", "=", "self", "::", "check_pip_package_version", "(", "$", "result", ")", ";", "if", "(", "$", "vercheck", "===", "0", ")", "{", "return", "true", ";", "}", "if", "(", "$", "exitcode", "!=", "0", ")", "{", "return", "get_string", "(", "'pythonpackagenotinstalled'", ",", "'mlbackend_python'", ",", "$", "cmd", ")", ";", "}", "if", "(", "$", "result", ")", "{", "$", "a", "=", "[", "'installed'", "=>", "$", "result", ",", "'required'", "=>", "self", "::", "REQUIRED_PIP_PACKAGE_VERSION", ",", "]", ";", "if", "(", "$", "vercheck", "<", "0", ")", "{", "return", "get_string", "(", "'packageinstalledshouldbe'", ",", "'mlbackend_python'", ",", "$", "a", ")", ";", "}", "else", "if", "(", "$", "vercheck", ">", "0", ")", "{", "return", "get_string", "(", "'packageinstalledtoohigh'", ",", "'mlbackend_python'", ",", "$", "a", ")", ";", "}", "}", "return", "get_string", "(", "'pythonpackagenotinstalled'", ",", "'mlbackend_python'", ",", "$", "cmd", ")", ";", "}" ]
Is the plugin ready to be used?. @return bool|string Returns true on success, a string detailing the error otherwise
[ "Is", "the", "plugin", "ready", "to", "be", "used?", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/python/classes/processor.php#L67-L106
218,277
moodle/moodle
lib/mlbackend/python/classes/processor.php
processor.check_pip_package_version
public static function check_pip_package_version($actual, $required = self::REQUIRED_PIP_PACKAGE_VERSION) { if (empty($actual)) { return -1; } if (version_compare($actual, $required, '<')) { return -1; } $parts = explode('.', $required); $requiredapiver = reset($parts); $parts = explode('.', $actual); $actualapiver = reset($parts); if ($requiredapiver > 0 || $actualapiver > 1) { if (version_compare($actual, $requiredapiver + 1, '>=')) { return 1; } } return 0; }
php
public static function check_pip_package_version($actual, $required = self::REQUIRED_PIP_PACKAGE_VERSION) { if (empty($actual)) { return -1; } if (version_compare($actual, $required, '<')) { return -1; } $parts = explode('.', $required); $requiredapiver = reset($parts); $parts = explode('.', $actual); $actualapiver = reset($parts); if ($requiredapiver > 0 || $actualapiver > 1) { if (version_compare($actual, $requiredapiver + 1, '>=')) { return 1; } } return 0; }
[ "public", "static", "function", "check_pip_package_version", "(", "$", "actual", ",", "$", "required", "=", "self", "::", "REQUIRED_PIP_PACKAGE_VERSION", ")", "{", "if", "(", "empty", "(", "$", "actual", ")", ")", "{", "return", "-", "1", ";", "}", "if", "(", "version_compare", "(", "$", "actual", ",", "$", "required", ",", "'<'", ")", ")", "{", "return", "-", "1", ";", "}", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "required", ")", ";", "$", "requiredapiver", "=", "reset", "(", "$", "parts", ")", ";", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "actual", ")", ";", "$", "actualapiver", "=", "reset", "(", "$", "parts", ")", ";", "if", "(", "$", "requiredapiver", ">", "0", "||", "$", "actualapiver", ">", "1", ")", "{", "if", "(", "version_compare", "(", "$", "actual", ",", "$", "requiredapiver", "+", "1", ",", "'>='", ")", ")", "{", "return", "1", ";", "}", "}", "return", "0", ";", "}" ]
Check that the given package version can be used and return the error status. When evaluating the version, we assume the sematic versioning scheme as described at https://semver.org/. @param string $actual The actual Python package version @param string $required The required version of the package @return int -1 = actual version is too low, 1 = actual version too high, 0 = actual version is ok
[ "Check", "that", "the", "given", "package", "version", "can", "be", "used", "and", "return", "the", "error", "status", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/python/classes/processor.php#L420-L443
218,278
moodle/moodle
badges/classes/observer.php
core_badges_observer.course_module_criteria_review
public static function course_module_criteria_review(\core\event\course_module_completion_updated $event) { global $DB, $CFG; if (!empty($CFG->enablebadges)) { require_once($CFG->dirroot.'/lib/badgeslib.php'); $eventdata = $event->get_record_snapshot('course_modules_completion', $event->objectid); $userid = $event->relateduserid; $mod = $event->contextinstanceid; if ($eventdata->completionstate == COMPLETION_COMPLETE || $eventdata->completionstate == COMPLETION_COMPLETE_PASS || $eventdata->completionstate == COMPLETION_COMPLETE_FAIL) { // Need to take into account that there can be more than one badge with the same activity in its criteria. if ($rs = $DB->get_records('badge_criteria_param', array('name' => 'module_' . $mod, 'value' => $mod))) { foreach ($rs as $r) { $bid = $DB->get_field('badge_criteria', 'badgeid', array('id' => $r->critid), MUST_EXIST); $badge = new badge($bid); if (!$badge->is_active() || $badge->is_issued($userid)) { continue; } if ($badge->criteria[BADGE_CRITERIA_TYPE_ACTIVITY]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_ACTIVITY]->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } } } } } }
php
public static function course_module_criteria_review(\core\event\course_module_completion_updated $event) { global $DB, $CFG; if (!empty($CFG->enablebadges)) { require_once($CFG->dirroot.'/lib/badgeslib.php'); $eventdata = $event->get_record_snapshot('course_modules_completion', $event->objectid); $userid = $event->relateduserid; $mod = $event->contextinstanceid; if ($eventdata->completionstate == COMPLETION_COMPLETE || $eventdata->completionstate == COMPLETION_COMPLETE_PASS || $eventdata->completionstate == COMPLETION_COMPLETE_FAIL) { // Need to take into account that there can be more than one badge with the same activity in its criteria. if ($rs = $DB->get_records('badge_criteria_param', array('name' => 'module_' . $mod, 'value' => $mod))) { foreach ($rs as $r) { $bid = $DB->get_field('badge_criteria', 'badgeid', array('id' => $r->critid), MUST_EXIST); $badge = new badge($bid); if (!$badge->is_active() || $badge->is_issued($userid)) { continue; } if ($badge->criteria[BADGE_CRITERIA_TYPE_ACTIVITY]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_ACTIVITY]->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } } } } } }
[ "public", "static", "function", "course_module_criteria_review", "(", "\\", "core", "\\", "event", "\\", "course_module_completion_updated", "$", "event", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "enablebadges", ")", ")", "{", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/lib/badgeslib.php'", ")", ";", "$", "eventdata", "=", "$", "event", "->", "get_record_snapshot", "(", "'course_modules_completion'", ",", "$", "event", "->", "objectid", ")", ";", "$", "userid", "=", "$", "event", "->", "relateduserid", ";", "$", "mod", "=", "$", "event", "->", "contextinstanceid", ";", "if", "(", "$", "eventdata", "->", "completionstate", "==", "COMPLETION_COMPLETE", "||", "$", "eventdata", "->", "completionstate", "==", "COMPLETION_COMPLETE_PASS", "||", "$", "eventdata", "->", "completionstate", "==", "COMPLETION_COMPLETE_FAIL", ")", "{", "// Need to take into account that there can be more than one badge with the same activity in its criteria.", "if", "(", "$", "rs", "=", "$", "DB", "->", "get_records", "(", "'badge_criteria_param'", ",", "array", "(", "'name'", "=>", "'module_'", ".", "$", "mod", ",", "'value'", "=>", "$", "mod", ")", ")", ")", "{", "foreach", "(", "$", "rs", "as", "$", "r", ")", "{", "$", "bid", "=", "$", "DB", "->", "get_field", "(", "'badge_criteria'", ",", "'badgeid'", ",", "array", "(", "'id'", "=>", "$", "r", "->", "critid", ")", ",", "MUST_EXIST", ")", ";", "$", "badge", "=", "new", "badge", "(", "$", "bid", ")", ";", "if", "(", "!", "$", "badge", "->", "is_active", "(", ")", "||", "$", "badge", "->", "is_issued", "(", "$", "userid", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_ACTIVITY", "]", "->", "review", "(", "$", "userid", ")", ")", "{", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_ACTIVITY", "]", "->", "mark_complete", "(", "$", "userid", ")", ";", "if", "(", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "review", "(", "$", "userid", ")", ")", "{", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "mark_complete", "(", "$", "userid", ")", ";", "$", "badge", "->", "issue", "(", "$", "userid", ")", ";", "}", "}", "}", "}", "}", "}", "}" ]
Triggered when 'course_module_completion_updated' event is triggered. @param \core\event\course_module_completion_updated $event
[ "Triggered", "when", "course_module_completion_updated", "event", "is", "triggered", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/classes/observer.php#L36-L70
218,279
moodle/moodle
badges/classes/observer.php
core_badges_observer.competency_criteria_review
public static function competency_criteria_review(\core\event\competency_evidence_created $event) { global $DB, $CFG; if (!empty($CFG->enablebadges)) { require_once($CFG->dirroot.'/lib/badgeslib.php'); if (!get_config('core_competency', 'enabled')) { return; } $ucid = $event->other['usercompetencyid']; $cid = $event->other['competencyid']; $userid = $event->relateduserid; if ($rs = $DB->get_records('badge_criteria_param', array('name' => 'competency_' . $cid, 'value' => $cid))) { foreach ($rs as $r) { $crit = $DB->get_record('badge_criteria', array('id' => $r->critid), 'badgeid, criteriatype', MUST_EXIST); $badge = new badge($crit->badgeid); // Only site badges are updated from site competencies. if (!$badge->is_active() || $badge->is_issued($userid)) { continue; } if ($badge->criteria[$crit->criteriatype]->review($userid)) { $badge->criteria[$crit->criteriatype]->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } } } } }
php
public static function competency_criteria_review(\core\event\competency_evidence_created $event) { global $DB, $CFG; if (!empty($CFG->enablebadges)) { require_once($CFG->dirroot.'/lib/badgeslib.php'); if (!get_config('core_competency', 'enabled')) { return; } $ucid = $event->other['usercompetencyid']; $cid = $event->other['competencyid']; $userid = $event->relateduserid; if ($rs = $DB->get_records('badge_criteria_param', array('name' => 'competency_' . $cid, 'value' => $cid))) { foreach ($rs as $r) { $crit = $DB->get_record('badge_criteria', array('id' => $r->critid), 'badgeid, criteriatype', MUST_EXIST); $badge = new badge($crit->badgeid); // Only site badges are updated from site competencies. if (!$badge->is_active() || $badge->is_issued($userid)) { continue; } if ($badge->criteria[$crit->criteriatype]->review($userid)) { $badge->criteria[$crit->criteriatype]->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } } } } }
[ "public", "static", "function", "competency_criteria_review", "(", "\\", "core", "\\", "event", "\\", "competency_evidence_created", "$", "event", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "enablebadges", ")", ")", "{", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/lib/badgeslib.php'", ")", ";", "if", "(", "!", "get_config", "(", "'core_competency'", ",", "'enabled'", ")", ")", "{", "return", ";", "}", "$", "ucid", "=", "$", "event", "->", "other", "[", "'usercompetencyid'", "]", ";", "$", "cid", "=", "$", "event", "->", "other", "[", "'competencyid'", "]", ";", "$", "userid", "=", "$", "event", "->", "relateduserid", ";", "if", "(", "$", "rs", "=", "$", "DB", "->", "get_records", "(", "'badge_criteria_param'", ",", "array", "(", "'name'", "=>", "'competency_'", ".", "$", "cid", ",", "'value'", "=>", "$", "cid", ")", ")", ")", "{", "foreach", "(", "$", "rs", "as", "$", "r", ")", "{", "$", "crit", "=", "$", "DB", "->", "get_record", "(", "'badge_criteria'", ",", "array", "(", "'id'", "=>", "$", "r", "->", "critid", ")", ",", "'badgeid, criteriatype'", ",", "MUST_EXIST", ")", ";", "$", "badge", "=", "new", "badge", "(", "$", "crit", "->", "badgeid", ")", ";", "// Only site badges are updated from site competencies.", "if", "(", "!", "$", "badge", "->", "is_active", "(", ")", "||", "$", "badge", "->", "is_issued", "(", "$", "userid", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "badge", "->", "criteria", "[", "$", "crit", "->", "criteriatype", "]", "->", "review", "(", "$", "userid", ")", ")", "{", "$", "badge", "->", "criteria", "[", "$", "crit", "->", "criteriatype", "]", "->", "mark_complete", "(", "$", "userid", ")", ";", "if", "(", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "review", "(", "$", "userid", ")", ")", "{", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "mark_complete", "(", "$", "userid", ")", ";", "$", "badge", "->", "issue", "(", "$", "userid", ")", ";", "}", "}", "}", "}", "}", "}" ]
Triggered when '\core\event\competency_evidence_created' event is triggered. @param \core\event\competency_evidence_created $event
[ "Triggered", "when", "\\", "core", "\\", "event", "\\", "competency_evidence_created", "event", "is", "triggered", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/classes/observer.php#L77-L111
218,280
moodle/moodle
badges/classes/observer.php
core_badges_observer.course_criteria_review
public static function course_criteria_review(\core\event\course_completed $event) { global $DB, $CFG; if (!empty($CFG->enablebadges)) { require_once($CFG->dirroot.'/lib/badgeslib.php'); $userid = $event->relateduserid; $courseid = $event->courseid; // Need to take into account that course can be a part of course_completion and courseset_completion criteria. if ($rs = $DB->get_records('badge_criteria_param', array('name' => 'course_' . $courseid, 'value' => $courseid))) { foreach ($rs as $r) { $crit = $DB->get_record('badge_criteria', array('id' => $r->critid), 'badgeid, criteriatype', MUST_EXIST); $badge = new badge($crit->badgeid); if (!$badge->is_active() || $badge->is_issued($userid)) { continue; } if ($badge->criteria[$crit->criteriatype]->review($userid)) { $badge->criteria[$crit->criteriatype]->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } } } } }
php
public static function course_criteria_review(\core\event\course_completed $event) { global $DB, $CFG; if (!empty($CFG->enablebadges)) { require_once($CFG->dirroot.'/lib/badgeslib.php'); $userid = $event->relateduserid; $courseid = $event->courseid; // Need to take into account that course can be a part of course_completion and courseset_completion criteria. if ($rs = $DB->get_records('badge_criteria_param', array('name' => 'course_' . $courseid, 'value' => $courseid))) { foreach ($rs as $r) { $crit = $DB->get_record('badge_criteria', array('id' => $r->critid), 'badgeid, criteriatype', MUST_EXIST); $badge = new badge($crit->badgeid); if (!$badge->is_active() || $badge->is_issued($userid)) { continue; } if ($badge->criteria[$crit->criteriatype]->review($userid)) { $badge->criteria[$crit->criteriatype]->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } } } } }
[ "public", "static", "function", "course_criteria_review", "(", "\\", "core", "\\", "event", "\\", "course_completed", "$", "event", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "enablebadges", ")", ")", "{", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/lib/badgeslib.php'", ")", ";", "$", "userid", "=", "$", "event", "->", "relateduserid", ";", "$", "courseid", "=", "$", "event", "->", "courseid", ";", "// Need to take into account that course can be a part of course_completion and courseset_completion criteria.", "if", "(", "$", "rs", "=", "$", "DB", "->", "get_records", "(", "'badge_criteria_param'", ",", "array", "(", "'name'", "=>", "'course_'", ".", "$", "courseid", ",", "'value'", "=>", "$", "courseid", ")", ")", ")", "{", "foreach", "(", "$", "rs", "as", "$", "r", ")", "{", "$", "crit", "=", "$", "DB", "->", "get_record", "(", "'badge_criteria'", ",", "array", "(", "'id'", "=>", "$", "r", "->", "critid", ")", ",", "'badgeid, criteriatype'", ",", "MUST_EXIST", ")", ";", "$", "badge", "=", "new", "badge", "(", "$", "crit", "->", "badgeid", ")", ";", "if", "(", "!", "$", "badge", "->", "is_active", "(", ")", "||", "$", "badge", "->", "is_issued", "(", "$", "userid", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "badge", "->", "criteria", "[", "$", "crit", "->", "criteriatype", "]", "->", "review", "(", "$", "userid", ")", ")", "{", "$", "badge", "->", "criteria", "[", "$", "crit", "->", "criteriatype", "]", "->", "mark_complete", "(", "$", "userid", ")", ";", "if", "(", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "review", "(", "$", "userid", ")", ")", "{", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "mark_complete", "(", "$", "userid", ")", ";", "$", "badge", "->", "issue", "(", "$", "userid", ")", ";", "}", "}", "}", "}", "}", "}" ]
Triggered when 'course_completed' event is triggered. @param \core\event\course_completed $event
[ "Triggered", "when", "course_completed", "event", "is", "triggered", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/classes/observer.php#L118-L147
218,281
moodle/moodle
badges/classes/observer.php
core_badges_observer.badge_criteria_review
public static function badge_criteria_review(\core\event\badge_awarded $event) { global $DB, $CFG; if (!empty($CFG->enablebadges)) { require_once($CFG->dirroot.'/lib/badgeslib.php'); $userid = $event->relateduserid; if ($rs = $DB->get_records('badge_criteria', array('criteriatype' => BADGE_CRITERIA_TYPE_BADGE))) { foreach ($rs as $r) { $badge = new badge($r->badgeid); if (!$badge->is_active() || $badge->is_issued($userid)) { continue; } if ($badge->criteria[BADGE_CRITERIA_TYPE_BADGE]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_BADGE]->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } } } } }
php
public static function badge_criteria_review(\core\event\badge_awarded $event) { global $DB, $CFG; if (!empty($CFG->enablebadges)) { require_once($CFG->dirroot.'/lib/badgeslib.php'); $userid = $event->relateduserid; if ($rs = $DB->get_records('badge_criteria', array('criteriatype' => BADGE_CRITERIA_TYPE_BADGE))) { foreach ($rs as $r) { $badge = new badge($r->badgeid); if (!$badge->is_active() || $badge->is_issued($userid)) { continue; } if ($badge->criteria[BADGE_CRITERIA_TYPE_BADGE]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_BADGE]->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } } } } }
[ "public", "static", "function", "badge_criteria_review", "(", "\\", "core", "\\", "event", "\\", "badge_awarded", "$", "event", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "enablebadges", ")", ")", "{", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/lib/badgeslib.php'", ")", ";", "$", "userid", "=", "$", "event", "->", "relateduserid", ";", "if", "(", "$", "rs", "=", "$", "DB", "->", "get_records", "(", "'badge_criteria'", ",", "array", "(", "'criteriatype'", "=>", "BADGE_CRITERIA_TYPE_BADGE", ")", ")", ")", "{", "foreach", "(", "$", "rs", "as", "$", "r", ")", "{", "$", "badge", "=", "new", "badge", "(", "$", "r", "->", "badgeid", ")", ";", "if", "(", "!", "$", "badge", "->", "is_active", "(", ")", "||", "$", "badge", "->", "is_issued", "(", "$", "userid", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_BADGE", "]", "->", "review", "(", "$", "userid", ")", ")", "{", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_BADGE", "]", "->", "mark_complete", "(", "$", "userid", ")", ";", "if", "(", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "review", "(", "$", "userid", ")", ")", "{", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "mark_complete", "(", "$", "userid", ")", ";", "$", "badge", "->", "issue", "(", "$", "userid", ")", ";", "}", "}", "}", "}", "}", "}" ]
Triggered when 'badge_awarded' event happens. @param \core\event\badge_awarded $event event generated when a badge is awarded.
[ "Triggered", "when", "badge_awarded", "event", "happens", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/classes/observer.php#L154-L179
218,282
moodle/moodle
badges/classes/observer.php
core_badges_observer.profile_criteria_review
public static function profile_criteria_review(\core\event\user_updated $event) { global $DB, $CFG; if (!empty($CFG->enablebadges)) { require_once($CFG->dirroot.'/lib/badgeslib.php'); $userid = $event->objectid; if ($rs = $DB->get_records('badge_criteria', array('criteriatype' => BADGE_CRITERIA_TYPE_PROFILE))) { foreach ($rs as $r) { $badge = new badge($r->badgeid); if (!$badge->is_active() || $badge->is_issued($userid)) { continue; } if ($badge->criteria[BADGE_CRITERIA_TYPE_PROFILE]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_PROFILE]->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } } } } }
php
public static function profile_criteria_review(\core\event\user_updated $event) { global $DB, $CFG; if (!empty($CFG->enablebadges)) { require_once($CFG->dirroot.'/lib/badgeslib.php'); $userid = $event->objectid; if ($rs = $DB->get_records('badge_criteria', array('criteriatype' => BADGE_CRITERIA_TYPE_PROFILE))) { foreach ($rs as $r) { $badge = new badge($r->badgeid); if (!$badge->is_active() || $badge->is_issued($userid)) { continue; } if ($badge->criteria[BADGE_CRITERIA_TYPE_PROFILE]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_PROFILE]->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } } } } }
[ "public", "static", "function", "profile_criteria_review", "(", "\\", "core", "\\", "event", "\\", "user_updated", "$", "event", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "enablebadges", ")", ")", "{", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/lib/badgeslib.php'", ")", ";", "$", "userid", "=", "$", "event", "->", "objectid", ";", "if", "(", "$", "rs", "=", "$", "DB", "->", "get_records", "(", "'badge_criteria'", ",", "array", "(", "'criteriatype'", "=>", "BADGE_CRITERIA_TYPE_PROFILE", ")", ")", ")", "{", "foreach", "(", "$", "rs", "as", "$", "r", ")", "{", "$", "badge", "=", "new", "badge", "(", "$", "r", "->", "badgeid", ")", ";", "if", "(", "!", "$", "badge", "->", "is_active", "(", ")", "||", "$", "badge", "->", "is_issued", "(", "$", "userid", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_PROFILE", "]", "->", "review", "(", "$", "userid", ")", ")", "{", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_PROFILE", "]", "->", "mark_complete", "(", "$", "userid", ")", ";", "if", "(", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "review", "(", "$", "userid", ")", ")", "{", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "mark_complete", "(", "$", "userid", ")", ";", "$", "badge", "->", "issue", "(", "$", "userid", ")", ";", "}", "}", "}", "}", "}", "}" ]
Triggered when 'user_updated' event happens. @param \core\event\user_updated $event event generated when user profile is updated.
[ "Triggered", "when", "user_updated", "event", "happens", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/classes/observer.php#L185-L210
218,283
moodle/moodle
badges/classes/observer.php
core_badges_observer.cohort_criteria_review
public static function cohort_criteria_review(\core\event\cohort_member_added $event) { global $DB, $CFG; if (!empty($CFG->enablebadges)) { require_once($CFG->dirroot.'/lib/badgeslib.php'); $cohortid = $event->objectid; $userid = $event->relateduserid; // Get relevant badges. $badgesql = "SELECT badgeid FROM {badge_criteria_param} cp JOIN {badge_criteria} c ON cp.critid = c.id WHERE c.criteriatype = ? AND cp.name = ?"; $badges = $DB->get_records_sql($badgesql, array(BADGE_CRITERIA_TYPE_COHORT, "cohort_{$cohortid}")); if (empty($badges)) { return; } foreach ($badges as $b) { $badge = new badge($b->badgeid); if (!$badge->is_active()) { continue; } if ($badge->is_issued($userid)) { continue; } if ($badge->criteria[BADGE_CRITERIA_TYPE_COHORT]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_COHORT]->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } } } }
php
public static function cohort_criteria_review(\core\event\cohort_member_added $event) { global $DB, $CFG; if (!empty($CFG->enablebadges)) { require_once($CFG->dirroot.'/lib/badgeslib.php'); $cohortid = $event->objectid; $userid = $event->relateduserid; // Get relevant badges. $badgesql = "SELECT badgeid FROM {badge_criteria_param} cp JOIN {badge_criteria} c ON cp.critid = c.id WHERE c.criteriatype = ? AND cp.name = ?"; $badges = $DB->get_records_sql($badgesql, array(BADGE_CRITERIA_TYPE_COHORT, "cohort_{$cohortid}")); if (empty($badges)) { return; } foreach ($badges as $b) { $badge = new badge($b->badgeid); if (!$badge->is_active()) { continue; } if ($badge->is_issued($userid)) { continue; } if ($badge->criteria[BADGE_CRITERIA_TYPE_COHORT]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_COHORT]->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } } } }
[ "public", "static", "function", "cohort_criteria_review", "(", "\\", "core", "\\", "event", "\\", "cohort_member_added", "$", "event", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "enablebadges", ")", ")", "{", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/lib/badgeslib.php'", ")", ";", "$", "cohortid", "=", "$", "event", "->", "objectid", ";", "$", "userid", "=", "$", "event", "->", "relateduserid", ";", "// Get relevant badges.", "$", "badgesql", "=", "\"SELECT badgeid\n FROM {badge_criteria_param} cp\n JOIN {badge_criteria} c ON cp.critid = c.id\n WHERE c.criteriatype = ?\n AND cp.name = ?\"", ";", "$", "badges", "=", "$", "DB", "->", "get_records_sql", "(", "$", "badgesql", ",", "array", "(", "BADGE_CRITERIA_TYPE_COHORT", ",", "\"cohort_{$cohortid}\"", ")", ")", ";", "if", "(", "empty", "(", "$", "badges", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "badges", "as", "$", "b", ")", "{", "$", "badge", "=", "new", "badge", "(", "$", "b", "->", "badgeid", ")", ";", "if", "(", "!", "$", "badge", "->", "is_active", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "badge", "->", "is_issued", "(", "$", "userid", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_COHORT", "]", "->", "review", "(", "$", "userid", ")", ")", "{", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_COHORT", "]", "->", "mark_complete", "(", "$", "userid", ")", ";", "if", "(", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "review", "(", "$", "userid", ")", ")", "{", "$", "badge", "->", "criteria", "[", "BADGE_CRITERIA_TYPE_OVERALL", "]", "->", "mark_complete", "(", "$", "userid", ")", ";", "$", "badge", "->", "issue", "(", "$", "userid", ")", ";", "}", "}", "}", "}", "}" ]
Triggered when the 'cohort_member_added' event happens. @param \core\event\cohort_member_added $event generated when a user is added to a cohort
[ "Triggered", "when", "the", "cohort_member_added", "event", "happens", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/classes/observer.php#L217-L255
218,284
moodle/moodle
lib/horde/framework/Horde/Crypt/Blowfish/Php.php
Horde_Crypt_Blowfish_Php._init
protected function _init() { if (!isset($this->_ob) || ($this->_ob->md5 != hash('md5', $this->key))) { switch ($this->cipher) { case 'cbc': $this->_ob = new Horde_Crypt_Blowfish_Php_Cbc($this->key); break; case 'ecb': $this->_ob = new Horde_Crypt_Blowfish_Php_Ecb($this->key); break; } } }
php
protected function _init() { if (!isset($this->_ob) || ($this->_ob->md5 != hash('md5', $this->key))) { switch ($this->cipher) { case 'cbc': $this->_ob = new Horde_Crypt_Blowfish_Php_Cbc($this->key); break; case 'ecb': $this->_ob = new Horde_Crypt_Blowfish_Php_Ecb($this->key); break; } } }
[ "protected", "function", "_init", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_ob", ")", "||", "(", "$", "this", "->", "_ob", "->", "md5", "!=", "hash", "(", "'md5'", ",", "$", "this", "->", "key", ")", ")", ")", "{", "switch", "(", "$", "this", "->", "cipher", ")", "{", "case", "'cbc'", ":", "$", "this", "->", "_ob", "=", "new", "Horde_Crypt_Blowfish_Php_Cbc", "(", "$", "this", "->", "key", ")", ";", "break", ";", "case", "'ecb'", ":", "$", "this", "->", "_ob", "=", "new", "Horde_Crypt_Blowfish_Php_Ecb", "(", "$", "this", "->", "key", ")", ";", "break", ";", "}", "}", "}" ]
Initialize the subclass.
[ "Initialize", "the", "subclass", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Crypt/Blowfish/Php.php#L59-L73
218,285
moodle/moodle
admin/tool/log/classes/helper/reader.php
reader.get_name
public function get_name() { if (get_string_manager()->string_exists('pluginname', $this->component)) { return get_string('pluginname', $this->component); } return $this->store; }
php
public function get_name() { if (get_string_manager()->string_exists('pluginname', $this->component)) { return get_string('pluginname', $this->component); } return $this->store; }
[ "public", "function", "get_name", "(", ")", "{", "if", "(", "get_string_manager", "(", ")", "->", "string_exists", "(", "'pluginname'", ",", "$", "this", "->", "component", ")", ")", "{", "return", "get_string", "(", "'pluginname'", ",", "$", "this", "->", "component", ")", ";", "}", "return", "$", "this", "->", "store", ";", "}" ]
Default get name api. @return string name of the store.
[ "Default", "get", "name", "api", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/classes/helper/reader.php#L46-L51
218,286
moodle/moodle
admin/tool/log/classes/helper/reader.php
reader.get_description
public function get_description() { if (get_string_manager()->string_exists('pluginname_desc', $this->component)) { return get_string('pluginname_desc', $this->component); } return $this->store; }
php
public function get_description() { if (get_string_manager()->string_exists('pluginname_desc', $this->component)) { return get_string('pluginname_desc', $this->component); } return $this->store; }
[ "public", "function", "get_description", "(", ")", "{", "if", "(", "get_string_manager", "(", ")", "->", "string_exists", "(", "'pluginname_desc'", ",", "$", "this", "->", "component", ")", ")", "{", "return", "get_string", "(", "'pluginname_desc'", ",", "$", "this", "->", "component", ")", ";", "}", "return", "$", "this", "->", "store", ";", "}" ]
Default get description method. @return string description of the store.
[ "Default", "get", "description", "method", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/classes/helper/reader.php#L58-L63
218,287
moodle/moodle
admin/tool/log/classes/helper/reader.php
reader.decode_other
public static function decode_other(?string $other) { if ($other === 'N;' || preg_match('~^.:~', $other)) { return unserialize($other); } else { return json_decode($other, true); } }
php
public static function decode_other(?string $other) { if ($other === 'N;' || preg_match('~^.:~', $other)) { return unserialize($other); } else { return json_decode($other, true); } }
[ "public", "static", "function", "decode_other", "(", "?", "string", "$", "other", ")", "{", "if", "(", "$", "other", "===", "'N;'", "||", "preg_match", "(", "'~^.:~'", ",", "$", "other", ")", ")", "{", "return", "unserialize", "(", "$", "other", ")", ";", "}", "else", "{", "return", "json_decode", "(", "$", "other", ",", "true", ")", ";", "}", "}" ]
Function decodes the other field into an array using either PHP serialisation or JSON. Note that this does not rely on the config setting, it supports both formats, so you can use it for data before/after making a change to the config setting. The return value is usually an array but it can also be null or a boolean or something. @param string $other Other value @return mixed Decoded value
[ "Function", "decodes", "the", "other", "field", "into", "an", "array", "using", "either", "PHP", "serialisation", "or", "JSON", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/classes/helper/reader.php#L76-L82
218,288
moodle/moodle
backup/util/helper/restore_decode_processor.class.php
restore_decode_processor.decode_content
public function decode_content($content) { if (!$content = $this->precheck_content($content)) { // Perform some prechecks return false; } // Iterate over all rules, chaining results foreach ($this->rules as $rule) { $content = $rule->decode($content); } return $content; }
php
public function decode_content($content) { if (!$content = $this->precheck_content($content)) { // Perform some prechecks return false; } // Iterate over all rules, chaining results foreach ($this->rules as $rule) { $content = $rule->decode($content); } return $content; }
[ "public", "function", "decode_content", "(", "$", "content", ")", "{", "if", "(", "!", "$", "content", "=", "$", "this", "->", "precheck_content", "(", "$", "content", ")", ")", "{", "// Perform some prechecks", "return", "false", ";", "}", "// Iterate over all rules, chaining results", "foreach", "(", "$", "this", "->", "rules", "as", "$", "rule", ")", "{", "$", "content", "=", "$", "rule", "->", "decode", "(", "$", "content", ")", ";", "}", "return", "$", "content", ";", "}" ]
Receive content from restore_decode_content objects and apply all the restore_decode_rules to them
[ "Receive", "content", "from", "restore_decode_content", "objects", "and", "apply", "all", "the", "restore_decode_rules", "to", "them" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/restore_decode_processor.class.php#L89-L98
218,289
moodle/moodle
lib/php-css-parser/RuleSet/DeclarationBlock.php
DeclarationBlock.removeSelector
public function removeSelector($mSelector) { if($mSelector instanceof Selector) { $mSelector = $mSelector->getSelector(); } foreach($this->aSelectors as $iKey => $oSelector) { if($oSelector->getSelector() === $mSelector) { unset($this->aSelectors[$iKey]); return true; } } return false; }
php
public function removeSelector($mSelector) { if($mSelector instanceof Selector) { $mSelector = $mSelector->getSelector(); } foreach($this->aSelectors as $iKey => $oSelector) { if($oSelector->getSelector() === $mSelector) { unset($this->aSelectors[$iKey]); return true; } } return false; }
[ "public", "function", "removeSelector", "(", "$", "mSelector", ")", "{", "if", "(", "$", "mSelector", "instanceof", "Selector", ")", "{", "$", "mSelector", "=", "$", "mSelector", "->", "getSelector", "(", ")", ";", "}", "foreach", "(", "$", "this", "->", "aSelectors", "as", "$", "iKey", "=>", "$", "oSelector", ")", "{", "if", "(", "$", "oSelector", "->", "getSelector", "(", ")", "===", "$", "mSelector", ")", "{", "unset", "(", "$", "this", "->", "aSelectors", "[", "$", "iKey", "]", ")", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
remove one of the selector of the block
[ "remove", "one", "of", "the", "selector", "of", "the", "block" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/php-css-parser/RuleSet/DeclarationBlock.php#L41-L52
218,290
moodle/moodle
lib/classes/oauth2/issuer.php
issuer.get_endpoint_url
public function get_endpoint_url($type) { $endpoint = endpoint::get_record([ 'issuerid' => $this->get('id'), 'name' => $type . '_endpoint' ]); if ($endpoint) { return $endpoint->get('url'); } return false; }
php
public function get_endpoint_url($type) { $endpoint = endpoint::get_record([ 'issuerid' => $this->get('id'), 'name' => $type . '_endpoint' ]); if ($endpoint) { return $endpoint->get('url'); } return false; }
[ "public", "function", "get_endpoint_url", "(", "$", "type", ")", "{", "$", "endpoint", "=", "endpoint", "::", "get_record", "(", "[", "'issuerid'", "=>", "$", "this", "->", "get", "(", "'id'", ")", ",", "'name'", "=>", "$", "type", ".", "'_endpoint'", "]", ")", ";", "if", "(", "$", "endpoint", ")", "{", "return", "$", "endpoint", "->", "get", "(", "'url'", ")", ";", "}", "return", "false", ";", "}" ]
Helper the get a named service endpoint. @param string $type @return string|false
[ "Helper", "the", "get", "a", "named", "service", "endpoint", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/issuer.php#L132-L142
218,291
moodle/moodle
lib/classes/oauth2/issuer.php
issuer.is_valid_login_domain
public function is_valid_login_domain($email) { if (empty($this->get('alloweddomains'))) { return true; } $validdomains = explode(',', $this->get('alloweddomains')); $parts = explode('@', $email, 2); $emaildomain = ''; if (count($parts) > 1) { $emaildomain = $parts[1]; } return \core\ip_utils::is_domain_in_allowed_list($emaildomain, $validdomains); }
php
public function is_valid_login_domain($email) { if (empty($this->get('alloweddomains'))) { return true; } $validdomains = explode(',', $this->get('alloweddomains')); $parts = explode('@', $email, 2); $emaildomain = ''; if (count($parts) > 1) { $emaildomain = $parts[1]; } return \core\ip_utils::is_domain_in_allowed_list($emaildomain, $validdomains); }
[ "public", "function", "is_valid_login_domain", "(", "$", "email", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "get", "(", "'alloweddomains'", ")", ")", ")", "{", "return", "true", ";", "}", "$", "validdomains", "=", "explode", "(", "','", ",", "$", "this", "->", "get", "(", "'alloweddomains'", ")", ")", ";", "$", "parts", "=", "explode", "(", "'@'", ",", "$", "email", ",", "2", ")", ";", "$", "emaildomain", "=", "''", ";", "if", "(", "count", "(", "$", "parts", ")", ">", "1", ")", "{", "$", "emaildomain", "=", "$", "parts", "[", "1", "]", ";", "}", "return", "\\", "core", "\\", "ip_utils", "::", "is_domain_in_allowed_list", "(", "$", "emaildomain", ",", "$", "validdomains", ")", ";", "}" ]
Perform matching against the list of allowed login domains for this issuer. @param string $email The email to check. @return boolean
[ "Perform", "matching", "against", "the", "list", "of", "allowed", "login", "domains", "for", "this", "issuer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/issuer.php#L150-L164
218,292
moodle/moodle
lib/classes/oauth2/issuer.php
issuer.is_system_account_connected
public function is_system_account_connected() { if (!$this->is_configured()) { return false; } $sys = system_account::get_record(['issuerid' => $this->get('id')]); if (empty($sys) || empty($sys->get('refreshtoken'))) { return false; } $scopes = api::get_system_scopes_for_issuer($this); $grantedscopes = $sys->get('grantedscopes'); $scopes = explode(' ', $scopes); foreach ($scopes as $scope) { if (!empty($scope)) { if (strpos(' ' . $grantedscopes . ' ', ' ' . $scope . ' ') === false) { // We have not been granted all the scopes that are required. return false; } } } return true; }
php
public function is_system_account_connected() { if (!$this->is_configured()) { return false; } $sys = system_account::get_record(['issuerid' => $this->get('id')]); if (empty($sys) || empty($sys->get('refreshtoken'))) { return false; } $scopes = api::get_system_scopes_for_issuer($this); $grantedscopes = $sys->get('grantedscopes'); $scopes = explode(' ', $scopes); foreach ($scopes as $scope) { if (!empty($scope)) { if (strpos(' ' . $grantedscopes . ' ', ' ' . $scope . ' ') === false) { // We have not been granted all the scopes that are required. return false; } } } return true; }
[ "public", "function", "is_system_account_connected", "(", ")", "{", "if", "(", "!", "$", "this", "->", "is_configured", "(", ")", ")", "{", "return", "false", ";", "}", "$", "sys", "=", "system_account", "::", "get_record", "(", "[", "'issuerid'", "=>", "$", "this", "->", "get", "(", "'id'", ")", "]", ")", ";", "if", "(", "empty", "(", "$", "sys", ")", "||", "empty", "(", "$", "sys", "->", "get", "(", "'refreshtoken'", ")", ")", ")", "{", "return", "false", ";", "}", "$", "scopes", "=", "api", "::", "get_system_scopes_for_issuer", "(", "$", "this", ")", ";", "$", "grantedscopes", "=", "$", "sys", "->", "get", "(", "'grantedscopes'", ")", ";", "$", "scopes", "=", "explode", "(", "' '", ",", "$", "scopes", ")", ";", "foreach", "(", "$", "scopes", "as", "$", "scope", ")", "{", "if", "(", "!", "empty", "(", "$", "scope", ")", ")", "{", "if", "(", "strpos", "(", "' '", ".", "$", "grantedscopes", ".", "' '", ",", "' '", ".", "$", "scope", ".", "' '", ")", "===", "false", ")", "{", "// We have not been granted all the scopes that are required.", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}" ]
Do we have a refresh token for a system account? @return boolean
[ "Do", "we", "have", "a", "refresh", "token", "for", "a", "system", "account?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/issuer.php#L187-L212
218,293
moodle/moodle
lib/classes/oauth2/issuer.php
issuer.validate_baseurl
protected function validate_baseurl($value) { global $CFG; include_once($CFG->dirroot . '/lib/validateurlsyntax.php'); if (!empty($value) && !validateUrlSyntax($value, 'S+')) { return new lang_string('sslonlyaccess', 'error'); } return true; }
php
protected function validate_baseurl($value) { global $CFG; include_once($CFG->dirroot . '/lib/validateurlsyntax.php'); if (!empty($value) && !validateUrlSyntax($value, 'S+')) { return new lang_string('sslonlyaccess', 'error'); } return true; }
[ "protected", "function", "validate_baseurl", "(", "$", "value", ")", "{", "global", "$", "CFG", ";", "include_once", "(", "$", "CFG", "->", "dirroot", ".", "'/lib/validateurlsyntax.php'", ")", ";", "if", "(", "!", "empty", "(", "$", "value", ")", "&&", "!", "validateUrlSyntax", "(", "$", "value", ",", "'S+'", ")", ")", "{", "return", "new", "lang_string", "(", "'sslonlyaccess'", ",", "'error'", ")", ";", "}", "return", "true", ";", "}" ]
Custom validator for end point URLs. Because we send Bearer tokens we must ensure SSL. @param string $value The value to check. @return lang_string|boolean
[ "Custom", "validator", "for", "end", "point", "URLs", ".", "Because", "we", "send", "Bearer", "tokens", "we", "must", "ensure", "SSL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/issuer.php#L221-L228
218,294
moodle/moodle
admin/tool/health/index.php
problem_000018.find_problems
public function find_problems() { global $DB; static $answer = null; if (is_null($answer)) { $categories = $DB->get_records('course_categories', array(), 'id'); // Look for missing parents. $missingparent = tool_health_category_find_missing_parents($categories); // Look for loops. $loops = tool_health_category_find_loops($categories); $answer = array($missingparent, $loops); } return $answer; }
php
public function find_problems() { global $DB; static $answer = null; if (is_null($answer)) { $categories = $DB->get_records('course_categories', array(), 'id'); // Look for missing parents. $missingparent = tool_health_category_find_missing_parents($categories); // Look for loops. $loops = tool_health_category_find_loops($categories); $answer = array($missingparent, $loops); } return $answer; }
[ "public", "function", "find_problems", "(", ")", "{", "global", "$", "DB", ";", "static", "$", "answer", "=", "null", ";", "if", "(", "is_null", "(", "$", "answer", ")", ")", "{", "$", "categories", "=", "$", "DB", "->", "get_records", "(", "'course_categories'", ",", "array", "(", ")", ",", "'id'", ")", ";", "// Look for missing parents.", "$", "missingparent", "=", "tool_health_category_find_missing_parents", "(", "$", "categories", ")", ";", "// Look for loops.", "$", "loops", "=", "tool_health_category_find_loops", "(", "$", "categories", ")", ";", "$", "answer", "=", "array", "(", "$", "missingparent", ",", "$", "loops", ")", ";", "}", "return", "$", "answer", ";", "}" ]
Search for problems in the course categories. @uses $DB @return array List of categories that contain missing parents or loops.
[ "Search", "for", "problems", "in", "the", "course", "categories", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/health/index.php#L685-L702
218,295
moodle/moodle
admin/tool/health/index.php
problem_000018.exists
public function exists() { list($missingparent, $loops) = $this->find_problems(); return !empty($missingparent) || !empty($loops); }
php
public function exists() { list($missingparent, $loops) = $this->find_problems(); return !empty($missingparent) || !empty($loops); }
[ "public", "function", "exists", "(", ")", "{", "list", "(", "$", "missingparent", ",", "$", "loops", ")", "=", "$", "this", "->", "find_problems", "(", ")", ";", "return", "!", "empty", "(", "$", "missingparent", ")", "||", "!", "empty", "(", "$", "loops", ")", ";", "}" ]
Check if the problem exists. @return boolean True if either missing parents or loops found
[ "Check", "if", "the", "problem", "exists", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/health/index.php#L709-L712
218,296
moodle/moodle
admin/tool/health/index.php
problem_000018.description
public function description() { list($missingparent, $loops) = $this->find_problems(); $description = '<p>The course categories should be arranged into tree ' . ' structures by the course_categories.parent field. Sometimes ' . ' this tree structure gets messed up.</p>'; $description .= tool_health_category_list_missing_parents($missingparent); $description .= tool_health_category_list_loops($loops); return $description; }
php
public function description() { list($missingparent, $loops) = $this->find_problems(); $description = '<p>The course categories should be arranged into tree ' . ' structures by the course_categories.parent field. Sometimes ' . ' this tree structure gets messed up.</p>'; $description .= tool_health_category_list_missing_parents($missingparent); $description .= tool_health_category_list_loops($loops); return $description; }
[ "public", "function", "description", "(", ")", "{", "list", "(", "$", "missingparent", ",", "$", "loops", ")", "=", "$", "this", "->", "find_problems", "(", ")", ";", "$", "description", "=", "'<p>The course categories should be arranged into tree '", ".", "' structures by the course_categories.parent field. Sometimes '", ".", "' this tree structure gets messed up.</p>'", ";", "$", "description", ".=", "tool_health_category_list_missing_parents", "(", "$", "missingparent", ")", ";", "$", "description", ".=", "tool_health_category_list_loops", "(", "$", "loops", ")", ";", "return", "$", "description", ";", "}" ]
Generate problem description. @return string HTML containing details of the problem.
[ "Generate", "problem", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/health/index.php#L728-L739
218,297
moodle/moodle
admin/tool/health/index.php
problem_000018.solution
public function solution() { global $CFG; list($missingparent, $loops) = $this->find_problems(); $solution = '<p>Consider executing the following SQL queries. These fix ' . 'the problem by moving some categories to the top level.</p>'; if (!empty($missingparent)) { $solution .= "<pre>UPDATE " . $CFG->prefix . "course_categories\n" . " SET parent = 0, depth = 1, path = CONCAT('/', id)\n" . " WHERE id IN (" . implode(',', array_keys($missingparent)) . ");</pre>\n"; } if (!empty($loops)) { $solution .= "<pre>UPDATE " . $CFG->prefix . "course_categories\n" . " SET parent = 0, depth = 1, path = CONCAT('/', id)\n" . " WHERE id IN (" . implode(',', array_keys($loops)) . ");</pre>\n"; } return $solution; }
php
public function solution() { global $CFG; list($missingparent, $loops) = $this->find_problems(); $solution = '<p>Consider executing the following SQL queries. These fix ' . 'the problem by moving some categories to the top level.</p>'; if (!empty($missingparent)) { $solution .= "<pre>UPDATE " . $CFG->prefix . "course_categories\n" . " SET parent = 0, depth = 1, path = CONCAT('/', id)\n" . " WHERE id IN (" . implode(',', array_keys($missingparent)) . ");</pre>\n"; } if (!empty($loops)) { $solution .= "<pre>UPDATE " . $CFG->prefix . "course_categories\n" . " SET parent = 0, depth = 1, path = CONCAT('/', id)\n" . " WHERE id IN (" . implode(',', array_keys($loops)) . ");</pre>\n"; } return $solution; }
[ "public", "function", "solution", "(", ")", "{", "global", "$", "CFG", ";", "list", "(", "$", "missingparent", ",", "$", "loops", ")", "=", "$", "this", "->", "find_problems", "(", ")", ";", "$", "solution", "=", "'<p>Consider executing the following SQL queries. These fix '", ".", "'the problem by moving some categories to the top level.</p>'", ";", "if", "(", "!", "empty", "(", "$", "missingparent", ")", ")", "{", "$", "solution", ".=", "\"<pre>UPDATE \"", ".", "$", "CFG", "->", "prefix", ".", "\"course_categories\\n\"", ".", "\" SET parent = 0, depth = 1, path = CONCAT('/', id)\\n\"", ".", "\" WHERE id IN (\"", ".", "implode", "(", "','", ",", "array_keys", "(", "$", "missingparent", ")", ")", ".", "\");</pre>\\n\"", ";", "}", "if", "(", "!", "empty", "(", "$", "loops", ")", ")", "{", "$", "solution", ".=", "\"<pre>UPDATE \"", ".", "$", "CFG", "->", "prefix", ".", "\"course_categories\\n\"", ".", "\" SET parent = 0, depth = 1, path = CONCAT('/', id)\\n\"", ".", "\" WHERE id IN (\"", ".", "implode", "(", "','", ",", "array_keys", "(", "$", "loops", ")", ")", ".", "\");</pre>\\n\"", ";", "}", "return", "$", "solution", ";", "}" ]
Generate solution text. @uses $CFG @return string HTML containing the suggested solution.
[ "Generate", "solution", "text", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/health/index.php#L747-L767
218,298
moodle/moodle
course/classes/editcategory_form.php
core_course_editcategory_form.get_description_editor_options
public function get_description_editor_options() { global $CFG; $context = $this->_customdata['context']; $itemid = $this->_customdata['itemid']; return array( 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'trusttext' => true, 'context' => $context, 'subdirs' => file_area_contains_subdirs($context, 'coursecat', 'description', $itemid), ); }
php
public function get_description_editor_options() { global $CFG; $context = $this->_customdata['context']; $itemid = $this->_customdata['itemid']; return array( 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'trusttext' => true, 'context' => $context, 'subdirs' => file_area_contains_subdirs($context, 'coursecat', 'description', $itemid), ); }
[ "public", "function", "get_description_editor_options", "(", ")", "{", "global", "$", "CFG", ";", "$", "context", "=", "$", "this", "->", "_customdata", "[", "'context'", "]", ";", "$", "itemid", "=", "$", "this", "->", "_customdata", "[", "'itemid'", "]", ";", "return", "array", "(", "'maxfiles'", "=>", "EDITOR_UNLIMITED_FILES", ",", "'maxbytes'", "=>", "$", "CFG", "->", "maxbytes", ",", "'trusttext'", "=>", "true", ",", "'context'", "=>", "$", "context", ",", "'subdirs'", "=>", "file_area_contains_subdirs", "(", "$", "context", ",", "'coursecat'", ",", "'description'", ",", "$", "itemid", ")", ",", ")", ";", "}" ]
Returns the description editor options. @return array
[ "Returns", "the", "description", "editor", "options", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/editcategory_form.php#L101-L112
218,299
moodle/moodle
course/classes/editcategory_form.php
core_course_editcategory_form.validation
public function validation($data, $files) { global $DB; $errors = parent::validation($data, $files); if (!empty($data['idnumber'])) { if ($existing = $DB->get_record('course_categories', array('idnumber' => $data['idnumber']))) { if (!$data['id'] || $existing->id != $data['id']) { $errors['idnumber'] = get_string('categoryidnumbertaken', 'error'); } } } return $errors; }
php
public function validation($data, $files) { global $DB; $errors = parent::validation($data, $files); if (!empty($data['idnumber'])) { if ($existing = $DB->get_record('course_categories', array('idnumber' => $data['idnumber']))) { if (!$data['id'] || $existing->id != $data['id']) { $errors['idnumber'] = get_string('categoryidnumbertaken', 'error'); } } } return $errors; }
[ "public", "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "global", "$", "DB", ";", "$", "errors", "=", "parent", "::", "validation", "(", "$", "data", ",", "$", "files", ")", ";", "if", "(", "!", "empty", "(", "$", "data", "[", "'idnumber'", "]", ")", ")", "{", "if", "(", "$", "existing", "=", "$", "DB", "->", "get_record", "(", "'course_categories'", ",", "array", "(", "'idnumber'", "=>", "$", "data", "[", "'idnumber'", "]", ")", ")", ")", "{", "if", "(", "!", "$", "data", "[", "'id'", "]", "||", "$", "existing", "->", "id", "!=", "$", "data", "[", "'id'", "]", ")", "{", "$", "errors", "[", "'idnumber'", "]", "=", "get_string", "(", "'categoryidnumbertaken'", ",", "'error'", ")", ";", "}", "}", "}", "return", "$", "errors", ";", "}" ]
Validates the data submit for this form. @param array $data An array of key,value data pairs. @param array $files Any files that may have been submit as well. @return array An array of errors.
[ "Validates", "the", "data", "submit", "for", "this", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/editcategory_form.php#L121-L132