id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
215,900
moodle/moodle
mod/forum/externallib.php
mod_forum_external.get_forum_discussions_paginated_parameters
public static function get_forum_discussions_paginated_parameters() { return new external_function_parameters ( array( 'forumid' => new external_value(PARAM_INT, 'forum instance id', VALUE_REQUIRED), 'sortby' => new external_value(PARAM_ALPHA, 'sort by this element: id, timemodified, timestart or timeend', VALUE_DEFAULT, 'timemodified'), 'sortdirection' => new external_value(PARAM_ALPHA, 'sort direction: ASC or DESC', VALUE_DEFAULT, 'DESC'), 'page' => new external_value(PARAM_INT, 'current page', VALUE_DEFAULT, -1), 'perpage' => new external_value(PARAM_INT, 'items per page', VALUE_DEFAULT, 0), ) ); }
php
public static function get_forum_discussions_paginated_parameters() { return new external_function_parameters ( array( 'forumid' => new external_value(PARAM_INT, 'forum instance id', VALUE_REQUIRED), 'sortby' => new external_value(PARAM_ALPHA, 'sort by this element: id, timemodified, timestart or timeend', VALUE_DEFAULT, 'timemodified'), 'sortdirection' => new external_value(PARAM_ALPHA, 'sort direction: ASC or DESC', VALUE_DEFAULT, 'DESC'), 'page' => new external_value(PARAM_INT, 'current page', VALUE_DEFAULT, -1), 'perpage' => new external_value(PARAM_INT, 'items per page', VALUE_DEFAULT, 0), ) ); }
[ "public", "static", "function", "get_forum_discussions_paginated_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'forumid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'forum instance id'", ",", "VALUE_REQUIRED", ")", ",", "'sortby'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'sort by this element: id, timemodified, timestart or timeend'", ",", "VALUE_DEFAULT", ",", "'timemodified'", ")", ",", "'sortdirection'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'sort direction: ASC or DESC'", ",", "VALUE_DEFAULT", ",", "'DESC'", ")", ",", "'page'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'current page'", ",", "VALUE_DEFAULT", ",", "-", "1", ")", ",", "'perpage'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'items per page'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for get_forum_discussions_paginated. @deprecated since 3.7 @return external_function_parameters @since Moodle 2.8
[ "Describes", "the", "parameters", "for", "get_forum_discussions_paginated", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/externallib.php#L503-L514
215,901
moodle/moodle
mod/forum/externallib.php
mod_forum_external.get_forum_discussions_paginated_returns
public static function get_forum_discussions_paginated_returns() { return new external_single_structure( array( 'discussions' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Post id'), 'name' => new external_value(PARAM_TEXT, 'Discussion name'), 'groupid' => new external_value(PARAM_INT, 'Group id'), 'timemodified' => new external_value(PARAM_INT, 'Time modified'), 'usermodified' => new external_value(PARAM_INT, 'The id of the user who last modified'), 'timestart' => new external_value(PARAM_INT, 'Time discussion can start'), 'timeend' => new external_value(PARAM_INT, 'Time discussion ends'), 'discussion' => new external_value(PARAM_INT, 'Discussion id'), 'parent' => new external_value(PARAM_INT, 'Parent id'), 'userid' => new external_value(PARAM_INT, 'User who started the discussion id'), 'created' => new external_value(PARAM_INT, 'Creation time'), 'modified' => new external_value(PARAM_INT, 'Time modified'), 'mailed' => new external_value(PARAM_INT, 'Mailed?'), 'subject' => new external_value(PARAM_TEXT, 'The post subject'), 'message' => new external_value(PARAM_RAW, 'The post message'), 'messageformat' => new external_format_value('message'), 'messagetrust' => new external_value(PARAM_INT, 'Can we trust?'), 'messageinlinefiles' => new external_files('post message inline files', VALUE_OPTIONAL), 'attachment' => new external_value(PARAM_RAW, 'Has attachments?'), 'attachments' => new external_files('attachments', VALUE_OPTIONAL), 'totalscore' => new external_value(PARAM_INT, 'The post message total score'), 'mailnow' => new external_value(PARAM_INT, 'Mail now?'), 'userfullname' => new external_value(PARAM_TEXT, 'Post author full name'), 'usermodifiedfullname' => new external_value(PARAM_TEXT, 'Post modifier full name'), 'userpictureurl' => new external_value(PARAM_URL, 'Post author picture.'), 'usermodifiedpictureurl' => new external_value(PARAM_URL, 'Post modifier picture.'), 'numreplies' => new external_value(PARAM_INT, 'The number of replies in the discussion'), 'numunread' => new external_value(PARAM_INT, 'The number of unread discussions.'), 'pinned' => new external_value(PARAM_BOOL, 'Is the discussion pinned'), 'locked' => new external_value(PARAM_BOOL, 'Is the discussion locked'), 'canreply' => new external_value(PARAM_BOOL, 'Can the user reply to the discussion'), 'canlock' => new external_value(PARAM_BOOL, 'Can the user lock the discussion'), ), 'post' ) ), 'warnings' => new external_warnings() ) ); }
php
public static function get_forum_discussions_paginated_returns() { return new external_single_structure( array( 'discussions' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Post id'), 'name' => new external_value(PARAM_TEXT, 'Discussion name'), 'groupid' => new external_value(PARAM_INT, 'Group id'), 'timemodified' => new external_value(PARAM_INT, 'Time modified'), 'usermodified' => new external_value(PARAM_INT, 'The id of the user who last modified'), 'timestart' => new external_value(PARAM_INT, 'Time discussion can start'), 'timeend' => new external_value(PARAM_INT, 'Time discussion ends'), 'discussion' => new external_value(PARAM_INT, 'Discussion id'), 'parent' => new external_value(PARAM_INT, 'Parent id'), 'userid' => new external_value(PARAM_INT, 'User who started the discussion id'), 'created' => new external_value(PARAM_INT, 'Creation time'), 'modified' => new external_value(PARAM_INT, 'Time modified'), 'mailed' => new external_value(PARAM_INT, 'Mailed?'), 'subject' => new external_value(PARAM_TEXT, 'The post subject'), 'message' => new external_value(PARAM_RAW, 'The post message'), 'messageformat' => new external_format_value('message'), 'messagetrust' => new external_value(PARAM_INT, 'Can we trust?'), 'messageinlinefiles' => new external_files('post message inline files', VALUE_OPTIONAL), 'attachment' => new external_value(PARAM_RAW, 'Has attachments?'), 'attachments' => new external_files('attachments', VALUE_OPTIONAL), 'totalscore' => new external_value(PARAM_INT, 'The post message total score'), 'mailnow' => new external_value(PARAM_INT, 'Mail now?'), 'userfullname' => new external_value(PARAM_TEXT, 'Post author full name'), 'usermodifiedfullname' => new external_value(PARAM_TEXT, 'Post modifier full name'), 'userpictureurl' => new external_value(PARAM_URL, 'Post author picture.'), 'usermodifiedpictureurl' => new external_value(PARAM_URL, 'Post modifier picture.'), 'numreplies' => new external_value(PARAM_INT, 'The number of replies in the discussion'), 'numunread' => new external_value(PARAM_INT, 'The number of unread discussions.'), 'pinned' => new external_value(PARAM_BOOL, 'Is the discussion pinned'), 'locked' => new external_value(PARAM_BOOL, 'Is the discussion locked'), 'canreply' => new external_value(PARAM_BOOL, 'Can the user reply to the discussion'), 'canlock' => new external_value(PARAM_BOOL, 'Can the user lock the discussion'), ), 'post' ) ), 'warnings' => new external_warnings() ) ); }
[ "public", "static", "function", "get_forum_discussions_paginated_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'discussions'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Post id'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Discussion name'", ")", ",", "'groupid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Group id'", ")", ",", "'timemodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time modified'", ")", ",", "'usermodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the user who last modified'", ")", ",", "'timestart'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time discussion can start'", ")", ",", "'timeend'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time discussion ends'", ")", ",", "'discussion'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Discussion id'", ")", ",", "'parent'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Parent id'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User who started the discussion id'", ")", ",", "'created'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Creation time'", ")", ",", "'modified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time modified'", ")", ",", "'mailed'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Mailed?'", ")", ",", "'subject'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'The post subject'", ")", ",", "'message'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The post message'", ")", ",", "'messageformat'", "=>", "new", "external_format_value", "(", "'message'", ")", ",", "'messagetrust'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Can we trust?'", ")", ",", "'messageinlinefiles'", "=>", "new", "external_files", "(", "'post message inline files'", ",", "VALUE_OPTIONAL", ")", ",", "'attachment'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Has attachments?'", ")", ",", "'attachments'", "=>", "new", "external_files", "(", "'attachments'", ",", "VALUE_OPTIONAL", ")", ",", "'totalscore'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The post message total score'", ")", ",", "'mailnow'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Mail now?'", ")", ",", "'userfullname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Post author full name'", ")", ",", "'usermodifiedfullname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Post modifier full name'", ")", ",", "'userpictureurl'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'Post author picture.'", ")", ",", "'usermodifiedpictureurl'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'Post modifier picture.'", ")", ",", "'numreplies'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The number of replies in the discussion'", ")", ",", "'numunread'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The number of unread discussions.'", ")", ",", "'pinned'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Is the discussion pinned'", ")", ",", "'locked'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Is the discussion locked'", ")", ",", "'canreply'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Can the user reply to the discussion'", ")", ",", "'canlock'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Can the user lock the discussion'", ")", ",", ")", ",", "'post'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ")", ")", ";", "}" ]
Describes the get_forum_discussions_paginated return value. @deprecated since 3.7 @return external_single_structure @since Moodle 2.8
[ "Describes", "the", "get_forum_discussions_paginated", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/externallib.php#L700-L744
215,902
moodle/moodle
mod/forum/externallib.php
mod_forum_external.get_forum_discussions_parameters
public static function get_forum_discussions_parameters() { return new external_function_parameters ( array( 'forumid' => new external_value(PARAM_INT, 'forum instance id', VALUE_REQUIRED), 'sortorder' => new external_value(PARAM_INT, 'sort by this element: numreplies, , created or timemodified', VALUE_DEFAULT, -1), 'page' => new external_value(PARAM_INT, 'current page', VALUE_DEFAULT, -1), 'perpage' => new external_value(PARAM_INT, 'items per page', VALUE_DEFAULT, 0), 'groupid' => new external_value(PARAM_INT, 'group id', VALUE_DEFAULT, 0), ) ); }
php
public static function get_forum_discussions_parameters() { return new external_function_parameters ( array( 'forumid' => new external_value(PARAM_INT, 'forum instance id', VALUE_REQUIRED), 'sortorder' => new external_value(PARAM_INT, 'sort by this element: numreplies, , created or timemodified', VALUE_DEFAULT, -1), 'page' => new external_value(PARAM_INT, 'current page', VALUE_DEFAULT, -1), 'perpage' => new external_value(PARAM_INT, 'items per page', VALUE_DEFAULT, 0), 'groupid' => new external_value(PARAM_INT, 'group id', VALUE_DEFAULT, 0), ) ); }
[ "public", "static", "function", "get_forum_discussions_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'forumid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'forum instance id'", ",", "VALUE_REQUIRED", ")", ",", "'sortorder'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'sort by this element: numreplies, , created or timemodified'", ",", "VALUE_DEFAULT", ",", "-", "1", ")", ",", "'page'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'current page'", ",", "VALUE_DEFAULT", ",", "-", "1", ")", ",", "'perpage'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'items per page'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'groupid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'group id'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for get_forum_discussions. @return external_function_parameters @since Moodle 3.7
[ "Describes", "the", "parameters", "for", "get_forum_discussions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/externallib.php#L752-L763
215,903
moodle/moodle
mod/forum/externallib.php
mod_forum_external.view_forum_discussion
public static function view_forum_discussion($discussionid) { global $DB, $CFG, $USER; require_once($CFG->dirroot . "/mod/forum/lib.php"); $params = self::validate_parameters(self::view_forum_discussion_parameters(), array( 'discussionid' => $discussionid )); $warnings = array(); $discussion = $DB->get_record('forum_discussions', array('id' => $params['discussionid']), '*', MUST_EXIST); $forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($forum, 'forum'); // Validate the module context. It checks everything that affects the module visibility (including groupings, etc..). $modcontext = context_module::instance($cm->id); self::validate_context($modcontext); require_capability('mod/forum:viewdiscussion', $modcontext, null, true, 'noviewdiscussionspermission', 'forum'); // Call the forum/lib API. forum_discussion_view($modcontext, $forum, $discussion); // Mark as read if required. if (!$CFG->forum_usermarksread && forum_tp_is_tracked($forum)) { forum_tp_mark_discussion_read($USER, $discussion->id); } $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
php
public static function view_forum_discussion($discussionid) { global $DB, $CFG, $USER; require_once($CFG->dirroot . "/mod/forum/lib.php"); $params = self::validate_parameters(self::view_forum_discussion_parameters(), array( 'discussionid' => $discussionid )); $warnings = array(); $discussion = $DB->get_record('forum_discussions', array('id' => $params['discussionid']), '*', MUST_EXIST); $forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($forum, 'forum'); // Validate the module context. It checks everything that affects the module visibility (including groupings, etc..). $modcontext = context_module::instance($cm->id); self::validate_context($modcontext); require_capability('mod/forum:viewdiscussion', $modcontext, null, true, 'noviewdiscussionspermission', 'forum'); // Call the forum/lib API. forum_discussion_view($modcontext, $forum, $discussion); // Mark as read if required. if (!$CFG->forum_usermarksread && forum_tp_is_tracked($forum)) { forum_tp_mark_discussion_read($USER, $discussion->id); } $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "view_forum_discussion", "(", "$", "discussionid", ")", "{", "global", "$", "DB", ",", "$", "CFG", ",", "$", "USER", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "\"/mod/forum/lib.php\"", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "view_forum_discussion_parameters", "(", ")", ",", "array", "(", "'discussionid'", "=>", "$", "discussionid", ")", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "discussion", "=", "$", "DB", "->", "get_record", "(", "'forum_discussions'", ",", "array", "(", "'id'", "=>", "$", "params", "[", "'discussionid'", "]", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "forum", "=", "$", "DB", "->", "get_record", "(", "'forum'", ",", "array", "(", "'id'", "=>", "$", "discussion", "->", "forum", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "list", "(", "$", "course", ",", "$", "cm", ")", "=", "get_course_and_cm_from_instance", "(", "$", "forum", ",", "'forum'", ")", ";", "// Validate the module context. It checks everything that affects the module visibility (including groupings, etc..).", "$", "modcontext", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "modcontext", ")", ";", "require_capability", "(", "'mod/forum:viewdiscussion'", ",", "$", "modcontext", ",", "null", ",", "true", ",", "'noviewdiscussionspermission'", ",", "'forum'", ")", ";", "// Call the forum/lib API.", "forum_discussion_view", "(", "$", "modcontext", ",", "$", "forum", ",", "$", "discussion", ")", ";", "// Mark as read if required.", "if", "(", "!", "$", "CFG", "->", "forum_usermarksread", "&&", "forum_tp_is_tracked", "(", "$", "forum", ")", ")", "{", "forum_tp_mark_discussion_read", "(", "$", "USER", ",", "$", "discussion", "->", "id", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'status'", "]", "=", "true", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Trigger the discussion viewed event. @param int $discussionid the discussion id @return array of warnings and status result @since Moodle 2.9 @throws moodle_exception
[ "Trigger", "the", "discussion", "viewed", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/externallib.php#L1114-L1146
215,904
moodle/moodle
mod/forum/externallib.php
mod_forum_external.toggle_favourite_state
public static function toggle_favourite_state($discussionid, $targetstate) { global $DB, $PAGE, $USER; $params = self::validate_parameters(self::toggle_favourite_state_parameters(), [ 'discussionid' => $discussionid, 'targetstate' => $targetstate ]); $vaultfactory = mod_forum\local\container::get_vault_factory(); // Get the discussion vault and the corresponding discussion entity. $discussionvault = $vaultfactory->get_discussion_vault(); $discussion = $discussionvault->get_from_id($params['discussionid']); $forumvault = $vaultfactory->get_forum_vault(); $forum = $forumvault->get_from_id($discussion->get_forum_id()); $forumcontext = $forum->get_context(); self::validate_context($forumcontext); $managerfactory = mod_forum\local\container::get_manager_factory(); $capabilitymanager = $managerfactory->get_capability_manager($forum); // Does the user have the ability to favourite the discussion? if (!$capabilitymanager->can_favourite_discussion($USER)) { throw new moodle_exception('cannotfavourite', 'forum'); } $usercontext = context_user::instance($USER->id); $ufservice = \core_favourites\service_factory::get_service_for_user_context($usercontext); $isfavourited = $ufservice->favourite_exists('mod_forum', 'discussions', $discussion->get_id(), $forumcontext); $favouritefunction = $targetstate ? 'create_favourite' : 'delete_favourite'; if ($isfavourited != (bool) $params['targetstate']) { $ufservice->{$favouritefunction}('mod_forum', 'discussions', $discussion->get_id(), $forumcontext); } $exporterfactory = mod_forum\local\container::get_exporter_factory(); $builder = mod_forum\local\container::get_builder_factory()->get_exported_discussion_builder(); $favourited = ($builder->is_favourited($discussion, $forumcontext, $USER) ? [$discussion->get_id()] : []); $exporter = $exporterfactory->get_discussion_exporter($USER, $forum, $discussion, [], $favourited); return $exporter->export($PAGE->get_renderer('mod_forum')); }
php
public static function toggle_favourite_state($discussionid, $targetstate) { global $DB, $PAGE, $USER; $params = self::validate_parameters(self::toggle_favourite_state_parameters(), [ 'discussionid' => $discussionid, 'targetstate' => $targetstate ]); $vaultfactory = mod_forum\local\container::get_vault_factory(); // Get the discussion vault and the corresponding discussion entity. $discussionvault = $vaultfactory->get_discussion_vault(); $discussion = $discussionvault->get_from_id($params['discussionid']); $forumvault = $vaultfactory->get_forum_vault(); $forum = $forumvault->get_from_id($discussion->get_forum_id()); $forumcontext = $forum->get_context(); self::validate_context($forumcontext); $managerfactory = mod_forum\local\container::get_manager_factory(); $capabilitymanager = $managerfactory->get_capability_manager($forum); // Does the user have the ability to favourite the discussion? if (!$capabilitymanager->can_favourite_discussion($USER)) { throw new moodle_exception('cannotfavourite', 'forum'); } $usercontext = context_user::instance($USER->id); $ufservice = \core_favourites\service_factory::get_service_for_user_context($usercontext); $isfavourited = $ufservice->favourite_exists('mod_forum', 'discussions', $discussion->get_id(), $forumcontext); $favouritefunction = $targetstate ? 'create_favourite' : 'delete_favourite'; if ($isfavourited != (bool) $params['targetstate']) { $ufservice->{$favouritefunction}('mod_forum', 'discussions', $discussion->get_id(), $forumcontext); } $exporterfactory = mod_forum\local\container::get_exporter_factory(); $builder = mod_forum\local\container::get_builder_factory()->get_exported_discussion_builder(); $favourited = ($builder->is_favourited($discussion, $forumcontext, $USER) ? [$discussion->get_id()] : []); $exporter = $exporterfactory->get_discussion_exporter($USER, $forum, $discussion, [], $favourited); return $exporter->export($PAGE->get_renderer('mod_forum')); }
[ "public", "static", "function", "toggle_favourite_state", "(", "$", "discussionid", ",", "$", "targetstate", ")", "{", "global", "$", "DB", ",", "$", "PAGE", ",", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "toggle_favourite_state_parameters", "(", ")", ",", "[", "'discussionid'", "=>", "$", "discussionid", ",", "'targetstate'", "=>", "$", "targetstate", "]", ")", ";", "$", "vaultfactory", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_vault_factory", "(", ")", ";", "// Get the discussion vault and the corresponding discussion entity.", "$", "discussionvault", "=", "$", "vaultfactory", "->", "get_discussion_vault", "(", ")", ";", "$", "discussion", "=", "$", "discussionvault", "->", "get_from_id", "(", "$", "params", "[", "'discussionid'", "]", ")", ";", "$", "forumvault", "=", "$", "vaultfactory", "->", "get_forum_vault", "(", ")", ";", "$", "forum", "=", "$", "forumvault", "->", "get_from_id", "(", "$", "discussion", "->", "get_forum_id", "(", ")", ")", ";", "$", "forumcontext", "=", "$", "forum", "->", "get_context", "(", ")", ";", "self", "::", "validate_context", "(", "$", "forumcontext", ")", ";", "$", "managerfactory", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_manager_factory", "(", ")", ";", "$", "capabilitymanager", "=", "$", "managerfactory", "->", "get_capability_manager", "(", "$", "forum", ")", ";", "// Does the user have the ability to favourite the discussion?", "if", "(", "!", "$", "capabilitymanager", "->", "can_favourite_discussion", "(", "$", "USER", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'cannotfavourite'", ",", "'forum'", ")", ";", "}", "$", "usercontext", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "$", "ufservice", "=", "\\", "core_favourites", "\\", "service_factory", "::", "get_service_for_user_context", "(", "$", "usercontext", ")", ";", "$", "isfavourited", "=", "$", "ufservice", "->", "favourite_exists", "(", "'mod_forum'", ",", "'discussions'", ",", "$", "discussion", "->", "get_id", "(", ")", ",", "$", "forumcontext", ")", ";", "$", "favouritefunction", "=", "$", "targetstate", "?", "'create_favourite'", ":", "'delete_favourite'", ";", "if", "(", "$", "isfavourited", "!=", "(", "bool", ")", "$", "params", "[", "'targetstate'", "]", ")", "{", "$", "ufservice", "->", "{", "$", "favouritefunction", "}", "(", "'mod_forum'", ",", "'discussions'", ",", "$", "discussion", "->", "get_id", "(", ")", ",", "$", "forumcontext", ")", ";", "}", "$", "exporterfactory", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_exporter_factory", "(", ")", ";", "$", "builder", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_builder_factory", "(", ")", "->", "get_exported_discussion_builder", "(", ")", ";", "$", "favourited", "=", "(", "$", "builder", "->", "is_favourited", "(", "$", "discussion", ",", "$", "forumcontext", ",", "$", "USER", ")", "?", "[", "$", "discussion", "->", "get_id", "(", ")", "]", ":", "[", "]", ")", ";", "$", "exporter", "=", "$", "exporterfactory", "->", "get_discussion_exporter", "(", "$", "USER", ",", "$", "forum", ",", "$", "discussion", ",", "[", "]", ",", "$", "favourited", ")", ";", "return", "$", "exporter", "->", "export", "(", "$", "PAGE", "->", "get_renderer", "(", "'mod_forum'", ")", ")", ";", "}" ]
Toggle the favouriting value for the discussion provided @param int $discussionid The discussion we need to favourite @param bool $targetstate The state of the favourite value @return array The exported discussion
[ "Toggle", "the", "favouriting", "value", "for", "the", "discussion", "provided" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/externallib.php#L1391-L1430
215,905
moodle/moodle
mod/forum/externallib.php
mod_forum_external.get_forum_access_information
public static function get_forum_access_information($forumid) { global $DB; $params = self::validate_parameters(self::get_forum_access_information_parameters(), array('forumid' => $forumid)); // Request and permission validation. $forum = $DB->get_record('forum', array('id' => $params['forumid']), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('forum', $forum->id); $context = context_module::instance($cm->id); self::validate_context($context); $result = array(); // Return all the available capabilities. $capabilities = load_capability_def('mod_forum'); foreach ($capabilities as $capname => $capdata) { // Get fields like cansubmit so it is consistent with the access_information function implemented in other modules. $field = 'can' . str_replace('mod/forum:', '', $capname); $result[$field] = has_capability($capname, $context); } $result['warnings'] = array(); return $result; }
php
public static function get_forum_access_information($forumid) { global $DB; $params = self::validate_parameters(self::get_forum_access_information_parameters(), array('forumid' => $forumid)); // Request and permission validation. $forum = $DB->get_record('forum', array('id' => $params['forumid']), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('forum', $forum->id); $context = context_module::instance($cm->id); self::validate_context($context); $result = array(); // Return all the available capabilities. $capabilities = load_capability_def('mod_forum'); foreach ($capabilities as $capname => $capdata) { // Get fields like cansubmit so it is consistent with the access_information function implemented in other modules. $field = 'can' . str_replace('mod/forum:', '', $capname); $result[$field] = has_capability($capname, $context); } $result['warnings'] = array(); return $result; }
[ "public", "static", "function", "get_forum_access_information", "(", "$", "forumid", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_forum_access_information_parameters", "(", ")", ",", "array", "(", "'forumid'", "=>", "$", "forumid", ")", ")", ";", "// Request and permission validation.", "$", "forum", "=", "$", "DB", "->", "get_record", "(", "'forum'", ",", "array", "(", "'id'", "=>", "$", "params", "[", "'forumid'", "]", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'forum'", ",", "$", "forum", "->", "id", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "result", "=", "array", "(", ")", ";", "// Return all the available capabilities.", "$", "capabilities", "=", "load_capability_def", "(", "'mod_forum'", ")", ";", "foreach", "(", "$", "capabilities", "as", "$", "capname", "=>", "$", "capdata", ")", "{", "// Get fields like cansubmit so it is consistent with the access_information function implemented in other modules.", "$", "field", "=", "'can'", ".", "str_replace", "(", "'mod/forum:'", ",", "''", ",", "$", "capname", ")", ";", "$", "result", "[", "$", "field", "]", "=", "has_capability", "(", "$", "capname", ",", "$", "context", ")", ";", "}", "$", "result", "[", "'warnings'", "]", "=", "array", "(", ")", ";", "return", "$", "result", ";", "}" ]
Return access information for a given forum. @param int $forumid forum instance id @return array of warnings and the access information @since Moodle 3.7 @throws moodle_exception
[ "Return", "access", "information", "for", "a", "given", "forum", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/externallib.php#L1744-L1767
215,906
moodle/moodle
mod/forum/externallib.php
mod_forum_external.get_forum_access_information_returns
public static function get_forum_access_information_returns() { $structure = array( 'warnings' => new external_warnings() ); $capabilities = load_capability_def('mod_forum'); foreach ($capabilities as $capname => $capdata) { // Get fields like cansubmit so it is consistent with the access_information function implemented in other modules. $field = 'can' . str_replace('mod/forum:', '', $capname); $structure[$field] = new external_value(PARAM_BOOL, 'Whether the user has the capability ' . $capname . ' allowed.', VALUE_OPTIONAL); } return new external_single_structure($structure); }
php
public static function get_forum_access_information_returns() { $structure = array( 'warnings' => new external_warnings() ); $capabilities = load_capability_def('mod_forum'); foreach ($capabilities as $capname => $capdata) { // Get fields like cansubmit so it is consistent with the access_information function implemented in other modules. $field = 'can' . str_replace('mod/forum:', '', $capname); $structure[$field] = new external_value(PARAM_BOOL, 'Whether the user has the capability ' . $capname . ' allowed.', VALUE_OPTIONAL); } return new external_single_structure($structure); }
[ "public", "static", "function", "get_forum_access_information_returns", "(", ")", "{", "$", "structure", "=", "array", "(", "'warnings'", "=>", "new", "external_warnings", "(", ")", ")", ";", "$", "capabilities", "=", "load_capability_def", "(", "'mod_forum'", ")", ";", "foreach", "(", "$", "capabilities", "as", "$", "capname", "=>", "$", "capdata", ")", "{", "// Get fields like cansubmit so it is consistent with the access_information function implemented in other modules.", "$", "field", "=", "'can'", ".", "str_replace", "(", "'mod/forum:'", ",", "''", ",", "$", "capname", ")", ";", "$", "structure", "[", "$", "field", "]", "=", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether the user has the capability '", ".", "$", "capname", ".", "' allowed.'", ",", "VALUE_OPTIONAL", ")", ";", "}", "return", "new", "external_single_structure", "(", "$", "structure", ")", ";", "}" ]
Describes the get_forum_access_information return value. @return external_single_structure @since Moodle 3.7
[ "Describes", "the", "get_forum_access_information", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/externallib.php#L1775-L1790
215,907
moodle/moodle
mod/forum/externallib.php
mod_forum_external.set_subscription_state
public static function set_subscription_state($forumid, $discussionid, $targetstate) { global $PAGE, $USER; $params = self::validate_parameters(self::set_subscription_state_parameters(), [ 'forumid' => $forumid, 'discussionid' => $discussionid, 'targetstate' => $targetstate ]); $vaultfactory = mod_forum\local\container::get_vault_factory(); $forumvault = $vaultfactory->get_forum_vault(); $forum = $forumvault->get_from_id($params['forumid']); $coursemodule = $forum->get_course_module_record(); $context = $forum->get_context(); self::validate_context($context); $discussionvault = $vaultfactory->get_discussion_vault(); $discussion = $discussionvault->get_from_id($params['discussionid']); $legacydatamapperfactory = mod_forum\local\container::get_legacy_data_mapper_factory(); $forumrecord = $legacydatamapperfactory->get_forum_data_mapper()->to_legacy_object($forum); $discussionrecord = $legacydatamapperfactory->get_discussion_data_mapper()->to_legacy_object($discussion); if (!\mod_forum\subscriptions::is_subscribable($forumrecord)) { // Nothing to do. We won't actually output any content here though. throw new \moodle_exception('cannotsubscribe', 'mod_forum'); } $issubscribed = \mod_forum\subscriptions::is_subscribed( $USER->id, $forumrecord, $discussion->get_id(), $coursemodule ); // If the current state doesn't equal the desired state then update the current // state to the desired state. if ($issubscribed != (bool) $params['targetstate']) { if ($params['targetstate']) { \mod_forum\subscriptions::subscribe_user_to_discussion($USER->id, $discussionrecord, $context); } else { \mod_forum\subscriptions::unsubscribe_user_from_discussion($USER->id, $discussionrecord, $context); } } $exporterfactory = mod_forum\local\container::get_exporter_factory(); $exporter = $exporterfactory->get_discussion_exporter($USER, $forum, $discussion); return $exporter->export($PAGE->get_renderer('mod_forum')); }
php
public static function set_subscription_state($forumid, $discussionid, $targetstate) { global $PAGE, $USER; $params = self::validate_parameters(self::set_subscription_state_parameters(), [ 'forumid' => $forumid, 'discussionid' => $discussionid, 'targetstate' => $targetstate ]); $vaultfactory = mod_forum\local\container::get_vault_factory(); $forumvault = $vaultfactory->get_forum_vault(); $forum = $forumvault->get_from_id($params['forumid']); $coursemodule = $forum->get_course_module_record(); $context = $forum->get_context(); self::validate_context($context); $discussionvault = $vaultfactory->get_discussion_vault(); $discussion = $discussionvault->get_from_id($params['discussionid']); $legacydatamapperfactory = mod_forum\local\container::get_legacy_data_mapper_factory(); $forumrecord = $legacydatamapperfactory->get_forum_data_mapper()->to_legacy_object($forum); $discussionrecord = $legacydatamapperfactory->get_discussion_data_mapper()->to_legacy_object($discussion); if (!\mod_forum\subscriptions::is_subscribable($forumrecord)) { // Nothing to do. We won't actually output any content here though. throw new \moodle_exception('cannotsubscribe', 'mod_forum'); } $issubscribed = \mod_forum\subscriptions::is_subscribed( $USER->id, $forumrecord, $discussion->get_id(), $coursemodule ); // If the current state doesn't equal the desired state then update the current // state to the desired state. if ($issubscribed != (bool) $params['targetstate']) { if ($params['targetstate']) { \mod_forum\subscriptions::subscribe_user_to_discussion($USER->id, $discussionrecord, $context); } else { \mod_forum\subscriptions::unsubscribe_user_from_discussion($USER->id, $discussionrecord, $context); } } $exporterfactory = mod_forum\local\container::get_exporter_factory(); $exporter = $exporterfactory->get_discussion_exporter($USER, $forum, $discussion); return $exporter->export($PAGE->get_renderer('mod_forum')); }
[ "public", "static", "function", "set_subscription_state", "(", "$", "forumid", ",", "$", "discussionid", ",", "$", "targetstate", ")", "{", "global", "$", "PAGE", ",", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "set_subscription_state_parameters", "(", ")", ",", "[", "'forumid'", "=>", "$", "forumid", ",", "'discussionid'", "=>", "$", "discussionid", ",", "'targetstate'", "=>", "$", "targetstate", "]", ")", ";", "$", "vaultfactory", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_vault_factory", "(", ")", ";", "$", "forumvault", "=", "$", "vaultfactory", "->", "get_forum_vault", "(", ")", ";", "$", "forum", "=", "$", "forumvault", "->", "get_from_id", "(", "$", "params", "[", "'forumid'", "]", ")", ";", "$", "coursemodule", "=", "$", "forum", "->", "get_course_module_record", "(", ")", ";", "$", "context", "=", "$", "forum", "->", "get_context", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "discussionvault", "=", "$", "vaultfactory", "->", "get_discussion_vault", "(", ")", ";", "$", "discussion", "=", "$", "discussionvault", "->", "get_from_id", "(", "$", "params", "[", "'discussionid'", "]", ")", ";", "$", "legacydatamapperfactory", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_legacy_data_mapper_factory", "(", ")", ";", "$", "forumrecord", "=", "$", "legacydatamapperfactory", "->", "get_forum_data_mapper", "(", ")", "->", "to_legacy_object", "(", "$", "forum", ")", ";", "$", "discussionrecord", "=", "$", "legacydatamapperfactory", "->", "get_discussion_data_mapper", "(", ")", "->", "to_legacy_object", "(", "$", "discussion", ")", ";", "if", "(", "!", "\\", "mod_forum", "\\", "subscriptions", "::", "is_subscribable", "(", "$", "forumrecord", ")", ")", "{", "// Nothing to do. We won't actually output any content here though.", "throw", "new", "\\", "moodle_exception", "(", "'cannotsubscribe'", ",", "'mod_forum'", ")", ";", "}", "$", "issubscribed", "=", "\\", "mod_forum", "\\", "subscriptions", "::", "is_subscribed", "(", "$", "USER", "->", "id", ",", "$", "forumrecord", ",", "$", "discussion", "->", "get_id", "(", ")", ",", "$", "coursemodule", ")", ";", "// If the current state doesn't equal the desired state then update the current", "// state to the desired state.", "if", "(", "$", "issubscribed", "!=", "(", "bool", ")", "$", "params", "[", "'targetstate'", "]", ")", "{", "if", "(", "$", "params", "[", "'targetstate'", "]", ")", "{", "\\", "mod_forum", "\\", "subscriptions", "::", "subscribe_user_to_discussion", "(", "$", "USER", "->", "id", ",", "$", "discussionrecord", ",", "$", "context", ")", ";", "}", "else", "{", "\\", "mod_forum", "\\", "subscriptions", "::", "unsubscribe_user_from_discussion", "(", "$", "USER", "->", "id", ",", "$", "discussionrecord", ",", "$", "context", ")", ";", "}", "}", "$", "exporterfactory", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_exporter_factory", "(", ")", ";", "$", "exporter", "=", "$", "exporterfactory", "->", "get_discussion_exporter", "(", "$", "USER", ",", "$", "forum", ",", "$", "discussion", ")", ";", "return", "$", "exporter", "->", "export", "(", "$", "PAGE", "->", "get_renderer", "(", "'mod_forum'", ")", ")", ";", "}" ]
Set the subscription state. @param int $forumid @param int $discussionid @param bool $targetstate @return \stdClass
[ "Set", "the", "subscription", "state", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/externallib.php#L1800-L1849
215,908
moodle/moodle
mod/forum/externallib.php
mod_forum_external.set_lock_state
public static function set_lock_state($forumid, $discussionid, $targetstate) { global $DB, $PAGE, $USER; $params = self::validate_parameters(self::set_lock_state_parameters(), [ 'forumid' => $forumid, 'discussionid' => $discussionid, 'targetstate' => $targetstate ]); $vaultfactory = mod_forum\local\container::get_vault_factory(); $forumvault = $vaultfactory->get_forum_vault(); $forum = $forumvault->get_from_id($params['forumid']); $managerfactory = mod_forum\local\container::get_manager_factory(); $capabilitymanager = $managerfactory->get_capability_manager($forum); if (!$capabilitymanager->can_manage_forum($USER)) { throw new moodle_exception('errorcannotlock', 'forum'); } // If the targetstate(currentstate) is not 0 then it should be set to the current time. $lockedvalue = $targetstate ? 0 : time(); self::validate_context($forum->get_context()); $discussionvault = $vaultfactory->get_discussion_vault(); $discussion = $discussionvault->get_from_id($params['discussionid']); // If the current state doesn't equal the desired state then update the current. // state to the desired state. $discussion->toggle_locked_state($lockedvalue); $response = $discussionvault->update_discussion($discussion); $discussion = !$response ? $response : $discussion; $exporterfactory = mod_forum\local\container::get_exporter_factory(); $exporter = $exporterfactory->get_discussion_exporter($USER, $forum, $discussion); return $exporter->export($PAGE->get_renderer('mod_forum')); }
php
public static function set_lock_state($forumid, $discussionid, $targetstate) { global $DB, $PAGE, $USER; $params = self::validate_parameters(self::set_lock_state_parameters(), [ 'forumid' => $forumid, 'discussionid' => $discussionid, 'targetstate' => $targetstate ]); $vaultfactory = mod_forum\local\container::get_vault_factory(); $forumvault = $vaultfactory->get_forum_vault(); $forum = $forumvault->get_from_id($params['forumid']); $managerfactory = mod_forum\local\container::get_manager_factory(); $capabilitymanager = $managerfactory->get_capability_manager($forum); if (!$capabilitymanager->can_manage_forum($USER)) { throw new moodle_exception('errorcannotlock', 'forum'); } // If the targetstate(currentstate) is not 0 then it should be set to the current time. $lockedvalue = $targetstate ? 0 : time(); self::validate_context($forum->get_context()); $discussionvault = $vaultfactory->get_discussion_vault(); $discussion = $discussionvault->get_from_id($params['discussionid']); // If the current state doesn't equal the desired state then update the current. // state to the desired state. $discussion->toggle_locked_state($lockedvalue); $response = $discussionvault->update_discussion($discussion); $discussion = !$response ? $response : $discussion; $exporterfactory = mod_forum\local\container::get_exporter_factory(); $exporter = $exporterfactory->get_discussion_exporter($USER, $forum, $discussion); return $exporter->export($PAGE->get_renderer('mod_forum')); }
[ "public", "static", "function", "set_lock_state", "(", "$", "forumid", ",", "$", "discussionid", ",", "$", "targetstate", ")", "{", "global", "$", "DB", ",", "$", "PAGE", ",", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "set_lock_state_parameters", "(", ")", ",", "[", "'forumid'", "=>", "$", "forumid", ",", "'discussionid'", "=>", "$", "discussionid", ",", "'targetstate'", "=>", "$", "targetstate", "]", ")", ";", "$", "vaultfactory", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_vault_factory", "(", ")", ";", "$", "forumvault", "=", "$", "vaultfactory", "->", "get_forum_vault", "(", ")", ";", "$", "forum", "=", "$", "forumvault", "->", "get_from_id", "(", "$", "params", "[", "'forumid'", "]", ")", ";", "$", "managerfactory", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_manager_factory", "(", ")", ";", "$", "capabilitymanager", "=", "$", "managerfactory", "->", "get_capability_manager", "(", "$", "forum", ")", ";", "if", "(", "!", "$", "capabilitymanager", "->", "can_manage_forum", "(", "$", "USER", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'errorcannotlock'", ",", "'forum'", ")", ";", "}", "// If the targetstate(currentstate) is not 0 then it should be set to the current time.", "$", "lockedvalue", "=", "$", "targetstate", "?", "0", ":", "time", "(", ")", ";", "self", "::", "validate_context", "(", "$", "forum", "->", "get_context", "(", ")", ")", ";", "$", "discussionvault", "=", "$", "vaultfactory", "->", "get_discussion_vault", "(", ")", ";", "$", "discussion", "=", "$", "discussionvault", "->", "get_from_id", "(", "$", "params", "[", "'discussionid'", "]", ")", ";", "// If the current state doesn't equal the desired state then update the current.", "// state to the desired state.", "$", "discussion", "->", "toggle_locked_state", "(", "$", "lockedvalue", ")", ";", "$", "response", "=", "$", "discussionvault", "->", "update_discussion", "(", "$", "discussion", ")", ";", "$", "discussion", "=", "!", "$", "response", "?", "$", "response", ":", "$", "discussion", ";", "$", "exporterfactory", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_exporter_factory", "(", ")", ";", "$", "exporter", "=", "$", "exporterfactory", "->", "get_discussion_exporter", "(", "$", "USER", ",", "$", "forum", ",", "$", "discussion", ")", ";", "return", "$", "exporter", "->", "export", "(", "$", "PAGE", "->", "get_renderer", "(", "'mod_forum'", ")", ")", ";", "}" ]
Set the lock state. @param int $forumid @param int $discussionid @param string $targetstate @return \stdClass
[ "Set", "the", "lock", "state", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/externallib.php#L1883-L1917
215,909
moodle/moodle
mod/forum/externallib.php
mod_forum_external.set_pin_state
public static function set_pin_state($discussionid, $targetstate) { global $PAGE, $USER; $params = self::validate_parameters(self::set_pin_state_parameters(), [ 'discussionid' => $discussionid, 'targetstate' => $targetstate, ]); $vaultfactory = mod_forum\local\container::get_vault_factory(); $managerfactory = mod_forum\local\container::get_manager_factory(); $forumvault = $vaultfactory->get_forum_vault(); $discussionvault = $vaultfactory->get_discussion_vault(); $discussion = $discussionvault->get_from_id($params['discussionid']); $forum = $forumvault->get_from_id($discussion->get_forum_id()); $capabilitymanager = $managerfactory->get_capability_manager($forum); self::validate_context($forum->get_context()); $legacydatamapperfactory = mod_forum\local\container::get_legacy_data_mapper_factory(); if (!$capabilitymanager->can_pin_discussions($USER)) { // Nothing to do. We won't actually output any content here though. throw new \moodle_exception('cannotpindiscussions', 'mod_forum'); } $discussion->set_pinned($targetstate); $discussionvault->update_discussion($discussion); $exporterfactory = mod_forum\local\container::get_exporter_factory(); $exporter = $exporterfactory->get_discussion_exporter($USER, $forum, $discussion); return $exporter->export($PAGE->get_renderer('mod_forum')); }
php
public static function set_pin_state($discussionid, $targetstate) { global $PAGE, $USER; $params = self::validate_parameters(self::set_pin_state_parameters(), [ 'discussionid' => $discussionid, 'targetstate' => $targetstate, ]); $vaultfactory = mod_forum\local\container::get_vault_factory(); $managerfactory = mod_forum\local\container::get_manager_factory(); $forumvault = $vaultfactory->get_forum_vault(); $discussionvault = $vaultfactory->get_discussion_vault(); $discussion = $discussionvault->get_from_id($params['discussionid']); $forum = $forumvault->get_from_id($discussion->get_forum_id()); $capabilitymanager = $managerfactory->get_capability_manager($forum); self::validate_context($forum->get_context()); $legacydatamapperfactory = mod_forum\local\container::get_legacy_data_mapper_factory(); if (!$capabilitymanager->can_pin_discussions($USER)) { // Nothing to do. We won't actually output any content here though. throw new \moodle_exception('cannotpindiscussions', 'mod_forum'); } $discussion->set_pinned($targetstate); $discussionvault->update_discussion($discussion); $exporterfactory = mod_forum\local\container::get_exporter_factory(); $exporter = $exporterfactory->get_discussion_exporter($USER, $forum, $discussion); return $exporter->export($PAGE->get_renderer('mod_forum')); }
[ "public", "static", "function", "set_pin_state", "(", "$", "discussionid", ",", "$", "targetstate", ")", "{", "global", "$", "PAGE", ",", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "set_pin_state_parameters", "(", ")", ",", "[", "'discussionid'", "=>", "$", "discussionid", ",", "'targetstate'", "=>", "$", "targetstate", ",", "]", ")", ";", "$", "vaultfactory", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_vault_factory", "(", ")", ";", "$", "managerfactory", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_manager_factory", "(", ")", ";", "$", "forumvault", "=", "$", "vaultfactory", "->", "get_forum_vault", "(", ")", ";", "$", "discussionvault", "=", "$", "vaultfactory", "->", "get_discussion_vault", "(", ")", ";", "$", "discussion", "=", "$", "discussionvault", "->", "get_from_id", "(", "$", "params", "[", "'discussionid'", "]", ")", ";", "$", "forum", "=", "$", "forumvault", "->", "get_from_id", "(", "$", "discussion", "->", "get_forum_id", "(", ")", ")", ";", "$", "capabilitymanager", "=", "$", "managerfactory", "->", "get_capability_manager", "(", "$", "forum", ")", ";", "self", "::", "validate_context", "(", "$", "forum", "->", "get_context", "(", ")", ")", ";", "$", "legacydatamapperfactory", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_legacy_data_mapper_factory", "(", ")", ";", "if", "(", "!", "$", "capabilitymanager", "->", "can_pin_discussions", "(", "$", "USER", ")", ")", "{", "// Nothing to do. We won't actually output any content here though.", "throw", "new", "\\", "moodle_exception", "(", "'cannotpindiscussions'", ",", "'mod_forum'", ")", ";", "}", "$", "discussion", "->", "set_pinned", "(", "$", "targetstate", ")", ";", "$", "discussionvault", "->", "update_discussion", "(", "$", "discussion", ")", ";", "$", "exporterfactory", "=", "mod_forum", "\\", "local", "\\", "container", "::", "get_exporter_factory", "(", ")", ";", "$", "exporter", "=", "$", "exporterfactory", "->", "get_discussion_exporter", "(", "$", "USER", ",", "$", "forum", ",", "$", "discussion", ")", ";", "return", "$", "exporter", "->", "export", "(", "$", "PAGE", "->", "get_renderer", "(", "'mod_forum'", ")", ")", ";", "}" ]
Set the pin state. @param int $discussionid @param bool $targetstate @return \stdClass
[ "Set", "the", "pin", "state", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/externallib.php#L1956-L1984
215,910
moodle/moodle
cache/forms.php
cachestore_addinstance_form.definition
protected final function definition() { $form = $this->_form; $store = $this->_customdata['store']; $plugin = $this->_customdata['plugin']; $locks = $this->_customdata['locks']; $form->addElement('hidden', 'plugin', $plugin); $form->setType('plugin', PARAM_PLUGIN); $form->addElement('hidden', 'editing', !empty($this->_customdata['store'])); $form->setType('editing', PARAM_BOOL); if (!$store) { $form->addElement('text', 'name', get_string('storename', 'cache')); $form->addHelpButton('name', 'storename', 'cache'); $form->addRule('name', get_string('required'), 'required'); $form->setType('name', PARAM_NOTAGS); } else { $form->addElement('hidden', 'name', $store); $form->addElement('static', 'name-value', get_string('storename', 'cache'), $store); $form->setType('name', PARAM_NOTAGS); } if (is_array($locks)) { $form->addElement('select', 'lock', get_string('locking', 'cache'), $locks); $form->addHelpButton('lock', 'locking', 'cache'); $form->setType('lock', PARAM_ALPHANUMEXT); } else { $form->addElement('hidden', 'lock', ''); $form->setType('lock', PARAM_ALPHANUMEXT); $form->addElement('static', 'lock-value', get_string('locking', 'cache'), '<em>'.get_string('nativelocking', 'cache').'</em>'); } if (method_exists($this, 'configuration_definition')) { $form->addElement('header', 'storeconfiguration', get_string('storeconfiguration', 'cache')); $this->configuration_definition(); } $this->add_action_buttons(); }
php
protected final function definition() { $form = $this->_form; $store = $this->_customdata['store']; $plugin = $this->_customdata['plugin']; $locks = $this->_customdata['locks']; $form->addElement('hidden', 'plugin', $plugin); $form->setType('plugin', PARAM_PLUGIN); $form->addElement('hidden', 'editing', !empty($this->_customdata['store'])); $form->setType('editing', PARAM_BOOL); if (!$store) { $form->addElement('text', 'name', get_string('storename', 'cache')); $form->addHelpButton('name', 'storename', 'cache'); $form->addRule('name', get_string('required'), 'required'); $form->setType('name', PARAM_NOTAGS); } else { $form->addElement('hidden', 'name', $store); $form->addElement('static', 'name-value', get_string('storename', 'cache'), $store); $form->setType('name', PARAM_NOTAGS); } if (is_array($locks)) { $form->addElement('select', 'lock', get_string('locking', 'cache'), $locks); $form->addHelpButton('lock', 'locking', 'cache'); $form->setType('lock', PARAM_ALPHANUMEXT); } else { $form->addElement('hidden', 'lock', ''); $form->setType('lock', PARAM_ALPHANUMEXT); $form->addElement('static', 'lock-value', get_string('locking', 'cache'), '<em>'.get_string('nativelocking', 'cache').'</em>'); } if (method_exists($this, 'configuration_definition')) { $form->addElement('header', 'storeconfiguration', get_string('storeconfiguration', 'cache')); $this->configuration_definition(); } $this->add_action_buttons(); }
[ "protected", "final", "function", "definition", "(", ")", "{", "$", "form", "=", "$", "this", "->", "_form", ";", "$", "store", "=", "$", "this", "->", "_customdata", "[", "'store'", "]", ";", "$", "plugin", "=", "$", "this", "->", "_customdata", "[", "'plugin'", "]", ";", "$", "locks", "=", "$", "this", "->", "_customdata", "[", "'locks'", "]", ";", "$", "form", "->", "addElement", "(", "'hidden'", ",", "'plugin'", ",", "$", "plugin", ")", ";", "$", "form", "->", "setType", "(", "'plugin'", ",", "PARAM_PLUGIN", ")", ";", "$", "form", "->", "addElement", "(", "'hidden'", ",", "'editing'", ",", "!", "empty", "(", "$", "this", "->", "_customdata", "[", "'store'", "]", ")", ")", ";", "$", "form", "->", "setType", "(", "'editing'", ",", "PARAM_BOOL", ")", ";", "if", "(", "!", "$", "store", ")", "{", "$", "form", "->", "addElement", "(", "'text'", ",", "'name'", ",", "get_string", "(", "'storename'", ",", "'cache'", ")", ")", ";", "$", "form", "->", "addHelpButton", "(", "'name'", ",", "'storename'", ",", "'cache'", ")", ";", "$", "form", "->", "addRule", "(", "'name'", ",", "get_string", "(", "'required'", ")", ",", "'required'", ")", ";", "$", "form", "->", "setType", "(", "'name'", ",", "PARAM_NOTAGS", ")", ";", "}", "else", "{", "$", "form", "->", "addElement", "(", "'hidden'", ",", "'name'", ",", "$", "store", ")", ";", "$", "form", "->", "addElement", "(", "'static'", ",", "'name-value'", ",", "get_string", "(", "'storename'", ",", "'cache'", ")", ",", "$", "store", ")", ";", "$", "form", "->", "setType", "(", "'name'", ",", "PARAM_NOTAGS", ")", ";", "}", "if", "(", "is_array", "(", "$", "locks", ")", ")", "{", "$", "form", "->", "addElement", "(", "'select'", ",", "'lock'", ",", "get_string", "(", "'locking'", ",", "'cache'", ")", ",", "$", "locks", ")", ";", "$", "form", "->", "addHelpButton", "(", "'lock'", ",", "'locking'", ",", "'cache'", ")", ";", "$", "form", "->", "setType", "(", "'lock'", ",", "PARAM_ALPHANUMEXT", ")", ";", "}", "else", "{", "$", "form", "->", "addElement", "(", "'hidden'", ",", "'lock'", ",", "''", ")", ";", "$", "form", "->", "setType", "(", "'lock'", ",", "PARAM_ALPHANUMEXT", ")", ";", "$", "form", "->", "addElement", "(", "'static'", ",", "'lock-value'", ",", "get_string", "(", "'locking'", ",", "'cache'", ")", ",", "'<em>'", ".", "get_string", "(", "'nativelocking'", ",", "'cache'", ")", ".", "'</em>'", ")", ";", "}", "if", "(", "method_exists", "(", "$", "this", ",", "'configuration_definition'", ")", ")", "{", "$", "form", "->", "addElement", "(", "'header'", ",", "'storeconfiguration'", ",", "get_string", "(", "'storeconfiguration'", ",", "'cache'", ")", ")", ";", "$", "this", "->", "configuration_definition", "(", ")", ";", "}", "$", "this", "->", "add_action_buttons", "(", ")", ";", "}" ]
The definition of the add instance form
[ "The", "definition", "of", "the", "add", "instance", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/forms.php#L45-L84
215,911
moodle/moodle
cache/forms.php
cachestore_addinstance_form.validation
public function validation($data, $files) { $errors = parent::validation($data, $files); if (!array_key_exists('name', $errors)) { if (!preg_match('#^[a-zA-Z0-9\-_ ]+$#', $data['name'])) { $errors['name'] = get_string('storenameinvalid', 'cache'); } else if (empty($this->_customdata['store'])) { $stores = cache_administration_helper::get_store_instance_summaries(); if (array_key_exists($data['name'], $stores)) { $errors['name'] = get_string('storenamealreadyused', 'cache'); } } } if (method_exists($this, 'configuration_validation')) { $newerrors = $this->configuration_validation($data, $files, $errors); // We need to selectiviliy merge here foreach ($newerrors as $element => $error) { if (!array_key_exists($element, $errors)) { $errors[$element] = $error; } } } return $errors; }
php
public function validation($data, $files) { $errors = parent::validation($data, $files); if (!array_key_exists('name', $errors)) { if (!preg_match('#^[a-zA-Z0-9\-_ ]+$#', $data['name'])) { $errors['name'] = get_string('storenameinvalid', 'cache'); } else if (empty($this->_customdata['store'])) { $stores = cache_administration_helper::get_store_instance_summaries(); if (array_key_exists($data['name'], $stores)) { $errors['name'] = get_string('storenamealreadyused', 'cache'); } } } if (method_exists($this, 'configuration_validation')) { $newerrors = $this->configuration_validation($data, $files, $errors); // We need to selectiviliy merge here foreach ($newerrors as $element => $error) { if (!array_key_exists($element, $errors)) { $errors[$element] = $error; } } } return $errors; }
[ "public", "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "$", "errors", "=", "parent", "::", "validation", "(", "$", "data", ",", "$", "files", ")", ";", "if", "(", "!", "array_key_exists", "(", "'name'", ",", "$", "errors", ")", ")", "{", "if", "(", "!", "preg_match", "(", "'#^[a-zA-Z0-9\\-_ ]+$#'", ",", "$", "data", "[", "'name'", "]", ")", ")", "{", "$", "errors", "[", "'name'", "]", "=", "get_string", "(", "'storenameinvalid'", ",", "'cache'", ")", ";", "}", "else", "if", "(", "empty", "(", "$", "this", "->", "_customdata", "[", "'store'", "]", ")", ")", "{", "$", "stores", "=", "cache_administration_helper", "::", "get_store_instance_summaries", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "data", "[", "'name'", "]", ",", "$", "stores", ")", ")", "{", "$", "errors", "[", "'name'", "]", "=", "get_string", "(", "'storenamealreadyused'", ",", "'cache'", ")", ";", "}", "}", "}", "if", "(", "method_exists", "(", "$", "this", ",", "'configuration_validation'", ")", ")", "{", "$", "newerrors", "=", "$", "this", "->", "configuration_validation", "(", "$", "data", ",", "$", "files", ",", "$", "errors", ")", ";", "// We need to selectiviliy merge here", "foreach", "(", "$", "newerrors", "as", "$", "element", "=>", "$", "error", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "element", ",", "$", "errors", ")", ")", "{", "$", "errors", "[", "$", "element", "]", "=", "$", "error", ";", "}", "}", "}", "return", "$", "errors", ";", "}" ]
Validates the add instance form data @param array $data @param array $files @return array
[ "Validates", "the", "add", "instance", "form", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/forms.php#L93-L118
215,912
moodle/moodle
cache/forms.php
cache_definition_sharing_form.set_data
public function set_data($data) { if (!isset($data['sharing'])) { // Set the default value here. mforms doesn't handle defaults very nicely. $data['sharing'] = cache_administration_helper::get_definition_sharing_options(cache_definition::SHARING_DEFAULT); } parent::set_data($data); }
php
public function set_data($data) { if (!isset($data['sharing'])) { // Set the default value here. mforms doesn't handle defaults very nicely. $data['sharing'] = cache_administration_helper::get_definition_sharing_options(cache_definition::SHARING_DEFAULT); } parent::set_data($data); }
[ "public", "function", "set_data", "(", "$", "data", ")", "{", "if", "(", "!", "isset", "(", "$", "data", "[", "'sharing'", "]", ")", ")", "{", "// Set the default value here. mforms doesn't handle defaults very nicely.", "$", "data", "[", "'sharing'", "]", "=", "cache_administration_helper", "::", "get_definition_sharing_options", "(", "cache_definition", "::", "SHARING_DEFAULT", ")", ";", "}", "parent", "::", "set_data", "(", "$", "data", ")", ";", "}" ]
Sets the data for this form. @param array $data
[ "Sets", "the", "data", "for", "this", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/forms.php#L247-L253
215,913
moodle/moodle
cache/forms.php
cache_definition_sharing_form.validation
public function validation($data, $files) { $errors = parent::validation($data, $files); if (count($errors) === 0 && !isset($data['sharing'])) { // They must select at least one sharing option. $errors['sharing'] = get_string('sharingrequired', 'cache'); } return $errors; }
php
public function validation($data, $files) { $errors = parent::validation($data, $files); if (count($errors) === 0 && !isset($data['sharing'])) { // They must select at least one sharing option. $errors['sharing'] = get_string('sharingrequired', 'cache'); } return $errors; }
[ "public", "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "$", "errors", "=", "parent", "::", "validation", "(", "$", "data", ",", "$", "files", ")", ";", "if", "(", "count", "(", "$", "errors", ")", "===", "0", "&&", "!", "isset", "(", "$", "data", "[", "'sharing'", "]", ")", ")", "{", "// They must select at least one sharing option.", "$", "errors", "[", "'sharing'", "]", "=", "get_string", "(", "'sharingrequired'", ",", "'cache'", ")", ";", "}", "return", "$", "errors", ";", "}" ]
Validates this form @param array $data @param array $files @return array
[ "Validates", "this", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/forms.php#L262-L269
215,914
moodle/moodle
cache/forms.php
cache_lock_form.definition
final public function definition() { $plugin = $this->_customdata['lock']; $this->_form->addElement('hidden', 'action', 'newlockinstance'); $this->_form->setType('action', PARAM_ALPHANUMEXT); $this->_form->addElement('hidden', 'lock', $plugin); $this->_form->setType('lock', PARAM_COMPONENT); $this->_form->addElement('text', 'name', get_string('lockname', 'cache')); $this->_form->setType('name', PARAM_ALPHANUMEXT); $this->_form->addRule('name', get_string('required'), 'required'); $this->_form->addElement('static', 'namedesc', '', get_string('locknamedesc', 'cache')); $this->plugin_definition(); $this->add_action_buttons(); }
php
final public function definition() { $plugin = $this->_customdata['lock']; $this->_form->addElement('hidden', 'action', 'newlockinstance'); $this->_form->setType('action', PARAM_ALPHANUMEXT); $this->_form->addElement('hidden', 'lock', $plugin); $this->_form->setType('lock', PARAM_COMPONENT); $this->_form->addElement('text', 'name', get_string('lockname', 'cache')); $this->_form->setType('name', PARAM_ALPHANUMEXT); $this->_form->addRule('name', get_string('required'), 'required'); $this->_form->addElement('static', 'namedesc', '', get_string('locknamedesc', 'cache')); $this->plugin_definition(); $this->add_action_buttons(); }
[ "final", "public", "function", "definition", "(", ")", "{", "$", "plugin", "=", "$", "this", "->", "_customdata", "[", "'lock'", "]", ";", "$", "this", "->", "_form", "->", "addElement", "(", "'hidden'", ",", "'action'", ",", "'newlockinstance'", ")", ";", "$", "this", "->", "_form", "->", "setType", "(", "'action'", ",", "PARAM_ALPHANUMEXT", ")", ";", "$", "this", "->", "_form", "->", "addElement", "(", "'hidden'", ",", "'lock'", ",", "$", "plugin", ")", ";", "$", "this", "->", "_form", "->", "setType", "(", "'lock'", ",", "PARAM_COMPONENT", ")", ";", "$", "this", "->", "_form", "->", "addElement", "(", "'text'", ",", "'name'", ",", "get_string", "(", "'lockname'", ",", "'cache'", ")", ")", ";", "$", "this", "->", "_form", "->", "setType", "(", "'name'", ",", "PARAM_ALPHANUMEXT", ")", ";", "$", "this", "->", "_form", "->", "addRule", "(", "'name'", ",", "get_string", "(", "'required'", ")", ",", "'required'", ")", ";", "$", "this", "->", "_form", "->", "addElement", "(", "'static'", ",", "'namedesc'", ",", "''", ",", "get_string", "(", "'locknamedesc'", ",", "'cache'", ")", ")", ";", "$", "this", "->", "plugin_definition", "(", ")", ";", "$", "this", "->", "add_action_buttons", "(", ")", ";", "}" ]
Defines this form.
[ "Defines", "this", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/forms.php#L331-L346
215,915
moodle/moodle
cache/forms.php
cache_lock_form.validation
final public function validation($data, $files) { $errors = parent::validation($data, $files); if (!isset($errors['name'])) { $config = cache_config::instance(); if (in_array($data['name'], array_keys($config->get_locks()))) { $errors['name'] = get_string('locknamenotunique', 'cache'); } } $errors = $this->plugin_validation($data, $files, $errors); return $errors; }
php
final public function validation($data, $files) { $errors = parent::validation($data, $files); if (!isset($errors['name'])) { $config = cache_config::instance(); if (in_array($data['name'], array_keys($config->get_locks()))) { $errors['name'] = get_string('locknamenotunique', 'cache'); } } $errors = $this->plugin_validation($data, $files, $errors); return $errors; }
[ "final", "public", "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "$", "errors", "=", "parent", "::", "validation", "(", "$", "data", ",", "$", "files", ")", ";", "if", "(", "!", "isset", "(", "$", "errors", "[", "'name'", "]", ")", ")", "{", "$", "config", "=", "cache_config", "::", "instance", "(", ")", ";", "if", "(", "in_array", "(", "$", "data", "[", "'name'", "]", ",", "array_keys", "(", "$", "config", "->", "get_locks", "(", ")", ")", ")", ")", "{", "$", "errors", "[", "'name'", "]", "=", "get_string", "(", "'locknamenotunique'", ",", "'cache'", ")", ";", "}", "}", "$", "errors", "=", "$", "this", "->", "plugin_validation", "(", "$", "data", ",", "$", "files", ",", "$", "errors", ")", ";", "return", "$", "errors", ";", "}" ]
Validates this form. @param array $data @param array $files @return array
[ "Validates", "this", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/forms.php#L355-L365
215,916
moodle/moodle
lib/filebrowser/file_info_stored.php
file_info_stored.get_readable_fullname
public function get_readable_fullname() { global $CFG; // retrieve the readable path with all parents (excluding the top most 'System') $fpath = array(); for ($parent = $this; $parent && $parent->get_parent(); $parent = $parent->get_parent()) { array_unshift($fpath, $parent->get_visible_name()); } if ($this->lf->get_component() == 'user' && $this->lf->get_filearea() == 'private') { // use the special syntax for user private files - 'USERNAME Private files: PATH' $username = array_shift($fpath); array_shift($fpath); // get rid of "Private Files/" in the beginning of the path return get_string('privatefilesof', 'repository', $username). ': '. join('/', $fpath); } else { // for all other files (except user private files) return 'Server files: PATH' // first, get and cache the name of the repository_local (will be used as prefix for file names): static $replocalname = null; if ($replocalname === null) { require_once($CFG->dirroot . "/repository/lib.php"); $instances = repository::get_instances(array('type' => 'local')); if (count($instances)) { $firstinstance = reset($instances); $replocalname = $firstinstance->get_name(); } else if (get_string_manager()->string_exists('pluginname', 'repository_local')) { $replocalname = get_string('pluginname', 'repository_local'); } else { $replocalname = get_string('arearoot', 'repository'); } } return $replocalname. ': '. join('/', $fpath); } }
php
public function get_readable_fullname() { global $CFG; // retrieve the readable path with all parents (excluding the top most 'System') $fpath = array(); for ($parent = $this; $parent && $parent->get_parent(); $parent = $parent->get_parent()) { array_unshift($fpath, $parent->get_visible_name()); } if ($this->lf->get_component() == 'user' && $this->lf->get_filearea() == 'private') { // use the special syntax for user private files - 'USERNAME Private files: PATH' $username = array_shift($fpath); array_shift($fpath); // get rid of "Private Files/" in the beginning of the path return get_string('privatefilesof', 'repository', $username). ': '. join('/', $fpath); } else { // for all other files (except user private files) return 'Server files: PATH' // first, get and cache the name of the repository_local (will be used as prefix for file names): static $replocalname = null; if ($replocalname === null) { require_once($CFG->dirroot . "/repository/lib.php"); $instances = repository::get_instances(array('type' => 'local')); if (count($instances)) { $firstinstance = reset($instances); $replocalname = $firstinstance->get_name(); } else if (get_string_manager()->string_exists('pluginname', 'repository_local')) { $replocalname = get_string('pluginname', 'repository_local'); } else { $replocalname = get_string('arearoot', 'repository'); } } return $replocalname. ': '. join('/', $fpath); } }
[ "public", "function", "get_readable_fullname", "(", ")", "{", "global", "$", "CFG", ";", "// retrieve the readable path with all parents (excluding the top most 'System')", "$", "fpath", "=", "array", "(", ")", ";", "for", "(", "$", "parent", "=", "$", "this", ";", "$", "parent", "&&", "$", "parent", "->", "get_parent", "(", ")", ";", "$", "parent", "=", "$", "parent", "->", "get_parent", "(", ")", ")", "{", "array_unshift", "(", "$", "fpath", ",", "$", "parent", "->", "get_visible_name", "(", ")", ")", ";", "}", "if", "(", "$", "this", "->", "lf", "->", "get_component", "(", ")", "==", "'user'", "&&", "$", "this", "->", "lf", "->", "get_filearea", "(", ")", "==", "'private'", ")", "{", "// use the special syntax for user private files - 'USERNAME Private files: PATH'", "$", "username", "=", "array_shift", "(", "$", "fpath", ")", ";", "array_shift", "(", "$", "fpath", ")", ";", "// get rid of \"Private Files/\" in the beginning of the path", "return", "get_string", "(", "'privatefilesof'", ",", "'repository'", ",", "$", "username", ")", ".", "': '", ".", "join", "(", "'/'", ",", "$", "fpath", ")", ";", "}", "else", "{", "// for all other files (except user private files) return 'Server files: PATH'", "// first, get and cache the name of the repository_local (will be used as prefix for file names):", "static", "$", "replocalname", "=", "null", ";", "if", "(", "$", "replocalname", "===", "null", ")", "{", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "\"/repository/lib.php\"", ")", ";", "$", "instances", "=", "repository", "::", "get_instances", "(", "array", "(", "'type'", "=>", "'local'", ")", ")", ";", "if", "(", "count", "(", "$", "instances", ")", ")", "{", "$", "firstinstance", "=", "reset", "(", "$", "instances", ")", ";", "$", "replocalname", "=", "$", "firstinstance", "->", "get_name", "(", ")", ";", "}", "else", "if", "(", "get_string_manager", "(", ")", "->", "string_exists", "(", "'pluginname'", ",", "'repository_local'", ")", ")", "{", "$", "replocalname", "=", "get_string", "(", "'pluginname'", ",", "'repository_local'", ")", ";", "}", "else", "{", "$", "replocalname", "=", "get_string", "(", "'arearoot'", ",", "'repository'", ")", ";", "}", "}", "return", "$", "replocalname", ".", "': '", ".", "join", "(", "'/'", ",", "$", "fpath", ")", ";", "}", "}" ]
Returns the localised human-readable name of the file together with virtual path @return string
[ "Returns", "the", "localised", "human", "-", "readable", "name", "of", "the", "file", "together", "with", "virtual", "path" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_stored.php#L121-L154
215,917
moodle/moodle
lib/filebrowser/file_info_stored.php
file_info_stored.is_empty_area
public function is_empty_area() { if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') { // test the emptiness only in the top most level, it does not make sense at lower levels $fs = get_file_storage(); return $fs->is_area_empty($this->lf->get_contextid(), $this->lf->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid()); } else { return false; } }
php
public function is_empty_area() { if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') { // test the emptiness only in the top most level, it does not make sense at lower levels $fs = get_file_storage(); return $fs->is_area_empty($this->lf->get_contextid(), $this->lf->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid()); } else { return false; } }
[ "public", "function", "is_empty_area", "(", ")", "{", "if", "(", "$", "this", "->", "lf", "->", "get_filepath", "(", ")", "===", "'/'", "and", "$", "this", "->", "lf", "->", "get_filename", "(", ")", "===", "'.'", ")", "{", "// test the emptiness only in the top most level, it does not make sense at lower levels", "$", "fs", "=", "get_file_storage", "(", ")", ";", "return", "$", "fs", "->", "is_area_empty", "(", "$", "this", "->", "lf", "->", "get_contextid", "(", ")", ",", "$", "this", "->", "lf", "->", "get_component", "(", ")", ",", "$", "this", "->", "lf", "->", "get_filearea", "(", ")", ",", "$", "this", "->", "lf", "->", "get_itemid", "(", ")", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Whether or not this is an empty area @return bool
[ "Whether", "or", "not", "this", "is", "an", "empty", "area" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_stored.php#L211-L219
215,918
moodle/moodle
lib/filebrowser/file_info_stored.php
file_info_stored.get_parent
public function get_parent() { if ($this->lf->get_filepath() === '/' and $this->lf->is_directory()) { if ($this->areaonly) { return null; } else if ($this->itemidused) { return $this->browser->get_file_info($this->context, $this->lf->get_component(), $this->lf->get_filearea()); } else { return $this->browser->get_file_info($this->context); } } if (!$this->lf->is_directory()) { return $this->browser->get_file_info($this->context, $this->lf->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid(), $this->lf->get_filepath(), '.'); } $filepath = $this->lf->get_filepath(); $filepath = trim($filepath, '/'); $dirs = explode('/', $filepath); array_pop($dirs); $filepath = implode('/', $dirs); $filepath = ($filepath === '') ? '/' : "/$filepath/"; return $this->browser->get_file_info($this->context, $this->lf->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid(), $filepath, '.'); }
php
public function get_parent() { if ($this->lf->get_filepath() === '/' and $this->lf->is_directory()) { if ($this->areaonly) { return null; } else if ($this->itemidused) { return $this->browser->get_file_info($this->context, $this->lf->get_component(), $this->lf->get_filearea()); } else { return $this->browser->get_file_info($this->context); } } if (!$this->lf->is_directory()) { return $this->browser->get_file_info($this->context, $this->lf->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid(), $this->lf->get_filepath(), '.'); } $filepath = $this->lf->get_filepath(); $filepath = trim($filepath, '/'); $dirs = explode('/', $filepath); array_pop($dirs); $filepath = implode('/', $dirs); $filepath = ($filepath === '') ? '/' : "/$filepath/"; return $this->browser->get_file_info($this->context, $this->lf->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid(), $filepath, '.'); }
[ "public", "function", "get_parent", "(", ")", "{", "if", "(", "$", "this", "->", "lf", "->", "get_filepath", "(", ")", "===", "'/'", "and", "$", "this", "->", "lf", "->", "is_directory", "(", ")", ")", "{", "if", "(", "$", "this", "->", "areaonly", ")", "{", "return", "null", ";", "}", "else", "if", "(", "$", "this", "->", "itemidused", ")", "{", "return", "$", "this", "->", "browser", "->", "get_file_info", "(", "$", "this", "->", "context", ",", "$", "this", "->", "lf", "->", "get_component", "(", ")", ",", "$", "this", "->", "lf", "->", "get_filearea", "(", ")", ")", ";", "}", "else", "{", "return", "$", "this", "->", "browser", "->", "get_file_info", "(", "$", "this", "->", "context", ")", ";", "}", "}", "if", "(", "!", "$", "this", "->", "lf", "->", "is_directory", "(", ")", ")", "{", "return", "$", "this", "->", "browser", "->", "get_file_info", "(", "$", "this", "->", "context", ",", "$", "this", "->", "lf", "->", "get_component", "(", ")", ",", "$", "this", "->", "lf", "->", "get_filearea", "(", ")", ",", "$", "this", "->", "lf", "->", "get_itemid", "(", ")", ",", "$", "this", "->", "lf", "->", "get_filepath", "(", ")", ",", "'.'", ")", ";", "}", "$", "filepath", "=", "$", "this", "->", "lf", "->", "get_filepath", "(", ")", ";", "$", "filepath", "=", "trim", "(", "$", "filepath", ",", "'/'", ")", ";", "$", "dirs", "=", "explode", "(", "'/'", ",", "$", "filepath", ")", ";", "array_pop", "(", "$", "dirs", ")", ";", "$", "filepath", "=", "implode", "(", "'/'", ",", "$", "dirs", ")", ";", "$", "filepath", "=", "(", "$", "filepath", "===", "''", ")", "?", "'/'", ":", "\"/$filepath/\"", ";", "return", "$", "this", "->", "browser", "->", "get_file_info", "(", "$", "this", "->", "context", ",", "$", "this", "->", "lf", "->", "get_component", "(", ")", ",", "$", "this", "->", "lf", "->", "get_filearea", "(", ")", ",", "$", "this", "->", "lf", "->", "get_itemid", "(", ")", ",", "$", "filepath", ",", "'.'", ")", ";", "}" ]
Returns parent file_info instance @return file_info|null file_info instance or null for root
[ "Returns", "parent", "file_info", "instance" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_stored.php#L436-L459
215,919
moodle/moodle
lib/filebrowser/file_info_stored.php
file_info_stored.create_directory
public function create_directory($newdirname, $userid = NULL) { if (!$this->is_writable() or !$this->lf->is_directory()) { return null; } $newdirname = clean_param($newdirname, PARAM_FILE); if ($newdirname === '') { return null; } $filepath = $this->lf->get_filepath().'/'.$newdirname.'/'; $fs = get_file_storage(); if ($file = $fs->create_directory($this->lf->get_contextid(), $this->lf->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid(), $filepath, $userid)) { return $this->browser->get_file_info($this->context, $this->lf->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); } return null; }
php
public function create_directory($newdirname, $userid = NULL) { if (!$this->is_writable() or !$this->lf->is_directory()) { return null; } $newdirname = clean_param($newdirname, PARAM_FILE); if ($newdirname === '') { return null; } $filepath = $this->lf->get_filepath().'/'.$newdirname.'/'; $fs = get_file_storage(); if ($file = $fs->create_directory($this->lf->get_contextid(), $this->lf->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid(), $filepath, $userid)) { return $this->browser->get_file_info($this->context, $this->lf->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); } return null; }
[ "public", "function", "create_directory", "(", "$", "newdirname", ",", "$", "userid", "=", "NULL", ")", "{", "if", "(", "!", "$", "this", "->", "is_writable", "(", ")", "or", "!", "$", "this", "->", "lf", "->", "is_directory", "(", ")", ")", "{", "return", "null", ";", "}", "$", "newdirname", "=", "clean_param", "(", "$", "newdirname", ",", "PARAM_FILE", ")", ";", "if", "(", "$", "newdirname", "===", "''", ")", "{", "return", "null", ";", "}", "$", "filepath", "=", "$", "this", "->", "lf", "->", "get_filepath", "(", ")", ".", "'/'", ".", "$", "newdirname", ".", "'/'", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "if", "(", "$", "file", "=", "$", "fs", "->", "create_directory", "(", "$", "this", "->", "lf", "->", "get_contextid", "(", ")", ",", "$", "this", "->", "lf", "->", "get_component", "(", ")", ",", "$", "this", "->", "lf", "->", "get_filearea", "(", ")", ",", "$", "this", "->", "lf", "->", "get_itemid", "(", ")", ",", "$", "filepath", ",", "$", "userid", ")", ")", "{", "return", "$", "this", "->", "browser", "->", "get_file_info", "(", "$", "this", "->", "context", ",", "$", "this", "->", "lf", "->", "get_component", "(", ")", ",", "$", "file", "->", "get_filearea", "(", ")", ",", "$", "file", "->", "get_itemid", "(", ")", ",", "$", "file", "->", "get_filepath", "(", ")", ",", "$", "file", "->", "get_filename", "(", ")", ")", ";", "}", "return", "null", ";", "}" ]
Create new directory, may throw exception - make sure params are valid. @param string $newdirname name of new directory @param int $userid id of author, default $USER->id @return file_info|null new directory's file_info instance or null if failed
[ "Create", "new", "directory", "may", "throw", "exception", "-", "make", "sure", "params", "are", "valid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_stored.php#L469-L487
215,920
moodle/moodle
lib/filebrowser/file_info_stored.php
file_info_stored.create_file_from_string
public function create_file_from_string($newfilename, $content, $userid = NULL) { if (!$this->is_writable() or !$this->lf->is_directory()) { return null; } $newfilename = clean_param($newfilename, PARAM_FILE); if ($newfilename === '') { return null; } $fs = get_file_storage(); $now = time(); $newrecord = new stdClass(); $newrecord->contextid = $this->lf->get_contextid(); $newrecord->component = $this->lf->get_component(); $newrecord->filearea = $this->lf->get_filearea(); $newrecord->itemid = $this->lf->get_itemid(); $newrecord->filepath = $this->lf->get_filepath(); $newrecord->filename = $newfilename; if ($fs->file_exists($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename)) { // file already exists, sorry return null; } $newrecord->timecreated = $now; $newrecord->timemodified = $now; $newrecord->mimetype = mimeinfo('type', $newfilename); $newrecord->userid = $userid; if ($file = $fs->create_file_from_string($newrecord, $content)) { return $this->browser->get_file_info($this->context, $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); } return null; }
php
public function create_file_from_string($newfilename, $content, $userid = NULL) { if (!$this->is_writable() or !$this->lf->is_directory()) { return null; } $newfilename = clean_param($newfilename, PARAM_FILE); if ($newfilename === '') { return null; } $fs = get_file_storage(); $now = time(); $newrecord = new stdClass(); $newrecord->contextid = $this->lf->get_contextid(); $newrecord->component = $this->lf->get_component(); $newrecord->filearea = $this->lf->get_filearea(); $newrecord->itemid = $this->lf->get_itemid(); $newrecord->filepath = $this->lf->get_filepath(); $newrecord->filename = $newfilename; if ($fs->file_exists($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename)) { // file already exists, sorry return null; } $newrecord->timecreated = $now; $newrecord->timemodified = $now; $newrecord->mimetype = mimeinfo('type', $newfilename); $newrecord->userid = $userid; if ($file = $fs->create_file_from_string($newrecord, $content)) { return $this->browser->get_file_info($this->context, $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); } return null; }
[ "public", "function", "create_file_from_string", "(", "$", "newfilename", ",", "$", "content", ",", "$", "userid", "=", "NULL", ")", "{", "if", "(", "!", "$", "this", "->", "is_writable", "(", ")", "or", "!", "$", "this", "->", "lf", "->", "is_directory", "(", ")", ")", "{", "return", "null", ";", "}", "$", "newfilename", "=", "clean_param", "(", "$", "newfilename", ",", "PARAM_FILE", ")", ";", "if", "(", "$", "newfilename", "===", "''", ")", "{", "return", "null", ";", "}", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "now", "=", "time", "(", ")", ";", "$", "newrecord", "=", "new", "stdClass", "(", ")", ";", "$", "newrecord", "->", "contextid", "=", "$", "this", "->", "lf", "->", "get_contextid", "(", ")", ";", "$", "newrecord", "->", "component", "=", "$", "this", "->", "lf", "->", "get_component", "(", ")", ";", "$", "newrecord", "->", "filearea", "=", "$", "this", "->", "lf", "->", "get_filearea", "(", ")", ";", "$", "newrecord", "->", "itemid", "=", "$", "this", "->", "lf", "->", "get_itemid", "(", ")", ";", "$", "newrecord", "->", "filepath", "=", "$", "this", "->", "lf", "->", "get_filepath", "(", ")", ";", "$", "newrecord", "->", "filename", "=", "$", "newfilename", ";", "if", "(", "$", "fs", "->", "file_exists", "(", "$", "newrecord", "->", "contextid", ",", "$", "newrecord", "->", "component", ",", "$", "newrecord", "->", "filearea", ",", "$", "newrecord", "->", "itemid", ",", "$", "newrecord", "->", "filepath", ",", "$", "newrecord", "->", "filename", ")", ")", "{", "// file already exists, sorry", "return", "null", ";", "}", "$", "newrecord", "->", "timecreated", "=", "$", "now", ";", "$", "newrecord", "->", "timemodified", "=", "$", "now", ";", "$", "newrecord", "->", "mimetype", "=", "mimeinfo", "(", "'type'", ",", "$", "newfilename", ")", ";", "$", "newrecord", "->", "userid", "=", "$", "userid", ";", "if", "(", "$", "file", "=", "$", "fs", "->", "create_file_from_string", "(", "$", "newrecord", ",", "$", "content", ")", ")", "{", "return", "$", "this", "->", "browser", "->", "get_file_info", "(", "$", "this", "->", "context", ",", "$", "file", "->", "get_component", "(", ")", ",", "$", "file", "->", "get_filearea", "(", ")", ",", "$", "file", "->", "get_itemid", "(", ")", ",", "$", "file", "->", "get_filepath", "(", ")", ",", "$", "file", "->", "get_filename", "(", ")", ")", ";", "}", "return", "null", ";", "}" ]
Create new file from string - make sure params are valid. @param string $newfilename name of new file @param string $content of file @param int $userid id of author, default $USER->id @return file_info|null new file's file_info instance or null if failed
[ "Create", "new", "file", "from", "string", "-", "make", "sure", "params", "are", "valid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_stored.php#L499-L535
215,921
moodle/moodle
lib/filebrowser/file_info_stored.php
file_info_stored.delete
public function delete() { if (!$this->is_writable()) { return false; } if ($this->is_directory()) { $filepath = $this->lf->get_filepath(); $fs = get_file_storage(); $storedfiles = $fs->get_area_files($this->context->id, $this->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid()); foreach ($storedfiles as $file) { if (strpos($file->get_filepath(), $filepath) === 0) { $file->delete(); } } } return $this->lf->delete(); }
php
public function delete() { if (!$this->is_writable()) { return false; } if ($this->is_directory()) { $filepath = $this->lf->get_filepath(); $fs = get_file_storage(); $storedfiles = $fs->get_area_files($this->context->id, $this->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid()); foreach ($storedfiles as $file) { if (strpos($file->get_filepath(), $filepath) === 0) { $file->delete(); } } } return $this->lf->delete(); }
[ "public", "function", "delete", "(", ")", "{", "if", "(", "!", "$", "this", "->", "is_writable", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "is_directory", "(", ")", ")", "{", "$", "filepath", "=", "$", "this", "->", "lf", "->", "get_filepath", "(", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "storedfiles", "=", "$", "fs", "->", "get_area_files", "(", "$", "this", "->", "context", "->", "id", ",", "$", "this", "->", "get_component", "(", ")", ",", "$", "this", "->", "lf", "->", "get_filearea", "(", ")", ",", "$", "this", "->", "lf", "->", "get_itemid", "(", ")", ")", ";", "foreach", "(", "$", "storedfiles", "as", "$", "file", ")", "{", "if", "(", "strpos", "(", "$", "file", "->", "get_filepath", "(", ")", ",", "$", "filepath", ")", "===", "0", ")", "{", "$", "file", "->", "delete", "(", ")", ";", "}", "}", "}", "return", "$", "this", "->", "lf", "->", "delete", "(", ")", ";", "}" ]
Delete file, make sure file is deletable first. @return bool success
[ "Delete", "file", "make", "sure", "file", "is", "deletable", "first", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_stored.php#L636-L653
215,922
moodle/moodle
lib/classes/event/course_module_deleted.php
course_module_deleted.get_legacy_eventdata
protected function get_legacy_eventdata() { $eventdata = new \stdClass(); $eventdata->modulename = $this->other['modulename']; $eventdata->cmid = $this->objectid; $eventdata->courseid = $this->courseid; $eventdata->userid = $this->userid; return $eventdata; }
php
protected function get_legacy_eventdata() { $eventdata = new \stdClass(); $eventdata->modulename = $this->other['modulename']; $eventdata->cmid = $this->objectid; $eventdata->courseid = $this->courseid; $eventdata->userid = $this->userid; return $eventdata; }
[ "protected", "function", "get_legacy_eventdata", "(", ")", "{", "$", "eventdata", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "eventdata", "->", "modulename", "=", "$", "this", "->", "other", "[", "'modulename'", "]", ";", "$", "eventdata", "->", "cmid", "=", "$", "this", "->", "objectid", ";", "$", "eventdata", "->", "courseid", "=", "$", "this", "->", "courseid", ";", "$", "eventdata", "->", "userid", "=", "$", "this", "->", "userid", ";", "return", "$", "eventdata", ";", "}" ]
Legacy event data. @return \stdClass
[ "Legacy", "event", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/course_module_deleted.php#L89-L96
215,923
moodle/moodle
lib/classes/task/asynchronous_backup_task.php
asynchronous_backup_task.execute
public function execute() { global $DB; $started = time(); $backupid = $this->get_custom_data()->backupid; $backuprecordid = $DB->get_field('backup_controllers', 'id', array('backupid' => $backupid), MUST_EXIST); mtrace('Processing asynchronous backup for backup: ' . $backupid); // Get the backup controller by backup id. $bc = \backup_controller::load_controller($backupid); $bc->set_progress(new \core\progress\db_updater($backuprecordid, 'backup_controllers', 'progress')); // Do some preflight checks on the backup. $status = $bc->get_status(); $execution = $bc->get_execution(); // Check that the backup is in the correct status and // that is set for asynchronous execution. if ($status == \backup::STATUS_AWAITING && $execution == \backup::EXECUTION_DELAYED) { // Execute the backup. $bc->execute_plan(); // Send message to user if enabled. $messageenabled = (bool)get_config('backup', 'backup_async_message_users'); if ($messageenabled && $bc->get_status() == \backup::STATUS_FINISHED_OK) { $asynchelper = new async_helper('backup', $backupid); $asynchelper->send_message(); } } else { // If status isn't 700, it means the process has failed. // Retrying isn't going to fix it, so marked operation as failed. $bc->set_status(\backup::STATUS_FINISHED_ERR); mtrace('Bad backup controller status, is: ' . $status . ' should be 700, marking job as failed.'); } // Cleanup. $bc->destroy(); $duration = time() - $started; mtrace('Backup completed in: ' . $duration . ' seconds'); }
php
public function execute() { global $DB; $started = time(); $backupid = $this->get_custom_data()->backupid; $backuprecordid = $DB->get_field('backup_controllers', 'id', array('backupid' => $backupid), MUST_EXIST); mtrace('Processing asynchronous backup for backup: ' . $backupid); // Get the backup controller by backup id. $bc = \backup_controller::load_controller($backupid); $bc->set_progress(new \core\progress\db_updater($backuprecordid, 'backup_controllers', 'progress')); // Do some preflight checks on the backup. $status = $bc->get_status(); $execution = $bc->get_execution(); // Check that the backup is in the correct status and // that is set for asynchronous execution. if ($status == \backup::STATUS_AWAITING && $execution == \backup::EXECUTION_DELAYED) { // Execute the backup. $bc->execute_plan(); // Send message to user if enabled. $messageenabled = (bool)get_config('backup', 'backup_async_message_users'); if ($messageenabled && $bc->get_status() == \backup::STATUS_FINISHED_OK) { $asynchelper = new async_helper('backup', $backupid); $asynchelper->send_message(); } } else { // If status isn't 700, it means the process has failed. // Retrying isn't going to fix it, so marked operation as failed. $bc->set_status(\backup::STATUS_FINISHED_ERR); mtrace('Bad backup controller status, is: ' . $status . ' should be 700, marking job as failed.'); } // Cleanup. $bc->destroy(); $duration = time() - $started; mtrace('Backup completed in: ' . $duration . ' seconds'); }
[ "public", "function", "execute", "(", ")", "{", "global", "$", "DB", ";", "$", "started", "=", "time", "(", ")", ";", "$", "backupid", "=", "$", "this", "->", "get_custom_data", "(", ")", "->", "backupid", ";", "$", "backuprecordid", "=", "$", "DB", "->", "get_field", "(", "'backup_controllers'", ",", "'id'", ",", "array", "(", "'backupid'", "=>", "$", "backupid", ")", ",", "MUST_EXIST", ")", ";", "mtrace", "(", "'Processing asynchronous backup for backup: '", ".", "$", "backupid", ")", ";", "// Get the backup controller by backup id.", "$", "bc", "=", "\\", "backup_controller", "::", "load_controller", "(", "$", "backupid", ")", ";", "$", "bc", "->", "set_progress", "(", "new", "\\", "core", "\\", "progress", "\\", "db_updater", "(", "$", "backuprecordid", ",", "'backup_controllers'", ",", "'progress'", ")", ")", ";", "// Do some preflight checks on the backup.", "$", "status", "=", "$", "bc", "->", "get_status", "(", ")", ";", "$", "execution", "=", "$", "bc", "->", "get_execution", "(", ")", ";", "// Check that the backup is in the correct status and", "// that is set for asynchronous execution.", "if", "(", "$", "status", "==", "\\", "backup", "::", "STATUS_AWAITING", "&&", "$", "execution", "==", "\\", "backup", "::", "EXECUTION_DELAYED", ")", "{", "// Execute the backup.", "$", "bc", "->", "execute_plan", "(", ")", ";", "// Send message to user if enabled.", "$", "messageenabled", "=", "(", "bool", ")", "get_config", "(", "'backup'", ",", "'backup_async_message_users'", ")", ";", "if", "(", "$", "messageenabled", "&&", "$", "bc", "->", "get_status", "(", ")", "==", "\\", "backup", "::", "STATUS_FINISHED_OK", ")", "{", "$", "asynchelper", "=", "new", "async_helper", "(", "'backup'", ",", "$", "backupid", ")", ";", "$", "asynchelper", "->", "send_message", "(", ")", ";", "}", "}", "else", "{", "// If status isn't 700, it means the process has failed.", "// Retrying isn't going to fix it, so marked operation as failed.", "$", "bc", "->", "set_status", "(", "\\", "backup", "::", "STATUS_FINISHED_ERR", ")", ";", "mtrace", "(", "'Bad backup controller status, is: '", ".", "$", "status", ".", "' should be 700, marking job as failed.'", ")", ";", "}", "// Cleanup.", "$", "bc", "->", "destroy", "(", ")", ";", "$", "duration", "=", "time", "(", ")", "-", "$", "started", ";", "mtrace", "(", "'Backup completed in: '", ".", "$", "duration", ".", "' seconds'", ")", ";", "}" ]
Run the adhoc task and preform the backup.
[ "Run", "the", "adhoc", "task", "and", "preform", "the", "backup", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/asynchronous_backup_task.php#L46-L88
215,924
moodle/moodle
lib/horde/framework/Horde/Mime/Id.php
Horde_Mime_Id.idArithmetic
public function idArithmetic($action, array $options = array()) { return $this->_idArithmetic($this->id, $action, array_merge(array( 'count' => 1 ), $options)); }
php
public function idArithmetic($action, array $options = array()) { return $this->_idArithmetic($this->id, $action, array_merge(array( 'count' => 1 ), $options)); }
[ "public", "function", "idArithmetic", "(", "$", "action", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "_idArithmetic", "(", "$", "this", "->", "id", ",", "$", "action", ",", "array_merge", "(", "array", "(", "'count'", "=>", "1", ")", ",", "$", "options", ")", ")", ";", "}" ]
Performs MIME ID "arithmetic". @param string $action One of: - ID_DOWN: ID of child. Note: ID_DOWN will first traverse to "$id.0" if given an ID *NOT* of the form "$id.0". If given an ID of the form "$id.0", ID_DOWN will traverse to "$id.1". This behavior can be avoided if 'no_rfc822' option is set. - ID_NEXT: ID of next sibling. - ID_PREV: ID of previous sibling. - ID_UP: ID of parent. Note: ID_UP will first traverse to "$id.0" if given an ID *NOT* of the form "$id.0". If given an ID of the form "$id.0", ID_UP will traverse to "$id". This behavior can be avoided if 'no_rfc822' option is set. @param array $options Additional options: - count: (integer) How many levels to traverse. DEFAULT: 1 - no_rfc822: (boolean) Don't traverse RFC 822 sub-levels. DEFAULT: false @return mixed The resulting ID string, or null if that ID can not exist.
[ "Performs", "MIME", "ID", "arithmetic", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Id.php#L79-L84
215,925
moodle/moodle
lib/horde/framework/Horde/Mime/Id.php
Horde_Mime_Id.isChild
public function isChild($id) { $base = (substr($this->id, -2) == '.0') ? substr($this->id, 0, -1) : rtrim($this->id, '.') . '.'; return ((($base == 0) && ($id != 0)) || (strpos(strval($id), strval($base)) === 0)); }
php
public function isChild($id) { $base = (substr($this->id, -2) == '.0') ? substr($this->id, 0, -1) : rtrim($this->id, '.') . '.'; return ((($base == 0) && ($id != 0)) || (strpos(strval($id), strval($base)) === 0)); }
[ "public", "function", "isChild", "(", "$", "id", ")", "{", "$", "base", "=", "(", "substr", "(", "$", "this", "->", "id", ",", "-", "2", ")", "==", "'.0'", ")", "?", "substr", "(", "$", "this", "->", "id", ",", "0", ",", "-", "1", ")", ":", "rtrim", "(", "$", "this", "->", "id", ",", "'.'", ")", ".", "'.'", ";", "return", "(", "(", "(", "$", "base", "==", "0", ")", "&&", "(", "$", "id", "!=", "0", ")", ")", "||", "(", "strpos", "(", "strval", "(", "$", "id", ")", ",", "strval", "(", "$", "base", ")", ")", "===", "0", ")", ")", ";", "}" ]
Determines if a given MIME ID lives underneath a base ID. @param string $id The MIME ID to query. @return boolean Whether $id lives under the base ID ($this->id).
[ "Determines", "if", "a", "given", "MIME", "ID", "lives", "underneath", "a", "base", "ID", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Id.php#L142-L150
215,926
moodle/moodle
lib/horde/framework/Horde/Mime/Headers.php
Horde_Mime_Headers.toArray
public function toArray(array $opts = array()) { $charset = array_key_exists('charset', $opts) ? (empty($opts['charset']) ? 'UTF-8' : $opts['charset']) : null; $eol = empty($opts['canonical']) ? $this->_eol : "\r\n"; $ret = array(); foreach ($this->_headers as $ob) { $sopts = array( 'charset' => $charset ); if (($ob instanceof Horde_Mime_Headers_Addresses) || ($ob instanceof Horde_Mime_Headers_AddressesMulti)) { if (!empty($opts['defserver'])) { $sopts['defserver'] = $opts['defserver']; } } elseif ($ob instanceof Horde_Mime_Headers_ContentParam) { $sopts['broken_rfc2231'] = !empty($opts['broken_rfc2231']); if (!empty($opts['lang'])) { $sopts['lang'] = $opts['lang']; } } $tmp = array(); foreach ($ob->sendEncode(array_filter($sopts)) as $val) { if (empty($opts['nowrap'])) { /* Remove any existing linebreaks and wrap the line. */ $htext = $ob->name . ': '; $val = ltrim( substr( wordwrap( $htext . strtr(trim($val), array("\r" => '', "\n" => '')), 76, $eol . ' ' ), strlen($htext) ) ); } $tmp[] = $val; } $ret[$ob->name] = (count($tmp) == 1) ? reset($tmp) : $tmp; } return $ret; }
php
public function toArray(array $opts = array()) { $charset = array_key_exists('charset', $opts) ? (empty($opts['charset']) ? 'UTF-8' : $opts['charset']) : null; $eol = empty($opts['canonical']) ? $this->_eol : "\r\n"; $ret = array(); foreach ($this->_headers as $ob) { $sopts = array( 'charset' => $charset ); if (($ob instanceof Horde_Mime_Headers_Addresses) || ($ob instanceof Horde_Mime_Headers_AddressesMulti)) { if (!empty($opts['defserver'])) { $sopts['defserver'] = $opts['defserver']; } } elseif ($ob instanceof Horde_Mime_Headers_ContentParam) { $sopts['broken_rfc2231'] = !empty($opts['broken_rfc2231']); if (!empty($opts['lang'])) { $sopts['lang'] = $opts['lang']; } } $tmp = array(); foreach ($ob->sendEncode(array_filter($sopts)) as $val) { if (empty($opts['nowrap'])) { /* Remove any existing linebreaks and wrap the line. */ $htext = $ob->name . ': '; $val = ltrim( substr( wordwrap( $htext . strtr(trim($val), array("\r" => '', "\n" => '')), 76, $eol . ' ' ), strlen($htext) ) ); } $tmp[] = $val; } $ret[$ob->name] = (count($tmp) == 1) ? reset($tmp) : $tmp; } return $ret; }
[ "public", "function", "toArray", "(", "array", "$", "opts", "=", "array", "(", ")", ")", "{", "$", "charset", "=", "array_key_exists", "(", "'charset'", ",", "$", "opts", ")", "?", "(", "empty", "(", "$", "opts", "[", "'charset'", "]", ")", "?", "'UTF-8'", ":", "$", "opts", "[", "'charset'", "]", ")", ":", "null", ";", "$", "eol", "=", "empty", "(", "$", "opts", "[", "'canonical'", "]", ")", "?", "$", "this", "->", "_eol", ":", "\"\\r\\n\"", ";", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "_headers", "as", "$", "ob", ")", "{", "$", "sopts", "=", "array", "(", "'charset'", "=>", "$", "charset", ")", ";", "if", "(", "(", "$", "ob", "instanceof", "Horde_Mime_Headers_Addresses", ")", "||", "(", "$", "ob", "instanceof", "Horde_Mime_Headers_AddressesMulti", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "opts", "[", "'defserver'", "]", ")", ")", "{", "$", "sopts", "[", "'defserver'", "]", "=", "$", "opts", "[", "'defserver'", "]", ";", "}", "}", "elseif", "(", "$", "ob", "instanceof", "Horde_Mime_Headers_ContentParam", ")", "{", "$", "sopts", "[", "'broken_rfc2231'", "]", "=", "!", "empty", "(", "$", "opts", "[", "'broken_rfc2231'", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "opts", "[", "'lang'", "]", ")", ")", "{", "$", "sopts", "[", "'lang'", "]", "=", "$", "opts", "[", "'lang'", "]", ";", "}", "}", "$", "tmp", "=", "array", "(", ")", ";", "foreach", "(", "$", "ob", "->", "sendEncode", "(", "array_filter", "(", "$", "sopts", ")", ")", "as", "$", "val", ")", "{", "if", "(", "empty", "(", "$", "opts", "[", "'nowrap'", "]", ")", ")", "{", "/* Remove any existing linebreaks and wrap the line. */", "$", "htext", "=", "$", "ob", "->", "name", ".", "': '", ";", "$", "val", "=", "ltrim", "(", "substr", "(", "wordwrap", "(", "$", "htext", ".", "strtr", "(", "trim", "(", "$", "val", ")", ",", "array", "(", "\"\\r\"", "=>", "''", ",", "\"\\n\"", "=>", "''", ")", ")", ",", "76", ",", "$", "eol", ".", "' '", ")", ",", "strlen", "(", "$", "htext", ")", ")", ")", ";", "}", "$", "tmp", "[", "]", "=", "$", "val", ";", "}", "$", "ret", "[", "$", "ob", "->", "name", "]", "=", "(", "count", "(", "$", "tmp", ")", "==", "1", ")", "?", "reset", "(", "$", "tmp", ")", ":", "$", "tmp", ";", "}", "return", "$", "ret", ";", "}" ]
Returns the headers in array format. @param array $opts Optional parameters: <pre> - broken_rfc2231: (boolean) Attempt to work around non-RFC 2231-compliant MUAs by generating both a RFC 2047-like parameter name and also the correct RFC 2231 parameter DEFAULT: false - canonical: (boolean) Use canonical (RFC 822/2045) CRLF EOLs? DEFAULT: Uses "\n" - charset: (string) Encodes the headers using this charset. If empty, encodes using UTF-8. DEFAULT: No encoding. - defserver: (string) The default domain to append to mailboxes. DEFAULT: No default name. - lang: (string) The language to use when encoding. DEFAULT: None specified - nowrap: (integer) Don't wrap the headers. DEFAULT: Headers are wrapped. </pre> @return array The headers in array format. Keys are header names, but case sensitivity cannot be guaranteed. Values are header values.
[ "Returns", "the", "headers", "in", "array", "format", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Headers.php#L103-L157
215,927
moodle/moodle
lib/horde/framework/Horde/Mime/Headers.php
Horde_Mime_Headers.toString
public function toString(array $opts = array()) { $eol = empty($opts['canonical']) ? $this->_eol : "\r\n"; $text = ''; foreach ($this->toArray($opts) as $key => $val) { foreach ((is_array($val) ? $val : array($val)) as $entry) { $text .= $key . ': ' . $entry . $eol; } } return $text . $eol; }
php
public function toString(array $opts = array()) { $eol = empty($opts['canonical']) ? $this->_eol : "\r\n"; $text = ''; foreach ($this->toArray($opts) as $key => $val) { foreach ((is_array($val) ? $val : array($val)) as $entry) { $text .= $key . ': ' . $entry . $eol; } } return $text . $eol; }
[ "public", "function", "toString", "(", "array", "$", "opts", "=", "array", "(", ")", ")", "{", "$", "eol", "=", "empty", "(", "$", "opts", "[", "'canonical'", "]", ")", "?", "$", "this", "->", "_eol", ":", "\"\\r\\n\"", ";", "$", "text", "=", "''", ";", "foreach", "(", "$", "this", "->", "toArray", "(", "$", "opts", ")", "as", "$", "key", "=>", "$", "val", ")", "{", "foreach", "(", "(", "is_array", "(", "$", "val", ")", "?", "$", "val", ":", "array", "(", "$", "val", ")", ")", "as", "$", "entry", ")", "{", "$", "text", ".=", "$", "key", ".", "': '", ".", "$", "entry", ".", "$", "eol", ";", "}", "}", "return", "$", "text", ".", "$", "eol", ";", "}" ]
Returns all headers concatenated into a single string. @param array $opts See toArray(). @return string The headers in string format.
[ "Returns", "all", "headers", "concatenated", "into", "a", "single", "string", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Headers.php#L166-L180
215,928
moodle/moodle
lib/horde/framework/Horde/Mime/Headers.php
Horde_Mime_Headers.addHeaderOb
public function addHeaderOb(Horde_Mime_Headers_Element $ob, $check = false) { if ($check) { $cname = $this->_getHeaderClassName($ob->name); if (!($ob instanceof $cname)) { throw new InvalidArgumentException(sprintf( 'Object is not correct class: %s', $cname )); } } /* Existing header? Add to that object. */ if ($hdr = $this[$ob->name]) { $hdr->setValue($ob); } else { $this->_headers[$ob->name] = $ob; } }
php
public function addHeaderOb(Horde_Mime_Headers_Element $ob, $check = false) { if ($check) { $cname = $this->_getHeaderClassName($ob->name); if (!($ob instanceof $cname)) { throw new InvalidArgumentException(sprintf( 'Object is not correct class: %s', $cname )); } } /* Existing header? Add to that object. */ if ($hdr = $this[$ob->name]) { $hdr->setValue($ob); } else { $this->_headers[$ob->name] = $ob; } }
[ "public", "function", "addHeaderOb", "(", "Horde_Mime_Headers_Element", "$", "ob", ",", "$", "check", "=", "false", ")", "{", "if", "(", "$", "check", ")", "{", "$", "cname", "=", "$", "this", "->", "_getHeaderClassName", "(", "$", "ob", "->", "name", ")", ";", "if", "(", "!", "(", "$", "ob", "instanceof", "$", "cname", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Object is not correct class: %s'", ",", "$", "cname", ")", ")", ";", "}", "}", "/* Existing header? Add to that object. */", "if", "(", "$", "hdr", "=", "$", "this", "[", "$", "ob", "->", "name", "]", ")", "{", "$", "hdr", "->", "setValue", "(", "$", "ob", ")", ";", "}", "else", "{", "$", "this", "->", "_headers", "[", "$", "ob", "->", "name", "]", "=", "$", "ob", ";", "}", "}" ]
Add a Horde_Mime_Headers_Element object to the current header list. @since 2.5.0 @param Horde_Mime_Headers_Element $ob Header object to add. @param boolean $check Check that the header and object type match? @throws InvalidArgumentException
[ "Add", "a", "Horde_Mime_Headers_Element", "object", "to", "the", "current", "header", "list", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Headers.php#L235-L253
215,929
moodle/moodle
lib/horde/framework/Horde/Mime/Headers.php
Horde_Mime_Headers._getHeaderClassName
protected function _getHeaderClassName($header) { if (empty(self::$_handlers)) { $search = array( 'Horde_Mime_Headers_Element_Single', 'Horde_Mime_Headers_AddressesMulti', 'Horde_Mime_Headers_Addresses', 'Horde_Mime_Headers_ContentDescription', 'Horde_Mime_Headers_ContentId', 'Horde_Mime_Headers_ContentLanguage', 'Horde_Mime_Headers_ContentParam_ContentDisposition', 'Horde_Mime_Headers_ContentParam_ContentType', 'Horde_Mime_Headers_ContentTransferEncoding', 'Horde_Mime_Headers_Date', 'Horde_Mime_Headers_Identification', 'Horde_Mime_Headers_MessageId', 'Horde_Mime_Headers_Mime', 'Horde_Mime_Headers_MimeVersion', 'Horde_Mime_Headers_Received', 'Horde_Mime_Headers_Subject', 'Horde_Mime_Headers_UserAgent' ); foreach ($search as $val) { foreach ($val::getHandles() as $hdr) { self::$_handlers[$hdr] = $val; } } } $header = Horde_String::lower($header); return isset(self::$_handlers[$header]) ? self::$_handlers[$header] : 'Horde_Mime_Headers_Element_Multiple'; }
php
protected function _getHeaderClassName($header) { if (empty(self::$_handlers)) { $search = array( 'Horde_Mime_Headers_Element_Single', 'Horde_Mime_Headers_AddressesMulti', 'Horde_Mime_Headers_Addresses', 'Horde_Mime_Headers_ContentDescription', 'Horde_Mime_Headers_ContentId', 'Horde_Mime_Headers_ContentLanguage', 'Horde_Mime_Headers_ContentParam_ContentDisposition', 'Horde_Mime_Headers_ContentParam_ContentType', 'Horde_Mime_Headers_ContentTransferEncoding', 'Horde_Mime_Headers_Date', 'Horde_Mime_Headers_Identification', 'Horde_Mime_Headers_MessageId', 'Horde_Mime_Headers_Mime', 'Horde_Mime_Headers_MimeVersion', 'Horde_Mime_Headers_Received', 'Horde_Mime_Headers_Subject', 'Horde_Mime_Headers_UserAgent' ); foreach ($search as $val) { foreach ($val::getHandles() as $hdr) { self::$_handlers[$hdr] = $val; } } } $header = Horde_String::lower($header); return isset(self::$_handlers[$header]) ? self::$_handlers[$header] : 'Horde_Mime_Headers_Element_Multiple'; }
[ "protected", "function", "_getHeaderClassName", "(", "$", "header", ")", "{", "if", "(", "empty", "(", "self", "::", "$", "_handlers", ")", ")", "{", "$", "search", "=", "array", "(", "'Horde_Mime_Headers_Element_Single'", ",", "'Horde_Mime_Headers_AddressesMulti'", ",", "'Horde_Mime_Headers_Addresses'", ",", "'Horde_Mime_Headers_ContentDescription'", ",", "'Horde_Mime_Headers_ContentId'", ",", "'Horde_Mime_Headers_ContentLanguage'", ",", "'Horde_Mime_Headers_ContentParam_ContentDisposition'", ",", "'Horde_Mime_Headers_ContentParam_ContentType'", ",", "'Horde_Mime_Headers_ContentTransferEncoding'", ",", "'Horde_Mime_Headers_Date'", ",", "'Horde_Mime_Headers_Identification'", ",", "'Horde_Mime_Headers_MessageId'", ",", "'Horde_Mime_Headers_Mime'", ",", "'Horde_Mime_Headers_MimeVersion'", ",", "'Horde_Mime_Headers_Received'", ",", "'Horde_Mime_Headers_Subject'", ",", "'Horde_Mime_Headers_UserAgent'", ")", ";", "foreach", "(", "$", "search", "as", "$", "val", ")", "{", "foreach", "(", "$", "val", "::", "getHandles", "(", ")", "as", "$", "hdr", ")", "{", "self", "::", "$", "_handlers", "[", "$", "hdr", "]", "=", "$", "val", ";", "}", "}", "}", "$", "header", "=", "Horde_String", "::", "lower", "(", "$", "header", ")", ";", "return", "isset", "(", "self", "::", "$", "_handlers", "[", "$", "header", "]", ")", "?", "self", "::", "$", "_handlers", "[", "$", "header", "]", ":", "'Horde_Mime_Headers_Element_Multiple'", ";", "}" ]
Return the header class to use for a header name. @param string $header The header name. @return string The Horde_Mime_Headers_* class to use.
[ "Return", "the", "header", "class", "to", "use", "for", "a", "header", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Headers.php#L262-L297
215,930
moodle/moodle
lib/horde/framework/Horde/Mime/Headers.php
Horde_Mime_Headers.parseHeaders
public static function parseHeaders($text) { $curr = null; $headers = new Horde_Mime_Headers(); $hdr_list = array(); if ($text instanceof Horde_Stream) { $stream = $text; $stream->rewind(); } else { $stream = new Horde_Stream_Temp(); $stream->add($text, true); } while (!$stream->eof()) { if (!($val = rtrim($stream->getToChar("\n", false), "\r"))) { break; } if ($curr && (($val[0] == ' ') || ($val[0] == "\t"))) { $curr->text .= ' ' . ltrim($val); } else { $pos = strpos($val, ':'); $curr = new stdClass; $curr->header = substr($val, 0, $pos); $curr->text = ltrim(substr($val, $pos + 1)); $hdr_list[] = $curr; } } foreach ($hdr_list as $val) { /* When parsing, only keep the FIRST header seen for single value * text-only headers, since newer headers generally are appended * to the top of the message. */ if (!($ob = $headers[$val->header]) || !($ob instanceof Horde_Mime_Headers_Element_Single) || ($ob instanceof Horde_Mime_Headers_Addresses)) { $headers->addHeader($val->header, rtrim($val->text)); } } if (!($text instanceof Horde_Stream)) { $stream->close(); } return $headers; }
php
public static function parseHeaders($text) { $curr = null; $headers = new Horde_Mime_Headers(); $hdr_list = array(); if ($text instanceof Horde_Stream) { $stream = $text; $stream->rewind(); } else { $stream = new Horde_Stream_Temp(); $stream->add($text, true); } while (!$stream->eof()) { if (!($val = rtrim($stream->getToChar("\n", false), "\r"))) { break; } if ($curr && (($val[0] == ' ') || ($val[0] == "\t"))) { $curr->text .= ' ' . ltrim($val); } else { $pos = strpos($val, ':'); $curr = new stdClass; $curr->header = substr($val, 0, $pos); $curr->text = ltrim(substr($val, $pos + 1)); $hdr_list[] = $curr; } } foreach ($hdr_list as $val) { /* When parsing, only keep the FIRST header seen for single value * text-only headers, since newer headers generally are appended * to the top of the message. */ if (!($ob = $headers[$val->header]) || !($ob instanceof Horde_Mime_Headers_Element_Single) || ($ob instanceof Horde_Mime_Headers_Addresses)) { $headers->addHeader($val->header, rtrim($val->text)); } } if (!($text instanceof Horde_Stream)) { $stream->close(); } return $headers; }
[ "public", "static", "function", "parseHeaders", "(", "$", "text", ")", "{", "$", "curr", "=", "null", ";", "$", "headers", "=", "new", "Horde_Mime_Headers", "(", ")", ";", "$", "hdr_list", "=", "array", "(", ")", ";", "if", "(", "$", "text", "instanceof", "Horde_Stream", ")", "{", "$", "stream", "=", "$", "text", ";", "$", "stream", "->", "rewind", "(", ")", ";", "}", "else", "{", "$", "stream", "=", "new", "Horde_Stream_Temp", "(", ")", ";", "$", "stream", "->", "add", "(", "$", "text", ",", "true", ")", ";", "}", "while", "(", "!", "$", "stream", "->", "eof", "(", ")", ")", "{", "if", "(", "!", "(", "$", "val", "=", "rtrim", "(", "$", "stream", "->", "getToChar", "(", "\"\\n\"", ",", "false", ")", ",", "\"\\r\"", ")", ")", ")", "{", "break", ";", "}", "if", "(", "$", "curr", "&&", "(", "(", "$", "val", "[", "0", "]", "==", "' '", ")", "||", "(", "$", "val", "[", "0", "]", "==", "\"\\t\"", ")", ")", ")", "{", "$", "curr", "->", "text", ".=", "' '", ".", "ltrim", "(", "$", "val", ")", ";", "}", "else", "{", "$", "pos", "=", "strpos", "(", "$", "val", ",", "':'", ")", ";", "$", "curr", "=", "new", "stdClass", ";", "$", "curr", "->", "header", "=", "substr", "(", "$", "val", ",", "0", ",", "$", "pos", ")", ";", "$", "curr", "->", "text", "=", "ltrim", "(", "substr", "(", "$", "val", ",", "$", "pos", "+", "1", ")", ")", ";", "$", "hdr_list", "[", "]", "=", "$", "curr", ";", "}", "}", "foreach", "(", "$", "hdr_list", "as", "$", "val", ")", "{", "/* When parsing, only keep the FIRST header seen for single value\n * text-only headers, since newer headers generally are appended\n * to the top of the message. */", "if", "(", "!", "(", "$", "ob", "=", "$", "headers", "[", "$", "val", "->", "header", "]", ")", "||", "!", "(", "$", "ob", "instanceof", "Horde_Mime_Headers_Element_Single", ")", "||", "(", "$", "ob", "instanceof", "Horde_Mime_Headers_Addresses", ")", ")", "{", "$", "headers", "->", "addHeader", "(", "$", "val", "->", "header", ",", "rtrim", "(", "$", "val", "->", "text", ")", ")", ";", "}", "}", "if", "(", "!", "(", "$", "text", "instanceof", "Horde_Stream", ")", ")", "{", "$", "stream", "->", "close", "(", ")", ";", "}", "return", "$", "headers", ";", "}" ]
Builds a Horde_Mime_Headers object from header text. @param mixed $text A text string (or, as of 2.3.0, a Horde_Stream object or stream resource) containing the headers. @return Horde_Mime_Headers A new Horde_Mime_Headers object.
[ "Builds", "a", "Horde_Mime_Headers", "object", "from", "header", "text", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Headers.php#L332-L380
215,931
moodle/moodle
lib/classes/event/question_category_base.php
question_category_base.create_from_question_category_instance
public static function create_from_question_category_instance($category, $context = null) { $params = ['objectid' => $category->id]; if (!empty($category->contextid)) { $params['contextid'] = $category->contextid; } $params['context'] = $context; $event = self::create($params); return $event; }
php
public static function create_from_question_category_instance($category, $context = null) { $params = ['objectid' => $category->id]; if (!empty($category->contextid)) { $params['contextid'] = $category->contextid; } $params['context'] = $context; $event = self::create($params); return $event; }
[ "public", "static", "function", "create_from_question_category_instance", "(", "$", "category", ",", "$", "context", "=", "null", ")", "{", "$", "params", "=", "[", "'objectid'", "=>", "$", "category", "->", "id", "]", ";", "if", "(", "!", "empty", "(", "$", "category", "->", "contextid", ")", ")", "{", "$", "params", "[", "'contextid'", "]", "=", "$", "category", "->", "contextid", ";", "}", "$", "params", "[", "'context'", "]", "=", "$", "context", ";", "$", "event", "=", "self", "::", "create", "(", "$", "params", ")", ";", "return", "$", "event", ";", "}" ]
Create a event from question category object @param object $category @param object|null $context @return base @throws \coding_exception
[ "Create", "a", "event", "from", "question", "category", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/question_category_base.php#L81-L93
215,932
moodle/moodle
enrol/flatfile/lib.php
enrol_flatfile_plugin.sync
public function sync(progress_trace $trace) { if (!enrol_is_enabled('flatfile')) { return 2; } $mailadmins = $this->get_config('mailadmins', 0); if ($mailadmins) { $buffer = new progress_trace_buffer(new text_progress_trace(), false); $trace = new combined_progress_trace(array($trace, $buffer)); } $processed = false; $processed = $this->process_file($trace) || $processed; $processed = $this->process_buffer($trace) || $processed; $processed = $this->process_expirations($trace) || $processed; if ($processed and $mailadmins) { if ($log = $buffer->get_buffer()) { $eventdata = new \core\message\message(); $eventdata->courseid = SITEID; $eventdata->modulename = 'moodle'; $eventdata->component = 'enrol_flatfile'; $eventdata->name = 'flatfile_enrolment'; $eventdata->userfrom = get_admin(); $eventdata->userto = get_admin(); $eventdata->subject = 'Flatfile Enrolment Log'; $eventdata->fullmessage = $log; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; message_send($eventdata); } $buffer->reset_buffer(); } return 0; }
php
public function sync(progress_trace $trace) { if (!enrol_is_enabled('flatfile')) { return 2; } $mailadmins = $this->get_config('mailadmins', 0); if ($mailadmins) { $buffer = new progress_trace_buffer(new text_progress_trace(), false); $trace = new combined_progress_trace(array($trace, $buffer)); } $processed = false; $processed = $this->process_file($trace) || $processed; $processed = $this->process_buffer($trace) || $processed; $processed = $this->process_expirations($trace) || $processed; if ($processed and $mailadmins) { if ($log = $buffer->get_buffer()) { $eventdata = new \core\message\message(); $eventdata->courseid = SITEID; $eventdata->modulename = 'moodle'; $eventdata->component = 'enrol_flatfile'; $eventdata->name = 'flatfile_enrolment'; $eventdata->userfrom = get_admin(); $eventdata->userto = get_admin(); $eventdata->subject = 'Flatfile Enrolment Log'; $eventdata->fullmessage = $log; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; message_send($eventdata); } $buffer->reset_buffer(); } return 0; }
[ "public", "function", "sync", "(", "progress_trace", "$", "trace", ")", "{", "if", "(", "!", "enrol_is_enabled", "(", "'flatfile'", ")", ")", "{", "return", "2", ";", "}", "$", "mailadmins", "=", "$", "this", "->", "get_config", "(", "'mailadmins'", ",", "0", ")", ";", "if", "(", "$", "mailadmins", ")", "{", "$", "buffer", "=", "new", "progress_trace_buffer", "(", "new", "text_progress_trace", "(", ")", ",", "false", ")", ";", "$", "trace", "=", "new", "combined_progress_trace", "(", "array", "(", "$", "trace", ",", "$", "buffer", ")", ")", ";", "}", "$", "processed", "=", "false", ";", "$", "processed", "=", "$", "this", "->", "process_file", "(", "$", "trace", ")", "||", "$", "processed", ";", "$", "processed", "=", "$", "this", "->", "process_buffer", "(", "$", "trace", ")", "||", "$", "processed", ";", "$", "processed", "=", "$", "this", "->", "process_expirations", "(", "$", "trace", ")", "||", "$", "processed", ";", "if", "(", "$", "processed", "and", "$", "mailadmins", ")", "{", "if", "(", "$", "log", "=", "$", "buffer", "->", "get_buffer", "(", ")", ")", "{", "$", "eventdata", "=", "new", "\\", "core", "\\", "message", "\\", "message", "(", ")", ";", "$", "eventdata", "->", "courseid", "=", "SITEID", ";", "$", "eventdata", "->", "modulename", "=", "'moodle'", ";", "$", "eventdata", "->", "component", "=", "'enrol_flatfile'", ";", "$", "eventdata", "->", "name", "=", "'flatfile_enrolment'", ";", "$", "eventdata", "->", "userfrom", "=", "get_admin", "(", ")", ";", "$", "eventdata", "->", "userto", "=", "get_admin", "(", ")", ";", "$", "eventdata", "->", "subject", "=", "'Flatfile Enrolment Log'", ";", "$", "eventdata", "->", "fullmessage", "=", "$", "log", ";", "$", "eventdata", "->", "fullmessageformat", "=", "FORMAT_PLAIN", ";", "$", "eventdata", "->", "fullmessagehtml", "=", "''", ";", "$", "eventdata", "->", "smallmessage", "=", "''", ";", "message_send", "(", "$", "eventdata", ")", ";", "}", "$", "buffer", "->", "reset_buffer", "(", ")", ";", "}", "return", "0", ";", "}" ]
Execute synchronisation. @param progress_trace @return int exit code, 0 means ok, 2 means plugin disabled
[ "Execute", "synchronisation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/flatfile/lib.php#L145-L183
215,933
moodle/moodle
enrol/flatfile/lib.php
enrol_flatfile_plugin.obfuscate_filepath
protected function obfuscate_filepath($filepath) { global $CFG; if (strpos($filepath, $CFG->dataroot.'/') === 0 or strpos($filepath, $CFG->dataroot.'\\') === 0) { $disclosefile = '$CFG->dataroot'.substr($filepath, strlen($CFG->dataroot)); } else if (strpos($filepath, $CFG->dirroot.'/') === 0 or strpos($filepath, $CFG->dirroot.'\\') === 0) { $disclosefile = '$CFG->dirroot'.substr($filepath, strlen($CFG->dirroot)); } else { $disclosefile = basename($filepath); } return $disclosefile; }
php
protected function obfuscate_filepath($filepath) { global $CFG; if (strpos($filepath, $CFG->dataroot.'/') === 0 or strpos($filepath, $CFG->dataroot.'\\') === 0) { $disclosefile = '$CFG->dataroot'.substr($filepath, strlen($CFG->dataroot)); } else if (strpos($filepath, $CFG->dirroot.'/') === 0 or strpos($filepath, $CFG->dirroot.'\\') === 0) { $disclosefile = '$CFG->dirroot'.substr($filepath, strlen($CFG->dirroot)); } else { $disclosefile = basename($filepath); } return $disclosefile; }
[ "protected", "function", "obfuscate_filepath", "(", "$", "filepath", ")", "{", "global", "$", "CFG", ";", "if", "(", "strpos", "(", "$", "filepath", ",", "$", "CFG", "->", "dataroot", ".", "'/'", ")", "===", "0", "or", "strpos", "(", "$", "filepath", ",", "$", "CFG", "->", "dataroot", ".", "'\\\\'", ")", "===", "0", ")", "{", "$", "disclosefile", "=", "'$CFG->dataroot'", ".", "substr", "(", "$", "filepath", ",", "strlen", "(", "$", "CFG", "->", "dataroot", ")", ")", ";", "}", "else", "if", "(", "strpos", "(", "$", "filepath", ",", "$", "CFG", "->", "dirroot", ".", "'/'", ")", "===", "0", "or", "strpos", "(", "$", "filepath", ",", "$", "CFG", "->", "dirroot", ".", "'\\\\'", ")", "===", "0", ")", "{", "$", "disclosefile", "=", "'$CFG->dirroot'", ".", "substr", "(", "$", "filepath", ",", "strlen", "(", "$", "CFG", "->", "dirroot", ")", ")", ";", "}", "else", "{", "$", "disclosefile", "=", "basename", "(", "$", "filepath", ")", ";", "}", "return", "$", "disclosefile", ";", "}" ]
Sorry, we do not want to show paths in cron output. @param string $filepath @return string
[ "Sorry", "we", "do", "not", "want", "to", "show", "paths", "in", "cron", "output", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/flatfile/lib.php#L191-L205
215,934
moodle/moodle
enrol/flatfile/lib.php
enrol_flatfile_plugin.process_buffer
protected function process_buffer(progress_trace $trace) { global $DB; if (!$future_enrols = $DB->get_records_select('enrol_flatfile', "timestart < ?", array(time()))) { $trace->output("No enrolments to be processed in flatfile buffer"); $trace->finished(); return false; } $trace->output("Starting processing of flatfile buffer"); foreach($future_enrols as $en) { $user = $DB->get_record('user', array('id'=>$en->userid)); $course = $DB->get_record('course', array('id'=>$en->courseid)); if ($user and $course) { $trace->output("buffer: $en->action $en->roleid $user->id $course->id $en->timestart $en->timeend", 1); $this->process_records($trace, $en->action, $en->roleid, $user, $course, $en->timestart, $en->timeend, false); } $DB->delete_records('enrol_flatfile', array('id'=>$en->id)); } $trace->output("Finished processing of flatfile buffer"); $trace->finished(); return true; }
php
protected function process_buffer(progress_trace $trace) { global $DB; if (!$future_enrols = $DB->get_records_select('enrol_flatfile', "timestart < ?", array(time()))) { $trace->output("No enrolments to be processed in flatfile buffer"); $trace->finished(); return false; } $trace->output("Starting processing of flatfile buffer"); foreach($future_enrols as $en) { $user = $DB->get_record('user', array('id'=>$en->userid)); $course = $DB->get_record('course', array('id'=>$en->courseid)); if ($user and $course) { $trace->output("buffer: $en->action $en->roleid $user->id $course->id $en->timestart $en->timeend", 1); $this->process_records($trace, $en->action, $en->roleid, $user, $course, $en->timestart, $en->timeend, false); } $DB->delete_records('enrol_flatfile', array('id'=>$en->id)); } $trace->output("Finished processing of flatfile buffer"); $trace->finished(); return true; }
[ "protected", "function", "process_buffer", "(", "progress_trace", "$", "trace", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "$", "future_enrols", "=", "$", "DB", "->", "get_records_select", "(", "'enrol_flatfile'", ",", "\"timestart < ?\"", ",", "array", "(", "time", "(", ")", ")", ")", ")", "{", "$", "trace", "->", "output", "(", "\"No enrolments to be processed in flatfile buffer\"", ")", ";", "$", "trace", "->", "finished", "(", ")", ";", "return", "false", ";", "}", "$", "trace", "->", "output", "(", "\"Starting processing of flatfile buffer\"", ")", ";", "foreach", "(", "$", "future_enrols", "as", "$", "en", ")", "{", "$", "user", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "en", "->", "userid", ")", ")", ";", "$", "course", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "array", "(", "'id'", "=>", "$", "en", "->", "courseid", ")", ")", ";", "if", "(", "$", "user", "and", "$", "course", ")", "{", "$", "trace", "->", "output", "(", "\"buffer: $en->action $en->roleid $user->id $course->id $en->timestart $en->timeend\"", ",", "1", ")", ";", "$", "this", "->", "process_records", "(", "$", "trace", ",", "$", "en", "->", "action", ",", "$", "en", "->", "roleid", ",", "$", "user", ",", "$", "course", ",", "$", "en", "->", "timestart", ",", "$", "en", "->", "timeend", ",", "false", ")", ";", "}", "$", "DB", "->", "delete_records", "(", "'enrol_flatfile'", ",", "array", "(", "'id'", "=>", "$", "en", "->", "id", ")", ")", ";", "}", "$", "trace", "->", "output", "(", "\"Finished processing of flatfile buffer\"", ")", ";", "$", "trace", "->", "finished", "(", ")", ";", "return", "true", ";", "}" ]
Process any future enrollments stored in the buffer. @param progress_trace $trace @return bool true if any data processed, false if not
[ "Process", "any", "future", "enrollments", "stored", "in", "the", "buffer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/flatfile/lib.php#L349-L372
215,935
moodle/moodle
enrol/flatfile/lib.php
enrol_flatfile_plugin.get_enroller
protected function get_enroller($courseid) { if ($this->lasternollercourseid == $courseid and $this->lasternoller) { return $this->lasternoller; } $context = context_course::instance($courseid); $users = get_enrolled_users($context, 'enrol/flatfile:manage'); if (!$users) { $users = get_enrolled_users($context, 'moodle/role:assign'); } if ($users) { $users = sort_by_roleassignment_authority($users, $context); $this->lasternoller = reset($users); unset($users); } else { $this->lasternoller = get_admin(); } $this->lasternollercourseid == $courseid; return $this->lasternoller; }
php
protected function get_enroller($courseid) { if ($this->lasternollercourseid == $courseid and $this->lasternoller) { return $this->lasternoller; } $context = context_course::instance($courseid); $users = get_enrolled_users($context, 'enrol/flatfile:manage'); if (!$users) { $users = get_enrolled_users($context, 'moodle/role:assign'); } if ($users) { $users = sort_by_roleassignment_authority($users, $context); $this->lasternoller = reset($users); unset($users); } else { $this->lasternoller = get_admin(); } $this->lasternollercourseid == $courseid; return $this->lasternoller; }
[ "protected", "function", "get_enroller", "(", "$", "courseid", ")", "{", "if", "(", "$", "this", "->", "lasternollercourseid", "==", "$", "courseid", "and", "$", "this", "->", "lasternoller", ")", "{", "return", "$", "this", "->", "lasternoller", ";", "}", "$", "context", "=", "context_course", "::", "instance", "(", "$", "courseid", ")", ";", "$", "users", "=", "get_enrolled_users", "(", "$", "context", ",", "'enrol/flatfile:manage'", ")", ";", "if", "(", "!", "$", "users", ")", "{", "$", "users", "=", "get_enrolled_users", "(", "$", "context", ",", "'moodle/role:assign'", ")", ";", "}", "if", "(", "$", "users", ")", "{", "$", "users", "=", "sort_by_roleassignment_authority", "(", "$", "users", ",", "$", "context", ")", ";", "$", "this", "->", "lasternoller", "=", "reset", "(", "$", "users", ")", ";", "unset", "(", "$", "users", ")", ";", "}", "else", "{", "$", "this", "->", "lasternoller", "=", "get_admin", "(", ")", ";", "}", "$", "this", "->", "lasternollercourseid", "==", "$", "courseid", ";", "return", "$", "this", "->", "lasternoller", ";", "}" ]
Returns the user who is responsible for flatfile enrolments in given curse. Usually it is the first editing teacher - the person with "highest authority" as defined by sort_by_roleassignment_authority() having 'enrol/flatfile:manage' or 'moodle/role:assign' capability. @param int $courseid enrolment instance id @return stdClass user record
[ "Returns", "the", "user", "who", "is", "responsible", "for", "flatfile", "enrolments", "in", "given", "curse", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/flatfile/lib.php#L599-L622
215,936
moodle/moodle
enrol/flatfile/lib.php
enrol_flatfile_plugin.get_role_map
protected function get_role_map(progress_trace $trace) { global $DB; // Get all roles. $rolemap = array(); $roles = $DB->get_records('role', null, '', 'id, name, shortname'); foreach ($roles as $id=>$role) { $alias = $this->get_config('map_'.$id, $role->shortname, ''); $alias = trim(core_text::strtolower($alias)); if ($alias === '') { // Either not configured yet or somebody wants to skip these intentionally. continue; } if (isset($rolemap[$alias])) { $trace->output("Duplicate role alias $alias detected!"); } else { $rolemap[$alias] = $id; } } return $rolemap; }
php
protected function get_role_map(progress_trace $trace) { global $DB; // Get all roles. $rolemap = array(); $roles = $DB->get_records('role', null, '', 'id, name, shortname'); foreach ($roles as $id=>$role) { $alias = $this->get_config('map_'.$id, $role->shortname, ''); $alias = trim(core_text::strtolower($alias)); if ($alias === '') { // Either not configured yet or somebody wants to skip these intentionally. continue; } if (isset($rolemap[$alias])) { $trace->output("Duplicate role alias $alias detected!"); } else { $rolemap[$alias] = $id; } } return $rolemap; }
[ "protected", "function", "get_role_map", "(", "progress_trace", "$", "trace", ")", "{", "global", "$", "DB", ";", "// Get all roles.", "$", "rolemap", "=", "array", "(", ")", ";", "$", "roles", "=", "$", "DB", "->", "get_records", "(", "'role'", ",", "null", ",", "''", ",", "'id, name, shortname'", ")", ";", "foreach", "(", "$", "roles", "as", "$", "id", "=>", "$", "role", ")", "{", "$", "alias", "=", "$", "this", "->", "get_config", "(", "'map_'", ".", "$", "id", ",", "$", "role", "->", "shortname", ",", "''", ")", ";", "$", "alias", "=", "trim", "(", "core_text", "::", "strtolower", "(", "$", "alias", ")", ")", ";", "if", "(", "$", "alias", "===", "''", ")", "{", "// Either not configured yet or somebody wants to skip these intentionally.", "continue", ";", "}", "if", "(", "isset", "(", "$", "rolemap", "[", "$", "alias", "]", ")", ")", "{", "$", "trace", "->", "output", "(", "\"Duplicate role alias $alias detected!\"", ")", ";", "}", "else", "{", "$", "rolemap", "[", "$", "alias", "]", "=", "$", "id", ";", "}", "}", "return", "$", "rolemap", ";", "}" ]
Returns a mapping of ims roles to role ids. @param progress_trace $trace @return array imsrolename=>roleid
[ "Returns", "a", "mapping", "of", "ims", "roles", "to", "role", "ids", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/flatfile/lib.php#L630-L651
215,937
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Auth/Scram.php
Horde_Imap_Client_Auth_Scram.getClientFirstMessage
public function getClientFirstMessage() { /* n: client doesn't support channel binding, * <empty>, * n=<user>: SASLprepped username with "," and "=" escaped, * r=<nonce>: Random nonce */ $this->_authmsg = 'n=' . str_replace( array(',', '='), array('=2C', '=3D'), $this->_user ) . ',r=' . $this->_nonce; return 'n,,' . $this->_authmsg; }
php
public function getClientFirstMessage() { /* n: client doesn't support channel binding, * <empty>, * n=<user>: SASLprepped username with "," and "=" escaped, * r=<nonce>: Random nonce */ $this->_authmsg = 'n=' . str_replace( array(',', '='), array('=2C', '=3D'), $this->_user ) . ',r=' . $this->_nonce; return 'n,,' . $this->_authmsg; }
[ "public", "function", "getClientFirstMessage", "(", ")", "{", "/* n: client doesn't support channel binding,\n * <empty>,\n * n=<user>: SASLprepped username with \",\" and \"=\" escaped,\n * r=<nonce>: Random nonce */", "$", "this", "->", "_authmsg", "=", "'n='", ".", "str_replace", "(", "array", "(", "','", ",", "'='", ")", ",", "array", "(", "'=2C'", ",", "'=3D'", ")", ",", "$", "this", "->", "_user", ")", ".", "',r='", ".", "$", "this", "->", "_nonce", ";", "return", "'n,,'", ".", "$", "this", "->", "_authmsg", ";", "}" ]
Return the initial client message. @return string Initial client message.
[ "Return", "the", "initial", "client", "message", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Auth/Scram.php#L139-L152
215,938
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Auth/Scram.php
Horde_Imap_Client_Auth_Scram.parseServerFirstMessage
public function parseServerFirstMessage($msg) { $i = $r = $s = false; foreach (explode(',', $msg) as $val) { list($attr, $aval) = array_map('trim', explode('=', $val, 2)); switch ($attr) { case 'i': $this->_iterations = intval($aval); $i = true; break; case 'r': /* Beginning of server-provided nonce MUST be the same as the * nonce we provided. */ if (strpos($aval, $this->_nonce) !== 0) { return false; } $this->_nonce = $aval; $r = true; break; case 's': $this->_salt = base64_decode($aval); $s = true; break; } } if ($i && $r && $s) { $this->_authmsg .= ',' . $msg; return true; } return false; }
php
public function parseServerFirstMessage($msg) { $i = $r = $s = false; foreach (explode(',', $msg) as $val) { list($attr, $aval) = array_map('trim', explode('=', $val, 2)); switch ($attr) { case 'i': $this->_iterations = intval($aval); $i = true; break; case 'r': /* Beginning of server-provided nonce MUST be the same as the * nonce we provided. */ if (strpos($aval, $this->_nonce) !== 0) { return false; } $this->_nonce = $aval; $r = true; break; case 's': $this->_salt = base64_decode($aval); $s = true; break; } } if ($i && $r && $s) { $this->_authmsg .= ',' . $msg; return true; } return false; }
[ "public", "function", "parseServerFirstMessage", "(", "$", "msg", ")", "{", "$", "i", "=", "$", "r", "=", "$", "s", "=", "false", ";", "foreach", "(", "explode", "(", "','", ",", "$", "msg", ")", "as", "$", "val", ")", "{", "list", "(", "$", "attr", ",", "$", "aval", ")", "=", "array_map", "(", "'trim'", ",", "explode", "(", "'='", ",", "$", "val", ",", "2", ")", ")", ";", "switch", "(", "$", "attr", ")", "{", "case", "'i'", ":", "$", "this", "->", "_iterations", "=", "intval", "(", "$", "aval", ")", ";", "$", "i", "=", "true", ";", "break", ";", "case", "'r'", ":", "/* Beginning of server-provided nonce MUST be the same as the\n * nonce we provided. */", "if", "(", "strpos", "(", "$", "aval", ",", "$", "this", "->", "_nonce", ")", "!==", "0", ")", "{", "return", "false", ";", "}", "$", "this", "->", "_nonce", "=", "$", "aval", ";", "$", "r", "=", "true", ";", "break", ";", "case", "'s'", ":", "$", "this", "->", "_salt", "=", "base64_decode", "(", "$", "aval", ")", ";", "$", "s", "=", "true", ";", "break", ";", "}", "}", "if", "(", "$", "i", "&&", "$", "r", "&&", "$", "s", ")", "{", "$", "this", "->", "_authmsg", ".=", "','", ".", "$", "msg", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Process the initial server message response. @param string $msg Initial server response. @return boolean False if authentication failed at this stage.
[ "Process", "the", "initial", "server", "message", "response", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Auth/Scram.php#L161-L197
215,939
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Auth/Scram.php
Horde_Imap_Client_Auth_Scram.getClientFinalMessage
public function getClientFinalMessage() { $final_msg = 'c=biws,r=' . $this->_nonce; /* Salted password. */ $s_pass = strval(new Horde_Crypt_Blowfish_Pbkdf2( $this->_pass, strlen(hash($this->_hash, '', true)), array( 'algo' => $this->_hash, 'i_count' => $this->_iterations, 'salt' => $this->_salt ) )); /* Client key. */ $c_key = hash_hmac($this->_hash, 'Client Key', $s_pass, true); /* Stored key. */ $s_key = hash($this->_hash, $c_key, true); /* Client signature. */ $auth_msg = $this->_authmsg . ',' . $final_msg; $c_sig = hash_hmac($this->_hash, $auth_msg, $s_key, true); /* Proof. */ $proof = $c_key ^ $c_sig; /* Server signature. */ $this->_serversig = hash_hmac( $this->_hash, $auth_msg, hash_hmac($this->_hash, 'Server Key', $s_pass, true), true ); /* c=biws: channel-binding ("biws" = base64('n,,')), * p=<proof>: base64 encoded ClientProof, * r=<nonce>: Nonce as returned from the server. */ return $final_msg . ',p=' . base64_encode($proof); }
php
public function getClientFinalMessage() { $final_msg = 'c=biws,r=' . $this->_nonce; /* Salted password. */ $s_pass = strval(new Horde_Crypt_Blowfish_Pbkdf2( $this->_pass, strlen(hash($this->_hash, '', true)), array( 'algo' => $this->_hash, 'i_count' => $this->_iterations, 'salt' => $this->_salt ) )); /* Client key. */ $c_key = hash_hmac($this->_hash, 'Client Key', $s_pass, true); /* Stored key. */ $s_key = hash($this->_hash, $c_key, true); /* Client signature. */ $auth_msg = $this->_authmsg . ',' . $final_msg; $c_sig = hash_hmac($this->_hash, $auth_msg, $s_key, true); /* Proof. */ $proof = $c_key ^ $c_sig; /* Server signature. */ $this->_serversig = hash_hmac( $this->_hash, $auth_msg, hash_hmac($this->_hash, 'Server Key', $s_pass, true), true ); /* c=biws: channel-binding ("biws" = base64('n,,')), * p=<proof>: base64 encoded ClientProof, * r=<nonce>: Nonce as returned from the server. */ return $final_msg . ',p=' . base64_encode($proof); }
[ "public", "function", "getClientFinalMessage", "(", ")", "{", "$", "final_msg", "=", "'c=biws,r='", ".", "$", "this", "->", "_nonce", ";", "/* Salted password. */", "$", "s_pass", "=", "strval", "(", "new", "Horde_Crypt_Blowfish_Pbkdf2", "(", "$", "this", "->", "_pass", ",", "strlen", "(", "hash", "(", "$", "this", "->", "_hash", ",", "''", ",", "true", ")", ")", ",", "array", "(", "'algo'", "=>", "$", "this", "->", "_hash", ",", "'i_count'", "=>", "$", "this", "->", "_iterations", ",", "'salt'", "=>", "$", "this", "->", "_salt", ")", ")", ")", ";", "/* Client key. */", "$", "c_key", "=", "hash_hmac", "(", "$", "this", "->", "_hash", ",", "'Client Key'", ",", "$", "s_pass", ",", "true", ")", ";", "/* Stored key. */", "$", "s_key", "=", "hash", "(", "$", "this", "->", "_hash", ",", "$", "c_key", ",", "true", ")", ";", "/* Client signature. */", "$", "auth_msg", "=", "$", "this", "->", "_authmsg", ".", "','", ".", "$", "final_msg", ";", "$", "c_sig", "=", "hash_hmac", "(", "$", "this", "->", "_hash", ",", "$", "auth_msg", ",", "$", "s_key", ",", "true", ")", ";", "/* Proof. */", "$", "proof", "=", "$", "c_key", "^", "$", "c_sig", ";", "/* Server signature. */", "$", "this", "->", "_serversig", "=", "hash_hmac", "(", "$", "this", "->", "_hash", ",", "$", "auth_msg", ",", "hash_hmac", "(", "$", "this", "->", "_hash", ",", "'Server Key'", ",", "$", "s_pass", ",", "true", ")", ",", "true", ")", ";", "/* c=biws: channel-binding (\"biws\" = base64('n,,')),\n * p=<proof>: base64 encoded ClientProof,\n * r=<nonce>: Nonce as returned from the server. */", "return", "$", "final_msg", ".", "',p='", ".", "base64_encode", "(", "$", "proof", ")", ";", "}" ]
Return the final client message. @return string Final client message.
[ "Return", "the", "final", "client", "message", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Auth/Scram.php#L204-L244
215,940
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Auth/Scram.php
Horde_Imap_Client_Auth_Scram.parseServerFinalMessage
public function parseServerFinalMessage($msg) { foreach (explode(',', $msg) as $val) { list($attr, $aval) = array_map('trim', explode('=', $val, 2)); switch ($attr) { case 'e': return false; case 'v': return (base64_decode($aval) === $this->_serversig); } } return false; }
php
public function parseServerFinalMessage($msg) { foreach (explode(',', $msg) as $val) { list($attr, $aval) = array_map('trim', explode('=', $val, 2)); switch ($attr) { case 'e': return false; case 'v': return (base64_decode($aval) === $this->_serversig); } } return false; }
[ "public", "function", "parseServerFinalMessage", "(", "$", "msg", ")", "{", "foreach", "(", "explode", "(", "','", ",", "$", "msg", ")", "as", "$", "val", ")", "{", "list", "(", "$", "attr", ",", "$", "aval", ")", "=", "array_map", "(", "'trim'", ",", "explode", "(", "'='", ",", "$", "val", ",", "2", ")", ")", ";", "switch", "(", "$", "attr", ")", "{", "case", "'e'", ":", "return", "false", ";", "case", "'v'", ":", "return", "(", "base64_decode", "(", "$", "aval", ")", "===", "$", "this", "->", "_serversig", ")", ";", "}", "}", "return", "false", ";", "}" ]
Process the final server message response. @param string $msg Final server response. @return boolean False if authentication failed.
[ "Process", "the", "final", "server", "message", "response", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Auth/Scram.php#L253-L268
215,941
moodle/moodle
admin/tool/behat/locallib.php
tool_behat.stepsdefinitions
public static function stepsdefinitions($type, $component, $filter) { // We don't require the test environment to be enabled to list the steps definitions // so test writers can more easily set up the environment. behat_command::behat_setup_problem(); // The loaded steps depends on the component specified. behat_config_manager::update_config_file($component, false); // The Moodle\BehatExtension\HelpPrinter\MoodleDefinitionsPrinter will parse this search format. if ($type) { $filter .= '&&' . $type; } if ($filter) { $filteroption = ' -d "' . $filter . '"'; } else { $filteroption = ' -di'; } // Get steps definitions from Behat. $options = ' --config="'.behat_config_manager::get_steps_list_config_filepath(). '" '.$filteroption; list($steps, $code) = behat_command::run($options); return $steps; }
php
public static function stepsdefinitions($type, $component, $filter) { // We don't require the test environment to be enabled to list the steps definitions // so test writers can more easily set up the environment. behat_command::behat_setup_problem(); // The loaded steps depends on the component specified. behat_config_manager::update_config_file($component, false); // The Moodle\BehatExtension\HelpPrinter\MoodleDefinitionsPrinter will parse this search format. if ($type) { $filter .= '&&' . $type; } if ($filter) { $filteroption = ' -d "' . $filter . '"'; } else { $filteroption = ' -di'; } // Get steps definitions from Behat. $options = ' --config="'.behat_config_manager::get_steps_list_config_filepath(). '" '.$filteroption; list($steps, $code) = behat_command::run($options); return $steps; }
[ "public", "static", "function", "stepsdefinitions", "(", "$", "type", ",", "$", "component", ",", "$", "filter", ")", "{", "// We don't require the test environment to be enabled to list the steps definitions", "// so test writers can more easily set up the environment.", "behat_command", "::", "behat_setup_problem", "(", ")", ";", "// The loaded steps depends on the component specified.", "behat_config_manager", "::", "update_config_file", "(", "$", "component", ",", "false", ")", ";", "// The Moodle\\BehatExtension\\HelpPrinter\\MoodleDefinitionsPrinter will parse this search format.", "if", "(", "$", "type", ")", "{", "$", "filter", ".=", "'&&'", ".", "$", "type", ";", "}", "if", "(", "$", "filter", ")", "{", "$", "filteroption", "=", "' -d \"'", ".", "$", "filter", ".", "'\"'", ";", "}", "else", "{", "$", "filteroption", "=", "' -di'", ";", "}", "// Get steps definitions from Behat.", "$", "options", "=", "' --config=\"'", ".", "behat_config_manager", "::", "get_steps_list_config_filepath", "(", ")", ".", "'\" '", ".", "$", "filteroption", ";", "list", "(", "$", "steps", ",", "$", "code", ")", "=", "behat_command", "::", "run", "(", "$", "options", ")", ";", "return", "$", "steps", ";", "}" ]
Lists the available steps definitions @param string $type @param string $component @param string $filter @return array System steps or empty array if case there are no steps
[ "Lists", "the", "available", "steps", "definitions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/behat/locallib.php#L49-L74
215,942
moodle/moodle
lib/phpexcel/PHPExcel/Cell/DataType.php
PHPExcel_Cell_DataType.checkString
public static function checkString($pValue = null) { if ($pValue instanceof PHPExcel_RichText) { // TODO: Sanitize Rich-Text string (max. character count is 32,767) return $pValue; } // string must never be longer than 32,767 characters, truncate if necessary $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 32767); // we require that newline is represented as "\n" in core, not as "\r\n" or "\r" $pValue = str_replace(array("\r\n", "\r"), "\n", $pValue); return $pValue; }
php
public static function checkString($pValue = null) { if ($pValue instanceof PHPExcel_RichText) { // TODO: Sanitize Rich-Text string (max. character count is 32,767) return $pValue; } // string must never be longer than 32,767 characters, truncate if necessary $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 32767); // we require that newline is represented as "\n" in core, not as "\r\n" or "\r" $pValue = str_replace(array("\r\n", "\r"), "\n", $pValue); return $pValue; }
[ "public", "static", "function", "checkString", "(", "$", "pValue", "=", "null", ")", "{", "if", "(", "$", "pValue", "instanceof", "PHPExcel_RichText", ")", "{", "// TODO: Sanitize Rich-Text string (max. character count is 32,767)", "return", "$", "pValue", ";", "}", "// string must never be longer than 32,767 characters, truncate if necessary", "$", "pValue", "=", "PHPExcel_Shared_String", "::", "Substring", "(", "$", "pValue", ",", "0", ",", "32767", ")", ";", "// we require that newline is represented as \"\\n\" in core, not as \"\\r\\n\" or \"\\r\"", "$", "pValue", "=", "str_replace", "(", "array", "(", "\"\\r\\n\"", ",", "\"\\r\"", ")", ",", "\"\\n\"", ",", "$", "pValue", ")", ";", "return", "$", "pValue", ";", "}" ]
Check a string that it satisfies Excel requirements @param mixed Value to sanitize to an Excel string @return mixed Sanitized value
[ "Check", "a", "string", "that", "it", "satisfies", "Excel", "requirements" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Cell/DataType.php#L83-L97
215,943
moodle/moodle
auth/shibboleth/auth.php
auth_plugin_shibboleth.get_userinfo
function get_userinfo($username) { // reads user information from shibboleth attributes and return it in array() global $CFG; // Check whether we have got all the essential attributes if ( empty($_SERVER[$this->config->user_attribute]) ) { print_error( 'shib_not_all_attributes_error', 'auth_shibboleth' , '', "'".$this->config->user_attribute."' ('".$_SERVER[$this->config->user_attribute]."'), '".$this->config->field_map_firstname."' ('".$_SERVER[$this->config->field_map_firstname]."'), '".$this->config->field_map_lastname."' ('".$_SERVER[$this->config->field_map_lastname]."') and '".$this->config->field_map_email."' ('".$_SERVER[$this->config->field_map_email]."')"); } $attrmap = $this->get_attributes(); $result = array(); $search_attribs = array(); foreach ($attrmap as $key=>$value) { // Check if attribute is present if (!isset($_SERVER[$value])){ $result[$key] = ''; continue; } // Make usename lowercase if ($key == 'username'){ $result[$key] = strtolower($this->get_first_string($_SERVER[$value])); } else { $result[$key] = $this->get_first_string($_SERVER[$value]); } } // Provide an API to modify the information to fit the Moodle internal // data representation if ( $this->config->convert_data && $this->config->convert_data != '' && is_readable($this->config->convert_data) ) { // Include a custom file outside the Moodle dir to // modify the variable $moodleattributes include($this->config->convert_data); } return $result; }
php
function get_userinfo($username) { // reads user information from shibboleth attributes and return it in array() global $CFG; // Check whether we have got all the essential attributes if ( empty($_SERVER[$this->config->user_attribute]) ) { print_error( 'shib_not_all_attributes_error', 'auth_shibboleth' , '', "'".$this->config->user_attribute."' ('".$_SERVER[$this->config->user_attribute]."'), '".$this->config->field_map_firstname."' ('".$_SERVER[$this->config->field_map_firstname]."'), '".$this->config->field_map_lastname."' ('".$_SERVER[$this->config->field_map_lastname]."') and '".$this->config->field_map_email."' ('".$_SERVER[$this->config->field_map_email]."')"); } $attrmap = $this->get_attributes(); $result = array(); $search_attribs = array(); foreach ($attrmap as $key=>$value) { // Check if attribute is present if (!isset($_SERVER[$value])){ $result[$key] = ''; continue; } // Make usename lowercase if ($key == 'username'){ $result[$key] = strtolower($this->get_first_string($_SERVER[$value])); } else { $result[$key] = $this->get_first_string($_SERVER[$value]); } } // Provide an API to modify the information to fit the Moodle internal // data representation if ( $this->config->convert_data && $this->config->convert_data != '' && is_readable($this->config->convert_data) ) { // Include a custom file outside the Moodle dir to // modify the variable $moodleattributes include($this->config->convert_data); } return $result; }
[ "function", "get_userinfo", "(", "$", "username", ")", "{", "// reads user information from shibboleth attributes and return it in array()", "global", "$", "CFG", ";", "// Check whether we have got all the essential attributes", "if", "(", "empty", "(", "$", "_SERVER", "[", "$", "this", "->", "config", "->", "user_attribute", "]", ")", ")", "{", "print_error", "(", "'shib_not_all_attributes_error'", ",", "'auth_shibboleth'", ",", "''", ",", "\"'\"", ".", "$", "this", "->", "config", "->", "user_attribute", ".", "\"' ('\"", ".", "$", "_SERVER", "[", "$", "this", "->", "config", "->", "user_attribute", "]", ".", "\"'), '\"", ".", "$", "this", "->", "config", "->", "field_map_firstname", ".", "\"' ('\"", ".", "$", "_SERVER", "[", "$", "this", "->", "config", "->", "field_map_firstname", "]", ".", "\"'), '\"", ".", "$", "this", "->", "config", "->", "field_map_lastname", ".", "\"' ('\"", ".", "$", "_SERVER", "[", "$", "this", "->", "config", "->", "field_map_lastname", "]", ".", "\"') and '\"", ".", "$", "this", "->", "config", "->", "field_map_email", ".", "\"' ('\"", ".", "$", "_SERVER", "[", "$", "this", "->", "config", "->", "field_map_email", "]", ".", "\"')\"", ")", ";", "}", "$", "attrmap", "=", "$", "this", "->", "get_attributes", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "search_attribs", "=", "array", "(", ")", ";", "foreach", "(", "$", "attrmap", "as", "$", "key", "=>", "$", "value", ")", "{", "// Check if attribute is present", "if", "(", "!", "isset", "(", "$", "_SERVER", "[", "$", "value", "]", ")", ")", "{", "$", "result", "[", "$", "key", "]", "=", "''", ";", "continue", ";", "}", "// Make usename lowercase", "if", "(", "$", "key", "==", "'username'", ")", "{", "$", "result", "[", "$", "key", "]", "=", "strtolower", "(", "$", "this", "->", "get_first_string", "(", "$", "_SERVER", "[", "$", "value", "]", ")", ")", ";", "}", "else", "{", "$", "result", "[", "$", "key", "]", "=", "$", "this", "->", "get_first_string", "(", "$", "_SERVER", "[", "$", "value", "]", ")", ";", "}", "}", "// Provide an API to modify the information to fit the Moodle internal", "// data representation", "if", "(", "$", "this", "->", "config", "->", "convert_data", "&&", "$", "this", "->", "config", "->", "convert_data", "!=", "''", "&&", "is_readable", "(", "$", "this", "->", "config", "->", "convert_data", ")", ")", "{", "// Include a custom file outside the Moodle dir to", "// modify the variable $moodleattributes", "include", "(", "$", "this", "->", "config", "->", "convert_data", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns the user information for 'external' users. In this case the attributes provided by Shibboleth @return array $result Associative array of user data
[ "Returns", "the", "user", "information", "for", "external", "users", ".", "In", "this", "case", "the", "attributes", "provided", "by", "Shibboleth" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/shibboleth/auth.php#L102-L145
215,944
moodle/moodle
auth/shibboleth/auth.php
auth_plugin_shibboleth.get_attributes
function get_attributes() { $configarray = (array) $this->config; $moodleattributes = array(); $userfields = array_merge($this->userfields, $this->get_custom_user_profile_fields()); foreach ($userfields as $field) { if (isset($configarray["field_map_$field"])) { $moodleattributes[$field] = $configarray["field_map_$field"]; } } $moodleattributes['username'] = $configarray["user_attribute"]; return $moodleattributes; }
php
function get_attributes() { $configarray = (array) $this->config; $moodleattributes = array(); $userfields = array_merge($this->userfields, $this->get_custom_user_profile_fields()); foreach ($userfields as $field) { if (isset($configarray["field_map_$field"])) { $moodleattributes[$field] = $configarray["field_map_$field"]; } } $moodleattributes['username'] = $configarray["user_attribute"]; return $moodleattributes; }
[ "function", "get_attributes", "(", ")", "{", "$", "configarray", "=", "(", "array", ")", "$", "this", "->", "config", ";", "$", "moodleattributes", "=", "array", "(", ")", ";", "$", "userfields", "=", "array_merge", "(", "$", "this", "->", "userfields", ",", "$", "this", "->", "get_custom_user_profile_fields", "(", ")", ")", ";", "foreach", "(", "$", "userfields", "as", "$", "field", ")", "{", "if", "(", "isset", "(", "$", "configarray", "[", "\"field_map_$field\"", "]", ")", ")", "{", "$", "moodleattributes", "[", "$", "field", "]", "=", "$", "configarray", "[", "\"field_map_$field\"", "]", ";", "}", "}", "$", "moodleattributes", "[", "'username'", "]", "=", "$", "configarray", "[", "\"user_attribute\"", "]", ";", "return", "$", "moodleattributes", ";", "}" ]
Returns array containg attribute mappings between Moodle and Shibboleth. @return array
[ "Returns", "array", "containg", "attribute", "mappings", "between", "Moodle", "and", "Shibboleth", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/shibboleth/auth.php#L152-L165
215,945
moodle/moodle
competency/classes/plan.php
plan.can_manage
public function can_manage() { if ($this->is_draft()) { return self::can_manage_user_draft($this->get('userid')); } return self::can_manage_user($this->get('userid')); }
php
public function can_manage() { if ($this->is_draft()) { return self::can_manage_user_draft($this->get('userid')); } return self::can_manage_user($this->get('userid')); }
[ "public", "function", "can_manage", "(", ")", "{", "if", "(", "$", "this", "->", "is_draft", "(", ")", ")", "{", "return", "self", "::", "can_manage_user_draft", "(", "$", "this", "->", "get", "(", "'userid'", ")", ")", ";", "}", "return", "self", "::", "can_manage_user", "(", "$", "this", "->", "get", "(", "'userid'", ")", ")", ";", "}" ]
Whether the current user can manage the plan. @return bool
[ "Whether", "the", "current", "user", "can", "manage", "the", "plan", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L141-L146
215,946
moodle/moodle
competency/classes/plan.php
plan.can_read
public function can_read() { if ($this->is_draft()) { return self::can_read_user_draft($this->get('userid')); } return self::can_read_user($this->get('userid')); }
php
public function can_read() { if ($this->is_draft()) { return self::can_read_user_draft($this->get('userid')); } return self::can_read_user($this->get('userid')); }
[ "public", "function", "can_read", "(", ")", "{", "if", "(", "$", "this", "->", "is_draft", "(", ")", ")", "{", "return", "self", "::", "can_read_user_draft", "(", "$", "this", "->", "get", "(", "'userid'", ")", ")", ";", "}", "return", "self", "::", "can_read_user", "(", "$", "this", "->", "get", "(", "'userid'", ")", ")", ";", "}" ]
Whether the current user can read the plan. @return bool
[ "Whether", "the", "current", "user", "can", "read", "the", "plan", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L153-L158
215,947
moodle/moodle
competency/classes/plan.php
plan.get_comment_object
public function get_comment_object() { global $CFG; require_once($CFG->dirroot . '/comment/lib.php'); if (!$this->get('id')) { throw new \coding_exception('The plan must exist.'); } $comment = new comment((object) array( 'client_id' => 'plancommentarea' . $this->get('id'), 'context' => $this->get_context(), 'component' => 'competency', // This cannot be named 'core_competency'. 'itemid' => $this->get('id'), 'area' => 'plan', 'showcount' => true, )); $comment->set_fullwidth(true); return $comment; }
php
public function get_comment_object() { global $CFG; require_once($CFG->dirroot . '/comment/lib.php'); if (!$this->get('id')) { throw new \coding_exception('The plan must exist.'); } $comment = new comment((object) array( 'client_id' => 'plancommentarea' . $this->get('id'), 'context' => $this->get_context(), 'component' => 'competency', // This cannot be named 'core_competency'. 'itemid' => $this->get('id'), 'area' => 'plan', 'showcount' => true, )); $comment->set_fullwidth(true); return $comment; }
[ "public", "function", "get_comment_object", "(", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/comment/lib.php'", ")", ";", "if", "(", "!", "$", "this", "->", "get", "(", "'id'", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'The plan must exist.'", ")", ";", "}", "$", "comment", "=", "new", "comment", "(", "(", "object", ")", "array", "(", "'client_id'", "=>", "'plancommentarea'", ".", "$", "this", "->", "get", "(", "'id'", ")", ",", "'context'", "=>", "$", "this", "->", "get_context", "(", ")", ",", "'component'", "=>", "'competency'", ",", "// This cannot be named 'core_competency'.", "'itemid'", "=>", "$", "this", "->", "get", "(", "'id'", ")", ",", "'area'", "=>", "'plan'", ",", "'showcount'", "=>", "true", ",", ")", ")", ";", "$", "comment", "->", "set_fullwidth", "(", "true", ")", ";", "return", "$", "comment", ";", "}" ]
Get the comment object. @return comment
[ "Get", "the", "comment", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L192-L210
215,948
moodle/moodle
competency/classes/plan.php
plan.get_competencies
public function get_competencies() { $competencies = array(); if ($this->get('status') == self::STATUS_COMPLETE) { // Get the competencies from the archive of the plan. $competencies = user_competency_plan::list_competencies($this->get('id'), $this->get('userid')); } else if ($this->is_based_on_template()) { // Get the competencies from the template. $competencies = template_competency::list_competencies($this->get('templateid')); } else { // Get the competencies from the plan. $competencies = plan_competency::list_competencies($this->get('id')); } return $competencies; }
php
public function get_competencies() { $competencies = array(); if ($this->get('status') == self::STATUS_COMPLETE) { // Get the competencies from the archive of the plan. $competencies = user_competency_plan::list_competencies($this->get('id'), $this->get('userid')); } else if ($this->is_based_on_template()) { // Get the competencies from the template. $competencies = template_competency::list_competencies($this->get('templateid')); } else { // Get the competencies from the plan. $competencies = plan_competency::list_competencies($this->get('id')); } return $competencies; }
[ "public", "function", "get_competencies", "(", ")", "{", "$", "competencies", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "get", "(", "'status'", ")", "==", "self", "::", "STATUS_COMPLETE", ")", "{", "// Get the competencies from the archive of the plan.", "$", "competencies", "=", "user_competency_plan", "::", "list_competencies", "(", "$", "this", "->", "get", "(", "'id'", ")", ",", "$", "this", "->", "get", "(", "'userid'", ")", ")", ";", "}", "else", "if", "(", "$", "this", "->", "is_based_on_template", "(", ")", ")", "{", "// Get the competencies from the template.", "$", "competencies", "=", "template_competency", "::", "list_competencies", "(", "$", "this", "->", "get", "(", "'templateid'", ")", ")", ";", "}", "else", "{", "// Get the competencies from the plan.", "$", "competencies", "=", "plan_competency", "::", "list_competencies", "(", "$", "this", "->", "get", "(", "'id'", ")", ")", ";", "}", "return", "$", "competencies", ";", "}" ]
Get the competencies in this plan. @return competency[]
[ "Get", "the", "competencies", "in", "this", "plan", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L217-L232
215,949
moodle/moodle
competency/classes/plan.php
plan.get_competency
public function get_competency($competencyid) { $competency = null; if ($this->get('status') == self::STATUS_COMPLETE) { // Get the competency from the archive of the plan. $competency = user_competency_plan::get_competency_by_planid($this->get('id'), $competencyid); } else if ($this->is_based_on_template()) { // Get the competency from the template. $competency = template_competency::get_competency($this->get('templateid'), $competencyid); } else { // Get the competency from the plan. $competency = plan_competency::get_competency($this->get('id'), $competencyid); } return $competency; }
php
public function get_competency($competencyid) { $competency = null; if ($this->get('status') == self::STATUS_COMPLETE) { // Get the competency from the archive of the plan. $competency = user_competency_plan::get_competency_by_planid($this->get('id'), $competencyid); } else if ($this->is_based_on_template()) { // Get the competency from the template. $competency = template_competency::get_competency($this->get('templateid'), $competencyid); } else { // Get the competency from the plan. $competency = plan_competency::get_competency($this->get('id'), $competencyid); } return $competency; }
[ "public", "function", "get_competency", "(", "$", "competencyid", ")", "{", "$", "competency", "=", "null", ";", "if", "(", "$", "this", "->", "get", "(", "'status'", ")", "==", "self", "::", "STATUS_COMPLETE", ")", "{", "// Get the competency from the archive of the plan.", "$", "competency", "=", "user_competency_plan", "::", "get_competency_by_planid", "(", "$", "this", "->", "get", "(", "'id'", ")", ",", "$", "competencyid", ")", ";", "}", "else", "if", "(", "$", "this", "->", "is_based_on_template", "(", ")", ")", "{", "// Get the competency from the template.", "$", "competency", "=", "template_competency", "::", "get_competency", "(", "$", "this", "->", "get", "(", "'templateid'", ")", ",", "$", "competencyid", ")", ";", "}", "else", "{", "// Get the competency from the plan.", "$", "competency", "=", "plan_competency", "::", "get_competency", "(", "$", "this", "->", "get", "(", "'id'", ")", ",", "$", "competencyid", ")", ";", "}", "return", "$", "competency", ";", "}" ]
Get a single competency from this plan. This will throw an exception if the competency does not belong to the plan. @param int $competencyid The competency ID. @return competency
[ "Get", "a", "single", "competency", "from", "this", "plan", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L242-L256
215,950
moodle/moodle
competency/classes/plan.php
plan.validate_userid
protected function validate_userid($value) { global $DB; // During create. if (!$this->get('id')) { // Check that the user exists. We do not need to do that on update because // the userid of a plan should never change. if (!$DB->record_exists('user', array('id' => $value))) { return new lang_string('invaliddata', 'error'); } } return true; }
php
protected function validate_userid($value) { global $DB; // During create. if (!$this->get('id')) { // Check that the user exists. We do not need to do that on update because // the userid of a plan should never change. if (!$DB->record_exists('user', array('id' => $value))) { return new lang_string('invaliddata', 'error'); } } return true; }
[ "protected", "function", "validate_userid", "(", "$", "value", ")", "{", "global", "$", "DB", ";", "// During create.", "if", "(", "!", "$", "this", "->", "get", "(", "'id'", ")", ")", "{", "// Check that the user exists. We do not need to do that on update because", "// the userid of a plan should never change.", "if", "(", "!", "$", "DB", "->", "record_exists", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "value", ")", ")", ")", "{", "return", "new", "lang_string", "(", "'invaliddata'", ",", "'error'", ")", ";", "}", "}", "return", "true", ";", "}" ]
Validate the user ID. @param int $value @return true|lang_string
[ "Validate", "the", "user", "ID", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L347-L362
215,951
moodle/moodle
competency/classes/plan.php
plan.can_comment_user
public static function can_comment_user($planuserid) { global $USER; $capabilities = array('moodle/competency:plancomment'); if ($USER->id == $planuserid) { $capabilities[] = 'moodle/competency:plancommentown'; } return has_any_capability($capabilities, context_user::instance($planuserid)); }
php
public static function can_comment_user($planuserid) { global $USER; $capabilities = array('moodle/competency:plancomment'); if ($USER->id == $planuserid) { $capabilities[] = 'moodle/competency:plancommentown'; } return has_any_capability($capabilities, context_user::instance($planuserid)); }
[ "public", "static", "function", "can_comment_user", "(", "$", "planuserid", ")", "{", "global", "$", "USER", ";", "$", "capabilities", "=", "array", "(", "'moodle/competency:plancomment'", ")", ";", "if", "(", "$", "USER", "->", "id", "==", "$", "planuserid", ")", "{", "$", "capabilities", "[", "]", "=", "'moodle/competency:plancommentown'", ";", "}", "return", "has_any_capability", "(", "$", "capabilities", ",", "context_user", "::", "instance", "(", "$", "planuserid", ")", ")", ";", "}" ]
Can the current user comment on a user's plan? @param int $planuserid The user ID the plan belongs to. @return bool
[ "Can", "the", "current", "user", "comment", "on", "a", "user", "s", "plan?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L370-L379
215,952
moodle/moodle
competency/classes/plan.php
plan.can_manage_user
public static function can_manage_user($planuserid) { global $USER; $context = context_user::instance($planuserid); $capabilities = array('moodle/competency:planmanage'); if ($context->instanceid == $USER->id) { $capabilities[] = 'moodle/competency:planmanageown'; } return has_any_capability($capabilities, $context); }
php
public static function can_manage_user($planuserid) { global $USER; $context = context_user::instance($planuserid); $capabilities = array('moodle/competency:planmanage'); if ($context->instanceid == $USER->id) { $capabilities[] = 'moodle/competency:planmanageown'; } return has_any_capability($capabilities, $context); }
[ "public", "static", "function", "can_manage_user", "(", "$", "planuserid", ")", "{", "global", "$", "USER", ";", "$", "context", "=", "context_user", "::", "instance", "(", "$", "planuserid", ")", ";", "$", "capabilities", "=", "array", "(", "'moodle/competency:planmanage'", ")", ";", "if", "(", "$", "context", "->", "instanceid", "==", "$", "USER", "->", "id", ")", "{", "$", "capabilities", "[", "]", "=", "'moodle/competency:planmanageown'", ";", "}", "return", "has_any_capability", "(", "$", "capabilities", ",", "$", "context", ")", ";", "}" ]
Can the current user manage a user's plan? @param int $planuserid The user to whom the plan would belong. @return bool
[ "Can", "the", "current", "user", "manage", "a", "user", "s", "plan?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L387-L397
215,953
moodle/moodle
competency/classes/plan.php
plan.can_request_review_user
public static function can_request_review_user($planuserid) { global $USER; $capabilities = array('moodle/competency:planrequestreview'); if ($USER->id == $planuserid) { $capabilities[] = 'moodle/competency:planrequestreviewown'; } return has_any_capability($capabilities, context_user::instance($planuserid)); }
php
public static function can_request_review_user($planuserid) { global $USER; $capabilities = array('moodle/competency:planrequestreview'); if ($USER->id == $planuserid) { $capabilities[] = 'moodle/competency:planrequestreviewown'; } return has_any_capability($capabilities, context_user::instance($planuserid)); }
[ "public", "static", "function", "can_request_review_user", "(", "$", "planuserid", ")", "{", "global", "$", "USER", ";", "$", "capabilities", "=", "array", "(", "'moodle/competency:planrequestreview'", ")", ";", "if", "(", "$", "USER", "->", "id", "==", "$", "planuserid", ")", "{", "$", "capabilities", "[", "]", "=", "'moodle/competency:planrequestreviewown'", ";", "}", "return", "has_any_capability", "(", "$", "capabilities", ",", "context_user", "::", "instance", "(", "$", "planuserid", ")", ")", ";", "}" ]
Can the current user request the draft to be reviewed. @param int $planuserid The user to whom the plan would belong. @return bool
[ "Can", "the", "current", "user", "request", "the", "draft", "to", "be", "reviewed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L472-L481
215,954
moodle/moodle
competency/classes/plan.php
plan.get_by_user_and_competency
public static function get_by_user_and_competency($userid, $competencyid) { global $DB; $sql = 'SELECT p.* FROM {' . self::TABLE . '} p LEFT JOIN {' . plan_competency::TABLE . '} pc ON pc.planid = p.id AND pc.competencyid = :competencyid1 LEFT JOIN {' . user_competency_plan::TABLE . '} ucp ON ucp.planid = p.id AND ucp.competencyid = :competencyid2 LEFT JOIN {' . template_competency::TABLE . '} tc ON tc.templateid = p.templateid AND tc.competencyid = :competencyid3 WHERE p.userid = :userid AND (pc.id IS NOT NULL OR ucp.id IS NOT NULL OR tc.id IS NOT NULL) ORDER BY p.id ASC'; $params = array( 'competencyid1' => $competencyid, 'competencyid2' => $competencyid, 'competencyid3' => $competencyid, 'userid' => $userid ); $plans = array(); $records = $DB->get_records_sql($sql, $params); foreach ($records as $record) { $plans[$record->id] = new plan(0, $record); } return $plans; }
php
public static function get_by_user_and_competency($userid, $competencyid) { global $DB; $sql = 'SELECT p.* FROM {' . self::TABLE . '} p LEFT JOIN {' . plan_competency::TABLE . '} pc ON pc.planid = p.id AND pc.competencyid = :competencyid1 LEFT JOIN {' . user_competency_plan::TABLE . '} ucp ON ucp.planid = p.id AND ucp.competencyid = :competencyid2 LEFT JOIN {' . template_competency::TABLE . '} tc ON tc.templateid = p.templateid AND tc.competencyid = :competencyid3 WHERE p.userid = :userid AND (pc.id IS NOT NULL OR ucp.id IS NOT NULL OR tc.id IS NOT NULL) ORDER BY p.id ASC'; $params = array( 'competencyid1' => $competencyid, 'competencyid2' => $competencyid, 'competencyid3' => $competencyid, 'userid' => $userid ); $plans = array(); $records = $DB->get_records_sql($sql, $params); foreach ($records as $record) { $plans[$record->id] = new plan(0, $record); } return $plans; }
[ "public", "static", "function", "get_by_user_and_competency", "(", "$", "userid", ",", "$", "competencyid", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "'SELECT p.*\n FROM {'", ".", "self", "::", "TABLE", ".", "'} p\n LEFT JOIN {'", ".", "plan_competency", "::", "TABLE", ".", "'} pc\n ON pc.planid = p.id\n AND pc.competencyid = :competencyid1\n LEFT JOIN {'", ".", "user_competency_plan", "::", "TABLE", ".", "'} ucp\n ON ucp.planid = p.id\n AND ucp.competencyid = :competencyid2\n LEFT JOIN {'", ".", "template_competency", "::", "TABLE", ".", "'} tc\n ON tc.templateid = p.templateid\n AND tc.competencyid = :competencyid3\n WHERE p.userid = :userid\n AND (pc.id IS NOT NULL\n OR ucp.id IS NOT NULL\n OR tc.id IS NOT NULL)\n ORDER BY p.id ASC'", ";", "$", "params", "=", "array", "(", "'competencyid1'", "=>", "$", "competencyid", ",", "'competencyid2'", "=>", "$", "competencyid", ",", "'competencyid3'", "=>", "$", "competencyid", ",", "'userid'", "=>", "$", "userid", ")", ";", "$", "plans", "=", "array", "(", ")", ";", "$", "records", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "plans", "[", "$", "record", "->", "id", "]", "=", "new", "plan", "(", "0", ",", "$", "record", ")", ";", "}", "return", "$", "plans", ";", "}" ]
Get the plans of a user containing a specific competency. @param int $userid The user ID. @param int $competencyid The competency ID. @return plans[]
[ "Get", "the", "plans", "of", "a", "user", "containing", "a", "specific", "competency", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L503-L537
215,955
moodle/moodle
competency/classes/plan.php
plan.get_recordset_for_due_and_incomplete
public static function get_recordset_for_due_and_incomplete() { global $DB; $sql = "duedate > 0 AND duedate < :now AND status = :status"; $params = array('now' => time(), 'status' => self::STATUS_ACTIVE); return $DB->get_recordset_select(self::TABLE, $sql, $params); }
php
public static function get_recordset_for_due_and_incomplete() { global $DB; $sql = "duedate > 0 AND duedate < :now AND status = :status"; $params = array('now' => time(), 'status' => self::STATUS_ACTIVE); return $DB->get_recordset_select(self::TABLE, $sql, $params); }
[ "public", "static", "function", "get_recordset_for_due_and_incomplete", "(", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"duedate > 0 AND duedate < :now AND status = :status\"", ";", "$", "params", "=", "array", "(", "'now'", "=>", "time", "(", ")", ",", "'status'", "=>", "self", "::", "STATUS_ACTIVE", ")", ";", "return", "$", "DB", "->", "get_recordset_select", "(", "self", "::", "TABLE", ",", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Get the recordset of the plans that are due, incomplete and not draft. @return \moodle_recordset
[ "Get", "the", "recordset", "of", "the", "plans", "that", "are", "due", "incomplete", "and", "not", "draft", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L553-L558
215,956
moodle/moodle
competency/classes/plan.php
plan.get_status_list
public static function get_status_list($userid) { $status = array(); if (self::can_manage_user_draft($userid)) { $status[self::STATUS_DRAFT] = get_string('planstatusdraft', 'core_competency'); } if (self::can_manage_user($userid)) { $status[self::STATUS_ACTIVE] = get_string('planstatusactive', 'core_competency'); } return $status; }
php
public static function get_status_list($userid) { $status = array(); if (self::can_manage_user_draft($userid)) { $status[self::STATUS_DRAFT] = get_string('planstatusdraft', 'core_competency'); } if (self::can_manage_user($userid)) { $status[self::STATUS_ACTIVE] = get_string('planstatusactive', 'core_competency'); } return $status; }
[ "public", "static", "function", "get_status_list", "(", "$", "userid", ")", "{", "$", "status", "=", "array", "(", ")", ";", "if", "(", "self", "::", "can_manage_user_draft", "(", "$", "userid", ")", ")", "{", "$", "status", "[", "self", "::", "STATUS_DRAFT", "]", "=", "get_string", "(", "'planstatusdraft'", ",", "'core_competency'", ")", ";", "}", "if", "(", "self", "::", "can_manage_user", "(", "$", "userid", ")", ")", "{", "$", "status", "[", "self", "::", "STATUS_ACTIVE", "]", "=", "get_string", "(", "'planstatusactive'", ",", "'core_competency'", ")", ";", "}", "return", "$", "status", ";", "}" ]
Return a list of status depending on capabilities. @param int $userid The user to whom the plan would belong. @return array
[ "Return", "a", "list", "of", "status", "depending", "on", "capabilities", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L566-L575
215,957
moodle/moodle
competency/classes/plan.php
plan.update_multiple_from_template
public static function update_multiple_from_template(template $template) { global $DB; if (!$template->is_valid()) { // As we will bypass this model's validation we rely on the template being validated. throw new \coding_exception('The template must be validated before updating plans.'); } $params = array( 'templateid' => $template->get('id'), 'status' => self::STATUS_COMPLETE, 'name' => $template->get('shortname'), 'description' => $template->get('description'), 'descriptionformat' => $template->get('descriptionformat'), 'duedate' => $template->get('duedate'), ); $sql = "UPDATE {" . self::TABLE . "} SET name = :name, description = :description, descriptionformat = :descriptionformat, duedate = :duedate WHERE templateid = :templateid AND status != :status"; return $DB->execute($sql, $params); }
php
public static function update_multiple_from_template(template $template) { global $DB; if (!$template->is_valid()) { // As we will bypass this model's validation we rely on the template being validated. throw new \coding_exception('The template must be validated before updating plans.'); } $params = array( 'templateid' => $template->get('id'), 'status' => self::STATUS_COMPLETE, 'name' => $template->get('shortname'), 'description' => $template->get('description'), 'descriptionformat' => $template->get('descriptionformat'), 'duedate' => $template->get('duedate'), ); $sql = "UPDATE {" . self::TABLE . "} SET name = :name, description = :description, descriptionformat = :descriptionformat, duedate = :duedate WHERE templateid = :templateid AND status != :status"; return $DB->execute($sql, $params); }
[ "public", "static", "function", "update_multiple_from_template", "(", "template", "$", "template", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "$", "template", "->", "is_valid", "(", ")", ")", "{", "// As we will bypass this model's validation we rely on the template being validated.", "throw", "new", "\\", "coding_exception", "(", "'The template must be validated before updating plans.'", ")", ";", "}", "$", "params", "=", "array", "(", "'templateid'", "=>", "$", "template", "->", "get", "(", "'id'", ")", ",", "'status'", "=>", "self", "::", "STATUS_COMPLETE", ",", "'name'", "=>", "$", "template", "->", "get", "(", "'shortname'", ")", ",", "'description'", "=>", "$", "template", "->", "get", "(", "'description'", ")", ",", "'descriptionformat'", "=>", "$", "template", "->", "get", "(", "'descriptionformat'", ")", ",", "'duedate'", "=>", "$", "template", "->", "get", "(", "'duedate'", ")", ",", ")", ";", "$", "sql", "=", "\"UPDATE {\"", ".", "self", "::", "TABLE", ".", "\"}\n SET name = :name,\n description = :description,\n descriptionformat = :descriptionformat,\n duedate = :duedate\n WHERE templateid = :templateid\n AND status != :status\"", ";", "return", "$", "DB", "->", "execute", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Update from template. Bulk update a lot of plans from a template @param template $template @return bool
[ "Update", "from", "template", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L585-L611
215,958
moodle/moodle
competency/classes/plan.php
plan.validate_duedate
protected function validate_duedate($value) { // We do not check duedate when plan is draft, complete, unset, or based on a template. if ($this->is_based_on_template() || $this->is_draft() || $this->get('status') == self::STATUS_COMPLETE || empty($value)) { return true; } // During update. if ($this->get('id')) { $before = $this->beforeupdate->get('duedate'); $beforestatus = $this->beforeupdate->get('status'); // The value has not changed, then it's always OK. Though if we're going // from draft to active it has to has to be validated. if ($before == $value && !in_array($beforestatus, self::get_draft_statuses())) { return true; } } if ($value <= time()) { // We cannot set the date in the past. return new lang_string('errorcannotsetduedateinthepast', 'core_competency'); } if ($value <= time() + self::DUEDATE_THRESHOLD) { // We cannot set the date too soon, but we can leave it empty. return new lang_string('errorcannotsetduedatetoosoon', 'core_competency'); } return true; }
php
protected function validate_duedate($value) { // We do not check duedate when plan is draft, complete, unset, or based on a template. if ($this->is_based_on_template() || $this->is_draft() || $this->get('status') == self::STATUS_COMPLETE || empty($value)) { return true; } // During update. if ($this->get('id')) { $before = $this->beforeupdate->get('duedate'); $beforestatus = $this->beforeupdate->get('status'); // The value has not changed, then it's always OK. Though if we're going // from draft to active it has to has to be validated. if ($before == $value && !in_array($beforestatus, self::get_draft_statuses())) { return true; } } if ($value <= time()) { // We cannot set the date in the past. return new lang_string('errorcannotsetduedateinthepast', 'core_competency'); } if ($value <= time() + self::DUEDATE_THRESHOLD) { // We cannot set the date too soon, but we can leave it empty. return new lang_string('errorcannotsetduedatetoosoon', 'core_competency'); } return true; }
[ "protected", "function", "validate_duedate", "(", "$", "value", ")", "{", "// We do not check duedate when plan is draft, complete, unset, or based on a template.", "if", "(", "$", "this", "->", "is_based_on_template", "(", ")", "||", "$", "this", "->", "is_draft", "(", ")", "||", "$", "this", "->", "get", "(", "'status'", ")", "==", "self", "::", "STATUS_COMPLETE", "||", "empty", "(", "$", "value", ")", ")", "{", "return", "true", ";", "}", "// During update.", "if", "(", "$", "this", "->", "get", "(", "'id'", ")", ")", "{", "$", "before", "=", "$", "this", "->", "beforeupdate", "->", "get", "(", "'duedate'", ")", ";", "$", "beforestatus", "=", "$", "this", "->", "beforeupdate", "->", "get", "(", "'status'", ")", ";", "// The value has not changed, then it's always OK. Though if we're going", "// from draft to active it has to has to be validated.", "if", "(", "$", "before", "==", "$", "value", "&&", "!", "in_array", "(", "$", "beforestatus", ",", "self", "::", "get_draft_statuses", "(", ")", ")", ")", "{", "return", "true", ";", "}", "}", "if", "(", "$", "value", "<=", "time", "(", ")", ")", "{", "// We cannot set the date in the past.", "return", "new", "lang_string", "(", "'errorcannotsetduedateinthepast'", ",", "'core_competency'", ")", ";", "}", "if", "(", "$", "value", "<=", "time", "(", ")", "+", "self", "::", "DUEDATE_THRESHOLD", ")", "{", "// We cannot set the date too soon, but we can leave it empty.", "return", "new", "lang_string", "(", "'errorcannotsetduedatetoosoon'", ",", "'core_competency'", ")", ";", "}", "return", "true", ";", "}" ]
Validate the due date. When setting a due date it must not exceed the DUEDATE_THRESHOLD. @param int $value The due date. @return bool|lang_string
[ "Validate", "the", "due", "date", ".", "When", "setting", "a", "due", "date", "it", "must", "not", "exceed", "the", "DUEDATE_THRESHOLD", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L638-L671
215,959
moodle/moodle
competency/classes/plan.php
plan.count_records_for_template
public static function count_records_for_template($templateid, $status) { $filters = array('templateid' => $templateid); if ($status > 0) { $filters['status'] = $status; } return self::count_records($filters); }
php
public static function count_records_for_template($templateid, $status) { $filters = array('templateid' => $templateid); if ($status > 0) { $filters['status'] = $status; } return self::count_records($filters); }
[ "public", "static", "function", "count_records_for_template", "(", "$", "templateid", ",", "$", "status", ")", "{", "$", "filters", "=", "array", "(", "'templateid'", "=>", "$", "templateid", ")", ";", "if", "(", "$", "status", ">", "0", ")", "{", "$", "filters", "[", "'status'", "]", "=", "$", "status", ";", "}", "return", "self", "::", "count_records", "(", "$", "filters", ")", ";", "}" ]
Count the number of plans for a template, optionally filtering by status. @param int $templateid The template ID @param int $status The plan status. 0 means all statuses. @return int
[ "Count", "the", "number", "of", "plans", "for", "a", "template", "optionally", "filtering", "by", "status", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L690-L696
215,960
moodle/moodle
competency/classes/plan.php
plan.get_records_for_template
public static function get_records_for_template($templateid, $status = 0, $skip = 0, $limit = 100) { $filters = array('templateid' => $templateid); if ($status > 0) { $filters['status'] = $status; } return self::get_records($filters, $skip, $limit); }
php
public static function get_records_for_template($templateid, $status = 0, $skip = 0, $limit = 100) { $filters = array('templateid' => $templateid); if ($status > 0) { $filters['status'] = $status; } return self::get_records($filters, $skip, $limit); }
[ "public", "static", "function", "get_records_for_template", "(", "$", "templateid", ",", "$", "status", "=", "0", ",", "$", "skip", "=", "0", ",", "$", "limit", "=", "100", ")", "{", "$", "filters", "=", "array", "(", "'templateid'", "=>", "$", "templateid", ")", ";", "if", "(", "$", "status", ">", "0", ")", "{", "$", "filters", "[", "'status'", "]", "=", "$", "status", ";", "}", "return", "self", "::", "get_records", "(", "$", "filters", ",", "$", "skip", ",", "$", "limit", ")", ";", "}" ]
Get the plans for a template, optionally filtering by status. @param int $templateid The template ID @param int $status The plan status. 0 means all statuses. @param int $skip The number of plans to skip @param int $limit The max number of plans to return @return int
[ "Get", "the", "plans", "for", "a", "template", "optionally", "filtering", "by", "status", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/plan.php#L707-L713
215,961
moodle/moodle
mod/glossary/classes/privacy/provider.php
provider.export_glossary_data_for_user
protected static function export_glossary_data_for_user(array $glossarydata, \context_module $context, array $subcontext, \stdClass $user) { // Fetch the generic module data for the glossary. $contextdata = helper::get_context_data($context, $user); // Merge with glossary data and write it. $contextdata = (object)array_merge((array)$contextdata, $glossarydata); writer::with_context($context)->export_data($subcontext, $contextdata); // Write generic module intro files. helper::export_context_files($context, $user); }
php
protected static function export_glossary_data_for_user(array $glossarydata, \context_module $context, array $subcontext, \stdClass $user) { // Fetch the generic module data for the glossary. $contextdata = helper::get_context_data($context, $user); // Merge with glossary data and write it. $contextdata = (object)array_merge((array)$contextdata, $glossarydata); writer::with_context($context)->export_data($subcontext, $contextdata); // Write generic module intro files. helper::export_context_files($context, $user); }
[ "protected", "static", "function", "export_glossary_data_for_user", "(", "array", "$", "glossarydata", ",", "\\", "context_module", "$", "context", ",", "array", "$", "subcontext", ",", "\\", "stdClass", "$", "user", ")", "{", "// Fetch the generic module data for the glossary.", "$", "contextdata", "=", "helper", "::", "get_context_data", "(", "$", "context", ",", "$", "user", ")", ";", "// Merge with glossary data and write it.", "$", "contextdata", "=", "(", "object", ")", "array_merge", "(", "(", "array", ")", "$", "contextdata", ",", "$", "glossarydata", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "$", "subcontext", ",", "$", "contextdata", ")", ";", "// Write generic module intro files.", "helper", "::", "export_context_files", "(", "$", "context", ",", "$", "user", ")", ";", "}" ]
Export the supplied personal data for a single glossary activity, along with any generic data or area files. @param array $glossarydata The personal data to export for the glossary. @param \context_module $context The context of the glossary. @param array $subcontext The location within the current context that this data belongs. @param \stdClass $user the user record
[ "Export", "the", "supplied", "personal", "data", "for", "a", "single", "glossary", "activity", "along", "with", "any", "generic", "data", "or", "area", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/privacy/provider.php#L308-L317
215,962
moodle/moodle
lib/classes/event/user_password_updated.php
user_password_updated.create_from_user
public static function create_from_user(\stdClass $user, $forgottenreset = false) { $data = array( 'context' => \context_user::instance($user->id), 'relateduserid' => $user->id, 'other' => array('forgottenreset' => $forgottenreset), ); $event = self::create($data); $event->add_record_snapshot('user', $user); return $event; }
php
public static function create_from_user(\stdClass $user, $forgottenreset = false) { $data = array( 'context' => \context_user::instance($user->id), 'relateduserid' => $user->id, 'other' => array('forgottenreset' => $forgottenreset), ); $event = self::create($data); $event->add_record_snapshot('user', $user); return $event; }
[ "public", "static", "function", "create_from_user", "(", "\\", "stdClass", "$", "user", ",", "$", "forgottenreset", "=", "false", ")", "{", "$", "data", "=", "array", "(", "'context'", "=>", "\\", "context_user", "::", "instance", "(", "$", "user", "->", "id", ")", ",", "'relateduserid'", "=>", "$", "user", "->", "id", ",", "'other'", "=>", "array", "(", "'forgottenreset'", "=>", "$", "forgottenreset", ")", ",", ")", ";", "$", "event", "=", "self", "::", "create", "(", "$", "data", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'user'", ",", "$", "user", ")", ";", "return", "$", "event", ";", "}" ]
Create event for user password changing and resetting. @param \stdClass $user @param bool $forgottenreset true if reset via recovery link @return user_password_updated
[ "Create", "event", "for", "user", "password", "changing", "and", "resetting", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/user_password_updated.php#L51-L60
215,963
moodle/moodle
lib/filestorage/file_system_filedir.php
file_system_filedir.get_local_path_from_storedfile
protected function get_local_path_from_storedfile(stored_file $file, $fetchifnotfound = false) { $filepath = $this->get_local_path_from_hash($file->get_contenthash(), $fetchifnotfound); // Try content recovery. if ($fetchifnotfound && !is_readable($filepath)) { $this->recover_file($file); } return $filepath; }
php
protected function get_local_path_from_storedfile(stored_file $file, $fetchifnotfound = false) { $filepath = $this->get_local_path_from_hash($file->get_contenthash(), $fetchifnotfound); // Try content recovery. if ($fetchifnotfound && !is_readable($filepath)) { $this->recover_file($file); } return $filepath; }
[ "protected", "function", "get_local_path_from_storedfile", "(", "stored_file", "$", "file", ",", "$", "fetchifnotfound", "=", "false", ")", "{", "$", "filepath", "=", "$", "this", "->", "get_local_path_from_hash", "(", "$", "file", "->", "get_contenthash", "(", ")", ",", "$", "fetchifnotfound", ")", ";", "// Try content recovery.", "if", "(", "$", "fetchifnotfound", "&&", "!", "is_readable", "(", "$", "filepath", ")", ")", "{", "$", "this", "->", "recover_file", "(", "$", "file", ")", ";", "}", "return", "$", "filepath", ";", "}" ]
Get a remote filepath for the specified stored file. @param stored_file $file The file to fetch the path for @param bool $fetchifnotfound Whether to attempt to fetch from the remote path if not found. @return string The full path to the content file
[ "Get", "a", "remote", "filepath", "for", "the", "specified", "stored", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system_filedir.php#L122-L131
215,964
moodle/moodle
lib/filestorage/file_system_filedir.php
file_system_filedir.copy_content_from_storedfile
public function copy_content_from_storedfile(stored_file $file, $target) { $source = $this->get_local_path_from_storedfile($file, true); return copy($source, $target); }
php
public function copy_content_from_storedfile(stored_file $file, $target) { $source = $this->get_local_path_from_storedfile($file, true); return copy($source, $target); }
[ "public", "function", "copy_content_from_storedfile", "(", "stored_file", "$", "file", ",", "$", "target", ")", "{", "$", "source", "=", "$", "this", "->", "get_local_path_from_storedfile", "(", "$", "file", ",", "true", ")", ";", "return", "copy", "(", "$", "source", ",", "$", "target", ")", ";", "}" ]
Copy content of file to given pathname. @param stored_file $file The file to be copied @param string $target real path to the new file @return bool success
[ "Copy", "content", "of", "file", "to", "given", "pathname", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system_filedir.php#L232-L235
215,965
moodle/moodle
lib/filestorage/file_system_filedir.php
file_system_filedir.recover_file
protected function recover_file(stored_file $file) { $contentfile = $this->get_local_path_from_storedfile($file, false); if (file_exists($contentfile)) { // The file already exists on the file system. No need to recover. return true; } $contenthash = $file->get_contenthash(); $contentdir = $this->get_fulldir_from_storedfile($file); $trashfile = $this->get_trash_fullpath_from_hash($contenthash); $alttrashfile = "{$this->trashdir}/{$contenthash}"; if (!is_readable($trashfile)) { // The trash file was not found. Check the alternative trash file too just in case. if (!is_readable($alttrashfile)) { return false; } // The alternative trash file in trash root exists. $trashfile = $alttrashfile; } if (filesize($trashfile) != $file->get_filesize() or file_storage::hash_from_path($trashfile) != $contenthash) { // The files are different. Leave this one in trash - something seems to be wrong with it. return false; } if (!is_dir($contentdir)) { if (!mkdir($contentdir, $this->dirpermissions, true)) { // Unable to create the target directory. return false; } } // Perform a rename - these are generally atomic which gives us big // performance wins, especially for large files. return rename($trashfile, $contentfile); }
php
protected function recover_file(stored_file $file) { $contentfile = $this->get_local_path_from_storedfile($file, false); if (file_exists($contentfile)) { // The file already exists on the file system. No need to recover. return true; } $contenthash = $file->get_contenthash(); $contentdir = $this->get_fulldir_from_storedfile($file); $trashfile = $this->get_trash_fullpath_from_hash($contenthash); $alttrashfile = "{$this->trashdir}/{$contenthash}"; if (!is_readable($trashfile)) { // The trash file was not found. Check the alternative trash file too just in case. if (!is_readable($alttrashfile)) { return false; } // The alternative trash file in trash root exists. $trashfile = $alttrashfile; } if (filesize($trashfile) != $file->get_filesize() or file_storage::hash_from_path($trashfile) != $contenthash) { // The files are different. Leave this one in trash - something seems to be wrong with it. return false; } if (!is_dir($contentdir)) { if (!mkdir($contentdir, $this->dirpermissions, true)) { // Unable to create the target directory. return false; } } // Perform a rename - these are generally atomic which gives us big // performance wins, especially for large files. return rename($trashfile, $contentfile); }
[ "protected", "function", "recover_file", "(", "stored_file", "$", "file", ")", "{", "$", "contentfile", "=", "$", "this", "->", "get_local_path_from_storedfile", "(", "$", "file", ",", "false", ")", ";", "if", "(", "file_exists", "(", "$", "contentfile", ")", ")", "{", "// The file already exists on the file system. No need to recover.", "return", "true", ";", "}", "$", "contenthash", "=", "$", "file", "->", "get_contenthash", "(", ")", ";", "$", "contentdir", "=", "$", "this", "->", "get_fulldir_from_storedfile", "(", "$", "file", ")", ";", "$", "trashfile", "=", "$", "this", "->", "get_trash_fullpath_from_hash", "(", "$", "contenthash", ")", ";", "$", "alttrashfile", "=", "\"{$this->trashdir}/{$contenthash}\"", ";", "if", "(", "!", "is_readable", "(", "$", "trashfile", ")", ")", "{", "// The trash file was not found. Check the alternative trash file too just in case.", "if", "(", "!", "is_readable", "(", "$", "alttrashfile", ")", ")", "{", "return", "false", ";", "}", "// The alternative trash file in trash root exists.", "$", "trashfile", "=", "$", "alttrashfile", ";", "}", "if", "(", "filesize", "(", "$", "trashfile", ")", "!=", "$", "file", "->", "get_filesize", "(", ")", "or", "file_storage", "::", "hash_from_path", "(", "$", "trashfile", ")", "!=", "$", "contenthash", ")", "{", "// The files are different. Leave this one in trash - something seems to be wrong with it.", "return", "false", ";", "}", "if", "(", "!", "is_dir", "(", "$", "contentdir", ")", ")", "{", "if", "(", "!", "mkdir", "(", "$", "contentdir", ",", "$", "this", "->", "dirpermissions", ",", "true", ")", ")", "{", "// Unable to create the target directory.", "return", "false", ";", "}", "}", "// Perform a rename - these are generally atomic which gives us big", "// performance wins, especially for large files.", "return", "rename", "(", "$", "trashfile", ",", "$", "contentfile", ")", ";", "}" ]
Tries to recover missing content of file from trash. @param stored_file $file stored_file instance @return bool success
[ "Tries", "to", "recover", "missing", "content", "of", "file", "from", "trash", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system_filedir.php#L243-L280
215,966
moodle/moodle
lib/filestorage/file_system_filedir.php
file_system_filedir.remove_file
public function remove_file($contenthash) { if (!self::is_file_removable($contenthash)) { // Don't remove the file - it's still in use. return; } if (!$this->is_file_readable_remotely_by_hash($contenthash)) { // The file wasn't found in the first place. Just ignore it. return; } $trashpath = $this->get_trash_fulldir_from_hash($contenthash); $trashfile = $this->get_trash_fullpath_from_hash($contenthash); $contentfile = $this->get_local_path_from_hash($contenthash, true); if (!is_dir($trashpath)) { mkdir($trashpath, $this->dirpermissions, true); } if (file_exists($trashfile)) { // A copy of this file is already in the trash. // Remove the old version. unlink($contentfile); return; } // Move the contentfile to the trash, and fix permissions as required. rename($contentfile, $trashfile); // Fix permissions, only if needed. $currentperms = octdec(substr(decoct(fileperms($trashfile)), -4)); if ((int)$this->filepermissions !== $currentperms) { chmod($trashfile, $this->filepermissions); } }
php
public function remove_file($contenthash) { if (!self::is_file_removable($contenthash)) { // Don't remove the file - it's still in use. return; } if (!$this->is_file_readable_remotely_by_hash($contenthash)) { // The file wasn't found in the first place. Just ignore it. return; } $trashpath = $this->get_trash_fulldir_from_hash($contenthash); $trashfile = $this->get_trash_fullpath_from_hash($contenthash); $contentfile = $this->get_local_path_from_hash($contenthash, true); if (!is_dir($trashpath)) { mkdir($trashpath, $this->dirpermissions, true); } if (file_exists($trashfile)) { // A copy of this file is already in the trash. // Remove the old version. unlink($contentfile); return; } // Move the contentfile to the trash, and fix permissions as required. rename($contentfile, $trashfile); // Fix permissions, only if needed. $currentperms = octdec(substr(decoct(fileperms($trashfile)), -4)); if ((int)$this->filepermissions !== $currentperms) { chmod($trashfile, $this->filepermissions); } }
[ "public", "function", "remove_file", "(", "$", "contenthash", ")", "{", "if", "(", "!", "self", "::", "is_file_removable", "(", "$", "contenthash", ")", ")", "{", "// Don't remove the file - it's still in use.", "return", ";", "}", "if", "(", "!", "$", "this", "->", "is_file_readable_remotely_by_hash", "(", "$", "contenthash", ")", ")", "{", "// The file wasn't found in the first place. Just ignore it.", "return", ";", "}", "$", "trashpath", "=", "$", "this", "->", "get_trash_fulldir_from_hash", "(", "$", "contenthash", ")", ";", "$", "trashfile", "=", "$", "this", "->", "get_trash_fullpath_from_hash", "(", "$", "contenthash", ")", ";", "$", "contentfile", "=", "$", "this", "->", "get_local_path_from_hash", "(", "$", "contenthash", ",", "true", ")", ";", "if", "(", "!", "is_dir", "(", "$", "trashpath", ")", ")", "{", "mkdir", "(", "$", "trashpath", ",", "$", "this", "->", "dirpermissions", ",", "true", ")", ";", "}", "if", "(", "file_exists", "(", "$", "trashfile", ")", ")", "{", "// A copy of this file is already in the trash.", "// Remove the old version.", "unlink", "(", "$", "contentfile", ")", ";", "return", ";", "}", "// Move the contentfile to the trash, and fix permissions as required.", "rename", "(", "$", "contentfile", ",", "$", "trashfile", ")", ";", "// Fix permissions, only if needed.", "$", "currentperms", "=", "octdec", "(", "substr", "(", "decoct", "(", "fileperms", "(", "$", "trashfile", ")", ")", ",", "-", "4", ")", ")", ";", "if", "(", "(", "int", ")", "$", "this", "->", "filepermissions", "!==", "$", "currentperms", ")", "{", "chmod", "(", "$", "trashfile", ",", "$", "this", "->", "filepermissions", ")", ";", "}", "}" ]
Marks pool file as candidate for deleting. @param string $contenthash
[ "Marks", "pool", "file", "as", "candidate", "for", "deleting", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system_filedir.php#L287-L321
215,967
moodle/moodle
lib/filestorage/file_system_filedir.php
file_system_filedir.add_file_from_path
public function add_file_from_path($pathname, $contenthash = null) { list($contenthash, $filesize) = $this->validate_hash_and_file_size($contenthash, $pathname); $hashpath = $this->get_fulldir_from_hash($contenthash); $hashfile = $this->get_local_path_from_hash($contenthash, false); $newfile = true; if (file_exists($hashfile)) { if (filesize($hashfile) === $filesize) { return array($contenthash, $filesize, false); } if (file_storage::hash_from_path($hashfile) === $contenthash) { // Jackpot! We have a hash collision. mkdir("$this->filedir/jackpot/", $this->dirpermissions, true); copy($pathname, "$this->filedir/jackpot/{$contenthash}_1"); copy($hashfile, "$this->filedir/jackpot/{$contenthash}_2"); throw new file_pool_content_exception($contenthash); } debugging("Replacing invalid content file $contenthash"); unlink($hashfile); $newfile = false; } if (!is_dir($hashpath)) { if (!mkdir($hashpath, $this->dirpermissions, true)) { // Permission trouble. throw new file_exception('storedfilecannotcreatefiledirs'); } } // Let's try to prevent some race conditions. $prev = ignore_user_abort(true); @unlink($hashfile.'.tmp'); if (!copy($pathname, $hashfile.'.tmp')) { // Borked permissions or out of disk space. @unlink($hashfile.'.tmp'); ignore_user_abort($prev); throw new file_exception('storedfilecannotcreatefile'); } if (file_storage::hash_from_path($hashfile.'.tmp') !== $contenthash) { // Highly unlikely edge case, but this can happen on an NFS volume with no space remaining. @unlink($hashfile.'.tmp'); ignore_user_abort($prev); throw new file_exception('storedfilecannotcreatefile'); } rename($hashfile.'.tmp', $hashfile); chmod($hashfile, $this->filepermissions); // Fix permissions if needed. @unlink($hashfile.'.tmp'); // Just in case anything fails in a weird way. ignore_user_abort($prev); return array($contenthash, $filesize, $newfile); }
php
public function add_file_from_path($pathname, $contenthash = null) { list($contenthash, $filesize) = $this->validate_hash_and_file_size($contenthash, $pathname); $hashpath = $this->get_fulldir_from_hash($contenthash); $hashfile = $this->get_local_path_from_hash($contenthash, false); $newfile = true; if (file_exists($hashfile)) { if (filesize($hashfile) === $filesize) { return array($contenthash, $filesize, false); } if (file_storage::hash_from_path($hashfile) === $contenthash) { // Jackpot! We have a hash collision. mkdir("$this->filedir/jackpot/", $this->dirpermissions, true); copy($pathname, "$this->filedir/jackpot/{$contenthash}_1"); copy($hashfile, "$this->filedir/jackpot/{$contenthash}_2"); throw new file_pool_content_exception($contenthash); } debugging("Replacing invalid content file $contenthash"); unlink($hashfile); $newfile = false; } if (!is_dir($hashpath)) { if (!mkdir($hashpath, $this->dirpermissions, true)) { // Permission trouble. throw new file_exception('storedfilecannotcreatefiledirs'); } } // Let's try to prevent some race conditions. $prev = ignore_user_abort(true); @unlink($hashfile.'.tmp'); if (!copy($pathname, $hashfile.'.tmp')) { // Borked permissions or out of disk space. @unlink($hashfile.'.tmp'); ignore_user_abort($prev); throw new file_exception('storedfilecannotcreatefile'); } if (file_storage::hash_from_path($hashfile.'.tmp') !== $contenthash) { // Highly unlikely edge case, but this can happen on an NFS volume with no space remaining. @unlink($hashfile.'.tmp'); ignore_user_abort($prev); throw new file_exception('storedfilecannotcreatefile'); } rename($hashfile.'.tmp', $hashfile); chmod($hashfile, $this->filepermissions); // Fix permissions if needed. @unlink($hashfile.'.tmp'); // Just in case anything fails in a weird way. ignore_user_abort($prev); return array($contenthash, $filesize, $newfile); }
[ "public", "function", "add_file_from_path", "(", "$", "pathname", ",", "$", "contenthash", "=", "null", ")", "{", "list", "(", "$", "contenthash", ",", "$", "filesize", ")", "=", "$", "this", "->", "validate_hash_and_file_size", "(", "$", "contenthash", ",", "$", "pathname", ")", ";", "$", "hashpath", "=", "$", "this", "->", "get_fulldir_from_hash", "(", "$", "contenthash", ")", ";", "$", "hashfile", "=", "$", "this", "->", "get_local_path_from_hash", "(", "$", "contenthash", ",", "false", ")", ";", "$", "newfile", "=", "true", ";", "if", "(", "file_exists", "(", "$", "hashfile", ")", ")", "{", "if", "(", "filesize", "(", "$", "hashfile", ")", "===", "$", "filesize", ")", "{", "return", "array", "(", "$", "contenthash", ",", "$", "filesize", ",", "false", ")", ";", "}", "if", "(", "file_storage", "::", "hash_from_path", "(", "$", "hashfile", ")", "===", "$", "contenthash", ")", "{", "// Jackpot! We have a hash collision.", "mkdir", "(", "\"$this->filedir/jackpot/\"", ",", "$", "this", "->", "dirpermissions", ",", "true", ")", ";", "copy", "(", "$", "pathname", ",", "\"$this->filedir/jackpot/{$contenthash}_1\"", ")", ";", "copy", "(", "$", "hashfile", ",", "\"$this->filedir/jackpot/{$contenthash}_2\"", ")", ";", "throw", "new", "file_pool_content_exception", "(", "$", "contenthash", ")", ";", "}", "debugging", "(", "\"Replacing invalid content file $contenthash\"", ")", ";", "unlink", "(", "$", "hashfile", ")", ";", "$", "newfile", "=", "false", ";", "}", "if", "(", "!", "is_dir", "(", "$", "hashpath", ")", ")", "{", "if", "(", "!", "mkdir", "(", "$", "hashpath", ",", "$", "this", "->", "dirpermissions", ",", "true", ")", ")", "{", "// Permission trouble.", "throw", "new", "file_exception", "(", "'storedfilecannotcreatefiledirs'", ")", ";", "}", "}", "// Let's try to prevent some race conditions.", "$", "prev", "=", "ignore_user_abort", "(", "true", ")", ";", "@", "unlink", "(", "$", "hashfile", ".", "'.tmp'", ")", ";", "if", "(", "!", "copy", "(", "$", "pathname", ",", "$", "hashfile", ".", "'.tmp'", ")", ")", "{", "// Borked permissions or out of disk space.", "@", "unlink", "(", "$", "hashfile", ".", "'.tmp'", ")", ";", "ignore_user_abort", "(", "$", "prev", ")", ";", "throw", "new", "file_exception", "(", "'storedfilecannotcreatefile'", ")", ";", "}", "if", "(", "file_storage", "::", "hash_from_path", "(", "$", "hashfile", ".", "'.tmp'", ")", "!==", "$", "contenthash", ")", "{", "// Highly unlikely edge case, but this can happen on an NFS volume with no space remaining.", "@", "unlink", "(", "$", "hashfile", ".", "'.tmp'", ")", ";", "ignore_user_abort", "(", "$", "prev", ")", ";", "throw", "new", "file_exception", "(", "'storedfilecannotcreatefile'", ")", ";", "}", "rename", "(", "$", "hashfile", ".", "'.tmp'", ",", "$", "hashfile", ")", ";", "chmod", "(", "$", "hashfile", ",", "$", "this", "->", "filepermissions", ")", ";", "// Fix permissions if needed.", "@", "unlink", "(", "$", "hashfile", ".", "'.tmp'", ")", ";", "// Just in case anything fails in a weird way.", "ignore_user_abort", "(", "$", "prev", ")", ";", "return", "array", "(", "$", "contenthash", ",", "$", "filesize", ",", "$", "newfile", ")", ";", "}" ]
Add the supplied file to the file system. Note: If overriding this function, it is advisable to store the file in the path returned by get_local_path_from_hash as there may be subsequent uses of the file in the same request. @param string $pathname Path to file currently on disk @param string $contenthash SHA1 hash of content if known (performance only) @return array (contenthash, filesize, newfile)
[ "Add", "the", "supplied", "file", "to", "the", "file", "system", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system_filedir.php#L346-L400
215,968
moodle/moodle
lib/filestorage/file_system_filedir.php
file_system_filedir.add_file_from_string
public function add_file_from_string($content) { global $CFG; $contenthash = file_storage::hash_from_string($content); // Binary length. $filesize = strlen($content); $hashpath = $this->get_fulldir_from_hash($contenthash); $hashfile = $this->get_local_path_from_hash($contenthash, false); $newfile = true; if (file_exists($hashfile)) { if (filesize($hashfile) === $filesize) { return array($contenthash, $filesize, false); } if (file_storage::hash_from_path($hashfile) === $contenthash) { // Jackpot! We have a hash collision. mkdir("$this->filedir/jackpot/", $this->dirpermissions, true); copy($hashfile, "$this->filedir/jackpot/{$contenthash}_1"); file_put_contents("$this->filedir/jackpot/{$contenthash}_2", $content); throw new file_pool_content_exception($contenthash); } debugging("Replacing invalid content file $contenthash"); unlink($hashfile); $newfile = false; } if (!is_dir($hashpath)) { if (!mkdir($hashpath, $this->dirpermissions, true)) { // Permission trouble. throw new file_exception('storedfilecannotcreatefiledirs'); } } // Hopefully this works around most potential race conditions. $prev = ignore_user_abort(true); if (!empty($CFG->preventfilelocking)) { $newsize = file_put_contents($hashfile.'.tmp', $content); } else { $newsize = file_put_contents($hashfile.'.tmp', $content, LOCK_EX); } if ($newsize === false) { // Borked permissions most likely. ignore_user_abort($prev); throw new file_exception('storedfilecannotcreatefile'); } if (filesize($hashfile.'.tmp') !== $filesize) { // Out of disk space? unlink($hashfile.'.tmp'); ignore_user_abort($prev); throw new file_exception('storedfilecannotcreatefile'); } rename($hashfile.'.tmp', $hashfile); chmod($hashfile, $this->filepermissions); // Fix permissions if needed. @unlink($hashfile.'.tmp'); // Just in case anything fails in a weird way. ignore_user_abort($prev); return array($contenthash, $filesize, $newfile); }
php
public function add_file_from_string($content) { global $CFG; $contenthash = file_storage::hash_from_string($content); // Binary length. $filesize = strlen($content); $hashpath = $this->get_fulldir_from_hash($contenthash); $hashfile = $this->get_local_path_from_hash($contenthash, false); $newfile = true; if (file_exists($hashfile)) { if (filesize($hashfile) === $filesize) { return array($contenthash, $filesize, false); } if (file_storage::hash_from_path($hashfile) === $contenthash) { // Jackpot! We have a hash collision. mkdir("$this->filedir/jackpot/", $this->dirpermissions, true); copy($hashfile, "$this->filedir/jackpot/{$contenthash}_1"); file_put_contents("$this->filedir/jackpot/{$contenthash}_2", $content); throw new file_pool_content_exception($contenthash); } debugging("Replacing invalid content file $contenthash"); unlink($hashfile); $newfile = false; } if (!is_dir($hashpath)) { if (!mkdir($hashpath, $this->dirpermissions, true)) { // Permission trouble. throw new file_exception('storedfilecannotcreatefiledirs'); } } // Hopefully this works around most potential race conditions. $prev = ignore_user_abort(true); if (!empty($CFG->preventfilelocking)) { $newsize = file_put_contents($hashfile.'.tmp', $content); } else { $newsize = file_put_contents($hashfile.'.tmp', $content, LOCK_EX); } if ($newsize === false) { // Borked permissions most likely. ignore_user_abort($prev); throw new file_exception('storedfilecannotcreatefile'); } if (filesize($hashfile.'.tmp') !== $filesize) { // Out of disk space? unlink($hashfile.'.tmp'); ignore_user_abort($prev); throw new file_exception('storedfilecannotcreatefile'); } rename($hashfile.'.tmp', $hashfile); chmod($hashfile, $this->filepermissions); // Fix permissions if needed. @unlink($hashfile.'.tmp'); // Just in case anything fails in a weird way. ignore_user_abort($prev); return array($contenthash, $filesize, $newfile); }
[ "public", "function", "add_file_from_string", "(", "$", "content", ")", "{", "global", "$", "CFG", ";", "$", "contenthash", "=", "file_storage", "::", "hash_from_string", "(", "$", "content", ")", ";", "// Binary length.", "$", "filesize", "=", "strlen", "(", "$", "content", ")", ";", "$", "hashpath", "=", "$", "this", "->", "get_fulldir_from_hash", "(", "$", "contenthash", ")", ";", "$", "hashfile", "=", "$", "this", "->", "get_local_path_from_hash", "(", "$", "contenthash", ",", "false", ")", ";", "$", "newfile", "=", "true", ";", "if", "(", "file_exists", "(", "$", "hashfile", ")", ")", "{", "if", "(", "filesize", "(", "$", "hashfile", ")", "===", "$", "filesize", ")", "{", "return", "array", "(", "$", "contenthash", ",", "$", "filesize", ",", "false", ")", ";", "}", "if", "(", "file_storage", "::", "hash_from_path", "(", "$", "hashfile", ")", "===", "$", "contenthash", ")", "{", "// Jackpot! We have a hash collision.", "mkdir", "(", "\"$this->filedir/jackpot/\"", ",", "$", "this", "->", "dirpermissions", ",", "true", ")", ";", "copy", "(", "$", "hashfile", ",", "\"$this->filedir/jackpot/{$contenthash}_1\"", ")", ";", "file_put_contents", "(", "\"$this->filedir/jackpot/{$contenthash}_2\"", ",", "$", "content", ")", ";", "throw", "new", "file_pool_content_exception", "(", "$", "contenthash", ")", ";", "}", "debugging", "(", "\"Replacing invalid content file $contenthash\"", ")", ";", "unlink", "(", "$", "hashfile", ")", ";", "$", "newfile", "=", "false", ";", "}", "if", "(", "!", "is_dir", "(", "$", "hashpath", ")", ")", "{", "if", "(", "!", "mkdir", "(", "$", "hashpath", ",", "$", "this", "->", "dirpermissions", ",", "true", ")", ")", "{", "// Permission trouble.", "throw", "new", "file_exception", "(", "'storedfilecannotcreatefiledirs'", ")", ";", "}", "}", "// Hopefully this works around most potential race conditions.", "$", "prev", "=", "ignore_user_abort", "(", "true", ")", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "preventfilelocking", ")", ")", "{", "$", "newsize", "=", "file_put_contents", "(", "$", "hashfile", ".", "'.tmp'", ",", "$", "content", ")", ";", "}", "else", "{", "$", "newsize", "=", "file_put_contents", "(", "$", "hashfile", ".", "'.tmp'", ",", "$", "content", ",", "LOCK_EX", ")", ";", "}", "if", "(", "$", "newsize", "===", "false", ")", "{", "// Borked permissions most likely.", "ignore_user_abort", "(", "$", "prev", ")", ";", "throw", "new", "file_exception", "(", "'storedfilecannotcreatefile'", ")", ";", "}", "if", "(", "filesize", "(", "$", "hashfile", ".", "'.tmp'", ")", "!==", "$", "filesize", ")", "{", "// Out of disk space?", "unlink", "(", "$", "hashfile", ".", "'.tmp'", ")", ";", "ignore_user_abort", "(", "$", "prev", ")", ";", "throw", "new", "file_exception", "(", "'storedfilecannotcreatefile'", ")", ";", "}", "rename", "(", "$", "hashfile", ".", "'.tmp'", ",", "$", "hashfile", ")", ";", "chmod", "(", "$", "hashfile", ",", "$", "this", "->", "filepermissions", ")", ";", "// Fix permissions if needed.", "@", "unlink", "(", "$", "hashfile", ".", "'.tmp'", ")", ";", "// Just in case anything fails in a weird way.", "ignore_user_abort", "(", "$", "prev", ")", ";", "return", "array", "(", "$", "contenthash", ",", "$", "filesize", ",", "$", "newfile", ")", ";", "}" ]
Add a file with the supplied content to the file system. Note: If overriding this function, it is advisable to store the file in the path returned by get_local_path_from_hash as there may be subsequent uses of the file in the same request. @param string $content file content - binary string @return array (contenthash, filesize, newfile)
[ "Add", "a", "file", "with", "the", "supplied", "content", "to", "the", "file", "system", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system_filedir.php#L412-L474
215,969
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.set_theme_suite_to_include_core_features
public function set_theme_suite_to_include_core_features($themetoset) { // If no value passed to --add-core-features-to-theme or ALL is passed, then set core features for all themes. if (!empty($themetoset)) { if (is_number($themetoset) || is_bool($themetoset) || (self::ALL_THEMES_TO_RUN === strtoupper($themetoset))) { $this->themesuitewithallfeatures = self::ALL_THEMES_TO_RUN; } else { $this->themesuitewithallfeatures = explode(',', $themetoset); $this->themesuitewithallfeatures = array_map('trim', $this->themesuitewithallfeatures); } } }
php
public function set_theme_suite_to_include_core_features($themetoset) { // If no value passed to --add-core-features-to-theme or ALL is passed, then set core features for all themes. if (!empty($themetoset)) { if (is_number($themetoset) || is_bool($themetoset) || (self::ALL_THEMES_TO_RUN === strtoupper($themetoset))) { $this->themesuitewithallfeatures = self::ALL_THEMES_TO_RUN; } else { $this->themesuitewithallfeatures = explode(',', $themetoset); $this->themesuitewithallfeatures = array_map('trim', $this->themesuitewithallfeatures); } } }
[ "public", "function", "set_theme_suite_to_include_core_features", "(", "$", "themetoset", ")", "{", "// If no value passed to --add-core-features-to-theme or ALL is passed, then set core features for all themes.", "if", "(", "!", "empty", "(", "$", "themetoset", ")", ")", "{", "if", "(", "is_number", "(", "$", "themetoset", ")", "||", "is_bool", "(", "$", "themetoset", ")", "||", "(", "self", "::", "ALL_THEMES_TO_RUN", "===", "strtoupper", "(", "$", "themetoset", ")", ")", ")", "{", "$", "this", "->", "themesuitewithallfeatures", "=", "self", "::", "ALL_THEMES_TO_RUN", ";", "}", "else", "{", "$", "this", "->", "themesuitewithallfeatures", "=", "explode", "(", "','", ",", "$", "themetoset", ")", ";", "$", "this", "->", "themesuitewithallfeatures", "=", "array_map", "(", "'trim'", ",", "$", "this", "->", "themesuitewithallfeatures", ")", ";", "}", "}", "}" ]
Set value for theme suite to include all core features. This should be used if your want all core features to be run with theme. @param bool $themetoset
[ "Set", "value", "for", "theme", "suite", "to", "include", "all", "core", "features", ".", "This", "should", "be", "used", "if", "your", "want", "all", "core", "features", "to", "be", "run", "with", "theme", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L99-L109
215,970
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.set_parallel_run
public function set_parallel_run($parallelruns, $currentrun) { if ($parallelruns < $currentrun) { behat_error(BEHAT_EXITCODE_REQUIREMENT, 'Parallel runs('.$parallelruns.') should be more then current run('.$currentrun.')'); } $this->parallelruns = $parallelruns; $this->currentrun = $currentrun; }
php
public function set_parallel_run($parallelruns, $currentrun) { if ($parallelruns < $currentrun) { behat_error(BEHAT_EXITCODE_REQUIREMENT, 'Parallel runs('.$parallelruns.') should be more then current run('.$currentrun.')'); } $this->parallelruns = $parallelruns; $this->currentrun = $currentrun; }
[ "public", "function", "set_parallel_run", "(", "$", "parallelruns", ",", "$", "currentrun", ")", "{", "if", "(", "$", "parallelruns", "<", "$", "currentrun", ")", "{", "behat_error", "(", "BEHAT_EXITCODE_REQUIREMENT", ",", "'Parallel runs('", ".", "$", "parallelruns", ".", "') should be more then current run('", ".", "$", "currentrun", ".", "')'", ")", ";", "}", "$", "this", "->", "parallelruns", "=", "$", "parallelruns", ";", "$", "this", "->", "currentrun", "=", "$", "currentrun", ";", "}" ]
Set parallel run to be used for generating config. @param int $parallelruns number of parallel runs. @param int $currentrun current run
[ "Set", "parallel", "run", "to", "be", "used", "for", "generating", "config", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L126-L135
215,971
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.get_number_of_parallel_run
public function get_number_of_parallel_run() { // Get number of parallel runs if not passed. if (empty($this->parallelruns) && ($this->parallelruns !== false)) { $this->parallelruns = behat_config_manager::get_behat_run_config_value('parallel'); } return $this->parallelruns; }
php
public function get_number_of_parallel_run() { // Get number of parallel runs if not passed. if (empty($this->parallelruns) && ($this->parallelruns !== false)) { $this->parallelruns = behat_config_manager::get_behat_run_config_value('parallel'); } return $this->parallelruns; }
[ "public", "function", "get_number_of_parallel_run", "(", ")", "{", "// Get number of parallel runs if not passed.", "if", "(", "empty", "(", "$", "this", "->", "parallelruns", ")", "&&", "(", "$", "this", "->", "parallelruns", "!==", "false", ")", ")", "{", "$", "this", "->", "parallelruns", "=", "behat_config_manager", "::", "get_behat_run_config_value", "(", "'parallel'", ")", ";", "}", "return", "$", "this", "->", "parallelruns", ";", "}" ]
Return parallel runs @return int number of parallel runs.
[ "Return", "parallel", "runs" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L142-L149
215,972
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.get_current_run
public function get_current_run() { global $CFG; // Get number of parallel runs if not passed. if (empty($this->currentrun) && ($this->currentrun !== false) && !empty($CFG->behatrunprocess)) { $this->currentrun = $CFG->behatrunprocess; } return $this->currentrun; }
php
public function get_current_run() { global $CFG; // Get number of parallel runs if not passed. if (empty($this->currentrun) && ($this->currentrun !== false) && !empty($CFG->behatrunprocess)) { $this->currentrun = $CFG->behatrunprocess; } return $this->currentrun; }
[ "public", "function", "get_current_run", "(", ")", "{", "global", "$", "CFG", ";", "// Get number of parallel runs if not passed.", "if", "(", "empty", "(", "$", "this", "->", "currentrun", ")", "&&", "(", "$", "this", "->", "currentrun", "!==", "false", ")", "&&", "!", "empty", "(", "$", "CFG", "->", "behatrunprocess", ")", ")", "{", "$", "this", "->", "currentrun", "=", "$", "CFG", "->", "behatrunprocess", ";", "}", "return", "$", "this", "->", "currentrun", ";", "}" ]
Return current run @return int current run.
[ "Return", "current", "run" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L156-L165
215,973
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.get_components_features
public function get_components_features($tags = '') { global $CFG; // If we already have a list created then just return that, as it's up-to-date. // If tags are passed then it's a new filter of features we need. if (!empty($this->features) && empty($tags)) { return $this->features; } // Gets all the components with features. $features = array(); $featurespaths = array(); $components = $this->get_components_with_tests(); if ($components) { foreach ($components as $componentname => $path) { $path = $this->clean_path($path) . self::get_behat_tests_path(); if (empty($featurespaths[$path]) && file_exists($path)) { list($key, $featurepath) = $this->get_clean_feature_key_and_path($path); $featurespaths[$key] = $featurepath; } } foreach ($featurespaths as $path) { $additional = glob("$path/*.feature"); $additionalfeatures = array(); foreach ($additional as $featurepath) { list($key, $path) = $this->get_clean_feature_key_and_path($featurepath); $additionalfeatures[$key] = $path; } $features = array_merge($features, $additionalfeatures); } } // Optionally include features from additional directories. if (!empty($CFG->behat_additionalfeatures)) { $additional = array_map("realpath", $CFG->behat_additionalfeatures); $additionalfeatures = array(); foreach ($additional as $featurepath) { list($key, $path) = $this->get_clean_feature_key_and_path($featurepath); $additionalfeatures[$key] = $path; } $features = array_merge($features, $additionalfeatures); } // Sanitize feature key. $cleanfeatures = array(); foreach ($features as $featurepath) { list($key, $path) = $this->get_clean_feature_key_and_path($featurepath); $cleanfeatures[$key] = $path; } // Sort feature list. ksort($cleanfeatures); $this->features = $cleanfeatures; // If tags are passed then filter features which has sepecified tags. if (!empty($tags)) { $cleanfeatures = $this->filtered_features_with_tags($cleanfeatures, $tags); } return $cleanfeatures; }
php
public function get_components_features($tags = '') { global $CFG; // If we already have a list created then just return that, as it's up-to-date. // If tags are passed then it's a new filter of features we need. if (!empty($this->features) && empty($tags)) { return $this->features; } // Gets all the components with features. $features = array(); $featurespaths = array(); $components = $this->get_components_with_tests(); if ($components) { foreach ($components as $componentname => $path) { $path = $this->clean_path($path) . self::get_behat_tests_path(); if (empty($featurespaths[$path]) && file_exists($path)) { list($key, $featurepath) = $this->get_clean_feature_key_and_path($path); $featurespaths[$key] = $featurepath; } } foreach ($featurespaths as $path) { $additional = glob("$path/*.feature"); $additionalfeatures = array(); foreach ($additional as $featurepath) { list($key, $path) = $this->get_clean_feature_key_and_path($featurepath); $additionalfeatures[$key] = $path; } $features = array_merge($features, $additionalfeatures); } } // Optionally include features from additional directories. if (!empty($CFG->behat_additionalfeatures)) { $additional = array_map("realpath", $CFG->behat_additionalfeatures); $additionalfeatures = array(); foreach ($additional as $featurepath) { list($key, $path) = $this->get_clean_feature_key_and_path($featurepath); $additionalfeatures[$key] = $path; } $features = array_merge($features, $additionalfeatures); } // Sanitize feature key. $cleanfeatures = array(); foreach ($features as $featurepath) { list($key, $path) = $this->get_clean_feature_key_and_path($featurepath); $cleanfeatures[$key] = $path; } // Sort feature list. ksort($cleanfeatures); $this->features = $cleanfeatures; // If tags are passed then filter features which has sepecified tags. if (!empty($tags)) { $cleanfeatures = $this->filtered_features_with_tags($cleanfeatures, $tags); } return $cleanfeatures; }
[ "public", "function", "get_components_features", "(", "$", "tags", "=", "''", ")", "{", "global", "$", "CFG", ";", "// If we already have a list created then just return that, as it's up-to-date.", "// If tags are passed then it's a new filter of features we need.", "if", "(", "!", "empty", "(", "$", "this", "->", "features", ")", "&&", "empty", "(", "$", "tags", ")", ")", "{", "return", "$", "this", "->", "features", ";", "}", "// Gets all the components with features.", "$", "features", "=", "array", "(", ")", ";", "$", "featurespaths", "=", "array", "(", ")", ";", "$", "components", "=", "$", "this", "->", "get_components_with_tests", "(", ")", ";", "if", "(", "$", "components", ")", "{", "foreach", "(", "$", "components", "as", "$", "componentname", "=>", "$", "path", ")", "{", "$", "path", "=", "$", "this", "->", "clean_path", "(", "$", "path", ")", ".", "self", "::", "get_behat_tests_path", "(", ")", ";", "if", "(", "empty", "(", "$", "featurespaths", "[", "$", "path", "]", ")", "&&", "file_exists", "(", "$", "path", ")", ")", "{", "list", "(", "$", "key", ",", "$", "featurepath", ")", "=", "$", "this", "->", "get_clean_feature_key_and_path", "(", "$", "path", ")", ";", "$", "featurespaths", "[", "$", "key", "]", "=", "$", "featurepath", ";", "}", "}", "foreach", "(", "$", "featurespaths", "as", "$", "path", ")", "{", "$", "additional", "=", "glob", "(", "\"$path/*.feature\"", ")", ";", "$", "additionalfeatures", "=", "array", "(", ")", ";", "foreach", "(", "$", "additional", "as", "$", "featurepath", ")", "{", "list", "(", "$", "key", ",", "$", "path", ")", "=", "$", "this", "->", "get_clean_feature_key_and_path", "(", "$", "featurepath", ")", ";", "$", "additionalfeatures", "[", "$", "key", "]", "=", "$", "path", ";", "}", "$", "features", "=", "array_merge", "(", "$", "features", ",", "$", "additionalfeatures", ")", ";", "}", "}", "// Optionally include features from additional directories.", "if", "(", "!", "empty", "(", "$", "CFG", "->", "behat_additionalfeatures", ")", ")", "{", "$", "additional", "=", "array_map", "(", "\"realpath\"", ",", "$", "CFG", "->", "behat_additionalfeatures", ")", ";", "$", "additionalfeatures", "=", "array", "(", ")", ";", "foreach", "(", "$", "additional", "as", "$", "featurepath", ")", "{", "list", "(", "$", "key", ",", "$", "path", ")", "=", "$", "this", "->", "get_clean_feature_key_and_path", "(", "$", "featurepath", ")", ";", "$", "additionalfeatures", "[", "$", "key", "]", "=", "$", "path", ";", "}", "$", "features", "=", "array_merge", "(", "$", "features", ",", "$", "additionalfeatures", ")", ";", "}", "// Sanitize feature key.", "$", "cleanfeatures", "=", "array", "(", ")", ";", "foreach", "(", "$", "features", "as", "$", "featurepath", ")", "{", "list", "(", "$", "key", ",", "$", "path", ")", "=", "$", "this", "->", "get_clean_feature_key_and_path", "(", "$", "featurepath", ")", ";", "$", "cleanfeatures", "[", "$", "key", "]", "=", "$", "path", ";", "}", "// Sort feature list.", "ksort", "(", "$", "cleanfeatures", ")", ";", "$", "this", "->", "features", "=", "$", "cleanfeatures", ";", "// If tags are passed then filter features which has sepecified tags.", "if", "(", "!", "empty", "(", "$", "tags", ")", ")", "{", "$", "cleanfeatures", "=", "$", "this", "->", "filtered_features_with_tags", "(", "$", "cleanfeatures", ",", "$", "tags", ")", ";", "}", "return", "$", "cleanfeatures", ";", "}" ]
Return list of features. @param string $tags tags. @return array
[ "Return", "list", "of", "features", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L173-L237
215,974
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.get_clean_feature_key_and_path
public function get_clean_feature_key_and_path($featurepath) { global $CFG; // Fix directory path. $featurepath = testing_cli_fix_directory_separator($featurepath); $dirroot = testing_cli_fix_directory_separator($CFG->dirroot . DIRECTORY_SEPARATOR); $key = basename($featurepath, '.feature'); // Get relative path. $featuredirname = str_replace($dirroot , '', $featurepath); // Get 5 levels of feature path to ensure we have a unique key. for ($i = 0; $i < 5; $i++) { if (($featuredirname = dirname($featuredirname)) && $featuredirname !== '.') { if ($basename = basename($featuredirname)) { $key .= '_' . $basename; } } } return array($key, $featurepath); }
php
public function get_clean_feature_key_and_path($featurepath) { global $CFG; // Fix directory path. $featurepath = testing_cli_fix_directory_separator($featurepath); $dirroot = testing_cli_fix_directory_separator($CFG->dirroot . DIRECTORY_SEPARATOR); $key = basename($featurepath, '.feature'); // Get relative path. $featuredirname = str_replace($dirroot , '', $featurepath); // Get 5 levels of feature path to ensure we have a unique key. for ($i = 0; $i < 5; $i++) { if (($featuredirname = dirname($featuredirname)) && $featuredirname !== '.') { if ($basename = basename($featuredirname)) { $key .= '_' . $basename; } } } return array($key, $featurepath); }
[ "public", "function", "get_clean_feature_key_and_path", "(", "$", "featurepath", ")", "{", "global", "$", "CFG", ";", "// Fix directory path.", "$", "featurepath", "=", "testing_cli_fix_directory_separator", "(", "$", "featurepath", ")", ";", "$", "dirroot", "=", "testing_cli_fix_directory_separator", "(", "$", "CFG", "->", "dirroot", ".", "DIRECTORY_SEPARATOR", ")", ";", "$", "key", "=", "basename", "(", "$", "featurepath", ",", "'.feature'", ")", ";", "// Get relative path.", "$", "featuredirname", "=", "str_replace", "(", "$", "dirroot", ",", "''", ",", "$", "featurepath", ")", ";", "// Get 5 levels of feature path to ensure we have a unique key.", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "5", ";", "$", "i", "++", ")", "{", "if", "(", "(", "$", "featuredirname", "=", "dirname", "(", "$", "featuredirname", ")", ")", "&&", "$", "featuredirname", "!==", "'.'", ")", "{", "if", "(", "$", "basename", "=", "basename", "(", "$", "featuredirname", ")", ")", "{", "$", "key", ".=", "'_'", ".", "$", "basename", ";", "}", "}", "}", "return", "array", "(", "$", "key", ",", "$", "featurepath", ")", ";", "}" ]
Return feature key for featurepath @param string $featurepath @return array key and featurepath.
[ "Return", "feature", "key", "for", "featurepath" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L245-L266
215,975
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.get_component_contexts
private function get_component_contexts($component) { if (empty($component)) { return $this->contexts; } $componentcontexts = array(); foreach ($this->contexts as $key => $path) { if ($component == '' || $component === $key) { $componentcontexts[$key] = $path; } } return $componentcontexts; }
php
private function get_component_contexts($component) { if (empty($component)) { return $this->contexts; } $componentcontexts = array(); foreach ($this->contexts as $key => $path) { if ($component == '' || $component === $key) { $componentcontexts[$key] = $path; } } return $componentcontexts; }
[ "private", "function", "get_component_contexts", "(", "$", "component", ")", "{", "if", "(", "empty", "(", "$", "component", ")", ")", "{", "return", "$", "this", "->", "contexts", ";", "}", "$", "componentcontexts", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "contexts", "as", "$", "key", "=>", "$", "path", ")", "{", "if", "(", "$", "component", "==", "''", "||", "$", "component", "===", "$", "key", ")", "{", "$", "componentcontexts", "[", "$", "key", "]", "=", "$", "path", ";", "}", "}", "return", "$", "componentcontexts", ";", "}" ]
Get component contexts. @param string $component component name. @return array
[ "Get", "component", "contexts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L274-L288
215,976
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.get_components_contexts
public function get_components_contexts($component = '') { // If we already have a list created then just return that, as it's up-to-date. if (!empty($this->contexts)) { return $this->get_component_contexts($component); } $components = $this->get_components_with_tests(); $this->contexts = array(); foreach ($components as $componentname => $componentpath) { if (false !== strpos($componentname, 'theme_')) { continue; } $componentpath = self::clean_path($componentpath); if (!file_exists($componentpath . self::get_behat_tests_path())) { continue; } $diriterator = new DirectoryIterator($componentpath . self::get_behat_tests_path()); $regite = new RegexIterator($diriterator, '|^behat_.*\.php$|'); // All behat_*.php inside self::get_behat_tests_path() are added as steps definitions files. foreach ($regite as $file) { $key = $file->getBasename('.php'); $this->contexts[$key] = $file->getPathname(); } } // Sort contexts with there name. ksort($this->contexts); return $this->get_component_contexts($component); }
php
public function get_components_contexts($component = '') { // If we already have a list created then just return that, as it's up-to-date. if (!empty($this->contexts)) { return $this->get_component_contexts($component); } $components = $this->get_components_with_tests(); $this->contexts = array(); foreach ($components as $componentname => $componentpath) { if (false !== strpos($componentname, 'theme_')) { continue; } $componentpath = self::clean_path($componentpath); if (!file_exists($componentpath . self::get_behat_tests_path())) { continue; } $diriterator = new DirectoryIterator($componentpath . self::get_behat_tests_path()); $regite = new RegexIterator($diriterator, '|^behat_.*\.php$|'); // All behat_*.php inside self::get_behat_tests_path() are added as steps definitions files. foreach ($regite as $file) { $key = $file->getBasename('.php'); $this->contexts[$key] = $file->getPathname(); } } // Sort contexts with there name. ksort($this->contexts); return $this->get_component_contexts($component); }
[ "public", "function", "get_components_contexts", "(", "$", "component", "=", "''", ")", "{", "// If we already have a list created then just return that, as it's up-to-date.", "if", "(", "!", "empty", "(", "$", "this", "->", "contexts", ")", ")", "{", "return", "$", "this", "->", "get_component_contexts", "(", "$", "component", ")", ";", "}", "$", "components", "=", "$", "this", "->", "get_components_with_tests", "(", ")", ";", "$", "this", "->", "contexts", "=", "array", "(", ")", ";", "foreach", "(", "$", "components", "as", "$", "componentname", "=>", "$", "componentpath", ")", "{", "if", "(", "false", "!==", "strpos", "(", "$", "componentname", ",", "'theme_'", ")", ")", "{", "continue", ";", "}", "$", "componentpath", "=", "self", "::", "clean_path", "(", "$", "componentpath", ")", ";", "if", "(", "!", "file_exists", "(", "$", "componentpath", ".", "self", "::", "get_behat_tests_path", "(", ")", ")", ")", "{", "continue", ";", "}", "$", "diriterator", "=", "new", "DirectoryIterator", "(", "$", "componentpath", ".", "self", "::", "get_behat_tests_path", "(", ")", ")", ";", "$", "regite", "=", "new", "RegexIterator", "(", "$", "diriterator", ",", "'|^behat_.*\\.php$|'", ")", ";", "// All behat_*.php inside self::get_behat_tests_path() are added as steps definitions files.", "foreach", "(", "$", "regite", "as", "$", "file", ")", "{", "$", "key", "=", "$", "file", "->", "getBasename", "(", "'.php'", ")", ";", "$", "this", "->", "contexts", "[", "$", "key", "]", "=", "$", "file", "->", "getPathname", "(", ")", ";", "}", "}", "// Sort contexts with there name.", "ksort", "(", "$", "this", "->", "contexts", ")", ";", "return", "$", "this", "->", "get_component_contexts", "(", "$", "component", ")", ";", "}" ]
Gets the list of Moodle behat contexts Class name as a key and the filepath as value Externalized from update_config_file() to use it from the steps definitions web interface @param string $component Restricts the obtained steps definitions to the specified component @return array
[ "Gets", "the", "list", "of", "Moodle", "behat", "contexts" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L301-L334
215,977
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.get_config_file_contents
public function get_config_file_contents($features = '', $contexts = '', $tags = '', $parallelruns = 0, $currentrun = 0) { global $CFG; // Set current run and parallel run. if (!empty($parallelruns) && !empty($currentrun)) { $this->set_parallel_run($parallelruns, $currentrun); } // If tags defined then use them. This is for BC. if (!empty($tags)) { $this->set_tag_for_feature_filter($tags); } // If features not passed then get it. Empty array means we don't need to include features. if (empty($features) && !is_array($features)) { $features = $this->get_components_features(); } else { $this->features = $features; } // If stepdefinitions not passed then get the list. if (empty($contexts)) { $this->get_components_contexts(); } else { $this->contexts = $contexts; } // We require here when we are sure behat dependencies are available. require_once($CFG->dirroot . '/vendor/autoload.php'); $config = $this->build_config(); $config = $this->merge_behat_config($config); $config = $this->merge_behat_profiles($config); // Return config array for phpunit, so it can be tested. if (defined('PHPUNIT_TEST') && PHPUNIT_TEST) { return $config; } return Symfony\Component\Yaml\Yaml::dump($config, 10, 2); }
php
public function get_config_file_contents($features = '', $contexts = '', $tags = '', $parallelruns = 0, $currentrun = 0) { global $CFG; // Set current run and parallel run. if (!empty($parallelruns) && !empty($currentrun)) { $this->set_parallel_run($parallelruns, $currentrun); } // If tags defined then use them. This is for BC. if (!empty($tags)) { $this->set_tag_for_feature_filter($tags); } // If features not passed then get it. Empty array means we don't need to include features. if (empty($features) && !is_array($features)) { $features = $this->get_components_features(); } else { $this->features = $features; } // If stepdefinitions not passed then get the list. if (empty($contexts)) { $this->get_components_contexts(); } else { $this->contexts = $contexts; } // We require here when we are sure behat dependencies are available. require_once($CFG->dirroot . '/vendor/autoload.php'); $config = $this->build_config(); $config = $this->merge_behat_config($config); $config = $this->merge_behat_profiles($config); // Return config array for phpunit, so it can be tested. if (defined('PHPUNIT_TEST') && PHPUNIT_TEST) { return $config; } return Symfony\Component\Yaml\Yaml::dump($config, 10, 2); }
[ "public", "function", "get_config_file_contents", "(", "$", "features", "=", "''", ",", "$", "contexts", "=", "''", ",", "$", "tags", "=", "''", ",", "$", "parallelruns", "=", "0", ",", "$", "currentrun", "=", "0", ")", "{", "global", "$", "CFG", ";", "// Set current run and parallel run.", "if", "(", "!", "empty", "(", "$", "parallelruns", ")", "&&", "!", "empty", "(", "$", "currentrun", ")", ")", "{", "$", "this", "->", "set_parallel_run", "(", "$", "parallelruns", ",", "$", "currentrun", ")", ";", "}", "// If tags defined then use them. This is for BC.", "if", "(", "!", "empty", "(", "$", "tags", ")", ")", "{", "$", "this", "->", "set_tag_for_feature_filter", "(", "$", "tags", ")", ";", "}", "// If features not passed then get it. Empty array means we don't need to include features.", "if", "(", "empty", "(", "$", "features", ")", "&&", "!", "is_array", "(", "$", "features", ")", ")", "{", "$", "features", "=", "$", "this", "->", "get_components_features", "(", ")", ";", "}", "else", "{", "$", "this", "->", "features", "=", "$", "features", ";", "}", "// If stepdefinitions not passed then get the list.", "if", "(", "empty", "(", "$", "contexts", ")", ")", "{", "$", "this", "->", "get_components_contexts", "(", ")", ";", "}", "else", "{", "$", "this", "->", "contexts", "=", "$", "contexts", ";", "}", "// We require here when we are sure behat dependencies are available.", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/vendor/autoload.php'", ")", ";", "$", "config", "=", "$", "this", "->", "build_config", "(", ")", ";", "$", "config", "=", "$", "this", "->", "merge_behat_config", "(", "$", "config", ")", ";", "$", "config", "=", "$", "this", "->", "merge_behat_profiles", "(", "$", "config", ")", ";", "// Return config array for phpunit, so it can be tested.", "if", "(", "defined", "(", "'PHPUNIT_TEST'", ")", "&&", "PHPUNIT_TEST", ")", "{", "return", "$", "config", ";", "}", "return", "Symfony", "\\", "Component", "\\", "Yaml", "\\", "Yaml", "::", "dump", "(", "$", "config", ",", "10", ",", "2", ")", ";", "}" ]
Behat config file specifing the main context class, the required Behat extensions and Moodle test wwwroot. @param array $features The system feature files @param array $contexts The system steps definitions @param string $tags filter features with specified tags. @param int $parallelruns number of parallel runs. @param int $currentrun current run for which config file is needed. @return string
[ "Behat", "config", "file", "specifing", "the", "main", "context", "class", "the", "required", "Behat", "extensions", "and", "Moodle", "test", "wwwroot", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L347-L389
215,978
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.filtered_features_with_tags
public function filtered_features_with_tags($features = '', $tags = '') { // This is for BC. Features if not passed then we already have a list in this object. if (empty($features)) { $features = $this->features; } // If no tags defined then return full list. if (empty($tags) && empty($this->tags)) { return $features; } // If no tags passed by the caller, then it's already set. if (empty($tags)) { $tags = $this->tags; } $newfeaturelist = array(); // Split tags in and and or. $tags = explode('&&', $tags); $andtags = array(); $ortags = array(); foreach ($tags as $tag) { // Explode all tags seperated by , and add it to ortags. $ortags = array_merge($ortags, explode(',', $tag)); // And tags will be the first one before comma(,). $andtags[] = preg_replace('/,.*/', '', $tag); } foreach ($features as $key => $featurefile) { $contents = file_get_contents($featurefile); $includefeature = true; foreach ($andtags as $tag) { // If negitive tag, then ensure it don't exist. if (strpos($tag, '~') !== false) { $tag = substr($tag, 1); if ($contents && strpos($contents, $tag) !== false) { $includefeature = false; break; } } else if ($contents && strpos($contents, $tag) === false) { $includefeature = false; break; } } // If feature not included then check or tags. if (!$includefeature && !empty($ortags)) { foreach ($ortags as $tag) { if ($contents && (strpos($tag, '~') === false) && (strpos($contents, $tag) !== false)) { $includefeature = true; break; } } } if ($includefeature) { $newfeaturelist[$key] = $featurefile; } } return $newfeaturelist; }
php
public function filtered_features_with_tags($features = '', $tags = '') { // This is for BC. Features if not passed then we already have a list in this object. if (empty($features)) { $features = $this->features; } // If no tags defined then return full list. if (empty($tags) && empty($this->tags)) { return $features; } // If no tags passed by the caller, then it's already set. if (empty($tags)) { $tags = $this->tags; } $newfeaturelist = array(); // Split tags in and and or. $tags = explode('&&', $tags); $andtags = array(); $ortags = array(); foreach ($tags as $tag) { // Explode all tags seperated by , and add it to ortags. $ortags = array_merge($ortags, explode(',', $tag)); // And tags will be the first one before comma(,). $andtags[] = preg_replace('/,.*/', '', $tag); } foreach ($features as $key => $featurefile) { $contents = file_get_contents($featurefile); $includefeature = true; foreach ($andtags as $tag) { // If negitive tag, then ensure it don't exist. if (strpos($tag, '~') !== false) { $tag = substr($tag, 1); if ($contents && strpos($contents, $tag) !== false) { $includefeature = false; break; } } else if ($contents && strpos($contents, $tag) === false) { $includefeature = false; break; } } // If feature not included then check or tags. if (!$includefeature && !empty($ortags)) { foreach ($ortags as $tag) { if ($contents && (strpos($tag, '~') === false) && (strpos($contents, $tag) !== false)) { $includefeature = true; break; } } } if ($includefeature) { $newfeaturelist[$key] = $featurefile; } } return $newfeaturelist; }
[ "public", "function", "filtered_features_with_tags", "(", "$", "features", "=", "''", ",", "$", "tags", "=", "''", ")", "{", "// This is for BC. Features if not passed then we already have a list in this object.", "if", "(", "empty", "(", "$", "features", ")", ")", "{", "$", "features", "=", "$", "this", "->", "features", ";", "}", "// If no tags defined then return full list.", "if", "(", "empty", "(", "$", "tags", ")", "&&", "empty", "(", "$", "this", "->", "tags", ")", ")", "{", "return", "$", "features", ";", "}", "// If no tags passed by the caller, then it's already set.", "if", "(", "empty", "(", "$", "tags", ")", ")", "{", "$", "tags", "=", "$", "this", "->", "tags", ";", "}", "$", "newfeaturelist", "=", "array", "(", ")", ";", "// Split tags in and and or.", "$", "tags", "=", "explode", "(", "'&&'", ",", "$", "tags", ")", ";", "$", "andtags", "=", "array", "(", ")", ";", "$", "ortags", "=", "array", "(", ")", ";", "foreach", "(", "$", "tags", "as", "$", "tag", ")", "{", "// Explode all tags seperated by , and add it to ortags.", "$", "ortags", "=", "array_merge", "(", "$", "ortags", ",", "explode", "(", "','", ",", "$", "tag", ")", ")", ";", "// And tags will be the first one before comma(,).", "$", "andtags", "[", "]", "=", "preg_replace", "(", "'/,.*/'", ",", "''", ",", "$", "tag", ")", ";", "}", "foreach", "(", "$", "features", "as", "$", "key", "=>", "$", "featurefile", ")", "{", "$", "contents", "=", "file_get_contents", "(", "$", "featurefile", ")", ";", "$", "includefeature", "=", "true", ";", "foreach", "(", "$", "andtags", "as", "$", "tag", ")", "{", "// If negitive tag, then ensure it don't exist.", "if", "(", "strpos", "(", "$", "tag", ",", "'~'", ")", "!==", "false", ")", "{", "$", "tag", "=", "substr", "(", "$", "tag", ",", "1", ")", ";", "if", "(", "$", "contents", "&&", "strpos", "(", "$", "contents", ",", "$", "tag", ")", "!==", "false", ")", "{", "$", "includefeature", "=", "false", ";", "break", ";", "}", "}", "else", "if", "(", "$", "contents", "&&", "strpos", "(", "$", "contents", ",", "$", "tag", ")", "===", "false", ")", "{", "$", "includefeature", "=", "false", ";", "break", ";", "}", "}", "// If feature not included then check or tags.", "if", "(", "!", "$", "includefeature", "&&", "!", "empty", "(", "$", "ortags", ")", ")", "{", "foreach", "(", "$", "ortags", "as", "$", "tag", ")", "{", "if", "(", "$", "contents", "&&", "(", "strpos", "(", "$", "tag", ",", "'~'", ")", "===", "false", ")", "&&", "(", "strpos", "(", "$", "contents", ",", "$", "tag", ")", "!==", "false", ")", ")", "{", "$", "includefeature", "=", "true", ";", "break", ";", "}", "}", "}", "if", "(", "$", "includefeature", ")", "{", "$", "newfeaturelist", "[", "$", "key", "]", "=", "$", "featurefile", ";", "}", "}", "return", "$", "newfeaturelist", ";", "}" ]
Search feature files for set of tags. @param array $features set of feature files. @param string $tags list of tags (currently support && only.) @return array filtered list of feature files with tags.
[ "Search", "feature", "files", "for", "set", "of", "tags", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L398-L459
215,979
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.build_config
protected function build_config($parallelruns = 0, $currentrun = 0) { global $CFG; if (!empty($parallelruns) && !empty($currentrun)) { $this->set_parallel_run($parallelruns, $currentrun); } else { $currentrun = $this->get_current_run(); $parallelruns = $this->get_number_of_parallel_run(); } $selenium2wdhost = array('wd_host' => 'http://localhost:4444/wd/hub'); // If parallel run, then set wd_host if specified. if (!empty($currentrun) && !empty($parallelruns)) { // Set proper selenium2 wd_host if defined. if (!empty($CFG->behat_parallel_run[$currentrun - 1]['wd_host'])) { $selenium2wdhost = array('wd_host' => $CFG->behat_parallel_run[$currentrun - 1]['wd_host']); } } // It is possible that it has no value as we don't require a full behat setup to list the step definitions. if (empty($CFG->behat_wwwroot)) { $CFG->behat_wwwroot = 'http://itwillnotbeused.com'; } $suites = $this->get_behat_suites($parallelruns, $currentrun); $selectortypes = ['named_partial', 'named_exact']; $allpaths = []; foreach (array_keys($suites) as $theme) { // Remove selectors from step definitions. foreach ($selectortypes as $selectortype) { // Don't include selector classes. $selectorclass = self::get_behat_theme_selector_override_classname($theme, $selectortype); if (isset($suites[$theme]['contexts'][$selectorclass])) { unset($suites[$theme]['contexts'][$selectorclass]); } } // Get a list of all step definition paths. $allpaths = array_merge($allpaths, $suites[$theme]['contexts']); // Convert the contexts array to a list of names only. $suites[$theme]['contexts'] = array_keys($suites[$theme]['contexts']); } // Comments use black color, so failure path is not visible. Using color other then black/white is safer. // https://github.com/Behat/Behat/pull/628. $config = array( 'default' => array( 'formatters' => array( 'moodle_progress' => array( 'output_styles' => array( 'comment' => array('magenta')) ) ), 'suites' => $suites, 'extensions' => array( 'Behat\MinkExtension' => array( 'base_url' => $CFG->behat_wwwroot, 'goutte' => null, 'selenium2' => $selenium2wdhost ), 'Moodle\BehatExtension' => array( 'moodledirroot' => $CFG->dirroot, 'steps_definitions' => $allpaths, ) ) ) ); return $config; }
php
protected function build_config($parallelruns = 0, $currentrun = 0) { global $CFG; if (!empty($parallelruns) && !empty($currentrun)) { $this->set_parallel_run($parallelruns, $currentrun); } else { $currentrun = $this->get_current_run(); $parallelruns = $this->get_number_of_parallel_run(); } $selenium2wdhost = array('wd_host' => 'http://localhost:4444/wd/hub'); // If parallel run, then set wd_host if specified. if (!empty($currentrun) && !empty($parallelruns)) { // Set proper selenium2 wd_host if defined. if (!empty($CFG->behat_parallel_run[$currentrun - 1]['wd_host'])) { $selenium2wdhost = array('wd_host' => $CFG->behat_parallel_run[$currentrun - 1]['wd_host']); } } // It is possible that it has no value as we don't require a full behat setup to list the step definitions. if (empty($CFG->behat_wwwroot)) { $CFG->behat_wwwroot = 'http://itwillnotbeused.com'; } $suites = $this->get_behat_suites($parallelruns, $currentrun); $selectortypes = ['named_partial', 'named_exact']; $allpaths = []; foreach (array_keys($suites) as $theme) { // Remove selectors from step definitions. foreach ($selectortypes as $selectortype) { // Don't include selector classes. $selectorclass = self::get_behat_theme_selector_override_classname($theme, $selectortype); if (isset($suites[$theme]['contexts'][$selectorclass])) { unset($suites[$theme]['contexts'][$selectorclass]); } } // Get a list of all step definition paths. $allpaths = array_merge($allpaths, $suites[$theme]['contexts']); // Convert the contexts array to a list of names only. $suites[$theme]['contexts'] = array_keys($suites[$theme]['contexts']); } // Comments use black color, so failure path is not visible. Using color other then black/white is safer. // https://github.com/Behat/Behat/pull/628. $config = array( 'default' => array( 'formatters' => array( 'moodle_progress' => array( 'output_styles' => array( 'comment' => array('magenta')) ) ), 'suites' => $suites, 'extensions' => array( 'Behat\MinkExtension' => array( 'base_url' => $CFG->behat_wwwroot, 'goutte' => null, 'selenium2' => $selenium2wdhost ), 'Moodle\BehatExtension' => array( 'moodledirroot' => $CFG->dirroot, 'steps_definitions' => $allpaths, ) ) ) ); return $config; }
[ "protected", "function", "build_config", "(", "$", "parallelruns", "=", "0", ",", "$", "currentrun", "=", "0", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "parallelruns", ")", "&&", "!", "empty", "(", "$", "currentrun", ")", ")", "{", "$", "this", "->", "set_parallel_run", "(", "$", "parallelruns", ",", "$", "currentrun", ")", ";", "}", "else", "{", "$", "currentrun", "=", "$", "this", "->", "get_current_run", "(", ")", ";", "$", "parallelruns", "=", "$", "this", "->", "get_number_of_parallel_run", "(", ")", ";", "}", "$", "selenium2wdhost", "=", "array", "(", "'wd_host'", "=>", "'http://localhost:4444/wd/hub'", ")", ";", "// If parallel run, then set wd_host if specified.", "if", "(", "!", "empty", "(", "$", "currentrun", ")", "&&", "!", "empty", "(", "$", "parallelruns", ")", ")", "{", "// Set proper selenium2 wd_host if defined.", "if", "(", "!", "empty", "(", "$", "CFG", "->", "behat_parallel_run", "[", "$", "currentrun", "-", "1", "]", "[", "'wd_host'", "]", ")", ")", "{", "$", "selenium2wdhost", "=", "array", "(", "'wd_host'", "=>", "$", "CFG", "->", "behat_parallel_run", "[", "$", "currentrun", "-", "1", "]", "[", "'wd_host'", "]", ")", ";", "}", "}", "// It is possible that it has no value as we don't require a full behat setup to list the step definitions.", "if", "(", "empty", "(", "$", "CFG", "->", "behat_wwwroot", ")", ")", "{", "$", "CFG", "->", "behat_wwwroot", "=", "'http://itwillnotbeused.com'", ";", "}", "$", "suites", "=", "$", "this", "->", "get_behat_suites", "(", "$", "parallelruns", ",", "$", "currentrun", ")", ";", "$", "selectortypes", "=", "[", "'named_partial'", ",", "'named_exact'", "]", ";", "$", "allpaths", "=", "[", "]", ";", "foreach", "(", "array_keys", "(", "$", "suites", ")", "as", "$", "theme", ")", "{", "// Remove selectors from step definitions.", "foreach", "(", "$", "selectortypes", "as", "$", "selectortype", ")", "{", "// Don't include selector classes.", "$", "selectorclass", "=", "self", "::", "get_behat_theme_selector_override_classname", "(", "$", "theme", ",", "$", "selectortype", ")", ";", "if", "(", "isset", "(", "$", "suites", "[", "$", "theme", "]", "[", "'contexts'", "]", "[", "$", "selectorclass", "]", ")", ")", "{", "unset", "(", "$", "suites", "[", "$", "theme", "]", "[", "'contexts'", "]", "[", "$", "selectorclass", "]", ")", ";", "}", "}", "// Get a list of all step definition paths.", "$", "allpaths", "=", "array_merge", "(", "$", "allpaths", ",", "$", "suites", "[", "$", "theme", "]", "[", "'contexts'", "]", ")", ";", "// Convert the contexts array to a list of names only.", "$", "suites", "[", "$", "theme", "]", "[", "'contexts'", "]", "=", "array_keys", "(", "$", "suites", "[", "$", "theme", "]", "[", "'contexts'", "]", ")", ";", "}", "// Comments use black color, so failure path is not visible. Using color other then black/white is safer.", "// https://github.com/Behat/Behat/pull/628.", "$", "config", "=", "array", "(", "'default'", "=>", "array", "(", "'formatters'", "=>", "array", "(", "'moodle_progress'", "=>", "array", "(", "'output_styles'", "=>", "array", "(", "'comment'", "=>", "array", "(", "'magenta'", ")", ")", ")", ")", ",", "'suites'", "=>", "$", "suites", ",", "'extensions'", "=>", "array", "(", "'Behat\\MinkExtension'", "=>", "array", "(", "'base_url'", "=>", "$", "CFG", "->", "behat_wwwroot", ",", "'goutte'", "=>", "null", ",", "'selenium2'", "=>", "$", "selenium2wdhost", ")", ",", "'Moodle\\BehatExtension'", "=>", "array", "(", "'moodledirroot'", "=>", "$", "CFG", "->", "dirroot", ",", "'steps_definitions'", "=>", "$", "allpaths", ",", ")", ")", ")", ")", ";", "return", "$", "config", ";", "}" ]
Build config for behat.yml. @param int $parallelruns how many parallel runs feature needs to be divided. @param int $currentrun current run for which features should be returned. @return array
[ "Build", "config", "for", "behat", ".", "yml", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L468-L539
215,980
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.get_features_for_the_run
protected function get_features_for_the_run($features, $parallelruns, $currentrun) { // If no features are passed then just return. if (empty($features)) { return $features; } $allocatedfeatures = $features; // If parallel run, then only divide features. if (!empty($currentrun) && !empty($parallelruns)) { $featurestodivide['withtags'] = $features; $allocatedfeatures = array(); // If tags are set then split features with tags first. if (!empty($this->tags)) { $featurestodivide['withtags'] = $this->filtered_features_with_tags($features); $featurestodivide['withouttags'] = $this->remove_blacklisted_features_from_list($features, $featurestodivide['withtags']); } // Attempt to split into weighted buckets using timing information, if available. foreach ($featurestodivide as $tagfeatures) { if ($alloc = $this->profile_guided_allocate($tagfeatures, max(1, $parallelruns), $currentrun)) { $allocatedfeatures = array_merge($allocatedfeatures, $alloc); } else { // Divide the list of feature files amongst the parallel runners. // Pull out the features for just this worker. if (count($tagfeatures)) { $splitfeatures = array_chunk($tagfeatures, ceil(count($tagfeatures) / max(1, $parallelruns))); // Check if there is any feature file for this process. if (!empty($splitfeatures[$currentrun - 1])) { $allocatedfeatures = array_merge($allocatedfeatures, $splitfeatures[$currentrun - 1]); } } } } } return $allocatedfeatures; }
php
protected function get_features_for_the_run($features, $parallelruns, $currentrun) { // If no features are passed then just return. if (empty($features)) { return $features; } $allocatedfeatures = $features; // If parallel run, then only divide features. if (!empty($currentrun) && !empty($parallelruns)) { $featurestodivide['withtags'] = $features; $allocatedfeatures = array(); // If tags are set then split features with tags first. if (!empty($this->tags)) { $featurestodivide['withtags'] = $this->filtered_features_with_tags($features); $featurestodivide['withouttags'] = $this->remove_blacklisted_features_from_list($features, $featurestodivide['withtags']); } // Attempt to split into weighted buckets using timing information, if available. foreach ($featurestodivide as $tagfeatures) { if ($alloc = $this->profile_guided_allocate($tagfeatures, max(1, $parallelruns), $currentrun)) { $allocatedfeatures = array_merge($allocatedfeatures, $alloc); } else { // Divide the list of feature files amongst the parallel runners. // Pull out the features for just this worker. if (count($tagfeatures)) { $splitfeatures = array_chunk($tagfeatures, ceil(count($tagfeatures) / max(1, $parallelruns))); // Check if there is any feature file for this process. if (!empty($splitfeatures[$currentrun - 1])) { $allocatedfeatures = array_merge($allocatedfeatures, $splitfeatures[$currentrun - 1]); } } } } } return $allocatedfeatures; }
[ "protected", "function", "get_features_for_the_run", "(", "$", "features", ",", "$", "parallelruns", ",", "$", "currentrun", ")", "{", "// If no features are passed then just return.", "if", "(", "empty", "(", "$", "features", ")", ")", "{", "return", "$", "features", ";", "}", "$", "allocatedfeatures", "=", "$", "features", ";", "// If parallel run, then only divide features.", "if", "(", "!", "empty", "(", "$", "currentrun", ")", "&&", "!", "empty", "(", "$", "parallelruns", ")", ")", "{", "$", "featurestodivide", "[", "'withtags'", "]", "=", "$", "features", ";", "$", "allocatedfeatures", "=", "array", "(", ")", ";", "// If tags are set then split features with tags first.", "if", "(", "!", "empty", "(", "$", "this", "->", "tags", ")", ")", "{", "$", "featurestodivide", "[", "'withtags'", "]", "=", "$", "this", "->", "filtered_features_with_tags", "(", "$", "features", ")", ";", "$", "featurestodivide", "[", "'withouttags'", "]", "=", "$", "this", "->", "remove_blacklisted_features_from_list", "(", "$", "features", ",", "$", "featurestodivide", "[", "'withtags'", "]", ")", ";", "}", "// Attempt to split into weighted buckets using timing information, if available.", "foreach", "(", "$", "featurestodivide", "as", "$", "tagfeatures", ")", "{", "if", "(", "$", "alloc", "=", "$", "this", "->", "profile_guided_allocate", "(", "$", "tagfeatures", ",", "max", "(", "1", ",", "$", "parallelruns", ")", ",", "$", "currentrun", ")", ")", "{", "$", "allocatedfeatures", "=", "array_merge", "(", "$", "allocatedfeatures", ",", "$", "alloc", ")", ";", "}", "else", "{", "// Divide the list of feature files amongst the parallel runners.", "// Pull out the features for just this worker.", "if", "(", "count", "(", "$", "tagfeatures", ")", ")", "{", "$", "splitfeatures", "=", "array_chunk", "(", "$", "tagfeatures", ",", "ceil", "(", "count", "(", "$", "tagfeatures", ")", "/", "max", "(", "1", ",", "$", "parallelruns", ")", ")", ")", ";", "// Check if there is any feature file for this process.", "if", "(", "!", "empty", "(", "$", "splitfeatures", "[", "$", "currentrun", "-", "1", "]", ")", ")", "{", "$", "allocatedfeatures", "=", "array_merge", "(", "$", "allocatedfeatures", ",", "$", "splitfeatures", "[", "$", "currentrun", "-", "1", "]", ")", ";", "}", "}", "}", "}", "}", "return", "$", "allocatedfeatures", ";", "}" ]
Divide features between the runs and return list. @param array $features list of features to be divided. @param int $parallelruns how many parallel runs feature needs to be divided. @param int $currentrun current run for which features should be returned. @return array
[ "Divide", "features", "between", "the", "runs", "and", "return", "list", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L549-L591
215,981
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.get_mobile_version_tags
protected function get_mobile_version_tags($verbose = true) : string { global $CFG; if (!empty($CFG->behat_ionic_dirroot)) { // Get app version from package.json. $jsonpath = $CFG->behat_ionic_dirroot . '/package.json'; $json = @file_get_contents($jsonpath); if (!$json) { throw new coding_exception('Unable to load app version from ' . $jsonpath); } $package = json_decode($json); if ($package === null || empty($package->version)) { throw new coding_exception('Invalid app package data in ' . $jsonpath); } $installedversion = $package->version; } else if (!empty($CFG->behat_ionic_wwwroot)) { // Get app version from config.json inside wwwroot. $jsonurl = $CFG->behat_ionic_wwwroot . '/config.json'; $json = @download_file_content($jsonurl); if (!$json) { throw new coding_exception('Unable to load app version from ' . $jsonurl); } $config = json_decode($json); if ($config === null || empty($config->versionname)) { throw new coding_exception('Invalid app config data in ' . $jsonurl); } $installedversion = str_replace('-dev', '', $config->versionname); } else { return ''; } // Read all feature files to check which mobile tags are used. (Note: This could be cached // but ideally, it is the sort of thing that really ought to be refreshed by doing a new // Behat init. Also, at time of coding it only takes 0.3 seconds and only if app enabled.) $usedtags = []; foreach ($this->features as $filepath) { $feature = file_get_contents($filepath); // This may incorrectly detect versions used e.g. in a comment or something, but it // doesn't do much harm if we have extra ones. if (preg_match_all('~@app_(?:from|upto)(?:[0-9]+(?:\.[0-9]+)*)~', $feature, $matches)) { foreach ($matches[0] as $tag) { // Store as key in array so we don't get duplicates. $usedtags[$tag] = true; } } } // Set up relevant tags for each version. $tags = []; foreach ($usedtags as $usedtag => $ignored) { if (!preg_match('~^@app_(from|upto)([0-9]+(?:\.[0-9]+)*)$~', $usedtag, $matches)) { throw new coding_exception('Unexpected tag format'); } $direction = $matches[1]; $version = $matches[2]; switch (version_compare($installedversion, $version)) { case -1: // Installed version OLDER than the one being considered, so do not // include any scenarios that only run from the considered version up. if ($direction === 'from') { $tags[] = '~@app_from' . $version; } break; case 0: // Installed version EQUAL to the one being considered - no tags need // excluding. break; case 1: // Installed version NEWER than the one being considered, so do not // include any scenarios that only run up to that version. if ($direction === 'upto') { $tags[] = '~@app_upto' . $version; } break; } } if ($verbose) { mtrace('Configured app tests for version ' . $installedversion); } return join(' && ', $tags); }
php
protected function get_mobile_version_tags($verbose = true) : string { global $CFG; if (!empty($CFG->behat_ionic_dirroot)) { // Get app version from package.json. $jsonpath = $CFG->behat_ionic_dirroot . '/package.json'; $json = @file_get_contents($jsonpath); if (!$json) { throw new coding_exception('Unable to load app version from ' . $jsonpath); } $package = json_decode($json); if ($package === null || empty($package->version)) { throw new coding_exception('Invalid app package data in ' . $jsonpath); } $installedversion = $package->version; } else if (!empty($CFG->behat_ionic_wwwroot)) { // Get app version from config.json inside wwwroot. $jsonurl = $CFG->behat_ionic_wwwroot . '/config.json'; $json = @download_file_content($jsonurl); if (!$json) { throw new coding_exception('Unable to load app version from ' . $jsonurl); } $config = json_decode($json); if ($config === null || empty($config->versionname)) { throw new coding_exception('Invalid app config data in ' . $jsonurl); } $installedversion = str_replace('-dev', '', $config->versionname); } else { return ''; } // Read all feature files to check which mobile tags are used. (Note: This could be cached // but ideally, it is the sort of thing that really ought to be refreshed by doing a new // Behat init. Also, at time of coding it only takes 0.3 seconds and only if app enabled.) $usedtags = []; foreach ($this->features as $filepath) { $feature = file_get_contents($filepath); // This may incorrectly detect versions used e.g. in a comment or something, but it // doesn't do much harm if we have extra ones. if (preg_match_all('~@app_(?:from|upto)(?:[0-9]+(?:\.[0-9]+)*)~', $feature, $matches)) { foreach ($matches[0] as $tag) { // Store as key in array so we don't get duplicates. $usedtags[$tag] = true; } } } // Set up relevant tags for each version. $tags = []; foreach ($usedtags as $usedtag => $ignored) { if (!preg_match('~^@app_(from|upto)([0-9]+(?:\.[0-9]+)*)$~', $usedtag, $matches)) { throw new coding_exception('Unexpected tag format'); } $direction = $matches[1]; $version = $matches[2]; switch (version_compare($installedversion, $version)) { case -1: // Installed version OLDER than the one being considered, so do not // include any scenarios that only run from the considered version up. if ($direction === 'from') { $tags[] = '~@app_from' . $version; } break; case 0: // Installed version EQUAL to the one being considered - no tags need // excluding. break; case 1: // Installed version NEWER than the one being considered, so do not // include any scenarios that only run up to that version. if ($direction === 'upto') { $tags[] = '~@app_upto' . $version; } break; } } if ($verbose) { mtrace('Configured app tests for version ' . $installedversion); } return join(' && ', $tags); }
[ "protected", "function", "get_mobile_version_tags", "(", "$", "verbose", "=", "true", ")", ":", "string", "{", "global", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "behat_ionic_dirroot", ")", ")", "{", "// Get app version from package.json.", "$", "jsonpath", "=", "$", "CFG", "->", "behat_ionic_dirroot", ".", "'/package.json'", ";", "$", "json", "=", "@", "file_get_contents", "(", "$", "jsonpath", ")", ";", "if", "(", "!", "$", "json", ")", "{", "throw", "new", "coding_exception", "(", "'Unable to load app version from '", ".", "$", "jsonpath", ")", ";", "}", "$", "package", "=", "json_decode", "(", "$", "json", ")", ";", "if", "(", "$", "package", "===", "null", "||", "empty", "(", "$", "package", "->", "version", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid app package data in '", ".", "$", "jsonpath", ")", ";", "}", "$", "installedversion", "=", "$", "package", "->", "version", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "CFG", "->", "behat_ionic_wwwroot", ")", ")", "{", "// Get app version from config.json inside wwwroot.", "$", "jsonurl", "=", "$", "CFG", "->", "behat_ionic_wwwroot", ".", "'/config.json'", ";", "$", "json", "=", "@", "download_file_content", "(", "$", "jsonurl", ")", ";", "if", "(", "!", "$", "json", ")", "{", "throw", "new", "coding_exception", "(", "'Unable to load app version from '", ".", "$", "jsonurl", ")", ";", "}", "$", "config", "=", "json_decode", "(", "$", "json", ")", ";", "if", "(", "$", "config", "===", "null", "||", "empty", "(", "$", "config", "->", "versionname", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid app config data in '", ".", "$", "jsonurl", ")", ";", "}", "$", "installedversion", "=", "str_replace", "(", "'-dev'", ",", "''", ",", "$", "config", "->", "versionname", ")", ";", "}", "else", "{", "return", "''", ";", "}", "// Read all feature files to check which mobile tags are used. (Note: This could be cached", "// but ideally, it is the sort of thing that really ought to be refreshed by doing a new", "// Behat init. Also, at time of coding it only takes 0.3 seconds and only if app enabled.)", "$", "usedtags", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "features", "as", "$", "filepath", ")", "{", "$", "feature", "=", "file_get_contents", "(", "$", "filepath", ")", ";", "// This may incorrectly detect versions used e.g. in a comment or something, but it", "// doesn't do much harm if we have extra ones.", "if", "(", "preg_match_all", "(", "'~@app_(?:from|upto)(?:[0-9]+(?:\\.[0-9]+)*)~'", ",", "$", "feature", ",", "$", "matches", ")", ")", "{", "foreach", "(", "$", "matches", "[", "0", "]", "as", "$", "tag", ")", "{", "// Store as key in array so we don't get duplicates.", "$", "usedtags", "[", "$", "tag", "]", "=", "true", ";", "}", "}", "}", "// Set up relevant tags for each version.", "$", "tags", "=", "[", "]", ";", "foreach", "(", "$", "usedtags", "as", "$", "usedtag", "=>", "$", "ignored", ")", "{", "if", "(", "!", "preg_match", "(", "'~^@app_(from|upto)([0-9]+(?:\\.[0-9]+)*)$~'", ",", "$", "usedtag", ",", "$", "matches", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Unexpected tag format'", ")", ";", "}", "$", "direction", "=", "$", "matches", "[", "1", "]", ";", "$", "version", "=", "$", "matches", "[", "2", "]", ";", "switch", "(", "version_compare", "(", "$", "installedversion", ",", "$", "version", ")", ")", "{", "case", "-", "1", ":", "// Installed version OLDER than the one being considered, so do not", "// include any scenarios that only run from the considered version up.", "if", "(", "$", "direction", "===", "'from'", ")", "{", "$", "tags", "[", "]", "=", "'~@app_from'", ".", "$", "version", ";", "}", "break", ";", "case", "0", ":", "// Installed version EQUAL to the one being considered - no tags need", "// excluding.", "break", ";", "case", "1", ":", "// Installed version NEWER than the one being considered, so do not", "// include any scenarios that only run up to that version.", "if", "(", "$", "direction", "===", "'upto'", ")", "{", "$", "tags", "[", "]", "=", "'~@app_upto'", ".", "$", "version", ";", "}", "break", ";", "}", "}", "if", "(", "$", "verbose", ")", "{", "mtrace", "(", "'Configured app tests for version '", ".", "$", "installedversion", ")", ";", "}", "return", "join", "(", "' && '", ",", "$", "tags", ")", ";", "}" ]
Gets version tags to use for the mobile app. This is based on the current mobile app version (from its package.json) and all known mobile app versions (based on the list appversions.json in the lib/behat directory). @param bool $verbose If true, outputs information about installed app version @return string List of tags or '' if not supporting mobile
[ "Gets", "version", "tags", "to", "use", "for", "the", "mobile", "app", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L706-L791
215,982
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.merge_config
public function merge_config($config, $localconfig) { if (!is_array($config) && !is_array($localconfig)) { return $localconfig; } // Local overrides also deeper default values. if (is_array($config) && !is_array($localconfig)) { return $localconfig; } foreach ($localconfig as $key => $value) { // If defaults are not as deep as local values let locals override. if (!is_array($config)) { unset($config); } // Add the param if it doesn't exists or merge branches. if (empty($config[$key])) { $config[$key] = $value; } else { $config[$key] = $this->merge_config($config[$key], $localconfig[$key]); } } return $config; }
php
public function merge_config($config, $localconfig) { if (!is_array($config) && !is_array($localconfig)) { return $localconfig; } // Local overrides also deeper default values. if (is_array($config) && !is_array($localconfig)) { return $localconfig; } foreach ($localconfig as $key => $value) { // If defaults are not as deep as local values let locals override. if (!is_array($config)) { unset($config); } // Add the param if it doesn't exists or merge branches. if (empty($config[$key])) { $config[$key] = $value; } else { $config[$key] = $this->merge_config($config[$key], $localconfig[$key]); } } return $config; }
[ "public", "function", "merge_config", "(", "$", "config", ",", "$", "localconfig", ")", "{", "if", "(", "!", "is_array", "(", "$", "config", ")", "&&", "!", "is_array", "(", "$", "localconfig", ")", ")", "{", "return", "$", "localconfig", ";", "}", "// Local overrides also deeper default values.", "if", "(", "is_array", "(", "$", "config", ")", "&&", "!", "is_array", "(", "$", "localconfig", ")", ")", "{", "return", "$", "localconfig", ";", "}", "foreach", "(", "$", "localconfig", "as", "$", "key", "=>", "$", "value", ")", "{", "// If defaults are not as deep as local values let locals override.", "if", "(", "!", "is_array", "(", "$", "config", ")", ")", "{", "unset", "(", "$", "config", ")", ";", "}", "// Add the param if it doesn't exists or merge branches.", "if", "(", "empty", "(", "$", "config", "[", "$", "key", "]", ")", ")", "{", "$", "config", "[", "$", "key", "]", "=", "$", "value", ";", "}", "else", "{", "$", "config", "[", "$", "key", "]", "=", "$", "this", "->", "merge_config", "(", "$", "config", "[", "$", "key", "]", ",", "$", "localconfig", "[", "$", "key", "]", ")", ";", "}", "}", "return", "$", "config", ";", "}" ]
Overrides default config with local config values array_merge does not merge completely the array's values @param mixed $config The node of the default config @param mixed $localconfig The node of the local config @return mixed The merge result
[ "Overrides", "default", "config", "with", "local", "config", "values" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L881-L908
215,983
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.get_behat_theme_selector_override_classname
public static final function get_behat_theme_selector_override_classname($themename, $selectortype, $includeclass = false) { global $CFG; if ($selectortype !== 'named_partial' && $selectortype !== 'named_exact') { throw new coding_exception("Unknown selector override type '{$selectortype}'"); } $overridebehatclassname = "behat_theme_{$themename}_behat_{$selectortype}_selectors"; if ($includeclass) { $themeoverrideselector = $CFG->dirroot . DIRECTORY_SEPARATOR . 'theme' . DIRECTORY_SEPARATOR . $themename . self::get_behat_tests_path() . DIRECTORY_SEPARATOR . $overridebehatclassname . '.php'; if (file_exists($themeoverrideselector)) { require_once($themeoverrideselector); } } return $overridebehatclassname; }
php
public static final function get_behat_theme_selector_override_classname($themename, $selectortype, $includeclass = false) { global $CFG; if ($selectortype !== 'named_partial' && $selectortype !== 'named_exact') { throw new coding_exception("Unknown selector override type '{$selectortype}'"); } $overridebehatclassname = "behat_theme_{$themename}_behat_{$selectortype}_selectors"; if ($includeclass) { $themeoverrideselector = $CFG->dirroot . DIRECTORY_SEPARATOR . 'theme' . DIRECTORY_SEPARATOR . $themename . self::get_behat_tests_path() . DIRECTORY_SEPARATOR . $overridebehatclassname . '.php'; if (file_exists($themeoverrideselector)) { require_once($themeoverrideselector); } } return $overridebehatclassname; }
[ "public", "static", "final", "function", "get_behat_theme_selector_override_classname", "(", "$", "themename", ",", "$", "selectortype", ",", "$", "includeclass", "=", "false", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "selectortype", "!==", "'named_partial'", "&&", "$", "selectortype", "!==", "'named_exact'", ")", "{", "throw", "new", "coding_exception", "(", "\"Unknown selector override type '{$selectortype}'\"", ")", ";", "}", "$", "overridebehatclassname", "=", "\"behat_theme_{$themename}_behat_{$selectortype}_selectors\"", ";", "if", "(", "$", "includeclass", ")", "{", "$", "themeoverrideselector", "=", "$", "CFG", "->", "dirroot", ".", "DIRECTORY_SEPARATOR", ".", "'theme'", ".", "DIRECTORY_SEPARATOR", ".", "$", "themename", ".", "self", "::", "get_behat_tests_path", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "overridebehatclassname", ".", "'.php'", ";", "if", "(", "file_exists", "(", "$", "themeoverrideselector", ")", ")", "{", "require_once", "(", "$", "themeoverrideselector", ")", ";", "}", "}", "return", "$", "overridebehatclassname", ";", "}" ]
Return context name of behat_theme selector to use. @param string $themename name of the theme. @param string $selectortype The type of selector (partial or exact at this stage) @param bool $includeclass if class should be included. @return string
[ "Return", "context", "name", "of", "behat_theme", "selector", "to", "use", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L1029-L1048
215,984
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.remove_blacklisted_features_from_list
protected function remove_blacklisted_features_from_list($features, $blacklist) { // If no blacklist passed then return. if (empty($blacklist)) { return $features; } // If there is no feature in suite then just return what was passed. if (empty($features)) { return $features; } if (!is_array($blacklist)) { $blacklist = array($blacklist); } // Remove blacklisted features. foreach ($blacklist as $blacklistpath) { list($key, $featurepath) = $this->get_clean_feature_key_and_path($blacklistpath); if (isset($features[$key])) { $features[$key] = null; unset($features[$key]); } else { $featurestocheck = $this->get_components_features(); if (!isset($featurestocheck[$key]) && (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST)) { behat_error(BEHAT_EXITCODE_REQUIREMENT, 'Blacklisted feature "' . $blacklistpath . '" not found.'); } } } return $features; }
php
protected function remove_blacklisted_features_from_list($features, $blacklist) { // If no blacklist passed then return. if (empty($blacklist)) { return $features; } // If there is no feature in suite then just return what was passed. if (empty($features)) { return $features; } if (!is_array($blacklist)) { $blacklist = array($blacklist); } // Remove blacklisted features. foreach ($blacklist as $blacklistpath) { list($key, $featurepath) = $this->get_clean_feature_key_and_path($blacklistpath); if (isset($features[$key])) { $features[$key] = null; unset($features[$key]); } else { $featurestocheck = $this->get_components_features(); if (!isset($featurestocheck[$key]) && (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST)) { behat_error(BEHAT_EXITCODE_REQUIREMENT, 'Blacklisted feature "' . $blacklistpath . '" not found.'); } } } return $features; }
[ "protected", "function", "remove_blacklisted_features_from_list", "(", "$", "features", ",", "$", "blacklist", ")", "{", "// If no blacklist passed then return.", "if", "(", "empty", "(", "$", "blacklist", ")", ")", "{", "return", "$", "features", ";", "}", "// If there is no feature in suite then just return what was passed.", "if", "(", "empty", "(", "$", "features", ")", ")", "{", "return", "$", "features", ";", "}", "if", "(", "!", "is_array", "(", "$", "blacklist", ")", ")", "{", "$", "blacklist", "=", "array", "(", "$", "blacklist", ")", ";", "}", "// Remove blacklisted features.", "foreach", "(", "$", "blacklist", "as", "$", "blacklistpath", ")", "{", "list", "(", "$", "key", ",", "$", "featurepath", ")", "=", "$", "this", "->", "get_clean_feature_key_and_path", "(", "$", "blacklistpath", ")", ";", "if", "(", "isset", "(", "$", "features", "[", "$", "key", "]", ")", ")", "{", "$", "features", "[", "$", "key", "]", "=", "null", ";", "unset", "(", "$", "features", "[", "$", "key", "]", ")", ";", "}", "else", "{", "$", "featurestocheck", "=", "$", "this", "->", "get_components_features", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "featurestocheck", "[", "$", "key", "]", ")", "&&", "(", "!", "defined", "(", "'PHPUNIT_TEST'", ")", "||", "!", "PHPUNIT_TEST", ")", ")", "{", "behat_error", "(", "BEHAT_EXITCODE_REQUIREMENT", ",", "'Blacklisted feature \"'", ".", "$", "blacklistpath", ".", "'\" not found.'", ")", ";", "}", "}", "}", "return", "$", "features", ";", "}" ]
Remove list of blacklisted features from the feature list. @param array $features list of original features. @param array|string $blacklist list of features which needs to be removed. @return array features - blacklisted features.
[ "Remove", "list", "of", "blacklisted", "features", "from", "the", "feature", "list", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L1070-L1103
215,985
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.get_list_of_themes
protected function get_list_of_themes() { $selectablethemes = array(); // Get all themes installed on site. $themes = core_component::get_plugin_list('theme'); ksort($themes); foreach ($themes as $themename => $themedir) { // Load the theme config. try { $theme = $this->get_theme_config($themename); } catch (Exception $e) { // Bad theme, just skip it for now. continue; } if ($themename !== $theme->name) { // Obsoleted or broken theme, just skip for now. continue; } if ($theme->hidefromselector) { // The theme doesn't want to be shown in the theme selector and as theme // designer mode is switched off we will respect that decision. continue; } $selectablethemes[] = $themename; } return $selectablethemes; }
php
protected function get_list_of_themes() { $selectablethemes = array(); // Get all themes installed on site. $themes = core_component::get_plugin_list('theme'); ksort($themes); foreach ($themes as $themename => $themedir) { // Load the theme config. try { $theme = $this->get_theme_config($themename); } catch (Exception $e) { // Bad theme, just skip it for now. continue; } if ($themename !== $theme->name) { // Obsoleted or broken theme, just skip for now. continue; } if ($theme->hidefromselector) { // The theme doesn't want to be shown in the theme selector and as theme // designer mode is switched off we will respect that decision. continue; } $selectablethemes[] = $themename; } return $selectablethemes; }
[ "protected", "function", "get_list_of_themes", "(", ")", "{", "$", "selectablethemes", "=", "array", "(", ")", ";", "// Get all themes installed on site.", "$", "themes", "=", "core_component", "::", "get_plugin_list", "(", "'theme'", ")", ";", "ksort", "(", "$", "themes", ")", ";", "foreach", "(", "$", "themes", "as", "$", "themename", "=>", "$", "themedir", ")", "{", "// Load the theme config.", "try", "{", "$", "theme", "=", "$", "this", "->", "get_theme_config", "(", "$", "themename", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// Bad theme, just skip it for now.", "continue", ";", "}", "if", "(", "$", "themename", "!==", "$", "theme", "->", "name", ")", "{", "// Obsoleted or broken theme, just skip for now.", "continue", ";", "}", "if", "(", "$", "theme", "->", "hidefromselector", ")", "{", "// The theme doesn't want to be shown in the theme selector and as theme", "// designer mode is switched off we will respect that decision.", "continue", ";", "}", "$", "selectablethemes", "[", "]", "=", "$", "themename", ";", "}", "return", "$", "selectablethemes", ";", "}" ]
Return list of themes which can be set in moodle. @return array list of themes with tests.
[ "Return", "list", "of", "themes", "which", "can", "be", "set", "in", "moodle", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L1201-L1229
215,986
moodle/moodle
lib/behat/classes/behat_config_util.php
behat_config_util.get_behat_features_for_theme
protected function get_behat_features_for_theme($theme) { global $CFG; // Get list of features defined by theme. $themefeatures = $this->get_tests_for_theme($theme, 'features'); $themeblacklistfeatures = $this->get_blacklisted_tests_for_theme($theme, 'features'); $themeblacklisttags = $this->get_blacklisted_tests_for_theme($theme, 'tags'); // Mobile app tests are not theme-specific, so run only for the default theme (and if // configured). if ((empty($CFG->behat_ionic_dirroot) && empty($CFG->behat_ionic_wwwroot)) || $theme !== $this->get_default_theme()) { $themeblacklisttags[] = '@app'; } // Clean feature key and path. $features = array(); $blacklistfeatures = array(); foreach ($themefeatures as $themefeature) { list($featurekey, $featurepath) = $this->get_clean_feature_key_and_path($themefeature); $features[$featurekey] = $featurepath; } foreach ($themeblacklistfeatures as $themeblacklistfeature) { list($blacklistfeaturekey, $blacklistfeaturepath) = $this->get_clean_feature_key_and_path($themeblacklistfeature); $blacklistfeatures[$blacklistfeaturekey] = $blacklistfeaturepath; } // If blacklist tags then add those features to list. if (!empty($themeblacklisttags)) { // Remove @ if given, so we are sure we have only tag names. $themeblacklisttags = array_map(function($v) { return ltrim($v, '@'); }, $themeblacklisttags); $themeblacklisttags = '@' . implode(',@', $themeblacklisttags); $blacklistedfeatureswithtag = $this->filtered_features_with_tags($this->get_components_features(), $themeblacklisttags); // Add features with blacklisted tags. if (!empty($blacklistedfeatureswithtag)) { foreach ($blacklistedfeatureswithtag as $themeblacklistfeature) { list($key, $path) = $this->get_clean_feature_key_and_path($themeblacklistfeature); $blacklistfeatures[$key] = $path; } } } ksort($features); $retval = array( 'blacklistfeatures' => $blacklistfeatures, 'features' => $features ); return $retval; }
php
protected function get_behat_features_for_theme($theme) { global $CFG; // Get list of features defined by theme. $themefeatures = $this->get_tests_for_theme($theme, 'features'); $themeblacklistfeatures = $this->get_blacklisted_tests_for_theme($theme, 'features'); $themeblacklisttags = $this->get_blacklisted_tests_for_theme($theme, 'tags'); // Mobile app tests are not theme-specific, so run only for the default theme (and if // configured). if ((empty($CFG->behat_ionic_dirroot) && empty($CFG->behat_ionic_wwwroot)) || $theme !== $this->get_default_theme()) { $themeblacklisttags[] = '@app'; } // Clean feature key and path. $features = array(); $blacklistfeatures = array(); foreach ($themefeatures as $themefeature) { list($featurekey, $featurepath) = $this->get_clean_feature_key_and_path($themefeature); $features[$featurekey] = $featurepath; } foreach ($themeblacklistfeatures as $themeblacklistfeature) { list($blacklistfeaturekey, $blacklistfeaturepath) = $this->get_clean_feature_key_and_path($themeblacklistfeature); $blacklistfeatures[$blacklistfeaturekey] = $blacklistfeaturepath; } // If blacklist tags then add those features to list. if (!empty($themeblacklisttags)) { // Remove @ if given, so we are sure we have only tag names. $themeblacklisttags = array_map(function($v) { return ltrim($v, '@'); }, $themeblacklisttags); $themeblacklisttags = '@' . implode(',@', $themeblacklisttags); $blacklistedfeatureswithtag = $this->filtered_features_with_tags($this->get_components_features(), $themeblacklisttags); // Add features with blacklisted tags. if (!empty($blacklistedfeatureswithtag)) { foreach ($blacklistedfeatureswithtag as $themeblacklistfeature) { list($key, $path) = $this->get_clean_feature_key_and_path($themeblacklistfeature); $blacklistfeatures[$key] = $path; } } } ksort($features); $retval = array( 'blacklistfeatures' => $blacklistfeatures, 'features' => $features ); return $retval; }
[ "protected", "function", "get_behat_features_for_theme", "(", "$", "theme", ")", "{", "global", "$", "CFG", ";", "// Get list of features defined by theme.", "$", "themefeatures", "=", "$", "this", "->", "get_tests_for_theme", "(", "$", "theme", ",", "'features'", ")", ";", "$", "themeblacklistfeatures", "=", "$", "this", "->", "get_blacklisted_tests_for_theme", "(", "$", "theme", ",", "'features'", ")", ";", "$", "themeblacklisttags", "=", "$", "this", "->", "get_blacklisted_tests_for_theme", "(", "$", "theme", ",", "'tags'", ")", ";", "// Mobile app tests are not theme-specific, so run only for the default theme (and if", "// configured).", "if", "(", "(", "empty", "(", "$", "CFG", "->", "behat_ionic_dirroot", ")", "&&", "empty", "(", "$", "CFG", "->", "behat_ionic_wwwroot", ")", ")", "||", "$", "theme", "!==", "$", "this", "->", "get_default_theme", "(", ")", ")", "{", "$", "themeblacklisttags", "[", "]", "=", "'@app'", ";", "}", "// Clean feature key and path.", "$", "features", "=", "array", "(", ")", ";", "$", "blacklistfeatures", "=", "array", "(", ")", ";", "foreach", "(", "$", "themefeatures", "as", "$", "themefeature", ")", "{", "list", "(", "$", "featurekey", ",", "$", "featurepath", ")", "=", "$", "this", "->", "get_clean_feature_key_and_path", "(", "$", "themefeature", ")", ";", "$", "features", "[", "$", "featurekey", "]", "=", "$", "featurepath", ";", "}", "foreach", "(", "$", "themeblacklistfeatures", "as", "$", "themeblacklistfeature", ")", "{", "list", "(", "$", "blacklistfeaturekey", ",", "$", "blacklistfeaturepath", ")", "=", "$", "this", "->", "get_clean_feature_key_and_path", "(", "$", "themeblacklistfeature", ")", ";", "$", "blacklistfeatures", "[", "$", "blacklistfeaturekey", "]", "=", "$", "blacklistfeaturepath", ";", "}", "// If blacklist tags then add those features to list.", "if", "(", "!", "empty", "(", "$", "themeblacklisttags", ")", ")", "{", "// Remove @ if given, so we are sure we have only tag names.", "$", "themeblacklisttags", "=", "array_map", "(", "function", "(", "$", "v", ")", "{", "return", "ltrim", "(", "$", "v", ",", "'@'", ")", ";", "}", ",", "$", "themeblacklisttags", ")", ";", "$", "themeblacklisttags", "=", "'@'", ".", "implode", "(", "',@'", ",", "$", "themeblacklisttags", ")", ";", "$", "blacklistedfeatureswithtag", "=", "$", "this", "->", "filtered_features_with_tags", "(", "$", "this", "->", "get_components_features", "(", ")", ",", "$", "themeblacklisttags", ")", ";", "// Add features with blacklisted tags.", "if", "(", "!", "empty", "(", "$", "blacklistedfeatureswithtag", ")", ")", "{", "foreach", "(", "$", "blacklistedfeatureswithtag", "as", "$", "themeblacklistfeature", ")", "{", "list", "(", "$", "key", ",", "$", "path", ")", "=", "$", "this", "->", "get_clean_feature_key_and_path", "(", "$", "themeblacklistfeature", ")", ";", "$", "blacklistfeatures", "[", "$", "key", "]", "=", "$", "path", ";", "}", "}", "}", "ksort", "(", "$", "features", ")", ";", "$", "retval", "=", "array", "(", "'blacklistfeatures'", "=>", "$", "blacklistfeatures", ",", "'features'", "=>", "$", "features", ")", ";", "return", "$", "retval", ";", "}" ]
Return list of blacklisted behat features for theme and features defined by theme only. @param string $theme theme name. @return array ($blacklistfeatures, $blacklisttags, $features)
[ "Return", "list", "of", "blacklisted", "behat", "features", "for", "theme", "and", "features", "defined", "by", "theme", "only", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_config_util.php#L1367-L1424
215,987
moodle/moodle
mod/assign/quickgradingform.php
mod_assign_quick_grading_form.definition
public function definition() { $mform = $this->_form; $instance = $this->_customdata; // Visible elements. $mform->addElement('html', $instance['gradingtable']); // Hidden params. $mform->addElement('hidden', 'id', $instance['cm']); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'action', 'quickgrade'); $mform->setType('action', PARAM_ALPHA); $mform->addElement('hidden', 'lastpage', $instance['page']); $mform->setType('lastpage', PARAM_INT); // Skip notifications option. $mform->addElement('selectyesno', 'sendstudentnotifications', get_string('sendstudentnotifications', 'assign')); $mform->setDefault('sendstudentnotifications', $instance['sendstudentnotifications']); // Buttons. $savemessage = get_string('saveallquickgradingchanges', 'assign'); $mform->addElement('submit', 'savequickgrades', $savemessage); }
php
public function definition() { $mform = $this->_form; $instance = $this->_customdata; // Visible elements. $mform->addElement('html', $instance['gradingtable']); // Hidden params. $mform->addElement('hidden', 'id', $instance['cm']); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'action', 'quickgrade'); $mform->setType('action', PARAM_ALPHA); $mform->addElement('hidden', 'lastpage', $instance['page']); $mform->setType('lastpage', PARAM_INT); // Skip notifications option. $mform->addElement('selectyesno', 'sendstudentnotifications', get_string('sendstudentnotifications', 'assign')); $mform->setDefault('sendstudentnotifications', $instance['sendstudentnotifications']); // Buttons. $savemessage = get_string('saveallquickgradingchanges', 'assign'); $mform->addElement('submit', 'savequickgrades', $savemessage); }
[ "public", "function", "definition", "(", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "instance", "=", "$", "this", "->", "_customdata", ";", "// Visible elements.", "$", "mform", "->", "addElement", "(", "'html'", ",", "$", "instance", "[", "'gradingtable'", "]", ")", ";", "// Hidden params.", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'id'", ",", "$", "instance", "[", "'cm'", "]", ")", ";", "$", "mform", "->", "setType", "(", "'id'", ",", "PARAM_INT", ")", ";", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'action'", ",", "'quickgrade'", ")", ";", "$", "mform", "->", "setType", "(", "'action'", ",", "PARAM_ALPHA", ")", ";", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'lastpage'", ",", "$", "instance", "[", "'page'", "]", ")", ";", "$", "mform", "->", "setType", "(", "'lastpage'", ",", "PARAM_INT", ")", ";", "// Skip notifications option.", "$", "mform", "->", "addElement", "(", "'selectyesno'", ",", "'sendstudentnotifications'", ",", "get_string", "(", "'sendstudentnotifications'", ",", "'assign'", ")", ")", ";", "$", "mform", "->", "setDefault", "(", "'sendstudentnotifications'", ",", "$", "instance", "[", "'sendstudentnotifications'", "]", ")", ";", "// Buttons.", "$", "savemessage", "=", "get_string", "(", "'saveallquickgradingchanges'", ",", "'assign'", ")", ";", "$", "mform", "->", "addElement", "(", "'submit'", ",", "'savequickgrades'", ",", "$", "savemessage", ")", ";", "}" ]
Define this form - called from the parent constructor
[ "Define", "this", "form", "-", "called", "from", "the", "parent", "constructor" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/quickgradingform.php#L42-L64
215,988
moodle/moodle
lib/classes/dml/table.php
table.get_fieldlist
protected function get_fieldlist() : array { global $DB; if (null === $this->fields) { $fields = []; foreach (array_keys($DB->get_columns($this->tablename)) as $fieldname) { $fields["{$this->fieldprefix}{$fieldname}"] = $fieldname; } $this->fields = $fields; } return $this->fields; }
php
protected function get_fieldlist() : array { global $DB; if (null === $this->fields) { $fields = []; foreach (array_keys($DB->get_columns($this->tablename)) as $fieldname) { $fields["{$this->fieldprefix}{$fieldname}"] = $fieldname; } $this->fields = $fields; } return $this->fields; }
[ "protected", "function", "get_fieldlist", "(", ")", ":", "array", "{", "global", "$", "DB", ";", "if", "(", "null", "===", "$", "this", "->", "fields", ")", "{", "$", "fields", "=", "[", "]", ";", "foreach", "(", "array_keys", "(", "$", "DB", "->", "get_columns", "(", "$", "this", "->", "tablename", ")", ")", "as", "$", "fieldname", ")", "{", "$", "fields", "[", "\"{$this->fieldprefix}{$fieldname}\"", "]", "=", "$", "fieldname", ";", "}", "$", "this", "->", "fields", "=", "$", "fields", ";", "}", "return", "$", "this", "->", "fields", ";", "}" ]
Get the list of fields in a table for use in preloading fields. @return array The list of columns in a table. The array key is the column name with an applied prefix.
[ "Get", "the", "list", "of", "fields", "in", "a", "table", "for", "use", "in", "preloading", "fields", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/dml/table.php#L80-L93
215,989
moodle/moodle
lib/classes/dml/table.php
table.get_field_select
public function get_field_select() : string { $fieldlist = $this->get_fieldlist(); return implode(', ', array_map(function($fieldname, $fieldalias) { return "{$this->tablealias}.{$fieldname} AS {$fieldalias}"; }, $fieldlist, array_keys($fieldlist))); }
php
public function get_field_select() : string { $fieldlist = $this->get_fieldlist(); return implode(', ', array_map(function($fieldname, $fieldalias) { return "{$this->tablealias}.{$fieldname} AS {$fieldalias}"; }, $fieldlist, array_keys($fieldlist))); }
[ "public", "function", "get_field_select", "(", ")", ":", "string", "{", "$", "fieldlist", "=", "$", "this", "->", "get_fieldlist", "(", ")", ";", "return", "implode", "(", "', '", ",", "array_map", "(", "function", "(", "$", "fieldname", ",", "$", "fieldalias", ")", "{", "return", "\"{$this->tablealias}.{$fieldname} AS {$fieldalias}\"", ";", "}", ",", "$", "fieldlist", ",", "array_keys", "(", "$", "fieldlist", ")", ")", ")", ";", "}" ]
Get the SELECT SQL to select a set of columns for this table. This function is intended to be used in combination with extract_from_result(). @return string The SQL to use in the SELECT
[ "Get", "the", "SELECT", "SQL", "to", "select", "a", "set", "of", "columns", "for", "this", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/dml/table.php#L102-L108
215,990
moodle/moodle
lib/classes/dml/table.php
table.extract_from_result
public function extract_from_result(stdClass $result) : stdClass { $record = new stdClass(); $fieldlist = $this->get_fieldlist(); foreach ($fieldlist as $fieldalias => $fieldname) { if (property_exists($result, $fieldalias)) { $record->$fieldname = $result->$fieldalias; unset($result->$fieldalias); } else { debugging("Field '{$fieldname}' not found", DEBUG_DEVELOPER); } } return $record; }
php
public function extract_from_result(stdClass $result) : stdClass { $record = new stdClass(); $fieldlist = $this->get_fieldlist(); foreach ($fieldlist as $fieldalias => $fieldname) { if (property_exists($result, $fieldalias)) { $record->$fieldname = $result->$fieldalias; unset($result->$fieldalias); } else { debugging("Field '{$fieldname}' not found", DEBUG_DEVELOPER); } } return $record; }
[ "public", "function", "extract_from_result", "(", "stdClass", "$", "result", ")", ":", "stdClass", "{", "$", "record", "=", "new", "stdClass", "(", ")", ";", "$", "fieldlist", "=", "$", "this", "->", "get_fieldlist", "(", ")", ";", "foreach", "(", "$", "fieldlist", "as", "$", "fieldalias", "=>", "$", "fieldname", ")", "{", "if", "(", "property_exists", "(", "$", "result", ",", "$", "fieldalias", ")", ")", "{", "$", "record", "->", "$", "fieldname", "=", "$", "result", "->", "$", "fieldalias", ";", "unset", "(", "$", "result", "->", "$", "fieldalias", ")", ";", "}", "else", "{", "debugging", "(", "\"Field '{$fieldname}' not found\"", ",", "DEBUG_DEVELOPER", ")", ";", "}", "}", "return", "$", "record", ";", "}" ]
Extract fields from the specified result. The fields are removed from the original object. This function is intended to be used in combination with get_field_select(). @param stdClass $result The result retrieved from the database with fields to be extracted @return stdClass The extracted result
[ "Extract", "fields", "from", "the", "specified", "result", ".", "The", "fields", "are", "removed", "from", "the", "original", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/dml/table.php#L118-L132
215,991
moodle/moodle
lib/classes/php_time_limit.php
core_php_time_limit.raise
public static function raise($newlimit = 0) { global $CFG; // Special behaviour in unit tests so that we can check the value. if (PHPUNIT_TEST) { self::$unittestdata[] = $newlimit; } // If the time limit has already been set to 'infinite', ignore. Also do // nothing in CLI scripts (including unit testing) which are set to // infinite by default. if (self::$currentend === 0 || CLI_SCRIPT) { return; } // Maximum time limit can be set in config. This can be useful for front-end // server systems; if the front-end server has a timeout without receiving // data, it's helpful to set this timeout lower to ensure that a suitable // error gets logged. if (!empty($CFG->maxtimelimit)) { $realtimeout = max(1, $CFG->maxtimelimit); if ($newlimit === 0) { $newlimit = $realtimeout; } else { $newlimit = min($newlimit, $realtimeout); } } // If new time limit is infinite, just set that. if ($newlimit === 0) { self::$currentend = 0; @set_time_limit(0); return; } // Calculate time limits to make sure it's longer than previous. $now = time(); $newend = $now + $newlimit; if (self::$currentend !== -1 && self::$currentend > $newend) { // Existing time limit is already longer, so do nothing. return; } // Set time limit and update current value. @set_time_limit($newlimit); self::$currentend = $newend; }
php
public static function raise($newlimit = 0) { global $CFG; // Special behaviour in unit tests so that we can check the value. if (PHPUNIT_TEST) { self::$unittestdata[] = $newlimit; } // If the time limit has already been set to 'infinite', ignore. Also do // nothing in CLI scripts (including unit testing) which are set to // infinite by default. if (self::$currentend === 0 || CLI_SCRIPT) { return; } // Maximum time limit can be set in config. This can be useful for front-end // server systems; if the front-end server has a timeout without receiving // data, it's helpful to set this timeout lower to ensure that a suitable // error gets logged. if (!empty($CFG->maxtimelimit)) { $realtimeout = max(1, $CFG->maxtimelimit); if ($newlimit === 0) { $newlimit = $realtimeout; } else { $newlimit = min($newlimit, $realtimeout); } } // If new time limit is infinite, just set that. if ($newlimit === 0) { self::$currentend = 0; @set_time_limit(0); return; } // Calculate time limits to make sure it's longer than previous. $now = time(); $newend = $now + $newlimit; if (self::$currentend !== -1 && self::$currentend > $newend) { // Existing time limit is already longer, so do nothing. return; } // Set time limit and update current value. @set_time_limit($newlimit); self::$currentend = $newend; }
[ "public", "static", "function", "raise", "(", "$", "newlimit", "=", "0", ")", "{", "global", "$", "CFG", ";", "// Special behaviour in unit tests so that we can check the value.", "if", "(", "PHPUNIT_TEST", ")", "{", "self", "::", "$", "unittestdata", "[", "]", "=", "$", "newlimit", ";", "}", "// If the time limit has already been set to 'infinite', ignore. Also do", "// nothing in CLI scripts (including unit testing) which are set to", "// infinite by default.", "if", "(", "self", "::", "$", "currentend", "===", "0", "||", "CLI_SCRIPT", ")", "{", "return", ";", "}", "// Maximum time limit can be set in config. This can be useful for front-end", "// server systems; if the front-end server has a timeout without receiving", "// data, it's helpful to set this timeout lower to ensure that a suitable", "// error gets logged.", "if", "(", "!", "empty", "(", "$", "CFG", "->", "maxtimelimit", ")", ")", "{", "$", "realtimeout", "=", "max", "(", "1", ",", "$", "CFG", "->", "maxtimelimit", ")", ";", "if", "(", "$", "newlimit", "===", "0", ")", "{", "$", "newlimit", "=", "$", "realtimeout", ";", "}", "else", "{", "$", "newlimit", "=", "min", "(", "$", "newlimit", ",", "$", "realtimeout", ")", ";", "}", "}", "// If new time limit is infinite, just set that.", "if", "(", "$", "newlimit", "===", "0", ")", "{", "self", "::", "$", "currentend", "=", "0", ";", "@", "set_time_limit", "(", "0", ")", ";", "return", ";", "}", "// Calculate time limits to make sure it's longer than previous.", "$", "now", "=", "time", "(", ")", ";", "$", "newend", "=", "$", "now", "+", "$", "newlimit", ";", "if", "(", "self", "::", "$", "currentend", "!==", "-", "1", "&&", "self", "::", "$", "currentend", ">", "$", "newend", ")", "{", "// Existing time limit is already longer, so do nothing.", "return", ";", "}", "// Set time limit and update current value.", "@", "set_time_limit", "(", "$", "newlimit", ")", ";", "self", "::", "$", "currentend", "=", "$", "newend", ";", "}" ]
Sets the PHP time limit to a number of seconds from now. This function will always extend the time limit (in other words, if the time limit has already been set further in the future, it will do nothing). In order to support front-end servers which may time out silently if no output is displayed, you should ideally only call this function if you expect some output to be displayed at the same time. (I.e. if you call this function each time around a loop, also display some output each time around the loop, such as a progress bar update.) @param int $newlimit Limit in seconds from now (0 = infinite)
[ "Sets", "the", "PHP", "time", "limit", "to", "a", "number", "of", "seconds", "from", "now", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/php_time_limit.php#L55-L101
215,992
moodle/moodle
lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php
PHPExcel_Writer_Excel2007_Style.writeGradientFill
private function writeGradientFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null) { // fill $objWriter->startElement('fill'); // gradientFill $objWriter->startElement('gradientFill'); $objWriter->writeAttribute('type', $pFill->getFillType()); $objWriter->writeAttribute('degree', $pFill->getRotation()); // stop $objWriter->startElement('stop'); $objWriter->writeAttribute('position', '0'); // color $objWriter->startElement('color'); $objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB()); $objWriter->endElement(); $objWriter->endElement(); // stop $objWriter->startElement('stop'); $objWriter->writeAttribute('position', '1'); // color $objWriter->startElement('color'); $objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB()); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); }
php
private function writeGradientFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null) { // fill $objWriter->startElement('fill'); // gradientFill $objWriter->startElement('gradientFill'); $objWriter->writeAttribute('type', $pFill->getFillType()); $objWriter->writeAttribute('degree', $pFill->getRotation()); // stop $objWriter->startElement('stop'); $objWriter->writeAttribute('position', '0'); // color $objWriter->startElement('color'); $objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB()); $objWriter->endElement(); $objWriter->endElement(); // stop $objWriter->startElement('stop'); $objWriter->writeAttribute('position', '1'); // color $objWriter->startElement('color'); $objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB()); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); }
[ "private", "function", "writeGradientFill", "(", "PHPExcel_Shared_XMLWriter", "$", "objWriter", "=", "null", ",", "PHPExcel_Style_Fill", "$", "pFill", "=", "null", ")", "{", "// fill", "$", "objWriter", "->", "startElement", "(", "'fill'", ")", ";", "// gradientFill", "$", "objWriter", "->", "startElement", "(", "'gradientFill'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'type'", ",", "$", "pFill", "->", "getFillType", "(", ")", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'degree'", ",", "$", "pFill", "->", "getRotation", "(", ")", ")", ";", "// stop", "$", "objWriter", "->", "startElement", "(", "'stop'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'position'", ",", "'0'", ")", ";", "// color", "$", "objWriter", "->", "startElement", "(", "'color'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'rgb'", ",", "$", "pFill", "->", "getStartColor", "(", ")", "->", "getARGB", "(", ")", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "// stop", "$", "objWriter", "->", "startElement", "(", "'stop'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'position'", ",", "'1'", ")", ";", "// color", "$", "objWriter", "->", "startElement", "(", "'color'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'rgb'", ",", "$", "pFill", "->", "getEndColor", "(", ")", "->", "getARGB", "(", ")", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "}" ]
Write Gradient Fill @param PHPExcel_Shared_XMLWriter $objWriter XML Writer @param PHPExcel_Style_Fill $pFill Fill style @throws PHPExcel_Writer_Exception
[ "Write", "Gradient", "Fill" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php#L187-L222
215,993
moodle/moodle
lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php
PHPExcel_Writer_Excel2007_Style.writePatternFill
private function writePatternFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null) { // fill $objWriter->startElement('fill'); // patternFill $objWriter->startElement('patternFill'); $objWriter->writeAttribute('patternType', $pFill->getFillType()); if ($pFill->getFillType() !== PHPExcel_Style_Fill::FILL_NONE) { // fgColor if ($pFill->getStartColor()->getARGB()) { $objWriter->startElement('fgColor'); $objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB()); $objWriter->endElement(); } } if ($pFill->getFillType() !== PHPExcel_Style_Fill::FILL_NONE) { // bgColor if ($pFill->getEndColor()->getARGB()) { $objWriter->startElement('bgColor'); $objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB()); $objWriter->endElement(); } } $objWriter->endElement(); $objWriter->endElement(); }
php
private function writePatternFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null) { // fill $objWriter->startElement('fill'); // patternFill $objWriter->startElement('patternFill'); $objWriter->writeAttribute('patternType', $pFill->getFillType()); if ($pFill->getFillType() !== PHPExcel_Style_Fill::FILL_NONE) { // fgColor if ($pFill->getStartColor()->getARGB()) { $objWriter->startElement('fgColor'); $objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB()); $objWriter->endElement(); } } if ($pFill->getFillType() !== PHPExcel_Style_Fill::FILL_NONE) { // bgColor if ($pFill->getEndColor()->getARGB()) { $objWriter->startElement('bgColor'); $objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB()); $objWriter->endElement(); } } $objWriter->endElement(); $objWriter->endElement(); }
[ "private", "function", "writePatternFill", "(", "PHPExcel_Shared_XMLWriter", "$", "objWriter", "=", "null", ",", "PHPExcel_Style_Fill", "$", "pFill", "=", "null", ")", "{", "// fill", "$", "objWriter", "->", "startElement", "(", "'fill'", ")", ";", "// patternFill", "$", "objWriter", "->", "startElement", "(", "'patternFill'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'patternType'", ",", "$", "pFill", "->", "getFillType", "(", ")", ")", ";", "if", "(", "$", "pFill", "->", "getFillType", "(", ")", "!==", "PHPExcel_Style_Fill", "::", "FILL_NONE", ")", "{", "// fgColor", "if", "(", "$", "pFill", "->", "getStartColor", "(", ")", "->", "getARGB", "(", ")", ")", "{", "$", "objWriter", "->", "startElement", "(", "'fgColor'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'rgb'", ",", "$", "pFill", "->", "getStartColor", "(", ")", "->", "getARGB", "(", ")", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "}", "}", "if", "(", "$", "pFill", "->", "getFillType", "(", ")", "!==", "PHPExcel_Style_Fill", "::", "FILL_NONE", ")", "{", "// bgColor", "if", "(", "$", "pFill", "->", "getEndColor", "(", ")", "->", "getARGB", "(", ")", ")", "{", "$", "objWriter", "->", "startElement", "(", "'bgColor'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'rgb'", ",", "$", "pFill", "->", "getEndColor", "(", ")", "->", "getARGB", "(", ")", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "}", "}", "$", "objWriter", "->", "endElement", "(", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "}" ]
Write Pattern Fill @param PHPExcel_Shared_XMLWriter $objWriter XML Writer @param PHPExcel_Style_Fill $pFill Fill style @throws PHPExcel_Writer_Exception
[ "Write", "Pattern", "Fill" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php#L231-L260
215,994
moodle/moodle
lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php
PHPExcel_Writer_Excel2007_Style.allConditionalStyles
public function allConditionalStyles(PHPExcel $pPHPExcel = null) { // Get an array of all styles $aStyles = array(); $sheetCount = $pPHPExcel->getSheetCount(); for ($i = 0; $i < $sheetCount; ++$i) { foreach ($pPHPExcel->getSheet($i)->getConditionalStylesCollection() as $conditionalStyles) { foreach ($conditionalStyles as $conditionalStyle) { $aStyles[] = $conditionalStyle; } } } return $aStyles; }
php
public function allConditionalStyles(PHPExcel $pPHPExcel = null) { // Get an array of all styles $aStyles = array(); $sheetCount = $pPHPExcel->getSheetCount(); for ($i = 0; $i < $sheetCount; ++$i) { foreach ($pPHPExcel->getSheet($i)->getConditionalStylesCollection() as $conditionalStyles) { foreach ($conditionalStyles as $conditionalStyle) { $aStyles[] = $conditionalStyle; } } } return $aStyles; }
[ "public", "function", "allConditionalStyles", "(", "PHPExcel", "$", "pPHPExcel", "=", "null", ")", "{", "// Get an array of all styles", "$", "aStyles", "=", "array", "(", ")", ";", "$", "sheetCount", "=", "$", "pPHPExcel", "->", "getSheetCount", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "sheetCount", ";", "++", "$", "i", ")", "{", "foreach", "(", "$", "pPHPExcel", "->", "getSheet", "(", "$", "i", ")", "->", "getConditionalStylesCollection", "(", ")", "as", "$", "conditionalStyles", ")", "{", "foreach", "(", "$", "conditionalStyles", "as", "$", "conditionalStyle", ")", "{", "$", "aStyles", "[", "]", "=", "$", "conditionalStyle", ";", "}", "}", "}", "return", "$", "aStyles", ";", "}" ]
Get an array of all conditional styles @param PHPExcel $pPHPExcel @return PHPExcel_Style_Conditional[] All conditional styles in PHPExcel @throws PHPExcel_Writer_Exception
[ "Get", "an", "array", "of", "all", "conditional", "styles" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php#L583-L598
215,995
moodle/moodle
lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php
PHPExcel_Writer_Excel2007_Style.allFills
public function allFills(PHPExcel $pPHPExcel = null) { // Get an array of unique fills $aFills = array(); // Two first fills are predefined $fill0 = new PHPExcel_Style_Fill(); $fill0->setFillType(PHPExcel_Style_Fill::FILL_NONE); $aFills[] = $fill0; $fill1 = new PHPExcel_Style_Fill(); $fill1->setFillType(PHPExcel_Style_Fill::FILL_PATTERN_GRAY125); $aFills[] = $fill1; // The remaining fills $aStyles = $this->allStyles($pPHPExcel); foreach ($aStyles as $style) { if (!array_key_exists($style->getFill()->getHashCode(), $aFills)) { $aFills[ $style->getFill()->getHashCode() ] = $style->getFill(); } } return $aFills; }
php
public function allFills(PHPExcel $pPHPExcel = null) { // Get an array of unique fills $aFills = array(); // Two first fills are predefined $fill0 = new PHPExcel_Style_Fill(); $fill0->setFillType(PHPExcel_Style_Fill::FILL_NONE); $aFills[] = $fill0; $fill1 = new PHPExcel_Style_Fill(); $fill1->setFillType(PHPExcel_Style_Fill::FILL_PATTERN_GRAY125); $aFills[] = $fill1; // The remaining fills $aStyles = $this->allStyles($pPHPExcel); foreach ($aStyles as $style) { if (!array_key_exists($style->getFill()->getHashCode(), $aFills)) { $aFills[ $style->getFill()->getHashCode() ] = $style->getFill(); } } return $aFills; }
[ "public", "function", "allFills", "(", "PHPExcel", "$", "pPHPExcel", "=", "null", ")", "{", "// Get an array of unique fills", "$", "aFills", "=", "array", "(", ")", ";", "// Two first fills are predefined", "$", "fill0", "=", "new", "PHPExcel_Style_Fill", "(", ")", ";", "$", "fill0", "->", "setFillType", "(", "PHPExcel_Style_Fill", "::", "FILL_NONE", ")", ";", "$", "aFills", "[", "]", "=", "$", "fill0", ";", "$", "fill1", "=", "new", "PHPExcel_Style_Fill", "(", ")", ";", "$", "fill1", "->", "setFillType", "(", "PHPExcel_Style_Fill", "::", "FILL_PATTERN_GRAY125", ")", ";", "$", "aFills", "[", "]", "=", "$", "fill1", ";", "// The remaining fills", "$", "aStyles", "=", "$", "this", "->", "allStyles", "(", "$", "pPHPExcel", ")", ";", "foreach", "(", "$", "aStyles", "as", "$", "style", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "style", "->", "getFill", "(", ")", "->", "getHashCode", "(", ")", ",", "$", "aFills", ")", ")", "{", "$", "aFills", "[", "$", "style", "->", "getFill", "(", ")", "->", "getHashCode", "(", ")", "]", "=", "$", "style", "->", "getFill", "(", ")", ";", "}", "}", "return", "$", "aFills", ";", "}" ]
Get an array of all fills @param PHPExcel $pPHPExcel @return PHPExcel_Style_Fill[] All fills in PHPExcel @throws PHPExcel_Writer_Exception
[ "Get", "an", "array", "of", "all", "fills" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php#L607-L629
215,996
moodle/moodle
lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php
PHPExcel_Writer_Excel2007_Style.allFonts
public function allFonts(PHPExcel $pPHPExcel = null) { // Get an array of unique fonts $aFonts = array(); $aStyles = $this->allStyles($pPHPExcel); foreach ($aStyles as $style) { if (!array_key_exists($style->getFont()->getHashCode(), $aFonts)) { $aFonts[ $style->getFont()->getHashCode() ] = $style->getFont(); } } return $aFonts; }
php
public function allFonts(PHPExcel $pPHPExcel = null) { // Get an array of unique fonts $aFonts = array(); $aStyles = $this->allStyles($pPHPExcel); foreach ($aStyles as $style) { if (!array_key_exists($style->getFont()->getHashCode(), $aFonts)) { $aFonts[ $style->getFont()->getHashCode() ] = $style->getFont(); } } return $aFonts; }
[ "public", "function", "allFonts", "(", "PHPExcel", "$", "pPHPExcel", "=", "null", ")", "{", "// Get an array of unique fonts", "$", "aFonts", "=", "array", "(", ")", ";", "$", "aStyles", "=", "$", "this", "->", "allStyles", "(", "$", "pPHPExcel", ")", ";", "foreach", "(", "$", "aStyles", "as", "$", "style", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "style", "->", "getFont", "(", ")", "->", "getHashCode", "(", ")", ",", "$", "aFonts", ")", ")", "{", "$", "aFonts", "[", "$", "style", "->", "getFont", "(", ")", "->", "getHashCode", "(", ")", "]", "=", "$", "style", "->", "getFont", "(", ")", ";", "}", "}", "return", "$", "aFonts", ";", "}" ]
Get an array of all fonts @param PHPExcel $pPHPExcel @return PHPExcel_Style_Font[] All fonts in PHPExcel @throws PHPExcel_Writer_Exception
[ "Get", "an", "array", "of", "all", "fonts" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php#L638-L651
215,997
moodle/moodle
lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php
PHPExcel_Writer_Excel2007_Style.allBorders
public function allBorders(PHPExcel $pPHPExcel = null) { // Get an array of unique borders $aBorders = array(); $aStyles = $this->allStyles($pPHPExcel); foreach ($aStyles as $style) { if (!array_key_exists($style->getBorders()->getHashCode(), $aBorders)) { $aBorders[ $style->getBorders()->getHashCode() ] = $style->getBorders(); } } return $aBorders; }
php
public function allBorders(PHPExcel $pPHPExcel = null) { // Get an array of unique borders $aBorders = array(); $aStyles = $this->allStyles($pPHPExcel); foreach ($aStyles as $style) { if (!array_key_exists($style->getBorders()->getHashCode(), $aBorders)) { $aBorders[ $style->getBorders()->getHashCode() ] = $style->getBorders(); } } return $aBorders; }
[ "public", "function", "allBorders", "(", "PHPExcel", "$", "pPHPExcel", "=", "null", ")", "{", "// Get an array of unique borders", "$", "aBorders", "=", "array", "(", ")", ";", "$", "aStyles", "=", "$", "this", "->", "allStyles", "(", "$", "pPHPExcel", ")", ";", "foreach", "(", "$", "aStyles", "as", "$", "style", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "style", "->", "getBorders", "(", ")", "->", "getHashCode", "(", ")", ",", "$", "aBorders", ")", ")", "{", "$", "aBorders", "[", "$", "style", "->", "getBorders", "(", ")", "->", "getHashCode", "(", ")", "]", "=", "$", "style", "->", "getBorders", "(", ")", ";", "}", "}", "return", "$", "aBorders", ";", "}" ]
Get an array of all borders @param PHPExcel $pPHPExcel @return PHPExcel_Style_Borders[] All borders in PHPExcel @throws PHPExcel_Writer_Exception
[ "Get", "an", "array", "of", "all", "borders" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php#L660-L673
215,998
moodle/moodle
lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php
PHPExcel_Writer_Excel2007_Style.allNumberFormats
public function allNumberFormats(PHPExcel $pPHPExcel = null) { // Get an array of unique number formats $aNumFmts = array(); $aStyles = $this->allStyles($pPHPExcel); foreach ($aStyles as $style) { if ($style->getNumberFormat()->getBuiltInFormatCode() === false && !array_key_exists($style->getNumberFormat()->getHashCode(), $aNumFmts)) { $aNumFmts[ $style->getNumberFormat()->getHashCode() ] = $style->getNumberFormat(); } } return $aNumFmts; }
php
public function allNumberFormats(PHPExcel $pPHPExcel = null) { // Get an array of unique number formats $aNumFmts = array(); $aStyles = $this->allStyles($pPHPExcel); foreach ($aStyles as $style) { if ($style->getNumberFormat()->getBuiltInFormatCode() === false && !array_key_exists($style->getNumberFormat()->getHashCode(), $aNumFmts)) { $aNumFmts[ $style->getNumberFormat()->getHashCode() ] = $style->getNumberFormat(); } } return $aNumFmts; }
[ "public", "function", "allNumberFormats", "(", "PHPExcel", "$", "pPHPExcel", "=", "null", ")", "{", "// Get an array of unique number formats", "$", "aNumFmts", "=", "array", "(", ")", ";", "$", "aStyles", "=", "$", "this", "->", "allStyles", "(", "$", "pPHPExcel", ")", ";", "foreach", "(", "$", "aStyles", "as", "$", "style", ")", "{", "if", "(", "$", "style", "->", "getNumberFormat", "(", ")", "->", "getBuiltInFormatCode", "(", ")", "===", "false", "&&", "!", "array_key_exists", "(", "$", "style", "->", "getNumberFormat", "(", ")", "->", "getHashCode", "(", ")", ",", "$", "aNumFmts", ")", ")", "{", "$", "aNumFmts", "[", "$", "style", "->", "getNumberFormat", "(", ")", "->", "getHashCode", "(", ")", "]", "=", "$", "style", "->", "getNumberFormat", "(", ")", ";", "}", "}", "return", "$", "aNumFmts", ";", "}" ]
Get an array of all number formats @param PHPExcel $pPHPExcel @return PHPExcel_Style_NumberFormat[] All number formats in PHPExcel @throws PHPExcel_Writer_Exception
[ "Get", "an", "array", "of", "all", "number", "formats" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Style.php#L682-L695
215,999
moodle/moodle
badges/endorsement_form.php
endorsement_form.validation
public function validation($data, $files) { $errors = parent::validation($data, $files); if ($data['issueremail'] && !validate_email($data['issueremail'])) { $errors['issueremail'] = get_string('invalidemail'); } if ($data['issuerurl'] && !preg_match('@^https?://.+@', $data['issuerurl'])) { $errors['issuerurl'] = get_string('invalidurl', 'badges'); } if ($data['claimid'] && !preg_match('@^https?://.+@', $data['claimid'])) { $errors['claimid'] = get_string('invalidurl', 'badges'); } return $errors; }
php
public function validation($data, $files) { $errors = parent::validation($data, $files); if ($data['issueremail'] && !validate_email($data['issueremail'])) { $errors['issueremail'] = get_string('invalidemail'); } if ($data['issuerurl'] && !preg_match('@^https?://.+@', $data['issuerurl'])) { $errors['issuerurl'] = get_string('invalidurl', 'badges'); } if ($data['claimid'] && !preg_match('@^https?://.+@', $data['claimid'])) { $errors['claimid'] = get_string('invalidurl', 'badges'); } return $errors; }
[ "public", "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "$", "errors", "=", "parent", "::", "validation", "(", "$", "data", ",", "$", "files", ")", ";", "if", "(", "$", "data", "[", "'issueremail'", "]", "&&", "!", "validate_email", "(", "$", "data", "[", "'issueremail'", "]", ")", ")", "{", "$", "errors", "[", "'issueremail'", "]", "=", "get_string", "(", "'invalidemail'", ")", ";", "}", "if", "(", "$", "data", "[", "'issuerurl'", "]", "&&", "!", "preg_match", "(", "'@^https?://.+@'", ",", "$", "data", "[", "'issuerurl'", "]", ")", ")", "{", "$", "errors", "[", "'issuerurl'", "]", "=", "get_string", "(", "'invalidurl'", ",", "'badges'", ")", ";", "}", "if", "(", "$", "data", "[", "'claimid'", "]", "&&", "!", "preg_match", "(", "'@^https?://.+@'", ",", "$", "data", "[", "'claimid'", "]", ")", ")", "{", "$", "errors", "[", "'claimid'", "]", "=", "get_string", "(", "'invalidurl'", ",", "'badges'", ")", ";", "}", "return", "$", "errors", ";", "}" ]
Validates form data. @param array $data submitted data. @param array $files submitted files. @return array $errors An array of errors.
[ "Validates", "form", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/endorsement_form.php#L84-L96