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
214,100
moodle/moodle
auth/oauth2/classes/auth.php
auth.is_ready_for_login_page
private function is_ready_for_login_page(\core\oauth2\issuer $issuer) { return $issuer->get('enabled') && $issuer->is_configured() && !empty($issuer->get('showonloginpage')); }
php
private function is_ready_for_login_page(\core\oauth2\issuer $issuer) { return $issuer->get('enabled') && $issuer->is_configured() && !empty($issuer->get('showonloginpage')); }
[ "private", "function", "is_ready_for_login_page", "(", "\\", "core", "\\", "oauth2", "\\", "issuer", "$", "issuer", ")", "{", "return", "$", "issuer", "->", "get", "(", "'enabled'", ")", "&&", "$", "issuer", "->", "is_configured", "(", ")", "&&", "!", "empty", "(", "$", "issuer", "->", "get", "(", "'showonloginpage'", ")", ")", ";", "}" ]
Do some checks on the identity provider before showing it on the login page. @param core\oauth2\issuer $issuer @return boolean
[ "Do", "some", "checks", "on", "the", "identity", "provider", "before", "showing", "it", "on", "the", "login", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/auth.php#L173-L177
214,101
moodle/moodle
auth/oauth2/classes/auth.php
auth.update_picture
private function update_picture($user) { global $CFG, $DB, $USER; require_once($CFG->libdir . '/filelib.php'); require_once($CFG->libdir . '/gdlib.php'); require_once($CFG->dirroot . '/user/lib.php'); $fs = get_file_storage(); $userid = $user->id; if (!empty($user->picture)) { return false; } if (!empty($CFG->enablegravatar)) { return false; } $picture = $this->get_static_user_picture(); if (empty($picture)) { return false; } $context = \context_user::instance($userid, MUST_EXIST); $fs->delete_area_files($context->id, 'user', 'newicon'); $filerecord = array( 'contextid' => $context->id, 'component' => 'user', 'filearea' => 'newicon', 'itemid' => 0, 'filepath' => '/', 'filename' => 'image' ); try { $fs->create_file_from_string($filerecord, $picture); } catch (\file_exception $e) { return get_string($e->errorcode, $e->module, $e->a); } $iconfile = $fs->get_area_files($context->id, 'user', 'newicon', false, 'itemid', false); // There should only be one. $iconfile = reset($iconfile); // Something went wrong while creating temp file - remove the uploaded file. if (!$iconfile = $iconfile->copy_content_to_temp()) { $fs->delete_area_files($context->id, 'user', 'newicon'); return false; } // Copy file to temporary location and the send it for processing icon. $newpicture = (int) process_new_icon($context, 'user', 'icon', 0, $iconfile); // Delete temporary file. @unlink($iconfile); // Remove uploaded file. $fs->delete_area_files($context->id, 'user', 'newicon'); // Set the user's picture. $updateuser = new stdClass(); $updateuser->id = $userid; $updateuser->picture = $newpicture; $USER->picture = $newpicture; user_update_user($updateuser); return true; }
php
private function update_picture($user) { global $CFG, $DB, $USER; require_once($CFG->libdir . '/filelib.php'); require_once($CFG->libdir . '/gdlib.php'); require_once($CFG->dirroot . '/user/lib.php'); $fs = get_file_storage(); $userid = $user->id; if (!empty($user->picture)) { return false; } if (!empty($CFG->enablegravatar)) { return false; } $picture = $this->get_static_user_picture(); if (empty($picture)) { return false; } $context = \context_user::instance($userid, MUST_EXIST); $fs->delete_area_files($context->id, 'user', 'newicon'); $filerecord = array( 'contextid' => $context->id, 'component' => 'user', 'filearea' => 'newicon', 'itemid' => 0, 'filepath' => '/', 'filename' => 'image' ); try { $fs->create_file_from_string($filerecord, $picture); } catch (\file_exception $e) { return get_string($e->errorcode, $e->module, $e->a); } $iconfile = $fs->get_area_files($context->id, 'user', 'newicon', false, 'itemid', false); // There should only be one. $iconfile = reset($iconfile); // Something went wrong while creating temp file - remove the uploaded file. if (!$iconfile = $iconfile->copy_content_to_temp()) { $fs->delete_area_files($context->id, 'user', 'newicon'); return false; } // Copy file to temporary location and the send it for processing icon. $newpicture = (int) process_new_icon($context, 'user', 'icon', 0, $iconfile); // Delete temporary file. @unlink($iconfile); // Remove uploaded file. $fs->delete_area_files($context->id, 'user', 'newicon'); // Set the user's picture. $updateuser = new stdClass(); $updateuser->id = $userid; $updateuser->picture = $newpicture; $USER->picture = $newpicture; user_update_user($updateuser); return true; }
[ "private", "function", "update_picture", "(", "$", "user", ")", "{", "global", "$", "CFG", ",", "$", "DB", ",", "$", "USER", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/filelib.php'", ")", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/gdlib.php'", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/user/lib.php'", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "userid", "=", "$", "user", "->", "id", ";", "if", "(", "!", "empty", "(", "$", "user", "->", "picture", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "empty", "(", "$", "CFG", "->", "enablegravatar", ")", ")", "{", "return", "false", ";", "}", "$", "picture", "=", "$", "this", "->", "get_static_user_picture", "(", ")", ";", "if", "(", "empty", "(", "$", "picture", ")", ")", "{", "return", "false", ";", "}", "$", "context", "=", "\\", "context_user", "::", "instance", "(", "$", "userid", ",", "MUST_EXIST", ")", ";", "$", "fs", "->", "delete_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'newicon'", ")", ";", "$", "filerecord", "=", "array", "(", "'contextid'", "=>", "$", "context", "->", "id", ",", "'component'", "=>", "'user'", ",", "'filearea'", "=>", "'newicon'", ",", "'itemid'", "=>", "0", ",", "'filepath'", "=>", "'/'", ",", "'filename'", "=>", "'image'", ")", ";", "try", "{", "$", "fs", "->", "create_file_from_string", "(", "$", "filerecord", ",", "$", "picture", ")", ";", "}", "catch", "(", "\\", "file_exception", "$", "e", ")", "{", "return", "get_string", "(", "$", "e", "->", "errorcode", ",", "$", "e", "->", "module", ",", "$", "e", "->", "a", ")", ";", "}", "$", "iconfile", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'newicon'", ",", "false", ",", "'itemid'", ",", "false", ")", ";", "// There should only be one.", "$", "iconfile", "=", "reset", "(", "$", "iconfile", ")", ";", "// Something went wrong while creating temp file - remove the uploaded file.", "if", "(", "!", "$", "iconfile", "=", "$", "iconfile", "->", "copy_content_to_temp", "(", ")", ")", "{", "$", "fs", "->", "delete_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'newicon'", ")", ";", "return", "false", ";", "}", "// Copy file to temporary location and the send it for processing icon.", "$", "newpicture", "=", "(", "int", ")", "process_new_icon", "(", "$", "context", ",", "'user'", ",", "'icon'", ",", "0", ",", "$", "iconfile", ")", ";", "// Delete temporary file.", "@", "unlink", "(", "$", "iconfile", ")", ";", "// Remove uploaded file.", "$", "fs", "->", "delete_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'newicon'", ")", ";", "// Set the user's picture.", "$", "updateuser", "=", "new", "stdClass", "(", ")", ";", "$", "updateuser", "->", "id", "=", "$", "userid", ";", "$", "updateuser", "->", "picture", "=", "$", "newpicture", ";", "$", "USER", "->", "picture", "=", "$", "newpicture", ";", "user_update_user", "(", "$", "updateuser", ")", ";", "return", "true", ";", "}" ]
If this user has no picture - but we got one from oauth - set it. @param stdClass $user @return boolean True if the image was updated.
[ "If", "this", "user", "has", "no", "picture", "-", "but", "we", "got", "one", "from", "oauth", "-", "set", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/auth.php#L239-L302
214,102
moodle/moodle
auth/oauth2/classes/auth.php
auth.update_user
private function update_user(array $externaldata, $userdata) { $user = (object) [ 'id' => $userdata->id, ]; // We can only update if the default authentication type of the user is set to OAuth2 as well. Otherwise, we might mess // up the user data of other users that use different authentication mechanisms (e.g. linked logins). if ($userdata->auth !== $this->authtype) { return $userdata; } // Go through each field from the external data. foreach ($externaldata as $fieldname => $value) { if (!in_array($fieldname, $this->userfields)) { // Skip if this field doesn't belong to the list of fields that can be synced with the OAuth2 issuer. continue; } if (!property_exists($userdata, $fieldname)) { // Just in case this field is on the list, but not part of the user data. This shouldn't happen though. continue; } // Get the old value. $oldvalue = (string)$userdata->$fieldname; // Get the lock configuration of the field. $lockvalue = $this->config->{'field_lock_' . $fieldname}; // We should update fields that meet the following criteria: // - Lock value set to 'unlocked'; or 'unlockedifempty', given the current value is empty. // - The value has changed. if ($lockvalue === 'unlocked' || ($lockvalue === 'unlockedifempty' && empty($oldvalue))) { $value = (string)$value; if ($oldvalue !== $value) { $user->$fieldname = $value; } } } // Update the user data. user_update_user($user, false); // Save user profile data. profile_save_data($user); // Refresh user for $USER variable. return get_complete_user_data('id', $user->id); }
php
private function update_user(array $externaldata, $userdata) { $user = (object) [ 'id' => $userdata->id, ]; // We can only update if the default authentication type of the user is set to OAuth2 as well. Otherwise, we might mess // up the user data of other users that use different authentication mechanisms (e.g. linked logins). if ($userdata->auth !== $this->authtype) { return $userdata; } // Go through each field from the external data. foreach ($externaldata as $fieldname => $value) { if (!in_array($fieldname, $this->userfields)) { // Skip if this field doesn't belong to the list of fields that can be synced with the OAuth2 issuer. continue; } if (!property_exists($userdata, $fieldname)) { // Just in case this field is on the list, but not part of the user data. This shouldn't happen though. continue; } // Get the old value. $oldvalue = (string)$userdata->$fieldname; // Get the lock configuration of the field. $lockvalue = $this->config->{'field_lock_' . $fieldname}; // We should update fields that meet the following criteria: // - Lock value set to 'unlocked'; or 'unlockedifempty', given the current value is empty. // - The value has changed. if ($lockvalue === 'unlocked' || ($lockvalue === 'unlockedifempty' && empty($oldvalue))) { $value = (string)$value; if ($oldvalue !== $value) { $user->$fieldname = $value; } } } // Update the user data. user_update_user($user, false); // Save user profile data. profile_save_data($user); // Refresh user for $USER variable. return get_complete_user_data('id', $user->id); }
[ "private", "function", "update_user", "(", "array", "$", "externaldata", ",", "$", "userdata", ")", "{", "$", "user", "=", "(", "object", ")", "[", "'id'", "=>", "$", "userdata", "->", "id", ",", "]", ";", "// We can only update if the default authentication type of the user is set to OAuth2 as well. Otherwise, we might mess", "// up the user data of other users that use different authentication mechanisms (e.g. linked logins).", "if", "(", "$", "userdata", "->", "auth", "!==", "$", "this", "->", "authtype", ")", "{", "return", "$", "userdata", ";", "}", "// Go through each field from the external data.", "foreach", "(", "$", "externaldata", "as", "$", "fieldname", "=>", "$", "value", ")", "{", "if", "(", "!", "in_array", "(", "$", "fieldname", ",", "$", "this", "->", "userfields", ")", ")", "{", "// Skip if this field doesn't belong to the list of fields that can be synced with the OAuth2 issuer.", "continue", ";", "}", "if", "(", "!", "property_exists", "(", "$", "userdata", ",", "$", "fieldname", ")", ")", "{", "// Just in case this field is on the list, but not part of the user data. This shouldn't happen though.", "continue", ";", "}", "// Get the old value.", "$", "oldvalue", "=", "(", "string", ")", "$", "userdata", "->", "$", "fieldname", ";", "// Get the lock configuration of the field.", "$", "lockvalue", "=", "$", "this", "->", "config", "->", "{", "'field_lock_'", ".", "$", "fieldname", "}", ";", "// We should update fields that meet the following criteria:", "// - Lock value set to 'unlocked'; or 'unlockedifempty', given the current value is empty.", "// - The value has changed.", "if", "(", "$", "lockvalue", "===", "'unlocked'", "||", "(", "$", "lockvalue", "===", "'unlockedifempty'", "&&", "empty", "(", "$", "oldvalue", ")", ")", ")", "{", "$", "value", "=", "(", "string", ")", "$", "value", ";", "if", "(", "$", "oldvalue", "!==", "$", "value", ")", "{", "$", "user", "->", "$", "fieldname", "=", "$", "value", ";", "}", "}", "}", "// Update the user data.", "user_update_user", "(", "$", "user", ",", "false", ")", ";", "// Save user profile data.", "profile_save_data", "(", "$", "user", ")", ";", "// Refresh user for $USER variable.", "return", "get_complete_user_data", "(", "'id'", ",", "$", "user", "->", "id", ")", ";", "}" ]
Update user data according to data sent by authorization server. @param array $externaldata data from authorization server @param stdClass $userdata Current data of the user to be updated @return stdClass The updated user record, or the existing one if there's nothing to be updated.
[ "Update", "user", "data", "according", "to", "data", "sent", "by", "authorization", "server", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/auth.php#L311-L358
214,103
moodle/moodle
auth/oauth2/classes/auth.php
auth.print_confirm_required
public function print_confirm_required($title, $message) { global $PAGE, $OUTPUT, $CFG; $PAGE->navbar->add($title); $PAGE->set_title($title); $PAGE->set_heading($PAGE->course->fullname); echo $OUTPUT->header(); notice($message, "$CFG->wwwroot/index.php"); }
php
public function print_confirm_required($title, $message) { global $PAGE, $OUTPUT, $CFG; $PAGE->navbar->add($title); $PAGE->set_title($title); $PAGE->set_heading($PAGE->course->fullname); echo $OUTPUT->header(); notice($message, "$CFG->wwwroot/index.php"); }
[ "public", "function", "print_confirm_required", "(", "$", "title", ",", "$", "message", ")", "{", "global", "$", "PAGE", ",", "$", "OUTPUT", ",", "$", "CFG", ";", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "title", ")", ";", "$", "PAGE", "->", "set_title", "(", "$", "title", ")", ";", "$", "PAGE", "->", "set_heading", "(", "$", "PAGE", "->", "course", "->", "fullname", ")", ";", "echo", "$", "OUTPUT", "->", "header", "(", ")", ";", "notice", "(", "$", "message", ",", "\"$CFG->wwwroot/index.php\"", ")", ";", "}" ]
Print a page showing that a confirm email was sent with instructions. @param string $title @param string $message
[ "Print", "a", "page", "showing", "that", "a", "confirm", "email", "was", "sent", "with", "instructions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/auth.php#L392-L400
214,104
moodle/moodle
auth/cas/CAS/CAS/CookieJar.php
CAS_CookieJar.parseCookieHeader
protected function parseCookieHeader ($line, $defaultDomain) { if (!$defaultDomain) { throw new CAS_InvalidArgumentException( '$defaultDomain was not provided.' ); } // Set our default values $cookie = array( 'domain' => $defaultDomain, 'path' => '/', 'secure' => false, ); $line = preg_replace('/^Set-Cookie2?: /i', '', trim($line)); // trim any trailing semicolons. $line = trim($line, ';'); phpCAS::trace("Cookie Line: $line"); // This implementation makes the assumption that semicolons will not // be present in quoted attribute values. While attribute values that // contain semicolons are allowed by RFC2965, they are hopefully rare // enough to ignore for our purposes. Most browsers make the same // assumption. $attributeStrings = explode(';', $line); foreach ( $attributeStrings as $attributeString ) { // split on the first equals sign and use the rest as value $attributeParts = explode('=', $attributeString, 2); $attributeName = trim($attributeParts[0]); $attributeNameLC = strtolower($attributeName); if (isset($attributeParts[1])) { $attributeValue = trim($attributeParts[1]); // Values may be quoted strings. if (strpos($attributeValue, '"') === 0) { $attributeValue = trim($attributeValue, '"'); // unescape any escaped quotes: $attributeValue = str_replace('\"', '"', $attributeValue); } } else { $attributeValue = null; } switch ($attributeNameLC) { case 'expires': $cookie['expires'] = strtotime($attributeValue); break; case 'max-age': $cookie['max-age'] = (int)$attributeValue; // Set an expiry time based on the max-age if ($cookie['max-age']) { $cookie['expires'] = time() + $cookie['max-age']; } else { // If max-age is zero, then the cookie should be removed // imediately so set an expiry before now. $cookie['expires'] = time() - 1; } break; case 'secure': $cookie['secure'] = true; break; case 'domain': case 'path': case 'port': case 'version': case 'comment': case 'commenturl': case 'discard': case 'httponly': $cookie[$attributeNameLC] = $attributeValue; break; default: $cookie['name'] = $attributeName; $cookie['value'] = $attributeValue; } } return $cookie; }
php
protected function parseCookieHeader ($line, $defaultDomain) { if (!$defaultDomain) { throw new CAS_InvalidArgumentException( '$defaultDomain was not provided.' ); } // Set our default values $cookie = array( 'domain' => $defaultDomain, 'path' => '/', 'secure' => false, ); $line = preg_replace('/^Set-Cookie2?: /i', '', trim($line)); // trim any trailing semicolons. $line = trim($line, ';'); phpCAS::trace("Cookie Line: $line"); // This implementation makes the assumption that semicolons will not // be present in quoted attribute values. While attribute values that // contain semicolons are allowed by RFC2965, they are hopefully rare // enough to ignore for our purposes. Most browsers make the same // assumption. $attributeStrings = explode(';', $line); foreach ( $attributeStrings as $attributeString ) { // split on the first equals sign and use the rest as value $attributeParts = explode('=', $attributeString, 2); $attributeName = trim($attributeParts[0]); $attributeNameLC = strtolower($attributeName); if (isset($attributeParts[1])) { $attributeValue = trim($attributeParts[1]); // Values may be quoted strings. if (strpos($attributeValue, '"') === 0) { $attributeValue = trim($attributeValue, '"'); // unescape any escaped quotes: $attributeValue = str_replace('\"', '"', $attributeValue); } } else { $attributeValue = null; } switch ($attributeNameLC) { case 'expires': $cookie['expires'] = strtotime($attributeValue); break; case 'max-age': $cookie['max-age'] = (int)$attributeValue; // Set an expiry time based on the max-age if ($cookie['max-age']) { $cookie['expires'] = time() + $cookie['max-age']; } else { // If max-age is zero, then the cookie should be removed // imediately so set an expiry before now. $cookie['expires'] = time() - 1; } break; case 'secure': $cookie['secure'] = true; break; case 'domain': case 'path': case 'port': case 'version': case 'comment': case 'commenturl': case 'discard': case 'httponly': $cookie[$attributeNameLC] = $attributeValue; break; default: $cookie['name'] = $attributeName; $cookie['value'] = $attributeValue; } } return $cookie; }
[ "protected", "function", "parseCookieHeader", "(", "$", "line", ",", "$", "defaultDomain", ")", "{", "if", "(", "!", "$", "defaultDomain", ")", "{", "throw", "new", "CAS_InvalidArgumentException", "(", "'$defaultDomain was not provided.'", ")", ";", "}", "// Set our default values", "$", "cookie", "=", "array", "(", "'domain'", "=>", "$", "defaultDomain", ",", "'path'", "=>", "'/'", ",", "'secure'", "=>", "false", ",", ")", ";", "$", "line", "=", "preg_replace", "(", "'/^Set-Cookie2?: /i'", ",", "''", ",", "trim", "(", "$", "line", ")", ")", ";", "// trim any trailing semicolons.", "$", "line", "=", "trim", "(", "$", "line", ",", "';'", ")", ";", "phpCAS", "::", "trace", "(", "\"Cookie Line: $line\"", ")", ";", "// This implementation makes the assumption that semicolons will not", "// be present in quoted attribute values. While attribute values that", "// contain semicolons are allowed by RFC2965, they are hopefully rare", "// enough to ignore for our purposes. Most browsers make the same", "// assumption.", "$", "attributeStrings", "=", "explode", "(", "';'", ",", "$", "line", ")", ";", "foreach", "(", "$", "attributeStrings", "as", "$", "attributeString", ")", "{", "// split on the first equals sign and use the rest as value", "$", "attributeParts", "=", "explode", "(", "'='", ",", "$", "attributeString", ",", "2", ")", ";", "$", "attributeName", "=", "trim", "(", "$", "attributeParts", "[", "0", "]", ")", ";", "$", "attributeNameLC", "=", "strtolower", "(", "$", "attributeName", ")", ";", "if", "(", "isset", "(", "$", "attributeParts", "[", "1", "]", ")", ")", "{", "$", "attributeValue", "=", "trim", "(", "$", "attributeParts", "[", "1", "]", ")", ";", "// Values may be quoted strings.", "if", "(", "strpos", "(", "$", "attributeValue", ",", "'\"'", ")", "===", "0", ")", "{", "$", "attributeValue", "=", "trim", "(", "$", "attributeValue", ",", "'\"'", ")", ";", "// unescape any escaped quotes:", "$", "attributeValue", "=", "str_replace", "(", "'\\\"'", ",", "'\"'", ",", "$", "attributeValue", ")", ";", "}", "}", "else", "{", "$", "attributeValue", "=", "null", ";", "}", "switch", "(", "$", "attributeNameLC", ")", "{", "case", "'expires'", ":", "$", "cookie", "[", "'expires'", "]", "=", "strtotime", "(", "$", "attributeValue", ")", ";", "break", ";", "case", "'max-age'", ":", "$", "cookie", "[", "'max-age'", "]", "=", "(", "int", ")", "$", "attributeValue", ";", "// Set an expiry time based on the max-age", "if", "(", "$", "cookie", "[", "'max-age'", "]", ")", "{", "$", "cookie", "[", "'expires'", "]", "=", "time", "(", ")", "+", "$", "cookie", "[", "'max-age'", "]", ";", "}", "else", "{", "// If max-age is zero, then the cookie should be removed", "// imediately so set an expiry before now.", "$", "cookie", "[", "'expires'", "]", "=", "time", "(", ")", "-", "1", ";", "}", "break", ";", "case", "'secure'", ":", "$", "cookie", "[", "'secure'", "]", "=", "true", ";", "break", ";", "case", "'domain'", ":", "case", "'path'", ":", "case", "'port'", ":", "case", "'version'", ":", "case", "'comment'", ":", "case", "'commenturl'", ":", "case", "'discard'", ":", "case", "'httponly'", ":", "$", "cookie", "[", "$", "attributeNameLC", "]", "=", "$", "attributeValue", ";", "break", ";", "default", ":", "$", "cookie", "[", "'name'", "]", "=", "$", "attributeName", ";", "$", "cookie", "[", "'value'", "]", "=", "$", "attributeValue", ";", "}", "}", "return", "$", "cookie", ";", "}" ]
Parse a single cookie header line. Based on RFC2965 http://www.ietf.org/rfc/rfc2965.txt @param string $line The header line. @param string $defaultDomain The domain to use if none is specified in the cookie. @return array
[ "Parse", "a", "single", "cookie", "header", "line", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/CookieJar.php#L161-L244
214,105
moodle/moodle
auth/cas/CAS/CAS/CookieJar.php
CAS_CookieJar.discardCookie
protected function discardCookie ($cookie) { if (!isset($cookie['domain']) || !isset($cookie['path']) || !isset($cookie['path']) ) { throw new CAS_InvalidArgumentException('Invalid Cookie array passed.'); } foreach ($this->_cookies as $key => $old_cookie) { if ( $cookie['domain'] == $old_cookie['domain'] && $cookie['path'] == $old_cookie['path'] && $cookie['name'] == $old_cookie['name'] ) { unset($this->_cookies[$key]); } } }
php
protected function discardCookie ($cookie) { if (!isset($cookie['domain']) || !isset($cookie['path']) || !isset($cookie['path']) ) { throw new CAS_InvalidArgumentException('Invalid Cookie array passed.'); } foreach ($this->_cookies as $key => $old_cookie) { if ( $cookie['domain'] == $old_cookie['domain'] && $cookie['path'] == $old_cookie['path'] && $cookie['name'] == $old_cookie['name'] ) { unset($this->_cookies[$key]); } } }
[ "protected", "function", "discardCookie", "(", "$", "cookie", ")", "{", "if", "(", "!", "isset", "(", "$", "cookie", "[", "'domain'", "]", ")", "||", "!", "isset", "(", "$", "cookie", "[", "'path'", "]", ")", "||", "!", "isset", "(", "$", "cookie", "[", "'path'", "]", ")", ")", "{", "throw", "new", "CAS_InvalidArgumentException", "(", "'Invalid Cookie array passed.'", ")", ";", "}", "foreach", "(", "$", "this", "->", "_cookies", "as", "$", "key", "=>", "$", "old_cookie", ")", "{", "if", "(", "$", "cookie", "[", "'domain'", "]", "==", "$", "old_cookie", "[", "'domain'", "]", "&&", "$", "cookie", "[", "'path'", "]", "==", "$", "old_cookie", "[", "'path'", "]", "&&", "$", "cookie", "[", "'name'", "]", "==", "$", "old_cookie", "[", "'name'", "]", ")", "{", "unset", "(", "$", "this", "->", "_cookies", "[", "$", "key", "]", ")", ";", "}", "}", "}" ]
Discard an existing cookie @param array $cookie An cookie @return void @access protected
[ "Discard", "an", "existing", "cookie" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/CookieJar.php#L272-L289
214,106
moodle/moodle
auth/cas/CAS/CAS/CookieJar.php
CAS_CookieJar.expireCookies
protected function expireCookies () { foreach ($this->_cookies as $key => $cookie) { if (isset($cookie['expires']) && $cookie['expires'] < time()) { unset($this->_cookies[$key]); } } }
php
protected function expireCookies () { foreach ($this->_cookies as $key => $cookie) { if (isset($cookie['expires']) && $cookie['expires'] < time()) { unset($this->_cookies[$key]); } } }
[ "protected", "function", "expireCookies", "(", ")", "{", "foreach", "(", "$", "this", "->", "_cookies", "as", "$", "key", "=>", "$", "cookie", ")", "{", "if", "(", "isset", "(", "$", "cookie", "[", "'expires'", "]", ")", "&&", "$", "cookie", "[", "'expires'", "]", "<", "time", "(", ")", ")", "{", "unset", "(", "$", "this", "->", "_cookies", "[", "$", "key", "]", ")", ";", "}", "}", "}" ]
Go through our stored cookies and remove any that are expired. @return void @access protected
[ "Go", "through", "our", "stored", "cookies", "and", "remove", "any", "that", "are", "expired", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/CookieJar.php#L298-L305
214,107
moodle/moodle
auth/cas/CAS/CAS/CookieJar.php
CAS_CookieJar.cookieMatchesTarget
protected function cookieMatchesTarget ($cookie, $target) { if (!is_array($target)) { throw new CAS_InvalidArgumentException( '$target must be an array of URL attributes as generated by parse_url().' ); } if (!isset($target['host'])) { throw new CAS_InvalidArgumentException( '$target must be an array of URL attributes as generated by parse_url().' ); } // Verify that the scheme matches if ($cookie['secure'] && $target['scheme'] != 'https') { return false; } // Verify that the host matches // Match domain and mulit-host cookies if (strpos($cookie['domain'], '.') === 0) { // .host.domain.edu cookies are valid for host.domain.edu if (substr($cookie['domain'], 1) == $target['host']) { // continue with other checks } else { // non-exact host-name matches. // check that the target host a.b.c.edu is within .b.c.edu $pos = strripos($target['host'], $cookie['domain']); if (!$pos) { return false; } // verify that the cookie domain is the last part of the host. if ($pos + strlen($cookie['domain']) != strlen($target['host'])) { return false; } // verify that the host name does not contain interior dots as per // RFC 2965 section 3.3.2 Rejecting Cookies // http://www.ietf.org/rfc/rfc2965.txt $hostname = substr($target['host'], 0, $pos); if (strpos($hostname, '.') !== false) { return false; } } } else { // If the cookie host doesn't begin with '.', // the host must case-insensitive match exactly if (strcasecmp($target['host'], $cookie['domain']) !== 0) { return false; } } // Verify that the port matches if (isset($cookie['ports']) && !in_array($target['port'], $cookie['ports']) ) { return false; } // Verify that the path matches if (strpos($target['path'], $cookie['path']) !== 0) { return false; } return true; }
php
protected function cookieMatchesTarget ($cookie, $target) { if (!is_array($target)) { throw new CAS_InvalidArgumentException( '$target must be an array of URL attributes as generated by parse_url().' ); } if (!isset($target['host'])) { throw new CAS_InvalidArgumentException( '$target must be an array of URL attributes as generated by parse_url().' ); } // Verify that the scheme matches if ($cookie['secure'] && $target['scheme'] != 'https') { return false; } // Verify that the host matches // Match domain and mulit-host cookies if (strpos($cookie['domain'], '.') === 0) { // .host.domain.edu cookies are valid for host.domain.edu if (substr($cookie['domain'], 1) == $target['host']) { // continue with other checks } else { // non-exact host-name matches. // check that the target host a.b.c.edu is within .b.c.edu $pos = strripos($target['host'], $cookie['domain']); if (!$pos) { return false; } // verify that the cookie domain is the last part of the host. if ($pos + strlen($cookie['domain']) != strlen($target['host'])) { return false; } // verify that the host name does not contain interior dots as per // RFC 2965 section 3.3.2 Rejecting Cookies // http://www.ietf.org/rfc/rfc2965.txt $hostname = substr($target['host'], 0, $pos); if (strpos($hostname, '.') !== false) { return false; } } } else { // If the cookie host doesn't begin with '.', // the host must case-insensitive match exactly if (strcasecmp($target['host'], $cookie['domain']) !== 0) { return false; } } // Verify that the port matches if (isset($cookie['ports']) && !in_array($target['port'], $cookie['ports']) ) { return false; } // Verify that the path matches if (strpos($target['path'], $cookie['path']) !== 0) { return false; } return true; }
[ "protected", "function", "cookieMatchesTarget", "(", "$", "cookie", ",", "$", "target", ")", "{", "if", "(", "!", "is_array", "(", "$", "target", ")", ")", "{", "throw", "new", "CAS_InvalidArgumentException", "(", "'$target must be an array of URL attributes as generated by parse_url().'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "target", "[", "'host'", "]", ")", ")", "{", "throw", "new", "CAS_InvalidArgumentException", "(", "'$target must be an array of URL attributes as generated by parse_url().'", ")", ";", "}", "// Verify that the scheme matches", "if", "(", "$", "cookie", "[", "'secure'", "]", "&&", "$", "target", "[", "'scheme'", "]", "!=", "'https'", ")", "{", "return", "false", ";", "}", "// Verify that the host matches", "// Match domain and mulit-host cookies", "if", "(", "strpos", "(", "$", "cookie", "[", "'domain'", "]", ",", "'.'", ")", "===", "0", ")", "{", "// .host.domain.edu cookies are valid for host.domain.edu", "if", "(", "substr", "(", "$", "cookie", "[", "'domain'", "]", ",", "1", ")", "==", "$", "target", "[", "'host'", "]", ")", "{", "// continue with other checks", "}", "else", "{", "// non-exact host-name matches.", "// check that the target host a.b.c.edu is within .b.c.edu", "$", "pos", "=", "strripos", "(", "$", "target", "[", "'host'", "]", ",", "$", "cookie", "[", "'domain'", "]", ")", ";", "if", "(", "!", "$", "pos", ")", "{", "return", "false", ";", "}", "// verify that the cookie domain is the last part of the host.", "if", "(", "$", "pos", "+", "strlen", "(", "$", "cookie", "[", "'domain'", "]", ")", "!=", "strlen", "(", "$", "target", "[", "'host'", "]", ")", ")", "{", "return", "false", ";", "}", "// verify that the host name does not contain interior dots as per", "// RFC 2965 section 3.3.2 Rejecting Cookies", "// http://www.ietf.org/rfc/rfc2965.txt", "$", "hostname", "=", "substr", "(", "$", "target", "[", "'host'", "]", ",", "0", ",", "$", "pos", ")", ";", "if", "(", "strpos", "(", "$", "hostname", ",", "'.'", ")", "!==", "false", ")", "{", "return", "false", ";", "}", "}", "}", "else", "{", "// If the cookie host doesn't begin with '.',", "// the host must case-insensitive match exactly", "if", "(", "strcasecmp", "(", "$", "target", "[", "'host'", "]", ",", "$", "cookie", "[", "'domain'", "]", ")", "!==", "0", ")", "{", "return", "false", ";", "}", "}", "// Verify that the port matches", "if", "(", "isset", "(", "$", "cookie", "[", "'ports'", "]", ")", "&&", "!", "in_array", "(", "$", "target", "[", "'port'", "]", ",", "$", "cookie", "[", "'ports'", "]", ")", ")", "{", "return", "false", ";", "}", "// Verify that the path matches", "if", "(", "strpos", "(", "$", "target", "[", "'path'", "]", ",", "$", "cookie", "[", "'path'", "]", ")", "!==", "0", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Answer true if cookie is applicable to a target. @param array $cookie An array of cookie attributes. @param array $target An array of URL attributes as generated by parse_url(). @return bool @access private
[ "Answer", "true", "if", "cookie", "is", "applicable", "to", "a", "target", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/CookieJar.php#L317-L381
214,108
moodle/moodle
competency/classes/privacy/provider.php
provider.delete_user_evidence_of_prior_learning
protected static function delete_user_evidence_of_prior_learning($userid) { global $DB; $usercontext = context_user::instance($userid); $ueids = $DB->get_fieldset_select(user_evidence::TABLE, 'id', 'userid = :userid', ['userid' => $userid]); if (empty($ueids)) { return; } list($insql, $inparams) = $DB->get_in_or_equal($ueids, SQL_PARAMS_NAMED); // Delete competencies associated with user evidence. $DB->delete_records_select(user_evidence_competency::TABLE, "userevidenceid $insql", $inparams); // Delete the user evidence. $DB->delete_records_select(user_evidence::TABLE, "id $insql", $inparams); // Delete the user evidence files. $fs = get_file_storage(); $fs->delete_area_files($usercontext->id, 'core_competency', 'userevidence'); }
php
protected static function delete_user_evidence_of_prior_learning($userid) { global $DB; $usercontext = context_user::instance($userid); $ueids = $DB->get_fieldset_select(user_evidence::TABLE, 'id', 'userid = :userid', ['userid' => $userid]); if (empty($ueids)) { return; } list($insql, $inparams) = $DB->get_in_or_equal($ueids, SQL_PARAMS_NAMED); // Delete competencies associated with user evidence. $DB->delete_records_select(user_evidence_competency::TABLE, "userevidenceid $insql", $inparams); // Delete the user evidence. $DB->delete_records_select(user_evidence::TABLE, "id $insql", $inparams); // Delete the user evidence files. $fs = get_file_storage(); $fs->delete_area_files($usercontext->id, 'core_competency', 'userevidence'); }
[ "protected", "static", "function", "delete_user_evidence_of_prior_learning", "(", "$", "userid", ")", "{", "global", "$", "DB", ";", "$", "usercontext", "=", "context_user", "::", "instance", "(", "$", "userid", ")", ";", "$", "ueids", "=", "$", "DB", "->", "get_fieldset_select", "(", "user_evidence", "::", "TABLE", ",", "'id'", ",", "'userid = :userid'", ",", "[", "'userid'", "=>", "$", "userid", "]", ")", ";", "if", "(", "empty", "(", "$", "ueids", ")", ")", "{", "return", ";", "}", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "ueids", ",", "SQL_PARAMS_NAMED", ")", ";", "// Delete competencies associated with user evidence.", "$", "DB", "->", "delete_records_select", "(", "user_evidence_competency", "::", "TABLE", ",", "\"userevidenceid $insql\"", ",", "$", "inparams", ")", ";", "// Delete the user evidence.", "$", "DB", "->", "delete_records_select", "(", "user_evidence", "::", "TABLE", ",", "\"id $insql\"", ",", "$", "inparams", ")", ";", "// Delete the user evidence files.", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "fs", "->", "delete_area_files", "(", "$", "usercontext", "->", "id", ",", "'core_competency'", ",", "'userevidence'", ")", ";", "}" ]
Delete evidence of prior learning. @param int $userid The user ID. @return void
[ "Delete", "evidence", "of", "prior", "learning", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L718-L737
214,109
moodle/moodle
competency/classes/privacy/provider.php
provider.delete_user_plans
protected static function delete_user_plans($userid) { global $DB; $usercontext = context_user::instance($userid); // Remove all the comments made on plans. \core_comment\privacy\provider::delete_comments_for_all_users($usercontext, 'competency', 'plan'); // Find the user plan IDs. $planids = $DB->get_fieldset_select(plan::TABLE, 'id', 'userid = :userid', ['userid' => $userid]); if (empty($planids)) { return; } list($insql, $inparams) = $DB->get_in_or_equal($planids, SQL_PARAMS_NAMED); // Delete all the competencies proficiency in the plans. $DB->delete_records_select(user_competency_plan::TABLE, "planid $insql", $inparams); // Delete all the competencies in the plans. $DB->delete_records_select(plan_competency::TABLE, "planid $insql", $inparams); // Delete all the plans. $DB->delete_records_select(plan::TABLE, "id $insql", $inparams); }
php
protected static function delete_user_plans($userid) { global $DB; $usercontext = context_user::instance($userid); // Remove all the comments made on plans. \core_comment\privacy\provider::delete_comments_for_all_users($usercontext, 'competency', 'plan'); // Find the user plan IDs. $planids = $DB->get_fieldset_select(plan::TABLE, 'id', 'userid = :userid', ['userid' => $userid]); if (empty($planids)) { return; } list($insql, $inparams) = $DB->get_in_or_equal($planids, SQL_PARAMS_NAMED); // Delete all the competencies proficiency in the plans. $DB->delete_records_select(user_competency_plan::TABLE, "planid $insql", $inparams); // Delete all the competencies in the plans. $DB->delete_records_select(plan_competency::TABLE, "planid $insql", $inparams); // Delete all the plans. $DB->delete_records_select(plan::TABLE, "id $insql", $inparams); }
[ "protected", "static", "function", "delete_user_plans", "(", "$", "userid", ")", "{", "global", "$", "DB", ";", "$", "usercontext", "=", "context_user", "::", "instance", "(", "$", "userid", ")", ";", "// Remove all the comments made on plans.", "\\", "core_comment", "\\", "privacy", "\\", "provider", "::", "delete_comments_for_all_users", "(", "$", "usercontext", ",", "'competency'", ",", "'plan'", ")", ";", "// Find the user plan IDs.", "$", "planids", "=", "$", "DB", "->", "get_fieldset_select", "(", "plan", "::", "TABLE", ",", "'id'", ",", "'userid = :userid'", ",", "[", "'userid'", "=>", "$", "userid", "]", ")", ";", "if", "(", "empty", "(", "$", "planids", ")", ")", "{", "return", ";", "}", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "planids", ",", "SQL_PARAMS_NAMED", ")", ";", "// Delete all the competencies proficiency in the plans.", "$", "DB", "->", "delete_records_select", "(", "user_competency_plan", "::", "TABLE", ",", "\"planid $insql\"", ",", "$", "inparams", ")", ";", "// Delete all the competencies in the plans.", "$", "DB", "->", "delete_records_select", "(", "plan_competency", "::", "TABLE", ",", "\"planid $insql\"", ",", "$", "inparams", ")", ";", "// Delete all the plans.", "$", "DB", "->", "delete_records_select", "(", "plan", "::", "TABLE", ",", "\"id $insql\"", ",", "$", "inparams", ")", ";", "}" ]
User plans. @param int $userid The user ID. @return void
[ "User", "plans", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L745-L767
214,110
moodle/moodle
competency/classes/privacy/provider.php
provider.delete_user_competencies
protected static function delete_user_competencies($userid) { global $DB; $usercontext = context_user::instance($userid); // Remove all the comments made on user competencies. \core_comment\privacy\provider::delete_comments_for_all_users($usercontext, 'competency', 'user_competency'); // Find the user competency IDs. $ucids = $DB->get_fieldset_select(user_competency::TABLE, 'id', 'userid = :userid', ['userid' => $userid]); if (empty($ucids)) { return; } list($insql, $inparams) = $DB->get_in_or_equal($ucids, SQL_PARAMS_NAMED); // Delete all the evidence associated with competencies. $DB->delete_records_select(evidence::TABLE, "usercompetencyid $insql", $inparams); // Delete all the record of competency. $DB->delete_records_select(user_competency::TABLE, "id $insql", $inparams); }
php
protected static function delete_user_competencies($userid) { global $DB; $usercontext = context_user::instance($userid); // Remove all the comments made on user competencies. \core_comment\privacy\provider::delete_comments_for_all_users($usercontext, 'competency', 'user_competency'); // Find the user competency IDs. $ucids = $DB->get_fieldset_select(user_competency::TABLE, 'id', 'userid = :userid', ['userid' => $userid]); if (empty($ucids)) { return; } list($insql, $inparams) = $DB->get_in_or_equal($ucids, SQL_PARAMS_NAMED); // Delete all the evidence associated with competencies. $DB->delete_records_select(evidence::TABLE, "usercompetencyid $insql", $inparams); // Delete all the record of competency. $DB->delete_records_select(user_competency::TABLE, "id $insql", $inparams); }
[ "protected", "static", "function", "delete_user_competencies", "(", "$", "userid", ")", "{", "global", "$", "DB", ";", "$", "usercontext", "=", "context_user", "::", "instance", "(", "$", "userid", ")", ";", "// Remove all the comments made on user competencies.", "\\", "core_comment", "\\", "privacy", "\\", "provider", "::", "delete_comments_for_all_users", "(", "$", "usercontext", ",", "'competency'", ",", "'user_competency'", ")", ";", "// Find the user competency IDs.", "$", "ucids", "=", "$", "DB", "->", "get_fieldset_select", "(", "user_competency", "::", "TABLE", ",", "'id'", ",", "'userid = :userid'", ",", "[", "'userid'", "=>", "$", "userid", "]", ")", ";", "if", "(", "empty", "(", "$", "ucids", ")", ")", "{", "return", ";", "}", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "ucids", ",", "SQL_PARAMS_NAMED", ")", ";", "// Delete all the evidence associated with competencies.", "$", "DB", "->", "delete_records_select", "(", "evidence", "::", "TABLE", ",", "\"usercompetencyid $insql\"", ",", "$", "inparams", ")", ";", "// Delete all the record of competency.", "$", "DB", "->", "delete_records_select", "(", "user_competency", "::", "TABLE", ",", "\"id $insql\"", ",", "$", "inparams", ")", ";", "}" ]
Delete user competency data. @param int $userid The user ID. @return void
[ "Delete", "user", "competency", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L775-L794
214,111
moodle/moodle
competency/classes/privacy/provider.php
provider.export_user_data_in_user_contexts
protected static function export_user_data_in_user_contexts($userid, array $contexts) { global $DB; $mycontext = context_user::instance($userid); $contextids = array_map(function($context) { return $context->id; }, $contexts); $exportowncontext = in_array($mycontext->id, $contextids); $othercontexts = array_filter($contextids, function($contextid) use ($mycontext) { return $contextid != $mycontext->id; }); if ($exportowncontext) { static::export_user_data_learning_plans($mycontext); static::export_user_data_competencies($mycontext); static::export_user_data_user_evidence($mycontext); } foreach ($othercontexts as $contextid) { static::export_user_data_learning_plans_related_to_me($userid, context::instance_by_id($contextid)); static::export_user_data_competencies_related_to_me($userid, context::instance_by_id($contextid)); static::export_user_data_user_evidence_related_to_me($userid, context::instance_by_id($contextid)); } }
php
protected static function export_user_data_in_user_contexts($userid, array $contexts) { global $DB; $mycontext = context_user::instance($userid); $contextids = array_map(function($context) { return $context->id; }, $contexts); $exportowncontext = in_array($mycontext->id, $contextids); $othercontexts = array_filter($contextids, function($contextid) use ($mycontext) { return $contextid != $mycontext->id; }); if ($exportowncontext) { static::export_user_data_learning_plans($mycontext); static::export_user_data_competencies($mycontext); static::export_user_data_user_evidence($mycontext); } foreach ($othercontexts as $contextid) { static::export_user_data_learning_plans_related_to_me($userid, context::instance_by_id($contextid)); static::export_user_data_competencies_related_to_me($userid, context::instance_by_id($contextid)); static::export_user_data_user_evidence_related_to_me($userid, context::instance_by_id($contextid)); } }
[ "protected", "static", "function", "export_user_data_in_user_contexts", "(", "$", "userid", ",", "array", "$", "contexts", ")", "{", "global", "$", "DB", ";", "$", "mycontext", "=", "context_user", "::", "instance", "(", "$", "userid", ")", ";", "$", "contextids", "=", "array_map", "(", "function", "(", "$", "context", ")", "{", "return", "$", "context", "->", "id", ";", "}", ",", "$", "contexts", ")", ";", "$", "exportowncontext", "=", "in_array", "(", "$", "mycontext", "->", "id", ",", "$", "contextids", ")", ";", "$", "othercontexts", "=", "array_filter", "(", "$", "contextids", ",", "function", "(", "$", "contextid", ")", "use", "(", "$", "mycontext", ")", "{", "return", "$", "contextid", "!=", "$", "mycontext", "->", "id", ";", "}", ")", ";", "if", "(", "$", "exportowncontext", ")", "{", "static", "::", "export_user_data_learning_plans", "(", "$", "mycontext", ")", ";", "static", "::", "export_user_data_competencies", "(", "$", "mycontext", ")", ";", "static", "::", "export_user_data_user_evidence", "(", "$", "mycontext", ")", ";", "}", "foreach", "(", "$", "othercontexts", "as", "$", "contextid", ")", "{", "static", "::", "export_user_data_learning_plans_related_to_me", "(", "$", "userid", ",", "context", "::", "instance_by_id", "(", "$", "contextid", ")", ")", ";", "static", "::", "export_user_data_competencies_related_to_me", "(", "$", "userid", ",", "context", "::", "instance_by_id", "(", "$", "contextid", ")", ")", ";", "static", "::", "export_user_data_user_evidence_related_to_me", "(", "$", "userid", ",", "context", "::", "instance_by_id", "(", "$", "contextid", ")", ")", ";", "}", "}" ]
Export the user data in user context. @param int $userid The user ID. @param array $contexts The contexts. @return void
[ "Export", "the", "user", "data", "in", "user", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L826-L849
214,112
moodle/moodle
competency/classes/privacy/provider.php
provider.export_user_data_in_system_context
protected static function export_user_data_in_system_context($userid) { static::export_user_data_frameworks_in_context($userid, context_system::instance()); static::export_user_data_templates_in_context($userid, context_system::instance()); }
php
protected static function export_user_data_in_system_context($userid) { static::export_user_data_frameworks_in_context($userid, context_system::instance()); static::export_user_data_templates_in_context($userid, context_system::instance()); }
[ "protected", "static", "function", "export_user_data_in_system_context", "(", "$", "userid", ")", "{", "static", "::", "export_user_data_frameworks_in_context", "(", "$", "userid", ",", "context_system", "::", "instance", "(", ")", ")", ";", "static", "::", "export_user_data_templates_in_context", "(", "$", "userid", ",", "context_system", "::", "instance", "(", ")", ")", ";", "}" ]
Export the user data in systen context. @param int $userid The user ID. @return void
[ "Export", "the", "user", "data", "in", "systen", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L857-L860
214,113
moodle/moodle
competency/classes/privacy/provider.php
provider.export_user_data_in_category_contexts
protected static function export_user_data_in_category_contexts($userid, array $contexts) { $contexts = array_filter($contexts, function($context) { return $context->contextlevel == CONTEXT_COURSECAT; }); if (empty($contexts)) { return; } foreach ($contexts as $context) { static::export_user_data_frameworks_in_context($userid, $context); static::export_user_data_templates_in_context($userid, $context); } }
php
protected static function export_user_data_in_category_contexts($userid, array $contexts) { $contexts = array_filter($contexts, function($context) { return $context->contextlevel == CONTEXT_COURSECAT; }); if (empty($contexts)) { return; } foreach ($contexts as $context) { static::export_user_data_frameworks_in_context($userid, $context); static::export_user_data_templates_in_context($userid, $context); } }
[ "protected", "static", "function", "export_user_data_in_category_contexts", "(", "$", "userid", ",", "array", "$", "contexts", ")", "{", "$", "contexts", "=", "array_filter", "(", "$", "contexts", ",", "function", "(", "$", "context", ")", "{", "return", "$", "context", "->", "contextlevel", "==", "CONTEXT_COURSECAT", ";", "}", ")", ";", "if", "(", "empty", "(", "$", "contexts", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "contexts", "as", "$", "context", ")", "{", "static", "::", "export_user_data_frameworks_in_context", "(", "$", "userid", ",", "$", "context", ")", ";", "static", "::", "export_user_data_templates_in_context", "(", "$", "userid", ",", "$", "context", ")", ";", "}", "}" ]
Export the user data in category contexts. @param int $userid The user ID. @param array $contexts The contexts. @return void
[ "Export", "the", "user", "data", "in", "category", "contexts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L869-L881
214,114
moodle/moodle
competency/classes/privacy/provider.php
provider.export_user_data_in_course_contexts_rated_by_me
protected static function export_user_data_in_course_contexts_rated_by_me($userid, $courseids, $path, performance_helper $helper) { global $DB; // Fetch all the records of competency proficiency in the course. $ffields = competency_framework::get_sql_fields('f', 'f_'); $compfields = competency::get_sql_fields('c', 'c_'); $uccfields = user_competency_course::get_sql_fields('ucc', 'ucc_'); $ctxfields = context_helper::get_preload_record_columns_sql('ctx'); list($insql, $inparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED); $sql = " SELECT $ffields, $compfields, $uccfields, $ctxfields FROM {" . user_competency_course::TABLE . "} ucc JOIN {" . competency::TABLE . "} c ON c.id = ucc.competencyid JOIN {" . competency_framework::TABLE . "} f ON f.id = c.competencyframeworkid JOIN {context} ctx ON ctx.id = f.contextid WHERE ucc.usermodified = :userid AND ucc.courseid $insql ORDER BY ucc.courseid, ucc.id"; $params = array_merge($inparams, ['userid' => $userid]); // Export the data. static::recordset_loop_and_export($DB->get_recordset_sql($sql, $params), 'ucc_courseid', [], function($carry, $record) use ($helper) { context_helper::preload_from_record($record); $framework = new competency_framework(null, competency_framework::extract_record($record, 'f_')); $competency = new competency(null, competency::extract_record($record, 'c_')); $ucc = new user_competency_course(null, user_competency_course::extract_record($record, 'ucc_')); $helper->ingest_framework($framework); $carry[] = array_merge(static::transform_competency_brief($competency), [ 'rating' => [ 'userid' => transform::user($ucc->get('userid')), 'rating' => static::transform_competency_grade($competency, $ucc->get('grade'), $helper), 'proficient' => static::transform_proficiency($ucc->get('proficiency')), 'timemodified' => transform::datetime($ucc->get('timemodified')), ] ]); return $carry; }, function($courseid, $data) use ($path) { $context = context_course::instance($courseid); writer::with_context($context)->export_related_data($path, 'rated_by_me', (object) [ 'ratings' => $data ]); } ); }
php
protected static function export_user_data_in_course_contexts_rated_by_me($userid, $courseids, $path, performance_helper $helper) { global $DB; // Fetch all the records of competency proficiency in the course. $ffields = competency_framework::get_sql_fields('f', 'f_'); $compfields = competency::get_sql_fields('c', 'c_'); $uccfields = user_competency_course::get_sql_fields('ucc', 'ucc_'); $ctxfields = context_helper::get_preload_record_columns_sql('ctx'); list($insql, $inparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED); $sql = " SELECT $ffields, $compfields, $uccfields, $ctxfields FROM {" . user_competency_course::TABLE . "} ucc JOIN {" . competency::TABLE . "} c ON c.id = ucc.competencyid JOIN {" . competency_framework::TABLE . "} f ON f.id = c.competencyframeworkid JOIN {context} ctx ON ctx.id = f.contextid WHERE ucc.usermodified = :userid AND ucc.courseid $insql ORDER BY ucc.courseid, ucc.id"; $params = array_merge($inparams, ['userid' => $userid]); // Export the data. static::recordset_loop_and_export($DB->get_recordset_sql($sql, $params), 'ucc_courseid', [], function($carry, $record) use ($helper) { context_helper::preload_from_record($record); $framework = new competency_framework(null, competency_framework::extract_record($record, 'f_')); $competency = new competency(null, competency::extract_record($record, 'c_')); $ucc = new user_competency_course(null, user_competency_course::extract_record($record, 'ucc_')); $helper->ingest_framework($framework); $carry[] = array_merge(static::transform_competency_brief($competency), [ 'rating' => [ 'userid' => transform::user($ucc->get('userid')), 'rating' => static::transform_competency_grade($competency, $ucc->get('grade'), $helper), 'proficient' => static::transform_proficiency($ucc->get('proficiency')), 'timemodified' => transform::datetime($ucc->get('timemodified')), ] ]); return $carry; }, function($courseid, $data) use ($path) { $context = context_course::instance($courseid); writer::with_context($context)->export_related_data($path, 'rated_by_me', (object) [ 'ratings' => $data ]); } ); }
[ "protected", "static", "function", "export_user_data_in_course_contexts_rated_by_me", "(", "$", "userid", ",", "$", "courseids", ",", "$", "path", ",", "performance_helper", "$", "helper", ")", "{", "global", "$", "DB", ";", "// Fetch all the records of competency proficiency in the course.", "$", "ffields", "=", "competency_framework", "::", "get_sql_fields", "(", "'f'", ",", "'f_'", ")", ";", "$", "compfields", "=", "competency", "::", "get_sql_fields", "(", "'c'", ",", "'c_'", ")", ";", "$", "uccfields", "=", "user_competency_course", "::", "get_sql_fields", "(", "'ucc'", ",", "'ucc_'", ")", ";", "$", "ctxfields", "=", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ";", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "courseids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sql", "=", "\"\n SELECT $ffields, $compfields, $uccfields, $ctxfields\n FROM {\"", ".", "user_competency_course", "::", "TABLE", ".", "\"} ucc\n JOIN {\"", ".", "competency", "::", "TABLE", ".", "\"} c\n ON c.id = ucc.competencyid\n JOIN {\"", ".", "competency_framework", "::", "TABLE", ".", "\"} f\n ON f.id = c.competencyframeworkid\n JOIN {context} ctx\n ON ctx.id = f.contextid\n WHERE ucc.usermodified = :userid\n AND ucc.courseid $insql\n ORDER BY ucc.courseid, ucc.id\"", ";", "$", "params", "=", "array_merge", "(", "$", "inparams", ",", "[", "'userid'", "=>", "$", "userid", "]", ")", ";", "// Export the data.", "static", "::", "recordset_loop_and_export", "(", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ",", "'ucc_courseid'", ",", "[", "]", ",", "function", "(", "$", "carry", ",", "$", "record", ")", "use", "(", "$", "helper", ")", "{", "context_helper", "::", "preload_from_record", "(", "$", "record", ")", ";", "$", "framework", "=", "new", "competency_framework", "(", "null", ",", "competency_framework", "::", "extract_record", "(", "$", "record", ",", "'f_'", ")", ")", ";", "$", "competency", "=", "new", "competency", "(", "null", ",", "competency", "::", "extract_record", "(", "$", "record", ",", "'c_'", ")", ")", ";", "$", "ucc", "=", "new", "user_competency_course", "(", "null", ",", "user_competency_course", "::", "extract_record", "(", "$", "record", ",", "'ucc_'", ")", ")", ";", "$", "helper", "->", "ingest_framework", "(", "$", "framework", ")", ";", "$", "carry", "[", "]", "=", "array_merge", "(", "static", "::", "transform_competency_brief", "(", "$", "competency", ")", ",", "[", "'rating'", "=>", "[", "'userid'", "=>", "transform", "::", "user", "(", "$", "ucc", "->", "get", "(", "'userid'", ")", ")", ",", "'rating'", "=>", "static", "::", "transform_competency_grade", "(", "$", "competency", ",", "$", "ucc", "->", "get", "(", "'grade'", ")", ",", "$", "helper", ")", ",", "'proficient'", "=>", "static", "::", "transform_proficiency", "(", "$", "ucc", "->", "get", "(", "'proficiency'", ")", ")", ",", "'timemodified'", "=>", "transform", "::", "datetime", "(", "$", "ucc", "->", "get", "(", "'timemodified'", ")", ")", ",", "]", "]", ")", ";", "return", "$", "carry", ";", "}", ",", "function", "(", "$", "courseid", ",", "$", "data", ")", "use", "(", "$", "path", ")", "{", "$", "context", "=", "context_course", "::", "instance", "(", "$", "courseid", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_related_data", "(", "$", "path", ",", "'rated_by_me'", ",", "(", "object", ")", "[", "'ratings'", "=>", "$", "data", "]", ")", ";", "}", ")", ";", "}" ]
Export the ratings given in a course. @param int $userid The user ID. @param array $courseids The course IDs. @param array $path The root path. @param performance_helper $helper The performance helper. @return void
[ "Export", "the", "ratings", "given", "in", "a", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L965-L1016
214,115
moodle/moodle
competency/classes/privacy/provider.php
provider.export_user_data_in_course_contexts_associations
protected static function export_user_data_in_course_contexts_associations($userid, $courseids, $path) { global $DB; // Fetch all the courses with associations we created or modified. $compfields = competency::get_sql_fields('c', 'c_'); $ccfields = course_competency::get_sql_fields('cc', 'cc_'); $ctxfields = context_helper::get_preload_record_columns_sql('ctx'); list($insql, $inparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED); $sql = " SELECT $compfields, $ccfields, $ctxfields FROM {" . course_competency::TABLE . "} cc JOIN {" . competency::TABLE . "} c ON c.id = cc.competencyid JOIN {" . competency_framework::TABLE . "} f ON f.id = c.competencyframeworkid JOIN {context} ctx ON ctx.id = f.contextid WHERE cc.usermodified = :userid AND cc.courseid $insql ORDER BY cc.courseid, c.id"; $params = array_merge($inparams, ['userid' => $userid]); $recordset = $DB->get_recordset_sql($sql, $params); // Export the data. static::recordset_loop_and_export($recordset, 'cc_courseid', [], function($carry, $record) { context_helper::preload_from_record($record); $competency = new competency(null, competency::extract_record($record, 'c_')); $cc = new course_competency(null, course_competency::extract_record($record, 'cc_')); $carry[] = array_merge(static::transform_competency_brief($competency), [ 'timemodified' => transform::datetime($cc->get('timemodified')), 'created_or_modified_by_you' => transform::yesno(true) ]); return $carry; }, function($courseid, $data) use ($path, $userid, $DB) { $context = context_course::instance($courseid); writer::with_context($context)->export_related_data($path, 'associations', (object) ['competencies' => $data]); }); }
php
protected static function export_user_data_in_course_contexts_associations($userid, $courseids, $path) { global $DB; // Fetch all the courses with associations we created or modified. $compfields = competency::get_sql_fields('c', 'c_'); $ccfields = course_competency::get_sql_fields('cc', 'cc_'); $ctxfields = context_helper::get_preload_record_columns_sql('ctx'); list($insql, $inparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED); $sql = " SELECT $compfields, $ccfields, $ctxfields FROM {" . course_competency::TABLE . "} cc JOIN {" . competency::TABLE . "} c ON c.id = cc.competencyid JOIN {" . competency_framework::TABLE . "} f ON f.id = c.competencyframeworkid JOIN {context} ctx ON ctx.id = f.contextid WHERE cc.usermodified = :userid AND cc.courseid $insql ORDER BY cc.courseid, c.id"; $params = array_merge($inparams, ['userid' => $userid]); $recordset = $DB->get_recordset_sql($sql, $params); // Export the data. static::recordset_loop_and_export($recordset, 'cc_courseid', [], function($carry, $record) { context_helper::preload_from_record($record); $competency = new competency(null, competency::extract_record($record, 'c_')); $cc = new course_competency(null, course_competency::extract_record($record, 'cc_')); $carry[] = array_merge(static::transform_competency_brief($competency), [ 'timemodified' => transform::datetime($cc->get('timemodified')), 'created_or_modified_by_you' => transform::yesno(true) ]); return $carry; }, function($courseid, $data) use ($path, $userid, $DB) { $context = context_course::instance($courseid); writer::with_context($context)->export_related_data($path, 'associations', (object) ['competencies' => $data]); }); }
[ "protected", "static", "function", "export_user_data_in_course_contexts_associations", "(", "$", "userid", ",", "$", "courseids", ",", "$", "path", ")", "{", "global", "$", "DB", ";", "// Fetch all the courses with associations we created or modified.", "$", "compfields", "=", "competency", "::", "get_sql_fields", "(", "'c'", ",", "'c_'", ")", ";", "$", "ccfields", "=", "course_competency", "::", "get_sql_fields", "(", "'cc'", ",", "'cc_'", ")", ";", "$", "ctxfields", "=", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ";", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "courseids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sql", "=", "\"\n SELECT $compfields, $ccfields, $ctxfields\n FROM {\"", ".", "course_competency", "::", "TABLE", ".", "\"} cc\n JOIN {\"", ".", "competency", "::", "TABLE", ".", "\"} c\n ON c.id = cc.competencyid\n JOIN {\"", ".", "competency_framework", "::", "TABLE", ".", "\"} f\n ON f.id = c.competencyframeworkid\n JOIN {context} ctx\n ON ctx.id = f.contextid\n WHERE cc.usermodified = :userid\n AND cc.courseid $insql\n ORDER BY cc.courseid, c.id\"", ";", "$", "params", "=", "array_merge", "(", "$", "inparams", ",", "[", "'userid'", "=>", "$", "userid", "]", ")", ";", "$", "recordset", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "// Export the data.", "static", "::", "recordset_loop_and_export", "(", "$", "recordset", ",", "'cc_courseid'", ",", "[", "]", ",", "function", "(", "$", "carry", ",", "$", "record", ")", "{", "context_helper", "::", "preload_from_record", "(", "$", "record", ")", ";", "$", "competency", "=", "new", "competency", "(", "null", ",", "competency", "::", "extract_record", "(", "$", "record", ",", "'c_'", ")", ")", ";", "$", "cc", "=", "new", "course_competency", "(", "null", ",", "course_competency", "::", "extract_record", "(", "$", "record", ",", "'cc_'", ")", ")", ";", "$", "carry", "[", "]", "=", "array_merge", "(", "static", "::", "transform_competency_brief", "(", "$", "competency", ")", ",", "[", "'timemodified'", "=>", "transform", "::", "datetime", "(", "$", "cc", "->", "get", "(", "'timemodified'", ")", ")", ",", "'created_or_modified_by_you'", "=>", "transform", "::", "yesno", "(", "true", ")", "]", ")", ";", "return", "$", "carry", ";", "}", ",", "function", "(", "$", "courseid", ",", "$", "data", ")", "use", "(", "$", "path", ",", "$", "userid", ",", "$", "DB", ")", "{", "$", "context", "=", "context_course", "::", "instance", "(", "$", "courseid", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_related_data", "(", "$", "path", ",", "'associations'", ",", "(", "object", ")", "[", "'competencies'", "=>", "$", "data", "]", ")", ";", "}", ")", ";", "}" ]
Export user data in course contexts related to linked competencies. @param int $userid The user ID. @param array $courseids The course IDs. @param array $path The root path to export at. @return void
[ "Export", "user", "data", "in", "course", "contexts", "related", "to", "linked", "competencies", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L1026-L1064
214,116
moodle/moodle
competency/classes/privacy/provider.php
provider.export_user_data_in_course_contexts_settings
protected static function export_user_data_in_course_contexts_settings($userid, $courseids, $path) { global $DB; // Fetch all the courses with associations we created or modified. $ccsfields = course_competency_settings::get_sql_fields('ccs', 'ccs_'); list($insql, $inparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED); $sql = " SELECT $ccsfields FROM {" . course_competency_settings::TABLE . "} ccs WHERE ccs.usermodified = :userid AND ccs.courseid $insql ORDER BY ccs.courseid"; $params = array_merge($inparams, ['userid' => $userid]); $recordset = $DB->get_recordset_sql($sql, $params); // Export the data. static::recordset_loop_and_export($recordset, 'ccs_courseid', [], function($carry, $record) { $ccs = new course_competency_settings(null, course_competency_settings::extract_record($record, 'ccs_')); return [ 'timemodified' => transform::datetime($ccs->get('timemodified')), 'created_or_modified_by_you' => transform::yesno(true) ]; }, function($courseid, $data) use ($path, $userid, $DB) { $context = context_course::instance($courseid); writer::with_context($context)->export_related_data($path, 'settings', (object) $data); }); }
php
protected static function export_user_data_in_course_contexts_settings($userid, $courseids, $path) { global $DB; // Fetch all the courses with associations we created or modified. $ccsfields = course_competency_settings::get_sql_fields('ccs', 'ccs_'); list($insql, $inparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED); $sql = " SELECT $ccsfields FROM {" . course_competency_settings::TABLE . "} ccs WHERE ccs.usermodified = :userid AND ccs.courseid $insql ORDER BY ccs.courseid"; $params = array_merge($inparams, ['userid' => $userid]); $recordset = $DB->get_recordset_sql($sql, $params); // Export the data. static::recordset_loop_and_export($recordset, 'ccs_courseid', [], function($carry, $record) { $ccs = new course_competency_settings(null, course_competency_settings::extract_record($record, 'ccs_')); return [ 'timemodified' => transform::datetime($ccs->get('timemodified')), 'created_or_modified_by_you' => transform::yesno(true) ]; }, function($courseid, $data) use ($path, $userid, $DB) { $context = context_course::instance($courseid); writer::with_context($context)->export_related_data($path, 'settings', (object) $data); }); }
[ "protected", "static", "function", "export_user_data_in_course_contexts_settings", "(", "$", "userid", ",", "$", "courseids", ",", "$", "path", ")", "{", "global", "$", "DB", ";", "// Fetch all the courses with associations we created or modified.", "$", "ccsfields", "=", "course_competency_settings", "::", "get_sql_fields", "(", "'ccs'", ",", "'ccs_'", ")", ";", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "courseids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sql", "=", "\"\n SELECT $ccsfields\n FROM {\"", ".", "course_competency_settings", "::", "TABLE", ".", "\"} ccs\n WHERE ccs.usermodified = :userid\n AND ccs.courseid $insql\n ORDER BY ccs.courseid\"", ";", "$", "params", "=", "array_merge", "(", "$", "inparams", ",", "[", "'userid'", "=>", "$", "userid", "]", ")", ";", "$", "recordset", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "// Export the data.", "static", "::", "recordset_loop_and_export", "(", "$", "recordset", ",", "'ccs_courseid'", ",", "[", "]", ",", "function", "(", "$", "carry", ",", "$", "record", ")", "{", "$", "ccs", "=", "new", "course_competency_settings", "(", "null", ",", "course_competency_settings", "::", "extract_record", "(", "$", "record", ",", "'ccs_'", ")", ")", ";", "return", "[", "'timemodified'", "=>", "transform", "::", "datetime", "(", "$", "ccs", "->", "get", "(", "'timemodified'", ")", ")", ",", "'created_or_modified_by_you'", "=>", "transform", "::", "yesno", "(", "true", ")", "]", ";", "}", ",", "function", "(", "$", "courseid", ",", "$", "data", ")", "use", "(", "$", "path", ",", "$", "userid", ",", "$", "DB", ")", "{", "$", "context", "=", "context_course", "::", "instance", "(", "$", "courseid", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_related_data", "(", "$", "path", ",", "'settings'", ",", "(", "object", ")", "$", "data", ")", ";", "}", ")", ";", "}" ]
Export user data in course contexts related to course settings. @param int $userid The user ID. @param array $courseids The course IDs. @param array $path The root path to export at. @return void
[ "Export", "user", "data", "in", "course", "contexts", "related", "to", "course", "settings", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L1074-L1100
214,117
moodle/moodle
competency/classes/privacy/provider.php
provider.export_user_data_in_module_contexts
protected static function export_user_data_in_module_contexts($userid, array $contexts) { global $DB; $contexts = array_filter($contexts, function($context) { return $context->contextlevel == CONTEXT_MODULE; }); if (empty($contexts)) { return; } $path = [get_string('competencies', 'core_competency')]; $cmids = array_map(function($context) { return $context->instanceid; }, $contexts); // Fetch all the modules with associations we created or modified. $compfields = competency::get_sql_fields('c', 'c_'); $cmcfields = course_module_competency::get_sql_fields('cmc', 'cmc_'); $ctxfields = context_helper::get_preload_record_columns_sql('ctx'); list($insql, $inparams) = $DB->get_in_or_equal($cmids, SQL_PARAMS_NAMED); $sql = " SELECT $compfields, $cmcfields, $ctxfields FROM {" . course_module_competency::TABLE . "} cmc JOIN {" . competency::TABLE . "} c ON c.id = cmc.competencyid JOIN {" . competency_framework::TABLE . "} f ON f.id = c.competencyframeworkid JOIN {context} ctx ON ctx.id = f.contextid WHERE cmc.usermodified = :userid AND cmc.cmid $insql ORDER BY cmc.cmid"; $params = array_merge($inparams, ['userid' => $userid]); // Export the data. $recordset = $DB->get_recordset_sql($sql, $params); static::recordset_loop_and_export($recordset, 'cmc_cmid', [], function($carry, $record) { context_helper::preload_from_record($record); $competency = new competency(null, competency::extract_record($record, 'c_')); $cmc = new course_module_competency(null, course_module_competency::extract_record($record, 'cmc_')); $carry[] = array_merge(static::transform_competency_brief($competency), [ 'timecreated' => transform::datetime($cmc->get('timecreated')), 'timemodified' => transform::datetime($cmc->get('timemodified')), 'created_or_modified_by_you' => transform::yesno(true) ]); return $carry; }, function($cmid, $data) use ($path) { $context = context_module::instance($cmid); writer::with_context($context)->export_data($path, (object) ['associations' => $data]); }); }
php
protected static function export_user_data_in_module_contexts($userid, array $contexts) { global $DB; $contexts = array_filter($contexts, function($context) { return $context->contextlevel == CONTEXT_MODULE; }); if (empty($contexts)) { return; } $path = [get_string('competencies', 'core_competency')]; $cmids = array_map(function($context) { return $context->instanceid; }, $contexts); // Fetch all the modules with associations we created or modified. $compfields = competency::get_sql_fields('c', 'c_'); $cmcfields = course_module_competency::get_sql_fields('cmc', 'cmc_'); $ctxfields = context_helper::get_preload_record_columns_sql('ctx'); list($insql, $inparams) = $DB->get_in_or_equal($cmids, SQL_PARAMS_NAMED); $sql = " SELECT $compfields, $cmcfields, $ctxfields FROM {" . course_module_competency::TABLE . "} cmc JOIN {" . competency::TABLE . "} c ON c.id = cmc.competencyid JOIN {" . competency_framework::TABLE . "} f ON f.id = c.competencyframeworkid JOIN {context} ctx ON ctx.id = f.contextid WHERE cmc.usermodified = :userid AND cmc.cmid $insql ORDER BY cmc.cmid"; $params = array_merge($inparams, ['userid' => $userid]); // Export the data. $recordset = $DB->get_recordset_sql($sql, $params); static::recordset_loop_and_export($recordset, 'cmc_cmid', [], function($carry, $record) { context_helper::preload_from_record($record); $competency = new competency(null, competency::extract_record($record, 'c_')); $cmc = new course_module_competency(null, course_module_competency::extract_record($record, 'cmc_')); $carry[] = array_merge(static::transform_competency_brief($competency), [ 'timecreated' => transform::datetime($cmc->get('timecreated')), 'timemodified' => transform::datetime($cmc->get('timemodified')), 'created_or_modified_by_you' => transform::yesno(true) ]); return $carry; }, function($cmid, $data) use ($path) { $context = context_module::instance($cmid); writer::with_context($context)->export_data($path, (object) ['associations' => $data]); }); }
[ "protected", "static", "function", "export_user_data_in_module_contexts", "(", "$", "userid", ",", "array", "$", "contexts", ")", "{", "global", "$", "DB", ";", "$", "contexts", "=", "array_filter", "(", "$", "contexts", ",", "function", "(", "$", "context", ")", "{", "return", "$", "context", "->", "contextlevel", "==", "CONTEXT_MODULE", ";", "}", ")", ";", "if", "(", "empty", "(", "$", "contexts", ")", ")", "{", "return", ";", "}", "$", "path", "=", "[", "get_string", "(", "'competencies'", ",", "'core_competency'", ")", "]", ";", "$", "cmids", "=", "array_map", "(", "function", "(", "$", "context", ")", "{", "return", "$", "context", "->", "instanceid", ";", "}", ",", "$", "contexts", ")", ";", "// Fetch all the modules with associations we created or modified.", "$", "compfields", "=", "competency", "::", "get_sql_fields", "(", "'c'", ",", "'c_'", ")", ";", "$", "cmcfields", "=", "course_module_competency", "::", "get_sql_fields", "(", "'cmc'", ",", "'cmc_'", ")", ";", "$", "ctxfields", "=", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ";", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "cmids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sql", "=", "\"\n SELECT $compfields, $cmcfields, $ctxfields\n FROM {\"", ".", "course_module_competency", "::", "TABLE", ".", "\"} cmc\n JOIN {\"", ".", "competency", "::", "TABLE", ".", "\"} c\n ON c.id = cmc.competencyid\n JOIN {\"", ".", "competency_framework", "::", "TABLE", ".", "\"} f\n ON f.id = c.competencyframeworkid\n JOIN {context} ctx\n ON ctx.id = f.contextid\n WHERE cmc.usermodified = :userid\n AND cmc.cmid $insql\n ORDER BY cmc.cmid\"", ";", "$", "params", "=", "array_merge", "(", "$", "inparams", ",", "[", "'userid'", "=>", "$", "userid", "]", ")", ";", "// Export the data.", "$", "recordset", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "static", "::", "recordset_loop_and_export", "(", "$", "recordset", ",", "'cmc_cmid'", ",", "[", "]", ",", "function", "(", "$", "carry", ",", "$", "record", ")", "{", "context_helper", "::", "preload_from_record", "(", "$", "record", ")", ";", "$", "competency", "=", "new", "competency", "(", "null", ",", "competency", "::", "extract_record", "(", "$", "record", ",", "'c_'", ")", ")", ";", "$", "cmc", "=", "new", "course_module_competency", "(", "null", ",", "course_module_competency", "::", "extract_record", "(", "$", "record", ",", "'cmc_'", ")", ")", ";", "$", "carry", "[", "]", "=", "array_merge", "(", "static", "::", "transform_competency_brief", "(", "$", "competency", ")", ",", "[", "'timecreated'", "=>", "transform", "::", "datetime", "(", "$", "cmc", "->", "get", "(", "'timecreated'", ")", ")", ",", "'timemodified'", "=>", "transform", "::", "datetime", "(", "$", "cmc", "->", "get", "(", "'timemodified'", ")", ")", ",", "'created_or_modified_by_you'", "=>", "transform", "::", "yesno", "(", "true", ")", "]", ")", ";", "return", "$", "carry", ";", "}", ",", "function", "(", "$", "cmid", ",", "$", "data", ")", "use", "(", "$", "path", ")", "{", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cmid", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "$", "path", ",", "(", "object", ")", "[", "'associations'", "=>", "$", "data", "]", ")", ";", "}", ")", ";", "}" ]
Export the user data in module contexts. @param int $userid The user whose data we're exporting. @param array $contexts A list of contexts. @return void
[ "Export", "the", "user", "data", "in", "module", "contexts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L1109-L1160
214,118
moodle/moodle
competency/classes/privacy/provider.php
provider.export_user_data_competencies
protected static function export_user_data_competencies(context_user $context) { global $DB; $userid = $context->instanceid; $path = [get_string('competencies', 'core_competency'), get_string('competencies', 'core_competency')]; $helper = new performance_helper(); $cfields = competency::get_sql_fields('c', 'c_'); $ucfields = user_competency::get_sql_fields('uc', 'uc_'); $efields = evidence::get_sql_fields('e', 'e_'); $makecomppath = function($competencyid, $data) use ($path) { return array_merge($path, [$data['name'] . ' (' . $competencyid . ')']); }; $sql = " SELECT $cfields, $ucfields, $efields FROM {" . user_competency::TABLE . "} uc JOIN {" . competency::TABLE . "} c ON c.id = uc.competencyid LEFT JOIN {" . evidence::TABLE . "} e ON uc.id = e.usercompetencyid WHERE uc.userid = :userid ORDER BY c.id, e.timecreated DESC, e.id DESC"; $params = ['userid' => $userid]; $recordset = $DB->get_recordset_sql($sql, $params); static::recordset_loop_and_export($recordset, 'c_id', null, function($carry, $record) use ($context, $userid, $helper, $makecomppath) { $competency = new competency(null, competency::extract_record($record, 'c_')); if ($carry === null) { $uc = new user_competency(null, user_competency::extract_record($record, 'uc_')); $carry = array_merge(static::transform_competency_brief($competency), [ 'rating' => static::transform_user_competency($userid, $uc, $competency, $helper), 'evidence' => [] ]); \core_comment\privacy\provider::export_comments($context, 'competency', 'user_competency', $uc->get('id'), $makecomppath($competency->get('id'), $carry), false); } // There is an evidence in this record. if (!empty($record->e_id)) { $evidence = new evidence(null, evidence::extract_record($record, 'e_')); $carry['evidence'][] = static::transform_evidence($userid, $evidence, $competency, $helper); } return $carry; }, function($competencyid, $data) use ($makecomppath, $context) { writer::with_context($context)->export_data($makecomppath($competencyid, $data), (object) $data); }); }
php
protected static function export_user_data_competencies(context_user $context) { global $DB; $userid = $context->instanceid; $path = [get_string('competencies', 'core_competency'), get_string('competencies', 'core_competency')]; $helper = new performance_helper(); $cfields = competency::get_sql_fields('c', 'c_'); $ucfields = user_competency::get_sql_fields('uc', 'uc_'); $efields = evidence::get_sql_fields('e', 'e_'); $makecomppath = function($competencyid, $data) use ($path) { return array_merge($path, [$data['name'] . ' (' . $competencyid . ')']); }; $sql = " SELECT $cfields, $ucfields, $efields FROM {" . user_competency::TABLE . "} uc JOIN {" . competency::TABLE . "} c ON c.id = uc.competencyid LEFT JOIN {" . evidence::TABLE . "} e ON uc.id = e.usercompetencyid WHERE uc.userid = :userid ORDER BY c.id, e.timecreated DESC, e.id DESC"; $params = ['userid' => $userid]; $recordset = $DB->get_recordset_sql($sql, $params); static::recordset_loop_and_export($recordset, 'c_id', null, function($carry, $record) use ($context, $userid, $helper, $makecomppath) { $competency = new competency(null, competency::extract_record($record, 'c_')); if ($carry === null) { $uc = new user_competency(null, user_competency::extract_record($record, 'uc_')); $carry = array_merge(static::transform_competency_brief($competency), [ 'rating' => static::transform_user_competency($userid, $uc, $competency, $helper), 'evidence' => [] ]); \core_comment\privacy\provider::export_comments($context, 'competency', 'user_competency', $uc->get('id'), $makecomppath($competency->get('id'), $carry), false); } // There is an evidence in this record. if (!empty($record->e_id)) { $evidence = new evidence(null, evidence::extract_record($record, 'e_')); $carry['evidence'][] = static::transform_evidence($userid, $evidence, $competency, $helper); } return $carry; }, function($competencyid, $data) use ($makecomppath, $context) { writer::with_context($context)->export_data($makecomppath($competencyid, $data), (object) $data); }); }
[ "protected", "static", "function", "export_user_data_competencies", "(", "context_user", "$", "context", ")", "{", "global", "$", "DB", ";", "$", "userid", "=", "$", "context", "->", "instanceid", ";", "$", "path", "=", "[", "get_string", "(", "'competencies'", ",", "'core_competency'", ")", ",", "get_string", "(", "'competencies'", ",", "'core_competency'", ")", "]", ";", "$", "helper", "=", "new", "performance_helper", "(", ")", ";", "$", "cfields", "=", "competency", "::", "get_sql_fields", "(", "'c'", ",", "'c_'", ")", ";", "$", "ucfields", "=", "user_competency", "::", "get_sql_fields", "(", "'uc'", ",", "'uc_'", ")", ";", "$", "efields", "=", "evidence", "::", "get_sql_fields", "(", "'e'", ",", "'e_'", ")", ";", "$", "makecomppath", "=", "function", "(", "$", "competencyid", ",", "$", "data", ")", "use", "(", "$", "path", ")", "{", "return", "array_merge", "(", "$", "path", ",", "[", "$", "data", "[", "'name'", "]", ".", "' ('", ".", "$", "competencyid", ".", "')'", "]", ")", ";", "}", ";", "$", "sql", "=", "\"\n SELECT $cfields, $ucfields, $efields\n FROM {\"", ".", "user_competency", "::", "TABLE", ".", "\"} uc\n JOIN {\"", ".", "competency", "::", "TABLE", ".", "\"} c\n ON c.id = uc.competencyid\n LEFT JOIN {\"", ".", "evidence", "::", "TABLE", ".", "\"} e\n ON uc.id = e.usercompetencyid\n WHERE uc.userid = :userid\n ORDER BY c.id, e.timecreated DESC, e.id DESC\"", ";", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", "]", ";", "$", "recordset", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "static", "::", "recordset_loop_and_export", "(", "$", "recordset", ",", "'c_id'", ",", "null", ",", "function", "(", "$", "carry", ",", "$", "record", ")", "use", "(", "$", "context", ",", "$", "userid", ",", "$", "helper", ",", "$", "makecomppath", ")", "{", "$", "competency", "=", "new", "competency", "(", "null", ",", "competency", "::", "extract_record", "(", "$", "record", ",", "'c_'", ")", ")", ";", "if", "(", "$", "carry", "===", "null", ")", "{", "$", "uc", "=", "new", "user_competency", "(", "null", ",", "user_competency", "::", "extract_record", "(", "$", "record", ",", "'uc_'", ")", ")", ";", "$", "carry", "=", "array_merge", "(", "static", "::", "transform_competency_brief", "(", "$", "competency", ")", ",", "[", "'rating'", "=>", "static", "::", "transform_user_competency", "(", "$", "userid", ",", "$", "uc", ",", "$", "competency", ",", "$", "helper", ")", ",", "'evidence'", "=>", "[", "]", "]", ")", ";", "\\", "core_comment", "\\", "privacy", "\\", "provider", "::", "export_comments", "(", "$", "context", ",", "'competency'", ",", "'user_competency'", ",", "$", "uc", "->", "get", "(", "'id'", ")", ",", "$", "makecomppath", "(", "$", "competency", "->", "get", "(", "'id'", ")", ",", "$", "carry", ")", ",", "false", ")", ";", "}", "// There is an evidence in this record.", "if", "(", "!", "empty", "(", "$", "record", "->", "e_id", ")", ")", "{", "$", "evidence", "=", "new", "evidence", "(", "null", ",", "evidence", "::", "extract_record", "(", "$", "record", ",", "'e_'", ")", ")", ";", "$", "carry", "[", "'evidence'", "]", "[", "]", "=", "static", "::", "transform_evidence", "(", "$", "userid", ",", "$", "evidence", ",", "$", "competency", ",", "$", "helper", ")", ";", "}", "return", "$", "carry", ";", "}", ",", "function", "(", "$", "competencyid", ",", "$", "data", ")", "use", "(", "$", "makecomppath", ",", "$", "context", ")", "{", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "$", "makecomppath", "(", "$", "competencyid", ",", "$", "data", ")", ",", "(", "object", ")", "$", "data", ")", ";", "}", ")", ";", "}" ]
Export a user's competencies. @param context_user $context The context of the user requesting the export. @return void
[ "Export", "a", "user", "s", "competencies", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L1168-L1220
214,119
moodle/moodle
competency/classes/privacy/provider.php
provider.export_user_data_user_evidence
protected static function export_user_data_user_evidence(context_user $context) { global $DB; $userid = $context->instanceid; $path = [get_string('competencies', 'core_competency'), get_string('privacy:path:userevidence', 'core_competency')]; $uefields = user_evidence::get_sql_fields('ue', 'ue_'); $cfields = competency::get_sql_fields('c', 'c_'); $sql = " SELECT $uefields, $cfields FROM {" . user_evidence::TABLE . "} ue LEFT JOIN {" . user_evidence_competency::TABLE . "} uec ON uec.userevidenceid = ue.id LEFT JOIN {" . competency::TABLE . "} c ON c.id = uec.competencyid WHERE ue.userid = :userid ORDER BY ue.id"; $params = ['userid' => $userid]; $recordset = $DB->get_recordset_sql($sql, $params); static::recordset_loop_and_export($recordset, 'ue_id', null, function($carry, $record) use ($userid, $context){ if ($carry === null) { $ue = new user_evidence(null, user_evidence::extract_record($record, 'ue_')); $carry = static::transform_user_evidence($userid, $ue); } if (!empty($record->c_id)) { $competency = new competency(null, competency::extract_record($record, 'c_')); $carry['competencies'][] = static::transform_competency_brief($competency); } return $carry; }, function($ueid, $data) use ($context, $path) { $finalpath = array_merge($path, [$data['name'] . ' (' . $ueid . ')']); writer::with_context($context)->export_area_files($finalpath, 'core_competency', 'userevidence', $ueid); writer::with_context($context)->export_data($finalpath, (object) $data); }); }
php
protected static function export_user_data_user_evidence(context_user $context) { global $DB; $userid = $context->instanceid; $path = [get_string('competencies', 'core_competency'), get_string('privacy:path:userevidence', 'core_competency')]; $uefields = user_evidence::get_sql_fields('ue', 'ue_'); $cfields = competency::get_sql_fields('c', 'c_'); $sql = " SELECT $uefields, $cfields FROM {" . user_evidence::TABLE . "} ue LEFT JOIN {" . user_evidence_competency::TABLE . "} uec ON uec.userevidenceid = ue.id LEFT JOIN {" . competency::TABLE . "} c ON c.id = uec.competencyid WHERE ue.userid = :userid ORDER BY ue.id"; $params = ['userid' => $userid]; $recordset = $DB->get_recordset_sql($sql, $params); static::recordset_loop_and_export($recordset, 'ue_id', null, function($carry, $record) use ($userid, $context){ if ($carry === null) { $ue = new user_evidence(null, user_evidence::extract_record($record, 'ue_')); $carry = static::transform_user_evidence($userid, $ue); } if (!empty($record->c_id)) { $competency = new competency(null, competency::extract_record($record, 'c_')); $carry['competencies'][] = static::transform_competency_brief($competency); } return $carry; }, function($ueid, $data) use ($context, $path) { $finalpath = array_merge($path, [$data['name'] . ' (' . $ueid . ')']); writer::with_context($context)->export_area_files($finalpath, 'core_competency', 'userevidence', $ueid); writer::with_context($context)->export_data($finalpath, (object) $data); }); }
[ "protected", "static", "function", "export_user_data_user_evidence", "(", "context_user", "$", "context", ")", "{", "global", "$", "DB", ";", "$", "userid", "=", "$", "context", "->", "instanceid", ";", "$", "path", "=", "[", "get_string", "(", "'competencies'", ",", "'core_competency'", ")", ",", "get_string", "(", "'privacy:path:userevidence'", ",", "'core_competency'", ")", "]", ";", "$", "uefields", "=", "user_evidence", "::", "get_sql_fields", "(", "'ue'", ",", "'ue_'", ")", ";", "$", "cfields", "=", "competency", "::", "get_sql_fields", "(", "'c'", ",", "'c_'", ")", ";", "$", "sql", "=", "\"\n SELECT $uefields, $cfields\n FROM {\"", ".", "user_evidence", "::", "TABLE", ".", "\"} ue\n LEFT JOIN {\"", ".", "user_evidence_competency", "::", "TABLE", ".", "\"} uec\n ON uec.userevidenceid = ue.id\n LEFT JOIN {\"", ".", "competency", "::", "TABLE", ".", "\"} c\n ON c.id = uec.competencyid\n WHERE ue.userid = :userid\n ORDER BY ue.id\"", ";", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", "]", ";", "$", "recordset", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "static", "::", "recordset_loop_and_export", "(", "$", "recordset", ",", "'ue_id'", ",", "null", ",", "function", "(", "$", "carry", ",", "$", "record", ")", "use", "(", "$", "userid", ",", "$", "context", ")", "{", "if", "(", "$", "carry", "===", "null", ")", "{", "$", "ue", "=", "new", "user_evidence", "(", "null", ",", "user_evidence", "::", "extract_record", "(", "$", "record", ",", "'ue_'", ")", ")", ";", "$", "carry", "=", "static", "::", "transform_user_evidence", "(", "$", "userid", ",", "$", "ue", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "record", "->", "c_id", ")", ")", "{", "$", "competency", "=", "new", "competency", "(", "null", ",", "competency", "::", "extract_record", "(", "$", "record", ",", "'c_'", ")", ")", ";", "$", "carry", "[", "'competencies'", "]", "[", "]", "=", "static", "::", "transform_competency_brief", "(", "$", "competency", ")", ";", "}", "return", "$", "carry", ";", "}", ",", "function", "(", "$", "ueid", ",", "$", "data", ")", "use", "(", "$", "context", ",", "$", "path", ")", "{", "$", "finalpath", "=", "array_merge", "(", "$", "path", ",", "[", "$", "data", "[", "'name'", "]", ".", "' ('", ".", "$", "ueid", ".", "')'", "]", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_area_files", "(", "$", "finalpath", ",", "'core_competency'", ",", "'userevidence'", ",", "$", "ueid", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "$", "finalpath", ",", "(", "object", ")", "$", "data", ")", ";", "}", ")", ";", "}" ]
Export the evidence of prior learning of a user. @param context_user $context The context of the user we're exporting for. @return void
[ "Export", "the", "evidence", "of", "prior", "learning", "of", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L1708-L1745
214,120
moodle/moodle
competency/classes/privacy/provider.php
provider.transform_competency_brief
protected static function transform_competency_brief(competency $competency) { global $OUTPUT; $exporter = new \core_competency\external\competency_exporter($competency, ['context' => $competency->get_context()]); $data = $exporter->export($OUTPUT); return [ 'idnumber' => $data->idnumber, 'name' => $data->shortname, 'description' => $data->description ]; }
php
protected static function transform_competency_brief(competency $competency) { global $OUTPUT; $exporter = new \core_competency\external\competency_exporter($competency, ['context' => $competency->get_context()]); $data = $exporter->export($OUTPUT); return [ 'idnumber' => $data->idnumber, 'name' => $data->shortname, 'description' => $data->description ]; }
[ "protected", "static", "function", "transform_competency_brief", "(", "competency", "$", "competency", ")", "{", "global", "$", "OUTPUT", ";", "$", "exporter", "=", "new", "\\", "core_competency", "\\", "external", "\\", "competency_exporter", "(", "$", "competency", ",", "[", "'context'", "=>", "$", "competency", "->", "get_context", "(", ")", "]", ")", ";", "$", "data", "=", "$", "exporter", "->", "export", "(", "$", "OUTPUT", ")", ";", "return", "[", "'idnumber'", "=>", "$", "data", "->", "idnumber", ",", "'name'", "=>", "$", "data", "->", "shortname", ",", "'description'", "=>", "$", "data", "->", "description", "]", ";", "}" ]
Transform a competency into a brief description. @param competency $competency The competency. @return array
[ "Transform", "a", "competency", "into", "a", "brief", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L2010-L2019
214,121
moodle/moodle
competency/classes/privacy/provider.php
provider.transform_competency_grade
protected static function transform_competency_grade(competency $competency, $grade, performance_helper $helper) { if ($grade === null) { return '-'; } $scale = $helper->get_scale_from_competency($competency); return $scale->scale_items[$grade - 1]; }
php
protected static function transform_competency_grade(competency $competency, $grade, performance_helper $helper) { if ($grade === null) { return '-'; } $scale = $helper->get_scale_from_competency($competency); return $scale->scale_items[$grade - 1]; }
[ "protected", "static", "function", "transform_competency_grade", "(", "competency", "$", "competency", ",", "$", "grade", ",", "performance_helper", "$", "helper", ")", "{", "if", "(", "$", "grade", "===", "null", ")", "{", "return", "'-'", ";", "}", "$", "scale", "=", "$", "helper", "->", "get_scale_from_competency", "(", "$", "competency", ")", ";", "return", "$", "scale", "->", "scale_items", "[", "$", "grade", "-", "1", "]", ";", "}" ]
Transform a competency rating. @param competency $competency The competency. @param int $grade The grade. @param performance_helper $helper The performance helper. @return string
[ "Transform", "a", "competency", "rating", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L2029-L2035
214,122
moodle/moodle
competency/classes/privacy/provider.php
provider.transform_evidence
protected static function transform_evidence($userid, evidence $evidence, competency $competency, performance_helper $helper) { $action = $evidence->get('action'); $actiontxt = '?'; if ($action == evidence::ACTION_LOG) { $actiontxt = get_string('privacy:evidence:action:log', 'core_competency'); } else if ($action == evidence::ACTION_COMPLETE) { $actiontxt = get_string('privacy:evidence:action:complete', 'core_competency'); } else if ($action == evidence::ACTION_OVERRIDE) { $actiontxt = get_string('privacy:evidence:action:override', 'core_competency'); } $actionuserid = $evidence->get('actionuserid'); return [ 'action' => $actiontxt, 'actionuserid' => $actionuserid ? transform::user($actionuserid) : '-', 'acting_user_is_you' => transform::yesno($userid == $actionuserid), 'description' => (string) $evidence->get_description(), 'url' => $evidence->get('url'), 'grade' => static::transform_competency_grade($competency, $evidence->get('grade'), $helper), 'note' => $evidence->get('note'), 'timecreated' => transform::datetime($evidence->get('timecreated')), 'timemodified' => transform::datetime($evidence->get('timemodified')), 'created_or_modified_by_you' => transform::yesno($userid == $evidence->get('usermodified')) ]; }
php
protected static function transform_evidence($userid, evidence $evidence, competency $competency, performance_helper $helper) { $action = $evidence->get('action'); $actiontxt = '?'; if ($action == evidence::ACTION_LOG) { $actiontxt = get_string('privacy:evidence:action:log', 'core_competency'); } else if ($action == evidence::ACTION_COMPLETE) { $actiontxt = get_string('privacy:evidence:action:complete', 'core_competency'); } else if ($action == evidence::ACTION_OVERRIDE) { $actiontxt = get_string('privacy:evidence:action:override', 'core_competency'); } $actionuserid = $evidence->get('actionuserid'); return [ 'action' => $actiontxt, 'actionuserid' => $actionuserid ? transform::user($actionuserid) : '-', 'acting_user_is_you' => transform::yesno($userid == $actionuserid), 'description' => (string) $evidence->get_description(), 'url' => $evidence->get('url'), 'grade' => static::transform_competency_grade($competency, $evidence->get('grade'), $helper), 'note' => $evidence->get('note'), 'timecreated' => transform::datetime($evidence->get('timecreated')), 'timemodified' => transform::datetime($evidence->get('timemodified')), 'created_or_modified_by_you' => transform::yesno($userid == $evidence->get('usermodified')) ]; }
[ "protected", "static", "function", "transform_evidence", "(", "$", "userid", ",", "evidence", "$", "evidence", ",", "competency", "$", "competency", ",", "performance_helper", "$", "helper", ")", "{", "$", "action", "=", "$", "evidence", "->", "get", "(", "'action'", ")", ";", "$", "actiontxt", "=", "'?'", ";", "if", "(", "$", "action", "==", "evidence", "::", "ACTION_LOG", ")", "{", "$", "actiontxt", "=", "get_string", "(", "'privacy:evidence:action:log'", ",", "'core_competency'", ")", ";", "}", "else", "if", "(", "$", "action", "==", "evidence", "::", "ACTION_COMPLETE", ")", "{", "$", "actiontxt", "=", "get_string", "(", "'privacy:evidence:action:complete'", ",", "'core_competency'", ")", ";", "}", "else", "if", "(", "$", "action", "==", "evidence", "::", "ACTION_OVERRIDE", ")", "{", "$", "actiontxt", "=", "get_string", "(", "'privacy:evidence:action:override'", ",", "'core_competency'", ")", ";", "}", "$", "actionuserid", "=", "$", "evidence", "->", "get", "(", "'actionuserid'", ")", ";", "return", "[", "'action'", "=>", "$", "actiontxt", ",", "'actionuserid'", "=>", "$", "actionuserid", "?", "transform", "::", "user", "(", "$", "actionuserid", ")", ":", "'-'", ",", "'acting_user_is_you'", "=>", "transform", "::", "yesno", "(", "$", "userid", "==", "$", "actionuserid", ")", ",", "'description'", "=>", "(", "string", ")", "$", "evidence", "->", "get_description", "(", ")", ",", "'url'", "=>", "$", "evidence", "->", "get", "(", "'url'", ")", ",", "'grade'", "=>", "static", "::", "transform_competency_grade", "(", "$", "competency", ",", "$", "evidence", "->", "get", "(", "'grade'", ")", ",", "$", "helper", ")", ",", "'note'", "=>", "$", "evidence", "->", "get", "(", "'note'", ")", ",", "'timecreated'", "=>", "transform", "::", "datetime", "(", "$", "evidence", "->", "get", "(", "'timecreated'", ")", ")", ",", "'timemodified'", "=>", "transform", "::", "datetime", "(", "$", "evidence", "->", "get", "(", "'timemodified'", ")", ")", ",", "'created_or_modified_by_you'", "=>", "transform", "::", "yesno", "(", "$", "userid", "==", "$", "evidence", "->", "get", "(", "'usermodified'", ")", ")", "]", ";", "}" ]
Transform an evidence. @param int $userid The user ID we are exporting for. @param evidence $evidence The evidence. @param competency $competency The associated competency. @param performance_helper $helper The performance helper. @return array
[ "Transform", "an", "evidence", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L2046-L2071
214,123
moodle/moodle
competency/classes/privacy/provider.php
provider.transform_framework_brief
protected static function transform_framework_brief(competency_framework $framework) { global $OUTPUT; $exporter = new \core_competency\external\competency_framework_exporter($framework); $data = $exporter->export($OUTPUT); return [ 'name' => $data->shortname, 'idnumber' => $data->idnumber, 'description' => $data->description ]; }
php
protected static function transform_framework_brief(competency_framework $framework) { global $OUTPUT; $exporter = new \core_competency\external\competency_framework_exporter($framework); $data = $exporter->export($OUTPUT); return [ 'name' => $data->shortname, 'idnumber' => $data->idnumber, 'description' => $data->description ]; }
[ "protected", "static", "function", "transform_framework_brief", "(", "competency_framework", "$", "framework", ")", "{", "global", "$", "OUTPUT", ";", "$", "exporter", "=", "new", "\\", "core_competency", "\\", "external", "\\", "competency_framework_exporter", "(", "$", "framework", ")", ";", "$", "data", "=", "$", "exporter", "->", "export", "(", "$", "OUTPUT", ")", ";", "return", "[", "'name'", "=>", "$", "data", "->", "shortname", ",", "'idnumber'", "=>", "$", "data", "->", "idnumber", ",", "'description'", "=>", "$", "data", "->", "description", "]", ";", "}" ]
Transform a framework into a brief description. @param competency_framework $framework The framework. @return array
[ "Transform", "a", "framework", "into", "a", "brief", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L2079-L2088
214,124
moodle/moodle
competency/classes/privacy/provider.php
provider.transform_template_brief
protected static function transform_template_brief(template $template) { global $OUTPUT; $exporter = new \core_competency\external\template_exporter($template); $data = $exporter->export($OUTPUT); return [ 'name' => $data->shortname, 'description' => $data->description ]; }
php
protected static function transform_template_brief(template $template) { global $OUTPUT; $exporter = new \core_competency\external\template_exporter($template); $data = $exporter->export($OUTPUT); return [ 'name' => $data->shortname, 'description' => $data->description ]; }
[ "protected", "static", "function", "transform_template_brief", "(", "template", "$", "template", ")", "{", "global", "$", "OUTPUT", ";", "$", "exporter", "=", "new", "\\", "core_competency", "\\", "external", "\\", "template_exporter", "(", "$", "template", ")", ";", "$", "data", "=", "$", "exporter", "->", "export", "(", "$", "OUTPUT", ")", ";", "return", "[", "'name'", "=>", "$", "data", "->", "shortname", ",", "'description'", "=>", "$", "data", "->", "description", "]", ";", "}" ]
Transform a template into a brief description. @param template $template The Template. @return array
[ "Transform", "a", "template", "into", "a", "brief", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L2096-L2104
214,125
moodle/moodle
competency/classes/privacy/provider.php
provider.transform_user_competency
protected static function transform_user_competency($userid, $uc, competency $competency, performance_helper $helper) { $data = [ 'proficient' => static::transform_proficiency($uc->get('proficiency')), 'rating' => static::transform_competency_grade($competency, $uc->get('grade'), $helper), 'timemodified' => $uc->get('timemodified') ? transform::datetime($uc->get('timemodified')) : '-', 'timecreated' => $uc->get('timecreated') ? transform::datetime($uc->get('timecreated')) : '-', 'created_or_modified_by_you' => transform::yesno($uc->get('usermodified') == $userid), ]; if ($uc instanceof user_competency) { $reviewer = $uc->get('reviewerid'); $data['status'] = (string) user_competency::get_status_name($uc->get('status')); $data['reviewerid'] = $reviewer ? transform::user($reviewer) : '-'; $data['reviewer_is_you'] = transform::yesno($reviewer == $userid); } return $data; }
php
protected static function transform_user_competency($userid, $uc, competency $competency, performance_helper $helper) { $data = [ 'proficient' => static::transform_proficiency($uc->get('proficiency')), 'rating' => static::transform_competency_grade($competency, $uc->get('grade'), $helper), 'timemodified' => $uc->get('timemodified') ? transform::datetime($uc->get('timemodified')) : '-', 'timecreated' => $uc->get('timecreated') ? transform::datetime($uc->get('timecreated')) : '-', 'created_or_modified_by_you' => transform::yesno($uc->get('usermodified') == $userid), ]; if ($uc instanceof user_competency) { $reviewer = $uc->get('reviewerid'); $data['status'] = (string) user_competency::get_status_name($uc->get('status')); $data['reviewerid'] = $reviewer ? transform::user($reviewer) : '-'; $data['reviewer_is_you'] = transform::yesno($reviewer == $userid); } return $data; }
[ "protected", "static", "function", "transform_user_competency", "(", "$", "userid", ",", "$", "uc", ",", "competency", "$", "competency", ",", "performance_helper", "$", "helper", ")", "{", "$", "data", "=", "[", "'proficient'", "=>", "static", "::", "transform_proficiency", "(", "$", "uc", "->", "get", "(", "'proficiency'", ")", ")", ",", "'rating'", "=>", "static", "::", "transform_competency_grade", "(", "$", "competency", ",", "$", "uc", "->", "get", "(", "'grade'", ")", ",", "$", "helper", ")", ",", "'timemodified'", "=>", "$", "uc", "->", "get", "(", "'timemodified'", ")", "?", "transform", "::", "datetime", "(", "$", "uc", "->", "get", "(", "'timemodified'", ")", ")", ":", "'-'", ",", "'timecreated'", "=>", "$", "uc", "->", "get", "(", "'timecreated'", ")", "?", "transform", "::", "datetime", "(", "$", "uc", "->", "get", "(", "'timecreated'", ")", ")", ":", "'-'", ",", "'created_or_modified_by_you'", "=>", "transform", "::", "yesno", "(", "$", "uc", "->", "get", "(", "'usermodified'", ")", "==", "$", "userid", ")", ",", "]", ";", "if", "(", "$", "uc", "instanceof", "user_competency", ")", "{", "$", "reviewer", "=", "$", "uc", "->", "get", "(", "'reviewerid'", ")", ";", "$", "data", "[", "'status'", "]", "=", "(", "string", ")", "user_competency", "::", "get_status_name", "(", "$", "uc", "->", "get", "(", "'status'", ")", ")", ";", "$", "data", "[", "'reviewerid'", "]", "=", "$", "reviewer", "?", "transform", "::", "user", "(", "$", "reviewer", ")", ":", "'-'", ";", "$", "data", "[", "'reviewer_is_you'", "]", "=", "transform", "::", "yesno", "(", "$", "reviewer", "==", "$", "userid", ")", ";", "}", "return", "$", "data", ";", "}" ]
Transform user competency. @param int $userid The user ID we are exporting for. @param user_competency|user_competency_plan|user_competency_course $uc The user competency. @param competency $competency The associated competency. @param performance_helper $helper The performance helper. @return array
[ "Transform", "user", "competency", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L2125-L2142
214,126
moodle/moodle
competency/classes/privacy/provider.php
provider.transform_user_evidence
protected static function transform_user_evidence($userid, user_evidence $ue) { $options = ['context' => $ue->get_context()]; return [ 'name' => format_string($ue->get('name'), true, $options), 'description' => format_text($ue->get('description'), $ue->get('descriptionformat'), $options), 'url' => $ue->get('url'), 'timecreated' => $ue->get('timecreated') ? transform::datetime($ue->get('timecreated')) : '-', 'timemodified' => $ue->get('timemodified') ? transform::datetime($ue->get('timemodified')) : '-', 'created_or_modified_by_you' => transform::yesno($ue->get('usermodified') == $userid), 'competencies' => [] ]; }
php
protected static function transform_user_evidence($userid, user_evidence $ue) { $options = ['context' => $ue->get_context()]; return [ 'name' => format_string($ue->get('name'), true, $options), 'description' => format_text($ue->get('description'), $ue->get('descriptionformat'), $options), 'url' => $ue->get('url'), 'timecreated' => $ue->get('timecreated') ? transform::datetime($ue->get('timecreated')) : '-', 'timemodified' => $ue->get('timemodified') ? transform::datetime($ue->get('timemodified')) : '-', 'created_or_modified_by_you' => transform::yesno($ue->get('usermodified') == $userid), 'competencies' => [] ]; }
[ "protected", "static", "function", "transform_user_evidence", "(", "$", "userid", ",", "user_evidence", "$", "ue", ")", "{", "$", "options", "=", "[", "'context'", "=>", "$", "ue", "->", "get_context", "(", ")", "]", ";", "return", "[", "'name'", "=>", "format_string", "(", "$", "ue", "->", "get", "(", "'name'", ")", ",", "true", ",", "$", "options", ")", ",", "'description'", "=>", "format_text", "(", "$", "ue", "->", "get", "(", "'description'", ")", ",", "$", "ue", "->", "get", "(", "'descriptionformat'", ")", ",", "$", "options", ")", ",", "'url'", "=>", "$", "ue", "->", "get", "(", "'url'", ")", ",", "'timecreated'", "=>", "$", "ue", "->", "get", "(", "'timecreated'", ")", "?", "transform", "::", "datetime", "(", "$", "ue", "->", "get", "(", "'timecreated'", ")", ")", ":", "'-'", ",", "'timemodified'", "=>", "$", "ue", "->", "get", "(", "'timemodified'", ")", "?", "transform", "::", "datetime", "(", "$", "ue", "->", "get", "(", "'timemodified'", ")", ")", ":", "'-'", ",", "'created_or_modified_by_you'", "=>", "transform", "::", "yesno", "(", "$", "ue", "->", "get", "(", "'usermodified'", ")", "==", "$", "userid", ")", ",", "'competencies'", "=>", "[", "]", "]", ";", "}" ]
Transform a user evidence. @param int $userid The user we are exporting for. @param user_evidence $ue The evidence of prior learning. @return array
[ "Transform", "a", "user", "evidence", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L2151-L2162
214,127
moodle/moodle
competency/classes/privacy/provider.php
provider.recordset_loop_and_export
protected static function recordset_loop_and_export(moodle_recordset $recordset, $splitkey, $initial, callable $reducer, callable $export) { $data = $initial; $lastid = null; foreach ($recordset as $record) { if ($lastid && $record->{$splitkey} != $lastid) { $export($lastid, $data); $data = $initial; } $data = $reducer($data, $record); $lastid = $record->{$splitkey}; } $recordset->close(); if (!empty($lastid)) { $export($lastid, $data); } }
php
protected static function recordset_loop_and_export(moodle_recordset $recordset, $splitkey, $initial, callable $reducer, callable $export) { $data = $initial; $lastid = null; foreach ($recordset as $record) { if ($lastid && $record->{$splitkey} != $lastid) { $export($lastid, $data); $data = $initial; } $data = $reducer($data, $record); $lastid = $record->{$splitkey}; } $recordset->close(); if (!empty($lastid)) { $export($lastid, $data); } }
[ "protected", "static", "function", "recordset_loop_and_export", "(", "moodle_recordset", "$", "recordset", ",", "$", "splitkey", ",", "$", "initial", ",", "callable", "$", "reducer", ",", "callable", "$", "export", ")", "{", "$", "data", "=", "$", "initial", ";", "$", "lastid", "=", "null", ";", "foreach", "(", "$", "recordset", "as", "$", "record", ")", "{", "if", "(", "$", "lastid", "&&", "$", "record", "->", "{", "$", "splitkey", "}", "!=", "$", "lastid", ")", "{", "$", "export", "(", "$", "lastid", ",", "$", "data", ")", ";", "$", "data", "=", "$", "initial", ";", "}", "$", "data", "=", "$", "reducer", "(", "$", "data", ",", "$", "record", ")", ";", "$", "lastid", "=", "$", "record", "->", "{", "$", "splitkey", "}", ";", "}", "$", "recordset", "->", "close", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "lastid", ")", ")", "{", "$", "export", "(", "$", "lastid", ",", "$", "data", ")", ";", "}", "}" ]
Loop and export from a recordset. @param moodle_recordset $recordset The recordset. @param string $splitkey The record key to determine when to export. @param mixed $initial The initial data to reduce from. @param callable $reducer The function to return the dataset, receives current dataset, and the current record. @param callable $export The function to export the dataset, receives the last value from $splitkey and the dataset. @return void
[ "Loop", "and", "export", "from", "a", "recordset", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/privacy/provider.php#L2174-L2193
214,128
moodle/moodle
lib/form/filepicker.php
MoodleQuickForm_filepicker.exportValue
function exportValue(&$submitValues, $assoc = false) { global $USER; $draftitemid = $this->_findValue($submitValues); if (null === $draftitemid) { $draftitemid = $this->getValue(); } // make sure max one file is present and it is not too big if (!is_null($draftitemid)) { $fs = get_file_storage(); $usercontext = context_user::instance($USER->id); if ($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id DESC', false)) { $file = array_shift($files); if ($this->_options['maxbytes'] and $this->_options['maxbytes'] !== USER_CAN_IGNORE_FILE_SIZE_LIMITS and $file->get_filesize() > $this->_options['maxbytes']) { // bad luck, somebody tries to sneak in oversized file $file->delete(); } foreach ($files as $file) { // only one file expected $file->delete(); } } } return $this->_prepareValue($draftitemid, true); }
php
function exportValue(&$submitValues, $assoc = false) { global $USER; $draftitemid = $this->_findValue($submitValues); if (null === $draftitemid) { $draftitemid = $this->getValue(); } // make sure max one file is present and it is not too big if (!is_null($draftitemid)) { $fs = get_file_storage(); $usercontext = context_user::instance($USER->id); if ($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id DESC', false)) { $file = array_shift($files); if ($this->_options['maxbytes'] and $this->_options['maxbytes'] !== USER_CAN_IGNORE_FILE_SIZE_LIMITS and $file->get_filesize() > $this->_options['maxbytes']) { // bad luck, somebody tries to sneak in oversized file $file->delete(); } foreach ($files as $file) { // only one file expected $file->delete(); } } } return $this->_prepareValue($draftitemid, true); }
[ "function", "exportValue", "(", "&", "$", "submitValues", ",", "$", "assoc", "=", "false", ")", "{", "global", "$", "USER", ";", "$", "draftitemid", "=", "$", "this", "->", "_findValue", "(", "$", "submitValues", ")", ";", "if", "(", "null", "===", "$", "draftitemid", ")", "{", "$", "draftitemid", "=", "$", "this", "->", "getValue", "(", ")", ";", "}", "// make sure max one file is present and it is not too big", "if", "(", "!", "is_null", "(", "$", "draftitemid", ")", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "usercontext", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "if", "(", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "usercontext", "->", "id", ",", "'user'", ",", "'draft'", ",", "$", "draftitemid", ",", "'id DESC'", ",", "false", ")", ")", "{", "$", "file", "=", "array_shift", "(", "$", "files", ")", ";", "if", "(", "$", "this", "->", "_options", "[", "'maxbytes'", "]", "and", "$", "this", "->", "_options", "[", "'maxbytes'", "]", "!==", "USER_CAN_IGNORE_FILE_SIZE_LIMITS", "and", "$", "file", "->", "get_filesize", "(", ")", ">", "$", "this", "->", "_options", "[", "'maxbytes'", "]", ")", "{", "// bad luck, somebody tries to sneak in oversized file", "$", "file", "->", "delete", "(", ")", ";", "}", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "// only one file expected", "$", "file", "->", "delete", "(", ")", ";", "}", "}", "}", "return", "$", "this", "->", "_prepareValue", "(", "$", "draftitemid", ",", "true", ")", ";", "}" ]
export uploaded file @param array $submitValues values submitted. @param bool $assoc specifies if returned array is associative @return array
[ "export", "uploaded", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/filepicker.php#L205-L234
214,129
moodle/moodle
lib/searchlib.php
search_parser.inquotedstring
function inquotedstring($content){ if (strlen($content) < 2) { // State exit or missing parameter. return true; } // Strip off the opening quote and add the reminder to the parsed token array. $this->tokens[] = new search_token(TOKEN_STRING,substr($content,1)); return true; }
php
function inquotedstring($content){ if (strlen($content) < 2) { // State exit or missing parameter. return true; } // Strip off the opening quote and add the reminder to the parsed token array. $this->tokens[] = new search_token(TOKEN_STRING,substr($content,1)); return true; }
[ "function", "inquotedstring", "(", "$", "content", ")", "{", "if", "(", "strlen", "(", "$", "content", ")", "<", "2", ")", "{", "// State exit or missing parameter.", "return", "true", ";", "}", "// Strip off the opening quote and add the reminder to the parsed token array.", "$", "this", "->", "tokens", "[", "]", "=", "new", "search_token", "(", "TOKEN_STRING", ",", "substr", "(", "$", "content", ",", "1", ")", ")", ";", "return", "true", ";", "}" ]
State entered when we've seen a quoted string. Potentially emits a token.
[ "State", "entered", "when", "we", "ve", "seen", "a", "quoted", "string", ".", "Potentially", "emits", "a", "token", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/searchlib.php#L363-L370
214,130
moodle/moodle
admin/tool/log/store/database/classes/log/store.php
store.init
protected function init() { if (isset($this->extdb)) { return !empty($this->extdb); } $dbdriver = $this->get_config('dbdriver'); if (empty($dbdriver)) { $this->extdb = false; return false; } list($dblibrary, $dbtype) = explode('/', $dbdriver); if (!$db = \moodle_database::get_driver_instance($dbtype, $dblibrary, true)) { debugging("Unknown driver $dblibrary/$dbtype", DEBUG_DEVELOPER); $this->extdb = false; return false; } $dboptions = array(); $dboptions['dbpersist'] = $this->get_config('dbpersist', '0'); $dboptions['dbsocket'] = $this->get_config('dbsocket', ''); $dboptions['dbport'] = $this->get_config('dbport', ''); $dboptions['dbschema'] = $this->get_config('dbschema', ''); $dboptions['dbcollation'] = $this->get_config('dbcollation', ''); $dboptions['dbhandlesoptions'] = $this->get_config('dbhandlesoptions', false); try { $db->connect($this->get_config('dbhost'), $this->get_config('dbuser'), $this->get_config('dbpass'), $this->get_config('dbname'), false, $dboptions); $tables = $db->get_tables(); if (!in_array($this->get_config('dbtable'), $tables)) { debugging('Cannot find the specified table', DEBUG_DEVELOPER); $this->extdb = false; return false; } } catch (\moodle_exception $e) { debugging('Cannot connect to external database: ' . $e->getMessage(), DEBUG_DEVELOPER); $this->extdb = false; return false; } $this->extdb = $db; return true; }
php
protected function init() { if (isset($this->extdb)) { return !empty($this->extdb); } $dbdriver = $this->get_config('dbdriver'); if (empty($dbdriver)) { $this->extdb = false; return false; } list($dblibrary, $dbtype) = explode('/', $dbdriver); if (!$db = \moodle_database::get_driver_instance($dbtype, $dblibrary, true)) { debugging("Unknown driver $dblibrary/$dbtype", DEBUG_DEVELOPER); $this->extdb = false; return false; } $dboptions = array(); $dboptions['dbpersist'] = $this->get_config('dbpersist', '0'); $dboptions['dbsocket'] = $this->get_config('dbsocket', ''); $dboptions['dbport'] = $this->get_config('dbport', ''); $dboptions['dbschema'] = $this->get_config('dbschema', ''); $dboptions['dbcollation'] = $this->get_config('dbcollation', ''); $dboptions['dbhandlesoptions'] = $this->get_config('dbhandlesoptions', false); try { $db->connect($this->get_config('dbhost'), $this->get_config('dbuser'), $this->get_config('dbpass'), $this->get_config('dbname'), false, $dboptions); $tables = $db->get_tables(); if (!in_array($this->get_config('dbtable'), $tables)) { debugging('Cannot find the specified table', DEBUG_DEVELOPER); $this->extdb = false; return false; } } catch (\moodle_exception $e) { debugging('Cannot connect to external database: ' . $e->getMessage(), DEBUG_DEVELOPER); $this->extdb = false; return false; } $this->extdb = $db; return true; }
[ "protected", "function", "init", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "extdb", ")", ")", "{", "return", "!", "empty", "(", "$", "this", "->", "extdb", ")", ";", "}", "$", "dbdriver", "=", "$", "this", "->", "get_config", "(", "'dbdriver'", ")", ";", "if", "(", "empty", "(", "$", "dbdriver", ")", ")", "{", "$", "this", "->", "extdb", "=", "false", ";", "return", "false", ";", "}", "list", "(", "$", "dblibrary", ",", "$", "dbtype", ")", "=", "explode", "(", "'/'", ",", "$", "dbdriver", ")", ";", "if", "(", "!", "$", "db", "=", "\\", "moodle_database", "::", "get_driver_instance", "(", "$", "dbtype", ",", "$", "dblibrary", ",", "true", ")", ")", "{", "debugging", "(", "\"Unknown driver $dblibrary/$dbtype\"", ",", "DEBUG_DEVELOPER", ")", ";", "$", "this", "->", "extdb", "=", "false", ";", "return", "false", ";", "}", "$", "dboptions", "=", "array", "(", ")", ";", "$", "dboptions", "[", "'dbpersist'", "]", "=", "$", "this", "->", "get_config", "(", "'dbpersist'", ",", "'0'", ")", ";", "$", "dboptions", "[", "'dbsocket'", "]", "=", "$", "this", "->", "get_config", "(", "'dbsocket'", ",", "''", ")", ";", "$", "dboptions", "[", "'dbport'", "]", "=", "$", "this", "->", "get_config", "(", "'dbport'", ",", "''", ")", ";", "$", "dboptions", "[", "'dbschema'", "]", "=", "$", "this", "->", "get_config", "(", "'dbschema'", ",", "''", ")", ";", "$", "dboptions", "[", "'dbcollation'", "]", "=", "$", "this", "->", "get_config", "(", "'dbcollation'", ",", "''", ")", ";", "$", "dboptions", "[", "'dbhandlesoptions'", "]", "=", "$", "this", "->", "get_config", "(", "'dbhandlesoptions'", ",", "false", ")", ";", "try", "{", "$", "db", "->", "connect", "(", "$", "this", "->", "get_config", "(", "'dbhost'", ")", ",", "$", "this", "->", "get_config", "(", "'dbuser'", ")", ",", "$", "this", "->", "get_config", "(", "'dbpass'", ")", ",", "$", "this", "->", "get_config", "(", "'dbname'", ")", ",", "false", ",", "$", "dboptions", ")", ";", "$", "tables", "=", "$", "db", "->", "get_tables", "(", ")", ";", "if", "(", "!", "in_array", "(", "$", "this", "->", "get_config", "(", "'dbtable'", ")", ",", "$", "tables", ")", ")", "{", "debugging", "(", "'Cannot find the specified table'", ",", "DEBUG_DEVELOPER", ")", ";", "$", "this", "->", "extdb", "=", "false", ";", "return", "false", ";", "}", "}", "catch", "(", "\\", "moodle_exception", "$", "e", ")", "{", "debugging", "(", "'Cannot connect to external database: '", ".", "$", "e", "->", "getMessage", "(", ")", ",", "DEBUG_DEVELOPER", ")", ";", "$", "this", "->", "extdb", "=", "false", ";", "return", "false", ";", "}", "$", "this", "->", "extdb", "=", "$", "db", ";", "return", "true", ";", "}" ]
Setup the Database. @return bool
[ "Setup", "the", "Database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/store/database/classes/log/store.php#L70-L112
214,131
moodle/moodle
admin/tool/log/store/database/classes/log/store.php
store.insert_event_entries
protected function insert_event_entries($evententries) { if (!$this->init()) { return; } if (!$dbtable = $this->get_config('dbtable')) { return; } try { $this->extdb->insert_records($dbtable, $evententries); } catch (\moodle_exception $e) { debugging('Cannot write to external database: ' . $e->getMessage(), DEBUG_DEVELOPER); } }
php
protected function insert_event_entries($evententries) { if (!$this->init()) { return; } if (!$dbtable = $this->get_config('dbtable')) { return; } try { $this->extdb->insert_records($dbtable, $evententries); } catch (\moodle_exception $e) { debugging('Cannot write to external database: ' . $e->getMessage(), DEBUG_DEVELOPER); } }
[ "protected", "function", "insert_event_entries", "(", "$", "evententries", ")", "{", "if", "(", "!", "$", "this", "->", "init", "(", ")", ")", "{", "return", ";", "}", "if", "(", "!", "$", "dbtable", "=", "$", "this", "->", "get_config", "(", "'dbtable'", ")", ")", "{", "return", ";", "}", "try", "{", "$", "this", "->", "extdb", "->", "insert_records", "(", "$", "dbtable", ",", "$", "evententries", ")", ";", "}", "catch", "(", "\\", "moodle_exception", "$", "e", ")", "{", "debugging", "(", "'Cannot write to external database: '", ".", "$", "e", "->", "getMessage", "(", ")", ",", "DEBUG_DEVELOPER", ")", ";", "}", "}" ]
Insert events in bulk to the database. @param array $evententries raw event data
[ "Insert", "events", "in", "bulk", "to", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/store/database/classes/log/store.php#L140-L152
214,132
moodle/moodle
admin/tool/log/store/database/classes/log/store.php
store.get_events_select
public function get_events_select($selectwhere, array $params, $sort, $limitfrom, $limitnum) { if (!$this->init()) { return array(); } if (!$dbtable = $this->get_config('dbtable')) { return array(); } $sort = self::tweak_sort_by_id($sort); $events = array(); $records = $this->extdb->get_records_select($dbtable, $selectwhere, $params, $sort, '*', $limitfrom, $limitnum); foreach ($records as $data) { if ($event = $this->get_log_event($data)) { $events[$data->id] = $event; } } return $events; }
php
public function get_events_select($selectwhere, array $params, $sort, $limitfrom, $limitnum) { if (!$this->init()) { return array(); } if (!$dbtable = $this->get_config('dbtable')) { return array(); } $sort = self::tweak_sort_by_id($sort); $events = array(); $records = $this->extdb->get_records_select($dbtable, $selectwhere, $params, $sort, '*', $limitfrom, $limitnum); foreach ($records as $data) { if ($event = $this->get_log_event($data)) { $events[$data->id] = $event; } } return $events; }
[ "public", "function", "get_events_select", "(", "$", "selectwhere", ",", "array", "$", "params", ",", "$", "sort", ",", "$", "limitfrom", ",", "$", "limitnum", ")", "{", "if", "(", "!", "$", "this", "->", "init", "(", ")", ")", "{", "return", "array", "(", ")", ";", "}", "if", "(", "!", "$", "dbtable", "=", "$", "this", "->", "get_config", "(", "'dbtable'", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "sort", "=", "self", "::", "tweak_sort_by_id", "(", "$", "sort", ")", ";", "$", "events", "=", "array", "(", ")", ";", "$", "records", "=", "$", "this", "->", "extdb", "->", "get_records_select", "(", "$", "dbtable", ",", "$", "selectwhere", ",", "$", "params", ",", "$", "sort", ",", "'*'", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ";", "foreach", "(", "$", "records", "as", "$", "data", ")", "{", "if", "(", "$", "event", "=", "$", "this", "->", "get_log_event", "(", "$", "data", ")", ")", "{", "$", "events", "[", "$", "data", "->", "id", "]", "=", "$", "event", ";", "}", "}", "return", "$", "events", ";", "}" ]
Get an array of events based on the passed on params. @param string $selectwhere select conditions. @param array $params params. @param string $sort sortorder. @param int $limitfrom limit constraints. @param int $limitnum limit constraints. @return array|\core\event\base[] array of events.
[ "Get", "an", "array", "of", "events", "based", "on", "the", "passed", "on", "params", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/store/database/classes/log/store.php#L165-L186
214,133
moodle/moodle
admin/tool/log/store/database/classes/log/store.php
store.get_events_select_count
public function get_events_select_count($selectwhere, array $params) { if (!$this->init()) { return 0; } if (!$dbtable = $this->get_config('dbtable')) { return 0; } return $this->extdb->count_records_select($dbtable, $selectwhere, $params); }
php
public function get_events_select_count($selectwhere, array $params) { if (!$this->init()) { return 0; } if (!$dbtable = $this->get_config('dbtable')) { return 0; } return $this->extdb->count_records_select($dbtable, $selectwhere, $params); }
[ "public", "function", "get_events_select_count", "(", "$", "selectwhere", ",", "array", "$", "params", ")", "{", "if", "(", "!", "$", "this", "->", "init", "(", ")", ")", "{", "return", "0", ";", "}", "if", "(", "!", "$", "dbtable", "=", "$", "this", "->", "get_config", "(", "'dbtable'", ")", ")", "{", "return", "0", ";", "}", "return", "$", "this", "->", "extdb", "->", "count_records_select", "(", "$", "dbtable", ",", "$", "selectwhere", ",", "$", "params", ")", ";", "}" ]
Get number of events present for the given select clause. @param string $selectwhere select conditions. @param array $params params. @return int Number of events available for the given conditions
[ "Get", "number", "of", "events", "present", "for", "the", "given", "select", "clause", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/store/database/classes/log/store.php#L253-L263
214,134
moodle/moodle
admin/tool/log/store/database/classes/log/store.php
store.dispose
public function dispose() { $this->helper_dispose(); if ($this->extdb) { $this->extdb->dispose(); } $this->extdb = null; }
php
public function dispose() { $this->helper_dispose(); if ($this->extdb) { $this->extdb->dispose(); } $this->extdb = null; }
[ "public", "function", "dispose", "(", ")", "{", "$", "this", "->", "helper_dispose", "(", ")", ";", "if", "(", "$", "this", "->", "extdb", ")", "{", "$", "this", "->", "extdb", "->", "dispose", "(", ")", ";", "}", "$", "this", "->", "extdb", "=", "null", ";", "}" ]
Dispose off database connection after pushing any buffered events to the database.
[ "Dispose", "off", "database", "connection", "after", "pushing", "any", "buffered", "events", "to", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/store/database/classes/log/store.php#L304-L310
214,135
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.process_stage
public function process_stage($stage, $alreadystolen=false) { $this->set('stage', $stage); if ($alreadystolen) { $this->alreadystolen[$stage] = true; } else { if (!array_key_exists($stage, $this->alreadystolen)) { $this->alreadystolen[$stage] = false; } } if (!$this->alreadystolen[$stage] && $url = $this->instance->steal_control($stage)) { $this->save(); redirect($url); // does not return } else { $this->save(); } $waiting = $this->instance->get_export_config('wait'); if ($stage > PORTFOLIO_STAGE_QUEUEORWAIT && empty($waiting)) { $stage = PORTFOLIO_STAGE_FINISHED; } $functionmap = array( PORTFOLIO_STAGE_CONFIG => 'config', PORTFOLIO_STAGE_CONFIRM => 'confirm', PORTFOLIO_STAGE_QUEUEORWAIT => 'queueorwait', PORTFOLIO_STAGE_PACKAGE => 'package', PORTFOLIO_STAGE_CLEANUP => 'cleanup', PORTFOLIO_STAGE_SEND => 'send', PORTFOLIO_STAGE_FINISHED => 'finished' ); $function = 'process_stage_' . $functionmap[$stage]; try { if ($this->$function()) { // if we get through here it means control was returned // as opposed to wanting to stop processing // eg to wait for user input. $this->save(); $stage++; return $this->process_stage($stage); } else { $this->save(); return false; } } catch (portfolio_caller_exception $e) { portfolio_export_rethrow_exception($this, $e); } catch (portfolio_plugin_exception $e) { portfolio_export_rethrow_exception($this, $e); } catch (portfolio_export_exception $e) { throw $e; } catch (Exception $e) { debugging(get_string('thirdpartyexception', 'portfolio', get_class($e))); debugging($e); portfolio_export_rethrow_exception($this, $e); } }
php
public function process_stage($stage, $alreadystolen=false) { $this->set('stage', $stage); if ($alreadystolen) { $this->alreadystolen[$stage] = true; } else { if (!array_key_exists($stage, $this->alreadystolen)) { $this->alreadystolen[$stage] = false; } } if (!$this->alreadystolen[$stage] && $url = $this->instance->steal_control($stage)) { $this->save(); redirect($url); // does not return } else { $this->save(); } $waiting = $this->instance->get_export_config('wait'); if ($stage > PORTFOLIO_STAGE_QUEUEORWAIT && empty($waiting)) { $stage = PORTFOLIO_STAGE_FINISHED; } $functionmap = array( PORTFOLIO_STAGE_CONFIG => 'config', PORTFOLIO_STAGE_CONFIRM => 'confirm', PORTFOLIO_STAGE_QUEUEORWAIT => 'queueorwait', PORTFOLIO_STAGE_PACKAGE => 'package', PORTFOLIO_STAGE_CLEANUP => 'cleanup', PORTFOLIO_STAGE_SEND => 'send', PORTFOLIO_STAGE_FINISHED => 'finished' ); $function = 'process_stage_' . $functionmap[$stage]; try { if ($this->$function()) { // if we get through here it means control was returned // as opposed to wanting to stop processing // eg to wait for user input. $this->save(); $stage++; return $this->process_stage($stage); } else { $this->save(); return false; } } catch (portfolio_caller_exception $e) { portfolio_export_rethrow_exception($this, $e); } catch (portfolio_plugin_exception $e) { portfolio_export_rethrow_exception($this, $e); } catch (portfolio_export_exception $e) { throw $e; } catch (Exception $e) { debugging(get_string('thirdpartyexception', 'portfolio', get_class($e))); debugging($e); portfolio_export_rethrow_exception($this, $e); } }
[ "public", "function", "process_stage", "(", "$", "stage", ",", "$", "alreadystolen", "=", "false", ")", "{", "$", "this", "->", "set", "(", "'stage'", ",", "$", "stage", ")", ";", "if", "(", "$", "alreadystolen", ")", "{", "$", "this", "->", "alreadystolen", "[", "$", "stage", "]", "=", "true", ";", "}", "else", "{", "if", "(", "!", "array_key_exists", "(", "$", "stage", ",", "$", "this", "->", "alreadystolen", ")", ")", "{", "$", "this", "->", "alreadystolen", "[", "$", "stage", "]", "=", "false", ";", "}", "}", "if", "(", "!", "$", "this", "->", "alreadystolen", "[", "$", "stage", "]", "&&", "$", "url", "=", "$", "this", "->", "instance", "->", "steal_control", "(", "$", "stage", ")", ")", "{", "$", "this", "->", "save", "(", ")", ";", "redirect", "(", "$", "url", ")", ";", "// does not return", "}", "else", "{", "$", "this", "->", "save", "(", ")", ";", "}", "$", "waiting", "=", "$", "this", "->", "instance", "->", "get_export_config", "(", "'wait'", ")", ";", "if", "(", "$", "stage", ">", "PORTFOLIO_STAGE_QUEUEORWAIT", "&&", "empty", "(", "$", "waiting", ")", ")", "{", "$", "stage", "=", "PORTFOLIO_STAGE_FINISHED", ";", "}", "$", "functionmap", "=", "array", "(", "PORTFOLIO_STAGE_CONFIG", "=>", "'config'", ",", "PORTFOLIO_STAGE_CONFIRM", "=>", "'confirm'", ",", "PORTFOLIO_STAGE_QUEUEORWAIT", "=>", "'queueorwait'", ",", "PORTFOLIO_STAGE_PACKAGE", "=>", "'package'", ",", "PORTFOLIO_STAGE_CLEANUP", "=>", "'cleanup'", ",", "PORTFOLIO_STAGE_SEND", "=>", "'send'", ",", "PORTFOLIO_STAGE_FINISHED", "=>", "'finished'", ")", ";", "$", "function", "=", "'process_stage_'", ".", "$", "functionmap", "[", "$", "stage", "]", ";", "try", "{", "if", "(", "$", "this", "->", "$", "function", "(", ")", ")", "{", "// if we get through here it means control was returned", "// as opposed to wanting to stop processing", "// eg to wait for user input.", "$", "this", "->", "save", "(", ")", ";", "$", "stage", "++", ";", "return", "$", "this", "->", "process_stage", "(", "$", "stage", ")", ";", "}", "else", "{", "$", "this", "->", "save", "(", ")", ";", "return", "false", ";", "}", "}", "catch", "(", "portfolio_caller_exception", "$", "e", ")", "{", "portfolio_export_rethrow_exception", "(", "$", "this", ",", "$", "e", ")", ";", "}", "catch", "(", "portfolio_plugin_exception", "$", "e", ")", "{", "portfolio_export_rethrow_exception", "(", "$", "this", ",", "$", "e", ")", ";", "}", "catch", "(", "portfolio_export_exception", "$", "e", ")", "{", "throw", "$", "e", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "debugging", "(", "get_string", "(", "'thirdpartyexception'", ",", "'portfolio'", ",", "get_class", "(", "$", "e", ")", ")", ")", ";", "debugging", "(", "$", "e", ")", ";", "portfolio_export_rethrow_exception", "(", "$", "this", ",", "$", "e", ")", ";", "}", "}" ]
Process the given stage calling whatever functions are necessary @param int $stage (see PORTFOLIO_STAGE_* constants) @param bool $alreadystolen used to avoid letting plugins steal control twice. @return bool whether or not to process the next stage. this is important as the function is called recursively.
[ "Process", "the", "given", "stage", "calling", "whatever", "functions", "are", "necessary" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L195-L249
214,136
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.process_stage_queueorwait
public function process_stage_queueorwait() { global $DB; $wait = $this->instance->get_export_config('wait'); if (empty($wait)) { $DB->set_field('portfolio_tempdata', 'queued', 1, array('id' => $this->id)); $this->queued = true; return $this->process_stage_finished(true); } return true; }
php
public function process_stage_queueorwait() { global $DB; $wait = $this->instance->get_export_config('wait'); if (empty($wait)) { $DB->set_field('portfolio_tempdata', 'queued', 1, array('id' => $this->id)); $this->queued = true; return $this->process_stage_finished(true); } return true; }
[ "public", "function", "process_stage_queueorwait", "(", ")", "{", "global", "$", "DB", ";", "$", "wait", "=", "$", "this", "->", "instance", "->", "get_export_config", "(", "'wait'", ")", ";", "if", "(", "empty", "(", "$", "wait", ")", ")", "{", "$", "DB", "->", "set_field", "(", "'portfolio_tempdata'", ",", "'queued'", ",", "1", ",", "array", "(", "'id'", "=>", "$", "this", "->", "id", ")", ")", ";", "$", "this", "->", "queued", "=", "true", ";", "return", "$", "this", "->", "process_stage_finished", "(", "true", ")", ";", "}", "return", "true", ";", "}" ]
Processes the 'queueornext' stage of the export @return bool whether or not to process the next stage. this is important as the control function is called recursively.
[ "Processes", "the", "queueornext", "stage", "of", "the", "export" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L436-L446
214,137
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.process_stage_package
public function process_stage_package() { // now we've agreed on a format, // the caller is given control to package it up however it wants // and then the portfolio plugin is given control to do whatever it wants. try { $this->caller->prepare_package(); } catch (portfolio_exception $e) { throw new portfolio_export_exception($this, 'callercouldnotpackage', 'portfolio', null, $e->getMessage()); } catch (file_exception $e) { throw new portfolio_export_exception($this, 'callercouldnotpackage', 'portfolio', null, $e->getMessage()); } try { $this->instance->prepare_package(); } catch (portfolio_exception $e) { throw new portfolio_export_exception($this, 'plugincouldnotpackage', 'portfolio', null, $e->getMessage()); } catch (file_exception $e) { throw new portfolio_export_exception($this, 'plugincouldnotpackage', 'portfolio', null, $e->getMessage()); } return true; }
php
public function process_stage_package() { // now we've agreed on a format, // the caller is given control to package it up however it wants // and then the portfolio plugin is given control to do whatever it wants. try { $this->caller->prepare_package(); } catch (portfolio_exception $e) { throw new portfolio_export_exception($this, 'callercouldnotpackage', 'portfolio', null, $e->getMessage()); } catch (file_exception $e) { throw new portfolio_export_exception($this, 'callercouldnotpackage', 'portfolio', null, $e->getMessage()); } try { $this->instance->prepare_package(); } catch (portfolio_exception $e) { throw new portfolio_export_exception($this, 'plugincouldnotpackage', 'portfolio', null, $e->getMessage()); } catch (file_exception $e) { throw new portfolio_export_exception($this, 'plugincouldnotpackage', 'portfolio', null, $e->getMessage()); } return true; }
[ "public", "function", "process_stage_package", "(", ")", "{", "// now we've agreed on a format,", "// the caller is given control to package it up however it wants", "// and then the portfolio plugin is given control to do whatever it wants.", "try", "{", "$", "this", "->", "caller", "->", "prepare_package", "(", ")", ";", "}", "catch", "(", "portfolio_exception", "$", "e", ")", "{", "throw", "new", "portfolio_export_exception", "(", "$", "this", ",", "'callercouldnotpackage'", ",", "'portfolio'", ",", "null", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "catch", "(", "file_exception", "$", "e", ")", "{", "throw", "new", "portfolio_export_exception", "(", "$", "this", ",", "'callercouldnotpackage'", ",", "'portfolio'", ",", "null", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "try", "{", "$", "this", "->", "instance", "->", "prepare_package", "(", ")", ";", "}", "catch", "(", "portfolio_exception", "$", "e", ")", "{", "throw", "new", "portfolio_export_exception", "(", "$", "this", ",", "'plugincouldnotpackage'", ",", "'portfolio'", ",", "null", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "catch", "(", "file_exception", "$", "e", ")", "{", "throw", "new", "portfolio_export_exception", "(", "$", "this", ",", "'plugincouldnotpackage'", ",", "'portfolio'", ",", "null", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "return", "true", ";", "}" ]
Processes the 'package' stage of the export @return bool whether or not to process the next stage. this is important as the control function is called recursively. @throws portfolio_export_exception
[ "Processes", "the", "package", "stage", "of", "the", "export" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L454-L476
214,138
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.process_stage_cleanup
public function process_stage_cleanup($pullok=false) { global $CFG, $DB; if (!$pullok && $this->get('instance') && !$this->get('instance')->is_push()) { return true; } if ($this->get('instance')) { // might not be set - before export really starts $this->get('instance')->cleanup(); } $DB->delete_records('portfolio_tempdata', array('id' => $this->id)); $fs = get_file_storage(); $fs->delete_area_files(SYSCONTEXTID, 'portfolio', 'exporter', $this->id); $this->deleted = true; return true; }
php
public function process_stage_cleanup($pullok=false) { global $CFG, $DB; if (!$pullok && $this->get('instance') && !$this->get('instance')->is_push()) { return true; } if ($this->get('instance')) { // might not be set - before export really starts $this->get('instance')->cleanup(); } $DB->delete_records('portfolio_tempdata', array('id' => $this->id)); $fs = get_file_storage(); $fs->delete_area_files(SYSCONTEXTID, 'portfolio', 'exporter', $this->id); $this->deleted = true; return true; }
[ "public", "function", "process_stage_cleanup", "(", "$", "pullok", "=", "false", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "if", "(", "!", "$", "pullok", "&&", "$", "this", "->", "get", "(", "'instance'", ")", "&&", "!", "$", "this", "->", "get", "(", "'instance'", ")", "->", "is_push", "(", ")", ")", "{", "return", "true", ";", "}", "if", "(", "$", "this", "->", "get", "(", "'instance'", ")", ")", "{", "// might not be set - before export really starts", "$", "this", "->", "get", "(", "'instance'", ")", "->", "cleanup", "(", ")", ";", "}", "$", "DB", "->", "delete_records", "(", "'portfolio_tempdata'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "id", ")", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "fs", "->", "delete_area_files", "(", "SYSCONTEXTID", ",", "'portfolio'", ",", "'exporter'", ",", "$", "this", "->", "id", ")", ";", "$", "this", "->", "deleted", "=", "true", ";", "return", "true", ";", "}" ]
Processes the 'cleanup' stage of the export @param bool $pullok normally cleanup is deferred for pull plugins until after the file is requested from portfolio/file.php if you want to clean up earlier, pass true here (defaults to false) @return bool whether or not to process the next stage. this is important as the control function is called recursively.
[ "Processes", "the", "cleanup", "stage", "of", "the", "export" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L485-L500
214,139
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.process_stage_send
public function process_stage_send() { // send the file try { $this->instance->send_package(); } catch (portfolio_plugin_exception $e) { // not catching anything more general here. plugins with dependencies on other libraries that throw exceptions should catch and rethrow. // eg curl exception throw new portfolio_export_exception($this, 'failedtosendpackage', 'portfolio', null, $e->getMessage()); } // only log push types, pull happens in send_file if ($this->get('instance')->is_push()) { $this->log_transfer(); } return true; }
php
public function process_stage_send() { // send the file try { $this->instance->send_package(); } catch (portfolio_plugin_exception $e) { // not catching anything more general here. plugins with dependencies on other libraries that throw exceptions should catch and rethrow. // eg curl exception throw new portfolio_export_exception($this, 'failedtosendpackage', 'portfolio', null, $e->getMessage()); } // only log push types, pull happens in send_file if ($this->get('instance')->is_push()) { $this->log_transfer(); } return true; }
[ "public", "function", "process_stage_send", "(", ")", "{", "// send the file", "try", "{", "$", "this", "->", "instance", "->", "send_package", "(", ")", ";", "}", "catch", "(", "portfolio_plugin_exception", "$", "e", ")", "{", "// not catching anything more general here. plugins with dependencies on other libraries that throw exceptions should catch and rethrow.", "// eg curl exception", "throw", "new", "portfolio_export_exception", "(", "$", "this", ",", "'failedtosendpackage'", ",", "'portfolio'", ",", "null", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "// only log push types, pull happens in send_file", "if", "(", "$", "this", "->", "get", "(", "'instance'", ")", "->", "is_push", "(", ")", ")", "{", "$", "this", "->", "log_transfer", "(", ")", ";", "}", "return", "true", ";", "}" ]
Processes the 'send' stage of the export @return bool whether or not to process the next stage. this is important as the control function is called recursively.
[ "Processes", "the", "send", "stage", "of", "the", "export" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L507-L522
214,140
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.log_transfer
public function log_transfer() { global $DB; $l = array( 'userid' => $this->user->id, 'portfolio' => $this->instance->get('id'), 'caller_file'=> '', 'caller_component' => $this->callercomponent, 'caller_sha1' => $this->caller->get_sha1(), 'caller_class' => get_class($this->caller), 'continueurl' => $this->instance->get_static_continue_url(), 'returnurl' => $this->caller->get_return_url(), 'tempdataid' => $this->id, 'time' => time(), ); $DB->insert_record('portfolio_log', $l); }
php
public function log_transfer() { global $DB; $l = array( 'userid' => $this->user->id, 'portfolio' => $this->instance->get('id'), 'caller_file'=> '', 'caller_component' => $this->callercomponent, 'caller_sha1' => $this->caller->get_sha1(), 'caller_class' => get_class($this->caller), 'continueurl' => $this->instance->get_static_continue_url(), 'returnurl' => $this->caller->get_return_url(), 'tempdataid' => $this->id, 'time' => time(), ); $DB->insert_record('portfolio_log', $l); }
[ "public", "function", "log_transfer", "(", ")", "{", "global", "$", "DB", ";", "$", "l", "=", "array", "(", "'userid'", "=>", "$", "this", "->", "user", "->", "id", ",", "'portfolio'", "=>", "$", "this", "->", "instance", "->", "get", "(", "'id'", ")", ",", "'caller_file'", "=>", "''", ",", "'caller_component'", "=>", "$", "this", "->", "callercomponent", ",", "'caller_sha1'", "=>", "$", "this", "->", "caller", "->", "get_sha1", "(", ")", ",", "'caller_class'", "=>", "get_class", "(", "$", "this", "->", "caller", ")", ",", "'continueurl'", "=>", "$", "this", "->", "instance", "->", "get_static_continue_url", "(", ")", ",", "'returnurl'", "=>", "$", "this", "->", "caller", "->", "get_return_url", "(", ")", ",", "'tempdataid'", "=>", "$", "this", "->", "id", ",", "'time'", "=>", "time", "(", ")", ",", ")", ";", "$", "DB", "->", "insert_record", "(", "'portfolio_log'", ",", "$", "l", ")", ";", "}" ]
Log the transfer this should only be called after the file has been sent either via push, or sent from a pull request.
[ "Log", "the", "transfer" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L530-L545
214,141
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.process_stage_finished
public function process_stage_finished($queued=false) { global $OUTPUT; $returnurl = $this->caller->get_return_url(); $continueurl = $this->instance->get_interactive_continue_url(); $extras = $this->instance->get_extra_finish_options(); $key = 'exportcomplete'; if ($queued || $this->forcequeue) { $key = 'exportqueued'; if ($this->forcequeue) { $key = 'exportqueuedforced'; } } $this->print_header(get_string($key, 'portfolio'), false); self::print_finish_info($returnurl, $continueurl, $extras); echo $OUTPUT->footer(); return false; }
php
public function process_stage_finished($queued=false) { global $OUTPUT; $returnurl = $this->caller->get_return_url(); $continueurl = $this->instance->get_interactive_continue_url(); $extras = $this->instance->get_extra_finish_options(); $key = 'exportcomplete'; if ($queued || $this->forcequeue) { $key = 'exportqueued'; if ($this->forcequeue) { $key = 'exportqueuedforced'; } } $this->print_header(get_string($key, 'portfolio'), false); self::print_finish_info($returnurl, $continueurl, $extras); echo $OUTPUT->footer(); return false; }
[ "public", "function", "process_stage_finished", "(", "$", "queued", "=", "false", ")", "{", "global", "$", "OUTPUT", ";", "$", "returnurl", "=", "$", "this", "->", "caller", "->", "get_return_url", "(", ")", ";", "$", "continueurl", "=", "$", "this", "->", "instance", "->", "get_interactive_continue_url", "(", ")", ";", "$", "extras", "=", "$", "this", "->", "instance", "->", "get_extra_finish_options", "(", ")", ";", "$", "key", "=", "'exportcomplete'", ";", "if", "(", "$", "queued", "||", "$", "this", "->", "forcequeue", ")", "{", "$", "key", "=", "'exportqueued'", ";", "if", "(", "$", "this", "->", "forcequeue", ")", "{", "$", "key", "=", "'exportqueuedforced'", ";", "}", "}", "$", "this", "->", "print_header", "(", "get_string", "(", "$", "key", ",", "'portfolio'", ")", ",", "false", ")", ";", "self", "::", "print_finish_info", "(", "$", "returnurl", ",", "$", "continueurl", ",", "$", "extras", ")", ";", "echo", "$", "OUTPUT", "->", "footer", "(", ")", ";", "return", "false", ";", "}" ]
Processes the 'finish' stage of the export @param bool $queued let the process to be queued @return bool whether or not to process the next stage. this is important as the control function is called recursively.
[ "Processes", "the", "finish", "stage", "of", "the", "export" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L564-L581
214,142
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.print_header
public function print_header($headingstr, $summary=true) { global $OUTPUT, $PAGE; $titlestr = get_string('exporting', 'portfolio'); $headerstr = get_string('exporting', 'portfolio'); $PAGE->set_title($titlestr); $PAGE->set_heading($headerstr); echo $OUTPUT->header(); echo $OUTPUT->heading($headingstr); if (!$summary) { return; } echo $OUTPUT->box_start(); echo $OUTPUT->box_start(); echo $this->caller->heading_summary(); echo $OUTPUT->box_end(); if ($this->instance) { echo $OUTPUT->box_start(); echo $this->instance->heading_summary(); echo $OUTPUT->box_end(); } echo $OUTPUT->box_end(); }
php
public function print_header($headingstr, $summary=true) { global $OUTPUT, $PAGE; $titlestr = get_string('exporting', 'portfolio'); $headerstr = get_string('exporting', 'portfolio'); $PAGE->set_title($titlestr); $PAGE->set_heading($headerstr); echo $OUTPUT->header(); echo $OUTPUT->heading($headingstr); if (!$summary) { return; } echo $OUTPUT->box_start(); echo $OUTPUT->box_start(); echo $this->caller->heading_summary(); echo $OUTPUT->box_end(); if ($this->instance) { echo $OUTPUT->box_start(); echo $this->instance->heading_summary(); echo $OUTPUT->box_end(); } echo $OUTPUT->box_end(); }
[ "public", "function", "print_header", "(", "$", "headingstr", ",", "$", "summary", "=", "true", ")", "{", "global", "$", "OUTPUT", ",", "$", "PAGE", ";", "$", "titlestr", "=", "get_string", "(", "'exporting'", ",", "'portfolio'", ")", ";", "$", "headerstr", "=", "get_string", "(", "'exporting'", ",", "'portfolio'", ")", ";", "$", "PAGE", "->", "set_title", "(", "$", "titlestr", ")", ";", "$", "PAGE", "->", "set_heading", "(", "$", "headerstr", ")", ";", "echo", "$", "OUTPUT", "->", "header", "(", ")", ";", "echo", "$", "OUTPUT", "->", "heading", "(", "$", "headingstr", ")", ";", "if", "(", "!", "$", "summary", ")", "{", "return", ";", "}", "echo", "$", "OUTPUT", "->", "box_start", "(", ")", ";", "echo", "$", "OUTPUT", "->", "box_start", "(", ")", ";", "echo", "$", "this", "->", "caller", "->", "heading_summary", "(", ")", ";", "echo", "$", "OUTPUT", "->", "box_end", "(", ")", ";", "if", "(", "$", "this", "->", "instance", ")", "{", "echo", "$", "OUTPUT", "->", "box_start", "(", ")", ";", "echo", "$", "this", "->", "instance", "->", "heading_summary", "(", ")", ";", "echo", "$", "OUTPUT", "->", "box_end", "(", ")", ";", "}", "echo", "$", "OUTPUT", "->", "box_end", "(", ")", ";", "}" ]
Local print header function to be reused across the export @param string $headingstr full language string @param bool $summary (optional) to print summary, default is set to true @return void
[ "Local", "print", "header", "function", "to", "be", "reused", "across", "the", "export" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L591-L615
214,143
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.cancel_request
public function cancel_request($logreturn=false) { global $CFG; if (!isset($this)) { return; } $this->process_stage_cleanup(true); if ($logreturn) { redirect($CFG->wwwroot . '/user/portfoliologs.php'); } redirect($this->caller->get_return_url()); exit; }
php
public function cancel_request($logreturn=false) { global $CFG; if (!isset($this)) { return; } $this->process_stage_cleanup(true); if ($logreturn) { redirect($CFG->wwwroot . '/user/portfoliologs.php'); } redirect($this->caller->get_return_url()); exit; }
[ "public", "function", "cancel_request", "(", "$", "logreturn", "=", "false", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "isset", "(", "$", "this", ")", ")", "{", "return", ";", "}", "$", "this", "->", "process_stage_cleanup", "(", "true", ")", ";", "if", "(", "$", "logreturn", ")", "{", "redirect", "(", "$", "CFG", "->", "wwwroot", ".", "'/user/portfoliologs.php'", ")", ";", "}", "redirect", "(", "$", "this", "->", "caller", "->", "get_return_url", "(", ")", ")", ";", "exit", ";", "}" ]
Cancels a potfolio request and cleans up the tempdata and redirects the user back to where they started @param bool $logreturn options to return to porfolio log or caller return page @return void @uses exit
[ "Cancels", "a", "potfolio", "request", "and", "cleans", "up", "the", "tempdata", "and", "redirects", "the", "user", "back", "to", "where", "they", "started" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L625-L636
214,144
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.save
public function save() { global $DB; if (empty($this->id)) { $r = (object)array( 'data' => base64_encode(serialize($this)), 'expirytime' => time() + (60*60*24), 'userid' => $this->user->id, 'instance' => (empty($this->instance)) ? null : $this->instance->get('id'), ); $this->id = $DB->insert_record('portfolio_tempdata', $r); $this->expirytime = $r->expirytime; $this->save(); // call again so that id gets added to the save data. } else { if (!$r = $DB->get_record('portfolio_tempdata', array('id' => $this->id))) { if (!$this->deleted) { //debugging("tried to save current object, but failed - see MDL-20872"); } return; } $r->data = base64_encode(serialize($this)); $r->instance = (empty($this->instance)) ? null : $this->instance->get('id'); $DB->update_record('portfolio_tempdata', $r); } }
php
public function save() { global $DB; if (empty($this->id)) { $r = (object)array( 'data' => base64_encode(serialize($this)), 'expirytime' => time() + (60*60*24), 'userid' => $this->user->id, 'instance' => (empty($this->instance)) ? null : $this->instance->get('id'), ); $this->id = $DB->insert_record('portfolio_tempdata', $r); $this->expirytime = $r->expirytime; $this->save(); // call again so that id gets added to the save data. } else { if (!$r = $DB->get_record('portfolio_tempdata', array('id' => $this->id))) { if (!$this->deleted) { //debugging("tried to save current object, but failed - see MDL-20872"); } return; } $r->data = base64_encode(serialize($this)); $r->instance = (empty($this->instance)) ? null : $this->instance->get('id'); $DB->update_record('portfolio_tempdata', $r); } }
[ "public", "function", "save", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "this", "->", "id", ")", ")", "{", "$", "r", "=", "(", "object", ")", "array", "(", "'data'", "=>", "base64_encode", "(", "serialize", "(", "$", "this", ")", ")", ",", "'expirytime'", "=>", "time", "(", ")", "+", "(", "60", "*", "60", "*", "24", ")", ",", "'userid'", "=>", "$", "this", "->", "user", "->", "id", ",", "'instance'", "=>", "(", "empty", "(", "$", "this", "->", "instance", ")", ")", "?", "null", ":", "$", "this", "->", "instance", "->", "get", "(", "'id'", ")", ",", ")", ";", "$", "this", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'portfolio_tempdata'", ",", "$", "r", ")", ";", "$", "this", "->", "expirytime", "=", "$", "r", "->", "expirytime", ";", "$", "this", "->", "save", "(", ")", ";", "// call again so that id gets added to the save data.", "}", "else", "{", "if", "(", "!", "$", "r", "=", "$", "DB", "->", "get_record", "(", "'portfolio_tempdata'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "id", ")", ")", ")", "{", "if", "(", "!", "$", "this", "->", "deleted", ")", "{", "//debugging(\"tried to save current object, but failed - see MDL-20872\");", "}", "return", ";", "}", "$", "r", "->", "data", "=", "base64_encode", "(", "serialize", "(", "$", "this", ")", ")", ";", "$", "r", "->", "instance", "=", "(", "empty", "(", "$", "this", "->", "instance", ")", ")", "?", "null", ":", "$", "this", "->", "instance", "->", "get", "(", "'id'", ")", ";", "$", "DB", "->", "update_record", "(", "'portfolio_tempdata'", ",", "$", "r", ")", ";", "}", "}" ]
Writes out the contents of this object and all its data to the portfolio_tempdata table and sets the 'id' field. @return void
[ "Writes", "out", "the", "contents", "of", "this", "object", "and", "all", "its", "data", "to", "the", "portfolio_tempdata", "table", "and", "sets", "the", "id", "field", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L643-L666
214,145
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.rewaken_object
public static function rewaken_object($id) { global $DB, $CFG; require_once($CFG->libdir . '/filelib.php'); require_once($CFG->libdir . '/portfolio/exporter.php'); require_once($CFG->libdir . '/portfolio/caller.php'); require_once($CFG->libdir . '/portfolio/plugin.php'); if (!$data = $DB->get_record('portfolio_tempdata', array('id' => $id))) { // maybe it's been finished already by a pull plugin // so look in the logs if ($log = $DB->get_record('portfolio_log', array('tempdataid' => $id))) { self::print_cleaned_export($log); } throw new portfolio_exception('invalidtempid', 'portfolio'); } $exporter = unserialize(base64_decode($data->data)); if ($exporter->instancefile) { require_once($CFG->dirroot . '/' . $exporter->instancefile); } if (!empty($exporter->callerfile)) { portfolio_include_callback_file($exporter->callerfile); } else if (!empty($exporter->callercomponent)) { portfolio_include_callback_file($exporter->callercomponent); } else { return; // Should never get here! } $exporter = unserialize(serialize($exporter)); if (!$exporter->get('id')) { // workaround for weird case // where the id doesn't get saved between a new insert // and the subsequent call that sets this field in the serialised data $exporter->set('id', $id); $exporter->save(); } return $exporter; }
php
public static function rewaken_object($id) { global $DB, $CFG; require_once($CFG->libdir . '/filelib.php'); require_once($CFG->libdir . '/portfolio/exporter.php'); require_once($CFG->libdir . '/portfolio/caller.php'); require_once($CFG->libdir . '/portfolio/plugin.php'); if (!$data = $DB->get_record('portfolio_tempdata', array('id' => $id))) { // maybe it's been finished already by a pull plugin // so look in the logs if ($log = $DB->get_record('portfolio_log', array('tempdataid' => $id))) { self::print_cleaned_export($log); } throw new portfolio_exception('invalidtempid', 'portfolio'); } $exporter = unserialize(base64_decode($data->data)); if ($exporter->instancefile) { require_once($CFG->dirroot . '/' . $exporter->instancefile); } if (!empty($exporter->callerfile)) { portfolio_include_callback_file($exporter->callerfile); } else if (!empty($exporter->callercomponent)) { portfolio_include_callback_file($exporter->callercomponent); } else { return; // Should never get here! } $exporter = unserialize(serialize($exporter)); if (!$exporter->get('id')) { // workaround for weird case // where the id doesn't get saved between a new insert // and the subsequent call that sets this field in the serialised data $exporter->set('id', $id); $exporter->save(); } return $exporter; }
[ "public", "static", "function", "rewaken_object", "(", "$", "id", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/filelib.php'", ")", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/portfolio/exporter.php'", ")", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/portfolio/caller.php'", ")", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/portfolio/plugin.php'", ")", ";", "if", "(", "!", "$", "data", "=", "$", "DB", "->", "get_record", "(", "'portfolio_tempdata'", ",", "array", "(", "'id'", "=>", "$", "id", ")", ")", ")", "{", "// maybe it's been finished already by a pull plugin", "// so look in the logs", "if", "(", "$", "log", "=", "$", "DB", "->", "get_record", "(", "'portfolio_log'", ",", "array", "(", "'tempdataid'", "=>", "$", "id", ")", ")", ")", "{", "self", "::", "print_cleaned_export", "(", "$", "log", ")", ";", "}", "throw", "new", "portfolio_exception", "(", "'invalidtempid'", ",", "'portfolio'", ")", ";", "}", "$", "exporter", "=", "unserialize", "(", "base64_decode", "(", "$", "data", "->", "data", ")", ")", ";", "if", "(", "$", "exporter", "->", "instancefile", ")", "{", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/'", ".", "$", "exporter", "->", "instancefile", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "exporter", "->", "callerfile", ")", ")", "{", "portfolio_include_callback_file", "(", "$", "exporter", "->", "callerfile", ")", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "exporter", "->", "callercomponent", ")", ")", "{", "portfolio_include_callback_file", "(", "$", "exporter", "->", "callercomponent", ")", ";", "}", "else", "{", "return", ";", "// Should never get here!", "}", "$", "exporter", "=", "unserialize", "(", "serialize", "(", "$", "exporter", ")", ")", ";", "if", "(", "!", "$", "exporter", "->", "get", "(", "'id'", ")", ")", "{", "// workaround for weird case", "// where the id doesn't get saved between a new insert", "// and the subsequent call that sets this field in the serialised data", "$", "exporter", "->", "set", "(", "'id'", ",", "$", "id", ")", ";", "$", "exporter", "->", "save", "(", ")", ";", "}", "return", "$", "exporter", ";", "}" ]
Rewakens the data from the database given the id. Makes sure to load the required files with the class definitions @param int $id id of data @return portfolio_exporter
[ "Rewakens", "the", "data", "from", "the", "database", "given", "the", "id", ".", "Makes", "sure", "to", "load", "the", "required", "files", "with", "the", "class", "definitions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L675-L710
214,146
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.verify_rewaken
public function verify_rewaken($readonly=false) { global $USER, $CFG; if ($this->get('user')->id != $USER->id) { // make sure it belongs to the right user throw new portfolio_exception('notyours', 'portfolio'); } if (!$readonly && $this->get('instance') && !$this->get('instance')->allows_multiple_exports()) { $already = portfolio_existing_exports($this->get('user')->id, $this->get('instance')->get('plugin')); $already = array_keys($already); if (array_shift($already) != $this->get('id')) { $a = (object)array( 'plugin' => $this->get('instance')->get('plugin'), 'link' => $CFG->wwwroot . '/user/portfoliologs.php', ); throw new portfolio_exception('nomultipleexports', 'portfolio', '', $a); } } if (!$this->caller->check_permissions()) { // recall the caller permission check throw new portfolio_caller_exception('nopermissions', 'portfolio', $this->caller->get_return_url()); } }
php
public function verify_rewaken($readonly=false) { global $USER, $CFG; if ($this->get('user')->id != $USER->id) { // make sure it belongs to the right user throw new portfolio_exception('notyours', 'portfolio'); } if (!$readonly && $this->get('instance') && !$this->get('instance')->allows_multiple_exports()) { $already = portfolio_existing_exports($this->get('user')->id, $this->get('instance')->get('plugin')); $already = array_keys($already); if (array_shift($already) != $this->get('id')) { $a = (object)array( 'plugin' => $this->get('instance')->get('plugin'), 'link' => $CFG->wwwroot . '/user/portfoliologs.php', ); throw new portfolio_exception('nomultipleexports', 'portfolio', '', $a); } } if (!$this->caller->check_permissions()) { // recall the caller permission check throw new portfolio_caller_exception('nopermissions', 'portfolio', $this->caller->get_return_url()); } }
[ "public", "function", "verify_rewaken", "(", "$", "readonly", "=", "false", ")", "{", "global", "$", "USER", ",", "$", "CFG", ";", "if", "(", "$", "this", "->", "get", "(", "'user'", ")", "->", "id", "!=", "$", "USER", "->", "id", ")", "{", "// make sure it belongs to the right user", "throw", "new", "portfolio_exception", "(", "'notyours'", ",", "'portfolio'", ")", ";", "}", "if", "(", "!", "$", "readonly", "&&", "$", "this", "->", "get", "(", "'instance'", ")", "&&", "!", "$", "this", "->", "get", "(", "'instance'", ")", "->", "allows_multiple_exports", "(", ")", ")", "{", "$", "already", "=", "portfolio_existing_exports", "(", "$", "this", "->", "get", "(", "'user'", ")", "->", "id", ",", "$", "this", "->", "get", "(", "'instance'", ")", "->", "get", "(", "'plugin'", ")", ")", ";", "$", "already", "=", "array_keys", "(", "$", "already", ")", ";", "if", "(", "array_shift", "(", "$", "already", ")", "!=", "$", "this", "->", "get", "(", "'id'", ")", ")", "{", "$", "a", "=", "(", "object", ")", "array", "(", "'plugin'", "=>", "$", "this", "->", "get", "(", "'instance'", ")", "->", "get", "(", "'plugin'", ")", ",", "'link'", "=>", "$", "CFG", "->", "wwwroot", ".", "'/user/portfoliologs.php'", ",", ")", ";", "throw", "new", "portfolio_exception", "(", "'nomultipleexports'", ",", "'portfolio'", ",", "''", ",", "$", "a", ")", ";", "}", "}", "if", "(", "!", "$", "this", "->", "caller", "->", "check_permissions", "(", ")", ")", "{", "// recall the caller permission check", "throw", "new", "portfolio_caller_exception", "(", "'nopermissions'", ",", "'portfolio'", ",", "$", "this", "->", "caller", "->", "get_return_url", "(", ")", ")", ";", "}", "}" ]
Verifies a rewoken object. Checks to make sure it belongs to the same user and session as is currently in use. @param bool $readonly if we're reawakening this for a user to just display in the log view, don't verify the sessionkey @throws portfolio_exception
[ "Verifies", "a", "rewoken", "object", ".", "Checks", "to", "make", "sure", "it", "belongs", "to", "the", "same", "user", "and", "session", "as", "is", "currently", "in", "use", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L736-L757
214,147
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.copy_existing_file
public function copy_existing_file($oldfile) { if (array_key_exists($oldfile->get_contenthash(), $this->newfilehashes)) { return $this->newfilehashes[$oldfile->get_contenthash()]; } $fs = get_file_storage(); $file_record = $this->new_file_record_base($oldfile->get_filename()); if ($dir = $this->get('format')->get_file_directory()) { $file_record->filepath = '/'. $dir . '/'; } try { $newfile = $fs->create_file_from_storedfile($file_record, $oldfile->get_id()); $this->newfilehashes[$newfile->get_contenthash()] = $newfile; return $newfile; } catch (file_exception $e) { return false; } }
php
public function copy_existing_file($oldfile) { if (array_key_exists($oldfile->get_contenthash(), $this->newfilehashes)) { return $this->newfilehashes[$oldfile->get_contenthash()]; } $fs = get_file_storage(); $file_record = $this->new_file_record_base($oldfile->get_filename()); if ($dir = $this->get('format')->get_file_directory()) { $file_record->filepath = '/'. $dir . '/'; } try { $newfile = $fs->create_file_from_storedfile($file_record, $oldfile->get_id()); $this->newfilehashes[$newfile->get_contenthash()] = $newfile; return $newfile; } catch (file_exception $e) { return false; } }
[ "public", "function", "copy_existing_file", "(", "$", "oldfile", ")", "{", "if", "(", "array_key_exists", "(", "$", "oldfile", "->", "get_contenthash", "(", ")", ",", "$", "this", "->", "newfilehashes", ")", ")", "{", "return", "$", "this", "->", "newfilehashes", "[", "$", "oldfile", "->", "get_contenthash", "(", ")", "]", ";", "}", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "file_record", "=", "$", "this", "->", "new_file_record_base", "(", "$", "oldfile", "->", "get_filename", "(", ")", ")", ";", "if", "(", "$", "dir", "=", "$", "this", "->", "get", "(", "'format'", ")", "->", "get_file_directory", "(", ")", ")", "{", "$", "file_record", "->", "filepath", "=", "'/'", ".", "$", "dir", ".", "'/'", ";", "}", "try", "{", "$", "newfile", "=", "$", "fs", "->", "create_file_from_storedfile", "(", "$", "file_record", ",", "$", "oldfile", "->", "get_id", "(", ")", ")", ";", "$", "this", "->", "newfilehashes", "[", "$", "newfile", "->", "get_contenthash", "(", ")", "]", "=", "$", "newfile", ";", "return", "$", "newfile", ";", "}", "catch", "(", "file_exception", "$", "e", ")", "{", "return", "false", ";", "}", "}" ]
Copies a file from somewhere else in moodle to the portfolio temporary working directory associated with this export @param stored_file $oldfile existing stored file object @return stored_file|bool new file object
[ "Copies", "a", "file", "from", "somewhere", "else", "in", "moodle", "to", "the", "portfolio", "temporary", "working", "directory", "associated", "with", "this", "export" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L766-L782
214,148
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.write_new_file
public function write_new_file($content, $name, $manifest=true) { $fs = get_file_storage(); $file_record = $this->new_file_record_base($name); if (empty($manifest) && ($dir = $this->get('format')->get_file_directory())) { $file_record->filepath = '/' . $dir . '/'; } return $fs->create_file_from_string($file_record, $content); }
php
public function write_new_file($content, $name, $manifest=true) { $fs = get_file_storage(); $file_record = $this->new_file_record_base($name); if (empty($manifest) && ($dir = $this->get('format')->get_file_directory())) { $file_record->filepath = '/' . $dir . '/'; } return $fs->create_file_from_string($file_record, $content); }
[ "public", "function", "write_new_file", "(", "$", "content", ",", "$", "name", ",", "$", "manifest", "=", "true", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "file_record", "=", "$", "this", "->", "new_file_record_base", "(", "$", "name", ")", ";", "if", "(", "empty", "(", "$", "manifest", ")", "&&", "(", "$", "dir", "=", "$", "this", "->", "get", "(", "'format'", ")", "->", "get_file_directory", "(", ")", ")", ")", "{", "$", "file_record", "->", "filepath", "=", "'/'", ".", "$", "dir", ".", "'/'", ";", "}", "return", "$", "fs", "->", "create_file_from_string", "(", "$", "file_record", ",", "$", "content", ")", ";", "}" ]
Writes out some content to a file in the portfolio temporary working directory associated with this export. @param string $content content to write @param string $name filename to use @param bool $manifest whether this is the main file or an secondary file (eg attachment) @return stored_file
[ "Writes", "out", "some", "content", "to", "a", "file", "in", "the", "portfolio", "temporary", "working", "directory", "associated", "with", "this", "export", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L794-L801
214,149
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.zip_tempfiles
public function zip_tempfiles($filename='portfolio-export.zip', $filepath='/final/') { $zipper = new zip_packer(); list ($contextid, $component, $filearea, $itemid) = array_values($this->get_base_filearea()); if ($newfile = $zipper->archive_to_storage($this->get_tempfiles(), $contextid, $component, $filearea, $itemid, $filepath, $filename, $this->user->id)) { return $newfile; } return false; }
php
public function zip_tempfiles($filename='portfolio-export.zip', $filepath='/final/') { $zipper = new zip_packer(); list ($contextid, $component, $filearea, $itemid) = array_values($this->get_base_filearea()); if ($newfile = $zipper->archive_to_storage($this->get_tempfiles(), $contextid, $component, $filearea, $itemid, $filepath, $filename, $this->user->id)) { return $newfile; } return false; }
[ "public", "function", "zip_tempfiles", "(", "$", "filename", "=", "'portfolio-export.zip'", ",", "$", "filepath", "=", "'/final/'", ")", "{", "$", "zipper", "=", "new", "zip_packer", "(", ")", ";", "list", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ")", "=", "array_values", "(", "$", "this", "->", "get_base_filearea", "(", ")", ")", ";", "if", "(", "$", "newfile", "=", "$", "zipper", "->", "archive_to_storage", "(", "$", "this", "->", "get_tempfiles", "(", ")", ",", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ",", "$", "filename", ",", "$", "this", "->", "user", "->", "id", ")", ")", "{", "return", "$", "newfile", ";", "}", "return", "false", ";", "}" ]
Zips all files in the temporary directory @param string $filename name of resulting zipfile (optional, defaults to portfolio-export.zip) @param string $filepath subpath in the filearea (optional, defaults to final) @return stored_file|bool resulting stored_file object, or false
[ "Zips", "all", "files", "in", "the", "temporary", "directory" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L810-L819
214,150
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.get_tempfiles
public function get_tempfiles($skipfile='portfolio-export.zip') { $fs = get_file_storage(); $files = $fs->get_area_files(SYSCONTEXTID, 'portfolio', 'exporter', $this->id, 'sortorder, itemid, filepath, filename', false); if (empty($files)) { return array(); } $returnfiles = array(); foreach ($files as $f) { if ($f->get_filename() == $skipfile) { continue; } $returnfiles[$f->get_filepath() . $f->get_filename()] = $f; } return $returnfiles; }
php
public function get_tempfiles($skipfile='portfolio-export.zip') { $fs = get_file_storage(); $files = $fs->get_area_files(SYSCONTEXTID, 'portfolio', 'exporter', $this->id, 'sortorder, itemid, filepath, filename', false); if (empty($files)) { return array(); } $returnfiles = array(); foreach ($files as $f) { if ($f->get_filename() == $skipfile) { continue; } $returnfiles[$f->get_filepath() . $f->get_filename()] = $f; } return $returnfiles; }
[ "public", "function", "get_tempfiles", "(", "$", "skipfile", "=", "'portfolio-export.zip'", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "SYSCONTEXTID", ",", "'portfolio'", ",", "'exporter'", ",", "$", "this", "->", "id", ",", "'sortorder, itemid, filepath, filename'", ",", "false", ")", ";", "if", "(", "empty", "(", "$", "files", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "returnfiles", "=", "array", "(", ")", ";", "foreach", "(", "$", "files", "as", "$", "f", ")", "{", "if", "(", "$", "f", "->", "get_filename", "(", ")", "==", "$", "skipfile", ")", "{", "continue", ";", "}", "$", "returnfiles", "[", "$", "f", "->", "get_filepath", "(", ")", ".", "$", "f", "->", "get_filename", "(", ")", "]", "=", "$", "f", ";", "}", "return", "$", "returnfiles", ";", "}" ]
Returns an arary of files in the temporary working directory for this export. Always use this instead of the files api directly @param string $skipfile name of the file to be skipped @return array of stored_file objects keyed by name
[ "Returns", "an", "arary", "of", "files", "in", "the", "temporary", "working", "directory", "for", "this", "export", ".", "Always", "use", "this", "instead", "of", "the", "files", "api", "directly" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L829-L843
214,151
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.print_expired_export
public static function print_expired_export() { global $CFG, $OUTPUT, $PAGE; $title = get_string('exportexpired', 'portfolio'); $PAGE->navbar->add(get_string('exportexpired', 'portfolio')); $PAGE->set_title($title); $PAGE->set_heading($title); echo $OUTPUT->header(); echo $OUTPUT->notification(get_string('exportexpireddesc', 'portfolio')); echo $OUTPUT->continue_button($CFG->wwwroot); echo $OUTPUT->footer(); exit; }
php
public static function print_expired_export() { global $CFG, $OUTPUT, $PAGE; $title = get_string('exportexpired', 'portfolio'); $PAGE->navbar->add(get_string('exportexpired', 'portfolio')); $PAGE->set_title($title); $PAGE->set_heading($title); echo $OUTPUT->header(); echo $OUTPUT->notification(get_string('exportexpireddesc', 'portfolio')); echo $OUTPUT->continue_button($CFG->wwwroot); echo $OUTPUT->footer(); exit; }
[ "public", "static", "function", "print_expired_export", "(", ")", "{", "global", "$", "CFG", ",", "$", "OUTPUT", ",", "$", "PAGE", ";", "$", "title", "=", "get_string", "(", "'exportexpired'", ",", "'portfolio'", ")", ";", "$", "PAGE", "->", "navbar", "->", "add", "(", "get_string", "(", "'exportexpired'", ",", "'portfolio'", ")", ")", ";", "$", "PAGE", "->", "set_title", "(", "$", "title", ")", ";", "$", "PAGE", "->", "set_heading", "(", "$", "title", ")", ";", "echo", "$", "OUTPUT", "->", "header", "(", ")", ";", "echo", "$", "OUTPUT", "->", "notification", "(", "get_string", "(", "'exportexpireddesc'", ",", "'portfolio'", ")", ")", ";", "echo", "$", "OUTPUT", "->", "continue_button", "(", "$", "CFG", "->", "wwwroot", ")", ";", "echo", "$", "OUTPUT", "->", "footer", "(", ")", ";", "exit", ";", "}" ]
Wrapper function to print a friendly error to users This is generally caused by them hitting an expired transfer through the usage of the backbutton @uses exit
[ "Wrapper", "function", "to", "print", "a", "friendly", "error", "to", "users", "This", "is", "generally", "caused", "by", "them", "hitting", "an", "expired", "transfer", "through", "the", "usage", "of", "the", "backbutton" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L870-L881
214,152
moodle/moodle
lib/portfolio/exporter.php
portfolio_exporter.print_cleaned_export
public static function print_cleaned_export($log, $instance=null) { global $CFG, $OUTPUT, $PAGE; if (empty($instance) || !$instance instanceof portfolio_plugin_base) { $instance = portfolio_instance($log->portfolio); } $title = get_string('exportalreadyfinished', 'portfolio'); $PAGE->navbar->add($title); $PAGE->set_title($title); $PAGE->set_heading($title); echo $OUTPUT->header(); echo $OUTPUT->notification(get_string('exportalreadyfinished', 'portfolio')); self::print_finish_info($log->returnurl, $instance->resolve_static_continue_url($log->continueurl)); echo $OUTPUT->continue_button($CFG->wwwroot); echo $OUTPUT->footer(); exit; }
php
public static function print_cleaned_export($log, $instance=null) { global $CFG, $OUTPUT, $PAGE; if (empty($instance) || !$instance instanceof portfolio_plugin_base) { $instance = portfolio_instance($log->portfolio); } $title = get_string('exportalreadyfinished', 'portfolio'); $PAGE->navbar->add($title); $PAGE->set_title($title); $PAGE->set_heading($title); echo $OUTPUT->header(); echo $OUTPUT->notification(get_string('exportalreadyfinished', 'portfolio')); self::print_finish_info($log->returnurl, $instance->resolve_static_continue_url($log->continueurl)); echo $OUTPUT->continue_button($CFG->wwwroot); echo $OUTPUT->footer(); exit; }
[ "public", "static", "function", "print_cleaned_export", "(", "$", "log", ",", "$", "instance", "=", "null", ")", "{", "global", "$", "CFG", ",", "$", "OUTPUT", ",", "$", "PAGE", ";", "if", "(", "empty", "(", "$", "instance", ")", "||", "!", "$", "instance", "instanceof", "portfolio_plugin_base", ")", "{", "$", "instance", "=", "portfolio_instance", "(", "$", "log", "->", "portfolio", ")", ";", "}", "$", "title", "=", "get_string", "(", "'exportalreadyfinished'", ",", "'portfolio'", ")", ";", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "title", ")", ";", "$", "PAGE", "->", "set_title", "(", "$", "title", ")", ";", "$", "PAGE", "->", "set_heading", "(", "$", "title", ")", ";", "echo", "$", "OUTPUT", "->", "header", "(", ")", ";", "echo", "$", "OUTPUT", "->", "notification", "(", "get_string", "(", "'exportalreadyfinished'", ",", "'portfolio'", ")", ")", ";", "self", "::", "print_finish_info", "(", "$", "log", "->", "returnurl", ",", "$", "instance", "->", "resolve_static_continue_url", "(", "$", "log", "->", "continueurl", ")", ")", ";", "echo", "$", "OUTPUT", "->", "continue_button", "(", "$", "CFG", "->", "wwwroot", ")", ";", "echo", "$", "OUTPUT", "->", "footer", "(", ")", ";", "exit", ";", "}" ]
Wrapper function to print a friendly error to users @param stdClass $log portfolio_log object @param portfolio_plugin_base $instance portfolio instance @uses exit
[ "Wrapper", "function", "to", "print", "a", "friendly", "error", "to", "users" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/exporter.php#L890-L905
214,153
moodle/moodle
grade/report/overview/classes/external.php
gradereport_overview_external.get_course_grades
public static function get_course_grades($userid = 0) { global $USER; $warnings = array(); // Validate the parameter. $params = self::validate_parameters(self::get_course_grades_parameters(), array( 'userid' => $userid ) ); $userid = $params['userid']; if (empty($userid)) { $userid = $USER->id; } $systemcontext = context_system::instance(); self::validate_context($systemcontext); if ($USER->id != $userid) { // We must check if the current user can view other users grades. $user = core_user::get_user($userid, '*', MUST_EXIST); core_user::require_active_user($user); require_capability('moodle/grade:viewall', $systemcontext); } // We need the site course, and course context. $course = get_course(SITEID); $context = context_course::instance($course->id); // Force a regrade if required. grade_regrade_final_grades_if_required($course); // Get the course final grades now. $gpr = new grade_plugin_return(array('type' => 'report', 'plugin' => 'overview', 'courseid' => $course->id, 'userid' => $userid)); $report = new grade_report_overview($userid, $gpr, $context); $coursesgrades = $report->setup_courses_data(true); $grades = array(); foreach ($coursesgrades as $coursegrade) { $gradeinfo = array( 'courseid' => $coursegrade['course']->id, 'grade' => grade_format_gradevalue($coursegrade['finalgrade'], $coursegrade['courseitem'], true), 'rawgrade' => $coursegrade['finalgrade'], ); if (isset($coursegrade['rank'])) { $gradeinfo['rank'] = $coursegrade['rank']; } $grades[] = $gradeinfo; } $result = array(); $result['grades'] = $grades; $result['warnings'] = $warnings; return $result; }
php
public static function get_course_grades($userid = 0) { global $USER; $warnings = array(); // Validate the parameter. $params = self::validate_parameters(self::get_course_grades_parameters(), array( 'userid' => $userid ) ); $userid = $params['userid']; if (empty($userid)) { $userid = $USER->id; } $systemcontext = context_system::instance(); self::validate_context($systemcontext); if ($USER->id != $userid) { // We must check if the current user can view other users grades. $user = core_user::get_user($userid, '*', MUST_EXIST); core_user::require_active_user($user); require_capability('moodle/grade:viewall', $systemcontext); } // We need the site course, and course context. $course = get_course(SITEID); $context = context_course::instance($course->id); // Force a regrade if required. grade_regrade_final_grades_if_required($course); // Get the course final grades now. $gpr = new grade_plugin_return(array('type' => 'report', 'plugin' => 'overview', 'courseid' => $course->id, 'userid' => $userid)); $report = new grade_report_overview($userid, $gpr, $context); $coursesgrades = $report->setup_courses_data(true); $grades = array(); foreach ($coursesgrades as $coursegrade) { $gradeinfo = array( 'courseid' => $coursegrade['course']->id, 'grade' => grade_format_gradevalue($coursegrade['finalgrade'], $coursegrade['courseitem'], true), 'rawgrade' => $coursegrade['finalgrade'], ); if (isset($coursegrade['rank'])) { $gradeinfo['rank'] = $coursegrade['rank']; } $grades[] = $gradeinfo; } $result = array(); $result['grades'] = $grades; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_course_grades", "(", "$", "userid", "=", "0", ")", "{", "global", "$", "USER", ";", "$", "warnings", "=", "array", "(", ")", ";", "// Validate the parameter.", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_course_grades_parameters", "(", ")", ",", "array", "(", "'userid'", "=>", "$", "userid", ")", ")", ";", "$", "userid", "=", "$", "params", "[", "'userid'", "]", ";", "if", "(", "empty", "(", "$", "userid", ")", ")", "{", "$", "userid", "=", "$", "USER", "->", "id", ";", "}", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "$", "USER", "->", "id", "!=", "$", "userid", ")", "{", "// We must check if the current user can view other users grades.", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "userid", ",", "'*'", ",", "MUST_EXIST", ")", ";", "core_user", "::", "require_active_user", "(", "$", "user", ")", ";", "require_capability", "(", "'moodle/grade:viewall'", ",", "$", "systemcontext", ")", ";", "}", "// We need the site course, and course context.", "$", "course", "=", "get_course", "(", "SITEID", ")", ";", "$", "context", "=", "context_course", "::", "instance", "(", "$", "course", "->", "id", ")", ";", "// Force a regrade if required.", "grade_regrade_final_grades_if_required", "(", "$", "course", ")", ";", "// Get the course final grades now.", "$", "gpr", "=", "new", "grade_plugin_return", "(", "array", "(", "'type'", "=>", "'report'", ",", "'plugin'", "=>", "'overview'", ",", "'courseid'", "=>", "$", "course", "->", "id", ",", "'userid'", "=>", "$", "userid", ")", ")", ";", "$", "report", "=", "new", "grade_report_overview", "(", "$", "userid", ",", "$", "gpr", ",", "$", "context", ")", ";", "$", "coursesgrades", "=", "$", "report", "->", "setup_courses_data", "(", "true", ")", ";", "$", "grades", "=", "array", "(", ")", ";", "foreach", "(", "$", "coursesgrades", "as", "$", "coursegrade", ")", "{", "$", "gradeinfo", "=", "array", "(", "'courseid'", "=>", "$", "coursegrade", "[", "'course'", "]", "->", "id", ",", "'grade'", "=>", "grade_format_gradevalue", "(", "$", "coursegrade", "[", "'finalgrade'", "]", ",", "$", "coursegrade", "[", "'courseitem'", "]", ",", "true", ")", ",", "'rawgrade'", "=>", "$", "coursegrade", "[", "'finalgrade'", "]", ",", ")", ";", "if", "(", "isset", "(", "$", "coursegrade", "[", "'rank'", "]", ")", ")", "{", "$", "gradeinfo", "[", "'rank'", "]", "=", "$", "coursegrade", "[", "'rank'", "]", ";", "}", "$", "grades", "[", "]", "=", "$", "gradeinfo", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'grades'", "]", "=", "$", "grades", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Get the given user courses final grades @param int $userid get grades for this user (optional, default current) @return array the grades tables @since Moodle 3.2
[ "Get", "the", "given", "user", "courses", "final", "grades" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/overview/classes/external.php#L64-L120
214,154
moodle/moodle
grade/report/overview/classes/external.php
gradereport_overview_external.get_course_grades_returns
public static function get_course_grades_returns() { return new external_single_structure( array( 'grades' => new external_multiple_structure( new external_single_structure( array( 'courseid' => new external_value(PARAM_INT, 'Course id'), 'grade' => new external_value(PARAM_RAW, 'Grade formatted'), 'rawgrade' => new external_value(PARAM_RAW, 'Raw grade, not formatted'), 'rank' => new external_value(PARAM_INT, 'Your rank in the course', VALUE_OPTIONAL), ) ) ), 'warnings' => new external_warnings() ) ); }
php
public static function get_course_grades_returns() { return new external_single_structure( array( 'grades' => new external_multiple_structure( new external_single_structure( array( 'courseid' => new external_value(PARAM_INT, 'Course id'), 'grade' => new external_value(PARAM_RAW, 'Grade formatted'), 'rawgrade' => new external_value(PARAM_RAW, 'Raw grade, not formatted'), 'rank' => new external_value(PARAM_INT, 'Your rank in the course', VALUE_OPTIONAL), ) ) ), 'warnings' => new external_warnings() ) ); }
[ "public", "static", "function", "get_course_grades_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'grades'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'courseid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Course id'", ")", ",", "'grade'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Grade formatted'", ")", ",", "'rawgrade'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Raw grade, not formatted'", ")", ",", "'rank'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Your rank in the course'", ",", "VALUE_OPTIONAL", ")", ",", ")", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ")", ")", ";", "}" ]
Describes the get_course_grades return value. @return external_single_structure @since Moodle 3.2
[ "Describes", "the", "get_course_grades", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/overview/classes/external.php#L128-L144
214,155
moodle/moodle
lib/behat/form_field/behat_form_select.php
behat_form_select.matches
public function matches($expectedvalue) { $multiple = $this->field->hasAttribute('multiple'); // Same implementation as the parent if it is a single select. if (!$multiple) { $cleanexpectedvalue = trim($expectedvalue); $selectedtext = trim($this->get_selected_options()); $selectedvalue = trim($this->get_selected_options(false)); if ($cleanexpectedvalue != $selectedvalue && $cleanexpectedvalue != $selectedtext) { return false; } return true; } // We are dealing with a multi-select. // Unescape + trim all options and flip it to have the expected values as keys. $expectedoptions = $this->get_unescaped_options($expectedvalue); // Get currently selected option's texts. $texts = $this->get_selected_options(true); $selectedoptiontexts = $this->get_unescaped_options($texts); // Get currently selected option's values. $values = $this->get_selected_options(false); $selectedoptionvalues = $this->get_unescaped_options($values); // We check against string-ordered lists of options. if ($expectedoptions !== $selectedoptiontexts && $expectedoptions !== $selectedoptionvalues) { return false; } return true; }
php
public function matches($expectedvalue) { $multiple = $this->field->hasAttribute('multiple'); // Same implementation as the parent if it is a single select. if (!$multiple) { $cleanexpectedvalue = trim($expectedvalue); $selectedtext = trim($this->get_selected_options()); $selectedvalue = trim($this->get_selected_options(false)); if ($cleanexpectedvalue != $selectedvalue && $cleanexpectedvalue != $selectedtext) { return false; } return true; } // We are dealing with a multi-select. // Unescape + trim all options and flip it to have the expected values as keys. $expectedoptions = $this->get_unescaped_options($expectedvalue); // Get currently selected option's texts. $texts = $this->get_selected_options(true); $selectedoptiontexts = $this->get_unescaped_options($texts); // Get currently selected option's values. $values = $this->get_selected_options(false); $selectedoptionvalues = $this->get_unescaped_options($values); // We check against string-ordered lists of options. if ($expectedoptions !== $selectedoptiontexts && $expectedoptions !== $selectedoptionvalues) { return false; } return true; }
[ "public", "function", "matches", "(", "$", "expectedvalue", ")", "{", "$", "multiple", "=", "$", "this", "->", "field", "->", "hasAttribute", "(", "'multiple'", ")", ";", "// Same implementation as the parent if it is a single select.", "if", "(", "!", "$", "multiple", ")", "{", "$", "cleanexpectedvalue", "=", "trim", "(", "$", "expectedvalue", ")", ";", "$", "selectedtext", "=", "trim", "(", "$", "this", "->", "get_selected_options", "(", ")", ")", ";", "$", "selectedvalue", "=", "trim", "(", "$", "this", "->", "get_selected_options", "(", "false", ")", ")", ";", "if", "(", "$", "cleanexpectedvalue", "!=", "$", "selectedvalue", "&&", "$", "cleanexpectedvalue", "!=", "$", "selectedtext", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}", "// We are dealing with a multi-select.", "// Unescape + trim all options and flip it to have the expected values as keys.", "$", "expectedoptions", "=", "$", "this", "->", "get_unescaped_options", "(", "$", "expectedvalue", ")", ";", "// Get currently selected option's texts.", "$", "texts", "=", "$", "this", "->", "get_selected_options", "(", "true", ")", ";", "$", "selectedoptiontexts", "=", "$", "this", "->", "get_unescaped_options", "(", "$", "texts", ")", ";", "// Get currently selected option's values.", "$", "values", "=", "$", "this", "->", "get_selected_options", "(", "false", ")", ";", "$", "selectedoptionvalues", "=", "$", "this", "->", "get_unescaped_options", "(", "$", "values", ")", ";", "// We check against string-ordered lists of options.", "if", "(", "$", "expectedoptions", "!==", "$", "selectedoptiontexts", "&&", "$", "expectedoptions", "!==", "$", "selectedoptionvalues", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Returns whether the provided argument matches the current value. @param mixed $expectedvalue @return bool
[ "Returns", "whether", "the", "provided", "argument", "matches", "the", "current", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/form_field/behat_form_select.php#L116-L151
214,156
moodle/moodle
lib/behat/form_field/behat_form_select.php
behat_form_select.get_unescaped_options
protected function get_unescaped_options($value) { // Can be multiple comma separated, with valuable commas escaped with backslash. $optionsarray = array_map( 'trim', preg_replace('/\\\,/', ',', preg_split('/(?<!\\\),/', $value) ) ); // Sort by value (keeping the keys is irrelevant). core_collator::asort($optionsarray, SORT_STRING); // Returning it as a string which is easier to match against other values. return implode('|||', $optionsarray); }
php
protected function get_unescaped_options($value) { // Can be multiple comma separated, with valuable commas escaped with backslash. $optionsarray = array_map( 'trim', preg_replace('/\\\,/', ',', preg_split('/(?<!\\\),/', $value) ) ); // Sort by value (keeping the keys is irrelevant). core_collator::asort($optionsarray, SORT_STRING); // Returning it as a string which is easier to match against other values. return implode('|||', $optionsarray); }
[ "protected", "function", "get_unescaped_options", "(", "$", "value", ")", "{", "// Can be multiple comma separated, with valuable commas escaped with backslash.", "$", "optionsarray", "=", "array_map", "(", "'trim'", ",", "preg_replace", "(", "'/\\\\\\,/'", ",", "','", ",", "preg_split", "(", "'/(?<!\\\\\\),/'", ",", "$", "value", ")", ")", ")", ";", "// Sort by value (keeping the keys is irrelevant).", "core_collator", "::", "asort", "(", "$", "optionsarray", ",", "SORT_STRING", ")", ";", "// Returning it as a string which is easier to match against other values.", "return", "implode", "(", "'|||'", ",", "$", "optionsarray", ")", ";", "}" ]
Cleans the list of options and returns it as a string separating options with |||. @param string $value The string containing the escaped options. @return string The options
[ "Cleans", "the", "list", "of", "options", "and", "returns", "it", "as", "a", "string", "separating", "options", "with", "|||", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/form_field/behat_form_select.php#L159-L174
214,157
moodle/moodle
lib/behat/form_field/behat_form_select.php
behat_form_select.get_selected_options
protected function get_selected_options($returntexts = true) { $method = 'getHtml'; if ($returntexts === false) { $method = 'getValue'; } // Is the select multiple? $multiple = $this->field->hasAttribute('multiple'); $selectedoptions = array(); // To accumulate found selected options. // Driver returns the values as an array or as a string depending // on whether multiple options are selected or not. $values = $this->field->getValue(); if (!is_array($values)) { $values = array($values); } // Get all the options in the select and extract their value/text pairs. $alloptions = $this->field->findAll('xpath', '//option'); foreach ($alloptions as $option) { // Is it selected? if (in_array($option->getValue(), $values)) { if ($multiple) { // If the select is multiple, text commas must be encoded. $selectedoptions[] = trim(str_replace(',', '\,', $option->{$method}())); } else { $selectedoptions[] = trim($option->{$method}()); } } } return implode(', ', $selectedoptions); }
php
protected function get_selected_options($returntexts = true) { $method = 'getHtml'; if ($returntexts === false) { $method = 'getValue'; } // Is the select multiple? $multiple = $this->field->hasAttribute('multiple'); $selectedoptions = array(); // To accumulate found selected options. // Driver returns the values as an array or as a string depending // on whether multiple options are selected or not. $values = $this->field->getValue(); if (!is_array($values)) { $values = array($values); } // Get all the options in the select and extract their value/text pairs. $alloptions = $this->field->findAll('xpath', '//option'); foreach ($alloptions as $option) { // Is it selected? if (in_array($option->getValue(), $values)) { if ($multiple) { // If the select is multiple, text commas must be encoded. $selectedoptions[] = trim(str_replace(',', '\,', $option->{$method}())); } else { $selectedoptions[] = trim($option->{$method}()); } } } return implode(', ', $selectedoptions); }
[ "protected", "function", "get_selected_options", "(", "$", "returntexts", "=", "true", ")", "{", "$", "method", "=", "'getHtml'", ";", "if", "(", "$", "returntexts", "===", "false", ")", "{", "$", "method", "=", "'getValue'", ";", "}", "// Is the select multiple?", "$", "multiple", "=", "$", "this", "->", "field", "->", "hasAttribute", "(", "'multiple'", ")", ";", "$", "selectedoptions", "=", "array", "(", ")", ";", "// To accumulate found selected options.", "// Driver returns the values as an array or as a string depending", "// on whether multiple options are selected or not.", "$", "values", "=", "$", "this", "->", "field", "->", "getValue", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "values", ")", ")", "{", "$", "values", "=", "array", "(", "$", "values", ")", ";", "}", "// Get all the options in the select and extract their value/text pairs.", "$", "alloptions", "=", "$", "this", "->", "field", "->", "findAll", "(", "'xpath'", ",", "'//option'", ")", ";", "foreach", "(", "$", "alloptions", "as", "$", "option", ")", "{", "// Is it selected?", "if", "(", "in_array", "(", "$", "option", "->", "getValue", "(", ")", ",", "$", "values", ")", ")", "{", "if", "(", "$", "multiple", ")", "{", "// If the select is multiple, text commas must be encoded.", "$", "selectedoptions", "[", "]", "=", "trim", "(", "str_replace", "(", "','", ",", "'\\,'", ",", "$", "option", "->", "{", "$", "method", "}", "(", ")", ")", ")", ";", "}", "else", "{", "$", "selectedoptions", "[", "]", "=", "trim", "(", "$", "option", "->", "{", "$", "method", "}", "(", ")", ")", ";", "}", "}", "}", "return", "implode", "(", "', '", ",", "$", "selectedoptions", ")", ";", "}" ]
Returns the field selected values. Externalized from the common behat_form_field API method get_value() as matches() needs to check against both values and texts. @param bool $returntexts Returns the options texts or the options values. @return string
[ "Returns", "the", "field", "selected", "values", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/form_field/behat_form_select.php#L185-L219
214,158
moodle/moodle
question/classes/statistics/questions/calculator.php
calculator.initial_steps_walker
protected function initial_steps_walker($step, $stats, $summarks, $positionstat = true, $dovariantalso = true) { $stats->s++; $stats->totalmarks += $step->mark; $stats->markarray[] = $step->mark; if ($positionstat) { $stats->totalothermarks += $summarks[$step->questionusageid] - $step->mark; $stats->othermarksarray[] = $summarks[$step->questionusageid] - $step->mark; } else { $stats->totalothermarks += $summarks[$step->questionusageid]; $stats->othermarksarray[] = $summarks[$step->questionusageid]; } if ($dovariantalso) { $this->initial_steps_walker($step, $stats->variantstats[$step->variant], $summarks, $positionstat, false); } }
php
protected function initial_steps_walker($step, $stats, $summarks, $positionstat = true, $dovariantalso = true) { $stats->s++; $stats->totalmarks += $step->mark; $stats->markarray[] = $step->mark; if ($positionstat) { $stats->totalothermarks += $summarks[$step->questionusageid] - $step->mark; $stats->othermarksarray[] = $summarks[$step->questionusageid] - $step->mark; } else { $stats->totalothermarks += $summarks[$step->questionusageid]; $stats->othermarksarray[] = $summarks[$step->questionusageid]; } if ($dovariantalso) { $this->initial_steps_walker($step, $stats->variantstats[$step->variant], $summarks, $positionstat, false); } }
[ "protected", "function", "initial_steps_walker", "(", "$", "step", ",", "$", "stats", ",", "$", "summarks", ",", "$", "positionstat", "=", "true", ",", "$", "dovariantalso", "=", "true", ")", "{", "$", "stats", "->", "s", "++", ";", "$", "stats", "->", "totalmarks", "+=", "$", "step", "->", "mark", ";", "$", "stats", "->", "markarray", "[", "]", "=", "$", "step", "->", "mark", ";", "if", "(", "$", "positionstat", ")", "{", "$", "stats", "->", "totalothermarks", "+=", "$", "summarks", "[", "$", "step", "->", "questionusageid", "]", "-", "$", "step", "->", "mark", ";", "$", "stats", "->", "othermarksarray", "[", "]", "=", "$", "summarks", "[", "$", "step", "->", "questionusageid", "]", "-", "$", "step", "->", "mark", ";", "}", "else", "{", "$", "stats", "->", "totalothermarks", "+=", "$", "summarks", "[", "$", "step", "->", "questionusageid", "]", ";", "$", "stats", "->", "othermarksarray", "[", "]", "=", "$", "summarks", "[", "$", "step", "->", "questionusageid", "]", ";", "}", "if", "(", "$", "dovariantalso", ")", "{", "$", "this", "->", "initial_steps_walker", "(", "$", "step", ",", "$", "stats", "->", "variantstats", "[", "$", "step", "->", "variant", "]", ",", "$", "summarks", ",", "$", "positionstat", ",", "false", ")", ";", "}", "}" ]
Calculating the stats is a four step process. We loop through all 'last step' data first. Update $stats->totalmarks, $stats->markarray, $stats->totalothermarks and $stats->othermarksarray to include another state. @param object $step the state to add to the statistics. @param calculated $stats the question statistics we are accumulating. @param array $summarks of the sum of marks for each question usage, indexed by question usage id @param bool $positionstat whether this is a statistic of position of question. @param bool $dovariantalso do we also want to do the same calculations for this variant?
[ "Calculating", "the", "stats", "is", "a", "four", "step", "process", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/calculator.php#L322-L338
214,159
moodle/moodle
question/classes/statistics/questions/calculator.php
calculator.initial_question_walker
protected function initial_question_walker($stats) { $stats->markaverage = $stats->totalmarks / $stats->s; if ($stats->maxmark != 0) { $stats->facility = $stats->markaverage / $stats->maxmark; } else { $stats->facility = null; } $stats->othermarkaverage = $stats->totalothermarks / $stats->s; $stats->summarksaverage = $stats->totalsummarks / $stats->s; sort($stats->markarray, SORT_NUMERIC); sort($stats->othermarksarray, SORT_NUMERIC); // Here we have collected enough data to make the decision about which questions have variants whose stats we also want to // calculate. We delete the initialised structures where they are not needed. if (!$stats->get_variants() || !$stats->break_down_by_variant()) { $stats->clear_variants(); } foreach ($stats->get_variants() as $variant) { $this->initial_question_walker($stats->variantstats[$variant]); } }
php
protected function initial_question_walker($stats) { $stats->markaverage = $stats->totalmarks / $stats->s; if ($stats->maxmark != 0) { $stats->facility = $stats->markaverage / $stats->maxmark; } else { $stats->facility = null; } $stats->othermarkaverage = $stats->totalothermarks / $stats->s; $stats->summarksaverage = $stats->totalsummarks / $stats->s; sort($stats->markarray, SORT_NUMERIC); sort($stats->othermarksarray, SORT_NUMERIC); // Here we have collected enough data to make the decision about which questions have variants whose stats we also want to // calculate. We delete the initialised structures where they are not needed. if (!$stats->get_variants() || !$stats->break_down_by_variant()) { $stats->clear_variants(); } foreach ($stats->get_variants() as $variant) { $this->initial_question_walker($stats->variantstats[$variant]); } }
[ "protected", "function", "initial_question_walker", "(", "$", "stats", ")", "{", "$", "stats", "->", "markaverage", "=", "$", "stats", "->", "totalmarks", "/", "$", "stats", "->", "s", ";", "if", "(", "$", "stats", "->", "maxmark", "!=", "0", ")", "{", "$", "stats", "->", "facility", "=", "$", "stats", "->", "markaverage", "/", "$", "stats", "->", "maxmark", ";", "}", "else", "{", "$", "stats", "->", "facility", "=", "null", ";", "}", "$", "stats", "->", "othermarkaverage", "=", "$", "stats", "->", "totalothermarks", "/", "$", "stats", "->", "s", ";", "$", "stats", "->", "summarksaverage", "=", "$", "stats", "->", "totalsummarks", "/", "$", "stats", "->", "s", ";", "sort", "(", "$", "stats", "->", "markarray", ",", "SORT_NUMERIC", ")", ";", "sort", "(", "$", "stats", "->", "othermarksarray", ",", "SORT_NUMERIC", ")", ";", "// Here we have collected enough data to make the decision about which questions have variants whose stats we also want to", "// calculate. We delete the initialised structures where they are not needed.", "if", "(", "!", "$", "stats", "->", "get_variants", "(", ")", "||", "!", "$", "stats", "->", "break_down_by_variant", "(", ")", ")", "{", "$", "stats", "->", "clear_variants", "(", ")", ";", "}", "foreach", "(", "$", "stats", "->", "get_variants", "(", ")", "as", "$", "variant", ")", "{", "$", "this", "->", "initial_question_walker", "(", "$", "stats", "->", "variantstats", "[", "$", "variant", "]", ")", ";", "}", "}" ]
Then loop through all questions for the first time. Perform some computations on the per-question statistics calculations after we have been through all the step data. @param calculated $stats question stats to update.
[ "Then", "loop", "through", "all", "questions", "for", "the", "first", "time", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/calculator.php#L348-L373
214,160
moodle/moodle
question/classes/statistics/questions/calculator.php
calculator.secondary_steps_walker
protected function secondary_steps_walker($step, $stats, $summarks) { $markdifference = $step->mark - $stats->markaverage; if ($stats->subquestion) { $othermarkdifference = $summarks[$step->questionusageid] - $stats->othermarkaverage; } else { $othermarkdifference = $summarks[$step->questionusageid] - $step->mark - $stats->othermarkaverage; } $overallmarkdifference = $summarks[$step->questionusageid] - $stats->summarksaverage; $sortedmarkdifference = array_shift($stats->markarray) - $stats->markaverage; $sortedothermarkdifference = array_shift($stats->othermarksarray) - $stats->othermarkaverage; $stats->markvariancesum += pow($markdifference, 2); $stats->othermarkvariancesum += pow($othermarkdifference, 2); $stats->covariancesum += $markdifference * $othermarkdifference; $stats->covariancemaxsum += $sortedmarkdifference * $sortedothermarkdifference; $stats->covariancewithoverallmarksum += $markdifference * $overallmarkdifference; if (isset($stats->variantstats[$step->variant])) { $this->secondary_steps_walker($step, $stats->variantstats[$step->variant], $summarks); } }
php
protected function secondary_steps_walker($step, $stats, $summarks) { $markdifference = $step->mark - $stats->markaverage; if ($stats->subquestion) { $othermarkdifference = $summarks[$step->questionusageid] - $stats->othermarkaverage; } else { $othermarkdifference = $summarks[$step->questionusageid] - $step->mark - $stats->othermarkaverage; } $overallmarkdifference = $summarks[$step->questionusageid] - $stats->summarksaverage; $sortedmarkdifference = array_shift($stats->markarray) - $stats->markaverage; $sortedothermarkdifference = array_shift($stats->othermarksarray) - $stats->othermarkaverage; $stats->markvariancesum += pow($markdifference, 2); $stats->othermarkvariancesum += pow($othermarkdifference, 2); $stats->covariancesum += $markdifference * $othermarkdifference; $stats->covariancemaxsum += $sortedmarkdifference * $sortedothermarkdifference; $stats->covariancewithoverallmarksum += $markdifference * $overallmarkdifference; if (isset($stats->variantstats[$step->variant])) { $this->secondary_steps_walker($step, $stats->variantstats[$step->variant], $summarks); } }
[ "protected", "function", "secondary_steps_walker", "(", "$", "step", ",", "$", "stats", ",", "$", "summarks", ")", "{", "$", "markdifference", "=", "$", "step", "->", "mark", "-", "$", "stats", "->", "markaverage", ";", "if", "(", "$", "stats", "->", "subquestion", ")", "{", "$", "othermarkdifference", "=", "$", "summarks", "[", "$", "step", "->", "questionusageid", "]", "-", "$", "stats", "->", "othermarkaverage", ";", "}", "else", "{", "$", "othermarkdifference", "=", "$", "summarks", "[", "$", "step", "->", "questionusageid", "]", "-", "$", "step", "->", "mark", "-", "$", "stats", "->", "othermarkaverage", ";", "}", "$", "overallmarkdifference", "=", "$", "summarks", "[", "$", "step", "->", "questionusageid", "]", "-", "$", "stats", "->", "summarksaverage", ";", "$", "sortedmarkdifference", "=", "array_shift", "(", "$", "stats", "->", "markarray", ")", "-", "$", "stats", "->", "markaverage", ";", "$", "sortedothermarkdifference", "=", "array_shift", "(", "$", "stats", "->", "othermarksarray", ")", "-", "$", "stats", "->", "othermarkaverage", ";", "$", "stats", "->", "markvariancesum", "+=", "pow", "(", "$", "markdifference", ",", "2", ")", ";", "$", "stats", "->", "othermarkvariancesum", "+=", "pow", "(", "$", "othermarkdifference", ",", "2", ")", ";", "$", "stats", "->", "covariancesum", "+=", "$", "markdifference", "*", "$", "othermarkdifference", ";", "$", "stats", "->", "covariancemaxsum", "+=", "$", "sortedmarkdifference", "*", "$", "sortedothermarkdifference", ";", "$", "stats", "->", "covariancewithoverallmarksum", "+=", "$", "markdifference", "*", "$", "overallmarkdifference", ";", "if", "(", "isset", "(", "$", "stats", "->", "variantstats", "[", "$", "step", "->", "variant", "]", ")", ")", "{", "$", "this", "->", "secondary_steps_walker", "(", "$", "step", ",", "$", "stats", "->", "variantstats", "[", "$", "step", "->", "variant", "]", ",", "$", "summarks", ")", ";", "}", "}" ]
Loop through all last step data again. Now we know the averages, accumulate the date needed to compute the higher moments of the question scores. @param object $step the state to add to the statistics. @param calculated $stats the question statistics we are accumulating. @param float[] $summarks of the sum of marks for each question usage, indexed by question usage id
[ "Loop", "through", "all", "last", "step", "data", "again", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/calculator.php#L385-L406
214,161
moodle/moodle
question/classes/statistics/questions/calculator.php
calculator.secondary_question_walker
protected function secondary_question_walker($stats) { if ($stats->s > 1) { $stats->markvariance = $stats->markvariancesum / ($stats->s - 1); $stats->othermarkvariance = $stats->othermarkvariancesum / ($stats->s - 1); $stats->covariance = $stats->covariancesum / ($stats->s - 1); $stats->covariancemax = $stats->covariancemaxsum / ($stats->s - 1); $stats->covariancewithoverallmark = $stats->covariancewithoverallmarksum / ($stats->s - 1); $stats->sd = sqrt($stats->markvariancesum / ($stats->s - 1)); if ($stats->covariancewithoverallmark >= 0) { $stats->negcovar = 0; } else { $stats->negcovar = 1; } } else { $stats->markvariance = null; $stats->othermarkvariance = null; $stats->covariance = null; $stats->covariancemax = null; $stats->covariancewithoverallmark = null; $stats->sd = null; $stats->negcovar = 0; } if ($stats->markvariance * $stats->othermarkvariance) { $stats->discriminationindex = 100 * $stats->covariance / sqrt($stats->markvariance * $stats->othermarkvariance); } else { $stats->discriminationindex = null; } if ($stats->covariancemax) { $stats->discriminativeefficiency = 100 * $stats->covariance / $stats->covariancemax; } else { $stats->discriminativeefficiency = null; } foreach ($stats->variantstats as $variantstat) { $this->secondary_question_walker($variantstat); } }
php
protected function secondary_question_walker($stats) { if ($stats->s > 1) { $stats->markvariance = $stats->markvariancesum / ($stats->s - 1); $stats->othermarkvariance = $stats->othermarkvariancesum / ($stats->s - 1); $stats->covariance = $stats->covariancesum / ($stats->s - 1); $stats->covariancemax = $stats->covariancemaxsum / ($stats->s - 1); $stats->covariancewithoverallmark = $stats->covariancewithoverallmarksum / ($stats->s - 1); $stats->sd = sqrt($stats->markvariancesum / ($stats->s - 1)); if ($stats->covariancewithoverallmark >= 0) { $stats->negcovar = 0; } else { $stats->negcovar = 1; } } else { $stats->markvariance = null; $stats->othermarkvariance = null; $stats->covariance = null; $stats->covariancemax = null; $stats->covariancewithoverallmark = null; $stats->sd = null; $stats->negcovar = 0; } if ($stats->markvariance * $stats->othermarkvariance) { $stats->discriminationindex = 100 * $stats->covariance / sqrt($stats->markvariance * $stats->othermarkvariance); } else { $stats->discriminationindex = null; } if ($stats->covariancemax) { $stats->discriminativeefficiency = 100 * $stats->covariance / $stats->covariancemax; } else { $stats->discriminativeefficiency = null; } foreach ($stats->variantstats as $variantstat) { $this->secondary_question_walker($variantstat); } }
[ "protected", "function", "secondary_question_walker", "(", "$", "stats", ")", "{", "if", "(", "$", "stats", "->", "s", ">", "1", ")", "{", "$", "stats", "->", "markvariance", "=", "$", "stats", "->", "markvariancesum", "/", "(", "$", "stats", "->", "s", "-", "1", ")", ";", "$", "stats", "->", "othermarkvariance", "=", "$", "stats", "->", "othermarkvariancesum", "/", "(", "$", "stats", "->", "s", "-", "1", ")", ";", "$", "stats", "->", "covariance", "=", "$", "stats", "->", "covariancesum", "/", "(", "$", "stats", "->", "s", "-", "1", ")", ";", "$", "stats", "->", "covariancemax", "=", "$", "stats", "->", "covariancemaxsum", "/", "(", "$", "stats", "->", "s", "-", "1", ")", ";", "$", "stats", "->", "covariancewithoverallmark", "=", "$", "stats", "->", "covariancewithoverallmarksum", "/", "(", "$", "stats", "->", "s", "-", "1", ")", ";", "$", "stats", "->", "sd", "=", "sqrt", "(", "$", "stats", "->", "markvariancesum", "/", "(", "$", "stats", "->", "s", "-", "1", ")", ")", ";", "if", "(", "$", "stats", "->", "covariancewithoverallmark", ">=", "0", ")", "{", "$", "stats", "->", "negcovar", "=", "0", ";", "}", "else", "{", "$", "stats", "->", "negcovar", "=", "1", ";", "}", "}", "else", "{", "$", "stats", "->", "markvariance", "=", "null", ";", "$", "stats", "->", "othermarkvariance", "=", "null", ";", "$", "stats", "->", "covariance", "=", "null", ";", "$", "stats", "->", "covariancemax", "=", "null", ";", "$", "stats", "->", "covariancewithoverallmark", "=", "null", ";", "$", "stats", "->", "sd", "=", "null", ";", "$", "stats", "->", "negcovar", "=", "0", ";", "}", "if", "(", "$", "stats", "->", "markvariance", "*", "$", "stats", "->", "othermarkvariance", ")", "{", "$", "stats", "->", "discriminationindex", "=", "100", "*", "$", "stats", "->", "covariance", "/", "sqrt", "(", "$", "stats", "->", "markvariance", "*", "$", "stats", "->", "othermarkvariance", ")", ";", "}", "else", "{", "$", "stats", "->", "discriminationindex", "=", "null", ";", "}", "if", "(", "$", "stats", "->", "covariancemax", ")", "{", "$", "stats", "->", "discriminativeefficiency", "=", "100", "*", "$", "stats", "->", "covariance", "/", "$", "stats", "->", "covariancemax", ";", "}", "else", "{", "$", "stats", "->", "discriminativeefficiency", "=", "null", ";", "}", "foreach", "(", "$", "stats", "->", "variantstats", "as", "$", "variantstat", ")", "{", "$", "this", "->", "secondary_question_walker", "(", "$", "variantstat", ")", ";", "}", "}" ]
And finally loop through all the questions again. Perform more per-question statistics calculations. @param calculated $stats question stats to update.
[ "And", "finally", "loop", "through", "all", "the", "questions", "again", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/calculator.php#L415-L457
214,162
moodle/moodle
lib/classes/session/database.php
database.handler_close
public function handler_close() { if ($this->recordid) { try { $this->database->release_session_lock($this->recordid); } catch (\Exception $ex) { // Ignore any problems. } } $this->recordid = null; $this->lasthash = null; return true; }
php
public function handler_close() { if ($this->recordid) { try { $this->database->release_session_lock($this->recordid); } catch (\Exception $ex) { // Ignore any problems. } } $this->recordid = null; $this->lasthash = null; return true; }
[ "public", "function", "handler_close", "(", ")", "{", "if", "(", "$", "this", "->", "recordid", ")", "{", "try", "{", "$", "this", "->", "database", "->", "release_session_lock", "(", "$", "this", "->", "recordid", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "// Ignore any problems.", "}", "}", "$", "this", "->", "recordid", "=", "null", ";", "$", "this", "->", "lasthash", "=", "null", ";", "return", "true", ";", "}" ]
Close session handler. {@see http://php.net/manual/en/function.session-set-save-handler.php} @return bool success
[ "Close", "session", "handler", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/session/database.php#L136-L147
214,163
moodle/moodle
lib/classes/session/database.php
database.handler_read
public function handler_read($sid) { try { if (!$record = $this->database->get_record('sessions', array('sid'=>$sid), 'id')) { // Let's cheat and skip locking if this is the first access, // do not create the record here, let the manager do it after session init. $this->failed = false; $this->recordid = null; $this->lasthash = sha1(''); return ''; } if ($this->recordid and $this->recordid != $record->id) { error_log('Second session read with different record id detected, cannot read session'); $this->failed = true; $this->recordid = null; return ''; } if (!$this->recordid) { // Lock session if exists and not already locked. $this->database->get_session_lock($record->id, $this->acquiretimeout); $this->recordid = $record->id; } } catch (\dml_sessionwait_exception $ex) { // This is a fatal error, better inform users. // It should not happen very often - all pages that need long time to execute // should close session immediately after access control checks. error_log('Cannot obtain session lock for sid: '.$sid); $this->failed = true; throw $ex; } catch (\Exception $ex) { // Do not rethrow exceptions here, this should not happen. error_log('Unknown exception when starting database session : '.$sid.' - '.$ex->getMessage()); $this->failed = true; $this->recordid = null; return ''; } // Finally read the full session data because we know we have the lock now. if (!$record = $this->database->get_record('sessions', array('id'=>$record->id), 'id, sessdata')) { // Ignore - something else just deleted the session record. $this->failed = true; $this->recordid = null; return ''; } $this->failed = false; if (is_null($record->sessdata)) { $data = ''; $this->lasthash = sha1(''); } else { $data = base64_decode($record->sessdata); $this->lasthash = sha1($record->sessdata); } return $data; }
php
public function handler_read($sid) { try { if (!$record = $this->database->get_record('sessions', array('sid'=>$sid), 'id')) { // Let's cheat and skip locking if this is the first access, // do not create the record here, let the manager do it after session init. $this->failed = false; $this->recordid = null; $this->lasthash = sha1(''); return ''; } if ($this->recordid and $this->recordid != $record->id) { error_log('Second session read with different record id detected, cannot read session'); $this->failed = true; $this->recordid = null; return ''; } if (!$this->recordid) { // Lock session if exists and not already locked. $this->database->get_session_lock($record->id, $this->acquiretimeout); $this->recordid = $record->id; } } catch (\dml_sessionwait_exception $ex) { // This is a fatal error, better inform users. // It should not happen very often - all pages that need long time to execute // should close session immediately after access control checks. error_log('Cannot obtain session lock for sid: '.$sid); $this->failed = true; throw $ex; } catch (\Exception $ex) { // Do not rethrow exceptions here, this should not happen. error_log('Unknown exception when starting database session : '.$sid.' - '.$ex->getMessage()); $this->failed = true; $this->recordid = null; return ''; } // Finally read the full session data because we know we have the lock now. if (!$record = $this->database->get_record('sessions', array('id'=>$record->id), 'id, sessdata')) { // Ignore - something else just deleted the session record. $this->failed = true; $this->recordid = null; return ''; } $this->failed = false; if (is_null($record->sessdata)) { $data = ''; $this->lasthash = sha1(''); } else { $data = base64_decode($record->sessdata); $this->lasthash = sha1($record->sessdata); } return $data; }
[ "public", "function", "handler_read", "(", "$", "sid", ")", "{", "try", "{", "if", "(", "!", "$", "record", "=", "$", "this", "->", "database", "->", "get_record", "(", "'sessions'", ",", "array", "(", "'sid'", "=>", "$", "sid", ")", ",", "'id'", ")", ")", "{", "// Let's cheat and skip locking if this is the first access,", "// do not create the record here, let the manager do it after session init.", "$", "this", "->", "failed", "=", "false", ";", "$", "this", "->", "recordid", "=", "null", ";", "$", "this", "->", "lasthash", "=", "sha1", "(", "''", ")", ";", "return", "''", ";", "}", "if", "(", "$", "this", "->", "recordid", "and", "$", "this", "->", "recordid", "!=", "$", "record", "->", "id", ")", "{", "error_log", "(", "'Second session read with different record id detected, cannot read session'", ")", ";", "$", "this", "->", "failed", "=", "true", ";", "$", "this", "->", "recordid", "=", "null", ";", "return", "''", ";", "}", "if", "(", "!", "$", "this", "->", "recordid", ")", "{", "// Lock session if exists and not already locked.", "$", "this", "->", "database", "->", "get_session_lock", "(", "$", "record", "->", "id", ",", "$", "this", "->", "acquiretimeout", ")", ";", "$", "this", "->", "recordid", "=", "$", "record", "->", "id", ";", "}", "}", "catch", "(", "\\", "dml_sessionwait_exception", "$", "ex", ")", "{", "// This is a fatal error, better inform users.", "// It should not happen very often - all pages that need long time to execute", "// should close session immediately after access control checks.", "error_log", "(", "'Cannot obtain session lock for sid: '", ".", "$", "sid", ")", ";", "$", "this", "->", "failed", "=", "true", ";", "throw", "$", "ex", ";", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "// Do not rethrow exceptions here, this should not happen.", "error_log", "(", "'Unknown exception when starting database session : '", ".", "$", "sid", ".", "' - '", ".", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "$", "this", "->", "failed", "=", "true", ";", "$", "this", "->", "recordid", "=", "null", ";", "return", "''", ";", "}", "// Finally read the full session data because we know we have the lock now.", "if", "(", "!", "$", "record", "=", "$", "this", "->", "database", "->", "get_record", "(", "'sessions'", ",", "array", "(", "'id'", "=>", "$", "record", "->", "id", ")", ",", "'id, sessdata'", ")", ")", "{", "// Ignore - something else just deleted the session record.", "$", "this", "->", "failed", "=", "true", ";", "$", "this", "->", "recordid", "=", "null", ";", "return", "''", ";", "}", "$", "this", "->", "failed", "=", "false", ";", "if", "(", "is_null", "(", "$", "record", "->", "sessdata", ")", ")", "{", "$", "data", "=", "''", ";", "$", "this", "->", "lasthash", "=", "sha1", "(", "''", ")", ";", "}", "else", "{", "$", "data", "=", "base64_decode", "(", "$", "record", "->", "sessdata", ")", ";", "$", "this", "->", "lasthash", "=", "sha1", "(", "$", "record", "->", "sessdata", ")", ";", "}", "return", "$", "data", ";", "}" ]
Read session handler. {@see http://php.net/manual/en/function.session-set-save-handler.php} @param string $sid @return string
[ "Read", "session", "handler", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/session/database.php#L157-L212
214,164
moodle/moodle
lib/classes/session/database.php
database.handler_write
public function handler_write($sid, $session_data) { if ($this->failed) { // Do not write anything back - we failed to start the session properly. return false; } $sessdata = base64_encode($session_data); // There might be some binary mess :-( $hash = sha1($sessdata); if ($hash === $this->lasthash) { return true; } try { if ($this->recordid) { $this->database->set_field('sessions', 'sessdata', $sessdata, array('id'=>$this->recordid)); } else { // This happens in the first request when session record was just created in manager. $this->database->set_field('sessions', 'sessdata', $sessdata, array('sid'=>$sid)); } } catch (\Exception $ex) { // Do not rethrow exceptions here, this should not happen. error_log('Unknown exception when writing database session data : '.$sid.' - '.$ex->getMessage()); } return true; }
php
public function handler_write($sid, $session_data) { if ($this->failed) { // Do not write anything back - we failed to start the session properly. return false; } $sessdata = base64_encode($session_data); // There might be some binary mess :-( $hash = sha1($sessdata); if ($hash === $this->lasthash) { return true; } try { if ($this->recordid) { $this->database->set_field('sessions', 'sessdata', $sessdata, array('id'=>$this->recordid)); } else { // This happens in the first request when session record was just created in manager. $this->database->set_field('sessions', 'sessdata', $sessdata, array('sid'=>$sid)); } } catch (\Exception $ex) { // Do not rethrow exceptions here, this should not happen. error_log('Unknown exception when writing database session data : '.$sid.' - '.$ex->getMessage()); } return true; }
[ "public", "function", "handler_write", "(", "$", "sid", ",", "$", "session_data", ")", "{", "if", "(", "$", "this", "->", "failed", ")", "{", "// Do not write anything back - we failed to start the session properly.", "return", "false", ";", "}", "$", "sessdata", "=", "base64_encode", "(", "$", "session_data", ")", ";", "// There might be some binary mess :-(", "$", "hash", "=", "sha1", "(", "$", "sessdata", ")", ";", "if", "(", "$", "hash", "===", "$", "this", "->", "lasthash", ")", "{", "return", "true", ";", "}", "try", "{", "if", "(", "$", "this", "->", "recordid", ")", "{", "$", "this", "->", "database", "->", "set_field", "(", "'sessions'", ",", "'sessdata'", ",", "$", "sessdata", ",", "array", "(", "'id'", "=>", "$", "this", "->", "recordid", ")", ")", ";", "}", "else", "{", "// This happens in the first request when session record was just created in manager.", "$", "this", "->", "database", "->", "set_field", "(", "'sessions'", ",", "'sessdata'", ",", "$", "sessdata", ",", "array", "(", "'sid'", "=>", "$", "sid", ")", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "// Do not rethrow exceptions here, this should not happen.", "error_log", "(", "'Unknown exception when writing database session data : '", ".", "$", "sid", ".", "' - '", ".", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "return", "true", ";", "}" ]
Write session handler. {@see http://php.net/manual/en/function.session-set-save-handler.php} NOTE: Do not write to output or throw any exceptions! Hopefully the next page is going to display nice error or it recovers... @param string $sid @param string $session_data @return bool success
[ "Write", "session", "handler", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/session/database.php#L226-L252
214,165
moodle/moodle
lib/classes/session/database.php
database.handler_destroy
public function handler_destroy($sid) { if (!$session = $this->database->get_record('sessions', array('sid'=>$sid), 'id, sid')) { if ($sid == session_id()) { $this->recordid = null; $this->lasthash = null; } return true; } if ($this->recordid and $session->id == $this->recordid) { try { $this->database->release_session_lock($this->recordid); } catch (\Exception $ex) { // Ignore problems. } $this->recordid = null; $this->lasthash = null; } $this->database->delete_records('sessions', array('id'=>$session->id)); return true; }
php
public function handler_destroy($sid) { if (!$session = $this->database->get_record('sessions', array('sid'=>$sid), 'id, sid')) { if ($sid == session_id()) { $this->recordid = null; $this->lasthash = null; } return true; } if ($this->recordid and $session->id == $this->recordid) { try { $this->database->release_session_lock($this->recordid); } catch (\Exception $ex) { // Ignore problems. } $this->recordid = null; $this->lasthash = null; } $this->database->delete_records('sessions', array('id'=>$session->id)); return true; }
[ "public", "function", "handler_destroy", "(", "$", "sid", ")", "{", "if", "(", "!", "$", "session", "=", "$", "this", "->", "database", "->", "get_record", "(", "'sessions'", ",", "array", "(", "'sid'", "=>", "$", "sid", ")", ",", "'id, sid'", ")", ")", "{", "if", "(", "$", "sid", "==", "session_id", "(", ")", ")", "{", "$", "this", "->", "recordid", "=", "null", ";", "$", "this", "->", "lasthash", "=", "null", ";", "}", "return", "true", ";", "}", "if", "(", "$", "this", "->", "recordid", "and", "$", "session", "->", "id", "==", "$", "this", "->", "recordid", ")", "{", "try", "{", "$", "this", "->", "database", "->", "release_session_lock", "(", "$", "this", "->", "recordid", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "// Ignore problems.", "}", "$", "this", "->", "recordid", "=", "null", ";", "$", "this", "->", "lasthash", "=", "null", ";", "}", "$", "this", "->", "database", "->", "delete_records", "(", "'sessions'", ",", "array", "(", "'id'", "=>", "$", "session", "->", "id", ")", ")", ";", "return", "true", ";", "}" ]
Destroy session handler. {@see http://php.net/manual/en/function.session-set-save-handler.php} @param string $sid @return bool success
[ "Destroy", "session", "handler", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/session/database.php#L262-L284
214,166
moodle/moodle
lib/classes/session/database.php
database.handler_gc
public function handler_gc($ignored_maxlifetime) { // This should do something only if cron is not running properly... if (!$stalelifetime = ini_get('session.gc_maxlifetime')) { return true; } $params = array('purgebefore' => (time() - $stalelifetime)); $this->database->delete_records_select('sessions', 'userid = 0 AND timemodified < :purgebefore', $params); return true; }
php
public function handler_gc($ignored_maxlifetime) { // This should do something only if cron is not running properly... if (!$stalelifetime = ini_get('session.gc_maxlifetime')) { return true; } $params = array('purgebefore' => (time() - $stalelifetime)); $this->database->delete_records_select('sessions', 'userid = 0 AND timemodified < :purgebefore', $params); return true; }
[ "public", "function", "handler_gc", "(", "$", "ignored_maxlifetime", ")", "{", "// This should do something only if cron is not running properly...", "if", "(", "!", "$", "stalelifetime", "=", "ini_get", "(", "'session.gc_maxlifetime'", ")", ")", "{", "return", "true", ";", "}", "$", "params", "=", "array", "(", "'purgebefore'", "=>", "(", "time", "(", ")", "-", "$", "stalelifetime", ")", ")", ";", "$", "this", "->", "database", "->", "delete_records_select", "(", "'sessions'", ",", "'userid = 0 AND timemodified < :purgebefore'", ",", "$", "params", ")", ";", "return", "true", ";", "}" ]
GC session handler. {@see http://php.net/manual/en/function.session-set-save-handler.php} @param int $ignored_maxlifetime moodle uses special timeout rules @return bool success
[ "GC", "session", "handler", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/session/database.php#L294-L302
214,167
moodle/moodle
mod/data/field/checkbox/field.class.php
data_field_checkbox.notemptyfield
function notemptyfield($value, $name) { $found = false; foreach ($value as $checkboxitem) { if (strval($checkboxitem) !== '') { $found = true; break; } } return $found; }
php
function notemptyfield($value, $name) { $found = false; foreach ($value as $checkboxitem) { if (strval($checkboxitem) !== '') { $found = true; break; } } return $found; }
[ "function", "notemptyfield", "(", "$", "value", ",", "$", "name", ")", "{", "$", "found", "=", "false", ";", "foreach", "(", "$", "value", "as", "$", "checkboxitem", ")", "{", "if", "(", "strval", "(", "$", "checkboxitem", ")", "!==", "''", ")", "{", "$", "found", "=", "true", ";", "break", ";", "}", "}", "return", "$", "found", ";", "}" ]
Check whether any boxes in the checkbox where checked. @param mixed $value The submitted values @param mixed $name @return bool
[ "Check", "whether", "any", "boxes", "in", "the", "checkbox", "where", "checked", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/field/checkbox/field.class.php#L248-L257
214,168
moodle/moodle
mod/data/field/checkbox/field.class.php
data_field_checkbox.get_content_value
public static function get_content_value($content) { $arr = explode('##', $content->content); $strvalue = ''; foreach ($arr as $a) { $strvalue .= $a . ' '; } return trim($strvalue, "\r\n "); }
php
public static function get_content_value($content) { $arr = explode('##', $content->content); $strvalue = ''; foreach ($arr as $a) { $strvalue .= $a . ' '; } return trim($strvalue, "\r\n "); }
[ "public", "static", "function", "get_content_value", "(", "$", "content", ")", "{", "$", "arr", "=", "explode", "(", "'##'", ",", "$", "content", "->", "content", ")", ";", "$", "strvalue", "=", "''", ";", "foreach", "(", "$", "arr", "as", "$", "a", ")", "{", "$", "strvalue", ".=", "$", "a", ".", "' '", ";", "}", "return", "trim", "(", "$", "strvalue", ",", "\"\\r\\n \"", ")", ";", "}" ]
Returns the presentable string value for a field content. The returned string should be plain text. @param stdClass $content @return string
[ "Returns", "the", "presentable", "string", "value", "for", "a", "field", "content", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/field/checkbox/field.class.php#L267-L276
214,169
moodle/moodle
lib/ltiprovider/src/ToolProvider/OAuthDataStore.php
OAuthDataStore.lookup_consumer
function lookup_consumer($consumerKey) { return new OAuth\OAuthConsumer($this->toolProvider->consumer->getKey(), $this->toolProvider->consumer->secret); }
php
function lookup_consumer($consumerKey) { return new OAuth\OAuthConsumer($this->toolProvider->consumer->getKey(), $this->toolProvider->consumer->secret); }
[ "function", "lookup_consumer", "(", "$", "consumerKey", ")", "{", "return", "new", "OAuth", "\\", "OAuthConsumer", "(", "$", "this", "->", "toolProvider", "->", "consumer", "->", "getKey", "(", ")", ",", "$", "this", "->", "toolProvider", "->", "consumer", "->", "secret", ")", ";", "}" ]
Create an OAuthConsumer object for the tool consumer. @param string $consumerKey Consumer key value @return OAuthConsumer OAuthConsumer object
[ "Create", "an", "OAuthConsumer", "object", "for", "the", "tool", "consumer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/OAuthDataStore.php#L45-L51
214,170
moodle/moodle
question/classes/statistics/responses/analysis_for_question.php
analysis_for_question.initialise_stats_for_variant
protected function initialise_stats_for_variant($variantno) { $this->subparts[$variantno] = array(); foreach ($this->possibleresponses as $subpartid => $classes) { $this->subparts[$variantno][$subpartid] = new analysis_for_subpart($classes); } }
php
protected function initialise_stats_for_variant($variantno) { $this->subparts[$variantno] = array(); foreach ($this->possibleresponses as $subpartid => $classes) { $this->subparts[$variantno][$subpartid] = new analysis_for_subpart($classes); } }
[ "protected", "function", "initialise_stats_for_variant", "(", "$", "variantno", ")", "{", "$", "this", "->", "subparts", "[", "$", "variantno", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "possibleresponses", "as", "$", "subpartid", "=>", "$", "classes", ")", "{", "$", "this", "->", "subparts", "[", "$", "variantno", "]", "[", "$", "subpartid", "]", "=", "new", "analysis_for_subpart", "(", "$", "classes", ")", ";", "}", "}" ]
Initialise data structure for response analysis of one variant. @param int $variantno
[ "Initialise", "data", "structure", "for", "response", "analysis", "of", "one", "variant", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/responses/analysis_for_question.php#L91-L96
214,171
moodle/moodle
lib/scssphp/Formatter.php
Formatter.blockLines
protected function blockLines(OutputBlock $block) { $inner = $this->indentStr(); $glue = $this->break . $inner; $this->write($inner . implode($glue, $block->lines)); if (! empty($block->children)) { $this->write($this->break); } }
php
protected function blockLines(OutputBlock $block) { $inner = $this->indentStr(); $glue = $this->break . $inner; $this->write($inner . implode($glue, $block->lines)); if (! empty($block->children)) { $this->write($this->break); } }
[ "protected", "function", "blockLines", "(", "OutputBlock", "$", "block", ")", "{", "$", "inner", "=", "$", "this", "->", "indentStr", "(", ")", ";", "$", "glue", "=", "$", "this", "->", "break", ".", "$", "inner", ";", "$", "this", "->", "write", "(", "$", "inner", ".", "implode", "(", "$", "glue", ",", "$", "block", "->", "lines", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "block", "->", "children", ")", ")", "{", "$", "this", "->", "write", "(", "$", "this", "->", "break", ")", ";", "}", "}" ]
Output lines inside a block @param \Leafo\ScssPhp\Formatter\OutputBlock $block
[ "Output", "lines", "inside", "a", "block" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Formatter.php#L141-L152
214,172
moodle/moodle
lib/scssphp/Formatter.php
Formatter.blockSelectors
protected function blockSelectors(OutputBlock $block) { $inner = $this->indentStr(); $this->write($inner . implode($this->tagSeparator, $block->selectors) . $this->open . $this->break); }
php
protected function blockSelectors(OutputBlock $block) { $inner = $this->indentStr(); $this->write($inner . implode($this->tagSeparator, $block->selectors) . $this->open . $this->break); }
[ "protected", "function", "blockSelectors", "(", "OutputBlock", "$", "block", ")", "{", "$", "inner", "=", "$", "this", "->", "indentStr", "(", ")", ";", "$", "this", "->", "write", "(", "$", "inner", ".", "implode", "(", "$", "this", "->", "tagSeparator", ",", "$", "block", "->", "selectors", ")", ".", "$", "this", "->", "open", ".", "$", "this", "->", "break", ")", ";", "}" ]
Output block selectors @param \Leafo\ScssPhp\Formatter\OutputBlock $block
[ "Output", "block", "selectors" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Formatter.php#L159-L166
214,173
moodle/moodle
lib/scssphp/Formatter.php
Formatter.blockChildren
protected function blockChildren(OutputBlock $block) { foreach ($block->children as $child) { $this->block($child); } }
php
protected function blockChildren(OutputBlock $block) { foreach ($block->children as $child) { $this->block($child); } }
[ "protected", "function", "blockChildren", "(", "OutputBlock", "$", "block", ")", "{", "foreach", "(", "$", "block", "->", "children", "as", "$", "child", ")", "{", "$", "this", "->", "block", "(", "$", "child", ")", ";", "}", "}" ]
Output block children @param \Leafo\ScssPhp\Formatter\OutputBlock $block
[ "Output", "block", "children" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Formatter.php#L173-L178
214,174
moodle/moodle
lib/scssphp/Formatter.php
Formatter.block
protected function block(OutputBlock $block) { if (empty($block->lines) && empty($block->children)) { return; } $this->currentBlock = $block; $pre = $this->indentStr(); if (! empty($block->selectors)) { $this->blockSelectors($block); $this->indentLevel++; } if (! empty($block->lines)) { $this->blockLines($block); } if (! empty($block->children)) { $this->blockChildren($block); } if (! empty($block->selectors)) { $this->indentLevel--; if (empty($block->children)) { $this->write($this->break); } $this->write($pre . $this->close . $this->break); } }
php
protected function block(OutputBlock $block) { if (empty($block->lines) && empty($block->children)) { return; } $this->currentBlock = $block; $pre = $this->indentStr(); if (! empty($block->selectors)) { $this->blockSelectors($block); $this->indentLevel++; } if (! empty($block->lines)) { $this->blockLines($block); } if (! empty($block->children)) { $this->blockChildren($block); } if (! empty($block->selectors)) { $this->indentLevel--; if (empty($block->children)) { $this->write($this->break); } $this->write($pre . $this->close . $this->break); } }
[ "protected", "function", "block", "(", "OutputBlock", "$", "block", ")", "{", "if", "(", "empty", "(", "$", "block", "->", "lines", ")", "&&", "empty", "(", "$", "block", "->", "children", ")", ")", "{", "return", ";", "}", "$", "this", "->", "currentBlock", "=", "$", "block", ";", "$", "pre", "=", "$", "this", "->", "indentStr", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "block", "->", "selectors", ")", ")", "{", "$", "this", "->", "blockSelectors", "(", "$", "block", ")", ";", "$", "this", "->", "indentLevel", "++", ";", "}", "if", "(", "!", "empty", "(", "$", "block", "->", "lines", ")", ")", "{", "$", "this", "->", "blockLines", "(", "$", "block", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "block", "->", "children", ")", ")", "{", "$", "this", "->", "blockChildren", "(", "$", "block", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "block", "->", "selectors", ")", ")", "{", "$", "this", "->", "indentLevel", "--", ";", "if", "(", "empty", "(", "$", "block", "->", "children", ")", ")", "{", "$", "this", "->", "write", "(", "$", "this", "->", "break", ")", ";", "}", "$", "this", "->", "write", "(", "$", "pre", ".", "$", "this", "->", "close", ".", "$", "this", "->", "break", ")", ";", "}", "}" ]
Output non-empty block @param \Leafo\ScssPhp\Formatter\OutputBlock $block
[ "Output", "non", "-", "empty", "block" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Formatter.php#L185-L218
214,175
moodle/moodle
lib/scssphp/Formatter.php
Formatter.format
public function format(OutputBlock $block, SourceMapGenerator $sourceMapGenerator = null) { $this->sourceMapGenerator = null; if ($sourceMapGenerator) { $this->currentLine = 1; $this->currentColumn = 0; $this->sourceMapGenerator = $sourceMapGenerator; } ob_start(); $this->block($block); $out = ob_get_clean(); return $out; }
php
public function format(OutputBlock $block, SourceMapGenerator $sourceMapGenerator = null) { $this->sourceMapGenerator = null; if ($sourceMapGenerator) { $this->currentLine = 1; $this->currentColumn = 0; $this->sourceMapGenerator = $sourceMapGenerator; } ob_start(); $this->block($block); $out = ob_get_clean(); return $out; }
[ "public", "function", "format", "(", "OutputBlock", "$", "block", ",", "SourceMapGenerator", "$", "sourceMapGenerator", "=", "null", ")", "{", "$", "this", "->", "sourceMapGenerator", "=", "null", ";", "if", "(", "$", "sourceMapGenerator", ")", "{", "$", "this", "->", "currentLine", "=", "1", ";", "$", "this", "->", "currentColumn", "=", "0", ";", "$", "this", "->", "sourceMapGenerator", "=", "$", "sourceMapGenerator", ";", "}", "ob_start", "(", ")", ";", "$", "this", "->", "block", "(", "$", "block", ")", ";", "$", "out", "=", "ob_get_clean", "(", ")", ";", "return", "$", "out", ";", "}" ]
Entry point to formatting a block @api @param \Leafo\ScssPhp\Formatter\OutputBlock $block An abstract syntax tree @param \Leafo\ScssPhp\SourceMap\SourceMapGenerator|null $sourceMapGenerator Optional source map generator @return string
[ "Entry", "point", "to", "formatting", "a", "block" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Formatter.php#L230-L247
214,176
moodle/moodle
mod/forum/classes/local/entities/discussion.php
discussion.toggle_locked_state
public function toggle_locked_state(int $timestamp) { // Check the current value against what we want the value to be i.e. '$timestamp'. $this->timelocked = ($this->timelocked && $timestamp ? $this->timelocked : $timestamp); }
php
public function toggle_locked_state(int $timestamp) { // Check the current value against what we want the value to be i.e. '$timestamp'. $this->timelocked = ($this->timelocked && $timestamp ? $this->timelocked : $timestamp); }
[ "public", "function", "toggle_locked_state", "(", "int", "$", "timestamp", ")", "{", "// Check the current value against what we want the value to be i.e. '$timestamp'.", "$", "this", "->", "timelocked", "=", "(", "$", "this", "->", "timelocked", "&&", "$", "timestamp", "?", "$", "this", "->", "timelocked", ":", "$", "timestamp", ")", ";", "}" ]
Set the locked timestamp @param int $timestamp The value we want to store into 'locked'
[ "Set", "the", "locked", "timestamp" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/entities/discussion.php#L259-L262
214,177
moodle/moodle
mod/forum/classes/local/entities/discussion.php
discussion.set_pinned
public function set_pinned(int $targetstate): void { if ($targetstate != $this->pinned) { $this->pinned = $targetstate; } }
php
public function set_pinned(int $targetstate): void { if ($targetstate != $this->pinned) { $this->pinned = $targetstate; } }
[ "public", "function", "set_pinned", "(", "int", "$", "targetstate", ")", ":", "void", "{", "if", "(", "$", "targetstate", "!=", "$", "this", "->", "pinned", ")", "{", "$", "this", "->", "pinned", "=", "$", "targetstate", ";", "}", "}" ]
Set the pinned value for this entity @param int $targetstate The state to change the pin to @return bool
[ "Set", "the", "pinned", "value", "for", "this", "entity" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/entities/discussion.php#L309-L313
214,178
moodle/moodle
mod/forum/classes/local/entities/discussion.php
discussion.is_timed_discussion
public function is_timed_discussion() : bool { global $CFG; return !empty($CFG->forum_enabletimedposts) && ($this->get_time_start() || $this->get_time_end()); }
php
public function is_timed_discussion() : bool { global $CFG; return !empty($CFG->forum_enabletimedposts) && ($this->get_time_start() || $this->get_time_end()); }
[ "public", "function", "is_timed_discussion", "(", ")", ":", "bool", "{", "global", "$", "CFG", ";", "return", "!", "empty", "(", "$", "CFG", "->", "forum_enabletimedposts", ")", "&&", "(", "$", "this", "->", "get_time_start", "(", ")", "||", "$", "this", "->", "get_time_end", "(", ")", ")", ";", "}" ]
Check if the discussion is timed. @return bool
[ "Check", "if", "the", "discussion", "is", "timed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/entities/discussion.php#L320-L325
214,179
moodle/moodle
mod/forum/classes/local/container.php
container.get_renderer_factory
public static function get_renderer_factory() : renderer_factory { global $PAGE; return new renderer_factory( self::get_legacy_data_mapper_factory(), self::get_exporter_factory(), self::get_vault_factory(), self::get_manager_factory(), self::get_entity_factory(), self::get_builder_factory(), self::get_url_factory(), $PAGE ); }
php
public static function get_renderer_factory() : renderer_factory { global $PAGE; return new renderer_factory( self::get_legacy_data_mapper_factory(), self::get_exporter_factory(), self::get_vault_factory(), self::get_manager_factory(), self::get_entity_factory(), self::get_builder_factory(), self::get_url_factory(), $PAGE ); }
[ "public", "static", "function", "get_renderer_factory", "(", ")", ":", "renderer_factory", "{", "global", "$", "PAGE", ";", "return", "new", "renderer_factory", "(", "self", "::", "get_legacy_data_mapper_factory", "(", ")", ",", "self", "::", "get_exporter_factory", "(", ")", ",", "self", "::", "get_vault_factory", "(", ")", ",", "self", "::", "get_manager_factory", "(", ")", ",", "self", "::", "get_entity_factory", "(", ")", ",", "self", "::", "get_builder_factory", "(", ")", ",", "self", "::", "get_url_factory", "(", ")", ",", "$", "PAGE", ")", ";", "}" ]
Create the renderer factory. @return renderer_factory
[ "Create", "the", "renderer", "factory", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/container.php#L53-L66
214,180
moodle/moodle
mod/forum/classes/local/container.php
container.get_exporter_factory
public static function get_exporter_factory() : exporter_factory { return new exporter_factory( self::get_legacy_data_mapper_factory(), self::get_manager_factory(), self::get_url_factory(), self::get_vault_factory() ); }
php
public static function get_exporter_factory() : exporter_factory { return new exporter_factory( self::get_legacy_data_mapper_factory(), self::get_manager_factory(), self::get_url_factory(), self::get_vault_factory() ); }
[ "public", "static", "function", "get_exporter_factory", "(", ")", ":", "exporter_factory", "{", "return", "new", "exporter_factory", "(", "self", "::", "get_legacy_data_mapper_factory", "(", ")", ",", "self", "::", "get_manager_factory", "(", ")", ",", "self", "::", "get_url_factory", "(", ")", ",", "self", "::", "get_vault_factory", "(", ")", ")", ";", "}" ]
Create the exporter factory. @return exporter_factory
[ "Create", "the", "exporter", "factory", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/container.php#L82-L89
214,181
moodle/moodle
mod/forum/classes/local/container.php
container.get_vault_factory
public static function get_vault_factory() : vault_factory { global $DB; return new vault_factory( $DB, self::get_entity_factory(), get_file_storage(), self::get_legacy_data_mapper_factory() ); }
php
public static function get_vault_factory() : vault_factory { global $DB; return new vault_factory( $DB, self::get_entity_factory(), get_file_storage(), self::get_legacy_data_mapper_factory() ); }
[ "public", "static", "function", "get_vault_factory", "(", ")", ":", "vault_factory", "{", "global", "$", "DB", ";", "return", "new", "vault_factory", "(", "$", "DB", ",", "self", "::", "get_entity_factory", "(", ")", ",", "get_file_storage", "(", ")", ",", "self", "::", "get_legacy_data_mapper_factory", "(", ")", ")", ";", "}" ]
Create the vault factory. @return vault_factory
[ "Create", "the", "vault", "factory", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/container.php#L96-L105
214,182
moodle/moodle
mod/forum/classes/local/container.php
container.get_builder_factory
public static function get_builder_factory() : builder_factory { global $PAGE; return new builder_factory( self::get_legacy_data_mapper_factory(), self::get_exporter_factory(), self::get_vault_factory(), self::get_manager_factory(), $PAGE->get_renderer('mod_forum') ); }
php
public static function get_builder_factory() : builder_factory { global $PAGE; return new builder_factory( self::get_legacy_data_mapper_factory(), self::get_exporter_factory(), self::get_vault_factory(), self::get_manager_factory(), $PAGE->get_renderer('mod_forum') ); }
[ "public", "static", "function", "get_builder_factory", "(", ")", ":", "builder_factory", "{", "global", "$", "PAGE", ";", "return", "new", "builder_factory", "(", "self", "::", "get_legacy_data_mapper_factory", "(", ")", ",", "self", "::", "get_exporter_factory", "(", ")", ",", "self", "::", "get_vault_factory", "(", ")", ",", "self", "::", "get_manager_factory", "(", ")", ",", "$", "PAGE", "->", "get_renderer", "(", "'mod_forum'", ")", ")", ";", "}" ]
Create the builder factory. @return builder_factory
[ "Create", "the", "builder", "factory", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/container.php#L132-L142
214,183
moodle/moodle
lib/phpexcel/PHPExcel/ReferenceHelper.php
PHPExcel_ReferenceHelper.columnSort
public static function columnSort($a, $b) { return strcasecmp(strlen($a) . $a, strlen($b) . $b); }
php
public static function columnSort($a, $b) { return strcasecmp(strlen($a) . $a, strlen($b) . $b); }
[ "public", "static", "function", "columnSort", "(", "$", "a", ",", "$", "b", ")", "{", "return", "strcasecmp", "(", "strlen", "(", "$", "a", ")", ".", "$", "a", ",", "strlen", "(", "$", "b", ")", ".", "$", "b", ")", ";", "}" ]
Compare two column addresses Intended for use as a Callback function for sorting column addresses by column @param string $a First column to test (e.g. 'AA') @param string $b Second column to test (e.g. 'Z') @return integer
[ "Compare", "two", "column", "addresses", "Intended", "for", "use", "as", "a", "Callback", "function", "for", "sorting", "column", "addresses", "by", "column" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/ReferenceHelper.php#L73-L76
214,184
moodle/moodle
lib/phpexcel/PHPExcel/ReferenceHelper.php
PHPExcel_ReferenceHelper.columnReverseSort
public static function columnReverseSort($a, $b) { return 1 - strcasecmp(strlen($a) . $a, strlen($b) . $b); }
php
public static function columnReverseSort($a, $b) { return 1 - strcasecmp(strlen($a) . $a, strlen($b) . $b); }
[ "public", "static", "function", "columnReverseSort", "(", "$", "a", ",", "$", "b", ")", "{", "return", "1", "-", "strcasecmp", "(", "strlen", "(", "$", "a", ")", ".", "$", "a", ",", "strlen", "(", "$", "b", ")", ".", "$", "b", ")", ";", "}" ]
Compare two column addresses Intended for use as a Callback function for reverse sorting column addresses by column @param string $a First column to test (e.g. 'AA') @param string $b Second column to test (e.g. 'Z') @return integer
[ "Compare", "two", "column", "addresses", "Intended", "for", "use", "as", "a", "Callback", "function", "for", "reverse", "sorting", "column", "addresses", "by", "column" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/ReferenceHelper.php#L86-L89
214,185
moodle/moodle
lib/phpexcel/PHPExcel/ReferenceHelper.php
PHPExcel_ReferenceHelper.cellSort
public static function cellSort($a, $b) { sscanf($a, '%[A-Z]%d', $ac, $ar); sscanf($b, '%[A-Z]%d', $bc, $br); if ($ar == $br) { return strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc); } return ($ar < $br) ? -1 : 1; }
php
public static function cellSort($a, $b) { sscanf($a, '%[A-Z]%d', $ac, $ar); sscanf($b, '%[A-Z]%d', $bc, $br); if ($ar == $br) { return strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc); } return ($ar < $br) ? -1 : 1; }
[ "public", "static", "function", "cellSort", "(", "$", "a", ",", "$", "b", ")", "{", "sscanf", "(", "$", "a", ",", "'%[A-Z]%d'", ",", "$", "ac", ",", "$", "ar", ")", ";", "sscanf", "(", "$", "b", ",", "'%[A-Z]%d'", ",", "$", "bc", ",", "$", "br", ")", ";", "if", "(", "$", "ar", "==", "$", "br", ")", "{", "return", "strcasecmp", "(", "strlen", "(", "$", "ac", ")", ".", "$", "ac", ",", "strlen", "(", "$", "bc", ")", ".", "$", "bc", ")", ";", "}", "return", "(", "$", "ar", "<", "$", "br", ")", "?", "-", "1", ":", "1", ";", "}" ]
Compare two cell addresses Intended for use as a Callback function for sorting cell addresses by column and row @param string $a First cell to test (e.g. 'AA1') @param string $b Second cell to test (e.g. 'Z1') @return integer
[ "Compare", "two", "cell", "addresses", "Intended", "for", "use", "as", "a", "Callback", "function", "for", "sorting", "cell", "addresses", "by", "column", "and", "row" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/ReferenceHelper.php#L99-L108
214,186
moodle/moodle
lib/phpexcel/PHPExcel/ReferenceHelper.php
PHPExcel_ReferenceHelper.updateSingleCellReference
private function updateSingleCellReference($pCellReference = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) { if (strpos($pCellReference, ':') === false && strpos($pCellReference, ',') === false) { // Get coordinates of $pBefore list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString($pBefore); // Get coordinates of $pCellReference list($newColumn, $newRow) = PHPExcel_Cell::coordinateFromString($pCellReference); // Verify which parts should be updated $updateColumn = (($newColumn{0} != '$') && ($beforeColumn{0} != '$') && (PHPExcel_Cell::columnIndexFromString($newColumn) >= PHPExcel_Cell::columnIndexFromString($beforeColumn))); $updateRow = (($newRow{0} != '$') && ($beforeRow{0} != '$') && $newRow >= $beforeRow); // Create new column reference if ($updateColumn) { $newColumn = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($newColumn) - 1 + $pNumCols); } // Create new row reference if ($updateRow) { $newRow = $newRow + $pNumRows; } // Return new reference return $newColumn . $newRow; } else { throw new PHPExcel_Exception("Only single cell references may be passed to this method."); } }
php
private function updateSingleCellReference($pCellReference = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) { if (strpos($pCellReference, ':') === false && strpos($pCellReference, ',') === false) { // Get coordinates of $pBefore list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString($pBefore); // Get coordinates of $pCellReference list($newColumn, $newRow) = PHPExcel_Cell::coordinateFromString($pCellReference); // Verify which parts should be updated $updateColumn = (($newColumn{0} != '$') && ($beforeColumn{0} != '$') && (PHPExcel_Cell::columnIndexFromString($newColumn) >= PHPExcel_Cell::columnIndexFromString($beforeColumn))); $updateRow = (($newRow{0} != '$') && ($beforeRow{0} != '$') && $newRow >= $beforeRow); // Create new column reference if ($updateColumn) { $newColumn = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($newColumn) - 1 + $pNumCols); } // Create new row reference if ($updateRow) { $newRow = $newRow + $pNumRows; } // Return new reference return $newColumn . $newRow; } else { throw new PHPExcel_Exception("Only single cell references may be passed to this method."); } }
[ "private", "function", "updateSingleCellReference", "(", "$", "pCellReference", "=", "'A1'", ",", "$", "pBefore", "=", "'A1'", ",", "$", "pNumCols", "=", "0", ",", "$", "pNumRows", "=", "0", ")", "{", "if", "(", "strpos", "(", "$", "pCellReference", ",", "':'", ")", "===", "false", "&&", "strpos", "(", "$", "pCellReference", ",", "','", ")", "===", "false", ")", "{", "// Get coordinates of $pBefore", "list", "(", "$", "beforeColumn", ",", "$", "beforeRow", ")", "=", "PHPExcel_Cell", "::", "coordinateFromString", "(", "$", "pBefore", ")", ";", "// Get coordinates of $pCellReference", "list", "(", "$", "newColumn", ",", "$", "newRow", ")", "=", "PHPExcel_Cell", "::", "coordinateFromString", "(", "$", "pCellReference", ")", ";", "// Verify which parts should be updated", "$", "updateColumn", "=", "(", "(", "$", "newColumn", "{", "0", "}", "!=", "'$'", ")", "&&", "(", "$", "beforeColumn", "{", "0", "}", "!=", "'$'", ")", "&&", "(", "PHPExcel_Cell", "::", "columnIndexFromString", "(", "$", "newColumn", ")", ">=", "PHPExcel_Cell", "::", "columnIndexFromString", "(", "$", "beforeColumn", ")", ")", ")", ";", "$", "updateRow", "=", "(", "(", "$", "newRow", "{", "0", "}", "!=", "'$'", ")", "&&", "(", "$", "beforeRow", "{", "0", "}", "!=", "'$'", ")", "&&", "$", "newRow", ">=", "$", "beforeRow", ")", ";", "// Create new column reference", "if", "(", "$", "updateColumn", ")", "{", "$", "newColumn", "=", "PHPExcel_Cell", "::", "stringFromColumnIndex", "(", "PHPExcel_Cell", "::", "columnIndexFromString", "(", "$", "newColumn", ")", "-", "1", "+", "$", "pNumCols", ")", ";", "}", "// Create new row reference", "if", "(", "$", "updateRow", ")", "{", "$", "newRow", "=", "$", "newRow", "+", "$", "pNumRows", ";", "}", "// Return new reference", "return", "$", "newColumn", ".", "$", "newRow", ";", "}", "else", "{", "throw", "new", "PHPExcel_Exception", "(", "\"Only single cell references may be passed to this method.\"", ")", ";", "}", "}" ]
Update single cell reference @param string $pCellReference Single cell reference @param int $pBefore Insert before this one @param int $pNumCols Number of columns to increment @param int $pNumRows Number of rows to increment @return string Updated cell reference @throws PHPExcel_Exception
[ "Update", "single", "cell", "reference" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/ReferenceHelper.php#L874-L902
214,187
moodle/moodle
lib/classes/oauth2/api.php
api.create_endpoints_for_google
private static function create_endpoints_for_google($issuer) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'name' => 'discovery_endpoint', 'url' => 'https://accounts.google.com/.well-known/openid-configuration' ]; $endpoint = new endpoint(0, $record); $endpoint->create(); return $issuer; }
php
private static function create_endpoints_for_google($issuer) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'name' => 'discovery_endpoint', 'url' => 'https://accounts.google.com/.well-known/openid-configuration' ]; $endpoint = new endpoint(0, $record); $endpoint->create(); return $issuer; }
[ "private", "static", "function", "create_endpoints_for_google", "(", "$", "issuer", ")", "{", "$", "record", "=", "(", "object", ")", "[", "'issuerid'", "=>", "$", "issuer", "->", "get", "(", "'id'", ")", ",", "'name'", "=>", "'discovery_endpoint'", ",", "'url'", "=>", "'https://accounts.google.com/.well-known/openid-configuration'", "]", ";", "$", "endpoint", "=", "new", "endpoint", "(", "0", ",", "$", "record", ")", ";", "$", "endpoint", "->", "create", "(", ")", ";", "return", "$", "issuer", ";", "}" ]
Create endpoints for google issuers. @param issuer $issuer issuer the endpoints should be created for. @return mixed @throws \coding_exception @throws \core\invalid_persistent_exception
[ "Create", "endpoints", "for", "google", "issuers", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L69-L79
214,188
moodle/moodle
lib/classes/oauth2/api.php
api.create_endpoints_for_facebook
private static function create_endpoints_for_facebook($issuer) { // The Facebook API version. $apiversion = '2.12'; // The Graph API URL. $graphurl = 'https://graph.facebook.com/v' . $apiversion; // User information fields that we want to fetch. $infofields = [ 'id', 'first_name', 'last_name', 'link', 'picture.type(large)', 'name', 'email', ]; $endpoints = [ 'authorization_endpoint' => sprintf('https://www.facebook.com/v%s/dialog/oauth', $apiversion), 'token_endpoint' => $graphurl . '/oauth/access_token', 'userinfo_endpoint' => $graphurl . '/me?fields=' . implode(',', $infofields) ]; foreach ($endpoints as $name => $url) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'name' => $name, 'url' => $url ]; $endpoint = new endpoint(0, $record); $endpoint->create(); } // Create the field mappings. $mapping = [ 'name' => 'alternatename', 'last_name' => 'lastname', 'email' => 'email', 'first_name' => 'firstname', 'picture-data-url' => 'picture', 'link' => 'url', ]; foreach ($mapping as $external => $internal) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'externalfield' => $external, 'internalfield' => $internal ]; $userfieldmapping = new user_field_mapping(0, $record); $userfieldmapping->create(); } return $issuer; }
php
private static function create_endpoints_for_facebook($issuer) { // The Facebook API version. $apiversion = '2.12'; // The Graph API URL. $graphurl = 'https://graph.facebook.com/v' . $apiversion; // User information fields that we want to fetch. $infofields = [ 'id', 'first_name', 'last_name', 'link', 'picture.type(large)', 'name', 'email', ]; $endpoints = [ 'authorization_endpoint' => sprintf('https://www.facebook.com/v%s/dialog/oauth', $apiversion), 'token_endpoint' => $graphurl . '/oauth/access_token', 'userinfo_endpoint' => $graphurl . '/me?fields=' . implode(',', $infofields) ]; foreach ($endpoints as $name => $url) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'name' => $name, 'url' => $url ]; $endpoint = new endpoint(0, $record); $endpoint->create(); } // Create the field mappings. $mapping = [ 'name' => 'alternatename', 'last_name' => 'lastname', 'email' => 'email', 'first_name' => 'firstname', 'picture-data-url' => 'picture', 'link' => 'url', ]; foreach ($mapping as $external => $internal) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'externalfield' => $external, 'internalfield' => $internal ]; $userfieldmapping = new user_field_mapping(0, $record); $userfieldmapping->create(); } return $issuer; }
[ "private", "static", "function", "create_endpoints_for_facebook", "(", "$", "issuer", ")", "{", "// The Facebook API version.", "$", "apiversion", "=", "'2.12'", ";", "// The Graph API URL.", "$", "graphurl", "=", "'https://graph.facebook.com/v'", ".", "$", "apiversion", ";", "// User information fields that we want to fetch.", "$", "infofields", "=", "[", "'id'", ",", "'first_name'", ",", "'last_name'", ",", "'link'", ",", "'picture.type(large)'", ",", "'name'", ",", "'email'", ",", "]", ";", "$", "endpoints", "=", "[", "'authorization_endpoint'", "=>", "sprintf", "(", "'https://www.facebook.com/v%s/dialog/oauth'", ",", "$", "apiversion", ")", ",", "'token_endpoint'", "=>", "$", "graphurl", ".", "'/oauth/access_token'", ",", "'userinfo_endpoint'", "=>", "$", "graphurl", ".", "'/me?fields='", ".", "implode", "(", "','", ",", "$", "infofields", ")", "]", ";", "foreach", "(", "$", "endpoints", "as", "$", "name", "=>", "$", "url", ")", "{", "$", "record", "=", "(", "object", ")", "[", "'issuerid'", "=>", "$", "issuer", "->", "get", "(", "'id'", ")", ",", "'name'", "=>", "$", "name", ",", "'url'", "=>", "$", "url", "]", ";", "$", "endpoint", "=", "new", "endpoint", "(", "0", ",", "$", "record", ")", ";", "$", "endpoint", "->", "create", "(", ")", ";", "}", "// Create the field mappings.", "$", "mapping", "=", "[", "'name'", "=>", "'alternatename'", ",", "'last_name'", "=>", "'lastname'", ",", "'email'", "=>", "'email'", ",", "'first_name'", "=>", "'firstname'", ",", "'picture-data-url'", "=>", "'picture'", ",", "'link'", "=>", "'url'", ",", "]", ";", "foreach", "(", "$", "mapping", "as", "$", "external", "=>", "$", "internal", ")", "{", "$", "record", "=", "(", "object", ")", "[", "'issuerid'", "=>", "$", "issuer", "->", "get", "(", "'id'", ")", ",", "'externalfield'", "=>", "$", "external", ",", "'internalfield'", "=>", "$", "internal", "]", ";", "$", "userfieldmapping", "=", "new", "user_field_mapping", "(", "0", ",", "$", "record", ")", ";", "$", "userfieldmapping", "->", "create", "(", ")", ";", "}", "return", "$", "issuer", ";", "}" ]
Create endpoints for facebook issuers. @param issuer $issuer issuer the endpoints should be created for. @return mixed @throws \coding_exception @throws \core\invalid_persistent_exception
[ "Create", "endpoints", "for", "facebook", "issuers", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L107-L157
214,189
moodle/moodle
lib/classes/oauth2/api.php
api.create_endpoints_for_microsoft
private static function create_endpoints_for_microsoft($issuer) { $endpoints = [ 'authorization_endpoint' => 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize', 'token_endpoint' => 'https://login.microsoftonline.com/common/oauth2/v2.0/token', 'userinfo_endpoint' => 'https://graph.microsoft.com/v1.0/me/', 'userpicture_endpoint' => 'https://graph.microsoft.com/v1.0/me/photo/$value', ]; foreach ($endpoints as $name => $url) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'name' => $name, 'url' => $url ]; $endpoint = new endpoint(0, $record); $endpoint->create(); } // Create the field mappings. $mapping = [ 'givenName' => 'firstname', 'surname' => 'lastname', 'userPrincipalName' => 'email', 'displayName' => 'alternatename', 'officeLocation' => 'address', 'mobilePhone' => 'phone1', 'preferredLanguage' => 'lang' ]; foreach ($mapping as $external => $internal) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'externalfield' => $external, 'internalfield' => $internal ]; $userfieldmapping = new user_field_mapping(0, $record); $userfieldmapping->create(); } return $issuer; }
php
private static function create_endpoints_for_microsoft($issuer) { $endpoints = [ 'authorization_endpoint' => 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize', 'token_endpoint' => 'https://login.microsoftonline.com/common/oauth2/v2.0/token', 'userinfo_endpoint' => 'https://graph.microsoft.com/v1.0/me/', 'userpicture_endpoint' => 'https://graph.microsoft.com/v1.0/me/photo/$value', ]; foreach ($endpoints as $name => $url) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'name' => $name, 'url' => $url ]; $endpoint = new endpoint(0, $record); $endpoint->create(); } // Create the field mappings. $mapping = [ 'givenName' => 'firstname', 'surname' => 'lastname', 'userPrincipalName' => 'email', 'displayName' => 'alternatename', 'officeLocation' => 'address', 'mobilePhone' => 'phone1', 'preferredLanguage' => 'lang' ]; foreach ($mapping as $external => $internal) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'externalfield' => $external, 'internalfield' => $internal ]; $userfieldmapping = new user_field_mapping(0, $record); $userfieldmapping->create(); } return $issuer; }
[ "private", "static", "function", "create_endpoints_for_microsoft", "(", "$", "issuer", ")", "{", "$", "endpoints", "=", "[", "'authorization_endpoint'", "=>", "'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'", ",", "'token_endpoint'", "=>", "'https://login.microsoftonline.com/common/oauth2/v2.0/token'", ",", "'userinfo_endpoint'", "=>", "'https://graph.microsoft.com/v1.0/me/'", ",", "'userpicture_endpoint'", "=>", "'https://graph.microsoft.com/v1.0/me/photo/$value'", ",", "]", ";", "foreach", "(", "$", "endpoints", "as", "$", "name", "=>", "$", "url", ")", "{", "$", "record", "=", "(", "object", ")", "[", "'issuerid'", "=>", "$", "issuer", "->", "get", "(", "'id'", ")", ",", "'name'", "=>", "$", "name", ",", "'url'", "=>", "$", "url", "]", ";", "$", "endpoint", "=", "new", "endpoint", "(", "0", ",", "$", "record", ")", ";", "$", "endpoint", "->", "create", "(", ")", ";", "}", "// Create the field mappings.", "$", "mapping", "=", "[", "'givenName'", "=>", "'firstname'", ",", "'surname'", "=>", "'lastname'", ",", "'userPrincipalName'", "=>", "'email'", ",", "'displayName'", "=>", "'alternatename'", ",", "'officeLocation'", "=>", "'address'", ",", "'mobilePhone'", "=>", "'phone1'", ",", "'preferredLanguage'", "=>", "'lang'", "]", ";", "foreach", "(", "$", "mapping", "as", "$", "external", "=>", "$", "internal", ")", "{", "$", "record", "=", "(", "object", ")", "[", "'issuerid'", "=>", "$", "issuer", "->", "get", "(", "'id'", ")", ",", "'externalfield'", "=>", "$", "external", ",", "'internalfield'", "=>", "$", "internal", "]", ";", "$", "userfieldmapping", "=", "new", "user_field_mapping", "(", "0", ",", "$", "record", ")", ";", "$", "userfieldmapping", "->", "create", "(", ")", ";", "}", "return", "$", "issuer", ";", "}" ]
Create endpoints for microsoft issuers. @param issuer $issuer issuer the endpoints should be created for. @return mixed @throws \coding_exception @throws \core\invalid_persistent_exception
[ "Create", "endpoints", "for", "microsoft", "issuers", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L185-L224
214,190
moodle/moodle
lib/classes/oauth2/api.php
api.create_endpoints_for_nextcloud
private static function create_endpoints_for_nextcloud($issuer) { $baseurl = $issuer->get('baseurl'); // Add trailing slash to baseurl, if needed. if (substr($baseurl, -1) !== '/') { $baseurl .= '/'; } $endpoints = [ // Baseurl will be prepended later. 'authorization_endpoint' => 'index.php/apps/oauth2/authorize', 'token_endpoint' => 'index.php/apps/oauth2/api/v1/token', 'userinfo_endpoint' => 'ocs/v2.php/cloud/user?format=json', 'webdav_endpoint' => 'remote.php/webdav/', 'ocs_endpoint' => 'ocs/v1.php/apps/files_sharing/api/v1/shares', ]; foreach ($endpoints as $name => $url) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'name' => $name, 'url' => $baseurl . $url, ]; $endpoint = new \core\oauth2\endpoint(0, $record); $endpoint->create(); } // Create the field mappings. $mapping = [ 'ocs-data-email' => 'email', 'ocs-data-id' => 'username', ]; foreach ($mapping as $external => $internal) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'externalfield' => $external, 'internalfield' => $internal ]; $userfieldmapping = new \core\oauth2\user_field_mapping(0, $record); $userfieldmapping->create(); } }
php
private static function create_endpoints_for_nextcloud($issuer) { $baseurl = $issuer->get('baseurl'); // Add trailing slash to baseurl, if needed. if (substr($baseurl, -1) !== '/') { $baseurl .= '/'; } $endpoints = [ // Baseurl will be prepended later. 'authorization_endpoint' => 'index.php/apps/oauth2/authorize', 'token_endpoint' => 'index.php/apps/oauth2/api/v1/token', 'userinfo_endpoint' => 'ocs/v2.php/cloud/user?format=json', 'webdav_endpoint' => 'remote.php/webdav/', 'ocs_endpoint' => 'ocs/v1.php/apps/files_sharing/api/v1/shares', ]; foreach ($endpoints as $name => $url) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'name' => $name, 'url' => $baseurl . $url, ]; $endpoint = new \core\oauth2\endpoint(0, $record); $endpoint->create(); } // Create the field mappings. $mapping = [ 'ocs-data-email' => 'email', 'ocs-data-id' => 'username', ]; foreach ($mapping as $external => $internal) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'externalfield' => $external, 'internalfield' => $internal ]; $userfieldmapping = new \core\oauth2\user_field_mapping(0, $record); $userfieldmapping->create(); } }
[ "private", "static", "function", "create_endpoints_for_nextcloud", "(", "$", "issuer", ")", "{", "$", "baseurl", "=", "$", "issuer", "->", "get", "(", "'baseurl'", ")", ";", "// Add trailing slash to baseurl, if needed.", "if", "(", "substr", "(", "$", "baseurl", ",", "-", "1", ")", "!==", "'/'", ")", "{", "$", "baseurl", ".=", "'/'", ";", "}", "$", "endpoints", "=", "[", "// Baseurl will be prepended later.", "'authorization_endpoint'", "=>", "'index.php/apps/oauth2/authorize'", ",", "'token_endpoint'", "=>", "'index.php/apps/oauth2/api/v1/token'", ",", "'userinfo_endpoint'", "=>", "'ocs/v2.php/cloud/user?format=json'", ",", "'webdav_endpoint'", "=>", "'remote.php/webdav/'", ",", "'ocs_endpoint'", "=>", "'ocs/v1.php/apps/files_sharing/api/v1/shares'", ",", "]", ";", "foreach", "(", "$", "endpoints", "as", "$", "name", "=>", "$", "url", ")", "{", "$", "record", "=", "(", "object", ")", "[", "'issuerid'", "=>", "$", "issuer", "->", "get", "(", "'id'", ")", ",", "'name'", "=>", "$", "name", ",", "'url'", "=>", "$", "baseurl", ".", "$", "url", ",", "]", ";", "$", "endpoint", "=", "new", "\\", "core", "\\", "oauth2", "\\", "endpoint", "(", "0", ",", "$", "record", ")", ";", "$", "endpoint", "->", "create", "(", ")", ";", "}", "// Create the field mappings.", "$", "mapping", "=", "[", "'ocs-data-email'", "=>", "'email'", ",", "'ocs-data-id'", "=>", "'username'", ",", "]", ";", "foreach", "(", "$", "mapping", "as", "$", "external", "=>", "$", "internal", ")", "{", "$", "record", "=", "(", "object", ")", "[", "'issuerid'", "=>", "$", "issuer", "->", "get", "(", "'id'", ")", ",", "'externalfield'", "=>", "$", "external", ",", "'internalfield'", "=>", "$", "internal", "]", ";", "$", "userfieldmapping", "=", "new", "\\", "core", "\\", "oauth2", "\\", "user_field_mapping", "(", "0", ",", "$", "record", ")", ";", "$", "userfieldmapping", "->", "create", "(", ")", ";", "}", "}" ]
Create endpoints for nextcloud issuers. @param issuer $issuer issuer the endpoints should be created for. @return mixed @throws \coding_exception @throws \core\invalid_persistent_exception
[ "Create", "endpoints", "for", "nextcloud", "issuers", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L250-L290
214,191
moodle/moodle
lib/classes/oauth2/api.php
api.init_standard_issuer
public static function init_standard_issuer($type) { require_capability('moodle/site:config', context_system::instance()); if ($type == 'google') { return self::init_google(); } else if ($type == 'microsoft') { return self::init_microsoft(); } else if ($type == 'facebook') { return self::init_facebook(); } else if ($type == 'nextcloud') { return self::init_nextcloud(); } else { throw new moodle_exception('OAuth 2 service type not recognised: ' . $type); } }
php
public static function init_standard_issuer($type) { require_capability('moodle/site:config', context_system::instance()); if ($type == 'google') { return self::init_google(); } else if ($type == 'microsoft') { return self::init_microsoft(); } else if ($type == 'facebook') { return self::init_facebook(); } else if ($type == 'nextcloud') { return self::init_nextcloud(); } else { throw new moodle_exception('OAuth 2 service type not recognised: ' . $type); } }
[ "public", "static", "function", "init_standard_issuer", "(", "$", "type", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "if", "(", "$", "type", "==", "'google'", ")", "{", "return", "self", "::", "init_google", "(", ")", ";", "}", "else", "if", "(", "$", "type", "==", "'microsoft'", ")", "{", "return", "self", "::", "init_microsoft", "(", ")", ";", "}", "else", "if", "(", "$", "type", "==", "'facebook'", ")", "{", "return", "self", "::", "init_facebook", "(", ")", ";", "}", "else", "if", "(", "$", "type", "==", "'nextcloud'", ")", "{", "return", "self", "::", "init_nextcloud", "(", ")", ";", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'OAuth 2 service type not recognised: '", ".", "$", "type", ")", ";", "}", "}" ]
Initializes a record for one of the standard issuers to be displayed in the settings. The issuer is not yet created in the database. @param string $type One of google, facebook, microsoft, nextcloud @return \core\oauth2\issuer
[ "Initializes", "a", "record", "for", "one", "of", "the", "standard", "issuers", "to", "be", "displayed", "in", "the", "settings", ".", "The", "issuer", "is", "not", "yet", "created", "in", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L298-L311
214,192
moodle/moodle
lib/classes/oauth2/api.php
api.create_endpoints_for_standard_issuer
public static function create_endpoints_for_standard_issuer($type, $issuer) { require_capability('moodle/site:config', context_system::instance()); if ($type == 'google') { $issuer = self::create_endpoints_for_google($issuer); self::discover_endpoints($issuer); return $issuer; } else if ($type == 'microsoft') { return self::create_endpoints_for_microsoft($issuer); } else if ($type == 'facebook') { return self::create_endpoints_for_facebook($issuer); } else if ($type == 'nextcloud') { return self::create_endpoints_for_nextcloud($issuer); } else { throw new moodle_exception('OAuth 2 service type not recognised: ' . $type); } }
php
public static function create_endpoints_for_standard_issuer($type, $issuer) { require_capability('moodle/site:config', context_system::instance()); if ($type == 'google') { $issuer = self::create_endpoints_for_google($issuer); self::discover_endpoints($issuer); return $issuer; } else if ($type == 'microsoft') { return self::create_endpoints_for_microsoft($issuer); } else if ($type == 'facebook') { return self::create_endpoints_for_facebook($issuer); } else if ($type == 'nextcloud') { return self::create_endpoints_for_nextcloud($issuer); } else { throw new moodle_exception('OAuth 2 service type not recognised: ' . $type); } }
[ "public", "static", "function", "create_endpoints_for_standard_issuer", "(", "$", "type", ",", "$", "issuer", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "if", "(", "$", "type", "==", "'google'", ")", "{", "$", "issuer", "=", "self", "::", "create_endpoints_for_google", "(", "$", "issuer", ")", ";", "self", "::", "discover_endpoints", "(", "$", "issuer", ")", ";", "return", "$", "issuer", ";", "}", "else", "if", "(", "$", "type", "==", "'microsoft'", ")", "{", "return", "self", "::", "create_endpoints_for_microsoft", "(", "$", "issuer", ")", ";", "}", "else", "if", "(", "$", "type", "==", "'facebook'", ")", "{", "return", "self", "::", "create_endpoints_for_facebook", "(", "$", "issuer", ")", ";", "}", "else", "if", "(", "$", "type", "==", "'nextcloud'", ")", "{", "return", "self", "::", "create_endpoints_for_nextcloud", "(", "$", "issuer", ")", ";", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'OAuth 2 service type not recognised: '", ".", "$", "type", ")", ";", "}", "}" ]
Create endpoints for standard issuers, based on the issuer created from submitted data. @param string $type One of google, facebook, microsoft, nextcloud @param issuer $issuer issuer the endpoints should be created for. @return \core\oauth2\issuer
[ "Create", "endpoints", "for", "standard", "issuers", "based", "on", "the", "issuer", "created", "from", "submitted", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L319-L334
214,193
moodle/moodle
lib/classes/oauth2/api.php
api.create_standard_issuer
public static function create_standard_issuer($type, $baseurl = false) { require_capability('moodle/site:config', context_system::instance()); if ($type == 'google') { $issuer = self::init_google(); $issuer->create(); return self::create_endpoints_for_google($issuer); } else if ($type == 'microsoft') { $issuer = self::init_microsoft(); $issuer->create(); return self::create_endpoints_for_microsoft($issuer); } else if ($type == 'facebook') { $issuer = self::init_facebook(); $issuer->create(); return self::create_endpoints_for_facebook($issuer); } else if ($type == 'nextcloud') { if (!$baseurl) { throw new moodle_exception('Nextcloud service type requires the baseurl parameter.'); } $issuer = self::init_nextcloud(); $issuer->set('baseurl', $baseurl); $issuer->create(); return self::create_endpoints_for_nextcloud($issuer); } else { throw new moodle_exception('OAuth 2 service type not recognised: ' . $type); } }
php
public static function create_standard_issuer($type, $baseurl = false) { require_capability('moodle/site:config', context_system::instance()); if ($type == 'google') { $issuer = self::init_google(); $issuer->create(); return self::create_endpoints_for_google($issuer); } else if ($type == 'microsoft') { $issuer = self::init_microsoft(); $issuer->create(); return self::create_endpoints_for_microsoft($issuer); } else if ($type == 'facebook') { $issuer = self::init_facebook(); $issuer->create(); return self::create_endpoints_for_facebook($issuer); } else if ($type == 'nextcloud') { if (!$baseurl) { throw new moodle_exception('Nextcloud service type requires the baseurl parameter.'); } $issuer = self::init_nextcloud(); $issuer->set('baseurl', $baseurl); $issuer->create(); return self::create_endpoints_for_nextcloud($issuer); } else { throw new moodle_exception('OAuth 2 service type not recognised: ' . $type); } }
[ "public", "static", "function", "create_standard_issuer", "(", "$", "type", ",", "$", "baseurl", "=", "false", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "if", "(", "$", "type", "==", "'google'", ")", "{", "$", "issuer", "=", "self", "::", "init_google", "(", ")", ";", "$", "issuer", "->", "create", "(", ")", ";", "return", "self", "::", "create_endpoints_for_google", "(", "$", "issuer", ")", ";", "}", "else", "if", "(", "$", "type", "==", "'microsoft'", ")", "{", "$", "issuer", "=", "self", "::", "init_microsoft", "(", ")", ";", "$", "issuer", "->", "create", "(", ")", ";", "return", "self", "::", "create_endpoints_for_microsoft", "(", "$", "issuer", ")", ";", "}", "else", "if", "(", "$", "type", "==", "'facebook'", ")", "{", "$", "issuer", "=", "self", "::", "init_facebook", "(", ")", ";", "$", "issuer", "->", "create", "(", ")", ";", "return", "self", "::", "create_endpoints_for_facebook", "(", "$", "issuer", ")", ";", "}", "else", "if", "(", "$", "type", "==", "'nextcloud'", ")", "{", "if", "(", "!", "$", "baseurl", ")", "{", "throw", "new", "moodle_exception", "(", "'Nextcloud service type requires the baseurl parameter.'", ")", ";", "}", "$", "issuer", "=", "self", "::", "init_nextcloud", "(", ")", ";", "$", "issuer", "->", "set", "(", "'baseurl'", ",", "$", "baseurl", ")", ";", "$", "issuer", "->", "create", "(", ")", ";", "return", "self", "::", "create_endpoints_for_nextcloud", "(", "$", "issuer", ")", ";", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'OAuth 2 service type not recognised: '", ".", "$", "type", ")", ";", "}", "}" ]
Create one of the standard issuers. @param string $type One of google, facebook, microsoft, or nextcloud @param string|false $baseurl Baseurl (only required for nextcloud) @return \core\oauth2\issuer
[ "Create", "one", "of", "the", "standard", "issuers", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L342-L367
214,194
moodle/moodle
lib/classes/oauth2/api.php
api.get_system_scopes_for_issuer
public static function get_system_scopes_for_issuer($issuer) { $scopes = $issuer->get('loginscopesoffline'); $pluginsfunction = get_plugins_with_function('oauth2_system_scopes', 'lib.php'); foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { // Get additional scopes from the plugin. $pluginscopes = $pluginfunction($issuer); if (empty($pluginscopes)) { continue; } // Merge the additional scopes with the existing ones. $additionalscopes = explode(' ', $pluginscopes); foreach ($additionalscopes as $scope) { if (!empty($scope)) { if (strpos(' ' . $scopes . ' ', ' ' . $scope . ' ') === false) { $scopes .= ' ' . $scope; } } } } } return $scopes; }
php
public static function get_system_scopes_for_issuer($issuer) { $scopes = $issuer->get('loginscopesoffline'); $pluginsfunction = get_plugins_with_function('oauth2_system_scopes', 'lib.php'); foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { // Get additional scopes from the plugin. $pluginscopes = $pluginfunction($issuer); if (empty($pluginscopes)) { continue; } // Merge the additional scopes with the existing ones. $additionalscopes = explode(' ', $pluginscopes); foreach ($additionalscopes as $scope) { if (!empty($scope)) { if (strpos(' ' . $scopes . ' ', ' ' . $scope . ' ') === false) { $scopes .= ' ' . $scope; } } } } } return $scopes; }
[ "public", "static", "function", "get_system_scopes_for_issuer", "(", "$", "issuer", ")", "{", "$", "scopes", "=", "$", "issuer", "->", "get", "(", "'loginscopesoffline'", ")", ";", "$", "pluginsfunction", "=", "get_plugins_with_function", "(", "'oauth2_system_scopes'", ",", "'lib.php'", ")", ";", "foreach", "(", "$", "pluginsfunction", "as", "$", "plugintype", "=>", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "pluginfunction", ")", "{", "// Get additional scopes from the plugin.", "$", "pluginscopes", "=", "$", "pluginfunction", "(", "$", "issuer", ")", ";", "if", "(", "empty", "(", "$", "pluginscopes", ")", ")", "{", "continue", ";", "}", "// Merge the additional scopes with the existing ones.", "$", "additionalscopes", "=", "explode", "(", "' '", ",", "$", "pluginscopes", ")", ";", "foreach", "(", "$", "additionalscopes", "as", "$", "scope", ")", "{", "if", "(", "!", "empty", "(", "$", "scope", ")", ")", "{", "if", "(", "strpos", "(", "' '", ".", "$", "scopes", ".", "' '", ",", "' '", ".", "$", "scope", ".", "' '", ")", "===", "false", ")", "{", "$", "scopes", ".=", "' '", ".", "$", "scope", ";", "}", "}", "}", "}", "}", "return", "$", "scopes", ";", "}" ]
Get the full list of system scopes required by an oauth issuer. This includes the list required for login as well as any scopes injected by the oauth2_system_scopes callback in plugins. @param \core\oauth2\issuer $issuer @return string
[ "Get", "the", "full", "list", "of", "system", "scopes", "required", "by", "an", "oauth", "issuer", ".", "This", "includes", "the", "list", "required", "for", "login", "as", "well", "as", "any", "scopes", "injected", "by", "the", "oauth2_system_scopes", "callback", "in", "plugins", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L426-L452
214,195
moodle/moodle
lib/classes/oauth2/api.php
api.get_system_oauth_client
public static function get_system_oauth_client(issuer $issuer) { $systemaccount = self::get_system_account($issuer); if (empty($systemaccount)) { return false; } // Get all the scopes! $scopes = self::get_system_scopes_for_issuer($issuer); $client = new \core\oauth2\client($issuer, null, $scopes, true); if (!$client->is_logged_in()) { if (!$client->upgrade_refresh_token($systemaccount)) { return false; } } return $client; }
php
public static function get_system_oauth_client(issuer $issuer) { $systemaccount = self::get_system_account($issuer); if (empty($systemaccount)) { return false; } // Get all the scopes! $scopes = self::get_system_scopes_for_issuer($issuer); $client = new \core\oauth2\client($issuer, null, $scopes, true); if (!$client->is_logged_in()) { if (!$client->upgrade_refresh_token($systemaccount)) { return false; } } return $client; }
[ "public", "static", "function", "get_system_oauth_client", "(", "issuer", "$", "issuer", ")", "{", "$", "systemaccount", "=", "self", "::", "get_system_account", "(", "$", "issuer", ")", ";", "if", "(", "empty", "(", "$", "systemaccount", ")", ")", "{", "return", "false", ";", "}", "// Get all the scopes!", "$", "scopes", "=", "self", "::", "get_system_scopes_for_issuer", "(", "$", "issuer", ")", ";", "$", "client", "=", "new", "\\", "core", "\\", "oauth2", "\\", "client", "(", "$", "issuer", ",", "null", ",", "$", "scopes", ",", "true", ")", ";", "if", "(", "!", "$", "client", "->", "is_logged_in", "(", ")", ")", "{", "if", "(", "!", "$", "client", "->", "upgrade_refresh_token", "(", "$", "systemaccount", ")", ")", "{", "return", "false", ";", "}", "}", "return", "$", "client", ";", "}" ]
Get an authenticated oauth2 client using the system account. This call uses the refresh token to get an access token. @param \core\oauth2\issuer $issuer @return \core\oauth2\client|false An authenticated client (or false if the token could not be upgraded) @throws moodle_exception Request for token upgrade failed for technical reasons
[ "Get", "an", "authenticated", "oauth2", "client", "using", "the", "system", "account", ".", "This", "call", "uses", "the", "refresh", "token", "to", "get", "an", "access", "token", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L462-L478
214,196
moodle/moodle
lib/classes/oauth2/api.php
api.get_user_oauth_client
public static function get_user_oauth_client(issuer $issuer, moodle_url $currenturl, $additionalscopes = '') { $client = new \core\oauth2\client($issuer, $currenturl, $additionalscopes); return $client; }
php
public static function get_user_oauth_client(issuer $issuer, moodle_url $currenturl, $additionalscopes = '') { $client = new \core\oauth2\client($issuer, $currenturl, $additionalscopes); return $client; }
[ "public", "static", "function", "get_user_oauth_client", "(", "issuer", "$", "issuer", ",", "moodle_url", "$", "currenturl", ",", "$", "additionalscopes", "=", "''", ")", "{", "$", "client", "=", "new", "\\", "core", "\\", "oauth2", "\\", "client", "(", "$", "issuer", ",", "$", "currenturl", ",", "$", "additionalscopes", ")", ";", "return", "$", "client", ";", "}" ]
Get an authenticated oauth2 client using the current user account. This call does the redirect dance back to the current page after authentication. @param \core\oauth2\issuer $issuer The desired OAuth issuer @param moodle_url $currenturl The url to the current page. @param string $additionalscopes The additional scopes required for authorization. @return \core\oauth2\client
[ "Get", "an", "authenticated", "oauth2", "client", "using", "the", "current", "user", "account", ".", "This", "call", "does", "the", "redirect", "dance", "back", "to", "the", "current", "page", "after", "authentication", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L489-L493
214,197
moodle/moodle
lib/classes/oauth2/api.php
api.guess_image
protected static function guess_image($issuer) { if (empty($issuer->get('image')) && !empty($issuer->get('baseurl'))) { $baseurl = parse_url($issuer->get('baseurl')); $imageurl = $baseurl['scheme'] . '://' . $baseurl['host'] . '/favicon.ico'; $issuer->set('image', $imageurl); $issuer->update(); } }
php
protected static function guess_image($issuer) { if (empty($issuer->get('image')) && !empty($issuer->get('baseurl'))) { $baseurl = parse_url($issuer->get('baseurl')); $imageurl = $baseurl['scheme'] . '://' . $baseurl['host'] . '/favicon.ico'; $issuer->set('image', $imageurl); $issuer->update(); } }
[ "protected", "static", "function", "guess_image", "(", "$", "issuer", ")", "{", "if", "(", "empty", "(", "$", "issuer", "->", "get", "(", "'image'", ")", ")", "&&", "!", "empty", "(", "$", "issuer", "->", "get", "(", "'baseurl'", ")", ")", ")", "{", "$", "baseurl", "=", "parse_url", "(", "$", "issuer", "->", "get", "(", "'baseurl'", ")", ")", ";", "$", "imageurl", "=", "$", "baseurl", "[", "'scheme'", "]", ".", "'://'", ".", "$", "baseurl", "[", "'host'", "]", ".", "'/favicon.ico'", ";", "$", "issuer", "->", "set", "(", "'image'", ",", "$", "imageurl", ")", ";", "$", "issuer", "->", "update", "(", ")", ";", "}", "}" ]
Guess an image from the discovery URL. @param \core\oauth2\issuer $issuer The desired OAuth issuer
[ "Guess", "an", "image", "from", "the", "discovery", "URL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L520-L527
214,198
moodle/moodle
lib/classes/oauth2/api.php
api.discover_endpoints
protected static function discover_endpoints($issuer) { $curl = new curl(); if (empty($issuer->get('baseurl'))) { return 0; } $url = $issuer->get_endpoint_url('discovery'); if (!$url) { $url = $issuer->get('baseurl') . '/.well-known/openid-configuration'; } if (!$json = $curl->get($url)) { $msg = 'Could not discover end points for identity issuer' . $issuer->get('name'); throw new moodle_exception($msg); } if ($msg = $curl->error) { throw new moodle_exception('Could not discover service endpoints: ' . $msg); } $info = json_decode($json); if (empty($info)) { $msg = 'Could not discover end points for identity issuer' . $issuer->get('name'); throw new moodle_exception($msg); } foreach (endpoint::get_records(['issuerid' => $issuer->get('id')]) as $endpoint) { if ($endpoint->get('name') != 'discovery_endpoint') { $endpoint->delete(); } } foreach ($info as $key => $value) { if (substr_compare($key, '_endpoint', - strlen('_endpoint')) === 0) { $record = new stdClass(); $record->issuerid = $issuer->get('id'); $record->name = $key; $record->url = $value; $endpoint = new endpoint(0, $record); $endpoint->create(); } if ($key == 'scopes_supported') { $issuer->set('scopessupported', implode(' ', $value)); $issuer->update(); } } // We got to here - must be a decent OpenID connect service. Add the default user field mapping list. foreach (user_field_mapping::get_records(['issuerid' => $issuer->get('id')]) as $userfieldmapping) { $userfieldmapping->delete(); } // Create the field mappings. $mapping = [ 'given_name' => 'firstname', 'middle_name' => 'middlename', 'family_name' => 'lastname', 'email' => 'email', 'website' => 'url', 'nickname' => 'alternatename', 'picture' => 'picture', 'address' => 'address', 'phone' => 'phone1', 'locale' => 'lang' ]; foreach ($mapping as $external => $internal) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'externalfield' => $external, 'internalfield' => $internal ]; $userfieldmapping = new user_field_mapping(0, $record); $userfieldmapping->create(); } return endpoint::count_records(['issuerid' => $issuer->get('id')]); }
php
protected static function discover_endpoints($issuer) { $curl = new curl(); if (empty($issuer->get('baseurl'))) { return 0; } $url = $issuer->get_endpoint_url('discovery'); if (!$url) { $url = $issuer->get('baseurl') . '/.well-known/openid-configuration'; } if (!$json = $curl->get($url)) { $msg = 'Could not discover end points for identity issuer' . $issuer->get('name'); throw new moodle_exception($msg); } if ($msg = $curl->error) { throw new moodle_exception('Could not discover service endpoints: ' . $msg); } $info = json_decode($json); if (empty($info)) { $msg = 'Could not discover end points for identity issuer' . $issuer->get('name'); throw new moodle_exception($msg); } foreach (endpoint::get_records(['issuerid' => $issuer->get('id')]) as $endpoint) { if ($endpoint->get('name') != 'discovery_endpoint') { $endpoint->delete(); } } foreach ($info as $key => $value) { if (substr_compare($key, '_endpoint', - strlen('_endpoint')) === 0) { $record = new stdClass(); $record->issuerid = $issuer->get('id'); $record->name = $key; $record->url = $value; $endpoint = new endpoint(0, $record); $endpoint->create(); } if ($key == 'scopes_supported') { $issuer->set('scopessupported', implode(' ', $value)); $issuer->update(); } } // We got to here - must be a decent OpenID connect service. Add the default user field mapping list. foreach (user_field_mapping::get_records(['issuerid' => $issuer->get('id')]) as $userfieldmapping) { $userfieldmapping->delete(); } // Create the field mappings. $mapping = [ 'given_name' => 'firstname', 'middle_name' => 'middlename', 'family_name' => 'lastname', 'email' => 'email', 'website' => 'url', 'nickname' => 'alternatename', 'picture' => 'picture', 'address' => 'address', 'phone' => 'phone1', 'locale' => 'lang' ]; foreach ($mapping as $external => $internal) { $record = (object) [ 'issuerid' => $issuer->get('id'), 'externalfield' => $external, 'internalfield' => $internal ]; $userfieldmapping = new user_field_mapping(0, $record); $userfieldmapping->create(); } return endpoint::count_records(['issuerid' => $issuer->get('id')]); }
[ "protected", "static", "function", "discover_endpoints", "(", "$", "issuer", ")", "{", "$", "curl", "=", "new", "curl", "(", ")", ";", "if", "(", "empty", "(", "$", "issuer", "->", "get", "(", "'baseurl'", ")", ")", ")", "{", "return", "0", ";", "}", "$", "url", "=", "$", "issuer", "->", "get_endpoint_url", "(", "'discovery'", ")", ";", "if", "(", "!", "$", "url", ")", "{", "$", "url", "=", "$", "issuer", "->", "get", "(", "'baseurl'", ")", ".", "'/.well-known/openid-configuration'", ";", "}", "if", "(", "!", "$", "json", "=", "$", "curl", "->", "get", "(", "$", "url", ")", ")", "{", "$", "msg", "=", "'Could not discover end points for identity issuer'", ".", "$", "issuer", "->", "get", "(", "'name'", ")", ";", "throw", "new", "moodle_exception", "(", "$", "msg", ")", ";", "}", "if", "(", "$", "msg", "=", "$", "curl", "->", "error", ")", "{", "throw", "new", "moodle_exception", "(", "'Could not discover service endpoints: '", ".", "$", "msg", ")", ";", "}", "$", "info", "=", "json_decode", "(", "$", "json", ")", ";", "if", "(", "empty", "(", "$", "info", ")", ")", "{", "$", "msg", "=", "'Could not discover end points for identity issuer'", ".", "$", "issuer", "->", "get", "(", "'name'", ")", ";", "throw", "new", "moodle_exception", "(", "$", "msg", ")", ";", "}", "foreach", "(", "endpoint", "::", "get_records", "(", "[", "'issuerid'", "=>", "$", "issuer", "->", "get", "(", "'id'", ")", "]", ")", "as", "$", "endpoint", ")", "{", "if", "(", "$", "endpoint", "->", "get", "(", "'name'", ")", "!=", "'discovery_endpoint'", ")", "{", "$", "endpoint", "->", "delete", "(", ")", ";", "}", "}", "foreach", "(", "$", "info", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "substr_compare", "(", "$", "key", ",", "'_endpoint'", ",", "-", "strlen", "(", "'_endpoint'", ")", ")", "===", "0", ")", "{", "$", "record", "=", "new", "stdClass", "(", ")", ";", "$", "record", "->", "issuerid", "=", "$", "issuer", "->", "get", "(", "'id'", ")", ";", "$", "record", "->", "name", "=", "$", "key", ";", "$", "record", "->", "url", "=", "$", "value", ";", "$", "endpoint", "=", "new", "endpoint", "(", "0", ",", "$", "record", ")", ";", "$", "endpoint", "->", "create", "(", ")", ";", "}", "if", "(", "$", "key", "==", "'scopes_supported'", ")", "{", "$", "issuer", "->", "set", "(", "'scopessupported'", ",", "implode", "(", "' '", ",", "$", "value", ")", ")", ";", "$", "issuer", "->", "update", "(", ")", ";", "}", "}", "// We got to here - must be a decent OpenID connect service. Add the default user field mapping list.", "foreach", "(", "user_field_mapping", "::", "get_records", "(", "[", "'issuerid'", "=>", "$", "issuer", "->", "get", "(", "'id'", ")", "]", ")", "as", "$", "userfieldmapping", ")", "{", "$", "userfieldmapping", "->", "delete", "(", ")", ";", "}", "// Create the field mappings.", "$", "mapping", "=", "[", "'given_name'", "=>", "'firstname'", ",", "'middle_name'", "=>", "'middlename'", ",", "'family_name'", "=>", "'lastname'", ",", "'email'", "=>", "'email'", ",", "'website'", "=>", "'url'", ",", "'nickname'", "=>", "'alternatename'", ",", "'picture'", "=>", "'picture'", ",", "'address'", "=>", "'address'", ",", "'phone'", "=>", "'phone1'", ",", "'locale'", "=>", "'lang'", "]", ";", "foreach", "(", "$", "mapping", "as", "$", "external", "=>", "$", "internal", ")", "{", "$", "record", "=", "(", "object", ")", "[", "'issuerid'", "=>", "$", "issuer", "->", "get", "(", "'id'", ")", ",", "'externalfield'", "=>", "$", "external", ",", "'internalfield'", "=>", "$", "internal", "]", ";", "$", "userfieldmapping", "=", "new", "user_field_mapping", "(", "0", ",", "$", "record", ")", ";", "$", "userfieldmapping", "->", "create", "(", ")", ";", "}", "return", "endpoint", "::", "count_records", "(", "[", "'issuerid'", "=>", "$", "issuer", "->", "get", "(", "'id'", ")", "]", ")", ";", "}" ]
If the discovery endpoint exists for this issuer, try and determine the list of valid endpoints. @param issuer $issuer @return int The number of discovered services.
[ "If", "the", "discovery", "endpoint", "exists", "for", "this", "issuer", "try", "and", "determine", "the", "list", "of", "valid", "endpoints", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L535-L614
214,199
moodle/moodle
lib/classes/oauth2/api.php
api.update_issuer
public static function update_issuer($data) { require_capability('moodle/site:config', context_system::instance()); $issuer = new issuer(0, $data); // Will throw exceptions on validation failures. $issuer->update(); // Perform service discovery. self::discover_endpoints($issuer); self::guess_image($issuer); return $issuer; }
php
public static function update_issuer($data) { require_capability('moodle/site:config', context_system::instance()); $issuer = new issuer(0, $data); // Will throw exceptions on validation failures. $issuer->update(); // Perform service discovery. self::discover_endpoints($issuer); self::guess_image($issuer); return $issuer; }
[ "public", "static", "function", "update_issuer", "(", "$", "data", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "$", "issuer", "=", "new", "issuer", "(", "0", ",", "$", "data", ")", ";", "// Will throw exceptions on validation failures.", "$", "issuer", "->", "update", "(", ")", ";", "// Perform service discovery.", "self", "::", "discover_endpoints", "(", "$", "issuer", ")", ";", "self", "::", "guess_image", "(", "$", "issuer", ")", ";", "return", "$", "issuer", ";", "}" ]
Take the data from the mform and update the issuer. @param stdClass $data @return \core\oauth2\issuer
[ "Take", "the", "data", "from", "the", "mform", "and", "update", "the", "issuer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L622-L633