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
216,200
moodle/moodle
message/externallib.php
core_message_external.mark_all_messages_as_read
public static function mark_all_messages_as_read($useridto, $useridfrom) { global $USER, $CFG; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = self::validate_parameters( self::mark_all_messages_as_read_parameters(), array( 'useridto' => $useridto, 'useridfrom' => $useridfrom, ) ); $context = context_system::instance(); self::validate_context($context); $useridto = $params['useridto']; $useridfrom = $params['useridfrom']; if (!empty($useridto)) { if (core_user::is_real_user($useridto)) { $userto = core_user::get_user($useridto, '*', MUST_EXIST); } else { throw new moodle_exception('invaliduser'); } } if (!empty($useridfrom)) { // We use get_user here because the from user can be the noreply or support user. $userfrom = core_user::get_user($useridfrom, '*', MUST_EXIST); } // Check if the current user is the sender/receiver or just a privileged user. if ($useridto != $USER->id and $useridfrom != $USER->id and // The deleteanymessage cap seems more reasonable here than readallmessages. !has_capability('moodle/site:deleteanymessage', $context)) { throw new moodle_exception('accessdenied', 'admin'); } if ($useridfrom) { if ($conversationid = \core_message\api::get_conversation_between_users([$useridto, $useridfrom])) { \core_message\api::mark_all_messages_as_read($useridto, $conversationid); } } else { \core_message\api::mark_all_messages_as_read($useridto); } return true; }
php
public static function mark_all_messages_as_read($useridto, $useridfrom) { global $USER, $CFG; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = self::validate_parameters( self::mark_all_messages_as_read_parameters(), array( 'useridto' => $useridto, 'useridfrom' => $useridfrom, ) ); $context = context_system::instance(); self::validate_context($context); $useridto = $params['useridto']; $useridfrom = $params['useridfrom']; if (!empty($useridto)) { if (core_user::is_real_user($useridto)) { $userto = core_user::get_user($useridto, '*', MUST_EXIST); } else { throw new moodle_exception('invaliduser'); } } if (!empty($useridfrom)) { // We use get_user here because the from user can be the noreply or support user. $userfrom = core_user::get_user($useridfrom, '*', MUST_EXIST); } // Check if the current user is the sender/receiver or just a privileged user. if ($useridto != $USER->id and $useridfrom != $USER->id and // The deleteanymessage cap seems more reasonable here than readallmessages. !has_capability('moodle/site:deleteanymessage', $context)) { throw new moodle_exception('accessdenied', 'admin'); } if ($useridfrom) { if ($conversationid = \core_message\api::get_conversation_between_users([$useridto, $useridfrom])) { \core_message\api::mark_all_messages_as_read($useridto, $conversationid); } } else { \core_message\api::mark_all_messages_as_read($useridto); } return true; }
[ "public", "static", "function", "mark_all_messages_as_read", "(", "$", "useridto", ",", "$", "useridfrom", ")", "{", "global", "$", "USER", ",", "$", "CFG", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "mark_all_messages_as_read_parameters", "(", ")", ",", "array", "(", "'useridto'", "=>", "$", "useridto", ",", "'useridfrom'", "=>", "$", "useridfrom", ",", ")", ")", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "useridto", "=", "$", "params", "[", "'useridto'", "]", ";", "$", "useridfrom", "=", "$", "params", "[", "'useridfrom'", "]", ";", "if", "(", "!", "empty", "(", "$", "useridto", ")", ")", "{", "if", "(", "core_user", "::", "is_real_user", "(", "$", "useridto", ")", ")", "{", "$", "userto", "=", "core_user", "::", "get_user", "(", "$", "useridto", ",", "'*'", ",", "MUST_EXIST", ")", ";", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'invaliduser'", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "useridfrom", ")", ")", "{", "// We use get_user here because the from user can be the noreply or support user.", "$", "userfrom", "=", "core_user", "::", "get_user", "(", "$", "useridfrom", ",", "'*'", ",", "MUST_EXIST", ")", ";", "}", "// Check if the current user is the sender/receiver or just a privileged user.", "if", "(", "$", "useridto", "!=", "$", "USER", "->", "id", "and", "$", "useridfrom", "!=", "$", "USER", "->", "id", "and", "// The deleteanymessage cap seems more reasonable here than readallmessages.", "!", "has_capability", "(", "'moodle/site:deleteanymessage'", ",", "$", "context", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'accessdenied'", ",", "'admin'", ")", ";", "}", "if", "(", "$", "useridfrom", ")", "{", "if", "(", "$", "conversationid", "=", "\\", "core_message", "\\", "api", "::", "get_conversation_between_users", "(", "[", "$", "useridto", ",", "$", "useridfrom", "]", ")", ")", "{", "\\", "core_message", "\\", "api", "::", "mark_all_messages_as_read", "(", "$", "useridto", ",", "$", "conversationid", ")", ";", "}", "}", "else", "{", "\\", "core_message", "\\", "api", "::", "mark_all_messages_as_read", "(", "$", "useridto", ")", ";", "}", "return", "true", ";", "}" ]
Mark all messages as read function. @deprecated since 3.6 @throws invalid_parameter_exception @throws moodle_exception @param int $useridto the user id who received the message @param int $useridfrom the user id who send the message. -10 or -20 for no-reply or support user @return external_description @since 3.2
[ "Mark", "all", "messages", "as", "read", "function", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L3688-L3739
216,201
moodle/moodle
message/externallib.php
core_message_external.mark_all_conversation_messages_as_read
public static function mark_all_conversation_messages_as_read(int $userid, int $conversationid) { global $CFG; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = array( 'userid' => $userid, 'conversationid' => $conversationid, ); $params = self::validate_parameters(self::mark_all_conversation_messages_as_read_parameters(), $params); $context = context_system::instance(); self::validate_context($context); $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); if (\core_message\api::can_mark_all_messages_as_read($params['userid'], $params['conversationid'])) { \core_message\api::mark_all_messages_as_read($params['userid'], $params['conversationid']); } else { throw new moodle_exception('accessdenied', 'admin'); } }
php
public static function mark_all_conversation_messages_as_read(int $userid, int $conversationid) { global $CFG; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = array( 'userid' => $userid, 'conversationid' => $conversationid, ); $params = self::validate_parameters(self::mark_all_conversation_messages_as_read_parameters(), $params); $context = context_system::instance(); self::validate_context($context); $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); if (\core_message\api::can_mark_all_messages_as_read($params['userid'], $params['conversationid'])) { \core_message\api::mark_all_messages_as_read($params['userid'], $params['conversationid']); } else { throw new moodle_exception('accessdenied', 'admin'); } }
[ "public", "static", "function", "mark_all_conversation_messages_as_read", "(", "int", "$", "userid", ",", "int", "$", "conversationid", ")", "{", "global", "$", "CFG", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "params", "=", "array", "(", "'userid'", "=>", "$", "userid", ",", "'conversationid'", "=>", "$", "conversationid", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "mark_all_conversation_messages_as_read_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "params", "[", "'userid'", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "core_user", "::", "require_active_user", "(", "$", "user", ")", ";", "if", "(", "\\", "core_message", "\\", "api", "::", "can_mark_all_messages_as_read", "(", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'conversationid'", "]", ")", ")", "{", "\\", "core_message", "\\", "api", "::", "mark_all_messages_as_read", "(", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'conversationid'", "]", ")", ";", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'accessdenied'", ",", "'admin'", ")", ";", "}", "}" ]
Mark all conversation messages as read function. @param int $userid The user id of who we want to delete the conversation for @param int $conversationid The id of the conversations @since 3.6
[ "Mark", "all", "conversation", "messages", "as", "read", "function", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L3784-L3809
216,202
moodle/moodle
message/externallib.php
core_message_external.delete_message
public static function delete_message($messageid, $userid, $read = true) { global $CFG; // Check if private messaging between users is allowed. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } // Warnings array, it can be empty at the end but is mandatory. $warnings = array(); // Validate params. $params = array( 'messageid' => $messageid, 'userid' => $userid, 'read' => $read ); $params = self::validate_parameters(self::delete_message_parameters(), $params); // Validate context. $context = context_system::instance(); self::validate_context($context); $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); if (\core_message\api::can_delete_message($user->id, $params['messageid'])) { $status = \core_message\api::delete_message($user->id, $params['messageid']); } else { throw new moodle_exception('You do not have permission to delete this message'); } $results = array( 'status' => $status, 'warnings' => $warnings ); return $results; }
php
public static function delete_message($messageid, $userid, $read = true) { global $CFG; // Check if private messaging between users is allowed. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } // Warnings array, it can be empty at the end but is mandatory. $warnings = array(); // Validate params. $params = array( 'messageid' => $messageid, 'userid' => $userid, 'read' => $read ); $params = self::validate_parameters(self::delete_message_parameters(), $params); // Validate context. $context = context_system::instance(); self::validate_context($context); $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); if (\core_message\api::can_delete_message($user->id, $params['messageid'])) { $status = \core_message\api::delete_message($user->id, $params['messageid']); } else { throw new moodle_exception('You do not have permission to delete this message'); } $results = array( 'status' => $status, 'warnings' => $warnings ); return $results; }
[ "public", "static", "function", "delete_message", "(", "$", "messageid", ",", "$", "userid", ",", "$", "read", "=", "true", ")", "{", "global", "$", "CFG", ";", "// Check if private messaging between users is allowed.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "// Warnings array, it can be empty at the end but is mandatory.", "$", "warnings", "=", "array", "(", ")", ";", "// Validate params.", "$", "params", "=", "array", "(", "'messageid'", "=>", "$", "messageid", ",", "'userid'", "=>", "$", "userid", ",", "'read'", "=>", "$", "read", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "delete_message_parameters", "(", ")", ",", "$", "params", ")", ";", "// Validate context.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "params", "[", "'userid'", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "core_user", "::", "require_active_user", "(", "$", "user", ")", ";", "if", "(", "\\", "core_message", "\\", "api", "::", "can_delete_message", "(", "$", "user", "->", "id", ",", "$", "params", "[", "'messageid'", "]", ")", ")", "{", "$", "status", "=", "\\", "core_message", "\\", "api", "::", "delete_message", "(", "$", "user", "->", "id", ",", "$", "params", "[", "'messageid'", "]", ")", ";", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to delete this message'", ")", ";", "}", "$", "results", "=", "array", "(", "'status'", "=>", "$", "status", ",", "'warnings'", "=>", "$", "warnings", ")", ";", "return", "$", "results", ";", "}" ]
Deletes a message @param int $messageid the message id @param int $userid the user id of who we want to delete the message for @param bool $read if is a message read (default to true) @return external_description @throws moodle_exception @since 3.1
[ "Deletes", "a", "message" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L4012-L4049
216,203
moodle/moodle
message/externallib.php
core_message_external.message_processor_config_form
public static function message_processor_config_form($userid, $name, $formvalues) { global $USER, $CFG; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = self::validate_parameters( self::message_processor_config_form_parameters(), array( 'userid' => $userid, 'name' => $name, 'formvalues' => $formvalues, ) ); $user = self::validate_preferences_permissions($params['userid']); $processor = get_message_processor($params['name']); $preferences = []; $form = new stdClass(); foreach ($params['formvalues'] as $formvalue) { // Curly braces to ensure interpretation is consistent between // php 5 and php 7. $form->{$formvalue['name']} = $formvalue['value']; } $processor->process_form($form, $preferences); if (!empty($preferences)) { set_user_preferences($preferences, $params['userid']); } }
php
public static function message_processor_config_form($userid, $name, $formvalues) { global $USER, $CFG; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = self::validate_parameters( self::message_processor_config_form_parameters(), array( 'userid' => $userid, 'name' => $name, 'formvalues' => $formvalues, ) ); $user = self::validate_preferences_permissions($params['userid']); $processor = get_message_processor($params['name']); $preferences = []; $form = new stdClass(); foreach ($params['formvalues'] as $formvalue) { // Curly braces to ensure interpretation is consistent between // php 5 and php 7. $form->{$formvalue['name']} = $formvalue['value']; } $processor->process_form($form, $preferences); if (!empty($preferences)) { set_user_preferences($preferences, $params['userid']); } }
[ "public", "static", "function", "message_processor_config_form", "(", "$", "userid", ",", "$", "name", ",", "$", "formvalues", ")", "{", "global", "$", "USER", ",", "$", "CFG", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "message_processor_config_form_parameters", "(", ")", ",", "array", "(", "'userid'", "=>", "$", "userid", ",", "'name'", "=>", "$", "name", ",", "'formvalues'", "=>", "$", "formvalues", ",", ")", ")", ";", "$", "user", "=", "self", "::", "validate_preferences_permissions", "(", "$", "params", "[", "'userid'", "]", ")", ";", "$", "processor", "=", "get_message_processor", "(", "$", "params", "[", "'name'", "]", ")", ";", "$", "preferences", "=", "[", "]", ";", "$", "form", "=", "new", "stdClass", "(", ")", ";", "foreach", "(", "$", "params", "[", "'formvalues'", "]", "as", "$", "formvalue", ")", "{", "// Curly braces to ensure interpretation is consistent between", "// php 5 and php 7.", "$", "form", "->", "{", "$", "formvalue", "[", "'name'", "]", "}", "=", "$", "formvalue", "[", "'value'", "]", ";", "}", "$", "processor", "->", "process_form", "(", "$", "form", ",", "$", "preferences", ")", ";", "if", "(", "!", "empty", "(", "$", "preferences", ")", ")", "{", "set_user_preferences", "(", "$", "preferences", ",", "$", "params", "[", "'userid'", "]", ")", ";", "}", "}" ]
Processes a message processor config form. @param int $userid the user id @param string $name the name of the processor @param array $formvalues the form values @return external_description @throws moodle_exception @since 3.2
[ "Processes", "a", "message", "processor", "config", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L4101-L4135
216,204
moodle/moodle
message/externallib.php
core_message_external.get_message_processor
public static function get_message_processor($userid = 0, $name) { global $USER, $PAGE, $CFG; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = self::validate_parameters( self::get_message_processor_parameters(), array( 'userid' => $userid, 'name' => $name, ) ); if (empty($params['userid'])) { $params['userid'] = $USER->id; } $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); self::validate_context(context_user::instance($params['userid'])); $processor = get_message_processor($params['name']); $processoroutput = new \core_message\output\processor($processor, $user); $renderer = $PAGE->get_renderer('core_message'); return $processoroutput->export_for_template($renderer); }
php
public static function get_message_processor($userid = 0, $name) { global $USER, $PAGE, $CFG; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = self::validate_parameters( self::get_message_processor_parameters(), array( 'userid' => $userid, 'name' => $name, ) ); if (empty($params['userid'])) { $params['userid'] = $USER->id; } $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); self::validate_context(context_user::instance($params['userid'])); $processor = get_message_processor($params['name']); $processoroutput = new \core_message\output\processor($processor, $user); $renderer = $PAGE->get_renderer('core_message'); return $processoroutput->export_for_template($renderer); }
[ "public", "static", "function", "get_message_processor", "(", "$", "userid", "=", "0", ",", "$", "name", ")", "{", "global", "$", "USER", ",", "$", "PAGE", ",", "$", "CFG", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_message_processor_parameters", "(", ")", ",", "array", "(", "'userid'", "=>", "$", "userid", ",", "'name'", "=>", "$", "name", ",", ")", ")", ";", "if", "(", "empty", "(", "$", "params", "[", "'userid'", "]", ")", ")", "{", "$", "params", "[", "'userid'", "]", "=", "$", "USER", "->", "id", ";", "}", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "params", "[", "'userid'", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "core_user", "::", "require_active_user", "(", "$", "user", ")", ";", "self", "::", "validate_context", "(", "context_user", "::", "instance", "(", "$", "params", "[", "'userid'", "]", ")", ")", ";", "$", "processor", "=", "get_message_processor", "(", "$", "params", "[", "'name'", "]", ")", ";", "$", "processoroutput", "=", "new", "\\", "core_message", "\\", "output", "\\", "processor", "(", "$", "processor", ",", "$", "user", ")", ";", "$", "renderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'core_message'", ")", ";", "return", "$", "processoroutput", "->", "export_for_template", "(", "$", "renderer", ")", ";", "}" ]
Get a message processor. @param int $userid @param string $name the name of the processor @return external_description @throws moodle_exception @since 3.2
[ "Get", "a", "message", "processor", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L4171-L4201
216,205
moodle/moodle
message/externallib.php
core_message_external.validate_preferences_permissions
protected static function validate_preferences_permissions($userid) { global $USER; if (empty($userid)) { $user = $USER; } else { $user = core_user::get_user($userid, '*', MUST_EXIST); core_user::require_active_user($user); } $systemcontext = context_system::instance(); self::validate_context($systemcontext); // Check access control. if ($user->id == $USER->id) { // Editing own message profile. require_capability('moodle/user:editownmessageprofile', $systemcontext); } else { // Teachers, parents, etc. $personalcontext = context_user::instance($user->id); require_capability('moodle/user:editmessageprofile', $personalcontext); } return $user; }
php
protected static function validate_preferences_permissions($userid) { global $USER; if (empty($userid)) { $user = $USER; } else { $user = core_user::get_user($userid, '*', MUST_EXIST); core_user::require_active_user($user); } $systemcontext = context_system::instance(); self::validate_context($systemcontext); // Check access control. if ($user->id == $USER->id) { // Editing own message profile. require_capability('moodle/user:editownmessageprofile', $systemcontext); } else { // Teachers, parents, etc. $personalcontext = context_user::instance($user->id); require_capability('moodle/user:editmessageprofile', $personalcontext); } return $user; }
[ "protected", "static", "function", "validate_preferences_permissions", "(", "$", "userid", ")", "{", "global", "$", "USER", ";", "if", "(", "empty", "(", "$", "userid", ")", ")", "{", "$", "user", "=", "$", "USER", ";", "}", "else", "{", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "userid", ",", "'*'", ",", "MUST_EXIST", ")", ";", "core_user", "::", "require_active_user", "(", "$", "user", ")", ";", "}", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "// Check access control.", "if", "(", "$", "user", "->", "id", "==", "$", "USER", "->", "id", ")", "{", "// Editing own message profile.", "require_capability", "(", "'moodle/user:editownmessageprofile'", ",", "$", "systemcontext", ")", ";", "}", "else", "{", "// Teachers, parents, etc.", "$", "personalcontext", "=", "context_user", "::", "instance", "(", "$", "user", "->", "id", ")", ";", "require_capability", "(", "'moodle/user:editmessageprofile'", ",", "$", "personalcontext", ")", ";", "}", "return", "$", "user", ";", "}" ]
Check that the user has enough permission to retrieve message or notifications preferences. @param int $userid the user id requesting the preferences @return stdClass full user object @throws moodle_exception @since Moodle 3.2
[ "Check", "that", "the", "user", "has", "enough", "permission", "to", "retrieve", "message", "or", "notifications", "preferences", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L4226-L4249
216,206
moodle/moodle
message/externallib.php
core_message_external.get_preferences_structure
protected static function get_preferences_structure() { return new external_single_structure( array( 'userid' => new external_value(PARAM_INT, 'User id'), 'disableall' => new external_value(PARAM_INT, 'Whether all the preferences are disabled'), 'processors' => new external_multiple_structure( new external_single_structure( array( 'displayname' => new external_value(PARAM_TEXT, 'Display name'), 'name' => new external_value(PARAM_PLUGIN, 'Processor name'), 'hassettings' => new external_value(PARAM_BOOL, 'Whether has settings'), 'contextid' => new external_value(PARAM_INT, 'Context id'), 'userconfigured' => new external_value(PARAM_INT, 'Whether is configured by the user'), ) ), 'Config form values' ), 'components' => new external_multiple_structure( new external_single_structure( array( 'displayname' => new external_value(PARAM_TEXT, 'Display name'), 'notifications' => new external_multiple_structure( new external_single_structure( array( 'displayname' => new external_value(PARAM_TEXT, 'Display name'), 'preferencekey' => new external_value(PARAM_ALPHANUMEXT, 'Preference key'), 'processors' => new external_multiple_structure( new external_single_structure( array( 'displayname' => new external_value(PARAM_TEXT, 'Display name'), 'name' => new external_value(PARAM_PLUGIN, 'Processor name'), 'locked' => new external_value(PARAM_BOOL, 'Is locked by admin?'), 'lockedmessage' => new external_value(PARAM_TEXT, 'Text to display if locked', VALUE_OPTIONAL), 'userconfigured' => new external_value(PARAM_INT, 'Is configured?'), 'loggedin' => new external_single_structure( array( 'name' => new external_value(PARAM_NOTAGS, 'Name'), 'displayname' => new external_value(PARAM_TEXT, 'Display name'), 'checked' => new external_value(PARAM_BOOL, 'Is checked?'), ) ), 'loggedoff' => new external_single_structure( array( 'name' => new external_value(PARAM_NOTAGS, 'Name'), 'displayname' => new external_value(PARAM_TEXT, 'Display name'), 'checked' => new external_value(PARAM_BOOL, 'Is checked?'), ) ), ) ), 'Processors values for this notification' ), ) ), 'List of notificaitons for the component' ), ) ), 'Available components' ), ) ); }
php
protected static function get_preferences_structure() { return new external_single_structure( array( 'userid' => new external_value(PARAM_INT, 'User id'), 'disableall' => new external_value(PARAM_INT, 'Whether all the preferences are disabled'), 'processors' => new external_multiple_structure( new external_single_structure( array( 'displayname' => new external_value(PARAM_TEXT, 'Display name'), 'name' => new external_value(PARAM_PLUGIN, 'Processor name'), 'hassettings' => new external_value(PARAM_BOOL, 'Whether has settings'), 'contextid' => new external_value(PARAM_INT, 'Context id'), 'userconfigured' => new external_value(PARAM_INT, 'Whether is configured by the user'), ) ), 'Config form values' ), 'components' => new external_multiple_structure( new external_single_structure( array( 'displayname' => new external_value(PARAM_TEXT, 'Display name'), 'notifications' => new external_multiple_structure( new external_single_structure( array( 'displayname' => new external_value(PARAM_TEXT, 'Display name'), 'preferencekey' => new external_value(PARAM_ALPHANUMEXT, 'Preference key'), 'processors' => new external_multiple_structure( new external_single_structure( array( 'displayname' => new external_value(PARAM_TEXT, 'Display name'), 'name' => new external_value(PARAM_PLUGIN, 'Processor name'), 'locked' => new external_value(PARAM_BOOL, 'Is locked by admin?'), 'lockedmessage' => new external_value(PARAM_TEXT, 'Text to display if locked', VALUE_OPTIONAL), 'userconfigured' => new external_value(PARAM_INT, 'Is configured?'), 'loggedin' => new external_single_structure( array( 'name' => new external_value(PARAM_NOTAGS, 'Name'), 'displayname' => new external_value(PARAM_TEXT, 'Display name'), 'checked' => new external_value(PARAM_BOOL, 'Is checked?'), ) ), 'loggedoff' => new external_single_structure( array( 'name' => new external_value(PARAM_NOTAGS, 'Name'), 'displayname' => new external_value(PARAM_TEXT, 'Display name'), 'checked' => new external_value(PARAM_BOOL, 'Is checked?'), ) ), ) ), 'Processors values for this notification' ), ) ), 'List of notificaitons for the component' ), ) ), 'Available components' ), ) ); }
[ "protected", "static", "function", "get_preferences_structure", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User id'", ")", ",", "'disableall'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Whether all the preferences are disabled'", ")", ",", "'processors'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'displayname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Display name'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_PLUGIN", ",", "'Processor name'", ")", ",", "'hassettings'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether has settings'", ")", ",", "'contextid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Context id'", ")", ",", "'userconfigured'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Whether is configured by the user'", ")", ",", ")", ")", ",", "'Config form values'", ")", ",", "'components'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'displayname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Display name'", ")", ",", "'notifications'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'displayname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Display name'", ")", ",", "'preferencekey'", "=>", "new", "external_value", "(", "PARAM_ALPHANUMEXT", ",", "'Preference key'", ")", ",", "'processors'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'displayname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Display name'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_PLUGIN", ",", "'Processor name'", ")", ",", "'locked'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Is locked by admin?'", ")", ",", "'lockedmessage'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Text to display if locked'", ",", "VALUE_OPTIONAL", ")", ",", "'userconfigured'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Is configured?'", ")", ",", "'loggedin'", "=>", "new", "external_single_structure", "(", "array", "(", "'name'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'Name'", ")", ",", "'displayname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Display name'", ")", ",", "'checked'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Is checked?'", ")", ",", ")", ")", ",", "'loggedoff'", "=>", "new", "external_single_structure", "(", "array", "(", "'name'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'Name'", ")", ",", "'displayname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Display name'", ")", ",", "'checked'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Is checked?'", ")", ",", ")", ")", ",", ")", ")", ",", "'Processors values for this notification'", ")", ",", ")", ")", ",", "'List of notificaitons for the component'", ")", ",", ")", ")", ",", "'Available components'", ")", ",", ")", ")", ";", "}" ]
Returns a notification or message preference structure. @return external_single_structure the structure @since Moodle 3.2
[ "Returns", "a", "notification", "or", "message", "preference", "structure", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L4257-L4320
216,207
moodle/moodle
message/externallib.php
core_message_external.set_favourite_conversations
public static function set_favourite_conversations(int $userid, array $conversationids) { global $CFG, $USER; // All the business logic checks that really shouldn't be in here. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = [ 'userid' => $userid, 'conversations' => $conversationids ]; $params = self::validate_parameters(self::set_favourite_conversations_parameters(), $params); $systemcontext = context_system::instance(); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } foreach ($params['conversations'] as $conversationid) { \core_message\api::set_favourite_conversation($conversationid, $params['userid']); } return []; }
php
public static function set_favourite_conversations(int $userid, array $conversationids) { global $CFG, $USER; // All the business logic checks that really shouldn't be in here. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = [ 'userid' => $userid, 'conversations' => $conversationids ]; $params = self::validate_parameters(self::set_favourite_conversations_parameters(), $params); $systemcontext = context_system::instance(); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } foreach ($params['conversations'] as $conversationid) { \core_message\api::set_favourite_conversation($conversationid, $params['userid']); } return []; }
[ "public", "static", "function", "set_favourite_conversations", "(", "int", "$", "userid", ",", "array", "$", "conversationids", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// All the business logic checks that really shouldn't be in here.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", ",", "'conversations'", "=>", "$", "conversationids", "]", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "set_favourite_conversations_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "foreach", "(", "$", "params", "[", "'conversations'", "]", "as", "$", "conversationid", ")", "{", "\\", "core_message", "\\", "api", "::", "set_favourite_conversation", "(", "$", "conversationid", ",", "$", "params", "[", "'userid'", "]", ")", ";", "}", "return", "[", "]", ";", "}" ]
Favourite a conversation, or list of conversations for a user. @param int $userid the id of the user, or 0 for the current user. @param array $conversationids the list of conversations ids to favourite. @return array @throws moodle_exception if messaging is disabled or if the user cannot perform the action.
[ "Favourite", "a", "conversation", "or", "list", "of", "conversations", "for", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L4488-L4512
216,208
moodle/moodle
message/externallib.php
core_message_external.unset_favourite_conversations
public static function unset_favourite_conversations(int $userid, array $conversationids) { global $CFG, $USER; // All the business logic checks that really shouldn't be in here. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = [ 'userid' => $userid, 'conversations' => $conversationids ]; $params = self::validate_parameters(self::unset_favourite_conversations_parameters(), $params); $systemcontext = context_system::instance(); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } foreach ($params['conversations'] as $conversationid) { \core_message\api::unset_favourite_conversation($conversationid, $params['userid']); } return []; }
php
public static function unset_favourite_conversations(int $userid, array $conversationids) { global $CFG, $USER; // All the business logic checks that really shouldn't be in here. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = [ 'userid' => $userid, 'conversations' => $conversationids ]; $params = self::validate_parameters(self::unset_favourite_conversations_parameters(), $params); $systemcontext = context_system::instance(); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } foreach ($params['conversations'] as $conversationid) { \core_message\api::unset_favourite_conversation($conversationid, $params['userid']); } return []; }
[ "public", "static", "function", "unset_favourite_conversations", "(", "int", "$", "userid", ",", "array", "$", "conversationids", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// All the business logic checks that really shouldn't be in here.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", ",", "'conversations'", "=>", "$", "conversationids", "]", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "unset_favourite_conversations_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "foreach", "(", "$", "params", "[", "'conversations'", "]", "as", "$", "conversationid", ")", "{", "\\", "core_message", "\\", "api", "::", "unset_favourite_conversation", "(", "$", "conversationid", ",", "$", "params", "[", "'userid'", "]", ")", ";", "}", "return", "[", "]", ";", "}" ]
Unfavourite a conversation, or list of conversations for a user. @param int $userid the id of the user, or 0 for the current user. @param array $conversationids the list of conversations ids unset as favourites. @return array @throws moodle_exception if messaging is disabled or if the user cannot perform the action.
[ "Unfavourite", "a", "conversation", "or", "list", "of", "conversations", "for", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L4547-L4571
216,209
moodle/moodle
message/externallib.php
core_message_external.get_conversation_counts
public static function get_conversation_counts(int $userid) { global $CFG, $USER; // All the business logic checks that really shouldn't be in here. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } if (empty($userid)) { $userid = $USER->id; } $params = ['userid' => $userid]; $params = self::validate_parameters(self::get_conversation_counts_parameters(), $params); $systemcontext = context_system::instance(); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } return \core_message\api::get_conversation_counts($params['userid']); }
php
public static function get_conversation_counts(int $userid) { global $CFG, $USER; // All the business logic checks that really shouldn't be in here. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } if (empty($userid)) { $userid = $USER->id; } $params = ['userid' => $userid]; $params = self::validate_parameters(self::get_conversation_counts_parameters(), $params); $systemcontext = context_system::instance(); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } return \core_message\api::get_conversation_counts($params['userid']); }
[ "public", "static", "function", "get_conversation_counts", "(", "int", "$", "userid", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// All the business logic checks that really shouldn't be in here.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "if", "(", "empty", "(", "$", "userid", ")", ")", "{", "$", "userid", "=", "$", "USER", "->", "id", ";", "}", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", "]", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_conversation_counts_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "return", "\\", "core_message", "\\", "api", "::", "get_conversation_counts", "(", "$", "params", "[", "'userid'", "]", ")", ";", "}" ]
Returns an array of conversation counts for the various types of conversations, including favourites. Return format: [ 'favourites' => 0, 'types' => [ \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL => 0, \core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP => 0 ] ] @param int $userid the id of the user whose counts we are fetching. @return array the array of conversation counts, indexed by type. @throws moodle_exception if the current user cannot perform this action.
[ "Returns", "an", "array", "of", "conversation", "counts", "for", "the", "various", "types", "of", "conversations", "including", "favourites", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L4685-L4708
216,210
moodle/moodle
message/externallib.php
core_message_external.get_conversation_counts_returns
public static function get_conversation_counts_returns() { return new external_single_structure( [ 'favourites' => new external_value(PARAM_INT, 'Total number of favourite conversations'), 'types' => new external_single_structure( [ \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL => new external_value(PARAM_INT, 'Total number of individual conversations'), \core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP => new external_value(PARAM_INT, 'Total number of group conversations'), \core_message\api::MESSAGE_CONVERSATION_TYPE_SELF => new external_value(PARAM_INT, 'Total number of self conversations'), ] ), ] ); }
php
public static function get_conversation_counts_returns() { return new external_single_structure( [ 'favourites' => new external_value(PARAM_INT, 'Total number of favourite conversations'), 'types' => new external_single_structure( [ \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL => new external_value(PARAM_INT, 'Total number of individual conversations'), \core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP => new external_value(PARAM_INT, 'Total number of group conversations'), \core_message\api::MESSAGE_CONVERSATION_TYPE_SELF => new external_value(PARAM_INT, 'Total number of self conversations'), ] ), ] ); }
[ "public", "static", "function", "get_conversation_counts_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "[", "'favourites'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Total number of favourite conversations'", ")", ",", "'types'", "=>", "new", "external_single_structure", "(", "[", "\\", "core_message", "\\", "api", "::", "MESSAGE_CONVERSATION_TYPE_INDIVIDUAL", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Total number of individual conversations'", ")", ",", "\\", "core_message", "\\", "api", "::", "MESSAGE_CONVERSATION_TYPE_GROUP", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Total number of group conversations'", ")", ",", "\\", "core_message", "\\", "api", "::", "MESSAGE_CONVERSATION_TYPE_SELF", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Total number of self conversations'", ")", ",", "]", ")", ",", "]", ")", ";", "}" ]
Get conversation counts return description. @return external_description
[ "Get", "conversation", "counts", "return", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L4715-L4731
216,211
moodle/moodle
mod/forum/classes/local/entities/sorter.php
sorter.flatten_children
public function flatten_children(array $items) : array { $result = []; foreach ($items as [$item, $children]) { $result[] = $item; $result = array_merge($result, $this->flatten_children($children)); } return $result; }
php
public function flatten_children(array $items) : array { $result = []; foreach ($items as [$item, $children]) { $result[] = $item; $result = array_merge($result, $this->flatten_children($children)); } return $result; }
[ "public", "function", "flatten_children", "(", "array", "$", "items", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "items", "as", "[", "$", "item", ",", "$", "children", "]", ")", "{", "$", "result", "[", "]", "=", "$", "item", ";", "$", "result", "=", "array_merge", "(", "$", "result", ",", "$", "this", "->", "flatten_children", "(", "$", "children", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Take the data structure returned from "sort_into_children" and flatten it back into an array. It does a depth first flatten which maintains the reply ordering. @param array $items Items in the data structure returned by "sort_into_children" @return array A flat array.
[ "Take", "the", "data", "structure", "returned", "from", "sort_into_children", "and", "flatten", "it", "back", "into", "an", "array", ".", "It", "does", "a", "depth", "first", "flatten", "which", "maintains", "the", "reply", "ordering", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/entities/sorter.php#L142-L151
216,212
moodle/moodle
mod/assign/feedback/file/importziplib.php
assignfeedback_file_zip_importer.is_file_modified
public function is_file_modified($assignment, $user, $plugin, $filename, $fileinfo) { $sg = null; if ($plugin->get_subtype() == 'assignsubmission') { $sg = $assignment->get_user_submission($user->id, false); } else if ($plugin->get_subtype() == 'assignfeedback') { $sg = $assignment->get_user_grade($user->id, false); } else { return false; } if (!$sg) { return true; } foreach ($plugin->get_files($sg, $user) as $pluginfilename => $file) { if ($pluginfilename == $filename) { // Extract the file and compare hashes. $contenthash = ''; if (is_array($file)) { $content = reset($file); $contenthash = file_storage::hash_from_string($content); } else { $contenthash = $file->get_contenthash(); } if ($contenthash != $fileinfo->get_contenthash()) { return true; } else { return false; } } } return true; }
php
public function is_file_modified($assignment, $user, $plugin, $filename, $fileinfo) { $sg = null; if ($plugin->get_subtype() == 'assignsubmission') { $sg = $assignment->get_user_submission($user->id, false); } else if ($plugin->get_subtype() == 'assignfeedback') { $sg = $assignment->get_user_grade($user->id, false); } else { return false; } if (!$sg) { return true; } foreach ($plugin->get_files($sg, $user) as $pluginfilename => $file) { if ($pluginfilename == $filename) { // Extract the file and compare hashes. $contenthash = ''; if (is_array($file)) { $content = reset($file); $contenthash = file_storage::hash_from_string($content); } else { $contenthash = $file->get_contenthash(); } if ($contenthash != $fileinfo->get_contenthash()) { return true; } else { return false; } } } return true; }
[ "public", "function", "is_file_modified", "(", "$", "assignment", ",", "$", "user", ",", "$", "plugin", ",", "$", "filename", ",", "$", "fileinfo", ")", "{", "$", "sg", "=", "null", ";", "if", "(", "$", "plugin", "->", "get_subtype", "(", ")", "==", "'assignsubmission'", ")", "{", "$", "sg", "=", "$", "assignment", "->", "get_user_submission", "(", "$", "user", "->", "id", ",", "false", ")", ";", "}", "else", "if", "(", "$", "plugin", "->", "get_subtype", "(", ")", "==", "'assignfeedback'", ")", "{", "$", "sg", "=", "$", "assignment", "->", "get_user_grade", "(", "$", "user", "->", "id", ",", "false", ")", ";", "}", "else", "{", "return", "false", ";", "}", "if", "(", "!", "$", "sg", ")", "{", "return", "true", ";", "}", "foreach", "(", "$", "plugin", "->", "get_files", "(", "$", "sg", ",", "$", "user", ")", "as", "$", "pluginfilename", "=>", "$", "file", ")", "{", "if", "(", "$", "pluginfilename", "==", "$", "filename", ")", "{", "// Extract the file and compare hashes.", "$", "contenthash", "=", "''", ";", "if", "(", "is_array", "(", "$", "file", ")", ")", "{", "$", "content", "=", "reset", "(", "$", "file", ")", ";", "$", "contenthash", "=", "file_storage", "::", "hash_from_string", "(", "$", "content", ")", ";", "}", "else", "{", "$", "contenthash", "=", "$", "file", "->", "get_contenthash", "(", ")", ";", "}", "if", "(", "$", "contenthash", "!=", "$", "fileinfo", "->", "get_contenthash", "(", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}" ]
Does this file exist in any of the current files supported by this plugin for this user? @param assign $assignment - The assignment instance @param stdClass $user The user matching this uploaded file @param assign_plugin $plugin The matching plugin from the filename @param string $filename The parsed filename from the zip @param stored_file $fileinfo The info about the extracted file from the zip @return bool - True if the file has been modified or is new
[ "Does", "this", "file", "exist", "in", "any", "of", "the", "current", "files", "supported", "by", "this", "plugin", "for", "this", "user?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/file/importziplib.php#L101-L133
216,213
moodle/moodle
mod/assign/feedback/file/importziplib.php
assignfeedback_file_zip_importer.delete_import_files
public function delete_import_files($contextid) { global $USER; $fs = get_file_storage(); return $fs->delete_area_files($contextid, 'assignfeedback_file', ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA, $USER->id); }
php
public function delete_import_files($contextid) { global $USER; $fs = get_file_storage(); return $fs->delete_area_files($contextid, 'assignfeedback_file', ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA, $USER->id); }
[ "public", "function", "delete_import_files", "(", "$", "contextid", ")", "{", "global", "$", "USER", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "return", "$", "fs", "->", "delete_area_files", "(", "$", "contextid", ",", "'assignfeedback_file'", ",", "ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA", ",", "$", "USER", "->", "id", ")", ";", "}" ]
Delete all temp files used when importing a zip @param int $contextid - The context id of this assignment instance @return bool true if all files were deleted
[ "Delete", "all", "temp", "files", "used", "when", "importing", "a", "zip" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/file/importziplib.php#L141-L150
216,214
moodle/moodle
mod/assign/feedback/file/importziplib.php
assignfeedback_file_zip_importer.extract_files_from_zip
public function extract_files_from_zip($zipfile, $contextid) { global $USER; $feedbackfilesupdated = 0; $feedbackfilesadded = 0; $userswithnewfeedback = array(); // Unzipping a large zip file is memory intensive. raise_memory_limit(MEMORY_EXTRA); $packer = get_file_packer('application/zip'); core_php_time_limit::raise(ASSIGNFEEDBACK_FILE_MAXFILEUNZIPTIME); return $packer->extract_to_storage($zipfile, $contextid, 'assignfeedback_file', ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA, $USER->id, 'import'); }
php
public function extract_files_from_zip($zipfile, $contextid) { global $USER; $feedbackfilesupdated = 0; $feedbackfilesadded = 0; $userswithnewfeedback = array(); // Unzipping a large zip file is memory intensive. raise_memory_limit(MEMORY_EXTRA); $packer = get_file_packer('application/zip'); core_php_time_limit::raise(ASSIGNFEEDBACK_FILE_MAXFILEUNZIPTIME); return $packer->extract_to_storage($zipfile, $contextid, 'assignfeedback_file', ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA, $USER->id, 'import'); }
[ "public", "function", "extract_files_from_zip", "(", "$", "zipfile", ",", "$", "contextid", ")", "{", "global", "$", "USER", ";", "$", "feedbackfilesupdated", "=", "0", ";", "$", "feedbackfilesadded", "=", "0", ";", "$", "userswithnewfeedback", "=", "array", "(", ")", ";", "// Unzipping a large zip file is memory intensive.", "raise_memory_limit", "(", "MEMORY_EXTRA", ")", ";", "$", "packer", "=", "get_file_packer", "(", "'application/zip'", ")", ";", "core_php_time_limit", "::", "raise", "(", "ASSIGNFEEDBACK_FILE_MAXFILEUNZIPTIME", ")", ";", "return", "$", "packer", "->", "extract_to_storage", "(", "$", "zipfile", ",", "$", "contextid", ",", "'assignfeedback_file'", ",", "ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA", ",", "$", "USER", "->", "id", ",", "'import'", ")", ";", "}" ]
Extract the uploaded zip to a temporary import area for this user @param stored_file $zipfile The uploaded file @param int $contextid The context for this assignment @return bool - True if the files were unpacked
[ "Extract", "the", "uploaded", "zip", "to", "a", "temporary", "import", "area", "for", "this", "user" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/file/importziplib.php#L159-L179
216,215
moodle/moodle
mod/assign/feedback/file/importziplib.php
assignfeedback_file_zip_importer.get_import_files
public function get_import_files($contextid) { global $USER; $fs = get_file_storage(); $files = $fs->get_directory_files($contextid, 'assignfeedback_file', ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA, $USER->id, '/import/', true); // Get files recursive (all levels). $keys = array_keys($files); return $files; }
php
public function get_import_files($contextid) { global $USER; $fs = get_file_storage(); $files = $fs->get_directory_files($contextid, 'assignfeedback_file', ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA, $USER->id, '/import/', true); // Get files recursive (all levels). $keys = array_keys($files); return $files; }
[ "public", "function", "get_import_files", "(", "$", "contextid", ")", "{", "global", "$", "USER", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_directory_files", "(", "$", "contextid", ",", "'assignfeedback_file'", ",", "ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA", ",", "$", "USER", "->", "id", ",", "'/import/'", ",", "true", ")", ";", "// Get files recursive (all levels).", "$", "keys", "=", "array_keys", "(", "$", "files", ")", ";", "return", "$", "files", ";", "}" ]
Get the list of files extracted from the uploaded zip @param int $contextid @return array of stored_files
[ "Get", "the", "list", "of", "files", "extracted", "from", "the", "uploaded", "zip" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/file/importziplib.php#L187-L200
216,216
moodle/moodle
media/classes/player_native.php
core_media_player_native.get_attribute
public static function get_attribute($tag, $attrname, $type = PARAM_RAW) { if (preg_match('/^<[^>]*\b' . $attrname . '="(.*?)"/is', $tag, $matches)) { return clean_param(htmlspecialchars_decode($matches[1]), $type); } else if (preg_match('~^<[^>]*\b' . $attrname . '[ />]"~is', $tag, $matches)) { // Some attributes may not have value, for example this is valid: <video controls>. return clean_param("true", $type); } return null; }
php
public static function get_attribute($tag, $attrname, $type = PARAM_RAW) { if (preg_match('/^<[^>]*\b' . $attrname . '="(.*?)"/is', $tag, $matches)) { return clean_param(htmlspecialchars_decode($matches[1]), $type); } else if (preg_match('~^<[^>]*\b' . $attrname . '[ />]"~is', $tag, $matches)) { // Some attributes may not have value, for example this is valid: <video controls>. return clean_param("true", $type); } return null; }
[ "public", "static", "function", "get_attribute", "(", "$", "tag", ",", "$", "attrname", ",", "$", "type", "=", "PARAM_RAW", ")", "{", "if", "(", "preg_match", "(", "'/^<[^>]*\\b'", ".", "$", "attrname", ".", "'=\"(.*?)\"/is'", ",", "$", "tag", ",", "$", "matches", ")", ")", "{", "return", "clean_param", "(", "htmlspecialchars_decode", "(", "$", "matches", "[", "1", "]", ")", ",", "$", "type", ")", ";", "}", "else", "if", "(", "preg_match", "(", "'~^<[^>]*\\b'", ".", "$", "attrname", ".", "'[ />]\"~is'", ",", "$", "tag", ",", "$", "matches", ")", ")", "{", "// Some attributes may not have value, for example this is valid: <video controls>.", "return", "clean_param", "(", "\"true\"", ",", "$", "type", ")", ";", "}", "return", "null", ";", "}" ]
Extracts a value for an attribute @param string $tag html tag which properties are extracted, for example "<video ...>....</video>" @param string $attrname name of the attribute we are looking for @param string $type one of PARAM_* constants to clean the attribute value @return string|null
[ "Extracts", "a", "value", "for", "an", "attribute" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/media/classes/player_native.php#L43-L51
216,217
moodle/moodle
media/classes/player_native.php
core_media_player_native.remove_attributes
public static function remove_attributes($tag, $attrname) { if (is_array($attrname)) { $attrname = join('|', $attrname); } while (preg_match('/^(<[^>]*\b)(' . $attrname . ')=".*?"(.*)$/is', $tag, $matches)) { $tag = $matches[1] . $matches[3]; } while (preg_match('~^(<[^>]*\b)(' . $attrname . ')([ />].*)$~is', $tag, $matches)) { // Some attributes may not have value, for example: <video controls>. $tag = $matches[1] . $matches[3]; } return $tag; }
php
public static function remove_attributes($tag, $attrname) { if (is_array($attrname)) { $attrname = join('|', $attrname); } while (preg_match('/^(<[^>]*\b)(' . $attrname . ')=".*?"(.*)$/is', $tag, $matches)) { $tag = $matches[1] . $matches[3]; } while (preg_match('~^(<[^>]*\b)(' . $attrname . ')([ />].*)$~is', $tag, $matches)) { // Some attributes may not have value, for example: <video controls>. $tag = $matches[1] . $matches[3]; } return $tag; }
[ "public", "static", "function", "remove_attributes", "(", "$", "tag", ",", "$", "attrname", ")", "{", "if", "(", "is_array", "(", "$", "attrname", ")", ")", "{", "$", "attrname", "=", "join", "(", "'|'", ",", "$", "attrname", ")", ";", "}", "while", "(", "preg_match", "(", "'/^(<[^>]*\\b)('", ".", "$", "attrname", ".", "')=\".*?\"(.*)$/is'", ",", "$", "tag", ",", "$", "matches", ")", ")", "{", "$", "tag", "=", "$", "matches", "[", "1", "]", ".", "$", "matches", "[", "3", "]", ";", "}", "while", "(", "preg_match", "(", "'~^(<[^>]*\\b)('", ".", "$", "attrname", ".", "')([ />].*)$~is'", ",", "$", "tag", ",", "$", "matches", ")", ")", "{", "// Some attributes may not have value, for example: <video controls>.", "$", "tag", "=", "$", "matches", "[", "1", "]", ".", "$", "matches", "[", "3", "]", ";", "}", "return", "$", "tag", ";", "}" ]
Removes an attribute from the media tags @param string $tag html tag which properties are extracted, for example "<video ...>....</video>" @param string|array $attrname @return string
[ "Removes", "an", "attribute", "from", "the", "media", "tags" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/media/classes/player_native.php#L60-L72
216,218
moodle/moodle
media/classes/player_native.php
core_media_player_native.add_attributes
public static function add_attributes($tag, $attributes) { $tag = self::remove_attributes($tag, array_keys($attributes)); if (!preg_match('/^(<.*?)(>.*)$/s', $tag, $matches)) { return $tag; } $rv = $matches[1]; foreach ($attributes as $name => $value) { $rv .= " $name=\"".s($value).'"'; } $rv .= $matches[2]; return $rv; }
php
public static function add_attributes($tag, $attributes) { $tag = self::remove_attributes($tag, array_keys($attributes)); if (!preg_match('/^(<.*?)(>.*)$/s', $tag, $matches)) { return $tag; } $rv = $matches[1]; foreach ($attributes as $name => $value) { $rv .= " $name=\"".s($value).'"'; } $rv .= $matches[2]; return $rv; }
[ "public", "static", "function", "add_attributes", "(", "$", "tag", ",", "$", "attributes", ")", "{", "$", "tag", "=", "self", "::", "remove_attributes", "(", "$", "tag", ",", "array_keys", "(", "$", "attributes", ")", ")", ";", "if", "(", "!", "preg_match", "(", "'/^(<.*?)(>.*)$/s'", ",", "$", "tag", ",", "$", "matches", ")", ")", "{", "return", "$", "tag", ";", "}", "$", "rv", "=", "$", "matches", "[", "1", "]", ";", "foreach", "(", "$", "attributes", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "rv", ".=", "\" $name=\\\"\"", ".", "s", "(", "$", "value", ")", ".", "'\"'", ";", "}", "$", "rv", ".=", "$", "matches", "[", "2", "]", ";", "return", "$", "rv", ";", "}" ]
Adds attributes to the media tags @param string $tag html tag which properties are extracted, for example "<video ...>....</video>" @param array $attributes key-value pairs of attributes to be added @return string
[ "Adds", "attributes", "to", "the", "media", "tags" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/media/classes/player_native.php#L81-L92
216,219
moodle/moodle
admin/tool/usertours/classes/cache.php
cache.get_enabled_tourdata
public static function get_enabled_tourdata() { global $DB; $cache = \cache::make('tool_usertours', self::CACHENAME_TOUR); $data = $cache->get(self::CACHEKEY_TOUR); if ($data === false) { $sql = <<<EOF SELECT t.* FROM {tool_usertours_tours} t WHERE t.enabled = 1 AND t.id IN (SELECT s.tourid FROM {tool_usertours_steps} s GROUP BY s.tourid) ORDER BY t.sortorder ASC EOF; $data = $DB->get_records_sql($sql); $cache->set('tours', $data); } return $data; }
php
public static function get_enabled_tourdata() { global $DB; $cache = \cache::make('tool_usertours', self::CACHENAME_TOUR); $data = $cache->get(self::CACHEKEY_TOUR); if ($data === false) { $sql = <<<EOF SELECT t.* FROM {tool_usertours_tours} t WHERE t.enabled = 1 AND t.id IN (SELECT s.tourid FROM {tool_usertours_steps} s GROUP BY s.tourid) ORDER BY t.sortorder ASC EOF; $data = $DB->get_records_sql($sql); $cache->set('tours', $data); } return $data; }
[ "public", "static", "function", "get_enabled_tourdata", "(", ")", "{", "global", "$", "DB", ";", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'tool_usertours'", ",", "self", "::", "CACHENAME_TOUR", ")", ";", "$", "data", "=", "$", "cache", "->", "get", "(", "self", "::", "CACHEKEY_TOUR", ")", ";", "if", "(", "$", "data", "===", "false", ")", "{", "$", "sql", "=", " <<<EOF\n SELECT t.*\n FROM {tool_usertours_tours} t\n WHERE t.enabled = 1\n AND t.id IN (SELECT s.tourid FROM {tool_usertours_steps} s GROUP BY s.tourid)\n ORDER BY t.sortorder ASC\nEOF", ";", "$", "data", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ")", ";", "$", "cache", "->", "set", "(", "'tours'", ",", "$", "data", ")", ";", "}", "return", "$", "data", ";", "}" ]
Fetch all enabled tours.
[ "Fetch", "all", "enabled", "tours", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/cache.php#L54-L74
216,220
moodle/moodle
admin/tool/usertours/classes/cache.php
cache.get_matching_tourdata
public static function get_matching_tourdata(\moodle_url $targetmatch) { $tours = self::get_enabled_tourdata(); // Attempt to determine whether this is the front page. // This is a special case because the frontpage uses a shortened page path making it difficult to detect exactly. $isfrontpage = $targetmatch->compare(new \moodle_url('/'), URL_MATCH_BASE); $target = $targetmatch->out_as_local_url(); return array_filter($tours, function($tour) use ($isfrontpage, $target) { if ($isfrontpage && $tour->pathmatch === 'FRONTPAGE') { return true; } $pattern = preg_quote($tour->pathmatch, '@'); $pattern = str_replace('%', '.*', $pattern); return !!preg_match("@{$pattern}@", $target); }); }
php
public static function get_matching_tourdata(\moodle_url $targetmatch) { $tours = self::get_enabled_tourdata(); // Attempt to determine whether this is the front page. // This is a special case because the frontpage uses a shortened page path making it difficult to detect exactly. $isfrontpage = $targetmatch->compare(new \moodle_url('/'), URL_MATCH_BASE); $target = $targetmatch->out_as_local_url(); return array_filter($tours, function($tour) use ($isfrontpage, $target) { if ($isfrontpage && $tour->pathmatch === 'FRONTPAGE') { return true; } $pattern = preg_quote($tour->pathmatch, '@'); $pattern = str_replace('%', '.*', $pattern); return !!preg_match("@{$pattern}@", $target); }); }
[ "public", "static", "function", "get_matching_tourdata", "(", "\\", "moodle_url", "$", "targetmatch", ")", "{", "$", "tours", "=", "self", "::", "get_enabled_tourdata", "(", ")", ";", "// Attempt to determine whether this is the front page.", "// This is a special case because the frontpage uses a shortened page path making it difficult to detect exactly.", "$", "isfrontpage", "=", "$", "targetmatch", "->", "compare", "(", "new", "\\", "moodle_url", "(", "'/'", ")", ",", "URL_MATCH_BASE", ")", ";", "$", "target", "=", "$", "targetmatch", "->", "out_as_local_url", "(", ")", ";", "return", "array_filter", "(", "$", "tours", ",", "function", "(", "$", "tour", ")", "use", "(", "$", "isfrontpage", ",", "$", "target", ")", "{", "if", "(", "$", "isfrontpage", "&&", "$", "tour", "->", "pathmatch", "===", "'FRONTPAGE'", ")", "{", "return", "true", ";", "}", "$", "pattern", "=", "preg_quote", "(", "$", "tour", "->", "pathmatch", ",", "'@'", ")", ";", "$", "pattern", "=", "str_replace", "(", "'%'", ",", "'.*'", ",", "$", "pattern", ")", ";", "return", "!", "!", "preg_match", "(", "\"@{$pattern}@\"", ",", "$", "target", ")", ";", "}", ")", ";", "}" ]
Fetch all enabled tours matching the specified target. @param moodle_url $targetmatch The URL to match.
[ "Fetch", "all", "enabled", "tours", "matching", "the", "specified", "target", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/cache.php#L81-L96
216,221
moodle/moodle
admin/tool/usertours/classes/cache.php
cache.notify_tour_change
public static function notify_tour_change() { $cache = \cache::make('tool_usertours', self::CACHENAME_TOUR); $cache->delete(self::CACHEKEY_TOUR); }
php
public static function notify_tour_change() { $cache = \cache::make('tool_usertours', self::CACHENAME_TOUR); $cache->delete(self::CACHEKEY_TOUR); }
[ "public", "static", "function", "notify_tour_change", "(", ")", "{", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'tool_usertours'", ",", "self", "::", "CACHENAME_TOUR", ")", ";", "$", "cache", "->", "delete", "(", "self", "::", "CACHEKEY_TOUR", ")", ";", "}" ]
Notify of changes to any tour to clear the tour cache.
[ "Notify", "of", "changes", "to", "any", "tour", "to", "clear", "the", "tour", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/cache.php#L101-L104
216,222
moodle/moodle
admin/tool/usertours/classes/cache.php
cache.get_stepdata
public static function get_stepdata($tourid) { global $DB; $cache = \cache::make('tool_usertours', self::CACHENAME_STEP); $data = $cache->get($tourid); if ($data === false) { $sql = <<<EOF SELECT s.* FROM {tool_usertours_steps} s WHERE s.tourid = :tourid ORDER BY s.sortorder ASC EOF; $data = $DB->get_records_sql($sql, ['tourid' => $tourid]); $cache->set($tourid, $data); } return $data; }
php
public static function get_stepdata($tourid) { global $DB; $cache = \cache::make('tool_usertours', self::CACHENAME_STEP); $data = $cache->get($tourid); if ($data === false) { $sql = <<<EOF SELECT s.* FROM {tool_usertours_steps} s WHERE s.tourid = :tourid ORDER BY s.sortorder ASC EOF; $data = $DB->get_records_sql($sql, ['tourid' => $tourid]); $cache->set($tourid, $data); } return $data; }
[ "public", "static", "function", "get_stepdata", "(", "$", "tourid", ")", "{", "global", "$", "DB", ";", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'tool_usertours'", ",", "self", "::", "CACHENAME_STEP", ")", ";", "$", "data", "=", "$", "cache", "->", "get", "(", "$", "tourid", ")", ";", "if", "(", "$", "data", "===", "false", ")", "{", "$", "sql", "=", " <<<EOF\n SELECT s.*\n FROM {tool_usertours_steps} s\n WHERE s.tourid = :tourid\n ORDER BY s.sortorder ASC\nEOF", ";", "$", "data", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "[", "'tourid'", "=>", "$", "tourid", "]", ")", ";", "$", "cache", "->", "set", "(", "$", "tourid", ",", "$", "data", ")", ";", "}", "return", "$", "data", ";", "}" ]
Fetch the tour data for the specified tour. @param int $tourid The ID of the tour to fetch steps for
[ "Fetch", "the", "tour", "data", "for", "the", "specified", "tour", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/cache.php#L111-L130
216,223
moodle/moodle
admin/tool/usertours/classes/cache.php
cache.notify_step_change
public static function notify_step_change($tourid) { $cache = \cache::make('tool_usertours', self::CACHENAME_STEP); $cache->delete($tourid); }
php
public static function notify_step_change($tourid) { $cache = \cache::make('tool_usertours', self::CACHENAME_STEP); $cache->delete($tourid); }
[ "public", "static", "function", "notify_step_change", "(", "$", "tourid", ")", "{", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'tool_usertours'", ",", "self", "::", "CACHENAME_STEP", ")", ";", "$", "cache", "->", "delete", "(", "$", "tourid", ")", ";", "}" ]
Notify of changes to any step to clear the step cache for that tour. @param int $tourid The ID of the tour to clear the step cache for
[ "Notify", "of", "changes", "to", "any", "step", "to", "clear", "the", "step", "cache", "for", "that", "tour", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/cache.php#L136-L139
216,224
moodle/moodle
lib/classes/event/course_completed.php
course_completed.create_from_completion
public static function create_from_completion(\stdClass $completion) { $event = self::create( array( 'objectid' => $completion->id, 'relateduserid' => $completion->userid, 'context' => \context_course::instance($completion->course), 'courseid' => $completion->course, 'other' => array('relateduserid' => $completion->userid), // Deprecated since 2.7, please use property relateduserid. ) ); $event->add_record_snapshot('course_completions', $completion); return $event; }
php
public static function create_from_completion(\stdClass $completion) { $event = self::create( array( 'objectid' => $completion->id, 'relateduserid' => $completion->userid, 'context' => \context_course::instance($completion->course), 'courseid' => $completion->course, 'other' => array('relateduserid' => $completion->userid), // Deprecated since 2.7, please use property relateduserid. ) ); $event->add_record_snapshot('course_completions', $completion); return $event; }
[ "public", "static", "function", "create_from_completion", "(", "\\", "stdClass", "$", "completion", ")", "{", "$", "event", "=", "self", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "completion", "->", "id", ",", "'relateduserid'", "=>", "$", "completion", "->", "userid", ",", "'context'", "=>", "\\", "context_course", "::", "instance", "(", "$", "completion", "->", "course", ")", ",", "'courseid'", "=>", "$", "completion", "->", "course", ",", "'other'", "=>", "array", "(", "'relateduserid'", "=>", "$", "completion", "->", "userid", ")", ",", "// Deprecated since 2.7, please use property relateduserid.", ")", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'course_completions'", ",", "$", "completion", ")", ";", "return", "$", "event", ";", "}" ]
Create event from course_completion record. @param \stdClass $completion @return course_completed
[ "Create", "event", "from", "course_completion", "record", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/course_completed.php#L50-L62
216,225
moodle/moodle
lib/phpexcel/PHPExcel/Shared/Date.php
PHPExcel_Shared_Date.dayStringToNumber
public static function dayStringToNumber($day) { $strippedDayValue = (str_replace(self::$numberSuffixes, '', $day)); if (is_numeric($strippedDayValue)) { return (integer) $strippedDayValue; } return $day; }
php
public static function dayStringToNumber($day) { $strippedDayValue = (str_replace(self::$numberSuffixes, '', $day)); if (is_numeric($strippedDayValue)) { return (integer) $strippedDayValue; } return $day; }
[ "public", "static", "function", "dayStringToNumber", "(", "$", "day", ")", "{", "$", "strippedDayValue", "=", "(", "str_replace", "(", "self", "::", "$", "numberSuffixes", ",", "''", ",", "$", "day", ")", ")", ";", "if", "(", "is_numeric", "(", "$", "strippedDayValue", ")", ")", "{", "return", "(", "integer", ")", "$", "strippedDayValue", ";", "}", "return", "$", "day", ";", "}" ]
Strips an ordinal froma numeric value @param string $day Day number with an ordinal @return integer|string The integer value with any ordinal stripped, or the original string argument if it isn't a valid numeric
[ "Strips", "an", "ordinal", "froma", "numeric", "value" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/Date.php#L401-L408
216,226
moodle/moodle
question/engine/questionattempt.php
question_attempt.get_step
public function get_step($i) { if ($i < 0 || $i >= count($this->steps)) { throw new coding_exception('Index out of bounds in question_attempt::get_step.'); } return $this->steps[$i]; }
php
public function get_step($i) { if ($i < 0 || $i >= count($this->steps)) { throw new coding_exception('Index out of bounds in question_attempt::get_step.'); } return $this->steps[$i]; }
[ "public", "function", "get_step", "(", "$", "i", ")", "{", "if", "(", "$", "i", "<", "0", "||", "$", "i", ">=", "count", "(", "$", "this", "->", "steps", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Index out of bounds in question_attempt::get_step.'", ")", ";", "}", "return", "$", "this", "->", "steps", "[", "$", "i", "]", ";", "}" ]
Get one of the steps in this attempt. @param int $i the step number, which counts from 0. @return question_attempt_step
[ "Get", "one", "of", "the", "steps", "in", "this", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L383-L388
216,227
moodle/moodle
question/engine/questionattempt.php
question_attempt.get_last_step_with_qt_var
public function get_last_step_with_qt_var($name) { foreach ($this->get_reverse_step_iterator() as $step) { if ($step->has_qt_var($name)) { return $step; } } return new question_attempt_step_read_only(); }
php
public function get_last_step_with_qt_var($name) { foreach ($this->get_reverse_step_iterator() as $step) { if ($step->has_qt_var($name)) { return $step; } } return new question_attempt_step_read_only(); }
[ "public", "function", "get_last_step_with_qt_var", "(", "$", "name", ")", "{", "foreach", "(", "$", "this", "->", "get_reverse_step_iterator", "(", ")", "as", "$", "step", ")", "{", "if", "(", "$", "step", "->", "has_qt_var", "(", "$", "name", ")", ")", "{", "return", "$", "step", ";", "}", "}", "return", "new", "question_attempt_step_read_only", "(", ")", ";", "}" ]
Get the last step with a particular question type varialbe set. @param string $name the name of the variable to get. @return question_attempt_step the last step, or a step with no variables if there was not a real step.
[ "Get", "the", "last", "step", "with", "a", "particular", "question", "type", "varialbe", "set", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L486-L493
216,228
moodle/moodle
question/engine/questionattempt.php
question_attempt.get_last_step_with_behaviour_var
public function get_last_step_with_behaviour_var($name) { foreach ($this->get_reverse_step_iterator() as $step) { if ($step->has_behaviour_var($name)) { return $step; } } return new question_attempt_step_read_only(); }
php
public function get_last_step_with_behaviour_var($name) { foreach ($this->get_reverse_step_iterator() as $step) { if ($step->has_behaviour_var($name)) { return $step; } } return new question_attempt_step_read_only(); }
[ "public", "function", "get_last_step_with_behaviour_var", "(", "$", "name", ")", "{", "foreach", "(", "$", "this", "->", "get_reverse_step_iterator", "(", ")", "as", "$", "step", ")", "{", "if", "(", "$", "step", "->", "has_behaviour_var", "(", "$", "name", ")", ")", "{", "return", "$", "step", ";", "}", "}", "return", "new", "question_attempt_step_read_only", "(", ")", ";", "}" ]
Get the last step with a particular behaviour variable set. @param string $name the name of the variable to get. @return question_attempt_step the last step, or a step with no variables if there was not a real step.
[ "Get", "the", "last", "step", "with", "a", "particular", "behaviour", "variable", "set", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L501-L508
216,229
moodle/moodle
question/engine/questionattempt.php
question_attempt.get_last_qt_var
public function get_last_qt_var($name, $default = null) { $step = $this->get_last_step_with_qt_var($name); if ($step->has_qt_var($name)) { return $step->get_qt_var($name); } else { return $default; } }
php
public function get_last_qt_var($name, $default = null) { $step = $this->get_last_step_with_qt_var($name); if ($step->has_qt_var($name)) { return $step->get_qt_var($name); } else { return $default; } }
[ "public", "function", "get_last_qt_var", "(", "$", "name", ",", "$", "default", "=", "null", ")", "{", "$", "step", "=", "$", "this", "->", "get_last_step_with_qt_var", "(", "$", "name", ")", ";", "if", "(", "$", "step", "->", "has_qt_var", "(", "$", "name", ")", ")", "{", "return", "$", "step", "->", "get_qt_var", "(", "$", "name", ")", ";", "}", "else", "{", "return", "$", "default", ";", "}", "}" ]
Get the latest value of a particular question type variable. That is, get the value from the latest step that has it set. Return null if it is not set in any step. @param string $name the name of the variable to get. @param mixed default the value to return in the variable has never been set. (Optional, defaults to null.) @return mixed string value, or $default if it has never been set.
[ "Get", "the", "latest", "value", "of", "a", "particular", "question", "type", "variable", ".", "That", "is", "get", "the", "value", "from", "the", "latest", "step", "that", "has", "it", "set", ".", "Return", "null", "if", "it", "is", "not", "set", "in", "any", "step", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L520-L527
216,230
moodle/moodle
question/engine/questionattempt.php
question_attempt.get_response_file_url
public function get_response_file_url(stored_file $file) { return file_encode_url(new moodle_url('/pluginfile.php'), '/' . implode('/', array( $file->get_contextid(), $file->get_component(), $file->get_filearea(), $this->usageid, $this->slot, $file->get_itemid())) . $file->get_filepath() . $file->get_filename(), true); }
php
public function get_response_file_url(stored_file $file) { return file_encode_url(new moodle_url('/pluginfile.php'), '/' . implode('/', array( $file->get_contextid(), $file->get_component(), $file->get_filearea(), $this->usageid, $this->slot, $file->get_itemid())) . $file->get_filepath() . $file->get_filename(), true); }
[ "public", "function", "get_response_file_url", "(", "stored_file", "$", "file", ")", "{", "return", "file_encode_url", "(", "new", "moodle_url", "(", "'/pluginfile.php'", ")", ",", "'/'", ".", "implode", "(", "'/'", ",", "array", "(", "$", "file", "->", "get_contextid", "(", ")", ",", "$", "file", "->", "get_component", "(", ")", ",", "$", "file", "->", "get_filearea", "(", ")", ",", "$", "this", "->", "usageid", ",", "$", "this", "->", "slot", ",", "$", "file", "->", "get_itemid", "(", ")", ")", ")", ".", "$", "file", "->", "get_filepath", "(", ")", ".", "$", "file", "->", "get_filename", "(", ")", ",", "true", ")", ";", "}" ]
Get the URL of a file that belongs to a response variable of this question_attempt. @param stored_file $file the file to link to. @return string the URL of that file.
[ "Get", "the", "URL", "of", "a", "file", "that", "belongs", "to", "a", "response", "variable", "of", "this", "question_attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L552-L561
216,231
moodle/moodle
question/engine/questionattempt.php
question_attempt.prepare_response_files_draft_itemid
public function prepare_response_files_draft_itemid($name, $contextid) { foreach ($this->get_reverse_step_iterator() as $step) { if ($step->has_qt_var($name)) { return $step->prepare_response_files_draft_itemid($name, $contextid); } } // No files yet. $draftid = 0; // Will be filled in by file_prepare_draft_area. file_prepare_draft_area($draftid, $contextid, 'question', 'response_' . $name, null); return $draftid; }
php
public function prepare_response_files_draft_itemid($name, $contextid) { foreach ($this->get_reverse_step_iterator() as $step) { if ($step->has_qt_var($name)) { return $step->prepare_response_files_draft_itemid($name, $contextid); } } // No files yet. $draftid = 0; // Will be filled in by file_prepare_draft_area. file_prepare_draft_area($draftid, $contextid, 'question', 'response_' . $name, null); return $draftid; }
[ "public", "function", "prepare_response_files_draft_itemid", "(", "$", "name", ",", "$", "contextid", ")", "{", "foreach", "(", "$", "this", "->", "get_reverse_step_iterator", "(", ")", "as", "$", "step", ")", "{", "if", "(", "$", "step", "->", "has_qt_var", "(", "$", "name", ")", ")", "{", "return", "$", "step", "->", "prepare_response_files_draft_itemid", "(", "$", "name", ",", "$", "contextid", ")", ";", "}", "}", "// No files yet.", "$", "draftid", "=", "0", ";", "// Will be filled in by file_prepare_draft_area.", "file_prepare_draft_area", "(", "$", "draftid", ",", "$", "contextid", ",", "'question'", ",", "'response_'", ".", "$", "name", ",", "null", ")", ";", "return", "$", "draftid", ";", "}" ]
Prepare a draft file are for the files belonging the a response variable of this question attempt. The draft area is populated with the files from the most recent step having files. @param string $name the variable name the files belong to. @param int $contextid the id of the context the quba belongs to. @return int the draft itemid.
[ "Prepare", "a", "draft", "file", "are", "for", "the", "files", "belonging", "the", "a", "response", "variable", "of", "this", "question", "attempt", ".", "The", "draft", "area", "is", "populated", "with", "the", "files", "from", "the", "most", "recent", "step", "having", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L572-L583
216,232
moodle/moodle
question/engine/questionattempt.php
question_attempt.get_last_behaviour_var
public function get_last_behaviour_var($name, $default = null) { foreach ($this->get_reverse_step_iterator() as $step) { if ($step->has_behaviour_var($name)) { return $step->get_behaviour_var($name); } } return $default; }
php
public function get_last_behaviour_var($name, $default = null) { foreach ($this->get_reverse_step_iterator() as $step) { if ($step->has_behaviour_var($name)) { return $step->get_behaviour_var($name); } } return $default; }
[ "public", "function", "get_last_behaviour_var", "(", "$", "name", ",", "$", "default", "=", "null", ")", "{", "foreach", "(", "$", "this", "->", "get_reverse_step_iterator", "(", ")", "as", "$", "step", ")", "{", "if", "(", "$", "step", "->", "has_behaviour_var", "(", "$", "name", ")", ")", "{", "return", "$", "step", "->", "get_behaviour_var", "(", "$", "name", ")", ";", "}", "}", "return", "$", "default", ";", "}" ]
Get the latest value of a particular behaviour variable. That is, get the value from the latest step that has it set. Return null if it is not set in any step. @param string $name the name of the variable to get. @param mixed default the value to return in the variable has never been set. (Optional, defaults to null.) @return mixed string value, or $default if it has never been set.
[ "Get", "the", "latest", "value", "of", "a", "particular", "behaviour", "variable", ".", "That", "is", "get", "the", "value", "from", "the", "latest", "step", "that", "has", "it", "set", ".", "Return", "null", "if", "it", "is", "not", "set", "in", "any", "step", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L595-L602
216,233
moodle/moodle
question/engine/questionattempt.php
question_attempt.get_current_manual_mark
public function get_current_manual_mark() { // Is there a current value in the current POST data? If so, use that. $mark = $this->get_submitted_var($this->get_behaviour_field_name('mark'), PARAM_RAW_TRIMMED); if ($mark !== null) { return $mark; } // Otherwise, use the stored value. // If the question max mark has not changed, use the stored value that was input. $storedmaxmark = $this->get_last_behaviour_var('maxmark'); if ($storedmaxmark !== null && ($storedmaxmark - $this->get_max_mark()) < 0.0000005) { return $this->get_last_behaviour_var('mark'); } // The max mark for this question has changed so we must re-scale the current mark. return format_float($this->get_mark(), 7, true, true); }
php
public function get_current_manual_mark() { // Is there a current value in the current POST data? If so, use that. $mark = $this->get_submitted_var($this->get_behaviour_field_name('mark'), PARAM_RAW_TRIMMED); if ($mark !== null) { return $mark; } // Otherwise, use the stored value. // If the question max mark has not changed, use the stored value that was input. $storedmaxmark = $this->get_last_behaviour_var('maxmark'); if ($storedmaxmark !== null && ($storedmaxmark - $this->get_max_mark()) < 0.0000005) { return $this->get_last_behaviour_var('mark'); } // The max mark for this question has changed so we must re-scale the current mark. return format_float($this->get_mark(), 7, true, true); }
[ "public", "function", "get_current_manual_mark", "(", ")", "{", "// Is there a current value in the current POST data? If so, use that.", "$", "mark", "=", "$", "this", "->", "get_submitted_var", "(", "$", "this", "->", "get_behaviour_field_name", "(", "'mark'", ")", ",", "PARAM_RAW_TRIMMED", ")", ";", "if", "(", "$", "mark", "!==", "null", ")", "{", "return", "$", "mark", ";", "}", "// Otherwise, use the stored value.", "// If the question max mark has not changed, use the stored value that was input.", "$", "storedmaxmark", "=", "$", "this", "->", "get_last_behaviour_var", "(", "'maxmark'", ")", ";", "if", "(", "$", "storedmaxmark", "!==", "null", "&&", "(", "$", "storedmaxmark", "-", "$", "this", "->", "get_max_mark", "(", ")", ")", "<", "0.0000005", ")", "{", "return", "$", "this", "->", "get_last_behaviour_var", "(", "'mark'", ")", ";", "}", "// The max mark for this question has changed so we must re-scale the current mark.", "return", "format_float", "(", "$", "this", "->", "get_mark", "(", ")", ",", "7", ",", "true", ",", "true", ")", ";", "}" ]
This is used by the manual grading code, particularly in association with validation. It gets the current manual mark for a question, in exactly the string form that the teacher entered it, if possible. This may come from the current POST request, if there is one, otherwise from the database. @return string the current manual mark for this question, in the format the teacher typed, if possible.
[ "This", "is", "used", "by", "the", "manual", "grading", "code", "particularly", "in", "association", "with", "validation", ".", "It", "gets", "the", "current", "manual", "mark", "for", "a", "question", "in", "exactly", "the", "string", "form", "that", "the", "teacher", "entered", "it", "if", "possible", ".", "This", "may", "come", "from", "the", "current", "POST", "request", "if", "there", "is", "one", "otherwise", "from", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L674-L690
216,234
moodle/moodle
question/engine/questionattempt.php
question_attempt.set_metadata
public function set_metadata($name, $value) { $firststep = $this->get_step(0); if (!$firststep->has_metadata_var($name)) { $this->observer->notify_metadata_added($this, $name); } else if ($value !== $firststep->get_metadata_var($name)) { $this->observer->notify_metadata_modified($this, $name); } $firststep->set_metadata_var($name, $value); }
php
public function set_metadata($name, $value) { $firststep = $this->get_step(0); if (!$firststep->has_metadata_var($name)) { $this->observer->notify_metadata_added($this, $name); } else if ($value !== $firststep->get_metadata_var($name)) { $this->observer->notify_metadata_modified($this, $name); } $firststep->set_metadata_var($name, $value); }
[ "public", "function", "set_metadata", "(", "$", "name", ",", "$", "value", ")", "{", "$", "firststep", "=", "$", "this", "->", "get_step", "(", "0", ")", ";", "if", "(", "!", "$", "firststep", "->", "has_metadata_var", "(", "$", "name", ")", ")", "{", "$", "this", "->", "observer", "->", "notify_metadata_added", "(", "$", "this", ",", "$", "name", ")", ";", "}", "else", "if", "(", "$", "value", "!==", "$", "firststep", "->", "get_metadata_var", "(", "$", "name", ")", ")", "{", "$", "this", "->", "observer", "->", "notify_metadata_modified", "(", "$", "this", ",", "$", "name", ")", ";", "}", "$", "firststep", "->", "set_metadata_var", "(", "$", "name", ",", "$", "value", ")", ";", "}" ]
Set some metadata for this question attempt. @param string $name the name of the metadata variable to return. @param string $value the value to set that metadata variable to.
[ "Set", "some", "metadata", "for", "this", "question", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L793-L801
216,235
moodle/moodle
question/engine/questionattempt.php
question_attempt.add_step
protected function add_step(question_attempt_step $step) { $this->steps[] = $step; end($this->steps); $this->observer->notify_step_added($step, $this, key($this->steps)); }
php
protected function add_step(question_attempt_step $step) { $this->steps[] = $step; end($this->steps); $this->observer->notify_step_added($step, $this, key($this->steps)); }
[ "protected", "function", "add_step", "(", "question_attempt_step", "$", "step", ")", "{", "$", "this", "->", "steps", "[", "]", "=", "$", "step", ";", "end", "(", "$", "this", "->", "steps", ")", ";", "$", "this", "->", "observer", "->", "notify_step_added", "(", "$", "step", ",", "$", "this", ",", "key", "(", "$", "this", "->", "steps", ")", ")", ";", "}" ]
Add a step to this question attempt. @param question_attempt_step $step the new step.
[ "Add", "a", "step", "to", "this", "question", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L913-L917
216,236
moodle/moodle
question/engine/questionattempt.php
question_attempt.add_autosaved_step
protected function add_autosaved_step(question_attempt_step $step) { $this->steps[] = $step; $this->autosavedstep = $step; end($this->steps); $this->observer->notify_step_added($step, $this, -key($this->steps)); }
php
protected function add_autosaved_step(question_attempt_step $step) { $this->steps[] = $step; $this->autosavedstep = $step; end($this->steps); $this->observer->notify_step_added($step, $this, -key($this->steps)); }
[ "protected", "function", "add_autosaved_step", "(", "question_attempt_step", "$", "step", ")", "{", "$", "this", "->", "steps", "[", "]", "=", "$", "step", ";", "$", "this", "->", "autosavedstep", "=", "$", "step", ";", "end", "(", "$", "this", "->", "steps", ")", ";", "$", "this", "->", "observer", "->", "notify_step_added", "(", "$", "step", ",", "$", "this", ",", "-", "key", "(", "$", "this", "->", "steps", ")", ")", ";", "}" ]
Add an auto-saved step to this question attempt. We mark auto-saved steps by changing saving the step number with a - sign. @param question_attempt_step $step the new step.
[ "Add", "an", "auto", "-", "saved", "step", "to", "this", "question", "attempt", ".", "We", "mark", "auto", "-", "saved", "steps", "by", "changing", "saving", "the", "step", "number", "with", "a", "-", "sign", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L924-L929
216,237
moodle/moodle
question/engine/questionattempt.php
question_attempt.discard_autosaved_step
public function discard_autosaved_step() { if (!$this->has_autosaved_step()) { return; } $autosaved = array_pop($this->steps); $this->autosavedstep = null; $this->observer->notify_step_deleted($autosaved, $this); }
php
public function discard_autosaved_step() { if (!$this->has_autosaved_step()) { return; } $autosaved = array_pop($this->steps); $this->autosavedstep = null; $this->observer->notify_step_deleted($autosaved, $this); }
[ "public", "function", "discard_autosaved_step", "(", ")", "{", "if", "(", "!", "$", "this", "->", "has_autosaved_step", "(", ")", ")", "{", "return", ";", "}", "$", "autosaved", "=", "array_pop", "(", "$", "this", "->", "steps", ")", ";", "$", "this", "->", "autosavedstep", "=", "null", ";", "$", "this", "->", "observer", "->", "notify_step_deleted", "(", "$", "autosaved", ",", "$", "this", ")", ";", "}" ]
Discard any auto-saved data belonging to this question attempt.
[ "Discard", "any", "auto", "-", "saved", "data", "belonging", "to", "this", "question", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L934-L942
216,238
moodle/moodle
question/engine/questionattempt.php
question_attempt.convert_autosaved_step_to_real_step
protected function convert_autosaved_step_to_real_step() { if ($this->autosavedstep === null) { return; } $laststep = end($this->steps); if ($laststep !== $this->autosavedstep) { throw new coding_exception('Cannot convert autosaved step to real step, since other steps have been added.'); } $this->observer->notify_step_modified($this->autosavedstep, $this, key($this->steps)); $this->autosavedstep = null; }
php
protected function convert_autosaved_step_to_real_step() { if ($this->autosavedstep === null) { return; } $laststep = end($this->steps); if ($laststep !== $this->autosavedstep) { throw new coding_exception('Cannot convert autosaved step to real step, since other steps have been added.'); } $this->observer->notify_step_modified($this->autosavedstep, $this, key($this->steps)); $this->autosavedstep = null; }
[ "protected", "function", "convert_autosaved_step_to_real_step", "(", ")", "{", "if", "(", "$", "this", "->", "autosavedstep", "===", "null", ")", "{", "return", ";", "}", "$", "laststep", "=", "end", "(", "$", "this", "->", "steps", ")", ";", "if", "(", "$", "laststep", "!==", "$", "this", "->", "autosavedstep", ")", "{", "throw", "new", "coding_exception", "(", "'Cannot convert autosaved step to real step, since other steps have been added.'", ")", ";", "}", "$", "this", "->", "observer", "->", "notify_step_modified", "(", "$", "this", "->", "autosavedstep", ",", "$", "this", ",", "key", "(", "$", "this", "->", "steps", ")", ")", ";", "$", "this", "->", "autosavedstep", "=", "null", ";", "}" ]
If there is an autosaved step, convert it into a real save, so that it is preserved.
[ "If", "there", "is", "an", "autosaved", "step", "convert", "it", "into", "a", "real", "save", "so", "that", "it", "is", "preserved", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L948-L960
216,239
moodle/moodle
question/engine/questionattempt.php
question_attempt.select_variant
public function select_variant(question_variant_selection_strategy $variantstrategy) { return $variantstrategy->choose_variant($this->get_question()->get_num_variants(), $this->get_question()->get_variants_selection_seed()); }
php
public function select_variant(question_variant_selection_strategy $variantstrategy) { return $variantstrategy->choose_variant($this->get_question()->get_num_variants(), $this->get_question()->get_variants_selection_seed()); }
[ "public", "function", "select_variant", "(", "question_variant_selection_strategy", "$", "variantstrategy", ")", "{", "return", "$", "variantstrategy", "->", "choose_variant", "(", "$", "this", "->", "get_question", "(", ")", "->", "get_num_variants", "(", ")", ",", "$", "this", "->", "get_question", "(", ")", "->", "get_variants_selection_seed", "(", ")", ")", ";", "}" ]
Use a strategy to pick a variant. @param question_variant_selection_strategy $variantstrategy a strategy. @return int the selected variant.
[ "Use", "a", "strategy", "to", "pick", "a", "variant", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L967-L970
216,240
moodle/moodle
question/engine/questionattempt.php
question_attempt.start
public function start($preferredbehaviour, $variant, $submitteddata = array(), $timestamp = null, $userid = null, $existingstepid = null) { if ($this->get_num_steps() > 0) { throw new coding_exception('Cannot start a question that is already started.'); } // Initialise the behaviour. $this->variant = $variant; if (is_string($preferredbehaviour)) { $this->behaviour = $this->question->make_behaviour($this, $preferredbehaviour); } else { $class = get_class($preferredbehaviour); $this->behaviour = new $class($this, $preferredbehaviour); } // Record the minimum and maximum fractions. $this->minfraction = $this->behaviour->get_min_fraction(); $this->maxfraction = $this->behaviour->get_max_fraction(); // Initialise the first step. $firststep = new question_attempt_step($submitteddata, $timestamp, $userid, $existingstepid); if ($submitteddata) { $firststep->set_state(question_state::$complete); $this->behaviour->apply_attempt_state($firststep); } else { $this->behaviour->init_first_step($firststep, $variant); } $this->add_step($firststep); // Record questionline and correct answer. $this->questionsummary = $this->behaviour->get_question_summary(); $this->rightanswer = $this->behaviour->get_right_answer_summary(); }
php
public function start($preferredbehaviour, $variant, $submitteddata = array(), $timestamp = null, $userid = null, $existingstepid = null) { if ($this->get_num_steps() > 0) { throw new coding_exception('Cannot start a question that is already started.'); } // Initialise the behaviour. $this->variant = $variant; if (is_string($preferredbehaviour)) { $this->behaviour = $this->question->make_behaviour($this, $preferredbehaviour); } else { $class = get_class($preferredbehaviour); $this->behaviour = new $class($this, $preferredbehaviour); } // Record the minimum and maximum fractions. $this->minfraction = $this->behaviour->get_min_fraction(); $this->maxfraction = $this->behaviour->get_max_fraction(); // Initialise the first step. $firststep = new question_attempt_step($submitteddata, $timestamp, $userid, $existingstepid); if ($submitteddata) { $firststep->set_state(question_state::$complete); $this->behaviour->apply_attempt_state($firststep); } else { $this->behaviour->init_first_step($firststep, $variant); } $this->add_step($firststep); // Record questionline and correct answer. $this->questionsummary = $this->behaviour->get_question_summary(); $this->rightanswer = $this->behaviour->get_right_answer_summary(); }
[ "public", "function", "start", "(", "$", "preferredbehaviour", ",", "$", "variant", ",", "$", "submitteddata", "=", "array", "(", ")", ",", "$", "timestamp", "=", "null", ",", "$", "userid", "=", "null", ",", "$", "existingstepid", "=", "null", ")", "{", "if", "(", "$", "this", "->", "get_num_steps", "(", ")", ">", "0", ")", "{", "throw", "new", "coding_exception", "(", "'Cannot start a question that is already started.'", ")", ";", "}", "// Initialise the behaviour.", "$", "this", "->", "variant", "=", "$", "variant", ";", "if", "(", "is_string", "(", "$", "preferredbehaviour", ")", ")", "{", "$", "this", "->", "behaviour", "=", "$", "this", "->", "question", "->", "make_behaviour", "(", "$", "this", ",", "$", "preferredbehaviour", ")", ";", "}", "else", "{", "$", "class", "=", "get_class", "(", "$", "preferredbehaviour", ")", ";", "$", "this", "->", "behaviour", "=", "new", "$", "class", "(", "$", "this", ",", "$", "preferredbehaviour", ")", ";", "}", "// Record the minimum and maximum fractions.", "$", "this", "->", "minfraction", "=", "$", "this", "->", "behaviour", "->", "get_min_fraction", "(", ")", ";", "$", "this", "->", "maxfraction", "=", "$", "this", "->", "behaviour", "->", "get_max_fraction", "(", ")", ";", "// Initialise the first step.", "$", "firststep", "=", "new", "question_attempt_step", "(", "$", "submitteddata", ",", "$", "timestamp", ",", "$", "userid", ",", "$", "existingstepid", ")", ";", "if", "(", "$", "submitteddata", ")", "{", "$", "firststep", "->", "set_state", "(", "question_state", "::", "$", "complete", ")", ";", "$", "this", "->", "behaviour", "->", "apply_attempt_state", "(", "$", "firststep", ")", ";", "}", "else", "{", "$", "this", "->", "behaviour", "->", "init_first_step", "(", "$", "firststep", ",", "$", "variant", ")", ";", "}", "$", "this", "->", "add_step", "(", "$", "firststep", ")", ";", "// Record questionline and correct answer.", "$", "this", "->", "questionsummary", "=", "$", "this", "->", "behaviour", "->", "get_question_summary", "(", ")", ";", "$", "this", "->", "rightanswer", "=", "$", "this", "->", "behaviour", "->", "get_right_answer_summary", "(", ")", ";", "}" ]
Start this question attempt. You should not call this method directly. Call {@link question_usage_by_activity::start_question()} instead. @param string|question_behaviour $preferredbehaviour the name of the desired archetypal behaviour, or an actual model instance. @param int $variant the variant of the question to start. Between 1 and $this->get_question()->get_num_variants() inclusive. @param array $submitteddata optional, used when re-starting to keep the same initial state. @param int $timestamp optional, the timstamp to record for this action. Defaults to now. @param int $userid optional, the user to attribute this action to. Defaults to the current user. @param int $existingstepid optional, if this step is going to replace an existing step (for example, during a regrade) this is the id of the previous step we are replacing.
[ "Start", "this", "question", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L988-L1022
216,241
moodle/moodle
question/engine/questionattempt.php
question_attempt.validate_manual_mark
public function validate_manual_mark($currentmark) { if ($currentmark === null || $currentmark === '') { return ''; } $mark = question_utils::clean_param_mark($currentmark); if ($mark === null) { return get_string('manualgradeinvalidformat', 'question'); } $maxmark = $this->get_max_mark(); if ($mark > $maxmark * $this->get_max_fraction() || $mark < $maxmark * $this->get_min_fraction()) { return get_string('manualgradeoutofrange', 'question'); } return ''; }
php
public function validate_manual_mark($currentmark) { if ($currentmark === null || $currentmark === '') { return ''; } $mark = question_utils::clean_param_mark($currentmark); if ($mark === null) { return get_string('manualgradeinvalidformat', 'question'); } $maxmark = $this->get_max_mark(); if ($mark > $maxmark * $this->get_max_fraction() || $mark < $maxmark * $this->get_min_fraction()) { return get_string('manualgradeoutofrange', 'question'); } return ''; }
[ "public", "function", "validate_manual_mark", "(", "$", "currentmark", ")", "{", "if", "(", "$", "currentmark", "===", "null", "||", "$", "currentmark", "===", "''", ")", "{", "return", "''", ";", "}", "$", "mark", "=", "question_utils", "::", "clean_param_mark", "(", "$", "currentmark", ")", ";", "if", "(", "$", "mark", "===", "null", ")", "{", "return", "get_string", "(", "'manualgradeinvalidformat'", ",", "'question'", ")", ";", "}", "$", "maxmark", "=", "$", "this", "->", "get_max_mark", "(", ")", ";", "if", "(", "$", "mark", ">", "$", "maxmark", "*", "$", "this", "->", "get_max_fraction", "(", ")", "||", "$", "mark", "<", "$", "maxmark", "*", "$", "this", "->", "get_min_fraction", "(", ")", ")", "{", "return", "get_string", "(", "'manualgradeoutofrange'", ",", "'question'", ")", ";", "}", "return", "''", ";", "}" ]
Validate the manual mark for a question. @param string $currentmark the user input (e.g. '1,0', '1,0' or 'invalid'. @return string any errors with the value, or '' if it is OK.
[ "Validate", "the", "manual", "mark", "for", "a", "question", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L1099-L1115
216,242
moodle/moodle
question/engine/questionattempt.php
question_attempt.process_response_files
protected function process_response_files($name, $draftidname, $postdata = null, $text = null) { if ($postdata) { // For simulated posts, get the draft itemid from there. $draftitemid = $this->get_submitted_var($draftidname, PARAM_INT, $postdata); } else { $draftitemid = file_get_submitted_draft_itemid($draftidname); } if (!$draftitemid) { return null; } $filearea = str_replace($this->get_field_prefix(), '', $name); $filearea = str_replace('-', 'bf_', $filearea); $filearea = 'response_' . $filearea; return new question_file_saver($draftitemid, 'question', $filearea, $text); }
php
protected function process_response_files($name, $draftidname, $postdata = null, $text = null) { if ($postdata) { // For simulated posts, get the draft itemid from there. $draftitemid = $this->get_submitted_var($draftidname, PARAM_INT, $postdata); } else { $draftitemid = file_get_submitted_draft_itemid($draftidname); } if (!$draftitemid) { return null; } $filearea = str_replace($this->get_field_prefix(), '', $name); $filearea = str_replace('-', 'bf_', $filearea); $filearea = 'response_' . $filearea; return new question_file_saver($draftitemid, 'question', $filearea, $text); }
[ "protected", "function", "process_response_files", "(", "$", "name", ",", "$", "draftidname", ",", "$", "postdata", "=", "null", ",", "$", "text", "=", "null", ")", "{", "if", "(", "$", "postdata", ")", "{", "// For simulated posts, get the draft itemid from there.", "$", "draftitemid", "=", "$", "this", "->", "get_submitted_var", "(", "$", "draftidname", ",", "PARAM_INT", ",", "$", "postdata", ")", ";", "}", "else", "{", "$", "draftitemid", "=", "file_get_submitted_draft_itemid", "(", "$", "draftidname", ")", ";", "}", "if", "(", "!", "$", "draftitemid", ")", "{", "return", "null", ";", "}", "$", "filearea", "=", "str_replace", "(", "$", "this", "->", "get_field_prefix", "(", ")", ",", "''", ",", "$", "name", ")", ";", "$", "filearea", "=", "str_replace", "(", "'-'", ",", "'bf_'", ",", "$", "filearea", ")", ";", "$", "filearea", "=", "'response_'", ".", "$", "filearea", ";", "return", "new", "question_file_saver", "(", "$", "draftitemid", ",", "'question'", ",", "$", "filearea", ",", "$", "text", ")", ";", "}" ]
Handle a submitted variable representing uploaded files. @param string $name the field name. @param string $draftidname the field name holding the draft file area id. @param array $postdata (optional, only inteded for testing use) take the data from this array, instead of from $_POST. At the moment, this behaves as if there were no files. @param string $text optional reponse text. @return question_file_saver that can be used to save the files later.
[ "Handle", "a", "submitted", "variable", "representing", "uploaded", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L1127-L1143
216,243
moodle/moodle
question/engine/questionattempt.php
question_attempt.get_expected_data
protected function get_expected_data($expected, $postdata, $extraprefix) { $submitteddata = array(); foreach ($expected as $name => $type) { $value = $this->get_submitted_var( $this->get_field_prefix() . $extraprefix . $name, $type, $postdata); if (!is_null($value)) { $submitteddata[$extraprefix . $name] = $value; } } return $submitteddata; }
php
protected function get_expected_data($expected, $postdata, $extraprefix) { $submitteddata = array(); foreach ($expected as $name => $type) { $value = $this->get_submitted_var( $this->get_field_prefix() . $extraprefix . $name, $type, $postdata); if (!is_null($value)) { $submitteddata[$extraprefix . $name] = $value; } } return $submitteddata; }
[ "protected", "function", "get_expected_data", "(", "$", "expected", ",", "$", "postdata", ",", "$", "extraprefix", ")", "{", "$", "submitteddata", "=", "array", "(", ")", ";", "foreach", "(", "$", "expected", "as", "$", "name", "=>", "$", "type", ")", "{", "$", "value", "=", "$", "this", "->", "get_submitted_var", "(", "$", "this", "->", "get_field_prefix", "(", ")", ".", "$", "extraprefix", ".", "$", "name", ",", "$", "type", ",", "$", "postdata", ")", ";", "if", "(", "!", "is_null", "(", "$", "value", ")", ")", "{", "$", "submitteddata", "[", "$", "extraprefix", ".", "$", "name", "]", "=", "$", "value", ";", "}", "}", "return", "$", "submitteddata", ";", "}" ]
Get any data from the request that matches the list of expected params. @param array $expected variable name => PARAM_... constant. @param null|array $postdata null to use real post data, otherwise an array of data to use. @param string $extraprefix '-' or ''. @return array name => value.
[ "Get", "any", "data", "from", "the", "request", "that", "matches", "the", "list", "of", "expected", "params", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L1153-L1163
216,244
moodle/moodle
question/engine/questionattempt.php
question_attempt.get_all_submitted_qt_vars
public function get_all_submitted_qt_vars($postdata) { if (is_null($postdata)) { $postdata = $_POST; } $pattern = '/^' . preg_quote($this->get_field_prefix(), '/') . '[^-:]/'; $prefixlen = strlen($this->get_field_prefix()); $submitteddata = array(); foreach ($postdata as $name => $value) { if (preg_match($pattern, $name)) { $submitteddata[substr($name, $prefixlen)] = $value; } } return $submitteddata; }
php
public function get_all_submitted_qt_vars($postdata) { if (is_null($postdata)) { $postdata = $_POST; } $pattern = '/^' . preg_quote($this->get_field_prefix(), '/') . '[^-:]/'; $prefixlen = strlen($this->get_field_prefix()); $submitteddata = array(); foreach ($postdata as $name => $value) { if (preg_match($pattern, $name)) { $submitteddata[substr($name, $prefixlen)] = $value; } } return $submitteddata; }
[ "public", "function", "get_all_submitted_qt_vars", "(", "$", "postdata", ")", "{", "if", "(", "is_null", "(", "$", "postdata", ")", ")", "{", "$", "postdata", "=", "$", "_POST", ";", "}", "$", "pattern", "=", "'/^'", ".", "preg_quote", "(", "$", "this", "->", "get_field_prefix", "(", ")", ",", "'/'", ")", ".", "'[^-:]/'", ";", "$", "prefixlen", "=", "strlen", "(", "$", "this", "->", "get_field_prefix", "(", ")", ")", ";", "$", "submitteddata", "=", "array", "(", ")", ";", "foreach", "(", "$", "postdata", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "preg_match", "(", "$", "pattern", ",", "$", "name", ")", ")", "{", "$", "submitteddata", "[", "substr", "(", "$", "name", ",", "$", "prefixlen", ")", "]", "=", "$", "value", ";", "}", "}", "return", "$", "submitteddata", ";", "}" ]
Get all the submitted question type data for this question, whithout checking that it is valid or cleaning it in any way. @param null|array $postdata null to use real post data, otherwise an array of data to use. @return array name => value.
[ "Get", "all", "the", "submitted", "question", "type", "data", "for", "this", "question", "whithout", "checking", "that", "it", "is", "valid", "or", "cleaning", "it", "in", "any", "way", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L1172-L1188
216,245
moodle/moodle
question/engine/questionattempt.php
question_attempt.get_submitted_data
public function get_submitted_data($postdata = null) { $submitteddata = $this->get_expected_data( $this->behaviour->get_expected_data(), $postdata, '-'); $expected = $this->behaviour->get_expected_qt_data(); $this->check_qt_var_name_restrictions($expected); if ($expected === self::USE_RAW_DATA) { $submitteddata += $this->get_all_submitted_qt_vars($postdata); } else { $submitteddata += $this->get_expected_data($expected, $postdata, ''); } return $submitteddata; }
php
public function get_submitted_data($postdata = null) { $submitteddata = $this->get_expected_data( $this->behaviour->get_expected_data(), $postdata, '-'); $expected = $this->behaviour->get_expected_qt_data(); $this->check_qt_var_name_restrictions($expected); if ($expected === self::USE_RAW_DATA) { $submitteddata += $this->get_all_submitted_qt_vars($postdata); } else { $submitteddata += $this->get_expected_data($expected, $postdata, ''); } return $submitteddata; }
[ "public", "function", "get_submitted_data", "(", "$", "postdata", "=", "null", ")", "{", "$", "submitteddata", "=", "$", "this", "->", "get_expected_data", "(", "$", "this", "->", "behaviour", "->", "get_expected_data", "(", ")", ",", "$", "postdata", ",", "'-'", ")", ";", "$", "expected", "=", "$", "this", "->", "behaviour", "->", "get_expected_qt_data", "(", ")", ";", "$", "this", "->", "check_qt_var_name_restrictions", "(", "$", "expected", ")", ";", "if", "(", "$", "expected", "===", "self", "::", "USE_RAW_DATA", ")", "{", "$", "submitteddata", "+=", "$", "this", "->", "get_all_submitted_qt_vars", "(", "$", "postdata", ")", ";", "}", "else", "{", "$", "submitteddata", "+=", "$", "this", "->", "get_expected_data", "(", "$", "expected", ",", "$", "postdata", ",", "''", ")", ";", "}", "return", "$", "submitteddata", ";", "}" ]
Get all the sumbitted data belonging to this question attempt from the current request. @param array $postdata (optional, only inteded for testing use) take the data from this array, instead of from $_POST. @return array name => value pairs that could be passed to {@link process_action()}.
[ "Get", "all", "the", "sumbitted", "data", "belonging", "to", "this", "question", "attempt", "from", "the", "current", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L1197-L1210
216,246
moodle/moodle
question/engine/questionattempt.php
question_attempt.check_qt_var_name_restrictions
protected function check_qt_var_name_restrictions($expected) { global $CFG; if ($CFG->debugdeveloper && $expected !== self::USE_RAW_DATA) { foreach ($expected as $key => $value) { if (strpos($key, 'bf_') !== false) { debugging('The bf_ prefix is reserved and cannot be used by question types', DEBUG_DEVELOPER); } } } }
php
protected function check_qt_var_name_restrictions($expected) { global $CFG; if ($CFG->debugdeveloper && $expected !== self::USE_RAW_DATA) { foreach ($expected as $key => $value) { if (strpos($key, 'bf_') !== false) { debugging('The bf_ prefix is reserved and cannot be used by question types', DEBUG_DEVELOPER); } } } }
[ "protected", "function", "check_qt_var_name_restrictions", "(", "$", "expected", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "CFG", "->", "debugdeveloper", "&&", "$", "expected", "!==", "self", "::", "USE_RAW_DATA", ")", "{", "foreach", "(", "$", "expected", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "strpos", "(", "$", "key", ",", "'bf_'", ")", "!==", "false", ")", "{", "debugging", "(", "'The bf_ prefix is reserved and cannot be used by question types'", ",", "DEBUG_DEVELOPER", ")", ";", "}", "}", "}", "}" ]
Ensure that no reserved prefixes are being used by installed question types. @param array $expected An array of question type variables
[ "Ensure", "that", "no", "reserved", "prefixes", "are", "being", "used", "by", "installed", "question", "types", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L1217-L1227
216,247
moodle/moodle
question/engine/questionattempt.php
question_attempt.get_correct_response
public function get_correct_response() { $response = $this->question->get_correct_response(); if (is_null($response)) { return null; } $imvars = $this->behaviour->get_correct_response(); foreach ($imvars as $name => $value) { $response['-' . $name] = $value; } return $response; }
php
public function get_correct_response() { $response = $this->question->get_correct_response(); if (is_null($response)) { return null; } $imvars = $this->behaviour->get_correct_response(); foreach ($imvars as $name => $value) { $response['-' . $name] = $value; } return $response; }
[ "public", "function", "get_correct_response", "(", ")", "{", "$", "response", "=", "$", "this", "->", "question", "->", "get_correct_response", "(", ")", ";", "if", "(", "is_null", "(", "$", "response", ")", ")", "{", "return", "null", ";", "}", "$", "imvars", "=", "$", "this", "->", "behaviour", "->", "get_correct_response", "(", ")", ";", "foreach", "(", "$", "imvars", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "response", "[", "'-'", ".", "$", "name", "]", "=", "$", "value", ";", "}", "return", "$", "response", ";", "}" ]
Get a set of response data for this question attempt that would get the best possible mark. If it is not possible to compute a correct response, this method should return null. @return array|null name => value pairs that could be passed to {@link process_action()}.
[ "Get", "a", "set", "of", "response", "data", "for", "this", "question", "attempt", "that", "would", "get", "the", "best", "possible", "mark", ".", "If", "it", "is", "not", "possible", "to", "compute", "a", "correct", "response", "this", "method", "should", "return", "null", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L1235-L1245
216,248
moodle/moodle
question/engine/questionattempt.php
question_attempt.process_autosave
public function process_autosave($submitteddata, $timestamp = null, $userid = null) { $pendingstep = new question_attempt_pending_step($submitteddata, $timestamp, $userid); if ($this->behaviour->process_autosave($pendingstep) == self::KEEP) { $this->add_autosaved_step($pendingstep); return true; } return false; }
php
public function process_autosave($submitteddata, $timestamp = null, $userid = null) { $pendingstep = new question_attempt_pending_step($submitteddata, $timestamp, $userid); if ($this->behaviour->process_autosave($pendingstep) == self::KEEP) { $this->add_autosaved_step($pendingstep); return true; } return false; }
[ "public", "function", "process_autosave", "(", "$", "submitteddata", ",", "$", "timestamp", "=", "null", ",", "$", "userid", "=", "null", ")", "{", "$", "pendingstep", "=", "new", "question_attempt_pending_step", "(", "$", "submitteddata", ",", "$", "timestamp", ",", "$", "userid", ")", ";", "if", "(", "$", "this", "->", "behaviour", "->", "process_autosave", "(", "$", "pendingstep", ")", "==", "self", "::", "KEEP", ")", "{", "$", "this", "->", "add_autosaved_step", "(", "$", "pendingstep", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Process an autosave. @param array $submitteddata the submitted data the determines the action. @param int $timestamp the time to record for the action. (If not given, use now.) @param int $userid the user to attribute the action to. (If not given, use the current user.) @return bool whether anything was saved.
[ "Process", "an", "autosave", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L1317-L1324
216,249
moodle/moodle
question/engine/questionattempt.php
question_attempt.finish
public function finish($timestamp = null, $userid = null) { $this->convert_autosaved_step_to_real_step(); $this->process_action(array('-finish' => 1), $timestamp, $userid); }
php
public function finish($timestamp = null, $userid = null) { $this->convert_autosaved_step_to_real_step(); $this->process_action(array('-finish' => 1), $timestamp, $userid); }
[ "public", "function", "finish", "(", "$", "timestamp", "=", "null", ",", "$", "userid", "=", "null", ")", "{", "$", "this", "->", "convert_autosaved_step_to_real_step", "(", ")", ";", "$", "this", "->", "process_action", "(", "array", "(", "'-finish'", "=>", "1", ")", ",", "$", "timestamp", ",", "$", "userid", ")", ";", "}" ]
Perform a finish action on this question attempt. This corresponds to an external finish action, for example the user pressing Submit all and finish in the quiz, rather than using one of the controls that is part of the question. @param int $timestamp the time to record for the action. (If not given, use now.) @param int $userid the user to attribute the aciton to. (If not given, use the current user.)
[ "Perform", "a", "finish", "action", "on", "this", "question", "attempt", ".", "This", "corresponds", "to", "an", "external", "finish", "action", "for", "example", "the", "user", "pressing", "Submit", "all", "and", "finish", "in", "the", "quiz", "rather", "than", "using", "one", "of", "the", "controls", "that", "is", "part", "of", "the", "question", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L1335-L1338
216,250
moodle/moodle
question/engine/questionattempt.php
question_attempt.manual_grade
public function manual_grade($comment, $mark, $commentformat = null, $timestamp = null, $userid = null) { $submitteddata = array('-comment' => $comment); if (is_null($commentformat)) { debugging('You should pass $commentformat to manual_grade.', DEBUG_DEVELOPER); $commentformat = FORMAT_HTML; } $submitteddata['-commentformat'] = $commentformat; if (!is_null($mark)) { $submitteddata['-mark'] = $mark; $submitteddata['-maxmark'] = $this->maxmark; } $this->process_action($submitteddata, $timestamp, $userid); }
php
public function manual_grade($comment, $mark, $commentformat = null, $timestamp = null, $userid = null) { $submitteddata = array('-comment' => $comment); if (is_null($commentformat)) { debugging('You should pass $commentformat to manual_grade.', DEBUG_DEVELOPER); $commentformat = FORMAT_HTML; } $submitteddata['-commentformat'] = $commentformat; if (!is_null($mark)) { $submitteddata['-mark'] = $mark; $submitteddata['-maxmark'] = $this->maxmark; } $this->process_action($submitteddata, $timestamp, $userid); }
[ "public", "function", "manual_grade", "(", "$", "comment", ",", "$", "mark", ",", "$", "commentformat", "=", "null", ",", "$", "timestamp", "=", "null", ",", "$", "userid", "=", "null", ")", "{", "$", "submitteddata", "=", "array", "(", "'-comment'", "=>", "$", "comment", ")", ";", "if", "(", "is_null", "(", "$", "commentformat", ")", ")", "{", "debugging", "(", "'You should pass $commentformat to manual_grade.'", ",", "DEBUG_DEVELOPER", ")", ";", "$", "commentformat", "=", "FORMAT_HTML", ";", "}", "$", "submitteddata", "[", "'-commentformat'", "]", "=", "$", "commentformat", ";", "if", "(", "!", "is_null", "(", "$", "mark", ")", ")", "{", "$", "submitteddata", "[", "'-mark'", "]", "=", "$", "mark", ";", "$", "submitteddata", "[", "'-maxmark'", "]", "=", "$", "this", "->", "maxmark", ";", "}", "$", "this", "->", "process_action", "(", "$", "submitteddata", ",", "$", "timestamp", ",", "$", "userid", ")", ";", "}" ]
Perform a manual grading action on this attempt. @param string $comment the comment being added. @param float $mark the new mark. If null, then only a comment is added. @param int $commentformat the FORMAT_... for $comment. Must be given. @param int $timestamp the time to record for the action. (If not given, use now.) @param int $userid the user to attribute the aciton to. (If not given, use the current user.)
[ "Perform", "a", "manual", "grading", "action", "on", "this", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L1401-L1413
216,251
moodle/moodle
question/engine/questionattempt.php
question_attempt.get_current_manual_comment
public function get_current_manual_comment() { $comment = $this->get_submitted_var($this->get_behaviour_field_name('comment'), PARAM_RAW); if (is_null($comment)) { return $this->get_manual_comment(); } else { $commentformat = $this->get_submitted_var( $this->get_behaviour_field_name('commentformat'), PARAM_INT); if ($commentformat === null) { $commentformat = FORMAT_HTML; } return array($comment, $commentformat, null); } }
php
public function get_current_manual_comment() { $comment = $this->get_submitted_var($this->get_behaviour_field_name('comment'), PARAM_RAW); if (is_null($comment)) { return $this->get_manual_comment(); } else { $commentformat = $this->get_submitted_var( $this->get_behaviour_field_name('commentformat'), PARAM_INT); if ($commentformat === null) { $commentformat = FORMAT_HTML; } return array($comment, $commentformat, null); } }
[ "public", "function", "get_current_manual_comment", "(", ")", "{", "$", "comment", "=", "$", "this", "->", "get_submitted_var", "(", "$", "this", "->", "get_behaviour_field_name", "(", "'comment'", ")", ",", "PARAM_RAW", ")", ";", "if", "(", "is_null", "(", "$", "comment", ")", ")", "{", "return", "$", "this", "->", "get_manual_comment", "(", ")", ";", "}", "else", "{", "$", "commentformat", "=", "$", "this", "->", "get_submitted_var", "(", "$", "this", "->", "get_behaviour_field_name", "(", "'commentformat'", ")", ",", "PARAM_INT", ")", ";", "if", "(", "$", "commentformat", "===", "null", ")", "{", "$", "commentformat", "=", "FORMAT_HTML", ";", "}", "return", "array", "(", "$", "comment", ",", "$", "commentformat", ",", "null", ")", ";", "}", "}" ]
This is used by the manual grading code, particularly in association with validation. If there is a comment submitted in the request, then use that, otherwise use the latest comment for this question. @return array with three elements, comment, commentformat and mark.
[ "This", "is", "used", "by", "the", "manual", "grading", "code", "particularly", "in", "association", "with", "validation", ".", "If", "there", "is", "a", "comment", "submitted", "in", "the", "request", "then", "use", "that", "otherwise", "use", "the", "latest", "comment", "for", "this", "question", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L1447-L1459
216,252
moodle/moodle
question/engine/questionattempt.php
question_attempt_steps_with_submitted_response_iterator.find_steps_with_submitted_response
protected function find_steps_with_submitted_response() { $stepnos = array(); $lastsavedstep = null; foreach ($this->qa->get_step_iterator() as $stepno => $step) { if ($this->qa->get_behaviour()->step_has_a_submitted_response($step)) { $stepnos[] = $stepno; $lastsavedstep = null; } else { $qtdata = $step->get_qt_data(); if (count($qtdata)) { $lastsavedstep = $stepno; } } } if (!is_null($lastsavedstep)) { $stepnos[] = $lastsavedstep; } if (empty($stepnos)) { $this->stepswithsubmittedresponses = array(); } else { // Re-index array so index starts with 1. $this->stepswithsubmittedresponses = array_combine(range(1, count($stepnos)), $stepnos); } }
php
protected function find_steps_with_submitted_response() { $stepnos = array(); $lastsavedstep = null; foreach ($this->qa->get_step_iterator() as $stepno => $step) { if ($this->qa->get_behaviour()->step_has_a_submitted_response($step)) { $stepnos[] = $stepno; $lastsavedstep = null; } else { $qtdata = $step->get_qt_data(); if (count($qtdata)) { $lastsavedstep = $stepno; } } } if (!is_null($lastsavedstep)) { $stepnos[] = $lastsavedstep; } if (empty($stepnos)) { $this->stepswithsubmittedresponses = array(); } else { // Re-index array so index starts with 1. $this->stepswithsubmittedresponses = array_combine(range(1, count($stepnos)), $stepnos); } }
[ "protected", "function", "find_steps_with_submitted_response", "(", ")", "{", "$", "stepnos", "=", "array", "(", ")", ";", "$", "lastsavedstep", "=", "null", ";", "foreach", "(", "$", "this", "->", "qa", "->", "get_step_iterator", "(", ")", "as", "$", "stepno", "=>", "$", "step", ")", "{", "if", "(", "$", "this", "->", "qa", "->", "get_behaviour", "(", ")", "->", "step_has_a_submitted_response", "(", "$", "step", ")", ")", "{", "$", "stepnos", "[", "]", "=", "$", "stepno", ";", "$", "lastsavedstep", "=", "null", ";", "}", "else", "{", "$", "qtdata", "=", "$", "step", "->", "get_qt_data", "(", ")", ";", "if", "(", "count", "(", "$", "qtdata", ")", ")", "{", "$", "lastsavedstep", "=", "$", "stepno", ";", "}", "}", "}", "if", "(", "!", "is_null", "(", "$", "lastsavedstep", ")", ")", "{", "$", "stepnos", "[", "]", "=", "$", "lastsavedstep", ";", "}", "if", "(", "empty", "(", "$", "stepnos", ")", ")", "{", "$", "this", "->", "stepswithsubmittedresponses", "=", "array", "(", ")", ";", "}", "else", "{", "// Re-index array so index starts with 1.", "$", "this", "->", "stepswithsubmittedresponses", "=", "array_combine", "(", "range", "(", "1", ",", "count", "(", "$", "stepnos", ")", ")", ",", "$", "stepnos", ")", ";", "}", "}" ]
Find the step nos in which a student has submitted a response. Including any step with a response that is saved before the question attempt finishes. Called from constructor, should not be called from elsewhere.
[ "Find", "the", "step", "nos", "in", "which", "a", "student", "has", "submitted", "a", "response", ".", "Including", "any", "step", "with", "a", "response", "that", "is", "saved", "before", "the", "question", "attempt", "finishes", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/questionattempt.php#L1792-L1816
216,253
moodle/moodle
lib/phpexcel/PHPExcel/Chart.php
PHPExcel_Chart.setTopLeftPosition
public function setTopLeftPosition($cell, $xOffset = null, $yOffset = null) { $this->topLeftCellRef = $cell; if (!is_null($xOffset)) { $this->setTopLeftXOffset($xOffset); } if (!is_null($yOffset)) { $this->setTopLeftYOffset($yOffset); } return $this; }
php
public function setTopLeftPosition($cell, $xOffset = null, $yOffset = null) { $this->topLeftCellRef = $cell; if (!is_null($xOffset)) { $this->setTopLeftXOffset($xOffset); } if (!is_null($yOffset)) { $this->setTopLeftYOffset($yOffset); } return $this; }
[ "public", "function", "setTopLeftPosition", "(", "$", "cell", ",", "$", "xOffset", "=", "null", ",", "$", "yOffset", "=", "null", ")", "{", "$", "this", "->", "topLeftCellRef", "=", "$", "cell", ";", "if", "(", "!", "is_null", "(", "$", "xOffset", ")", ")", "{", "$", "this", "->", "setTopLeftXOffset", "(", "$", "xOffset", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "yOffset", ")", ")", "{", "$", "this", "->", "setTopLeftYOffset", "(", "$", "yOffset", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the Top Left position for the chart @param string $cell @param integer $xOffset @param integer $yOffset @return PHPExcel_Chart
[ "Set", "the", "Top", "Left", "position", "for", "the", "chart" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Chart.php#L434-L445
216,254
moodle/moodle
lib/phpexcel/PHPExcel/Chart.php
PHPExcel_Chart.setTopLeftOffset
public function setTopLeftOffset($xOffset = null, $yOffset = null) { if (!is_null($xOffset)) { $this->setTopLeftXOffset($xOffset); } if (!is_null($yOffset)) { $this->setTopLeftYOffset($yOffset); } return $this; }
php
public function setTopLeftOffset($xOffset = null, $yOffset = null) { if (!is_null($xOffset)) { $this->setTopLeftXOffset($xOffset); } if (!is_null($yOffset)) { $this->setTopLeftYOffset($yOffset); } return $this; }
[ "public", "function", "setTopLeftOffset", "(", "$", "xOffset", "=", "null", ",", "$", "yOffset", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "xOffset", ")", ")", "{", "$", "this", "->", "setTopLeftXOffset", "(", "$", "xOffset", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "yOffset", ")", ")", "{", "$", "this", "->", "setTopLeftYOffset", "(", "$", "yOffset", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the offset position within the Top Left cell for the chart @param integer $xOffset @param integer $yOffset @return PHPExcel_Chart
[ "Set", "the", "offset", "position", "within", "the", "Top", "Left", "cell", "for", "the", "chart" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Chart.php#L491-L501
216,255
moodle/moodle
lib/phpexcel/PHPExcel/Chart.php
PHPExcel_Chart.setBottomRightOffset
public function setBottomRightOffset($xOffset = null, $yOffset = null) { if (!is_null($xOffset)) { $this->setBottomRightXOffset($xOffset); } if (!is_null($yOffset)) { $this->setBottomRightYOffset($yOffset); } return $this; }
php
public function setBottomRightOffset($xOffset = null, $yOffset = null) { if (!is_null($xOffset)) { $this->setBottomRightXOffset($xOffset); } if (!is_null($yOffset)) { $this->setBottomRightYOffset($yOffset); } return $this; }
[ "public", "function", "setBottomRightOffset", "(", "$", "xOffset", "=", "null", ",", "$", "yOffset", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "xOffset", ")", ")", "{", "$", "this", "->", "setBottomRightXOffset", "(", "$", "xOffset", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "yOffset", ")", ")", "{", "$", "this", "->", "setBottomRightYOffset", "(", "$", "yOffset", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the offset position within the Bottom Right cell for the chart @param integer $xOffset @param integer $yOffset @return PHPExcel_Chart
[ "Set", "the", "offset", "position", "within", "the", "Bottom", "Right", "cell", "for", "the", "chart" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Chart.php#L599-L609
216,256
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Mailbox/List.php
Horde_Imap_Client_Mailbox_List.sort
public function sort(array $opts = array()) { $this->_delimiter = isset($opts['delimiter']) ? $opts['delimiter'] : '.'; $this->_sortinbox = (!isset($opts['inbox']) || !empty($opts['inbox'])); if (empty($opts['noupdate'])) { $mboxes = &$this->_mboxes; } else { $mboxes = $this->_mboxes; } uasort($mboxes, array($this, '_mboxCompare')); return $mboxes; }
php
public function sort(array $opts = array()) { $this->_delimiter = isset($opts['delimiter']) ? $opts['delimiter'] : '.'; $this->_sortinbox = (!isset($opts['inbox']) || !empty($opts['inbox'])); if (empty($opts['noupdate'])) { $mboxes = &$this->_mboxes; } else { $mboxes = $this->_mboxes; } uasort($mboxes, array($this, '_mboxCompare')); return $mboxes; }
[ "public", "function", "sort", "(", "array", "$", "opts", "=", "array", "(", ")", ")", "{", "$", "this", "->", "_delimiter", "=", "isset", "(", "$", "opts", "[", "'delimiter'", "]", ")", "?", "$", "opts", "[", "'delimiter'", "]", ":", "'.'", ";", "$", "this", "->", "_sortinbox", "=", "(", "!", "isset", "(", "$", "opts", "[", "'inbox'", "]", ")", "||", "!", "empty", "(", "$", "opts", "[", "'inbox'", "]", ")", ")", ";", "if", "(", "empty", "(", "$", "opts", "[", "'noupdate'", "]", ")", ")", "{", "$", "mboxes", "=", "&", "$", "this", "->", "_mboxes", ";", "}", "else", "{", "$", "mboxes", "=", "$", "this", "->", "_mboxes", ";", "}", "uasort", "(", "$", "mboxes", ",", "array", "(", "$", "this", ",", "'_mboxCompare'", ")", ")", ";", "return", "$", "mboxes", ";", "}" ]
Sort the list of mailboxes. @param array $opts Options: - delimiter: (string) The delimiter to use. DEFAULT: '.' - inbox: (boolean) Always put INBOX at the head of the list? DEFAULT: Yes - noupdate: (boolean) Do not update the object's mailbox list? DEFAULT: true @return array List of sorted mailboxes (index association is kept).
[ "Sort", "the", "list", "of", "mailboxes", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Mailbox/List.php#L71-L87
216,257
moodle/moodle
mod/quiz/classes/privacy/helper.php
helper.get_quiz_attempt_subcontext
public static function get_quiz_attempt_subcontext(\stdClass $attempt, \stdClass $user) { $subcontext = [ get_string('attempts', 'mod_quiz'), ]; if ($attempt->userid != $user->id) { $subcontext[] = fullname($user); } $subcontext[] = $attempt->attempt; return $subcontext; }
php
public static function get_quiz_attempt_subcontext(\stdClass $attempt, \stdClass $user) { $subcontext = [ get_string('attempts', 'mod_quiz'), ]; if ($attempt->userid != $user->id) { $subcontext[] = fullname($user); } $subcontext[] = $attempt->attempt; return $subcontext; }
[ "public", "static", "function", "get_quiz_attempt_subcontext", "(", "\\", "stdClass", "$", "attempt", ",", "\\", "stdClass", "$", "user", ")", "{", "$", "subcontext", "=", "[", "get_string", "(", "'attempts'", ",", "'mod_quiz'", ")", ",", "]", ";", "if", "(", "$", "attempt", "->", "userid", "!=", "$", "user", "->", "id", ")", "{", "$", "subcontext", "[", "]", "=", "fullname", "(", "$", "user", ")", ";", "}", "$", "subcontext", "[", "]", "=", "$", "attempt", "->", "attempt", ";", "return", "$", "subcontext", ";", "}" ]
Determine the subcontext for the specified quiz attempt. @param \stdClass $attempt The attempt data retrieved from the database. @param \stdClass $user The user record. @return \array The calculated subcontext.
[ "Determine", "the", "subcontext", "for", "the", "specified", "quiz", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/privacy/helper.php#L54-L64
216,258
moodle/moodle
question/type/multichoice/questiontype.php
qtype_multichoice.create_default_options
protected function create_default_options($question) { // Create a default question options record. $options = new stdClass(); $options->questionid = $question->id; // Get the default strings and just set the format. $options->correctfeedback = get_string('correctfeedbackdefault', 'question'); $options->correctfeedbackformat = FORMAT_HTML; $options->partiallycorrectfeedback = get_string('partiallycorrectfeedbackdefault', 'question');; $options->partiallycorrectfeedbackformat = FORMAT_HTML; $options->incorrectfeedback = get_string('incorrectfeedbackdefault', 'question'); $options->incorrectfeedbackformat = FORMAT_HTML; $config = get_config('qtype_multichoice'); $options->single = $config->answerhowmany; if (isset($question->layout)) { $options->layout = $question->layout; } $options->answernumbering = $config->answernumbering; $options->shuffleanswers = $config->shuffleanswers; $options->shownumcorrect = 1; return $options; }
php
protected function create_default_options($question) { // Create a default question options record. $options = new stdClass(); $options->questionid = $question->id; // Get the default strings and just set the format. $options->correctfeedback = get_string('correctfeedbackdefault', 'question'); $options->correctfeedbackformat = FORMAT_HTML; $options->partiallycorrectfeedback = get_string('partiallycorrectfeedbackdefault', 'question');; $options->partiallycorrectfeedbackformat = FORMAT_HTML; $options->incorrectfeedback = get_string('incorrectfeedbackdefault', 'question'); $options->incorrectfeedbackformat = FORMAT_HTML; $config = get_config('qtype_multichoice'); $options->single = $config->answerhowmany; if (isset($question->layout)) { $options->layout = $question->layout; } $options->answernumbering = $config->answernumbering; $options->shuffleanswers = $config->shuffleanswers; $options->shownumcorrect = 1; return $options; }
[ "protected", "function", "create_default_options", "(", "$", "question", ")", "{", "// Create a default question options record.", "$", "options", "=", "new", "stdClass", "(", ")", ";", "$", "options", "->", "questionid", "=", "$", "question", "->", "id", ";", "// Get the default strings and just set the format.", "$", "options", "->", "correctfeedback", "=", "get_string", "(", "'correctfeedbackdefault'", ",", "'question'", ")", ";", "$", "options", "->", "correctfeedbackformat", "=", "FORMAT_HTML", ";", "$", "options", "->", "partiallycorrectfeedback", "=", "get_string", "(", "'partiallycorrectfeedbackdefault'", ",", "'question'", ")", ";", ";", "$", "options", "->", "partiallycorrectfeedbackformat", "=", "FORMAT_HTML", ";", "$", "options", "->", "incorrectfeedback", "=", "get_string", "(", "'incorrectfeedbackdefault'", ",", "'question'", ")", ";", "$", "options", "->", "incorrectfeedbackformat", "=", "FORMAT_HTML", ";", "$", "config", "=", "get_config", "(", "'qtype_multichoice'", ")", ";", "$", "options", "->", "single", "=", "$", "config", "->", "answerhowmany", ";", "if", "(", "isset", "(", "$", "question", "->", "layout", ")", ")", "{", "$", "options", "->", "layout", "=", "$", "question", "->", "layout", ";", "}", "$", "options", "->", "answernumbering", "=", "$", "config", "->", "answernumbering", ";", "$", "options", "->", "shuffleanswers", "=", "$", "config", "->", "shuffleanswers", ";", "$", "options", "->", "shownumcorrect", "=", "1", ";", "return", "$", "options", ";", "}" ]
Create a default options object for the provided question. @param object $question The queston we are working with. @return object The options object.
[ "Create", "a", "default", "options", "object", "for", "the", "provided", "question", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/multichoice/questiontype.php#L62-L85
216,259
moodle/moodle
analytics/classes/local/indicator/linear.php
linear.to_features
protected function to_features($calculatedvalues) { // Null mean if all calculated values are null. $nullmean = true; foreach ($calculatedvalues as $value) { if (!is_null($value)) { // Early break, we don't want to spend a lot of time here. $nullmean = false; break; } } if ($nullmean) { $mean = null; } else { $mean = round(array_sum($calculatedvalues) / count($calculatedvalues), 2); } foreach ($calculatedvalues as $sampleid => $calculatedvalue) { if (!is_null($calculatedvalue)) { $calculatedvalue = round($calculatedvalue, 2); } if (static::include_averages()) { $calculatedvalues[$sampleid] = array($calculatedvalue, $mean); } else { // Basically just convert the scalar to an array of scalars with a single value. $calculatedvalues[$sampleid] = array($calculatedvalue); } } // Returns each sample as an array of values, appending the mean to the calculated value. return $calculatedvalues; }
php
protected function to_features($calculatedvalues) { // Null mean if all calculated values are null. $nullmean = true; foreach ($calculatedvalues as $value) { if (!is_null($value)) { // Early break, we don't want to spend a lot of time here. $nullmean = false; break; } } if ($nullmean) { $mean = null; } else { $mean = round(array_sum($calculatedvalues) / count($calculatedvalues), 2); } foreach ($calculatedvalues as $sampleid => $calculatedvalue) { if (!is_null($calculatedvalue)) { $calculatedvalue = round($calculatedvalue, 2); } if (static::include_averages()) { $calculatedvalues[$sampleid] = array($calculatedvalue, $mean); } else { // Basically just convert the scalar to an array of scalars with a single value. $calculatedvalues[$sampleid] = array($calculatedvalue); } } // Returns each sample as an array of values, appending the mean to the calculated value. return $calculatedvalues; }
[ "protected", "function", "to_features", "(", "$", "calculatedvalues", ")", "{", "// Null mean if all calculated values are null.", "$", "nullmean", "=", "true", ";", "foreach", "(", "$", "calculatedvalues", "as", "$", "value", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", ")", "{", "// Early break, we don't want to spend a lot of time here.", "$", "nullmean", "=", "false", ";", "break", ";", "}", "}", "if", "(", "$", "nullmean", ")", "{", "$", "mean", "=", "null", ";", "}", "else", "{", "$", "mean", "=", "round", "(", "array_sum", "(", "$", "calculatedvalues", ")", "/", "count", "(", "$", "calculatedvalues", ")", ",", "2", ")", ";", "}", "foreach", "(", "$", "calculatedvalues", "as", "$", "sampleid", "=>", "$", "calculatedvalue", ")", "{", "if", "(", "!", "is_null", "(", "$", "calculatedvalue", ")", ")", "{", "$", "calculatedvalue", "=", "round", "(", "$", "calculatedvalue", ",", "2", ")", ";", "}", "if", "(", "static", "::", "include_averages", "(", ")", ")", "{", "$", "calculatedvalues", "[", "$", "sampleid", "]", "=", "array", "(", "$", "calculatedvalue", ",", "$", "mean", ")", ";", "}", "else", "{", "// Basically just convert the scalar to an array of scalars with a single value.", "$", "calculatedvalues", "[", "$", "sampleid", "]", "=", "array", "(", "$", "calculatedvalue", ")", ";", "}", "}", "// Returns each sample as an array of values, appending the mean to the calculated value.", "return", "$", "calculatedvalues", ";", "}" ]
Converts the calculated values to a list of features for the dataset. @param array $calculatedvalues @return array
[ "Converts", "the", "calculated", "values", "to", "a", "list", "of", "features", "for", "the", "dataset", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/linear.php#L112-L146
216,260
moodle/moodle
lib/filterlib.php
filter_manager.instance
public static function instance() { global $CFG; if (is_null(self::$singletoninstance)) { if (!empty($CFG->perfdebug) and $CFG->perfdebug > 7) { self::$singletoninstance = new performance_measuring_filter_manager(); } else { self::$singletoninstance = new self(); } } return self::$singletoninstance; }
php
public static function instance() { global $CFG; if (is_null(self::$singletoninstance)) { if (!empty($CFG->perfdebug) and $CFG->perfdebug > 7) { self::$singletoninstance = new performance_measuring_filter_manager(); } else { self::$singletoninstance = new self(); } } return self::$singletoninstance; }
[ "public", "static", "function", "instance", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "is_null", "(", "self", "::", "$", "singletoninstance", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "CFG", "->", "perfdebug", ")", "and", "$", "CFG", "->", "perfdebug", ">", "7", ")", "{", "self", "::", "$", "singletoninstance", "=", "new", "performance_measuring_filter_manager", "(", ")", ";", "}", "else", "{", "self", "::", "$", "singletoninstance", "=", "new", "self", "(", ")", ";", "}", "}", "return", "self", "::", "$", "singletoninstance", ";", "}" ]
Factory method. Use this to get the filter manager. @return filter_manager the singleton instance.
[ "Factory", "method", ".", "Use", "this", "to", "get", "the", "filter", "manager", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filterlib.php#L85-L95
216,261
moodle/moodle
lib/filterlib.php
filter_manager.load_filters
protected function load_filters($context) { $filters = filter_get_active_in_context($context); $this->textfilters[$context->id] = array(); $this->stringfilters[$context->id] = array(); foreach ($filters as $filtername => $localconfig) { $filter = $this->make_filter_object($filtername, $context, $localconfig); if (is_null($filter)) { continue; } $this->textfilters[$context->id][$filtername] = $filter; if (in_array($filtername, $this->stringfilternames)) { $this->stringfilters[$context->id][$filtername] = $filter; } } }
php
protected function load_filters($context) { $filters = filter_get_active_in_context($context); $this->textfilters[$context->id] = array(); $this->stringfilters[$context->id] = array(); foreach ($filters as $filtername => $localconfig) { $filter = $this->make_filter_object($filtername, $context, $localconfig); if (is_null($filter)) { continue; } $this->textfilters[$context->id][$filtername] = $filter; if (in_array($filtername, $this->stringfilternames)) { $this->stringfilters[$context->id][$filtername] = $filter; } } }
[ "protected", "function", "load_filters", "(", "$", "context", ")", "{", "$", "filters", "=", "filter_get_active_in_context", "(", "$", "context", ")", ";", "$", "this", "->", "textfilters", "[", "$", "context", "->", "id", "]", "=", "array", "(", ")", ";", "$", "this", "->", "stringfilters", "[", "$", "context", "->", "id", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "filters", "as", "$", "filtername", "=>", "$", "localconfig", ")", "{", "$", "filter", "=", "$", "this", "->", "make_filter_object", "(", "$", "filtername", ",", "$", "context", ",", "$", "localconfig", ")", ";", "if", "(", "is_null", "(", "$", "filter", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "textfilters", "[", "$", "context", "->", "id", "]", "[", "$", "filtername", "]", "=", "$", "filter", ";", "if", "(", "in_array", "(", "$", "filtername", ",", "$", "this", "->", "stringfilternames", ")", ")", "{", "$", "this", "->", "stringfilters", "[", "$", "context", "->", "id", "]", "[", "$", "filtername", "]", "=", "$", "filter", ";", "}", "}", "}" ]
Load all the filters required by this context. @param context $context the context.
[ "Load", "all", "the", "filters", "required", "by", "this", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filterlib.php#L121-L135
216,262
moodle/moodle
lib/filterlib.php
filter_manager.make_filter_object
protected function make_filter_object($filtername, $context, $localconfig) { global $CFG; $path = $CFG->dirroot .'/filter/'. $filtername .'/filter.php'; if (!is_readable($path)) { return null; } include_once($path); $filterclassname = 'filter_' . $filtername; if (class_exists($filterclassname)) { return new $filterclassname($context, $localconfig); } return null; }
php
protected function make_filter_object($filtername, $context, $localconfig) { global $CFG; $path = $CFG->dirroot .'/filter/'. $filtername .'/filter.php'; if (!is_readable($path)) { return null; } include_once($path); $filterclassname = 'filter_' . $filtername; if (class_exists($filterclassname)) { return new $filterclassname($context, $localconfig); } return null; }
[ "protected", "function", "make_filter_object", "(", "$", "filtername", ",", "$", "context", ",", "$", "localconfig", ")", "{", "global", "$", "CFG", ";", "$", "path", "=", "$", "CFG", "->", "dirroot", ".", "'/filter/'", ".", "$", "filtername", ".", "'/filter.php'", ";", "if", "(", "!", "is_readable", "(", "$", "path", ")", ")", "{", "return", "null", ";", "}", "include_once", "(", "$", "path", ")", ";", "$", "filterclassname", "=", "'filter_'", ".", "$", "filtername", ";", "if", "(", "class_exists", "(", "$", "filterclassname", ")", ")", "{", "return", "new", "$", "filterclassname", "(", "$", "context", ",", "$", "localconfig", ")", ";", "}", "return", "null", ";", "}" ]
Factory method for creating a filter. @param string $filtername The filter name, for example 'tex'. @param context $context context object. @param array $localconfig array of local configuration variables for this filter. @return moodle_text_filter The filter, or null, if this type of filter is not recognised or could not be created.
[ "Factory", "method", "for", "creating", "a", "filter", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filterlib.php#L146-L160
216,263
moodle/moodle
lib/filterlib.php
filter_manager.apply_filter_chain
protected function apply_filter_chain($text, $filterchain, array $options = array(), array $skipfilters = null) { foreach ($filterchain as $filtername => $filter) { if ($skipfilters !== null && in_array($filtername, $skipfilters)) { continue; } $text = $filter->filter($text, $options); } return $text; }
php
protected function apply_filter_chain($text, $filterchain, array $options = array(), array $skipfilters = null) { foreach ($filterchain as $filtername => $filter) { if ($skipfilters !== null && in_array($filtername, $skipfilters)) { continue; } $text = $filter->filter($text, $options); } return $text; }
[ "protected", "function", "apply_filter_chain", "(", "$", "text", ",", "$", "filterchain", ",", "array", "$", "options", "=", "array", "(", ")", ",", "array", "$", "skipfilters", "=", "null", ")", "{", "foreach", "(", "$", "filterchain", "as", "$", "filtername", "=>", "$", "filter", ")", "{", "if", "(", "$", "skipfilters", "!==", "null", "&&", "in_array", "(", "$", "filtername", ",", "$", "skipfilters", ")", ")", "{", "continue", ";", "}", "$", "text", "=", "$", "filter", "->", "filter", "(", "$", "text", ",", "$", "options", ")", ";", "}", "return", "$", "text", ";", "}" ]
Apply a list of filters to some content. @param string $text @param moodle_text_filter[] $filterchain array filter name => filter object. @param array $options options passed to the filters. @param array $skipfilters of filter names. Any filters that should not be applied to this text. @return string $text
[ "Apply", "a", "list", "of", "filters", "to", "some", "content", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filterlib.php#L170-L179
216,264
moodle/moodle
lib/filterlib.php
filter_manager.get_text_filters
protected function get_text_filters($context) { if (!isset($this->textfilters[$context->id])) { $this->load_filters($context); } return $this->textfilters[$context->id]; }
php
protected function get_text_filters($context) { if (!isset($this->textfilters[$context->id])) { $this->load_filters($context); } return $this->textfilters[$context->id]; }
[ "protected", "function", "get_text_filters", "(", "$", "context", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "textfilters", "[", "$", "context", "->", "id", "]", ")", ")", "{", "$", "this", "->", "load_filters", "(", "$", "context", ")", ";", "}", "return", "$", "this", "->", "textfilters", "[", "$", "context", "->", "id", "]", ";", "}" ]
Get all the filters that apply to a given context for calls to format_text. @param context $context @return moodle_text_filter[] A text filter
[ "Get", "all", "the", "filters", "that", "apply", "to", "a", "given", "context", "for", "calls", "to", "format_text", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filterlib.php#L187-L192
216,265
moodle/moodle
lib/filterlib.php
filter_manager.get_string_filters
protected function get_string_filters($context) { if (!isset($this->stringfilters[$context->id])) { $this->load_filters($context); } return $this->stringfilters[$context->id]; }
php
protected function get_string_filters($context) { if (!isset($this->stringfilters[$context->id])) { $this->load_filters($context); } return $this->stringfilters[$context->id]; }
[ "protected", "function", "get_string_filters", "(", "$", "context", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "stringfilters", "[", "$", "context", "->", "id", "]", ")", ")", "{", "$", "this", "->", "load_filters", "(", "$", "context", ")", ";", "}", "return", "$", "this", "->", "stringfilters", "[", "$", "context", "->", "id", "]", ";", "}" ]
Get all the filters that apply to a given context for calls to format_string. @param context $context the context. @return moodle_text_filter[] A text filter
[ "Get", "all", "the", "filters", "that", "apply", "to", "a", "given", "context", "for", "calls", "to", "format_string", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filterlib.php#L200-L205
216,266
moodle/moodle
lib/filterlib.php
filter_manager.filter_text
public function filter_text($text, $context, array $options = array(), array $skipfilters = null) { $text = $this->apply_filter_chain($text, $this->get_text_filters($context), $options, $skipfilters); // Remove <nolink> tags for XHTML compatibility. $text = str_replace(array('<nolink>', '</nolink>'), '', $text); return $text; }
php
public function filter_text($text, $context, array $options = array(), array $skipfilters = null) { $text = $this->apply_filter_chain($text, $this->get_text_filters($context), $options, $skipfilters); // Remove <nolink> tags for XHTML compatibility. $text = str_replace(array('<nolink>', '</nolink>'), '', $text); return $text; }
[ "public", "function", "filter_text", "(", "$", "text", ",", "$", "context", ",", "array", "$", "options", "=", "array", "(", ")", ",", "array", "$", "skipfilters", "=", "null", ")", "{", "$", "text", "=", "$", "this", "->", "apply_filter_chain", "(", "$", "text", ",", "$", "this", "->", "get_text_filters", "(", "$", "context", ")", ",", "$", "options", ",", "$", "skipfilters", ")", ";", "// Remove <nolink> tags for XHTML compatibility.", "$", "text", "=", "str_replace", "(", "array", "(", "'<nolink>'", ",", "'</nolink>'", ")", ",", "''", ",", "$", "text", ")", ";", "return", "$", "text", ";", "}" ]
Filter some text @param string $text The text to filter @param context $context the context. @param array $options options passed to the filters @param array $skipfilters of filter names. Any filters that should not be applied to this text. @return string resulting text
[ "Filter", "some", "text" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filterlib.php#L216-L222
216,267
moodle/moodle
lib/filterlib.php
filter_manager.setup_page_for_filters
public function setup_page_for_filters($page, $context) { $filters = $this->get_text_filters($context); foreach ($filters as $filter) { $filter->setup($page, $context); } }
php
public function setup_page_for_filters($page, $context) { $filters = $this->get_text_filters($context); foreach ($filters as $filter) { $filter->setup($page, $context); } }
[ "public", "function", "setup_page_for_filters", "(", "$", "page", ",", "$", "context", ")", "{", "$", "filters", "=", "$", "this", "->", "get_text_filters", "(", "$", "context", ")", ";", "foreach", "(", "$", "filters", "as", "$", "filter", ")", "{", "$", "filter", "->", "setup", "(", "$", "page", ",", "$", "context", ")", ";", "}", "}" ]
Setup page with filters requirements and other prepare stuff. This method is used by {@see format_text()} and {@see format_string()} in order to allow filters to setup any page requirement (js, css...) or perform any action needed to get them prepared before filtering itself happens by calling to each every active setup() method. Note it's executed for each piece of text filtered, so filter implementations are responsible of controlling the cardinality of the executions that may be different depending of the stuff to prepare. @param moodle_page $page the page we are going to add requirements to. @param context $context the context which contents are going to be filtered. @since Moodle 2.3
[ "Setup", "page", "with", "filters", "requirements", "and", "other", "prepare", "stuff", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filterlib.php#L258-L263
216,268
moodle/moodle
lib/filterlib.php
filter_manager.setup_page_for_globally_available_filters
public function setup_page_for_globally_available_filters($page) { $context = context_system::instance(); $filterdata = filter_get_globally_enabled_filters_with_config(); foreach ($filterdata as $name => $config) { if (isset($this->textfilters[$context->id][$name])) { $filter = $this->textfilters[$context->id][$name]; } else { $filter = $this->make_filter_object($name, $context, $config); if (is_null($filter)) { continue; } } $filter->setup($page, $context); } }
php
public function setup_page_for_globally_available_filters($page) { $context = context_system::instance(); $filterdata = filter_get_globally_enabled_filters_with_config(); foreach ($filterdata as $name => $config) { if (isset($this->textfilters[$context->id][$name])) { $filter = $this->textfilters[$context->id][$name]; } else { $filter = $this->make_filter_object($name, $context, $config); if (is_null($filter)) { continue; } } $filter->setup($page, $context); } }
[ "public", "function", "setup_page_for_globally_available_filters", "(", "$", "page", ")", "{", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "$", "filterdata", "=", "filter_get_globally_enabled_filters_with_config", "(", ")", ";", "foreach", "(", "$", "filterdata", "as", "$", "name", "=>", "$", "config", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "textfilters", "[", "$", "context", "->", "id", "]", "[", "$", "name", "]", ")", ")", "{", "$", "filter", "=", "$", "this", "->", "textfilters", "[", "$", "context", "->", "id", "]", "[", "$", "name", "]", ";", "}", "else", "{", "$", "filter", "=", "$", "this", "->", "make_filter_object", "(", "$", "name", ",", "$", "context", ",", "$", "config", ")", ";", "if", "(", "is_null", "(", "$", "filter", ")", ")", "{", "continue", ";", "}", "}", "$", "filter", "->", "setup", "(", "$", "page", ",", "$", "context", ")", ";", "}", "}" ]
Setup the page for globally available filters. This helps setting up the page for filters which may be applied to the page, even if they do not belong to the current context, or are not yet visible because the content is lazily added (ajax). This method always uses to the system context which determines the globally available filters. This should only ever be called once per request. @param moodle_page $page The page. @since Moodle 3.2
[ "Setup", "the", "page", "for", "globally", "available", "filters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filterlib.php#L279-L293
216,269
moodle/moodle
auth/cas/CAS/CAS/Request/CurlRequest.php
CAS_Request_CurlRequest.sendRequest
protected function sendRequest () { phpCAS::traceBegin(); /********************************************************* * initialize the CURL session *********************************************************/ $ch = $this->initAndConfigure(); /********************************************************* * Perform the query *********************************************************/ $buf = curl_exec($ch); if ( $buf === false ) { phpCAS::trace('curl_exec() failed'); $this->storeErrorMessage( 'CURL error #'.curl_errno($ch).': '.curl_error($ch) ); $res = false; } else { $this->storeResponseBody($buf); phpCAS::trace("Response Body: \n".$buf."\n"); $res = true; } // close the CURL session curl_close($ch); phpCAS::traceEnd($res); return $res; }
php
protected function sendRequest () { phpCAS::traceBegin(); /********************************************************* * initialize the CURL session *********************************************************/ $ch = $this->initAndConfigure(); /********************************************************* * Perform the query *********************************************************/ $buf = curl_exec($ch); if ( $buf === false ) { phpCAS::trace('curl_exec() failed'); $this->storeErrorMessage( 'CURL error #'.curl_errno($ch).': '.curl_error($ch) ); $res = false; } else { $this->storeResponseBody($buf); phpCAS::trace("Response Body: \n".$buf."\n"); $res = true; } // close the CURL session curl_close($ch); phpCAS::traceEnd($res); return $res; }
[ "protected", "function", "sendRequest", "(", ")", "{", "phpCAS", "::", "traceBegin", "(", ")", ";", "/*********************************************************\n * initialize the CURL session\n *********************************************************/", "$", "ch", "=", "$", "this", "->", "initAndConfigure", "(", ")", ";", "/*********************************************************\n * Perform the query\n *********************************************************/", "$", "buf", "=", "curl_exec", "(", "$", "ch", ")", ";", "if", "(", "$", "buf", "===", "false", ")", "{", "phpCAS", "::", "trace", "(", "'curl_exec() failed'", ")", ";", "$", "this", "->", "storeErrorMessage", "(", "'CURL error #'", ".", "curl_errno", "(", "$", "ch", ")", ".", "': '", ".", "curl_error", "(", "$", "ch", ")", ")", ";", "$", "res", "=", "false", ";", "}", "else", "{", "$", "this", "->", "storeResponseBody", "(", "$", "buf", ")", ";", "phpCAS", "::", "trace", "(", "\"Response Body: \\n\"", ".", "$", "buf", ".", "\"\\n\"", ")", ";", "$", "res", "=", "true", ";", "}", "// close the CURL session", "curl_close", "(", "$", "ch", ")", ";", "phpCAS", "::", "traceEnd", "(", "$", "res", ")", ";", "return", "$", "res", ";", "}" ]
Send the request and store the results. @return bool true on success, false on failure.
[ "Send", "the", "request", "and", "store", "the", "results", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Request/CurlRequest.php#L63-L93
216,270
moodle/moodle
auth/cas/CAS/CAS/Request/CurlRequest.php
CAS_Request_CurlRequest.initAndConfigure
public function initAndConfigure() { /********************************************************* * initialize the CURL session *********************************************************/ $ch = curl_init($this->url); if (version_compare(PHP_VERSION, '5.1.3', '>=')) { //only avaible in php5 curl_setopt_array($ch, $this->_curlOptions); } else { foreach ($this->_curlOptions as $key => $value) { curl_setopt($ch, $key, $value); } } /********************************************************* * Set SSL configuration *********************************************************/ if ($this->caCertPath) { if ($this->validateCN) { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); } else { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_CAINFO, $this->caCertPath); phpCAS::trace('CURL: Set CURLOPT_CAINFO ' . $this->caCertPath); } else { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); } /********************************************************* * Configure curl to capture our output. *********************************************************/ // return the CURL output into a variable curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // get the HTTP header with a callback curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, '_curlReadHeaders')); /********************************************************* * Add cookie headers to our request. *********************************************************/ if (count($this->cookies)) { $cookieStrings = array(); foreach ($this->cookies as $name => $val) { $cookieStrings[] = $name.'='.$val; } curl_setopt($ch, CURLOPT_COOKIE, implode(';', $cookieStrings)); } /********************************************************* * Add any additional headers *********************************************************/ if (count($this->headers)) { curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers); } /********************************************************* * Flag and Body for POST requests *********************************************************/ if ($this->isPost) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postBody); } return $ch; }
php
public function initAndConfigure() { /********************************************************* * initialize the CURL session *********************************************************/ $ch = curl_init($this->url); if (version_compare(PHP_VERSION, '5.1.3', '>=')) { //only avaible in php5 curl_setopt_array($ch, $this->_curlOptions); } else { foreach ($this->_curlOptions as $key => $value) { curl_setopt($ch, $key, $value); } } /********************************************************* * Set SSL configuration *********************************************************/ if ($this->caCertPath) { if ($this->validateCN) { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); } else { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_CAINFO, $this->caCertPath); phpCAS::trace('CURL: Set CURLOPT_CAINFO ' . $this->caCertPath); } else { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); } /********************************************************* * Configure curl to capture our output. *********************************************************/ // return the CURL output into a variable curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // get the HTTP header with a callback curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, '_curlReadHeaders')); /********************************************************* * Add cookie headers to our request. *********************************************************/ if (count($this->cookies)) { $cookieStrings = array(); foreach ($this->cookies as $name => $val) { $cookieStrings[] = $name.'='.$val; } curl_setopt($ch, CURLOPT_COOKIE, implode(';', $cookieStrings)); } /********************************************************* * Add any additional headers *********************************************************/ if (count($this->headers)) { curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers); } /********************************************************* * Flag and Body for POST requests *********************************************************/ if ($this->isPost) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postBody); } return $ch; }
[ "public", "function", "initAndConfigure", "(", ")", "{", "/*********************************************************\n * initialize the CURL session\n *********************************************************/", "$", "ch", "=", "curl_init", "(", "$", "this", "->", "url", ")", ";", "if", "(", "version_compare", "(", "PHP_VERSION", ",", "'5.1.3'", ",", "'>='", ")", ")", "{", "//only avaible in php5", "curl_setopt_array", "(", "$", "ch", ",", "$", "this", "->", "_curlOptions", ")", ";", "}", "else", "{", "foreach", "(", "$", "this", "->", "_curlOptions", "as", "$", "key", "=>", "$", "value", ")", "{", "curl_setopt", "(", "$", "ch", ",", "$", "key", ",", "$", "value", ")", ";", "}", "}", "/*********************************************************\n * Set SSL configuration\n *********************************************************/", "if", "(", "$", "this", "->", "caCertPath", ")", "{", "if", "(", "$", "this", "->", "validateCN", ")", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYHOST", ",", "2", ")", ";", "}", "else", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYHOST", ",", "0", ")", ";", "}", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYPEER", ",", "1", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_CAINFO", ",", "$", "this", "->", "caCertPath", ")", ";", "phpCAS", "::", "trace", "(", "'CURL: Set CURLOPT_CAINFO '", ".", "$", "this", "->", "caCertPath", ")", ";", "}", "else", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYPEER", ",", "0", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYHOST", ",", "0", ")", ";", "}", "/*********************************************************\n * Configure curl to capture our output.\n *********************************************************/", "// return the CURL output into a variable", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_RETURNTRANSFER", ",", "1", ")", ";", "// get the HTTP header with a callback", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_HEADERFUNCTION", ",", "array", "(", "$", "this", ",", "'_curlReadHeaders'", ")", ")", ";", "/*********************************************************\n * Add cookie headers to our request.\n *********************************************************/", "if", "(", "count", "(", "$", "this", "->", "cookies", ")", ")", "{", "$", "cookieStrings", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "cookies", "as", "$", "name", "=>", "$", "val", ")", "{", "$", "cookieStrings", "[", "]", "=", "$", "name", ".", "'='", ".", "$", "val", ";", "}", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_COOKIE", ",", "implode", "(", "';'", ",", "$", "cookieStrings", ")", ")", ";", "}", "/*********************************************************\n * Add any additional headers\n *********************************************************/", "if", "(", "count", "(", "$", "this", "->", "headers", ")", ")", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_HTTPHEADER", ",", "$", "this", "->", "headers", ")", ";", "}", "/*********************************************************\n * Flag and Body for POST requests\n *********************************************************/", "if", "(", "$", "this", "->", "isPost", ")", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POST", ",", "1", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POSTFIELDS", ",", "$", "this", "->", "postBody", ")", ";", "}", "return", "$", "ch", ";", "}" ]
Internal method to initialize our cURL handle and configure the request. This method should NOT be used outside of the CurlRequest or the CurlMultiRequest. @return resource The cURL handle on success, false on failure
[ "Internal", "method", "to", "initialize", "our", "cURL", "handle", "and", "configure", "the", "request", ".", "This", "method", "should", "NOT", "be", "used", "outside", "of", "the", "CurlRequest", "or", "the", "CurlMultiRequest", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Request/CurlRequest.php#L102-L171
216,271
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.output_individual_question_data
protected function output_individual_question_data($quiz, $questionstat) { global $OUTPUT; // On-screen display. Show a summary of the question's place in the quiz, // and the question statistics. $datumfromtable = $this->table->format_row($questionstat); // Set up the question info table. $questioninfotable = new html_table(); $questioninfotable->align = array('center', 'center'); $questioninfotable->width = '60%'; $questioninfotable->attributes['class'] = 'generaltable titlesleft'; $questioninfotable->data = array(); $questioninfotable->data[] = array(get_string('modulename', 'quiz'), $quiz->name); $questioninfotable->data[] = array(get_string('questionname', 'quiz_statistics'), $questionstat->question->name.'&nbsp;'.$datumfromtable['actions']); if ($questionstat->variant !== null) { $questioninfotable->data[] = array(get_string('variant', 'quiz_statistics'), $questionstat->variant); } $questioninfotable->data[] = array(get_string('questiontype', 'quiz_statistics'), $datumfromtable['icon'] . '&nbsp;' . question_bank::get_qtype($questionstat->question->qtype, false)->menu_name() . '&nbsp;' . $datumfromtable['icon']); $questioninfotable->data[] = array(get_string('positions', 'quiz_statistics'), $questionstat->positions); // Set up the question statistics table. $questionstatstable = new html_table(); $questionstatstable->align = array('center', 'center'); $questionstatstable->width = '60%'; $questionstatstable->attributes['class'] = 'generaltable titlesleft'; unset($datumfromtable['number']); unset($datumfromtable['icon']); $actions = $datumfromtable['actions']; unset($datumfromtable['actions']); unset($datumfromtable['name']); $labels = array( 's' => get_string('attempts', 'quiz_statistics'), 'facility' => get_string('facility', 'quiz_statistics'), 'sd' => get_string('standarddeviationq', 'quiz_statistics'), 'random_guess_score' => get_string('random_guess_score', 'quiz_statistics'), 'intended_weight' => get_string('intended_weight', 'quiz_statistics'), 'effective_weight' => get_string('effective_weight', 'quiz_statistics'), 'discrimination_index' => get_string('discrimination_index', 'quiz_statistics'), 'discriminative_efficiency' => get_string('discriminative_efficiency', 'quiz_statistics') ); foreach ($datumfromtable as $item => $value) { $questionstatstable->data[] = array($labels[$item], $value); } // Display the various bits. echo $OUTPUT->heading(get_string('questioninformation', 'quiz_statistics'), 3); echo html_writer::table($questioninfotable); echo $this->render_question_text($questionstat->question); echo $OUTPUT->heading(get_string('questionstatistics', 'quiz_statistics'), 3); echo html_writer::table($questionstatstable); }
php
protected function output_individual_question_data($quiz, $questionstat) { global $OUTPUT; // On-screen display. Show a summary of the question's place in the quiz, // and the question statistics. $datumfromtable = $this->table->format_row($questionstat); // Set up the question info table. $questioninfotable = new html_table(); $questioninfotable->align = array('center', 'center'); $questioninfotable->width = '60%'; $questioninfotable->attributes['class'] = 'generaltable titlesleft'; $questioninfotable->data = array(); $questioninfotable->data[] = array(get_string('modulename', 'quiz'), $quiz->name); $questioninfotable->data[] = array(get_string('questionname', 'quiz_statistics'), $questionstat->question->name.'&nbsp;'.$datumfromtable['actions']); if ($questionstat->variant !== null) { $questioninfotable->data[] = array(get_string('variant', 'quiz_statistics'), $questionstat->variant); } $questioninfotable->data[] = array(get_string('questiontype', 'quiz_statistics'), $datumfromtable['icon'] . '&nbsp;' . question_bank::get_qtype($questionstat->question->qtype, false)->menu_name() . '&nbsp;' . $datumfromtable['icon']); $questioninfotable->data[] = array(get_string('positions', 'quiz_statistics'), $questionstat->positions); // Set up the question statistics table. $questionstatstable = new html_table(); $questionstatstable->align = array('center', 'center'); $questionstatstable->width = '60%'; $questionstatstable->attributes['class'] = 'generaltable titlesleft'; unset($datumfromtable['number']); unset($datumfromtable['icon']); $actions = $datumfromtable['actions']; unset($datumfromtable['actions']); unset($datumfromtable['name']); $labels = array( 's' => get_string('attempts', 'quiz_statistics'), 'facility' => get_string('facility', 'quiz_statistics'), 'sd' => get_string('standarddeviationq', 'quiz_statistics'), 'random_guess_score' => get_string('random_guess_score', 'quiz_statistics'), 'intended_weight' => get_string('intended_weight', 'quiz_statistics'), 'effective_weight' => get_string('effective_weight', 'quiz_statistics'), 'discrimination_index' => get_string('discrimination_index', 'quiz_statistics'), 'discriminative_efficiency' => get_string('discriminative_efficiency', 'quiz_statistics') ); foreach ($datumfromtable as $item => $value) { $questionstatstable->data[] = array($labels[$item], $value); } // Display the various bits. echo $OUTPUT->heading(get_string('questioninformation', 'quiz_statistics'), 3); echo html_writer::table($questioninfotable); echo $this->render_question_text($questionstat->question); echo $OUTPUT->heading(get_string('questionstatistics', 'quiz_statistics'), 3); echo html_writer::table($questionstatstable); }
[ "protected", "function", "output_individual_question_data", "(", "$", "quiz", ",", "$", "questionstat", ")", "{", "global", "$", "OUTPUT", ";", "// On-screen display. Show a summary of the question's place in the quiz,", "// and the question statistics.", "$", "datumfromtable", "=", "$", "this", "->", "table", "->", "format_row", "(", "$", "questionstat", ")", ";", "// Set up the question info table.", "$", "questioninfotable", "=", "new", "html_table", "(", ")", ";", "$", "questioninfotable", "->", "align", "=", "array", "(", "'center'", ",", "'center'", ")", ";", "$", "questioninfotable", "->", "width", "=", "'60%'", ";", "$", "questioninfotable", "->", "attributes", "[", "'class'", "]", "=", "'generaltable titlesleft'", ";", "$", "questioninfotable", "->", "data", "=", "array", "(", ")", ";", "$", "questioninfotable", "->", "data", "[", "]", "=", "array", "(", "get_string", "(", "'modulename'", ",", "'quiz'", ")", ",", "$", "quiz", "->", "name", ")", ";", "$", "questioninfotable", "->", "data", "[", "]", "=", "array", "(", "get_string", "(", "'questionname'", ",", "'quiz_statistics'", ")", ",", "$", "questionstat", "->", "question", "->", "name", ".", "'&nbsp;'", ".", "$", "datumfromtable", "[", "'actions'", "]", ")", ";", "if", "(", "$", "questionstat", "->", "variant", "!==", "null", ")", "{", "$", "questioninfotable", "->", "data", "[", "]", "=", "array", "(", "get_string", "(", "'variant'", ",", "'quiz_statistics'", ")", ",", "$", "questionstat", "->", "variant", ")", ";", "}", "$", "questioninfotable", "->", "data", "[", "]", "=", "array", "(", "get_string", "(", "'questiontype'", ",", "'quiz_statistics'", ")", ",", "$", "datumfromtable", "[", "'icon'", "]", ".", "'&nbsp;'", ".", "question_bank", "::", "get_qtype", "(", "$", "questionstat", "->", "question", "->", "qtype", ",", "false", ")", "->", "menu_name", "(", ")", ".", "'&nbsp;'", ".", "$", "datumfromtable", "[", "'icon'", "]", ")", ";", "$", "questioninfotable", "->", "data", "[", "]", "=", "array", "(", "get_string", "(", "'positions'", ",", "'quiz_statistics'", ")", ",", "$", "questionstat", "->", "positions", ")", ";", "// Set up the question statistics table.", "$", "questionstatstable", "=", "new", "html_table", "(", ")", ";", "$", "questionstatstable", "->", "align", "=", "array", "(", "'center'", ",", "'center'", ")", ";", "$", "questionstatstable", "->", "width", "=", "'60%'", ";", "$", "questionstatstable", "->", "attributes", "[", "'class'", "]", "=", "'generaltable titlesleft'", ";", "unset", "(", "$", "datumfromtable", "[", "'number'", "]", ")", ";", "unset", "(", "$", "datumfromtable", "[", "'icon'", "]", ")", ";", "$", "actions", "=", "$", "datumfromtable", "[", "'actions'", "]", ";", "unset", "(", "$", "datumfromtable", "[", "'actions'", "]", ")", ";", "unset", "(", "$", "datumfromtable", "[", "'name'", "]", ")", ";", "$", "labels", "=", "array", "(", "'s'", "=>", "get_string", "(", "'attempts'", ",", "'quiz_statistics'", ")", ",", "'facility'", "=>", "get_string", "(", "'facility'", ",", "'quiz_statistics'", ")", ",", "'sd'", "=>", "get_string", "(", "'standarddeviationq'", ",", "'quiz_statistics'", ")", ",", "'random_guess_score'", "=>", "get_string", "(", "'random_guess_score'", ",", "'quiz_statistics'", ")", ",", "'intended_weight'", "=>", "get_string", "(", "'intended_weight'", ",", "'quiz_statistics'", ")", ",", "'effective_weight'", "=>", "get_string", "(", "'effective_weight'", ",", "'quiz_statistics'", ")", ",", "'discrimination_index'", "=>", "get_string", "(", "'discrimination_index'", ",", "'quiz_statistics'", ")", ",", "'discriminative_efficiency'", "=>", "get_string", "(", "'discriminative_efficiency'", ",", "'quiz_statistics'", ")", ")", ";", "foreach", "(", "$", "datumfromtable", "as", "$", "item", "=>", "$", "value", ")", "{", "$", "questionstatstable", "->", "data", "[", "]", "=", "array", "(", "$", "labels", "[", "$", "item", "]", ",", "$", "value", ")", ";", "}", "// Display the various bits.", "echo", "$", "OUTPUT", "->", "heading", "(", "get_string", "(", "'questioninformation'", ",", "'quiz_statistics'", ")", ",", "3", ")", ";", "echo", "html_writer", "::", "table", "(", "$", "questioninfotable", ")", ";", "echo", "$", "this", "->", "render_question_text", "(", "$", "questionstat", "->", "question", ")", ";", "echo", "$", "OUTPUT", "->", "heading", "(", "get_string", "(", "'questionstatistics'", ",", "'quiz_statistics'", ")", ",", "3", ")", ";", "echo", "html_writer", "::", "table", "(", "$", "questionstatstable", ")", ";", "}" ]
Display the statistical and introductory information about a question. Only called when not downloading. @param object $quiz the quiz settings. @param \core_question\statistics\questions\calculated $questionstat the question to report on.
[ "Display", "the", "statistical", "and", "introductory", "information", "about", "a", "question", ".", "Only", "called", "when", "not", "downloading", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L285-L346
216,272
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.render_question_text
protected function render_question_text($question) { global $OUTPUT; $text = question_rewrite_question_preview_urls($question->questiontext, $question->id, $question->contextid, 'question', 'questiontext', $question->id, $this->context->id, 'quiz_statistics'); return $OUTPUT->box(format_text($text, $question->questiontextformat, array('noclean' => true, 'para' => false, 'overflowdiv' => true)), 'questiontext boxaligncenter generalbox boxwidthnormal mdl-align'); }
php
protected function render_question_text($question) { global $OUTPUT; $text = question_rewrite_question_preview_urls($question->questiontext, $question->id, $question->contextid, 'question', 'questiontext', $question->id, $this->context->id, 'quiz_statistics'); return $OUTPUT->box(format_text($text, $question->questiontextformat, array('noclean' => true, 'para' => false, 'overflowdiv' => true)), 'questiontext boxaligncenter generalbox boxwidthnormal mdl-align'); }
[ "protected", "function", "render_question_text", "(", "$", "question", ")", "{", "global", "$", "OUTPUT", ";", "$", "text", "=", "question_rewrite_question_preview_urls", "(", "$", "question", "->", "questiontext", ",", "$", "question", "->", "id", ",", "$", "question", "->", "contextid", ",", "'question'", ",", "'questiontext'", ",", "$", "question", "->", "id", ",", "$", "this", "->", "context", "->", "id", ",", "'quiz_statistics'", ")", ";", "return", "$", "OUTPUT", "->", "box", "(", "format_text", "(", "$", "text", ",", "$", "question", "->", "questiontextformat", ",", "array", "(", "'noclean'", "=>", "true", ",", "'para'", "=>", "false", ",", "'overflowdiv'", "=>", "true", ")", ")", ",", "'questiontext boxaligncenter generalbox boxwidthnormal mdl-align'", ")", ";", "}" ]
Output question text in a box with urls appropriate for a preview of the question. @param object $question question data. @return string HTML of question text, ready for display.
[ "Output", "question", "text", "in", "a", "box", "with", "urls", "appropriate", "for", "a", "preview", "of", "the", "question", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L354-L364
216,273
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.output_individual_question_response_analysis
protected function output_individual_question_response_analysis($question, $variantno, $s, $reporturl, $qubaids, $whichtries = question_attempt::LAST_TRY) { global $OUTPUT; if (!question_bank::get_qtype($question->qtype, false)->can_analyse_responses()) { return; } $qtable = new quiz_statistics_question_table($question->id); $exportclass = $this->table->export_class_instance(); $qtable->export_class_instance($exportclass); if (!$this->table->is_downloading()) { // Output an appropriate title. echo $OUTPUT->heading(get_string('analysisofresponses', 'quiz_statistics'), 3); } else { // Work out an appropriate title. $a = clone($question); $a->variant = $variantno; if (!empty($question->number) && !is_null($variantno)) { $questiontabletitle = get_string('analysisnovariant', 'quiz_statistics', $a); } else if (!empty($question->number)) { $questiontabletitle = get_string('analysisno', 'quiz_statistics', $a); } else if (!is_null($variantno)) { $questiontabletitle = get_string('analysisvariant', 'quiz_statistics', $a); } else { $questiontabletitle = get_string('analysisnameonly', 'quiz_statistics', $a); } if ($this->table->is_downloading() == 'html') { $questiontabletitle = get_string('analysisofresponsesfor', 'quiz_statistics', $questiontabletitle); } // Set up the table. $exportclass->start_table($questiontabletitle); if ($this->table->is_downloading() == 'html') { echo $this->render_question_text($question); } } $responesanalyser = new \core_question\statistics\responses\analyser($question, $whichtries); $responseanalysis = $responesanalyser->load_cached($qubaids, $whichtries); $qtable->question_setup($reporturl, $question, $s, $responseanalysis); if ($this->table->is_downloading()) { $exportclass->output_headers($qtable->headers); } // Where no variant no is specified the variant no is actually one. if ($variantno === null) { $variantno = 1; } foreach ($responseanalysis->get_subpart_ids($variantno) as $partid) { $subpart = $responseanalysis->get_analysis_for_subpart($variantno, $partid); foreach ($subpart->get_response_class_ids() as $responseclassid) { $responseclass = $subpart->get_response_class($responseclassid); $tabledata = $responseclass->data_for_question_response_table($subpart->has_multiple_response_classes(), $partid); foreach ($tabledata as $row) { $qtable->add_data_keyed($qtable->format_row($row)); } } } $qtable->finish_output(!$this->table->is_downloading()); }
php
protected function output_individual_question_response_analysis($question, $variantno, $s, $reporturl, $qubaids, $whichtries = question_attempt::LAST_TRY) { global $OUTPUT; if (!question_bank::get_qtype($question->qtype, false)->can_analyse_responses()) { return; } $qtable = new quiz_statistics_question_table($question->id); $exportclass = $this->table->export_class_instance(); $qtable->export_class_instance($exportclass); if (!$this->table->is_downloading()) { // Output an appropriate title. echo $OUTPUT->heading(get_string('analysisofresponses', 'quiz_statistics'), 3); } else { // Work out an appropriate title. $a = clone($question); $a->variant = $variantno; if (!empty($question->number) && !is_null($variantno)) { $questiontabletitle = get_string('analysisnovariant', 'quiz_statistics', $a); } else if (!empty($question->number)) { $questiontabletitle = get_string('analysisno', 'quiz_statistics', $a); } else if (!is_null($variantno)) { $questiontabletitle = get_string('analysisvariant', 'quiz_statistics', $a); } else { $questiontabletitle = get_string('analysisnameonly', 'quiz_statistics', $a); } if ($this->table->is_downloading() == 'html') { $questiontabletitle = get_string('analysisofresponsesfor', 'quiz_statistics', $questiontabletitle); } // Set up the table. $exportclass->start_table($questiontabletitle); if ($this->table->is_downloading() == 'html') { echo $this->render_question_text($question); } } $responesanalyser = new \core_question\statistics\responses\analyser($question, $whichtries); $responseanalysis = $responesanalyser->load_cached($qubaids, $whichtries); $qtable->question_setup($reporturl, $question, $s, $responseanalysis); if ($this->table->is_downloading()) { $exportclass->output_headers($qtable->headers); } // Where no variant no is specified the variant no is actually one. if ($variantno === null) { $variantno = 1; } foreach ($responseanalysis->get_subpart_ids($variantno) as $partid) { $subpart = $responseanalysis->get_analysis_for_subpart($variantno, $partid); foreach ($subpart->get_response_class_ids() as $responseclassid) { $responseclass = $subpart->get_response_class($responseclassid); $tabledata = $responseclass->data_for_question_response_table($subpart->has_multiple_response_classes(), $partid); foreach ($tabledata as $row) { $qtable->add_data_keyed($qtable->format_row($row)); } } } $qtable->finish_output(!$this->table->is_downloading()); }
[ "protected", "function", "output_individual_question_response_analysis", "(", "$", "question", ",", "$", "variantno", ",", "$", "s", ",", "$", "reporturl", ",", "$", "qubaids", ",", "$", "whichtries", "=", "question_attempt", "::", "LAST_TRY", ")", "{", "global", "$", "OUTPUT", ";", "if", "(", "!", "question_bank", "::", "get_qtype", "(", "$", "question", "->", "qtype", ",", "false", ")", "->", "can_analyse_responses", "(", ")", ")", "{", "return", ";", "}", "$", "qtable", "=", "new", "quiz_statistics_question_table", "(", "$", "question", "->", "id", ")", ";", "$", "exportclass", "=", "$", "this", "->", "table", "->", "export_class_instance", "(", ")", ";", "$", "qtable", "->", "export_class_instance", "(", "$", "exportclass", ")", ";", "if", "(", "!", "$", "this", "->", "table", "->", "is_downloading", "(", ")", ")", "{", "// Output an appropriate title.", "echo", "$", "OUTPUT", "->", "heading", "(", "get_string", "(", "'analysisofresponses'", ",", "'quiz_statistics'", ")", ",", "3", ")", ";", "}", "else", "{", "// Work out an appropriate title.", "$", "a", "=", "clone", "(", "$", "question", ")", ";", "$", "a", "->", "variant", "=", "$", "variantno", ";", "if", "(", "!", "empty", "(", "$", "question", "->", "number", ")", "&&", "!", "is_null", "(", "$", "variantno", ")", ")", "{", "$", "questiontabletitle", "=", "get_string", "(", "'analysisnovariant'", ",", "'quiz_statistics'", ",", "$", "a", ")", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "question", "->", "number", ")", ")", "{", "$", "questiontabletitle", "=", "get_string", "(", "'analysisno'", ",", "'quiz_statistics'", ",", "$", "a", ")", ";", "}", "else", "if", "(", "!", "is_null", "(", "$", "variantno", ")", ")", "{", "$", "questiontabletitle", "=", "get_string", "(", "'analysisvariant'", ",", "'quiz_statistics'", ",", "$", "a", ")", ";", "}", "else", "{", "$", "questiontabletitle", "=", "get_string", "(", "'analysisnameonly'", ",", "'quiz_statistics'", ",", "$", "a", ")", ";", "}", "if", "(", "$", "this", "->", "table", "->", "is_downloading", "(", ")", "==", "'html'", ")", "{", "$", "questiontabletitle", "=", "get_string", "(", "'analysisofresponsesfor'", ",", "'quiz_statistics'", ",", "$", "questiontabletitle", ")", ";", "}", "// Set up the table.", "$", "exportclass", "->", "start_table", "(", "$", "questiontabletitle", ")", ";", "if", "(", "$", "this", "->", "table", "->", "is_downloading", "(", ")", "==", "'html'", ")", "{", "echo", "$", "this", "->", "render_question_text", "(", "$", "question", ")", ";", "}", "}", "$", "responesanalyser", "=", "new", "\\", "core_question", "\\", "statistics", "\\", "responses", "\\", "analyser", "(", "$", "question", ",", "$", "whichtries", ")", ";", "$", "responseanalysis", "=", "$", "responesanalyser", "->", "load_cached", "(", "$", "qubaids", ",", "$", "whichtries", ")", ";", "$", "qtable", "->", "question_setup", "(", "$", "reporturl", ",", "$", "question", ",", "$", "s", ",", "$", "responseanalysis", ")", ";", "if", "(", "$", "this", "->", "table", "->", "is_downloading", "(", ")", ")", "{", "$", "exportclass", "->", "output_headers", "(", "$", "qtable", "->", "headers", ")", ";", "}", "// Where no variant no is specified the variant no is actually one.", "if", "(", "$", "variantno", "===", "null", ")", "{", "$", "variantno", "=", "1", ";", "}", "foreach", "(", "$", "responseanalysis", "->", "get_subpart_ids", "(", "$", "variantno", ")", "as", "$", "partid", ")", "{", "$", "subpart", "=", "$", "responseanalysis", "->", "get_analysis_for_subpart", "(", "$", "variantno", ",", "$", "partid", ")", ";", "foreach", "(", "$", "subpart", "->", "get_response_class_ids", "(", ")", "as", "$", "responseclassid", ")", "{", "$", "responseclass", "=", "$", "subpart", "->", "get_response_class", "(", "$", "responseclassid", ")", ";", "$", "tabledata", "=", "$", "responseclass", "->", "data_for_question_response_table", "(", "$", "subpart", "->", "has_multiple_response_classes", "(", ")", ",", "$", "partid", ")", ";", "foreach", "(", "$", "tabledata", "as", "$", "row", ")", "{", "$", "qtable", "->", "add_data_keyed", "(", "$", "qtable", "->", "format_row", "(", "$", "row", ")", ")", ";", "}", "}", "}", "$", "qtable", "->", "finish_output", "(", "!", "$", "this", "->", "table", "->", "is_downloading", "(", ")", ")", ";", "}" ]
Display the response analysis for a question. @param object $question the question to report on. @param int|null $variantno the variant @param int $s @param moodle_url $reporturl the URL to redisplay this report. @param qubaid_condition $qubaids @param string $whichtries
[ "Display", "the", "response", "analysis", "for", "a", "question", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L376-L442
216,274
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.output_quiz_structure_analysis_table
protected function output_quiz_structure_analysis_table($questionstats) { $limitvariants = !$this->table->is_downloading(); foreach ($questionstats->get_all_slots() as $slot) { // Output the data for these question statistics. $structureanalysis = $questionstats->structure_analysis_for_one_slot($slot, $limitvariants); if (is_null($structureanalysis)) { $this->table->add_separator(); } else { foreach ($structureanalysis as $row) { $bgcssclass = ''; // The only way to identify in this point of the report if a row is a summary row // is checking if it's a instance of calculated_question_summary class. if ($row instanceof \core_question\statistics\questions\calculated_question_summary) { // Apply a custom css class to summary row to remove border and reduce paddings. $bgcssclass = 'quiz_statistics-summaryrow'; // For question that contain a summary row, we add a "hidden" row in between so the report // display both rows with same background color. $this->table->add_data_keyed([], 'd-none hidden'); } $this->table->add_data_keyed($this->table->format_row($row), $bgcssclass); } } } $this->table->finish_output(!$this->table->is_downloading()); }
php
protected function output_quiz_structure_analysis_table($questionstats) { $limitvariants = !$this->table->is_downloading(); foreach ($questionstats->get_all_slots() as $slot) { // Output the data for these question statistics. $structureanalysis = $questionstats->structure_analysis_for_one_slot($slot, $limitvariants); if (is_null($structureanalysis)) { $this->table->add_separator(); } else { foreach ($structureanalysis as $row) { $bgcssclass = ''; // The only way to identify in this point of the report if a row is a summary row // is checking if it's a instance of calculated_question_summary class. if ($row instanceof \core_question\statistics\questions\calculated_question_summary) { // Apply a custom css class to summary row to remove border and reduce paddings. $bgcssclass = 'quiz_statistics-summaryrow'; // For question that contain a summary row, we add a "hidden" row in between so the report // display both rows with same background color. $this->table->add_data_keyed([], 'd-none hidden'); } $this->table->add_data_keyed($this->table->format_row($row), $bgcssclass); } } } $this->table->finish_output(!$this->table->is_downloading()); }
[ "protected", "function", "output_quiz_structure_analysis_table", "(", "$", "questionstats", ")", "{", "$", "limitvariants", "=", "!", "$", "this", "->", "table", "->", "is_downloading", "(", ")", ";", "foreach", "(", "$", "questionstats", "->", "get_all_slots", "(", ")", "as", "$", "slot", ")", "{", "// Output the data for these question statistics.", "$", "structureanalysis", "=", "$", "questionstats", "->", "structure_analysis_for_one_slot", "(", "$", "slot", ",", "$", "limitvariants", ")", ";", "if", "(", "is_null", "(", "$", "structureanalysis", ")", ")", "{", "$", "this", "->", "table", "->", "add_separator", "(", ")", ";", "}", "else", "{", "foreach", "(", "$", "structureanalysis", "as", "$", "row", ")", "{", "$", "bgcssclass", "=", "''", ";", "// The only way to identify in this point of the report if a row is a summary row", "// is checking if it's a instance of calculated_question_summary class.", "if", "(", "$", "row", "instanceof", "\\", "core_question", "\\", "statistics", "\\", "questions", "\\", "calculated_question_summary", ")", "{", "// Apply a custom css class to summary row to remove border and reduce paddings.", "$", "bgcssclass", "=", "'quiz_statistics-summaryrow'", ";", "// For question that contain a summary row, we add a \"hidden\" row in between so the report", "// display both rows with same background color.", "$", "this", "->", "table", "->", "add_data_keyed", "(", "[", "]", ",", "'d-none hidden'", ")", ";", "}", "$", "this", "->", "table", "->", "add_data_keyed", "(", "$", "this", "->", "table", "->", "format_row", "(", "$", "row", ")", ",", "$", "bgcssclass", ")", ";", "}", "}", "}", "$", "this", "->", "table", "->", "finish_output", "(", "!", "$", "this", "->", "table", "->", "is_downloading", "(", ")", ")", ";", "}" ]
Output the table that lists all the questions in the quiz with their statistics. @param \core_question\statistics\questions\all_calculated_for_qubaid_condition $questionstats the stats for all questions in the quiz including subqs and variants.
[ "Output", "the", "table", "that", "lists", "all", "the", "questions", "in", "the", "quiz", "with", "their", "statistics", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L451-L478
216,275
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.output_quiz_info_table
protected function output_quiz_info_table($quizinfo) { $quizinfotable = new html_table(); $quizinfotable->align = array('center', 'center'); $quizinfotable->width = '60%'; $quizinfotable->attributes['class'] = 'generaltable titlesleft'; $quizinfotable->data = array(); foreach ($quizinfo as $heading => $value) { $quizinfotable->data[] = array($heading, $value); } return html_writer::table($quizinfotable); }
php
protected function output_quiz_info_table($quizinfo) { $quizinfotable = new html_table(); $quizinfotable->align = array('center', 'center'); $quizinfotable->width = '60%'; $quizinfotable->attributes['class'] = 'generaltable titlesleft'; $quizinfotable->data = array(); foreach ($quizinfo as $heading => $value) { $quizinfotable->data[] = array($heading, $value); } return html_writer::table($quizinfotable); }
[ "protected", "function", "output_quiz_info_table", "(", "$", "quizinfo", ")", "{", "$", "quizinfotable", "=", "new", "html_table", "(", ")", ";", "$", "quizinfotable", "->", "align", "=", "array", "(", "'center'", ",", "'center'", ")", ";", "$", "quizinfotable", "->", "width", "=", "'60%'", ";", "$", "quizinfotable", "->", "attributes", "[", "'class'", "]", "=", "'generaltable titlesleft'", ";", "$", "quizinfotable", "->", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "quizinfo", "as", "$", "heading", "=>", "$", "value", ")", "{", "$", "quizinfotable", "->", "data", "[", "]", "=", "array", "(", "$", "heading", ",", "$", "value", ")", ";", "}", "return", "html_writer", "::", "table", "(", "$", "quizinfotable", ")", ";", "}" ]
Return HTML for table of overall quiz statistics. @param array $quizinfo as returned by {@link get_formatted_quiz_info_data()}. @return string the HTML.
[ "Return", "HTML", "for", "table", "of", "overall", "quiz", "statistics", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L486-L499
216,276
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.download_quiz_info_table
protected function download_quiz_info_table($quizinfo) { global $OUTPUT; // HTML download is a special case. if ($this->table->is_downloading() == 'html') { echo $OUTPUT->heading(get_string('quizinformation', 'quiz_statistics'), 3); echo $this->output_quiz_info_table($quizinfo); return; } // Reformat the data ready for output. $headers = array(); $row = array(); foreach ($quizinfo as $heading => $value) { $headers[] = $heading; $row[] = $value; } // Do the output. $exportclass = $this->table->export_class_instance(); $exportclass->start_table(get_string('quizinformation', 'quiz_statistics')); $exportclass->output_headers($headers); $exportclass->add_data($row); $exportclass->finish_table(); }
php
protected function download_quiz_info_table($quizinfo) { global $OUTPUT; // HTML download is a special case. if ($this->table->is_downloading() == 'html') { echo $OUTPUT->heading(get_string('quizinformation', 'quiz_statistics'), 3); echo $this->output_quiz_info_table($quizinfo); return; } // Reformat the data ready for output. $headers = array(); $row = array(); foreach ($quizinfo as $heading => $value) { $headers[] = $heading; $row[] = $value; } // Do the output. $exportclass = $this->table->export_class_instance(); $exportclass->start_table(get_string('quizinformation', 'quiz_statistics')); $exportclass->output_headers($headers); $exportclass->add_data($row); $exportclass->finish_table(); }
[ "protected", "function", "download_quiz_info_table", "(", "$", "quizinfo", ")", "{", "global", "$", "OUTPUT", ";", "// HTML download is a special case.", "if", "(", "$", "this", "->", "table", "->", "is_downloading", "(", ")", "==", "'html'", ")", "{", "echo", "$", "OUTPUT", "->", "heading", "(", "get_string", "(", "'quizinformation'", ",", "'quiz_statistics'", ")", ",", "3", ")", ";", "echo", "$", "this", "->", "output_quiz_info_table", "(", "$", "quizinfo", ")", ";", "return", ";", "}", "// Reformat the data ready for output.", "$", "headers", "=", "array", "(", ")", ";", "$", "row", "=", "array", "(", ")", ";", "foreach", "(", "$", "quizinfo", "as", "$", "heading", "=>", "$", "value", ")", "{", "$", "headers", "[", "]", "=", "$", "heading", ";", "$", "row", "[", "]", "=", "$", "value", ";", "}", "// Do the output.", "$", "exportclass", "=", "$", "this", "->", "table", "->", "export_class_instance", "(", ")", ";", "$", "exportclass", "->", "start_table", "(", "get_string", "(", "'quizinformation'", ",", "'quiz_statistics'", ")", ")", ";", "$", "exportclass", "->", "output_headers", "(", "$", "headers", ")", ";", "$", "exportclass", "->", "add_data", "(", "$", "row", ")", ";", "$", "exportclass", "->", "finish_table", "(", ")", ";", "}" ]
Download the table of overall quiz statistics. @param array $quizinfo as returned by {@link get_formatted_quiz_info_data()}.
[ "Download", "the", "table", "of", "overall", "quiz", "statistics", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L506-L530
216,277
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.output_statistics_graph
protected function output_statistics_graph($quizorid, $qubaids) { global $DB, $PAGE; $quiz = $quizorid; if (!is_object($quiz)) { $quiz = $DB->get_record('quiz', array('id' => $quizorid), '*', MUST_EXIST); } // Load the rest of the required data. $questions = quiz_report_get_significant_questions($quiz); // Only load main question not sub questions. $questionstatistics = $DB->get_records_select('question_statistics', 'hashcode = ? AND slot IS NOT NULL AND variant IS NULL', [$qubaids->get_hash_code()]); // Configure what to display. $fieldstoplot = [ 'facility' => get_string('facility', 'quiz_statistics'), 'discriminativeefficiency' => get_string('discriminative_efficiency', 'quiz_statistics') ]; $fieldstoplotfactor = ['facility' => 100, 'discriminativeefficiency' => 1]; // Prepare the arrays to hold the data. $xdata = []; foreach (array_keys($fieldstoplot) as $fieldtoplot) { $ydata[$fieldtoplot] = []; } // Fill in the data for each question. foreach ($questionstatistics as $questionstatistic) { $number = $questions[$questionstatistic->slot]->number; $xdata[$number] = $number; foreach ($fieldstoplot as $fieldtoplot => $notused) { $value = $questionstatistic->$fieldtoplot; if (is_null($value)) { $value = 0; } $value *= $fieldstoplotfactor[$fieldtoplot]; $ydata[$fieldtoplot][$number] = number_format($value, 2); } } // Create the chart. sort($xdata); $chart = new \core\chart_bar(); $chart->get_xaxis(0, true)->set_label(get_string('position', 'quiz_statistics')); $chart->set_labels(array_values($xdata)); foreach ($fieldstoplot as $fieldtoplot => $notused) { ksort($ydata[$fieldtoplot]); $series = new \core\chart_series($fieldstoplot[$fieldtoplot], array_values($ydata[$fieldtoplot])); $chart->add_series($series); } // Find max. $max = 0; foreach ($fieldstoplot as $fieldtoplot => $notused) { $max = max($max, max($ydata[$fieldtoplot])); } // Set Y properties. $yaxis = $chart->get_yaxis(0, true); $yaxis->set_stepsize(10); $yaxis->set_label('%'); $output = $PAGE->get_renderer('mod_quiz'); $graphname = get_string('statisticsreportgraph', 'quiz_statistics'); echo $output->chart($chart, $graphname); }
php
protected function output_statistics_graph($quizorid, $qubaids) { global $DB, $PAGE; $quiz = $quizorid; if (!is_object($quiz)) { $quiz = $DB->get_record('quiz', array('id' => $quizorid), '*', MUST_EXIST); } // Load the rest of the required data. $questions = quiz_report_get_significant_questions($quiz); // Only load main question not sub questions. $questionstatistics = $DB->get_records_select('question_statistics', 'hashcode = ? AND slot IS NOT NULL AND variant IS NULL', [$qubaids->get_hash_code()]); // Configure what to display. $fieldstoplot = [ 'facility' => get_string('facility', 'quiz_statistics'), 'discriminativeefficiency' => get_string('discriminative_efficiency', 'quiz_statistics') ]; $fieldstoplotfactor = ['facility' => 100, 'discriminativeefficiency' => 1]; // Prepare the arrays to hold the data. $xdata = []; foreach (array_keys($fieldstoplot) as $fieldtoplot) { $ydata[$fieldtoplot] = []; } // Fill in the data for each question. foreach ($questionstatistics as $questionstatistic) { $number = $questions[$questionstatistic->slot]->number; $xdata[$number] = $number; foreach ($fieldstoplot as $fieldtoplot => $notused) { $value = $questionstatistic->$fieldtoplot; if (is_null($value)) { $value = 0; } $value *= $fieldstoplotfactor[$fieldtoplot]; $ydata[$fieldtoplot][$number] = number_format($value, 2); } } // Create the chart. sort($xdata); $chart = new \core\chart_bar(); $chart->get_xaxis(0, true)->set_label(get_string('position', 'quiz_statistics')); $chart->set_labels(array_values($xdata)); foreach ($fieldstoplot as $fieldtoplot => $notused) { ksort($ydata[$fieldtoplot]); $series = new \core\chart_series($fieldstoplot[$fieldtoplot], array_values($ydata[$fieldtoplot])); $chart->add_series($series); } // Find max. $max = 0; foreach ($fieldstoplot as $fieldtoplot => $notused) { $max = max($max, max($ydata[$fieldtoplot])); } // Set Y properties. $yaxis = $chart->get_yaxis(0, true); $yaxis->set_stepsize(10); $yaxis->set_label('%'); $output = $PAGE->get_renderer('mod_quiz'); $graphname = get_string('statisticsreportgraph', 'quiz_statistics'); echo $output->chart($chart, $graphname); }
[ "protected", "function", "output_statistics_graph", "(", "$", "quizorid", ",", "$", "qubaids", ")", "{", "global", "$", "DB", ",", "$", "PAGE", ";", "$", "quiz", "=", "$", "quizorid", ";", "if", "(", "!", "is_object", "(", "$", "quiz", ")", ")", "{", "$", "quiz", "=", "$", "DB", "->", "get_record", "(", "'quiz'", ",", "array", "(", "'id'", "=>", "$", "quizorid", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "}", "// Load the rest of the required data.", "$", "questions", "=", "quiz_report_get_significant_questions", "(", "$", "quiz", ")", ";", "// Only load main question not sub questions.", "$", "questionstatistics", "=", "$", "DB", "->", "get_records_select", "(", "'question_statistics'", ",", "'hashcode = ? AND slot IS NOT NULL AND variant IS NULL'", ",", "[", "$", "qubaids", "->", "get_hash_code", "(", ")", "]", ")", ";", "// Configure what to display.", "$", "fieldstoplot", "=", "[", "'facility'", "=>", "get_string", "(", "'facility'", ",", "'quiz_statistics'", ")", ",", "'discriminativeefficiency'", "=>", "get_string", "(", "'discriminative_efficiency'", ",", "'quiz_statistics'", ")", "]", ";", "$", "fieldstoplotfactor", "=", "[", "'facility'", "=>", "100", ",", "'discriminativeefficiency'", "=>", "1", "]", ";", "// Prepare the arrays to hold the data.", "$", "xdata", "=", "[", "]", ";", "foreach", "(", "array_keys", "(", "$", "fieldstoplot", ")", "as", "$", "fieldtoplot", ")", "{", "$", "ydata", "[", "$", "fieldtoplot", "]", "=", "[", "]", ";", "}", "// Fill in the data for each question.", "foreach", "(", "$", "questionstatistics", "as", "$", "questionstatistic", ")", "{", "$", "number", "=", "$", "questions", "[", "$", "questionstatistic", "->", "slot", "]", "->", "number", ";", "$", "xdata", "[", "$", "number", "]", "=", "$", "number", ";", "foreach", "(", "$", "fieldstoplot", "as", "$", "fieldtoplot", "=>", "$", "notused", ")", "{", "$", "value", "=", "$", "questionstatistic", "->", "$", "fieldtoplot", ";", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "$", "value", "=", "0", ";", "}", "$", "value", "*=", "$", "fieldstoplotfactor", "[", "$", "fieldtoplot", "]", ";", "$", "ydata", "[", "$", "fieldtoplot", "]", "[", "$", "number", "]", "=", "number_format", "(", "$", "value", ",", "2", ")", ";", "}", "}", "// Create the chart.", "sort", "(", "$", "xdata", ")", ";", "$", "chart", "=", "new", "\\", "core", "\\", "chart_bar", "(", ")", ";", "$", "chart", "->", "get_xaxis", "(", "0", ",", "true", ")", "->", "set_label", "(", "get_string", "(", "'position'", ",", "'quiz_statistics'", ")", ")", ";", "$", "chart", "->", "set_labels", "(", "array_values", "(", "$", "xdata", ")", ")", ";", "foreach", "(", "$", "fieldstoplot", "as", "$", "fieldtoplot", "=>", "$", "notused", ")", "{", "ksort", "(", "$", "ydata", "[", "$", "fieldtoplot", "]", ")", ";", "$", "series", "=", "new", "\\", "core", "\\", "chart_series", "(", "$", "fieldstoplot", "[", "$", "fieldtoplot", "]", ",", "array_values", "(", "$", "ydata", "[", "$", "fieldtoplot", "]", ")", ")", ";", "$", "chart", "->", "add_series", "(", "$", "series", ")", ";", "}", "// Find max.", "$", "max", "=", "0", ";", "foreach", "(", "$", "fieldstoplot", "as", "$", "fieldtoplot", "=>", "$", "notused", ")", "{", "$", "max", "=", "max", "(", "$", "max", ",", "max", "(", "$", "ydata", "[", "$", "fieldtoplot", "]", ")", ")", ";", "}", "// Set Y properties.", "$", "yaxis", "=", "$", "chart", "->", "get_yaxis", "(", "0", ",", "true", ")", ";", "$", "yaxis", "->", "set_stepsize", "(", "10", ")", ";", "$", "yaxis", "->", "set_label", "(", "'%'", ")", ";", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'mod_quiz'", ")", ";", "$", "graphname", "=", "get_string", "(", "'statisticsreportgraph'", ",", "'quiz_statistics'", ")", ";", "echo", "$", "output", "->", "chart", "(", "$", "chart", ",", "$", "graphname", ")", ";", "}" ]
Output the HTML needed to show the statistics graph. @param int|object $quizorid The quiz, or its ID. @param qubaid_condition $qubaids the question usages whose responses to analyse. @param string $whichattempts Which attempts constant.
[ "Output", "the", "HTML", "needed", "to", "show", "the", "statistics", "graph", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L539-L609
216,278
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.get_all_stats_and_analysis
public function get_all_stats_and_analysis( $quiz, $whichattempts, $whichtries, \core\dml\sql_join $groupstudentsjoins, $questions, $progress = null) { if ($progress === null) { $progress = new \core\progress\none(); } $qubaids = quiz_statistics_qubaids_condition($quiz->id, $groupstudentsjoins, $whichattempts); $qcalc = new \core_question\statistics\questions\calculator($questions, $progress); $quizcalc = new \quiz_statistics\calculator($progress); $progress->start_progress('', 3); if ($quizcalc->get_last_calculated_time($qubaids) === false) { // Recalculate now. $questionstats = $qcalc->calculate($qubaids); $progress->progress(1); $quizstats = $quizcalc->calculate($quiz->id, $whichattempts, $groupstudentsjoins, count($questions), $qcalc->get_sum_of_mark_variance()); $progress->progress(2); } else { $quizstats = $quizcalc->get_cached($qubaids); $progress->progress(1); $questionstats = $qcalc->get_cached($qubaids); $progress->progress(2); } if ($quizstats->s()) { $subquestions = $questionstats->get_sub_questions(); $this->analyse_responses_for_all_questions_and_subquestions($questions, $subquestions, $qubaids, $whichtries, $progress); } $progress->progress(3); $progress->end_progress(); return array($quizstats, $questionstats); }
php
public function get_all_stats_and_analysis( $quiz, $whichattempts, $whichtries, \core\dml\sql_join $groupstudentsjoins, $questions, $progress = null) { if ($progress === null) { $progress = new \core\progress\none(); } $qubaids = quiz_statistics_qubaids_condition($quiz->id, $groupstudentsjoins, $whichattempts); $qcalc = new \core_question\statistics\questions\calculator($questions, $progress); $quizcalc = new \quiz_statistics\calculator($progress); $progress->start_progress('', 3); if ($quizcalc->get_last_calculated_time($qubaids) === false) { // Recalculate now. $questionstats = $qcalc->calculate($qubaids); $progress->progress(1); $quizstats = $quizcalc->calculate($quiz->id, $whichattempts, $groupstudentsjoins, count($questions), $qcalc->get_sum_of_mark_variance()); $progress->progress(2); } else { $quizstats = $quizcalc->get_cached($qubaids); $progress->progress(1); $questionstats = $qcalc->get_cached($qubaids); $progress->progress(2); } if ($quizstats->s()) { $subquestions = $questionstats->get_sub_questions(); $this->analyse_responses_for_all_questions_and_subquestions($questions, $subquestions, $qubaids, $whichtries, $progress); } $progress->progress(3); $progress->end_progress(); return array($quizstats, $questionstats); }
[ "public", "function", "get_all_stats_and_analysis", "(", "$", "quiz", ",", "$", "whichattempts", ",", "$", "whichtries", ",", "\\", "core", "\\", "dml", "\\", "sql_join", "$", "groupstudentsjoins", ",", "$", "questions", ",", "$", "progress", "=", "null", ")", "{", "if", "(", "$", "progress", "===", "null", ")", "{", "$", "progress", "=", "new", "\\", "core", "\\", "progress", "\\", "none", "(", ")", ";", "}", "$", "qubaids", "=", "quiz_statistics_qubaids_condition", "(", "$", "quiz", "->", "id", ",", "$", "groupstudentsjoins", ",", "$", "whichattempts", ")", ";", "$", "qcalc", "=", "new", "\\", "core_question", "\\", "statistics", "\\", "questions", "\\", "calculator", "(", "$", "questions", ",", "$", "progress", ")", ";", "$", "quizcalc", "=", "new", "\\", "quiz_statistics", "\\", "calculator", "(", "$", "progress", ")", ";", "$", "progress", "->", "start_progress", "(", "''", ",", "3", ")", ";", "if", "(", "$", "quizcalc", "->", "get_last_calculated_time", "(", "$", "qubaids", ")", "===", "false", ")", "{", "// Recalculate now.", "$", "questionstats", "=", "$", "qcalc", "->", "calculate", "(", "$", "qubaids", ")", ";", "$", "progress", "->", "progress", "(", "1", ")", ";", "$", "quizstats", "=", "$", "quizcalc", "->", "calculate", "(", "$", "quiz", "->", "id", ",", "$", "whichattempts", ",", "$", "groupstudentsjoins", ",", "count", "(", "$", "questions", ")", ",", "$", "qcalc", "->", "get_sum_of_mark_variance", "(", ")", ")", ";", "$", "progress", "->", "progress", "(", "2", ")", ";", "}", "else", "{", "$", "quizstats", "=", "$", "quizcalc", "->", "get_cached", "(", "$", "qubaids", ")", ";", "$", "progress", "->", "progress", "(", "1", ")", ";", "$", "questionstats", "=", "$", "qcalc", "->", "get_cached", "(", "$", "qubaids", ")", ";", "$", "progress", "->", "progress", "(", "2", ")", ";", "}", "if", "(", "$", "quizstats", "->", "s", "(", ")", ")", "{", "$", "subquestions", "=", "$", "questionstats", "->", "get_sub_questions", "(", ")", ";", "$", "this", "->", "analyse_responses_for_all_questions_and_subquestions", "(", "$", "questions", ",", "$", "subquestions", ",", "$", "qubaids", ",", "$", "whichtries", ",", "$", "progress", ")", ";", "}", "$", "progress", "->", "progress", "(", "3", ")", ";", "$", "progress", "->", "end_progress", "(", ")", ";", "return", "array", "(", "$", "quizstats", ",", "$", "questionstats", ")", ";", "}" ]
Get the quiz and question statistics, either by loading the cached results, or by recomputing them. @param object $quiz the quiz settings. @param string $whichattempts which attempts to use, represented internally as one of the constants as used in $quiz->grademethod ie. QUIZ_GRADEAVERAGE, QUIZ_GRADEHIGHEST, QUIZ_ATTEMPTLAST or QUIZ_ATTEMPTFIRST we calculate stats based on which attempts would affect the grade for each student. @param string $whichtries which tries to analyse for response analysis. Will be one of question_attempt::FIRST_TRY, LAST_TRY or ALL_TRIES. @param \core\dml\sql_join $groupstudentsjoins Contains joins, wheres, params for students in this group. @param array $questions full question data. @param \core\progress\base|null $progress @return array with 2 elements: - $quizstats The statistics for overall attempt scores. - $questionstats \core_question\statistics\questions\all_calculated_for_qubaid_condition
[ "Get", "the", "quiz", "and", "question", "statistics", "either", "by", "loading", "the", "cached", "results", "or", "by", "recomputing", "them", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L628-L670
216,279
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.get_progress_trace_instance
protected function get_progress_trace_instance() { if ($this->progress === null) { if (!$this->table->is_downloading()) { $this->progress = new \core\progress\display_if_slow(get_string('calculatingallstats', 'quiz_statistics')); $this->progress->set_display_names(); } else { $this->progress = new \core\progress\none(); } } return $this->progress; }
php
protected function get_progress_trace_instance() { if ($this->progress === null) { if (!$this->table->is_downloading()) { $this->progress = new \core\progress\display_if_slow(get_string('calculatingallstats', 'quiz_statistics')); $this->progress->set_display_names(); } else { $this->progress = new \core\progress\none(); } } return $this->progress; }
[ "protected", "function", "get_progress_trace_instance", "(", ")", "{", "if", "(", "$", "this", "->", "progress", "===", "null", ")", "{", "if", "(", "!", "$", "this", "->", "table", "->", "is_downloading", "(", ")", ")", "{", "$", "this", "->", "progress", "=", "new", "\\", "core", "\\", "progress", "\\", "display_if_slow", "(", "get_string", "(", "'calculatingallstats'", ",", "'quiz_statistics'", ")", ")", ";", "$", "this", "->", "progress", "->", "set_display_names", "(", ")", ";", "}", "else", "{", "$", "this", "->", "progress", "=", "new", "\\", "core", "\\", "progress", "\\", "none", "(", ")", ";", "}", "}", "return", "$", "this", "->", "progress", ";", "}" ]
Appropriate instance depending if we want html output for the user or not. @return \core\progress\base child of \core\progress\base to handle the display (or not) of task progress.
[ "Appropriate", "instance", "depending", "if", "we", "want", "html", "output", "for", "the", "user", "or", "not", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L677-L687
216,280
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.analyse_responses_for_all_questions_and_subquestions
protected function analyse_responses_for_all_questions_and_subquestions($questions, $subquestions, $qubaids, $whichtries, $progress = null) { if ($progress === null) { $progress = new \core\progress\none(); } // Starting response analysis tasks. $progress->start_progress('', count($questions) + count($subquestions)); $done = $this->analyse_responses_for_questions($questions, $qubaids, $whichtries, $progress); $this->analyse_responses_for_questions($subquestions, $qubaids, $whichtries, $progress, $done); // Finished all response analysis tasks. $progress->end_progress(); }
php
protected function analyse_responses_for_all_questions_and_subquestions($questions, $subquestions, $qubaids, $whichtries, $progress = null) { if ($progress === null) { $progress = new \core\progress\none(); } // Starting response analysis tasks. $progress->start_progress('', count($questions) + count($subquestions)); $done = $this->analyse_responses_for_questions($questions, $qubaids, $whichtries, $progress); $this->analyse_responses_for_questions($subquestions, $qubaids, $whichtries, $progress, $done); // Finished all response analysis tasks. $progress->end_progress(); }
[ "protected", "function", "analyse_responses_for_all_questions_and_subquestions", "(", "$", "questions", ",", "$", "subquestions", ",", "$", "qubaids", ",", "$", "whichtries", ",", "$", "progress", "=", "null", ")", "{", "if", "(", "$", "progress", "===", "null", ")", "{", "$", "progress", "=", "new", "\\", "core", "\\", "progress", "\\", "none", "(", ")", ";", "}", "// Starting response analysis tasks.", "$", "progress", "->", "start_progress", "(", "''", ",", "count", "(", "$", "questions", ")", "+", "count", "(", "$", "subquestions", ")", ")", ";", "$", "done", "=", "$", "this", "->", "analyse_responses_for_questions", "(", "$", "questions", ",", "$", "qubaids", ",", "$", "whichtries", ",", "$", "progress", ")", ";", "$", "this", "->", "analyse_responses_for_questions", "(", "$", "subquestions", ",", "$", "qubaids", ",", "$", "whichtries", ",", "$", "progress", ",", "$", "done", ")", ";", "// Finished all response analysis tasks.", "$", "progress", "->", "end_progress", "(", ")", ";", "}" ]
Analyse responses for all questions and sub questions in this quiz. @param object[] $questions as returned by self::load_and_initialise_questions_for_calculations @param object[] $subquestions full question objects. @param qubaid_condition $qubaids the question usages whose responses to analyse. @param string $whichtries which tries to analyse \question_attempt::FIRST_TRY, LAST_TRY or ALL_TRIES. @param null|\core\progress\base $progress Used to indicate progress of task.
[ "Analyse", "responses", "for", "all", "questions", "and", "sub", "questions", "in", "this", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L698-L713
216,281
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.analyse_responses_for_questions
protected function analyse_responses_for_questions($questions, $qubaids, $whichtries, $progress = null, $done = array()) { $countquestions = count($questions); if (!$countquestions) { return array(); } if ($progress === null) { $progress = new \core\progress\none(); } $progress->start_progress('', $countquestions, $countquestions); foreach ($questions as $question) { $progress->increment_progress(); if (question_bank::get_qtype($question->qtype, false)->can_analyse_responses() && !isset($done[$question->id])) { $responesstats = new \core_question\statistics\responses\analyser($question, $whichtries); if ($responesstats->get_last_analysed_time($qubaids, $whichtries) === false) { $responesstats->calculate($qubaids, $whichtries); } } $done[$question->id] = 1; } $progress->end_progress(); return $done; }
php
protected function analyse_responses_for_questions($questions, $qubaids, $whichtries, $progress = null, $done = array()) { $countquestions = count($questions); if (!$countquestions) { return array(); } if ($progress === null) { $progress = new \core\progress\none(); } $progress->start_progress('', $countquestions, $countquestions); foreach ($questions as $question) { $progress->increment_progress(); if (question_bank::get_qtype($question->qtype, false)->can_analyse_responses() && !isset($done[$question->id])) { $responesstats = new \core_question\statistics\responses\analyser($question, $whichtries); if ($responesstats->get_last_analysed_time($qubaids, $whichtries) === false) { $responesstats->calculate($qubaids, $whichtries); } } $done[$question->id] = 1; } $progress->end_progress(); return $done; }
[ "protected", "function", "analyse_responses_for_questions", "(", "$", "questions", ",", "$", "qubaids", ",", "$", "whichtries", ",", "$", "progress", "=", "null", ",", "$", "done", "=", "array", "(", ")", ")", "{", "$", "countquestions", "=", "count", "(", "$", "questions", ")", ";", "if", "(", "!", "$", "countquestions", ")", "{", "return", "array", "(", ")", ";", "}", "if", "(", "$", "progress", "===", "null", ")", "{", "$", "progress", "=", "new", "\\", "core", "\\", "progress", "\\", "none", "(", ")", ";", "}", "$", "progress", "->", "start_progress", "(", "''", ",", "$", "countquestions", ",", "$", "countquestions", ")", ";", "foreach", "(", "$", "questions", "as", "$", "question", ")", "{", "$", "progress", "->", "increment_progress", "(", ")", ";", "if", "(", "question_bank", "::", "get_qtype", "(", "$", "question", "->", "qtype", ",", "false", ")", "->", "can_analyse_responses", "(", ")", "&&", "!", "isset", "(", "$", "done", "[", "$", "question", "->", "id", "]", ")", ")", "{", "$", "responesstats", "=", "new", "\\", "core_question", "\\", "statistics", "\\", "responses", "\\", "analyser", "(", "$", "question", ",", "$", "whichtries", ")", ";", "if", "(", "$", "responesstats", "->", "get_last_analysed_time", "(", "$", "qubaids", ",", "$", "whichtries", ")", "===", "false", ")", "{", "$", "responesstats", "->", "calculate", "(", "$", "qubaids", ",", "$", "whichtries", ")", ";", "}", "}", "$", "done", "[", "$", "question", "->", "id", "]", "=", "1", ";", "}", "$", "progress", "->", "end_progress", "(", ")", ";", "return", "$", "done", ";", "}" ]
Analyse responses for an array of questions or sub questions. @param object[] $questions as returned by self::load_and_initialise_questions_for_calculations. @param qubaid_condition $qubaids the question usages whose responses to analyse. @param string $whichtries which tries to analyse \question_attempt::FIRST_TRY, LAST_TRY or ALL_TRIES. @param null|\core\progress\base $progress Used to indicate progress of task. @param int[] $done array keys are ids of questions that have been analysed before calling method. @return array array keys are ids of questions that were analysed after this method call.
[ "Analyse", "responses", "for", "an", "array", "of", "questions", "or", "sub", "questions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L725-L746
216,282
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.everything_download_options
protected function everything_download_options(moodle_url $reporturl) { global $OUTPUT; return $OUTPUT->download_dataformat_selector(get_string('downloadeverything', 'quiz_statistics'), $reporturl->out_omit_querystring(), 'download', $reporturl->params() + array('everything' => 1)); }
php
protected function everything_download_options(moodle_url $reporturl) { global $OUTPUT; return $OUTPUT->download_dataformat_selector(get_string('downloadeverything', 'quiz_statistics'), $reporturl->out_omit_querystring(), 'download', $reporturl->params() + array('everything' => 1)); }
[ "protected", "function", "everything_download_options", "(", "moodle_url", "$", "reporturl", ")", "{", "global", "$", "OUTPUT", ";", "return", "$", "OUTPUT", "->", "download_dataformat_selector", "(", "get_string", "(", "'downloadeverything'", ",", "'quiz_statistics'", ")", ",", "$", "reporturl", "->", "out_omit_querystring", "(", ")", ",", "'download'", ",", "$", "reporturl", "->", "params", "(", ")", "+", "array", "(", "'everything'", "=>", "1", ")", ")", ";", "}" ]
Return a little form for the user to request to download the full report, including quiz stats and response analysis for all questions and sub-questions. @param moodle_url $reporturl the base URL of the report. @return string HTML.
[ "Return", "a", "little", "form", "for", "the", "user", "to", "request", "to", "download", "the", "full", "report", "including", "quiz", "stats", "and", "response", "analysis", "for", "all", "questions", "and", "sub", "-", "questions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L755-L759
216,283
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.output_caching_info
protected function output_caching_info($lastcachetime, $quizid, $groupstudentsjoins, $whichattempts, $reporturl) { global $DB, $OUTPUT; if (empty($lastcachetime)) { return ''; } // Find the number of attempts since the cached statistics were computed. list($fromqa, $whereqa, $qaparams) = quiz_statistics_attempts_sql($quizid, $groupstudentsjoins, $whichattempts, true); $count = $DB->count_records_sql(" SELECT COUNT(1) FROM $fromqa WHERE $whereqa AND quiza.timefinish > {$lastcachetime}", $qaparams); if (!$count) { $count = 0; } // Generate the output. $a = new stdClass(); $a->lastcalculated = format_time(time() - $lastcachetime); $a->count = $count; $recalcualteurl = new moodle_url($reporturl, array('recalculate' => 1, 'sesskey' => sesskey())); $output = ''; $output .= $OUTPUT->box_start( 'boxaligncenter generalbox boxwidthnormal mdl-align', 'cachingnotice'); $output .= get_string('lastcalculated', 'quiz_statistics', $a); $output .= $OUTPUT->single_button($recalcualteurl, get_string('recalculatenow', 'quiz_statistics')); $output .= $OUTPUT->box_end(true); return $output; }
php
protected function output_caching_info($lastcachetime, $quizid, $groupstudentsjoins, $whichattempts, $reporturl) { global $DB, $OUTPUT; if (empty($lastcachetime)) { return ''; } // Find the number of attempts since the cached statistics were computed. list($fromqa, $whereqa, $qaparams) = quiz_statistics_attempts_sql($quizid, $groupstudentsjoins, $whichattempts, true); $count = $DB->count_records_sql(" SELECT COUNT(1) FROM $fromqa WHERE $whereqa AND quiza.timefinish > {$lastcachetime}", $qaparams); if (!$count) { $count = 0; } // Generate the output. $a = new stdClass(); $a->lastcalculated = format_time(time() - $lastcachetime); $a->count = $count; $recalcualteurl = new moodle_url($reporturl, array('recalculate' => 1, 'sesskey' => sesskey())); $output = ''; $output .= $OUTPUT->box_start( 'boxaligncenter generalbox boxwidthnormal mdl-align', 'cachingnotice'); $output .= get_string('lastcalculated', 'quiz_statistics', $a); $output .= $OUTPUT->single_button($recalcualteurl, get_string('recalculatenow', 'quiz_statistics')); $output .= $OUTPUT->box_end(true); return $output; }
[ "protected", "function", "output_caching_info", "(", "$", "lastcachetime", ",", "$", "quizid", ",", "$", "groupstudentsjoins", ",", "$", "whichattempts", ",", "$", "reporturl", ")", "{", "global", "$", "DB", ",", "$", "OUTPUT", ";", "if", "(", "empty", "(", "$", "lastcachetime", ")", ")", "{", "return", "''", ";", "}", "// Find the number of attempts since the cached statistics were computed.", "list", "(", "$", "fromqa", ",", "$", "whereqa", ",", "$", "qaparams", ")", "=", "quiz_statistics_attempts_sql", "(", "$", "quizid", ",", "$", "groupstudentsjoins", ",", "$", "whichattempts", ",", "true", ")", ";", "$", "count", "=", "$", "DB", "->", "count_records_sql", "(", "\"\n SELECT COUNT(1)\n FROM $fromqa\n WHERE $whereqa\n AND quiza.timefinish > {$lastcachetime}\"", ",", "$", "qaparams", ")", ";", "if", "(", "!", "$", "count", ")", "{", "$", "count", "=", "0", ";", "}", "// Generate the output.", "$", "a", "=", "new", "stdClass", "(", ")", ";", "$", "a", "->", "lastcalculated", "=", "format_time", "(", "time", "(", ")", "-", "$", "lastcachetime", ")", ";", "$", "a", "->", "count", "=", "$", "count", ";", "$", "recalcualteurl", "=", "new", "moodle_url", "(", "$", "reporturl", ",", "array", "(", "'recalculate'", "=>", "1", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ";", "$", "output", "=", "''", ";", "$", "output", ".=", "$", "OUTPUT", "->", "box_start", "(", "'boxaligncenter generalbox boxwidthnormal mdl-align'", ",", "'cachingnotice'", ")", ";", "$", "output", ".=", "get_string", "(", "'lastcalculated'", ",", "'quiz_statistics'", ",", "$", "a", ")", ";", "$", "output", ".=", "$", "OUTPUT", "->", "single_button", "(", "$", "recalcualteurl", ",", "get_string", "(", "'recalculatenow'", ",", "'quiz_statistics'", ")", ")", ";", "$", "output", ".=", "$", "OUTPUT", "->", "box_end", "(", "true", ")", ";", "return", "$", "output", ";", "}" ]
Return HTML for a message that says when the stats were last calculated and a 'recalculate now' button. @param int $lastcachetime the time the stats were last cached. @param int $quizid the quiz id. @param array $groupstudentsjoins (joins, wheres, params) for students in the group or empty array if groups not used. @param string $whichattempts which attempts to use, represented internally as one of the constants as used in $quiz->grademethod ie. QUIZ_GRADEAVERAGE, QUIZ_GRADEHIGHEST, QUIZ_ATTEMPTLAST or QUIZ_ATTEMPTFIRST we calculate stats based on which attempts would affect the grade for each student. @param moodle_url $reporturl url for this report @return string HTML.
[ "Return", "HTML", "for", "a", "message", "that", "says", "when", "the", "stats", "were", "last", "calculated", "and", "a", "recalculate", "now", "button", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L774-L809
216,284
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.clear_cached_data
protected function clear_cached_data($qubaids) { global $DB; $DB->delete_records('quiz_statistics', array('hashcode' => $qubaids->get_hash_code())); $DB->delete_records('question_statistics', array('hashcode' => $qubaids->get_hash_code())); $DB->delete_records('question_response_analysis', array('hashcode' => $qubaids->get_hash_code())); }
php
protected function clear_cached_data($qubaids) { global $DB; $DB->delete_records('quiz_statistics', array('hashcode' => $qubaids->get_hash_code())); $DB->delete_records('question_statistics', array('hashcode' => $qubaids->get_hash_code())); $DB->delete_records('question_response_analysis', array('hashcode' => $qubaids->get_hash_code())); }
[ "protected", "function", "clear_cached_data", "(", "$", "qubaids", ")", "{", "global", "$", "DB", ";", "$", "DB", "->", "delete_records", "(", "'quiz_statistics'", ",", "array", "(", "'hashcode'", "=>", "$", "qubaids", "->", "get_hash_code", "(", ")", ")", ")", ";", "$", "DB", "->", "delete_records", "(", "'question_statistics'", ",", "array", "(", "'hashcode'", "=>", "$", "qubaids", "->", "get_hash_code", "(", ")", ")", ")", ";", "$", "DB", "->", "delete_records", "(", "'question_response_analysis'", ",", "array", "(", "'hashcode'", "=>", "$", "qubaids", "->", "get_hash_code", "(", ")", ")", ")", ";", "}" ]
Clear the cached data for a particular report configuration. This will trigger a re-computation the next time the report is displayed. @param $qubaids qubaid_condition
[ "Clear", "the", "cached", "data", "for", "a", "particular", "report", "configuration", ".", "This", "will", "trigger", "a", "re", "-", "computation", "the", "next", "time", "the", "report", "is", "displayed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L817-L822
216,285
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.load_and_initialise_questions_for_calculations
public function load_and_initialise_questions_for_calculations($quiz) { // Load the questions. $questions = quiz_report_get_significant_questions($quiz); $questionids = array(); foreach ($questions as $question) { $questionids[] = $question->id; } $fullquestions = question_load_questions($questionids); foreach ($questions as $qno => $question) { $q = $fullquestions[$question->id]; $q->maxmark = $question->maxmark; $q->slot = $qno; $q->number = $question->number; $questions[$qno] = $q; } return $questions; }
php
public function load_and_initialise_questions_for_calculations($quiz) { // Load the questions. $questions = quiz_report_get_significant_questions($quiz); $questionids = array(); foreach ($questions as $question) { $questionids[] = $question->id; } $fullquestions = question_load_questions($questionids); foreach ($questions as $qno => $question) { $q = $fullquestions[$question->id]; $q->maxmark = $question->maxmark; $q->slot = $qno; $q->number = $question->number; $questions[$qno] = $q; } return $questions; }
[ "public", "function", "load_and_initialise_questions_for_calculations", "(", "$", "quiz", ")", "{", "// Load the questions.", "$", "questions", "=", "quiz_report_get_significant_questions", "(", "$", "quiz", ")", ";", "$", "questionids", "=", "array", "(", ")", ";", "foreach", "(", "$", "questions", "as", "$", "question", ")", "{", "$", "questionids", "[", "]", "=", "$", "question", "->", "id", ";", "}", "$", "fullquestions", "=", "question_load_questions", "(", "$", "questionids", ")", ";", "foreach", "(", "$", "questions", "as", "$", "qno", "=>", "$", "question", ")", "{", "$", "q", "=", "$", "fullquestions", "[", "$", "question", "->", "id", "]", ";", "$", "q", "->", "maxmark", "=", "$", "question", "->", "maxmark", ";", "$", "q", "->", "slot", "=", "$", "qno", ";", "$", "q", "->", "number", "=", "$", "question", "->", "number", ";", "$", "questions", "[", "$", "qno", "]", "=", "$", "q", ";", "}", "return", "$", "questions", ";", "}" ]
Load the questions in this quiz and add some properties to the objects needed in the reports. @param object $quiz the quiz. @return array of questions for this quiz.
[ "Load", "the", "questions", "in", "this", "quiz", "and", "add", "some", "properties", "to", "the", "objects", "needed", "in", "the", "reports", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L830-L846
216,286
moodle/moodle
mod/quiz/report/statistics/report.php
quiz_statistics_report.output_all_question_response_analysis
protected function output_all_question_response_analysis($qubaids, $questions, $questionstats, $reporturl, $whichtries = question_attempt::LAST_TRY) { foreach ($questions as $slot => $question) { if (question_bank::get_qtype( $question->qtype, false)->can_analyse_responses() ) { if ($questionstats->for_slot($slot)->get_variants()) { foreach ($questionstats->for_slot($slot)->get_variants() as $variantno) { $this->output_individual_question_response_analysis($question, $variantno, $questionstats->for_slot($slot, $variantno)->s, $reporturl, $qubaids, $whichtries); } } else { $this->output_individual_question_response_analysis($question, null, $questionstats->for_slot($slot)->s, $reporturl, $qubaids, $whichtries); } } else if ($subqids = $questionstats->for_slot($slot)->get_sub_question_ids()) { foreach ($subqids as $subqid) { if ($variants = $questionstats->for_subq($subqid)->get_variants()) { foreach ($variants as $variantno) { $this->output_individual_question_response_analysis( $questionstats->for_subq($subqid, $variantno)->question, $variantno, $questionstats->for_subq($subqid, $variantno)->s, $reporturl, $qubaids, $whichtries); } } else { $this->output_individual_question_response_analysis( $questionstats->for_subq($subqid)->question, null, $questionstats->for_subq($subqid)->s, $reporturl, $qubaids, $whichtries); } } } } }
php
protected function output_all_question_response_analysis($qubaids, $questions, $questionstats, $reporturl, $whichtries = question_attempt::LAST_TRY) { foreach ($questions as $slot => $question) { if (question_bank::get_qtype( $question->qtype, false)->can_analyse_responses() ) { if ($questionstats->for_slot($slot)->get_variants()) { foreach ($questionstats->for_slot($slot)->get_variants() as $variantno) { $this->output_individual_question_response_analysis($question, $variantno, $questionstats->for_slot($slot, $variantno)->s, $reporturl, $qubaids, $whichtries); } } else { $this->output_individual_question_response_analysis($question, null, $questionstats->for_slot($slot)->s, $reporturl, $qubaids, $whichtries); } } else if ($subqids = $questionstats->for_slot($slot)->get_sub_question_ids()) { foreach ($subqids as $subqid) { if ($variants = $questionstats->for_subq($subqid)->get_variants()) { foreach ($variants as $variantno) { $this->output_individual_question_response_analysis( $questionstats->for_subq($subqid, $variantno)->question, $variantno, $questionstats->for_subq($subqid, $variantno)->s, $reporturl, $qubaids, $whichtries); } } else { $this->output_individual_question_response_analysis( $questionstats->for_subq($subqid)->question, null, $questionstats->for_subq($subqid)->s, $reporturl, $qubaids, $whichtries); } } } } }
[ "protected", "function", "output_all_question_response_analysis", "(", "$", "qubaids", ",", "$", "questions", ",", "$", "questionstats", ",", "$", "reporturl", ",", "$", "whichtries", "=", "question_attempt", "::", "LAST_TRY", ")", "{", "foreach", "(", "$", "questions", "as", "$", "slot", "=>", "$", "question", ")", "{", "if", "(", "question_bank", "::", "get_qtype", "(", "$", "question", "->", "qtype", ",", "false", ")", "->", "can_analyse_responses", "(", ")", ")", "{", "if", "(", "$", "questionstats", "->", "for_slot", "(", "$", "slot", ")", "->", "get_variants", "(", ")", ")", "{", "foreach", "(", "$", "questionstats", "->", "for_slot", "(", "$", "slot", ")", "->", "get_variants", "(", ")", "as", "$", "variantno", ")", "{", "$", "this", "->", "output_individual_question_response_analysis", "(", "$", "question", ",", "$", "variantno", ",", "$", "questionstats", "->", "for_slot", "(", "$", "slot", ",", "$", "variantno", ")", "->", "s", ",", "$", "reporturl", ",", "$", "qubaids", ",", "$", "whichtries", ")", ";", "}", "}", "else", "{", "$", "this", "->", "output_individual_question_response_analysis", "(", "$", "question", ",", "null", ",", "$", "questionstats", "->", "for_slot", "(", "$", "slot", ")", "->", "s", ",", "$", "reporturl", ",", "$", "qubaids", ",", "$", "whichtries", ")", ";", "}", "}", "else", "if", "(", "$", "subqids", "=", "$", "questionstats", "->", "for_slot", "(", "$", "slot", ")", "->", "get_sub_question_ids", "(", ")", ")", "{", "foreach", "(", "$", "subqids", "as", "$", "subqid", ")", "{", "if", "(", "$", "variants", "=", "$", "questionstats", "->", "for_subq", "(", "$", "subqid", ")", "->", "get_variants", "(", ")", ")", "{", "foreach", "(", "$", "variants", "as", "$", "variantno", ")", "{", "$", "this", "->", "output_individual_question_response_analysis", "(", "$", "questionstats", "->", "for_subq", "(", "$", "subqid", ",", "$", "variantno", ")", "->", "question", ",", "$", "variantno", ",", "$", "questionstats", "->", "for_subq", "(", "$", "subqid", ",", "$", "variantno", ")", "->", "s", ",", "$", "reporturl", ",", "$", "qubaids", ",", "$", "whichtries", ")", ";", "}", "}", "else", "{", "$", "this", "->", "output_individual_question_response_analysis", "(", "$", "questionstats", "->", "for_subq", "(", "$", "subqid", ")", "->", "question", ",", "null", ",", "$", "questionstats", "->", "for_subq", "(", "$", "subqid", ")", "->", "s", ",", "$", "reporturl", ",", "$", "qubaids", ",", "$", "whichtries", ")", ";", "}", "}", "}", "}", "}" ]
Output all response analysis for all questions, sub-questions and variants. For download in a number of formats. @param $qubaids @param $questions @param $questionstats @param $reporturl @param $whichtries string
[ "Output", "all", "response", "analysis", "for", "all", "questions", "sub", "-", "questions", "and", "variants", ".", "For", "download", "in", "a", "number", "of", "formats", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/report.php#L857-L908
216,287
moodle/moodle
mod/choice/classes/privacy/provider.php
provider.export_choice_data_for_user
protected static function export_choice_data_for_user(array $choicedata, \context_module $context, \stdClass $user) { // Fetch the generic module data for the choice. $contextdata = helper::get_context_data($context, $user); // Merge with choice data and write it. $contextdata = (object)array_merge((array)$contextdata, $choicedata); writer::with_context($context)->export_data([], $contextdata); // Write generic module intro files. helper::export_context_files($context, $user); }
php
protected static function export_choice_data_for_user(array $choicedata, \context_module $context, \stdClass $user) { // Fetch the generic module data for the choice. $contextdata = helper::get_context_data($context, $user); // Merge with choice data and write it. $contextdata = (object)array_merge((array)$contextdata, $choicedata); writer::with_context($context)->export_data([], $contextdata); // Write generic module intro files. helper::export_context_files($context, $user); }
[ "protected", "static", "function", "export_choice_data_for_user", "(", "array", "$", "choicedata", ",", "\\", "context_module", "$", "context", ",", "\\", "stdClass", "$", "user", ")", "{", "// Fetch the generic module data for the choice.", "$", "contextdata", "=", "helper", "::", "get_context_data", "(", "$", "context", ",", "$", "user", ")", ";", "// Merge with choice data and write it.", "$", "contextdata", "=", "(", "object", ")", "array_merge", "(", "(", "array", ")", "$", "contextdata", ",", "$", "choicedata", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "[", "]", ",", "$", "contextdata", ")", ";", "// Write generic module intro files.", "helper", "::", "export_context_files", "(", "$", "context", ",", "$", "user", ")", ";", "}" ]
Export the supplied personal data for a single choice activity, along with any generic data or area files. @param array $choicedata the personal data to export for the choice. @param \context_module $context the context of the choice. @param \stdClass $user the user record
[ "Export", "the", "supplied", "personal", "data", "for", "a", "single", "choice", "activity", "along", "with", "any", "generic", "data", "or", "area", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/choice/classes/privacy/provider.php#L200-L210
216,288
moodle/moodle
lib/spout/src/Spout/Writer/XLSX/Internal/Workbook.php
Workbook.close
public function close($finalFilePointer) { /** @var Worksheet[] $worksheets */ $worksheets = $this->worksheets; foreach ($worksheets as $worksheet) { $worksheet->close(); } $this->sharedStringsHelper->close(); // Finish creating all the necessary files before zipping everything together $this->fileSystemHelper ->createContentTypesFile($worksheets) ->createWorkbookFile($worksheets) ->createWorkbookRelsFile($worksheets) ->createStylesFile($this->styleHelper) ->zipRootFolderAndCopyToStream($finalFilePointer); $this->cleanupTempFolder(); }
php
public function close($finalFilePointer) { /** @var Worksheet[] $worksheets */ $worksheets = $this->worksheets; foreach ($worksheets as $worksheet) { $worksheet->close(); } $this->sharedStringsHelper->close(); // Finish creating all the necessary files before zipping everything together $this->fileSystemHelper ->createContentTypesFile($worksheets) ->createWorkbookFile($worksheets) ->createWorkbookRelsFile($worksheets) ->createStylesFile($this->styleHelper) ->zipRootFolderAndCopyToStream($finalFilePointer); $this->cleanupTempFolder(); }
[ "public", "function", "close", "(", "$", "finalFilePointer", ")", "{", "/** @var Worksheet[] $worksheets */", "$", "worksheets", "=", "$", "this", "->", "worksheets", ";", "foreach", "(", "$", "worksheets", "as", "$", "worksheet", ")", "{", "$", "worksheet", "->", "close", "(", ")", ";", "}", "$", "this", "->", "sharedStringsHelper", "->", "close", "(", ")", ";", "// Finish creating all the necessary files before zipping everything together", "$", "this", "->", "fileSystemHelper", "->", "createContentTypesFile", "(", "$", "worksheets", ")", "->", "createWorkbookFile", "(", "$", "worksheets", ")", "->", "createWorkbookRelsFile", "(", "$", "worksheets", ")", "->", "createStylesFile", "(", "$", "this", "->", "styleHelper", ")", "->", "zipRootFolderAndCopyToStream", "(", "$", "finalFilePointer", ")", ";", "$", "this", "->", "cleanupTempFolder", "(", ")", ";", "}" ]
Closes the workbook and all its associated sheets. All the necessary files are written to disk and zipped together to create the XLSX file. All the temporary files are then deleted. @param resource $finalFilePointer Pointer to the XLSX that will be created @return void
[ "Closes", "the", "workbook", "and", "all", "its", "associated", "sheets", ".", "All", "the", "necessary", "files", "are", "written", "to", "disk", "and", "zipped", "together", "to", "create", "the", "XLSX", "file", ".", "All", "the", "temporary", "files", "are", "then", "deleted", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/XLSX/Internal/Workbook.php#L103-L123
216,289
moodle/moodle
admin/tool/dataprivacy/classes/external/purpose_exporter.php
purpose_exporter.get_other_values
protected function get_other_values(renderer_base $output) { $values = []; $formattedbases = []; $lawfulbases = explode(',', $this->persistent->get('lawfulbases')); if (!empty($lawfulbases)) { foreach ($lawfulbases as $basis) { if (empty(trim($basis))) { continue; } $formattedbases[] = (object)[ 'name' => get_string($basis . '_name', 'tool_dataprivacy'), 'description' => get_string($basis . '_description', 'tool_dataprivacy') ]; } } $values['formattedlawfulbases'] = $formattedbases; $formattedsensitivereasons = []; $sensitivereasons = explode(',', $this->persistent->get('sensitivedatareasons')); if (!empty($sensitivereasons)) { foreach ($sensitivereasons as $reason) { if (empty(trim($reason))) { continue; } $formattedsensitivereasons[] = (object)[ 'name' => get_string($reason . '_name', 'tool_dataprivacy'), 'description' => get_string($reason . '_description', 'tool_dataprivacy') ]; } } $values['formattedsensitivedatareasons'] = $formattedsensitivereasons; $retentionperiod = $this->persistent->get('retentionperiod'); if ($retentionperiod) { $formattedtime = \tool_dataprivacy\api::format_retention_period(new \DateInterval($retentionperiod)); } else { $formattedtime = get_string('retentionperiodnotdefined', 'tool_dataprivacy'); } $values['formattedretentionperiod'] = $formattedtime; $values['roleoverrides'] = !empty($this->persistent->get_purpose_overrides()); return $values; }
php
protected function get_other_values(renderer_base $output) { $values = []; $formattedbases = []; $lawfulbases = explode(',', $this->persistent->get('lawfulbases')); if (!empty($lawfulbases)) { foreach ($lawfulbases as $basis) { if (empty(trim($basis))) { continue; } $formattedbases[] = (object)[ 'name' => get_string($basis . '_name', 'tool_dataprivacy'), 'description' => get_string($basis . '_description', 'tool_dataprivacy') ]; } } $values['formattedlawfulbases'] = $formattedbases; $formattedsensitivereasons = []; $sensitivereasons = explode(',', $this->persistent->get('sensitivedatareasons')); if (!empty($sensitivereasons)) { foreach ($sensitivereasons as $reason) { if (empty(trim($reason))) { continue; } $formattedsensitivereasons[] = (object)[ 'name' => get_string($reason . '_name', 'tool_dataprivacy'), 'description' => get_string($reason . '_description', 'tool_dataprivacy') ]; } } $values['formattedsensitivedatareasons'] = $formattedsensitivereasons; $retentionperiod = $this->persistent->get('retentionperiod'); if ($retentionperiod) { $formattedtime = \tool_dataprivacy\api::format_retention_period(new \DateInterval($retentionperiod)); } else { $formattedtime = get_string('retentionperiodnotdefined', 'tool_dataprivacy'); } $values['formattedretentionperiod'] = $formattedtime; $values['roleoverrides'] = !empty($this->persistent->get_purpose_overrides()); return $values; }
[ "protected", "function", "get_other_values", "(", "renderer_base", "$", "output", ")", "{", "$", "values", "=", "[", "]", ";", "$", "formattedbases", "=", "[", "]", ";", "$", "lawfulbases", "=", "explode", "(", "','", ",", "$", "this", "->", "persistent", "->", "get", "(", "'lawfulbases'", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "lawfulbases", ")", ")", "{", "foreach", "(", "$", "lawfulbases", "as", "$", "basis", ")", "{", "if", "(", "empty", "(", "trim", "(", "$", "basis", ")", ")", ")", "{", "continue", ";", "}", "$", "formattedbases", "[", "]", "=", "(", "object", ")", "[", "'name'", "=>", "get_string", "(", "$", "basis", ".", "'_name'", ",", "'tool_dataprivacy'", ")", ",", "'description'", "=>", "get_string", "(", "$", "basis", ".", "'_description'", ",", "'tool_dataprivacy'", ")", "]", ";", "}", "}", "$", "values", "[", "'formattedlawfulbases'", "]", "=", "$", "formattedbases", ";", "$", "formattedsensitivereasons", "=", "[", "]", ";", "$", "sensitivereasons", "=", "explode", "(", "','", ",", "$", "this", "->", "persistent", "->", "get", "(", "'sensitivedatareasons'", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "sensitivereasons", ")", ")", "{", "foreach", "(", "$", "sensitivereasons", "as", "$", "reason", ")", "{", "if", "(", "empty", "(", "trim", "(", "$", "reason", ")", ")", ")", "{", "continue", ";", "}", "$", "formattedsensitivereasons", "[", "]", "=", "(", "object", ")", "[", "'name'", "=>", "get_string", "(", "$", "reason", ".", "'_name'", ",", "'tool_dataprivacy'", ")", ",", "'description'", "=>", "get_string", "(", "$", "reason", ".", "'_description'", ",", "'tool_dataprivacy'", ")", "]", ";", "}", "}", "$", "values", "[", "'formattedsensitivedatareasons'", "]", "=", "$", "formattedsensitivereasons", ";", "$", "retentionperiod", "=", "$", "this", "->", "persistent", "->", "get", "(", "'retentionperiod'", ")", ";", "if", "(", "$", "retentionperiod", ")", "{", "$", "formattedtime", "=", "\\", "tool_dataprivacy", "\\", "api", "::", "format_retention_period", "(", "new", "\\", "DateInterval", "(", "$", "retentionperiod", ")", ")", ";", "}", "else", "{", "$", "formattedtime", "=", "get_string", "(", "'retentionperiodnotdefined'", ",", "'tool_dataprivacy'", ")", ";", "}", "$", "values", "[", "'formattedretentionperiod'", "]", "=", "$", "formattedtime", ";", "$", "values", "[", "'roleoverrides'", "]", "=", "!", "empty", "(", "$", "this", "->", "persistent", "->", "get_purpose_overrides", "(", ")", ")", ";", "return", "$", "values", ";", "}" ]
Return other properties. @param renderer_base $output @return array @throws coding_exception @throws Exception
[ "Return", "other", "properties", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/external/purpose_exporter.php#L95-L139
216,290
moodle/moodle
admin/tool/dataprivacy/classes/external/purpose_exporter.php
purpose_exporter.get_name
public static function get_name($purposeid) { global $PAGE; if ($purposeid === false || $purposeid == context_instance::INHERIT) { return get_string('inherit', 'tool_dataprivacy'); } else if ($purposeid == context_instance::NOTSET) { return get_string('notset', 'tool_dataprivacy'); } else { $purpose = new purpose($purposeid); $output = $PAGE->get_renderer('tool_dataprivacy'); $exporter = new self($purpose, ['context' => \context_system::instance()]); $data = $exporter->export($output); return $data->name; } }
php
public static function get_name($purposeid) { global $PAGE; if ($purposeid === false || $purposeid == context_instance::INHERIT) { return get_string('inherit', 'tool_dataprivacy'); } else if ($purposeid == context_instance::NOTSET) { return get_string('notset', 'tool_dataprivacy'); } else { $purpose = new purpose($purposeid); $output = $PAGE->get_renderer('tool_dataprivacy'); $exporter = new self($purpose, ['context' => \context_system::instance()]); $data = $exporter->export($output); return $data->name; } }
[ "public", "static", "function", "get_name", "(", "$", "purposeid", ")", "{", "global", "$", "PAGE", ";", "if", "(", "$", "purposeid", "===", "false", "||", "$", "purposeid", "==", "context_instance", "::", "INHERIT", ")", "{", "return", "get_string", "(", "'inherit'", ",", "'tool_dataprivacy'", ")", ";", "}", "else", "if", "(", "$", "purposeid", "==", "context_instance", "::", "NOTSET", ")", "{", "return", "get_string", "(", "'notset'", ",", "'tool_dataprivacy'", ")", ";", "}", "else", "{", "$", "purpose", "=", "new", "purpose", "(", "$", "purposeid", ")", ";", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'tool_dataprivacy'", ")", ";", "$", "exporter", "=", "new", "self", "(", "$", "purpose", ",", "[", "'context'", "=>", "\\", "context_system", "::", "instance", "(", ")", "]", ")", ";", "$", "data", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "return", "$", "data", "->", "name", ";", "}", "}" ]
Utility function that fetches a purpose name from the given ID. @param int $purposeid The purpose ID. Could be INHERIT (false, -1), NOT_SET (0), or the actual ID. @return string The purpose name.
[ "Utility", "function", "that", "fetches", "a", "purpose", "name", "from", "the", "given", "ID", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/external/purpose_exporter.php#L147-L160
216,291
moodle/moodle
admin/tool/installaddon/classes/installer.php
tool_installaddon_installer.get_addons_repository_url
public function get_addons_repository_url() { global $CFG; if (!empty($CFG->config_php_settings['alternativeaddonsrepositoryurl'])) { $url = $CFG->config_php_settings['alternativeaddonsrepositoryurl']; } else { $url = 'https://moodle.org/plugins/get.php'; } if (!$this->should_send_site_info()) { return new moodle_url($url); } // Append the basic information about our site. $site = array( 'fullname' => $this->get_site_fullname(), 'url' => $this->get_site_url(), 'majorversion' => $this->get_site_major_version(), ); $site = $this->encode_site_information($site); return new moodle_url($url, array('site' => $site)); }
php
public function get_addons_repository_url() { global $CFG; if (!empty($CFG->config_php_settings['alternativeaddonsrepositoryurl'])) { $url = $CFG->config_php_settings['alternativeaddonsrepositoryurl']; } else { $url = 'https://moodle.org/plugins/get.php'; } if (!$this->should_send_site_info()) { return new moodle_url($url); } // Append the basic information about our site. $site = array( 'fullname' => $this->get_site_fullname(), 'url' => $this->get_site_url(), 'majorversion' => $this->get_site_major_version(), ); $site = $this->encode_site_information($site); return new moodle_url($url, array('site' => $site)); }
[ "public", "function", "get_addons_repository_url", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "config_php_settings", "[", "'alternativeaddonsrepositoryurl'", "]", ")", ")", "{", "$", "url", "=", "$", "CFG", "->", "config_php_settings", "[", "'alternativeaddonsrepositoryurl'", "]", ";", "}", "else", "{", "$", "url", "=", "'https://moodle.org/plugins/get.php'", ";", "}", "if", "(", "!", "$", "this", "->", "should_send_site_info", "(", ")", ")", "{", "return", "new", "moodle_url", "(", "$", "url", ")", ";", "}", "// Append the basic information about our site.", "$", "site", "=", "array", "(", "'fullname'", "=>", "$", "this", "->", "get_site_fullname", "(", ")", ",", "'url'", "=>", "$", "this", "->", "get_site_url", "(", ")", ",", "'majorversion'", "=>", "$", "this", "->", "get_site_major_version", "(", ")", ",", ")", ";", "$", "site", "=", "$", "this", "->", "encode_site_information", "(", "$", "site", ")", ";", "return", "new", "moodle_url", "(", "$", "url", ",", "array", "(", "'site'", "=>", "$", "site", ")", ")", ";", "}" ]
Returns URL to the repository that addons can be searched in and installed from @return moodle_url
[ "Returns", "URL", "to", "the", "repository", "that", "addons", "can", "be", "searched", "in", "and", "installed", "from" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/classes/installer.php#L64-L87
216,292
moodle/moodle
admin/tool/installaddon/classes/installer.php
tool_installaddon_installer.get_plugin_types_menu
public function get_plugin_types_menu() { global $CFG; $pluginman = core_plugin_manager::instance(); $menu = array('' => get_string('choosedots')); foreach (array_keys($pluginman->get_plugin_types()) as $plugintype) { $menu[$plugintype] = $pluginman->plugintype_name($plugintype).' ('.$plugintype.')'; } return $menu; }
php
public function get_plugin_types_menu() { global $CFG; $pluginman = core_plugin_manager::instance(); $menu = array('' => get_string('choosedots')); foreach (array_keys($pluginman->get_plugin_types()) as $plugintype) { $menu[$plugintype] = $pluginman->plugintype_name($plugintype).' ('.$plugintype.')'; } return $menu; }
[ "public", "function", "get_plugin_types_menu", "(", ")", "{", "global", "$", "CFG", ";", "$", "pluginman", "=", "core_plugin_manager", "::", "instance", "(", ")", ";", "$", "menu", "=", "array", "(", "''", "=>", "get_string", "(", "'choosedots'", ")", ")", ";", "foreach", "(", "array_keys", "(", "$", "pluginman", "->", "get_plugin_types", "(", ")", ")", "as", "$", "plugintype", ")", "{", "$", "menu", "[", "$", "plugintype", "]", "=", "$", "pluginman", "->", "plugintype_name", "(", "$", "plugintype", ")", ".", "' ('", ".", "$", "plugintype", ".", "')'", ";", "}", "return", "$", "menu", ";", "}" ]
Returns localised list of available plugin types @return array (string)plugintype => (string)plugin name
[ "Returns", "localised", "list", "of", "available", "plugin", "types" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/classes/installer.php#L123-L134
216,293
moodle/moodle
admin/tool/installaddon/classes/installer.php
tool_installaddon_installer.handle_remote_request
public function handle_remote_request(tool_installaddon_renderer $output, $request) { if (is_null($request)) { return; } $data = $this->decode_remote_request($request); if ($data === false) { echo $output->remote_request_invalid_page($this->index_url()); exit(); } list($plugintype, $pluginname) = core_component::normalize_component($data->component); $pluginman = core_plugin_manager::instance(); $plugintypepath = $pluginman->get_plugintype_root($plugintype); if (file_exists($plugintypepath.'/'.$pluginname)) { echo $output->remote_request_alreadyinstalled_page($data, $this->index_url()); exit(); } if (!$pluginman->is_plugintype_writable($plugintype)) { $continueurl = $this->index_url(array('installaddonrequest' => $request)); echo $output->remote_request_permcheck_page($data, $plugintypepath, $continueurl, $this->index_url()); exit(); } if (!$pluginman->is_remote_plugin_installable($data->component, $data->version, $reason)) { $data->reason = $reason; echo $output->remote_request_non_installable_page($data, $this->index_url()); exit(); } $continueurl = $this->index_url(array( 'installremote' => $data->component, 'installremoteversion' => $data->version )); echo $output->remote_request_confirm_page($data, $continueurl, $this->index_url()); exit(); }
php
public function handle_remote_request(tool_installaddon_renderer $output, $request) { if (is_null($request)) { return; } $data = $this->decode_remote_request($request); if ($data === false) { echo $output->remote_request_invalid_page($this->index_url()); exit(); } list($plugintype, $pluginname) = core_component::normalize_component($data->component); $pluginman = core_plugin_manager::instance(); $plugintypepath = $pluginman->get_plugintype_root($plugintype); if (file_exists($plugintypepath.'/'.$pluginname)) { echo $output->remote_request_alreadyinstalled_page($data, $this->index_url()); exit(); } if (!$pluginman->is_plugintype_writable($plugintype)) { $continueurl = $this->index_url(array('installaddonrequest' => $request)); echo $output->remote_request_permcheck_page($data, $plugintypepath, $continueurl, $this->index_url()); exit(); } if (!$pluginman->is_remote_plugin_installable($data->component, $data->version, $reason)) { $data->reason = $reason; echo $output->remote_request_non_installable_page($data, $this->index_url()); exit(); } $continueurl = $this->index_url(array( 'installremote' => $data->component, 'installremoteversion' => $data->version )); echo $output->remote_request_confirm_page($data, $continueurl, $this->index_url()); exit(); }
[ "public", "function", "handle_remote_request", "(", "tool_installaddon_renderer", "$", "output", ",", "$", "request", ")", "{", "if", "(", "is_null", "(", "$", "request", ")", ")", "{", "return", ";", "}", "$", "data", "=", "$", "this", "->", "decode_remote_request", "(", "$", "request", ")", ";", "if", "(", "$", "data", "===", "false", ")", "{", "echo", "$", "output", "->", "remote_request_invalid_page", "(", "$", "this", "->", "index_url", "(", ")", ")", ";", "exit", "(", ")", ";", "}", "list", "(", "$", "plugintype", ",", "$", "pluginname", ")", "=", "core_component", "::", "normalize_component", "(", "$", "data", "->", "component", ")", ";", "$", "pluginman", "=", "core_plugin_manager", "::", "instance", "(", ")", ";", "$", "plugintypepath", "=", "$", "pluginman", "->", "get_plugintype_root", "(", "$", "plugintype", ")", ";", "if", "(", "file_exists", "(", "$", "plugintypepath", ".", "'/'", ".", "$", "pluginname", ")", ")", "{", "echo", "$", "output", "->", "remote_request_alreadyinstalled_page", "(", "$", "data", ",", "$", "this", "->", "index_url", "(", ")", ")", ";", "exit", "(", ")", ";", "}", "if", "(", "!", "$", "pluginman", "->", "is_plugintype_writable", "(", "$", "plugintype", ")", ")", "{", "$", "continueurl", "=", "$", "this", "->", "index_url", "(", "array", "(", "'installaddonrequest'", "=>", "$", "request", ")", ")", ";", "echo", "$", "output", "->", "remote_request_permcheck_page", "(", "$", "data", ",", "$", "plugintypepath", ",", "$", "continueurl", ",", "$", "this", "->", "index_url", "(", ")", ")", ";", "exit", "(", ")", ";", "}", "if", "(", "!", "$", "pluginman", "->", "is_remote_plugin_installable", "(", "$", "data", "->", "component", ",", "$", "data", "->", "version", ",", "$", "reason", ")", ")", "{", "$", "data", "->", "reason", "=", "$", "reason", ";", "echo", "$", "output", "->", "remote_request_non_installable_page", "(", "$", "data", ",", "$", "this", "->", "index_url", "(", ")", ")", ";", "exit", "(", ")", ";", "}", "$", "continueurl", "=", "$", "this", "->", "index_url", "(", "array", "(", "'installremote'", "=>", "$", "data", "->", "component", ",", "'installremoteversion'", "=>", "$", "data", "->", "version", ")", ")", ";", "echo", "$", "output", "->", "remote_request_confirm_page", "(", "$", "data", ",", "$", "continueurl", ",", "$", "this", "->", "index_url", "(", ")", ")", ";", "exit", "(", ")", ";", "}" ]
Hook method to handle the remote request to install an add-on This is used as a callback when the admin picks a plugin version in the Moodle Plugins directory and is redirected back to their site to install it. This hook is called early from admin/tool/installaddon/index.php page so that it has opportunity to take over the UI and display the first confirmation screen. @param tool_installaddon_renderer $output @param string|null $request
[ "Hook", "method", "to", "handle", "the", "remote", "request", "to", "install", "an", "add", "-", "on" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/classes/installer.php#L149-L191
216,294
moodle/moodle
admin/tool/installaddon/classes/installer.php
tool_installaddon_installer.detect_plugin_component
public function detect_plugin_component($zipfilepath) { $workdir = make_request_directory(); $versionphp = $this->extract_versionphp_file($zipfilepath, $workdir); if (empty($versionphp)) { return false; } return $this->detect_plugin_component_from_versionphp(file_get_contents($workdir.'/'.$versionphp)); }
php
public function detect_plugin_component($zipfilepath) { $workdir = make_request_directory(); $versionphp = $this->extract_versionphp_file($zipfilepath, $workdir); if (empty($versionphp)) { return false; } return $this->detect_plugin_component_from_versionphp(file_get_contents($workdir.'/'.$versionphp)); }
[ "public", "function", "detect_plugin_component", "(", "$", "zipfilepath", ")", "{", "$", "workdir", "=", "make_request_directory", "(", ")", ";", "$", "versionphp", "=", "$", "this", "->", "extract_versionphp_file", "(", "$", "zipfilepath", ",", "$", "workdir", ")", ";", "if", "(", "empty", "(", "$", "versionphp", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "detect_plugin_component_from_versionphp", "(", "file_get_contents", "(", "$", "workdir", ".", "'/'", ".", "$", "versionphp", ")", ")", ";", "}" ]
Detect the given plugin's component name Only plugins that declare valid $plugin->component value in the version.php are supported. @param string $zipfilepath full path to the saved ZIP file @return string|bool declared component name or false if unable to detect
[ "Detect", "the", "given", "plugin", "s", "component", "name" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/classes/installer.php#L202-L212
216,295
moodle/moodle
admin/tool/installaddon/classes/installer.php
tool_installaddon_installer.decode_remote_request
protected function decode_remote_request($request) { $data = base64_decode($request, true); if ($data === false) { return false; } $data = json_decode($data); if (is_null($data)) { return false; } if (!isset($data->name) or !isset($data->component) or !isset($data->version)) { return false; } $data->name = s(strip_tags($data->name)); if ($data->component !== clean_param($data->component, PARAM_COMPONENT)) { return false; } list($plugintype, $pluginname) = core_component::normalize_component($data->component); if ($plugintype === 'core') { return false; } if ($data->component !== $plugintype.'_'.$pluginname) { return false; } if (!core_component::is_valid_plugin_name($plugintype, $pluginname)) { return false; } $plugintypes = core_component::get_plugin_types(); if (!isset($plugintypes[$plugintype])) { return false; } // Keep this regex in sync with the one used by the download.moodle.org/api/x.y/pluginfo.php if (!preg_match('/^[0-9]+$/', $data->version)) { return false; } return $data; }
php
protected function decode_remote_request($request) { $data = base64_decode($request, true); if ($data === false) { return false; } $data = json_decode($data); if (is_null($data)) { return false; } if (!isset($data->name) or !isset($data->component) or !isset($data->version)) { return false; } $data->name = s(strip_tags($data->name)); if ($data->component !== clean_param($data->component, PARAM_COMPONENT)) { return false; } list($plugintype, $pluginname) = core_component::normalize_component($data->component); if ($plugintype === 'core') { return false; } if ($data->component !== $plugintype.'_'.$pluginname) { return false; } if (!core_component::is_valid_plugin_name($plugintype, $pluginname)) { return false; } $plugintypes = core_component::get_plugin_types(); if (!isset($plugintypes[$plugintype])) { return false; } // Keep this regex in sync with the one used by the download.moodle.org/api/x.y/pluginfo.php if (!preg_match('/^[0-9]+$/', $data->version)) { return false; } return $data; }
[ "protected", "function", "decode_remote_request", "(", "$", "request", ")", "{", "$", "data", "=", "base64_decode", "(", "$", "request", ",", "true", ")", ";", "if", "(", "$", "data", "===", "false", ")", "{", "return", "false", ";", "}", "$", "data", "=", "json_decode", "(", "$", "data", ")", ";", "if", "(", "is_null", "(", "$", "data", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "isset", "(", "$", "data", "->", "name", ")", "or", "!", "isset", "(", "$", "data", "->", "component", ")", "or", "!", "isset", "(", "$", "data", "->", "version", ")", ")", "{", "return", "false", ";", "}", "$", "data", "->", "name", "=", "s", "(", "strip_tags", "(", "$", "data", "->", "name", ")", ")", ";", "if", "(", "$", "data", "->", "component", "!==", "clean_param", "(", "$", "data", "->", "component", ",", "PARAM_COMPONENT", ")", ")", "{", "return", "false", ";", "}", "list", "(", "$", "plugintype", ",", "$", "pluginname", ")", "=", "core_component", "::", "normalize_component", "(", "$", "data", "->", "component", ")", ";", "if", "(", "$", "plugintype", "===", "'core'", ")", "{", "return", "false", ";", "}", "if", "(", "$", "data", "->", "component", "!==", "$", "plugintype", ".", "'_'", ".", "$", "pluginname", ")", "{", "return", "false", ";", "}", "if", "(", "!", "core_component", "::", "is_valid_plugin_name", "(", "$", "plugintype", ",", "$", "pluginname", ")", ")", "{", "return", "false", ";", "}", "$", "plugintypes", "=", "core_component", "::", "get_plugin_types", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "plugintypes", "[", "$", "plugintype", "]", ")", ")", "{", "return", "false", ";", "}", "// Keep this regex in sync with the one used by the download.moodle.org/api/x.y/pluginfo.php", "if", "(", "!", "preg_match", "(", "'/^[0-9]+$/'", ",", "$", "data", "->", "version", ")", ")", "{", "return", "false", ";", "}", "return", "$", "data", ";", "}" ]
Decode the request from the Moodle Plugins directory @param string $request submitted via 'installaddonrequest' HTTP parameter @return stdClass|bool false on error, object otherwise
[ "Decode", "the", "request", "from", "the", "Moodle", "Plugins", "directory" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/classes/installer.php#L279-L328
216,296
moodle/moodle
admin/tool/installaddon/classes/installer.php
tool_installaddon_installer.extract_versionphp_file
protected function extract_versionphp_file($zipfilepath, $targetdir) { global $CFG; require_once($CFG->libdir.'/filelib.php'); $fp = get_file_packer('application/zip'); $files = $fp->list_files($zipfilepath); if (empty($files)) { return false; } $rootdirname = null; $found = null; foreach ($files as $file) { // Valid plugin ZIP package has just one root directory with all // files in it. $pathnameitems = explode('/', $file->pathname); if (empty($pathnameitems)) { return false; } // Set the expected name of the root directory in the first // iteration of the loop. if ($rootdirname === null) { $rootdirname = $pathnameitems[0]; } // Require the same root directory for all files in the ZIP // package. if ($rootdirname !== $pathnameitems[0]) { return false; } // If we reached the valid version.php file, remember it. if ($pathnameitems[1] === 'version.php' and !$file->is_directory and $file->size > 0) { $found = $file->pathname; } } if (empty($found)) { return false; } $extracted = $fp->extract_to_pathname($zipfilepath, $targetdir, array($found)); if (empty($extracted)) { return false; } // The following syntax uses function array dereferencing, added in PHP 5.4.0. return array_keys($extracted)[0]; }
php
protected function extract_versionphp_file($zipfilepath, $targetdir) { global $CFG; require_once($CFG->libdir.'/filelib.php'); $fp = get_file_packer('application/zip'); $files = $fp->list_files($zipfilepath); if (empty($files)) { return false; } $rootdirname = null; $found = null; foreach ($files as $file) { // Valid plugin ZIP package has just one root directory with all // files in it. $pathnameitems = explode('/', $file->pathname); if (empty($pathnameitems)) { return false; } // Set the expected name of the root directory in the first // iteration of the loop. if ($rootdirname === null) { $rootdirname = $pathnameitems[0]; } // Require the same root directory for all files in the ZIP // package. if ($rootdirname !== $pathnameitems[0]) { return false; } // If we reached the valid version.php file, remember it. if ($pathnameitems[1] === 'version.php' and !$file->is_directory and $file->size > 0) { $found = $file->pathname; } } if (empty($found)) { return false; } $extracted = $fp->extract_to_pathname($zipfilepath, $targetdir, array($found)); if (empty($extracted)) { return false; } // The following syntax uses function array dereferencing, added in PHP 5.4.0. return array_keys($extracted)[0]; }
[ "protected", "function", "extract_versionphp_file", "(", "$", "zipfilepath", ",", "$", "targetdir", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/filelib.php'", ")", ";", "$", "fp", "=", "get_file_packer", "(", "'application/zip'", ")", ";", "$", "files", "=", "$", "fp", "->", "list_files", "(", "$", "zipfilepath", ")", ";", "if", "(", "empty", "(", "$", "files", ")", ")", "{", "return", "false", ";", "}", "$", "rootdirname", "=", "null", ";", "$", "found", "=", "null", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "// Valid plugin ZIP package has just one root directory with all", "// files in it.", "$", "pathnameitems", "=", "explode", "(", "'/'", ",", "$", "file", "->", "pathname", ")", ";", "if", "(", "empty", "(", "$", "pathnameitems", ")", ")", "{", "return", "false", ";", "}", "// Set the expected name of the root directory in the first", "// iteration of the loop.", "if", "(", "$", "rootdirname", "===", "null", ")", "{", "$", "rootdirname", "=", "$", "pathnameitems", "[", "0", "]", ";", "}", "// Require the same root directory for all files in the ZIP", "// package.", "if", "(", "$", "rootdirname", "!==", "$", "pathnameitems", "[", "0", "]", ")", "{", "return", "false", ";", "}", "// If we reached the valid version.php file, remember it.", "if", "(", "$", "pathnameitems", "[", "1", "]", "===", "'version.php'", "and", "!", "$", "file", "->", "is_directory", "and", "$", "file", "->", "size", ">", "0", ")", "{", "$", "found", "=", "$", "file", "->", "pathname", ";", "}", "}", "if", "(", "empty", "(", "$", "found", ")", ")", "{", "return", "false", ";", "}", "$", "extracted", "=", "$", "fp", "->", "extract_to_pathname", "(", "$", "zipfilepath", ",", "$", "targetdir", ",", "array", "(", "$", "found", ")", ")", ";", "if", "(", "empty", "(", "$", "extracted", ")", ")", "{", "return", "false", ";", "}", "// The following syntax uses function array dereferencing, added in PHP 5.4.0.", "return", "array_keys", "(", "$", "extracted", ")", "[", "0", "]", ";", "}" ]
Extracts the version.php from the given plugin ZIP file into the target directory @param string $zipfilepath full path to the saved ZIP file @param string $targetdir full path to extract the file to @return string|bool path to the version.php within the $targetpath; false on error (e.g. not found)
[ "Extracts", "the", "version", ".", "php", "from", "the", "given", "plugin", "ZIP", "file", "into", "the", "target", "directory" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/classes/installer.php#L337-L390
216,297
moodle/moodle
admin/tool/installaddon/classes/installer.php
tool_installaddon_installer.detect_plugin_component_from_versionphp
protected function detect_plugin_component_from_versionphp($code) { $result = preg_match_all('#^\s*\$plugin\->component\s*=\s*([\'"])(.+?_.+?)\1\s*;#m', $code, $matches); // Return if and only if the single match was detected. if ($result === 1 and !empty($matches[2][0])) { return $matches[2][0]; } return false; }
php
protected function detect_plugin_component_from_versionphp($code) { $result = preg_match_all('#^\s*\$plugin\->component\s*=\s*([\'"])(.+?_.+?)\1\s*;#m', $code, $matches); // Return if and only if the single match was detected. if ($result === 1 and !empty($matches[2][0])) { return $matches[2][0]; } return false; }
[ "protected", "function", "detect_plugin_component_from_versionphp", "(", "$", "code", ")", "{", "$", "result", "=", "preg_match_all", "(", "'#^\\s*\\$plugin\\->component\\s*=\\s*([\\'\"])(.+?_.+?)\\1\\s*;#m'", ",", "$", "code", ",", "$", "matches", ")", ";", "// Return if and only if the single match was detected.", "if", "(", "$", "result", "===", "1", "and", "!", "empty", "(", "$", "matches", "[", "2", "]", "[", "0", "]", ")", ")", "{", "return", "$", "matches", "[", "2", "]", "[", "0", "]", ";", "}", "return", "false", ";", "}" ]
Return the plugin component declared in its version.php file @param string $code the contents of the version.php file @return string|bool declared plugin component or false if unable to detect
[ "Return", "the", "plugin", "component", "declared", "in", "its", "version", ".", "php", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/classes/installer.php#L398-L408
216,298
moodle/moodle
question/classes/external/question_summary_exporter.php
question_summary_exporter.get_mandatory_properties
public static function get_mandatory_properties() { $properties = self::define_properties(); $mandatoryproperties = array_filter($properties, function($property) { return empty($property['optional']); }); return array_keys($mandatoryproperties); }
php
public static function get_mandatory_properties() { $properties = self::define_properties(); $mandatoryproperties = array_filter($properties, function($property) { return empty($property['optional']); }); return array_keys($mandatoryproperties); }
[ "public", "static", "function", "get_mandatory_properties", "(", ")", "{", "$", "properties", "=", "self", "::", "define_properties", "(", ")", ";", "$", "mandatoryproperties", "=", "array_filter", "(", "$", "properties", ",", "function", "(", "$", "property", ")", "{", "return", "empty", "(", "$", "property", "[", "'optional'", "]", ")", ";", "}", ")", ";", "return", "array_keys", "(", "$", "mandatoryproperties", ")", ";", "}" ]
The list of mandatory properties required on the question object to export. @return string[] List of properties.
[ "The", "list", "of", "mandatory", "properties", "required", "on", "the", "question", "object", "to", "export", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/external/question_summary_exporter.php#L68-L74
216,299
moodle/moodle
question/classes/external/question_summary_exporter.php
question_summary_exporter.get_other_values
protected function get_other_values(\renderer_base $output) { $iconexporter = new question_icon_exporter($this->question, $this->related); return [ 'icon' => $iconexporter->export($output), ]; }
php
protected function get_other_values(\renderer_base $output) { $iconexporter = new question_icon_exporter($this->question, $this->related); return [ 'icon' => $iconexporter->export($output), ]; }
[ "protected", "function", "get_other_values", "(", "\\", "renderer_base", "$", "output", ")", "{", "$", "iconexporter", "=", "new", "question_icon_exporter", "(", "$", "this", "->", "question", ",", "$", "this", "->", "related", ")", ";", "return", "[", "'icon'", "=>", "$", "iconexporter", "->", "export", "(", "$", "output", ")", ",", "]", ";", "}" ]
Calculate the values for the properties defined in the define_other_properties function. @param renderer_base $output A renderer. @return array The list of properties.
[ "Calculate", "the", "values", "for", "the", "properties", "defined", "in", "the", "define_other_properties", "function", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/external/question_summary_exporter.php#L121-L127