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
213,400
moodle/moodle
calendar/classes/local/event/container.php
container.apply_component_provide_event_action
public static function apply_component_provide_event_action(event_interface $event) { // Callbacks will get supplied a "legacy" version // of the event class. $mapper = self::$eventmapper; $action = null; if ($event->get_course_module()) { $requestinguserid = self::get_requesting_user(); $legacyevent = $mapper->from_event_to_legacy_event($event); // We know for a fact that the the requesting user might be different from the logged in user, // but the event mapper is not aware of that. if (empty($event->user) && !empty($legacyevent->userid)) { $legacyevent->userid = $requestinguserid; } // TODO MDL-58866 Only activity modules currently support this callback. // Any other event will not be displayed on the dashboard. $action = component_callback( 'mod_' . $event->get_course_module()->get('modname'), 'core_calendar_provide_event_action', [ $legacyevent, self::$actionfactory, $requestinguserid ] ); } // If we get an action back, return an action event, otherwise // continue piping through the original event. // // If a module does not implement the callback, component_callback // returns null. return $action ? new action_event($event, $action) : $event; }
php
public static function apply_component_provide_event_action(event_interface $event) { // Callbacks will get supplied a "legacy" version // of the event class. $mapper = self::$eventmapper; $action = null; if ($event->get_course_module()) { $requestinguserid = self::get_requesting_user(); $legacyevent = $mapper->from_event_to_legacy_event($event); // We know for a fact that the the requesting user might be different from the logged in user, // but the event mapper is not aware of that. if (empty($event->user) && !empty($legacyevent->userid)) { $legacyevent->userid = $requestinguserid; } // TODO MDL-58866 Only activity modules currently support this callback. // Any other event will not be displayed on the dashboard. $action = component_callback( 'mod_' . $event->get_course_module()->get('modname'), 'core_calendar_provide_event_action', [ $legacyevent, self::$actionfactory, $requestinguserid ] ); } // If we get an action back, return an action event, otherwise // continue piping through the original event. // // If a module does not implement the callback, component_callback // returns null. return $action ? new action_event($event, $action) : $event; }
[ "public", "static", "function", "apply_component_provide_event_action", "(", "event_interface", "$", "event", ")", "{", "// Callbacks will get supplied a \"legacy\" version", "// of the event class.", "$", "mapper", "=", "self", "::", "$", "eventmapper", ";", "$", "action", "=", "null", ";", "if", "(", "$", "event", "->", "get_course_module", "(", ")", ")", "{", "$", "requestinguserid", "=", "self", "::", "get_requesting_user", "(", ")", ";", "$", "legacyevent", "=", "$", "mapper", "->", "from_event_to_legacy_event", "(", "$", "event", ")", ";", "// We know for a fact that the the requesting user might be different from the logged in user,", "// but the event mapper is not aware of that.", "if", "(", "empty", "(", "$", "event", "->", "user", ")", "&&", "!", "empty", "(", "$", "legacyevent", "->", "userid", ")", ")", "{", "$", "legacyevent", "->", "userid", "=", "$", "requestinguserid", ";", "}", "// TODO MDL-58866 Only activity modules currently support this callback.", "// Any other event will not be displayed on the dashboard.", "$", "action", "=", "component_callback", "(", "'mod_'", ".", "$", "event", "->", "get_course_module", "(", ")", "->", "get", "(", "'modname'", ")", ",", "'core_calendar_provide_event_action'", ",", "[", "$", "legacyevent", ",", "self", "::", "$", "actionfactory", ",", "$", "requestinguserid", "]", ")", ";", "}", "// If we get an action back, return an action event, otherwise", "// continue piping through the original event.", "//", "// If a module does not implement the callback, component_callback", "// returns null.", "return", "$", "action", "?", "new", "action_event", "(", "$", "event", ",", "$", "action", ")", ":", "$", "event", ";", "}" ]
Calls callback 'core_calendar_provide_event_action' from the component responsible for the event If no callback is present or callback returns null, there is no action on the event and it will not be displayed on the dashboard. @param event_interface $event @return action_event|event_interface
[ "Calls", "callback", "core_calendar_provide_event_action", "from", "the", "component", "responsible", "for", "the", "event" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/container.php#L277-L310
213,401
moodle/moodle
calendar/classes/local/event/container.php
container.apply_component_is_event_visible
public static function apply_component_is_event_visible(event_interface $event) { $mapper = self::$eventmapper; $eventvisible = null; if ($event->get_course_module()) { $requestinguserid = self::get_requesting_user(); $legacyevent = $mapper->from_event_to_legacy_event($event); // We know for a fact that the the requesting user might be different from the logged in user, // but the event mapper is not aware of that. if (empty($event->user) && !empty($legacyevent->userid)) { $legacyevent->userid = $requestinguserid; } // TODO MDL-58866 Only activity modules currently support this callback. $eventvisible = component_callback( 'mod_' . $event->get_course_module()->get('modname'), 'core_calendar_is_event_visible', [ $legacyevent, $requestinguserid ] ); } // Do not display the event if there is nothing to action. if ($event instanceof action_event_interface && $event->get_action()->get_item_count() === 0) { return false; } // Module does not implement the callback, event should be visible. if (is_null($eventvisible)) { return true; } return $eventvisible ? true : false; }
php
public static function apply_component_is_event_visible(event_interface $event) { $mapper = self::$eventmapper; $eventvisible = null; if ($event->get_course_module()) { $requestinguserid = self::get_requesting_user(); $legacyevent = $mapper->from_event_to_legacy_event($event); // We know for a fact that the the requesting user might be different from the logged in user, // but the event mapper is not aware of that. if (empty($event->user) && !empty($legacyevent->userid)) { $legacyevent->userid = $requestinguserid; } // TODO MDL-58866 Only activity modules currently support this callback. $eventvisible = component_callback( 'mod_' . $event->get_course_module()->get('modname'), 'core_calendar_is_event_visible', [ $legacyevent, $requestinguserid ] ); } // Do not display the event if there is nothing to action. if ($event instanceof action_event_interface && $event->get_action()->get_item_count() === 0) { return false; } // Module does not implement the callback, event should be visible. if (is_null($eventvisible)) { return true; } return $eventvisible ? true : false; }
[ "public", "static", "function", "apply_component_is_event_visible", "(", "event_interface", "$", "event", ")", "{", "$", "mapper", "=", "self", "::", "$", "eventmapper", ";", "$", "eventvisible", "=", "null", ";", "if", "(", "$", "event", "->", "get_course_module", "(", ")", ")", "{", "$", "requestinguserid", "=", "self", "::", "get_requesting_user", "(", ")", ";", "$", "legacyevent", "=", "$", "mapper", "->", "from_event_to_legacy_event", "(", "$", "event", ")", ";", "// We know for a fact that the the requesting user might be different from the logged in user,", "// but the event mapper is not aware of that.", "if", "(", "empty", "(", "$", "event", "->", "user", ")", "&&", "!", "empty", "(", "$", "legacyevent", "->", "userid", ")", ")", "{", "$", "legacyevent", "->", "userid", "=", "$", "requestinguserid", ";", "}", "// TODO MDL-58866 Only activity modules currently support this callback.", "$", "eventvisible", "=", "component_callback", "(", "'mod_'", ".", "$", "event", "->", "get_course_module", "(", ")", "->", "get", "(", "'modname'", ")", ",", "'core_calendar_is_event_visible'", ",", "[", "$", "legacyevent", ",", "$", "requestinguserid", "]", ")", ";", "}", "// Do not display the event if there is nothing to action.", "if", "(", "$", "event", "instanceof", "action_event_interface", "&&", "$", "event", "->", "get_action", "(", ")", "->", "get_item_count", "(", ")", "===", "0", ")", "{", "return", "false", ";", "}", "// Module does not implement the callback, event should be visible.", "if", "(", "is_null", "(", "$", "eventvisible", ")", ")", "{", "return", "true", ";", "}", "return", "$", "eventvisible", "?", "true", ":", "false", ";", "}" ]
Calls callback 'core_calendar_is_event_visible' from the component responsible for the event The visibility callback is optional, if not present it is assumed as visible. If it is an actionable event but the get_item_count() returns 0 the visibility is set to false. @param event_interface $event @return bool
[ "Calls", "callback", "core_calendar_is_event_visible", "from", "the", "component", "responsible", "for", "the", "event" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/container.php#L322-L356
213,402
moodle/moodle
lib/lessphp/Visitor/toCSS.php
Less_Visitor_toCSS.visitRulesetRoot
private function visitRulesetRoot( $rulesetNode ){ $rulesetNode->accept( $this ); if( $rulesetNode->firstRoot || $rulesetNode->rules ){ return $rulesetNode; } return array(); }
php
private function visitRulesetRoot( $rulesetNode ){ $rulesetNode->accept( $this ); if( $rulesetNode->firstRoot || $rulesetNode->rules ){ return $rulesetNode; } return array(); }
[ "private", "function", "visitRulesetRoot", "(", "$", "rulesetNode", ")", "{", "$", "rulesetNode", "->", "accept", "(", "$", "this", ")", ";", "if", "(", "$", "rulesetNode", "->", "firstRoot", "||", "$", "rulesetNode", "->", "rules", ")", "{", "return", "$", "rulesetNode", ";", "}", "return", "array", "(", ")", ";", "}" ]
Helper function for visitiRuleset return array|Less_Tree_Ruleset
[ "Helper", "function", "for", "visitiRuleset" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Visitor/toCSS.php#L162-L168
213,403
moodle/moodle
message/classes/output/preferences/notification_list_processor.php
notification_list_processor.is_preference_enabled
private function is_preference_enabled($name) { $processor = $this->processor; $preferences = $this->preferences; $defaultpreferences = get_message_output_default_preferences(); $checked = false; // See if user has touched this preference. if (isset($preferences->{$name})) { // User has some preferences for this state in the database. $checked = isset($preferences->{$name}[$processor->name]); } else { // User has not set this preference yet, using site default preferences set by admin. $defaultpreference = 'message_provider_'.$name; if (isset($defaultpreferences->{$defaultpreference})) { $checked = (int)in_array($processor->name, explode(',', $defaultpreferences->{$defaultpreference})); } } return $checked; }
php
private function is_preference_enabled($name) { $processor = $this->processor; $preferences = $this->preferences; $defaultpreferences = get_message_output_default_preferences(); $checked = false; // See if user has touched this preference. if (isset($preferences->{$name})) { // User has some preferences for this state in the database. $checked = isset($preferences->{$name}[$processor->name]); } else { // User has not set this preference yet, using site default preferences set by admin. $defaultpreference = 'message_provider_'.$name; if (isset($defaultpreferences->{$defaultpreference})) { $checked = (int)in_array($processor->name, explode(',', $defaultpreferences->{$defaultpreference})); } } return $checked; }
[ "private", "function", "is_preference_enabled", "(", "$", "name", ")", "{", "$", "processor", "=", "$", "this", "->", "processor", ";", "$", "preferences", "=", "$", "this", "->", "preferences", ";", "$", "defaultpreferences", "=", "get_message_output_default_preferences", "(", ")", ";", "$", "checked", "=", "false", ";", "// See if user has touched this preference.", "if", "(", "isset", "(", "$", "preferences", "->", "{", "$", "name", "}", ")", ")", "{", "// User has some preferences for this state in the database.", "$", "checked", "=", "isset", "(", "$", "preferences", "->", "{", "$", "name", "}", "[", "$", "processor", "->", "name", "]", ")", ";", "}", "else", "{", "// User has not set this preference yet, using site default preferences set by admin.", "$", "defaultpreference", "=", "'message_provider_'", ".", "$", "name", ";", "if", "(", "isset", "(", "$", "defaultpreferences", "->", "{", "$", "defaultpreference", "}", ")", ")", "{", "$", "checked", "=", "(", "int", ")", "in_array", "(", "$", "processor", "->", "name", ",", "explode", "(", "','", ",", "$", "defaultpreferences", "->", "{", "$", "defaultpreference", "}", ")", ")", ";", "}", "}", "return", "$", "checked", ";", "}" ]
Check if the given preference is enabled or not. @param string $name preference name @return bool
[ "Check", "if", "the", "given", "preference", "is", "enabled", "or", "not", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/output/preferences/notification_list_processor.php#L86-L105
213,404
moodle/moodle
tag/classes/renderer.php
core_tag_renderer.tag_search_page
public function tag_search_page($query = '', $tagcollid = 0) { $rv = $this->output->heading(get_string('searchtags', 'tag'), 2); $searchbox = $this->search_form($query, $tagcollid); $rv .= html_writer::div($searchbox, '', array('id' => 'tag-search-box')); $tagcloud = core_tag_collection::get_tag_cloud($tagcollid, false, 150, 'name', $query); $searchresults = ''; if ($tagcloud->get_count()) { $searchresults = $this->output->render_from_template('core_tag/tagcloud', $tagcloud->export_for_template($this->output)); $rv .= html_writer::div($searchresults, '', array('id' => 'tag-search-results')); } else if (strval($query) !== '') { $rv .= '<div class="tag-search-empty">' . get_string('notagsfound', 'tag', s($query)) . '</div>'; } return $rv; }
php
public function tag_search_page($query = '', $tagcollid = 0) { $rv = $this->output->heading(get_string('searchtags', 'tag'), 2); $searchbox = $this->search_form($query, $tagcollid); $rv .= html_writer::div($searchbox, '', array('id' => 'tag-search-box')); $tagcloud = core_tag_collection::get_tag_cloud($tagcollid, false, 150, 'name', $query); $searchresults = ''; if ($tagcloud->get_count()) { $searchresults = $this->output->render_from_template('core_tag/tagcloud', $tagcloud->export_for_template($this->output)); $rv .= html_writer::div($searchresults, '', array('id' => 'tag-search-results')); } else if (strval($query) !== '') { $rv .= '<div class="tag-search-empty">' . get_string('notagsfound', 'tag', s($query)) . '</div>'; } return $rv; }
[ "public", "function", "tag_search_page", "(", "$", "query", "=", "''", ",", "$", "tagcollid", "=", "0", ")", "{", "$", "rv", "=", "$", "this", "->", "output", "->", "heading", "(", "get_string", "(", "'searchtags'", ",", "'tag'", ")", ",", "2", ")", ";", "$", "searchbox", "=", "$", "this", "->", "search_form", "(", "$", "query", ",", "$", "tagcollid", ")", ";", "$", "rv", ".=", "html_writer", "::", "div", "(", "$", "searchbox", ",", "''", ",", "array", "(", "'id'", "=>", "'tag-search-box'", ")", ")", ";", "$", "tagcloud", "=", "core_tag_collection", "::", "get_tag_cloud", "(", "$", "tagcollid", ",", "false", ",", "150", ",", "'name'", ",", "$", "query", ")", ";", "$", "searchresults", "=", "''", ";", "if", "(", "$", "tagcloud", "->", "get_count", "(", ")", ")", "{", "$", "searchresults", "=", "$", "this", "->", "output", "->", "render_from_template", "(", "'core_tag/tagcloud'", ",", "$", "tagcloud", "->", "export_for_template", "(", "$", "this", "->", "output", ")", ")", ";", "$", "rv", ".=", "html_writer", "::", "div", "(", "$", "searchresults", ",", "''", ",", "array", "(", "'id'", "=>", "'tag-search-results'", ")", ")", ";", "}", "else", "if", "(", "strval", "(", "$", "query", ")", "!==", "''", ")", "{", "$", "rv", ".=", "'<div class=\"tag-search-empty\">'", ".", "get_string", "(", "'notagsfound'", ",", "'tag'", ",", "s", "(", "$", "query", ")", ")", ".", "'</div>'", ";", "}", "return", "$", "rv", ";", "}" ]
Renders the tag search page @param string $query @param int $tagcollid @return string
[ "Renders", "the", "tag", "search", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/renderer.php#L43-L60
213,405
moodle/moodle
tag/classes/renderer.php
core_tag_renderer.tag_index_page
public function tag_index_page($tag, $entities, $tagareaid, $exclusivemode, $fromctx, $ctx, $rec, $page) { global $CFG, $OUTPUT; $this->page->requires->js_call_amd('core/tag', 'initTagindexPage'); $tagname = $tag->get_display_name(); $systemcontext = context_system::instance(); if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) { $tagname = '<span class="flagged-tag">' . $tagname . '</span>'; } $rv = ''; $rv .= $this->output->heading($tagname, 2); $rv .= $this->tag_links($tag); if ($desciption = $tag->get_formatted_description()) { $rv .= $this->output->box($desciption, 'generalbox tag-description'); } $relatedtagslimit = 10; $relatedtags = $tag->get_related_tags(); $taglist = new \core_tag\output\taglist($relatedtags, get_string('relatedtags', 'tag'), 'tag-relatedtags', $relatedtagslimit); $rv .= $OUTPUT->render_from_template('core_tag/taglist', $taglist->export_for_template($OUTPUT)); // Display quick menu of the item types (if more than one item type found). $entitylinks = array(); foreach ($entities as $entity) { if (!empty($entity->hascontent)) { $entitylinks[] = '<li><a href="#'.$entity->anchor.'">' . core_tag_area::display_name($entity->component, $entity->itemtype) . '</a></li>'; } } if (count($entitylinks) > 1) { $rv .= '<div class="tag-index-toc"><ul class="inline-list">' . join('', $entitylinks) . '</ul></div>'; } else if (!$entitylinks) { $rv .= '<div class="tag-noresults">' . get_string('noresultsfor', 'tag', $tagname) . '</div>'; } // Display entities tagged with the tag. $content = ''; foreach ($entities as $entity) { if (!empty($entity->hascontent)) { $content .= $this->output->render_from_template('core_tag/index', $entity->export_for_template($this->output)); } } if ($exclusivemode) { $rv .= $content; } else if ($content) { $rv .= html_writer::div($content, 'tag-index-items'); } // Display back link if we are browsing one tag area. if ($tagareaid) { $url = $tag->get_view_url(0, $fromctx, $ctx, $rec); $rv .= '<div class="tag-backtoallitems">' . html_writer::link($url, get_string('backtoallitems', 'tag', $tag->get_display_name())) . '</div>'; } return $rv; }
php
public function tag_index_page($tag, $entities, $tagareaid, $exclusivemode, $fromctx, $ctx, $rec, $page) { global $CFG, $OUTPUT; $this->page->requires->js_call_amd('core/tag', 'initTagindexPage'); $tagname = $tag->get_display_name(); $systemcontext = context_system::instance(); if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) { $tagname = '<span class="flagged-tag">' . $tagname . '</span>'; } $rv = ''; $rv .= $this->output->heading($tagname, 2); $rv .= $this->tag_links($tag); if ($desciption = $tag->get_formatted_description()) { $rv .= $this->output->box($desciption, 'generalbox tag-description'); } $relatedtagslimit = 10; $relatedtags = $tag->get_related_tags(); $taglist = new \core_tag\output\taglist($relatedtags, get_string('relatedtags', 'tag'), 'tag-relatedtags', $relatedtagslimit); $rv .= $OUTPUT->render_from_template('core_tag/taglist', $taglist->export_for_template($OUTPUT)); // Display quick menu of the item types (if more than one item type found). $entitylinks = array(); foreach ($entities as $entity) { if (!empty($entity->hascontent)) { $entitylinks[] = '<li><a href="#'.$entity->anchor.'">' . core_tag_area::display_name($entity->component, $entity->itemtype) . '</a></li>'; } } if (count($entitylinks) > 1) { $rv .= '<div class="tag-index-toc"><ul class="inline-list">' . join('', $entitylinks) . '</ul></div>'; } else if (!$entitylinks) { $rv .= '<div class="tag-noresults">' . get_string('noresultsfor', 'tag', $tagname) . '</div>'; } // Display entities tagged with the tag. $content = ''; foreach ($entities as $entity) { if (!empty($entity->hascontent)) { $content .= $this->output->render_from_template('core_tag/index', $entity->export_for_template($this->output)); } } if ($exclusivemode) { $rv .= $content; } else if ($content) { $rv .= html_writer::div($content, 'tag-index-items'); } // Display back link if we are browsing one tag area. if ($tagareaid) { $url = $tag->get_view_url(0, $fromctx, $ctx, $rec); $rv .= '<div class="tag-backtoallitems">' . html_writer::link($url, get_string('backtoallitems', 'tag', $tag->get_display_name())) . '</div>'; } return $rv; }
[ "public", "function", "tag_index_page", "(", "$", "tag", ",", "$", "entities", ",", "$", "tagareaid", ",", "$", "exclusivemode", ",", "$", "fromctx", ",", "$", "ctx", ",", "$", "rec", ",", "$", "page", ")", "{", "global", "$", "CFG", ",", "$", "OUTPUT", ";", "$", "this", "->", "page", "->", "requires", "->", "js_call_amd", "(", "'core/tag'", ",", "'initTagindexPage'", ")", ";", "$", "tagname", "=", "$", "tag", "->", "get_display_name", "(", ")", ";", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "if", "(", "$", "tag", "->", "flag", ">", "0", "&&", "has_capability", "(", "'moodle/tag:manage'", ",", "$", "systemcontext", ")", ")", "{", "$", "tagname", "=", "'<span class=\"flagged-tag\">'", ".", "$", "tagname", ".", "'</span>'", ";", "}", "$", "rv", "=", "''", ";", "$", "rv", ".=", "$", "this", "->", "output", "->", "heading", "(", "$", "tagname", ",", "2", ")", ";", "$", "rv", ".=", "$", "this", "->", "tag_links", "(", "$", "tag", ")", ";", "if", "(", "$", "desciption", "=", "$", "tag", "->", "get_formatted_description", "(", ")", ")", "{", "$", "rv", ".=", "$", "this", "->", "output", "->", "box", "(", "$", "desciption", ",", "'generalbox tag-description'", ")", ";", "}", "$", "relatedtagslimit", "=", "10", ";", "$", "relatedtags", "=", "$", "tag", "->", "get_related_tags", "(", ")", ";", "$", "taglist", "=", "new", "\\", "core_tag", "\\", "output", "\\", "taglist", "(", "$", "relatedtags", ",", "get_string", "(", "'relatedtags'", ",", "'tag'", ")", ",", "'tag-relatedtags'", ",", "$", "relatedtagslimit", ")", ";", "$", "rv", ".=", "$", "OUTPUT", "->", "render_from_template", "(", "'core_tag/taglist'", ",", "$", "taglist", "->", "export_for_template", "(", "$", "OUTPUT", ")", ")", ";", "// Display quick menu of the item types (if more than one item type found).", "$", "entitylinks", "=", "array", "(", ")", ";", "foreach", "(", "$", "entities", "as", "$", "entity", ")", "{", "if", "(", "!", "empty", "(", "$", "entity", "->", "hascontent", ")", ")", "{", "$", "entitylinks", "[", "]", "=", "'<li><a href=\"#'", ".", "$", "entity", "->", "anchor", ".", "'\">'", ".", "core_tag_area", "::", "display_name", "(", "$", "entity", "->", "component", ",", "$", "entity", "->", "itemtype", ")", ".", "'</a></li>'", ";", "}", "}", "if", "(", "count", "(", "$", "entitylinks", ")", ">", "1", ")", "{", "$", "rv", ".=", "'<div class=\"tag-index-toc\"><ul class=\"inline-list\">'", ".", "join", "(", "''", ",", "$", "entitylinks", ")", ".", "'</ul></div>'", ";", "}", "else", "if", "(", "!", "$", "entitylinks", ")", "{", "$", "rv", ".=", "'<div class=\"tag-noresults\">'", ".", "get_string", "(", "'noresultsfor'", ",", "'tag'", ",", "$", "tagname", ")", ".", "'</div>'", ";", "}", "// Display entities tagged with the tag.", "$", "content", "=", "''", ";", "foreach", "(", "$", "entities", "as", "$", "entity", ")", "{", "if", "(", "!", "empty", "(", "$", "entity", "->", "hascontent", ")", ")", "{", "$", "content", ".=", "$", "this", "->", "output", "->", "render_from_template", "(", "'core_tag/index'", ",", "$", "entity", "->", "export_for_template", "(", "$", "this", "->", "output", ")", ")", ";", "}", "}", "if", "(", "$", "exclusivemode", ")", "{", "$", "rv", ".=", "$", "content", ";", "}", "else", "if", "(", "$", "content", ")", "{", "$", "rv", ".=", "html_writer", "::", "div", "(", "$", "content", ",", "'tag-index-items'", ")", ";", "}", "// Display back link if we are browsing one tag area.", "if", "(", "$", "tagareaid", ")", "{", "$", "url", "=", "$", "tag", "->", "get_view_url", "(", "0", ",", "$", "fromctx", ",", "$", "ctx", ",", "$", "rec", ")", ";", "$", "rv", ".=", "'<div class=\"tag-backtoallitems\">'", ".", "html_writer", "::", "link", "(", "$", "url", ",", "get_string", "(", "'backtoallitems'", ",", "'tag'", ",", "$", "tag", "->", "get_display_name", "(", ")", ")", ")", ".", "'</div>'", ";", "}", "return", "$", "rv", ";", "}" ]
Renders the tag index page @param core_tag_tag $tag @param \core_tag\output\tagindex[] $entities @param int $tagareaid @param bool $exclusivemode if set to true it means that no other entities tagged with this tag are displayed on the page and the per-page limit may be bigger @param int $fromctx context id where the link was displayed, may be used by callbacks to display items in the same context first @param int $ctx context id where to search for records @param bool $rec search in subcontexts as well @param int $page 0-based number of page being displayed @return string
[ "Renders", "the", "tag", "index", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/renderer.php#L77-L141
213,406
moodle/moodle
tag/classes/renderer.php
core_tag_renderer.tag_links
protected function tag_links($tag) { if ($links = $tag->get_links()) { $content = '<ul class="inline-list"><li>' . implode('</li> <li>', $links) . '</li></ul>'; return html_writer::div($content, 'tag-management-box'); } return ''; }
php
protected function tag_links($tag) { if ($links = $tag->get_links()) { $content = '<ul class="inline-list"><li>' . implode('</li> <li>', $links) . '</li></ul>'; return html_writer::div($content, 'tag-management-box'); } return ''; }
[ "protected", "function", "tag_links", "(", "$", "tag", ")", "{", "if", "(", "$", "links", "=", "$", "tag", "->", "get_links", "(", ")", ")", "{", "$", "content", "=", "'<ul class=\"inline-list\"><li>'", ".", "implode", "(", "'</li> <li>'", ",", "$", "links", ")", ".", "'</li></ul>'", ";", "return", "html_writer", "::", "div", "(", "$", "content", ",", "'tag-management-box'", ")", ";", "}", "return", "''", ";", "}" ]
Prints a box that contains the management links of a tag @param core_tag_tag $tag @return string
[ "Prints", "a", "box", "that", "contains", "the", "management", "links", "of", "a", "tag" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/renderer.php#L149-L155
213,407
moodle/moodle
tag/classes/renderer.php
core_tag_renderer.search_form
protected function search_form($query = '', $tagcollid = 0) { $searchurl = new moodle_url('/tag/search.php'); $output = '<form action="' . $searchurl . '">'; $output .= '<label class="accesshide" for="searchform_query">' . get_string('searchtags', 'tag') . '</label>'; $output .= '<input id="searchform_query" name="query" type="text" size="40" value="' . s($query) . '" />'; $tagcolls = core_tag_collection::get_collections_menu(false, true, get_string('inalltagcoll', 'tag')); if (count($tagcolls) > 1) { $output .= '<label class="accesshide" for="searchform_tc">' . get_string('selectcoll', 'tag') . '</label>'; $output .= html_writer::select($tagcolls, 'tc', $tagcollid, null, array('id' => 'searchform_tc')); } $output .= '<input name="go" type="submit" size="40" value="' . s(get_string('search', 'tag')) . '" />'; $output .= '</form>'; return $output; }
php
protected function search_form($query = '', $tagcollid = 0) { $searchurl = new moodle_url('/tag/search.php'); $output = '<form action="' . $searchurl . '">'; $output .= '<label class="accesshide" for="searchform_query">' . get_string('searchtags', 'tag') . '</label>'; $output .= '<input id="searchform_query" name="query" type="text" size="40" value="' . s($query) . '" />'; $tagcolls = core_tag_collection::get_collections_menu(false, true, get_string('inalltagcoll', 'tag')); if (count($tagcolls) > 1) { $output .= '<label class="accesshide" for="searchform_tc">' . get_string('selectcoll', 'tag') . '</label>'; $output .= html_writer::select($tagcolls, 'tc', $tagcollid, null, array('id' => 'searchform_tc')); } $output .= '<input name="go" type="submit" size="40" value="' . s(get_string('search', 'tag')) . '" />'; $output .= '</form>'; return $output; }
[ "protected", "function", "search_form", "(", "$", "query", "=", "''", ",", "$", "tagcollid", "=", "0", ")", "{", "$", "searchurl", "=", "new", "moodle_url", "(", "'/tag/search.php'", ")", ";", "$", "output", "=", "'<form action=\"'", ".", "$", "searchurl", ".", "'\">'", ";", "$", "output", ".=", "'<label class=\"accesshide\" for=\"searchform_query\">'", ".", "get_string", "(", "'searchtags'", ",", "'tag'", ")", ".", "'</label>'", ";", "$", "output", ".=", "'<input id=\"searchform_query\" name=\"query\" type=\"text\" size=\"40\" value=\"'", ".", "s", "(", "$", "query", ")", ".", "'\" />'", ";", "$", "tagcolls", "=", "core_tag_collection", "::", "get_collections_menu", "(", "false", ",", "true", ",", "get_string", "(", "'inalltagcoll'", ",", "'tag'", ")", ")", ";", "if", "(", "count", "(", "$", "tagcolls", ")", ">", "1", ")", "{", "$", "output", ".=", "'<label class=\"accesshide\" for=\"searchform_tc\">'", ".", "get_string", "(", "'selectcoll'", ",", "'tag'", ")", ".", "'</label>'", ";", "$", "output", ".=", "html_writer", "::", "select", "(", "$", "tagcolls", ",", "'tc'", ",", "$", "tagcollid", ",", "null", ",", "array", "(", "'id'", "=>", "'searchform_tc'", ")", ")", ";", "}", "$", "output", ".=", "'<input name=\"go\" type=\"submit\" size=\"40\" value=\"'", ".", "s", "(", "get_string", "(", "'search'", ",", "'tag'", ")", ")", ".", "'\" />'", ";", "$", "output", ".=", "'</form>'", ";", "return", "$", "output", ";", "}" ]
Prints the tag search box @param string $query last search string @param int $tagcollid last selected tag collection id @return string
[ "Prints", "the", "tag", "search", "box" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/renderer.php#L164-L178
213,408
moodle/moodle
lib/mlbackend/php/phpml/src/Phpml/Helper/Optimizer/Optimizer.php
Optimizer.setInitialTheta
public function setInitialTheta(array $theta) { if (count($theta) != $this->dimensions) { throw new \Exception("Number of values in the weights array should be $this->dimensions"); } $this->theta = $theta; return $this; }
php
public function setInitialTheta(array $theta) { if (count($theta) != $this->dimensions) { throw new \Exception("Number of values in the weights array should be $this->dimensions"); } $this->theta = $theta; return $this; }
[ "public", "function", "setInitialTheta", "(", "array", "$", "theta", ")", "{", "if", "(", "count", "(", "$", "theta", ")", "!=", "$", "this", "->", "dimensions", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Number of values in the weights array should be $this->dimensions\"", ")", ";", "}", "$", "this", "->", "theta", "=", "$", "theta", ";", "return", "$", "this", ";", "}" ]
Sets the weights manually @param array $theta @return $this @throws \Exception
[ "Sets", "the", "weights", "manually" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Helper/Optimizer/Optimizer.php#L48-L57
213,409
moodle/moodle
lib/classes/oauth2/client.php
client.get_additional_login_parameters
public function get_additional_login_parameters() { $params = ''; if ($this->system) { if (!empty($this->issuer->get('loginparamsoffline'))) { $params = $this->issuer->get('loginparamsoffline'); } } else { if (!empty($this->issuer->get('loginparams'))) { $params = $this->issuer->get('loginparams'); } } if (empty($params)) { return []; } $result = []; parse_str($params, $result); return $result; }
php
public function get_additional_login_parameters() { $params = ''; if ($this->system) { if (!empty($this->issuer->get('loginparamsoffline'))) { $params = $this->issuer->get('loginparamsoffline'); } } else { if (!empty($this->issuer->get('loginparams'))) { $params = $this->issuer->get('loginparams'); } } if (empty($params)) { return []; } $result = []; parse_str($params, $result); return $result; }
[ "public", "function", "get_additional_login_parameters", "(", ")", "{", "$", "params", "=", "''", ";", "if", "(", "$", "this", "->", "system", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "issuer", "->", "get", "(", "'loginparamsoffline'", ")", ")", ")", "{", "$", "params", "=", "$", "this", "->", "issuer", "->", "get", "(", "'loginparamsoffline'", ")", ";", "}", "}", "else", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "issuer", "->", "get", "(", "'loginparams'", ")", ")", ")", "{", "$", "params", "=", "$", "this", "->", "issuer", "->", "get", "(", "'loginparams'", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "params", ")", ")", "{", "return", "[", "]", ";", "}", "$", "result", "=", "[", "]", ";", "parse_str", "(", "$", "params", ",", "$", "result", ")", ";", "return", "$", "result", ";", "}" ]
Override to append additional params to a authentication request. @return array (name value pairs).
[ "Override", "to", "append", "additional", "params", "to", "a", "authentication", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/client.php#L99-L116
213,410
moodle/moodle
lib/classes/oauth2/client.php
client.store_token
protected function store_token($token) { if (!$this->system) { parent::store_token($token); return; } $this->accesstoken = $token; // Create or update a DB record with the new token. $persistedtoken = access_token::get_record(['issuerid' => $this->issuer->get('id')]); if ($token !== null) { if (!$persistedtoken) { $persistedtoken = new access_token(); $persistedtoken->set('issuerid', $this->issuer->get('id')); } // Update values from $token. Don't use from_record because that would skip validation. $persistedtoken->set('token', $token->token); if (isset($token->expires)) { $persistedtoken->set('expires', $token->expires); } else { // Assume an arbitrary time span of 1 week for access tokens without expiration. // The "refresh_system_tokens_task" is run hourly (by default), so the token probably won't last that long. $persistedtoken->set('expires', time() + WEEKSECS); } $persistedtoken->set('scope', $token->scope); $persistedtoken->save(); } else { if ($persistedtoken) { $persistedtoken->delete(); } } }
php
protected function store_token($token) { if (!$this->system) { parent::store_token($token); return; } $this->accesstoken = $token; // Create or update a DB record with the new token. $persistedtoken = access_token::get_record(['issuerid' => $this->issuer->get('id')]); if ($token !== null) { if (!$persistedtoken) { $persistedtoken = new access_token(); $persistedtoken->set('issuerid', $this->issuer->get('id')); } // Update values from $token. Don't use from_record because that would skip validation. $persistedtoken->set('token', $token->token); if (isset($token->expires)) { $persistedtoken->set('expires', $token->expires); } else { // Assume an arbitrary time span of 1 week for access tokens without expiration. // The "refresh_system_tokens_task" is run hourly (by default), so the token probably won't last that long. $persistedtoken->set('expires', time() + WEEKSECS); } $persistedtoken->set('scope', $token->scope); $persistedtoken->save(); } else { if ($persistedtoken) { $persistedtoken->delete(); } } }
[ "protected", "function", "store_token", "(", "$", "token", ")", "{", "if", "(", "!", "$", "this", "->", "system", ")", "{", "parent", "::", "store_token", "(", "$", "token", ")", ";", "return", ";", "}", "$", "this", "->", "accesstoken", "=", "$", "token", ";", "// Create or update a DB record with the new token.", "$", "persistedtoken", "=", "access_token", "::", "get_record", "(", "[", "'issuerid'", "=>", "$", "this", "->", "issuer", "->", "get", "(", "'id'", ")", "]", ")", ";", "if", "(", "$", "token", "!==", "null", ")", "{", "if", "(", "!", "$", "persistedtoken", ")", "{", "$", "persistedtoken", "=", "new", "access_token", "(", ")", ";", "$", "persistedtoken", "->", "set", "(", "'issuerid'", ",", "$", "this", "->", "issuer", "->", "get", "(", "'id'", ")", ")", ";", "}", "// Update values from $token. Don't use from_record because that would skip validation.", "$", "persistedtoken", "->", "set", "(", "'token'", ",", "$", "token", "->", "token", ")", ";", "if", "(", "isset", "(", "$", "token", "->", "expires", ")", ")", "{", "$", "persistedtoken", "->", "set", "(", "'expires'", ",", "$", "token", "->", "expires", ")", ";", "}", "else", "{", "// Assume an arbitrary time span of 1 week for access tokens without expiration.", "// The \"refresh_system_tokens_task\" is run hourly (by default), so the token probably won't last that long.", "$", "persistedtoken", "->", "set", "(", "'expires'", ",", "time", "(", ")", "+", "WEEKSECS", ")", ";", "}", "$", "persistedtoken", "->", "set", "(", "'scope'", ",", "$", "token", "->", "scope", ")", ";", "$", "persistedtoken", "->", "save", "(", ")", ";", "}", "else", "{", "if", "(", "$", "persistedtoken", ")", "{", "$", "persistedtoken", "->", "delete", "(", ")", ";", "}", "}", "}" ]
Store a token between requests. Uses session named by get_tokenname for user account tokens and a database record for system account tokens. @param stdClass|null $token token object to store or null to clear
[ "Store", "a", "token", "between", "requests", ".", "Uses", "session", "named", "by", "get_tokenname", "for", "user", "account", "tokens", "and", "a", "database", "record", "for", "system", "account", "tokens", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/client.php#L161-L192
213,411
moodle/moodle
lib/classes/oauth2/client.php
client.get_userinfo_mapping
protected function get_userinfo_mapping() { $fields = user_field_mapping::get_records(['issuerid' => $this->issuer->get('id')]); $map = []; foreach ($fields as $field) { $map[$field->get('externalfield')] = $field->get('internalfield'); } return $map; }
php
protected function get_userinfo_mapping() { $fields = user_field_mapping::get_records(['issuerid' => $this->issuer->get('id')]); $map = []; foreach ($fields as $field) { $map[$field->get('externalfield')] = $field->get('internalfield'); } return $map; }
[ "protected", "function", "get_userinfo_mapping", "(", ")", "{", "$", "fields", "=", "user_field_mapping", "::", "get_records", "(", "[", "'issuerid'", "=>", "$", "this", "->", "issuer", "->", "get", "(", "'id'", ")", "]", ")", ";", "$", "map", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "$", "map", "[", "$", "field", "->", "get", "(", "'externalfield'", ")", "]", "=", "$", "field", "->", "get", "(", "'internalfield'", ")", ";", "}", "return", "$", "map", ";", "}" ]
Get a list of the mapping user fields in an associative array. @return array
[ "Get", "a", "list", "of", "the", "mapping", "user", "fields", "in", "an", "associative", "array", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/client.php#L216-L224
213,412
moodle/moodle
lib/classes/oauth2/client.php
client.upgrade_refresh_token
public function upgrade_refresh_token(system_account $systemaccount) { $refreshtoken = $systemaccount->get('refreshtoken'); $params = array('refresh_token' => $refreshtoken, 'grant_type' => 'refresh_token' ); if ($this->basicauth) { $idsecret = urlencode($this->issuer->get('clientid')) . ':' . urlencode($this->issuer->get('clientsecret')); $this->setHeader('Authorization: Basic ' . base64_encode($idsecret)); } else { $params['client_id'] = $this->issuer->get('clientid'); $params['client_secret'] = $this->issuer->get('clientsecret'); } // Requests can either use http GET or POST. if ($this->use_http_get()) { $response = $this->get($this->token_url(), $params); } else { $response = $this->post($this->token_url(), $this->build_post_data($params)); } if ($this->info['http_code'] !== 200) { throw new moodle_exception('Could not upgrade oauth token'); } $r = json_decode($response); if (!empty($r->error)) { throw new moodle_exception($r->error . ' ' . $r->error_description); } if (!isset($r->access_token)) { return false; } // Store the token an expiry time. $accesstoken = new stdClass; $accesstoken->token = $r->access_token; if (isset($r->expires_in)) { // Expires 10 seconds before actual expiry. $accesstoken->expires = (time() + ($r->expires_in - 10)); } $accesstoken->scope = $this->scope; // Also add the scopes. $this->store_token($accesstoken); if (isset($r->refresh_token)) { $systemaccount->set('refreshtoken', $r->refresh_token); $systemaccount->update(); $this->refreshtoken = $r->refresh_token; } return true; }
php
public function upgrade_refresh_token(system_account $systemaccount) { $refreshtoken = $systemaccount->get('refreshtoken'); $params = array('refresh_token' => $refreshtoken, 'grant_type' => 'refresh_token' ); if ($this->basicauth) { $idsecret = urlencode($this->issuer->get('clientid')) . ':' . urlencode($this->issuer->get('clientsecret')); $this->setHeader('Authorization: Basic ' . base64_encode($idsecret)); } else { $params['client_id'] = $this->issuer->get('clientid'); $params['client_secret'] = $this->issuer->get('clientsecret'); } // Requests can either use http GET or POST. if ($this->use_http_get()) { $response = $this->get($this->token_url(), $params); } else { $response = $this->post($this->token_url(), $this->build_post_data($params)); } if ($this->info['http_code'] !== 200) { throw new moodle_exception('Could not upgrade oauth token'); } $r = json_decode($response); if (!empty($r->error)) { throw new moodle_exception($r->error . ' ' . $r->error_description); } if (!isset($r->access_token)) { return false; } // Store the token an expiry time. $accesstoken = new stdClass; $accesstoken->token = $r->access_token; if (isset($r->expires_in)) { // Expires 10 seconds before actual expiry. $accesstoken->expires = (time() + ($r->expires_in - 10)); } $accesstoken->scope = $this->scope; // Also add the scopes. $this->store_token($accesstoken); if (isset($r->refresh_token)) { $systemaccount->set('refreshtoken', $r->refresh_token); $systemaccount->update(); $this->refreshtoken = $r->refresh_token; } return true; }
[ "public", "function", "upgrade_refresh_token", "(", "system_account", "$", "systemaccount", ")", "{", "$", "refreshtoken", "=", "$", "systemaccount", "->", "get", "(", "'refreshtoken'", ")", ";", "$", "params", "=", "array", "(", "'refresh_token'", "=>", "$", "refreshtoken", ",", "'grant_type'", "=>", "'refresh_token'", ")", ";", "if", "(", "$", "this", "->", "basicauth", ")", "{", "$", "idsecret", "=", "urlencode", "(", "$", "this", "->", "issuer", "->", "get", "(", "'clientid'", ")", ")", ".", "':'", ".", "urlencode", "(", "$", "this", "->", "issuer", "->", "get", "(", "'clientsecret'", ")", ")", ";", "$", "this", "->", "setHeader", "(", "'Authorization: Basic '", ".", "base64_encode", "(", "$", "idsecret", ")", ")", ";", "}", "else", "{", "$", "params", "[", "'client_id'", "]", "=", "$", "this", "->", "issuer", "->", "get", "(", "'clientid'", ")", ";", "$", "params", "[", "'client_secret'", "]", "=", "$", "this", "->", "issuer", "->", "get", "(", "'clientsecret'", ")", ";", "}", "// Requests can either use http GET or POST.", "if", "(", "$", "this", "->", "use_http_get", "(", ")", ")", "{", "$", "response", "=", "$", "this", "->", "get", "(", "$", "this", "->", "token_url", "(", ")", ",", "$", "params", ")", ";", "}", "else", "{", "$", "response", "=", "$", "this", "->", "post", "(", "$", "this", "->", "token_url", "(", ")", ",", "$", "this", "->", "build_post_data", "(", "$", "params", ")", ")", ";", "}", "if", "(", "$", "this", "->", "info", "[", "'http_code'", "]", "!==", "200", ")", "{", "throw", "new", "moodle_exception", "(", "'Could not upgrade oauth token'", ")", ";", "}", "$", "r", "=", "json_decode", "(", "$", "response", ")", ";", "if", "(", "!", "empty", "(", "$", "r", "->", "error", ")", ")", "{", "throw", "new", "moodle_exception", "(", "$", "r", "->", "error", ".", "' '", ".", "$", "r", "->", "error_description", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "r", "->", "access_token", ")", ")", "{", "return", "false", ";", "}", "// Store the token an expiry time.", "$", "accesstoken", "=", "new", "stdClass", ";", "$", "accesstoken", "->", "token", "=", "$", "r", "->", "access_token", ";", "if", "(", "isset", "(", "$", "r", "->", "expires_in", ")", ")", "{", "// Expires 10 seconds before actual expiry.", "$", "accesstoken", "->", "expires", "=", "(", "time", "(", ")", "+", "(", "$", "r", "->", "expires_in", "-", "10", ")", ")", ";", "}", "$", "accesstoken", "->", "scope", "=", "$", "this", "->", "scope", ";", "// Also add the scopes.", "$", "this", "->", "store_token", "(", "$", "accesstoken", ")", ";", "if", "(", "isset", "(", "$", "r", "->", "refresh_token", ")", ")", "{", "$", "systemaccount", "->", "set", "(", "'refreshtoken'", ",", "$", "r", "->", "refresh_token", ")", ";", "$", "systemaccount", "->", "update", "(", ")", ";", "$", "this", "->", "refreshtoken", "=", "$", "r", "->", "refresh_token", ";", "}", "return", "true", ";", "}" ]
Upgrade a refresh token from oauth 2.0 to an access token @param \core\oauth2\system_account $systemaccount @return boolean true if token is upgraded succesfully @throws moodle_exception Request for token upgrade failed for technical reasons
[ "Upgrade", "a", "refresh", "token", "from", "oauth", "2", ".", "0", "to", "an", "access", "token" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/client.php#L233-L287
213,413
moodle/moodle
lib/classes/oauth2/client.php
client.get_userinfo
public function get_userinfo() { $url = $this->get_issuer()->get_endpoint_url('userinfo'); $response = $this->get($url); if (!$response) { return false; } $userinfo = new stdClass(); try { $userinfo = json_decode($response); } catch (\Exception $e) { return false; } $map = $this->get_userinfo_mapping(); $user = new stdClass(); foreach ($map as $openidproperty => $moodleproperty) { // We support nested objects via a-b-c syntax. $getfunc = function($obj, $prop) use (&$getfunc) { $proplist = explode('-', $prop, 2); if (empty($proplist[0]) || empty($obj->{$proplist[0]})) { return false; } $obj = $obj->{$proplist[0]}; if (count($proplist) > 1) { return $getfunc($obj, $proplist[1]); } return $obj; }; $resolved = $getfunc($userinfo, $openidproperty); if (!empty($resolved)) { $user->$moodleproperty = $resolved; } } if (empty($user->username) && !empty($user->email)) { $user->username = $user->email; } if (!empty($user->picture)) { $user->picture = download_file_content($user->picture, null, null, false, 10, 10, true, null, false); } else { $pictureurl = $this->issuer->get_endpoint_url('userpicture'); if (!empty($pictureurl)) { $user->picture = $this->get($pictureurl); } } if (!empty($user->picture)) { // If it doesn't look like a picture lets unset it. if (function_exists('imagecreatefromstring')) { $img = @imagecreatefromstring($user->picture); if (empty($img)) { unset($user->picture); } else { imagedestroy($img); } } } return (array)$user; }
php
public function get_userinfo() { $url = $this->get_issuer()->get_endpoint_url('userinfo'); $response = $this->get($url); if (!$response) { return false; } $userinfo = new stdClass(); try { $userinfo = json_decode($response); } catch (\Exception $e) { return false; } $map = $this->get_userinfo_mapping(); $user = new stdClass(); foreach ($map as $openidproperty => $moodleproperty) { // We support nested objects via a-b-c syntax. $getfunc = function($obj, $prop) use (&$getfunc) { $proplist = explode('-', $prop, 2); if (empty($proplist[0]) || empty($obj->{$proplist[0]})) { return false; } $obj = $obj->{$proplist[0]}; if (count($proplist) > 1) { return $getfunc($obj, $proplist[1]); } return $obj; }; $resolved = $getfunc($userinfo, $openidproperty); if (!empty($resolved)) { $user->$moodleproperty = $resolved; } } if (empty($user->username) && !empty($user->email)) { $user->username = $user->email; } if (!empty($user->picture)) { $user->picture = download_file_content($user->picture, null, null, false, 10, 10, true, null, false); } else { $pictureurl = $this->issuer->get_endpoint_url('userpicture'); if (!empty($pictureurl)) { $user->picture = $this->get($pictureurl); } } if (!empty($user->picture)) { // If it doesn't look like a picture lets unset it. if (function_exists('imagecreatefromstring')) { $img = @imagecreatefromstring($user->picture); if (empty($img)) { unset($user->picture); } else { imagedestroy($img); } } } return (array)$user; }
[ "public", "function", "get_userinfo", "(", ")", "{", "$", "url", "=", "$", "this", "->", "get_issuer", "(", ")", "->", "get_endpoint_url", "(", "'userinfo'", ")", ";", "$", "response", "=", "$", "this", "->", "get", "(", "$", "url", ")", ";", "if", "(", "!", "$", "response", ")", "{", "return", "false", ";", "}", "$", "userinfo", "=", "new", "stdClass", "(", ")", ";", "try", "{", "$", "userinfo", "=", "json_decode", "(", "$", "response", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "false", ";", "}", "$", "map", "=", "$", "this", "->", "get_userinfo_mapping", "(", ")", ";", "$", "user", "=", "new", "stdClass", "(", ")", ";", "foreach", "(", "$", "map", "as", "$", "openidproperty", "=>", "$", "moodleproperty", ")", "{", "// We support nested objects via a-b-c syntax.", "$", "getfunc", "=", "function", "(", "$", "obj", ",", "$", "prop", ")", "use", "(", "&", "$", "getfunc", ")", "{", "$", "proplist", "=", "explode", "(", "'-'", ",", "$", "prop", ",", "2", ")", ";", "if", "(", "empty", "(", "$", "proplist", "[", "0", "]", ")", "||", "empty", "(", "$", "obj", "->", "{", "$", "proplist", "[", "0", "]", "}", ")", ")", "{", "return", "false", ";", "}", "$", "obj", "=", "$", "obj", "->", "{", "$", "proplist", "[", "0", "]", "}", ";", "if", "(", "count", "(", "$", "proplist", ")", ">", "1", ")", "{", "return", "$", "getfunc", "(", "$", "obj", ",", "$", "proplist", "[", "1", "]", ")", ";", "}", "return", "$", "obj", ";", "}", ";", "$", "resolved", "=", "$", "getfunc", "(", "$", "userinfo", ",", "$", "openidproperty", ")", ";", "if", "(", "!", "empty", "(", "$", "resolved", ")", ")", "{", "$", "user", "->", "$", "moodleproperty", "=", "$", "resolved", ";", "}", "}", "if", "(", "empty", "(", "$", "user", "->", "username", ")", "&&", "!", "empty", "(", "$", "user", "->", "email", ")", ")", "{", "$", "user", "->", "username", "=", "$", "user", "->", "email", ";", "}", "if", "(", "!", "empty", "(", "$", "user", "->", "picture", ")", ")", "{", "$", "user", "->", "picture", "=", "download_file_content", "(", "$", "user", "->", "picture", ",", "null", ",", "null", ",", "false", ",", "10", ",", "10", ",", "true", ",", "null", ",", "false", ")", ";", "}", "else", "{", "$", "pictureurl", "=", "$", "this", "->", "issuer", "->", "get_endpoint_url", "(", "'userpicture'", ")", ";", "if", "(", "!", "empty", "(", "$", "pictureurl", ")", ")", "{", "$", "user", "->", "picture", "=", "$", "this", "->", "get", "(", "$", "pictureurl", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "user", "->", "picture", ")", ")", "{", "// If it doesn't look like a picture lets unset it.", "if", "(", "function_exists", "(", "'imagecreatefromstring'", ")", ")", "{", "$", "img", "=", "@", "imagecreatefromstring", "(", "$", "user", "->", "picture", ")", ";", "if", "(", "empty", "(", "$", "img", ")", ")", "{", "unset", "(", "$", "user", "->", "picture", ")", ";", "}", "else", "{", "imagedestroy", "(", "$", "img", ")", ";", "}", "}", "}", "return", "(", "array", ")", "$", "user", ";", "}" ]
Fetch the user info from the user info endpoint and map all the fields back into moodle fields. @return array|false Moodle user fields for the logged in user (or false if request failed)
[ "Fetch", "the", "user", "info", "from", "the", "user", "info", "endpoint", "and", "map", "all", "the", "fields", "back", "into", "moodle", "fields", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/client.php#L295-L358
213,414
moodle/moodle
lib/horde/framework/Horde/Mime/Mdn.php
Horde_Mime_Mdn.userConfirmationNeeded
public function userConfirmationNeeded() { $return_path = $this->_headers['Return-Path']; /* RFC 3798 [2.1]: Explicit confirmation is needed if there is no * Return-Path in the header. Also, "if the message contains more * than one Return-Path header, the implementation may [] treat the * situation as a failure of the comparison." */ if (!$return_path || (count($return_path->value) > 1)) { return true; } /* RFC 3798 [2.1]: Explicit confirmation is needed if there is more * than one distinct address in the Disposition-Notification-To * header. */ $addr_ob = ($hdr = $this->_headers[self::MDN_HEADER]) ? $hdr->getAddressList(true) : array(); switch (count($addr_ob)) { case 0: return false; case 1: // No-op break; default: return true; } /* RFC 3798 [2.1] states that "MDNs SHOULD NOT be sent automatically * if the address in the Disposition-Notification-To header differs * from the address in the Return-Path header." This comparison is * case-sensitive for the mailbox part and case-insensitive for the * host part. */ $ret_ob = new Horde_Mail_Rfc822_Address($return_path->value); return (!$ret_ob->valid || !$addr_ob->match($ret_ob)); }
php
public function userConfirmationNeeded() { $return_path = $this->_headers['Return-Path']; /* RFC 3798 [2.1]: Explicit confirmation is needed if there is no * Return-Path in the header. Also, "if the message contains more * than one Return-Path header, the implementation may [] treat the * situation as a failure of the comparison." */ if (!$return_path || (count($return_path->value) > 1)) { return true; } /* RFC 3798 [2.1]: Explicit confirmation is needed if there is more * than one distinct address in the Disposition-Notification-To * header. */ $addr_ob = ($hdr = $this->_headers[self::MDN_HEADER]) ? $hdr->getAddressList(true) : array(); switch (count($addr_ob)) { case 0: return false; case 1: // No-op break; default: return true; } /* RFC 3798 [2.1] states that "MDNs SHOULD NOT be sent automatically * if the address in the Disposition-Notification-To header differs * from the address in the Return-Path header." This comparison is * case-sensitive for the mailbox part and case-insensitive for the * host part. */ $ret_ob = new Horde_Mail_Rfc822_Address($return_path->value); return (!$ret_ob->valid || !$addr_ob->match($ret_ob)); }
[ "public", "function", "userConfirmationNeeded", "(", ")", "{", "$", "return_path", "=", "$", "this", "->", "_headers", "[", "'Return-Path'", "]", ";", "/* RFC 3798 [2.1]: Explicit confirmation is needed if there is no\n * Return-Path in the header. Also, \"if the message contains more\n * than one Return-Path header, the implementation may [] treat the\n * situation as a failure of the comparison.\" */", "if", "(", "!", "$", "return_path", "||", "(", "count", "(", "$", "return_path", "->", "value", ")", ">", "1", ")", ")", "{", "return", "true", ";", "}", "/* RFC 3798 [2.1]: Explicit confirmation is needed if there is more\n * than one distinct address in the Disposition-Notification-To\n * header. */", "$", "addr_ob", "=", "(", "$", "hdr", "=", "$", "this", "->", "_headers", "[", "self", "::", "MDN_HEADER", "]", ")", "?", "$", "hdr", "->", "getAddressList", "(", "true", ")", ":", "array", "(", ")", ";", "switch", "(", "count", "(", "$", "addr_ob", ")", ")", "{", "case", "0", ":", "return", "false", ";", "case", "1", ":", "// No-op", "break", ";", "default", ":", "return", "true", ";", "}", "/* RFC 3798 [2.1] states that \"MDNs SHOULD NOT be sent automatically\n * if the address in the Disposition-Notification-To header differs\n * from the address in the Return-Path header.\" This comparison is\n * case-sensitive for the mailbox part and case-insensitive for the\n * host part. */", "$", "ret_ob", "=", "new", "Horde_Mail_Rfc822_Address", "(", "$", "return_path", "->", "value", ")", ";", "return", "(", "!", "$", "ret_ob", "->", "valid", "||", "!", "$", "addr_ob", "->", "match", "(", "$", "ret_ob", ")", ")", ";", "}" ]
Is user input required to send the MDN? Explicit confirmation is needed in some cases to prevent mail loops and the use of MDNs for mail bombing. @return boolean Is explicit user input required to send the MDN?
[ "Is", "user", "input", "required", "to", "send", "the", "MDN?", "Explicit", "confirmation", "is", "needed", "in", "some", "cases", "to", "prevent", "mail", "loops", "and", "the", "use", "of", "MDNs", "for", "mail", "bombing", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Mdn.php#L74-L112
213,415
moodle/moodle
report/log/classes/renderable.php
report_log_renderable.get_activities_list
public function get_activities_list() { $activities = array(); // For site just return site errors option. $sitecontext = context_system::instance(); if ($this->course->id == SITEID && has_capability('report/log:view', $sitecontext)) { $activities["site_errors"] = get_string("siteerrors"); return $activities; } $modinfo = get_fast_modinfo($this->course); if (!empty($modinfo->cms)) { $section = 0; $thissection = array(); foreach ($modinfo->cms as $cm) { if (!$cm->uservisible || !$cm->has_view()) { continue; } if ($cm->sectionnum > 0 and $section <> $cm->sectionnum) { $activities[] = $thissection; $thissection = array(); } $section = $cm->sectionnum; $modname = strip_tags($cm->get_formatted_name()); if (core_text::strlen($modname) > 55) { $modname = core_text::substr($modname, 0, 50)."..."; } if (!$cm->visible) { $modname = "(".$modname.")"; } $key = get_section_name($this->course, $cm->sectionnum); if (!isset($thissection[$key])) { $thissection[$key] = array(); } $thissection[$key][$cm->id] = $modname; } if (!empty($thissection)) { $activities[] = $thissection; } } return $activities; }
php
public function get_activities_list() { $activities = array(); // For site just return site errors option. $sitecontext = context_system::instance(); if ($this->course->id == SITEID && has_capability('report/log:view', $sitecontext)) { $activities["site_errors"] = get_string("siteerrors"); return $activities; } $modinfo = get_fast_modinfo($this->course); if (!empty($modinfo->cms)) { $section = 0; $thissection = array(); foreach ($modinfo->cms as $cm) { if (!$cm->uservisible || !$cm->has_view()) { continue; } if ($cm->sectionnum > 0 and $section <> $cm->sectionnum) { $activities[] = $thissection; $thissection = array(); } $section = $cm->sectionnum; $modname = strip_tags($cm->get_formatted_name()); if (core_text::strlen($modname) > 55) { $modname = core_text::substr($modname, 0, 50)."..."; } if (!$cm->visible) { $modname = "(".$modname.")"; } $key = get_section_name($this->course, $cm->sectionnum); if (!isset($thissection[$key])) { $thissection[$key] = array(); } $thissection[$key][$cm->id] = $modname; } if (!empty($thissection)) { $activities[] = $thissection; } } return $activities; }
[ "public", "function", "get_activities_list", "(", ")", "{", "$", "activities", "=", "array", "(", ")", ";", "// For site just return site errors option.", "$", "sitecontext", "=", "context_system", "::", "instance", "(", ")", ";", "if", "(", "$", "this", "->", "course", "->", "id", "==", "SITEID", "&&", "has_capability", "(", "'report/log:view'", ",", "$", "sitecontext", ")", ")", "{", "$", "activities", "[", "\"site_errors\"", "]", "=", "get_string", "(", "\"siteerrors\"", ")", ";", "return", "$", "activities", ";", "}", "$", "modinfo", "=", "get_fast_modinfo", "(", "$", "this", "->", "course", ")", ";", "if", "(", "!", "empty", "(", "$", "modinfo", "->", "cms", ")", ")", "{", "$", "section", "=", "0", ";", "$", "thissection", "=", "array", "(", ")", ";", "foreach", "(", "$", "modinfo", "->", "cms", "as", "$", "cm", ")", "{", "if", "(", "!", "$", "cm", "->", "uservisible", "||", "!", "$", "cm", "->", "has_view", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "cm", "->", "sectionnum", ">", "0", "and", "$", "section", "<>", "$", "cm", "->", "sectionnum", ")", "{", "$", "activities", "[", "]", "=", "$", "thissection", ";", "$", "thissection", "=", "array", "(", ")", ";", "}", "$", "section", "=", "$", "cm", "->", "sectionnum", ";", "$", "modname", "=", "strip_tags", "(", "$", "cm", "->", "get_formatted_name", "(", ")", ")", ";", "if", "(", "core_text", "::", "strlen", "(", "$", "modname", ")", ">", "55", ")", "{", "$", "modname", "=", "core_text", "::", "substr", "(", "$", "modname", ",", "0", ",", "50", ")", ".", "\"...\"", ";", "}", "if", "(", "!", "$", "cm", "->", "visible", ")", "{", "$", "modname", "=", "\"(\"", ".", "$", "modname", ".", "\")\"", ";", "}", "$", "key", "=", "get_section_name", "(", "$", "this", "->", "course", ",", "$", "cm", "->", "sectionnum", ")", ";", "if", "(", "!", "isset", "(", "$", "thissection", "[", "$", "key", "]", ")", ")", "{", "$", "thissection", "[", "$", "key", "]", "=", "array", "(", ")", ";", "}", "$", "thissection", "[", "$", "key", "]", "[", "$", "cm", "->", "id", "]", "=", "$", "modname", ";", "}", "if", "(", "!", "empty", "(", "$", "thissection", ")", ")", "{", "$", "activities", "[", "]", "=", "$", "thissection", ";", "}", "}", "return", "$", "activities", ";", "}" ]
Helper function to return list of activities to show in selection filter. @return array list of activities.
[ "Helper", "function", "to", "return", "list", "of", "activities", "to", "show", "in", "selection", "filter", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/renderable.php#L191-L232
213,416
moodle/moodle
report/log/classes/renderable.php
report_log_renderable.get_selected_group
public function get_selected_group() { global $SESSION, $USER; // No groups for system. if (empty($this->course)) { return 0; } $context = context_course::instance($this->course->id); $selectedgroup = 0; // Setup for group handling. $groupmode = groups_get_course_groupmode($this->course); if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { $selectedgroup = -1; } else if ($groupmode) { $selectedgroup = $this->groupid; } else { $selectedgroup = 0; } if ($selectedgroup === -1) { if (isset($SESSION->currentgroup[$this->course->id])) { $selectedgroup = $SESSION->currentgroup[$this->course->id]; } else { $selectedgroup = groups_get_all_groups($this->course->id, $USER->id); if (is_array($selectedgroup)) { $groupids = array_keys($selectedgroup); $selectedgroup = array_shift($groupids); $SESSION->currentgroup[$this->course->id] = $selectedgroup; } else { $selectedgroup = 0; } } } return $selectedgroup; }
php
public function get_selected_group() { global $SESSION, $USER; // No groups for system. if (empty($this->course)) { return 0; } $context = context_course::instance($this->course->id); $selectedgroup = 0; // Setup for group handling. $groupmode = groups_get_course_groupmode($this->course); if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { $selectedgroup = -1; } else if ($groupmode) { $selectedgroup = $this->groupid; } else { $selectedgroup = 0; } if ($selectedgroup === -1) { if (isset($SESSION->currentgroup[$this->course->id])) { $selectedgroup = $SESSION->currentgroup[$this->course->id]; } else { $selectedgroup = groups_get_all_groups($this->course->id, $USER->id); if (is_array($selectedgroup)) { $groupids = array_keys($selectedgroup); $selectedgroup = array_shift($groupids); $SESSION->currentgroup[$this->course->id] = $selectedgroup; } else { $selectedgroup = 0; } } } return $selectedgroup; }
[ "public", "function", "get_selected_group", "(", ")", "{", "global", "$", "SESSION", ",", "$", "USER", ";", "// No groups for system.", "if", "(", "empty", "(", "$", "this", "->", "course", ")", ")", "{", "return", "0", ";", "}", "$", "context", "=", "context_course", "::", "instance", "(", "$", "this", "->", "course", "->", "id", ")", ";", "$", "selectedgroup", "=", "0", ";", "// Setup for group handling.", "$", "groupmode", "=", "groups_get_course_groupmode", "(", "$", "this", "->", "course", ")", ";", "if", "(", "$", "groupmode", "==", "SEPARATEGROUPS", "and", "!", "has_capability", "(", "'moodle/site:accessallgroups'", ",", "$", "context", ")", ")", "{", "$", "selectedgroup", "=", "-", "1", ";", "}", "else", "if", "(", "$", "groupmode", ")", "{", "$", "selectedgroup", "=", "$", "this", "->", "groupid", ";", "}", "else", "{", "$", "selectedgroup", "=", "0", ";", "}", "if", "(", "$", "selectedgroup", "===", "-", "1", ")", "{", "if", "(", "isset", "(", "$", "SESSION", "->", "currentgroup", "[", "$", "this", "->", "course", "->", "id", "]", ")", ")", "{", "$", "selectedgroup", "=", "$", "SESSION", "->", "currentgroup", "[", "$", "this", "->", "course", "->", "id", "]", ";", "}", "else", "{", "$", "selectedgroup", "=", "groups_get_all_groups", "(", "$", "this", "->", "course", "->", "id", ",", "$", "USER", "->", "id", ")", ";", "if", "(", "is_array", "(", "$", "selectedgroup", ")", ")", "{", "$", "groupids", "=", "array_keys", "(", "$", "selectedgroup", ")", ";", "$", "selectedgroup", "=", "array_shift", "(", "$", "groupids", ")", ";", "$", "SESSION", "->", "currentgroup", "[", "$", "this", "->", "course", "->", "id", "]", "=", "$", "selectedgroup", ";", "}", "else", "{", "$", "selectedgroup", "=", "0", ";", "}", "}", "}", "return", "$", "selectedgroup", ";", "}" ]
Helper function to get selected group. @return int selected group.
[ "Helper", "function", "to", "get", "selected", "group", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/renderable.php#L239-L275
213,417
moodle/moodle
report/log/classes/renderable.php
report_log_renderable.get_course_list
public function get_course_list() { global $DB, $SITE; $courses = array(); $sitecontext = context_system::instance(); // First check to see if we can override showcourses and showusers. $numcourses = $DB->count_records("course"); if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$this->showcourses) { $this->showcourses = 1; } // Check if course filter should be shown. if (has_capability('report/log:view', $sitecontext) && $this->showcourses) { if ($courserecords = $DB->get_records("course", null, "fullname", "id,shortname,fullname,category")) { foreach ($courserecords as $course) { if ($course->id == SITEID) { $courses[$course->id] = format_string($course->fullname) . ' (' . get_string('site') . ')'; } else { $courses[$course->id] = format_string(get_course_display_name_for_list($course)); } } } core_collator::asort($courses); } return $courses; }
php
public function get_course_list() { global $DB, $SITE; $courses = array(); $sitecontext = context_system::instance(); // First check to see if we can override showcourses and showusers. $numcourses = $DB->count_records("course"); if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$this->showcourses) { $this->showcourses = 1; } // Check if course filter should be shown. if (has_capability('report/log:view', $sitecontext) && $this->showcourses) { if ($courserecords = $DB->get_records("course", null, "fullname", "id,shortname,fullname,category")) { foreach ($courserecords as $course) { if ($course->id == SITEID) { $courses[$course->id] = format_string($course->fullname) . ' (' . get_string('site') . ')'; } else { $courses[$course->id] = format_string(get_course_display_name_for_list($course)); } } } core_collator::asort($courses); } return $courses; }
[ "public", "function", "get_course_list", "(", ")", "{", "global", "$", "DB", ",", "$", "SITE", ";", "$", "courses", "=", "array", "(", ")", ";", "$", "sitecontext", "=", "context_system", "::", "instance", "(", ")", ";", "// First check to see if we can override showcourses and showusers.", "$", "numcourses", "=", "$", "DB", "->", "count_records", "(", "\"course\"", ")", ";", "if", "(", "$", "numcourses", "<", "COURSE_MAX_COURSES_PER_DROPDOWN", "&&", "!", "$", "this", "->", "showcourses", ")", "{", "$", "this", "->", "showcourses", "=", "1", ";", "}", "// Check if course filter should be shown.", "if", "(", "has_capability", "(", "'report/log:view'", ",", "$", "sitecontext", ")", "&&", "$", "this", "->", "showcourses", ")", "{", "if", "(", "$", "courserecords", "=", "$", "DB", "->", "get_records", "(", "\"course\"", ",", "null", ",", "\"fullname\"", ",", "\"id,shortname,fullname,category\"", ")", ")", "{", "foreach", "(", "$", "courserecords", "as", "$", "course", ")", "{", "if", "(", "$", "course", "->", "id", "==", "SITEID", ")", "{", "$", "courses", "[", "$", "course", "->", "id", "]", "=", "format_string", "(", "$", "course", "->", "fullname", ")", ".", "' ('", ".", "get_string", "(", "'site'", ")", ".", "')'", ";", "}", "else", "{", "$", "courses", "[", "$", "course", "->", "id", "]", "=", "format_string", "(", "get_course_display_name_for_list", "(", "$", "course", ")", ")", ";", "}", "}", "}", "core_collator", "::", "asort", "(", "$", "courses", ")", ";", "}", "return", "$", "courses", ";", "}" ]
Return list of courses to show in selector. @return array list of courses.
[ "Return", "list", "of", "courses", "to", "show", "in", "selector", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/renderable.php#L309-L335
213,418
moodle/moodle
report/log/classes/renderable.php
report_log_renderable.get_group_list
public function get_group_list() { // No groups for system. if (empty($this->course)) { return array(); } $context = context_course::instance($this->course->id); $groups = array(); $groupmode = groups_get_course_groupmode($this->course); if (($groupmode == VISIBLEGROUPS) || ($groupmode == SEPARATEGROUPS and has_capability('moodle/site:accessallgroups', $context))) { // Get all groups. if ($cgroups = groups_get_all_groups($this->course->id)) { foreach ($cgroups as $cgroup) { $groups[$cgroup->id] = $cgroup->name; } } } return $groups; }
php
public function get_group_list() { // No groups for system. if (empty($this->course)) { return array(); } $context = context_course::instance($this->course->id); $groups = array(); $groupmode = groups_get_course_groupmode($this->course); if (($groupmode == VISIBLEGROUPS) || ($groupmode == SEPARATEGROUPS and has_capability('moodle/site:accessallgroups', $context))) { // Get all groups. if ($cgroups = groups_get_all_groups($this->course->id)) { foreach ($cgroups as $cgroup) { $groups[$cgroup->id] = $cgroup->name; } } } return $groups; }
[ "public", "function", "get_group_list", "(", ")", "{", "// No groups for system.", "if", "(", "empty", "(", "$", "this", "->", "course", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "context", "=", "context_course", "::", "instance", "(", "$", "this", "->", "course", "->", "id", ")", ";", "$", "groups", "=", "array", "(", ")", ";", "$", "groupmode", "=", "groups_get_course_groupmode", "(", "$", "this", "->", "course", ")", ";", "if", "(", "(", "$", "groupmode", "==", "VISIBLEGROUPS", ")", "||", "(", "$", "groupmode", "==", "SEPARATEGROUPS", "and", "has_capability", "(", "'moodle/site:accessallgroups'", ",", "$", "context", ")", ")", ")", "{", "// Get all groups.", "if", "(", "$", "cgroups", "=", "groups_get_all_groups", "(", "$", "this", "->", "course", "->", "id", ")", ")", "{", "foreach", "(", "$", "cgroups", "as", "$", "cgroup", ")", "{", "$", "groups", "[", "$", "cgroup", "->", "id", "]", "=", "$", "cgroup", "->", "name", ";", "}", "}", "}", "return", "$", "groups", ";", "}" ]
Return list of groups. @return array list of groups.
[ "Return", "list", "of", "groups", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/renderable.php#L342-L362
213,419
moodle/moodle
report/log/classes/renderable.php
report_log_renderable.get_user_list
public function get_user_list() { global $CFG, $SITE; $courseid = $SITE->id; if (!empty($this->course)) { $courseid = $this->course->id; } $context = context_course::instance($courseid); $limitfrom = empty($this->showusers) ? 0 : ''; $limitnum = empty($this->showusers) ? COURSE_MAX_USERS_PER_DROPDOWN + 1 : ''; $courseusers = get_enrolled_users($context, '', $this->groupid, 'u.id, ' . get_all_user_name_fields(true, 'u'), null, $limitfrom, $limitnum); if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$this->showusers) { $this->showusers = 1; } $users = array(); if ($this->showusers) { if ($courseusers) { foreach ($courseusers as $courseuser) { $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context)); } } $users[$CFG->siteguest] = get_string('guestuser'); } return $users; }
php
public function get_user_list() { global $CFG, $SITE; $courseid = $SITE->id; if (!empty($this->course)) { $courseid = $this->course->id; } $context = context_course::instance($courseid); $limitfrom = empty($this->showusers) ? 0 : ''; $limitnum = empty($this->showusers) ? COURSE_MAX_USERS_PER_DROPDOWN + 1 : ''; $courseusers = get_enrolled_users($context, '', $this->groupid, 'u.id, ' . get_all_user_name_fields(true, 'u'), null, $limitfrom, $limitnum); if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$this->showusers) { $this->showusers = 1; } $users = array(); if ($this->showusers) { if ($courseusers) { foreach ($courseusers as $courseuser) { $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context)); } } $users[$CFG->siteguest] = get_string('guestuser'); } return $users; }
[ "public", "function", "get_user_list", "(", ")", "{", "global", "$", "CFG", ",", "$", "SITE", ";", "$", "courseid", "=", "$", "SITE", "->", "id", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "course", ")", ")", "{", "$", "courseid", "=", "$", "this", "->", "course", "->", "id", ";", "}", "$", "context", "=", "context_course", "::", "instance", "(", "$", "courseid", ")", ";", "$", "limitfrom", "=", "empty", "(", "$", "this", "->", "showusers", ")", "?", "0", ":", "''", ";", "$", "limitnum", "=", "empty", "(", "$", "this", "->", "showusers", ")", "?", "COURSE_MAX_USERS_PER_DROPDOWN", "+", "1", ":", "''", ";", "$", "courseusers", "=", "get_enrolled_users", "(", "$", "context", ",", "''", ",", "$", "this", "->", "groupid", ",", "'u.id, '", ".", "get_all_user_name_fields", "(", "true", ",", "'u'", ")", ",", "null", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ";", "if", "(", "count", "(", "$", "courseusers", ")", "<", "COURSE_MAX_USERS_PER_DROPDOWN", "&&", "!", "$", "this", "->", "showusers", ")", "{", "$", "this", "->", "showusers", "=", "1", ";", "}", "$", "users", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "showusers", ")", "{", "if", "(", "$", "courseusers", ")", "{", "foreach", "(", "$", "courseusers", "as", "$", "courseuser", ")", "{", "$", "users", "[", "$", "courseuser", "->", "id", "]", "=", "fullname", "(", "$", "courseuser", ",", "has_capability", "(", "'moodle/site:viewfullnames'", ",", "$", "context", ")", ")", ";", "}", "}", "$", "users", "[", "$", "CFG", "->", "siteguest", "]", "=", "get_string", "(", "'guestuser'", ")", ";", "}", "return", "$", "users", ";", "}" ]
Return list of users. @return array list of users.
[ "Return", "list", "of", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/renderable.php#L369-L396
213,420
moodle/moodle
report/log/classes/renderable.php
report_log_renderable.get_date_options
public function get_date_options() { global $SITE; $strftimedate = get_string("strftimedate"); $strftimedaydate = get_string("strftimedaydate"); // Get all the possible dates. // Note that we are keeping track of real (GMT) time and user time. // User time is only used in displays - all calcs and passing is GMT. $timenow = time(); // GMT. // What day is it now for the user, and when is midnight that day (in GMT). $timemidnight = usergetmidnight($timenow); // Put today up the top of the list. $dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) ); // If course is empty, get it from frontpage. $course = $SITE; if (!empty($this->course)) { $course = $this->course; } if (!$course->startdate or ($course->startdate > $timenow)) { $course->startdate = $course->timecreated; } $numdates = 1; while ($timemidnight > $course->startdate and $numdates < 365) { $timemidnight = $timemidnight - 86400; $timenow = $timenow - 86400; $dates["$timemidnight"] = userdate($timenow, $strftimedaydate); $numdates++; } return $dates; }
php
public function get_date_options() { global $SITE; $strftimedate = get_string("strftimedate"); $strftimedaydate = get_string("strftimedaydate"); // Get all the possible dates. // Note that we are keeping track of real (GMT) time and user time. // User time is only used in displays - all calcs and passing is GMT. $timenow = time(); // GMT. // What day is it now for the user, and when is midnight that day (in GMT). $timemidnight = usergetmidnight($timenow); // Put today up the top of the list. $dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) ); // If course is empty, get it from frontpage. $course = $SITE; if (!empty($this->course)) { $course = $this->course; } if (!$course->startdate or ($course->startdate > $timenow)) { $course->startdate = $course->timecreated; } $numdates = 1; while ($timemidnight > $course->startdate and $numdates < 365) { $timemidnight = $timemidnight - 86400; $timenow = $timenow - 86400; $dates["$timemidnight"] = userdate($timenow, $strftimedaydate); $numdates++; } return $dates; }
[ "public", "function", "get_date_options", "(", ")", "{", "global", "$", "SITE", ";", "$", "strftimedate", "=", "get_string", "(", "\"strftimedate\"", ")", ";", "$", "strftimedaydate", "=", "get_string", "(", "\"strftimedaydate\"", ")", ";", "// Get all the possible dates.", "// Note that we are keeping track of real (GMT) time and user time.", "// User time is only used in displays - all calcs and passing is GMT.", "$", "timenow", "=", "time", "(", ")", ";", "// GMT.", "// What day is it now for the user, and when is midnight that day (in GMT).", "$", "timemidnight", "=", "usergetmidnight", "(", "$", "timenow", ")", ";", "// Put today up the top of the list.", "$", "dates", "=", "array", "(", "\"$timemidnight\"", "=>", "get_string", "(", "\"today\"", ")", ".", "\", \"", ".", "userdate", "(", "$", "timenow", ",", "$", "strftimedate", ")", ")", ";", "// If course is empty, get it from frontpage.", "$", "course", "=", "$", "SITE", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "course", ")", ")", "{", "$", "course", "=", "$", "this", "->", "course", ";", "}", "if", "(", "!", "$", "course", "->", "startdate", "or", "(", "$", "course", "->", "startdate", ">", "$", "timenow", ")", ")", "{", "$", "course", "->", "startdate", "=", "$", "course", "->", "timecreated", ";", "}", "$", "numdates", "=", "1", ";", "while", "(", "$", "timemidnight", ">", "$", "course", "->", "startdate", "and", "$", "numdates", "<", "365", ")", "{", "$", "timemidnight", "=", "$", "timemidnight", "-", "86400", ";", "$", "timenow", "=", "$", "timenow", "-", "86400", ";", "$", "dates", "[", "\"$timemidnight\"", "]", "=", "userdate", "(", "$", "timenow", ",", "$", "strftimedaydate", ")", ";", "$", "numdates", "++", ";", "}", "return", "$", "dates", ";", "}" ]
Return list of date options. @return array date options.
[ "Return", "list", "of", "date", "options", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/renderable.php#L403-L437
213,421
moodle/moodle
report/log/classes/renderable.php
report_log_renderable.get_origin_options
public function get_origin_options() { $ret = array(); $ret[''] = get_string('allsources', 'report_log'); $ret['cli'] = get_string('cli', 'report_log'); $ret['restore'] = get_string('restore', 'report_log'); $ret['web'] = get_string('web', 'report_log'); $ret['ws'] = get_string('ws', 'report_log'); $ret['---'] = get_string('other', 'report_log'); return $ret; }
php
public function get_origin_options() { $ret = array(); $ret[''] = get_string('allsources', 'report_log'); $ret['cli'] = get_string('cli', 'report_log'); $ret['restore'] = get_string('restore', 'report_log'); $ret['web'] = get_string('web', 'report_log'); $ret['ws'] = get_string('ws', 'report_log'); $ret['---'] = get_string('other', 'report_log'); return $ret; }
[ "public", "function", "get_origin_options", "(", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "$", "ret", "[", "''", "]", "=", "get_string", "(", "'allsources'", ",", "'report_log'", ")", ";", "$", "ret", "[", "'cli'", "]", "=", "get_string", "(", "'cli'", ",", "'report_log'", ")", ";", "$", "ret", "[", "'restore'", "]", "=", "get_string", "(", "'restore'", ",", "'report_log'", ")", ";", "$", "ret", "[", "'web'", "]", "=", "get_string", "(", "'web'", ",", "'report_log'", ")", ";", "$", "ret", "[", "'ws'", "]", "=", "get_string", "(", "'ws'", ",", "'report_log'", ")", ";", "$", "ret", "[", "'---'", "]", "=", "get_string", "(", "'other'", ",", "'report_log'", ")", ";", "return", "$", "ret", ";", "}" ]
Return list of components to show in selector. @return array list of origins.
[ "Return", "list", "of", "components", "to", "show", "in", "selector", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/renderable.php#L444-L453
213,422
moodle/moodle
report/log/classes/renderable.php
report_log_renderable.download
public function download() { $filename = 'logs_' . userdate(time(), get_string('backupnameformat', 'langconfig'), 99, false); if ($this->course->id !== SITEID) { $courseshortname = format_string($this->course->shortname, true, array('context' => context_course::instance($this->course->id))); $filename = clean_filename('logs_' . $courseshortname . '_' . userdate(time(), get_string('backupnameformat', 'langconfig'), 99, false)); } $this->tablelog->is_downloading($this->logformat, $filename); $this->tablelog->out($this->perpage, false); }
php
public function download() { $filename = 'logs_' . userdate(time(), get_string('backupnameformat', 'langconfig'), 99, false); if ($this->course->id !== SITEID) { $courseshortname = format_string($this->course->shortname, true, array('context' => context_course::instance($this->course->id))); $filename = clean_filename('logs_' . $courseshortname . '_' . userdate(time(), get_string('backupnameformat', 'langconfig'), 99, false)); } $this->tablelog->is_downloading($this->logformat, $filename); $this->tablelog->out($this->perpage, false); }
[ "public", "function", "download", "(", ")", "{", "$", "filename", "=", "'logs_'", ".", "userdate", "(", "time", "(", ")", ",", "get_string", "(", "'backupnameformat'", ",", "'langconfig'", ")", ",", "99", ",", "false", ")", ";", "if", "(", "$", "this", "->", "course", "->", "id", "!==", "SITEID", ")", "{", "$", "courseshortname", "=", "format_string", "(", "$", "this", "->", "course", "->", "shortname", ",", "true", ",", "array", "(", "'context'", "=>", "context_course", "::", "instance", "(", "$", "this", "->", "course", "->", "id", ")", ")", ")", ";", "$", "filename", "=", "clean_filename", "(", "'logs_'", ".", "$", "courseshortname", ".", "'_'", ".", "userdate", "(", "time", "(", ")", ",", "get_string", "(", "'backupnameformat'", ",", "'langconfig'", ")", ",", "99", ",", "false", ")", ")", ";", "}", "$", "this", "->", "tablelog", "->", "is_downloading", "(", "$", "this", "->", "logformat", ",", "$", "filename", ")", ";", "$", "this", "->", "tablelog", "->", "out", "(", "$", "this", "->", "perpage", ",", "false", ")", ";", "}" ]
Download logs in specified format.
[ "Download", "logs", "in", "specified", "format", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/renderable.php#L508-L518
213,423
moodle/moodle
lib/simplepie/library/SimplePie/Item.php
SimplePie_Item.get_item_tags
public function get_item_tags($namespace, $tag) { if (isset($this->data['child'][$namespace][$tag])) { return $this->data['child'][$namespace][$tag]; } else { return null; } }
php
public function get_item_tags($namespace, $tag) { if (isset($this->data['child'][$namespace][$tag])) { return $this->data['child'][$namespace][$tag]; } else { return null; } }
[ "public", "function", "get_item_tags", "(", "$", "namespace", ",", "$", "tag", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "'child'", "]", "[", "$", "namespace", "]", "[", "$", "tag", "]", ")", ")", "{", "return", "$", "this", "->", "data", "[", "'child'", "]", "[", "$", "namespace", "]", "[", "$", "tag", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Get data for an item-level element This method allows you to get access to ANY element/attribute that is a sub-element of the item/entry tag. See {@see SimplePie::get_feed_tags()} for a description of the return value @since 1.0 @see http://simplepie.org/wiki/faq/supported_xml_namespaces @param string $namespace The URL of the XML namespace of the elements you're trying to access @param string $tag Tag name @return array
[ "Get", "data", "for", "an", "item", "-", "level", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Item.php#L144-L154
213,424
moodle/moodle
lib/simplepie/library/SimplePie/Item.php
SimplePie_Item.get_title
public function get_title() { if (!isset($this->data['title'])) { if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); } elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); } elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); } elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); } elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); } elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } else { $this->data['title'] = null; } } return $this->data['title']; }
php
public function get_title() { if (!isset($this->data['title'])) { if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); } elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); } elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); } elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); } elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); } elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) { $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } else { $this->data['title'] = null; } } return $this->data['title']; }
[ "public", "function", "get_title", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "data", "[", "'title'", "]", ")", ")", "{", "if", "(", "$", "return", "=", "$", "this", "->", "get_item_tags", "(", "SIMPLEPIE_NAMESPACE_ATOM_10", ",", "'title'", ")", ")", "{", "$", "this", "->", "data", "[", "'title'", "]", "=", "$", "this", "->", "sanitize", "(", "$", "return", "[", "0", "]", "[", "'data'", "]", ",", "$", "this", "->", "registry", "->", "call", "(", "'Misc'", ",", "'atom_10_construct_type'", ",", "array", "(", "$", "return", "[", "0", "]", "[", "'attribs'", "]", ")", ")", ",", "$", "this", "->", "get_base", "(", "$", "return", "[", "0", "]", ")", ")", ";", "}", "elseif", "(", "$", "return", "=", "$", "this", "->", "get_item_tags", "(", "SIMPLEPIE_NAMESPACE_ATOM_03", ",", "'title'", ")", ")", "{", "$", "this", "->", "data", "[", "'title'", "]", "=", "$", "this", "->", "sanitize", "(", "$", "return", "[", "0", "]", "[", "'data'", "]", ",", "$", "this", "->", "registry", "->", "call", "(", "'Misc'", ",", "'atom_03_construct_type'", ",", "array", "(", "$", "return", "[", "0", "]", "[", "'attribs'", "]", ")", ")", ",", "$", "this", "->", "get_base", "(", "$", "return", "[", "0", "]", ")", ")", ";", "}", "elseif", "(", "$", "return", "=", "$", "this", "->", "get_item_tags", "(", "SIMPLEPIE_NAMESPACE_RSS_10", ",", "'title'", ")", ")", "{", "$", "this", "->", "data", "[", "'title'", "]", "=", "$", "this", "->", "sanitize", "(", "$", "return", "[", "0", "]", "[", "'data'", "]", ",", "SIMPLEPIE_CONSTRUCT_MAYBE_HTML", ",", "$", "this", "->", "get_base", "(", "$", "return", "[", "0", "]", ")", ")", ";", "}", "elseif", "(", "$", "return", "=", "$", "this", "->", "get_item_tags", "(", "SIMPLEPIE_NAMESPACE_RSS_090", ",", "'title'", ")", ")", "{", "$", "this", "->", "data", "[", "'title'", "]", "=", "$", "this", "->", "sanitize", "(", "$", "return", "[", "0", "]", "[", "'data'", "]", ",", "SIMPLEPIE_CONSTRUCT_MAYBE_HTML", ",", "$", "this", "->", "get_base", "(", "$", "return", "[", "0", "]", ")", ")", ";", "}", "elseif", "(", "$", "return", "=", "$", "this", "->", "get_item_tags", "(", "SIMPLEPIE_NAMESPACE_RSS_20", ",", "'title'", ")", ")", "{", "$", "this", "->", "data", "[", "'title'", "]", "=", "$", "this", "->", "sanitize", "(", "$", "return", "[", "0", "]", "[", "'data'", "]", ",", "SIMPLEPIE_CONSTRUCT_MAYBE_HTML", ",", "$", "this", "->", "get_base", "(", "$", "return", "[", "0", "]", ")", ")", ";", "}", "elseif", "(", "$", "return", "=", "$", "this", "->", "get_item_tags", "(", "SIMPLEPIE_NAMESPACE_DC_11", ",", "'title'", ")", ")", "{", "$", "this", "->", "data", "[", "'title'", "]", "=", "$", "this", "->", "sanitize", "(", "$", "return", "[", "0", "]", "[", "'data'", "]", ",", "SIMPLEPIE_CONSTRUCT_TEXT", ")", ";", "}", "elseif", "(", "$", "return", "=", "$", "this", "->", "get_item_tags", "(", "SIMPLEPIE_NAMESPACE_DC_10", ",", "'title'", ")", ")", "{", "$", "this", "->", "data", "[", "'title'", "]", "=", "$", "this", "->", "sanitize", "(", "$", "return", "[", "0", "]", "[", "'data'", "]", ",", "SIMPLEPIE_CONSTRUCT_TEXT", ")", ";", "}", "else", "{", "$", "this", "->", "data", "[", "'title'", "]", "=", "null", ";", "}", "}", "return", "$", "this", "->", "data", "[", "'title'", "]", ";", "}" ]
Get the title of the item Uses `<atom:title>`, `<title>` or `<dc:title>` @since Beta 2 (previously called `get_item_title` since 0.8) @return string|null
[ "Get", "the", "title", "of", "the", "item" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Item.php#L262-L300
213,425
moodle/moodle
lib/simplepie/library/SimplePie/Item.php
SimplePie_Item.get_categories
public function get_categories() { $categories = array(); $type = 'category'; foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, $type) as $category) { $term = null; $scheme = null; $label = null; if (isset($category['attribs']['']['term'])) { $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_HTML); } if (isset($category['attribs']['']['scheme'])) { $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_HTML); } if (isset($category['attribs']['']['label'])) { $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_HTML); } $categories[] = $this->registry->create('Category', array($term, $scheme, $label, $type)); } foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, $type) as $category) { // This is really the label, but keep this as the term also for BC. // Label will also work on retrieving because that falls back to term. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML); if (isset($category['attribs']['']['domain'])) { $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_HTML); } else { $scheme = null; } $categories[] = $this->registry->create('Category', array($term, $scheme, null, $type)); } $type = 'subject'; foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, $type) as $category) { $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null, $type)); } foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, $type) as $category) { $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null, $type)); } if (!empty($categories)) { return array_unique($categories); } else { return null; } }
php
public function get_categories() { $categories = array(); $type = 'category'; foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, $type) as $category) { $term = null; $scheme = null; $label = null; if (isset($category['attribs']['']['term'])) { $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_HTML); } if (isset($category['attribs']['']['scheme'])) { $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_HTML); } if (isset($category['attribs']['']['label'])) { $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_HTML); } $categories[] = $this->registry->create('Category', array($term, $scheme, $label, $type)); } foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, $type) as $category) { // This is really the label, but keep this as the term also for BC. // Label will also work on retrieving because that falls back to term. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML); if (isset($category['attribs']['']['domain'])) { $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_HTML); } else { $scheme = null; } $categories[] = $this->registry->create('Category', array($term, $scheme, null, $type)); } $type = 'subject'; foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, $type) as $category) { $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null, $type)); } foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, $type) as $category) { $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null, $type)); } if (!empty($categories)) { return array_unique($categories); } else { return null; } }
[ "public", "function", "get_categories", "(", ")", "{", "$", "categories", "=", "array", "(", ")", ";", "$", "type", "=", "'category'", ";", "foreach", "(", "(", "array", ")", "$", "this", "->", "get_item_tags", "(", "SIMPLEPIE_NAMESPACE_ATOM_10", ",", "$", "type", ")", "as", "$", "category", ")", "{", "$", "term", "=", "null", ";", "$", "scheme", "=", "null", ";", "$", "label", "=", "null", ";", "if", "(", "isset", "(", "$", "category", "[", "'attribs'", "]", "[", "''", "]", "[", "'term'", "]", ")", ")", "{", "$", "term", "=", "$", "this", "->", "sanitize", "(", "$", "category", "[", "'attribs'", "]", "[", "''", "]", "[", "'term'", "]", ",", "SIMPLEPIE_CONSTRUCT_HTML", ")", ";", "}", "if", "(", "isset", "(", "$", "category", "[", "'attribs'", "]", "[", "''", "]", "[", "'scheme'", "]", ")", ")", "{", "$", "scheme", "=", "$", "this", "->", "sanitize", "(", "$", "category", "[", "'attribs'", "]", "[", "''", "]", "[", "'scheme'", "]", ",", "SIMPLEPIE_CONSTRUCT_HTML", ")", ";", "}", "if", "(", "isset", "(", "$", "category", "[", "'attribs'", "]", "[", "''", "]", "[", "'label'", "]", ")", ")", "{", "$", "label", "=", "$", "this", "->", "sanitize", "(", "$", "category", "[", "'attribs'", "]", "[", "''", "]", "[", "'label'", "]", ",", "SIMPLEPIE_CONSTRUCT_HTML", ")", ";", "}", "$", "categories", "[", "]", "=", "$", "this", "->", "registry", "->", "create", "(", "'Category'", ",", "array", "(", "$", "term", ",", "$", "scheme", ",", "$", "label", ",", "$", "type", ")", ")", ";", "}", "foreach", "(", "(", "array", ")", "$", "this", "->", "get_item_tags", "(", "SIMPLEPIE_NAMESPACE_RSS_20", ",", "$", "type", ")", "as", "$", "category", ")", "{", "// This is really the label, but keep this as the term also for BC.", "// Label will also work on retrieving because that falls back to term.", "$", "term", "=", "$", "this", "->", "sanitize", "(", "$", "category", "[", "'data'", "]", ",", "SIMPLEPIE_CONSTRUCT_HTML", ")", ";", "if", "(", "isset", "(", "$", "category", "[", "'attribs'", "]", "[", "''", "]", "[", "'domain'", "]", ")", ")", "{", "$", "scheme", "=", "$", "this", "->", "sanitize", "(", "$", "category", "[", "'attribs'", "]", "[", "''", "]", "[", "'domain'", "]", ",", "SIMPLEPIE_CONSTRUCT_HTML", ")", ";", "}", "else", "{", "$", "scheme", "=", "null", ";", "}", "$", "categories", "[", "]", "=", "$", "this", "->", "registry", "->", "create", "(", "'Category'", ",", "array", "(", "$", "term", ",", "$", "scheme", ",", "null", ",", "$", "type", ")", ")", ";", "}", "$", "type", "=", "'subject'", ";", "foreach", "(", "(", "array", ")", "$", "this", "->", "get_item_tags", "(", "SIMPLEPIE_NAMESPACE_DC_11", ",", "$", "type", ")", "as", "$", "category", ")", "{", "$", "categories", "[", "]", "=", "$", "this", "->", "registry", "->", "create", "(", "'Category'", ",", "array", "(", "$", "this", "->", "sanitize", "(", "$", "category", "[", "'data'", "]", ",", "SIMPLEPIE_CONSTRUCT_HTML", ")", ",", "null", ",", "null", ",", "$", "type", ")", ")", ";", "}", "foreach", "(", "(", "array", ")", "$", "this", "->", "get_item_tags", "(", "SIMPLEPIE_NAMESPACE_DC_10", ",", "$", "type", ")", "as", "$", "category", ")", "{", "$", "categories", "[", "]", "=", "$", "this", "->", "registry", "->", "create", "(", "'Category'", ",", "array", "(", "$", "this", "->", "sanitize", "(", "$", "category", "[", "'data'", "]", ",", "SIMPLEPIE_CONSTRUCT_HTML", ")", ",", "null", ",", "null", ",", "$", "type", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "categories", ")", ")", "{", "return", "array_unique", "(", "$", "categories", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Get all categories for the item Uses `<atom:category>`, `<category>` or `<dc:subject>` @since Beta 3 @return SimplePie_Category[]|null List of {@see SimplePie_Category} objects
[ "Get", "all", "categories", "for", "the", "item" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Item.php#L468-L526
213,426
moodle/moodle
lib/simplepie/library/SimplePie/Item.php
SimplePie_Item.get_link
public function get_link($key = 0, $rel = 'alternate') { $links = $this->get_links($rel); if ($links[$key] !== null) { return $links[$key]; } else { return null; } }
php
public function get_link($key = 0, $rel = 'alternate') { $links = $this->get_links($rel); if ($links[$key] !== null) { return $links[$key]; } else { return null; } }
[ "public", "function", "get_link", "(", "$", "key", "=", "0", ",", "$", "rel", "=", "'alternate'", ")", "{", "$", "links", "=", "$", "this", "->", "get_links", "(", "$", "rel", ")", ";", "if", "(", "$", "links", "[", "$", "key", "]", "!==", "null", ")", "{", "return", "$", "links", "[", "$", "key", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Get a single link for the item @since Beta 3 @param int $key The link that you want to return. Remember that arrays begin with 0, not 1 @param string $rel The relationship of the link to return @return string|null Link URL
[ "Get", "a", "single", "link", "for", "the", "item" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Item.php#L986-L997
213,427
moodle/moodle
lib/simplepie/library/SimplePie/Item.php
SimplePie_Item.get_enclosure
public function get_enclosure($key = 0, $prefer = null) { $enclosures = $this->get_enclosures(); if (isset($enclosures[$key])) { return $enclosures[$key]; } else { return null; } }
php
public function get_enclosure($key = 0, $prefer = null) { $enclosures = $this->get_enclosures(); if (isset($enclosures[$key])) { return $enclosures[$key]; } else { return null; } }
[ "public", "function", "get_enclosure", "(", "$", "key", "=", "0", ",", "$", "prefer", "=", "null", ")", "{", "$", "enclosures", "=", "$", "this", "->", "get_enclosures", "(", ")", ";", "if", "(", "isset", "(", "$", "enclosures", "[", "$", "key", "]", ")", ")", "{", "return", "$", "enclosures", "[", "$", "key", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Get an enclosure from the item Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS. @since Beta 2 @todo Add ability to prefer one type of content over another (in a media group). @param int $key The enclosure that you want to return. Remember that arrays begin with 0, not 1 @return SimplePie_Enclosure|null
[ "Get", "an", "enclosure", "from", "the", "item" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Item.php#L1092-L1103
213,428
moodle/moodle
mod/forum/classes/local/entities/forum.php
forum.is_discussion_time_locked
public function is_discussion_time_locked(discussion_entity $discussion) : bool { if (!$this->has_lock_discussions_after()) { return false; } if ($this->get_type() === 'single') { // It does not make sense to lock a single discussion forum. return false; } return (($discussion->get_time_modified() + $this->get_lock_discussions_after()) < time()); }
php
public function is_discussion_time_locked(discussion_entity $discussion) : bool { if (!$this->has_lock_discussions_after()) { return false; } if ($this->get_type() === 'single') { // It does not make sense to lock a single discussion forum. return false; } return (($discussion->get_time_modified() + $this->get_lock_discussions_after()) < time()); }
[ "public", "function", "is_discussion_time_locked", "(", "discussion_entity", "$", "discussion", ")", ":", "bool", "{", "if", "(", "!", "$", "this", "->", "has_lock_discussions_after", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "get_type", "(", ")", "===", "'single'", ")", "{", "// It does not make sense to lock a single discussion forum.", "return", "false", ";", "}", "return", "(", "(", "$", "discussion", "->", "get_time_modified", "(", ")", "+", "$", "this", "->", "get_lock_discussions_after", "(", ")", ")", "<", "time", "(", ")", ")", ";", "}" ]
Check whether the discussion is locked based on forum's time based locking criteria @param discussion_entity $discussion @return bool
[ "Check", "whether", "the", "discussion", "is", "locked", "based", "on", "forum", "s", "time", "based", "locking", "criteria" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/entities/forum.php#L547-L558
213,429
moodle/moodle
mod/forum/classes/local/entities/forum.php
forum.is_discussion_locked
public function is_discussion_locked(discussion_entity $discussion) : bool { if ($discussion->is_locked()) { return true; } return $this->is_discussion_time_locked($discussion); }
php
public function is_discussion_locked(discussion_entity $discussion) : bool { if ($discussion->is_locked()) { return true; } return $this->is_discussion_time_locked($discussion); }
[ "public", "function", "is_discussion_locked", "(", "discussion_entity", "$", "discussion", ")", ":", "bool", "{", "if", "(", "$", "discussion", "->", "is_locked", "(", ")", ")", "{", "return", "true", ";", "}", "return", "$", "this", "->", "is_discussion_time_locked", "(", "$", "discussion", ")", ";", "}" ]
Is the discussion locked? - Takes into account both discussion settings AND forum's criteria @param discussion_entity $discussion The discussion to check @return bool
[ "Is", "the", "discussion", "locked?", "-", "Takes", "into", "account", "both", "discussion", "settings", "AND", "forum", "s", "criteria" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/entities/forum.php#L628-L634
213,430
moodle/moodle
repository/nextcloud/lib.php
repository_nextcloud.get_system_oauth_client
private function get_system_oauth_client() { if ($this->systemoauthclient === false) { try { $this->systemoauthclient = \core\oauth2\api::get_system_oauth_client($this->issuer); } catch (\moodle_exception $e) { $this->systemoauthclient = false; } } return $this->systemoauthclient; }
php
private function get_system_oauth_client() { if ($this->systemoauthclient === false) { try { $this->systemoauthclient = \core\oauth2\api::get_system_oauth_client($this->issuer); } catch (\moodle_exception $e) { $this->systemoauthclient = false; } } return $this->systemoauthclient; }
[ "private", "function", "get_system_oauth_client", "(", ")", "{", "if", "(", "$", "this", "->", "systemoauthclient", "===", "false", ")", "{", "try", "{", "$", "this", "->", "systemoauthclient", "=", "\\", "core", "\\", "oauth2", "\\", "api", "::", "get_system_oauth_client", "(", "$", "this", "->", "issuer", ")", ";", "}", "catch", "(", "\\", "moodle_exception", "$", "e", ")", "{", "$", "this", "->", "systemoauthclient", "=", "false", ";", "}", "}", "return", "$", "this", "->", "systemoauthclient", ";", "}" ]
Get or initialise an oauth client for the system account. @return false|oauth2_client False if initialisation was unsuccessful, otherwise an initialised client.
[ "Get", "or", "initialise", "an", "oauth", "client", "for", "the", "system", "account", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/lib.php#L153-L162
213,431
moodle/moodle
repository/nextcloud/lib.php
repository_nextcloud.get_system_ocs_client
private function get_system_ocs_client() { if ($this->systemocsclient === null) { try { $systemoauth = $this->get_system_oauth_client(); if (!$systemoauth) { return null; } $this->systemocsclient = new ocs_client($systemoauth); } catch (\moodle_exception $e) { $this->systemocsclient = null; } } return $this->systemocsclient; }
php
private function get_system_ocs_client() { if ($this->systemocsclient === null) { try { $systemoauth = $this->get_system_oauth_client(); if (!$systemoauth) { return null; } $this->systemocsclient = new ocs_client($systemoauth); } catch (\moodle_exception $e) { $this->systemocsclient = null; } } return $this->systemocsclient; }
[ "private", "function", "get_system_ocs_client", "(", ")", "{", "if", "(", "$", "this", "->", "systemocsclient", "===", "null", ")", "{", "try", "{", "$", "systemoauth", "=", "$", "this", "->", "get_system_oauth_client", "(", ")", ";", "if", "(", "!", "$", "systemoauth", ")", "{", "return", "null", ";", "}", "$", "this", "->", "systemocsclient", "=", "new", "ocs_client", "(", "$", "systemoauth", ")", ";", "}", "catch", "(", "\\", "moodle_exception", "$", "e", ")", "{", "$", "this", "->", "systemocsclient", "=", "null", ";", "}", "}", "return", "$", "this", "->", "systemocsclient", ";", "}" ]
Get or initialise an ocs client for the system account. @return null|ocs_client Null if initialisation was unsuccessful, otherwise an initialised client.
[ "Get", "or", "initialise", "an", "ocs", "client", "for", "the", "system", "account", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/lib.php#L169-L182
213,432
moodle/moodle
repository/nextcloud/lib.php
repository_nextcloud.initiate_webdavclient
private function initiate_webdavclient() { if ($this->dav !== null) { return $this->dav; } $webdavendpoint = issuer_management::parse_endpoint_url('webdav', $this->issuer); // Selects the necessary information (port, type, server) from the path to build the webdavclient. $server = $webdavendpoint['host']; if ($webdavendpoint['scheme'] === 'https') { $webdavtype = 'ssl://'; $webdavport = 443; } else if ($webdavendpoint['scheme'] === 'http') { $webdavtype = ''; $webdavport = 80; } // Override default port, if a specific one is set. if (isset($webdavendpoint['port'])) { $webdavport = $webdavendpoint['port']; } // Authentication method is `bearer` for OAuth 2. Pass token of authenticated client, too. $this->dav = new \webdav_client($server, '', '', 'bearer', $webdavtype, $this->get_user_oauth_client()->get_accesstoken()->token); $this->dav->port = $webdavport; $this->dav->debug = false; return $this->dav; }
php
private function initiate_webdavclient() { if ($this->dav !== null) { return $this->dav; } $webdavendpoint = issuer_management::parse_endpoint_url('webdav', $this->issuer); // Selects the necessary information (port, type, server) from the path to build the webdavclient. $server = $webdavendpoint['host']; if ($webdavendpoint['scheme'] === 'https') { $webdavtype = 'ssl://'; $webdavport = 443; } else if ($webdavendpoint['scheme'] === 'http') { $webdavtype = ''; $webdavport = 80; } // Override default port, if a specific one is set. if (isset($webdavendpoint['port'])) { $webdavport = $webdavendpoint['port']; } // Authentication method is `bearer` for OAuth 2. Pass token of authenticated client, too. $this->dav = new \webdav_client($server, '', '', 'bearer', $webdavtype, $this->get_user_oauth_client()->get_accesstoken()->token); $this->dav->port = $webdavport; $this->dav->debug = false; return $this->dav; }
[ "private", "function", "initiate_webdavclient", "(", ")", "{", "if", "(", "$", "this", "->", "dav", "!==", "null", ")", "{", "return", "$", "this", "->", "dav", ";", "}", "$", "webdavendpoint", "=", "issuer_management", "::", "parse_endpoint_url", "(", "'webdav'", ",", "$", "this", "->", "issuer", ")", ";", "// Selects the necessary information (port, type, server) from the path to build the webdavclient.", "$", "server", "=", "$", "webdavendpoint", "[", "'host'", "]", ";", "if", "(", "$", "webdavendpoint", "[", "'scheme'", "]", "===", "'https'", ")", "{", "$", "webdavtype", "=", "'ssl://'", ";", "$", "webdavport", "=", "443", ";", "}", "else", "if", "(", "$", "webdavendpoint", "[", "'scheme'", "]", "===", "'http'", ")", "{", "$", "webdavtype", "=", "''", ";", "$", "webdavport", "=", "80", ";", "}", "// Override default port, if a specific one is set.", "if", "(", "isset", "(", "$", "webdavendpoint", "[", "'port'", "]", ")", ")", "{", "$", "webdavport", "=", "$", "webdavendpoint", "[", "'port'", "]", ";", "}", "// Authentication method is `bearer` for OAuth 2. Pass token of authenticated client, too.", "$", "this", "->", "dav", "=", "new", "\\", "webdav_client", "(", "$", "server", ",", "''", ",", "''", ",", "'bearer'", ",", "$", "webdavtype", ",", "$", "this", "->", "get_user_oauth_client", "(", ")", "->", "get_accesstoken", "(", ")", "->", "token", ")", ";", "$", "this", "->", "dav", "->", "port", "=", "$", "webdavport", ";", "$", "this", "->", "dav", "->", "debug", "=", "false", ";", "return", "$", "this", "->", "dav", ";", "}" ]
Initiates the webdav client. @throws \repository_nextcloud\configuration_exception If configuration is missing (endpoints).
[ "Initiates", "the", "webdav", "client", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/lib.php#L189-L218
213,433
moodle/moodle
repository/nextcloud/lib.php
repository_nextcloud.get_link
public function get_link($url) { $ocsparams = [ 'path' => $url, 'shareType' => ocs_client::SHARE_TYPE_PUBLIC, 'publicUpload' => false, 'permissions' => ocs_client::SHARE_PERMISSION_READ ]; $response = $this->ocsclient->call('create_share', $ocsparams); $xml = simplexml_load_string($response); if ($xml === false ) { throw new \repository_nextcloud\request_exception(array('instance' => $this->get_name(), 'errormessage' => get_string('invalidresponse', 'repository_nextcloud'))); } if ((string)$xml->meta->status !== 'ok') { throw new \repository_nextcloud\request_exception(array('instance' => $this->get_name(), 'errormessage' => sprintf( '(%s) %s', $xml->meta->statuscode, $xml->meta->message))); } // Take the share link and convert it into a download link. return ((string)$xml->data[0]->url) . '/download'; }
php
public function get_link($url) { $ocsparams = [ 'path' => $url, 'shareType' => ocs_client::SHARE_TYPE_PUBLIC, 'publicUpload' => false, 'permissions' => ocs_client::SHARE_PERMISSION_READ ]; $response = $this->ocsclient->call('create_share', $ocsparams); $xml = simplexml_load_string($response); if ($xml === false ) { throw new \repository_nextcloud\request_exception(array('instance' => $this->get_name(), 'errormessage' => get_string('invalidresponse', 'repository_nextcloud'))); } if ((string)$xml->meta->status !== 'ok') { throw new \repository_nextcloud\request_exception(array('instance' => $this->get_name(), 'errormessage' => sprintf( '(%s) %s', $xml->meta->statuscode, $xml->meta->message))); } // Take the share link and convert it into a download link. return ((string)$xml->data[0]->url) . '/download'; }
[ "public", "function", "get_link", "(", "$", "url", ")", "{", "$", "ocsparams", "=", "[", "'path'", "=>", "$", "url", ",", "'shareType'", "=>", "ocs_client", "::", "SHARE_TYPE_PUBLIC", ",", "'publicUpload'", "=>", "false", ",", "'permissions'", "=>", "ocs_client", "::", "SHARE_PERMISSION_READ", "]", ";", "$", "response", "=", "$", "this", "->", "ocsclient", "->", "call", "(", "'create_share'", ",", "$", "ocsparams", ")", ";", "$", "xml", "=", "simplexml_load_string", "(", "$", "response", ")", ";", "if", "(", "$", "xml", "===", "false", ")", "{", "throw", "new", "\\", "repository_nextcloud", "\\", "request_exception", "(", "array", "(", "'instance'", "=>", "$", "this", "->", "get_name", "(", ")", ",", "'errormessage'", "=>", "get_string", "(", "'invalidresponse'", ",", "'repository_nextcloud'", ")", ")", ")", ";", "}", "if", "(", "(", "string", ")", "$", "xml", "->", "meta", "->", "status", "!==", "'ok'", ")", "{", "throw", "new", "\\", "repository_nextcloud", "\\", "request_exception", "(", "array", "(", "'instance'", "=>", "$", "this", "->", "get_name", "(", ")", ",", "'errormessage'", "=>", "sprintf", "(", "'(%s) %s'", ",", "$", "xml", "->", "meta", "->", "statuscode", ",", "$", "xml", "->", "meta", "->", "message", ")", ")", ")", ";", "}", "// Take the share link and convert it into a download link.", "return", "(", "(", "string", ")", "$", "xml", "->", "data", "[", "0", "]", "->", "url", ")", ".", "'/download'", ";", "}" ]
Use OCS to generate a public share to the requested file. This method derives a download link from the public share URL. @param string $url relative path to the chosen file @return string the generated download link. @throws \repository_nextcloud\request_exception If nextcloud responded badly
[ "Use", "OCS", "to", "generate", "a", "public", "share", "to", "the", "requested", "file", ".", "This", "method", "derives", "a", "download", "link", "from", "the", "public", "share", "URL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/lib.php#L293-L316
213,434
moodle/moodle
repository/nextcloud/lib.php
repository_nextcloud.get_user_oauth_client
protected function get_user_oauth_client($overrideurl = false) { if ($this->client) { return $this->client; } if ($overrideurl) { $returnurl = $overrideurl; } else { $returnurl = new moodle_url('/repository/repository_callback.php'); $returnurl->param('callback', 'yes'); $returnurl->param('repo_id', $this->id); $returnurl->param('sesskey', sesskey()); } $this->client = \core\oauth2\api::get_user_oauth_client($this->issuer, $returnurl, self::SCOPES); return $this->client; }
php
protected function get_user_oauth_client($overrideurl = false) { if ($this->client) { return $this->client; } if ($overrideurl) { $returnurl = $overrideurl; } else { $returnurl = new moodle_url('/repository/repository_callback.php'); $returnurl->param('callback', 'yes'); $returnurl->param('repo_id', $this->id); $returnurl->param('sesskey', sesskey()); } $this->client = \core\oauth2\api::get_user_oauth_client($this->issuer, $returnurl, self::SCOPES); return $this->client; }
[ "protected", "function", "get_user_oauth_client", "(", "$", "overrideurl", "=", "false", ")", "{", "if", "(", "$", "this", "->", "client", ")", "{", "return", "$", "this", "->", "client", ";", "}", "if", "(", "$", "overrideurl", ")", "{", "$", "returnurl", "=", "$", "overrideurl", ";", "}", "else", "{", "$", "returnurl", "=", "new", "moodle_url", "(", "'/repository/repository_callback.php'", ")", ";", "$", "returnurl", "->", "param", "(", "'callback'", ",", "'yes'", ")", ";", "$", "returnurl", "->", "param", "(", "'repo_id'", ",", "$", "this", "->", "id", ")", ";", "$", "returnurl", "->", "param", "(", "'sesskey'", ",", "sesskey", "(", ")", ")", ";", "}", "$", "this", "->", "client", "=", "\\", "core", "\\", "oauth2", "\\", "api", "::", "get_user_oauth_client", "(", "$", "this", "->", "issuer", ",", "$", "returnurl", ",", "self", "::", "SCOPES", ")", ";", "return", "$", "this", "->", "client", ";", "}" ]
Get a cached user authenticated oauth client. @param bool|moodle_url $overrideurl Use this url instead of the repo callback. @return \core\oauth2\client
[ "Get", "a", "cached", "user", "authenticated", "oauth", "client", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/lib.php#L565-L579
213,435
moodle/moodle
repository/nextcloud/lib.php
repository_nextcloud.print_login
public function print_login() { $client = $this->get_user_oauth_client(); $loginurl = $client->get_login_url(); if ($this->options['ajax']) { $ret = array(); $btn = new \stdClass(); $btn->type = 'popup'; $btn->url = $loginurl->out(false); $ret['login'] = array($btn); return $ret; } else { echo html_writer::link($loginurl, get_string('login', 'repository'), array('target' => '_blank', 'rel' => 'noopener noreferrer')); } }
php
public function print_login() { $client = $this->get_user_oauth_client(); $loginurl = $client->get_login_url(); if ($this->options['ajax']) { $ret = array(); $btn = new \stdClass(); $btn->type = 'popup'; $btn->url = $loginurl->out(false); $ret['login'] = array($btn); return $ret; } else { echo html_writer::link($loginurl, get_string('login', 'repository'), array('target' => '_blank', 'rel' => 'noopener noreferrer')); } }
[ "public", "function", "print_login", "(", ")", "{", "$", "client", "=", "$", "this", "->", "get_user_oauth_client", "(", ")", ";", "$", "loginurl", "=", "$", "client", "->", "get_login_url", "(", ")", ";", "if", "(", "$", "this", "->", "options", "[", "'ajax'", "]", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "$", "btn", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "btn", "->", "type", "=", "'popup'", ";", "$", "btn", "->", "url", "=", "$", "loginurl", "->", "out", "(", "false", ")", ";", "$", "ret", "[", "'login'", "]", "=", "array", "(", "$", "btn", ")", ";", "return", "$", "ret", ";", "}", "else", "{", "echo", "html_writer", "::", "link", "(", "$", "loginurl", ",", "get_string", "(", "'login'", ",", "'repository'", ")", ",", "array", "(", "'target'", "=>", "'_blank'", ",", "'rel'", "=>", "'noopener noreferrer'", ")", ")", ";", "}", "}" ]
Prints a simple Login Button which redirects to an authorization window from Nextcloud. @return mixed login window properties. @throws coding_exception
[ "Prints", "a", "simple", "Login", "Button", "which", "redirects", "to", "an", "authorization", "window", "from", "Nextcloud", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/lib.php#L587-L601
213,436
moodle/moodle
repository/nextcloud/lib.php
repository_nextcloud.instance_config_form
public static function instance_config_form($mform) { if (!has_capability('moodle/site:config', context_system::instance())) { $mform->addElement('static', null, '', get_string('nopermissions', 'error', get_string('configplugin', 'repository_nextcloud'))); return false; } // Load configured issuers. $issuers = core\oauth2\api::get_all_issuers(); $types = array(); // Validates which issuers implement the right endpoints. WebDav is necessary for Nextcloud. $validissuers = []; foreach ($issuers as $issuer) { $types[$issuer->get('id')] = $issuer->get('name'); if (\repository_nextcloud\issuer_management::is_valid_issuer($issuer)) { $validissuers[] = $issuer->get('name'); } } // Render the form. $url = new \moodle_url('/admin/tool/oauth2/issuers.php'); $mform->addElement('static', null, '', get_string('oauth2serviceslink', 'repository_nextcloud', $url->out())); $mform->addElement('select', 'issuerid', get_string('chooseissuer', 'repository_nextcloud'), $types); $mform->addRule('issuerid', get_string('required'), 'required', null, 'issuer'); $mform->addHelpButton('issuerid', 'chooseissuer', 'repository_nextcloud'); $mform->setType('issuerid', PARAM_INT); // All issuers that are valid are displayed seperately (if any). if (count($validissuers) === 0) { $mform->addElement('static', null, '', get_string('no_right_issuers', 'repository_nextcloud')); } else { $mform->addElement('static', null, '', get_string('right_issuers', 'repository_nextcloud', implode(', ', $validissuers))); } $mform->addElement('text', 'controlledlinkfoldername', get_string('foldername', 'repository_nextcloud')); $mform->addHelpButton('controlledlinkfoldername', 'foldername', 'repository_nextcloud'); $mform->setType('controlledlinkfoldername', PARAM_TEXT); $mform->setDefault('controlledlinkfoldername', 'Moodlefiles'); $mform->addElement('static', null, '', get_string('fileoptions', 'repository_nextcloud')); $choices = [ 'both' => get_string('both', 'repository_nextcloud'), 'internal' => get_string('internal', 'repository_nextcloud'), 'external' => get_string('external', 'repository_nextcloud'), ]; $mform->addElement('select', 'supportedreturntypes', get_string('supportedreturntypes', 'repository_nextcloud'), $choices); $choices = [ FILE_INTERNAL => get_string('internal', 'repository_nextcloud'), FILE_CONTROLLED_LINK => get_string('external', 'repository_nextcloud'), ]; $mform->addElement('select', 'defaultreturntype', get_string('defaultreturntype', 'repository_nextcloud'), $choices); }
php
public static function instance_config_form($mform) { if (!has_capability('moodle/site:config', context_system::instance())) { $mform->addElement('static', null, '', get_string('nopermissions', 'error', get_string('configplugin', 'repository_nextcloud'))); return false; } // Load configured issuers. $issuers = core\oauth2\api::get_all_issuers(); $types = array(); // Validates which issuers implement the right endpoints. WebDav is necessary for Nextcloud. $validissuers = []; foreach ($issuers as $issuer) { $types[$issuer->get('id')] = $issuer->get('name'); if (\repository_nextcloud\issuer_management::is_valid_issuer($issuer)) { $validissuers[] = $issuer->get('name'); } } // Render the form. $url = new \moodle_url('/admin/tool/oauth2/issuers.php'); $mform->addElement('static', null, '', get_string('oauth2serviceslink', 'repository_nextcloud', $url->out())); $mform->addElement('select', 'issuerid', get_string('chooseissuer', 'repository_nextcloud'), $types); $mform->addRule('issuerid', get_string('required'), 'required', null, 'issuer'); $mform->addHelpButton('issuerid', 'chooseissuer', 'repository_nextcloud'); $mform->setType('issuerid', PARAM_INT); // All issuers that are valid are displayed seperately (if any). if (count($validissuers) === 0) { $mform->addElement('static', null, '', get_string('no_right_issuers', 'repository_nextcloud')); } else { $mform->addElement('static', null, '', get_string('right_issuers', 'repository_nextcloud', implode(', ', $validissuers))); } $mform->addElement('text', 'controlledlinkfoldername', get_string('foldername', 'repository_nextcloud')); $mform->addHelpButton('controlledlinkfoldername', 'foldername', 'repository_nextcloud'); $mform->setType('controlledlinkfoldername', PARAM_TEXT); $mform->setDefault('controlledlinkfoldername', 'Moodlefiles'); $mform->addElement('static', null, '', get_string('fileoptions', 'repository_nextcloud')); $choices = [ 'both' => get_string('both', 'repository_nextcloud'), 'internal' => get_string('internal', 'repository_nextcloud'), 'external' => get_string('external', 'repository_nextcloud'), ]; $mform->addElement('select', 'supportedreturntypes', get_string('supportedreturntypes', 'repository_nextcloud'), $choices); $choices = [ FILE_INTERNAL => get_string('internal', 'repository_nextcloud'), FILE_CONTROLLED_LINK => get_string('external', 'repository_nextcloud'), ]; $mform->addElement('select', 'defaultreturntype', get_string('defaultreturntype', 'repository_nextcloud'), $choices); }
[ "public", "static", "function", "instance_config_form", "(", "$", "mform", ")", "{", "if", "(", "!", "has_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ")", "{", "$", "mform", "->", "addElement", "(", "'static'", ",", "null", ",", "''", ",", "get_string", "(", "'nopermissions'", ",", "'error'", ",", "get_string", "(", "'configplugin'", ",", "'repository_nextcloud'", ")", ")", ")", ";", "return", "false", ";", "}", "// Load configured issuers.", "$", "issuers", "=", "core", "\\", "oauth2", "\\", "api", "::", "get_all_issuers", "(", ")", ";", "$", "types", "=", "array", "(", ")", ";", "// Validates which issuers implement the right endpoints. WebDav is necessary for Nextcloud.", "$", "validissuers", "=", "[", "]", ";", "foreach", "(", "$", "issuers", "as", "$", "issuer", ")", "{", "$", "types", "[", "$", "issuer", "->", "get", "(", "'id'", ")", "]", "=", "$", "issuer", "->", "get", "(", "'name'", ")", ";", "if", "(", "\\", "repository_nextcloud", "\\", "issuer_management", "::", "is_valid_issuer", "(", "$", "issuer", ")", ")", "{", "$", "validissuers", "[", "]", "=", "$", "issuer", "->", "get", "(", "'name'", ")", ";", "}", "}", "// Render the form.", "$", "url", "=", "new", "\\", "moodle_url", "(", "'/admin/tool/oauth2/issuers.php'", ")", ";", "$", "mform", "->", "addElement", "(", "'static'", ",", "null", ",", "''", ",", "get_string", "(", "'oauth2serviceslink'", ",", "'repository_nextcloud'", ",", "$", "url", "->", "out", "(", ")", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'issuerid'", ",", "get_string", "(", "'chooseissuer'", ",", "'repository_nextcloud'", ")", ",", "$", "types", ")", ";", "$", "mform", "->", "addRule", "(", "'issuerid'", ",", "get_string", "(", "'required'", ")", ",", "'required'", ",", "null", ",", "'issuer'", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'issuerid'", ",", "'chooseissuer'", ",", "'repository_nextcloud'", ")", ";", "$", "mform", "->", "setType", "(", "'issuerid'", ",", "PARAM_INT", ")", ";", "// All issuers that are valid are displayed seperately (if any).", "if", "(", "count", "(", "$", "validissuers", ")", "===", "0", ")", "{", "$", "mform", "->", "addElement", "(", "'static'", ",", "null", ",", "''", ",", "get_string", "(", "'no_right_issuers'", ",", "'repository_nextcloud'", ")", ")", ";", "}", "else", "{", "$", "mform", "->", "addElement", "(", "'static'", ",", "null", ",", "''", ",", "get_string", "(", "'right_issuers'", ",", "'repository_nextcloud'", ",", "implode", "(", "', '", ",", "$", "validissuers", ")", ")", ")", ";", "}", "$", "mform", "->", "addElement", "(", "'text'", ",", "'controlledlinkfoldername'", ",", "get_string", "(", "'foldername'", ",", "'repository_nextcloud'", ")", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'controlledlinkfoldername'", ",", "'foldername'", ",", "'repository_nextcloud'", ")", ";", "$", "mform", "->", "setType", "(", "'controlledlinkfoldername'", ",", "PARAM_TEXT", ")", ";", "$", "mform", "->", "setDefault", "(", "'controlledlinkfoldername'", ",", "'Moodlefiles'", ")", ";", "$", "mform", "->", "addElement", "(", "'static'", ",", "null", ",", "''", ",", "get_string", "(", "'fileoptions'", ",", "'repository_nextcloud'", ")", ")", ";", "$", "choices", "=", "[", "'both'", "=>", "get_string", "(", "'both'", ",", "'repository_nextcloud'", ")", ",", "'internal'", "=>", "get_string", "(", "'internal'", ",", "'repository_nextcloud'", ")", ",", "'external'", "=>", "get_string", "(", "'external'", ",", "'repository_nextcloud'", ")", ",", "]", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'supportedreturntypes'", ",", "get_string", "(", "'supportedreturntypes'", ",", "'repository_nextcloud'", ")", ",", "$", "choices", ")", ";", "$", "choices", "=", "[", "FILE_INTERNAL", "=>", "get_string", "(", "'internal'", ",", "'repository_nextcloud'", ")", ",", "FILE_CONTROLLED_LINK", "=>", "get_string", "(", "'external'", ",", "'repository_nextcloud'", ")", ",", "]", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'defaultreturntype'", ",", "get_string", "(", "'defaultreturntype'", ",", "'repository_nextcloud'", ")", ",", "$", "choices", ")", ";", "}" ]
This method adds a select form and additional information to the settings form.. @param \moodleform $mform Moodle form (passed by reference) @return bool|void @throws coding_exception @throws dml_exception
[ "This", "method", "adds", "a", "select", "form", "and", "additional", "information", "to", "the", "settings", "form", ".." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/lib.php#L652-L707
213,437
moodle/moodle
repository/nextcloud/lib.php
repository_nextcloud.get_listing_prepare_response
private function get_listing_prepare_response($path) { $ret = [ // Fetch the list dynamically. An AJAX request is sent to the server as soon as the user opens a folder. 'dynload' => true, 'nosearch' => true, // Disable search. 'nologin' => false, // Provide a login link because a user logs into his/her private Nextcloud storage. 'path' => array([ // Contains all parent paths to the current path. 'name' => $this->get_meta()->name, 'path' => '', ]), 'defaultreturntype' => $this->default_returntype(), 'manage' => $this->issuer->get('baseurl'), // Provide button to go into file management interface quickly. 'list' => array(), // Contains all file/folder information and is required to build the file/folder tree. ]; // If relative path is a non-top-level path, calculate all its parents' paths. // This is used for navigation in the file picker. if ($path != '/') { $chunks = explode('/', trim($path, '/')); $parent = '/'; // Every sub-path to the last part of the current path is a parent path. foreach ($chunks as $chunk) { $subpath = $parent . $chunk . '/'; $ret['path'][] = [ 'name' => urldecode($chunk), 'path' => $subpath ]; // Prepare next iteration. $parent = $subpath; } } return $ret; }
php
private function get_listing_prepare_response($path) { $ret = [ // Fetch the list dynamically. An AJAX request is sent to the server as soon as the user opens a folder. 'dynload' => true, 'nosearch' => true, // Disable search. 'nologin' => false, // Provide a login link because a user logs into his/her private Nextcloud storage. 'path' => array([ // Contains all parent paths to the current path. 'name' => $this->get_meta()->name, 'path' => '', ]), 'defaultreturntype' => $this->default_returntype(), 'manage' => $this->issuer->get('baseurl'), // Provide button to go into file management interface quickly. 'list' => array(), // Contains all file/folder information and is required to build the file/folder tree. ]; // If relative path is a non-top-level path, calculate all its parents' paths. // This is used for navigation in the file picker. if ($path != '/') { $chunks = explode('/', trim($path, '/')); $parent = '/'; // Every sub-path to the last part of the current path is a parent path. foreach ($chunks as $chunk) { $subpath = $parent . $chunk . '/'; $ret['path'][] = [ 'name' => urldecode($chunk), 'path' => $subpath ]; // Prepare next iteration. $parent = $subpath; } } return $ret; }
[ "private", "function", "get_listing_prepare_response", "(", "$", "path", ")", "{", "$", "ret", "=", "[", "// Fetch the list dynamically. An AJAX request is sent to the server as soon as the user opens a folder.", "'dynload'", "=>", "true", ",", "'nosearch'", "=>", "true", ",", "// Disable search.", "'nologin'", "=>", "false", ",", "// Provide a login link because a user logs into his/her private Nextcloud storage.", "'path'", "=>", "array", "(", "[", "// Contains all parent paths to the current path.", "'name'", "=>", "$", "this", "->", "get_meta", "(", ")", "->", "name", ",", "'path'", "=>", "''", ",", "]", ")", ",", "'defaultreturntype'", "=>", "$", "this", "->", "default_returntype", "(", ")", ",", "'manage'", "=>", "$", "this", "->", "issuer", "->", "get", "(", "'baseurl'", ")", ",", "// Provide button to go into file management interface quickly.", "'list'", "=>", "array", "(", ")", ",", "// Contains all file/folder information and is required to build the file/folder tree.", "]", ";", "// If relative path is a non-top-level path, calculate all its parents' paths.", "// This is used for navigation in the file picker.", "if", "(", "$", "path", "!=", "'/'", ")", "{", "$", "chunks", "=", "explode", "(", "'/'", ",", "trim", "(", "$", "path", ",", "'/'", ")", ")", ";", "$", "parent", "=", "'/'", ";", "// Every sub-path to the last part of the current path is a parent path.", "foreach", "(", "$", "chunks", "as", "$", "chunk", ")", "{", "$", "subpath", "=", "$", "parent", ".", "$", "chunk", ".", "'/'", ";", "$", "ret", "[", "'path'", "]", "[", "]", "=", "[", "'name'", "=>", "urldecode", "(", "$", "chunk", ")", ",", "'path'", "=>", "$", "subpath", "]", ";", "// Prepare next iteration.", "$", "parent", "=", "$", "subpath", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Prepare response of get_listing; namely - defining setting elements, - filling in the parent path of the currently-viewed directory. @param string $path Relative path @return array ret array for use as get_listing's $ret
[ "Prepare", "response", "of", "get_listing", ";", "namely", "-", "defining", "setting", "elements", "-", "filling", "in", "the", "parent", "path", "of", "the", "currently", "-", "viewed", "directory", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/lib.php#L856-L888
213,438
moodle/moodle
repository/nextcloud/lib.php
repository_nextcloud.get_reference_details
public function get_reference_details($reference, $filestatus = 0) { if ($this->disabled) { throw new repository_exception('cannotdownload', 'repository'); } if (empty($reference)) { return get_string('unknownsource', 'repository'); } $source = json_decode($reference); $path = ''; if (!empty($source->usesystem) && !empty($source->name)) { $path = $source->name; } return $path; }
php
public function get_reference_details($reference, $filestatus = 0) { if ($this->disabled) { throw new repository_exception('cannotdownload', 'repository'); } if (empty($reference)) { return get_string('unknownsource', 'repository'); } $source = json_decode($reference); $path = ''; if (!empty($source->usesystem) && !empty($source->name)) { $path = $source->name; } return $path; }
[ "public", "function", "get_reference_details", "(", "$", "reference", ",", "$", "filestatus", "=", "0", ")", "{", "if", "(", "$", "this", "->", "disabled", ")", "{", "throw", "new", "repository_exception", "(", "'cannotdownload'", ",", "'repository'", ")", ";", "}", "if", "(", "empty", "(", "$", "reference", ")", ")", "{", "return", "get_string", "(", "'unknownsource'", ",", "'repository'", ")", ";", "}", "$", "source", "=", "json_decode", "(", "$", "reference", ")", ";", "$", "path", "=", "''", ";", "if", "(", "!", "empty", "(", "$", "source", "->", "usesystem", ")", "&&", "!", "empty", "(", "$", "source", "->", "name", ")", ")", "{", "$", "path", "=", "$", "source", "->", "name", ";", "}", "return", "$", "path", ";", "}" ]
When a controlled link is clicked in the file picker get the human readable info about this file. @param string $reference @param int $filestatus @return string
[ "When", "a", "controlled", "link", "is", "clicked", "in", "the", "file", "picker", "get", "the", "human", "readable", "info", "about", "this", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/lib.php#L897-L911
213,439
moodle/moodle
admin/roles/classes/define_role_table_advanced.php
core_role_define_role_table_advanced.force_archetype
public function force_archetype($archetype, array $options) { $archetypes = get_role_archetypes(); if (!isset($archetypes[$archetype])) { throw new coding_exception('Unknown archetype: '.$archetype); } if ($options['shortname']) { $this->role->shortname = ''; } if ($options['name']) { $this->role->name = ''; } if ($options['description']) { $this->role->description = ''; } if ($options['archetype']) { $this->role->archetype = $archetype; } if ($options['contextlevels']) { $this->contextlevels = array(); $defaults = get_default_contextlevels($archetype); foreach ($defaults as $cl) { $this->contextlevels[$cl] = $cl; } } if ($options['allowassign']) { $this->allowassign = get_default_role_archetype_allows('assign', $archetype); } if ($options['allowoverride']) { $this->allowoverride = get_default_role_archetype_allows('override', $archetype); } if ($options['allowswitch']) { $this->allowswitch = get_default_role_archetype_allows('switch', $archetype); } if ($options['allowview']) { $this->allowview = get_default_role_archetype_allows('view', $archetype); } if ($options['permissions']) { $defaultpermissions = get_default_capabilities($archetype); foreach ($this->permissions as $k => $v) { if (isset($defaultpermissions[$k])) { $this->permissions[$k] = $defaultpermissions[$k]; continue; } $this->permissions[$k] = CAP_INHERIT; } } }
php
public function force_archetype($archetype, array $options) { $archetypes = get_role_archetypes(); if (!isset($archetypes[$archetype])) { throw new coding_exception('Unknown archetype: '.$archetype); } if ($options['shortname']) { $this->role->shortname = ''; } if ($options['name']) { $this->role->name = ''; } if ($options['description']) { $this->role->description = ''; } if ($options['archetype']) { $this->role->archetype = $archetype; } if ($options['contextlevels']) { $this->contextlevels = array(); $defaults = get_default_contextlevels($archetype); foreach ($defaults as $cl) { $this->contextlevels[$cl] = $cl; } } if ($options['allowassign']) { $this->allowassign = get_default_role_archetype_allows('assign', $archetype); } if ($options['allowoverride']) { $this->allowoverride = get_default_role_archetype_allows('override', $archetype); } if ($options['allowswitch']) { $this->allowswitch = get_default_role_archetype_allows('switch', $archetype); } if ($options['allowview']) { $this->allowview = get_default_role_archetype_allows('view', $archetype); } if ($options['permissions']) { $defaultpermissions = get_default_capabilities($archetype); foreach ($this->permissions as $k => $v) { if (isset($defaultpermissions[$k])) { $this->permissions[$k] = $defaultpermissions[$k]; continue; } $this->permissions[$k] = CAP_INHERIT; } } }
[ "public", "function", "force_archetype", "(", "$", "archetype", ",", "array", "$", "options", ")", "{", "$", "archetypes", "=", "get_role_archetypes", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "archetypes", "[", "$", "archetype", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Unknown archetype: '", ".", "$", "archetype", ")", ";", "}", "if", "(", "$", "options", "[", "'shortname'", "]", ")", "{", "$", "this", "->", "role", "->", "shortname", "=", "''", ";", "}", "if", "(", "$", "options", "[", "'name'", "]", ")", "{", "$", "this", "->", "role", "->", "name", "=", "''", ";", "}", "if", "(", "$", "options", "[", "'description'", "]", ")", "{", "$", "this", "->", "role", "->", "description", "=", "''", ";", "}", "if", "(", "$", "options", "[", "'archetype'", "]", ")", "{", "$", "this", "->", "role", "->", "archetype", "=", "$", "archetype", ";", "}", "if", "(", "$", "options", "[", "'contextlevels'", "]", ")", "{", "$", "this", "->", "contextlevels", "=", "array", "(", ")", ";", "$", "defaults", "=", "get_default_contextlevels", "(", "$", "archetype", ")", ";", "foreach", "(", "$", "defaults", "as", "$", "cl", ")", "{", "$", "this", "->", "contextlevels", "[", "$", "cl", "]", "=", "$", "cl", ";", "}", "}", "if", "(", "$", "options", "[", "'allowassign'", "]", ")", "{", "$", "this", "->", "allowassign", "=", "get_default_role_archetype_allows", "(", "'assign'", ",", "$", "archetype", ")", ";", "}", "if", "(", "$", "options", "[", "'allowoverride'", "]", ")", "{", "$", "this", "->", "allowoverride", "=", "get_default_role_archetype_allows", "(", "'override'", ",", "$", "archetype", ")", ";", "}", "if", "(", "$", "options", "[", "'allowswitch'", "]", ")", "{", "$", "this", "->", "allowswitch", "=", "get_default_role_archetype_allows", "(", "'switch'", ",", "$", "archetype", ")", ";", "}", "if", "(", "$", "options", "[", "'allowview'", "]", ")", "{", "$", "this", "->", "allowview", "=", "get_default_role_archetype_allows", "(", "'view'", ",", "$", "archetype", ")", ";", "}", "if", "(", "$", "options", "[", "'permissions'", "]", ")", "{", "$", "defaultpermissions", "=", "get_default_capabilities", "(", "$", "archetype", ")", ";", "foreach", "(", "$", "this", "->", "permissions", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "isset", "(", "$", "defaultpermissions", "[", "$", "k", "]", ")", ")", "{", "$", "this", "->", "permissions", "[", "$", "k", "]", "=", "$", "defaultpermissions", "[", "$", "k", "]", ";", "continue", ";", "}", "$", "this", "->", "permissions", "[", "$", "k", "]", "=", "CAP_INHERIT", ";", "}", "}", "}" ]
Change the role definition to match given archetype. @param string $archetype @param array $options array with following keys: 'name', 'shortname', 'description', 'permissions', 'archetype', 'contextlevels', 'allowassign', 'allowoverride', 'allowswitch', 'allowview'
[ "Change", "the", "role", "definition", "to", "match", "given", "archetype", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/define_role_table_advanced.php#L302-L355
213,440
moodle/moodle
admin/roles/classes/define_role_table_advanced.php
core_role_define_role_table_advanced.force_preset
public function force_preset($xml, array $options) { if (!$info = core_role_preset::parse_preset($xml)) { throw new coding_exception('Invalid role preset'); } if ($options['shortname']) { if (isset($info['shortname'])) { $this->role->shortname = $info['shortname']; } } if ($options['name']) { if (isset($info['name'])) { $this->role->name = $info['name']; } } if ($options['description']) { if (isset($info['description'])) { $this->role->description = $info['description']; } } if ($options['archetype']) { if (isset($info['archetype'])) { $this->role->archetype = $info['archetype']; } } if ($options['contextlevels']) { if (isset($info['contextlevels'])) { $this->contextlevels = $info['contextlevels']; } } foreach (array('assign', 'override', 'switch', 'view') as $type) { if ($options['allow'.$type]) { if (isset($info['allow'.$type])) { $this->{'allow'.$type} = $info['allow'.$type]; } } } if ($options['permissions']) { foreach ($this->permissions as $k => $v) { // Note: do not set everything else to CAP_INHERIT here // because the xml file might not contain all capabilities. if (isset($info['permissions'][$k])) { $this->permissions[$k] = $info['permissions'][$k]; } } } }
php
public function force_preset($xml, array $options) { if (!$info = core_role_preset::parse_preset($xml)) { throw new coding_exception('Invalid role preset'); } if ($options['shortname']) { if (isset($info['shortname'])) { $this->role->shortname = $info['shortname']; } } if ($options['name']) { if (isset($info['name'])) { $this->role->name = $info['name']; } } if ($options['description']) { if (isset($info['description'])) { $this->role->description = $info['description']; } } if ($options['archetype']) { if (isset($info['archetype'])) { $this->role->archetype = $info['archetype']; } } if ($options['contextlevels']) { if (isset($info['contextlevels'])) { $this->contextlevels = $info['contextlevels']; } } foreach (array('assign', 'override', 'switch', 'view') as $type) { if ($options['allow'.$type]) { if (isset($info['allow'.$type])) { $this->{'allow'.$type} = $info['allow'.$type]; } } } if ($options['permissions']) { foreach ($this->permissions as $k => $v) { // Note: do not set everything else to CAP_INHERIT here // because the xml file might not contain all capabilities. if (isset($info['permissions'][$k])) { $this->permissions[$k] = $info['permissions'][$k]; } } } }
[ "public", "function", "force_preset", "(", "$", "xml", ",", "array", "$", "options", ")", "{", "if", "(", "!", "$", "info", "=", "core_role_preset", "::", "parse_preset", "(", "$", "xml", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid role preset'", ")", ";", "}", "if", "(", "$", "options", "[", "'shortname'", "]", ")", "{", "if", "(", "isset", "(", "$", "info", "[", "'shortname'", "]", ")", ")", "{", "$", "this", "->", "role", "->", "shortname", "=", "$", "info", "[", "'shortname'", "]", ";", "}", "}", "if", "(", "$", "options", "[", "'name'", "]", ")", "{", "if", "(", "isset", "(", "$", "info", "[", "'name'", "]", ")", ")", "{", "$", "this", "->", "role", "->", "name", "=", "$", "info", "[", "'name'", "]", ";", "}", "}", "if", "(", "$", "options", "[", "'description'", "]", ")", "{", "if", "(", "isset", "(", "$", "info", "[", "'description'", "]", ")", ")", "{", "$", "this", "->", "role", "->", "description", "=", "$", "info", "[", "'description'", "]", ";", "}", "}", "if", "(", "$", "options", "[", "'archetype'", "]", ")", "{", "if", "(", "isset", "(", "$", "info", "[", "'archetype'", "]", ")", ")", "{", "$", "this", "->", "role", "->", "archetype", "=", "$", "info", "[", "'archetype'", "]", ";", "}", "}", "if", "(", "$", "options", "[", "'contextlevels'", "]", ")", "{", "if", "(", "isset", "(", "$", "info", "[", "'contextlevels'", "]", ")", ")", "{", "$", "this", "->", "contextlevels", "=", "$", "info", "[", "'contextlevels'", "]", ";", "}", "}", "foreach", "(", "array", "(", "'assign'", ",", "'override'", ",", "'switch'", ",", "'view'", ")", "as", "$", "type", ")", "{", "if", "(", "$", "options", "[", "'allow'", ".", "$", "type", "]", ")", "{", "if", "(", "isset", "(", "$", "info", "[", "'allow'", ".", "$", "type", "]", ")", ")", "{", "$", "this", "->", "{", "'allow'", ".", "$", "type", "}", "=", "$", "info", "[", "'allow'", ".", "$", "type", "]", ";", "}", "}", "}", "if", "(", "$", "options", "[", "'permissions'", "]", ")", "{", "foreach", "(", "$", "this", "->", "permissions", "as", "$", "k", "=>", "$", "v", ")", "{", "// Note: do not set everything else to CAP_INHERIT here", "// because the xml file might not contain all capabilities.", "if", "(", "isset", "(", "$", "info", "[", "'permissions'", "]", "[", "$", "k", "]", ")", ")", "{", "$", "this", "->", "permissions", "[", "$", "k", "]", "=", "$", "info", "[", "'permissions'", "]", "[", "$", "k", "]", ";", "}", "}", "}", "}" ]
Change the role definition to match given preset. @param string $xml @param array $options array with following keys: 'name', 'shortname', 'description', 'permissions', 'archetype', 'contextlevels', 'allowassign', 'allowoverride', 'allowswitch', 'allowview'
[ "Change", "the", "role", "definition", "to", "match", "given", "preset", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/define_role_table_advanced.php#L366-L418
213,441
moodle/moodle
admin/roles/classes/define_role_table_advanced.php
core_role_define_role_table_advanced.get_allow_roles_list
protected function get_allow_roles_list($type, $roleid = null) { global $DB; if ($type !== 'assign' and $type !== 'switch' and $type !== 'override' and $type !== 'view') { debugging('Invalid role allowed type specified', DEBUG_DEVELOPER); return array(); } if ($roleid === null) { $roleid = $this->roleid; } if (empty($roleid)) { return array(); } $sql = "SELECT r.* FROM {role} r JOIN {role_allow_{$type}} a ON a.allow{$type} = r.id WHERE a.roleid = :roleid ORDER BY r.sortorder ASC"; return $DB->get_records_sql($sql, array('roleid'=>$roleid)); }
php
protected function get_allow_roles_list($type, $roleid = null) { global $DB; if ($type !== 'assign' and $type !== 'switch' and $type !== 'override' and $type !== 'view') { debugging('Invalid role allowed type specified', DEBUG_DEVELOPER); return array(); } if ($roleid === null) { $roleid = $this->roleid; } if (empty($roleid)) { return array(); } $sql = "SELECT r.* FROM {role} r JOIN {role_allow_{$type}} a ON a.allow{$type} = r.id WHERE a.roleid = :roleid ORDER BY r.sortorder ASC"; return $DB->get_records_sql($sql, array('roleid'=>$roleid)); }
[ "protected", "function", "get_allow_roles_list", "(", "$", "type", ",", "$", "roleid", "=", "null", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "type", "!==", "'assign'", "and", "$", "type", "!==", "'switch'", "and", "$", "type", "!==", "'override'", "and", "$", "type", "!==", "'view'", ")", "{", "debugging", "(", "'Invalid role allowed type specified'", ",", "DEBUG_DEVELOPER", ")", ";", "return", "array", "(", ")", ";", "}", "if", "(", "$", "roleid", "===", "null", ")", "{", "$", "roleid", "=", "$", "this", "->", "roleid", ";", "}", "if", "(", "empty", "(", "$", "roleid", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "sql", "=", "\"SELECT r.*\n FROM {role} r\n JOIN {role_allow_{$type}} a ON a.allow{$type} = r.id\n WHERE a.roleid = :roleid\n ORDER BY r.sortorder ASC\"", ";", "return", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "array", "(", "'roleid'", "=>", "$", "roleid", ")", ")", ";", "}" ]
Returns an array of roles of the allowed type. @param string $type Must be one of: assign, switch, or override. @param int $roleid (null means current role) @return array
[ "Returns", "an", "array", "of", "roles", "of", "the", "allowed", "type", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/define_role_table_advanced.php#L546-L568
213,442
moodle/moodle
admin/roles/classes/define_role_table_advanced.php
core_role_define_role_table_advanced.get_allow_role_control
protected function get_allow_role_control($type) { if ($type !== 'assign' and $type !== 'switch' and $type !== 'override' and $type !== 'view') { debugging('Invalid role allowed type specified', DEBUG_DEVELOPER); return ''; } $property = 'allow'.$type; $selected = $this->$property; $options = array(); foreach (role_get_names(null, ROLENAME_ALIAS) as $role) { $options[$role->id] = $role->localname; } if ($this->roleid == 0) { $options[-1] = get_string('thisnewrole', 'core_role'); } return html_writer::select($options, 'allow'.$type.'[]', $selected, false, array('multiple' => 'multiple', 'size' => 10, 'class' => 'form-control')); }
php
protected function get_allow_role_control($type) { if ($type !== 'assign' and $type !== 'switch' and $type !== 'override' and $type !== 'view') { debugging('Invalid role allowed type specified', DEBUG_DEVELOPER); return ''; } $property = 'allow'.$type; $selected = $this->$property; $options = array(); foreach (role_get_names(null, ROLENAME_ALIAS) as $role) { $options[$role->id] = $role->localname; } if ($this->roleid == 0) { $options[-1] = get_string('thisnewrole', 'core_role'); } return html_writer::select($options, 'allow'.$type.'[]', $selected, false, array('multiple' => 'multiple', 'size' => 10, 'class' => 'form-control')); }
[ "protected", "function", "get_allow_role_control", "(", "$", "type", ")", "{", "if", "(", "$", "type", "!==", "'assign'", "and", "$", "type", "!==", "'switch'", "and", "$", "type", "!==", "'override'", "and", "$", "type", "!==", "'view'", ")", "{", "debugging", "(", "'Invalid role allowed type specified'", ",", "DEBUG_DEVELOPER", ")", ";", "return", "''", ";", "}", "$", "property", "=", "'allow'", ".", "$", "type", ";", "$", "selected", "=", "$", "this", "->", "$", "property", ";", "$", "options", "=", "array", "(", ")", ";", "foreach", "(", "role_get_names", "(", "null", ",", "ROLENAME_ALIAS", ")", "as", "$", "role", ")", "{", "$", "options", "[", "$", "role", "->", "id", "]", "=", "$", "role", "->", "localname", ";", "}", "if", "(", "$", "this", "->", "roleid", "==", "0", ")", "{", "$", "options", "[", "-", "1", "]", "=", "get_string", "(", "'thisnewrole'", ",", "'core_role'", ")", ";", "}", "return", "html_writer", "::", "select", "(", "$", "options", ",", "'allow'", ".", "$", "type", ".", "'[]'", ",", "$", "selected", ",", "false", ",", "array", "(", "'multiple'", "=>", "'multiple'", ",", "'size'", "=>", "10", ",", "'class'", "=>", "'form-control'", ")", ")", ";", "}" ]
Returns an array of roles with the allowed type. @param string $type Must be one of: assign, switch, override or view. @return array Am array of role names with the allowed type
[ "Returns", "an", "array", "of", "roles", "with", "the", "allowed", "type", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/define_role_table_advanced.php#L576-L594
213,443
moodle/moodle
admin/roles/classes/define_role_table_advanced.php
core_role_define_role_table_advanced.print_field
protected function print_field($name, $caption, $field, $helpicon = null) { global $OUTPUT; // Attempt to generate HTML like formslib. echo '<div class="fitem row form-group">'; echo '<div class="fitemtitle col-md-3">'; if ($name) { echo '<label for="' . $name . '">'; } echo $caption; if ($name) { echo "</label>\n"; } if ($helpicon) { echo '<span class="pull-xs-right text-nowrap">'.$helpicon.'</span>'; } echo '</div>'; if (isset($this->errors[$name])) { $extraclass = ' error'; } else { $extraclass = ''; } echo '<div class="felement col-md-9 form-inline' . $extraclass . '">'; echo $field; if (isset($this->errors[$name])) { echo $OUTPUT->error_text($this->errors[$name]); } echo '</div>'; echo '</div>'; }
php
protected function print_field($name, $caption, $field, $helpicon = null) { global $OUTPUT; // Attempt to generate HTML like formslib. echo '<div class="fitem row form-group">'; echo '<div class="fitemtitle col-md-3">'; if ($name) { echo '<label for="' . $name . '">'; } echo $caption; if ($name) { echo "</label>\n"; } if ($helpicon) { echo '<span class="pull-xs-right text-nowrap">'.$helpicon.'</span>'; } echo '</div>'; if (isset($this->errors[$name])) { $extraclass = ' error'; } else { $extraclass = ''; } echo '<div class="felement col-md-9 form-inline' . $extraclass . '">'; echo $field; if (isset($this->errors[$name])) { echo $OUTPUT->error_text($this->errors[$name]); } echo '</div>'; echo '</div>'; }
[ "protected", "function", "print_field", "(", "$", "name", ",", "$", "caption", ",", "$", "field", ",", "$", "helpicon", "=", "null", ")", "{", "global", "$", "OUTPUT", ";", "// Attempt to generate HTML like formslib.", "echo", "'<div class=\"fitem row form-group\">'", ";", "echo", "'<div class=\"fitemtitle col-md-3\">'", ";", "if", "(", "$", "name", ")", "{", "echo", "'<label for=\"'", ".", "$", "name", ".", "'\">'", ";", "}", "echo", "$", "caption", ";", "if", "(", "$", "name", ")", "{", "echo", "\"</label>\\n\"", ";", "}", "if", "(", "$", "helpicon", ")", "{", "echo", "'<span class=\"pull-xs-right text-nowrap\">'", ".", "$", "helpicon", ".", "'</span>'", ";", "}", "echo", "'</div>'", ";", "if", "(", "isset", "(", "$", "this", "->", "errors", "[", "$", "name", "]", ")", ")", "{", "$", "extraclass", "=", "' error'", ";", "}", "else", "{", "$", "extraclass", "=", "''", ";", "}", "echo", "'<div class=\"felement col-md-9 form-inline'", ".", "$", "extraclass", ".", "'\">'", ";", "echo", "$", "field", ";", "if", "(", "isset", "(", "$", "this", "->", "errors", "[", "$", "name", "]", ")", ")", "{", "echo", "$", "OUTPUT", "->", "error_text", "(", "$", "this", "->", "errors", "[", "$", "name", "]", ")", ";", "}", "echo", "'</div>'", ";", "echo", "'</div>'", ";", "}" ]
Print labels, fields and help icon on role administration page. @param string $name The field name. @param string $caption The field caption. @param string $field The field type. @param null|string $helpicon The help icon content.
[ "Print", "labels", "fields", "and", "help", "icon", "on", "role", "administration", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/define_role_table_advanced.php#L613-L641
213,444
moodle/moodle
lib/form/classes/external.php
external.get_filetypes_browser_data_parameters
public static function get_filetypes_browser_data_parameters() { return new external_function_parameters([ 'onlytypes' => new external_value(PARAM_RAW, 'Limit the browser to the given groups and extensions', VALUE_DEFAULT, ''), 'allowall' => new external_value(PARAM_BOOL, 'Allows to select All file types, does not apply with onlytypes are set.', VALUE_DEFAULT, true), 'current' => new external_value(PARAM_RAW, 'Current types that should be selected.', VALUE_DEFAULT, ''), ]); }
php
public static function get_filetypes_browser_data_parameters() { return new external_function_parameters([ 'onlytypes' => new external_value(PARAM_RAW, 'Limit the browser to the given groups and extensions', VALUE_DEFAULT, ''), 'allowall' => new external_value(PARAM_BOOL, 'Allows to select All file types, does not apply with onlytypes are set.', VALUE_DEFAULT, true), 'current' => new external_value(PARAM_RAW, 'Current types that should be selected.', VALUE_DEFAULT, ''), ]); }
[ "public", "static", "function", "get_filetypes_browser_data_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "[", "'onlytypes'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Limit the browser to the given groups and extensions'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", "'allowall'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Allows to select All file types, does not apply with onlytypes are set.'", ",", "VALUE_DEFAULT", ",", "true", ")", ",", "'current'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Current types that should be selected.'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", "]", ")", ";", "}" ]
Describes the input paramaters of the get_filetypes_browser_data external function. @return external_description
[ "Describes", "the", "input", "paramaters", "of", "the", "get_filetypes_browser_data", "external", "function", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/classes/external.php#L53-L60
213,445
moodle/moodle
lib/form/classes/external.php
external.get_filetypes_browser_data
public static function get_filetypes_browser_data($onlytypes, $allowall, $current) { $params = self::validate_parameters(self::get_filetypes_browser_data_parameters(), compact('onlytypes', 'allowall', 'current')); $util = new filetypes_util(); return ['groups' => $util->data_for_browser($params['onlytypes'], $params['allowall'], $params['current'])]; }
php
public static function get_filetypes_browser_data($onlytypes, $allowall, $current) { $params = self::validate_parameters(self::get_filetypes_browser_data_parameters(), compact('onlytypes', 'allowall', 'current')); $util = new filetypes_util(); return ['groups' => $util->data_for_browser($params['onlytypes'], $params['allowall'], $params['current'])]; }
[ "public", "static", "function", "get_filetypes_browser_data", "(", "$", "onlytypes", ",", "$", "allowall", ",", "$", "current", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_filetypes_browser_data_parameters", "(", ")", ",", "compact", "(", "'onlytypes'", ",", "'allowall'", ",", "'current'", ")", ")", ";", "$", "util", "=", "new", "filetypes_util", "(", ")", ";", "return", "[", "'groups'", "=>", "$", "util", "->", "data_for_browser", "(", "$", "params", "[", "'onlytypes'", "]", ",", "$", "params", "[", "'allowall'", "]", ",", "$", "params", "[", "'current'", "]", ")", "]", ";", "}" ]
Implements the get_filetypes_browser_data external function. @param string $onlytypes Allow selection from these file types only; for example 'web_image'. @param bool $allowall Allow to select 'All file types'. Does not apply if onlytypes is set. @param string $current Current values that should be selected. @return object
[ "Implements", "the", "get_filetypes_browser_data", "external", "function", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/classes/external.php#L70-L78
213,446
moodle/moodle
lib/form/classes/external.php
external.get_filetypes_browser_data_returns
public static function get_filetypes_browser_data_returns() { $type = new external_single_structure([ 'key' => new external_value(PARAM_RAW, 'The file type identifier'), 'name' => new external_value(PARAM_RAW, 'The file type name'), 'selected' => new external_value(PARAM_BOOL, 'Should it be marked as selected'), 'ext' => new external_value(PARAM_RAW, 'The file extension associated with the file type'), ]); $group = new external_single_structure([ 'key' => new external_value(PARAM_RAW, 'The file type group identifier'), 'name' => new external_value(PARAM_RAW, 'The file type group name'), 'selectable' => new external_value(PARAM_BOOL, 'Can it be marked as selected'), 'selected' => new external_value(PARAM_BOOL, 'Should it be marked as selected'), 'ext' => new external_value(PARAM_RAW, 'The list of file extensions associated with the group'), 'expanded' => new external_value(PARAM_BOOL, 'Should the group start as expanded or collapsed'), 'types' => new external_multiple_structure($type, 'List of file types in the group'), ]); return new external_single_structure([ 'groups' => new external_multiple_structure($group, 'List of file type groups'), ]); }
php
public static function get_filetypes_browser_data_returns() { $type = new external_single_structure([ 'key' => new external_value(PARAM_RAW, 'The file type identifier'), 'name' => new external_value(PARAM_RAW, 'The file type name'), 'selected' => new external_value(PARAM_BOOL, 'Should it be marked as selected'), 'ext' => new external_value(PARAM_RAW, 'The file extension associated with the file type'), ]); $group = new external_single_structure([ 'key' => new external_value(PARAM_RAW, 'The file type group identifier'), 'name' => new external_value(PARAM_RAW, 'The file type group name'), 'selectable' => new external_value(PARAM_BOOL, 'Can it be marked as selected'), 'selected' => new external_value(PARAM_BOOL, 'Should it be marked as selected'), 'ext' => new external_value(PARAM_RAW, 'The list of file extensions associated with the group'), 'expanded' => new external_value(PARAM_BOOL, 'Should the group start as expanded or collapsed'), 'types' => new external_multiple_structure($type, 'List of file types in the group'), ]); return new external_single_structure([ 'groups' => new external_multiple_structure($group, 'List of file type groups'), ]); }
[ "public", "static", "function", "get_filetypes_browser_data_returns", "(", ")", "{", "$", "type", "=", "new", "external_single_structure", "(", "[", "'key'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The file type identifier'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The file type name'", ")", ",", "'selected'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Should it be marked as selected'", ")", ",", "'ext'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The file extension associated with the file type'", ")", ",", "]", ")", ";", "$", "group", "=", "new", "external_single_structure", "(", "[", "'key'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The file type group identifier'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The file type group name'", ")", ",", "'selectable'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Can it be marked as selected'", ")", ",", "'selected'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Should it be marked as selected'", ")", ",", "'ext'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The list of file extensions associated with the group'", ")", ",", "'expanded'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Should the group start as expanded or collapsed'", ")", ",", "'types'", "=>", "new", "external_multiple_structure", "(", "$", "type", ",", "'List of file types in the group'", ")", ",", "]", ")", ";", "return", "new", "external_single_structure", "(", "[", "'groups'", "=>", "new", "external_multiple_structure", "(", "$", "group", ",", "'List of file type groups'", ")", ",", "]", ")", ";", "}" ]
Describes the output of the get_filetypes_browser_data external function. @return external_description
[ "Describes", "the", "output", "of", "the", "get_filetypes_browser_data", "external", "function", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/classes/external.php#L85-L107
213,447
moodle/moodle
lib/scssphp/Compiler.php
Compiler.isSelfExtend
protected function isSelfExtend($target, $origin) { foreach ($origin as $sel) { if (in_array($target, $sel)) { return true; } } return false; }
php
protected function isSelfExtend($target, $origin) { foreach ($origin as $sel) { if (in_array($target, $sel)) { return true; } } return false; }
[ "protected", "function", "isSelfExtend", "(", "$", "target", ",", "$", "origin", ")", "{", "foreach", "(", "$", "origin", "as", "$", "sel", ")", "{", "if", "(", "in_array", "(", "$", "target", ",", "$", "sel", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Is self extend? @param array $target @param array $origin @return boolean
[ "Is", "self", "extend?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L266-L275
213,448
moodle/moodle
lib/scssphp/Compiler.php
Compiler.makeOutputBlock
protected function makeOutputBlock($type, $selectors = null) { $out = new OutputBlock; $out->type = $type; $out->lines = []; $out->children = []; $out->parent = $this->scope; $out->selectors = $selectors; $out->depth = $this->env->depth; $out->sourceName = $this->env->block->sourceName; $out->sourceLine = $this->env->block->sourceLine; $out->sourceColumn = $this->env->block->sourceColumn; return $out; }
php
protected function makeOutputBlock($type, $selectors = null) { $out = new OutputBlock; $out->type = $type; $out->lines = []; $out->children = []; $out->parent = $this->scope; $out->selectors = $selectors; $out->depth = $this->env->depth; $out->sourceName = $this->env->block->sourceName; $out->sourceLine = $this->env->block->sourceLine; $out->sourceColumn = $this->env->block->sourceColumn; return $out; }
[ "protected", "function", "makeOutputBlock", "(", "$", "type", ",", "$", "selectors", "=", "null", ")", "{", "$", "out", "=", "new", "OutputBlock", ";", "$", "out", "->", "type", "=", "$", "type", ";", "$", "out", "->", "lines", "=", "[", "]", ";", "$", "out", "->", "children", "=", "[", "]", ";", "$", "out", "->", "parent", "=", "$", "this", "->", "scope", ";", "$", "out", "->", "selectors", "=", "$", "selectors", ";", "$", "out", "->", "depth", "=", "$", "this", "->", "env", "->", "depth", ";", "$", "out", "->", "sourceName", "=", "$", "this", "->", "env", "->", "block", "->", "sourceName", ";", "$", "out", "->", "sourceLine", "=", "$", "this", "->", "env", "->", "block", "->", "sourceLine", ";", "$", "out", "->", "sourceColumn", "=", "$", "this", "->", "env", "->", "block", "->", "sourceColumn", ";", "return", "$", "out", ";", "}" ]
Make output block @param string $type @param array $selectors @return \Leafo\ScssPhp\Formatter\OutputBlock
[ "Make", "output", "block" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L310-L324
213,449
moodle/moodle
lib/scssphp/Compiler.php
Compiler.missingSelectors
protected function missingSelectors() { foreach ($this->extends as $extend) { if (isset($extend[3])) { continue; } list($target, $origin, $block) = $extend; // ignore if !optional if ($block[2]) { continue; } $target = implode(' ', $target); $origin = $this->collapseSelectors($origin); $this->sourceLine = $block[Parser::SOURCE_LINE]; $this->throwError("\"$origin\" failed to @extend \"$target\". The selector \"$target\" was not found."); } }
php
protected function missingSelectors() { foreach ($this->extends as $extend) { if (isset($extend[3])) { continue; } list($target, $origin, $block) = $extend; // ignore if !optional if ($block[2]) { continue; } $target = implode(' ', $target); $origin = $this->collapseSelectors($origin); $this->sourceLine = $block[Parser::SOURCE_LINE]; $this->throwError("\"$origin\" failed to @extend \"$target\". The selector \"$target\" was not found."); } }
[ "protected", "function", "missingSelectors", "(", ")", "{", "foreach", "(", "$", "this", "->", "extends", "as", "$", "extend", ")", "{", "if", "(", "isset", "(", "$", "extend", "[", "3", "]", ")", ")", "{", "continue", ";", "}", "list", "(", "$", "target", ",", "$", "origin", ",", "$", "block", ")", "=", "$", "extend", ";", "// ignore if !optional", "if", "(", "$", "block", "[", "2", "]", ")", "{", "continue", ";", "}", "$", "target", "=", "implode", "(", "' '", ",", "$", "target", ")", ";", "$", "origin", "=", "$", "this", "->", "collapseSelectors", "(", "$", "origin", ")", ";", "$", "this", "->", "sourceLine", "=", "$", "block", "[", "Parser", "::", "SOURCE_LINE", "]", ";", "$", "this", "->", "throwError", "(", "\"\\\"$origin\\\" failed to @extend \\\"$target\\\". The selector \\\"$target\\\" was not found.\"", ")", ";", "}", "}" ]
Report missing selectors
[ "Report", "missing", "selectors" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L343-L363
213,450
moodle/moodle
lib/scssphp/Compiler.php
Compiler.matchExtendsSingle
protected function matchExtendsSingle($rawSingle, &$outOrigin) { $counts = []; $single = []; foreach ($rawSingle as $part) { // matches Number if (! is_string($part)) { return false; } if (! preg_match('/^[\[.:#%]/', $part) && count($single)) { $single[count($single) - 1] .= $part; } else { $single[] = $part; } } $extendingDecoratedTag = false; if (count($single) > 1) { $matches = null; $extendingDecoratedTag = preg_match('/^[a-z0-9]+$/i', $single[0], $matches) ? $matches[0] : false; } foreach ($single as $part) { if (isset($this->extendsMap[$part])) { foreach ($this->extendsMap[$part] as $idx) { $counts[$idx] = isset($counts[$idx]) ? $counts[$idx] + 1 : 1; } } } $outOrigin = []; $found = false; foreach ($counts as $idx => $count) { list($target, $origin, /* $block */) = $this->extends[$idx]; // check count if ($count !== count($target)) { continue; } $this->extends[$idx][3] = true; $rem = array_diff($single, $target); foreach ($origin as $j => $new) { // prevent infinite loop when target extends itself if ($this->isSelfExtend($single, $origin)) { return false; } $replacement = end($new); // Extending a decorated tag with another tag is not possible. if ($extendingDecoratedTag && $replacement[0] != $extendingDecoratedTag && preg_match('/^[a-z0-9]+$/i', $replacement[0]) ) { unset($origin[$j]); continue; } $combined = $this->combineSelectorSingle($replacement, $rem); if (count(array_diff($combined, $origin[$j][count($origin[$j]) - 1]))) { $origin[$j][count($origin[$j]) - 1] = $combined; } } $outOrigin = array_merge($outOrigin, $origin); $found = true; } return $found; }
php
protected function matchExtendsSingle($rawSingle, &$outOrigin) { $counts = []; $single = []; foreach ($rawSingle as $part) { // matches Number if (! is_string($part)) { return false; } if (! preg_match('/^[\[.:#%]/', $part) && count($single)) { $single[count($single) - 1] .= $part; } else { $single[] = $part; } } $extendingDecoratedTag = false; if (count($single) > 1) { $matches = null; $extendingDecoratedTag = preg_match('/^[a-z0-9]+$/i', $single[0], $matches) ? $matches[0] : false; } foreach ($single as $part) { if (isset($this->extendsMap[$part])) { foreach ($this->extendsMap[$part] as $idx) { $counts[$idx] = isset($counts[$idx]) ? $counts[$idx] + 1 : 1; } } } $outOrigin = []; $found = false; foreach ($counts as $idx => $count) { list($target, $origin, /* $block */) = $this->extends[$idx]; // check count if ($count !== count($target)) { continue; } $this->extends[$idx][3] = true; $rem = array_diff($single, $target); foreach ($origin as $j => $new) { // prevent infinite loop when target extends itself if ($this->isSelfExtend($single, $origin)) { return false; } $replacement = end($new); // Extending a decorated tag with another tag is not possible. if ($extendingDecoratedTag && $replacement[0] != $extendingDecoratedTag && preg_match('/^[a-z0-9]+$/i', $replacement[0]) ) { unset($origin[$j]); continue; } $combined = $this->combineSelectorSingle($replacement, $rem); if (count(array_diff($combined, $origin[$j][count($origin[$j]) - 1]))) { $origin[$j][count($origin[$j]) - 1] = $combined; } } $outOrigin = array_merge($outOrigin, $origin); $found = true; } return $found; }
[ "protected", "function", "matchExtendsSingle", "(", "$", "rawSingle", ",", "&", "$", "outOrigin", ")", "{", "$", "counts", "=", "[", "]", ";", "$", "single", "=", "[", "]", ";", "foreach", "(", "$", "rawSingle", "as", "$", "part", ")", "{", "// matches Number", "if", "(", "!", "is_string", "(", "$", "part", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "preg_match", "(", "'/^[\\[.:#%]/'", ",", "$", "part", ")", "&&", "count", "(", "$", "single", ")", ")", "{", "$", "single", "[", "count", "(", "$", "single", ")", "-", "1", "]", ".=", "$", "part", ";", "}", "else", "{", "$", "single", "[", "]", "=", "$", "part", ";", "}", "}", "$", "extendingDecoratedTag", "=", "false", ";", "if", "(", "count", "(", "$", "single", ")", ">", "1", ")", "{", "$", "matches", "=", "null", ";", "$", "extendingDecoratedTag", "=", "preg_match", "(", "'/^[a-z0-9]+$/i'", ",", "$", "single", "[", "0", "]", ",", "$", "matches", ")", "?", "$", "matches", "[", "0", "]", ":", "false", ";", "}", "foreach", "(", "$", "single", "as", "$", "part", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "extendsMap", "[", "$", "part", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "extendsMap", "[", "$", "part", "]", "as", "$", "idx", ")", "{", "$", "counts", "[", "$", "idx", "]", "=", "isset", "(", "$", "counts", "[", "$", "idx", "]", ")", "?", "$", "counts", "[", "$", "idx", "]", "+", "1", ":", "1", ";", "}", "}", "}", "$", "outOrigin", "=", "[", "]", ";", "$", "found", "=", "false", ";", "foreach", "(", "$", "counts", "as", "$", "idx", "=>", "$", "count", ")", "{", "list", "(", "$", "target", ",", "$", "origin", ",", "/* $block */", ")", "=", "$", "this", "->", "extends", "[", "$", "idx", "]", ";", "// check count", "if", "(", "$", "count", "!==", "count", "(", "$", "target", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "extends", "[", "$", "idx", "]", "[", "3", "]", "=", "true", ";", "$", "rem", "=", "array_diff", "(", "$", "single", ",", "$", "target", ")", ";", "foreach", "(", "$", "origin", "as", "$", "j", "=>", "$", "new", ")", "{", "// prevent infinite loop when target extends itself", "if", "(", "$", "this", "->", "isSelfExtend", "(", "$", "single", ",", "$", "origin", ")", ")", "{", "return", "false", ";", "}", "$", "replacement", "=", "end", "(", "$", "new", ")", ";", "// Extending a decorated tag with another tag is not possible.", "if", "(", "$", "extendingDecoratedTag", "&&", "$", "replacement", "[", "0", "]", "!=", "$", "extendingDecoratedTag", "&&", "preg_match", "(", "'/^[a-z0-9]+$/i'", ",", "$", "replacement", "[", "0", "]", ")", ")", "{", "unset", "(", "$", "origin", "[", "$", "j", "]", ")", ";", "continue", ";", "}", "$", "combined", "=", "$", "this", "->", "combineSelectorSingle", "(", "$", "replacement", ",", "$", "rem", ")", ";", "if", "(", "count", "(", "array_diff", "(", "$", "combined", ",", "$", "origin", "[", "$", "j", "]", "[", "count", "(", "$", "origin", "[", "$", "j", "]", ")", "-", "1", "]", ")", ")", ")", "{", "$", "origin", "[", "$", "j", "]", "[", "count", "(", "$", "origin", "[", "$", "j", "]", ")", "-", "1", "]", "=", "$", "combined", ";", "}", "}", "$", "outOrigin", "=", "array_merge", "(", "$", "outOrigin", ",", "$", "origin", ")", ";", "$", "found", "=", "true", ";", "}", "return", "$", "found", ";", "}" ]
Match extends single @param array $rawSingle @param array $outOrigin @return boolean
[ "Match", "extends", "single" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L520-L597
213,451
moodle/moodle
lib/scssphp/Compiler.php
Compiler.extractRelationshipFromFragment
protected function extractRelationshipFromFragment(array $fragment) { $parents = []; $children = []; $j = $i = count($fragment); for (;;) { $children = $j != $i ? array_slice($fragment, $j, $i - $j) : []; $parents = array_slice($fragment, 0, $j); $slice = end($parents); if (empty($slice) || ! $this->isImmediateRelationshipCombinator($slice[0])) { break; } $j -= 2; } return [$parents, $children]; }
php
protected function extractRelationshipFromFragment(array $fragment) { $parents = []; $children = []; $j = $i = count($fragment); for (;;) { $children = $j != $i ? array_slice($fragment, $j, $i - $j) : []; $parents = array_slice($fragment, 0, $j); $slice = end($parents); if (empty($slice) || ! $this->isImmediateRelationshipCombinator($slice[0])) { break; } $j -= 2; } return [$parents, $children]; }
[ "protected", "function", "extractRelationshipFromFragment", "(", "array", "$", "fragment", ")", "{", "$", "parents", "=", "[", "]", ";", "$", "children", "=", "[", "]", ";", "$", "j", "=", "$", "i", "=", "count", "(", "$", "fragment", ")", ";", "for", "(", ";", ";", ")", "{", "$", "children", "=", "$", "j", "!=", "$", "i", "?", "array_slice", "(", "$", "fragment", ",", "$", "j", ",", "$", "i", "-", "$", "j", ")", ":", "[", "]", ";", "$", "parents", "=", "array_slice", "(", "$", "fragment", ",", "0", ",", "$", "j", ")", ";", "$", "slice", "=", "end", "(", "$", "parents", ")", ";", "if", "(", "empty", "(", "$", "slice", ")", "||", "!", "$", "this", "->", "isImmediateRelationshipCombinator", "(", "$", "slice", "[", "0", "]", ")", ")", "{", "break", ";", "}", "$", "j", "-=", "2", ";", "}", "return", "[", "$", "parents", ",", "$", "children", "]", ";", "}" ]
Extract a relationship from the fragment. When extracting the last portion of a selector we will be left with a fragment which may end with a direction relationship combinator. This method will extract the relationship fragment and return it along side the rest. @param array $fragment The selector fragment maybe ending with a direction relationship combinator. @return array The selector without the relationship fragment if any, the relationship fragment.
[ "Extract", "a", "relationship", "from", "the", "fragment", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L611-L630
213,452
moodle/moodle
lib/scssphp/Compiler.php
Compiler.combineSelectorSingle
protected function combineSelectorSingle($base, $other) { $tag = []; $out = []; $wasTag = true; foreach ([$base, $other] as $single) { foreach ($single as $part) { if (preg_match('/^[\[.:#]/', $part)) { $out[] = $part; $wasTag = false; } elseif (preg_match('/^[^_-]/', $part)) { $tag[] = $part; $wasTag = true; } elseif ($wasTag) { $tag[count($tag) - 1] .= $part; } else { $out[count($out) - 1] .= $part; } } } if (count($tag)) { array_unshift($out, $tag[0]); } return $out; }
php
protected function combineSelectorSingle($base, $other) { $tag = []; $out = []; $wasTag = true; foreach ([$base, $other] as $single) { foreach ($single as $part) { if (preg_match('/^[\[.:#]/', $part)) { $out[] = $part; $wasTag = false; } elseif (preg_match('/^[^_-]/', $part)) { $tag[] = $part; $wasTag = true; } elseif ($wasTag) { $tag[count($tag) - 1] .= $part; } else { $out[count($out) - 1] .= $part; } } } if (count($tag)) { array_unshift($out, $tag[0]); } return $out; }
[ "protected", "function", "combineSelectorSingle", "(", "$", "base", ",", "$", "other", ")", "{", "$", "tag", "=", "[", "]", ";", "$", "out", "=", "[", "]", ";", "$", "wasTag", "=", "true", ";", "foreach", "(", "[", "$", "base", ",", "$", "other", "]", "as", "$", "single", ")", "{", "foreach", "(", "$", "single", "as", "$", "part", ")", "{", "if", "(", "preg_match", "(", "'/^[\\[.:#]/'", ",", "$", "part", ")", ")", "{", "$", "out", "[", "]", "=", "$", "part", ";", "$", "wasTag", "=", "false", ";", "}", "elseif", "(", "preg_match", "(", "'/^[^_-]/'", ",", "$", "part", ")", ")", "{", "$", "tag", "[", "]", "=", "$", "part", ";", "$", "wasTag", "=", "true", ";", "}", "elseif", "(", "$", "wasTag", ")", "{", "$", "tag", "[", "count", "(", "$", "tag", ")", "-", "1", "]", ".=", "$", "part", ";", "}", "else", "{", "$", "out", "[", "count", "(", "$", "out", ")", "-", "1", "]", ".=", "$", "part", ";", "}", "}", "}", "if", "(", "count", "(", "$", "tag", ")", ")", "{", "array_unshift", "(", "$", "out", ",", "$", "tag", "[", "0", "]", ")", ";", "}", "return", "$", "out", ";", "}" ]
Combine selector single @param array $base @param array $other @return array
[ "Combine", "selector", "single" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L640-L667
213,453
moodle/moodle
lib/scssphp/Compiler.php
Compiler.spliceTree
private function spliceTree($envs, Block $block, $without) { $newBlock = null; foreach ($envs as $e) { if (! isset($e->block)) { continue; } if ($e->block === $block) { continue; } if (isset($e->block->type) && $e->block->type === Type::T_AT_ROOT) { continue; } if ($e->block && $this->isWithout($without, $e->block)) { continue; } $b = new Block; $b->sourceName = $e->block->sourceName; $b->sourceIndex = $e->block->sourceIndex; $b->sourceLine = $e->block->sourceLine; $b->sourceColumn = $e->block->sourceColumn; $b->selectors = []; $b->comments = $e->block->comments; $b->parent = null; if ($newBlock) { $type = isset($newBlock->type) ? $newBlock->type : Type::T_BLOCK; $b->children = [[$type, $newBlock]]; $newBlock->parent = $b; } elseif (count($block->children)) { foreach ($block->children as $child) { if ($child[0] === Type::T_BLOCK) { $child[1]->parent = $b; } } $b->children = $block->children; } if (isset($e->block->type)) { $b->type = $e->block->type; } if (isset($e->block->name)) { $b->name = $e->block->name; } if (isset($e->block->queryList)) { $b->queryList = $e->block->queryList; } if (isset($e->block->value)) { $b->value = $e->block->value; } $newBlock = $b; } $type = isset($newBlock->type) ? $newBlock->type : Type::T_BLOCK; return [$type, $newBlock]; }
php
private function spliceTree($envs, Block $block, $without) { $newBlock = null; foreach ($envs as $e) { if (! isset($e->block)) { continue; } if ($e->block === $block) { continue; } if (isset($e->block->type) && $e->block->type === Type::T_AT_ROOT) { continue; } if ($e->block && $this->isWithout($without, $e->block)) { continue; } $b = new Block; $b->sourceName = $e->block->sourceName; $b->sourceIndex = $e->block->sourceIndex; $b->sourceLine = $e->block->sourceLine; $b->sourceColumn = $e->block->sourceColumn; $b->selectors = []; $b->comments = $e->block->comments; $b->parent = null; if ($newBlock) { $type = isset($newBlock->type) ? $newBlock->type : Type::T_BLOCK; $b->children = [[$type, $newBlock]]; $newBlock->parent = $b; } elseif (count($block->children)) { foreach ($block->children as $child) { if ($child[0] === Type::T_BLOCK) { $child[1]->parent = $b; } } $b->children = $block->children; } if (isset($e->block->type)) { $b->type = $e->block->type; } if (isset($e->block->name)) { $b->name = $e->block->name; } if (isset($e->block->queryList)) { $b->queryList = $e->block->queryList; } if (isset($e->block->value)) { $b->value = $e->block->value; } $newBlock = $b; } $type = isset($newBlock->type) ? $newBlock->type : Type::T_BLOCK; return [$type, $newBlock]; }
[ "private", "function", "spliceTree", "(", "$", "envs", ",", "Block", "$", "block", ",", "$", "without", ")", "{", "$", "newBlock", "=", "null", ";", "foreach", "(", "$", "envs", "as", "$", "e", ")", "{", "if", "(", "!", "isset", "(", "$", "e", "->", "block", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "e", "->", "block", "===", "$", "block", ")", "{", "continue", ";", "}", "if", "(", "isset", "(", "$", "e", "->", "block", "->", "type", ")", "&&", "$", "e", "->", "block", "->", "type", "===", "Type", "::", "T_AT_ROOT", ")", "{", "continue", ";", "}", "if", "(", "$", "e", "->", "block", "&&", "$", "this", "->", "isWithout", "(", "$", "without", ",", "$", "e", "->", "block", ")", ")", "{", "continue", ";", "}", "$", "b", "=", "new", "Block", ";", "$", "b", "->", "sourceName", "=", "$", "e", "->", "block", "->", "sourceName", ";", "$", "b", "->", "sourceIndex", "=", "$", "e", "->", "block", "->", "sourceIndex", ";", "$", "b", "->", "sourceLine", "=", "$", "e", "->", "block", "->", "sourceLine", ";", "$", "b", "->", "sourceColumn", "=", "$", "e", "->", "block", "->", "sourceColumn", ";", "$", "b", "->", "selectors", "=", "[", "]", ";", "$", "b", "->", "comments", "=", "$", "e", "->", "block", "->", "comments", ";", "$", "b", "->", "parent", "=", "null", ";", "if", "(", "$", "newBlock", ")", "{", "$", "type", "=", "isset", "(", "$", "newBlock", "->", "type", ")", "?", "$", "newBlock", "->", "type", ":", "Type", "::", "T_BLOCK", ";", "$", "b", "->", "children", "=", "[", "[", "$", "type", ",", "$", "newBlock", "]", "]", ";", "$", "newBlock", "->", "parent", "=", "$", "b", ";", "}", "elseif", "(", "count", "(", "$", "block", "->", "children", ")", ")", "{", "foreach", "(", "$", "block", "->", "children", "as", "$", "child", ")", "{", "if", "(", "$", "child", "[", "0", "]", "===", "Type", "::", "T_BLOCK", ")", "{", "$", "child", "[", "1", "]", "->", "parent", "=", "$", "b", ";", "}", "}", "$", "b", "->", "children", "=", "$", "block", "->", "children", ";", "}", "if", "(", "isset", "(", "$", "e", "->", "block", "->", "type", ")", ")", "{", "$", "b", "->", "type", "=", "$", "e", "->", "block", "->", "type", ";", "}", "if", "(", "isset", "(", "$", "e", "->", "block", "->", "name", ")", ")", "{", "$", "b", "->", "name", "=", "$", "e", "->", "block", "->", "name", ";", "}", "if", "(", "isset", "(", "$", "e", "->", "block", "->", "queryList", ")", ")", "{", "$", "b", "->", "queryList", "=", "$", "e", "->", "block", "->", "queryList", ";", "}", "if", "(", "isset", "(", "$", "e", "->", "block", "->", "value", ")", ")", "{", "$", "b", "->", "value", "=", "$", "e", "->", "block", "->", "value", ";", "}", "$", "newBlock", "=", "$", "b", ";", "}", "$", "type", "=", "isset", "(", "$", "newBlock", "->", "type", ")", "?", "$", "newBlock", "->", "type", ":", "Type", "::", "T_BLOCK", ";", "return", "[", "$", "type", ",", "$", "newBlock", "]", ";", "}" ]
Splice parse tree @param array $envs @param \Leafo\ScssPhp\Block $block @param integer $without @return array
[ "Splice", "parse", "tree" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L813-L881
213,454
moodle/moodle
lib/scssphp/Compiler.php
Compiler.filterWithout
private function filterWithout($envs, $without) { $filtered = []; foreach ($envs as $e) { if ($e->block && $this->isWithout($without, $e->block)) { continue; } $filtered[] = $e; } return $this->extractEnv($filtered); }
php
private function filterWithout($envs, $without) { $filtered = []; foreach ($envs as $e) { if ($e->block && $this->isWithout($without, $e->block)) { continue; } $filtered[] = $e; } return $this->extractEnv($filtered); }
[ "private", "function", "filterWithout", "(", "$", "envs", ",", "$", "without", ")", "{", "$", "filtered", "=", "[", "]", ";", "foreach", "(", "$", "envs", "as", "$", "e", ")", "{", "if", "(", "$", "e", "->", "block", "&&", "$", "this", "->", "isWithout", "(", "$", "without", ",", "$", "e", "->", "block", ")", ")", "{", "continue", ";", "}", "$", "filtered", "[", "]", "=", "$", "e", ";", "}", "return", "$", "this", "->", "extractEnv", "(", "$", "filtered", ")", ";", "}" ]
Filter env stack @param array $envs @param integer $without @return \Leafo\ScssPhp\Compiler\Environment
[ "Filter", "env", "stack" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L941-L954
213,455
moodle/moodle
lib/scssphp/Compiler.php
Compiler.compileKeyframeBlock
protected function compileKeyframeBlock(Block $block, $selectors) { $env = $this->pushEnv($block); $envs = $this->compactEnv($env); $this->env = $this->extractEnv(array_filter($envs, function (Environment $e) { return ! isset($e->block->selectors); })); $this->scope = $this->makeOutputBlock($block->type, $selectors); $this->scope->depth = 1; $this->scope->parent->children[] = $this->scope; $this->compileChildrenNoReturn($block->children, $this->scope); $this->scope = $this->scope->parent; $this->env = $this->extractEnv($envs); $this->popEnv(); }
php
protected function compileKeyframeBlock(Block $block, $selectors) { $env = $this->pushEnv($block); $envs = $this->compactEnv($env); $this->env = $this->extractEnv(array_filter($envs, function (Environment $e) { return ! isset($e->block->selectors); })); $this->scope = $this->makeOutputBlock($block->type, $selectors); $this->scope->depth = 1; $this->scope->parent->children[] = $this->scope; $this->compileChildrenNoReturn($block->children, $this->scope); $this->scope = $this->scope->parent; $this->env = $this->extractEnv($envs); $this->popEnv(); }
[ "protected", "function", "compileKeyframeBlock", "(", "Block", "$", "block", ",", "$", "selectors", ")", "{", "$", "env", "=", "$", "this", "->", "pushEnv", "(", "$", "block", ")", ";", "$", "envs", "=", "$", "this", "->", "compactEnv", "(", "$", "env", ")", ";", "$", "this", "->", "env", "=", "$", "this", "->", "extractEnv", "(", "array_filter", "(", "$", "envs", ",", "function", "(", "Environment", "$", "e", ")", "{", "return", "!", "isset", "(", "$", "e", "->", "block", "->", "selectors", ")", ";", "}", ")", ")", ";", "$", "this", "->", "scope", "=", "$", "this", "->", "makeOutputBlock", "(", "$", "block", "->", "type", ",", "$", "selectors", ")", ";", "$", "this", "->", "scope", "->", "depth", "=", "1", ";", "$", "this", "->", "scope", "->", "parent", "->", "children", "[", "]", "=", "$", "this", "->", "scope", ";", "$", "this", "->", "compileChildrenNoReturn", "(", "$", "block", "->", "children", ",", "$", "this", "->", "scope", ")", ";", "$", "this", "->", "scope", "=", "$", "this", "->", "scope", "->", "parent", ";", "$", "this", "->", "env", "=", "$", "this", "->", "extractEnv", "(", "$", "envs", ")", ";", "$", "this", "->", "popEnv", "(", ")", ";", "}" ]
Compile keyframe block @param \Leafo\ScssPhp\Block $block @param array $selectors
[ "Compile", "keyframe", "block" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L985-L1005
213,456
moodle/moodle
lib/scssphp/Compiler.php
Compiler.compileComment
protected function compileComment($block) { $out = $this->makeOutputBlock(Type::T_COMMENT); $out->lines[] = $block[1]; $this->scope->children[] = $out; }
php
protected function compileComment($block) { $out = $this->makeOutputBlock(Type::T_COMMENT); $out->lines[] = $block[1]; $this->scope->children[] = $out; }
[ "protected", "function", "compileComment", "(", "$", "block", ")", "{", "$", "out", "=", "$", "this", "->", "makeOutputBlock", "(", "Type", "::", "T_COMMENT", ")", ";", "$", "out", "->", "lines", "[", "]", "=", "$", "block", "[", "1", "]", ";", "$", "this", "->", "scope", "->", "children", "[", "]", "=", "$", "out", ";", "}" ]
Compile root level comment @param array $block
[ "Compile", "root", "level", "comment" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L1094-L1099
213,457
moodle/moodle
lib/scssphp/Compiler.php
Compiler.evalSelectorPart
protected function evalSelectorPart($part) { foreach ($part as &$p) { if (is_array($p) && ($p[0] === Type::T_INTERPOLATE || $p[0] === Type::T_STRING)) { $p = $this->compileValue($p); // force re-evaluation if (strpos($p, '&') !== false || strpos($p, ',') !== false) { $this->shouldEvaluate = true; } } elseif (is_string($p) && strlen($p) >= 2 && ($first = $p[0]) && ($first === '"' || $first === "'") && substr($p, -1) === $first ) { $p = substr($p, 1, -1); } } return $this->flattenSelectorSingle($part); }
php
protected function evalSelectorPart($part) { foreach ($part as &$p) { if (is_array($p) && ($p[0] === Type::T_INTERPOLATE || $p[0] === Type::T_STRING)) { $p = $this->compileValue($p); // force re-evaluation if (strpos($p, '&') !== false || strpos($p, ',') !== false) { $this->shouldEvaluate = true; } } elseif (is_string($p) && strlen($p) >= 2 && ($first = $p[0]) && ($first === '"' || $first === "'") && substr($p, -1) === $first ) { $p = substr($p, 1, -1); } } return $this->flattenSelectorSingle($part); }
[ "protected", "function", "evalSelectorPart", "(", "$", "part", ")", "{", "foreach", "(", "$", "part", "as", "&", "$", "p", ")", "{", "if", "(", "is_array", "(", "$", "p", ")", "&&", "(", "$", "p", "[", "0", "]", "===", "Type", "::", "T_INTERPOLATE", "||", "$", "p", "[", "0", "]", "===", "Type", "::", "T_STRING", ")", ")", "{", "$", "p", "=", "$", "this", "->", "compileValue", "(", "$", "p", ")", ";", "// force re-evaluation", "if", "(", "strpos", "(", "$", "p", ",", "'&'", ")", "!==", "false", "||", "strpos", "(", "$", "p", ",", "','", ")", "!==", "false", ")", "{", "$", "this", "->", "shouldEvaluate", "=", "true", ";", "}", "}", "elseif", "(", "is_string", "(", "$", "p", ")", "&&", "strlen", "(", "$", "p", ")", ">=", "2", "&&", "(", "$", "first", "=", "$", "p", "[", "0", "]", ")", "&&", "(", "$", "first", "===", "'\"'", "||", "$", "first", "===", "\"'\"", ")", "&&", "substr", "(", "$", "p", ",", "-", "1", ")", "===", "$", "first", ")", "{", "$", "p", "=", "substr", "(", "$", "p", ",", "1", ",", "-", "1", ")", ";", "}", "}", "return", "$", "this", "->", "flattenSelectorSingle", "(", "$", "part", ")", ";", "}" ]
Evaluate selector part; replaces all the interpolates, stripping quotes @param array $part @return array
[ "Evaluate", "selector", "part", ";", "replaces", "all", "the", "interpolates", "stripping", "quotes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L1146-L1165
213,458
moodle/moodle
lib/scssphp/Compiler.php
Compiler.compileMediaQuery
protected function compileMediaQuery($queryList) { $out = '@media'; $first = true; foreach ($queryList as $query) { $type = null; $parts = []; foreach ($query as $q) { switch ($q[0]) { case Type::T_MEDIA_TYPE: if ($type) { $type = $this->mergeMediaTypes( $type, array_map([$this, 'compileValue'], array_slice($q, 1)) ); if (empty($type)) { // merge failed return null; } } else { $type = array_map([$this, 'compileValue'], array_slice($q, 1)); } break; case Type::T_MEDIA_EXPRESSION: if (isset($q[2])) { $parts[] = '(' . $this->compileValue($q[1]) . $this->formatter->assignSeparator . $this->compileValue($q[2]) . ')'; } else { $parts[] = '(' . $this->compileValue($q[1]) . ')'; } break; case Type::T_MEDIA_VALUE: $parts[] = $this->compileValue($q[1]); break; } } if ($type) { array_unshift($parts, implode(' ', array_filter($type))); } if (! empty($parts)) { if ($first) { $first = false; $out .= ' '; } else { $out .= $this->formatter->tagSeparator; } $out .= implode(' and ', $parts); } } return $out; }
php
protected function compileMediaQuery($queryList) { $out = '@media'; $first = true; foreach ($queryList as $query) { $type = null; $parts = []; foreach ($query as $q) { switch ($q[0]) { case Type::T_MEDIA_TYPE: if ($type) { $type = $this->mergeMediaTypes( $type, array_map([$this, 'compileValue'], array_slice($q, 1)) ); if (empty($type)) { // merge failed return null; } } else { $type = array_map([$this, 'compileValue'], array_slice($q, 1)); } break; case Type::T_MEDIA_EXPRESSION: if (isset($q[2])) { $parts[] = '(' . $this->compileValue($q[1]) . $this->formatter->assignSeparator . $this->compileValue($q[2]) . ')'; } else { $parts[] = '(' . $this->compileValue($q[1]) . ')'; } break; case Type::T_MEDIA_VALUE: $parts[] = $this->compileValue($q[1]); break; } } if ($type) { array_unshift($parts, implode(' ', array_filter($type))); } if (! empty($parts)) { if ($first) { $first = false; $out .= ' '; } else { $out .= $this->formatter->tagSeparator; } $out .= implode(' and ', $parts); } } return $out; }
[ "protected", "function", "compileMediaQuery", "(", "$", "queryList", ")", "{", "$", "out", "=", "'@media'", ";", "$", "first", "=", "true", ";", "foreach", "(", "$", "queryList", "as", "$", "query", ")", "{", "$", "type", "=", "null", ";", "$", "parts", "=", "[", "]", ";", "foreach", "(", "$", "query", "as", "$", "q", ")", "{", "switch", "(", "$", "q", "[", "0", "]", ")", "{", "case", "Type", "::", "T_MEDIA_TYPE", ":", "if", "(", "$", "type", ")", "{", "$", "type", "=", "$", "this", "->", "mergeMediaTypes", "(", "$", "type", ",", "array_map", "(", "[", "$", "this", ",", "'compileValue'", "]", ",", "array_slice", "(", "$", "q", ",", "1", ")", ")", ")", ";", "if", "(", "empty", "(", "$", "type", ")", ")", "{", "// merge failed", "return", "null", ";", "}", "}", "else", "{", "$", "type", "=", "array_map", "(", "[", "$", "this", ",", "'compileValue'", "]", ",", "array_slice", "(", "$", "q", ",", "1", ")", ")", ";", "}", "break", ";", "case", "Type", "::", "T_MEDIA_EXPRESSION", ":", "if", "(", "isset", "(", "$", "q", "[", "2", "]", ")", ")", "{", "$", "parts", "[", "]", "=", "'('", ".", "$", "this", "->", "compileValue", "(", "$", "q", "[", "1", "]", ")", ".", "$", "this", "->", "formatter", "->", "assignSeparator", ".", "$", "this", "->", "compileValue", "(", "$", "q", "[", "2", "]", ")", ".", "')'", ";", "}", "else", "{", "$", "parts", "[", "]", "=", "'('", ".", "$", "this", "->", "compileValue", "(", "$", "q", "[", "1", "]", ")", ".", "')'", ";", "}", "break", ";", "case", "Type", "::", "T_MEDIA_VALUE", ":", "$", "parts", "[", "]", "=", "$", "this", "->", "compileValue", "(", "$", "q", "[", "1", "]", ")", ";", "break", ";", "}", "}", "if", "(", "$", "type", ")", "{", "array_unshift", "(", "$", "parts", ",", "implode", "(", "' '", ",", "array_filter", "(", "$", "type", ")", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "parts", ")", ")", "{", "if", "(", "$", "first", ")", "{", "$", "first", "=", "false", ";", "$", "out", ".=", "' '", ";", "}", "else", "{", "$", "out", ".=", "$", "this", "->", "formatter", "->", "tagSeparator", ";", "}", "$", "out", ".=", "implode", "(", "' and '", ",", "$", "parts", ")", ";", "}", "}", "return", "$", "out", ";", "}" ]
Compile media query @param array $queryList @return string
[ "Compile", "media", "query" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L1345-L1408
213,459
moodle/moodle
lib/scssphp/Compiler.php
Compiler.mergeMediaTypes
protected function mergeMediaTypes($type1, $type2) { if (empty($type1)) { return $type2; } if (empty($type2)) { return $type1; } $m1 = ''; $t1 = ''; if (count($type1) > 1) { $m1= strtolower($type1[0]); $t1= strtolower($type1[1]); } else { $t1 = strtolower($type1[0]); } $m2 = ''; $t2 = ''; if (count($type2) > 1) { $m2 = strtolower($type2[0]); $t2 = strtolower($type2[1]); } else { $t2 = strtolower($type2[0]); } if (($m1 === Type::T_NOT) ^ ($m2 === Type::T_NOT)) { if ($t1 === $t2) { return null; } return [ $m1 === Type::T_NOT ? $m2 : $m1, $m1 === Type::T_NOT ? $t2 : $t1, ]; } if ($m1 === Type::T_NOT && $m2 === Type::T_NOT) { // CSS has no way of representing "neither screen nor print" if ($t1 !== $t2) { return null; } return [Type::T_NOT, $t1]; } if ($t1 !== $t2) { return null; } // t1 == t2, neither m1 nor m2 are "not" return [empty($m1)? $m2 : $m1, $t1]; }
php
protected function mergeMediaTypes($type1, $type2) { if (empty($type1)) { return $type2; } if (empty($type2)) { return $type1; } $m1 = ''; $t1 = ''; if (count($type1) > 1) { $m1= strtolower($type1[0]); $t1= strtolower($type1[1]); } else { $t1 = strtolower($type1[0]); } $m2 = ''; $t2 = ''; if (count($type2) > 1) { $m2 = strtolower($type2[0]); $t2 = strtolower($type2[1]); } else { $t2 = strtolower($type2[0]); } if (($m1 === Type::T_NOT) ^ ($m2 === Type::T_NOT)) { if ($t1 === $t2) { return null; } return [ $m1 === Type::T_NOT ? $m2 : $m1, $m1 === Type::T_NOT ? $t2 : $t1, ]; } if ($m1 === Type::T_NOT && $m2 === Type::T_NOT) { // CSS has no way of representing "neither screen nor print" if ($t1 !== $t2) { return null; } return [Type::T_NOT, $t1]; } if ($t1 !== $t2) { return null; } // t1 == t2, neither m1 nor m2 are "not" return [empty($m1)? $m2 : $m1, $t1]; }
[ "protected", "function", "mergeMediaTypes", "(", "$", "type1", ",", "$", "type2", ")", "{", "if", "(", "empty", "(", "$", "type1", ")", ")", "{", "return", "$", "type2", ";", "}", "if", "(", "empty", "(", "$", "type2", ")", ")", "{", "return", "$", "type1", ";", "}", "$", "m1", "=", "''", ";", "$", "t1", "=", "''", ";", "if", "(", "count", "(", "$", "type1", ")", ">", "1", ")", "{", "$", "m1", "=", "strtolower", "(", "$", "type1", "[", "0", "]", ")", ";", "$", "t1", "=", "strtolower", "(", "$", "type1", "[", "1", "]", ")", ";", "}", "else", "{", "$", "t1", "=", "strtolower", "(", "$", "type1", "[", "0", "]", ")", ";", "}", "$", "m2", "=", "''", ";", "$", "t2", "=", "''", ";", "if", "(", "count", "(", "$", "type2", ")", ">", "1", ")", "{", "$", "m2", "=", "strtolower", "(", "$", "type2", "[", "0", "]", ")", ";", "$", "t2", "=", "strtolower", "(", "$", "type2", "[", "1", "]", ")", ";", "}", "else", "{", "$", "t2", "=", "strtolower", "(", "$", "type2", "[", "0", "]", ")", ";", "}", "if", "(", "(", "$", "m1", "===", "Type", "::", "T_NOT", ")", "^", "(", "$", "m2", "===", "Type", "::", "T_NOT", ")", ")", "{", "if", "(", "$", "t1", "===", "$", "t2", ")", "{", "return", "null", ";", "}", "return", "[", "$", "m1", "===", "Type", "::", "T_NOT", "?", "$", "m2", ":", "$", "m1", ",", "$", "m1", "===", "Type", "::", "T_NOT", "?", "$", "t2", ":", "$", "t1", ",", "]", ";", "}", "if", "(", "$", "m1", "===", "Type", "::", "T_NOT", "&&", "$", "m2", "===", "Type", "::", "T_NOT", ")", "{", "// CSS has no way of representing \"neither screen nor print\"", "if", "(", "$", "t1", "!==", "$", "t2", ")", "{", "return", "null", ";", "}", "return", "[", "Type", "::", "T_NOT", ",", "$", "t1", "]", ";", "}", "if", "(", "$", "t1", "!==", "$", "t2", ")", "{", "return", "null", ";", "}", "// t1 == t2, neither m1 nor m2 are \"not\"", "return", "[", "empty", "(", "$", "m1", ")", "?", "$", "m2", ":", "$", "m1", ",", "$", "t1", "]", ";", "}" ]
Merge media types @param array $type1 @param array $type2 @return array|null
[ "Merge", "media", "types" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L1449-L1505
213,460
moodle/moodle
lib/scssphp/Compiler.php
Compiler.compileImport
protected function compileImport($rawPath, $out, $once = false) { if ($rawPath[0] === Type::T_STRING) { $path = $this->compileStringContent($rawPath); if ($path = $this->findImport($path)) { if (! $once || ! in_array($path, $this->importedFiles)) { $this->importFile($path, $out); $this->importedFiles[] = $path; } return true; } return false; } if ($rawPath[0] === Type::T_LIST) { // handle a list of strings if (count($rawPath[2]) === 0) { return false; } foreach ($rawPath[2] as $path) { if ($path[0] !== Type::T_STRING) { return false; } } foreach ($rawPath[2] as $path) { $this->compileImport($path, $out); } return true; } return false; }
php
protected function compileImport($rawPath, $out, $once = false) { if ($rawPath[0] === Type::T_STRING) { $path = $this->compileStringContent($rawPath); if ($path = $this->findImport($path)) { if (! $once || ! in_array($path, $this->importedFiles)) { $this->importFile($path, $out); $this->importedFiles[] = $path; } return true; } return false; } if ($rawPath[0] === Type::T_LIST) { // handle a list of strings if (count($rawPath[2]) === 0) { return false; } foreach ($rawPath[2] as $path) { if ($path[0] !== Type::T_STRING) { return false; } } foreach ($rawPath[2] as $path) { $this->compileImport($path, $out); } return true; } return false; }
[ "protected", "function", "compileImport", "(", "$", "rawPath", ",", "$", "out", ",", "$", "once", "=", "false", ")", "{", "if", "(", "$", "rawPath", "[", "0", "]", "===", "Type", "::", "T_STRING", ")", "{", "$", "path", "=", "$", "this", "->", "compileStringContent", "(", "$", "rawPath", ")", ";", "if", "(", "$", "path", "=", "$", "this", "->", "findImport", "(", "$", "path", ")", ")", "{", "if", "(", "!", "$", "once", "||", "!", "in_array", "(", "$", "path", ",", "$", "this", "->", "importedFiles", ")", ")", "{", "$", "this", "->", "importFile", "(", "$", "path", ",", "$", "out", ")", ";", "$", "this", "->", "importedFiles", "[", "]", "=", "$", "path", ";", "}", "return", "true", ";", "}", "return", "false", ";", "}", "if", "(", "$", "rawPath", "[", "0", "]", "===", "Type", "::", "T_LIST", ")", "{", "// handle a list of strings", "if", "(", "count", "(", "$", "rawPath", "[", "2", "]", ")", "===", "0", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "rawPath", "[", "2", "]", "as", "$", "path", ")", "{", "if", "(", "$", "path", "[", "0", "]", "!==", "Type", "::", "T_STRING", ")", "{", "return", "false", ";", "}", "}", "foreach", "(", "$", "rawPath", "[", "2", "]", "as", "$", "path", ")", "{", "$", "this", "->", "compileImport", "(", "$", "path", ",", "$", "out", ")", ";", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
Compile import; returns true if the value was something that could be imported @param array $rawPath @param array $out @param boolean $once @return boolean
[ "Compile", "import", ";", "returns", "true", "if", "the", "value", "was", "something", "that", "could", "be", "imported" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L1516-L1553
213,461
moodle/moodle
lib/scssphp/Compiler.php
Compiler.expToString
protected function expToString($exp) { list(, $op, $left, $right, /* $inParens */, $whiteLeft, $whiteRight) = $exp; $content = [$this->reduce($left)]; if ($whiteLeft) { $content[] = ' '; } $content[] = $op; if ($whiteRight) { $content[] = ' '; } $content[] = $this->reduce($right); return [Type::T_STRING, '', $content]; }
php
protected function expToString($exp) { list(, $op, $left, $right, /* $inParens */, $whiteLeft, $whiteRight) = $exp; $content = [$this->reduce($left)]; if ($whiteLeft) { $content[] = ' '; } $content[] = $op; if ($whiteRight) { $content[] = ' '; } $content[] = $this->reduce($right); return [Type::T_STRING, '', $content]; }
[ "protected", "function", "expToString", "(", "$", "exp", ")", "{", "list", "(", ",", "$", "op", ",", "$", "left", ",", "$", "right", ",", "/* $inParens */", ",", "$", "whiteLeft", ",", "$", "whiteRight", ")", "=", "$", "exp", ";", "$", "content", "=", "[", "$", "this", "->", "reduce", "(", "$", "left", ")", "]", ";", "if", "(", "$", "whiteLeft", ")", "{", "$", "content", "[", "]", "=", "' '", ";", "}", "$", "content", "[", "]", "=", "$", "op", ";", "if", "(", "$", "whiteRight", ")", "{", "$", "content", "[", "]", "=", "' '", ";", "}", "$", "content", "[", "]", "=", "$", "this", "->", "reduce", "(", "$", "right", ")", ";", "return", "[", "Type", "::", "T_STRING", ",", "''", ",", "$", "content", "]", ";", "}" ]
Reduce expression to string @param array $exp @return array
[ "Reduce", "expression", "to", "string" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L1943-L1962
213,462
moodle/moodle
lib/scssphp/Compiler.php
Compiler.opNumberColor
protected function opNumberColor($op, $left, $right) { $value = $left[1]; return $this->opColorColor( $op, [Type::T_COLOR, $value, $value, $value], $right ); }
php
protected function opNumberColor($op, $left, $right) { $value = $left[1]; return $this->opColorColor( $op, [Type::T_COLOR, $value, $value, $value], $right ); }
[ "protected", "function", "opNumberColor", "(", "$", "op", ",", "$", "left", ",", "$", "right", ")", "{", "$", "value", "=", "$", "left", "[", "1", "]", ";", "return", "$", "this", "->", "opColorColor", "(", "$", "op", ",", "[", "Type", "::", "T_COLOR", ",", "$", "value", ",", "$", "value", ",", "$", "value", "]", ",", "$", "right", ")", ";", "}" ]
Compare number and color @param string $op @param array $left @param array $right @return array
[ "Compare", "number", "and", "color" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L2524-L2533
213,463
moodle/moodle
lib/scssphp/Compiler.php
Compiler.opEq
protected function opEq($left, $right) { if (($lStr = $this->coerceString($left)) && ($rStr = $this->coerceString($right))) { $lStr[1] = ''; $rStr[1] = ''; $left = $this->compileValue($lStr); $right = $this->compileValue($rStr); } return $this->toBool($left === $right); }
php
protected function opEq($left, $right) { if (($lStr = $this->coerceString($left)) && ($rStr = $this->coerceString($right))) { $lStr[1] = ''; $rStr[1] = ''; $left = $this->compileValue($lStr); $right = $this->compileValue($rStr); } return $this->toBool($left === $right); }
[ "protected", "function", "opEq", "(", "$", "left", ",", "$", "right", ")", "{", "if", "(", "(", "$", "lStr", "=", "$", "this", "->", "coerceString", "(", "$", "left", ")", ")", "&&", "(", "$", "rStr", "=", "$", "this", "->", "coerceString", "(", "$", "right", ")", ")", ")", "{", "$", "lStr", "[", "1", "]", "=", "''", ";", "$", "rStr", "[", "1", "]", "=", "''", ";", "$", "left", "=", "$", "this", "->", "compileValue", "(", "$", "lStr", ")", ";", "$", "right", "=", "$", "this", "->", "compileValue", "(", "$", "rStr", ")", ";", "}", "return", "$", "this", "->", "toBool", "(", "$", "left", "===", "$", "right", ")", ";", "}" ]
Compare number1 == number2 @param array $left @param array $right @return array
[ "Compare", "number1", "==", "number2" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L2543-L2554
213,464
moodle/moodle
lib/scssphp/Compiler.php
Compiler.opCmpNumberNumber
protected function opCmpNumberNumber($left, $right) { $n = $left[1] - $right[1]; return new Node\Number($n ? $n / abs($n) : 0, ''); }
php
protected function opCmpNumberNumber($left, $right) { $n = $left[1] - $right[1]; return new Node\Number($n ? $n / abs($n) : 0, ''); }
[ "protected", "function", "opCmpNumberNumber", "(", "$", "left", ",", "$", "right", ")", "{", "$", "n", "=", "$", "left", "[", "1", "]", "-", "$", "right", "[", "1", "]", ";", "return", "new", "Node", "\\", "Number", "(", "$", "n", "?", "$", "n", "/", "abs", "(", "$", "n", ")", ":", "0", ",", "''", ")", ";", "}" ]
Three-way comparison, aka spaceship operator @param array $left @param array $right @return \Leafo\ScssPhp\Node\Number
[ "Three", "-", "way", "comparison", "aka", "spaceship", "operator" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L2637-L2642
213,465
moodle/moodle
lib/scssphp/Compiler.php
Compiler.extractInterpolation
protected function extractInterpolation($list) { $items = $list[2]; foreach ($items as $i => $item) { if ($item[0] === Type::T_INTERPOLATE) { $before = [Type::T_LIST, $list[1], array_slice($items, 0, $i)]; $after = [Type::T_LIST, $list[1], array_slice($items, $i + 1)]; return [Type::T_INTERPOLATED, $item, $before, $after]; } } return $list; }
php
protected function extractInterpolation($list) { $items = $list[2]; foreach ($items as $i => $item) { if ($item[0] === Type::T_INTERPOLATE) { $before = [Type::T_LIST, $list[1], array_slice($items, 0, $i)]; $after = [Type::T_LIST, $list[1], array_slice($items, $i + 1)]; return [Type::T_INTERPOLATED, $item, $before, $after]; } } return $list; }
[ "protected", "function", "extractInterpolation", "(", "$", "list", ")", "{", "$", "items", "=", "$", "list", "[", "2", "]", ";", "foreach", "(", "$", "items", "as", "$", "i", "=>", "$", "item", ")", "{", "if", "(", "$", "item", "[", "0", "]", "===", "Type", "::", "T_INTERPOLATE", ")", "{", "$", "before", "=", "[", "Type", "::", "T_LIST", ",", "$", "list", "[", "1", "]", ",", "array_slice", "(", "$", "items", ",", "0", ",", "$", "i", ")", "]", ";", "$", "after", "=", "[", "Type", "::", "T_LIST", ",", "$", "list", "[", "1", "]", ",", "array_slice", "(", "$", "items", ",", "$", "i", "+", "1", ")", "]", ";", "return", "[", "Type", "::", "T_INTERPOLATED", ",", "$", "item", ",", "$", "before", ",", "$", "after", "]", ";", "}", "}", "return", "$", "list", ";", "}" ]
Extract interpolation; it doesn't need to be recursive, compileValue will handle that @param array $list @return array
[ "Extract", "interpolation", ";", "it", "doesn", "t", "need", "to", "be", "recursive", "compileValue", "will", "handle", "that" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L2873-L2887
213,466
moodle/moodle
lib/scssphp/Compiler.php
Compiler.compactEnv
private function compactEnv(Environment $env) { for ($envs = []; $env; $env = $env->parent) { $envs[] = $env; } return $envs; }
php
private function compactEnv(Environment $env) { for ($envs = []; $env; $env = $env->parent) { $envs[] = $env; } return $envs; }
[ "private", "function", "compactEnv", "(", "Environment", "$", "env", ")", "{", "for", "(", "$", "envs", "=", "[", "]", ";", "$", "env", ";", "$", "env", "=", "$", "env", "->", "parent", ")", "{", "$", "envs", "[", "]", "=", "$", "env", ";", "}", "return", "$", "envs", ";", "}" ]
Convert env linked list to stack @param \Leafo\ScssPhp\Compiler\Environment $env @return array
[ "Convert", "env", "linked", "list", "to", "stack" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L3010-L3017
213,467
moodle/moodle
lib/scssphp/Compiler.php
Compiler.addParsedFile
public function addParsedFile($path) { if (isset($path) && file_exists($path)) { $this->parsedFiles[realpath($path)] = filemtime($path); } }
php
public function addParsedFile($path) { if (isset($path) && file_exists($path)) { $this->parsedFiles[realpath($path)] = filemtime($path); } }
[ "public", "function", "addParsedFile", "(", "$", "path", ")", "{", "if", "(", "isset", "(", "$", "path", ")", "&&", "file_exists", "(", "$", "path", ")", ")", "{", "$", "this", "->", "parsedFiles", "[", "realpath", "(", "$", "path", ")", "]", "=", "filemtime", "(", "$", "path", ")", ";", "}", "}" ]
Adds to list of parsed files @api @param string $path
[ "Adds", "to", "list", "of", "parsed", "files" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L3278-L3283
213,468
moodle/moodle
lib/scssphp/Compiler.php
Compiler.handleImportLoop
protected function handleImportLoop($name) { for ($env = $this->env; $env; $env = $env->parent) { $file = $this->sourceNames[$env->block->sourceIndex]; if (realpath($file) === $name) { $this->throwError('An @import loop has been found: %s imports %s', $file, basename($file)); break; } } }
php
protected function handleImportLoop($name) { for ($env = $this->env; $env; $env = $env->parent) { $file = $this->sourceNames[$env->block->sourceIndex]; if (realpath($file) === $name) { $this->throwError('An @import loop has been found: %s imports %s', $file, basename($file)); break; } } }
[ "protected", "function", "handleImportLoop", "(", "$", "name", ")", "{", "for", "(", "$", "env", "=", "$", "this", "->", "env", ";", "$", "env", ";", "$", "env", "=", "$", "env", "->", "parent", ")", "{", "$", "file", "=", "$", "this", "->", "sourceNames", "[", "$", "env", "->", "block", "->", "sourceIndex", "]", ";", "if", "(", "realpath", "(", "$", "file", ")", "===", "$", "name", ")", "{", "$", "this", "->", "throwError", "(", "'An @import loop has been found: %s imports %s'", ",", "$", "file", ",", "basename", "(", "$", "file", ")", ")", ";", "break", ";", "}", "}", "}" ]
Handle import loop @param string $name @throws \Exception
[ "Handle", "import", "loop" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L3556-L3566
213,469
moodle/moodle
lib/scssphp/Compiler.php
Compiler.getBuiltinFunction
protected function getBuiltinFunction($name) { $libName = 'lib' . preg_replace_callback( '/_(.)/', function ($m) { return ucfirst($m[1]); }, ucfirst($name) ); return [$this, $libName]; }
php
protected function getBuiltinFunction($name) { $libName = 'lib' . preg_replace_callback( '/_(.)/', function ($m) { return ucfirst($m[1]); }, ucfirst($name) ); return [$this, $libName]; }
[ "protected", "function", "getBuiltinFunction", "(", "$", "name", ")", "{", "$", "libName", "=", "'lib'", ".", "preg_replace_callback", "(", "'/_(.)/'", ",", "function", "(", "$", "m", ")", "{", "return", "ucfirst", "(", "$", "m", "[", "1", "]", ")", ";", "}", ",", "ucfirst", "(", "$", "name", ")", ")", ";", "return", "[", "$", "this", ",", "$", "libName", "]", ";", "}" ]
Get built-in function @param string $name Normalized name @return array
[ "Get", "built", "-", "in", "function" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L3675-L3686
213,470
moodle/moodle
lib/scssphp/Compiler.php
Compiler.coerceMap
protected function coerceMap($item) { if ($item[0] === Type::T_MAP) { return $item; } if ($item === static::$emptyList) { return static::$emptyMap; } return [Type::T_MAP, [$item], [static::$null]]; }
php
protected function coerceMap($item) { if ($item[0] === Type::T_MAP) { return $item; } if ($item === static::$emptyList) { return static::$emptyMap; } return [Type::T_MAP, [$item], [static::$null]]; }
[ "protected", "function", "coerceMap", "(", "$", "item", ")", "{", "if", "(", "$", "item", "[", "0", "]", "===", "Type", "::", "T_MAP", ")", "{", "return", "$", "item", ";", "}", "if", "(", "$", "item", "===", "static", "::", "$", "emptyList", ")", "{", "return", "static", "::", "$", "emptyMap", ";", "}", "return", "[", "Type", "::", "T_MAP", ",", "[", "$", "item", "]", ",", "[", "static", "::", "$", "null", "]", "]", ";", "}" ]
Coerce something to map @param array $item @return array
[ "Coerce", "something", "to", "map" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L3913-L3924
213,471
moodle/moodle
lib/scssphp/Compiler.php
Compiler.coerceList
protected function coerceList($item, $delim = ',') { if (isset($item) && $item[0] === Type::T_LIST) { return $item; } if (isset($item) && $item[0] === Type::T_MAP) { $keys = $item[1]; $values = $item[2]; $list = []; for ($i = 0, $s = count($keys); $i < $s; $i++) { $key = $keys[$i]; $value = $values[$i]; $list[] = [ Type::T_LIST, '', [[Type::T_KEYWORD, $this->compileStringContent($this->coerceString($key))], $value] ]; } return [Type::T_LIST, ',', $list]; } return [Type::T_LIST, $delim, ! isset($item) ? []: [$item]]; }
php
protected function coerceList($item, $delim = ',') { if (isset($item) && $item[0] === Type::T_LIST) { return $item; } if (isset($item) && $item[0] === Type::T_MAP) { $keys = $item[1]; $values = $item[2]; $list = []; for ($i = 0, $s = count($keys); $i < $s; $i++) { $key = $keys[$i]; $value = $values[$i]; $list[] = [ Type::T_LIST, '', [[Type::T_KEYWORD, $this->compileStringContent($this->coerceString($key))], $value] ]; } return [Type::T_LIST, ',', $list]; } return [Type::T_LIST, $delim, ! isset($item) ? []: [$item]]; }
[ "protected", "function", "coerceList", "(", "$", "item", ",", "$", "delim", "=", "','", ")", "{", "if", "(", "isset", "(", "$", "item", ")", "&&", "$", "item", "[", "0", "]", "===", "Type", "::", "T_LIST", ")", "{", "return", "$", "item", ";", "}", "if", "(", "isset", "(", "$", "item", ")", "&&", "$", "item", "[", "0", "]", "===", "Type", "::", "T_MAP", ")", "{", "$", "keys", "=", "$", "item", "[", "1", "]", ";", "$", "values", "=", "$", "item", "[", "2", "]", ";", "$", "list", "=", "[", "]", ";", "for", "(", "$", "i", "=", "0", ",", "$", "s", "=", "count", "(", "$", "keys", ")", ";", "$", "i", "<", "$", "s", ";", "$", "i", "++", ")", "{", "$", "key", "=", "$", "keys", "[", "$", "i", "]", ";", "$", "value", "=", "$", "values", "[", "$", "i", "]", ";", "$", "list", "[", "]", "=", "[", "Type", "::", "T_LIST", ",", "''", ",", "[", "[", "Type", "::", "T_KEYWORD", ",", "$", "this", "->", "compileStringContent", "(", "$", "this", "->", "coerceString", "(", "$", "key", ")", ")", "]", ",", "$", "value", "]", "]", ";", "}", "return", "[", "Type", "::", "T_LIST", ",", "','", ",", "$", "list", "]", ";", "}", "return", "[", "Type", "::", "T_LIST", ",", "$", "delim", ",", "!", "isset", "(", "$", "item", ")", "?", "[", "]", ":", "[", "$", "item", "]", "]", ";", "}" ]
Coerce something to list @param array $item @param string $delim @return array
[ "Coerce", "something", "to", "list" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L3934-L3960
213,472
moodle/moodle
lib/scssphp/Compiler.php
Compiler.coerceColor
protected function coerceColor($value) { switch ($value[0]) { case Type::T_COLOR: return $value; case Type::T_KEYWORD: $name = strtolower($value[1]); if (isset(Colors::$cssColors[$name])) { $rgba = explode(',', Colors::$cssColors[$name]); return isset($rgba[3]) ? [Type::T_COLOR, (int) $rgba[0], (int) $rgba[1], (int) $rgba[2], (int) $rgba[3]] : [Type::T_COLOR, (int) $rgba[0], (int) $rgba[1], (int) $rgba[2]]; } return null; } return null; }
php
protected function coerceColor($value) { switch ($value[0]) { case Type::T_COLOR: return $value; case Type::T_KEYWORD: $name = strtolower($value[1]); if (isset(Colors::$cssColors[$name])) { $rgba = explode(',', Colors::$cssColors[$name]); return isset($rgba[3]) ? [Type::T_COLOR, (int) $rgba[0], (int) $rgba[1], (int) $rgba[2], (int) $rgba[3]] : [Type::T_COLOR, (int) $rgba[0], (int) $rgba[1], (int) $rgba[2]]; } return null; } return null; }
[ "protected", "function", "coerceColor", "(", "$", "value", ")", "{", "switch", "(", "$", "value", "[", "0", "]", ")", "{", "case", "Type", "::", "T_COLOR", ":", "return", "$", "value", ";", "case", "Type", "::", "T_KEYWORD", ":", "$", "name", "=", "strtolower", "(", "$", "value", "[", "1", "]", ")", ";", "if", "(", "isset", "(", "Colors", "::", "$", "cssColors", "[", "$", "name", "]", ")", ")", "{", "$", "rgba", "=", "explode", "(", "','", ",", "Colors", "::", "$", "cssColors", "[", "$", "name", "]", ")", ";", "return", "isset", "(", "$", "rgba", "[", "3", "]", ")", "?", "[", "Type", "::", "T_COLOR", ",", "(", "int", ")", "$", "rgba", "[", "0", "]", ",", "(", "int", ")", "$", "rgba", "[", "1", "]", ",", "(", "int", ")", "$", "rgba", "[", "2", "]", ",", "(", "int", ")", "$", "rgba", "[", "3", "]", "]", ":", "[", "Type", "::", "T_COLOR", ",", "(", "int", ")", "$", "rgba", "[", "0", "]", ",", "(", "int", ")", "$", "rgba", "[", "1", "]", ",", "(", "int", ")", "$", "rgba", "[", "2", "]", "]", ";", "}", "return", "null", ";", "}", "return", "null", ";", "}" ]
Coerce value to color @param array $value @return array|null
[ "Coerce", "value", "to", "color" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L3985-L4006
213,473
moodle/moodle
lib/scssphp/Compiler.php
Compiler.coerceString
protected function coerceString($value) { if ($value[0] === Type::T_STRING) { return $value; } return [Type::T_STRING, '', [$this->compileValue($value)]]; }
php
protected function coerceString($value) { if ($value[0] === Type::T_STRING) { return $value; } return [Type::T_STRING, '', [$this->compileValue($value)]]; }
[ "protected", "function", "coerceString", "(", "$", "value", ")", "{", "if", "(", "$", "value", "[", "0", "]", "===", "Type", "::", "T_STRING", ")", "{", "return", "$", "value", ";", "}", "return", "[", "Type", "::", "T_STRING", ",", "''", ",", "[", "$", "this", "->", "compileValue", "(", "$", "value", ")", "]", "]", ";", "}" ]
Coerce value to string @param array $value @return array|null
[ "Coerce", "value", "to", "string" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L4015-L4022
213,474
moodle/moodle
lib/scssphp/Compiler.php
Compiler.fixColor
protected function fixColor($c) { foreach ([1, 2, 3] as $i) { if ($c[$i] < 0) { $c[$i] = 0; } if ($c[$i] > 255) { $c[$i] = 255; } } return $c; }
php
protected function fixColor($c) { foreach ([1, 2, 3] as $i) { if ($c[$i] < 0) { $c[$i] = 0; } if ($c[$i] > 255) { $c[$i] = 255; } } return $c; }
[ "protected", "function", "fixColor", "(", "$", "c", ")", "{", "foreach", "(", "[", "1", ",", "2", ",", "3", "]", "as", "$", "i", ")", "{", "if", "(", "$", "c", "[", "$", "i", "]", "<", "0", ")", "{", "$", "c", "[", "$", "i", "]", "=", "0", ";", "}", "if", "(", "$", "c", "[", "$", "i", "]", ">", "255", ")", "{", "$", "c", "[", "$", "i", "]", "=", "255", ";", "}", "}", "return", "$", "c", ";", "}" ]
Make sure a color's components don't go out of bounds @param array $c @return array
[ "Make", "sure", "a", "color", "s", "components", "don", "t", "go", "out", "of", "bounds" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L4133-L4146
213,475
moodle/moodle
lib/scssphp/Compiler.php
Compiler.toHSL
public function toHSL($red, $green, $blue) { $min = min($red, $green, $blue); $max = max($red, $green, $blue); $l = $min + $max; $d = $max - $min; if ((int) $d === 0) { $h = $s = 0; } else { if ($l < 255) { $s = $d / $l; } else { $s = $d / (510 - $l); } if ($red == $max) { $h = 60 * ($green - $blue) / $d; } elseif ($green == $max) { $h = 60 * ($blue - $red) / $d + 120; } elseif ($blue == $max) { $h = 60 * ($red - $green) / $d + 240; } } return [Type::T_HSL, fmod($h, 360), $s * 100, $l / 5.1]; }
php
public function toHSL($red, $green, $blue) { $min = min($red, $green, $blue); $max = max($red, $green, $blue); $l = $min + $max; $d = $max - $min; if ((int) $d === 0) { $h = $s = 0; } else { if ($l < 255) { $s = $d / $l; } else { $s = $d / (510 - $l); } if ($red == $max) { $h = 60 * ($green - $blue) / $d; } elseif ($green == $max) { $h = 60 * ($blue - $red) / $d + 120; } elseif ($blue == $max) { $h = 60 * ($red - $green) / $d + 240; } } return [Type::T_HSL, fmod($h, 360), $s * 100, $l / 5.1]; }
[ "public", "function", "toHSL", "(", "$", "red", ",", "$", "green", ",", "$", "blue", ")", "{", "$", "min", "=", "min", "(", "$", "red", ",", "$", "green", ",", "$", "blue", ")", ";", "$", "max", "=", "max", "(", "$", "red", ",", "$", "green", ",", "$", "blue", ")", ";", "$", "l", "=", "$", "min", "+", "$", "max", ";", "$", "d", "=", "$", "max", "-", "$", "min", ";", "if", "(", "(", "int", ")", "$", "d", "===", "0", ")", "{", "$", "h", "=", "$", "s", "=", "0", ";", "}", "else", "{", "if", "(", "$", "l", "<", "255", ")", "{", "$", "s", "=", "$", "d", "/", "$", "l", ";", "}", "else", "{", "$", "s", "=", "$", "d", "/", "(", "510", "-", "$", "l", ")", ";", "}", "if", "(", "$", "red", "==", "$", "max", ")", "{", "$", "h", "=", "60", "*", "(", "$", "green", "-", "$", "blue", ")", "/", "$", "d", ";", "}", "elseif", "(", "$", "green", "==", "$", "max", ")", "{", "$", "h", "=", "60", "*", "(", "$", "blue", "-", "$", "red", ")", "/", "$", "d", "+", "120", ";", "}", "elseif", "(", "$", "blue", "==", "$", "max", ")", "{", "$", "h", "=", "60", "*", "(", "$", "red", "-", "$", "green", ")", "/", "$", "d", "+", "240", ";", "}", "}", "return", "[", "Type", "::", "T_HSL", ",", "fmod", "(", "$", "h", ",", "360", ")", ",", "$", "s", "*", "100", ",", "$", "l", "/", "5.1", "]", ";", "}" ]
Convert RGB to HSL @api @param integer $red @param integer $green @param integer $blue @return array
[ "Convert", "RGB", "to", "HSL" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L4159-L4186
213,476
moodle/moodle
lib/scssphp/Compiler.php
Compiler.getNormalizedNumbers
protected function getNormalizedNumbers($args) { $unit = null; $originalUnit = null; $numbers = []; foreach ($args as $key => $item) { if ($item[0] !== Type::T_NUMBER) { $this->throwError('%s is not a number', $item[0]); break; } $number = $item->normalize(); if (null === $unit) { $unit = $number[2]; $originalUnit = $item->unitStr(); } elseif ($unit !== $number[2]) { $this->throwError('Incompatible units: "%s" and "%s".', $originalUnit, $item->unitStr()); break; } $numbers[$key] = $number; } return $numbers; }
php
protected function getNormalizedNumbers($args) { $unit = null; $originalUnit = null; $numbers = []; foreach ($args as $key => $item) { if ($item[0] !== Type::T_NUMBER) { $this->throwError('%s is not a number', $item[0]); break; } $number = $item->normalize(); if (null === $unit) { $unit = $number[2]; $originalUnit = $item->unitStr(); } elseif ($unit !== $number[2]) { $this->throwError('Incompatible units: "%s" and "%s".', $originalUnit, $item->unitStr()); break; } $numbers[$key] = $number; } return $numbers; }
[ "protected", "function", "getNormalizedNumbers", "(", "$", "args", ")", "{", "$", "unit", "=", "null", ";", "$", "originalUnit", "=", "null", ";", "$", "numbers", "=", "[", "]", ";", "foreach", "(", "$", "args", "as", "$", "key", "=>", "$", "item", ")", "{", "if", "(", "$", "item", "[", "0", "]", "!==", "Type", "::", "T_NUMBER", ")", "{", "$", "this", "->", "throwError", "(", "'%s is not a number'", ",", "$", "item", "[", "0", "]", ")", ";", "break", ";", "}", "$", "number", "=", "$", "item", "->", "normalize", "(", ")", ";", "if", "(", "null", "===", "$", "unit", ")", "{", "$", "unit", "=", "$", "number", "[", "2", "]", ";", "$", "originalUnit", "=", "$", "item", "->", "unitStr", "(", ")", ";", "}", "elseif", "(", "$", "unit", "!==", "$", "number", "[", "2", "]", ")", "{", "$", "this", "->", "throwError", "(", "'Incompatible units: \"%s\" and \"%s\".'", ",", "$", "originalUnit", ",", "$", "item", "->", "unitStr", "(", ")", ")", ";", "break", ";", "}", "$", "numbers", "[", "$", "key", "]", "=", "$", "number", ";", "}", "return", "$", "numbers", ";", "}" ]
Helper to normalize args containing numbers @param array $args @return array
[ "Helper", "to", "normalize", "args", "containing", "numbers" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L4815-L4841
213,477
moodle/moodle
lib/scssphp/Compiler.php
Compiler.libCounter
protected function libCounter($args) { $list = array_map([$this, 'compileValue'], $args); return [Type::T_STRING, '', ['counter(' . implode(',', $list) . ')']]; }
php
protected function libCounter($args) { $list = array_map([$this, 'compileValue'], $args); return [Type::T_STRING, '', ['counter(' . implode(',', $list) . ')']]; }
[ "protected", "function", "libCounter", "(", "$", "args", ")", "{", "$", "list", "=", "array_map", "(", "[", "$", "this", ",", "'compileValue'", "]", ",", "$", "args", ")", ";", "return", "[", "Type", "::", "T_STRING", ",", "''", ",", "[", "'counter('", ".", "implode", "(", "','", ",", "$", "list", ")", ".", "')'", "]", "]", ";", "}" ]
Workaround IE7's content counter bug. @param array $args @return array
[ "Workaround", "IE7", "s", "content", "counter", "bug", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Compiler.php#L5289-L5294
213,478
moodle/moodle
enrol/cohort/lib.php
enrol_cohort_plugin.get_instance_name
public function get_instance_name($instance) { global $DB; if (empty($instance)) { $enrol = $this->get_name(); return get_string('pluginname', 'enrol_'.$enrol); } else if (empty($instance->name)) { $enrol = $this->get_name(); $cohort = $DB->get_record('cohort', array('id'=>$instance->customint1)); if (!$cohort) { return get_string('pluginname', 'enrol_'.$enrol); } $cohortname = format_string($cohort->name, true, array('context'=>context::instance_by_id($cohort->contextid))); if ($role = $DB->get_record('role', array('id'=>$instance->roleid))) { $role = role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING)); return get_string('pluginname', 'enrol_'.$enrol) . ' (' . $cohortname . ' - ' . $role .')'; } else { return get_string('pluginname', 'enrol_'.$enrol) . ' (' . $cohortname . ')'; } } else { return format_string($instance->name, true, array('context'=>context_course::instance($instance->courseid))); } }
php
public function get_instance_name($instance) { global $DB; if (empty($instance)) { $enrol = $this->get_name(); return get_string('pluginname', 'enrol_'.$enrol); } else if (empty($instance->name)) { $enrol = $this->get_name(); $cohort = $DB->get_record('cohort', array('id'=>$instance->customint1)); if (!$cohort) { return get_string('pluginname', 'enrol_'.$enrol); } $cohortname = format_string($cohort->name, true, array('context'=>context::instance_by_id($cohort->contextid))); if ($role = $DB->get_record('role', array('id'=>$instance->roleid))) { $role = role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING)); return get_string('pluginname', 'enrol_'.$enrol) . ' (' . $cohortname . ' - ' . $role .')'; } else { return get_string('pluginname', 'enrol_'.$enrol) . ' (' . $cohortname . ')'; } } else { return format_string($instance->name, true, array('context'=>context_course::instance($instance->courseid))); } }
[ "public", "function", "get_instance_name", "(", "$", "instance", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "instance", ")", ")", "{", "$", "enrol", "=", "$", "this", "->", "get_name", "(", ")", ";", "return", "get_string", "(", "'pluginname'", ",", "'enrol_'", ".", "$", "enrol", ")", ";", "}", "else", "if", "(", "empty", "(", "$", "instance", "->", "name", ")", ")", "{", "$", "enrol", "=", "$", "this", "->", "get_name", "(", ")", ";", "$", "cohort", "=", "$", "DB", "->", "get_record", "(", "'cohort'", ",", "array", "(", "'id'", "=>", "$", "instance", "->", "customint1", ")", ")", ";", "if", "(", "!", "$", "cohort", ")", "{", "return", "get_string", "(", "'pluginname'", ",", "'enrol_'", ".", "$", "enrol", ")", ";", "}", "$", "cohortname", "=", "format_string", "(", "$", "cohort", "->", "name", ",", "true", ",", "array", "(", "'context'", "=>", "context", "::", "instance_by_id", "(", "$", "cohort", "->", "contextid", ")", ")", ")", ";", "if", "(", "$", "role", "=", "$", "DB", "->", "get_record", "(", "'role'", ",", "array", "(", "'id'", "=>", "$", "instance", "->", "roleid", ")", ")", ")", "{", "$", "role", "=", "role_get_name", "(", "$", "role", ",", "context_course", "::", "instance", "(", "$", "instance", "->", "courseid", ",", "IGNORE_MISSING", ")", ")", ";", "return", "get_string", "(", "'pluginname'", ",", "'enrol_'", ".", "$", "enrol", ")", ".", "' ('", ".", "$", "cohortname", ".", "' - '", ".", "$", "role", ".", "')'", ";", "}", "else", "{", "return", "get_string", "(", "'pluginname'", ",", "'enrol_'", ".", "$", "enrol", ")", ".", "' ('", ".", "$", "cohortname", ".", "')'", ";", "}", "}", "else", "{", "return", "format_string", "(", "$", "instance", "->", "name", ",", "true", ",", "array", "(", "'context'", "=>", "context_course", "::", "instance", "(", "$", "instance", "->", "courseid", ")", ")", ")", ";", "}", "}" ]
Returns localised name of enrol instance. @param stdClass $instance (null is accepted too) @return string
[ "Returns", "localised", "name", "of", "enrol", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/cohort/lib.php#L56-L80
213,479
moodle/moodle
enrol/cohort/lib.php
enrol_cohort_plugin.can_add_instance
public function can_add_instance($courseid) { global $CFG; require_once($CFG->dirroot . '/cohort/lib.php'); $coursecontext = context_course::instance($courseid); if (!has_capability('moodle/course:enrolconfig', $coursecontext) or !has_capability('enrol/cohort:config', $coursecontext)) { return false; } return cohort_get_available_cohorts($coursecontext, 0, 0, 1) ? true : false; }
php
public function can_add_instance($courseid) { global $CFG; require_once($CFG->dirroot . '/cohort/lib.php'); $coursecontext = context_course::instance($courseid); if (!has_capability('moodle/course:enrolconfig', $coursecontext) or !has_capability('enrol/cohort:config', $coursecontext)) { return false; } return cohort_get_available_cohorts($coursecontext, 0, 0, 1) ? true : false; }
[ "public", "function", "can_add_instance", "(", "$", "courseid", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/cohort/lib.php'", ")", ";", "$", "coursecontext", "=", "context_course", "::", "instance", "(", "$", "courseid", ")", ";", "if", "(", "!", "has_capability", "(", "'moodle/course:enrolconfig'", ",", "$", "coursecontext", ")", "or", "!", "has_capability", "(", "'enrol/cohort:config'", ",", "$", "coursecontext", ")", ")", "{", "return", "false", ";", "}", "return", "cohort_get_available_cohorts", "(", "$", "coursecontext", ",", "0", ",", "0", ",", "1", ")", "?", "true", ":", "false", ";", "}" ]
Given a courseid this function returns true if the user is able to enrol or configure cohorts. AND there are cohorts that the user can view. @param int $courseid @return bool
[ "Given", "a", "courseid", "this", "function", "returns", "true", "if", "the", "user", "is", "able", "to", "enrol", "or", "configure", "cohorts", ".", "AND", "there", "are", "cohorts", "that", "the", "user", "can", "view", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/cohort/lib.php#L89-L97
213,480
moodle/moodle
enrol/cohort/lib.php
enrol_cohort_plugin.get_cohort_options
protected function get_cohort_options($instance, $context) { global $DB, $CFG; require_once($CFG->dirroot . '/cohort/lib.php'); $cohorts = array(); if ($instance->id) { if ($cohort = $DB->get_record('cohort', array('id' => $instance->customint1))) { $name = format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid))); $cohorts = array($instance->customint1 => $name); } else { $cohorts = array($instance->customint1 => get_string('error')); } } else { $cohorts = array('' => get_string('choosedots')); $allcohorts = cohort_get_available_cohorts($context, 0, 0, 0); foreach ($allcohorts as $c) { $cohorts[$c->id] = format_string($c->name); } } return $cohorts; }
php
protected function get_cohort_options($instance, $context) { global $DB, $CFG; require_once($CFG->dirroot . '/cohort/lib.php'); $cohorts = array(); if ($instance->id) { if ($cohort = $DB->get_record('cohort', array('id' => $instance->customint1))) { $name = format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid))); $cohorts = array($instance->customint1 => $name); } else { $cohorts = array($instance->customint1 => get_string('error')); } } else { $cohorts = array('' => get_string('choosedots')); $allcohorts = cohort_get_available_cohorts($context, 0, 0, 0); foreach ($allcohorts as $c) { $cohorts[$c->id] = format_string($c->name); } } return $cohorts; }
[ "protected", "function", "get_cohort_options", "(", "$", "instance", ",", "$", "context", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/cohort/lib.php'", ")", ";", "$", "cohorts", "=", "array", "(", ")", ";", "if", "(", "$", "instance", "->", "id", ")", "{", "if", "(", "$", "cohort", "=", "$", "DB", "->", "get_record", "(", "'cohort'", ",", "array", "(", "'id'", "=>", "$", "instance", "->", "customint1", ")", ")", ")", "{", "$", "name", "=", "format_string", "(", "$", "cohort", "->", "name", ",", "true", ",", "array", "(", "'context'", "=>", "context", "::", "instance_by_id", "(", "$", "cohort", "->", "contextid", ")", ")", ")", ";", "$", "cohorts", "=", "array", "(", "$", "instance", "->", "customint1", "=>", "$", "name", ")", ";", "}", "else", "{", "$", "cohorts", "=", "array", "(", "$", "instance", "->", "customint1", "=>", "get_string", "(", "'error'", ")", ")", ";", "}", "}", "else", "{", "$", "cohorts", "=", "array", "(", "''", "=>", "get_string", "(", "'choosedots'", ")", ")", ";", "$", "allcohorts", "=", "cohort_get_available_cohorts", "(", "$", "context", ",", "0", ",", "0", ",", "0", ")", ";", "foreach", "(", "$", "allcohorts", "as", "$", "c", ")", "{", "$", "cohorts", "[", "$", "c", "->", "id", "]", "=", "format_string", "(", "$", "c", "->", "name", ")", ";", "}", "}", "return", "$", "cohorts", ";", "}" ]
Return an array of valid options for the cohorts. @param stdClass $instance @param context $context @return array
[ "Return", "an", "array", "of", "valid", "options", "for", "the", "cohorts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/cohort/lib.php#L333-L355
213,481
moodle/moodle
enrol/cohort/lib.php
enrol_cohort_plugin.get_role_options
protected function get_role_options($instance, $coursecontext) { global $DB; $roles = get_assignable_roles($coursecontext); $roles[0] = get_string('none'); $roles = array_reverse($roles, true); // Descending default sortorder. if ($instance->id and !isset($roles[$instance->roleid])) { if ($role = $DB->get_record('role', array('id' => $instance->roleid))) { $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS, true); $roles[$instance->roleid] = role_get_name($role, $coursecontext); } else { $roles[$instance->roleid] = get_string('error'); } } return $roles; }
php
protected function get_role_options($instance, $coursecontext) { global $DB; $roles = get_assignable_roles($coursecontext); $roles[0] = get_string('none'); $roles = array_reverse($roles, true); // Descending default sortorder. if ($instance->id and !isset($roles[$instance->roleid])) { if ($role = $DB->get_record('role', array('id' => $instance->roleid))) { $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS, true); $roles[$instance->roleid] = role_get_name($role, $coursecontext); } else { $roles[$instance->roleid] = get_string('error'); } } return $roles; }
[ "protected", "function", "get_role_options", "(", "$", "instance", ",", "$", "coursecontext", ")", "{", "global", "$", "DB", ";", "$", "roles", "=", "get_assignable_roles", "(", "$", "coursecontext", ")", ";", "$", "roles", "[", "0", "]", "=", "get_string", "(", "'none'", ")", ";", "$", "roles", "=", "array_reverse", "(", "$", "roles", ",", "true", ")", ";", "// Descending default sortorder.", "if", "(", "$", "instance", "->", "id", "and", "!", "isset", "(", "$", "roles", "[", "$", "instance", "->", "roleid", "]", ")", ")", "{", "if", "(", "$", "role", "=", "$", "DB", "->", "get_record", "(", "'role'", ",", "array", "(", "'id'", "=>", "$", "instance", "->", "roleid", ")", ")", ")", "{", "$", "roles", "=", "role_fix_names", "(", "$", "roles", ",", "$", "coursecontext", ",", "ROLENAME_ALIAS", ",", "true", ")", ";", "$", "roles", "[", "$", "instance", "->", "roleid", "]", "=", "role_get_name", "(", "$", "role", ",", "$", "coursecontext", ")", ";", "}", "else", "{", "$", "roles", "[", "$", "instance", "->", "roleid", "]", "=", "get_string", "(", "'error'", ")", ";", "}", "}", "return", "$", "roles", ";", "}" ]
Return an array of valid options for the roles. @param stdClass $instance @param context $coursecontext @return array
[ "Return", "an", "array", "of", "valid", "options", "for", "the", "roles", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/cohort/lib.php#L364-L380
213,482
moodle/moodle
enrol/cohort/lib.php
enrol_cohort_plugin.get_group_options
protected function get_group_options($coursecontext) { $groups = array(0 => get_string('none')); if (has_capability('moodle/course:managegroups', $coursecontext)) { $groups[COHORT_CREATE_GROUP] = get_string('creategroup', 'enrol_cohort'); } foreach (groups_get_all_groups($coursecontext->instanceid) as $group) { $groups[$group->id] = format_string($group->name, true, array('context' => $coursecontext)); } return $groups; }
php
protected function get_group_options($coursecontext) { $groups = array(0 => get_string('none')); if (has_capability('moodle/course:managegroups', $coursecontext)) { $groups[COHORT_CREATE_GROUP] = get_string('creategroup', 'enrol_cohort'); } foreach (groups_get_all_groups($coursecontext->instanceid) as $group) { $groups[$group->id] = format_string($group->name, true, array('context' => $coursecontext)); } return $groups; }
[ "protected", "function", "get_group_options", "(", "$", "coursecontext", ")", "{", "$", "groups", "=", "array", "(", "0", "=>", "get_string", "(", "'none'", ")", ")", ";", "if", "(", "has_capability", "(", "'moodle/course:managegroups'", ",", "$", "coursecontext", ")", ")", "{", "$", "groups", "[", "COHORT_CREATE_GROUP", "]", "=", "get_string", "(", "'creategroup'", ",", "'enrol_cohort'", ")", ";", "}", "foreach", "(", "groups_get_all_groups", "(", "$", "coursecontext", "->", "instanceid", ")", "as", "$", "group", ")", "{", "$", "groups", "[", "$", "group", "->", "id", "]", "=", "format_string", "(", "$", "group", "->", "name", ",", "true", ",", "array", "(", "'context'", "=>", "$", "coursecontext", ")", ")", ";", "}", "return", "$", "groups", ";", "}" ]
Return an array of valid options for the groups. @param context $coursecontext @return array
[ "Return", "an", "array", "of", "valid", "options", "for", "the", "groups", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/cohort/lib.php#L388-L399
213,483
moodle/moodle
files/converter/googledrive/classes/converter.php
converter.supports
public static function supports($from, $to) { // This is not a one-liner because of php 5.6. $imports = self::$imports; $exports = self::$exports; return isset($imports[$from]) && isset($exports[$to]); }
php
public static function supports($from, $to) { // This is not a one-liner because of php 5.6. $imports = self::$imports; $exports = self::$exports; return isset($imports[$from]) && isset($exports[$to]); }
[ "public", "static", "function", "supports", "(", "$", "from", ",", "$", "to", ")", "{", "// This is not a one-liner because of php 5.6.", "$", "imports", "=", "self", "::", "$", "imports", ";", "$", "exports", "=", "self", "::", "$", "exports", ";", "return", "isset", "(", "$", "imports", "[", "$", "from", "]", ")", "&&", "isset", "(", "$", "exports", "[", "$", "to", "]", ")", ";", "}" ]
Whether a file conversion can be completed using this converter. @param string $from The source type @param string $to The destination type @return bool
[ "Whether", "a", "file", "conversion", "can", "be", "completed", "using", "this", "converter", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/converter/googledrive/classes/converter.php#L256-L261
213,484
moodle/moodle
calendar/classes/external/month_exporter.php
month_exporter.get_day_names
protected function get_day_names(renderer_base $output) { $weekdays = $this->related['type']->get_weekdays(); $daysinweek = count($weekdays); $daynames = []; for ($i = 0; $i < $daysinweek; $i++) { // Bump the currentdayno and ensure it loops. $dayno = ($i + $this->firstdayofweek + $daysinweek) % $daysinweek; $dayname = new day_name_exporter($dayno, $weekdays[$dayno]); $daynames[] = $dayname->export($output); } return $daynames; }
php
protected function get_day_names(renderer_base $output) { $weekdays = $this->related['type']->get_weekdays(); $daysinweek = count($weekdays); $daynames = []; for ($i = 0; $i < $daysinweek; $i++) { // Bump the currentdayno and ensure it loops. $dayno = ($i + $this->firstdayofweek + $daysinweek) % $daysinweek; $dayname = new day_name_exporter($dayno, $weekdays[$dayno]); $daynames[] = $dayname->export($output); } return $daynames; }
[ "protected", "function", "get_day_names", "(", "renderer_base", "$", "output", ")", "{", "$", "weekdays", "=", "$", "this", "->", "related", "[", "'type'", "]", "->", "get_weekdays", "(", ")", ";", "$", "daysinweek", "=", "count", "(", "$", "weekdays", ")", ";", "$", "daynames", "=", "[", "]", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "daysinweek", ";", "$", "i", "++", ")", "{", "// Bump the currentdayno and ensure it loops.", "$", "dayno", "=", "(", "$", "i", "+", "$", "this", "->", "firstdayofweek", "+", "$", "daysinweek", ")", "%", "$", "daysinweek", ";", "$", "dayname", "=", "new", "day_name_exporter", "(", "$", "dayno", ",", "$", "weekdays", "[", "$", "dayno", "]", ")", ";", "$", "daynames", "[", "]", "=", "$", "dayname", "->", "export", "(", "$", "output", ")", ";", "}", "return", "$", "daynames", ";", "}" ]
Get the list of day names for display, re-ordered from the first day of the week. @param renderer_base $output @return day_name_exporter[]
[ "Get", "the", "list", "of", "day", "names", "for", "display", "re", "-", "ordered", "from", "the", "first", "day", "of", "the", "week", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/month_exporter.php#L268-L281
213,485
moodle/moodle
calendar/classes/external/month_exporter.php
month_exporter.get_weeks
protected function get_weeks(renderer_base $output) { $weeks = []; $alldays = $this->get_days(); $daysinweek = count($this->related['type']->get_weekdays()); // Calculate which day number is the first, and last day of the week. $firstdayofweek = $this->firstdayofweek; // The first week is special as it may have padding at the beginning. $day = reset($alldays); $firstdayno = $day['wday']; $prepadding = ($firstdayno + $daysinweek - $firstdayofweek) % $daysinweek; $daysinfirstweek = $daysinweek - $prepadding; $days = array_slice($alldays, 0, $daysinfirstweek); $week = new week_exporter($this->calendar, $days, $prepadding, ($daysinweek - count($days) - $prepadding), $this->related); $weeks[] = $week->export($output); // Now chunk up the remaining day. and turn them into weeks. $daychunks = array_chunk(array_slice($alldays, $daysinfirstweek), $daysinweek); foreach ($daychunks as $days) { $week = new week_exporter($this->calendar, $days, 0, ($daysinweek - count($days)), $this->related); $weeks[] = $week->export($output); } return $weeks; }
php
protected function get_weeks(renderer_base $output) { $weeks = []; $alldays = $this->get_days(); $daysinweek = count($this->related['type']->get_weekdays()); // Calculate which day number is the first, and last day of the week. $firstdayofweek = $this->firstdayofweek; // The first week is special as it may have padding at the beginning. $day = reset($alldays); $firstdayno = $day['wday']; $prepadding = ($firstdayno + $daysinweek - $firstdayofweek) % $daysinweek; $daysinfirstweek = $daysinweek - $prepadding; $days = array_slice($alldays, 0, $daysinfirstweek); $week = new week_exporter($this->calendar, $days, $prepadding, ($daysinweek - count($days) - $prepadding), $this->related); $weeks[] = $week->export($output); // Now chunk up the remaining day. and turn them into weeks. $daychunks = array_chunk(array_slice($alldays, $daysinfirstweek), $daysinweek); foreach ($daychunks as $days) { $week = new week_exporter($this->calendar, $days, 0, ($daysinweek - count($days)), $this->related); $weeks[] = $week->export($output); } return $weeks; }
[ "protected", "function", "get_weeks", "(", "renderer_base", "$", "output", ")", "{", "$", "weeks", "=", "[", "]", ";", "$", "alldays", "=", "$", "this", "->", "get_days", "(", ")", ";", "$", "daysinweek", "=", "count", "(", "$", "this", "->", "related", "[", "'type'", "]", "->", "get_weekdays", "(", ")", ")", ";", "// Calculate which day number is the first, and last day of the week.", "$", "firstdayofweek", "=", "$", "this", "->", "firstdayofweek", ";", "// The first week is special as it may have padding at the beginning.", "$", "day", "=", "reset", "(", "$", "alldays", ")", ";", "$", "firstdayno", "=", "$", "day", "[", "'wday'", "]", ";", "$", "prepadding", "=", "(", "$", "firstdayno", "+", "$", "daysinweek", "-", "$", "firstdayofweek", ")", "%", "$", "daysinweek", ";", "$", "daysinfirstweek", "=", "$", "daysinweek", "-", "$", "prepadding", ";", "$", "days", "=", "array_slice", "(", "$", "alldays", ",", "0", ",", "$", "daysinfirstweek", ")", ";", "$", "week", "=", "new", "week_exporter", "(", "$", "this", "->", "calendar", ",", "$", "days", ",", "$", "prepadding", ",", "(", "$", "daysinweek", "-", "count", "(", "$", "days", ")", "-", "$", "prepadding", ")", ",", "$", "this", "->", "related", ")", ";", "$", "weeks", "[", "]", "=", "$", "week", "->", "export", "(", "$", "output", ")", ";", "// Now chunk up the remaining day. and turn them into weeks.", "$", "daychunks", "=", "array_chunk", "(", "array_slice", "(", "$", "alldays", ",", "$", "daysinfirstweek", ")", ",", "$", "daysinweek", ")", ";", "foreach", "(", "$", "daychunks", "as", "$", "days", ")", "{", "$", "week", "=", "new", "week_exporter", "(", "$", "this", "->", "calendar", ",", "$", "days", ",", "0", ",", "(", "$", "daysinweek", "-", "count", "(", "$", "days", ")", ")", ",", "$", "this", "->", "related", ")", ";", "$", "weeks", "[", "]", "=", "$", "week", "->", "export", "(", "$", "output", ")", ";", "}", "return", "$", "weeks", ";", "}" ]
Get the list of week days, ordered into weeks and padded according to the value of the first day of the week. @param renderer_base $output @return array The list of weeks.
[ "Get", "the", "list", "of", "week", "days", "ordered", "into", "weeks", "and", "padded", "according", "to", "the", "value", "of", "the", "first", "day", "of", "the", "week", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/month_exporter.php#L290-L317
213,486
moodle/moodle
calendar/classes/external/month_exporter.php
month_exporter.get_days
protected function get_days() { $date = $this->related['type']->timestamp_to_date_array($this->calendar->time); $monthdays = $this->related['type']->get_num_days_in_month($date['year'], $date['mon']); $days = []; for ($dayno = 1; $dayno <= $monthdays; $dayno++) { // Get the gregorian representation of the day. $timestamp = $this->related['type']->convert_to_timestamp($date['year'], $date['mon'], $dayno); $days[] = $this->related['type']->timestamp_to_date_array($timestamp); } return $days; }
php
protected function get_days() { $date = $this->related['type']->timestamp_to_date_array($this->calendar->time); $monthdays = $this->related['type']->get_num_days_in_month($date['year'], $date['mon']); $days = []; for ($dayno = 1; $dayno <= $monthdays; $dayno++) { // Get the gregorian representation of the day. $timestamp = $this->related['type']->convert_to_timestamp($date['year'], $date['mon'], $dayno); $days[] = $this->related['type']->timestamp_to_date_array($timestamp); } return $days; }
[ "protected", "function", "get_days", "(", ")", "{", "$", "date", "=", "$", "this", "->", "related", "[", "'type'", "]", "->", "timestamp_to_date_array", "(", "$", "this", "->", "calendar", "->", "time", ")", ";", "$", "monthdays", "=", "$", "this", "->", "related", "[", "'type'", "]", "->", "get_num_days_in_month", "(", "$", "date", "[", "'year'", "]", ",", "$", "date", "[", "'mon'", "]", ")", ";", "$", "days", "=", "[", "]", ";", "for", "(", "$", "dayno", "=", "1", ";", "$", "dayno", "<=", "$", "monthdays", ";", "$", "dayno", "++", ")", "{", "// Get the gregorian representation of the day.", "$", "timestamp", "=", "$", "this", "->", "related", "[", "'type'", "]", "->", "convert_to_timestamp", "(", "$", "date", "[", "'year'", "]", ",", "$", "date", "[", "'mon'", "]", ",", "$", "dayno", ")", ";", "$", "days", "[", "]", "=", "$", "this", "->", "related", "[", "'type'", "]", "->", "timestamp_to_date_array", "(", "$", "timestamp", ")", ";", "}", "return", "$", "days", ";", "}" ]
Get the list of days with the matching date array. @return array
[ "Get", "the", "list", "of", "days", "with", "the", "matching", "date", "array", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/month_exporter.php#L324-L337
213,487
moodle/moodle
calendar/classes/external/month_exporter.php
month_exporter.get_month_data
protected function get_month_data() { $date = $this->related['type']->timestamp_to_date_array($this->calendar->time); $monthtime = $this->related['type']->convert_to_gregorian($date['year'], $date['month'], 1); return make_timestamp($monthtime['year'], $monthtime['month']); }
php
protected function get_month_data() { $date = $this->related['type']->timestamp_to_date_array($this->calendar->time); $monthtime = $this->related['type']->convert_to_gregorian($date['year'], $date['month'], 1); return make_timestamp($monthtime['year'], $monthtime['month']); }
[ "protected", "function", "get_month_data", "(", ")", "{", "$", "date", "=", "$", "this", "->", "related", "[", "'type'", "]", "->", "timestamp_to_date_array", "(", "$", "this", "->", "calendar", "->", "time", ")", ";", "$", "monthtime", "=", "$", "this", "->", "related", "[", "'type'", "]", "->", "convert_to_gregorian", "(", "$", "date", "[", "'year'", "]", ",", "$", "date", "[", "'month'", "]", ",", "1", ")", ";", "return", "make_timestamp", "(", "$", "monthtime", "[", "'year'", "]", ",", "$", "monthtime", "[", "'month'", "]", ")", ";", "}" ]
Get the current month timestamp. @return int The month timestamp.
[ "Get", "the", "current", "month", "timestamp", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/month_exporter.php#L357-L362
213,488
moodle/moodle
calendar/classes/external/month_exporter.php
month_exporter.get_previous_month_data
protected function get_previous_month_data() { $type = $this->related['type']; $date = $type->timestamp_to_date_array($this->calendar->time); list($date['mon'], $date['year']) = $type->get_prev_month($date['year'], $date['mon']); $time = $type->convert_to_timestamp($date['year'], $date['mon'], 1); return $type->timestamp_to_date_array($time); }
php
protected function get_previous_month_data() { $type = $this->related['type']; $date = $type->timestamp_to_date_array($this->calendar->time); list($date['mon'], $date['year']) = $type->get_prev_month($date['year'], $date['mon']); $time = $type->convert_to_timestamp($date['year'], $date['mon'], 1); return $type->timestamp_to_date_array($time); }
[ "protected", "function", "get_previous_month_data", "(", ")", "{", "$", "type", "=", "$", "this", "->", "related", "[", "'type'", "]", ";", "$", "date", "=", "$", "type", "->", "timestamp_to_date_array", "(", "$", "this", "->", "calendar", "->", "time", ")", ";", "list", "(", "$", "date", "[", "'mon'", "]", ",", "$", "date", "[", "'year'", "]", ")", "=", "$", "type", "->", "get_prev_month", "(", "$", "date", "[", "'year'", "]", ",", "$", "date", "[", "'mon'", "]", ")", ";", "$", "time", "=", "$", "type", "->", "convert_to_timestamp", "(", "$", "date", "[", "'year'", "]", ",", "$", "date", "[", "'mon'", "]", ",", "1", ")", ";", "return", "$", "type", "->", "timestamp_to_date_array", "(", "$", "time", ")", ";", "}" ]
Get the previous month timestamp. @return int The previous month timestamp.
[ "Get", "the", "previous", "month", "timestamp", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/month_exporter.php#L369-L376
213,489
moodle/moodle
calendar/classes/external/month_exporter.php
month_exporter.get_next_month_data
protected function get_next_month_data() { $type = $this->related['type']; $date = $type->timestamp_to_date_array($this->calendar->time); list($date['mon'], $date['year']) = $type->get_next_month($date['year'], $date['mon']); $time = $type->convert_to_timestamp($date['year'], $date['mon'], 1); return $type->timestamp_to_date_array($time); }
php
protected function get_next_month_data() { $type = $this->related['type']; $date = $type->timestamp_to_date_array($this->calendar->time); list($date['mon'], $date['year']) = $type->get_next_month($date['year'], $date['mon']); $time = $type->convert_to_timestamp($date['year'], $date['mon'], 1); return $type->timestamp_to_date_array($time); }
[ "protected", "function", "get_next_month_data", "(", ")", "{", "$", "type", "=", "$", "this", "->", "related", "[", "'type'", "]", ";", "$", "date", "=", "$", "type", "->", "timestamp_to_date_array", "(", "$", "this", "->", "calendar", "->", "time", ")", ";", "list", "(", "$", "date", "[", "'mon'", "]", ",", "$", "date", "[", "'year'", "]", ")", "=", "$", "type", "->", "get_next_month", "(", "$", "date", "[", "'year'", "]", ",", "$", "date", "[", "'mon'", "]", ")", ";", "$", "time", "=", "$", "type", "->", "convert_to_timestamp", "(", "$", "date", "[", "'year'", "]", ",", "$", "date", "[", "'mon'", "]", ",", "1", ")", ";", "return", "$", "type", "->", "timestamp_to_date_array", "(", "$", "time", ")", ";", "}" ]
Get the next month timestamp. @return int The next month timestamp.
[ "Get", "the", "next", "month", "timestamp", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/month_exporter.php#L383-L390
213,490
moodle/moodle
calendar/classes/external/month_exporter.php
month_exporter.get_default_add_context
protected function get_default_add_context() { if (calendar_user_can_add_event($this->calendar->course)) { return \context_course::instance($this->calendar->course->id); } return null; }
php
protected function get_default_add_context() { if (calendar_user_can_add_event($this->calendar->course)) { return \context_course::instance($this->calendar->course->id); } return null; }
[ "protected", "function", "get_default_add_context", "(", ")", "{", "if", "(", "calendar_user_can_add_event", "(", "$", "this", "->", "calendar", "->", "course", ")", ")", "{", "return", "\\", "context_course", "::", "instance", "(", "$", "this", "->", "calendar", "->", "course", "->", "id", ")", ";", "}", "return", "null", ";", "}" ]
Get the default context for use when adding a new event. @return null|\context
[ "Get", "the", "default", "context", "for", "use", "when", "adding", "a", "new", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/month_exporter.php#L434-L440
213,491
moodle/moodle
calendar/classes/local/event/data_access/event_vault.php
event_vault.timefield_pagination_from
protected function timefield_pagination_from( $field, $timefrom, $lastseentime = null, $lastseenid = null, $withduration = true ) { $where = ''; $params = []; if ($lastseentime && $lastseentime >= $timefrom) { $where = '((timesort = :timefrom1 AND e.id > :timefromid) OR timesort > :timefrom2)'; if ($field === 'timestart') { $where = '((timestart = :timefrom1 AND e.id > :timefromid) OR timestart > :timefrom2' . ($withduration ? ' OR timestart + timeduration > :timefrom3' : '') . ')'; } $params['timefromid'] = $lastseenid; $params['timefrom1'] = $lastseentime; $params['timefrom2'] = $lastseentime; $params['timefrom3'] = $lastseentime; } else { $where = 'timesort >= :timefrom'; if ($field === 'timestart') { $where = '(timestart >= :timefrom' . ($withduration ? ' OR timestart + timeduration > :timefrom2' : '') . ')'; } $params['timefrom'] = $timefrom; $params['timefrom2'] = $timefrom; } return ['where' => [$where], 'params' => $params]; }
php
protected function timefield_pagination_from( $field, $timefrom, $lastseentime = null, $lastseenid = null, $withduration = true ) { $where = ''; $params = []; if ($lastseentime && $lastseentime >= $timefrom) { $where = '((timesort = :timefrom1 AND e.id > :timefromid) OR timesort > :timefrom2)'; if ($field === 'timestart') { $where = '((timestart = :timefrom1 AND e.id > :timefromid) OR timestart > :timefrom2' . ($withduration ? ' OR timestart + timeduration > :timefrom3' : '') . ')'; } $params['timefromid'] = $lastseenid; $params['timefrom1'] = $lastseentime; $params['timefrom2'] = $lastseentime; $params['timefrom3'] = $lastseentime; } else { $where = 'timesort >= :timefrom'; if ($field === 'timestart') { $where = '(timestart >= :timefrom' . ($withduration ? ' OR timestart + timeduration > :timefrom2' : '') . ')'; } $params['timefrom'] = $timefrom; $params['timefrom2'] = $timefrom; } return ['where' => [$where], 'params' => $params]; }
[ "protected", "function", "timefield_pagination_from", "(", "$", "field", ",", "$", "timefrom", ",", "$", "lastseentime", "=", "null", ",", "$", "lastseenid", "=", "null", ",", "$", "withduration", "=", "true", ")", "{", "$", "where", "=", "''", ";", "$", "params", "=", "[", "]", ";", "if", "(", "$", "lastseentime", "&&", "$", "lastseentime", ">=", "$", "timefrom", ")", "{", "$", "where", "=", "'((timesort = :timefrom1 AND e.id > :timefromid) OR timesort > :timefrom2)'", ";", "if", "(", "$", "field", "===", "'timestart'", ")", "{", "$", "where", "=", "'((timestart = :timefrom1 AND e.id > :timefromid) OR timestart > :timefrom2'", ".", "(", "$", "withduration", "?", "' OR timestart + timeduration > :timefrom3'", ":", "''", ")", ".", "')'", ";", "}", "$", "params", "[", "'timefromid'", "]", "=", "$", "lastseenid", ";", "$", "params", "[", "'timefrom1'", "]", "=", "$", "lastseentime", ";", "$", "params", "[", "'timefrom2'", "]", "=", "$", "lastseentime", ";", "$", "params", "[", "'timefrom3'", "]", "=", "$", "lastseentime", ";", "}", "else", "{", "$", "where", "=", "'timesort >= :timefrom'", ";", "if", "(", "$", "field", "===", "'timestart'", ")", "{", "$", "where", "=", "'(timestart >= :timefrom'", ".", "(", "$", "withduration", "?", "' OR timestart + timeduration > :timefrom2'", ":", "''", ")", ".", "')'", ";", "}", "$", "params", "[", "'timefrom'", "]", "=", "$", "timefrom", ";", "$", "params", "[", "'timefrom2'", "]", "=", "$", "timefrom", ";", "}", "return", "[", "'where'", "=>", "[", "$", "where", "]", ",", "'params'", "=>", "$", "params", "]", ";", "}" ]
Generates SQL subquery and parameters for 'from' pagination. @param string $field @param int $timefrom @param int|null $lastseentime @param int|null $lastseenid @param bool $withduration @return array
[ "Generates", "SQL", "subquery", "and", "parameters", "for", "from", "pagination", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/data_access/event_vault.php#L276-L308
213,492
moodle/moodle
calendar/classes/local/event/data_access/event_vault.php
event_vault.timefield_pagination_to
protected function timefield_pagination_to( $field, $timeto, $lastseentime = null, $lastseenid = null ) { $where = []; $params = []; if ($lastseentime && $lastseentime > $timeto) { // The last seen event from this set is after the time sort range which // means all events in this range have been seen, so we can just return // early here. return false; } else if ($lastseentime && $lastseentime == $timeto) { $where[] = '((timesort = :timeto1 AND e.id > :timetoid) OR timesort < :timeto2)'; if ($field === 'timestart') { $where[] = '((timestart = :timeto1 AND e.id > :timetoid) OR timestart < :timeto2)'; } $params['timetoid'] = $lastseenid; $params['timeto1'] = $timeto; $params['timeto2'] = $timeto; } else { $where[] = ($field === 'timestart' ? 'timestart' : 'timesort') . ' <= :timeto'; $params['timeto'] = $timeto; } return ['where' => $where, 'params' => $params]; }
php
protected function timefield_pagination_to( $field, $timeto, $lastseentime = null, $lastseenid = null ) { $where = []; $params = []; if ($lastseentime && $lastseentime > $timeto) { // The last seen event from this set is after the time sort range which // means all events in this range have been seen, so we can just return // early here. return false; } else if ($lastseentime && $lastseentime == $timeto) { $where[] = '((timesort = :timeto1 AND e.id > :timetoid) OR timesort < :timeto2)'; if ($field === 'timestart') { $where[] = '((timestart = :timeto1 AND e.id > :timetoid) OR timestart < :timeto2)'; } $params['timetoid'] = $lastseenid; $params['timeto1'] = $timeto; $params['timeto2'] = $timeto; } else { $where[] = ($field === 'timestart' ? 'timestart' : 'timesort') . ' <= :timeto'; $params['timeto'] = $timeto; } return ['where' => $where, 'params' => $params]; }
[ "protected", "function", "timefield_pagination_to", "(", "$", "field", ",", "$", "timeto", ",", "$", "lastseentime", "=", "null", ",", "$", "lastseenid", "=", "null", ")", "{", "$", "where", "=", "[", "]", ";", "$", "params", "=", "[", "]", ";", "if", "(", "$", "lastseentime", "&&", "$", "lastseentime", ">", "$", "timeto", ")", "{", "// The last seen event from this set is after the time sort range which", "// means all events in this range have been seen, so we can just return", "// early here.", "return", "false", ";", "}", "else", "if", "(", "$", "lastseentime", "&&", "$", "lastseentime", "==", "$", "timeto", ")", "{", "$", "where", "[", "]", "=", "'((timesort = :timeto1 AND e.id > :timetoid) OR timesort < :timeto2)'", ";", "if", "(", "$", "field", "===", "'timestart'", ")", "{", "$", "where", "[", "]", "=", "'((timestart = :timeto1 AND e.id > :timetoid) OR timestart < :timeto2)'", ";", "}", "$", "params", "[", "'timetoid'", "]", "=", "$", "lastseenid", ";", "$", "params", "[", "'timeto1'", "]", "=", "$", "timeto", ";", "$", "params", "[", "'timeto2'", "]", "=", "$", "timeto", ";", "}", "else", "{", "$", "where", "[", "]", "=", "(", "$", "field", "===", "'timestart'", "?", "'timestart'", ":", "'timesort'", ")", ".", "' <= :timeto'", ";", "$", "params", "[", "'timeto'", "]", "=", "$", "timeto", ";", "}", "return", "[", "'where'", "=>", "$", "where", ",", "'params'", "=>", "$", "params", "]", ";", "}" ]
Generates SQL subquery and parameters for 'to' pagination. @param string $field @param int $timeto @param int|null $lastseentime @param int|null $lastseenid @return array|bool
[ "Generates", "SQL", "subquery", "and", "parameters", "for", "to", "pagination", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/data_access/event_vault.php#L319-L347
213,493
moodle/moodle
calendar/classes/local/event/data_access/event_vault.php
event_vault.get_from_db
protected function get_from_db( $userid, $whereconditions, $whereparams, $ordersql, $offset, $limitnum ) { return array_values( $this->retrievalstrategy->get_raw_events( [$userid], null, null, null, $whereconditions, $whereparams, $ordersql, $offset, $limitnum ) ); }
php
protected function get_from_db( $userid, $whereconditions, $whereparams, $ordersql, $offset, $limitnum ) { return array_values( $this->retrievalstrategy->get_raw_events( [$userid], null, null, null, $whereconditions, $whereparams, $ordersql, $offset, $limitnum ) ); }
[ "protected", "function", "get_from_db", "(", "$", "userid", ",", "$", "whereconditions", ",", "$", "whereparams", ",", "$", "ordersql", ",", "$", "offset", ",", "$", "limitnum", ")", "{", "return", "array_values", "(", "$", "this", "->", "retrievalstrategy", "->", "get_raw_events", "(", "[", "$", "userid", "]", ",", "null", ",", "null", ",", "null", ",", "$", "whereconditions", ",", "$", "whereparams", ",", "$", "ordersql", ",", "$", "offset", ",", "$", "limitnum", ")", ")", ";", "}" ]
Fetches records from DB. @param int $userid @param string $whereconditions @param array $whereparams @param string $ordersql @param int $offset @param int $limitnum @return array
[ "Fetches", "records", "from", "DB", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/data_access/event_vault.php#L370-L391
213,494
moodle/moodle
admin/tool/log/classes/log/observer.php
observer.store
public static function store(\core\event\base $event) { $logmanager = get_log_manager(); if (get_class($logmanager) === 'tool_log\log\manager') { /** @var \tool_log\log\manager $logmanager */ $logmanager->process($event); } }
php
public static function store(\core\event\base $event) { $logmanager = get_log_manager(); if (get_class($logmanager) === 'tool_log\log\manager') { /** @var \tool_log\log\manager $logmanager */ $logmanager->process($event); } }
[ "public", "static", "function", "store", "(", "\\", "core", "\\", "event", "\\", "base", "$", "event", ")", "{", "$", "logmanager", "=", "get_log_manager", "(", ")", ";", "if", "(", "get_class", "(", "$", "logmanager", ")", "===", "'tool_log\\log\\manager'", ")", "{", "/** @var \\tool_log\\log\\manager $logmanager */", "$", "logmanager", "->", "process", "(", "$", "event", ")", ";", "}", "}" ]
Redirect all events to this log manager, but only if this log manager is actually used. @param \core\event\base $event
[ "Redirect", "all", "events", "to", "this", "log", "manager", "but", "only", "if", "this", "log", "manager", "is", "actually", "used", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/classes/log/observer.php#L36-L42
213,495
moodle/moodle
question/type/essay/backup/moodle1/lib.php
moodle1_qtype_essay_handler.process_question
public function process_question(array $data, array $raw) { // Data added on the upgrade step 2011031000. $this->write_xml('essay', array( 'id' => $this->converter->get_nextid(), 'responseformat' => 'editor', 'responserequired' => 1, 'responsefieldlines' => 15, 'attachments' => 0, 'attachmentsrequired' => 0, 'graderinfo' => '', 'graderinfoformat' => FORMAT_HTML, 'responsetemplate' => '', 'responsetemplateformat' => FORMAT_HTML ), array('/essay/id')); }
php
public function process_question(array $data, array $raw) { // Data added on the upgrade step 2011031000. $this->write_xml('essay', array( 'id' => $this->converter->get_nextid(), 'responseformat' => 'editor', 'responserequired' => 1, 'responsefieldlines' => 15, 'attachments' => 0, 'attachmentsrequired' => 0, 'graderinfo' => '', 'graderinfoformat' => FORMAT_HTML, 'responsetemplate' => '', 'responsetemplateformat' => FORMAT_HTML ), array('/essay/id')); }
[ "public", "function", "process_question", "(", "array", "$", "data", ",", "array", "$", "raw", ")", "{", "// Data added on the upgrade step 2011031000.", "$", "this", "->", "write_xml", "(", "'essay'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "converter", "->", "get_nextid", "(", ")", ",", "'responseformat'", "=>", "'editor'", ",", "'responserequired'", "=>", "1", ",", "'responsefieldlines'", "=>", "15", ",", "'attachments'", "=>", "0", ",", "'attachmentsrequired'", "=>", "0", ",", "'graderinfo'", "=>", "''", ",", "'graderinfoformat'", "=>", "FORMAT_HTML", ",", "'responsetemplate'", "=>", "''", ",", "'responsetemplateformat'", "=>", "FORMAT_HTML", ")", ",", "array", "(", "'/essay/id'", ")", ")", ";", "}" ]
Appends the essay specific information to the question
[ "Appends", "the", "essay", "specific", "information", "to", "the", "question" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/essay/backup/moodle1/lib.php#L41-L55
213,496
moodle/moodle
lib/horde/framework/Horde/Support/Timer.php
Horde_Support_Timer.pop
public function pop() { $etime = microtime(true); if (! ($this->_idx > 0)) { throw new Exception('No timers have been started'); } return $etime - $this->_start[--$this->_idx]; }
php
public function pop() { $etime = microtime(true); if (! ($this->_idx > 0)) { throw new Exception('No timers have been started'); } return $etime - $this->_start[--$this->_idx]; }
[ "public", "function", "pop", "(", ")", "{", "$", "etime", "=", "microtime", "(", "true", ")", ";", "if", "(", "!", "(", "$", "this", "->", "_idx", ">", "0", ")", ")", "{", "throw", "new", "Exception", "(", "'No timers have been started'", ")", ";", "}", "return", "$", "etime", "-", "$", "this", "->", "_start", "[", "--", "$", "this", "->", "_idx", "]", ";", "}" ]
Pop the latest timer start and return the difference with the current time. @return float The amount of time passed.
[ "Pop", "the", "latest", "timer", "start", "and", "return", "the", "difference", "with", "the", "current", "time", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Timer.php#L48-L57
213,497
moodle/moodle
blocks/community/classes/privacy/provider.php
provider.export_user_data
public static function export_user_data(approved_contextlist $contextlist) { global $DB; // If the user has block_community data, then only the User context should be present so get the first context. $contexts = $contextlist->get_contexts(); if (count($contexts) == 0) { return; } $context = reset($contexts); // Sanity check that context is at the User context level, then get the userid. if ($context->contextlevel !== CONTEXT_USER) { return; } $userid = $context->instanceid; // The block_community data export is organised in: {User Context}/Community Finder/My communities/data.json. $subcontext = [ get_string('pluginname', 'block_community'), get_string('mycommunities', 'block_community') ]; $sql = "SELECT bc.id as id, bc.coursename as name, bc.coursedescription as description, bc.courseurl as url, bc.imageurl as imageurl FROM {block_community} bc WHERE bc.userid = :userid ORDER BY bc.coursename"; $params = [ 'userid' => $userid ]; $communities = $DB->get_records_sql($sql, $params); $data = (object) [ 'communities' => $communities ]; writer::with_context($context)->export_data($subcontext, $data); }
php
public static function export_user_data(approved_contextlist $contextlist) { global $DB; // If the user has block_community data, then only the User context should be present so get the first context. $contexts = $contextlist->get_contexts(); if (count($contexts) == 0) { return; } $context = reset($contexts); // Sanity check that context is at the User context level, then get the userid. if ($context->contextlevel !== CONTEXT_USER) { return; } $userid = $context->instanceid; // The block_community data export is organised in: {User Context}/Community Finder/My communities/data.json. $subcontext = [ get_string('pluginname', 'block_community'), get_string('mycommunities', 'block_community') ]; $sql = "SELECT bc.id as id, bc.coursename as name, bc.coursedescription as description, bc.courseurl as url, bc.imageurl as imageurl FROM {block_community} bc WHERE bc.userid = :userid ORDER BY bc.coursename"; $params = [ 'userid' => $userid ]; $communities = $DB->get_records_sql($sql, $params); $data = (object) [ 'communities' => $communities ]; writer::with_context($context)->export_data($subcontext, $data); }
[ "public", "static", "function", "export_user_data", "(", "approved_contextlist", "$", "contextlist", ")", "{", "global", "$", "DB", ";", "// If the user has block_community data, then only the User context should be present so get the first context.", "$", "contexts", "=", "$", "contextlist", "->", "get_contexts", "(", ")", ";", "if", "(", "count", "(", "$", "contexts", ")", "==", "0", ")", "{", "return", ";", "}", "$", "context", "=", "reset", "(", "$", "contexts", ")", ";", "// Sanity check that context is at the User context level, then get the userid.", "if", "(", "$", "context", "->", "contextlevel", "!==", "CONTEXT_USER", ")", "{", "return", ";", "}", "$", "userid", "=", "$", "context", "->", "instanceid", ";", "// The block_community data export is organised in: {User Context}/Community Finder/My communities/data.json.", "$", "subcontext", "=", "[", "get_string", "(", "'pluginname'", ",", "'block_community'", ")", ",", "get_string", "(", "'mycommunities'", ",", "'block_community'", ")", "]", ";", "$", "sql", "=", "\"SELECT bc.id as id,\n bc.coursename as name,\n bc.coursedescription as description,\n bc.courseurl as url,\n bc.imageurl as imageurl\n FROM {block_community} bc\n WHERE bc.userid = :userid\n ORDER BY bc.coursename\"", ";", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", "]", ";", "$", "communities", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "data", "=", "(", "object", ")", "[", "'communities'", "=>", "$", "communities", "]", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "$", "subcontext", ",", "$", "data", ")", ";", "}" ]
Export all user data for the specified user using the User context level. @param approved_contextlist $contextlist The approved contexts to export information for.
[ "Export", "all", "user", "data", "for", "the", "specified", "user", "using", "the", "User", "context", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/community/classes/privacy/provider.php#L120-L162
213,498
moodle/moodle
lib/classes/analytics/analyser/site_courses.php
site_courses.get_all_samples
public function get_all_samples(\core_analytics\analysable $site) { global $DB; // Getting courses from DB instead of from the site as these samples // will be stored in memory and we just want the id. $select = 'id != 1'; $courses = get_courses('all', 'c.sortorder ASC'); unset($courses[SITEID]); $courseids = array_keys($courses); $sampleids = array_combine($courseids, $courseids); $courses = array_map(function($course) { return array('course' => $course, 'context' => \context_course::instance($course->id)); }, $courses); // No related data attached. return array($sampleids, $courses); }
php
public function get_all_samples(\core_analytics\analysable $site) { global $DB; // Getting courses from DB instead of from the site as these samples // will be stored in memory and we just want the id. $select = 'id != 1'; $courses = get_courses('all', 'c.sortorder ASC'); unset($courses[SITEID]); $courseids = array_keys($courses); $sampleids = array_combine($courseids, $courseids); $courses = array_map(function($course) { return array('course' => $course, 'context' => \context_course::instance($course->id)); }, $courses); // No related data attached. return array($sampleids, $courses); }
[ "public", "function", "get_all_samples", "(", "\\", "core_analytics", "\\", "analysable", "$", "site", ")", "{", "global", "$", "DB", ";", "// Getting courses from DB instead of from the site as these samples", "// will be stored in memory and we just want the id.", "$", "select", "=", "'id != 1'", ";", "$", "courses", "=", "get_courses", "(", "'all'", ",", "'c.sortorder ASC'", ")", ";", "unset", "(", "$", "courses", "[", "SITEID", "]", ")", ";", "$", "courseids", "=", "array_keys", "(", "$", "courses", ")", ";", "$", "sampleids", "=", "array_combine", "(", "$", "courseids", ",", "$", "courseids", ")", ";", "$", "courses", "=", "array_map", "(", "function", "(", "$", "course", ")", "{", "return", "array", "(", "'course'", "=>", "$", "course", ",", "'context'", "=>", "\\", "context_course", "::", "instance", "(", "$", "course", "->", "id", ")", ")", ";", "}", ",", "$", "courses", ")", ";", "// No related data attached.", "return", "array", "(", "$", "sampleids", ",", "$", "courses", ")", ";", "}" ]
Returns all site courses. @param \core_analytics\analysable $site @return array
[ "Returns", "all", "site", "courses", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/analytics/analyser/site_courses.php#L82-L100
213,499
moodle/moodle
lib/classes/analytics/analyser/site_courses.php
site_courses.get_samples
public function get_samples($sampleids) { global $DB; list($sql, $params) = $DB->get_in_or_equal($sampleids, SQL_PARAMS_NAMED); $courses = $DB->get_records_select('course', "id $sql", $params); $courseids = array_keys($courses); $sampleids = array_combine($courseids, $courseids); $courses = array_map(function($course) { return array('course' => $course, 'context' => \context_course::instance($course->id)); }, $courses); // No related data attached. return array($sampleids, $courses); }
php
public function get_samples($sampleids) { global $DB; list($sql, $params) = $DB->get_in_or_equal($sampleids, SQL_PARAMS_NAMED); $courses = $DB->get_records_select('course', "id $sql", $params); $courseids = array_keys($courses); $sampleids = array_combine($courseids, $courseids); $courses = array_map(function($course) { return array('course' => $course, 'context' => \context_course::instance($course->id)); }, $courses); // No related data attached. return array($sampleids, $courses); }
[ "public", "function", "get_samples", "(", "$", "sampleids", ")", "{", "global", "$", "DB", ";", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "sampleids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "courses", "=", "$", "DB", "->", "get_records_select", "(", "'course'", ",", "\"id $sql\"", ",", "$", "params", ")", ";", "$", "courseids", "=", "array_keys", "(", "$", "courses", ")", ";", "$", "sampleids", "=", "array_combine", "(", "$", "courseids", ",", "$", "courseids", ")", ";", "$", "courses", "=", "array_map", "(", "function", "(", "$", "course", ")", "{", "return", "array", "(", "'course'", "=>", "$", "course", ",", "'context'", "=>", "\\", "context_course", "::", "instance", "(", "$", "course", "->", "id", ")", ")", ";", "}", ",", "$", "courses", ")", ";", "// No related data attached.", "return", "array", "(", "$", "sampleids", ",", "$", "courses", ")", ";", "}" ]
Return all complete samples data from sample ids. @param int[] $sampleids @return array
[ "Return", "all", "complete", "samples", "data", "from", "sample", "ids", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/analytics/analyser/site_courses.php#L108-L123