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,200
moodle/moodle
lib/classes/oauth2/api.php
api.create_issuer
public static function create_issuer($data) { require_capability('moodle/site:config', context_system::instance()); $issuer = new issuer(0, $data); // Will throw exceptions on validation failures. $issuer->create(); // Perform service discovery. self::discover_endpoints($issuer); self::guess_image($issuer); return $issuer; }
php
public static function create_issuer($data) { require_capability('moodle/site:config', context_system::instance()); $issuer = new issuer(0, $data); // Will throw exceptions on validation failures. $issuer->create(); // Perform service discovery. self::discover_endpoints($issuer); self::guess_image($issuer); return $issuer; }
[ "public", "static", "function", "create_issuer", "(", "$", "data", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "$", "issuer", "=", "new", "issuer", "(", "0", ",", "$", "data", ")", ";", "// Will throw exceptions on validation failures.", "$", "issuer", "->", "create", "(", ")", ";", "// Perform service discovery.", "self", "::", "discover_endpoints", "(", "$", "issuer", ")", ";", "self", "::", "guess_image", "(", "$", "issuer", ")", ";", "return", "$", "issuer", ";", "}" ]
Take the data from the mform and create the issuer. @param stdClass $data @return \core\oauth2\issuer
[ "Take", "the", "data", "from", "the", "mform", "and", "create", "the", "issuer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L641-L652
214,201
moodle/moodle
lib/classes/oauth2/api.php
api.update_endpoint
public static function update_endpoint($data) { require_capability('moodle/site:config', context_system::instance()); $endpoint = new endpoint(0, $data); // Will throw exceptions on validation failures. $endpoint->update(); return $endpoint; }
php
public static function update_endpoint($data) { require_capability('moodle/site:config', context_system::instance()); $endpoint = new endpoint(0, $data); // Will throw exceptions on validation failures. $endpoint->update(); return $endpoint; }
[ "public", "static", "function", "update_endpoint", "(", "$", "data", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "$", "endpoint", "=", "new", "endpoint", "(", "0", ",", "$", "data", ")", ";", "// Will throw exceptions on validation failures.", "$", "endpoint", "->", "update", "(", ")", ";", "return", "$", "endpoint", ";", "}" ]
Take the data from the mform and update the endpoint. @param stdClass $data @return \core\oauth2\endpoint
[ "Take", "the", "data", "from", "the", "mform", "and", "update", "the", "endpoint", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L660-L668
214,202
moodle/moodle
lib/classes/oauth2/api.php
api.create_endpoint
public static function create_endpoint($data) { require_capability('moodle/site:config', context_system::instance()); $endpoint = new endpoint(0, $data); // Will throw exceptions on validation failures. $endpoint->create(); return $endpoint; }
php
public static function create_endpoint($data) { require_capability('moodle/site:config', context_system::instance()); $endpoint = new endpoint(0, $data); // Will throw exceptions on validation failures. $endpoint->create(); return $endpoint; }
[ "public", "static", "function", "create_endpoint", "(", "$", "data", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "$", "endpoint", "=", "new", "endpoint", "(", "0", ",", "$", "data", ")", ";", "// Will throw exceptions on validation failures.", "$", "endpoint", "->", "create", "(", ")", ";", "return", "$", "endpoint", ";", "}" ]
Take the data from the mform and create the endpoint. @param stdClass $data @return \core\oauth2\endpoint
[ "Take", "the", "data", "from", "the", "mform", "and", "create", "the", "endpoint", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L676-L683
214,203
moodle/moodle
lib/classes/oauth2/api.php
api.update_user_field_mapping
public static function update_user_field_mapping($data) { require_capability('moodle/site:config', context_system::instance()); $userfieldmapping = new user_field_mapping(0, $data); // Will throw exceptions on validation failures. $userfieldmapping->update(); return $userfieldmapping; }
php
public static function update_user_field_mapping($data) { require_capability('moodle/site:config', context_system::instance()); $userfieldmapping = new user_field_mapping(0, $data); // Will throw exceptions on validation failures. $userfieldmapping->update(); return $userfieldmapping; }
[ "public", "static", "function", "update_user_field_mapping", "(", "$", "data", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "$", "userfieldmapping", "=", "new", "user_field_mapping", "(", "0", ",", "$", "data", ")", ";", "// Will throw exceptions on validation failures.", "$", "userfieldmapping", "->", "update", "(", ")", ";", "return", "$", "userfieldmapping", ";", "}" ]
Take the data from the mform and update the user field mapping. @param stdClass $data @return \core\oauth2\user_field_mapping
[ "Take", "the", "data", "from", "the", "mform", "and", "update", "the", "user", "field", "mapping", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L691-L699
214,204
moodle/moodle
lib/classes/oauth2/api.php
api.create_user_field_mapping
public static function create_user_field_mapping($data) { require_capability('moodle/site:config', context_system::instance()); $userfieldmapping = new user_field_mapping(0, $data); // Will throw exceptions on validation failures. $userfieldmapping->create(); return $userfieldmapping; }
php
public static function create_user_field_mapping($data) { require_capability('moodle/site:config', context_system::instance()); $userfieldmapping = new user_field_mapping(0, $data); // Will throw exceptions on validation failures. $userfieldmapping->create(); return $userfieldmapping; }
[ "public", "static", "function", "create_user_field_mapping", "(", "$", "data", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "$", "userfieldmapping", "=", "new", "user_field_mapping", "(", "0", ",", "$", "data", ")", ";", "// Will throw exceptions on validation failures.", "$", "userfieldmapping", "->", "create", "(", ")", ";", "return", "$", "userfieldmapping", ";", "}" ]
Take the data from the mform and create the user field mapping. @param stdClass $data @return \core\oauth2\user_field_mapping
[ "Take", "the", "data", "from", "the", "mform", "and", "create", "the", "user", "field", "mapping", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L707-L714
214,205
moodle/moodle
lib/classes/oauth2/api.php
api.move_up_issuer
public static function move_up_issuer($id) { require_capability('moodle/site:config', context_system::instance()); $current = new issuer($id); $sortorder = $current->get('sortorder'); if ($sortorder == 0) { return false; } $sortorder = $sortorder - 1; $current->set('sortorder', $sortorder); $filters = array('sortorder' => $sortorder); $children = issuer::get_records($filters, 'id'); foreach ($children as $needtoswap) { $needtoswap->set('sortorder', $sortorder + 1); $needtoswap->update(); } // OK - all set. $result = $current->update(); return $result; }
php
public static function move_up_issuer($id) { require_capability('moodle/site:config', context_system::instance()); $current = new issuer($id); $sortorder = $current->get('sortorder'); if ($sortorder == 0) { return false; } $sortorder = $sortorder - 1; $current->set('sortorder', $sortorder); $filters = array('sortorder' => $sortorder); $children = issuer::get_records($filters, 'id'); foreach ($children as $needtoswap) { $needtoswap->set('sortorder', $sortorder + 1); $needtoswap->update(); } // OK - all set. $result = $current->update(); return $result; }
[ "public", "static", "function", "move_up_issuer", "(", "$", "id", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "$", "current", "=", "new", "issuer", "(", "$", "id", ")", ";", "$", "sortorder", "=", "$", "current", "->", "get", "(", "'sortorder'", ")", ";", "if", "(", "$", "sortorder", "==", "0", ")", "{", "return", "false", ";", "}", "$", "sortorder", "=", "$", "sortorder", "-", "1", ";", "$", "current", "->", "set", "(", "'sortorder'", ",", "$", "sortorder", ")", ";", "$", "filters", "=", "array", "(", "'sortorder'", "=>", "$", "sortorder", ")", ";", "$", "children", "=", "issuer", "::", "get_records", "(", "$", "filters", ",", "'id'", ")", ";", "foreach", "(", "$", "children", "as", "$", "needtoswap", ")", "{", "$", "needtoswap", "->", "set", "(", "'sortorder'", ",", "$", "sortorder", "+", "1", ")", ";", "$", "needtoswap", "->", "update", "(", ")", ";", "}", "// OK - all set.", "$", "result", "=", "$", "current", "->", "update", "(", ")", ";", "return", "$", "result", ";", "}" ]
Reorder this identity issuer. Requires moodle/site:config capability at the system context. @param int $id The id of the identity issuer to move. @return boolean
[ "Reorder", "this", "identity", "issuer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L724-L747
214,206
moodle/moodle
lib/classes/oauth2/api.php
api.disable_issuer
public static function disable_issuer($id) { require_capability('moodle/site:config', context_system::instance()); $issuer = new issuer($id); $issuer->set('enabled', 0); return $issuer->update(); }
php
public static function disable_issuer($id) { require_capability('moodle/site:config', context_system::instance()); $issuer = new issuer($id); $issuer->set('enabled', 0); return $issuer->update(); }
[ "public", "static", "function", "disable_issuer", "(", "$", "id", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "$", "issuer", "=", "new", "issuer", "(", "$", "id", ")", ";", "$", "issuer", "->", "set", "(", "'enabled'", ",", "0", ")", ";", "return", "$", "issuer", "->", "update", "(", ")", ";", "}" ]
Disable an identity issuer. Requires moodle/site:config capability at the system context. @param int $id The id of the identity issuer to disable. @return boolean
[ "Disable", "an", "identity", "issuer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L794-L800
214,207
moodle/moodle
lib/classes/oauth2/api.php
api.enable_issuer
public static function enable_issuer($id) { require_capability('moodle/site:config', context_system::instance()); $issuer = new issuer($id); $issuer->set('enabled', 1); return $issuer->update(); }
php
public static function enable_issuer($id) { require_capability('moodle/site:config', context_system::instance()); $issuer = new issuer($id); $issuer->set('enabled', 1); return $issuer->update(); }
[ "public", "static", "function", "enable_issuer", "(", "$", "id", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "$", "issuer", "=", "new", "issuer", "(", "$", "id", ")", ";", "$", "issuer", "->", "set", "(", "'enabled'", ",", "1", ")", ";", "return", "$", "issuer", "->", "update", "(", ")", ";", "}" ]
Enable an identity issuer. Requires moodle/site:config capability at the system context. @param int $id The id of the identity issuer to enable. @return boolean
[ "Enable", "an", "identity", "issuer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L811-L817
214,208
moodle/moodle
lib/classes/oauth2/api.php
api.delete_issuer
public static function delete_issuer($id) { require_capability('moodle/site:config', context_system::instance()); $issuer = new issuer($id); $systemaccount = self::get_system_account($issuer); if ($systemaccount) { $systemaccount->delete(); } $endpoints = self::get_endpoints($issuer); if ($endpoints) { foreach ($endpoints as $endpoint) { $endpoint->delete(); } } // Will throw exceptions on validation failures. return $issuer->delete(); }
php
public static function delete_issuer($id) { require_capability('moodle/site:config', context_system::instance()); $issuer = new issuer($id); $systemaccount = self::get_system_account($issuer); if ($systemaccount) { $systemaccount->delete(); } $endpoints = self::get_endpoints($issuer); if ($endpoints) { foreach ($endpoints as $endpoint) { $endpoint->delete(); } } // Will throw exceptions on validation failures. return $issuer->delete(); }
[ "public", "static", "function", "delete_issuer", "(", "$", "id", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "$", "issuer", "=", "new", "issuer", "(", "$", "id", ")", ";", "$", "systemaccount", "=", "self", "::", "get_system_account", "(", "$", "issuer", ")", ";", "if", "(", "$", "systemaccount", ")", "{", "$", "systemaccount", "->", "delete", "(", ")", ";", "}", "$", "endpoints", "=", "self", "::", "get_endpoints", "(", "$", "issuer", ")", ";", "if", "(", "$", "endpoints", ")", "{", "foreach", "(", "$", "endpoints", "as", "$", "endpoint", ")", "{", "$", "endpoint", "->", "delete", "(", ")", ";", "}", "}", "// Will throw exceptions on validation failures.", "return", "$", "issuer", "->", "delete", "(", ")", ";", "}" ]
Delete an identity issuer. Requires moodle/site:config capability at the system context. @param int $id The id of the identity issuer to delete. @return boolean
[ "Delete", "an", "identity", "issuer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L827-L844
214,209
moodle/moodle
lib/classes/oauth2/api.php
api.delete_endpoint
public static function delete_endpoint($id) { require_capability('moodle/site:config', context_system::instance()); $endpoint = new endpoint($id); // Will throw exceptions on validation failures. return $endpoint->delete(); }
php
public static function delete_endpoint($id) { require_capability('moodle/site:config', context_system::instance()); $endpoint = new endpoint($id); // Will throw exceptions on validation failures. return $endpoint->delete(); }
[ "public", "static", "function", "delete_endpoint", "(", "$", "id", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "$", "endpoint", "=", "new", "endpoint", "(", "$", "id", ")", ";", "// Will throw exceptions on validation failures.", "return", "$", "endpoint", "->", "delete", "(", ")", ";", "}" ]
Delete an endpoint. Requires moodle/site:config capability at the system context. @param int $id The id of the endpoint to delete. @return boolean
[ "Delete", "an", "endpoint", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L854-L860
214,210
moodle/moodle
lib/classes/oauth2/api.php
api.delete_user_field_mapping
public static function delete_user_field_mapping($id) { require_capability('moodle/site:config', context_system::instance()); $userfieldmapping = new user_field_mapping($id); // Will throw exceptions on validation failures. return $userfieldmapping->delete(); }
php
public static function delete_user_field_mapping($id) { require_capability('moodle/site:config', context_system::instance()); $userfieldmapping = new user_field_mapping($id); // Will throw exceptions on validation failures. return $userfieldmapping->delete(); }
[ "public", "static", "function", "delete_user_field_mapping", "(", "$", "id", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "$", "userfieldmapping", "=", "new", "user_field_mapping", "(", "$", "id", ")", ";", "// Will throw exceptions on validation failures.", "return", "$", "userfieldmapping", "->", "delete", "(", ")", ";", "}" ]
Delete a user_field_mapping. Requires moodle/site:config capability at the system context. @param int $id The id of the user_field_mapping to delete. @return boolean
[ "Delete", "a", "user_field_mapping", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L870-L876
214,211
moodle/moodle
lib/classes/oauth2/api.php
api.connect_system_account
public static function connect_system_account($issuer, $returnurl) { require_capability('moodle/site:config', context_system::instance()); // We need to authenticate with an oauth 2 client AS a system user and get a refresh token for offline access. $scopes = self::get_system_scopes_for_issuer($issuer); // Allow callbacks to inject non-standard scopes to the auth request. $client = new client($issuer, $returnurl, $scopes, true); if (!optional_param('response', false, PARAM_BOOL)) { $client->log_out(); } if (optional_param('error', '', PARAM_RAW)) { return false; } if (!$client->is_logged_in()) { redirect($client->get_login_url()); } $refreshtoken = $client->get_refresh_token(); if (!$refreshtoken) { return false; } $systemaccount = self::get_system_account($issuer); if ($systemaccount) { $systemaccount->delete(); } $userinfo = $client->get_userinfo(); $record = new stdClass(); $record->issuerid = $issuer->get('id'); $record->refreshtoken = $refreshtoken; $record->grantedscopes = $scopes; $record->email = isset($userinfo['email']) ? $userinfo['email'] : ''; $record->username = $userinfo['username']; $systemaccount = new system_account(0, $record); $systemaccount->create(); $client->log_out(); return true; }
php
public static function connect_system_account($issuer, $returnurl) { require_capability('moodle/site:config', context_system::instance()); // We need to authenticate with an oauth 2 client AS a system user and get a refresh token for offline access. $scopes = self::get_system_scopes_for_issuer($issuer); // Allow callbacks to inject non-standard scopes to the auth request. $client = new client($issuer, $returnurl, $scopes, true); if (!optional_param('response', false, PARAM_BOOL)) { $client->log_out(); } if (optional_param('error', '', PARAM_RAW)) { return false; } if (!$client->is_logged_in()) { redirect($client->get_login_url()); } $refreshtoken = $client->get_refresh_token(); if (!$refreshtoken) { return false; } $systemaccount = self::get_system_account($issuer); if ($systemaccount) { $systemaccount->delete(); } $userinfo = $client->get_userinfo(); $record = new stdClass(); $record->issuerid = $issuer->get('id'); $record->refreshtoken = $refreshtoken; $record->grantedscopes = $scopes; $record->email = isset($userinfo['email']) ? $userinfo['email'] : ''; $record->username = $userinfo['username']; $systemaccount = new system_account(0, $record); $systemaccount->create(); $client->log_out(); return true; }
[ "public", "static", "function", "connect_system_account", "(", "$", "issuer", ",", "$", "returnurl", ")", "{", "require_capability", "(", "'moodle/site:config'", ",", "context_system", "::", "instance", "(", ")", ")", ";", "// We need to authenticate with an oauth 2 client AS a system user and get a refresh token for offline access.", "$", "scopes", "=", "self", "::", "get_system_scopes_for_issuer", "(", "$", "issuer", ")", ";", "// Allow callbacks to inject non-standard scopes to the auth request.", "$", "client", "=", "new", "client", "(", "$", "issuer", ",", "$", "returnurl", ",", "$", "scopes", ",", "true", ")", ";", "if", "(", "!", "optional_param", "(", "'response'", ",", "false", ",", "PARAM_BOOL", ")", ")", "{", "$", "client", "->", "log_out", "(", ")", ";", "}", "if", "(", "optional_param", "(", "'error'", ",", "''", ",", "PARAM_RAW", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "client", "->", "is_logged_in", "(", ")", ")", "{", "redirect", "(", "$", "client", "->", "get_login_url", "(", ")", ")", ";", "}", "$", "refreshtoken", "=", "$", "client", "->", "get_refresh_token", "(", ")", ";", "if", "(", "!", "$", "refreshtoken", ")", "{", "return", "false", ";", "}", "$", "systemaccount", "=", "self", "::", "get_system_account", "(", "$", "issuer", ")", ";", "if", "(", "$", "systemaccount", ")", "{", "$", "systemaccount", "->", "delete", "(", ")", ";", "}", "$", "userinfo", "=", "$", "client", "->", "get_userinfo", "(", ")", ";", "$", "record", "=", "new", "stdClass", "(", ")", ";", "$", "record", "->", "issuerid", "=", "$", "issuer", "->", "get", "(", "'id'", ")", ";", "$", "record", "->", "refreshtoken", "=", "$", "refreshtoken", ";", "$", "record", "->", "grantedscopes", "=", "$", "scopes", ";", "$", "record", "->", "email", "=", "isset", "(", "$", "userinfo", "[", "'email'", "]", ")", "?", "$", "userinfo", "[", "'email'", "]", ":", "''", ";", "$", "record", "->", "username", "=", "$", "userinfo", "[", "'username'", "]", ";", "$", "systemaccount", "=", "new", "system_account", "(", "0", ",", "$", "record", ")", ";", "$", "systemaccount", "->", "create", "(", ")", ";", "$", "client", "->", "log_out", "(", ")", ";", "return", "true", ";", "}" ]
Perform the OAuth dance and get a refresh token. Requires moodle/site:config capability at the system context. @param \core\oauth2\issuer $issuer @param moodle_url $returnurl The url to the current page (we will be redirected back here after authentication). @return boolean
[ "Perform", "the", "OAuth", "dance", "and", "get", "a", "refresh", "token", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/api.php#L887-L934
214,212
moodle/moodle
mod/forum/classes/output/forum_post.php
forum_post.get_permalink
public function get_permalink() { $link = $this->_get_discussionlink(); $link->set_anchor($this->get_postanchor()); return $link->out(false); }
php
public function get_permalink() { $link = $this->_get_discussionlink(); $link->set_anchor($this->get_postanchor()); return $link->out(false); }
[ "public", "function", "get_permalink", "(", ")", "{", "$", "link", "=", "$", "this", "->", "_get_discussionlink", "(", ")", ";", "$", "link", "->", "set_anchor", "(", "$", "this", "->", "get_postanchor", "(", ")", ")", ";", "return", "$", "link", "->", "out", "(", "false", ")", ";", "}" ]
Get the link to the current post, including post anchor. @return string
[ "Get", "the", "link", "to", "the", "current", "post", "including", "post", "anchor", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/output/forum_post.php#L354-L359
214,213
moodle/moodle
mod/forum/classes/output/forum_post.php
forum_post.get_parentpostlink
public function get_parentpostlink() { $link = $this->_get_discussionlink(); $link->param('parent', $this->post->parent); return $link->out(false); }
php
public function get_parentpostlink() { $link = $this->_get_discussionlink(); $link->param('parent', $this->post->parent); return $link->out(false); }
[ "public", "function", "get_parentpostlink", "(", ")", "{", "$", "link", "=", "$", "this", "->", "_get_discussionlink", "(", ")", ";", "$", "link", "->", "param", "(", "'parent'", ",", "$", "this", "->", "post", "->", "parent", ")", ";", "return", "$", "link", "->", "out", "(", "false", ")", ";", "}" ]
Get the link to the parent post. @return string
[ "Get", "the", "link", "to", "the", "parent", "post", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/output/forum_post.php#L366-L371
214,214
moodle/moodle
mod/forum/classes/output/forum_post.php
forum_post.get_authorlink
public function get_authorlink() { $link = new \moodle_url( '/user/view.php', array( 'id' => $this->post->userid, 'course' => $this->course->id, ) ); return $link->out(false); }
php
public function get_authorlink() { $link = new \moodle_url( '/user/view.php', array( 'id' => $this->post->userid, 'course' => $this->course->id, ) ); return $link->out(false); }
[ "public", "function", "get_authorlink", "(", ")", "{", "$", "link", "=", "new", "\\", "moodle_url", "(", "'/user/view.php'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "post", "->", "userid", ",", "'course'", "=>", "$", "this", "->", "course", "->", "id", ",", ")", ")", ";", "return", "$", "link", "->", "out", "(", "false", ")", ";", "}" ]
Get the link to the author's profile page. @return string
[ "Get", "the", "link", "to", "the", "author", "s", "profile", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/output/forum_post.php#L378-L387
214,215
moodle/moodle
mod/forum/classes/output/forum_post.php
forum_post.get_unsubscribeforumlink
public function get_unsubscribeforumlink() { if (!\mod_forum\subscriptions::is_subscribable($this->forum)) { return null; } $link = new \moodle_url( '/mod/forum/subscribe.php', array( 'id' => $this->forum->id, ) ); return $link->out(false); }
php
public function get_unsubscribeforumlink() { if (!\mod_forum\subscriptions::is_subscribable($this->forum)) { return null; } $link = new \moodle_url( '/mod/forum/subscribe.php', array( 'id' => $this->forum->id, ) ); return $link->out(false); }
[ "public", "function", "get_unsubscribeforumlink", "(", ")", "{", "if", "(", "!", "\\", "mod_forum", "\\", "subscriptions", "::", "is_subscribable", "(", "$", "this", "->", "forum", ")", ")", "{", "return", "null", ";", "}", "$", "link", "=", "new", "\\", "moodle_url", "(", "'/mod/forum/subscribe.php'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "forum", "->", "id", ",", ")", ")", ";", "return", "$", "link", "->", "out", "(", "false", ")", ";", "}" ]
Get the link to unsubscribe from the forum. @return string
[ "Get", "the", "link", "to", "unsubscribe", "from", "the", "forum", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/output/forum_post.php#L394-L405
214,216
moodle/moodle
mod/forum/classes/output/forum_post.php
forum_post.get_unsubscribediscussionlink
public function get_unsubscribediscussionlink() { if (!\mod_forum\subscriptions::is_subscribable($this->forum)) { return null; } $link = new \moodle_url( '/mod/forum/subscribe.php', array( 'id' => $this->forum->id, 'd' => $this->discussion->id, ) ); return $link->out(false); }
php
public function get_unsubscribediscussionlink() { if (!\mod_forum\subscriptions::is_subscribable($this->forum)) { return null; } $link = new \moodle_url( '/mod/forum/subscribe.php', array( 'id' => $this->forum->id, 'd' => $this->discussion->id, ) ); return $link->out(false); }
[ "public", "function", "get_unsubscribediscussionlink", "(", ")", "{", "if", "(", "!", "\\", "mod_forum", "\\", "subscriptions", "::", "is_subscribable", "(", "$", "this", "->", "forum", ")", ")", "{", "return", "null", ";", "}", "$", "link", "=", "new", "\\", "moodle_url", "(", "'/mod/forum/subscribe.php'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "forum", "->", "id", ",", "'d'", "=>", "$", "this", "->", "discussion", "->", "id", ",", ")", ")", ";", "return", "$", "link", "->", "out", "(", "false", ")", ";", "}" ]
Get the link to unsubscribe from the discussion. @return string
[ "Get", "the", "link", "to", "unsubscribe", "from", "the", "discussion", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/output/forum_post.php#L412-L424
214,217
moodle/moodle
mod/forum/classes/output/forum_post.php
forum_post.get_coursefullname
public function get_coursefullname() { return format_string($this->course->fullname, true, array( 'context' => \context_course::instance($this->course->id), )); }
php
public function get_coursefullname() { return format_string($this->course->fullname, true, array( 'context' => \context_course::instance($this->course->id), )); }
[ "public", "function", "get_coursefullname", "(", ")", "{", "return", "format_string", "(", "$", "this", "->", "course", "->", "fullname", ",", "true", ",", "array", "(", "'context'", "=>", "\\", "context_course", "::", "instance", "(", "$", "this", "->", "course", "->", "id", ")", ",", ")", ")", ";", "}" ]
The full name of the course that the forum is in. @return string
[ "The", "full", "name", "of", "the", "course", "that", "the", "forum", "is", "in", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/output/forum_post.php#L471-L475
214,218
moodle/moodle
mod/forum/classes/output/forum_post.php
forum_post.get_coursename
public function get_coursename() { return format_string($this->course->shortname, true, array( 'context' => \context_course::instance($this->course->id), )); }
php
public function get_coursename() { return format_string($this->course->shortname, true, array( 'context' => \context_course::instance($this->course->id), )); }
[ "public", "function", "get_coursename", "(", ")", "{", "return", "format_string", "(", "$", "this", "->", "course", "->", "shortname", ",", "true", ",", "array", "(", "'context'", "=>", "\\", "context_course", "::", "instance", "(", "$", "this", "->", "course", "->", "id", ")", ",", ")", ")", ";", "}" ]
The name of the course that the forum is in. @return string
[ "The", "name", "of", "the", "course", "that", "the", "forum", "is", "in", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/output/forum_post.php#L482-L486
214,219
moodle/moodle
mod/forum/classes/output/forum_post.php
forum_post.get_postdate
public function get_postdate() { global $CFG; $postmodified = $this->post->modified; if (!empty($CFG->forum_enabletimedposts) && ($this->discussion->timestart > $postmodified)) { $postmodified = $this->discussion->timestart; } return userdate($postmodified, "", \core_date::get_user_timezone($this->get_postto())); }
php
public function get_postdate() { global $CFG; $postmodified = $this->post->modified; if (!empty($CFG->forum_enabletimedposts) && ($this->discussion->timestart > $postmodified)) { $postmodified = $this->discussion->timestart; } return userdate($postmodified, "", \core_date::get_user_timezone($this->get_postto())); }
[ "public", "function", "get_postdate", "(", ")", "{", "global", "$", "CFG", ";", "$", "postmodified", "=", "$", "this", "->", "post", "->", "modified", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "forum_enabletimedposts", ")", "&&", "(", "$", "this", "->", "discussion", "->", "timestart", ">", "$", "postmodified", ")", ")", "{", "$", "postmodified", "=", "$", "this", "->", "discussion", "->", "timestart", ";", "}", "return", "userdate", "(", "$", "postmodified", ",", "\"\"", ",", "\\", "core_date", "::", "get_user_timezone", "(", "$", "this", "->", "get_postto", "(", ")", ")", ")", ";", "}" ]
The date of the post, formatted according to the postto user's preferences. @return string.
[ "The", "date", "of", "the", "post", "formatted", "according", "to", "the", "postto", "user", "s", "preferences", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/output/forum_post.php#L546-L555
214,220
moodle/moodle
mod/forum/classes/output/forum_post.php
forum_post.get_author_picture
public function get_author_picture(\renderer_base $renderer) { return $renderer->user_picture($this->author, array('courseid' => $this->course->id)); }
php
public function get_author_picture(\renderer_base $renderer) { return $renderer->user_picture($this->author, array('courseid' => $this->course->id)); }
[ "public", "function", "get_author_picture", "(", "\\", "renderer_base", "$", "renderer", ")", "{", "return", "$", "renderer", "->", "user_picture", "(", "$", "this", "->", "author", ",", "array", "(", "'courseid'", "=>", "$", "this", "->", "course", "->", "id", ")", ")", ";", "}" ]
The HTML for the author's user picture. @param \renderer_base $renderer @return string
[ "The", "HTML", "for", "the", "author", "s", "user", "picture", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/output/forum_post.php#L563-L565
214,221
moodle/moodle
mod/forum/classes/output/forum_post.php
forum_post.get_group_picture
public function get_group_picture(\renderer_base $renderer) { if (isset($this->userfrom->groups)) { $groups = $this->userfrom->groups[$this->forum->id]; } else { $groups = groups_get_all_groups($this->course->id, $this->author->id, $this->cm->groupingid); } if ($this->get_is_firstpost()) { return print_group_picture($groups, $this->course->id, false, true, true, true); } }
php
public function get_group_picture(\renderer_base $renderer) { if (isset($this->userfrom->groups)) { $groups = $this->userfrom->groups[$this->forum->id]; } else { $groups = groups_get_all_groups($this->course->id, $this->author->id, $this->cm->groupingid); } if ($this->get_is_firstpost()) { return print_group_picture($groups, $this->course->id, false, true, true, true); } }
[ "public", "function", "get_group_picture", "(", "\\", "renderer_base", "$", "renderer", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "userfrom", "->", "groups", ")", ")", "{", "$", "groups", "=", "$", "this", "->", "userfrom", "->", "groups", "[", "$", "this", "->", "forum", "->", "id", "]", ";", "}", "else", "{", "$", "groups", "=", "groups_get_all_groups", "(", "$", "this", "->", "course", "->", "id", ",", "$", "this", "->", "author", "->", "id", ",", "$", "this", "->", "cm", "->", "groupingid", ")", ";", "}", "if", "(", "$", "this", "->", "get_is_firstpost", "(", ")", ")", "{", "return", "print_group_picture", "(", "$", "groups", ",", "$", "this", "->", "course", "->", "id", ",", "false", ",", "true", ",", "true", ",", "true", ")", ";", "}", "}" ]
The HTML for a group picture. @param \renderer_base $renderer @return string
[ "The", "HTML", "for", "a", "group", "picture", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/output/forum_post.php#L573-L583
214,222
moodle/moodle
admin/tool/log/classes/helper/buffered_writer.php
buffered_writer.flush
public function flush() { if ($this->count == 0) { return; } $events = $this->buffer; $this->count = 0; $this->buffer = array(); $this->insert_event_entries($events); }
php
public function flush() { if ($this->count == 0) { return; } $events = $this->buffer; $this->count = 0; $this->buffer = array(); $this->insert_event_entries($events); }
[ "public", "function", "flush", "(", ")", "{", "if", "(", "$", "this", "->", "count", "==", "0", ")", "{", "return", ";", "}", "$", "events", "=", "$", "this", "->", "buffer", ";", "$", "this", "->", "count", "=", "0", ";", "$", "this", "->", "buffer", "=", "array", "(", ")", ";", "$", "this", "->", "insert_event_entries", "(", "$", "events", ")", ";", "}" ]
Flush event buffer.
[ "Flush", "event", "buffer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/classes/helper/buffered_writer.php#L99-L107
214,223
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.validate_quiz
protected static function validate_quiz($quizid) { global $DB; // Request and permission validation. $quiz = $DB->get_record('quiz', array('id' => $quizid), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($quiz, 'quiz'); $context = context_module::instance($cm->id); self::validate_context($context); return array($quiz, $course, $cm, $context); }
php
protected static function validate_quiz($quizid) { global $DB; // Request and permission validation. $quiz = $DB->get_record('quiz', array('id' => $quizid), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($quiz, 'quiz'); $context = context_module::instance($cm->id); self::validate_context($context); return array($quiz, $course, $cm, $context); }
[ "protected", "static", "function", "validate_quiz", "(", "$", "quizid", ")", "{", "global", "$", "DB", ";", "// Request and permission validation.", "$", "quiz", "=", "$", "DB", "->", "get_record", "(", "'quiz'", ",", "array", "(", "'id'", "=>", "$", "quizid", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "list", "(", "$", "course", ",", "$", "cm", ")", "=", "get_course_and_cm_from_instance", "(", "$", "quiz", ",", "'quiz'", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "return", "array", "(", "$", "quiz", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", ";", "}" ]
Utility function for validating a quiz. @param int $quizid quiz instance id @return array array containing the quiz, course, context and course module objects @since Moodle 3.1
[ "Utility", "function", "for", "validating", "a", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L287-L298
214,224
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_user_attempts_parameters
public static function get_user_attempts_parameters() { return new external_function_parameters ( array( 'quizid' => new external_value(PARAM_INT, 'quiz instance id'), 'userid' => new external_value(PARAM_INT, 'user id, empty for current user', VALUE_DEFAULT, 0), 'status' => new external_value(PARAM_ALPHA, 'quiz status: all, finished or unfinished', VALUE_DEFAULT, 'finished'), 'includepreviews' => new external_value(PARAM_BOOL, 'whether to include previews or not', VALUE_DEFAULT, false), ) ); }
php
public static function get_user_attempts_parameters() { return new external_function_parameters ( array( 'quizid' => new external_value(PARAM_INT, 'quiz instance id'), 'userid' => new external_value(PARAM_INT, 'user id, empty for current user', VALUE_DEFAULT, 0), 'status' => new external_value(PARAM_ALPHA, 'quiz status: all, finished or unfinished', VALUE_DEFAULT, 'finished'), 'includepreviews' => new external_value(PARAM_BOOL, 'whether to include previews or not', VALUE_DEFAULT, false), ) ); }
[ "public", "static", "function", "get_user_attempts_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'quizid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'quiz instance id'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'user id, empty for current user'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'status'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'quiz status: all, finished or unfinished'", ",", "VALUE_DEFAULT", ",", "'finished'", ")", ",", "'includepreviews'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'whether to include previews or not'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for get_user_attempts. @return external_function_parameters @since Moodle 3.1
[ "Describes", "the", "parameters", "for", "get_user_attempts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L360-L370
214,225
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_user_attempts
public static function get_user_attempts($quizid, $userid = 0, $status = 'finished', $includepreviews = false) { global $DB, $USER; $warnings = array(); $params = array( 'quizid' => $quizid, 'userid' => $userid, 'status' => $status, 'includepreviews' => $includepreviews, ); $params = self::validate_parameters(self::get_user_attempts_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); if (!in_array($params['status'], array('all', 'finished', 'unfinished'))) { throw new invalid_parameter_exception('Invalid status value'); } // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $user->id) { require_capability('mod/quiz:viewreports', $context); } $attempts = quiz_get_user_attempts($quiz->id, $user->id, $params['status'], $params['includepreviews']); $result = array(); $result['attempts'] = $attempts; $result['warnings'] = $warnings; return $result; }
php
public static function get_user_attempts($quizid, $userid = 0, $status = 'finished', $includepreviews = false) { global $DB, $USER; $warnings = array(); $params = array( 'quizid' => $quizid, 'userid' => $userid, 'status' => $status, 'includepreviews' => $includepreviews, ); $params = self::validate_parameters(self::get_user_attempts_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); if (!in_array($params['status'], array('all', 'finished', 'unfinished'))) { throw new invalid_parameter_exception('Invalid status value'); } // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $user->id) { require_capability('mod/quiz:viewreports', $context); } $attempts = quiz_get_user_attempts($quiz->id, $user->id, $params['status'], $params['includepreviews']); $result = array(); $result['attempts'] = $attempts; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_user_attempts", "(", "$", "quizid", ",", "$", "userid", "=", "0", ",", "$", "status", "=", "'finished'", ",", "$", "includepreviews", "=", "false", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'quizid'", "=>", "$", "quizid", ",", "'userid'", "=>", "$", "userid", ",", "'status'", "=>", "$", "status", ",", "'includepreviews'", "=>", "$", "includepreviews", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_user_attempts_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "quiz", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_quiz", "(", "$", "params", "[", "'quizid'", "]", ")", ";", "if", "(", "!", "in_array", "(", "$", "params", "[", "'status'", "]", ",", "array", "(", "'all'", ",", "'finished'", ",", "'unfinished'", ")", ")", ")", "{", "throw", "new", "invalid_parameter_exception", "(", "'Invalid status value'", ")", ";", "}", "// Default value for userid.", "if", "(", "empty", "(", "$", "params", "[", "'userid'", "]", ")", ")", "{", "$", "params", "[", "'userid'", "]", "=", "$", "USER", "->", "id", ";", "}", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "params", "[", "'userid'", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "core_user", "::", "require_active_user", "(", "$", "user", ")", ";", "// Extra checks so only users with permissions can view other users attempts.", "if", "(", "$", "USER", "->", "id", "!=", "$", "user", "->", "id", ")", "{", "require_capability", "(", "'mod/quiz:viewreports'", ",", "$", "context", ")", ";", "}", "$", "attempts", "=", "quiz_get_user_attempts", "(", "$", "quiz", "->", "id", ",", "$", "user", "->", "id", ",", "$", "params", "[", "'status'", "]", ",", "$", "params", "[", "'includepreviews'", "]", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'attempts'", "]", "=", "$", "attempts", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Return a list of attempts for the given quiz and user. @param int $quizid quiz instance id @param int $userid user id @param string $status quiz status: all, finished or unfinished @param bool $includepreviews whether to include previews or not @return array of warnings and the list of attempts @since Moodle 3.1 @throws invalid_parameter_exception
[ "Return", "a", "list", "of", "attempts", "for", "the", "given", "quiz", "and", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L383-L421
214,226
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.attempt_structure
private static function attempt_structure() { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Attempt id.', VALUE_OPTIONAL), 'quiz' => new external_value(PARAM_INT, 'Foreign key reference to the quiz that was attempted.', VALUE_OPTIONAL), 'userid' => new external_value(PARAM_INT, 'Foreign key reference to the user whose attempt this is.', VALUE_OPTIONAL), 'attempt' => new external_value(PARAM_INT, 'Sequentially numbers this students attempts at this quiz.', VALUE_OPTIONAL), 'uniqueid' => new external_value(PARAM_INT, 'Foreign key reference to the question_usage that holds the details of the the question_attempts that make up this quiz attempt.', VALUE_OPTIONAL), 'layout' => new external_value(PARAM_RAW, 'Attempt layout.', VALUE_OPTIONAL), 'currentpage' => new external_value(PARAM_INT, 'Attempt current page.', VALUE_OPTIONAL), 'preview' => new external_value(PARAM_INT, 'Whether is a preview attempt or not.', VALUE_OPTIONAL), 'state' => new external_value(PARAM_ALPHA, 'The current state of the attempts. \'inprogress\', \'overdue\', \'finished\' or \'abandoned\'.', VALUE_OPTIONAL), 'timestart' => new external_value(PARAM_INT, 'Time when the attempt was started.', VALUE_OPTIONAL), 'timefinish' => new external_value(PARAM_INT, 'Time when the attempt was submitted. 0 if the attempt has not been submitted yet.', VALUE_OPTIONAL), 'timemodified' => new external_value(PARAM_INT, 'Last modified time.', VALUE_OPTIONAL), 'timemodifiedoffline' => new external_value(PARAM_INT, 'Last modified time via webservices.', VALUE_OPTIONAL), 'timecheckstate' => new external_value(PARAM_INT, 'Next time quiz cron should check attempt for state changes. NULL means never check.', VALUE_OPTIONAL), 'sumgrades' => new external_value(PARAM_FLOAT, 'Total marks for this attempt.', VALUE_OPTIONAL), ) ); }
php
private static function attempt_structure() { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Attempt id.', VALUE_OPTIONAL), 'quiz' => new external_value(PARAM_INT, 'Foreign key reference to the quiz that was attempted.', VALUE_OPTIONAL), 'userid' => new external_value(PARAM_INT, 'Foreign key reference to the user whose attempt this is.', VALUE_OPTIONAL), 'attempt' => new external_value(PARAM_INT, 'Sequentially numbers this students attempts at this quiz.', VALUE_OPTIONAL), 'uniqueid' => new external_value(PARAM_INT, 'Foreign key reference to the question_usage that holds the details of the the question_attempts that make up this quiz attempt.', VALUE_OPTIONAL), 'layout' => new external_value(PARAM_RAW, 'Attempt layout.', VALUE_OPTIONAL), 'currentpage' => new external_value(PARAM_INT, 'Attempt current page.', VALUE_OPTIONAL), 'preview' => new external_value(PARAM_INT, 'Whether is a preview attempt or not.', VALUE_OPTIONAL), 'state' => new external_value(PARAM_ALPHA, 'The current state of the attempts. \'inprogress\', \'overdue\', \'finished\' or \'abandoned\'.', VALUE_OPTIONAL), 'timestart' => new external_value(PARAM_INT, 'Time when the attempt was started.', VALUE_OPTIONAL), 'timefinish' => new external_value(PARAM_INT, 'Time when the attempt was submitted. 0 if the attempt has not been submitted yet.', VALUE_OPTIONAL), 'timemodified' => new external_value(PARAM_INT, 'Last modified time.', VALUE_OPTIONAL), 'timemodifiedoffline' => new external_value(PARAM_INT, 'Last modified time via webservices.', VALUE_OPTIONAL), 'timecheckstate' => new external_value(PARAM_INT, 'Next time quiz cron should check attempt for state changes. NULL means never check.', VALUE_OPTIONAL), 'sumgrades' => new external_value(PARAM_FLOAT, 'Total marks for this attempt.', VALUE_OPTIONAL), ) ); }
[ "private", "static", "function", "attempt_structure", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Attempt id.'", ",", "VALUE_OPTIONAL", ")", ",", "'quiz'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Foreign key reference to the quiz that was attempted.'", ",", "VALUE_OPTIONAL", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Foreign key reference to the user whose attempt this is.'", ",", "VALUE_OPTIONAL", ")", ",", "'attempt'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Sequentially numbers this students attempts at this quiz.'", ",", "VALUE_OPTIONAL", ")", ",", "'uniqueid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Foreign key reference to the question_usage that holds the\n details of the the question_attempts that make up this quiz\n attempt.'", ",", "VALUE_OPTIONAL", ")", ",", "'layout'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Attempt layout.'", ",", "VALUE_OPTIONAL", ")", ",", "'currentpage'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Attempt current page.'", ",", "VALUE_OPTIONAL", ")", ",", "'preview'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Whether is a preview attempt or not.'", ",", "VALUE_OPTIONAL", ")", ",", "'state'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'The current state of the attempts. \\'inprogress\\',\n \\'overdue\\', \\'finished\\' or \\'abandoned\\'.'", ",", "VALUE_OPTIONAL", ")", ",", "'timestart'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time when the attempt was started.'", ",", "VALUE_OPTIONAL", ")", ",", "'timefinish'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time when the attempt was submitted.\n 0 if the attempt has not been submitted yet.'", ",", "VALUE_OPTIONAL", ")", ",", "'timemodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Last modified time.'", ",", "VALUE_OPTIONAL", ")", ",", "'timemodifiedoffline'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Last modified time via webservices.'", ",", "VALUE_OPTIONAL", ")", ",", "'timecheckstate'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Next time quiz cron should check attempt for\n state changes. NULL means never check.'", ",", "VALUE_OPTIONAL", ")", ",", "'sumgrades'", "=>", "new", "external_value", "(", "PARAM_FLOAT", ",", "'Total marks for this attempt.'", ",", "VALUE_OPTIONAL", ")", ",", ")", ")", ";", "}" ]
Describes a single attempt structure. @return external_single_structure the attempt structure
[ "Describes", "a", "single", "attempt", "structure", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L428-L456
214,227
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_user_best_grade
public static function get_user_best_grade($quizid, $userid = 0) { global $DB, $USER; $warnings = array(); $params = array( 'quizid' => $quizid, 'userid' => $userid, ); $params = self::validate_parameters(self::get_user_best_grade_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $user->id) { require_capability('mod/quiz:viewreports', $context); } $result = array(); $grade = quiz_get_best_grade($quiz, $user->id); if ($grade === null) { $result['hasgrade'] = false; } else { $result['hasgrade'] = true; $result['grade'] = $grade; } $result['warnings'] = $warnings; return $result; }
php
public static function get_user_best_grade($quizid, $userid = 0) { global $DB, $USER; $warnings = array(); $params = array( 'quizid' => $quizid, 'userid' => $userid, ); $params = self::validate_parameters(self::get_user_best_grade_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $user->id) { require_capability('mod/quiz:viewreports', $context); } $result = array(); $grade = quiz_get_best_grade($quiz, $user->id); if ($grade === null) { $result['hasgrade'] = false; } else { $result['hasgrade'] = true; $result['grade'] = $grade; } $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_user_best_grade", "(", "$", "quizid", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'quizid'", "=>", "$", "quizid", ",", "'userid'", "=>", "$", "userid", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_user_best_grade_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "quiz", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_quiz", "(", "$", "params", "[", "'quizid'", "]", ")", ";", "// Default value for userid.", "if", "(", "empty", "(", "$", "params", "[", "'userid'", "]", ")", ")", "{", "$", "params", "[", "'userid'", "]", "=", "$", "USER", "->", "id", ";", "}", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "params", "[", "'userid'", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "core_user", "::", "require_active_user", "(", "$", "user", ")", ";", "// Extra checks so only users with permissions can view other users attempts.", "if", "(", "$", "USER", "->", "id", "!=", "$", "user", "->", "id", ")", "{", "require_capability", "(", "'mod/quiz:viewreports'", ",", "$", "context", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "grade", "=", "quiz_get_best_grade", "(", "$", "quiz", ",", "$", "user", "->", "id", ")", ";", "if", "(", "$", "grade", "===", "null", ")", "{", "$", "result", "[", "'hasgrade'", "]", "=", "false", ";", "}", "else", "{", "$", "result", "[", "'hasgrade'", "]", "=", "true", ";", "$", "result", "[", "'grade'", "]", "=", "$", "grade", ";", "}", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Get the best current grade for the given user on a quiz. @param int $quizid quiz instance id @param int $userid user id @return array of warnings and the grade information @since Moodle 3.1
[ "Get", "the", "best", "current", "grade", "for", "the", "given", "user", "on", "a", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L496-L533
214,228
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_combined_review_options
public static function get_combined_review_options($quizid, $userid = 0) { global $DB, $USER; $warnings = array(); $params = array( 'quizid' => $quizid, 'userid' => $userid, ); $params = self::validate_parameters(self::get_combined_review_options_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $user->id) { require_capability('mod/quiz:viewreports', $context); } $attempts = quiz_get_user_attempts($quiz->id, $user->id, 'all', true); $result = array(); $result['someoptions'] = []; $result['alloptions'] = []; list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts); foreach (array('someoptions', 'alloptions') as $typeofoption) { foreach ($$typeofoption as $key => $value) { $result[$typeofoption][] = array( "name" => $key, "value" => (!empty($value)) ? $value : 0 ); } } $result['warnings'] = $warnings; return $result; }
php
public static function get_combined_review_options($quizid, $userid = 0) { global $DB, $USER; $warnings = array(); $params = array( 'quizid' => $quizid, 'userid' => $userid, ); $params = self::validate_parameters(self::get_combined_review_options_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); // Default value for userid. if (empty($params['userid'])) { $params['userid'] = $USER->id; } $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $user->id) { require_capability('mod/quiz:viewreports', $context); } $attempts = quiz_get_user_attempts($quiz->id, $user->id, 'all', true); $result = array(); $result['someoptions'] = []; $result['alloptions'] = []; list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts); foreach (array('someoptions', 'alloptions') as $typeofoption) { foreach ($$typeofoption as $key => $value) { $result[$typeofoption][] = array( "name" => $key, "value" => (!empty($value)) ? $value : 0 ); } } $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_combined_review_options", "(", "$", "quizid", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'quizid'", "=>", "$", "quizid", ",", "'userid'", "=>", "$", "userid", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_combined_review_options_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "quiz", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_quiz", "(", "$", "params", "[", "'quizid'", "]", ")", ";", "// Default value for userid.", "if", "(", "empty", "(", "$", "params", "[", "'userid'", "]", ")", ")", "{", "$", "params", "[", "'userid'", "]", "=", "$", "USER", "->", "id", ";", "}", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "params", "[", "'userid'", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "core_user", "::", "require_active_user", "(", "$", "user", ")", ";", "// Extra checks so only users with permissions can view other users attempts.", "if", "(", "$", "USER", "->", "id", "!=", "$", "user", "->", "id", ")", "{", "require_capability", "(", "'mod/quiz:viewreports'", ",", "$", "context", ")", ";", "}", "$", "attempts", "=", "quiz_get_user_attempts", "(", "$", "quiz", "->", "id", ",", "$", "user", "->", "id", ",", "'all'", ",", "true", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'someoptions'", "]", "=", "[", "]", ";", "$", "result", "[", "'alloptions'", "]", "=", "[", "]", ";", "list", "(", "$", "someoptions", ",", "$", "alloptions", ")", "=", "quiz_get_combined_reviewoptions", "(", "$", "quiz", ",", "$", "attempts", ")", ";", "foreach", "(", "array", "(", "'someoptions'", ",", "'alloptions'", ")", "as", "$", "typeofoption", ")", "{", "foreach", "(", "$", "$", "typeofoption", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "result", "[", "$", "typeofoption", "]", "[", "]", "=", "array", "(", "\"name\"", "=>", "$", "key", ",", "\"value\"", "=>", "(", "!", "empty", "(", "$", "value", ")", ")", "?", "$", "value", ":", "0", ")", ";", "}", "}", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Combines the review options from a number of different quiz attempts. @param int $quizid quiz instance id @param int $userid user id (empty for current user) @return array of warnings and the review options @since Moodle 3.1
[ "Combines", "the", "review", "options", "from", "a", "number", "of", "different", "quiz", "attempts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L575-L620
214,229
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_combined_review_options_returns
public static function get_combined_review_options_returns() { return new external_single_structure( array( 'someoptions' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'option name'), 'value' => new external_value(PARAM_INT, 'option value'), ) ) ), 'alloptions' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'option name'), 'value' => new external_value(PARAM_INT, 'option value'), ) ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_combined_review_options_returns() { return new external_single_structure( array( 'someoptions' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'option name'), 'value' => new external_value(PARAM_INT, 'option value'), ) ) ), 'alloptions' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'option name'), 'value' => new external_value(PARAM_INT, 'option value'), ) ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_combined_review_options_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'someoptions'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'name'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'option name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'option value'", ")", ",", ")", ")", ")", ",", "'alloptions'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'name'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'option name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'option value'", ")", ",", ")", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_combined_review_options return value. @return external_single_structure @since Moodle 3.1
[ "Describes", "the", "get_combined_review_options", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L628-L650
214,230
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.start_attempt_parameters
public static function start_attempt_parameters() { return new external_function_parameters ( array( 'quizid' => new external_value(PARAM_INT, 'quiz instance id'), 'preflightdata' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() ), 'forcenew' => new external_value(PARAM_BOOL, 'Whether to force a new attempt or not.', VALUE_DEFAULT, false), ) ); }
php
public static function start_attempt_parameters() { return new external_function_parameters ( array( 'quizid' => new external_value(PARAM_INT, 'quiz instance id'), 'preflightdata' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() ), 'forcenew' => new external_value(PARAM_BOOL, 'Whether to force a new attempt or not.', VALUE_DEFAULT, false), ) ); }
[ "public", "static", "function", "start_attempt_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'quizid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'quiz instance id'", ")", ",", "'preflightdata'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'name'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'data name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'data value'", ")", ",", ")", ")", ",", "'Preflight required data (like passwords)'", ",", "VALUE_DEFAULT", ",", "array", "(", ")", ")", ",", "'forcenew'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether to force a new attempt or not.'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for start_attempt. @return external_function_parameters @since Moodle 3.1
[ "Describes", "the", "parameters", "for", "start_attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L658-L674
214,231
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.start_attempt
public static function start_attempt($quizid, $preflightdata = array(), $forcenew = false) { global $DB, $USER; $warnings = array(); $attempt = array(); $params = array( 'quizid' => $quizid, 'preflightdata' => $preflightdata, 'forcenew' => $forcenew, ); $params = self::validate_parameters(self::start_attempt_parameters(), $params); $forcenew = $params['forcenew']; list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); $quizobj = quiz::create($cm->instance, $USER->id); // Check questions. if (!$quizobj->has_questions()) { throw new moodle_quiz_exception($quizobj, 'noquestionsfound'); } // Create an object to manage all the other (non-roles) access rules. $timenow = time(); $accessmanager = $quizobj->get_access_manager($timenow); // Validate permissions for creating a new attempt and start a new preview attempt if required. list($currentattemptid, $attemptnumber, $lastattempt, $messages, $page) = quiz_validate_new_attempt($quizobj, $accessmanager, $forcenew, -1, false); // Check access. if (!$quizobj->is_preview_user() && $messages) { // Create warnings with the exact messages. foreach ($messages as $message) { $warnings[] = array( 'item' => 'quiz', 'itemid' => $quiz->id, 'warningcode' => '1', 'message' => clean_text($message, PARAM_TEXT) ); } } else { if ($accessmanager->is_preflight_check_required($currentattemptid)) { // Need to do some checks before allowing the user to continue. $provideddata = array(); foreach ($params['preflightdata'] as $data) { $provideddata[$data['name']] = $data['value']; } $errors = $accessmanager->validate_preflight_check($provideddata, [], $currentattemptid); if (!empty($errors)) { throw new moodle_quiz_exception($quizobj, array_shift($errors)); } // Pre-flight check passed. $accessmanager->notify_preflight_check_passed($currentattemptid); } if ($currentattemptid) { if ($lastattempt->state == quiz_attempt::OVERDUE) { throw new moodle_quiz_exception($quizobj, 'stateoverdue'); } else { throw new moodle_quiz_exception($quizobj, 'attemptstillinprogress'); } } $offlineattempt = WS_SERVER ? true : false; $attempt = quiz_prepare_and_start_new_attempt($quizobj, $attemptnumber, $lastattempt, $offlineattempt); } $result = array(); $result['attempt'] = $attempt; $result['warnings'] = $warnings; return $result; }
php
public static function start_attempt($quizid, $preflightdata = array(), $forcenew = false) { global $DB, $USER; $warnings = array(); $attempt = array(); $params = array( 'quizid' => $quizid, 'preflightdata' => $preflightdata, 'forcenew' => $forcenew, ); $params = self::validate_parameters(self::start_attempt_parameters(), $params); $forcenew = $params['forcenew']; list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); $quizobj = quiz::create($cm->instance, $USER->id); // Check questions. if (!$quizobj->has_questions()) { throw new moodle_quiz_exception($quizobj, 'noquestionsfound'); } // Create an object to manage all the other (non-roles) access rules. $timenow = time(); $accessmanager = $quizobj->get_access_manager($timenow); // Validate permissions for creating a new attempt and start a new preview attempt if required. list($currentattemptid, $attemptnumber, $lastattempt, $messages, $page) = quiz_validate_new_attempt($quizobj, $accessmanager, $forcenew, -1, false); // Check access. if (!$quizobj->is_preview_user() && $messages) { // Create warnings with the exact messages. foreach ($messages as $message) { $warnings[] = array( 'item' => 'quiz', 'itemid' => $quiz->id, 'warningcode' => '1', 'message' => clean_text($message, PARAM_TEXT) ); } } else { if ($accessmanager->is_preflight_check_required($currentattemptid)) { // Need to do some checks before allowing the user to continue. $provideddata = array(); foreach ($params['preflightdata'] as $data) { $provideddata[$data['name']] = $data['value']; } $errors = $accessmanager->validate_preflight_check($provideddata, [], $currentattemptid); if (!empty($errors)) { throw new moodle_quiz_exception($quizobj, array_shift($errors)); } // Pre-flight check passed. $accessmanager->notify_preflight_check_passed($currentattemptid); } if ($currentattemptid) { if ($lastattempt->state == quiz_attempt::OVERDUE) { throw new moodle_quiz_exception($quizobj, 'stateoverdue'); } else { throw new moodle_quiz_exception($quizobj, 'attemptstillinprogress'); } } $offlineattempt = WS_SERVER ? true : false; $attempt = quiz_prepare_and_start_new_attempt($quizobj, $attemptnumber, $lastattempt, $offlineattempt); } $result = array(); $result['attempt'] = $attempt; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "start_attempt", "(", "$", "quizid", ",", "$", "preflightdata", "=", "array", "(", ")", ",", "$", "forcenew", "=", "false", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "attempt", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'quizid'", "=>", "$", "quizid", ",", "'preflightdata'", "=>", "$", "preflightdata", ",", "'forcenew'", "=>", "$", "forcenew", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "start_attempt_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "forcenew", "=", "$", "params", "[", "'forcenew'", "]", ";", "list", "(", "$", "quiz", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_quiz", "(", "$", "params", "[", "'quizid'", "]", ")", ";", "$", "quizobj", "=", "quiz", "::", "create", "(", "$", "cm", "->", "instance", ",", "$", "USER", "->", "id", ")", ";", "// Check questions.", "if", "(", "!", "$", "quizobj", "->", "has_questions", "(", ")", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "quizobj", ",", "'noquestionsfound'", ")", ";", "}", "// Create an object to manage all the other (non-roles) access rules.", "$", "timenow", "=", "time", "(", ")", ";", "$", "accessmanager", "=", "$", "quizobj", "->", "get_access_manager", "(", "$", "timenow", ")", ";", "// Validate permissions for creating a new attempt and start a new preview attempt if required.", "list", "(", "$", "currentattemptid", ",", "$", "attemptnumber", ",", "$", "lastattempt", ",", "$", "messages", ",", "$", "page", ")", "=", "quiz_validate_new_attempt", "(", "$", "quizobj", ",", "$", "accessmanager", ",", "$", "forcenew", ",", "-", "1", ",", "false", ")", ";", "// Check access.", "if", "(", "!", "$", "quizobj", "->", "is_preview_user", "(", ")", "&&", "$", "messages", ")", "{", "// Create warnings with the exact messages.", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "$", "warnings", "[", "]", "=", "array", "(", "'item'", "=>", "'quiz'", ",", "'itemid'", "=>", "$", "quiz", "->", "id", ",", "'warningcode'", "=>", "'1'", ",", "'message'", "=>", "clean_text", "(", "$", "message", ",", "PARAM_TEXT", ")", ")", ";", "}", "}", "else", "{", "if", "(", "$", "accessmanager", "->", "is_preflight_check_required", "(", "$", "currentattemptid", ")", ")", "{", "// Need to do some checks before allowing the user to continue.", "$", "provideddata", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "[", "'preflightdata'", "]", "as", "$", "data", ")", "{", "$", "provideddata", "[", "$", "data", "[", "'name'", "]", "]", "=", "$", "data", "[", "'value'", "]", ";", "}", "$", "errors", "=", "$", "accessmanager", "->", "validate_preflight_check", "(", "$", "provideddata", ",", "[", "]", ",", "$", "currentattemptid", ")", ";", "if", "(", "!", "empty", "(", "$", "errors", ")", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "quizobj", ",", "array_shift", "(", "$", "errors", ")", ")", ";", "}", "// Pre-flight check passed.", "$", "accessmanager", "->", "notify_preflight_check_passed", "(", "$", "currentattemptid", ")", ";", "}", "if", "(", "$", "currentattemptid", ")", "{", "if", "(", "$", "lastattempt", "->", "state", "==", "quiz_attempt", "::", "OVERDUE", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "quizobj", ",", "'stateoverdue'", ")", ";", "}", "else", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "quizobj", ",", "'attemptstillinprogress'", ")", ";", "}", "}", "$", "offlineattempt", "=", "WS_SERVER", "?", "true", ":", "false", ";", "$", "attempt", "=", "quiz_prepare_and_start_new_attempt", "(", "$", "quizobj", ",", "$", "attemptnumber", ",", "$", "lastattempt", ",", "$", "offlineattempt", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'attempt'", "]", "=", "$", "attempt", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Starts a new attempt at a quiz. @param int $quizid quiz instance id @param array $preflightdata preflight required data (like passwords) @param bool $forcenew Whether to force a new attempt or not. @return array of warnings and the attempt basic data @since Moodle 3.1 @throws moodle_quiz_exception
[ "Starts", "a", "new", "attempt", "at", "a", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L686-L762
214,232
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.validate_attempt
protected static function validate_attempt($params, $checkaccessrules = true, $failifoverdue = true) { global $USER; $attemptobj = quiz_attempt::create($params['attemptid']); $context = context_module::instance($attemptobj->get_cm()->id); self::validate_context($context); // Check that this attempt belongs to this user. if ($attemptobj->get_userid() != $USER->id) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt'); } // General capabilities check. $ispreviewuser = $attemptobj->is_preview_user(); if (!$ispreviewuser) { $attemptobj->require_capability('mod/quiz:attempt'); } // Check the access rules. $accessmanager = $attemptobj->get_access_manager(time()); $messages = array(); if ($checkaccessrules) { // If the attempt is now overdue, or abandoned, deal with that. $attemptobj->handle_if_time_expired(time(), true); $messages = $accessmanager->prevent_access(); if (!$ispreviewuser && $messages) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'attempterror'); } } // Attempt closed?. if ($attemptobj->is_finished()) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'attemptalreadyclosed'); } else if ($failifoverdue && $attemptobj->get_state() == quiz_attempt::OVERDUE) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'stateoverdue'); } // User submitted data (like the quiz password). if ($accessmanager->is_preflight_check_required($attemptobj->get_attemptid())) { $provideddata = array(); foreach ($params['preflightdata'] as $data) { $provideddata[$data['name']] = $data['value']; } $errors = $accessmanager->validate_preflight_check($provideddata, [], $params['attemptid']); if (!empty($errors)) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), array_shift($errors)); } // Pre-flight check passed. $accessmanager->notify_preflight_check_passed($params['attemptid']); } if (isset($params['page'])) { // Check if the page is out of range. if ($params['page'] != $attemptobj->force_page_number_into_range($params['page'])) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'Invalid page number'); } // Prevent out of sequence access. if (!$attemptobj->check_page_access($params['page'])) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'Out of sequence access'); } // Check slots. $slots = $attemptobj->get_slots($params['page']); if (empty($slots)) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noquestionsfound'); } } return array($attemptobj, $messages); }
php
protected static function validate_attempt($params, $checkaccessrules = true, $failifoverdue = true) { global $USER; $attemptobj = quiz_attempt::create($params['attemptid']); $context = context_module::instance($attemptobj->get_cm()->id); self::validate_context($context); // Check that this attempt belongs to this user. if ($attemptobj->get_userid() != $USER->id) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt'); } // General capabilities check. $ispreviewuser = $attemptobj->is_preview_user(); if (!$ispreviewuser) { $attemptobj->require_capability('mod/quiz:attempt'); } // Check the access rules. $accessmanager = $attemptobj->get_access_manager(time()); $messages = array(); if ($checkaccessrules) { // If the attempt is now overdue, or abandoned, deal with that. $attemptobj->handle_if_time_expired(time(), true); $messages = $accessmanager->prevent_access(); if (!$ispreviewuser && $messages) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'attempterror'); } } // Attempt closed?. if ($attemptobj->is_finished()) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'attemptalreadyclosed'); } else if ($failifoverdue && $attemptobj->get_state() == quiz_attempt::OVERDUE) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'stateoverdue'); } // User submitted data (like the quiz password). if ($accessmanager->is_preflight_check_required($attemptobj->get_attemptid())) { $provideddata = array(); foreach ($params['preflightdata'] as $data) { $provideddata[$data['name']] = $data['value']; } $errors = $accessmanager->validate_preflight_check($provideddata, [], $params['attemptid']); if (!empty($errors)) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), array_shift($errors)); } // Pre-flight check passed. $accessmanager->notify_preflight_check_passed($params['attemptid']); } if (isset($params['page'])) { // Check if the page is out of range. if ($params['page'] != $attemptobj->force_page_number_into_range($params['page'])) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'Invalid page number'); } // Prevent out of sequence access. if (!$attemptobj->check_page_access($params['page'])) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'Out of sequence access'); } // Check slots. $slots = $attemptobj->get_slots($params['page']); if (empty($slots)) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noquestionsfound'); } } return array($attemptobj, $messages); }
[ "protected", "static", "function", "validate_attempt", "(", "$", "params", ",", "$", "checkaccessrules", "=", "true", ",", "$", "failifoverdue", "=", "true", ")", "{", "global", "$", "USER", ";", "$", "attemptobj", "=", "quiz_attempt", "::", "create", "(", "$", "params", "[", "'attemptid'", "]", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "attemptobj", "->", "get_cm", "(", ")", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "// Check that this attempt belongs to this user.", "if", "(", "$", "attemptobj", "->", "get_userid", "(", ")", "!=", "$", "USER", "->", "id", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "attemptobj", "->", "get_quizobj", "(", ")", ",", "'notyourattempt'", ")", ";", "}", "// General capabilities check.", "$", "ispreviewuser", "=", "$", "attemptobj", "->", "is_preview_user", "(", ")", ";", "if", "(", "!", "$", "ispreviewuser", ")", "{", "$", "attemptobj", "->", "require_capability", "(", "'mod/quiz:attempt'", ")", ";", "}", "// Check the access rules.", "$", "accessmanager", "=", "$", "attemptobj", "->", "get_access_manager", "(", "time", "(", ")", ")", ";", "$", "messages", "=", "array", "(", ")", ";", "if", "(", "$", "checkaccessrules", ")", "{", "// If the attempt is now overdue, or abandoned, deal with that.", "$", "attemptobj", "->", "handle_if_time_expired", "(", "time", "(", ")", ",", "true", ")", ";", "$", "messages", "=", "$", "accessmanager", "->", "prevent_access", "(", ")", ";", "if", "(", "!", "$", "ispreviewuser", "&&", "$", "messages", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "attemptobj", "->", "get_quizobj", "(", ")", ",", "'attempterror'", ")", ";", "}", "}", "// Attempt closed?.", "if", "(", "$", "attemptobj", "->", "is_finished", "(", ")", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "attemptobj", "->", "get_quizobj", "(", ")", ",", "'attemptalreadyclosed'", ")", ";", "}", "else", "if", "(", "$", "failifoverdue", "&&", "$", "attemptobj", "->", "get_state", "(", ")", "==", "quiz_attempt", "::", "OVERDUE", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "attemptobj", "->", "get_quizobj", "(", ")", ",", "'stateoverdue'", ")", ";", "}", "// User submitted data (like the quiz password).", "if", "(", "$", "accessmanager", "->", "is_preflight_check_required", "(", "$", "attemptobj", "->", "get_attemptid", "(", ")", ")", ")", "{", "$", "provideddata", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "[", "'preflightdata'", "]", "as", "$", "data", ")", "{", "$", "provideddata", "[", "$", "data", "[", "'name'", "]", "]", "=", "$", "data", "[", "'value'", "]", ";", "}", "$", "errors", "=", "$", "accessmanager", "->", "validate_preflight_check", "(", "$", "provideddata", ",", "[", "]", ",", "$", "params", "[", "'attemptid'", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "errors", ")", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "attemptobj", "->", "get_quizobj", "(", ")", ",", "array_shift", "(", "$", "errors", ")", ")", ";", "}", "// Pre-flight check passed.", "$", "accessmanager", "->", "notify_preflight_check_passed", "(", "$", "params", "[", "'attemptid'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "params", "[", "'page'", "]", ")", ")", "{", "// Check if the page is out of range.", "if", "(", "$", "params", "[", "'page'", "]", "!=", "$", "attemptobj", "->", "force_page_number_into_range", "(", "$", "params", "[", "'page'", "]", ")", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "attemptobj", "->", "get_quizobj", "(", ")", ",", "'Invalid page number'", ")", ";", "}", "// Prevent out of sequence access.", "if", "(", "!", "$", "attemptobj", "->", "check_page_access", "(", "$", "params", "[", "'page'", "]", ")", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "attemptobj", "->", "get_quizobj", "(", ")", ",", "'Out of sequence access'", ")", ";", "}", "// Check slots.", "$", "slots", "=", "$", "attemptobj", "->", "get_slots", "(", "$", "params", "[", "'page'", "]", ")", ";", "if", "(", "empty", "(", "$", "slots", ")", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "attemptobj", "->", "get_quizobj", "(", ")", ",", "'noquestionsfound'", ")", ";", "}", "}", "return", "array", "(", "$", "attemptobj", ",", "$", "messages", ")", ";", "}" ]
Utility function for validating a given attempt @param array $params array of parameters including the attemptid and preflight data @param bool $checkaccessrules whether to check the quiz access rules or not @param bool $failifoverdue whether to return error if the attempt is overdue @return array containing the attempt object and access messages @throws moodle_quiz_exception @since Moodle 3.1
[ "Utility", "function", "for", "validating", "a", "given", "attempt" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L789-L863
214,233
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.question_structure
private static function question_structure() { return new external_single_structure( array( 'slot' => new external_value(PARAM_INT, 'slot number'), 'type' => new external_value(PARAM_ALPHANUMEXT, 'question type, i.e: multichoice'), 'page' => new external_value(PARAM_INT, 'page of the quiz this question appears on'), 'html' => new external_value(PARAM_RAW, 'the question rendered'), 'sequencecheck' => new external_value(PARAM_INT, 'the number of real steps in this attempt', VALUE_OPTIONAL), 'lastactiontime' => new external_value(PARAM_INT, 'the timestamp of the most recent step in this question attempt', VALUE_OPTIONAL), 'hasautosavedstep' => new external_value(PARAM_BOOL, 'whether this question attempt has autosaved data', VALUE_OPTIONAL), 'flagged' => new external_value(PARAM_BOOL, 'whether the question is flagged or not'), 'number' => new external_value(PARAM_INT, 'question ordering number in the quiz', VALUE_OPTIONAL), 'state' => new external_value(PARAM_ALPHA, 'the state where the question is in. It will not be returned if the user cannot see it due to the quiz display correctness settings.', VALUE_OPTIONAL), 'status' => new external_value(PARAM_RAW, 'current formatted state of the question', VALUE_OPTIONAL), 'blockedbyprevious' => new external_value(PARAM_BOOL, 'whether the question is blocked by the previous question', VALUE_OPTIONAL), 'mark' => new external_value(PARAM_RAW, 'the mark awarded. It will be returned only if the user is allowed to see it.', VALUE_OPTIONAL), 'maxmark' => new external_value(PARAM_FLOAT, 'the maximum mark possible for this question attempt. It will be returned only if the user is allowed to see it.', VALUE_OPTIONAL), ), 'The question data. Some fields may not be returned depending on the quiz display settings.' ); }
php
private static function question_structure() { return new external_single_structure( array( 'slot' => new external_value(PARAM_INT, 'slot number'), 'type' => new external_value(PARAM_ALPHANUMEXT, 'question type, i.e: multichoice'), 'page' => new external_value(PARAM_INT, 'page of the quiz this question appears on'), 'html' => new external_value(PARAM_RAW, 'the question rendered'), 'sequencecheck' => new external_value(PARAM_INT, 'the number of real steps in this attempt', VALUE_OPTIONAL), 'lastactiontime' => new external_value(PARAM_INT, 'the timestamp of the most recent step in this question attempt', VALUE_OPTIONAL), 'hasautosavedstep' => new external_value(PARAM_BOOL, 'whether this question attempt has autosaved data', VALUE_OPTIONAL), 'flagged' => new external_value(PARAM_BOOL, 'whether the question is flagged or not'), 'number' => new external_value(PARAM_INT, 'question ordering number in the quiz', VALUE_OPTIONAL), 'state' => new external_value(PARAM_ALPHA, 'the state where the question is in. It will not be returned if the user cannot see it due to the quiz display correctness settings.', VALUE_OPTIONAL), 'status' => new external_value(PARAM_RAW, 'current formatted state of the question', VALUE_OPTIONAL), 'blockedbyprevious' => new external_value(PARAM_BOOL, 'whether the question is blocked by the previous question', VALUE_OPTIONAL), 'mark' => new external_value(PARAM_RAW, 'the mark awarded. It will be returned only if the user is allowed to see it.', VALUE_OPTIONAL), 'maxmark' => new external_value(PARAM_FLOAT, 'the maximum mark possible for this question attempt. It will be returned only if the user is allowed to see it.', VALUE_OPTIONAL), ), 'The question data. Some fields may not be returned depending on the quiz display settings.' ); }
[ "private", "static", "function", "question_structure", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'slot'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'slot number'", ")", ",", "'type'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'question type, i.e: multichoice'", ")", ",", "'page'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'page of the quiz this question appears on'", ")", ",", "'html'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'the question rendered'", ")", ",", "'sequencecheck'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'the number of real steps in this attempt'", ",", "VALUE_OPTIONAL", ")", ",", "'lastactiontime'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'the timestamp of the most recent step in this question attempt'", ",", "VALUE_OPTIONAL", ")", ",", "'hasautosavedstep'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'whether this question attempt has autosaved data'", ",", "VALUE_OPTIONAL", ")", ",", "'flagged'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'whether the question is flagged or not'", ")", ",", "'number'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'question ordering number in the quiz'", ",", "VALUE_OPTIONAL", ")", ",", "'state'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'the state where the question is in.\n It will not be returned if the user cannot see it due to the quiz display correctness settings.'", ",", "VALUE_OPTIONAL", ")", ",", "'status'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'current formatted state of the question'", ",", "VALUE_OPTIONAL", ")", ",", "'blockedbyprevious'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'whether the question is blocked by the previous question'", ",", "VALUE_OPTIONAL", ")", ",", "'mark'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'the mark awarded.\n It will be returned only if the user is allowed to see it.'", ",", "VALUE_OPTIONAL", ")", ",", "'maxmark'", "=>", "new", "external_value", "(", "PARAM_FLOAT", ",", "'the maximum mark possible for this question attempt.\n It will be returned only if the user is allowed to see it.'", ",", "VALUE_OPTIONAL", ")", ",", ")", ",", "'The question data. Some fields may not be returned depending on the quiz display settings.'", ")", ";", "}" ]
Describes a single question structure. @return external_single_structure the question data. Some fields may not be returned depending on the quiz display settings. @since Moodle 3.1 @since Moodle 3.2 blockedbyprevious parameter added.
[ "Describes", "a", "single", "question", "structure", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L872-L899
214,234
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_attempt_questions_data
private static function get_attempt_questions_data(quiz_attempt $attemptobj, $review, $page = 'all') { global $PAGE; $questions = array(); $contextid = $attemptobj->get_quizobj()->get_context()->id; $displayoptions = $attemptobj->get_display_options($review); $renderer = $PAGE->get_renderer('mod_quiz'); foreach ($attemptobj->get_slots($page) as $slot) { $question = array( 'slot' => $slot, 'type' => $attemptobj->get_question_type_name($slot), 'page' => $attemptobj->get_question_page($slot), 'flagged' => $attemptobj->is_question_flagged($slot), 'html' => $attemptobj->render_question($slot, $review, $renderer) . $PAGE->requires->get_end_code(), 'sequencecheck' => $attemptobj->get_question_attempt($slot)->get_sequence_check_count(), 'lastactiontime' => $attemptobj->get_question_attempt($slot)->get_last_step()->get_timecreated(), 'hasautosavedstep' => $attemptobj->get_question_attempt($slot)->has_autosaved_step() ); if ($attemptobj->is_real_question($slot)) { $question['number'] = $attemptobj->get_question_number($slot); $showcorrectness = $displayoptions->correctness && $attemptobj->get_question_attempt($slot)->has_marks(); if ($showcorrectness) { $question['state'] = (string) $attemptobj->get_question_state($slot); } $question['status'] = $attemptobj->get_question_status($slot, $displayoptions->correctness); $question['blockedbyprevious'] = $attemptobj->is_blocked_by_previous_question($slot); } if ($displayoptions->marks >= question_display_options::MAX_ONLY) { $question['maxmark'] = $attemptobj->get_question_attempt($slot)->get_max_mark(); } if ($displayoptions->marks >= question_display_options::MARK_AND_MAX) { $question['mark'] = $attemptobj->get_question_mark($slot); } $questions[] = $question; } return $questions; }
php
private static function get_attempt_questions_data(quiz_attempt $attemptobj, $review, $page = 'all') { global $PAGE; $questions = array(); $contextid = $attemptobj->get_quizobj()->get_context()->id; $displayoptions = $attemptobj->get_display_options($review); $renderer = $PAGE->get_renderer('mod_quiz'); foreach ($attemptobj->get_slots($page) as $slot) { $question = array( 'slot' => $slot, 'type' => $attemptobj->get_question_type_name($slot), 'page' => $attemptobj->get_question_page($slot), 'flagged' => $attemptobj->is_question_flagged($slot), 'html' => $attemptobj->render_question($slot, $review, $renderer) . $PAGE->requires->get_end_code(), 'sequencecheck' => $attemptobj->get_question_attempt($slot)->get_sequence_check_count(), 'lastactiontime' => $attemptobj->get_question_attempt($slot)->get_last_step()->get_timecreated(), 'hasautosavedstep' => $attemptobj->get_question_attempt($slot)->has_autosaved_step() ); if ($attemptobj->is_real_question($slot)) { $question['number'] = $attemptobj->get_question_number($slot); $showcorrectness = $displayoptions->correctness && $attemptobj->get_question_attempt($slot)->has_marks(); if ($showcorrectness) { $question['state'] = (string) $attemptobj->get_question_state($slot); } $question['status'] = $attemptobj->get_question_status($slot, $displayoptions->correctness); $question['blockedbyprevious'] = $attemptobj->is_blocked_by_previous_question($slot); } if ($displayoptions->marks >= question_display_options::MAX_ONLY) { $question['maxmark'] = $attemptobj->get_question_attempt($slot)->get_max_mark(); } if ($displayoptions->marks >= question_display_options::MARK_AND_MAX) { $question['mark'] = $attemptobj->get_question_mark($slot); } $questions[] = $question; } return $questions; }
[ "private", "static", "function", "get_attempt_questions_data", "(", "quiz_attempt", "$", "attemptobj", ",", "$", "review", ",", "$", "page", "=", "'all'", ")", "{", "global", "$", "PAGE", ";", "$", "questions", "=", "array", "(", ")", ";", "$", "contextid", "=", "$", "attemptobj", "->", "get_quizobj", "(", ")", "->", "get_context", "(", ")", "->", "id", ";", "$", "displayoptions", "=", "$", "attemptobj", "->", "get_display_options", "(", "$", "review", ")", ";", "$", "renderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'mod_quiz'", ")", ";", "foreach", "(", "$", "attemptobj", "->", "get_slots", "(", "$", "page", ")", "as", "$", "slot", ")", "{", "$", "question", "=", "array", "(", "'slot'", "=>", "$", "slot", ",", "'type'", "=>", "$", "attemptobj", "->", "get_question_type_name", "(", "$", "slot", ")", ",", "'page'", "=>", "$", "attemptobj", "->", "get_question_page", "(", "$", "slot", ")", ",", "'flagged'", "=>", "$", "attemptobj", "->", "is_question_flagged", "(", "$", "slot", ")", ",", "'html'", "=>", "$", "attemptobj", "->", "render_question", "(", "$", "slot", ",", "$", "review", ",", "$", "renderer", ")", ".", "$", "PAGE", "->", "requires", "->", "get_end_code", "(", ")", ",", "'sequencecheck'", "=>", "$", "attemptobj", "->", "get_question_attempt", "(", "$", "slot", ")", "->", "get_sequence_check_count", "(", ")", ",", "'lastactiontime'", "=>", "$", "attemptobj", "->", "get_question_attempt", "(", "$", "slot", ")", "->", "get_last_step", "(", ")", "->", "get_timecreated", "(", ")", ",", "'hasautosavedstep'", "=>", "$", "attemptobj", "->", "get_question_attempt", "(", "$", "slot", ")", "->", "has_autosaved_step", "(", ")", ")", ";", "if", "(", "$", "attemptobj", "->", "is_real_question", "(", "$", "slot", ")", ")", "{", "$", "question", "[", "'number'", "]", "=", "$", "attemptobj", "->", "get_question_number", "(", "$", "slot", ")", ";", "$", "showcorrectness", "=", "$", "displayoptions", "->", "correctness", "&&", "$", "attemptobj", "->", "get_question_attempt", "(", "$", "slot", ")", "->", "has_marks", "(", ")", ";", "if", "(", "$", "showcorrectness", ")", "{", "$", "question", "[", "'state'", "]", "=", "(", "string", ")", "$", "attemptobj", "->", "get_question_state", "(", "$", "slot", ")", ";", "}", "$", "question", "[", "'status'", "]", "=", "$", "attemptobj", "->", "get_question_status", "(", "$", "slot", ",", "$", "displayoptions", "->", "correctness", ")", ";", "$", "question", "[", "'blockedbyprevious'", "]", "=", "$", "attemptobj", "->", "is_blocked_by_previous_question", "(", "$", "slot", ")", ";", "}", "if", "(", "$", "displayoptions", "->", "marks", ">=", "question_display_options", "::", "MAX_ONLY", ")", "{", "$", "question", "[", "'maxmark'", "]", "=", "$", "attemptobj", "->", "get_question_attempt", "(", "$", "slot", ")", "->", "get_max_mark", "(", ")", ";", "}", "if", "(", "$", "displayoptions", "->", "marks", ">=", "question_display_options", "::", "MARK_AND_MAX", ")", "{", "$", "question", "[", "'mark'", "]", "=", "$", "attemptobj", "->", "get_question_mark", "(", "$", "slot", ")", ";", "}", "$", "questions", "[", "]", "=", "$", "question", ";", "}", "return", "$", "questions", ";", "}" ]
Return questions information for a given attempt. @param quiz_attempt $attemptobj the quiz attempt object @param bool $review whether if we are in review mode or not @param mixed $page string 'all' or integer page number @return array array of questions including data
[ "Return", "questions", "information", "for", "a", "given", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L909-L949
214,235
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_attempt_data_parameters
public static function get_attempt_data_parameters() { return new external_function_parameters ( array( 'attemptid' => new external_value(PARAM_INT, 'attempt id'), 'page' => new external_value(PARAM_INT, 'page number'), 'preflightdata' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() ) ) ); }
php
public static function get_attempt_data_parameters() { return new external_function_parameters ( array( 'attemptid' => new external_value(PARAM_INT, 'attempt id'), 'page' => new external_value(PARAM_INT, 'page number'), 'preflightdata' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() ) ) ); }
[ "public", "static", "function", "get_attempt_data_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'attemptid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'attempt id'", ")", ",", "'page'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'page number'", ")", ",", "'preflightdata'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'name'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'data name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'data value'", ")", ",", ")", ")", ",", "'Preflight required data (like passwords)'", ",", "VALUE_DEFAULT", ",", "array", "(", ")", ")", ")", ")", ";", "}" ]
Describes the parameters for get_attempt_data. @return external_function_parameters @since Moodle 3.1
[ "Describes", "the", "parameters", "for", "get_attempt_data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L957-L972
214,236
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_attempt_data
public static function get_attempt_data($attemptid, $page, $preflightdata = array()) { $warnings = array(); $params = array( 'attemptid' => $attemptid, 'page' => $page, 'preflightdata' => $preflightdata, ); $params = self::validate_parameters(self::get_attempt_data_parameters(), $params); list($attemptobj, $messages) = self::validate_attempt($params); if ($attemptobj->is_last_page($params['page'])) { $nextpage = -1; } else { $nextpage = $params['page'] + 1; } $result = array(); $result['attempt'] = $attemptobj->get_attempt(); $result['messages'] = $messages; $result['nextpage'] = $nextpage; $result['warnings'] = $warnings; $result['questions'] = self::get_attempt_questions_data($attemptobj, false, $params['page']); return $result; }
php
public static function get_attempt_data($attemptid, $page, $preflightdata = array()) { $warnings = array(); $params = array( 'attemptid' => $attemptid, 'page' => $page, 'preflightdata' => $preflightdata, ); $params = self::validate_parameters(self::get_attempt_data_parameters(), $params); list($attemptobj, $messages) = self::validate_attempt($params); if ($attemptobj->is_last_page($params['page'])) { $nextpage = -1; } else { $nextpage = $params['page'] + 1; } $result = array(); $result['attempt'] = $attemptobj->get_attempt(); $result['messages'] = $messages; $result['nextpage'] = $nextpage; $result['warnings'] = $warnings; $result['questions'] = self::get_attempt_questions_data($attemptobj, false, $params['page']); return $result; }
[ "public", "static", "function", "get_attempt_data", "(", "$", "attemptid", ",", "$", "page", ",", "$", "preflightdata", "=", "array", "(", ")", ")", "{", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'attemptid'", "=>", "$", "attemptid", ",", "'page'", "=>", "$", "page", ",", "'preflightdata'", "=>", "$", "preflightdata", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_attempt_data_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "attemptobj", ",", "$", "messages", ")", "=", "self", "::", "validate_attempt", "(", "$", "params", ")", ";", "if", "(", "$", "attemptobj", "->", "is_last_page", "(", "$", "params", "[", "'page'", "]", ")", ")", "{", "$", "nextpage", "=", "-", "1", ";", "}", "else", "{", "$", "nextpage", "=", "$", "params", "[", "'page'", "]", "+", "1", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'attempt'", "]", "=", "$", "attemptobj", "->", "get_attempt", "(", ")", ";", "$", "result", "[", "'messages'", "]", "=", "$", "messages", ";", "$", "result", "[", "'nextpage'", "]", "=", "$", "nextpage", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "$", "result", "[", "'questions'", "]", "=", "self", "::", "get_attempt_questions_data", "(", "$", "attemptobj", ",", "false", ",", "$", "params", "[", "'page'", "]", ")", ";", "return", "$", "result", ";", "}" ]
Returns information for the given attempt page for a quiz attempt in progress. @param int $attemptid attempt id @param int $page page number @param array $preflightdata preflight required data (like passwords) @return array of warnings and the attempt data, next page, message and questions @since Moodle 3.1 @throws moodle_quiz_exceptions
[ "Returns", "information", "for", "the", "given", "attempt", "page", "for", "a", "quiz", "attempt", "in", "progress", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L984-L1011
214,237
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_attempt_data_returns
public static function get_attempt_data_returns() { return new external_single_structure( array( 'attempt' => self::attempt_structure(), 'messages' => new external_multiple_structure( new external_value(PARAM_TEXT, 'access message'), 'access messages, will only be returned for users with mod/quiz:preview capability, for other users this method will throw an exception if there are messages'), 'nextpage' => new external_value(PARAM_INT, 'next page number'), 'questions' => new external_multiple_structure(self::question_structure()), 'warnings' => new external_warnings(), ) ); }
php
public static function get_attempt_data_returns() { return new external_single_structure( array( 'attempt' => self::attempt_structure(), 'messages' => new external_multiple_structure( new external_value(PARAM_TEXT, 'access message'), 'access messages, will only be returned for users with mod/quiz:preview capability, for other users this method will throw an exception if there are messages'), 'nextpage' => new external_value(PARAM_INT, 'next page number'), 'questions' => new external_multiple_structure(self::question_structure()), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_attempt_data_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'attempt'", "=>", "self", "::", "attempt_structure", "(", ")", ",", "'messages'", "=>", "new", "external_multiple_structure", "(", "new", "external_value", "(", "PARAM_TEXT", ",", "'access message'", ")", ",", "'access messages, will only be returned for users with mod/quiz:preview capability,\n for other users this method will throw an exception if there are messages'", ")", ",", "'nextpage'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'next page number'", ")", ",", "'questions'", "=>", "new", "external_multiple_structure", "(", "self", "::", "question_structure", "(", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_attempt_data return value. @return external_single_structure @since Moodle 3.1
[ "Describes", "the", "get_attempt_data", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1019-L1032
214,238
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_attempt_summary
public static function get_attempt_summary($attemptid, $preflightdata = array()) { $warnings = array(); $params = array( 'attemptid' => $attemptid, 'preflightdata' => $preflightdata, ); $params = self::validate_parameters(self::get_attempt_summary_parameters(), $params); list($attemptobj, $messages) = self::validate_attempt($params, true, false); $result = array(); $result['warnings'] = $warnings; $result['questions'] = self::get_attempt_questions_data($attemptobj, false, 'all'); return $result; }
php
public static function get_attempt_summary($attemptid, $preflightdata = array()) { $warnings = array(); $params = array( 'attemptid' => $attemptid, 'preflightdata' => $preflightdata, ); $params = self::validate_parameters(self::get_attempt_summary_parameters(), $params); list($attemptobj, $messages) = self::validate_attempt($params, true, false); $result = array(); $result['warnings'] = $warnings; $result['questions'] = self::get_attempt_questions_data($attemptobj, false, 'all'); return $result; }
[ "public", "static", "function", "get_attempt_summary", "(", "$", "attemptid", ",", "$", "preflightdata", "=", "array", "(", ")", ")", "{", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'attemptid'", "=>", "$", "attemptid", ",", "'preflightdata'", "=>", "$", "preflightdata", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_attempt_summary_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "attemptobj", ",", "$", "messages", ")", "=", "self", "::", "validate_attempt", "(", "$", "params", ",", "true", ",", "false", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "$", "result", "[", "'questions'", "]", "=", "self", "::", "get_attempt_questions_data", "(", "$", "attemptobj", ",", "false", ",", "'all'", ")", ";", "return", "$", "result", ";", "}" ]
Returns a summary of a quiz attempt before it is submitted. @param int $attemptid attempt id @param int $preflightdata preflight required data (like passwords) @return array of warnings and the attempt summary data for each question @since Moodle 3.1
[ "Returns", "a", "summary", "of", "a", "quiz", "attempt", "before", "it", "is", "submitted", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1064-L1081
214,239
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.save_attempt_parameters
public static function save_attempt_parameters() { return new external_function_parameters ( array( 'attemptid' => new external_value(PARAM_INT, 'attempt id'), 'data' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_RAW, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'the data to be saved' ), 'preflightdata' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() ) ) ); }
php
public static function save_attempt_parameters() { return new external_function_parameters ( array( 'attemptid' => new external_value(PARAM_INT, 'attempt id'), 'data' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_RAW, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'the data to be saved' ), 'preflightdata' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() ) ) ); }
[ "public", "static", "function", "save_attempt_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'attemptid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'attempt id'", ")", ",", "'data'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'name'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'data name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'data value'", ")", ",", ")", ")", ",", "'the data to be saved'", ")", ",", "'preflightdata'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'name'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'data name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'data value'", ")", ",", ")", ")", ",", "'Preflight required data (like passwords)'", ",", "VALUE_DEFAULT", ",", "array", "(", ")", ")", ")", ")", ";", "}" ]
Describes the parameters for save_attempt. @return external_function_parameters @since Moodle 3.1
[ "Describes", "the", "parameters", "for", "save_attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1104-L1126
214,240
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.save_attempt
public static function save_attempt($attemptid, $data, $preflightdata = array()) { global $DB; $warnings = array(); $params = array( 'attemptid' => $attemptid, 'data' => $data, 'preflightdata' => $preflightdata, ); $params = self::validate_parameters(self::save_attempt_parameters(), $params); // Add a page, required by validate_attempt. list($attemptobj, $messages) = self::validate_attempt($params); $transaction = $DB->start_delegated_transaction(); // Create the $_POST object required by the question engine. $_POST = array(); foreach ($data as $element) { $_POST[$element['name']] = $element['value']; } $timenow = time(); // Update the timemodifiedoffline field. $attemptobj->set_offline_modified_time($timenow); $attemptobj->process_auto_save($timenow); $transaction->allow_commit(); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
php
public static function save_attempt($attemptid, $data, $preflightdata = array()) { global $DB; $warnings = array(); $params = array( 'attemptid' => $attemptid, 'data' => $data, 'preflightdata' => $preflightdata, ); $params = self::validate_parameters(self::save_attempt_parameters(), $params); // Add a page, required by validate_attempt. list($attemptobj, $messages) = self::validate_attempt($params); $transaction = $DB->start_delegated_transaction(); // Create the $_POST object required by the question engine. $_POST = array(); foreach ($data as $element) { $_POST[$element['name']] = $element['value']; } $timenow = time(); // Update the timemodifiedoffline field. $attemptobj->set_offline_modified_time($timenow); $attemptobj->process_auto_save($timenow); $transaction->allow_commit(); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "save_attempt", "(", "$", "attemptid", ",", "$", "data", ",", "$", "preflightdata", "=", "array", "(", ")", ")", "{", "global", "$", "DB", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'attemptid'", "=>", "$", "attemptid", ",", "'data'", "=>", "$", "data", ",", "'preflightdata'", "=>", "$", "preflightdata", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "save_attempt_parameters", "(", ")", ",", "$", "params", ")", ";", "// Add a page, required by validate_attempt.", "list", "(", "$", "attemptobj", ",", "$", "messages", ")", "=", "self", "::", "validate_attempt", "(", "$", "params", ")", ";", "$", "transaction", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "// Create the $_POST object required by the question engine.", "$", "_POST", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "element", ")", "{", "$", "_POST", "[", "$", "element", "[", "'name'", "]", "]", "=", "$", "element", "[", "'value'", "]", ";", "}", "$", "timenow", "=", "time", "(", ")", ";", "// Update the timemodifiedoffline field.", "$", "attemptobj", "->", "set_offline_modified_time", "(", "$", "timenow", ")", ";", "$", "attemptobj", "->", "process_auto_save", "(", "$", "timenow", ")", ";", "$", "transaction", "->", "allow_commit", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'status'", "]", "=", "true", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Processes save requests during the quiz. This function is intended for the quiz auto-save feature. @param int $attemptid attempt id @param array $data the data to be saved @param array $preflightdata preflight required data (like passwords) @return array of warnings and execution result @since Moodle 3.1
[ "Processes", "save", "requests", "during", "the", "quiz", ".", "This", "function", "is", "intended", "for", "the", "quiz", "auto", "-", "save", "feature", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1137-L1168
214,241
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.process_attempt_parameters
public static function process_attempt_parameters() { return new external_function_parameters ( array( 'attemptid' => new external_value(PARAM_INT, 'attempt id'), 'data' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_RAW, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'the data to be saved', VALUE_DEFAULT, array() ), 'finishattempt' => new external_value(PARAM_BOOL, 'whether to finish or not the attempt', VALUE_DEFAULT, false), 'timeup' => new external_value(PARAM_BOOL, 'whether the WS was called by a timer when the time is up', VALUE_DEFAULT, false), 'preflightdata' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() ) ) ); }
php
public static function process_attempt_parameters() { return new external_function_parameters ( array( 'attemptid' => new external_value(PARAM_INT, 'attempt id'), 'data' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_RAW, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'the data to be saved', VALUE_DEFAULT, array() ), 'finishattempt' => new external_value(PARAM_BOOL, 'whether to finish or not the attempt', VALUE_DEFAULT, false), 'timeup' => new external_value(PARAM_BOOL, 'whether the WS was called by a timer when the time is up', VALUE_DEFAULT, false), 'preflightdata' => new external_multiple_structure( new external_single_structure( array( 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), ) ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() ) ) ); }
[ "public", "static", "function", "process_attempt_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'attemptid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'attempt id'", ")", ",", "'data'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'name'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'data name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'data value'", ")", ",", ")", ")", ",", "'the data to be saved'", ",", "VALUE_DEFAULT", ",", "array", "(", ")", ")", ",", "'finishattempt'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'whether to finish or not the attempt'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", "'timeup'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'whether the WS was called by a timer when the time is up'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", "'preflightdata'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'name'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'data name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'data value'", ")", ",", ")", ")", ",", "'Preflight required data (like passwords)'", ",", "VALUE_DEFAULT", ",", "array", "(", ")", ")", ")", ")", ";", "}" ]
Describes the parameters for process_attempt. @return external_function_parameters @since Moodle 3.1
[ "Describes", "the", "parameters", "for", "process_attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1191-L1217
214,242
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.process_attempt
public static function process_attempt($attemptid, $data, $finishattempt = false, $timeup = false, $preflightdata = array()) { $warnings = array(); $params = array( 'attemptid' => $attemptid, 'data' => $data, 'finishattempt' => $finishattempt, 'timeup' => $timeup, 'preflightdata' => $preflightdata, ); $params = self::validate_parameters(self::process_attempt_parameters(), $params); // Do not check access manager rules and evaluate fail if overdue. $attemptobj = quiz_attempt::create($params['attemptid']); $failifoverdue = !($attemptobj->get_quizobj()->get_quiz()->overduehandling == 'graceperiod'); list($attemptobj, $messages) = self::validate_attempt($params, false, $failifoverdue); // Create the $_POST object required by the question engine. $_POST = array(); foreach ($params['data'] as $element) { $_POST[$element['name']] = $element['value']; } $timenow = time(); $finishattempt = $params['finishattempt']; $timeup = $params['timeup']; $result = array(); // Update the timemodifiedoffline field. $attemptobj->set_offline_modified_time($timenow); $result['state'] = $attemptobj->process_attempt($timenow, $finishattempt, $timeup, 0); $result['warnings'] = $warnings; return $result; }
php
public static function process_attempt($attemptid, $data, $finishattempt = false, $timeup = false, $preflightdata = array()) { $warnings = array(); $params = array( 'attemptid' => $attemptid, 'data' => $data, 'finishattempt' => $finishattempt, 'timeup' => $timeup, 'preflightdata' => $preflightdata, ); $params = self::validate_parameters(self::process_attempt_parameters(), $params); // Do not check access manager rules and evaluate fail if overdue. $attemptobj = quiz_attempt::create($params['attemptid']); $failifoverdue = !($attemptobj->get_quizobj()->get_quiz()->overduehandling == 'graceperiod'); list($attemptobj, $messages) = self::validate_attempt($params, false, $failifoverdue); // Create the $_POST object required by the question engine. $_POST = array(); foreach ($params['data'] as $element) { $_POST[$element['name']] = $element['value']; } $timenow = time(); $finishattempt = $params['finishattempt']; $timeup = $params['timeup']; $result = array(); // Update the timemodifiedoffline field. $attemptobj->set_offline_modified_time($timenow); $result['state'] = $attemptobj->process_attempt($timenow, $finishattempt, $timeup, 0); $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "process_attempt", "(", "$", "attemptid", ",", "$", "data", ",", "$", "finishattempt", "=", "false", ",", "$", "timeup", "=", "false", ",", "$", "preflightdata", "=", "array", "(", ")", ")", "{", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'attemptid'", "=>", "$", "attemptid", ",", "'data'", "=>", "$", "data", ",", "'finishattempt'", "=>", "$", "finishattempt", ",", "'timeup'", "=>", "$", "timeup", ",", "'preflightdata'", "=>", "$", "preflightdata", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "process_attempt_parameters", "(", ")", ",", "$", "params", ")", ";", "// Do not check access manager rules and evaluate fail if overdue.", "$", "attemptobj", "=", "quiz_attempt", "::", "create", "(", "$", "params", "[", "'attemptid'", "]", ")", ";", "$", "failifoverdue", "=", "!", "(", "$", "attemptobj", "->", "get_quizobj", "(", ")", "->", "get_quiz", "(", ")", "->", "overduehandling", "==", "'graceperiod'", ")", ";", "list", "(", "$", "attemptobj", ",", "$", "messages", ")", "=", "self", "::", "validate_attempt", "(", "$", "params", ",", "false", ",", "$", "failifoverdue", ")", ";", "// Create the $_POST object required by the question engine.", "$", "_POST", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "[", "'data'", "]", "as", "$", "element", ")", "{", "$", "_POST", "[", "$", "element", "[", "'name'", "]", "]", "=", "$", "element", "[", "'value'", "]", ";", "}", "$", "timenow", "=", "time", "(", ")", ";", "$", "finishattempt", "=", "$", "params", "[", "'finishattempt'", "]", ";", "$", "timeup", "=", "$", "params", "[", "'timeup'", "]", ";", "$", "result", "=", "array", "(", ")", ";", "// Update the timemodifiedoffline field.", "$", "attemptobj", "->", "set_offline_modified_time", "(", "$", "timenow", ")", ";", "$", "result", "[", "'state'", "]", "=", "$", "attemptobj", "->", "process_attempt", "(", "$", "timenow", ",", "$", "finishattempt", ",", "$", "timeup", ",", "0", ")", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Process responses during an attempt at a quiz and also deals with attempts finishing. @param int $attemptid attempt id @param array $data the data to be saved @param bool $finishattempt whether to finish or not the attempt @param bool $timeup whether the WS was called by a timer when the time is up @param array $preflightdata preflight required data (like passwords) @return array of warnings and the attempt state after the processing @since Moodle 3.1
[ "Process", "responses", "during", "an", "attempt", "at", "a", "quiz", "and", "also", "deals", "with", "attempts", "finishing", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1230-L1265
214,243
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.validate_attempt_review
protected static function validate_attempt_review($params) { $attemptobj = quiz_attempt::create($params['attemptid']); $attemptobj->check_review_capability(); $displayoptions = $attemptobj->get_display_options(true); if ($attemptobj->is_own_attempt()) { if (!$attemptobj->is_finished()) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'attemptclosed'); } else if (!$displayoptions->attempt) { throw new moodle_exception($attemptobj->cannot_review_message()); } } else if (!$attemptobj->is_review_allowed()) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noreviewattempt'); } return array($attemptobj, $displayoptions); }
php
protected static function validate_attempt_review($params) { $attemptobj = quiz_attempt::create($params['attemptid']); $attemptobj->check_review_capability(); $displayoptions = $attemptobj->get_display_options(true); if ($attemptobj->is_own_attempt()) { if (!$attemptobj->is_finished()) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'attemptclosed'); } else if (!$displayoptions->attempt) { throw new moodle_exception($attemptobj->cannot_review_message()); } } else if (!$attemptobj->is_review_allowed()) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noreviewattempt'); } return array($attemptobj, $displayoptions); }
[ "protected", "static", "function", "validate_attempt_review", "(", "$", "params", ")", "{", "$", "attemptobj", "=", "quiz_attempt", "::", "create", "(", "$", "params", "[", "'attemptid'", "]", ")", ";", "$", "attemptobj", "->", "check_review_capability", "(", ")", ";", "$", "displayoptions", "=", "$", "attemptobj", "->", "get_display_options", "(", "true", ")", ";", "if", "(", "$", "attemptobj", "->", "is_own_attempt", "(", ")", ")", "{", "if", "(", "!", "$", "attemptobj", "->", "is_finished", "(", ")", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "attemptobj", "->", "get_quizobj", "(", ")", ",", "'attemptclosed'", ")", ";", "}", "else", "if", "(", "!", "$", "displayoptions", "->", "attempt", ")", "{", "throw", "new", "moodle_exception", "(", "$", "attemptobj", "->", "cannot_review_message", "(", ")", ")", ";", "}", "}", "else", "if", "(", "!", "$", "attemptobj", "->", "is_review_allowed", "(", ")", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "attemptobj", "->", "get_quizobj", "(", ")", ",", "'noreviewattempt'", ")", ";", "}", "return", "array", "(", "$", "attemptobj", ",", "$", "displayoptions", ")", ";", "}" ]
Validate an attempt finished for review. The attempt would be reviewed by a user or a teacher. @param array $params Array of parameters including the attemptid @return array containing the attempt object and display options @since Moodle 3.1 @throws moodle_exception @throws moodle_quiz_exception
[ "Validate", "an", "attempt", "finished", "for", "review", ".", "The", "attempt", "would", "be", "reviewed", "by", "a", "user", "or", "a", "teacher", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1292-L1308
214,244
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_attempt_review
public static function get_attempt_review($attemptid, $page = -1) { global $PAGE; $warnings = array(); $params = array( 'attemptid' => $attemptid, 'page' => $page, ); $params = self::validate_parameters(self::get_attempt_review_parameters(), $params); list($attemptobj, $displayoptions) = self::validate_attempt_review($params); if ($params['page'] !== -1) { $page = $attemptobj->force_page_number_into_range($params['page']); } else { $page = 'all'; } // Prepare the output. $result = array(); $result['attempt'] = $attemptobj->get_attempt(); $result['questions'] = self::get_attempt_questions_data($attemptobj, true, $page, true); $result['additionaldata'] = array(); // Summary data (from behaviours). $summarydata = $attemptobj->get_additional_summary_data($displayoptions); foreach ($summarydata as $key => $data) { // This text does not need formatting (no need for external_format_[string|text]). $result['additionaldata'][] = array( 'id' => $key, 'title' => $data['title'], $attemptobj->get_quizobj()->get_context()->id, 'content' => $data['content'], ); } // Feedback if there is any, and the user is allowed to see it now. $grade = quiz_rescale_grade($attemptobj->get_attempt()->sumgrades, $attemptobj->get_quiz(), false); $feedback = $attemptobj->get_overall_feedback($grade); if ($displayoptions->overallfeedback && $feedback) { $result['additionaldata'][] = array( 'id' => 'feedback', 'title' => get_string('feedback', 'quiz'), 'content' => $feedback, ); } $result['grade'] = $grade; $result['warnings'] = $warnings; return $result; }
php
public static function get_attempt_review($attemptid, $page = -1) { global $PAGE; $warnings = array(); $params = array( 'attemptid' => $attemptid, 'page' => $page, ); $params = self::validate_parameters(self::get_attempt_review_parameters(), $params); list($attemptobj, $displayoptions) = self::validate_attempt_review($params); if ($params['page'] !== -1) { $page = $attemptobj->force_page_number_into_range($params['page']); } else { $page = 'all'; } // Prepare the output. $result = array(); $result['attempt'] = $attemptobj->get_attempt(); $result['questions'] = self::get_attempt_questions_data($attemptobj, true, $page, true); $result['additionaldata'] = array(); // Summary data (from behaviours). $summarydata = $attemptobj->get_additional_summary_data($displayoptions); foreach ($summarydata as $key => $data) { // This text does not need formatting (no need for external_format_[string|text]). $result['additionaldata'][] = array( 'id' => $key, 'title' => $data['title'], $attemptobj->get_quizobj()->get_context()->id, 'content' => $data['content'], ); } // Feedback if there is any, and the user is allowed to see it now. $grade = quiz_rescale_grade($attemptobj->get_attempt()->sumgrades, $attemptobj->get_quiz(), false); $feedback = $attemptobj->get_overall_feedback($grade); if ($displayoptions->overallfeedback && $feedback) { $result['additionaldata'][] = array( 'id' => 'feedback', 'title' => get_string('feedback', 'quiz'), 'content' => $feedback, ); } $result['grade'] = $grade; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_attempt_review", "(", "$", "attemptid", ",", "$", "page", "=", "-", "1", ")", "{", "global", "$", "PAGE", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'attemptid'", "=>", "$", "attemptid", ",", "'page'", "=>", "$", "page", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_attempt_review_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "attemptobj", ",", "$", "displayoptions", ")", "=", "self", "::", "validate_attempt_review", "(", "$", "params", ")", ";", "if", "(", "$", "params", "[", "'page'", "]", "!==", "-", "1", ")", "{", "$", "page", "=", "$", "attemptobj", "->", "force_page_number_into_range", "(", "$", "params", "[", "'page'", "]", ")", ";", "}", "else", "{", "$", "page", "=", "'all'", ";", "}", "// Prepare the output.", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'attempt'", "]", "=", "$", "attemptobj", "->", "get_attempt", "(", ")", ";", "$", "result", "[", "'questions'", "]", "=", "self", "::", "get_attempt_questions_data", "(", "$", "attemptobj", ",", "true", ",", "$", "page", ",", "true", ")", ";", "$", "result", "[", "'additionaldata'", "]", "=", "array", "(", ")", ";", "// Summary data (from behaviours).", "$", "summarydata", "=", "$", "attemptobj", "->", "get_additional_summary_data", "(", "$", "displayoptions", ")", ";", "foreach", "(", "$", "summarydata", "as", "$", "key", "=>", "$", "data", ")", "{", "// This text does not need formatting (no need for external_format_[string|text]).", "$", "result", "[", "'additionaldata'", "]", "[", "]", "=", "array", "(", "'id'", "=>", "$", "key", ",", "'title'", "=>", "$", "data", "[", "'title'", "]", ",", "$", "attemptobj", "->", "get_quizobj", "(", ")", "->", "get_context", "(", ")", "->", "id", ",", "'content'", "=>", "$", "data", "[", "'content'", "]", ",", ")", ";", "}", "// Feedback if there is any, and the user is allowed to see it now.", "$", "grade", "=", "quiz_rescale_grade", "(", "$", "attemptobj", "->", "get_attempt", "(", ")", "->", "sumgrades", ",", "$", "attemptobj", "->", "get_quiz", "(", ")", ",", "false", ")", ";", "$", "feedback", "=", "$", "attemptobj", "->", "get_overall_feedback", "(", "$", "grade", ")", ";", "if", "(", "$", "displayoptions", "->", "overallfeedback", "&&", "$", "feedback", ")", "{", "$", "result", "[", "'additionaldata'", "]", "[", "]", "=", "array", "(", "'id'", "=>", "'feedback'", ",", "'title'", "=>", "get_string", "(", "'feedback'", ",", "'quiz'", ")", ",", "'content'", "=>", "$", "feedback", ",", ")", ";", "}", "$", "result", "[", "'grade'", "]", "=", "$", "grade", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Returns review information for the given finished attempt, can be used by users or teachers. @param int $attemptid attempt id @param int $page page number, empty for all the questions in all the pages @return array of warnings and the attempt data, feedback and questions @since Moodle 3.1 @throws moodle_exception @throws moodle_quiz_exception
[ "Returns", "review", "information", "for", "the", "given", "finished", "attempt", "can", "be", "used", "by", "users", "or", "teachers", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1336-L1387
214,245
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_attempt_review_returns
public static function get_attempt_review_returns() { return new external_single_structure( array( 'grade' => new external_value(PARAM_RAW, 'grade for the quiz (or empty or "notyetgraded")'), 'attempt' => self::attempt_structure(), 'additionaldata' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_ALPHANUMEXT, 'id of the data'), 'title' => new external_value(PARAM_TEXT, 'data title'), 'content' => new external_value(PARAM_RAW, 'data content'), ) ) ), 'questions' => new external_multiple_structure(self::question_structure()), 'warnings' => new external_warnings(), ) ); }
php
public static function get_attempt_review_returns() { return new external_single_structure( array( 'grade' => new external_value(PARAM_RAW, 'grade for the quiz (or empty or "notyetgraded")'), 'attempt' => self::attempt_structure(), 'additionaldata' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_ALPHANUMEXT, 'id of the data'), 'title' => new external_value(PARAM_TEXT, 'data title'), 'content' => new external_value(PARAM_RAW, 'data content'), ) ) ), 'questions' => new external_multiple_structure(self::question_structure()), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_attempt_review_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'grade'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'grade for the quiz (or empty or \"notyetgraded\")'", ")", ",", "'attempt'", "=>", "self", "::", "attempt_structure", "(", ")", ",", "'additionaldata'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'id of the data'", ")", ",", "'title'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'data title'", ")", ",", "'content'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'data content'", ")", ",", ")", ")", ")", ",", "'questions'", "=>", "new", "external_multiple_structure", "(", "self", "::", "question_structure", "(", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_attempt_review return value. @return external_single_structure @since Moodle 3.1
[ "Describes", "the", "get_attempt_review", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1395-L1413
214,246
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.view_attempt
public static function view_attempt($attemptid, $page, $preflightdata = array()) { $warnings = array(); $params = array( 'attemptid' => $attemptid, 'page' => $page, 'preflightdata' => $preflightdata, ); $params = self::validate_parameters(self::view_attempt_parameters(), $params); list($attemptobj, $messages) = self::validate_attempt($params); // Log action. $attemptobj->fire_attempt_viewed_event(); // Update attempt page, throwing an exception if $page is not valid. if (!$attemptobj->set_currentpage($params['page'])) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'Out of sequence access'); } $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
php
public static function view_attempt($attemptid, $page, $preflightdata = array()) { $warnings = array(); $params = array( 'attemptid' => $attemptid, 'page' => $page, 'preflightdata' => $preflightdata, ); $params = self::validate_parameters(self::view_attempt_parameters(), $params); list($attemptobj, $messages) = self::validate_attempt($params); // Log action. $attemptobj->fire_attempt_viewed_event(); // Update attempt page, throwing an exception if $page is not valid. if (!$attemptobj->set_currentpage($params['page'])) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'Out of sequence access'); } $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "view_attempt", "(", "$", "attemptid", ",", "$", "page", ",", "$", "preflightdata", "=", "array", "(", ")", ")", "{", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'attemptid'", "=>", "$", "attemptid", ",", "'page'", "=>", "$", "page", ",", "'preflightdata'", "=>", "$", "preflightdata", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "view_attempt_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "attemptobj", ",", "$", "messages", ")", "=", "self", "::", "validate_attempt", "(", "$", "params", ")", ";", "// Log action.", "$", "attemptobj", "->", "fire_attempt_viewed_event", "(", ")", ";", "// Update attempt page, throwing an exception if $page is not valid.", "if", "(", "!", "$", "attemptobj", "->", "set_currentpage", "(", "$", "params", "[", "'page'", "]", ")", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "attemptobj", "->", "get_quizobj", "(", ")", ",", "'Out of sequence access'", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'status'", "]", "=", "true", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Trigger the attempt viewed event. @param int $attemptid attempt id @param int $page page number @param array $preflightdata preflight required data (like passwords) @return array of warnings and status result @since Moodle 3.1
[ "Trigger", "the", "attempt", "viewed", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1447-L1471
214,247
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.view_attempt_summary
public static function view_attempt_summary($attemptid, $preflightdata = array()) { $warnings = array(); $params = array( 'attemptid' => $attemptid, 'preflightdata' => $preflightdata, ); $params = self::validate_parameters(self::view_attempt_summary_parameters(), $params); list($attemptobj, $messages) = self::validate_attempt($params); // Log action. $attemptobj->fire_attempt_summary_viewed_event(); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
php
public static function view_attempt_summary($attemptid, $preflightdata = array()) { $warnings = array(); $params = array( 'attemptid' => $attemptid, 'preflightdata' => $preflightdata, ); $params = self::validate_parameters(self::view_attempt_summary_parameters(), $params); list($attemptobj, $messages) = self::validate_attempt($params); // Log action. $attemptobj->fire_attempt_summary_viewed_event(); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "view_attempt_summary", "(", "$", "attemptid", ",", "$", "preflightdata", "=", "array", "(", ")", ")", "{", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'attemptid'", "=>", "$", "attemptid", ",", "'preflightdata'", "=>", "$", "preflightdata", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "view_attempt_summary_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "attemptobj", ",", "$", "messages", ")", "=", "self", "::", "validate_attempt", "(", "$", "params", ")", ";", "// Log action.", "$", "attemptobj", "->", "fire_attempt_summary_viewed_event", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'status'", "]", "=", "true", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Trigger the attempt summary viewed event. @param int $attemptid attempt id @param array $preflightdata preflight required data (like passwords) @return array of warnings and status result @since Moodle 3.1
[ "Trigger", "the", "attempt", "summary", "viewed", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1518-L1536
214,248
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.view_attempt_review
public static function view_attempt_review($attemptid) { $warnings = array(); $params = array( 'attemptid' => $attemptid, ); $params = self::validate_parameters(self::view_attempt_review_parameters(), $params); list($attemptobj, $displayoptions) = self::validate_attempt_review($params); // Log action. $attemptobj->fire_attempt_reviewed_event(); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
php
public static function view_attempt_review($attemptid) { $warnings = array(); $params = array( 'attemptid' => $attemptid, ); $params = self::validate_parameters(self::view_attempt_review_parameters(), $params); list($attemptobj, $displayoptions) = self::validate_attempt_review($params); // Log action. $attemptobj->fire_attempt_reviewed_event(); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "view_attempt_review", "(", "$", "attemptid", ")", "{", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'attemptid'", "=>", "$", "attemptid", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "view_attempt_review_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "attemptobj", ",", "$", "displayoptions", ")", "=", "self", "::", "validate_attempt_review", "(", "$", "params", ")", ";", "// Log action.", "$", "attemptobj", "->", "fire_attempt_reviewed_event", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'status'", "]", "=", "true", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Trigger the attempt reviewed event. @param int $attemptid attempt id @return array of warnings and status result @since Moodle 3.1
[ "Trigger", "the", "attempt", "reviewed", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1574-L1591
214,249
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_quiz_feedback_for_grade
public static function get_quiz_feedback_for_grade($quizid, $grade) { global $DB; $params = array( 'quizid' => $quizid, 'grade' => $grade, ); $params = self::validate_parameters(self::get_quiz_feedback_for_grade_parameters(), $params); $warnings = array(); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); $result = array(); $result['feedbacktext'] = ''; $result['feedbacktextformat'] = FORMAT_MOODLE; $feedback = quiz_feedback_record_for_grade($params['grade'], $quiz); if (!empty($feedback->feedbacktext)) { list($text, $format) = external_format_text($feedback->feedbacktext, $feedback->feedbacktextformat, $context->id, 'mod_quiz', 'feedback', $feedback->id); $result['feedbacktext'] = $text; $result['feedbacktextformat'] = $format; $feedbackinlinefiles = external_util::get_area_files($context->id, 'mod_quiz', 'feedback', $feedback->id); if (!empty($feedbackinlinefiles)) { $result['feedbackinlinefiles'] = $feedbackinlinefiles; } } $result['warnings'] = $warnings; return $result; }
php
public static function get_quiz_feedback_for_grade($quizid, $grade) { global $DB; $params = array( 'quizid' => $quizid, 'grade' => $grade, ); $params = self::validate_parameters(self::get_quiz_feedback_for_grade_parameters(), $params); $warnings = array(); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); $result = array(); $result['feedbacktext'] = ''; $result['feedbacktextformat'] = FORMAT_MOODLE; $feedback = quiz_feedback_record_for_grade($params['grade'], $quiz); if (!empty($feedback->feedbacktext)) { list($text, $format) = external_format_text($feedback->feedbacktext, $feedback->feedbacktextformat, $context->id, 'mod_quiz', 'feedback', $feedback->id); $result['feedbacktext'] = $text; $result['feedbacktextformat'] = $format; $feedbackinlinefiles = external_util::get_area_files($context->id, 'mod_quiz', 'feedback', $feedback->id); if (!empty($feedbackinlinefiles)) { $result['feedbackinlinefiles'] = $feedbackinlinefiles; } } $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_quiz_feedback_for_grade", "(", "$", "quizid", ",", "$", "grade", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", "'quizid'", "=>", "$", "quizid", ",", "'grade'", "=>", "$", "grade", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_quiz_feedback_for_grade_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "list", "(", "$", "quiz", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_quiz", "(", "$", "params", "[", "'quizid'", "]", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'feedbacktext'", "]", "=", "''", ";", "$", "result", "[", "'feedbacktextformat'", "]", "=", "FORMAT_MOODLE", ";", "$", "feedback", "=", "quiz_feedback_record_for_grade", "(", "$", "params", "[", "'grade'", "]", ",", "$", "quiz", ")", ";", "if", "(", "!", "empty", "(", "$", "feedback", "->", "feedbacktext", ")", ")", "{", "list", "(", "$", "text", ",", "$", "format", ")", "=", "external_format_text", "(", "$", "feedback", "->", "feedbacktext", ",", "$", "feedback", "->", "feedbacktextformat", ",", "$", "context", "->", "id", ",", "'mod_quiz'", ",", "'feedback'", ",", "$", "feedback", "->", "id", ")", ";", "$", "result", "[", "'feedbacktext'", "]", "=", "$", "text", ";", "$", "result", "[", "'feedbacktextformat'", "]", "=", "$", "format", ";", "$", "feedbackinlinefiles", "=", "external_util", "::", "get_area_files", "(", "$", "context", "->", "id", ",", "'mod_quiz'", ",", "'feedback'", ",", "$", "feedback", "->", "id", ")", ";", "if", "(", "!", "empty", "(", "$", "feedbackinlinefiles", ")", ")", "{", "$", "result", "[", "'feedbackinlinefiles'", "]", "=", "$", "feedbackinlinefiles", ";", "}", "}", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Get the feedback text that should be show to a student who got the given grade in the given quiz. @param int $quizid quiz instance id @param float $grade the grade to check @return array of warnings and status result @since Moodle 3.1 @throws moodle_exception
[ "Get", "the", "feedback", "text", "that", "should", "be", "show", "to", "a", "student", "who", "got", "the", "given", "grade", "in", "the", "given", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1632-L1662
214,250
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_quiz_access_information
public static function get_quiz_access_information($quizid) { global $DB, $USER; $warnings = array(); $params = array( 'quizid' => $quizid ); $params = self::validate_parameters(self::get_quiz_access_information_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); $result = array(); // Capabilities first. $result['canattempt'] = has_capability('mod/quiz:attempt', $context);; $result['canmanage'] = has_capability('mod/quiz:manage', $context);; $result['canpreview'] = has_capability('mod/quiz:preview', $context);; $result['canreviewmyattempts'] = has_capability('mod/quiz:reviewmyattempts', $context);; $result['canviewreports'] = has_capability('mod/quiz:viewreports', $context);; // Access manager now. $quizobj = quiz::create($cm->instance, $USER->id); $ignoretimelimits = has_capability('mod/quiz:ignoretimelimits', $context, null, false); $timenow = time(); $accessmanager = new quiz_access_manager($quizobj, $timenow, $ignoretimelimits); $result['accessrules'] = $accessmanager->describe_rules(); $result['activerulenames'] = $accessmanager->get_active_rule_names(); $result['preventaccessreasons'] = $accessmanager->prevent_access(); $result['warnings'] = $warnings; return $result; }
php
public static function get_quiz_access_information($quizid) { global $DB, $USER; $warnings = array(); $params = array( 'quizid' => $quizid ); $params = self::validate_parameters(self::get_quiz_access_information_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); $result = array(); // Capabilities first. $result['canattempt'] = has_capability('mod/quiz:attempt', $context);; $result['canmanage'] = has_capability('mod/quiz:manage', $context);; $result['canpreview'] = has_capability('mod/quiz:preview', $context);; $result['canreviewmyattempts'] = has_capability('mod/quiz:reviewmyattempts', $context);; $result['canviewreports'] = has_capability('mod/quiz:viewreports', $context);; // Access manager now. $quizobj = quiz::create($cm->instance, $USER->id); $ignoretimelimits = has_capability('mod/quiz:ignoretimelimits', $context, null, false); $timenow = time(); $accessmanager = new quiz_access_manager($quizobj, $timenow, $ignoretimelimits); $result['accessrules'] = $accessmanager->describe_rules(); $result['activerulenames'] = $accessmanager->get_active_rule_names(); $result['preventaccessreasons'] = $accessmanager->prevent_access(); $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_quiz_access_information", "(", "$", "quizid", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'quizid'", "=>", "$", "quizid", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_quiz_access_information_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "quiz", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_quiz", "(", "$", "params", "[", "'quizid'", "]", ")", ";", "$", "result", "=", "array", "(", ")", ";", "// Capabilities first.", "$", "result", "[", "'canattempt'", "]", "=", "has_capability", "(", "'mod/quiz:attempt'", ",", "$", "context", ")", ";", ";", "$", "result", "[", "'canmanage'", "]", "=", "has_capability", "(", "'mod/quiz:manage'", ",", "$", "context", ")", ";", ";", "$", "result", "[", "'canpreview'", "]", "=", "has_capability", "(", "'mod/quiz:preview'", ",", "$", "context", ")", ";", ";", "$", "result", "[", "'canreviewmyattempts'", "]", "=", "has_capability", "(", "'mod/quiz:reviewmyattempts'", ",", "$", "context", ")", ";", ";", "$", "result", "[", "'canviewreports'", "]", "=", "has_capability", "(", "'mod/quiz:viewreports'", ",", "$", "context", ")", ";", ";", "// Access manager now.", "$", "quizobj", "=", "quiz", "::", "create", "(", "$", "cm", "->", "instance", ",", "$", "USER", "->", "id", ")", ";", "$", "ignoretimelimits", "=", "has_capability", "(", "'mod/quiz:ignoretimelimits'", ",", "$", "context", ",", "null", ",", "false", ")", ";", "$", "timenow", "=", "time", "(", ")", ";", "$", "accessmanager", "=", "new", "quiz_access_manager", "(", "$", "quizobj", ",", "$", "timenow", ",", "$", "ignoretimelimits", ")", ";", "$", "result", "[", "'accessrules'", "]", "=", "$", "accessmanager", "->", "describe_rules", "(", ")", ";", "$", "result", "[", "'activerulenames'", "]", "=", "$", "accessmanager", "->", "get_active_rule_names", "(", ")", ";", "$", "result", "[", "'preventaccessreasons'", "]", "=", "$", "accessmanager", "->", "prevent_access", "(", ")", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Return access information for a given quiz. @param int $quizid quiz instance id @return array of warnings and the access information @since Moodle 3.1 @throws moodle_quiz_exception
[ "Return", "access", "information", "for", "a", "given", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1703-L1735
214,251
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_quiz_access_information_returns
public static function get_quiz_access_information_returns() { return new external_single_structure( array( 'canattempt' => new external_value(PARAM_BOOL, 'Whether the user can do the quiz or not.'), 'canmanage' => new external_value(PARAM_BOOL, 'Whether the user can edit the quiz settings or not.'), 'canpreview' => new external_value(PARAM_BOOL, 'Whether the user can preview the quiz or not.'), 'canreviewmyattempts' => new external_value(PARAM_BOOL, 'Whether the users can review their previous attempts or not.'), 'canviewreports' => new external_value(PARAM_BOOL, 'Whether the user can view the quiz reports or not.'), 'accessrules' => new external_multiple_structure( new external_value(PARAM_TEXT, 'rule description'), 'list of rules'), 'activerulenames' => new external_multiple_structure( new external_value(PARAM_PLUGIN, 'rule plugin names'), 'list of active rules'), 'preventaccessreasons' => new external_multiple_structure( new external_value(PARAM_TEXT, 'access restriction description'), 'list of reasons'), 'warnings' => new external_warnings(), ) ); }
php
public static function get_quiz_access_information_returns() { return new external_single_structure( array( 'canattempt' => new external_value(PARAM_BOOL, 'Whether the user can do the quiz or not.'), 'canmanage' => new external_value(PARAM_BOOL, 'Whether the user can edit the quiz settings or not.'), 'canpreview' => new external_value(PARAM_BOOL, 'Whether the user can preview the quiz or not.'), 'canreviewmyattempts' => new external_value(PARAM_BOOL, 'Whether the users can review their previous attempts or not.'), 'canviewreports' => new external_value(PARAM_BOOL, 'Whether the user can view the quiz reports or not.'), 'accessrules' => new external_multiple_structure( new external_value(PARAM_TEXT, 'rule description'), 'list of rules'), 'activerulenames' => new external_multiple_structure( new external_value(PARAM_PLUGIN, 'rule plugin names'), 'list of active rules'), 'preventaccessreasons' => new external_multiple_structure( new external_value(PARAM_TEXT, 'access restriction description'), 'list of reasons'), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_quiz_access_information_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'canattempt'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether the user can do the quiz or not.'", ")", ",", "'canmanage'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether the user can edit the quiz settings or not.'", ")", ",", "'canpreview'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether the user can preview the quiz or not.'", ")", ",", "'canreviewmyattempts'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether the users can review their previous attempts\n or not.'", ")", ",", "'canviewreports'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether the user can view the quiz reports or not.'", ")", ",", "'accessrules'", "=>", "new", "external_multiple_structure", "(", "new", "external_value", "(", "PARAM_TEXT", ",", "'rule description'", ")", ",", "'list of rules'", ")", ",", "'activerulenames'", "=>", "new", "external_multiple_structure", "(", "new", "external_value", "(", "PARAM_PLUGIN", ",", "'rule plugin names'", ")", ",", "'list of active rules'", ")", ",", "'preventaccessreasons'", "=>", "new", "external_multiple_structure", "(", "new", "external_value", "(", "PARAM_TEXT", ",", "'access restriction description'", ")", ",", "'list of reasons'", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_quiz_access_information return value. @return external_single_structure @since Moodle 3.1
[ "Describes", "the", "get_quiz_access_information", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1743-L1761
214,252
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_attempt_access_information
public static function get_attempt_access_information($quizid, $attemptid = 0) { global $DB, $USER; $warnings = array(); $params = array( 'quizid' => $quizid, 'attemptid' => $attemptid, ); $params = self::validate_parameters(self::get_attempt_access_information_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); $attempttocheck = 0; if (!empty($params['attemptid'])) { $attemptobj = quiz_attempt::create($params['attemptid']); if ($attemptobj->get_userid() != $USER->id) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt'); } $attempttocheck = $attemptobj->get_attempt(); } // Access manager now. $quizobj = quiz::create($cm->instance, $USER->id); $ignoretimelimits = has_capability('mod/quiz:ignoretimelimits', $context, null, false); $timenow = time(); $accessmanager = new quiz_access_manager($quizobj, $timenow, $ignoretimelimits); $attempts = quiz_get_user_attempts($quiz->id, $USER->id, 'finished', true); $lastfinishedattempt = end($attempts); if ($unfinishedattempt = quiz_get_user_attempt_unfinished($quiz->id, $USER->id)) { $attempts[] = $unfinishedattempt; // Check if the attempt is now overdue. In that case the state will change. $quizobj->create_attempt_object($unfinishedattempt)->handle_if_time_expired(time(), false); if ($unfinishedattempt->state != quiz_attempt::IN_PROGRESS and $unfinishedattempt->state != quiz_attempt::OVERDUE) { $lastfinishedattempt = $unfinishedattempt; } } $numattempts = count($attempts); if (!$attempttocheck) { $attempttocheck = $unfinishedattempt ? $unfinishedattempt : $lastfinishedattempt; } $result = array(); $result['isfinished'] = $accessmanager->is_finished($numattempts, $lastfinishedattempt); $result['preventnewattemptreasons'] = $accessmanager->prevent_new_attempt($numattempts, $lastfinishedattempt); if ($attempttocheck) { $endtime = $accessmanager->get_end_time($attempttocheck); $result['endtime'] = ($endtime === false) ? 0 : $endtime; $attemptid = $unfinishedattempt ? $unfinishedattempt->id : null; $result['ispreflightcheckrequired'] = $accessmanager->is_preflight_check_required($attemptid); } $result['warnings'] = $warnings; return $result; }
php
public static function get_attempt_access_information($quizid, $attemptid = 0) { global $DB, $USER; $warnings = array(); $params = array( 'quizid' => $quizid, 'attemptid' => $attemptid, ); $params = self::validate_parameters(self::get_attempt_access_information_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); $attempttocheck = 0; if (!empty($params['attemptid'])) { $attemptobj = quiz_attempt::create($params['attemptid']); if ($attemptobj->get_userid() != $USER->id) { throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt'); } $attempttocheck = $attemptobj->get_attempt(); } // Access manager now. $quizobj = quiz::create($cm->instance, $USER->id); $ignoretimelimits = has_capability('mod/quiz:ignoretimelimits', $context, null, false); $timenow = time(); $accessmanager = new quiz_access_manager($quizobj, $timenow, $ignoretimelimits); $attempts = quiz_get_user_attempts($quiz->id, $USER->id, 'finished', true); $lastfinishedattempt = end($attempts); if ($unfinishedattempt = quiz_get_user_attempt_unfinished($quiz->id, $USER->id)) { $attempts[] = $unfinishedattempt; // Check if the attempt is now overdue. In that case the state will change. $quizobj->create_attempt_object($unfinishedattempt)->handle_if_time_expired(time(), false); if ($unfinishedattempt->state != quiz_attempt::IN_PROGRESS and $unfinishedattempt->state != quiz_attempt::OVERDUE) { $lastfinishedattempt = $unfinishedattempt; } } $numattempts = count($attempts); if (!$attempttocheck) { $attempttocheck = $unfinishedattempt ? $unfinishedattempt : $lastfinishedattempt; } $result = array(); $result['isfinished'] = $accessmanager->is_finished($numattempts, $lastfinishedattempt); $result['preventnewattemptreasons'] = $accessmanager->prevent_new_attempt($numattempts, $lastfinishedattempt); if ($attempttocheck) { $endtime = $accessmanager->get_end_time($attempttocheck); $result['endtime'] = ($endtime === false) ? 0 : $endtime; $attemptid = $unfinishedattempt ? $unfinishedattempt->id : null; $result['ispreflightcheckrequired'] = $accessmanager->is_preflight_check_required($attemptid); } $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_attempt_access_information", "(", "$", "quizid", ",", "$", "attemptid", "=", "0", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'quizid'", "=>", "$", "quizid", ",", "'attemptid'", "=>", "$", "attemptid", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_attempt_access_information_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "quiz", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_quiz", "(", "$", "params", "[", "'quizid'", "]", ")", ";", "$", "attempttocheck", "=", "0", ";", "if", "(", "!", "empty", "(", "$", "params", "[", "'attemptid'", "]", ")", ")", "{", "$", "attemptobj", "=", "quiz_attempt", "::", "create", "(", "$", "params", "[", "'attemptid'", "]", ")", ";", "if", "(", "$", "attemptobj", "->", "get_userid", "(", ")", "!=", "$", "USER", "->", "id", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "attemptobj", "->", "get_quizobj", "(", ")", ",", "'notyourattempt'", ")", ";", "}", "$", "attempttocheck", "=", "$", "attemptobj", "->", "get_attempt", "(", ")", ";", "}", "// Access manager now.", "$", "quizobj", "=", "quiz", "::", "create", "(", "$", "cm", "->", "instance", ",", "$", "USER", "->", "id", ")", ";", "$", "ignoretimelimits", "=", "has_capability", "(", "'mod/quiz:ignoretimelimits'", ",", "$", "context", ",", "null", ",", "false", ")", ";", "$", "timenow", "=", "time", "(", ")", ";", "$", "accessmanager", "=", "new", "quiz_access_manager", "(", "$", "quizobj", ",", "$", "timenow", ",", "$", "ignoretimelimits", ")", ";", "$", "attempts", "=", "quiz_get_user_attempts", "(", "$", "quiz", "->", "id", ",", "$", "USER", "->", "id", ",", "'finished'", ",", "true", ")", ";", "$", "lastfinishedattempt", "=", "end", "(", "$", "attempts", ")", ";", "if", "(", "$", "unfinishedattempt", "=", "quiz_get_user_attempt_unfinished", "(", "$", "quiz", "->", "id", ",", "$", "USER", "->", "id", ")", ")", "{", "$", "attempts", "[", "]", "=", "$", "unfinishedattempt", ";", "// Check if the attempt is now overdue. In that case the state will change.", "$", "quizobj", "->", "create_attempt_object", "(", "$", "unfinishedattempt", ")", "->", "handle_if_time_expired", "(", "time", "(", ")", ",", "false", ")", ";", "if", "(", "$", "unfinishedattempt", "->", "state", "!=", "quiz_attempt", "::", "IN_PROGRESS", "and", "$", "unfinishedattempt", "->", "state", "!=", "quiz_attempt", "::", "OVERDUE", ")", "{", "$", "lastfinishedattempt", "=", "$", "unfinishedattempt", ";", "}", "}", "$", "numattempts", "=", "count", "(", "$", "attempts", ")", ";", "if", "(", "!", "$", "attempttocheck", ")", "{", "$", "attempttocheck", "=", "$", "unfinishedattempt", "?", "$", "unfinishedattempt", ":", "$", "lastfinishedattempt", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'isfinished'", "]", "=", "$", "accessmanager", "->", "is_finished", "(", "$", "numattempts", ",", "$", "lastfinishedattempt", ")", ";", "$", "result", "[", "'preventnewattemptreasons'", "]", "=", "$", "accessmanager", "->", "prevent_new_attempt", "(", "$", "numattempts", ",", "$", "lastfinishedattempt", ")", ";", "if", "(", "$", "attempttocheck", ")", "{", "$", "endtime", "=", "$", "accessmanager", "->", "get_end_time", "(", "$", "attempttocheck", ")", ";", "$", "result", "[", "'endtime'", "]", "=", "(", "$", "endtime", "===", "false", ")", "?", "0", ":", "$", "endtime", ";", "$", "attemptid", "=", "$", "unfinishedattempt", "?", "$", "unfinishedattempt", "->", "id", ":", "null", ";", "$", "result", "[", "'ispreflightcheckrequired'", "]", "=", "$", "accessmanager", "->", "is_preflight_check_required", "(", "$", "attemptid", ")", ";", "}", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Return access information for a given attempt in a quiz. @param int $quizid quiz instance id @param int $attemptid attempt id, 0 for the user last attempt if exists @return array of warnings and the access information @since Moodle 3.1 @throws moodle_quiz_exception
[ "Return", "access", "information", "for", "a", "given", "attempt", "in", "a", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1787-L1846
214,253
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_attempt_access_information_returns
public static function get_attempt_access_information_returns() { return new external_single_structure( array( 'endtime' => new external_value(PARAM_INT, 'When the attempt must be submitted (determined by rules).', VALUE_OPTIONAL), 'isfinished' => new external_value(PARAM_BOOL, 'Whether there is no way the user will ever be allowed to attempt.'), 'ispreflightcheckrequired' => new external_value(PARAM_BOOL, 'whether a check is required before the user starts/continues his attempt.', VALUE_OPTIONAL), 'preventnewattemptreasons' => new external_multiple_structure( new external_value(PARAM_TEXT, 'access restriction description'), 'list of reasons'), 'warnings' => new external_warnings(), ) ); }
php
public static function get_attempt_access_information_returns() { return new external_single_structure( array( 'endtime' => new external_value(PARAM_INT, 'When the attempt must be submitted (determined by rules).', VALUE_OPTIONAL), 'isfinished' => new external_value(PARAM_BOOL, 'Whether there is no way the user will ever be allowed to attempt.'), 'ispreflightcheckrequired' => new external_value(PARAM_BOOL, 'whether a check is required before the user starts/continues his attempt.', VALUE_OPTIONAL), 'preventnewattemptreasons' => new external_multiple_structure( new external_value(PARAM_TEXT, 'access restriction description'), 'list of reasons'), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_attempt_access_information_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'endtime'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'When the attempt must be submitted (determined by rules).'", ",", "VALUE_OPTIONAL", ")", ",", "'isfinished'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether there is no way the user will ever be allowed to attempt.'", ")", ",", "'ispreflightcheckrequired'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'whether a check is required before the user\n starts/continues his attempt.'", ",", "VALUE_OPTIONAL", ")", ",", "'preventnewattemptreasons'", "=>", "new", "external_multiple_structure", "(", "new", "external_value", "(", "PARAM_TEXT", ",", "'access restriction description'", ")", ",", "'list of reasons'", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_attempt_access_information return value. @return external_single_structure @since Moodle 3.1
[ "Describes", "the", "get_attempt_access_information", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1854-L1868
214,254
moodle/moodle
mod/quiz/classes/external.php
mod_quiz_external.get_quiz_required_qtypes
public static function get_quiz_required_qtypes($quizid) { global $DB, $USER; $warnings = array(); $params = array( 'quizid' => $quizid ); $params = self::validate_parameters(self::get_quiz_required_qtypes_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); $quizobj = quiz::create($cm->instance, $USER->id); $quizobj->preload_questions(); $quizobj->load_questions(); // Question types used. $result = array(); $result['questiontypes'] = $quizobj->get_all_question_types_used(true); $result['warnings'] = $warnings; return $result; }
php
public static function get_quiz_required_qtypes($quizid) { global $DB, $USER; $warnings = array(); $params = array( 'quizid' => $quizid ); $params = self::validate_parameters(self::get_quiz_required_qtypes_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); $quizobj = quiz::create($cm->instance, $USER->id); $quizobj->preload_questions(); $quizobj->load_questions(); // Question types used. $result = array(); $result['questiontypes'] = $quizobj->get_all_question_types_used(true); $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_quiz_required_qtypes", "(", "$", "quizid", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", "'quizid'", "=>", "$", "quizid", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_quiz_required_qtypes_parameters", "(", ")", ",", "$", "params", ")", ";", "list", "(", "$", "quiz", ",", "$", "course", ",", "$", "cm", ",", "$", "context", ")", "=", "self", "::", "validate_quiz", "(", "$", "params", "[", "'quizid'", "]", ")", ";", "$", "quizobj", "=", "quiz", "::", "create", "(", "$", "cm", "->", "instance", ",", "$", "USER", "->", "id", ")", ";", "$", "quizobj", "->", "preload_questions", "(", ")", ";", "$", "quizobj", "->", "load_questions", "(", ")", ";", "// Question types used.", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'questiontypes'", "]", "=", "$", "quizobj", "->", "get_all_question_types_used", "(", "true", ")", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Return the potential question types that would be required for a given quiz. Please note that for random question types we return the potential question types in the category choosen. @param int $quizid quiz instance id @return array of warnings and the access information @since Moodle 3.1 @throws moodle_quiz_exception
[ "Return", "the", "potential", "question", "types", "that", "would", "be", "required", "for", "a", "given", "quiz", ".", "Please", "note", "that", "for", "random", "question", "types", "we", "return", "the", "potential", "question", "types", "in", "the", "category", "choosen", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/external.php#L1893-L1914
214,255
moodle/moodle
enrol/lti/classes/manage_table.php
manage_table.col_name
public function col_name($tool) { $name = helper::get_name($tool); return $this->get_display_text($tool, $name); }
php
public function col_name($tool) { $name = helper::get_name($tool); return $this->get_display_text($tool, $name); }
[ "public", "function", "col_name", "(", "$", "tool", ")", "{", "$", "name", "=", "helper", "::", "get_name", "(", "$", "tool", ")", ";", "return", "$", "this", "->", "get_display_text", "(", "$", "tool", ",", "$", "name", ")", ";", "}" ]
Generate the name column. @param \stdClass $tool event data. @return string
[ "Generate", "the", "name", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/manage_table.php#L103-L107
214,256
moodle/moodle
enrol/lti/classes/manage_table.php
manage_table.col_launch
public function col_launch($tool) { global $OUTPUT; $url = helper::get_cartridge_url($tool); $cartridgeurllabel = get_string('cartridgeurl', 'enrol_lti'); $cartridgeurl = $url; $secretlabel = get_string('secret', 'enrol_lti'); $secret = $tool->secret; $launchurl = helper::get_launch_url($tool->id); $launchurllabel = get_string('launchurl', 'enrol_lti'); $data = [ "rows" => [ [ "label" => $cartridgeurllabel, "text" => $cartridgeurl, "id" => "cartridgeurl", "hidelabel" => false ], [ "label" => $secretlabel, "text" => $secret, "id" => "secret", "hidelabel" => false ], [ "label" => $launchurllabel, "text" => $launchurl, "id" => "launchurl", "hidelabel" => false ], ] ]; $return = $OUTPUT->render_from_template("enrol_lti/copy_grid", $data); return $return; }
php
public function col_launch($tool) { global $OUTPUT; $url = helper::get_cartridge_url($tool); $cartridgeurllabel = get_string('cartridgeurl', 'enrol_lti'); $cartridgeurl = $url; $secretlabel = get_string('secret', 'enrol_lti'); $secret = $tool->secret; $launchurl = helper::get_launch_url($tool->id); $launchurllabel = get_string('launchurl', 'enrol_lti'); $data = [ "rows" => [ [ "label" => $cartridgeurllabel, "text" => $cartridgeurl, "id" => "cartridgeurl", "hidelabel" => false ], [ "label" => $secretlabel, "text" => $secret, "id" => "secret", "hidelabel" => false ], [ "label" => $launchurllabel, "text" => $launchurl, "id" => "launchurl", "hidelabel" => false ], ] ]; $return = $OUTPUT->render_from_template("enrol_lti/copy_grid", $data); return $return; }
[ "public", "function", "col_launch", "(", "$", "tool", ")", "{", "global", "$", "OUTPUT", ";", "$", "url", "=", "helper", "::", "get_cartridge_url", "(", "$", "tool", ")", ";", "$", "cartridgeurllabel", "=", "get_string", "(", "'cartridgeurl'", ",", "'enrol_lti'", ")", ";", "$", "cartridgeurl", "=", "$", "url", ";", "$", "secretlabel", "=", "get_string", "(", "'secret'", ",", "'enrol_lti'", ")", ";", "$", "secret", "=", "$", "tool", "->", "secret", ";", "$", "launchurl", "=", "helper", "::", "get_launch_url", "(", "$", "tool", "->", "id", ")", ";", "$", "launchurllabel", "=", "get_string", "(", "'launchurl'", ",", "'enrol_lti'", ")", ";", "$", "data", "=", "[", "\"rows\"", "=>", "[", "[", "\"label\"", "=>", "$", "cartridgeurllabel", ",", "\"text\"", "=>", "$", "cartridgeurl", ",", "\"id\"", "=>", "\"cartridgeurl\"", ",", "\"hidelabel\"", "=>", "false", "]", ",", "[", "\"label\"", "=>", "$", "secretlabel", ",", "\"text\"", "=>", "$", "secret", ",", "\"id\"", "=>", "\"secret\"", ",", "\"hidelabel\"", "=>", "false", "]", ",", "[", "\"label\"", "=>", "$", "launchurllabel", ",", "\"text\"", "=>", "$", "launchurl", ",", "\"id\"", "=>", "\"launchurl\"", ",", "\"hidelabel\"", "=>", "false", "]", ",", "]", "]", ";", "$", "return", "=", "$", "OUTPUT", "->", "render_from_template", "(", "\"enrol_lti/copy_grid\"", ",", "$", "data", ")", ";", "return", "$", "return", ";", "}" ]
Generate the launch column. @param \stdClass $tool instance data. @return string
[ "Generate", "the", "launch", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/manage_table.php#L115-L138
214,257
moodle/moodle
enrol/lti/classes/manage_table.php
manage_table.col_registration
public function col_registration($tool) { global $OUTPUT; $url = helper::get_proxy_url($tool); $toolurllabel = get_string("registrationurl", "enrol_lti"); $toolurl = $url; $data = [ "rows" => [ [ "label" => $toolurllabel, "text" => $toolurl, "id" => "toolurl" , "hidelabel" => true], ] ]; $return = $OUTPUT->render_from_template("enrol_lti/copy_grid", $data); return $return; }
php
public function col_registration($tool) { global $OUTPUT; $url = helper::get_proxy_url($tool); $toolurllabel = get_string("registrationurl", "enrol_lti"); $toolurl = $url; $data = [ "rows" => [ [ "label" => $toolurllabel, "text" => $toolurl, "id" => "toolurl" , "hidelabel" => true], ] ]; $return = $OUTPUT->render_from_template("enrol_lti/copy_grid", $data); return $return; }
[ "public", "function", "col_registration", "(", "$", "tool", ")", "{", "global", "$", "OUTPUT", ";", "$", "url", "=", "helper", "::", "get_proxy_url", "(", "$", "tool", ")", ";", "$", "toolurllabel", "=", "get_string", "(", "\"registrationurl\"", ",", "\"enrol_lti\"", ")", ";", "$", "toolurl", "=", "$", "url", ";", "$", "data", "=", "[", "\"rows\"", "=>", "[", "[", "\"label\"", "=>", "$", "toolurllabel", ",", "\"text\"", "=>", "$", "toolurl", ",", "\"id\"", "=>", "\"toolurl\"", ",", "\"hidelabel\"", "=>", "true", "]", ",", "]", "]", ";", "$", "return", "=", "$", "OUTPUT", "->", "render_from_template", "(", "\"enrol_lti/copy_grid\"", ",", "$", "data", ")", ";", "return", "$", "return", ";", "}" ]
Generate the Registration column. @param \stdClass $tool instance data. @return string
[ "Generate", "the", "Registration", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/manage_table.php#L146-L162
214,258
moodle/moodle
enrol/lti/classes/manage_table.php
manage_table.col_edit
public function col_edit($tool) { global $OUTPUT; $buttons = array(); $instance = new \stdClass(); $instance->id = $tool->enrolid; $instance->courseid = $tool->courseid; $instance->enrol = 'lti'; $instance->status = $tool->status; $strdelete = get_string('delete'); $strenable = get_string('enable'); $strdisable = get_string('disable'); $url = new \moodle_url('/enrol/lti/index.php', array('sesskey' => sesskey(), 'courseid' => $this->courseid)); if ($this->ltiplugin->can_delete_instance($instance)) { $aurl = new \moodle_url($url, array('action' => 'delete', 'instanceid' => $instance->id)); $buttons[] = $OUTPUT->action_icon($aurl, new \pix_icon('t/delete', $strdelete, 'core', array('class' => 'iconsmall'))); } if ($this->ltienabled && $this->ltiplugin->can_hide_show_instance($instance)) { if ($instance->status == ENROL_INSTANCE_ENABLED) { $aurl = new \moodle_url($url, array('action' => 'disable', 'instanceid' => $instance->id)); $buttons[] = $OUTPUT->action_icon($aurl, new \pix_icon('t/hide', $strdisable, 'core', array('class' => 'iconsmall'))); } else if ($instance->status == ENROL_INSTANCE_DISABLED) { $aurl = new \moodle_url($url, array('action' => 'enable', 'instanceid' => $instance->id)); $buttons[] = $OUTPUT->action_icon($aurl, new \pix_icon('t/show', $strenable, 'core', array('class' => 'iconsmall'))); } } if ($this->ltienabled && $this->canconfig) { $linkparams = array( 'courseid' => $instance->courseid, 'id' => $instance->id, 'type' => $instance->enrol, 'returnurl' => new \moodle_url('/enrol/lti/index.php', array('courseid' => $this->courseid)) ); $editlink = new \moodle_url("/enrol/editinstance.php", $linkparams); $buttons[] = $OUTPUT->action_icon($editlink, new \pix_icon('t/edit', get_string('edit'), 'core', array('class' => 'iconsmall'))); } return implode(' ', $buttons); }
php
public function col_edit($tool) { global $OUTPUT; $buttons = array(); $instance = new \stdClass(); $instance->id = $tool->enrolid; $instance->courseid = $tool->courseid; $instance->enrol = 'lti'; $instance->status = $tool->status; $strdelete = get_string('delete'); $strenable = get_string('enable'); $strdisable = get_string('disable'); $url = new \moodle_url('/enrol/lti/index.php', array('sesskey' => sesskey(), 'courseid' => $this->courseid)); if ($this->ltiplugin->can_delete_instance($instance)) { $aurl = new \moodle_url($url, array('action' => 'delete', 'instanceid' => $instance->id)); $buttons[] = $OUTPUT->action_icon($aurl, new \pix_icon('t/delete', $strdelete, 'core', array('class' => 'iconsmall'))); } if ($this->ltienabled && $this->ltiplugin->can_hide_show_instance($instance)) { if ($instance->status == ENROL_INSTANCE_ENABLED) { $aurl = new \moodle_url($url, array('action' => 'disable', 'instanceid' => $instance->id)); $buttons[] = $OUTPUT->action_icon($aurl, new \pix_icon('t/hide', $strdisable, 'core', array('class' => 'iconsmall'))); } else if ($instance->status == ENROL_INSTANCE_DISABLED) { $aurl = new \moodle_url($url, array('action' => 'enable', 'instanceid' => $instance->id)); $buttons[] = $OUTPUT->action_icon($aurl, new \pix_icon('t/show', $strenable, 'core', array('class' => 'iconsmall'))); } } if ($this->ltienabled && $this->canconfig) { $linkparams = array( 'courseid' => $instance->courseid, 'id' => $instance->id, 'type' => $instance->enrol, 'returnurl' => new \moodle_url('/enrol/lti/index.php', array('courseid' => $this->courseid)) ); $editlink = new \moodle_url("/enrol/editinstance.php", $linkparams); $buttons[] = $OUTPUT->action_icon($editlink, new \pix_icon('t/edit', get_string('edit'), 'core', array('class' => 'iconsmall'))); } return implode(' ', $buttons); }
[ "public", "function", "col_edit", "(", "$", "tool", ")", "{", "global", "$", "OUTPUT", ";", "$", "buttons", "=", "array", "(", ")", ";", "$", "instance", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "instance", "->", "id", "=", "$", "tool", "->", "enrolid", ";", "$", "instance", "->", "courseid", "=", "$", "tool", "->", "courseid", ";", "$", "instance", "->", "enrol", "=", "'lti'", ";", "$", "instance", "->", "status", "=", "$", "tool", "->", "status", ";", "$", "strdelete", "=", "get_string", "(", "'delete'", ")", ";", "$", "strenable", "=", "get_string", "(", "'enable'", ")", ";", "$", "strdisable", "=", "get_string", "(", "'disable'", ")", ";", "$", "url", "=", "new", "\\", "moodle_url", "(", "'/enrol/lti/index.php'", ",", "array", "(", "'sesskey'", "=>", "sesskey", "(", ")", ",", "'courseid'", "=>", "$", "this", "->", "courseid", ")", ")", ";", "if", "(", "$", "this", "->", "ltiplugin", "->", "can_delete_instance", "(", "$", "instance", ")", ")", "{", "$", "aurl", "=", "new", "\\", "moodle_url", "(", "$", "url", ",", "array", "(", "'action'", "=>", "'delete'", ",", "'instanceid'", "=>", "$", "instance", "->", "id", ")", ")", ";", "$", "buttons", "[", "]", "=", "$", "OUTPUT", "->", "action_icon", "(", "$", "aurl", ",", "new", "\\", "pix_icon", "(", "'t/delete'", ",", "$", "strdelete", ",", "'core'", ",", "array", "(", "'class'", "=>", "'iconsmall'", ")", ")", ")", ";", "}", "if", "(", "$", "this", "->", "ltienabled", "&&", "$", "this", "->", "ltiplugin", "->", "can_hide_show_instance", "(", "$", "instance", ")", ")", "{", "if", "(", "$", "instance", "->", "status", "==", "ENROL_INSTANCE_ENABLED", ")", "{", "$", "aurl", "=", "new", "\\", "moodle_url", "(", "$", "url", ",", "array", "(", "'action'", "=>", "'disable'", ",", "'instanceid'", "=>", "$", "instance", "->", "id", ")", ")", ";", "$", "buttons", "[", "]", "=", "$", "OUTPUT", "->", "action_icon", "(", "$", "aurl", ",", "new", "\\", "pix_icon", "(", "'t/hide'", ",", "$", "strdisable", ",", "'core'", ",", "array", "(", "'class'", "=>", "'iconsmall'", ")", ")", ")", ";", "}", "else", "if", "(", "$", "instance", "->", "status", "==", "ENROL_INSTANCE_DISABLED", ")", "{", "$", "aurl", "=", "new", "\\", "moodle_url", "(", "$", "url", ",", "array", "(", "'action'", "=>", "'enable'", ",", "'instanceid'", "=>", "$", "instance", "->", "id", ")", ")", ";", "$", "buttons", "[", "]", "=", "$", "OUTPUT", "->", "action_icon", "(", "$", "aurl", ",", "new", "\\", "pix_icon", "(", "'t/show'", ",", "$", "strenable", ",", "'core'", ",", "array", "(", "'class'", "=>", "'iconsmall'", ")", ")", ")", ";", "}", "}", "if", "(", "$", "this", "->", "ltienabled", "&&", "$", "this", "->", "canconfig", ")", "{", "$", "linkparams", "=", "array", "(", "'courseid'", "=>", "$", "instance", "->", "courseid", ",", "'id'", "=>", "$", "instance", "->", "id", ",", "'type'", "=>", "$", "instance", "->", "enrol", ",", "'returnurl'", "=>", "new", "\\", "moodle_url", "(", "'/enrol/lti/index.php'", ",", "array", "(", "'courseid'", "=>", "$", "this", "->", "courseid", ")", ")", ")", ";", "$", "editlink", "=", "new", "\\", "moodle_url", "(", "\"/enrol/editinstance.php\"", ",", "$", "linkparams", ")", ";", "$", "buttons", "[", "]", "=", "$", "OUTPUT", "->", "action_icon", "(", "$", "editlink", ",", "new", "\\", "pix_icon", "(", "'t/edit'", ",", "get_string", "(", "'edit'", ")", ",", "'core'", ",", "array", "(", "'class'", "=>", "'iconsmall'", ")", ")", ")", ";", "}", "return", "implode", "(", "' '", ",", "$", "buttons", ")", ";", "}" ]
Generate the edit column. @param \stdClass $tool event data. @return string
[ "Generate", "the", "edit", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/manage_table.php#L170-L217
214,259
moodle/moodle
enrol/lti/classes/manage_table.php
manage_table.get_display_text
protected function get_display_text($tool, $text) { if ($tool->status != ENROL_INSTANCE_ENABLED) { return \html_writer::tag('span', $text, array('class' => 'dimmed_text')); } return $text; }
php
protected function get_display_text($tool, $text) { if ($tool->status != ENROL_INSTANCE_ENABLED) { return \html_writer::tag('span', $text, array('class' => 'dimmed_text')); } return $text; }
[ "protected", "function", "get_display_text", "(", "$", "tool", ",", "$", "text", ")", "{", "if", "(", "$", "tool", "->", "status", "!=", "ENROL_INSTANCE_ENABLED", ")", "{", "return", "\\", "html_writer", "::", "tag", "(", "'span'", ",", "$", "text", ",", "array", "(", "'class'", "=>", "'dimmed_text'", ")", ")", ";", "}", "return", "$", "text", ";", "}" ]
Returns text to display in the columns. @param \stdClass $tool the tool @param string $text the text to alter @return string
[ "Returns", "text", "to", "display", "in", "the", "columns", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/manage_table.php#L244-L250
214,260
moodle/moodle
webservice/classes/privacy/provider.php
provider.transform_token
protected static function transform_token($record) { $notexportedstr = get_string('privacy:request:notexportedsecurity', 'core_webservice'); return [ 'external_service' => $record->externalservicename, 'token' => $notexportedstr, 'private_token' => $record->privatetoken ? $notexportedstr : null, 'ip_restriction' => $record->iprestriction, 'valid_until' => $record->validuntil ? transform::datetime($record->validuntil) : null, 'created_on' => transform::datetime($record->timecreated), 'last_access' => $record->lastaccess ? transform::datetime($record->lastaccess) : null, ]; }
php
protected static function transform_token($record) { $notexportedstr = get_string('privacy:request:notexportedsecurity', 'core_webservice'); return [ 'external_service' => $record->externalservicename, 'token' => $notexportedstr, 'private_token' => $record->privatetoken ? $notexportedstr : null, 'ip_restriction' => $record->iprestriction, 'valid_until' => $record->validuntil ? transform::datetime($record->validuntil) : null, 'created_on' => transform::datetime($record->timecreated), 'last_access' => $record->lastaccess ? transform::datetime($record->lastaccess) : null, ]; }
[ "protected", "static", "function", "transform_token", "(", "$", "record", ")", "{", "$", "notexportedstr", "=", "get_string", "(", "'privacy:request:notexportedsecurity'", ",", "'core_webservice'", ")", ";", "return", "[", "'external_service'", "=>", "$", "record", "->", "externalservicename", ",", "'token'", "=>", "$", "notexportedstr", ",", "'private_token'", "=>", "$", "record", "->", "privatetoken", "?", "$", "notexportedstr", ":", "null", ",", "'ip_restriction'", "=>", "$", "record", "->", "iprestriction", ",", "'valid_until'", "=>", "$", "record", "->", "validuntil", "?", "transform", "::", "datetime", "(", "$", "record", "->", "validuntil", ")", ":", "null", ",", "'created_on'", "=>", "transform", "::", "datetime", "(", "$", "record", "->", "timecreated", ")", ",", "'last_access'", "=>", "$", "record", "->", "lastaccess", "?", "transform", "::", "datetime", "(", "$", "record", "->", "lastaccess", ")", ":", "null", ",", "]", ";", "}" ]
Transform a token entry. @param object $record The token record. @return array
[ "Transform", "a", "token", "entry", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/classes/privacy/provider.php#L295-L306
214,261
moodle/moodle
backup/util/dbops/backup_controller_dbops.class.php
backup_controller_dbops.get_courseid_from_type_id
public static function get_courseid_from_type_id($type, $id) { global $DB; if ($type == backup::TYPE_1COURSE) { return $id; // id is the course id } else if ($type == backup::TYPE_1SECTION) { if (! $courseid = $DB->get_field('course_sections', 'course', array('id' => $id))) { throw new backup_dbops_exception('course_not_found_for_section', $id); } return $courseid; } else if ($type == backup::TYPE_1ACTIVITY) { if (! $courseid = $DB->get_field('course_modules', 'course', array('id' => $id))) { throw new backup_dbops_exception('course_not_found_for_moduleid', $id); } return $courseid; } }
php
public static function get_courseid_from_type_id($type, $id) { global $DB; if ($type == backup::TYPE_1COURSE) { return $id; // id is the course id } else if ($type == backup::TYPE_1SECTION) { if (! $courseid = $DB->get_field('course_sections', 'course', array('id' => $id))) { throw new backup_dbops_exception('course_not_found_for_section', $id); } return $courseid; } else if ($type == backup::TYPE_1ACTIVITY) { if (! $courseid = $DB->get_field('course_modules', 'course', array('id' => $id))) { throw new backup_dbops_exception('course_not_found_for_moduleid', $id); } return $courseid; } }
[ "public", "static", "function", "get_courseid_from_type_id", "(", "$", "type", ",", "$", "id", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "type", "==", "backup", "::", "TYPE_1COURSE", ")", "{", "return", "$", "id", ";", "// id is the course id", "}", "else", "if", "(", "$", "type", "==", "backup", "::", "TYPE_1SECTION", ")", "{", "if", "(", "!", "$", "courseid", "=", "$", "DB", "->", "get_field", "(", "'course_sections'", ",", "'course'", ",", "array", "(", "'id'", "=>", "$", "id", ")", ")", ")", "{", "throw", "new", "backup_dbops_exception", "(", "'course_not_found_for_section'", ",", "$", "id", ")", ";", "}", "return", "$", "courseid", ";", "}", "else", "if", "(", "$", "type", "==", "backup", "::", "TYPE_1ACTIVITY", ")", "{", "if", "(", "!", "$", "courseid", "=", "$", "DB", "->", "get_field", "(", "'course_modules'", ",", "'course'", ",", "array", "(", "'id'", "=>", "$", "id", ")", ")", ")", "{", "throw", "new", "backup_dbops_exception", "(", "'course_not_found_for_moduleid'", ",", "$", "id", ")", ";", "}", "return", "$", "courseid", ";", "}", "}" ]
Given one type and id from controller, return the corresponding courseid
[ "Given", "one", "type", "and", "id", "from", "controller", "return", "the", "corresponding", "courseid" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_controller_dbops.class.php#L208-L224
214,262
moodle/moodle
backup/util/dbops/backup_controller_dbops.class.php
backup_controller_dbops.apply_version_and_release
public static function apply_version_and_release() { global $CFG; if ($CFG->backup_version < backup::VERSION) { set_config('backup_version', backup::VERSION); set_config('backup_release', backup::RELEASE); } }
php
public static function apply_version_and_release() { global $CFG; if ($CFG->backup_version < backup::VERSION) { set_config('backup_version', backup::VERSION); set_config('backup_release', backup::RELEASE); } }
[ "public", "static", "function", "apply_version_and_release", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "CFG", "->", "backup_version", "<", "backup", "::", "VERSION", ")", "{", "set_config", "(", "'backup_version'", ",", "backup", "::", "VERSION", ")", ";", "set_config", "(", "'backup_release'", ",", "backup", "::", "RELEASE", ")", ";", "}", "}" ]
Update CFG->backup_version and CFG->backup_release if change in version is detected.
[ "Update", "CFG", "-", ">", "backup_version", "and", "CFG", "-", ">", "backup_release", "if", "change", "in", "version", "is", "detected", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_controller_dbops.class.php#L456-L463
214,263
moodle/moodle
backup/util/dbops/backup_controller_dbops.class.php
backup_controller_dbops.backup_includes_mnet_remote_users
public static function backup_includes_mnet_remote_users($backupid) { global $CFG, $DB; $sql = "SELECT COUNT(*) FROM {backup_ids_temp} b JOIN {user} u ON u.id = b.itemid WHERE b.backupid = ? AND b.itemname = 'userfinal' AND u.mnethostid != ?"; $count = $DB->count_records_sql($sql, array($backupid, $CFG->mnet_localhost_id)); return (int)(bool)$count; }
php
public static function backup_includes_mnet_remote_users($backupid) { global $CFG, $DB; $sql = "SELECT COUNT(*) FROM {backup_ids_temp} b JOIN {user} u ON u.id = b.itemid WHERE b.backupid = ? AND b.itemname = 'userfinal' AND u.mnethostid != ?"; $count = $DB->count_records_sql($sql, array($backupid, $CFG->mnet_localhost_id)); return (int)(bool)$count; }
[ "public", "static", "function", "backup_includes_mnet_remote_users", "(", "$", "backupid", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "sql", "=", "\"SELECT COUNT(*)\n FROM {backup_ids_temp} b\n JOIN {user} u ON u.id = b.itemid\n WHERE b.backupid = ?\n AND b.itemname = 'userfinal'\n AND u.mnethostid != ?\"", ";", "$", "count", "=", "$", "DB", "->", "count_records_sql", "(", "$", "sql", ",", "array", "(", "$", "backupid", ",", "$", "CFG", "->", "mnet_localhost_id", ")", ")", ";", "return", "(", "int", ")", "(", "bool", ")", "$", "count", ";", "}" ]
Given the backupid, detect if the backup includes "mnet" remote users or no
[ "Given", "the", "backupid", "detect", "if", "the", "backup", "includes", "mnet", "remote", "users", "or", "no" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_controller_dbops.class.php#L468-L479
214,264
moodle/moodle
backup/util/dbops/backup_controller_dbops.class.php
backup_controller_dbops.backup_includes_files
public static function backup_includes_files($backupid) { // This function is called repeatedly in a backup with many files. // Loading the controller is a nontrivial operation (in a large test // backup it took 0.3 seconds), so we do a temporary cache of it within // this request. if (self::$includesfilescachebackupid === $backupid) { return self::$includesfilescache; } // Load controller, get value, then destroy controller and return result. self::$includesfilescachebackupid = $backupid; $bc = self::load_controller($backupid); self::$includesfilescache = $bc->get_include_files(); $bc->destroy(); return self::$includesfilescache; }
php
public static function backup_includes_files($backupid) { // This function is called repeatedly in a backup with many files. // Loading the controller is a nontrivial operation (in a large test // backup it took 0.3 seconds), so we do a temporary cache of it within // this request. if (self::$includesfilescachebackupid === $backupid) { return self::$includesfilescache; } // Load controller, get value, then destroy controller and return result. self::$includesfilescachebackupid = $backupid; $bc = self::load_controller($backupid); self::$includesfilescache = $bc->get_include_files(); $bc->destroy(); return self::$includesfilescache; }
[ "public", "static", "function", "backup_includes_files", "(", "$", "backupid", ")", "{", "// This function is called repeatedly in a backup with many files.", "// Loading the controller is a nontrivial operation (in a large test", "// backup it took 0.3 seconds), so we do a temporary cache of it within", "// this request.", "if", "(", "self", "::", "$", "includesfilescachebackupid", "===", "$", "backupid", ")", "{", "return", "self", "::", "$", "includesfilescache", ";", "}", "// Load controller, get value, then destroy controller and return result.", "self", "::", "$", "includesfilescachebackupid", "=", "$", "backupid", ";", "$", "bc", "=", "self", "::", "load_controller", "(", "$", "backupid", ")", ";", "self", "::", "$", "includesfilescache", "=", "$", "bc", "->", "get_include_files", "(", ")", ";", "$", "bc", "->", "destroy", "(", ")", ";", "return", "self", "::", "$", "includesfilescache", ";", "}" ]
Given the backupid, determine whether this backup should include files from the moodle file storage system. @param string $backupid The ID of the backup. @return int Indicates whether files should be included in backups.
[ "Given", "the", "backupid", "determine", "whether", "this", "backup", "should", "include", "files", "from", "the", "moodle", "file", "storage", "system", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_controller_dbops.class.php#L488-L503
214,265
moodle/moodle
backup/util/dbops/backup_controller_dbops.class.php
backup_controller_dbops.backup_includes_file_references
public static function backup_includes_file_references($backupid) { global $CFG, $DB; $sql = "SELECT count(r.repositoryid) FROM {files} f LEFT JOIN {files_reference} r ON r.id = f.referencefileid JOIN {backup_ids_temp} bi ON f.id = bi.itemid WHERE bi.backupid = ? AND bi.itemname = 'filefinal'"; $count = $DB->count_records_sql($sql, array($backupid)); return (int)(bool)$count; }
php
public static function backup_includes_file_references($backupid) { global $CFG, $DB; $sql = "SELECT count(r.repositoryid) FROM {files} f LEFT JOIN {files_reference} r ON r.id = f.referencefileid JOIN {backup_ids_temp} bi ON f.id = bi.itemid WHERE bi.backupid = ? AND bi.itemname = 'filefinal'"; $count = $DB->count_records_sql($sql, array($backupid)); return (int)(bool)$count; }
[ "public", "static", "function", "backup_includes_file_references", "(", "$", "backupid", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "sql", "=", "\"SELECT count(r.repositoryid)\n FROM {files} f\n LEFT JOIN {files_reference} r\n ON r.id = f.referencefileid\n JOIN {backup_ids_temp} bi\n ON f.id = bi.itemid\n WHERE bi.backupid = ?\n AND bi.itemname = 'filefinal'\"", ";", "$", "count", "=", "$", "DB", "->", "count_records_sql", "(", "$", "sql", ",", "array", "(", "$", "backupid", ")", ")", ";", "return", "(", "int", ")", "(", "bool", ")", "$", "count", ";", "}" ]
Given the backupid, detect if the backup contains references to external contents @copyright 2012 Dongsheng Cai {@link http://dongsheng.org} @return int
[ "Given", "the", "backupid", "detect", "if", "the", "backup", "contains", "references", "to", "external", "contents" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_controller_dbops.class.php#L511-L524
214,266
moodle/moodle
backup/util/dbops/backup_controller_dbops.class.php
backup_controller_dbops.apply_config_defaults
public static function apply_config_defaults(backup_controller $controller) { // Based on the mode of the backup (general, automated, import, hub...) // decide the action to perform to get defaults loaded $mode = $controller->get_mode(); switch ($mode) { case backup::MODE_GENERAL: // Load the general defaults $settings = array( 'backup_general_users' => 'users', 'backup_general_anonymize' => 'anonymize', 'backup_general_role_assignments' => 'role_assignments', 'backup_general_activities' => 'activities', 'backup_general_blocks' => 'blocks', 'backup_general_filters' => 'filters', 'backup_general_comments' => 'comments', 'backup_general_badges' => 'badges', 'backup_general_calendarevents' => 'calendarevents', 'backup_general_userscompletion' => 'userscompletion', 'backup_general_logs' => 'logs', 'backup_general_histories' => 'grade_histories', 'backup_general_questionbank' => 'questionbank', 'backup_general_groups' => 'groups', 'backup_general_competencies' => 'competencies' ); self::apply_admin_config_defaults($controller, $settings, true); break; case backup::MODE_IMPORT: // Load the import defaults. $settings = array( 'backup_import_activities' => 'activities', 'backup_import_blocks' => 'blocks', 'backup_import_filters' => 'filters', 'backup_import_calendarevents' => 'calendarevents', 'backup_import_questionbank' => 'questionbank', 'backup_import_groups' => 'groups', 'backup_import_competencies' => 'competencies' ); self::apply_admin_config_defaults($controller, $settings, true); if ((!$controller->get_interactive()) && $controller->get_type() == backup::TYPE_1ACTIVITY) { // This is duplicate - there is no concept of defaults - these settings must be on. $settings = array( 'activities', 'blocks', 'filters', 'questionbank' ); self::force_enable_settings($controller, $settings); } break; case backup::MODE_AUTOMATED: // Load the automated defaults. $settings = array( 'backup_auto_users' => 'users', 'backup_auto_role_assignments' => 'role_assignments', 'backup_auto_activities' => 'activities', 'backup_auto_blocks' => 'blocks', 'backup_auto_filters' => 'filters', 'backup_auto_comments' => 'comments', 'backup_auto_badges' => 'badges', 'backup_auto_calendarevents' => 'calendarevents', 'backup_auto_userscompletion' => 'userscompletion', 'backup_auto_logs' => 'logs', 'backup_auto_histories' => 'grade_histories', 'backup_auto_questionbank' => 'questionbank', 'backup_auto_groups' => 'groups', 'backup_auto_competencies' => 'competencies' ); self::apply_admin_config_defaults($controller, $settings, false); break; default: // Nothing to do for other modes (HUB...). Some day we // can define defaults (admin UI...) for them if we want to } }
php
public static function apply_config_defaults(backup_controller $controller) { // Based on the mode of the backup (general, automated, import, hub...) // decide the action to perform to get defaults loaded $mode = $controller->get_mode(); switch ($mode) { case backup::MODE_GENERAL: // Load the general defaults $settings = array( 'backup_general_users' => 'users', 'backup_general_anonymize' => 'anonymize', 'backup_general_role_assignments' => 'role_assignments', 'backup_general_activities' => 'activities', 'backup_general_blocks' => 'blocks', 'backup_general_filters' => 'filters', 'backup_general_comments' => 'comments', 'backup_general_badges' => 'badges', 'backup_general_calendarevents' => 'calendarevents', 'backup_general_userscompletion' => 'userscompletion', 'backup_general_logs' => 'logs', 'backup_general_histories' => 'grade_histories', 'backup_general_questionbank' => 'questionbank', 'backup_general_groups' => 'groups', 'backup_general_competencies' => 'competencies' ); self::apply_admin_config_defaults($controller, $settings, true); break; case backup::MODE_IMPORT: // Load the import defaults. $settings = array( 'backup_import_activities' => 'activities', 'backup_import_blocks' => 'blocks', 'backup_import_filters' => 'filters', 'backup_import_calendarevents' => 'calendarevents', 'backup_import_questionbank' => 'questionbank', 'backup_import_groups' => 'groups', 'backup_import_competencies' => 'competencies' ); self::apply_admin_config_defaults($controller, $settings, true); if ((!$controller->get_interactive()) && $controller->get_type() == backup::TYPE_1ACTIVITY) { // This is duplicate - there is no concept of defaults - these settings must be on. $settings = array( 'activities', 'blocks', 'filters', 'questionbank' ); self::force_enable_settings($controller, $settings); } break; case backup::MODE_AUTOMATED: // Load the automated defaults. $settings = array( 'backup_auto_users' => 'users', 'backup_auto_role_assignments' => 'role_assignments', 'backup_auto_activities' => 'activities', 'backup_auto_blocks' => 'blocks', 'backup_auto_filters' => 'filters', 'backup_auto_comments' => 'comments', 'backup_auto_badges' => 'badges', 'backup_auto_calendarevents' => 'calendarevents', 'backup_auto_userscompletion' => 'userscompletion', 'backup_auto_logs' => 'logs', 'backup_auto_histories' => 'grade_histories', 'backup_auto_questionbank' => 'questionbank', 'backup_auto_groups' => 'groups', 'backup_auto_competencies' => 'competencies' ); self::apply_admin_config_defaults($controller, $settings, false); break; default: // Nothing to do for other modes (HUB...). Some day we // can define defaults (admin UI...) for them if we want to } }
[ "public", "static", "function", "apply_config_defaults", "(", "backup_controller", "$", "controller", ")", "{", "// Based on the mode of the backup (general, automated, import, hub...)", "// decide the action to perform to get defaults loaded", "$", "mode", "=", "$", "controller", "->", "get_mode", "(", ")", ";", "switch", "(", "$", "mode", ")", "{", "case", "backup", "::", "MODE_GENERAL", ":", "// Load the general defaults", "$", "settings", "=", "array", "(", "'backup_general_users'", "=>", "'users'", ",", "'backup_general_anonymize'", "=>", "'anonymize'", ",", "'backup_general_role_assignments'", "=>", "'role_assignments'", ",", "'backup_general_activities'", "=>", "'activities'", ",", "'backup_general_blocks'", "=>", "'blocks'", ",", "'backup_general_filters'", "=>", "'filters'", ",", "'backup_general_comments'", "=>", "'comments'", ",", "'backup_general_badges'", "=>", "'badges'", ",", "'backup_general_calendarevents'", "=>", "'calendarevents'", ",", "'backup_general_userscompletion'", "=>", "'userscompletion'", ",", "'backup_general_logs'", "=>", "'logs'", ",", "'backup_general_histories'", "=>", "'grade_histories'", ",", "'backup_general_questionbank'", "=>", "'questionbank'", ",", "'backup_general_groups'", "=>", "'groups'", ",", "'backup_general_competencies'", "=>", "'competencies'", ")", ";", "self", "::", "apply_admin_config_defaults", "(", "$", "controller", ",", "$", "settings", ",", "true", ")", ";", "break", ";", "case", "backup", "::", "MODE_IMPORT", ":", "// Load the import defaults.", "$", "settings", "=", "array", "(", "'backup_import_activities'", "=>", "'activities'", ",", "'backup_import_blocks'", "=>", "'blocks'", ",", "'backup_import_filters'", "=>", "'filters'", ",", "'backup_import_calendarevents'", "=>", "'calendarevents'", ",", "'backup_import_questionbank'", "=>", "'questionbank'", ",", "'backup_import_groups'", "=>", "'groups'", ",", "'backup_import_competencies'", "=>", "'competencies'", ")", ";", "self", "::", "apply_admin_config_defaults", "(", "$", "controller", ",", "$", "settings", ",", "true", ")", ";", "if", "(", "(", "!", "$", "controller", "->", "get_interactive", "(", ")", ")", "&&", "$", "controller", "->", "get_type", "(", ")", "==", "backup", "::", "TYPE_1ACTIVITY", ")", "{", "// This is duplicate - there is no concept of defaults - these settings must be on.", "$", "settings", "=", "array", "(", "'activities'", ",", "'blocks'", ",", "'filters'", ",", "'questionbank'", ")", ";", "self", "::", "force_enable_settings", "(", "$", "controller", ",", "$", "settings", ")", ";", "}", "break", ";", "case", "backup", "::", "MODE_AUTOMATED", ":", "// Load the automated defaults.", "$", "settings", "=", "array", "(", "'backup_auto_users'", "=>", "'users'", ",", "'backup_auto_role_assignments'", "=>", "'role_assignments'", ",", "'backup_auto_activities'", "=>", "'activities'", ",", "'backup_auto_blocks'", "=>", "'blocks'", ",", "'backup_auto_filters'", "=>", "'filters'", ",", "'backup_auto_comments'", "=>", "'comments'", ",", "'backup_auto_badges'", "=>", "'badges'", ",", "'backup_auto_calendarevents'", "=>", "'calendarevents'", ",", "'backup_auto_userscompletion'", "=>", "'userscompletion'", ",", "'backup_auto_logs'", "=>", "'logs'", ",", "'backup_auto_histories'", "=>", "'grade_histories'", ",", "'backup_auto_questionbank'", "=>", "'questionbank'", ",", "'backup_auto_groups'", "=>", "'groups'", ",", "'backup_auto_competencies'", "=>", "'competencies'", ")", ";", "self", "::", "apply_admin_config_defaults", "(", "$", "controller", ",", "$", "settings", ",", "false", ")", ";", "break", ";", "default", ":", "// Nothing to do for other modes (HUB...). Some day we", "// can define defaults (admin UI...) for them if we want to", "}", "}" ]
Sets the default values for the settings in a backup operation Based on the mode of the backup it will load proper defaults using {@link apply_admin_config_defaults}. @param backup_controller $controller
[ "Sets", "the", "default", "values", "for", "the", "settings", "in", "a", "backup", "operation" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_controller_dbops.class.php#L544-L619
214,267
moodle/moodle
backup/util/dbops/backup_controller_dbops.class.php
backup_controller_dbops.get_progress
public static function get_progress($backupid) { global $DB; $progress = array(); $backuprecord = $DB->get_record( 'backup_controllers', array('backupid' => $backupid), 'status, progress, operation', MUST_EXIST); $status = $backuprecord->status; $progress = $backuprecord->progress; $operation = $backuprecord->operation; $progress = array('status' => $status, 'progress' => $progress, 'backupid' => $backupid, 'operation' => $operation); return $progress; }
php
public static function get_progress($backupid) { global $DB; $progress = array(); $backuprecord = $DB->get_record( 'backup_controllers', array('backupid' => $backupid), 'status, progress, operation', MUST_EXIST); $status = $backuprecord->status; $progress = $backuprecord->progress; $operation = $backuprecord->operation; $progress = array('status' => $status, 'progress' => $progress, 'backupid' => $backupid, 'operation' => $operation); return $progress; }
[ "public", "static", "function", "get_progress", "(", "$", "backupid", ")", "{", "global", "$", "DB", ";", "$", "progress", "=", "array", "(", ")", ";", "$", "backuprecord", "=", "$", "DB", "->", "get_record", "(", "'backup_controllers'", ",", "array", "(", "'backupid'", "=>", "$", "backupid", ")", ",", "'status, progress, operation'", ",", "MUST_EXIST", ")", ";", "$", "status", "=", "$", "backuprecord", "->", "status", ";", "$", "progress", "=", "$", "backuprecord", "->", "progress", ";", "$", "operation", "=", "$", "backuprecord", "->", "operation", ";", "$", "progress", "=", "array", "(", "'status'", "=>", "$", "status", ",", "'progress'", "=>", "$", "progress", ",", "'backupid'", "=>", "$", "backupid", ",", "'operation'", "=>", "$", "operation", ")", ";", "return", "$", "progress", ";", "}" ]
Get the progress details of a backup operation. Get backup records directly from database, if the backup has successfully completed there will be no controller object to load. @param string $backupid The backup id to query. @return array $progress The backup progress details.
[ "Get", "the", "progress", "details", "of", "a", "backup", "operation", ".", "Get", "backup", "records", "directly", "from", "database", "if", "the", "backup", "has", "successfully", "completed", "there", "will", "be", "no", "controller", "object", "to", "load", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/backup_controller_dbops.class.php#L688-L705
214,268
moodle/moodle
admin/tool/log/store/standard/backup/moodle2/restore_logstore_standard_subplugin.class.php
restore_logstore_standard_subplugin.process_logstore_standard_log
public function process_logstore_standard_log($data) { global $DB; $data = $this->process_log($data, get_config('logstore_standard', 'jsonformat')); if ($data) { $DB->insert_record('logstore_standard_log', $data); } }
php
public function process_logstore_standard_log($data) { global $DB; $data = $this->process_log($data, get_config('logstore_standard', 'jsonformat')); if ($data) { $DB->insert_record('logstore_standard_log', $data); } }
[ "public", "function", "process_logstore_standard_log", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "$", "this", "->", "process_log", "(", "$", "data", ",", "get_config", "(", "'logstore_standard'", ",", "'jsonformat'", ")", ")", ";", "if", "(", "$", "data", ")", "{", "$", "DB", "->", "insert_record", "(", "'logstore_standard_log'", ",", "$", "data", ")", ";", "}", "}" ]
Process logstore_standard_log entries. This method proceeds to read, complete, remap and, finally, discard or save every log entry. @param array() $data log entry.
[ "Process", "logstore_standard_log", "entries", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/store/standard/backup/moodle2/restore_logstore_standard_subplugin.class.php#L60-L68
214,269
moodle/moodle
lib/classes/message/inbound/address_manager.php
address_manager.set_data
public function set_data($datavalue, $datakey = null) { $this->datavalue = $datavalue; // We must clear the datakey when changing the datavalue. $this->set_data_key($datakey); }
php
public function set_data($datavalue, $datakey = null) { $this->datavalue = $datavalue; // We must clear the datakey when changing the datavalue. $this->set_data_key($datakey); }
[ "public", "function", "set_data", "(", "$", "datavalue", ",", "$", "datakey", "=", "null", ")", "{", "$", "this", "->", "datavalue", "=", "$", "datavalue", ";", "// We must clear the datakey when changing the datavalue.", "$", "this", "->", "set_data_key", "(", "$", "datakey", ")", ";", "}" ]
Specify an integer data item value for this record. @param int $datavalue The value of the data item. @param string $datakey A hash to use for the datakey
[ "Specify", "an", "integer", "data", "item", "value", "for", "this", "record", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/address_manager.php#L152-L157
214,270
moodle/moodle
lib/classes/message/inbound/address_manager.php
address_manager.fetch_data_key
public function fetch_data_key() { global $CFG, $DB; // Only generate a key if Inbound Message is actually enabled, and the handler is enabled. if (!isset($CFG->messageinbound_enabled) || !$this->handler || !$this->handler->enabled) { return null; } if (!isset($this->datakey)) { // Attempt to fetch an existing key first if one has not already been specified. $datakey = $DB->get_field('messageinbound_datakeys', 'datakey', array( 'handler' => $this->handler->id, 'datavalue' => $this->datavalue, )); if (!$datakey) { $datakey = $this->generate_data_key(); } $this->datakey = $datakey; } return $this->datakey; }
php
public function fetch_data_key() { global $CFG, $DB; // Only generate a key if Inbound Message is actually enabled, and the handler is enabled. if (!isset($CFG->messageinbound_enabled) || !$this->handler || !$this->handler->enabled) { return null; } if (!isset($this->datakey)) { // Attempt to fetch an existing key first if one has not already been specified. $datakey = $DB->get_field('messageinbound_datakeys', 'datakey', array( 'handler' => $this->handler->id, 'datavalue' => $this->datavalue, )); if (!$datakey) { $datakey = $this->generate_data_key(); } $this->datakey = $datakey; } return $this->datakey; }
[ "public", "function", "fetch_data_key", "(", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "// Only generate a key if Inbound Message is actually enabled, and the handler is enabled.", "if", "(", "!", "isset", "(", "$", "CFG", "->", "messageinbound_enabled", ")", "||", "!", "$", "this", "->", "handler", "||", "!", "$", "this", "->", "handler", "->", "enabled", ")", "{", "return", "null", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "datakey", ")", ")", "{", "// Attempt to fetch an existing key first if one has not already been specified.", "$", "datakey", "=", "$", "DB", "->", "get_field", "(", "'messageinbound_datakeys'", ",", "'datakey'", ",", "array", "(", "'handler'", "=>", "$", "this", "->", "handler", "->", "id", ",", "'datavalue'", "=>", "$", "this", "->", "datavalue", ",", ")", ")", ";", "if", "(", "!", "$", "datakey", ")", "{", "$", "datakey", "=", "$", "this", "->", "generate_data_key", "(", ")", ";", "}", "$", "this", "->", "datakey", "=", "$", "datakey", ";", "}", "return", "$", "this", "->", "datakey", ";", "}" ]
Return the data key for the data item. If no data key has been defined yet, this will call generate_data_key() to generate a new key on the fly. @return string The secret key for this data item.
[ "Return", "the", "data", "key", "for", "the", "data", "item", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/address_manager.php#L180-L201
214,271
moodle/moodle
lib/classes/message/inbound/address_manager.php
address_manager.generate_data_key
protected function generate_data_key() { global $DB; $key = new \stdClass(); $key->handler = $this->handler->id; $key->datavalue = $this->datavalue; $key->datakey = md5($this->datavalue . '_' . time() . random_string(40)); $key->timecreated = time(); if ($this->handler->defaultexpiration) { // Apply the default expiration time to the datakey. $key->expires = $key->timecreated + $this->handler->defaultexpiration; } $DB->insert_record('messageinbound_datakeys', $key); return $key->datakey; }
php
protected function generate_data_key() { global $DB; $key = new \stdClass(); $key->handler = $this->handler->id; $key->datavalue = $this->datavalue; $key->datakey = md5($this->datavalue . '_' . time() . random_string(40)); $key->timecreated = time(); if ($this->handler->defaultexpiration) { // Apply the default expiration time to the datakey. $key->expires = $key->timecreated + $this->handler->defaultexpiration; } $DB->insert_record('messageinbound_datakeys', $key); return $key->datakey; }
[ "protected", "function", "generate_data_key", "(", ")", "{", "global", "$", "DB", ";", "$", "key", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "key", "->", "handler", "=", "$", "this", "->", "handler", "->", "id", ";", "$", "key", "->", "datavalue", "=", "$", "this", "->", "datavalue", ";", "$", "key", "->", "datakey", "=", "md5", "(", "$", "this", "->", "datavalue", ".", "'_'", ".", "time", "(", ")", ".", "random_string", "(", "40", ")", ")", ";", "$", "key", "->", "timecreated", "=", "time", "(", ")", ";", "if", "(", "$", "this", "->", "handler", "->", "defaultexpiration", ")", "{", "// Apply the default expiration time to the datakey.", "$", "key", "->", "expires", "=", "$", "key", "->", "timecreated", "+", "$", "this", "->", "handler", "->", "defaultexpiration", ";", "}", "$", "DB", "->", "insert_record", "(", "'messageinbound_datakeys'", ",", "$", "key", ")", ";", "return", "$", "key", "->", "datakey", ";", "}" ]
Generate a new secret key for the current data item and handler combination. @return string The new generated secret key for this data item.
[ "Generate", "a", "new", "secret", "key", "for", "the", "current", "data", "item", "and", "handler", "combination", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/address_manager.php#L208-L224
214,272
moodle/moodle
lib/classes/message/inbound/address_manager.php
address_manager.generate
public function generate($userid, $userkey = null) { global $CFG; // Ensure that Inbound Message is enabled and that there is enough information to proceed. if (!manager::is_enabled()) { return null; } if ($userkey == null) { $userkey = get_user_key('messageinbound_handler', $userid); } // Ensure that the minimum requirements are in place. if (!isset($this->handler) || !$this->handler) { throw new \coding_exception('Inbound Message handler not specified.'); } // Ensure that the requested handler is actually enabled. if (!$this->handler->enabled) { return null; } if (!isset($this->datavalue)) { throw new \coding_exception('Inbound Message data item has not been specified.'); } $data = array( self::pack_int($this->handler->id), self::pack_int($userid), self::pack_int($this->datavalue), pack('H*', substr(md5($this->fetch_data_key() . $userkey), 0, self::HASHSIZE)), ); $subaddress = base64_encode(implode($data)); return $CFG->messageinbound_mailbox . '+' . $subaddress . '@' . $CFG->messageinbound_domain; }
php
public function generate($userid, $userkey = null) { global $CFG; // Ensure that Inbound Message is enabled and that there is enough information to proceed. if (!manager::is_enabled()) { return null; } if ($userkey == null) { $userkey = get_user_key('messageinbound_handler', $userid); } // Ensure that the minimum requirements are in place. if (!isset($this->handler) || !$this->handler) { throw new \coding_exception('Inbound Message handler not specified.'); } // Ensure that the requested handler is actually enabled. if (!$this->handler->enabled) { return null; } if (!isset($this->datavalue)) { throw new \coding_exception('Inbound Message data item has not been specified.'); } $data = array( self::pack_int($this->handler->id), self::pack_int($userid), self::pack_int($this->datavalue), pack('H*', substr(md5($this->fetch_data_key() . $userkey), 0, self::HASHSIZE)), ); $subaddress = base64_encode(implode($data)); return $CFG->messageinbound_mailbox . '+' . $subaddress . '@' . $CFG->messageinbound_domain; }
[ "public", "function", "generate", "(", "$", "userid", ",", "$", "userkey", "=", "null", ")", "{", "global", "$", "CFG", ";", "// Ensure that Inbound Message is enabled and that there is enough information to proceed.", "if", "(", "!", "manager", "::", "is_enabled", "(", ")", ")", "{", "return", "null", ";", "}", "if", "(", "$", "userkey", "==", "null", ")", "{", "$", "userkey", "=", "get_user_key", "(", "'messageinbound_handler'", ",", "$", "userid", ")", ";", "}", "// Ensure that the minimum requirements are in place.", "if", "(", "!", "isset", "(", "$", "this", "->", "handler", ")", "||", "!", "$", "this", "->", "handler", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Inbound Message handler not specified.'", ")", ";", "}", "// Ensure that the requested handler is actually enabled.", "if", "(", "!", "$", "this", "->", "handler", "->", "enabled", ")", "{", "return", "null", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "datavalue", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Inbound Message data item has not been specified.'", ")", ";", "}", "$", "data", "=", "array", "(", "self", "::", "pack_int", "(", "$", "this", "->", "handler", "->", "id", ")", ",", "self", "::", "pack_int", "(", "$", "userid", ")", ",", "self", "::", "pack_int", "(", "$", "this", "->", "datavalue", ")", ",", "pack", "(", "'H*'", ",", "substr", "(", "md5", "(", "$", "this", "->", "fetch_data_key", "(", ")", ".", "$", "userkey", ")", ",", "0", ",", "self", "::", "HASHSIZE", ")", ")", ",", ")", ";", "$", "subaddress", "=", "base64_encode", "(", "implode", "(", "$", "data", ")", ")", ";", "return", "$", "CFG", "->", "messageinbound_mailbox", ".", "'+'", ".", "$", "subaddress", ".", "'@'", ".", "$", "CFG", "->", "messageinbound_domain", ";", "}" ]
Generate an e-mail address for the Inbound Message handler, storing a private key for the data object if one was not specified. @param int $userid The ID of the user to generated an address for. @param string $userkey The unique key for this user. If not specified this will be retrieved using get_user_key(). This key must have been created using get_user_key(). This parameter is provided as a performance optimisation for when generating multiple addresses for the same user. @return string|null The generated address, or null if an address could not be generated.
[ "Generate", "an", "e", "-", "mail", "address", "for", "the", "Inbound", "Message", "handler", "storing", "a", "private", "key", "for", "the", "data", "object", "if", "one", "was", "not", "specified", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/address_manager.php#L236-L271
214,273
moodle/moodle
lib/classes/message/inbound/address_manager.php
address_manager.process
protected function process($address) { global $DB; if (!self::is_correct_format($address)) { // This address does not contain a subaddress to parse. return; } // Ensure that the instance record is empty. $this->record = null; $record = new \stdClass(); $record->address = $address; list($localpart) = explode('@', $address, 2); list($record->mailbox, $encodeddata) = explode('+', $localpart, 2); $data = base64_decode($encodeddata, true); if (!$data) { // This address has no valid data. return; } $content = @unpack('N2handlerid/N2userid/N2datavalue/H*datakey', $data); if (!$content) { // This address has no data. return; } if (PHP_INT_SIZE === 8) { // 64-bit machine. $content['handlerid'] = $content['handlerid1'] << 32 | $content['handlerid2']; $content['userid'] = $content['userid1'] << 32 | $content['userid2']; $content['datavalue'] = $content['datavalue1'] << 32 | $content['datavalue2']; } else { if ($content['handlerid1'] > 0 || $content['userid1'] > 0 || $content['datavalue1'] > 0) { // Any 64-bit integer which is greater than the 32-bit integer size will have a non-zero value in the first // half of the integer. throw new \moodle_exception('Mixed environment.' . ' Key generated with a 64-bit machine but received into a 32-bit machine.'); } $content['handlerid'] = $content['handlerid2']; $content['userid'] = $content['userid2']; $content['datavalue'] = $content['datavalue2']; } // Clear the 32-bit to 64-bit variables away. unset($content['handlerid1']); unset($content['handlerid2']); unset($content['userid1']); unset($content['userid2']); unset($content['datavalue1']); unset($content['datavalue2']); $record = (object) array_merge((array) $record, $content); // Fetch the user record. $record->user = $DB->get_record('user', array('id' => $record->userid)); // Fetch and set the handler. if ($handler = manager::get_handler_from_id($record->handlerid)) { $this->handler = $handler; // Retrieve the record for the data key. $record->data = $DB->get_record('messageinbound_datakeys', array('handler' => $handler->id, 'datavalue' => $record->datavalue)); } $this->record = $record; }
php
protected function process($address) { global $DB; if (!self::is_correct_format($address)) { // This address does not contain a subaddress to parse. return; } // Ensure that the instance record is empty. $this->record = null; $record = new \stdClass(); $record->address = $address; list($localpart) = explode('@', $address, 2); list($record->mailbox, $encodeddata) = explode('+', $localpart, 2); $data = base64_decode($encodeddata, true); if (!$data) { // This address has no valid data. return; } $content = @unpack('N2handlerid/N2userid/N2datavalue/H*datakey', $data); if (!$content) { // This address has no data. return; } if (PHP_INT_SIZE === 8) { // 64-bit machine. $content['handlerid'] = $content['handlerid1'] << 32 | $content['handlerid2']; $content['userid'] = $content['userid1'] << 32 | $content['userid2']; $content['datavalue'] = $content['datavalue1'] << 32 | $content['datavalue2']; } else { if ($content['handlerid1'] > 0 || $content['userid1'] > 0 || $content['datavalue1'] > 0) { // Any 64-bit integer which is greater than the 32-bit integer size will have a non-zero value in the first // half of the integer. throw new \moodle_exception('Mixed environment.' . ' Key generated with a 64-bit machine but received into a 32-bit machine.'); } $content['handlerid'] = $content['handlerid2']; $content['userid'] = $content['userid2']; $content['datavalue'] = $content['datavalue2']; } // Clear the 32-bit to 64-bit variables away. unset($content['handlerid1']); unset($content['handlerid2']); unset($content['userid1']); unset($content['userid2']); unset($content['datavalue1']); unset($content['datavalue2']); $record = (object) array_merge((array) $record, $content); // Fetch the user record. $record->user = $DB->get_record('user', array('id' => $record->userid)); // Fetch and set the handler. if ($handler = manager::get_handler_from_id($record->handlerid)) { $this->handler = $handler; // Retrieve the record for the data key. $record->data = $DB->get_record('messageinbound_datakeys', array('handler' => $handler->id, 'datavalue' => $record->datavalue)); } $this->record = $record; }
[ "protected", "function", "process", "(", "$", "address", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "self", "::", "is_correct_format", "(", "$", "address", ")", ")", "{", "// This address does not contain a subaddress to parse.", "return", ";", "}", "// Ensure that the instance record is empty.", "$", "this", "->", "record", "=", "null", ";", "$", "record", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "record", "->", "address", "=", "$", "address", ";", "list", "(", "$", "localpart", ")", "=", "explode", "(", "'@'", ",", "$", "address", ",", "2", ")", ";", "list", "(", "$", "record", "->", "mailbox", ",", "$", "encodeddata", ")", "=", "explode", "(", "'+'", ",", "$", "localpart", ",", "2", ")", ";", "$", "data", "=", "base64_decode", "(", "$", "encodeddata", ",", "true", ")", ";", "if", "(", "!", "$", "data", ")", "{", "// This address has no valid data.", "return", ";", "}", "$", "content", "=", "@", "unpack", "(", "'N2handlerid/N2userid/N2datavalue/H*datakey'", ",", "$", "data", ")", ";", "if", "(", "!", "$", "content", ")", "{", "// This address has no data.", "return", ";", "}", "if", "(", "PHP_INT_SIZE", "===", "8", ")", "{", "// 64-bit machine.", "$", "content", "[", "'handlerid'", "]", "=", "$", "content", "[", "'handlerid1'", "]", "<<", "32", "|", "$", "content", "[", "'handlerid2'", "]", ";", "$", "content", "[", "'userid'", "]", "=", "$", "content", "[", "'userid1'", "]", "<<", "32", "|", "$", "content", "[", "'userid2'", "]", ";", "$", "content", "[", "'datavalue'", "]", "=", "$", "content", "[", "'datavalue1'", "]", "<<", "32", "|", "$", "content", "[", "'datavalue2'", "]", ";", "}", "else", "{", "if", "(", "$", "content", "[", "'handlerid1'", "]", ">", "0", "||", "$", "content", "[", "'userid1'", "]", ">", "0", "||", "$", "content", "[", "'datavalue1'", "]", ">", "0", ")", "{", "// Any 64-bit integer which is greater than the 32-bit integer size will have a non-zero value in the first", "// half of the integer.", "throw", "new", "\\", "moodle_exception", "(", "'Mixed environment.'", ".", "' Key generated with a 64-bit machine but received into a 32-bit machine.'", ")", ";", "}", "$", "content", "[", "'handlerid'", "]", "=", "$", "content", "[", "'handlerid2'", "]", ";", "$", "content", "[", "'userid'", "]", "=", "$", "content", "[", "'userid2'", "]", ";", "$", "content", "[", "'datavalue'", "]", "=", "$", "content", "[", "'datavalue2'", "]", ";", "}", "// Clear the 32-bit to 64-bit variables away.", "unset", "(", "$", "content", "[", "'handlerid1'", "]", ")", ";", "unset", "(", "$", "content", "[", "'handlerid2'", "]", ")", ";", "unset", "(", "$", "content", "[", "'userid1'", "]", ")", ";", "unset", "(", "$", "content", "[", "'userid2'", "]", ")", ";", "unset", "(", "$", "content", "[", "'datavalue1'", "]", ")", ";", "unset", "(", "$", "content", "[", "'datavalue2'", "]", ")", ";", "$", "record", "=", "(", "object", ")", "array_merge", "(", "(", "array", ")", "$", "record", ",", "$", "content", ")", ";", "// Fetch the user record.", "$", "record", "->", "user", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "record", "->", "userid", ")", ")", ";", "// Fetch and set the handler.", "if", "(", "$", "handler", "=", "manager", "::", "get_handler_from_id", "(", "$", "record", "->", "handlerid", ")", ")", "{", "$", "this", "->", "handler", "=", "$", "handler", ";", "// Retrieve the record for the data key.", "$", "record", "->", "data", "=", "$", "DB", "->", "get_record", "(", "'messageinbound_datakeys'", ",", "array", "(", "'handler'", "=>", "$", "handler", "->", "id", ",", "'datavalue'", "=>", "$", "record", "->", "datavalue", ")", ")", ";", "}", "$", "this", "->", "record", "=", "$", "record", ";", "}" ]
Process an inbound address to obtain the data stored within it. @param string $address The fully formed e-mail address to process.
[ "Process", "an", "inbound", "address", "to", "obtain", "the", "data", "stored", "within", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/address_manager.php#L290-L359
214,274
moodle/moodle
lib/classes/message/inbound/address_manager.php
address_manager.validate
protected function validate($address) { if (!$this->record) { // The record does not exist, so there is nothing to validate against. return self::VALIDATION_INVALID_ADDRESS_FORMAT; } // Build the list of validation errors. $returnvalue = 0; if (!$this->handler) { $returnvalue += self::VALIDATION_UNKNOWN_HANDLER; } else if (!$this->handler->enabled) { $returnvalue += self::VALIDATION_DISABLED_HANDLER; } if (!isset($this->record->data) || !$this->record->data) { $returnvalue += self::VALIDATION_UNKNOWN_DATAKEY; } else if ($this->record->data->expires != 0 && $this->record->data->expires < time()) { $returnvalue += self::VALIDATION_EXPIRED_DATAKEY; } else { if (!$this->record->user) { $returnvalue += self::VALIDATION_UNKNOWN_USER; } else { if ($this->record->user->deleted || !$this->record->user->confirmed) { $returnvalue += self::VALIDATION_DISABLED_USER; } $userkey = get_user_key('messageinbound_handler', $this->record->user->id); $hashvalidation = substr(md5($this->record->data->datakey . $userkey), 0, self::HASHSIZE) == $this->record->datakey; if (!$hashvalidation) { // The address data did not check out, so the originator is deemed invalid. $returnvalue += self::VALIDATION_INVALID_HASH; } if ($this->handler->validateaddress) { // Validation of the sender's e-mail address is also required. if ($address !== $this->record->user->email) { // The e-mail address of the originator did not match the // address held on record for this user. $returnvalue += self::VALIDATION_ADDRESS_MISMATCH; } } } } return $returnvalue; }
php
protected function validate($address) { if (!$this->record) { // The record does not exist, so there is nothing to validate against. return self::VALIDATION_INVALID_ADDRESS_FORMAT; } // Build the list of validation errors. $returnvalue = 0; if (!$this->handler) { $returnvalue += self::VALIDATION_UNKNOWN_HANDLER; } else if (!$this->handler->enabled) { $returnvalue += self::VALIDATION_DISABLED_HANDLER; } if (!isset($this->record->data) || !$this->record->data) { $returnvalue += self::VALIDATION_UNKNOWN_DATAKEY; } else if ($this->record->data->expires != 0 && $this->record->data->expires < time()) { $returnvalue += self::VALIDATION_EXPIRED_DATAKEY; } else { if (!$this->record->user) { $returnvalue += self::VALIDATION_UNKNOWN_USER; } else { if ($this->record->user->deleted || !$this->record->user->confirmed) { $returnvalue += self::VALIDATION_DISABLED_USER; } $userkey = get_user_key('messageinbound_handler', $this->record->user->id); $hashvalidation = substr(md5($this->record->data->datakey . $userkey), 0, self::HASHSIZE) == $this->record->datakey; if (!$hashvalidation) { // The address data did not check out, so the originator is deemed invalid. $returnvalue += self::VALIDATION_INVALID_HASH; } if ($this->handler->validateaddress) { // Validation of the sender's e-mail address is also required. if ($address !== $this->record->user->email) { // The e-mail address of the originator did not match the // address held on record for this user. $returnvalue += self::VALIDATION_ADDRESS_MISMATCH; } } } } return $returnvalue; }
[ "protected", "function", "validate", "(", "$", "address", ")", "{", "if", "(", "!", "$", "this", "->", "record", ")", "{", "// The record does not exist, so there is nothing to validate against.", "return", "self", "::", "VALIDATION_INVALID_ADDRESS_FORMAT", ";", "}", "// Build the list of validation errors.", "$", "returnvalue", "=", "0", ";", "if", "(", "!", "$", "this", "->", "handler", ")", "{", "$", "returnvalue", "+=", "self", "::", "VALIDATION_UNKNOWN_HANDLER", ";", "}", "else", "if", "(", "!", "$", "this", "->", "handler", "->", "enabled", ")", "{", "$", "returnvalue", "+=", "self", "::", "VALIDATION_DISABLED_HANDLER", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "record", "->", "data", ")", "||", "!", "$", "this", "->", "record", "->", "data", ")", "{", "$", "returnvalue", "+=", "self", "::", "VALIDATION_UNKNOWN_DATAKEY", ";", "}", "else", "if", "(", "$", "this", "->", "record", "->", "data", "->", "expires", "!=", "0", "&&", "$", "this", "->", "record", "->", "data", "->", "expires", "<", "time", "(", ")", ")", "{", "$", "returnvalue", "+=", "self", "::", "VALIDATION_EXPIRED_DATAKEY", ";", "}", "else", "{", "if", "(", "!", "$", "this", "->", "record", "->", "user", ")", "{", "$", "returnvalue", "+=", "self", "::", "VALIDATION_UNKNOWN_USER", ";", "}", "else", "{", "if", "(", "$", "this", "->", "record", "->", "user", "->", "deleted", "||", "!", "$", "this", "->", "record", "->", "user", "->", "confirmed", ")", "{", "$", "returnvalue", "+=", "self", "::", "VALIDATION_DISABLED_USER", ";", "}", "$", "userkey", "=", "get_user_key", "(", "'messageinbound_handler'", ",", "$", "this", "->", "record", "->", "user", "->", "id", ")", ";", "$", "hashvalidation", "=", "substr", "(", "md5", "(", "$", "this", "->", "record", "->", "data", "->", "datakey", ".", "$", "userkey", ")", ",", "0", ",", "self", "::", "HASHSIZE", ")", "==", "$", "this", "->", "record", "->", "datakey", ";", "if", "(", "!", "$", "hashvalidation", ")", "{", "// The address data did not check out, so the originator is deemed invalid.", "$", "returnvalue", "+=", "self", "::", "VALIDATION_INVALID_HASH", ";", "}", "if", "(", "$", "this", "->", "handler", "->", "validateaddress", ")", "{", "// Validation of the sender's e-mail address is also required.", "if", "(", "$", "address", "!==", "$", "this", "->", "record", "->", "user", "->", "email", ")", "{", "// The e-mail address of the originator did not match the", "// address held on record for this user.", "$", "returnvalue", "+=", "self", "::", "VALIDATION_ADDRESS_MISMATCH", ";", "}", "}", "}", "}", "return", "$", "returnvalue", ";", "}" ]
Ensure that the parsed data is valid, and if the handler requires address validation, validate the sender against the user record of identified user record. @param string $address The fully formed e-mail address to process. @return int The validation status.
[ "Ensure", "that", "the", "parsed", "data", "is", "valid", "and", "if", "the", "handler", "requires", "address", "validation", "validate", "the", "sender", "against", "the", "user", "record", "of", "identified", "user", "record", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/address_manager.php#L377-L424
214,275
moodle/moodle
lib/classes/message/inbound/address_manager.php
address_manager.process_envelope
public function process_envelope($recipient, $sender) { // Process the recipient address to retrieve the handler data. $this->process($recipient); // Validate the retrieved data against the e-mail address of the originator. $this->status = $this->validate($sender); return $this->status; }
php
public function process_envelope($recipient, $sender) { // Process the recipient address to retrieve the handler data. $this->process($recipient); // Validate the retrieved data against the e-mail address of the originator. $this->status = $this->validate($sender); return $this->status; }
[ "public", "function", "process_envelope", "(", "$", "recipient", ",", "$", "sender", ")", "{", "// Process the recipient address to retrieve the handler data.", "$", "this", "->", "process", "(", "$", "recipient", ")", ";", "// Validate the retrieved data against the e-mail address of the originator.", "$", "this", "->", "status", "=", "$", "this", "->", "validate", "(", "$", "sender", ")", ";", "return", "$", "this", "->", "status", ";", "}" ]
Process the message recipient, load the handler, and then validate the sender with the associated data record. @param string $recipient The recipient of the message @param string $sender The sender of the message
[ "Process", "the", "message", "recipient", "load", "the", "handler", "and", "then", "validate", "the", "sender", "with", "the", "associated", "data", "record", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/address_manager.php#L433-L441
214,276
moodle/moodle
lib/classes/message/inbound/address_manager.php
address_manager.handle_message
public function handle_message(\stdClass $messagedata) { $this->record = $this->get_data(); return $this->handler->process_message($this->record, $messagedata); }
php
public function handle_message(\stdClass $messagedata) { $this->record = $this->get_data(); return $this->handler->process_message($this->record, $messagedata); }
[ "public", "function", "handle_message", "(", "\\", "stdClass", "$", "messagedata", ")", "{", "$", "this", "->", "record", "=", "$", "this", "->", "get_data", "(", ")", ";", "return", "$", "this", "->", "handler", "->", "process_message", "(", "$", "this", "->", "record", ",", "$", "messagedata", ")", ";", "}" ]
Process the message against the relevant handler. @param \stdClass $messagedata The data for the current message being processed. @return mixed The result of the handler's message processor. A truthy result suggests a successful send.
[ "Process", "the", "message", "against", "the", "relevant", "handler", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/address_manager.php#L449-L452
214,277
moodle/moodle
lib/classes/message/inbound/address_manager.php
address_manager.pack_int
protected function pack_int($int) { if (PHP_INT_SIZE === 8) { $left = 0xffffffff00000000; $right = 0x00000000ffffffff; $l = ($int & $left) >>32; $r = $int & $right; return pack('NN', $l, $r); } else { return pack('NN', 0, $int); } }
php
protected function pack_int($int) { if (PHP_INT_SIZE === 8) { $left = 0xffffffff00000000; $right = 0x00000000ffffffff; $l = ($int & $left) >>32; $r = $int & $right; return pack('NN', $l, $r); } else { return pack('NN', 0, $int); } }
[ "protected", "function", "pack_int", "(", "$", "int", ")", "{", "if", "(", "PHP_INT_SIZE", "===", "8", ")", "{", "$", "left", "=", "0xffffffff00000000", ";", "$", "right", "=", "0x00000000ffffffff", ";", "$", "l", "=", "(", "$", "int", "&", "$", "left", ")", ">>", "32", ";", "$", "r", "=", "$", "int", "&", "$", "right", ";", "return", "pack", "(", "'NN'", ",", "$", "l", ",", "$", "r", ")", ";", "}", "else", "{", "return", "pack", "(", "'NN'", ",", "0", ",", "$", "int", ")", ";", "}", "}" ]
Pack an integer into a pair of 32-bit numbers. @param int $int The integer to pack @return string The encoded binary data
[ "Pack", "an", "integer", "into", "a", "pair", "of", "32", "-", "bit", "numbers", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/address_manager.php#L460-L471
214,278
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Token.php
HTMLPurifier_Token.position
public function position($l = null, $c = null) { $this->line = $l; $this->col = $c; }
php
public function position($l = null, $c = null) { $this->line = $l; $this->col = $c; }
[ "public", "function", "position", "(", "$", "l", "=", "null", ",", "$", "c", "=", "null", ")", "{", "$", "this", "->", "line", "=", "$", "l", ";", "$", "this", "->", "col", "=", "$", "c", ";", "}" ]
Sets the position of the token in the source document. @param int $l @param int $c
[ "Sets", "the", "position", "of", "the", "token", "in", "the", "source", "document", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Token.php#L74-L78
214,279
moodle/moodle
lib/horde/framework/Horde/String/Transliterate.php
Horde_String_Transliterate.toAscii
public static function toAscii($str) { $methods = array( '_intlToAscii', '_iconvToAscii', '_fallbackToAscii' ); foreach ($methods as $val) { if (($out = call_user_func(array(__CLASS__, $val), $str)) !== false) { return $out; } } return $str; }
php
public static function toAscii($str) { $methods = array( '_intlToAscii', '_iconvToAscii', '_fallbackToAscii' ); foreach ($methods as $val) { if (($out = call_user_func(array(__CLASS__, $val), $str)) !== false) { return $out; } } return $str; }
[ "public", "static", "function", "toAscii", "(", "$", "str", ")", "{", "$", "methods", "=", "array", "(", "'_intlToAscii'", ",", "'_iconvToAscii'", ",", "'_fallbackToAscii'", ")", ";", "foreach", "(", "$", "methods", "as", "$", "val", ")", "{", "if", "(", "(", "$", "out", "=", "call_user_func", "(", "array", "(", "__CLASS__", ",", "$", "val", ")", ",", "$", "str", ")", ")", "!==", "false", ")", "{", "return", "$", "out", ";", "}", "}", "return", "$", "str", ";", "}" ]
Transliterates an UTF-8 string to ASCII, replacing non-English characters to their English equivalents. Note: there is no guarantee that the output string will be ASCII-only, since any non-ASCII character not in the transliteration list will be ignored. @param string $str Input string (UTF-8). @return string Transliterated string (UTF-8).
[ "Transliterates", "an", "UTF", "-", "8", "string", "to", "ASCII", "replacing", "non", "-", "English", "characters", "to", "their", "English", "equivalents", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String/Transliterate.php#L53-L68
214,280
moodle/moodle
lib/horde/framework/Horde/String/Transliterate.php
Horde_String_Transliterate._intlToAscii
protected static function _intlToAscii($str) { if (class_exists('Transliterator')) { if (!isset(self::$_transliterator)) { self::$_transliterator = Transliterator::create( 'Any-Latin; Latin-ASCII' ); } if (!is_null(self::$_transliterator)) { /* Returns false on error. */ return self::$_transliterator->transliterate($str); } } return false; }
php
protected static function _intlToAscii($str) { if (class_exists('Transliterator')) { if (!isset(self::$_transliterator)) { self::$_transliterator = Transliterator::create( 'Any-Latin; Latin-ASCII' ); } if (!is_null(self::$_transliterator)) { /* Returns false on error. */ return self::$_transliterator->transliterate($str); } } return false; }
[ "protected", "static", "function", "_intlToAscii", "(", "$", "str", ")", "{", "if", "(", "class_exists", "(", "'Transliterator'", ")", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "_transliterator", ")", ")", "{", "self", "::", "$", "_transliterator", "=", "Transliterator", "::", "create", "(", "'Any-Latin; Latin-ASCII'", ")", ";", "}", "if", "(", "!", "is_null", "(", "self", "::", "$", "_transliterator", ")", ")", "{", "/* Returns false on error. */", "return", "self", "::", "$", "_transliterator", "->", "transliterate", "(", "$", "str", ")", ";", "}", "}", "return", "false", ";", "}" ]
Transliterate using the Transliterator package. @param string $str Input string (UTF-8). @return mixed Transliterated string (UTF-8), or false on error.
[ "Transliterate", "using", "the", "Transliterator", "package", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String/Transliterate.php#L77-L93
214,281
moodle/moodle
blocks/rss_client/block_rss_client.php
block_rss_client.get_footer
protected function get_footer($feedrecords) { global $PAGE; $footer = null; if ($this->config->block_rss_client_show_channel_link) { global $CFG; require_once($CFG->libdir.'/simplepie/moodle_simplepie.php'); $feedrecord = array_pop($feedrecords); $feed = new moodle_simplepie($feedrecord->url); $channellink = new moodle_url($feed->get_link()); if (!empty($channellink)) { $footer = new block_rss_client\output\footer($channellink); } } if ($this->hasfailedfeeds) { if (has_any_capability(['block/rss_client:manageownfeeds', 'block/rss_client:manageanyfeeds'], $this->context)) { if ($footer === null) { $footer = new block_rss_client\output\footer(); } $manageurl = new moodle_url('/blocks/rss_client/managefeeds.php', ['courseid' => $PAGE->course->id]); $footer->set_failed($manageurl); } } return $footer; }
php
protected function get_footer($feedrecords) { global $PAGE; $footer = null; if ($this->config->block_rss_client_show_channel_link) { global $CFG; require_once($CFG->libdir.'/simplepie/moodle_simplepie.php'); $feedrecord = array_pop($feedrecords); $feed = new moodle_simplepie($feedrecord->url); $channellink = new moodle_url($feed->get_link()); if (!empty($channellink)) { $footer = new block_rss_client\output\footer($channellink); } } if ($this->hasfailedfeeds) { if (has_any_capability(['block/rss_client:manageownfeeds', 'block/rss_client:manageanyfeeds'], $this->context)) { if ($footer === null) { $footer = new block_rss_client\output\footer(); } $manageurl = new moodle_url('/blocks/rss_client/managefeeds.php', ['courseid' => $PAGE->course->id]); $footer->set_failed($manageurl); } } return $footer; }
[ "protected", "function", "get_footer", "(", "$", "feedrecords", ")", "{", "global", "$", "PAGE", ";", "$", "footer", "=", "null", ";", "if", "(", "$", "this", "->", "config", "->", "block_rss_client_show_channel_link", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/simplepie/moodle_simplepie.php'", ")", ";", "$", "feedrecord", "=", "array_pop", "(", "$", "feedrecords", ")", ";", "$", "feed", "=", "new", "moodle_simplepie", "(", "$", "feedrecord", "->", "url", ")", ";", "$", "channellink", "=", "new", "moodle_url", "(", "$", "feed", "->", "get_link", "(", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "channellink", ")", ")", "{", "$", "footer", "=", "new", "block_rss_client", "\\", "output", "\\", "footer", "(", "$", "channellink", ")", ";", "}", "}", "if", "(", "$", "this", "->", "hasfailedfeeds", ")", "{", "if", "(", "has_any_capability", "(", "[", "'block/rss_client:manageownfeeds'", ",", "'block/rss_client:manageanyfeeds'", "]", ",", "$", "this", "->", "context", ")", ")", "{", "if", "(", "$", "footer", "===", "null", ")", "{", "$", "footer", "=", "new", "block_rss_client", "\\", "output", "\\", "footer", "(", ")", ";", "}", "$", "manageurl", "=", "new", "moodle_url", "(", "'/blocks/rss_client/managefeeds.php'", ",", "[", "'courseid'", "=>", "$", "PAGE", "->", "course", "->", "id", "]", ")", ";", "$", "footer", "->", "set_failed", "(", "$", "manageurl", ")", ";", "}", "}", "return", "$", "footer", ";", "}" ]
Gets the footer, which is the channel link of the last feed in our list of feeds @param array $feedrecords The feed records from the database. @return block_rss_client\output\footer|null The renderable footer or null if none should be displayed.
[ "Gets", "the", "footer", "which", "is", "the", "channel", "link", "of", "the", "last", "feed", "in", "our", "list", "of", "feeds" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/rss_client/block_rss_client.php#L61-L89
214,282
moodle/moodle
blocks/rss_client/block_rss_client.php
block_rss_client.get_feed
public function get_feed($feedrecord, $maxentries, $showtitle) { global $CFG; require_once($CFG->libdir.'/simplepie/moodle_simplepie.php'); if ($feedrecord->skipuntil) { // Last attempt to gather this feed via cron failed - do not try to fetch it now. $this->hasfailedfeeds = true; return null; } $simplepiefeed = new moodle_simplepie($feedrecord->url); if(isset($CFG->block_rss_client_timeout)){ $simplepiefeed->set_cache_duration($CFG->block_rss_client_timeout * 60); } if ($simplepiefeed->error()) { debugging($feedrecord->url .' Failed with code: '.$simplepiefeed->error()); return null; } if(empty($feedrecord->preferredtitle)){ // Simplepie does escape HTML entities. $feedtitle = $this->format_title($simplepiefeed->get_title()); }else{ // Moodle custom title does not does escape HTML entities. $feedtitle = $this->format_title(s($feedrecord->preferredtitle)); } if (empty($this->config->title)){ //NOTE: this means the 'last feed' displayed wins the block title - but //this is exiting behaviour.. $this->title = strip_tags($feedtitle); } $feed = new \block_rss_client\output\feed($feedtitle, $showtitle, $this->config->block_rss_client_show_channel_image); if ($simplepieitems = $simplepiefeed->get_items(0, $maxentries)) { foreach ($simplepieitems as $simplepieitem) { try { $item = new \block_rss_client\output\item( $simplepieitem->get_id(), new moodle_url($simplepieitem->get_link()), $simplepieitem->get_title(), $simplepieitem->get_description(), new moodle_url($simplepieitem->get_permalink()), $simplepieitem->get_date('U'), $this->config->display_description ); $feed->add_item($item); } catch (moodle_exception $e) { // If there is an error with the RSS item, we don't // want to crash the page. Specifically, moodle_url can // throw an exception of the param is an extremely // malformed url. debugging($e->getMessage()); } } } // Feed image. if ($imageurl = $simplepiefeed->get_image_url()) { try { $image = new \block_rss_client\output\channel_image( new moodle_url($imageurl), $simplepiefeed->get_image_title(), new moodle_url($simplepiefeed->get_image_link()) ); $feed->set_image($image); } catch (moodle_exception $e) { // If there is an error with the RSS image, we don'twant to // crash the page. Specifically, moodle_url can throw an // exception if the param is an extremely malformed url. debugging($e->getMessage()); } } return $feed; }
php
public function get_feed($feedrecord, $maxentries, $showtitle) { global $CFG; require_once($CFG->libdir.'/simplepie/moodle_simplepie.php'); if ($feedrecord->skipuntil) { // Last attempt to gather this feed via cron failed - do not try to fetch it now. $this->hasfailedfeeds = true; return null; } $simplepiefeed = new moodle_simplepie($feedrecord->url); if(isset($CFG->block_rss_client_timeout)){ $simplepiefeed->set_cache_duration($CFG->block_rss_client_timeout * 60); } if ($simplepiefeed->error()) { debugging($feedrecord->url .' Failed with code: '.$simplepiefeed->error()); return null; } if(empty($feedrecord->preferredtitle)){ // Simplepie does escape HTML entities. $feedtitle = $this->format_title($simplepiefeed->get_title()); }else{ // Moodle custom title does not does escape HTML entities. $feedtitle = $this->format_title(s($feedrecord->preferredtitle)); } if (empty($this->config->title)){ //NOTE: this means the 'last feed' displayed wins the block title - but //this is exiting behaviour.. $this->title = strip_tags($feedtitle); } $feed = new \block_rss_client\output\feed($feedtitle, $showtitle, $this->config->block_rss_client_show_channel_image); if ($simplepieitems = $simplepiefeed->get_items(0, $maxentries)) { foreach ($simplepieitems as $simplepieitem) { try { $item = new \block_rss_client\output\item( $simplepieitem->get_id(), new moodle_url($simplepieitem->get_link()), $simplepieitem->get_title(), $simplepieitem->get_description(), new moodle_url($simplepieitem->get_permalink()), $simplepieitem->get_date('U'), $this->config->display_description ); $feed->add_item($item); } catch (moodle_exception $e) { // If there is an error with the RSS item, we don't // want to crash the page. Specifically, moodle_url can // throw an exception of the param is an extremely // malformed url. debugging($e->getMessage()); } } } // Feed image. if ($imageurl = $simplepiefeed->get_image_url()) { try { $image = new \block_rss_client\output\channel_image( new moodle_url($imageurl), $simplepiefeed->get_image_title(), new moodle_url($simplepiefeed->get_image_link()) ); $feed->set_image($image); } catch (moodle_exception $e) { // If there is an error with the RSS image, we don'twant to // crash the page. Specifically, moodle_url can throw an // exception if the param is an extremely malformed url. debugging($e->getMessage()); } } return $feed; }
[ "public", "function", "get_feed", "(", "$", "feedrecord", ",", "$", "maxentries", ",", "$", "showtitle", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/simplepie/moodle_simplepie.php'", ")", ";", "if", "(", "$", "feedrecord", "->", "skipuntil", ")", "{", "// Last attempt to gather this feed via cron failed - do not try to fetch it now.", "$", "this", "->", "hasfailedfeeds", "=", "true", ";", "return", "null", ";", "}", "$", "simplepiefeed", "=", "new", "moodle_simplepie", "(", "$", "feedrecord", "->", "url", ")", ";", "if", "(", "isset", "(", "$", "CFG", "->", "block_rss_client_timeout", ")", ")", "{", "$", "simplepiefeed", "->", "set_cache_duration", "(", "$", "CFG", "->", "block_rss_client_timeout", "*", "60", ")", ";", "}", "if", "(", "$", "simplepiefeed", "->", "error", "(", ")", ")", "{", "debugging", "(", "$", "feedrecord", "->", "url", ".", "' Failed with code: '", ".", "$", "simplepiefeed", "->", "error", "(", ")", ")", ";", "return", "null", ";", "}", "if", "(", "empty", "(", "$", "feedrecord", "->", "preferredtitle", ")", ")", "{", "// Simplepie does escape HTML entities.", "$", "feedtitle", "=", "$", "this", "->", "format_title", "(", "$", "simplepiefeed", "->", "get_title", "(", ")", ")", ";", "}", "else", "{", "// Moodle custom title does not does escape HTML entities.", "$", "feedtitle", "=", "$", "this", "->", "format_title", "(", "s", "(", "$", "feedrecord", "->", "preferredtitle", ")", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "config", "->", "title", ")", ")", "{", "//NOTE: this means the 'last feed' displayed wins the block title - but", "//this is exiting behaviour..", "$", "this", "->", "title", "=", "strip_tags", "(", "$", "feedtitle", ")", ";", "}", "$", "feed", "=", "new", "\\", "block_rss_client", "\\", "output", "\\", "feed", "(", "$", "feedtitle", ",", "$", "showtitle", ",", "$", "this", "->", "config", "->", "block_rss_client_show_channel_image", ")", ";", "if", "(", "$", "simplepieitems", "=", "$", "simplepiefeed", "->", "get_items", "(", "0", ",", "$", "maxentries", ")", ")", "{", "foreach", "(", "$", "simplepieitems", "as", "$", "simplepieitem", ")", "{", "try", "{", "$", "item", "=", "new", "\\", "block_rss_client", "\\", "output", "\\", "item", "(", "$", "simplepieitem", "->", "get_id", "(", ")", ",", "new", "moodle_url", "(", "$", "simplepieitem", "->", "get_link", "(", ")", ")", ",", "$", "simplepieitem", "->", "get_title", "(", ")", ",", "$", "simplepieitem", "->", "get_description", "(", ")", ",", "new", "moodle_url", "(", "$", "simplepieitem", "->", "get_permalink", "(", ")", ")", ",", "$", "simplepieitem", "->", "get_date", "(", "'U'", ")", ",", "$", "this", "->", "config", "->", "display_description", ")", ";", "$", "feed", "->", "add_item", "(", "$", "item", ")", ";", "}", "catch", "(", "moodle_exception", "$", "e", ")", "{", "// If there is an error with the RSS item, we don't", "// want to crash the page. Specifically, moodle_url can", "// throw an exception of the param is an extremely", "// malformed url.", "debugging", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}", "}", "// Feed image.", "if", "(", "$", "imageurl", "=", "$", "simplepiefeed", "->", "get_image_url", "(", ")", ")", "{", "try", "{", "$", "image", "=", "new", "\\", "block_rss_client", "\\", "output", "\\", "channel_image", "(", "new", "moodle_url", "(", "$", "imageurl", ")", ",", "$", "simplepiefeed", "->", "get_image_title", "(", ")", ",", "new", "moodle_url", "(", "$", "simplepiefeed", "->", "get_image_link", "(", ")", ")", ")", ";", "$", "feed", "->", "set_image", "(", "$", "image", ")", ";", "}", "catch", "(", "moodle_exception", "$", "e", ")", "{", "// If there is an error with the RSS image, we don'twant to", "// crash the page. Specifically, moodle_url can throw an", "// exception if the param is an extremely malformed url.", "debugging", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}", "return", "$", "feed", ";", "}" ]
Returns the html of a feed to be displaed in the block @param mixed feedrecord The feed record from the database @param int maxentries The maximum number of entries to be displayed @param boolean showtitle Should the feed title be displayed in html @return block_rss_client\output\feed|null The renderable feed or null of there is an error
[ "Returns", "the", "html", "of", "a", "feed", "to", "be", "displaed", "in", "the", "block" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/rss_client/block_rss_client.php#L183-L263
214,283
moodle/moodle
blocks/rss_client/block_rss_client.php
block_rss_client.format_title
function format_title($title,$max=64) { if (core_text::strlen($title) <= $max) { return $title; } else { return core_text::substr($title, 0, $max - 3) . '...'; } }
php
function format_title($title,$max=64) { if (core_text::strlen($title) <= $max) { return $title; } else { return core_text::substr($title, 0, $max - 3) . '...'; } }
[ "function", "format_title", "(", "$", "title", ",", "$", "max", "=", "64", ")", "{", "if", "(", "core_text", "::", "strlen", "(", "$", "title", ")", "<=", "$", "max", ")", "{", "return", "$", "title", ";", "}", "else", "{", "return", "core_text", "::", "substr", "(", "$", "title", ",", "0", ",", "$", "max", "-", "3", ")", ".", "'...'", ";", "}", "}" ]
Strips a large title to size and adds ... if title too long This function does not escape HTML entities, so they have to be escaped before being passed here. @param string title to shorten @param int max character length of title @return string title shortened if necessary
[ "Strips", "a", "large", "title", "to", "size", "and", "adds", "...", "if", "title", "too", "long", "This", "function", "does", "not", "escape", "HTML", "entities", "so", "they", "have", "to", "be", "escaped", "before", "being", "passed", "here", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/rss_client/block_rss_client.php#L274-L281
214,284
moodle/moodle
grade/report/overview/lib.php
grade_report_overview.setup_table
public function setup_table() { /* * Table has 3 columns *| course | final grade | rank (optional) | */ // setting up table headers if ($this->showrank['any']) { $tablecolumns = array('coursename', 'grade', 'rank'); $tableheaders = array($this->get_lang_string('coursename', 'grades'), $this->get_lang_string('grade'), $this->get_lang_string('rank', 'grades')); } else { $tablecolumns = array('coursename', 'grade'); $tableheaders = array($this->get_lang_string('coursename', 'grades'), $this->get_lang_string('grade')); } $this->table = new flexible_table('grade-report-overview-'.$this->user->id); $this->table->define_columns($tablecolumns); $this->table->define_headers($tableheaders); $this->table->define_baseurl($this->baseurl); $this->table->set_attribute('cellspacing', '0'); $this->table->set_attribute('id', 'overview-grade'); $this->table->set_attribute('class', 'boxaligncenter generaltable'); $this->table->setup(); }
php
public function setup_table() { /* * Table has 3 columns *| course | final grade | rank (optional) | */ // setting up table headers if ($this->showrank['any']) { $tablecolumns = array('coursename', 'grade', 'rank'); $tableheaders = array($this->get_lang_string('coursename', 'grades'), $this->get_lang_string('grade'), $this->get_lang_string('rank', 'grades')); } else { $tablecolumns = array('coursename', 'grade'); $tableheaders = array($this->get_lang_string('coursename', 'grades'), $this->get_lang_string('grade')); } $this->table = new flexible_table('grade-report-overview-'.$this->user->id); $this->table->define_columns($tablecolumns); $this->table->define_headers($tableheaders); $this->table->define_baseurl($this->baseurl); $this->table->set_attribute('cellspacing', '0'); $this->table->set_attribute('id', 'overview-grade'); $this->table->set_attribute('class', 'boxaligncenter generaltable'); $this->table->setup(); }
[ "public", "function", "setup_table", "(", ")", "{", "/*\n * Table has 3 columns\n *| course | final grade | rank (optional) |\n */", "// setting up table headers", "if", "(", "$", "this", "->", "showrank", "[", "'any'", "]", ")", "{", "$", "tablecolumns", "=", "array", "(", "'coursename'", ",", "'grade'", ",", "'rank'", ")", ";", "$", "tableheaders", "=", "array", "(", "$", "this", "->", "get_lang_string", "(", "'coursename'", ",", "'grades'", ")", ",", "$", "this", "->", "get_lang_string", "(", "'grade'", ")", ",", "$", "this", "->", "get_lang_string", "(", "'rank'", ",", "'grades'", ")", ")", ";", "}", "else", "{", "$", "tablecolumns", "=", "array", "(", "'coursename'", ",", "'grade'", ")", ";", "$", "tableheaders", "=", "array", "(", "$", "this", "->", "get_lang_string", "(", "'coursename'", ",", "'grades'", ")", ",", "$", "this", "->", "get_lang_string", "(", "'grade'", ")", ")", ";", "}", "$", "this", "->", "table", "=", "new", "flexible_table", "(", "'grade-report-overview-'", ".", "$", "this", "->", "user", "->", "id", ")", ";", "$", "this", "->", "table", "->", "define_columns", "(", "$", "tablecolumns", ")", ";", "$", "this", "->", "table", "->", "define_headers", "(", "$", "tableheaders", ")", ";", "$", "this", "->", "table", "->", "define_baseurl", "(", "$", "this", "->", "baseurl", ")", ";", "$", "this", "->", "table", "->", "set_attribute", "(", "'cellspacing'", ",", "'0'", ")", ";", "$", "this", "->", "table", "->", "set_attribute", "(", "'id'", ",", "'overview-grade'", ")", ";", "$", "this", "->", "table", "->", "set_attribute", "(", "'class'", ",", "'boxaligncenter generaltable'", ")", ";", "$", "this", "->", "table", "->", "setup", "(", ")", ";", "}" ]
Prepares the headers and attributes of the flexitable.
[ "Prepares", "the", "headers", "and", "attributes", "of", "the", "flexitable", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/overview/lib.php#L137-L165
214,285
moodle/moodle
grade/report/overview/lib.php
grade_report_overview.fill_table
public function fill_table($activitylink = false, $studentcoursesonly = false) { global $CFG, $DB, $OUTPUT, $USER; if ($studentcoursesonly && count($this->studentcourseids) == 0) { return false; } // Only show user's courses instead of all courses. if ($this->courses) { $coursesdata = $this->setup_courses_data($studentcoursesonly); foreach ($coursesdata as $coursedata) { $course = $coursedata['course']; $coursecontext = $coursedata['context']; $finalgrade = $coursedata['finalgrade']; $courseitem = $coursedata['courseitem']; $coursename = format_string(get_course_display_name_for_list($course), true, array('context' => $coursecontext)); // Link to the activity report version of the user grade report. if ($activitylink) { $courselink = html_writer::link(new moodle_url('/course/user.php', array('mode' => 'grade', 'id' => $course->id, 'user' => $this->user->id)), $coursename); } else { $courselink = html_writer::link(new moodle_url('/grade/report/user/index.php', array('id' => $course->id, 'userid' => $this->user->id, 'group' => $this->gpr->groupid)), $coursename); } $data = array($courselink, grade_format_gradevalue($finalgrade, $courseitem, true)); if ($this->showrank['any']) { if ($this->showrank[$course->id] && !is_null($finalgrade)) { $rank = $coursedata['rank']; $numusers = $coursedata['numusers']; $data[] = "$rank/$numusers"; } else { // No grade, no rank. // Or this course wants rank hidden. $data[] = '-'; } } $this->table->add_data($data); } return true; } else { echo $OUTPUT->notification(get_string('notenrolled', 'grades'), 'notifymessage'); return false; } }
php
public function fill_table($activitylink = false, $studentcoursesonly = false) { global $CFG, $DB, $OUTPUT, $USER; if ($studentcoursesonly && count($this->studentcourseids) == 0) { return false; } // Only show user's courses instead of all courses. if ($this->courses) { $coursesdata = $this->setup_courses_data($studentcoursesonly); foreach ($coursesdata as $coursedata) { $course = $coursedata['course']; $coursecontext = $coursedata['context']; $finalgrade = $coursedata['finalgrade']; $courseitem = $coursedata['courseitem']; $coursename = format_string(get_course_display_name_for_list($course), true, array('context' => $coursecontext)); // Link to the activity report version of the user grade report. if ($activitylink) { $courselink = html_writer::link(new moodle_url('/course/user.php', array('mode' => 'grade', 'id' => $course->id, 'user' => $this->user->id)), $coursename); } else { $courselink = html_writer::link(new moodle_url('/grade/report/user/index.php', array('id' => $course->id, 'userid' => $this->user->id, 'group' => $this->gpr->groupid)), $coursename); } $data = array($courselink, grade_format_gradevalue($finalgrade, $courseitem, true)); if ($this->showrank['any']) { if ($this->showrank[$course->id] && !is_null($finalgrade)) { $rank = $coursedata['rank']; $numusers = $coursedata['numusers']; $data[] = "$rank/$numusers"; } else { // No grade, no rank. // Or this course wants rank hidden. $data[] = '-'; } } $this->table->add_data($data); } return true; } else { echo $OUTPUT->notification(get_string('notenrolled', 'grades'), 'notifymessage'); return false; } }
[ "public", "function", "fill_table", "(", "$", "activitylink", "=", "false", ",", "$", "studentcoursesonly", "=", "false", ")", "{", "global", "$", "CFG", ",", "$", "DB", ",", "$", "OUTPUT", ",", "$", "USER", ";", "if", "(", "$", "studentcoursesonly", "&&", "count", "(", "$", "this", "->", "studentcourseids", ")", "==", "0", ")", "{", "return", "false", ";", "}", "// Only show user's courses instead of all courses.", "if", "(", "$", "this", "->", "courses", ")", "{", "$", "coursesdata", "=", "$", "this", "->", "setup_courses_data", "(", "$", "studentcoursesonly", ")", ";", "foreach", "(", "$", "coursesdata", "as", "$", "coursedata", ")", "{", "$", "course", "=", "$", "coursedata", "[", "'course'", "]", ";", "$", "coursecontext", "=", "$", "coursedata", "[", "'context'", "]", ";", "$", "finalgrade", "=", "$", "coursedata", "[", "'finalgrade'", "]", ";", "$", "courseitem", "=", "$", "coursedata", "[", "'courseitem'", "]", ";", "$", "coursename", "=", "format_string", "(", "get_course_display_name_for_list", "(", "$", "course", ")", ",", "true", ",", "array", "(", "'context'", "=>", "$", "coursecontext", ")", ")", ";", "// Link to the activity report version of the user grade report.", "if", "(", "$", "activitylink", ")", "{", "$", "courselink", "=", "html_writer", "::", "link", "(", "new", "moodle_url", "(", "'/course/user.php'", ",", "array", "(", "'mode'", "=>", "'grade'", ",", "'id'", "=>", "$", "course", "->", "id", ",", "'user'", "=>", "$", "this", "->", "user", "->", "id", ")", ")", ",", "$", "coursename", ")", ";", "}", "else", "{", "$", "courselink", "=", "html_writer", "::", "link", "(", "new", "moodle_url", "(", "'/grade/report/user/index.php'", ",", "array", "(", "'id'", "=>", "$", "course", "->", "id", ",", "'userid'", "=>", "$", "this", "->", "user", "->", "id", ",", "'group'", "=>", "$", "this", "->", "gpr", "->", "groupid", ")", ")", ",", "$", "coursename", ")", ";", "}", "$", "data", "=", "array", "(", "$", "courselink", ",", "grade_format_gradevalue", "(", "$", "finalgrade", ",", "$", "courseitem", ",", "true", ")", ")", ";", "if", "(", "$", "this", "->", "showrank", "[", "'any'", "]", ")", "{", "if", "(", "$", "this", "->", "showrank", "[", "$", "course", "->", "id", "]", "&&", "!", "is_null", "(", "$", "finalgrade", ")", ")", "{", "$", "rank", "=", "$", "coursedata", "[", "'rank'", "]", ";", "$", "numusers", "=", "$", "coursedata", "[", "'numusers'", "]", ";", "$", "data", "[", "]", "=", "\"$rank/$numusers\"", ";", "}", "else", "{", "// No grade, no rank.", "// Or this course wants rank hidden.", "$", "data", "[", "]", "=", "'-'", ";", "}", "}", "$", "this", "->", "table", "->", "add_data", "(", "$", "data", ")", ";", "}", "return", "true", ";", "}", "else", "{", "echo", "$", "OUTPUT", "->", "notification", "(", "get_string", "(", "'notenrolled'", ",", "'grades'", ")", ",", "'notifymessage'", ")", ";", "return", "false", ";", "}", "}" ]
Fill the table for displaying. @param bool $activitylink If this report link to the activity report or the user report. @param bool $studentcoursesonly Only show courses that the user is a student of.
[ "Fill", "the", "table", "for", "displaying", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/overview/lib.php#L264-L314
214,286
moodle/moodle
grade/report/overview/lib.php
grade_report_overview.print_table
public function print_table($return=false) { ob_start(); $this->table->print_html(); $html = ob_get_clean(); if ($return) { return $html; } else { echo $html; } }
php
public function print_table($return=false) { ob_start(); $this->table->print_html(); $html = ob_get_clean(); if ($return) { return $html; } else { echo $html; } }
[ "public", "function", "print_table", "(", "$", "return", "=", "false", ")", "{", "ob_start", "(", ")", ";", "$", "this", "->", "table", "->", "print_html", "(", ")", ";", "$", "html", "=", "ob_get_clean", "(", ")", ";", "if", "(", "$", "return", ")", "{", "return", "$", "html", ";", "}", "else", "{", "echo", "$", "html", ";", "}", "}" ]
Prints or returns the HTML from the flexitable. @param bool $return Whether or not to return the data instead of printing it directly. @return string
[ "Prints", "or", "returns", "the", "HTML", "from", "the", "flexitable", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/overview/lib.php#L321-L330
214,287
moodle/moodle
grade/report/overview/lib.php
grade_report_overview.print_teacher_table
public function print_teacher_table() { $table = new html_table(); $table->head = array(get_string('coursename', 'grades')); $table->data = null; foreach ($this->teachercourses as $courseid => $course) { $url = new moodle_url('/grade/report/index.php', array('id' => $courseid)); $table->data[] = array(html_writer::link($url, $course->fullname)); } echo html_writer::table($table); }
php
public function print_teacher_table() { $table = new html_table(); $table->head = array(get_string('coursename', 'grades')); $table->data = null; foreach ($this->teachercourses as $courseid => $course) { $url = new moodle_url('/grade/report/index.php', array('id' => $courseid)); $table->data[] = array(html_writer::link($url, $course->fullname)); } echo html_writer::table($table); }
[ "public", "function", "print_teacher_table", "(", ")", "{", "$", "table", "=", "new", "html_table", "(", ")", ";", "$", "table", "->", "head", "=", "array", "(", "get_string", "(", "'coursename'", ",", "'grades'", ")", ")", ";", "$", "table", "->", "data", "=", "null", ";", "foreach", "(", "$", "this", "->", "teachercourses", "as", "$", "courseid", "=>", "$", "course", ")", "{", "$", "url", "=", "new", "moodle_url", "(", "'/grade/report/index.php'", ",", "array", "(", "'id'", "=>", "$", "courseid", ")", ")", ";", "$", "table", "->", "data", "[", "]", "=", "array", "(", "html_writer", "::", "link", "(", "$", "url", ",", "$", "course", "->", "fullname", ")", ")", ";", "}", "echo", "html_writer", "::", "table", "(", "$", "table", ")", ";", "}" ]
Print a table to show courses that the user is able to grade.
[ "Print", "a", "table", "to", "show", "courses", "that", "the", "user", "is", "able", "to", "grade", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/overview/lib.php#L335-L344
214,288
moodle/moodle
grade/report/overview/lib.php
grade_report_overview.check_access
public static function check_access($systemcontext, $context, $personalcontext, $course, $userid) { global $USER; $access = false; if (has_capability('moodle/grade:viewall', $systemcontext)) { // Ok - can view all course grades. $access = true; } else if (has_capability('moodle/grade:viewall', $context)) { // Ok - can view any grades in context. $access = true; } else if ($userid == $USER->id and ((has_capability('moodle/grade:view', $context) and $course->showgrades) || $course->id == SITEID)) { // Ok - can view own course grades. $access = true; } else if (has_capability('moodle/grade:viewall', $personalcontext) and $course->showgrades) { // Ok - can view grades of this user - parent most probably. $access = true; } else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and $course->showgrades) { // Ok - can view grades of this user - parent most probably. $access = true; } return $access; }
php
public static function check_access($systemcontext, $context, $personalcontext, $course, $userid) { global $USER; $access = false; if (has_capability('moodle/grade:viewall', $systemcontext)) { // Ok - can view all course grades. $access = true; } else if (has_capability('moodle/grade:viewall', $context)) { // Ok - can view any grades in context. $access = true; } else if ($userid == $USER->id and ((has_capability('moodle/grade:view', $context) and $course->showgrades) || $course->id == SITEID)) { // Ok - can view own course grades. $access = true; } else if (has_capability('moodle/grade:viewall', $personalcontext) and $course->showgrades) { // Ok - can view grades of this user - parent most probably. $access = true; } else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and $course->showgrades) { // Ok - can view grades of this user - parent most probably. $access = true; } return $access; }
[ "public", "static", "function", "check_access", "(", "$", "systemcontext", ",", "$", "context", ",", "$", "personalcontext", ",", "$", "course", ",", "$", "userid", ")", "{", "global", "$", "USER", ";", "$", "access", "=", "false", ";", "if", "(", "has_capability", "(", "'moodle/grade:viewall'", ",", "$", "systemcontext", ")", ")", "{", "// Ok - can view all course grades.", "$", "access", "=", "true", ";", "}", "else", "if", "(", "has_capability", "(", "'moodle/grade:viewall'", ",", "$", "context", ")", ")", "{", "// Ok - can view any grades in context.", "$", "access", "=", "true", ";", "}", "else", "if", "(", "$", "userid", "==", "$", "USER", "->", "id", "and", "(", "(", "has_capability", "(", "'moodle/grade:view'", ",", "$", "context", ")", "and", "$", "course", "->", "showgrades", ")", "||", "$", "course", "->", "id", "==", "SITEID", ")", ")", "{", "// Ok - can view own course grades.", "$", "access", "=", "true", ";", "}", "else", "if", "(", "has_capability", "(", "'moodle/grade:viewall'", ",", "$", "personalcontext", ")", "and", "$", "course", "->", "showgrades", ")", "{", "// Ok - can view grades of this user - parent most probably.", "$", "access", "=", "true", ";", "}", "else", "if", "(", "has_capability", "(", "'moodle/user:viewuseractivitiesreport'", ",", "$", "personalcontext", ")", "and", "$", "course", "->", "showgrades", ")", "{", "// Ok - can view grades of this user - parent most probably.", "$", "access", "=", "true", ";", "}", "return", "$", "access", ";", "}" ]
Check if the user can access the report. @param stdClass $systemcontext system context @param stdClass $context course context @param stdClass $personalcontext personal context @param stdClass $course course object @param int $userid userid @return bool true if the user can access the report @since Moodle 3.2
[ "Check", "if", "the", "user", "can", "access", "the", "report", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/overview/lib.php#L374-L399
214,289
moodle/moodle
grade/report/overview/lib.php
grade_report_overview.viewed
public static function viewed($context, $courseid, $userid) { $event = \gradereport_overview\event\grade_report_viewed::create( array( 'context' => $context, 'courseid' => $courseid, 'relateduserid' => $userid, ) ); $event->trigger(); }
php
public static function viewed($context, $courseid, $userid) { $event = \gradereport_overview\event\grade_report_viewed::create( array( 'context' => $context, 'courseid' => $courseid, 'relateduserid' => $userid, ) ); $event->trigger(); }
[ "public", "static", "function", "viewed", "(", "$", "context", ",", "$", "courseid", ",", "$", "userid", ")", "{", "$", "event", "=", "\\", "gradereport_overview", "\\", "event", "\\", "grade_report_viewed", "::", "create", "(", "array", "(", "'context'", "=>", "$", "context", ",", "'courseid'", "=>", "$", "courseid", ",", "'relateduserid'", "=>", "$", "userid", ",", ")", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Trigger the grade_report_viewed event @param stdClass $context course context @param int $courseid course id @param int $userid user id @since Moodle 3.2
[ "Trigger", "the", "grade_report_viewed", "event" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/overview/lib.php#L409-L418
214,290
moodle/moodle
lib/bennu/iCalendar_properties.php
iCalendar_property.is_valid_value
function is_valid_value($value) { if(is_array($value)) { if(!$this->val_multi) { return false; } else { foreach($value as $oneval) { if(!rfc2445_is_valid_value($oneval, $this->val_type)) { return false; } } } return true; } return rfc2445_is_valid_value($value, $this->val_type); }
php
function is_valid_value($value) { if(is_array($value)) { if(!$this->val_multi) { return false; } else { foreach($value as $oneval) { if(!rfc2445_is_valid_value($oneval, $this->val_type)) { return false; } } } return true; } return rfc2445_is_valid_value($value, $this->val_type); }
[ "function", "is_valid_value", "(", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "if", "(", "!", "$", "this", "->", "val_multi", ")", "{", "return", "false", ";", "}", "else", "{", "foreach", "(", "$", "value", "as", "$", "oneval", ")", "{", "if", "(", "!", "rfc2445_is_valid_value", "(", "$", "oneval", ",", "$", "this", "->", "val_type", ")", ")", "{", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}", "return", "rfc2445_is_valid_value", "(", "$", "value", ",", "$", "this", "->", "val_type", ")", ";", "}" ]
Only data type validation is done here
[ "Only", "data", "type", "validation", "is", "done", "here" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/bennu/iCalendar_properties.php#L57-L72
214,291
moodle/moodle
mod/workshop/form/rubric/backup/moodle1/lib.php
moodle1_workshopform_rubric_handler.on_elements_end
public function on_elements_end() { $numofrubrics = 0; foreach ($this->rubrics as $itemid => $levels) { $numofrubrics += count($levels); } if ($numofrubrics == 0) { $this->convert_legacy_criterion_elements(); } else { $this->convert_legacy_rubric_elements(); } }
php
public function on_elements_end() { $numofrubrics = 0; foreach ($this->rubrics as $itemid => $levels) { $numofrubrics += count($levels); } if ($numofrubrics == 0) { $this->convert_legacy_criterion_elements(); } else { $this->convert_legacy_rubric_elements(); } }
[ "public", "function", "on_elements_end", "(", ")", "{", "$", "numofrubrics", "=", "0", ";", "foreach", "(", "$", "this", "->", "rubrics", "as", "$", "itemid", "=>", "$", "levels", ")", "{", "$", "numofrubrics", "+=", "count", "(", "$", "levels", ")", ";", "}", "if", "(", "$", "numofrubrics", "==", "0", ")", "{", "$", "this", "->", "convert_legacy_criterion_elements", "(", ")", ";", "}", "else", "{", "$", "this", "->", "convert_legacy_rubric_elements", "(", ")", ";", "}", "}" ]
Processes gathered elements and rubrics
[ "Processes", "gathered", "elements", "and", "rubrics" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/rubric/backup/moodle1/lib.php#L68-L81
214,292
moodle/moodle
mod/workshop/form/rubric/backup/moodle1/lib.php
moodle1_workshopform_rubric_handler.convert_legacy_criterion_elements
protected function convert_legacy_criterion_elements() { $this->write_xml('workshopform_rubric_config', array('layout' => 'list')); $firstelement = reset($this->elements); if ($firstelement === false) { // no elements defined in moodle.xml return; } // write the xml describing the artificial single rubric item $this->xmlwriter->begin_tag('workshopform_rubric_dimension', array('id' => $firstelement['id'])); $this->xmlwriter->full_tag('sort', 1); $this->xmlwriter->full_tag('description', trim(get_string('dimensionnumber', 'workshopform_rubric', ''))); $this->xmlwriter->full_tag('descriptionformat', FORMAT_HTML); foreach ($this->elements as $element) { $this->write_xml('workshopform_rubric_level', array( 'id' => $element['id'], 'grade' => $element['maxscore'], 'definition' => $element['description'], 'definitionformat' => FORMAT_HTML ), array('/workshopform_rubric_level/id')); } $this->xmlwriter->end_tag('workshopform_rubric_dimension'); }
php
protected function convert_legacy_criterion_elements() { $this->write_xml('workshopform_rubric_config', array('layout' => 'list')); $firstelement = reset($this->elements); if ($firstelement === false) { // no elements defined in moodle.xml return; } // write the xml describing the artificial single rubric item $this->xmlwriter->begin_tag('workshopform_rubric_dimension', array('id' => $firstelement['id'])); $this->xmlwriter->full_tag('sort', 1); $this->xmlwriter->full_tag('description', trim(get_string('dimensionnumber', 'workshopform_rubric', ''))); $this->xmlwriter->full_tag('descriptionformat', FORMAT_HTML); foreach ($this->elements as $element) { $this->write_xml('workshopform_rubric_level', array( 'id' => $element['id'], 'grade' => $element['maxscore'], 'definition' => $element['description'], 'definitionformat' => FORMAT_HTML ), array('/workshopform_rubric_level/id')); } $this->xmlwriter->end_tag('workshopform_rubric_dimension'); }
[ "protected", "function", "convert_legacy_criterion_elements", "(", ")", "{", "$", "this", "->", "write_xml", "(", "'workshopform_rubric_config'", ",", "array", "(", "'layout'", "=>", "'list'", ")", ")", ";", "$", "firstelement", "=", "reset", "(", "$", "this", "->", "elements", ")", ";", "if", "(", "$", "firstelement", "===", "false", ")", "{", "// no elements defined in moodle.xml", "return", ";", "}", "// write the xml describing the artificial single rubric item", "$", "this", "->", "xmlwriter", "->", "begin_tag", "(", "'workshopform_rubric_dimension'", ",", "array", "(", "'id'", "=>", "$", "firstelement", "[", "'id'", "]", ")", ")", ";", "$", "this", "->", "xmlwriter", "->", "full_tag", "(", "'sort'", ",", "1", ")", ";", "$", "this", "->", "xmlwriter", "->", "full_tag", "(", "'description'", ",", "trim", "(", "get_string", "(", "'dimensionnumber'", ",", "'workshopform_rubric'", ",", "''", ")", ")", ")", ";", "$", "this", "->", "xmlwriter", "->", "full_tag", "(", "'descriptionformat'", ",", "FORMAT_HTML", ")", ";", "foreach", "(", "$", "this", "->", "elements", "as", "$", "element", ")", "{", "$", "this", "->", "write_xml", "(", "'workshopform_rubric_level'", ",", "array", "(", "'id'", "=>", "$", "element", "[", "'id'", "]", ",", "'grade'", "=>", "$", "element", "[", "'maxscore'", "]", ",", "'definition'", "=>", "$", "element", "[", "'description'", "]", ",", "'definitionformat'", "=>", "FORMAT_HTML", ")", ",", "array", "(", "'/workshopform_rubric_level/id'", ")", ")", ";", "}", "$", "this", "->", "xmlwriter", "->", "end_tag", "(", "'workshopform_rubric_dimension'", ")", ";", "}" ]
Processes gathered elements coming from the legacy criterion strategy Legacy criterion strategy is converted to a rubric with single rubric item and the layout set to 'list'.
[ "Processes", "gathered", "elements", "coming", "from", "the", "legacy", "criterion", "strategy" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/rubric/backup/moodle1/lib.php#L89-L115
214,293
moodle/moodle
mod/workshop/form/rubric/backup/moodle1/lib.php
moodle1_workshopform_rubric_handler.convert_legacy_rubric_elements
protected function convert_legacy_rubric_elements() { $this->write_xml('workshopform_rubric_config', array('layout' => 'grid')); foreach ($this->elements as $element) { $this->xmlwriter->begin_tag('workshopform_rubric_dimension', array('id' => $element['id'])); $this->xmlwriter->full_tag('sort', $element['elementno']); $this->xmlwriter->full_tag('description', $element['description']); $this->xmlwriter->full_tag('descriptionformat', FORMAT_HTML); foreach ($this->rubrics[$element['id']] as $rubric) { $fakerecord = new stdClass(); $fakerecord->rgrade = $rubric['rubricno']; $fakerecord->eweight = $element['weight']; $fakerecord->rdesc = $rubric['description']; $level = (array)workshopform_rubric_upgrade_rubric_level($fakerecord, $element['id']); unset($level['dimensionid']); $level['id'] = $this->converter->get_nextid(); $this->write_xml('workshopform_rubric_level', $level, array('/workshopform_rubric_level/id')); } $this->xmlwriter->end_tag('workshopform_rubric_dimension'); } }
php
protected function convert_legacy_rubric_elements() { $this->write_xml('workshopform_rubric_config', array('layout' => 'grid')); foreach ($this->elements as $element) { $this->xmlwriter->begin_tag('workshopform_rubric_dimension', array('id' => $element['id'])); $this->xmlwriter->full_tag('sort', $element['elementno']); $this->xmlwriter->full_tag('description', $element['description']); $this->xmlwriter->full_tag('descriptionformat', FORMAT_HTML); foreach ($this->rubrics[$element['id']] as $rubric) { $fakerecord = new stdClass(); $fakerecord->rgrade = $rubric['rubricno']; $fakerecord->eweight = $element['weight']; $fakerecord->rdesc = $rubric['description']; $level = (array)workshopform_rubric_upgrade_rubric_level($fakerecord, $element['id']); unset($level['dimensionid']); $level['id'] = $this->converter->get_nextid(); $this->write_xml('workshopform_rubric_level', $level, array('/workshopform_rubric_level/id')); } $this->xmlwriter->end_tag('workshopform_rubric_dimension'); } }
[ "protected", "function", "convert_legacy_rubric_elements", "(", ")", "{", "$", "this", "->", "write_xml", "(", "'workshopform_rubric_config'", ",", "array", "(", "'layout'", "=>", "'grid'", ")", ")", ";", "foreach", "(", "$", "this", "->", "elements", "as", "$", "element", ")", "{", "$", "this", "->", "xmlwriter", "->", "begin_tag", "(", "'workshopform_rubric_dimension'", ",", "array", "(", "'id'", "=>", "$", "element", "[", "'id'", "]", ")", ")", ";", "$", "this", "->", "xmlwriter", "->", "full_tag", "(", "'sort'", ",", "$", "element", "[", "'elementno'", "]", ")", ";", "$", "this", "->", "xmlwriter", "->", "full_tag", "(", "'description'", ",", "$", "element", "[", "'description'", "]", ")", ";", "$", "this", "->", "xmlwriter", "->", "full_tag", "(", "'descriptionformat'", ",", "FORMAT_HTML", ")", ";", "foreach", "(", "$", "this", "->", "rubrics", "[", "$", "element", "[", "'id'", "]", "]", "as", "$", "rubric", ")", "{", "$", "fakerecord", "=", "new", "stdClass", "(", ")", ";", "$", "fakerecord", "->", "rgrade", "=", "$", "rubric", "[", "'rubricno'", "]", ";", "$", "fakerecord", "->", "eweight", "=", "$", "element", "[", "'weight'", "]", ";", "$", "fakerecord", "->", "rdesc", "=", "$", "rubric", "[", "'description'", "]", ";", "$", "level", "=", "(", "array", ")", "workshopform_rubric_upgrade_rubric_level", "(", "$", "fakerecord", ",", "$", "element", "[", "'id'", "]", ")", ";", "unset", "(", "$", "level", "[", "'dimensionid'", "]", ")", ";", "$", "level", "[", "'id'", "]", "=", "$", "this", "->", "converter", "->", "get_nextid", "(", ")", ";", "$", "this", "->", "write_xml", "(", "'workshopform_rubric_level'", ",", "$", "level", ",", "array", "(", "'/workshopform_rubric_level/id'", ")", ")", ";", "}", "$", "this", "->", "xmlwriter", "->", "end_tag", "(", "'workshopform_rubric_dimension'", ")", ";", "}", "}" ]
Processes gathered elements coming from the legacy rubric strategy
[ "Processes", "gathered", "elements", "coming", "from", "the", "legacy", "rubric", "strategy" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/rubric/backup/moodle1/lib.php#L120-L142
214,294
moodle/moodle
backup/cc/cc_lib/cc_resources.php
cc_resource.import_resource
public function import_resource(DOMElement &$node, cc_i_manifest &$doc) { $searchstr = "//imscc:manifest[@identifier='".$doc->manifestID(). "']/imscc:resources/imscc:resource"; $this->identifier = $this->get_attr_value($node, "identifier"); $this->type = $this->get_attr_value($node, "type"); $this->href = $this->get_attr_value($node, "href"); $this->base = $this->get_attr_value($node, "base"); $this->persiststate = null; $nodo = $doc->nodeList($searchstr."[@identifier='". $this->identifier."']/metadata/@href"); $this->metadata = $nodo->nodeValue; $this->filename = $this->href; $nlist = $doc->nodeList($searchstr."[@identifier='". $this->identifier."']/imscc:file/@href"); $this->files = array(); foreach ($nlist as $file) { $this->files[] = $file->nodeValue; } $nlist = $doc->nodeList($searchstr."[@identifier='". $this->identifier."']/imscc:dependency/@identifierref"); $this->dependency = array(); foreach ($nlist as $dependency) { $this->dependency[] = $dependency->nodeValue; } $this->isempty = false; }
php
public function import_resource(DOMElement &$node, cc_i_manifest &$doc) { $searchstr = "//imscc:manifest[@identifier='".$doc->manifestID(). "']/imscc:resources/imscc:resource"; $this->identifier = $this->get_attr_value($node, "identifier"); $this->type = $this->get_attr_value($node, "type"); $this->href = $this->get_attr_value($node, "href"); $this->base = $this->get_attr_value($node, "base"); $this->persiststate = null; $nodo = $doc->nodeList($searchstr."[@identifier='". $this->identifier."']/metadata/@href"); $this->metadata = $nodo->nodeValue; $this->filename = $this->href; $nlist = $doc->nodeList($searchstr."[@identifier='". $this->identifier."']/imscc:file/@href"); $this->files = array(); foreach ($nlist as $file) { $this->files[] = $file->nodeValue; } $nlist = $doc->nodeList($searchstr."[@identifier='". $this->identifier."']/imscc:dependency/@identifierref"); $this->dependency = array(); foreach ($nlist as $dependency) { $this->dependency[] = $dependency->nodeValue; } $this->isempty = false; }
[ "public", "function", "import_resource", "(", "DOMElement", "&", "$", "node", ",", "cc_i_manifest", "&", "$", "doc", ")", "{", "$", "searchstr", "=", "\"//imscc:manifest[@identifier='\"", ".", "$", "doc", "->", "manifestID", "(", ")", ".", "\"']/imscc:resources/imscc:resource\"", ";", "$", "this", "->", "identifier", "=", "$", "this", "->", "get_attr_value", "(", "$", "node", ",", "\"identifier\"", ")", ";", "$", "this", "->", "type", "=", "$", "this", "->", "get_attr_value", "(", "$", "node", ",", "\"type\"", ")", ";", "$", "this", "->", "href", "=", "$", "this", "->", "get_attr_value", "(", "$", "node", ",", "\"href\"", ")", ";", "$", "this", "->", "base", "=", "$", "this", "->", "get_attr_value", "(", "$", "node", ",", "\"base\"", ")", ";", "$", "this", "->", "persiststate", "=", "null", ";", "$", "nodo", "=", "$", "doc", "->", "nodeList", "(", "$", "searchstr", ".", "\"[@identifier='\"", ".", "$", "this", "->", "identifier", ".", "\"']/metadata/@href\"", ")", ";", "$", "this", "->", "metadata", "=", "$", "nodo", "->", "nodeValue", ";", "$", "this", "->", "filename", "=", "$", "this", "->", "href", ";", "$", "nlist", "=", "$", "doc", "->", "nodeList", "(", "$", "searchstr", ".", "\"[@identifier='\"", ".", "$", "this", "->", "identifier", ".", "\"']/imscc:file/@href\"", ")", ";", "$", "this", "->", "files", "=", "array", "(", ")", ";", "foreach", "(", "$", "nlist", "as", "$", "file", ")", "{", "$", "this", "->", "files", "[", "]", "=", "$", "file", "->", "nodeValue", ";", "}", "$", "nlist", "=", "$", "doc", "->", "nodeList", "(", "$", "searchstr", ".", "\"[@identifier='\"", ".", "$", "this", "->", "identifier", ".", "\"']/imscc:dependency/@identifierref\"", ")", ";", "$", "this", "->", "dependency", "=", "array", "(", ")", ";", "foreach", "(", "$", "nlist", "as", "$", "dependency", ")", "{", "$", "this", "->", "dependency", "[", "]", "=", "$", "dependency", "->", "nodeValue", ";", "}", "$", "this", "->", "isempty", "=", "false", ";", "}" ]
Import a resource @param DOMElement $node @param cc_i_manifest $doc
[ "Import", "a", "resource" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/cc/cc_lib/cc_resources.php#L129-L155
214,295
moodle/moodle
backup/cc/cc_lib/cc_resources.php
cc_resource.process_resource
public function process_resource($manifestroot, &$fname, $folder) { $file = empty($folder) ? $manifestroot.'/'.$fname : $manifestroot.'/'.$folder.'/'.$fname; if (!file_exists($file) && $this->throwonerror) { throw new Exception('The file doesnt exist!'); } GetDepFiles($manifestroot, $fname, $this->folder, $this->files); array_unshift($this->files, $folder.$fname); $this->init_empty_new(); $this->href = $folder.$fname; $this->identifierref = $folder.$fname; $this->filename = $fname; $this->isempty = false; $this->folder = $folder; }
php
public function process_resource($manifestroot, &$fname, $folder) { $file = empty($folder) ? $manifestroot.'/'.$fname : $manifestroot.'/'.$folder.'/'.$fname; if (!file_exists($file) && $this->throwonerror) { throw new Exception('The file doesnt exist!'); } GetDepFiles($manifestroot, $fname, $this->folder, $this->files); array_unshift($this->files, $folder.$fname); $this->init_empty_new(); $this->href = $folder.$fname; $this->identifierref = $folder.$fname; $this->filename = $fname; $this->isempty = false; $this->folder = $folder; }
[ "public", "function", "process_resource", "(", "$", "manifestroot", ",", "&", "$", "fname", ",", "$", "folder", ")", "{", "$", "file", "=", "empty", "(", "$", "folder", ")", "?", "$", "manifestroot", ".", "'/'", ".", "$", "fname", ":", "$", "manifestroot", ".", "'/'", ".", "$", "folder", ".", "'/'", ".", "$", "fname", ";", "if", "(", "!", "file_exists", "(", "$", "file", ")", "&&", "$", "this", "->", "throwonerror", ")", "{", "throw", "new", "Exception", "(", "'The file doesnt exist!'", ")", ";", "}", "GetDepFiles", "(", "$", "manifestroot", ",", "$", "fname", ",", "$", "this", "->", "folder", ",", "$", "this", "->", "files", ")", ";", "array_unshift", "(", "$", "this", "->", "files", ",", "$", "folder", ".", "$", "fname", ")", ";", "$", "this", "->", "init_empty_new", "(", ")", ";", "$", "this", "->", "href", "=", "$", "folder", ".", "$", "fname", ";", "$", "this", "->", "identifierref", "=", "$", "folder", ".", "$", "fname", ";", "$", "this", "->", "filename", "=", "$", "fname", ";", "$", "this", "->", "isempty", "=", "false", ";", "$", "this", "->", "folder", "=", "$", "folder", ";", "}" ]
Process a resource @param string $manifestroot @param string $fname @param string $folder
[ "Process", "a", "resource" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/cc/cc_lib/cc_resources.php#L179-L193
214,296
moodle/moodle
completion/classes/progress.php
progress.get_course_progress_percentage
public static function get_course_progress_percentage($course, $userid = 0) { global $USER; // Make sure we continue with a valid userid. if (empty($userid)) { $userid = $USER->id; } $completion = new \completion_info($course); // First, let's make sure completion is enabled. if (!$completion->is_enabled()) { return null; } if (!$completion->is_tracked_user($userid)) { return null; } // Before we check how many modules have been completed see if the course has. if ($completion->is_course_complete($userid)) { return 100; } // Get the number of modules that support completion. $modules = $completion->get_activities(); $count = count($modules); if (!$count) { return null; } // Get the number of modules that have been completed. $completed = 0; foreach ($modules as $module) { $data = $completion->get_data($module, true, $userid); $completed += $data->completionstate == COMPLETION_INCOMPLETE ? 0 : 1; } return ($completed / $count) * 100; }
php
public static function get_course_progress_percentage($course, $userid = 0) { global $USER; // Make sure we continue with a valid userid. if (empty($userid)) { $userid = $USER->id; } $completion = new \completion_info($course); // First, let's make sure completion is enabled. if (!$completion->is_enabled()) { return null; } if (!$completion->is_tracked_user($userid)) { return null; } // Before we check how many modules have been completed see if the course has. if ($completion->is_course_complete($userid)) { return 100; } // Get the number of modules that support completion. $modules = $completion->get_activities(); $count = count($modules); if (!$count) { return null; } // Get the number of modules that have been completed. $completed = 0; foreach ($modules as $module) { $data = $completion->get_data($module, true, $userid); $completed += $data->completionstate == COMPLETION_INCOMPLETE ? 0 : 1; } return ($completed / $count) * 100; }
[ "public", "static", "function", "get_course_progress_percentage", "(", "$", "course", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "USER", ";", "// Make sure we continue with a valid userid.", "if", "(", "empty", "(", "$", "userid", ")", ")", "{", "$", "userid", "=", "$", "USER", "->", "id", ";", "}", "$", "completion", "=", "new", "\\", "completion_info", "(", "$", "course", ")", ";", "// First, let's make sure completion is enabled.", "if", "(", "!", "$", "completion", "->", "is_enabled", "(", ")", ")", "{", "return", "null", ";", "}", "if", "(", "!", "$", "completion", "->", "is_tracked_user", "(", "$", "userid", ")", ")", "{", "return", "null", ";", "}", "// Before we check how many modules have been completed see if the course has.", "if", "(", "$", "completion", "->", "is_course_complete", "(", "$", "userid", ")", ")", "{", "return", "100", ";", "}", "// Get the number of modules that support completion.", "$", "modules", "=", "$", "completion", "->", "get_activities", "(", ")", ";", "$", "count", "=", "count", "(", "$", "modules", ")", ";", "if", "(", "!", "$", "count", ")", "{", "return", "null", ";", "}", "// Get the number of modules that have been completed.", "$", "completed", "=", "0", ";", "foreach", "(", "$", "modules", "as", "$", "module", ")", "{", "$", "data", "=", "$", "completion", "->", "get_data", "(", "$", "module", ",", "true", ",", "$", "userid", ")", ";", "$", "completed", "+=", "$", "data", "->", "completionstate", "==", "COMPLETION_INCOMPLETE", "?", "0", ":", "1", ";", "}", "return", "(", "$", "completed", "/", "$", "count", ")", "*", "100", ";", "}" ]
Returns the course percentage completed by a certain user, returns null if no completion data is available. @param \stdClass $course Moodle course object @param int $userid The id of the user, 0 for the current user @return null|float The percentage, or null if completion is not supported in the course, or there are no activities that support completion.
[ "Returns", "the", "course", "percentage", "completed", "by", "a", "certain", "user", "returns", "null", "if", "no", "completion", "data", "is", "available", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/progress.php#L48-L87
214,297
moodle/moodle
lib/phpexcel/PHPExcel/Style/Color.php
PHPExcel_Style_Color.changeBrightness
public static function changeBrightness($hex, $adjustPercentage) { $rgba = (strlen($hex) == 8); $red = self::getRed($hex, false); $green = self::getGreen($hex, false); $blue = self::getBlue($hex, false); if ($adjustPercentage > 0) { $red += (255 - $red) * $adjustPercentage; $green += (255 - $green) * $adjustPercentage; $blue += (255 - $blue) * $adjustPercentage; } else { $red += $red * $adjustPercentage; $green += $green * $adjustPercentage; $blue += $blue * $adjustPercentage; } if ($red < 0) { $red = 0; } elseif ($red > 255) { $red = 255; } if ($green < 0) { $green = 0; } elseif ($green > 255) { $green = 255; } if ($blue < 0) { $blue = 0; } elseif ($blue > 255) { $blue = 255; } $rgb = strtoupper( str_pad(dechex($red), 2, '0', 0) . str_pad(dechex($green), 2, '0', 0) . str_pad(dechex($blue), 2, '0', 0) ); return (($rgba) ? 'FF' : '') . $rgb; }
php
public static function changeBrightness($hex, $adjustPercentage) { $rgba = (strlen($hex) == 8); $red = self::getRed($hex, false); $green = self::getGreen($hex, false); $blue = self::getBlue($hex, false); if ($adjustPercentage > 0) { $red += (255 - $red) * $adjustPercentage; $green += (255 - $green) * $adjustPercentage; $blue += (255 - $blue) * $adjustPercentage; } else { $red += $red * $adjustPercentage; $green += $green * $adjustPercentage; $blue += $blue * $adjustPercentage; } if ($red < 0) { $red = 0; } elseif ($red > 255) { $red = 255; } if ($green < 0) { $green = 0; } elseif ($green > 255) { $green = 255; } if ($blue < 0) { $blue = 0; } elseif ($blue > 255) { $blue = 255; } $rgb = strtoupper( str_pad(dechex($red), 2, '0', 0) . str_pad(dechex($green), 2, '0', 0) . str_pad(dechex($blue), 2, '0', 0) ); return (($rgba) ? 'FF' : '') . $rgb; }
[ "public", "static", "function", "changeBrightness", "(", "$", "hex", ",", "$", "adjustPercentage", ")", "{", "$", "rgba", "=", "(", "strlen", "(", "$", "hex", ")", "==", "8", ")", ";", "$", "red", "=", "self", "::", "getRed", "(", "$", "hex", ",", "false", ")", ";", "$", "green", "=", "self", "::", "getGreen", "(", "$", "hex", ",", "false", ")", ";", "$", "blue", "=", "self", "::", "getBlue", "(", "$", "hex", ",", "false", ")", ";", "if", "(", "$", "adjustPercentage", ">", "0", ")", "{", "$", "red", "+=", "(", "255", "-", "$", "red", ")", "*", "$", "adjustPercentage", ";", "$", "green", "+=", "(", "255", "-", "$", "green", ")", "*", "$", "adjustPercentage", ";", "$", "blue", "+=", "(", "255", "-", "$", "blue", ")", "*", "$", "adjustPercentage", ";", "}", "else", "{", "$", "red", "+=", "$", "red", "*", "$", "adjustPercentage", ";", "$", "green", "+=", "$", "green", "*", "$", "adjustPercentage", ";", "$", "blue", "+=", "$", "blue", "*", "$", "adjustPercentage", ";", "}", "if", "(", "$", "red", "<", "0", ")", "{", "$", "red", "=", "0", ";", "}", "elseif", "(", "$", "red", ">", "255", ")", "{", "$", "red", "=", "255", ";", "}", "if", "(", "$", "green", "<", "0", ")", "{", "$", "green", "=", "0", ";", "}", "elseif", "(", "$", "green", ">", "255", ")", "{", "$", "green", "=", "255", ";", "}", "if", "(", "$", "blue", "<", "0", ")", "{", "$", "blue", "=", "0", ";", "}", "elseif", "(", "$", "blue", ">", "255", ")", "{", "$", "blue", "=", "255", ";", "}", "$", "rgb", "=", "strtoupper", "(", "str_pad", "(", "dechex", "(", "$", "red", ")", ",", "2", ",", "'0'", ",", "0", ")", ".", "str_pad", "(", "dechex", "(", "$", "green", ")", ",", "2", ",", "'0'", ",", "0", ")", ".", "str_pad", "(", "dechex", "(", "$", "blue", ")", ",", "2", ",", "'0'", ",", "0", ")", ")", ";", "return", "(", "(", "$", "rgba", ")", "?", "'FF'", ":", "''", ")", ".", "$", "rgb", ";", "}" ]
Adjust the brightness of a color @param string $hex The colour as an RGBA or RGB value (e.g. FF00CCCC or CCDDEE) @param float $adjustPercentage The percentage by which to adjust the colour as a float from -1 to 1 @return string The adjusted colour as an RGBA or RGB value (e.g. FF00CCCC or CCDDEE)
[ "Adjust", "the", "brightness", "of", "a", "color" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Style/Color.php#L302-L341
214,298
moodle/moodle
grade/report/singleview/classes/local/ui/feedback.php
feedback.is_disabled
public function is_disabled() { $locked = 0; $gradeitemlocked = 0; $overridden = 0; /* Disable editing if grade item or grade score is locked * if any of these items are set, then we will disable editing * at some point, we might want to show the reason for the lock * this code could be simplified, but its more readable for steve's little mind */ if (!empty($this->grade->locked)) { $locked = 1; } if (!empty($this->grade->grade_item->locked)) { $gradeitemlocked = 1; } if ($this->grade->grade_item->is_overridable_item() and !$this->grade->is_overridden()) { $overridden = 1; } return ($locked || $gradeitemlocked || $overridden); }
php
public function is_disabled() { $locked = 0; $gradeitemlocked = 0; $overridden = 0; /* Disable editing if grade item or grade score is locked * if any of these items are set, then we will disable editing * at some point, we might want to show the reason for the lock * this code could be simplified, but its more readable for steve's little mind */ if (!empty($this->grade->locked)) { $locked = 1; } if (!empty($this->grade->grade_item->locked)) { $gradeitemlocked = 1; } if ($this->grade->grade_item->is_overridable_item() and !$this->grade->is_overridden()) { $overridden = 1; } return ($locked || $gradeitemlocked || $overridden); }
[ "public", "function", "is_disabled", "(", ")", "{", "$", "locked", "=", "0", ";", "$", "gradeitemlocked", "=", "0", ";", "$", "overridden", "=", "0", ";", "/* Disable editing if grade item or grade score is locked\n * if any of these items are set, then we will disable editing\n * at some point, we might want to show the reason for the lock\n * this code could be simplified, but its more readable for steve's little mind\n */", "if", "(", "!", "empty", "(", "$", "this", "->", "grade", "->", "locked", ")", ")", "{", "$", "locked", "=", "1", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "grade", "->", "grade_item", "->", "locked", ")", ")", "{", "$", "gradeitemlocked", "=", "1", ";", "}", "if", "(", "$", "this", "->", "grade", "->", "grade_item", "->", "is_overridable_item", "(", ")", "and", "!", "$", "this", "->", "grade", "->", "is_overridden", "(", ")", ")", "{", "$", "overridden", "=", "1", ";", "}", "return", "(", "$", "locked", "||", "$", "gradeitemlocked", "||", "$", "overridden", ")", ";", "}" ]
Determine if this input should be disabled based on the other settings. @return boolean Should this input be disabled when the page loads.
[ "Determine", "if", "this", "input", "should", "be", "disabled", "based", "on", "the", "other", "settings", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/feedback.php#L67-L86
214,299
moodle/moodle
grade/report/singleview/classes/local/ui/feedback.php
feedback.determine_format
public function determine_format() { return new text_attribute( $this->get_name(), $this->get_value(), $this->get_label(), $this->is_disabled() ); }
php
public function determine_format() { return new text_attribute( $this->get_name(), $this->get_value(), $this->get_label(), $this->is_disabled() ); }
[ "public", "function", "determine_format", "(", ")", "{", "return", "new", "text_attribute", "(", "$", "this", "->", "get_name", "(", ")", ",", "$", "this", "->", "get_value", "(", ")", ",", "$", "this", "->", "get_label", "(", ")", ",", "$", "this", "->", "is_disabled", "(", ")", ")", ";", "}" ]
Create a text_attribute for this ui element. @return text_attribute
[ "Create", "a", "text_attribute", "for", "this", "ui", "element", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/feedback.php#L93-L100