diff --git a/mod/quiz/accessrule/delaybetweenattempts/rule.php b/mod/quiz/accessrule/delaybetweenattempts/rule.php index f2cf9d1f1fe..bc58d3b74bc 100644 --- a/mod/quiz/accessrule/delaybetweenattempts/rule.php +++ b/mod/quiz/accessrule/delaybetweenattempts/rule.php @@ -59,7 +59,7 @@ class quizaccess_delaybetweenattempts extends access_rule_base { * Compute the next time a student would be allowed to start an attempt, * according to this rule. * @param int $numprevattempts number of previous attempts. - * @param object $lastattempt information about the previous attempt. + * @param stdClass $lastattempt information about the previous attempt. * @return number the time. */ protected function compute_next_start_time($numprevattempts, $lastattempt) { diff --git a/mod/quiz/accessrule/offlineattempts/rule.php b/mod/quiz/accessrule/offlineattempts/rule.php index aaa3fe0053e..4b2b9a1db2c 100644 --- a/mod/quiz/accessrule/offlineattempts/rule.php +++ b/mod/quiz/accessrule/offlineattempts/rule.php @@ -44,7 +44,7 @@ class quizaccess_offlineattempts extends access_rule_base { // First, check if the user did something offline. if (!empty($attemptid)) { - $timemodifiedoffline = $DB->get_field('quiz_attempts', 'timemodifiedoffline', array('id' => $attemptid)); + $timemodifiedoffline = $DB->get_field('quiz_attempts', 'timemodifiedoffline', ['id' => $attemptid]); if (empty($timemodifiedoffline)) { return false; } @@ -59,7 +59,7 @@ class quizaccess_offlineattempts extends access_rule_base { MoodleQuickForm $mform, $attemptid) { global $DB; - $timemodifiedoffline = $DB->get_field('quiz_attempts', 'timemodifiedoffline', array('id' => $attemptid)); + $timemodifiedoffline = $DB->get_field('quiz_attempts', 'timemodifiedoffline', ['id' => $attemptid]); $lasttime = format_time(time() - $timemodifiedoffline); $mform->addElement('header', 'offlineattemptsheader', get_string('mobileapp', 'quizaccess_offlineattempts')); diff --git a/mod/quiz/accessrule/password/rule.php b/mod/quiz/accessrule/password/rule.php index 956fc7b8365..7dc5f24605b 100644 --- a/mod/quiz/accessrule/password/rule.php +++ b/mod/quiz/accessrule/password/rule.php @@ -54,7 +54,7 @@ class quizaccess_password extends access_rule_base { // Don't use the 'proper' field name of 'password' since that get's // Firefox's password auto-complete over-excited. $mform->addElement('password', 'quizpassword', - get_string('quizpassword', 'quizaccess_password'), array('autofocus' => 'true')); + get_string('quizpassword', 'quizaccess_password'), ['autofocus' => 'true']); } public function validate_preflight_check($data, $files, $errors, $attemptid) { diff --git a/mod/quiz/accessrule/seb/classes/event/access_prevented.php b/mod/quiz/accessrule/seb/classes/event/access_prevented.php index f9e919d1a56..03dc8e4629b 100644 --- a/mod/quiz/accessrule/seb/classes/event/access_prevented.php +++ b/mod/quiz/accessrule/seb/classes/event/access_prevented.php @@ -110,7 +110,7 @@ class access_prevented extends base { * @return array Mapping of object id. */ public static function get_objectid_mapping() : array { - return array('db' => 'quiz', 'restore' => 'quiz'); + return ['db' => 'quiz', 'restore' => 'quiz']; } /** diff --git a/mod/quiz/accessrule/seb/classes/event/template_created.php b/mod/quiz/accessrule/seb/classes/event/template_created.php index 9f3bb3542b0..86c51e774d3 100644 --- a/mod/quiz/accessrule/seb/classes/event/template_created.php +++ b/mod/quiz/accessrule/seb/classes/event/template_created.php @@ -106,7 +106,7 @@ class template_created extends base { * @return array Mapping of object id. */ public static function get_objectid_mapping() : array { - return array('db' => 'quizaccess_seb_template', 'restore' => 'quizaccess_seb_template'); + return ['db' => 'quizaccess_seb_template', 'restore' => 'quizaccess_seb_template']; } /** diff --git a/mod/quiz/accessrule/seb/classes/event/template_deleted.php b/mod/quiz/accessrule/seb/classes/event/template_deleted.php index 84379edb332..4e122b52479 100644 --- a/mod/quiz/accessrule/seb/classes/event/template_deleted.php +++ b/mod/quiz/accessrule/seb/classes/event/template_deleted.php @@ -100,7 +100,7 @@ class template_deleted extends base { * @return array Mapping of object id. */ public static function get_objectid_mapping() : array { - return array('db' => 'quizaccess_seb_template', 'restore' => 'quizaccess_seb_template'); + return ['db' => 'quizaccess_seb_template', 'restore' => 'quizaccess_seb_template']; } /** diff --git a/mod/quiz/accessrule/seb/classes/event/template_disabled.php b/mod/quiz/accessrule/seb/classes/event/template_disabled.php index 45a6ca9119e..8d8eb151035 100644 --- a/mod/quiz/accessrule/seb/classes/event/template_disabled.php +++ b/mod/quiz/accessrule/seb/classes/event/template_disabled.php @@ -106,7 +106,7 @@ class template_disabled extends base { * @return array Mapping of object id. */ public static function get_objectid_mapping() : array { - return array('db' => 'quizaccess_seb_template', 'restore' => 'quizaccess_seb_template'); + return ['db' => 'quizaccess_seb_template', 'restore' => 'quizaccess_seb_template']; } /** diff --git a/mod/quiz/accessrule/seb/classes/event/template_enabled.php b/mod/quiz/accessrule/seb/classes/event/template_enabled.php index 728c3b27c3e..8710ece5acd 100644 --- a/mod/quiz/accessrule/seb/classes/event/template_enabled.php +++ b/mod/quiz/accessrule/seb/classes/event/template_enabled.php @@ -106,7 +106,7 @@ class template_enabled extends base { * @return array Mapping of object id. */ public static function get_objectid_mapping() : array { - return array('db' => 'quizaccess_seb_template', 'restore' => 'quizaccess_seb_template'); + return ['db' => 'quizaccess_seb_template', 'restore' => 'quizaccess_seb_template']; } /** diff --git a/mod/quiz/accessrule/seb/classes/event/template_updated.php b/mod/quiz/accessrule/seb/classes/event/template_updated.php index 28498d5a4cb..d94a7118fd2 100644 --- a/mod/quiz/accessrule/seb/classes/event/template_updated.php +++ b/mod/quiz/accessrule/seb/classes/event/template_updated.php @@ -106,7 +106,7 @@ class template_updated extends base { * @return array Mapping of object id. */ public static function get_objectid_mapping() : array { - return array('db' => 'quizaccess_seb_template', 'restore' => 'quizaccess_seb_template'); + return ['db' => 'quizaccess_seb_template', 'restore' => 'quizaccess_seb_template']; } /** diff --git a/mod/quiz/accessrule/seb/classes/helper.php b/mod/quiz/accessrule/seb/classes/helper.php index 65acf56a875..11a4d5c4fc5 100644 --- a/mod/quiz/accessrule/seb/classes/helper.php +++ b/mod/quiz/accessrule/seb/classes/helper.php @@ -47,7 +47,7 @@ class helper { * @param array $options Display options. * @return string */ - public static function format_icon_link($url, $icon, $alt, $iconcomponent = 'moodle', $options = array()) { + public static function format_icon_link($url, $icon, $alt, $iconcomponent = 'moodle', $options = []) { global $OUTPUT; return $OUTPUT->action_icon( diff --git a/mod/quiz/accessrule/seb/db/access.php b/mod/quiz/accessrule/seb/db/access.php index c857fa96b03..d79df406959 100644 --- a/mod/quiz/accessrule/seb/db/access.php +++ b/mod/quiz/accessrule/seb/db/access.php @@ -25,213 +25,213 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( - 'quizaccess/seb:managetemplates' => array( +$capabilities = [ + 'quizaccess/seb:managetemplates' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, - ) - ), - 'quizaccess/seb:bypassseb' => array( + ] + ], + 'quizaccess/seb:bypassseb' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_requiresafeexambrowser' => array( + ] + ], + 'quizaccess/seb:manage_seb_requiresafeexambrowser' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_templateid' => array( + ] + ], + 'quizaccess/seb:manage_seb_templateid' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_filemanager_sebconfigfile' => array( + ] + ], + 'quizaccess/seb:manage_filemanager_sebconfigfile' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_showsebdownloadlink' => array( + ] + ], + 'quizaccess/seb:manage_seb_showsebdownloadlink' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_allowedbrowserexamkeys' => array( + ] + ], + 'quizaccess/seb:manage_seb_allowedbrowserexamkeys' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_linkquitseb' => array( + ] + ], + 'quizaccess/seb:manage_seb_linkquitseb' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_userconfirmquit' => array( + ] + ], + 'quizaccess/seb:manage_seb_userconfirmquit' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_allowuserquitseb' => array( + ] + ], + 'quizaccess/seb:manage_seb_allowuserquitseb' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_quitpassword' => array( + ] + ], + 'quizaccess/seb:manage_seb_quitpassword' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_allowreloadinexam' => array( + ] + ], + 'quizaccess/seb:manage_seb_allowreloadinexam' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_showsebtaskbar' => array( + ] + ], + 'quizaccess/seb:manage_seb_showsebtaskbar' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_showreloadbutton' => array( + ] + ], + 'quizaccess/seb:manage_seb_showreloadbutton' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_showtime' => array( + ] + ], + 'quizaccess/seb:manage_seb_showtime' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_showkeyboardlayout' => array( + ] + ], + 'quizaccess/seb:manage_seb_showkeyboardlayout' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), + ] + ], - 'quizaccess/seb:manage_seb_showwificontrol' => array( + 'quizaccess/seb:manage_seb_showwificontrol' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_enableaudiocontrol' => array( + ] + ], + 'quizaccess/seb:manage_seb_enableaudiocontrol' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_muteonstartup' => array( + ] + ], + 'quizaccess/seb:manage_seb_muteonstartup' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_allowspellchecking' => array( + ] + ], + 'quizaccess/seb:manage_seb_allowspellchecking' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_activateurlfiltering' => array( + ] + ], + 'quizaccess/seb:manage_seb_activateurlfiltering' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_filterembeddedcontent' => array( + ] + ], + 'quizaccess/seb:manage_seb_filterembeddedcontent' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_expressionsallowed' => array( + ] + ], + 'quizaccess/seb:manage_seb_expressionsallowed' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_regexallowed' => array( + ] + ], + 'quizaccess/seb:manage_seb_regexallowed' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_expressionsblocked' => array( + ] + ], + 'quizaccess/seb:manage_seb_expressionsblocked' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), - 'quizaccess/seb:manage_seb_regexblocked' => array( + ] + ], + 'quizaccess/seb:manage_seb_regexblocked' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ) - ), -); + ] + ], +]; diff --git a/mod/quiz/accessrule/seb/lib.php b/mod/quiz/accessrule/seb/lib.php index 50236e4cca2..cc7b0dd8fc5 100644 --- a/mod/quiz/accessrule/seb/lib.php +++ b/mod/quiz/accessrule/seb/lib.php @@ -38,7 +38,7 @@ defined('MOODLE_INTERNAL') || die(); * @param array $options additional options affecting the file serving * @return bool false if the file not found, just send the file otherwise and do not return anything */ -function quizaccess_seb_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { +function quizaccess_seb_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options= []) { if ($context->contextlevel != CONTEXT_MODULE) { return false; } @@ -68,4 +68,4 @@ function quizaccess_seb_pluginfile($course, $cm, $context, $filearea, $args, $fo } send_stored_file($file, 0, 0, $forcedownload, $options); -} \ No newline at end of file +} diff --git a/mod/quiz/accessrule/seb/rule.php b/mod/quiz/accessrule/seb/rule.php index 3c4e02aa7f0..8ed6029c064 100644 --- a/mod/quiz/accessrule/seb/rule.php +++ b/mod/quiz/accessrule/seb/rule.php @@ -151,7 +151,7 @@ class quizaccess_seb extends access_rule_base { * Save any submitted settings when the quiz settings form is submitted. This * is called from {@link quiz_after_add_or_update()} in lib.php. * - * @param object $quiz the data from the quiz form, including $quiz->id + * @param stdClass $quiz the data from the quiz form, including $quiz->id * which is the id of the quiz being saved. */ public static function save_settings($quiz) { @@ -204,7 +204,7 @@ class quizaccess_seb extends access_rule_base { * Delete any rule-specific settings when the quiz is deleted. This is called * from {@link quiz_delete_instance()} in lib.php. * - * @param object $quiz the data from the database, including $quiz->id + * @param stdClass $quiz the data from the database, including $quiz->id * which is the id of the quiz being deleted. */ public static function delete_settings($quiz) { @@ -543,7 +543,7 @@ class quizaccess_seb extends access_rule_base { // Rendering as a href and not as button in a form to circumvent browser warnings for sending to URL with unknown protocol. $seblink = \quizaccess_seb\link_generator::get_link($this->quiz->cmid, true, is_https()); - $buttonlink = html_writer::start_tag('div', array('class' => 'singlebutton')); + $buttonlink = html_writer::start_tag('div', ['class' => 'singlebutton']); $buttonlink .= html_writer::link($seblink, get_string('seblinkbutton', 'quizaccess_seb'), ['class' => 'btn btn-secondary', 'title' => get_string('seblinkbutton', 'quizaccess_seb')]); $buttonlink .= html_writer::end_tag('div'); @@ -560,7 +560,7 @@ class quizaccess_seb extends access_rule_base { // Rendering as a href and not as button in a form to circumvent browser warnings for sending to URL with unknown protocol. $httplink = \quizaccess_seb\link_generator::get_link($this->quiz->cmid, false, is_https()); - $buttonlink = html_writer::start_tag('div', array('class' => 'singlebutton')); + $buttonlink = html_writer::start_tag('div', ['class' => 'singlebutton']); $buttonlink .= html_writer::link($httplink, get_string('httplinkbutton', 'quizaccess_seb'), ['class' => 'btn btn-secondary', 'title' => get_string('httplinkbutton', 'quizaccess_seb')]); $buttonlink .= html_writer::end_tag('div'); diff --git a/mod/quiz/accessrule/seb/tests/privacy/provider_test.php b/mod/quiz/accessrule/seb/tests/privacy/provider_test.php index aeae1b69ccf..3ece5a279a0 100644 --- a/mod/quiz/accessrule/seb/tests/privacy/provider_test.php +++ b/mod/quiz/accessrule/seb/tests/privacy/provider_test.php @@ -109,7 +109,7 @@ class provider_test extends provider_testcase { // per table, like postgres and mysql do, rendering this useless. In any // case better to have the situation covered by some DBs, // like sqlsrv or oracle than by none). - $this->getDataGenerator()->create_module('label', array('course' => $this->course->id)); + $this->getDataGenerator()->create_module('label', ['course' => $this->course->id]); $contextlist = provider::get_contexts_for_userid($this->user->id); $approvedcontextlist = new approved_contextlist( diff --git a/mod/quiz/accessrule/seb/tests/test_helper_trait.php b/mod/quiz/accessrule/seb/tests/test_helper_trait.php index 7ae25d5df5e..6101270b3b3 100644 --- a/mod/quiz/accessrule/seb/tests/test_helper_trait.php +++ b/mod/quiz/accessrule/seb/tests/test_helper_trait.php @@ -172,9 +172,9 @@ trait quizaccess_seb_test_helper_trait { $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); + $saq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); quiz_add_quiz_question($saq->id, $quiz); - $numq = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $numq = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); quiz_add_quiz_question($numq->id, $quiz); return $quiz; diff --git a/mod/quiz/accessrule/securewindow/rule.php b/mod/quiz/accessrule/securewindow/rule.php index 6aa636b6b82..59c69e8b6a5 100644 --- a/mod/quiz/accessrule/securewindow/rule.php +++ b/mod/quiz/accessrule/securewindow/rule.php @@ -27,7 +27,7 @@ use mod_quiz\quiz_settings; */ class quizaccess_securewindow extends access_rule_base { /** @var array options that should be used for opening the secure popup. */ - protected static $popupoptions = array( + protected static $popupoptions = [ 'left' => 0, 'top' => 0, 'fullscreen' => true, @@ -39,7 +39,7 @@ class quizaccess_securewindow extends access_rule_base { 'location' => false, 'status' => false, 'menubar' => false, - ); + ]; public static function make(quiz_settings $quizobj, $timenow, $canignoretimelimits) { @@ -77,7 +77,7 @@ class quizaccess_securewindow extends access_rule_base { * security settings menu. */ public static function get_browser_security_choices() { - return array('securewindow' => - get_string('popupwithjavascriptsupport', 'quizaccess_securewindow')); + return ['securewindow' => + get_string('popupwithjavascriptsupport', 'quizaccess_securewindow')]; } } diff --git a/mod/quiz/addrandom.php b/mod/quiz/addrandom.php index d47d14a1892..9d720dc9e73 100644 --- a/mod/quiz/addrandom.php +++ b/mod/quiz/addrandom.php @@ -42,7 +42,7 @@ $category = optional_param('category', 0, PARAM_INT); $mdlscrollto = optional_param('mdlscrollto', 0, PARAM_INT); // Get the course object and related bits. -if (!$course = $DB->get_record('course', array('id' => $quiz->course))) { +if (!$course = $DB->get_record('course', ['id' => $quiz->course])) { throw new \moodle_exception('invalidcourseid'); } // You need mod/quiz:manage in addition to question capabilities to access this page. @@ -57,7 +57,7 @@ $PAGE->set_url($thispageurl); if ($returnurl) { $returnurl = new moodle_url($returnurl); } else { - $returnurl = new moodle_url('/mod/quiz/edit.php', array('cmid' => $cmid)); + $returnurl = new moodle_url('/mod/quiz/edit.php', ['cmid' => $cmid]); } if ($mdlscrollto) { $returnurl->param('mdlscrollto', $mdlscrollto); @@ -76,7 +76,7 @@ $qcobject = new question_category_object( $contexts->having_cap('moodle/question:add')); $mform = new add_random_form(new moodle_url('/mod/quiz/addrandom.php'), - array('contexts' => $contexts, 'cat' => $pagevars['cat'])); + ['contexts' => $contexts, 'cat' => $pagevars['cat']]); if ($mform->is_cancelled()) { redirect($returnurl); @@ -117,12 +117,12 @@ if ($data = $mform->get_data()) { redirect($returnurl); } -$mform->set_data(array( +$mform->set_data([ 'addonpage' => $addonpage, 'returnurl' => $returnurl, 'cmid' => $cm->id, 'category' => $category, -)); +]); // Setup $PAGE. $streditingquiz = get_string('editinga', 'moodle', get_string('modulename', 'quiz')); @@ -131,7 +131,7 @@ $PAGE->set_title($streditingquiz); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); -if (!$quizname = $DB->get_field($cm->modname, 'name', array('id' => $cm->instance))) { +if (!$quizname = $DB->get_field($cm->modname, 'name', ['id' => $cm->instance])) { throw new \moodle_exception('invalidcoursemodule'); } diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 163b8277ca4..84f336f6533 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -37,7 +37,7 @@ if ($id = optional_param('id', 0, PARAM_INT)) { throw new \moodle_exception('invalidquizid', 'quiz'); } redirect(new moodle_url('/mod/quiz/startattempt.php', - array('cmid' => $cm->id, 'sesskey' => sesskey()))); + ['cmid' => $cm->id, 'sesskey' => sesskey()])); } // Get submitted parameters. @@ -101,7 +101,7 @@ if ($accessmanager->is_preflight_check_required($attemptobj->get_attemptid())) { $autosaveperiod = get_config('quiz', 'autosaveperiod'); if ($autosaveperiod) { $PAGE->requires->yui_module('moodle-mod_quiz-autosave', - 'M.mod_quiz.autosave.init', array($autosaveperiod)); + 'M.mod_quiz.autosave.init', [$autosaveperiod]); } // Log this page view. diff --git a/mod/quiz/backup/moodle1/lib.php b/mod/quiz/backup/moodle1/lib.php index 02bb98684d5..2880e6b07fd 100644 --- a/mod/quiz/backup/moodle1/lib.php +++ b/mod/quiz/backup/moodle1/lib.php @@ -50,40 +50,40 @@ class moodle1_mod_quiz_handler extends moodle1_mod_handler { * @return array of {@link convert_path} instances */ public function get_paths() { - return array( + return [ new convert_path( 'quiz', '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUIZ', - array( - 'newfields' => array( + [ + 'newfields' => [ 'showuserpicture' => 0, 'questiondecimalpoints' => -1, 'introformat' => 0, 'showblocks' => 0, - ), - ) + ], + ] ), new convert_path('quiz_question_instances', '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUIZ/QUESTION_INSTANCES'), new convert_path('quiz_question_instance', '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUIZ/QUESTION_INSTANCES/QUESTION_INSTANCE', - array( - 'renamefields' => array( + [ + 'renamefields' => [ 'question' => 'questionid', 'grade' => 'maxmark', - ), - ) + ], + ] ), new convert_path('quiz_feedbacks', '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUIZ/FEEDBACKS'), new convert_path('quiz_feedback', '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUIZ/FEEDBACKS/FEEDBACK', - array( - 'newfields' => array( + [ + 'newfields' => [ 'feedbacktextformat' => FORMAT_HTML, - ) - ) + ] + ] ) - ); + ]; } /** @@ -126,10 +126,10 @@ class moodle1_mod_quiz_handler extends moodle1_mod_handler { // Start writing quiz.xml. $this->open_xml_writer("activities/quiz_{$this->moduleid}/quiz.xml"); - $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, + $this->xmlwriter->begin_tag('activity', ['id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'quiz', - 'contextid' => $contextid)); - $this->xmlwriter->begin_tag('quiz', array('id' => $instanceid)); + 'contextid' => $contextid]); + $this->xmlwriter->begin_tag('quiz', ['id' => $instanceid]); foreach ($data as $field => $value) { if ($field <> 'id') { @@ -149,7 +149,7 @@ class moodle1_mod_quiz_handler extends moodle1_mod_handler { } public function process_quiz_question_instance($data) { - $this->write_xml('question_instance', $data, array('/question_instance/id')); + $this->write_xml('question_instance', $data, ['/question_instance/id']); } public function on_quiz_feedbacks_start() { @@ -169,7 +169,7 @@ class moodle1_mod_quiz_handler extends moodle1_mod_handler { $data['maxgrade'] = 0; } - $this->write_xml('feedback', $data, array('/feedback/id')); + $this->write_xml('feedback', $data, ['/feedback/id']); } /** @@ -178,7 +178,7 @@ class moodle1_mod_quiz_handler extends moodle1_mod_handler { public function on_quiz_end() { // Append empty subpath element. - $this->write_xml('overrides', array()); + $this->write_xml('overrides', []); // Finish writing quiz.xml. $this->xmlwriter->end_tag('quiz'); @@ -190,7 +190,7 @@ class moodle1_mod_quiz_handler extends moodle1_mod_handler { $this->xmlwriter->begin_tag('inforef'); $this->xmlwriter->begin_tag('fileref'); foreach ($this->fileman->get_fileids() as $fileid) { - $this->write_xml('file', array('id' => $fileid)); + $this->write_xml('file', ['id' => $fileid]); } $this->xmlwriter->end_tag('fileref'); $this->xmlwriter->end_tag('inforef'); diff --git a/mod/quiz/backup/moodle2/restore_quiz_activity_task.class.php b/mod/quiz/backup/moodle2/restore_quiz_activity_task.class.php index c7b99fc36dd..b93e78a7281 100644 --- a/mod/quiz/backup/moodle2/restore_quiz_activity_task.class.php +++ b/mod/quiz/backup/moodle2/restore_quiz_activity_task.class.php @@ -56,11 +56,11 @@ class restore_quiz_activity_task extends restore_activity_task { * processed by the link decoder */ public static function define_decode_contents() { - $contents = array(); + $contents = []; - $contents[] = new restore_decode_content('quiz', array('intro'), 'quiz'); + $contents[] = new restore_decode_content('quiz', ['intro'], 'quiz'); $contents[] = new restore_decode_content('quiz_feedback', - array('feedbacktext'), 'quiz_feedback'); + ['feedbacktext'], 'quiz_feedback'); return $contents; } @@ -70,7 +70,7 @@ class restore_quiz_activity_task extends restore_activity_task { * to the activity to be executed by the link decoder */ public static function define_decode_rules() { - $rules = array(); + $rules = []; $rules[] = new restore_decode_rule('QUIZVIEWBYID', '/mod/quiz/view.php?id=$1', 'course_module'); @@ -90,7 +90,7 @@ class restore_quiz_activity_task extends restore_activity_task { * of {@link restore_log_rule} objects */ public static function define_restore_log_rules() { - $rules = array(); + $rules = []; $rules[] = new restore_log_rule('quiz', 'add', 'view.php?id={course_module}', '{quiz}'); @@ -181,7 +181,7 @@ class restore_quiz_activity_task extends restore_activity_task { * activity level. All them are rules not linked to any module instance (cmid = 0) */ public static function define_restore_log_rules_for_course() { - $rules = array(); + $rules = []; $rules[] = new restore_log_rule('quiz', 'view all', 'index.php?id={course}', null); diff --git a/mod/quiz/backup/moodle2/restore_quiz_stepslib.php b/mod/quiz/backup/moodle2/restore_quiz_stepslib.php index 62bdee3e621..986d00c6397 100644 --- a/mod/quiz/backup/moodle2/restore_quiz_stepslib.php +++ b/mod/quiz/backup/moodle2/restore_quiz_stepslib.php @@ -44,7 +44,7 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st protected function define_structure() { - $paths = array(); + $paths = []; $userinfo = $this->get_setting_value('userinfo'); $quiz = new restore_path_element('quiz', '/activity/quiz'); @@ -568,7 +568,7 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st $this->process_quiz_attempt($data); - $quiz = $DB->get_record('quiz', array('id' => $this->get_new_parentid('quiz'))); + $quiz = $DB->get_record('quiz', ['id' => $this->get_new_parentid('quiz')]); $quiz->oldquestions = $this->oldquizlayout; $this->process_legacy_quiz_attempt_data($data, $quiz); } @@ -600,10 +600,10 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st $this->add_related_files('mod_quiz', 'feedback', 'quiz_feedback'); if (!$this->sectioncreated) { - $DB->insert_record('quiz_sections', array( + $DB->insert_record('quiz_sections', [ 'quizid' => $this->get_new_parentid('quiz'), 'firstslot' => 1, 'heading' => '', - 'shufflequestions' => $this->legacyshufflequestionsoption)); + 'shufflequestions' => $this->legacyshufflequestionsoption]); } } } diff --git a/mod/quiz/classes/admin/review_setting.php b/mod/quiz/classes/admin/review_setting.php index 1dbe1ffcd0d..d22e2e108b9 100644 --- a/mod/quiz/classes/admin/review_setting.php +++ b/mod/quiz/classes/admin/review_setting.php @@ -60,7 +60,7 @@ class review_setting extends \admin_setting { * @return array */ public static function fields() { - return array( + return [ 'attempt' => get_string('theattempt', 'quiz'), 'correctness' => get_string('whethercorrect', 'question'), 'marks' => get_string('marks', 'question'), @@ -68,7 +68,7 @@ class review_setting extends \admin_setting { 'generalfeedback' => get_string('generalfeedback', 'question'), 'rightanswer' => get_string('rightanswer', 'question'), 'overallfeedback' => get_string('overallfeedback', 'quiz'), - ); + ]; } /** @@ -101,12 +101,12 @@ class review_setting extends \admin_setting { * @return array an array of time constant => lang string. */ protected static function times() { - return array( + return [ self::DURING => get_string('reviewduring', 'quiz'), self::IMMEDIATELY_AFTER => get_string('reviewimmediately', 'quiz'), self::LATER_WHILE_OPEN => get_string('reviewopen', 'quiz'), self::AFTER_CLOSE => get_string('reviewclosed', 'quiz'), - ); + ]; } protected function normalise_data($data) { diff --git a/mod/quiz/classes/analytics/indicator/activity_base.php b/mod/quiz/classes/analytics/indicator/activity_base.php index 03f12e0d523..dc0df052362 100644 --- a/mod/quiz/classes/analytics/indicator/activity_base.php +++ b/mod/quiz/classes/analytics/indicator/activity_base.php @@ -51,7 +51,7 @@ abstract class activity_base extends \core_analytics\local\indicator\community_o * @return string[] */ protected function feedback_viewed_events() { - return array('\mod_quiz\event\course_module_viewed'); + return ['\mod_quiz\event\course_module_viewed']; } /** diff --git a/mod/quiz/classes/analytics/indicator/cognitive_depth.php b/mod/quiz/classes/analytics/indicator/cognitive_depth.php index 7e3fbfd667c..608ae54cfdc 100644 --- a/mod/quiz/classes/analytics/indicator/cognitive_depth.php +++ b/mod/quiz/classes/analytics/indicator/cognitive_depth.php @@ -60,7 +60,7 @@ class cognitive_depth extends activity_base { * @return string[] */ protected function feedback_submitted_events() { - return array('\mod_quiz\event\attempt_submitted'); + return ['\mod_quiz\event\attempt_submitted']; } /** diff --git a/mod/quiz/classes/cache/overrides.php b/mod/quiz/classes/cache/overrides.php index 839b3b29554..5a69313978b 100644 --- a/mod/quiz/classes/cache/overrides.php +++ b/mod/quiz/classes/cache/overrides.php @@ -45,7 +45,7 @@ class overrides implements \cache_data_source { * specified by this interface. * * @param cache_definition $definition - * @return object + * @return stdClass */ public static function get_instance_for_cache(cache_definition $definition): overrides { if (is_null(self::$instance)) { diff --git a/mod/quiz/classes/event/attempt_abandoned.php b/mod/quiz/classes/event/attempt_abandoned.php index 5960954557b..b6435cf19b8 100644 --- a/mod/quiz/classes/event/attempt_abandoned.php +++ b/mod/quiz/classes/event/attempt_abandoned.php @@ -84,7 +84,7 @@ class attempt_abandoned extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/review.php', array('attempt' => $this->objectid)); + return new \moodle_url('/mod/quiz/review.php', ['attempt' => $this->objectid]); } /** @@ -128,13 +128,13 @@ class attempt_abandoned extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + return ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['submitterid'] = array('db' => 'user', 'restore' => 'user'); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['submitterid'] = ['db' => 'user', 'restore' => 'user']; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/attempt_becameoverdue.php b/mod/quiz/classes/event/attempt_becameoverdue.php index 549e839c326..b4298da02b4 100644 --- a/mod/quiz/classes/event/attempt_becameoverdue.php +++ b/mod/quiz/classes/event/attempt_becameoverdue.php @@ -87,7 +87,7 @@ class attempt_becameoverdue extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/review.php', array('attempt' => $this->objectid)); + return new \moodle_url('/mod/quiz/review.php', ['attempt' => $this->objectid]); } /** @@ -130,13 +130,13 @@ class attempt_becameoverdue extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + return ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['submitterid'] = array('db' => 'user', 'restore' => 'user'); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['submitterid'] = ['db' => 'user', 'restore' => 'user']; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/attempt_deleted.php b/mod/quiz/classes/event/attempt_deleted.php index 0662f397304..c656f7c1162 100644 --- a/mod/quiz/classes/event/attempt_deleted.php +++ b/mod/quiz/classes/event/attempt_deleted.php @@ -75,7 +75,7 @@ class attempt_deleted extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/report.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/quiz/report.php', ['id' => $this->contextinstanceid]); } /** @@ -84,8 +84,8 @@ class attempt_deleted extends \core\event\base { * @return array */ protected function get_legacy_logdata() { - return array($this->courseid, 'quiz', 'delete attempt', 'report.php?id=' . $this->contextinstanceid, - $this->objectid, $this->contextinstanceid); + return [$this->courseid, 'quiz', 'delete attempt', 'report.php?id=' . $this->contextinstanceid, + $this->objectid, $this->contextinstanceid]; } /** @@ -107,12 +107,12 @@ class attempt_deleted extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + return ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/attempt_preview_started.php b/mod/quiz/classes/event/attempt_preview_started.php index 7b00db28e9b..459d89a1e14 100644 --- a/mod/quiz/classes/event/attempt_preview_started.php +++ b/mod/quiz/classes/event/attempt_preview_started.php @@ -76,7 +76,7 @@ class attempt_preview_started extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/quiz/view.php', ['id' => $this->contextinstanceid]); } /** @@ -85,8 +85,8 @@ class attempt_preview_started extends \core\event\base { * @return array */ protected function get_legacy_logdata() { - return array($this->courseid, 'quiz', 'preview', 'view.php?id=' . $this->contextinstanceid, - $this->other['quizid'], $this->contextinstanceid); + return [$this->courseid, 'quiz', 'preview', 'view.php?id=' . $this->contextinstanceid, + $this->other['quizid'], $this->contextinstanceid]; } /** @@ -108,12 +108,12 @@ class attempt_preview_started extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + return ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/attempt_regraded.php b/mod/quiz/classes/event/attempt_regraded.php index dbbfd5fcad5..b3a24b51bb2 100644 --- a/mod/quiz/classes/event/attempt_regraded.php +++ b/mod/quiz/classes/event/attempt_regraded.php @@ -74,7 +74,7 @@ class attempt_regraded extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/review.php', array('attempt' => $this->objectid)); + return new \moodle_url('/mod/quiz/review.php', ['attempt' => $this->objectid]); } /** @@ -105,7 +105,7 @@ class attempt_regraded extends \core\event\base { * @return array Array of mappings */ public static function get_objectid_mapping() { - return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + return ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt']; } /** @@ -114,8 +114,8 @@ class attempt_regraded extends \core\event\base { * @return array Array of array mappings */ public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/attempt_reviewed.php b/mod/quiz/classes/event/attempt_reviewed.php index fbfdd8dc62a..2cf6dd2fde5 100644 --- a/mod/quiz/classes/event/attempt_reviewed.php +++ b/mod/quiz/classes/event/attempt_reviewed.php @@ -75,7 +75,7 @@ class attempt_reviewed extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/review.php', array('attempt' => $this->objectid)); + return new \moodle_url('/mod/quiz/review.php', ['attempt' => $this->objectid]); } /** @@ -84,8 +84,8 @@ class attempt_reviewed extends \core\event\base { * @return array */ protected function get_legacy_logdata() { - return array($this->courseid, 'quiz', 'review', 'review.php?attempt=' . $this->objectid, - $this->other['quizid'], $this->contextinstanceid); + return [$this->courseid, 'quiz', 'review', 'review.php?attempt=' . $this->objectid, + $this->other['quizid'], $this->contextinstanceid]; } /** @@ -107,12 +107,12 @@ class attempt_reviewed extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + return ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/attempt_started.php b/mod/quiz/classes/event/attempt_started.php index f5e70162a74..681c4bb6c90 100644 --- a/mod/quiz/classes/event/attempt_started.php +++ b/mod/quiz/classes/event/attempt_started.php @@ -83,7 +83,7 @@ class attempt_started extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/review.php', array('attempt' => $this->objectid)); + return new \moodle_url('/mod/quiz/review.php', ['attempt' => $this->objectid]); } /** @@ -115,8 +115,8 @@ class attempt_started extends \core\event\base { protected function get_legacy_logdata() { $attempt = $this->get_record_snapshot('quiz_attempts', $this->objectid); - return array($this->courseid, 'quiz', 'attempt', 'review.php?attempt=' . $this->objectid, - $attempt->quiz, $this->contextinstanceid); + return [$this->courseid, 'quiz', 'attempt', 'review.php?attempt=' . $this->objectid, + $attempt->quiz, $this->contextinstanceid]; } /** @@ -133,12 +133,12 @@ class attempt_started extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + return ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/attempt_submitted.php b/mod/quiz/classes/event/attempt_submitted.php index 6d881ce6d36..3c186ca125b 100644 --- a/mod/quiz/classes/event/attempt_submitted.php +++ b/mod/quiz/classes/event/attempt_submitted.php @@ -85,7 +85,7 @@ class attempt_submitted extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/review.php', array('attempt' => $this->objectid)); + return new \moodle_url('/mod/quiz/review.php', ['attempt' => $this->objectid]); } /** @@ -129,13 +129,13 @@ class attempt_submitted extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + return ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['submitterid'] = array('db' => 'user', 'restore' => 'user'); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['submitterid'] = ['db' => 'user', 'restore' => 'user']; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/attempt_summary_viewed.php b/mod/quiz/classes/event/attempt_summary_viewed.php index 385e2b356d3..3a7d198b4b2 100644 --- a/mod/quiz/classes/event/attempt_summary_viewed.php +++ b/mod/quiz/classes/event/attempt_summary_viewed.php @@ -78,7 +78,7 @@ class attempt_summary_viewed extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/summary.php', array('attempt' => $this->objectid)); + return new \moodle_url('/mod/quiz/summary.php', ['attempt' => $this->objectid]); } /** @@ -87,8 +87,8 @@ class attempt_summary_viewed extends \core\event\base { * @return array */ protected function get_legacy_logdata() { - return array($this->courseid, 'quiz', 'view summary', 'summary.php?attempt=' . $this->objectid, - $this->other['quizid'], $this->contextinstanceid); + return [$this->courseid, 'quiz', 'view summary', 'summary.php?attempt=' . $this->objectid, + $this->other['quizid'], $this->contextinstanceid]; } /** @@ -110,12 +110,12 @@ class attempt_summary_viewed extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + return ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/attempt_viewed.php b/mod/quiz/classes/event/attempt_viewed.php index 4771e5049b9..05c34b7d1e7 100644 --- a/mod/quiz/classes/event/attempt_viewed.php +++ b/mod/quiz/classes/event/attempt_viewed.php @@ -91,8 +91,8 @@ class attempt_viewed extends \core\event\base { * @return array */ protected function get_legacy_logdata() { - return array($this->courseid, 'quiz', 'continue attempt', 'review.php?attempt=' . $this->objectid, - $this->other['quizid'], $this->contextinstanceid); + return [$this->courseid, 'quiz', 'continue attempt', 'review.php?attempt=' . $this->objectid, + $this->other['quizid'], $this->contextinstanceid]; } /** @@ -118,12 +118,12 @@ class attempt_viewed extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + return ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/course_module_viewed.php b/mod/quiz/classes/event/course_module_viewed.php index dbdf0fc8621..cc18e8d4a1d 100644 --- a/mod/quiz/classes/event/course_module_viewed.php +++ b/mod/quiz/classes/event/course_module_viewed.php @@ -48,6 +48,6 @@ class course_module_viewed extends \core\event\course_module_viewed { } public static function get_objectid_mapping() { - return array('db' => 'quiz', 'restore' => 'quiz'); + return ['db' => 'quiz', 'restore' => 'quiz']; } } diff --git a/mod/quiz/classes/event/edit_page_viewed.php b/mod/quiz/classes/event/edit_page_viewed.php index 80247260376..2d102b4e5d1 100644 --- a/mod/quiz/classes/event/edit_page_viewed.php +++ b/mod/quiz/classes/event/edit_page_viewed.php @@ -75,7 +75,7 @@ class edit_page_viewed extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/edit.php', array('cmid' => $this->contextinstanceid)); + return new \moodle_url('/mod/quiz/edit.php', ['cmid' => $this->contextinstanceid]); } /** @@ -84,8 +84,8 @@ class edit_page_viewed extends \core\event\base { * @return array */ protected function get_legacy_logdata() { - return array($this->courseid, 'quiz', 'editquestions', 'view.php?id=' . $this->contextinstanceid, - $this->other['quizid'], $this->contextinstanceid); + return [$this->courseid, 'quiz', 'editquestions', 'view.php?id=' . $this->contextinstanceid, + $this->other['quizid'], $this->contextinstanceid]; } /** @@ -103,8 +103,8 @@ class edit_page_viewed extends \core\event\base { } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/group_override_created.php b/mod/quiz/classes/event/group_override_created.php index 2d21b8dd132..93f4278bad2 100644 --- a/mod/quiz/classes/event/group_override_created.php +++ b/mod/quiz/classes/event/group_override_created.php @@ -77,7 +77,7 @@ class group_override_created extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/overrideedit.php', array('id' => $this->objectid)); + return new \moodle_url('/mod/quiz/overrideedit.php', ['id' => $this->objectid]); } /** @@ -99,13 +99,13 @@ class group_override_created extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_overrides', 'restore' => 'quiz_override'); + return ['db' => 'quiz_overrides', 'restore' => 'quiz_override']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); - $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; + $othermapped['groupid'] = ['db' => 'groups', 'restore' => 'group']; return $othermapped; } diff --git a/mod/quiz/classes/event/group_override_deleted.php b/mod/quiz/classes/event/group_override_deleted.php index 9fe90c15b5d..9ae146d8877 100644 --- a/mod/quiz/classes/event/group_override_deleted.php +++ b/mod/quiz/classes/event/group_override_deleted.php @@ -76,7 +76,7 @@ class group_override_deleted extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/overrides.php', array('cmid' => $this->contextinstanceid)); + return new \moodle_url('/mod/quiz/overrides.php', ['cmid' => $this->contextinstanceid]); } /** @@ -85,8 +85,8 @@ class group_override_deleted extends \core\event\base { * @return array */ protected function get_legacy_logdata() { - return array($this->courseid, 'quiz', 'delete override', 'overrides.php?cmid=' . $this->contextinstanceid, - $this->other['quizid'], $this->contextinstanceid); + return [$this->courseid, 'quiz', 'delete override', 'overrides.php?cmid=' . $this->contextinstanceid, + $this->other['quizid'], $this->contextinstanceid]; } /** @@ -108,13 +108,13 @@ class group_override_deleted extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_overrides', 'restore' => 'quiz_override'); + return ['db' => 'quiz_overrides', 'restore' => 'quiz_override']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); - $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; + $othermapped['groupid'] = ['db' => 'groups', 'restore' => 'group']; return $othermapped; } diff --git a/mod/quiz/classes/event/group_override_updated.php b/mod/quiz/classes/event/group_override_updated.php index 5476b019e61..d60fc19f327 100644 --- a/mod/quiz/classes/event/group_override_updated.php +++ b/mod/quiz/classes/event/group_override_updated.php @@ -76,7 +76,7 @@ class group_override_updated extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/overrideedit.php', array('id' => $this->objectid)); + return new \moodle_url('/mod/quiz/overrideedit.php', ['id' => $this->objectid]); } /** @@ -85,8 +85,8 @@ class group_override_updated extends \core\event\base { * @return array */ protected function get_legacy_logdata() { - return array($this->courseid, 'quiz', 'edit override', 'overrideedit.php?id=' . $this->objectid, $this->other['quizid'], - $this->contextinstanceid); + return [$this->courseid, 'quiz', 'edit override', 'overrideedit.php?id=' . $this->objectid, $this->other['quizid'], + $this->contextinstanceid]; } /** @@ -108,13 +108,13 @@ class group_override_updated extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_overrides', 'restore' => 'quiz_override'); + return ['db' => 'quiz_overrides', 'restore' => 'quiz_override']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); - $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; + $othermapped['groupid'] = ['db' => 'groups', 'restore' => 'group']; return $othermapped; } diff --git a/mod/quiz/classes/event/question_manually_graded.php b/mod/quiz/classes/event/question_manually_graded.php index a77912ee3ed..15477cfe71e 100644 --- a/mod/quiz/classes/event/question_manually_graded.php +++ b/mod/quiz/classes/event/question_manually_graded.php @@ -77,8 +77,8 @@ class question_manually_graded extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/comment.php', array('attempt' => $this->other['attemptid'], - 'slot' => $this->other['slot'])); + return new \moodle_url('/mod/quiz/comment.php', ['attempt' => $this->other['attemptid'], + 'slot' => $this->other['slot']]); } /** @@ -87,8 +87,8 @@ class question_manually_graded extends \core\event\base { * @return array */ protected function get_legacy_logdata() { - return array($this->courseid, 'quiz', 'manualgrade', 'comment.php?attempt=' . $this->other['attemptid'] . - '&slot=' . $this->other['slot'], $this->other['quizid'], $this->contextinstanceid); + return [$this->courseid, 'quiz', 'manualgrade', 'comment.php?attempt=' . $this->other['attemptid'] . + '&slot=' . $this->other['slot'], $this->other['quizid'], $this->contextinstanceid]; } /** @@ -114,13 +114,13 @@ class question_manually_graded extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'question', 'restore' => 'question'); + return ['db' => 'question', 'restore' => 'question']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); - $othermapped['attemptid'] = array('db' => 'quiz_attempts', 'restore' => 'quiz_attempt'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; + $othermapped['attemptid'] = ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt']; return $othermapped; } diff --git a/mod/quiz/classes/event/report_viewed.php b/mod/quiz/classes/event/report_viewed.php index de23f9df4a3..f8c32e03dc0 100644 --- a/mod/quiz/classes/event/report_viewed.php +++ b/mod/quiz/classes/event/report_viewed.php @@ -78,8 +78,8 @@ class report_viewed extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/report.php', array('id' => $this->contextinstanceid, - 'mode' => $this->other['reportname'])); + return new \moodle_url('/mod/quiz/report.php', ['id' => $this->contextinstanceid, + 'mode' => $this->other['reportname']]); } /** @@ -88,8 +88,8 @@ class report_viewed extends \core\event\base { * @return array */ protected function get_legacy_logdata() { - return array($this->courseid, 'quiz', 'report', 'report.php?id=' . $this->contextinstanceid . '&mode=' . - $this->other['reportname'], $this->other['quizid'], $this->contextinstanceid); + return [$this->courseid, 'quiz', 'report', 'report.php?id=' . $this->contextinstanceid . '&mode=' . + $this->other['reportname'], $this->other['quizid'], $this->contextinstanceid]; } /** @@ -111,8 +111,8 @@ class report_viewed extends \core\event\base { } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/user_override_created.php b/mod/quiz/classes/event/user_override_created.php index e8cbfd0411b..7c845d4aadf 100644 --- a/mod/quiz/classes/event/user_override_created.php +++ b/mod/quiz/classes/event/user_override_created.php @@ -75,7 +75,7 @@ class user_override_created extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/overrideedit.php', array('id' => $this->objectid)); + return new \moodle_url('/mod/quiz/overrideedit.php', ['id' => $this->objectid]); } /** @@ -97,12 +97,12 @@ class user_override_created extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_overrides', 'restore' => 'quiz_override'); + return ['db' => 'quiz_overrides', 'restore' => 'quiz_override']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/user_override_deleted.php b/mod/quiz/classes/event/user_override_deleted.php index f851189292f..c6bed782fa1 100644 --- a/mod/quiz/classes/event/user_override_deleted.php +++ b/mod/quiz/classes/event/user_override_deleted.php @@ -75,7 +75,7 @@ class user_override_deleted extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/overrides.php', array('cmid' => $this->contextinstanceid)); + return new \moodle_url('/mod/quiz/overrides.php', ['cmid' => $this->contextinstanceid]); } /** @@ -84,8 +84,8 @@ class user_override_deleted extends \core\event\base { * @return array */ protected function get_legacy_logdata() { - return array($this->courseid, 'quiz', 'delete override', 'overrides.php?cmid=' . $this->contextinstanceid, - $this->other['quizid'], $this->contextinstanceid); + return [$this->courseid, 'quiz', 'delete override', 'overrides.php?cmid=' . $this->contextinstanceid, + $this->other['quizid'], $this->contextinstanceid]; } /** @@ -107,12 +107,12 @@ class user_override_deleted extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_overrides', 'restore' => 'quiz_override'); + return ['db' => 'quiz_overrides', 'restore' => 'quiz_override']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/event/user_override_updated.php b/mod/quiz/classes/event/user_override_updated.php index 2b902a28949..d801d2bfab5 100644 --- a/mod/quiz/classes/event/user_override_updated.php +++ b/mod/quiz/classes/event/user_override_updated.php @@ -76,7 +76,7 @@ class user_override_updated extends \core\event\base { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/quiz/overrideedit.php', array('id' => $this->objectid)); + return new \moodle_url('/mod/quiz/overrideedit.php', ['id' => $this->objectid]); } /** @@ -85,8 +85,8 @@ class user_override_updated extends \core\event\base { * @return array */ protected function get_legacy_logdata() { - return array($this->courseid, 'quiz', 'edit override', 'overrideedit.php?id=' . $this->objectid, $this->other['quizid'], - $this->contextinstanceid); + return [$this->courseid, 'quiz', 'edit override', 'overrideedit.php?id=' . $this->objectid, $this->other['quizid'], + $this->contextinstanceid]; } /** @@ -108,12 +108,12 @@ class user_override_updated extends \core\event\base { } public static function get_objectid_mapping() { - return array('db' => 'quiz_overrides', 'restore' => 'quiz_override'); + return ['db' => 'quiz_overrides', 'restore' => 'quiz_override']; } public static function get_other_mapping() { - $othermapped = array(); - $othermapped['quizid'] = array('db' => 'quiz', 'restore' => 'quiz'); + $othermapped = []; + $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz']; return $othermapped; } diff --git a/mod/quiz/classes/external.php b/mod/quiz/classes/external.php index 73e4f49b0d3..f4e4415f5f3 100644 --- a/mod/quiz/classes/external.php +++ b/mod/quiz/classes/external.php @@ -61,11 +61,11 @@ class mod_quiz_external extends external_api { */ public static function get_quizzes_by_courses_parameters() { return new external_function_parameters ( - array( + [ 'courseids' => new external_multiple_structure( - new external_value(PARAM_INT, 'course id'), 'Array of course ids', VALUE_DEFAULT, array() + new external_value(PARAM_INT, 'course id'), 'Array of course ids', VALUE_DEFAULT, [] ), - ) + ] ); } @@ -77,18 +77,18 @@ class mod_quiz_external extends external_api { * @return array of quizzes details * @since Moodle 3.1 */ - public static function get_quizzes_by_courses($courseids = array()) { + public static function get_quizzes_by_courses($courseids = []) { global $USER; - $warnings = array(); - $returnedquizzes = array(); + $warnings = []; + $returnedquizzes = []; - $params = array( + $params = [ 'courseids' => $courseids, - ); + ]; $params = self::validate_parameters(self::get_quizzes_by_courses_parameters(), $params); - $mycourses = array(); + $mycourses = []; if (empty($params['courseids'])) { $mycourses = enrol_get_my_courses(); $params['courseids'] = array_keys($mycourses); @@ -114,8 +114,8 @@ class mod_quiz_external extends external_api { if (has_capability('mod/quiz:view', $context)) { $quizdetails['introfiles'] = util::get_area_files($context->id, 'mod_quiz', 'intro', false, false); - $viewablefields = array('timeopen', 'timeclose', 'attempts', 'timelimit', 'grademethod', 'decimalpoints', - 'questiondecimalpoints', 'sumgrades', 'grade', 'preferredbehaviour'); + $viewablefields = ['timeopen', 'timeclose', 'attempts', 'timelimit', 'grademethod', 'decimalpoints', + 'questiondecimalpoints', 'sumgrades', 'grade', 'preferredbehaviour']; // Sometimes this function returns just empty. $hasfeedback = quiz_has_feedback($quiz); @@ -131,12 +131,12 @@ class mod_quiz_external extends external_api { $quizdetails['hasquestions'] = (int) $quizobj->has_questions(); $quizdetails['autosaveperiod'] = get_config('quiz', 'autosaveperiod'); - $additionalfields = array('attemptonlast', 'reviewattempt', 'reviewcorrectness', 'reviewmarks', + $additionalfields = ['attemptonlast', 'reviewattempt', 'reviewcorrectness', 'reviewmarks', 'reviewspecificfeedback', 'reviewgeneralfeedback', 'reviewrightanswer', 'reviewoverallfeedback', 'questionsperpage', 'navmethod', 'browsersecurity', 'delay1', 'delay2', 'showuserpicture', 'showblocks', 'completionattemptsexhausted', 'overduehandling', - 'graceperiod', 'canredoquestions', 'allowofflineattempts'); + 'graceperiod', 'canredoquestions', 'allowofflineattempts']; $viewablefields = array_merge($viewablefields, $additionalfields); // Any course module fields that previously existed in quiz. @@ -145,7 +145,7 @@ class mod_quiz_external extends external_api { // Fields only for managers. if (has_capability('moodle/course:manageactivities', $context)) { - $additionalfields = array('shuffleanswers', 'timecreated', 'timemodified', 'password', 'subnet'); + $additionalfields = ['shuffleanswers', 'timecreated', 'timemodified', 'password', 'subnet']; $viewablefields = array_merge($viewablefields, $additionalfields); } @@ -156,7 +156,7 @@ class mod_quiz_external extends external_api { $returnedquizzes[] = $quizdetails; } } - $result = array(); + $result = []; $result['quizzes'] = $returnedquizzes; $result['warnings'] = $warnings; return $result; @@ -170,7 +170,7 @@ class mod_quiz_external extends external_api { */ public static function get_quizzes_by_courses_returns() { return new external_single_structure( - array( + [ 'quizzes' => new external_multiple_structure( new external_single_structure(array_merge( helper_for_get_mods_by_courses::standard_coursemodule_elements_returns(true), @@ -270,7 +270,7 @@ class mod_quiz_external extends external_api { )) ), 'warnings' => new external_warnings(), - ) + ] ); } @@ -286,13 +286,13 @@ class mod_quiz_external extends external_api { global $DB; // Request and permission validation. - $quiz = $DB->get_record('quiz', array('id' => $quizid), '*', MUST_EXIST); + $quiz = $DB->get_record('quiz', ['id' => $quizid], '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($quiz, 'quiz'); $context = context_module::instance($cm->id); self::validate_context($context); - return array($quiz, $course, $cm, $context); + return [$quiz, $course, $cm, $context]; } /** @@ -303,9 +303,9 @@ class mod_quiz_external extends external_api { */ public static function view_quiz_parameters() { return new external_function_parameters ( - array( + [ 'quizid' => new external_value(PARAM_INT, 'quiz instance id'), - ) + ] ); } @@ -319,15 +319,15 @@ class mod_quiz_external extends external_api { public static function view_quiz($quizid) { global $DB; - $params = self::validate_parameters(self::view_quiz_parameters(), array('quizid' => $quizid)); - $warnings = array(); + $params = self::validate_parameters(self::view_quiz_parameters(), ['quizid' => $quizid]); + $warnings = []; list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); // Trigger course_module_viewed event and completion. quiz_view($quiz, $course, $cm, $context); - $result = array(); + $result = []; $result['status'] = true; $result['warnings'] = $warnings; return $result; @@ -341,10 +341,10 @@ class mod_quiz_external extends external_api { */ public static function view_quiz_returns() { return new external_single_structure( - array( + [ 'status' => new external_value(PARAM_BOOL, 'status: true if success'), 'warnings' => new external_warnings(), - ) + ] ); } @@ -356,13 +356,13 @@ class mod_quiz_external extends external_api { */ public static function get_user_attempts_parameters() { return new external_function_parameters ( - array( + [ 'quizid' => new external_value(PARAM_INT, 'quiz instance id'), 'userid' => new external_value(PARAM_INT, 'user id, empty for current user', VALUE_DEFAULT, 0), 'status' => new external_value(PARAM_ALPHA, 'quiz status: all, finished or unfinished', VALUE_DEFAULT, 'finished'), 'includepreviews' => new external_value(PARAM_BOOL, 'whether to include previews or not', VALUE_DEFAULT, false), - ) + ] ); } @@ -379,19 +379,19 @@ class mod_quiz_external extends external_api { public static function get_user_attempts($quizid, $userid = 0, $status = 'finished', $includepreviews = false) { global $USER; - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'quizid' => $quizid, 'userid' => $userid, 'status' => $status, 'includepreviews' => $includepreviews, - ); + ]; $params = self::validate_parameters(self::get_user_attempts_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); - if (!in_array($params['status'], array('all', 'finished', 'unfinished'))) { + if (!in_array($params['status'], ['all', 'finished', 'unfinished'])) { throw new invalid_parameter_exception('Invalid status value'); } @@ -421,7 +421,7 @@ class mod_quiz_external extends external_api { } $attemptresponse[] = $attempt; } - $result = array(); + $result = []; $result['attempts'] = $attemptresponse; $result['warnings'] = $warnings; return $result; @@ -434,7 +434,7 @@ class mod_quiz_external extends external_api { */ private static function attempt_structure() { return new external_single_structure( - array( + [ 'id' => new external_value(PARAM_INT, 'Attempt id.', VALUE_OPTIONAL), 'quiz' => new external_value(PARAM_INT, 'Foreign key reference to the quiz that was attempted.', VALUE_OPTIONAL), @@ -460,7 +460,7 @@ class mod_quiz_external extends external_api { 'sumgrades' => new external_value(PARAM_FLOAT, 'Total marks for this attempt.', VALUE_OPTIONAL), 'gradednotificationsenttime' => new external_value(PARAM_INT, 'Time when the student was notified that manual grading of their attempt was complete.', VALUE_OPTIONAL), - ) + ] ); } @@ -472,10 +472,10 @@ class mod_quiz_external extends external_api { */ public static function get_user_attempts_returns() { return new external_single_structure( - array( + [ 'attempts' => new external_multiple_structure(self::attempt_structure()), 'warnings' => new external_warnings(), - ) + ] ); } @@ -487,10 +487,10 @@ class mod_quiz_external extends external_api { */ public static function get_user_best_grade_parameters() { return new external_function_parameters ( - array( + [ 'quizid' => new external_value(PARAM_INT, 'quiz instance id'), 'userid' => new external_value(PARAM_INT, 'user id', VALUE_DEFAULT, 0), - ) + ] ); } @@ -506,12 +506,12 @@ class mod_quiz_external extends external_api { global $DB, $USER, $CFG; require_once($CFG->libdir . '/gradelib.php'); - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'quizid' => $quizid, 'userid' => $userid, - ); + ]; $params = self::validate_parameters(self::get_user_best_grade_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); @@ -529,7 +529,7 @@ class mod_quiz_external extends external_api { require_capability('mod/quiz:viewreports', $context); } - $result = array(); + $result = []; // This code was mostly copied from mod/quiz/view.php. We need to make the web service logic consistent. // Get this user's attempts. @@ -577,12 +577,12 @@ class mod_quiz_external extends external_api { */ public static function get_user_best_grade_returns() { return new external_single_structure( - array( + [ 'hasgrade' => new external_value(PARAM_BOOL, 'Whether the user has a grade on the given quiz.'), 'grade' => new external_value(PARAM_FLOAT, 'The grade (only if the user has a grade).', VALUE_OPTIONAL), 'gradetopass' => new external_value(PARAM_FLOAT, 'The grade to pass the quiz (only if set).', VALUE_OPTIONAL), 'warnings' => new external_warnings(), - ) + ] ); } @@ -594,11 +594,11 @@ class mod_quiz_external extends external_api { */ public static function get_combined_review_options_parameters() { return new external_function_parameters ( - array( + [ 'quizid' => new external_value(PARAM_INT, 'quiz instance id'), 'userid' => new external_value(PARAM_INT, 'user id (empty for current user)', VALUE_DEFAULT, 0), - ) + ] ); } @@ -613,12 +613,12 @@ class mod_quiz_external extends external_api { public static function get_combined_review_options($quizid, $userid = 0) { global $DB, $USER; - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'quizid' => $quizid, 'userid' => $userid, - ); + ]; $params = self::validate_parameters(self::get_combined_review_options_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); @@ -638,18 +638,18 @@ class mod_quiz_external extends external_api { $attempts = quiz_get_user_attempts($quiz->id, $user->id, 'all', true); - $result = array(); + $result = []; $result['someoptions'] = []; $result['alloptions'] = []; list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts); - foreach (array('someoptions', 'alloptions') as $typeofoption) { + foreach (['someoptions', 'alloptions'] as $typeofoption) { foreach ($$typeofoption as $key => $value) { - $result[$typeofoption][] = array( + $result[$typeofoption][] = [ "name" => $key, "value" => (!empty($value)) ? $value : 0 - ); + ]; } } @@ -665,25 +665,25 @@ class mod_quiz_external extends external_api { */ public static function get_combined_review_options_returns() { return new external_single_structure( - array( + [ 'someoptions' => new external_multiple_structure( new external_single_structure( - array( + [ 'name' => new external_value(PARAM_ALPHANUMEXT, 'option name'), 'value' => new external_value(PARAM_INT, 'option value'), - ) + ] ) ), 'alloptions' => new external_multiple_structure( new external_single_structure( - array( + [ 'name' => new external_value(PARAM_ALPHANUMEXT, 'option name'), 'value' => new external_value(PARAM_INT, 'option value'), - ) + ] ) ), 'warnings' => new external_warnings(), - ) + ] ); } @@ -695,19 +695,19 @@ class mod_quiz_external extends external_api { */ public static function start_attempt_parameters() { return new external_function_parameters ( - array( + [ 'quizid' => new external_value(PARAM_INT, 'quiz instance id'), 'preflightdata' => new external_multiple_structure( new external_single_structure( - array( + [ 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), - ) - ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() + ] + ), 'Preflight required data (like passwords)', VALUE_DEFAULT, [] ), 'forcenew' => new external_value(PARAM_BOOL, 'Whether to force a new attempt or not.', VALUE_DEFAULT, false), - ) + ] ); } @@ -720,17 +720,17 @@ class mod_quiz_external extends external_api { * @return array of warnings and the attempt basic data * @since Moodle 3.1 */ - public static function start_attempt($quizid, $preflightdata = array(), $forcenew = false) { + public static function start_attempt($quizid, $preflightdata = [], $forcenew = false) { global $DB, $USER; - $warnings = array(); - $attempt = array(); + $warnings = []; + $attempt = []; - $params = array( + $params = [ 'quizid' => $quizid, 'preflightdata' => $preflightdata, 'forcenew' => $forcenew, - ); + ]; $params = self::validate_parameters(self::start_attempt_parameters(), $params); $forcenew = $params['forcenew']; @@ -755,18 +755,18 @@ class mod_quiz_external extends external_api { if (!$quizobj->is_preview_user() && $messages) { // Create warnings with the exact messages. foreach ($messages as $message) { - $warnings[] = array( + $warnings[] = [ 'item' => 'quiz', 'itemid' => $quiz->id, 'warningcode' => '1', 'message' => clean_text($message, PARAM_TEXT) - ); + ]; } } else { if ($accessmanager->is_preflight_check_required($currentattemptid)) { // Need to do some checks before allowing the user to continue. - $provideddata = array(); + $provideddata = []; foreach ($params['preflightdata'] as $data) { $provideddata[$data['name']] = $data['value']; } @@ -792,7 +792,7 @@ class mod_quiz_external extends external_api { $attempt = quiz_prepare_and_start_new_attempt($quizobj, $attemptnumber, $lastattempt, $offlineattempt); } - $result = array(); + $result = []; $result['attempt'] = $attempt; $result['warnings'] = $warnings; return $result; @@ -806,10 +806,10 @@ class mod_quiz_external extends external_api { */ public static function start_attempt_returns() { return new external_single_structure( - array( + [ 'attempt' => self::attempt_structure(), 'warnings' => new external_warnings(), - ) + ] ); } @@ -843,7 +843,7 @@ class mod_quiz_external extends external_api { // Check the access rules. $accessmanager = $attemptobj->get_access_manager(time()); - $messages = array(); + $messages = []; if ($checkaccessrules) { // If the attempt is now overdue, or abandoned, deal with that. $attemptobj->handle_if_time_expired(time(), true); @@ -863,7 +863,7 @@ class mod_quiz_external extends external_api { // User submitted data (like the quiz password). if ($accessmanager->is_preflight_check_required($attemptobj->get_attemptid())) { - $provideddata = array(); + $provideddata = []; foreach ($params['preflightdata'] as $data) { $provideddata[$data['name']] = $data['value']; } @@ -895,7 +895,7 @@ class mod_quiz_external extends external_api { } } - return array($attemptobj, $messages); + return [$attemptobj, $messages]; } /** @@ -907,17 +907,17 @@ class mod_quiz_external extends external_api { */ private static function question_structure() { return new external_single_structure( - array( + [ 'slot' => new external_value(PARAM_INT, 'slot number'), 'type' => new external_value(PARAM_ALPHANUMEXT, 'question type, i.e: multichoice'), 'page' => new external_value(PARAM_INT, 'page of the quiz this question appears on'), 'html' => new external_value(PARAM_RAW, 'the question rendered'), 'responsefileareas' => new external_multiple_structure( new external_single_structure( - array( + [ 'area' => new external_value(PARAM_NOTAGS, 'File area name'), 'files' => new external_files('Response files for the question', VALUE_OPTIONAL), - ) + ] ), 'Response file areas including files', VALUE_OPTIONAL ), 'sequencecheck' => new external_value(PARAM_INT, 'the number of real steps in this attempt', VALUE_OPTIONAL), @@ -938,7 +938,7 @@ class mod_quiz_external extends external_api { 'maxmark' => new external_value(PARAM_FLOAT, 'the maximum mark possible for this question attempt. It will be returned only if the user is allowed to see it.', VALUE_OPTIONAL), 'settings' => new external_value(PARAM_RAW, 'Question settings (JSON encoded).', VALUE_OPTIONAL), - ), + ], 'The question data. Some fields may not be returned depending on the quiz display settings.' ); } @@ -954,7 +954,7 @@ class mod_quiz_external extends external_api { private static function get_attempt_questions_data(quiz_attempt $attemptobj, $review, $page = 'all') { global $PAGE; - $questions = array(); + $questions = []; $contextid = $attemptobj->get_quizobj()->get_context()->id; $displayoptions = $attemptobj->get_display_options($review); $renderer = $PAGE->get_renderer('mod_quiz'); @@ -973,14 +973,14 @@ class mod_quiz_external extends external_api { $responsefileareas[$area]['files'] = []; foreach ($files as $file) { - $responsefileareas[$area]['files'][] = array( + $responsefileareas[$area]['files'][] = [ 'filename' => $file->get_filename(), 'fileurl' => $qattempt->get_response_file_url($file), 'filesize' => $file->get_filesize(), 'filepath' => $file->get_filepath(), 'mimetype' => $file->get_mimetype(), 'timemodified' => $file->get_timemodified(), - ); + ]; } } } @@ -988,7 +988,7 @@ class mod_quiz_external extends external_api { // Check display settings for question. $settings = $questiondef->get_question_definition_for_external_rendering($qattempt, $displayoptions); - $question = array( + $question = [ 'slot' => $slot, 'type' => $qtype, 'page' => $attemptobj->get_question_page($slot), @@ -999,7 +999,7 @@ class mod_quiz_external extends external_api { 'lastactiontime' => $qattempt->get_last_step()->get_timecreated(), 'hasautosavedstep' => $qattempt->has_autosaved_step(), 'settings' => !empty($settings) ? json_encode($settings) : null, - ); + ]; if ($attemptobj->is_real_question($slot)) { $question['number'] = $attemptobj->get_question_number($slot); @@ -1031,18 +1031,18 @@ class mod_quiz_external extends external_api { */ public static function get_attempt_data_parameters() { return new external_function_parameters ( - array( + [ 'attemptid' => new external_value(PARAM_INT, 'attempt id'), 'page' => new external_value(PARAM_INT, 'page number'), 'preflightdata' => new external_multiple_structure( new external_single_structure( - array( + [ 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), - ) - ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() + ] + ), 'Preflight required data (like passwords)', VALUE_DEFAULT, [] ) - ) + ] ); } @@ -1055,16 +1055,16 @@ class mod_quiz_external extends external_api { * @return array of warnings and the attempt data, next page, message and questions * @since Moodle 3.1 */ - public static function get_attempt_data($attemptid, $page, $preflightdata = array()) { + public static function get_attempt_data($attemptid, $page, $preflightdata = []) { global $PAGE; - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'attemptid' => $attemptid, 'page' => $page, 'preflightdata' => $preflightdata, - ); + ]; $params = self::validate_parameters(self::get_attempt_data_parameters(), $params); list($attemptobj, $messages) = self::validate_attempt($params); @@ -1079,7 +1079,7 @@ class mod_quiz_external extends external_api { // Set a default URL to stop the debugging output. $PAGE->set_url('/fake/url'); - $result = array(); + $result = []; $result['attempt'] = $attemptobj->get_attempt(); $result['messages'] = $messages; $result['nextpage'] = $nextpage; @@ -1097,7 +1097,7 @@ class mod_quiz_external extends external_api { */ public static function get_attempt_data_returns() { return new external_single_structure( - array( + [ 'attempt' => self::attempt_structure(), 'messages' => new external_multiple_structure( new external_value(PARAM_TEXT, 'access message'), @@ -1106,7 +1106,7 @@ class mod_quiz_external extends external_api { 'nextpage' => new external_value(PARAM_INT, 'next page number'), 'questions' => new external_multiple_structure(self::question_structure()), 'warnings' => new external_warnings(), - ) + ] ); } @@ -1118,17 +1118,17 @@ class mod_quiz_external extends external_api { */ public static function get_attempt_summary_parameters() { return new external_function_parameters ( - array( + [ 'attemptid' => new external_value(PARAM_INT, 'attempt id'), 'preflightdata' => new external_multiple_structure( new external_single_structure( - array( + [ 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), - ) - ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() + ] + ), 'Preflight required data (like passwords)', VALUE_DEFAULT, [] ) - ) + ] ); } @@ -1140,19 +1140,19 @@ class mod_quiz_external extends external_api { * @return array of warnings and the attempt summary data for each question * @since Moodle 3.1 */ - public static function get_attempt_summary($attemptid, $preflightdata = array()) { + public static function get_attempt_summary($attemptid, $preflightdata = []) { - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'attemptid' => $attemptid, 'preflightdata' => $preflightdata, - ); + ]; $params = self::validate_parameters(self::get_attempt_summary_parameters(), $params); list($attemptobj, $messages) = self::validate_attempt($params, true, false); - $result = array(); + $result = []; $result['warnings'] = $warnings; $result['questions'] = self::get_attempt_questions_data($attemptobj, false, 'all'); @@ -1167,10 +1167,10 @@ class mod_quiz_external extends external_api { */ public static function get_attempt_summary_returns() { return new external_single_structure( - array( + [ 'questions' => new external_multiple_structure(self::question_structure()), 'warnings' => new external_warnings(), - ) + ] ); } @@ -1182,25 +1182,25 @@ class mod_quiz_external extends external_api { */ public static function save_attempt_parameters() { return new external_function_parameters ( - array( + [ 'attemptid' => new external_value(PARAM_INT, 'attempt id'), 'data' => new external_multiple_structure( new external_single_structure( - array( + [ 'name' => new external_value(PARAM_RAW, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), - ) + ] ), 'the data to be saved' ), 'preflightdata' => new external_multiple_structure( new external_single_structure( - array( + [ 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), - ) - ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() + ] + ), 'Preflight required data (like passwords)', VALUE_DEFAULT, [] ) - ) + ] ); } @@ -1213,16 +1213,16 @@ class mod_quiz_external extends external_api { * @return array of warnings and execution result * @since Moodle 3.1 */ - public static function save_attempt($attemptid, $data, $preflightdata = array()) { + public static function save_attempt($attemptid, $data, $preflightdata = []) { global $DB, $USER; - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'attemptid' => $attemptid, 'data' => $data, 'preflightdata' => $preflightdata, - ); + ]; $params = self::validate_parameters(self::save_attempt_parameters(), $params); // Add a page, required by validate_attempt. @@ -1234,7 +1234,7 @@ class mod_quiz_external extends external_api { } $transaction = $DB->start_delegated_transaction(); // Create the $_POST object required by the question engine. - $_POST = array(); + $_POST = []; foreach ($data as $element) { $_POST[$element['name']] = $element['value']; // Some deep core functions like file_get_submitted_draft_itemid() also requires $_REQUEST to be filled. @@ -1246,7 +1246,7 @@ class mod_quiz_external extends external_api { $attemptobj->process_auto_save($timenow); $transaction->allow_commit(); - $result = array(); + $result = []; $result['status'] = true; $result['warnings'] = $warnings; return $result; @@ -1260,10 +1260,10 @@ class mod_quiz_external extends external_api { */ public static function save_attempt_returns() { return new external_single_structure( - array( + [ 'status' => new external_value(PARAM_BOOL, 'status: true if success'), 'warnings' => new external_warnings(), - ) + ] ); } @@ -1275,29 +1275,29 @@ class mod_quiz_external extends external_api { */ public static function process_attempt_parameters() { return new external_function_parameters ( - array( + [ 'attemptid' => new external_value(PARAM_INT, 'attempt id'), 'data' => new external_multiple_structure( new external_single_structure( - array( + [ 'name' => new external_value(PARAM_RAW, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), - ) + ] ), - 'the data to be saved', VALUE_DEFAULT, array() + 'the data to be saved', VALUE_DEFAULT, [] ), 'finishattempt' => new external_value(PARAM_BOOL, 'whether to finish or not the attempt', VALUE_DEFAULT, false), 'timeup' => new external_value(PARAM_BOOL, 'whether the WS was called by a timer when the time is up', VALUE_DEFAULT, false), 'preflightdata' => new external_multiple_structure( new external_single_structure( - array( + [ 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), - ) - ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() + ] + ), 'Preflight required data (like passwords)', VALUE_DEFAULT, [] ) - ) + ] ); } @@ -1312,18 +1312,18 @@ class mod_quiz_external extends external_api { * @return array of warnings and the attempt state after the processing * @since Moodle 3.1 */ - public static function process_attempt($attemptid, $data, $finishattempt = false, $timeup = false, $preflightdata = array()) { + public static function process_attempt($attemptid, $data, $finishattempt = false, $timeup = false, $preflightdata = []) { global $USER; - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'attemptid' => $attemptid, 'data' => $data, 'finishattempt' => $finishattempt, 'timeup' => $timeup, 'preflightdata' => $preflightdata, - ); + ]; $params = self::validate_parameters(self::process_attempt_parameters(), $params); // Do not check access manager rules and evaluate fail if overdue. @@ -1337,7 +1337,7 @@ class mod_quiz_external extends external_api { $USER->ignoresesskey = true; } // Create the $_POST object required by the question engine. - $_POST = array(); + $_POST = []; foreach ($params['data'] as $element) { $_POST[$element['name']] = $element['value']; $_REQUEST[$element['name']] = $element['value']; @@ -1346,7 +1346,7 @@ class mod_quiz_external extends external_api { $finishattempt = $params['finishattempt']; $timeup = $params['timeup']; - $result = array(); + $result = []; // Update the timemodifiedoffline field. $attemptobj->set_offline_modified_time($timenow); $result['state'] = $attemptobj->process_attempt($timenow, $finishattempt, $timeup, 0); @@ -1363,11 +1363,11 @@ class mod_quiz_external extends external_api { */ public static function process_attempt_returns() { return new external_single_structure( - array( + [ 'state' => new external_value(PARAM_ALPHANUMEXT, 'state: the new attempt state: inprogress, finished, overdue, abandoned'), 'warnings' => new external_warnings(), - ) + ] ); } @@ -1394,7 +1394,7 @@ class mod_quiz_external extends external_api { } else if (!$attemptobj->is_review_allowed()) { throw new moodle_exception('noreviewattempt', 'quiz', $attemptobj->view_url()); } - return array($attemptobj, $displayoptions); + return [$attemptobj, $displayoptions]; } /** @@ -1405,11 +1405,11 @@ class mod_quiz_external extends external_api { */ public static function get_attempt_review_parameters() { return new external_function_parameters ( - array( + [ 'attemptid' => new external_value(PARAM_INT, 'attempt id'), 'page' => new external_value(PARAM_INT, 'page number, empty for all the questions in all the pages', VALUE_DEFAULT, -1), - ) + ] ); } @@ -1424,12 +1424,12 @@ class mod_quiz_external extends external_api { public static function get_attempt_review($attemptid, $page = -1) { global $PAGE; - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'attemptid' => $attemptid, 'page' => $page, - ); + ]; $params = self::validate_parameters(self::get_attempt_review_parameters(), $params); list($attemptobj, $displayoptions) = self::validate_attempt_review($params); @@ -1441,20 +1441,20 @@ class mod_quiz_external extends external_api { } // Prepare the output. - $result = array(); + $result = []; $result['attempt'] = $attemptobj->get_attempt(); $result['questions'] = self::get_attempt_questions_data($attemptobj, true, $page, true); - $result['additionaldata'] = array(); + $result['additionaldata'] = []; // Summary data (from behaviours). $summarydata = $attemptobj->get_additional_summary_data($displayoptions); foreach ($summarydata as $key => $data) { // This text does not need formatting (no need for external_format_[string|text]). - $result['additionaldata'][] = array( + $result['additionaldata'][] = [ 'id' => $key, 'title' => $data['title'], $attemptobj->get_quizobj()->get_context()->id, 'content' => $data['content'], - ); + ]; } // Feedback if there is any, and the user is allowed to see it now. @@ -1462,11 +1462,11 @@ class mod_quiz_external extends external_api { $feedback = $attemptobj->get_overall_feedback($grade); if ($displayoptions->overallfeedback && $feedback) { - $result['additionaldata'][] = array( + $result['additionaldata'][] = [ 'id' => 'feedback', 'title' => get_string('feedback', 'quiz'), 'content' => $feedback, - ); + ]; } $result['grade'] = $grade; @@ -1482,21 +1482,21 @@ class mod_quiz_external extends external_api { */ public static function get_attempt_review_returns() { return new external_single_structure( - array( + [ 'grade' => new external_value(PARAM_RAW, 'grade for the quiz (or empty or "notyetgraded")'), 'attempt' => self::attempt_structure(), 'additionaldata' => new external_multiple_structure( new external_single_structure( - array( + [ 'id' => new external_value(PARAM_ALPHANUMEXT, 'id of the data'), 'title' => new external_value(PARAM_TEXT, 'data title'), 'content' => new external_value(PARAM_RAW, 'data content'), - ) + ] ) ), 'questions' => new external_multiple_structure(self::question_structure()), 'warnings' => new external_warnings(), - ) + ] ); } @@ -1508,18 +1508,18 @@ class mod_quiz_external extends external_api { */ public static function view_attempt_parameters() { return new external_function_parameters ( - array( + [ 'attemptid' => new external_value(PARAM_INT, 'attempt id'), 'page' => new external_value(PARAM_INT, 'page number'), 'preflightdata' => new external_multiple_structure( new external_single_structure( - array( + [ 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), - ) - ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() + ] + ), 'Preflight required data (like passwords)', VALUE_DEFAULT, [] ) - ) + ] ); } @@ -1532,15 +1532,15 @@ class mod_quiz_external extends external_api { * @return array of warnings and status result * @since Moodle 3.1 */ - public static function view_attempt($attemptid, $page, $preflightdata = array()) { + public static function view_attempt($attemptid, $page, $preflightdata = []) { - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'attemptid' => $attemptid, 'page' => $page, 'preflightdata' => $preflightdata, - ); + ]; $params = self::validate_parameters(self::view_attempt_parameters(), $params); list($attemptobj, $messages) = self::validate_attempt($params); @@ -1552,7 +1552,7 @@ class mod_quiz_external extends external_api { throw new moodle_exception('Out of sequence access', 'quiz', $attemptobj->view_url()); } - $result = array(); + $result = []; $result['status'] = true; $result['warnings'] = $warnings; return $result; @@ -1566,10 +1566,10 @@ class mod_quiz_external extends external_api { */ public static function view_attempt_returns() { return new external_single_structure( - array( + [ 'status' => new external_value(PARAM_BOOL, 'status: true if success'), 'warnings' => new external_warnings(), - ) + ] ); } @@ -1581,17 +1581,17 @@ class mod_quiz_external extends external_api { */ public static function view_attempt_summary_parameters() { return new external_function_parameters ( - array( + [ 'attemptid' => new external_value(PARAM_INT, 'attempt id'), 'preflightdata' => new external_multiple_structure( new external_single_structure( - array( + [ 'name' => new external_value(PARAM_ALPHANUMEXT, 'data name'), 'value' => new external_value(PARAM_RAW, 'data value'), - ) - ), 'Preflight required data (like passwords)', VALUE_DEFAULT, array() + ] + ), 'Preflight required data (like passwords)', VALUE_DEFAULT, [] ) - ) + ] ); } @@ -1603,21 +1603,21 @@ class mod_quiz_external extends external_api { * @return array of warnings and status result * @since Moodle 3.1 */ - public static function view_attempt_summary($attemptid, $preflightdata = array()) { + public static function view_attempt_summary($attemptid, $preflightdata = []) { - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'attemptid' => $attemptid, 'preflightdata' => $preflightdata, - ); + ]; $params = self::validate_parameters(self::view_attempt_summary_parameters(), $params); list($attemptobj, $messages) = self::validate_attempt($params); // Log action. $attemptobj->fire_attempt_summary_viewed_event(); - $result = array(); + $result = []; $result['status'] = true; $result['warnings'] = $warnings; return $result; @@ -1631,10 +1631,10 @@ class mod_quiz_external extends external_api { */ public static function view_attempt_summary_returns() { return new external_single_structure( - array( + [ 'status' => new external_value(PARAM_BOOL, 'status: true if success'), 'warnings' => new external_warnings(), - ) + ] ); } @@ -1646,9 +1646,9 @@ class mod_quiz_external extends external_api { */ public static function view_attempt_review_parameters() { return new external_function_parameters ( - array( + [ 'attemptid' => new external_value(PARAM_INT, 'attempt id'), - ) + ] ); } @@ -1661,18 +1661,18 @@ class mod_quiz_external extends external_api { */ public static function view_attempt_review($attemptid) { - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'attemptid' => $attemptid, - ); + ]; $params = self::validate_parameters(self::view_attempt_review_parameters(), $params); list($attemptobj, $displayoptions) = self::validate_attempt_review($params); // Log action. $attemptobj->fire_attempt_reviewed_event(); - $result = array(); + $result = []; $result['status'] = true; $result['warnings'] = $warnings; return $result; @@ -1686,10 +1686,10 @@ class mod_quiz_external extends external_api { */ public static function view_attempt_review_returns() { return new external_single_structure( - array( + [ 'status' => new external_value(PARAM_BOOL, 'status: true if success'), 'warnings' => new external_warnings(), - ) + ] ); } @@ -1701,10 +1701,10 @@ class mod_quiz_external extends external_api { */ public static function get_quiz_feedback_for_grade_parameters() { return new external_function_parameters ( - array( + [ 'quizid' => new external_value(PARAM_INT, 'quiz instance id'), 'grade' => new external_value(PARAM_FLOAT, 'the grade to check'), - ) + ] ); } @@ -1719,16 +1719,16 @@ class mod_quiz_external extends external_api { public static function get_quiz_feedback_for_grade($quizid, $grade) { global $DB; - $params = array( + $params = [ 'quizid' => $quizid, 'grade' => $grade, - ); + ]; $params = self::validate_parameters(self::get_quiz_feedback_for_grade_parameters(), $params); - $warnings = array(); + $warnings = []; list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); - $result = array(); + $result = []; $result['feedbacktext'] = ''; $result['feedbacktextformat'] = FORMAT_MOODLE; @@ -1762,12 +1762,12 @@ class mod_quiz_external extends external_api { */ public static function get_quiz_feedback_for_grade_returns() { return new external_single_structure( - array( + [ 'feedbacktext' => new external_value(PARAM_RAW, 'the comment that corresponds to this grade (empty for none)'), 'feedbacktextformat' => new external_format_value('feedbacktext', VALUE_OPTIONAL), 'feedbackinlinefiles' => new external_files('feedback inline files', VALUE_OPTIONAL), 'warnings' => new external_warnings(), - ) + ] ); } @@ -1779,9 +1779,9 @@ class mod_quiz_external extends external_api { */ public static function get_quiz_access_information_parameters() { return new external_function_parameters ( - array( + [ 'quizid' => new external_value(PARAM_INT, 'quiz instance id') - ) + ] ); } @@ -1795,16 +1795,16 @@ class mod_quiz_external extends external_api { public static function get_quiz_access_information($quizid) { global $DB, $USER; - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'quizid' => $quizid - ); + ]; $params = self::validate_parameters(self::get_quiz_access_information_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); - $result = array(); + $result = []; // Capabilities first. $result['canattempt'] = has_capability('mod/quiz:attempt', $context);; $result['canmanage'] = has_capability('mod/quiz:manage', $context);; @@ -1834,7 +1834,7 @@ class mod_quiz_external extends external_api { */ public static function get_quiz_access_information_returns() { return new external_single_structure( - array( + [ 'canattempt' => new external_value(PARAM_BOOL, 'Whether the user can do the quiz or not.'), 'canmanage' => new external_value(PARAM_BOOL, 'Whether the user can edit the quiz settings or not.'), 'canpreview' => new external_value(PARAM_BOOL, 'Whether the user can preview the quiz or not.'), @@ -1848,7 +1848,7 @@ class mod_quiz_external extends external_api { 'preventaccessreasons' => new external_multiple_structure( new external_value(PARAM_TEXT, 'access restriction description'), 'list of reasons'), 'warnings' => new external_warnings(), - ) + ] ); } @@ -1860,10 +1860,10 @@ class mod_quiz_external extends external_api { */ public static function get_attempt_access_information_parameters() { return new external_function_parameters ( - array( + [ 'quizid' => new external_value(PARAM_INT, 'quiz instance id'), 'attemptid' => new external_value(PARAM_INT, 'attempt id, 0 for the user last attempt if exists', VALUE_DEFAULT, 0), - ) + ] ); } @@ -1878,12 +1878,12 @@ class mod_quiz_external extends external_api { public static function get_attempt_access_information($quizid, $attemptid = 0) { global $DB, $USER; - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'quizid' => $quizid, 'attemptid' => $attemptid, - ); + ]; $params = self::validate_parameters(self::get_attempt_access_information_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); @@ -1921,7 +1921,7 @@ class mod_quiz_external extends external_api { $attempttocheck = $unfinishedattempt ?: $lastfinishedattempt; } - $result = array(); + $result = []; $result['isfinished'] = $accessmanager->is_finished($numattempts, $lastfinishedattempt); $result['preventnewattemptreasons'] = $accessmanager->prevent_new_attempt($numattempts, $lastfinishedattempt); @@ -1944,7 +1944,7 @@ class mod_quiz_external extends external_api { */ public static function get_attempt_access_information_returns() { return new external_single_structure( - array( + [ 'endtime' => new external_value(PARAM_INT, 'When the attempt must be submitted (determined by rules).', VALUE_OPTIONAL), 'isfinished' => new external_value(PARAM_BOOL, 'Whether there is no way the user will ever be allowed to attempt.'), @@ -1954,7 +1954,7 @@ class mod_quiz_external extends external_api { new external_value(PARAM_TEXT, 'access restriction description'), 'list of reasons'), 'warnings' => new external_warnings(), - ) + ] ); } @@ -1966,9 +1966,9 @@ class mod_quiz_external extends external_api { */ public static function get_quiz_required_qtypes_parameters() { return new external_function_parameters ( - array( + [ 'quizid' => new external_value(PARAM_INT, 'quiz instance id') - ) + ] ); } @@ -1983,11 +1983,11 @@ class mod_quiz_external extends external_api { public static function get_quiz_required_qtypes($quizid) { global $DB, $USER; - $warnings = array(); + $warnings = []; - $params = array( + $params = [ 'quizid' => $quizid - ); + ]; $params = self::validate_parameters(self::get_quiz_required_qtypes_parameters(), $params); list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']); @@ -1997,7 +1997,7 @@ class mod_quiz_external extends external_api { $quizobj->load_questions(); // Question types used. - $result = array(); + $result = []; $result['questiontypes'] = $quizobj->get_all_question_types_used(true); $result['warnings'] = $warnings; return $result; @@ -2011,11 +2011,11 @@ class mod_quiz_external extends external_api { */ public static function get_quiz_required_qtypes_returns() { return new external_single_structure( - array( + [ 'questiontypes' => new external_multiple_structure( new external_value(PARAM_PLUGIN, 'question type'), 'list of question types used in the quiz'), 'warnings' => new external_warnings(), - ) + ] ); } diff --git a/mod/quiz/classes/form/add_random_form.php b/mod/quiz/classes/form/add_random_form.php index 2498abb0e2e..d90d2495602 100644 --- a/mod/quiz/classes/form/add_random_form.php +++ b/mod/quiz/classes/form/add_random_form.php @@ -47,7 +47,7 @@ class add_random_form extends moodleform { get_string('randomfromexistingcategory', 'quiz')); $mform->addElement('questioncategory', 'category', get_string('category'), - array('contexts' => $usablecontexts, 'top' => true)); + ['contexts' => $usablecontexts, 'top' => true]); $mform->setDefault('category', $this->_customdata['cat']); $mform->addElement('checkbox', 'includesubcategories', '', get_string('recurse', 'quiz')); @@ -56,15 +56,15 @@ class add_random_form extends moodleform { $mform->hideIf('includesubcategories', 'category', 'in', $tops); if ($CFG->usetags) { - $tagstrings = array(); + $tagstrings = []; $tags = core_tag_tag::get_tags_by_area_in_contexts('core_question', 'question', $usablecontexts); foreach ($tags as $tag) { $tagstrings["{$tag->id},{$tag->name}"] = $tag->name; } - $options = array( + $options = [ 'multiple' => true, 'noselectionstring' => get_string('anytags', 'quiz'), - ); + ]; $mform->addElement('autocomplete', 'fromtags', get_string('randomquestiontags', 'mod_quiz'), $tagstrings, $options); $mform->addHelpButton('fromtags', 'randomquestiontags', 'mod_quiz'); } @@ -92,7 +92,7 @@ class add_random_form extends moodleform { $mform->setType('name', PARAM_TEXT); $mform->addElement('questioncategory', 'parent', get_string('parentcategory', 'question'), - array('contexts' => $usablecontexts, 'top' => true)); + ['contexts' => $usablecontexts, 'top' => true]); $mform->addHelpButton('parent', 'parentcategory', 'question'); $mform->addElement('submit', 'newcategory', @@ -136,7 +136,7 @@ class add_random_form extends moodleform { * @return array of integers [1, 2, ..., 100] (or to the smaller of $maxrand and 100.) */ private function get_number_of_questions_to_add_choices($maxrand = 100) { - $randomcount = array(); + $randomcount = []; for ($i = 1; $i <= min(100, $maxrand); $i++) { $randomcount[$i] = $i; } diff --git a/mod/quiz/classes/form/preflight_check_form.php b/mod/quiz/classes/form/preflight_check_form.php index a734d137fec..37eb007b9cc 100644 --- a/mod/quiz/classes/form/preflight_check_form.php +++ b/mod/quiz/classes/form/preflight_check_form.php @@ -33,7 +33,7 @@ class preflight_check_form extends moodleform { protected function definition() { $mform = $this->_form; - $this->_form->updateAttributes(array('id' => 'mod_quiz_preflight_form')); + $this->_form->updateAttributes(['id' => 'mod_quiz_preflight_form']); foreach ($this->_customdata['hidden'] as $name => $value) { if ($name === 'sesskey') { diff --git a/mod/quiz/classes/form/randomquestion_form.php b/mod/quiz/classes/form/randomquestion_form.php index 140f71810f4..4636e115eb0 100644 --- a/mod/quiz/classes/form/randomquestion_form.php +++ b/mod/quiz/classes/form/randomquestion_form.php @@ -50,22 +50,22 @@ class randomquestion_form extends \moodleform { $mform->addElement('header', 'generalheader', get_string("general", 'form')); $mform->addElement('questioncategory', 'category', get_string('category', 'question'), - array('contexts' => $usablecontexts, 'top' => true)); + ['contexts' => $usablecontexts, 'top' => true]); - $mform->addElement('advcheckbox', 'includesubcategories', get_string('recurse', 'quiz'), null, null, array(0, 1)); + $mform->addElement('advcheckbox', 'includesubcategories', get_string('recurse', 'quiz'), null, null, [0, 1]); $tops = question_get_top_categories_for_contexts(array_column($contexts->all(), 'id')); $mform->hideIf('includesubcategories', 'category', 'in', $tops); $tags = \core_tag_tag::get_tags_by_area_in_contexts('core_question', 'question', $usablecontexts); - $tagstrings = array(); + $tagstrings = []; foreach ($tags as $tag) { $tagstrings["{$tag->id},{$tag->name}"] = $tag->name; } - $options = array( + $options = [ 'multiple' => true, 'noselectionstring' => get_string('anytags', 'quiz'), - ); + ]; $mform->addElement('autocomplete', 'fromtags', get_string('randomquestiontags', 'mod_quiz'), $tagstrings, $options); $mform->addHelpButton('fromtags', 'randomquestiontags', 'mod_quiz'); @@ -75,10 +75,10 @@ class randomquestion_form extends \moodleform { $mform->addElement('hidden', 'returnurl'); $mform->setType('returnurl', PARAM_LOCALURL); - $buttonarray = array(); + $buttonarray = []; $buttonarray[] = $mform->createElement('submit', 'submitbutton', get_string('savechanges')); $buttonarray[] = $mform->createElement('cancel'); - $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); + $mform->addGroup($buttonarray, 'buttonar', '', [' '], false); $mform->closeHeaderBefore('buttonar'); } diff --git a/mod/quiz/classes/group_observers.php b/mod/quiz/classes/group_observers.php index c77e3d182f7..3728db6d138 100644 --- a/mod/quiz/classes/group_observers.php +++ b/mod/quiz/classes/group_observers.php @@ -65,7 +65,7 @@ class group_observers { quiz_process_group_deleted_in_course($event->courseid); } if (!empty($event->other['reset_options']['reset_groups_members'])) { - quiz_update_open_attempts(array('courseid' => $event->courseid)); + quiz_update_open_attempts(['courseid' => $event->courseid]); } } @@ -93,7 +93,7 @@ class group_observers { * @return void */ public static function group_member_added($event) { - quiz_update_open_attempts(array('userid' => $event->relateduserid, 'groupid' => $event->objectid)); + quiz_update_open_attempts(['userid' => $event->relateduserid, 'groupid' => $event->objectid]); } /** @@ -107,7 +107,7 @@ class group_observers { // We will take care of that once the course reset ends. return; } - quiz_update_open_attempts(array('userid' => $event->relateduserid, 'groupid' => $event->objectid)); + quiz_update_open_attempts(['userid' => $event->relateduserid, 'groupid' => $event->objectid]); } } diff --git a/mod/quiz/classes/local/access_rule_base.php b/mod/quiz/classes/local/access_rule_base.php index 9ab7b85c92b..085a806b339 100644 --- a/mod/quiz/classes/local/access_rule_base.php +++ b/mod/quiz/classes/local/access_rule_base.php @@ -82,7 +82,7 @@ abstract class access_rule_base { * Whether a user should be allowed to start a new attempt at this quiz now. * * @param int $numprevattempts the number of previous attempts this user has made. - * @param object $lastattempt information about the user's last completed attempt. + * @param stdClass $lastattempt information about the user's last completed attempt. * @return string false if access should be allowed, a message explaining the * reason if access should be prevented. */ @@ -185,7 +185,7 @@ abstract class access_rule_base { * active attempt for this user. * * @param int $numprevattempts the number of previous attempts this user has made. - * @param object $lastattempt information about the user's last completed attempt. + * @param stdClass $lastattempt information about the user's last completed attempt. * @return bool true if this rule means that this user will never be allowed another * attempt at this quiz. */ @@ -206,7 +206,7 @@ abstract class access_rule_base { /** * If the user should be shown a different amount of time than $timenow - $this->end_time(), then * override this method. This is useful if the time remaining is large enough to be omitted. - * @param object $attempt the current attempt + * @param stdClass $attempt the current attempt * @param int $timenow the time now. We don't use $this->timenow, so we can * give the user a more accurate indication of how much time is left. * @return mixed the time left in seconds (can be negative) or false if there is no limit. @@ -301,7 +301,7 @@ abstract class access_rule_base { /** * Save any submitted settings when the quiz settings form is submitted. This * is called from {@see quiz_after_add_or_update()} in lib.php. - * @param object $quiz the data from the quiz form, including $quiz->id + * @param stdClass $quiz the data from the quiz form, including $quiz->id * which is the id of the quiz being saved. */ public static function save_settings($quiz) { @@ -311,7 +311,7 @@ abstract class access_rule_base { /** * Delete any rule-specific settings when the quiz is deleted. This is called * from {@see quiz_delete_instance()} in lib.php. - * @param object $quiz the data from the database, including $quiz->id + * @param stdClass $quiz the data from the database, including $quiz->id * which is the id of the quiz being deleted. * @since Moodle 2.7.1, 2.6.4, 2.5.7 */ diff --git a/mod/quiz/classes/local/reports/attempts_report.php b/mod/quiz/classes/local/reports/attempts_report.php index 9f246fd21b4..ce1f1519ca9 100644 --- a/mod/quiz/classes/local/reports/attempts_report.php +++ b/mod/quiz/classes/local/reports/attempts_report.php @@ -68,9 +68,9 @@ abstract class attempts_report extends report_base { * * @param string $mode * @param string $formclass - * @param object $quiz - * @param object $cm - * @param object $course + * @param stdClass $quiz + * @param stdClass $cm + * @param stdClass $course * @return array with four elements: * 0 => integer the current group id (0 for none). * 1 => \core\dml\sql_join Contains joins, wheres, params for all the students in this course. @@ -107,8 +107,8 @@ abstract class attempts_report extends report_base { * Get sql fragments (joins) which can be used to build queries that * will select an appropriate set of students to show in the reports. * - * @param object $cm the course module. - * @param object $course the course settings. + * @param stdClass $cm the course module. + * @param stdClass $course the course settings. * @return array with four elements: * 0 => integer the current group id (0 for none). * 1 => \core\dml\sql_join Contains joins, wheres, params for all the students in this course. @@ -257,7 +257,7 @@ abstract class attempts_report extends report_base { /** * Add all the grade and feedback columns, if applicable, to the $columns * and $headers arrays. - * @param object $quiz the quiz settings. + * @param stdClass $quiz the quiz settings. * @param bool $usercanseegrades whether the user is allowed to see grades for this quiz. * @param array $columns the list of columns. Added to. * @param array $headers the columns headings. Added to. @@ -305,8 +305,8 @@ abstract class attempts_report extends report_base { /** * Process any submitted actions. - * @param object $quiz the quiz settings. - * @param object $cm the cm object for the quiz. + * @param stdClass $quiz the quiz settings. + * @param stdClass $cm the cm object for the quiz. * @param int $currentgroup the currently selected group. * @param \core\dml\sql_join $groupstudentsjoins (joins, wheres, params) the students in the current group. * @param \core\dml\sql_join $allowedjoins (joins, wheres, params) the users whose attempt this user is allowed to modify. @@ -327,9 +327,9 @@ abstract class attempts_report extends report_base { /** * Delete the quiz attempts - * @param object $quiz the quiz settings. Attempts that don't belong to + * @param stdClass $quiz the quiz settings. Attempts that don't belong to * this quiz are not deleted. - * @param object $cm the course_module object. + * @param stdClass $cm the course_module object. * @param array $attemptids the list of attempt ids to delete. * @param \core\dml\sql_join $allowedjoins (joins, wheres, params) This list of userids that are visible in the report. * Users can only delete attempts that they are allowed to see in the report. diff --git a/mod/quiz/classes/local/reports/attempts_report_options.php b/mod/quiz/classes/local/reports/attempts_report_options.php index 5d8f92383d5..8f55cbdcb32 100644 --- a/mod/quiz/classes/local/reports/attempts_report_options.php +++ b/mod/quiz/classes/local/reports/attempts_report_options.php @@ -90,9 +90,9 @@ class attempts_report_options { * Constructor. * * @param string $mode which report these options are for. - * @param object $quiz the settings for the quiz being reported on. - * @param object $cm the course module objects for the quiz being reported on. - * @param object $course the course settings for the coures this quiz is in. + * @param stdClass $quiz the settings for the quiz being reported on. + * @param stdClass $cm the course module objects for the quiz being reported on. + * @param stdClass $course the course settings for the coures this quiz is in. */ public function __construct($mode, $quiz, $cm, $course) { $this->mode = $mode; @@ -137,7 +137,7 @@ class attempts_report_options { * Process the data we get when the settings form is submitted. This includes * updating the fields of this class, and updating the user preferences * where appropriate. - * @param object $fromform The data from $mform->get_data() from the settings form. + * @param stdClass $fromform The data from $mform->get_data() from the settings form. */ public function process_settings_from_form($fromform) { $this->setup_from_form_data($fromform); @@ -175,7 +175,7 @@ class attempts_report_options { /** * Set the fields of this object from the form data. - * @param object $fromform The data from $mform->get_data() from the settings form. + * @param stdClass $fromform The data from $mform->get_data() from the settings form. */ public function setup_from_form_data($fromform) { $this->attempts = $fromform->attempts; diff --git a/mod/quiz/classes/local/reports/report_base.php b/mod/quiz/classes/local/reports/report_base.php index a6bcffe8cbe..edfac16b31a 100644 --- a/mod/quiz/classes/local/reports/report_base.php +++ b/mod/quiz/classes/local/reports/report_base.php @@ -77,8 +77,8 @@ abstract class report_base { /** * Get the current group for the user user looking at the report. * - * @param object $cm the course_module information. - * @param object $course the course settings. + * @param stdClass $cm the course_module information. + * @param stdClass $course the course settings. * @param context $context the quiz context. * @return int the current group id, if applicable. 0 for all users, * NO_GROUPS_ALLOWED if the user cannot see any group. diff --git a/mod/quiz/classes/local/structure/slot_random.php b/mod/quiz/classes/local/structure/slot_random.php index fe2abedc166..644e521e384 100644 --- a/mod/quiz/classes/local/structure/slot_random.php +++ b/mod/quiz/classes/local/structure/slot_random.php @@ -88,7 +88,7 @@ class slot_random { if (empty($this->record->quizid)) { throw new \coding_exception('quizid is not set.'); } - $this->quiz = $DB->get_record('quiz', array('id' => $this->record->quizid)); + $this->quiz = $DB->get_record('quiz', ['id' => $this->record->quizid]); } return $this->quiz; @@ -151,7 +151,7 @@ class slot_random { public function insert($page) { global $DB; - $slots = $DB->get_records('quiz_slots', array('quizid' => $this->record->quizid), + $slots = $DB->get_records('quiz_slots', ['quizid' => $this->record->quizid], 'slot', 'id, slot, page'); $quiz = $this->get_quiz(); @@ -173,7 +173,7 @@ class slot_random { $lastslotbefore = 0; foreach (array_reverse($slots) as $otherslot) { if ($otherslot->page > $page) { - $DB->set_field('quiz_slots', 'slot', $otherslot->slot + 1, array('id' => $otherslot->id)); + $DB->set_field('quiz_slots', 'slot', $otherslot->slot + 1, ['id' => $otherslot->id]); } else { $lastslotbefore = $otherslot->slot; break; diff --git a/mod/quiz/classes/output/edit_renderer.php b/mod/quiz/classes/output/edit_renderer.php index 25ae62954af..85d735b0cc7 100644 --- a/mod/quiz/classes/output/edit_renderer.php +++ b/mod/quiz/classes/output/edit_renderer.php @@ -94,7 +94,7 @@ class edit_renderer extends \plugin_renderer_base { if ($structure->is_last_section($section)) { $output .= \html_writer::start_div('last-add-menu'); $output .= html_writer::tag('span', $this->add_menu_actions($structure, 0, - $pageurl, $contexts, $pagevars), array('class' => 'add-menu-outer')); + $pageurl, $contexts, $pagevars), ['class' => 'add-menu-outer']); $output .= \html_writer::end_div(); } @@ -143,7 +143,7 @@ class edit_renderer extends \plugin_renderer_base { return ''; } - $output = array(); + $output = []; foreach ($warnings as $warning) { $output[] = \html_writer::tag('p', $warning); } @@ -163,7 +163,7 @@ class edit_renderer extends \plugin_renderer_base { get_string('numquestionsx', 'quiz', $structure->get_question_count()), 'numberofquestions') . ' | ' . html_writer::span($currentstatus, 'quizopeningstatus', - array('title' => $explanation)); + ['title' => $explanation]); return html_writer::div($output, 'statusbar'); } @@ -178,19 +178,19 @@ class edit_renderer extends \plugin_renderer_base { public function maximum_grade_input($structure, \moodle_url $pageurl) { $output = ''; $output .= html_writer::start_div('maxgrade'); - $output .= html_writer::start_tag('form', array('method' => 'post', 'action' => 'edit.php', - 'class' => 'quizsavegradesform form-inline')); - $output .= html_writer::start_tag('fieldset', array('class' => 'invisiblefieldset')); - $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); + $output .= html_writer::start_tag('form', ['method' => 'post', 'action' => 'edit.php', + 'class' => 'quizsavegradesform form-inline']); + $output .= html_writer::start_tag('fieldset', ['class' => 'invisiblefieldset']); + $output .= html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()]); $output .= html_writer::input_hidden_params($pageurl); $output .= html_writer::tag('label', get_string('maximumgrade') . ' ', - array('for' => 'inputmaxgrade')); - $output .= html_writer::empty_tag('input', array('type' => 'text', 'id' => 'inputmaxgrade', + ['for' => 'inputmaxgrade']); + $output .= html_writer::empty_tag('input', ['type' => 'text', 'id' => 'inputmaxgrade', 'name' => 'maxgrade', 'size' => ($structure->get_decimal_places_for_grades() + 2), 'value' => $structure->formatted_quiz_grade(), - 'class' => 'form-control')); - $output .= html_writer::empty_tag('input', array('type' => 'submit', 'class' => 'btn btn-secondary ml-1', - 'name' => 'savechanges', 'value' => get_string('save', 'quiz'))); + 'class' => 'form-control']); + $output .= html_writer::empty_tag('input', ['type' => 'submit', 'class' => 'btn btn-secondary ml-1', + 'name' => 'savechanges', 'value' => get_string('save', 'quiz')]); $output .= html_writer::end_tag('fieldset'); $output .= html_writer::end_tag('form'); $output .= html_writer::end_tag('div'); @@ -204,10 +204,10 @@ class edit_renderer extends \plugin_renderer_base { * @return string HTML to output. */ protected function repaginate_button(structure $structure, \moodle_url $pageurl) { - $header = html_writer::tag('span', get_string('repaginatecommand', 'quiz'), array('class' => 'repaginatecommand')); + $header = html_writer::tag('span', get_string('repaginatecommand', 'quiz'), ['class' => 'repaginatecommand']); $form = $this->repaginate_form($structure, $pageurl); - $buttonoptions = array( + $buttonoptions = [ 'type' => 'submit', 'name' => 'repaginate', 'id' => 'repaginatecommand', @@ -215,7 +215,7 @@ class edit_renderer extends \plugin_renderer_base { 'class' => 'btn btn-secondary mr-1', 'data-header' => $header, 'data-form' => $form, - ); + ]; if (!$structure->can_be_repaginated()) { $buttonoptions['disabled'] = 'disabled'; } else { @@ -232,13 +232,13 @@ class edit_renderer extends \plugin_renderer_base { * @return string HTML to output. */ protected function selectmultiple_button(structure $structure) { - $buttonoptions = array( + $buttonoptions = [ 'type' => 'button', 'name' => 'selectmultiple', 'id' => 'selectmultiplecommand', 'value' => get_string('selectmultipleitems', 'quiz'), 'class' => 'btn btn-secondary' - ); + ]; if (!$structure->can_be_edited()) { $buttonoptions['disabled'] = 'disabled'; } @@ -256,7 +256,7 @@ class edit_renderer extends \plugin_renderer_base { $output = ''; // Bulk action button delete and bulk action button cancel. - $buttondeleteoptions = array( + $buttondeleteoptions = [ 'type' => 'button', 'id' => 'selectmultipledeletecommand', 'value' => get_string('deleteselected', 'mod_quiz'), @@ -265,18 +265,18 @@ class edit_renderer extends \plugin_renderer_base { 'data-togglegroup' => $this->togglegroup, 'data-toggle' => 'action', 'disabled' => true - ); - $buttoncanceloptions = array( + ]; + $buttoncanceloptions = [ 'type' => 'button', 'id' => 'selectmultiplecancelcommand', 'value' => get_string('cancel', 'moodle'), 'class' => 'btn btn-secondary' - ); + ]; - $groupoptions = array( + $groupoptions = [ 'class' => 'btn-group selectmultiplecommand actions m-1', 'role' => 'group' - ); + ]; $output .= html_writer::tag('div', html_writer::tag('button', get_string('deleteselected', 'mod_quiz'), $buttondeleteoptions) . @@ -284,11 +284,11 @@ class edit_renderer extends \plugin_renderer_base { html_writer::tag('button', get_string('cancel', 'moodle'), $buttoncanceloptions), $groupoptions); - $toolbaroptions = array( + $toolbaroptions = [ 'class' => 'btn-toolbar m-1', 'role' => 'toolbar', 'aria-label' => get_string('selectmultipletoolbar', 'quiz'), - ); + ]; // Select all/deselect all questions. $selectallid = 'questionselectall'; @@ -315,7 +315,7 @@ class edit_renderer extends \plugin_renderer_base { * @return string HTML to output. */ protected function repaginate_form(structure $structure, \moodle_url $pageurl) { - $perpage = array(); + $perpage = []; $perpage[0] = get_string('allinone', 'quiz'); for ($i = 1; $i <= 50; ++$i) { $perpage[$i] = $i; @@ -325,22 +325,22 @@ class edit_renderer extends \plugin_renderer_base { $hiddenurl->param('sesskey', sesskey()); $select = html_writer::select($perpage, 'questionsperpage', - $structure->get_questions_per_page(), false, array('class' => 'custom-select')); + $structure->get_questions_per_page(), false, ['class' => 'custom-select']); - $buttonattributes = array( + $buttonattributes = [ 'type' => 'submit', 'name' => 'repaginate', 'value' => get_string('go'), 'class' => 'btn btn-secondary ml-1' - ); + ]; $formcontent = html_writer::tag('form', html_writer::div( html_writer::input_hidden_params($hiddenurl) . get_string('repaginate', 'quiz', $select) . html_writer::empty_tag('input', $buttonattributes) - ), array('action' => 'edit.php', 'method' => 'post')); + ), ['action' => 'edit.php', 'method' => 'post']); - return html_writer::div($formcontent, '', array('id' => 'repaginatedialog')); + return html_writer::div($formcontent, '', ['id' => 'repaginatedialog']); } /** @@ -353,7 +353,7 @@ class edit_renderer extends \plugin_renderer_base { $totalmark = html_writer::span(quiz_format_grade($quiz, $quiz->sumgrades), 'mod_quiz_summarks'); return html_writer::tag('span', get_string('totalmarksx', 'quiz', $totalmark), - array('class' => 'totalpoints')); + ['class' => 'totalpoints']); } /** @@ -366,7 +366,7 @@ class edit_renderer extends \plugin_renderer_base { if ($structure->get_section_count() == 1) { $class .= ' only-one-section'; } - return html_writer::start_tag('ul', array('class' => $class, 'role' => 'presentation')); + return html_writer::start_tag('ul', ['class' => $class, 'role' => 'presentation']); } /** @@ -402,9 +402,9 @@ class edit_renderer extends \plugin_renderer_base { $sectionheading = html_writer::span($sectionheadingtext, 'instancesection sr-only'); } - $output .= html_writer::start_tag('li', array('id' => 'section-'.$section->id, + $output .= html_writer::start_tag('li', ['id' => 'section-'.$section->id, 'class' => 'section main clearfix'.$sectionstyle, 'role' => 'presentation', - 'data-sectionname' => $sectionheadingtext)); + 'data-sectionname' => $sectionheadingtext]); $output .= html_writer::start_div('content'); @@ -417,8 +417,8 @@ class edit_renderer extends \plugin_renderer_base { } else { $editsectionheadingicon = html_writer::link(new \moodle_url('#'), $this->pix_icon('t/editstring', get_string('sectionheadingedit', 'quiz', $sectionheadingtext), - 'moodle', array('class' => 'editicon visibleifjs')), - array('class' => 'editing_section', 'data-action' => 'edit_section_title', 'role' => 'button')); + 'moodle', ['class' => 'editicon visibleifjs']), + ['class' => 'editing_section', 'data-action' => 'edit_section_title', 'role' => 'button']); } $output .= html_writer::div($headingtext . $editsectionheadingicon, 'instancesectioncontainer'); @@ -440,13 +440,13 @@ class edit_renderer extends \plugin_renderer_base { * @return string HTML to output. */ public function section_shuffle_questions(structure $structure, $section) { - $checkboxattributes = array( + $checkboxattributes = [ 'type' => 'checkbox', 'id' => 'shuffle-' . $section->id, 'value' => 1, 'data-action' => 'shuffle_questions', 'class' => 'cm-edit-action', - ); + ]; if (!$structure->can_be_edited()) { $checkboxattributes['disabled'] = 'disabled'; @@ -467,7 +467,7 @@ class edit_renderer extends \plugin_renderer_base { $label = html_writer::label(get_string('shufflequestions', 'quiz'), $checkboxattributes['id'], false); return html_writer::span($progressspan . $checkbox . $label. ' ' . $helpspan, - 'instanceshufflequestions', array('data-action' => 'shuffle_questions')); + 'instanceshufflequestions', ['data-action' => 'shuffle_questions']); } /** @@ -485,16 +485,16 @@ class edit_renderer extends \plugin_renderer_base { /** * Render an icon to remove a section from the quiz. * - * @param object $section the section to be removed. + * @param stdClass $section the section to be removed. * @return string HTML to output. */ public function section_remove_icon($section) { $title = get_string('sectionheadingremove', 'quiz', format_string($section->heading)); $url = new \moodle_url('/mod/quiz/edit.php', - array('sesskey' => sesskey(), 'removesection' => '1', 'sectionid' => $section->id)); + ['sesskey' => sesskey(), 'removesection' => '1', 'sectionid' => $section->id]); $image = $this->pix_icon('t/delete', $title); - return $this->action_link($url, $image, null, array( - 'class' => 'cm-edit-action editing_delete', 'data-action' => 'deletesection')); + return $this->action_link($url, $image, null, [ + 'class' => 'cm-edit-action editing_delete', 'data-action' => 'deletesection']); } /** @@ -516,7 +516,7 @@ class edit_renderer extends \plugin_renderer_base { foreach ($structure->get_slots_in_section($section->id) as $slot) { $output .= $this->question_row($structure, $slot, $contexts, $pagevars, $pageurl); } - return html_writer::tag('ul', $output, array('class' => 'section img-text')); + return html_writer::tag('ul', $output, ['class' => 'section img-text']); } /** @@ -546,8 +546,8 @@ class edit_renderer extends \plugin_renderer_base { $questionclasses = 'activity ' . $qtype . ' qtype_' . $qtype . ' slot'; $output .= html_writer::tag('li', $questionhtml . $joinhtml, - array('class' => $questionclasses, 'id' => 'slot-' . $structure->get_slot_id_for_slot($slot), - 'data-canfinish' => $structure->can_finish_during_the_attempt($slot))); + ['class' => $questionclasses, 'id' => 'slot-' . $structure->get_slot_id_for_slot($slot), + 'data-canfinish' => $structure->can_finish_during_the_attempt($slot)]); return $output; } @@ -574,13 +574,13 @@ class edit_renderer extends \plugin_renderer_base { // Add the add-menu at the page level. $addmenu = html_writer::tag('span', $this->add_menu_actions($structure, $pagenumber, $pageurl, $contexts, $pagevars), - array('class' => 'add-menu-outer')); + ['class' => 'add-menu-outer']); $addquestionform = $this->add_question_form($structure, $pagenumber, $pageurl, $pagevars); $output .= html_writer::tag('li', $page . $addmenu . $addquestionform, - array('class' => 'pagenumber activity yui3-dd-drop page', 'id' => 'page-' . $pagenumber)); + ['class' => 'pagenumber activity yui3-dd-drop page', 'id' => 'page-' . $pagenumber]); } return $output; @@ -604,7 +604,7 @@ class edit_renderer extends \plugin_renderer_base { } $menu = new \action_menu(); $menu->set_constraint('.mod-quiz-edit-content'); - $trigger = html_writer::tag('span', get_string('add', 'quiz'), array('class' => 'add-menu')); + $trigger = html_writer::tag('span', get_string('add', 'quiz'), ['class' => 'add-menu']); $menu->set_menu_trigger($trigger); // The menu appears within an absolutely positioned element causing width problems. // Make sure no-wrap is set so that we don't get a squashed menu. @@ -642,61 +642,61 @@ class edit_renderer extends \plugin_renderer_base { $questioncategoryid = question_get_category_id_from_pagevars($pagevars); static $str; if (!isset($str)) { - $str = get_strings(array('addasection', 'addaquestion', 'addarandomquestion', - 'addarandomselectedquestion', 'questionbank'), 'quiz'); + $str = get_strings(['addasection', 'addaquestion', 'addarandomquestion', + 'addarandomselectedquestion', 'questionbank'], 'quiz'); } // Get section, page, slotnumber and maxmark. - $actions = array(); + $actions = []; // Add a new question to the quiz. - $returnurl = new \moodle_url($pageurl, array('addonpage' => $page)); - $params = array('returnurl' => $returnurl->out_as_local_url(false), + $returnurl = new \moodle_url($pageurl, ['addonpage' => $page]); + $params = ['returnurl' => $returnurl->out_as_local_url(false), 'cmid' => $structure->get_cmid(), 'category' => $questioncategoryid, - 'addonpage' => $page, 'appendqnumstring' => 'addquestion'); + 'addonpage' => $page, 'appendqnumstring' => 'addquestion']; $actions['addaquestion'] = new \action_menu_link_secondary( new \moodle_url('/question/bank/editquestion/addquestion.php', $params), - new \pix_icon('t/add', $str->addaquestion, 'moodle', array('class' => 'iconsmall', 'title' => '')), - $str->addaquestion, array('class' => 'cm-edit-action addquestion', 'data-action' => 'addquestion') + new \pix_icon('t/add', $str->addaquestion, 'moodle', ['class' => 'iconsmall', 'title' => '']), + $str->addaquestion, ['class' => 'cm-edit-action addquestion', 'data-action' => 'addquestion'] ); // Call question bank. - $icon = new \pix_icon('t/add', $str->questionbank, 'moodle', array('class' => 'iconsmall', 'title' => '')); + $icon = new \pix_icon('t/add', $str->questionbank, 'moodle', ['class' => 'iconsmall', 'title' => '']); if ($page) { $title = get_string('addquestionfrombanktopage', 'quiz', $page); } else { $title = get_string('addquestionfrombankatend', 'quiz'); } - $attributes = array('class' => 'cm-edit-action questionbank', - 'data-header' => $title, 'data-action' => 'questionbank', 'data-addonpage' => $page); + $attributes = ['class' => 'cm-edit-action questionbank', + 'data-header' => $title, 'data-action' => 'questionbank', 'data-addonpage' => $page]; $actions['questionbank'] = new \action_menu_link_secondary($pageurl, $icon, $str->questionbank, $attributes); // Add a random question. if ($structure->can_add_random_questions()) { - $returnurl = new \moodle_url('/mod/quiz/edit.php', array('cmid' => $structure->get_cmid(), 'data-addonpage' => $page)); + $returnurl = new \moodle_url('/mod/quiz/edit.php', ['cmid' => $structure->get_cmid(), 'data-addonpage' => $page]); $params = ['returnurl' => $returnurl, 'cmid' => $structure->get_cmid(), 'appendqnumstring' => 'addarandomquestion']; $url = new \moodle_url('/mod/quiz/addrandom.php', $params); - $icon = new \pix_icon('t/add', $str->addarandomquestion, 'moodle', array('class' => 'iconsmall', 'title' => '')); - $attributes = array('class' => 'cm-edit-action addarandomquestion', 'data-action' => 'addarandomquestion'); + $icon = new \pix_icon('t/add', $str->addarandomquestion, 'moodle', ['class' => 'iconsmall', 'title' => '']); + $attributes = ['class' => 'cm-edit-action addarandomquestion', 'data-action' => 'addarandomquestion']; if ($page) { $title = get_string('addrandomquestiontopage', 'quiz', $page); } else { $title = get_string('addrandomquestionatend', 'quiz'); } - $attributes = array_merge(array('data-header' => $title, 'data-addonpage' => $page), $attributes); + $attributes = array_merge(['data-header' => $title, 'data-addonpage' => $page], $attributes); $actions['addarandomquestion'] = new \action_menu_link_secondary($url, $icon, $str->addarandomquestion, $attributes); } // Add a new section to the add_menu if possible. This is always added to the HTML // then hidden with CSS when no needed, so that as things are re-ordered, etc. with // Ajax it can be relevaled again when necessary. - $params = array('cmid' => $structure->get_cmid(), 'addsectionatpage' => $page); + $params = ['cmid' => $structure->get_cmid(), 'addsectionatpage' => $page]; $actions['addasection'] = new \action_menu_link_secondary( new \moodle_url($pageurl, $params), - new \pix_icon('t/add', $str->addasection, 'moodle', array('class' => 'iconsmall', 'title' => '')), - $str->addasection, array('class' => 'cm-edit-action addasection', 'data-action' => 'addasection') + new \pix_icon('t/add', $str->addasection, 'moodle', ['class' => 'iconsmall', 'title' => '']), + $str->addasection, ['class' => 'cm-edit-action addasection', 'data-action' => 'addasection'] ); return $actions; @@ -716,18 +716,18 @@ class edit_renderer extends \plugin_renderer_base { $questioncategoryid = question_get_category_id_from_pagevars($pagevars); $output = html_writer::tag('input', null, - array('type' => 'hidden', 'name' => 'returnurl', - 'value' => $pageurl->out_as_local_url(false, array('addonpage' => $page)))); + ['type' => 'hidden', 'name' => 'returnurl', + 'value' => $pageurl->out_as_local_url(false, ['addonpage' => $page])]); $output .= html_writer::tag('input', null, - array('type' => 'hidden', 'name' => 'cmid', 'value' => $structure->get_cmid())); + ['type' => 'hidden', 'name' => 'cmid', 'value' => $structure->get_cmid()]); $output .= html_writer::tag('input', null, - array('type' => 'hidden', 'name' => 'appendqnumstring', 'value' => 'addquestion')); + ['type' => 'hidden', 'name' => 'appendqnumstring', 'value' => 'addquestion']); $output .= html_writer::tag('input', null, - array('type' => 'hidden', 'name' => 'category', 'value' => $questioncategoryid)); + ['type' => 'hidden', 'name' => 'category', 'value' => $questioncategoryid]); return html_writer::tag('form', html_writer::div($output), - array('class' => 'addnewquestion', 'method' => 'post', - 'action' => new \moodle_url('/question/bank/editquestion/addquestion.php'))); + ['class' => 'addnewquestion', 'method' => 'post', + 'action' => new \moodle_url('/question/bank/editquestion/addquestion.php')]); } /** @@ -858,8 +858,8 @@ class edit_renderer extends \plugin_renderer_base { */ public function question_move_icon(structure $structure, $slot) { return html_writer::link(new \moodle_url('#'), - $this->pix_icon('i/dragdrop', get_string('move'), 'moodle', array('class' => 'iconsmall', 'title' => '')), - array('class' => 'editing_move', 'data-action' => 'move') + $this->pix_icon('i/dragdrop', get_string('move'), 'moodle', ['class' => 'iconsmall', 'title' => '']), + ['class' => 'editing_move', 'data-action' => 'move'] ); } @@ -908,7 +908,7 @@ class edit_renderer extends \plugin_renderer_base { \qbank_previewquestion\helper::question_preview_popup_params()); return $this->action_link($url, $image . $strpreviewlabel, $action, - array('title' => $strpreviewquestion, 'class' => 'preview')); + ['title' => $strpreviewquestion, 'class' => 'preview']); } /** @@ -920,13 +920,13 @@ class edit_renderer extends \plugin_renderer_base { * @return string HTML to output. */ public function question_remove_icon(structure $structure, $slot, $pageurl) { - $url = new \moodle_url($pageurl, array('sesskey' => sesskey(), 'remove' => $slot)); + $url = new \moodle_url($pageurl, ['sesskey' => sesskey(), 'remove' => $slot]); $strdelete = get_string('delete'); $image = $this->pix_icon('t/delete', $strdelete); - return $this->action_link($url, $image, null, array('title' => $strdelete, - 'class' => 'cm-edit-action editing_delete', 'data-action' => 'delete')); + return $this->action_link($url, $image, null, ['title' => $strdelete, + 'class' => 'cm-edit-action editing_delete', 'data-action' => 'delete']); } /** @@ -938,8 +938,8 @@ class edit_renderer extends \plugin_renderer_base { */ public function page_split_join_button($structure, $slot) { $insertpagebreak = !$structure->is_last_slot_on_page($slot); - $url = new \moodle_url('repaginate.php', array('quizid' => $structure->get_quizid(), - 'slot' => $slot, 'repag' => $insertpagebreak ? 2 : 1, 'sesskey' => sesskey())); + $url = new \moodle_url('repaginate.php', ['quizid' => $structure->get_quizid(), + 'slot' => $slot, 'repag' => $insertpagebreak ? 2 : 1, 'sesskey' => sesskey()]); if ($insertpagebreak) { $title = get_string('addpagebreak', 'quiz'); @@ -956,8 +956,8 @@ class edit_renderer extends \plugin_renderer_base { if (!$structure->can_be_edited()) { $disabled = 'disabled'; } - return html_writer::span($this->action_link($url, $image, null, array('title' => $title, - 'class' => 'page_split_join cm-edit-action', 'disabled' => $disabled, 'data-action' => $action)), + return html_writer::span($this->action_link($url, $image, null, ['title' => $title, + 'class' => 'page_split_join cm-edit-action', 'disabled' => $disabled, 'data-action' => $action]), 'page_split_join_wrapper'); } @@ -970,19 +970,19 @@ class edit_renderer extends \plugin_renderer_base { * @return string HTML to output. */ public function question_dependency_icon($structure, $slot) { - $a = array( + $a = [ 'thisq' => $structure->get_displayed_number_for_slot($slot), 'previousq' => $structure->get_displayed_number_for_slot(max($slot - 1, 1)), - ); + ]; if ($structure->is_question_dependent_on_previous_slot($slot)) { $title = get_string('questiondependencyremove', 'quiz', $a); $image = $this->pix_icon('t/locked', get_string('questiondependsonprevious', 'quiz'), - 'moodle', array('title' => '')); + 'moodle', ['title' => '']); $action = 'removedependency'; } else { $title = get_string('questiondependencyadd', 'quiz', $a); $image = $this->pix_icon('t/unlocked', get_string('questiondependencyfree', 'quiz'), - 'moodle', array('title' => '')); + 'moodle', ['title' => '']); $action = 'adddependency'; } @@ -995,8 +995,8 @@ class edit_renderer extends \plugin_renderer_base { if (!$structure->can_question_depend_on_previous_slot($slot)) { $extraclass = ' question_dependency_cannot_depend'; } - return html_writer::span($this->action_link('#', $image, null, array('title' => $title, - 'class' => 'cm-edit-action', 'disabled' => $disabled, 'data-action' => $action)), + return html_writer::span($this->action_link('#', $image, null, ['title' => $title, + 'class' => 'cm-edit-action', 'disabled' => $disabled, 'data-action' => $action]), 'question_dependency_wrapper' . $extraclass); } @@ -1015,27 +1015,27 @@ class edit_renderer extends \plugin_renderer_base { $output = ''; $question = $structure->get_question_in_slot($slot); - $editurl = new \moodle_url('/question/bank/editquestion/question.php', array( + $editurl = new \moodle_url('/question/bank/editquestion/question.php', [ 'returnurl' => $pageurl->out_as_local_url(), - 'cmid' => $structure->get_cmid(), 'id' => $question->questionid)); + 'cmid' => $structure->get_cmid(), 'id' => $question->questionid]); $instancename = quiz_question_tostring($question); $qtype = \question_bank::get_qtype($question->qtype, false); $namestr = $qtype->local_name(); - $icon = $this->pix_icon('icon', $namestr, $qtype->plugin_name(), array('title' => $namestr, - 'class' => 'activityicon', 'alt' => ' ', 'role' => 'presentation')); + $icon = $this->pix_icon('icon', $namestr, $qtype->plugin_name(), ['title' => $namestr, + 'class' => 'activityicon', 'alt' => ' ', 'role' => 'presentation']); - $editicon = $this->pix_icon('t/edit', '', 'moodle', array('title' => '')); + $editicon = $this->pix_icon('t/edit', '', 'moodle', ['title' => '']); // Need plain question name without html tags for link title. $title = shorten_text(format_string($question->name), 100); // Display the link itself. - $activitylink = $icon . html_writer::tag('span', $editicon . $instancename, array('class' => 'instancename')); + $activitylink = $icon . html_writer::tag('span', $editicon . $instancename, ['class' => 'instancename']); $output .= html_writer::link($editurl, $activitylink, - array('title' => get_string('editquestion', 'quiz').' '.$title)); + ['title' => get_string('editquestion', 'quiz').' '.$title]); return $output; } @@ -1053,7 +1053,7 @@ class edit_renderer extends \plugin_renderer_base { $question = $structure->get_question_in_slot($slotnumber); $slot = $structure->get_slot_by_number($slotnumber); $editurl = new \moodle_url('/mod/quiz/editrandom.php', - array('returnurl' => $pageurl->out_as_local_url(), 'slotid' => $slot->id)); + ['returnurl' => $pageurl->out_as_local_url(), 'slotid' => $slot->id]); $temp = clone($question); $temp->questiontext = ''; @@ -1063,10 +1063,10 @@ class edit_renderer extends \plugin_renderer_base { $configuretitle = get_string('configurerandomquestion', 'quiz'); $qtype = \question_bank::get_qtype($question->qtype, false); $namestr = $qtype->local_name(); - $icon = $this->pix_icon('icon', $namestr, $qtype->plugin_name(), array('title' => $namestr, - 'class' => 'icon activityicon', 'alt' => ' ', 'role' => 'presentation')); + $icon = $this->pix_icon('icon', $namestr, $qtype->plugin_name(), ['title' => $namestr, + 'class' => 'icon activityicon', 'alt' => ' ', 'role' => 'presentation']); - $editicon = $this->pix_icon('t/edit', $configuretitle, 'moodle', array('title' => '')); + $editicon = $this->pix_icon('t/edit', $configuretitle, 'moodle', ['title' => '']); $qbankurlparams = [ 'cmid' => $structure->get_cmid(), 'cat' => $slot->category . ',' . $slot->contextid, @@ -1086,9 +1086,9 @@ class edit_renderer extends \plugin_renderer_base { // selected from in the question bank. $qbankurl = new \moodle_url('/question/edit.php', $qbankurlparams); $qbanklink = ' ' . \html_writer::link($qbankurl, - get_string('seequestions', 'quiz'), array('class' => 'mod_quiz_random_qbank_link')); + get_string('seequestions', 'quiz'), ['class' => 'mod_quiz_random_qbank_link']); - return html_writer::link($editurl, $icon . $editicon, array('title' => $configuretitle)) . + return html_writer::link($editurl, $icon . $editicon, ['title' => $configuretitle]) . ' ' . $instancename . ' ' . $qbanklink; } @@ -1105,24 +1105,24 @@ class edit_renderer extends \plugin_renderer_base { 'instancemaxmark decimalplaces_' . $structure->get_decimal_places_for_question_marks()); $output .= html_writer::span( - $this->pix_icon('spacer', '', 'moodle', array('class' => 'editicon visibleifjs', 'title' => '')), + $this->pix_icon('spacer', '', 'moodle', ['class' => 'editicon visibleifjs', 'title' => '']), 'editing_maxmark'); return html_writer::span($output, 'instancemaxmarkcontainer infoitem'); } $output = html_writer::span($structure->formatted_question_grade($slot), 'instancemaxmark decimalplaces_' . $structure->get_decimal_places_for_question_marks(), - array('title' => get_string('maxmark', 'quiz'))); + ['title' => get_string('maxmark', 'quiz')]); $output .= html_writer::span( html_writer::link( new \moodle_url('#'), - $this->pix_icon('t/editstring', '', 'moodle', array('class' => 'editicon visibleifjs', 'title' => '')), - array( + $this->pix_icon('t/editstring', '', 'moodle', ['class' => 'editicon visibleifjs', 'title' => '']), + [ 'class' => 'editing_maxmark', 'data-action' => 'editmaxmark', 'title' => get_string('editmaxmark', 'quiz'), - ) + ] ) ); return html_writer::span($output, 'instancemaxmarkcontainer'); @@ -1144,7 +1144,7 @@ class edit_renderer extends \plugin_renderer_base { */ public function question_chooser() { $chooser = \mod_quiz\output\question_chooser::get($this->page->course, [], null); - $container = html_writer::div($this->render($chooser), '', array('id' => 'qtypechoicecontainer')); + $container = html_writer::div($this->render($chooser), '', ['id' => 'qtypechoicecontainer']); return html_writer::div($container, 'createnewquestion'); } @@ -1173,52 +1173,52 @@ class edit_renderer extends \plugin_renderer_base { $config = new \stdClass(); $config->resourceurl = '/mod/quiz/edit_rest.php'; $config->sectionurl = '/mod/quiz/edit_rest.php'; - $config->pageparams = array(); + $config->pageparams = []; $config->questiondecimalpoints = $structure->get_decimal_places_for_question_marks(); $config->pagehtml = $this->new_page_template($structure, $contexts, $pagevars, $pageurl); $config->addpageiconhtml = $this->add_page_icon_template($structure); $this->page->requires->yui_module('moodle-mod_quiz-toolboxes', 'M.mod_quiz.init_resource_toolbox', - array(array( + [[ 'courseid' => $structure->get_courseid(), 'quizid' => $structure->get_quizid(), 'ajaxurl' => $config->resourceurl, 'config' => $config, - )) + ]] ); unset($config->pagehtml); unset($config->addpageiconhtml); - $this->page->requires->strings_for_js(array('areyousureremoveselected'), 'quiz'); + $this->page->requires->strings_for_js(['areyousureremoveselected'], 'quiz'); $this->page->requires->yui_module('moodle-mod_quiz-toolboxes', 'M.mod_quiz.init_section_toolbox', - array(array( + [[ 'courseid' => $structure, 'quizid' => $structure->get_quizid(), 'ajaxurl' => $config->sectionurl, 'config' => $config, - )) + ]] ); $this->page->requires->yui_module('moodle-mod_quiz-dragdrop', 'M.mod_quiz.init_section_dragdrop', - array(array( + [[ 'courseid' => $structure, 'quizid' => $structure->get_quizid(), 'ajaxurl' => $config->sectionurl, 'config' => $config, - )), null, true); + ]], null, true); $this->page->requires->yui_module('moodle-mod_quiz-dragdrop', 'M.mod_quiz.init_resource_dragdrop', - array(array( + [[ 'courseid' => $structure, 'quizid' => $structure->get_quizid(), 'ajaxurl' => $config->resourceurl, 'config' => $config, - )), null, true); + ]], null, true); // Require various strings for the command toolbox. - $this->page->requires->strings_for_js(array( + $this->page->requires->strings_for_js([ 'clicktohideshow', 'deletechecktype', 'deletechecktypename', @@ -1237,9 +1237,9 @@ class edit_renderer extends \plugin_renderer_base { 'selectall', 'show', 'tocontent', - ), 'moodle'); + ], 'moodle'); - $this->page->requires->strings_for_js(array( + $this->page->requires->strings_for_js([ 'addpagebreak', 'cannotremoveallsectionslots', 'cannotremoveslots', @@ -1256,7 +1256,7 @@ class edit_renderer extends \plugin_renderer_base { 'questiondependencyfree', 'questiondependencyremove', 'questiondependsonprevious', - ), 'quiz'); + ], 'quiz'); foreach (\question_bank::get_all_qtypes() as $qtype => $notused) { $this->page->requires->string_for_js('pluginname', 'qtype_' . $qtype); @@ -1284,7 +1284,7 @@ class edit_renderer extends \plugin_renderer_base { // Normalise the page number. $pagenumber = $structure->get_page_number_for_slot(1); - $strcontexts = array(); + $strcontexts = []; $strcontexts[] = 'page-'; $strcontexts[] = get_string('page') . ' '; $strcontexts[] = 'addonpage%3D'; diff --git a/mod/quiz/classes/output/navigation_panel_attempt.php b/mod/quiz/classes/output/navigation_panel_attempt.php index 1fd6fbfc80a..0461179f55f 100644 --- a/mod/quiz/classes/output/navigation_panel_attempt.php +++ b/mod/quiz/classes/output/navigation_panel_attempt.php @@ -40,7 +40,7 @@ class navigation_panel_attempt extends navigation_panel_base { public function render_before_button_bits(renderer $output) { return html_writer::tag('div', get_string('navnojswarning', 'quiz'), - array('id' => 'quiznojswarning')); + ['id' => 'quiznojswarning']); } public function render_end_bits(renderer $output) { @@ -49,7 +49,7 @@ class navigation_panel_attempt extends navigation_panel_base { return ''; } return html_writer::link($this->attemptobj->summary_url(), - get_string('endtest', 'quiz'), array('class' => 'endtestlink aalink')) . + get_string('endtest', 'quiz'), ['class' => 'endtestlink aalink']) . $this->render_restart_preview_link($output); } } diff --git a/mod/quiz/classes/output/navigation_panel_base.php b/mod/quiz/classes/output/navigation_panel_base.php index 6de96a68b1a..92f584d755a 100644 --- a/mod/quiz/classes/output/navigation_panel_base.php +++ b/mod/quiz/classes/output/navigation_panel_base.php @@ -67,7 +67,7 @@ abstract class navigation_panel_base { * @return renderable[] the buttons, possibly interleaved with section headings. */ public function get_question_buttons() { - $buttons = array(); + $buttons = []; foreach ($this->attemptobj->get_slots() as $slot) { $heading = $this->attemptobj->get_heading_before_slot($slot); if (!is_null($heading)) { @@ -153,7 +153,7 @@ abstract class navigation_panel_base { return ''; } return $output->restart_preview_button(new moodle_url( - $this->attemptobj->start_attempt_url(), array('forcenew' => true))); + $this->attemptobj->start_attempt_url(), ['forcenew' => true])); } /** @@ -174,7 +174,7 @@ abstract class navigation_panel_base { if ($this->attemptobj->get_quiz()->showuserpicture == QUIZ_SHOWIMAGE_NONE) { return null; } - $user = $DB->get_record('user', array('id' => $this->attemptobj->get_userid())); + $user = $DB->get_record('user', ['id' => $this->attemptobj->get_userid()]); $userpicture = new user_picture($user); $userpicture->courseid = $this->attemptobj->get_courseid(); if ($this->attemptobj->get_quiz()->showuserpicture == QUIZ_SHOWIMAGE_LARGE) { diff --git a/mod/quiz/classes/output/renderer.php b/mod/quiz/classes/output/renderer.php index 0c6f13e92f8..bb5973ff296 100644 --- a/mod/quiz/classes/output/renderer.php +++ b/mod/quiz/classes/output/renderer.php @@ -1031,8 +1031,8 @@ class renderer extends plugin_renderer_base { /** * Output the page information * - * @param object $quiz the quiz settings. - * @param object $cm the course_module object. + * @param stdClass $quiz the quiz settings. + * @param stdClass $cm the course_module object. * @param context $context the quiz context. * @param array $messages any access messages that should be described. * @param bool $quizhasquestions does quiz has questions added. @@ -1067,8 +1067,8 @@ class renderer extends plugin_renderer_base { /** * Output the quiz intro. * - * @param object $quiz the quiz settings. - * @param object $cm the course_module object. + * @param stdClass $quiz the quiz settings. + * @param stdClass $cm the course_module object. * @return string HTML to output. */ public function quiz_intro($quiz, $cm) { diff --git a/mod/quiz/classes/output/view_page.php b/mod/quiz/classes/output/view_page.php index ec437bfafa7..bc967837efa 100644 --- a/mod/quiz/classes/output/view_page.php +++ b/mod/quiz/classes/output/view_page.php @@ -72,7 +72,7 @@ class view_page { public $gradebookfeedback; /** @var bool $unfinished contains 1 if an attempt is unfinished. */ public $unfinished; - /** @var object $lastfinishedattempt the last attempt from the attempts array. */ + /** @var stdClass $lastfinishedattempt the last attempt from the attempts array. */ public $lastfinishedattempt; /** @var array $preventmessages of messages telling the user why they can't * attempt the quiz now. */ diff --git a/mod/quiz/classes/plugininfo/quiz.php b/mod/quiz/classes/plugininfo/quiz.php index e52dfafbca6..9b8608e48b7 100644 --- a/mod/quiz/classes/plugininfo/quiz.php +++ b/mod/quiz/classes/plugininfo/quiz.php @@ -46,7 +46,7 @@ class quiz extends base { // Do the opposite of db/install.php scripts - deregister the report. - $DB->delete_records('quiz_reports', array('name'=>$this->name)); + $DB->delete_records('quiz_reports', ['name' => $this->name]); parent::uninstall_cleanup(); } diff --git a/mod/quiz/classes/question/bank/custom_view.php b/mod/quiz/classes/question/bank/custom_view.php index 0df54d72b81..d7d7563a24f 100644 --- a/mod/quiz/classes/question/bank/custom_view.php +++ b/mod/quiz/classes/question/bank/custom_view.php @@ -201,7 +201,7 @@ class custom_view extends \core_question\local\bank\view { echo \html_writer::start_tag('div', ['class' => 'pt-2']); if ($canuseall) { // Add selected questions to the quiz. - $params = array( + $params = [ 'type' => 'submit', 'name' => 'add', 'class' => 'btn btn-primary', @@ -210,7 +210,7 @@ class custom_view extends \core_question\local\bank\view { 'data-togglegroup' => 'qbank', 'data-toggle' => 'action', 'disabled' => true, - ); + ]; echo \html_writer::empty_tag('input', $params); } echo \html_writer::end_tag('div'); diff --git a/mod/quiz/classes/question/qubaids_for_quiz.php b/mod/quiz/classes/question/qubaids_for_quiz.php index 5583349d061..720750ddaf9 100644 --- a/mod/quiz/classes/question/qubaids_for_quiz.php +++ b/mod/quiz/classes/question/qubaids_for_quiz.php @@ -41,7 +41,7 @@ class qubaids_for_quiz extends \qubaid_join { */ public function __construct(int $quizid, bool $includepreviews = true, bool $onlyfinished = false) { $where = 'quiza.quiz = :quizaquiz'; - $params = array('quizaquiz' => $quizid); + $params = ['quizaquiz' => $quizid]; if (!$includepreviews) { $where .= ' AND preview = 0'; diff --git a/mod/quiz/classes/quiz_settings.php b/mod/quiz/classes/quiz_settings.php index de053228c96..146fc82d555 100644 --- a/mod/quiz/classes/quiz_settings.php +++ b/mod/quiz/classes/quiz_settings.php @@ -68,9 +68,9 @@ class quiz_settings { /** * Constructor, assuming we already have the necessary data loaded. * - * @param object $quiz the row from the quiz table. - * @param object $cm the course_module object for this quiz. - * @param object $course the row from the course table for the course we belong to. + * @param stdClass $quiz the row from the quiz table. + * @param stdClass $cm the course_module object for this quiz. + * @param stdClass $course the row from the course table for the course we belong to. * @param bool $getcontext intended for testing - stops the constructor getting the context. */ public function __construct($quiz, $cm, $course, $getcontext = true) { @@ -108,7 +108,7 @@ class quiz_settings { /** * Create a {@see quiz_attempt} for an attempt at this quiz. * - * @param object $attemptdata row from the quiz_attempts table. + * @param stdClass $attemptdata row from the quiz_attempts table. * @return quiz_attempt the new quiz_attempt object. */ public function create_attempt_object($attemptdata) { @@ -176,7 +176,7 @@ class quiz_settings { /** * Get the course settings object that this quiz belongs to. * - * @return object the row of the course table. + * @return stdClass the row of the course table. */ public function get_course() { return $this->course; @@ -239,7 +239,7 @@ class quiz_settings { /** * Get the course-module object for this quiz. * - * @return object the course_module object. + * @return stdClass the course_module object. */ public function get_cm() { return $this->cm; diff --git a/mod/quiz/classes/repaginate.php b/mod/quiz/classes/repaginate.php index d4423f06fe0..af8f16b231e 100644 --- a/mod/quiz/classes/repaginate.php +++ b/mod/quiz/classes/repaginate.php @@ -14,15 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Defines the quiz repaginate class. - * - * @package mod_quiz - * @copyright 2014 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace mod_quiz; + +use stdClass; + defined('MOODLE_INTERNAL') || die(); /** @@ -31,6 +26,7 @@ defined('MOODLE_INTERNAL') || die(); * The quiz setting allows users to write quizzes with one question per page, * n questions per page, or all questions on one page. * + * @package mod_quiz * @copyright 2014 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -55,10 +51,10 @@ class repaginate { global $DB; $this->quizid = $quizid; if (!$this->quizid) { - $this->slots = array(); + $this->slots = []; } if (!$slots) { - $this->slots = $DB->get_records('quiz_slots', array('quizid' => $this->quizid), 'slot'); + $this->slots = $DB->get_records('quiz_slots', ['quizid' => $this->quizid], 'slot'); } else { $this->slots = $slots; } @@ -83,7 +79,7 @@ class repaginate { * @return stdClass $slot */ protected function get_this_slot($slots, $slotnumber) { - foreach ($slots as $key => $slot) { + foreach ($slots as $slot) { if ($slot->slot == $slotnumber) { return $slot; } @@ -98,9 +94,9 @@ class repaginate { */ protected function get_slots_by_slot_number($slots) { if (!$slots) { - return array(); + return []; } - $newslots = array(); + $newslots = []; foreach ($slots as $slot) { $newslots[$slot->slot] = $slot; } @@ -114,9 +110,9 @@ class repaginate { */ protected function get_slots_by_slotid($slots) { if (!$slots) { - return array(); + return []; } - $newslots = array(); + $newslots = []; foreach ($slots as $slot) { $newslots[$slot->id] = $slot; } @@ -124,15 +120,16 @@ class repaginate { } /** - * Repaginate, update DB and slots object + * Repaginate, update DB and slots object. + * * @param int $nextslotnumber * @param int $type repaginate::LINK or repaginate::UNLINK. */ public function repaginate_slots($nextslotnumber, $type) { global $DB; - $this->slots = $DB->get_records('quiz_slots', array('quizid' => $this->quizid), 'slot'); + $this->slots = $DB->get_records('quiz_slots', ['quizid' => $this->quizid], 'slot'); $nextslot = null; - $newslots = array(); + $newslots = []; foreach ($this->slots as $slot) { if ($slot->slot < $nextslotnumber) { $newslots[$slot->id] = $slot; @@ -153,7 +150,8 @@ class repaginate { } /** - * Repaginate next slot and return the modified slot object + * Repaginate next slot and return the modified slot object. + * * @param int $nextslotnumber * @param int $type repaginate::LINK or repaginate::UNLINK. * @return stdClass|null @@ -182,11 +180,11 @@ class repaginate { */ public function repaginate_n_question_per_page($slots, $number) { $slots = $this->get_slots_by_slot_number($slots); - $newslots = array(); + $newslots = []; $count = 0; $page = 1; - foreach ($slots as $key => $slot) { - for ($page + $count; $page < ($number + $count + 1); $page++) { + foreach ($slots as $slot) { + for (; $page < ($number + $count + 1); $page++) { if ($slot->slot >= $page) { $slot->page = $page; $count++; @@ -199,6 +197,7 @@ class repaginate { /** * Repaginate the rest. + * * @param stdClass[] $quizslots * @param int $slotfrom * @param int $type @@ -210,7 +209,7 @@ class repaginate { if (!$quizslots) { return null; } - $newslots = array(); + $newslots = []; foreach ($quizslots as $slot) { if ($type == self::LINK) { if ($slot->slot <= $slotfrom) { diff --git a/mod/quiz/classes/structure.php b/mod/quiz/classes/structure.php index 7164975e093..49a375b7444 100644 --- a/mod/quiz/classes/structure.php +++ b/mod/quiz/classes/structure.php @@ -14,17 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Defines the \mod_quiz\structure class. - * - * @package mod_quiz - * @copyright 2013 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace mod_quiz; + use mod_quiz\question\bank\qbank_helper; use mod_quiz\question\qubaids_for_quiz; +use stdClass; /** * Quiz structure class. @@ -35,27 +29,28 @@ use mod_quiz\question\qubaids_for_quiz; * has been started, then the attempt holds the specific set of questions * that that student should answer, and we no longer use this class. * + * @package mod_quiz * @copyright 2014 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class structure { - /** @var \mod_quiz\quiz_settings the quiz this is the structure of. */ + /** @var quiz_settings the quiz this is the structure of. */ protected $quizobj = null; /** - * @var \stdClass[] the questions in this quiz. Contains the row from the questions + * @var stdClass[] the questions in this quiz. Contains the row from the questions * table, with the data from the quiz_slots table added, and also question_categories.contextid. */ - protected $questions = array(); + protected $questions = []; - /** @var \stdClass[] quiz_slots.slot => the quiz_slots rows for this quiz, agumented by sectionid. */ - protected $slotsinorder = array(); + /** @var stdClass[] quiz_slots.slot => the quiz_slots rows for this quiz, augmented by sectionid. */ + protected $slotsinorder = []; /** - * @var \stdClass[] currently a dummy. Holds data that will match the + * @var stdClass[] currently a dummy. Holds data that will match the * quiz_sections, once it exists. */ - protected $sections = array(); + protected $sections = []; /** @var bool caches the results of can_be_edited. */ protected $canbeedited = null; @@ -63,14 +58,6 @@ class structure { /** @var bool caches the results of can_add_random_question. */ protected $canaddrandom = null; - /** @var bool tracks whether tags have been loaded */ - protected $hasloadedtags = false; - - /** - * @var \stdClass[] the tags for slots. Indexed by slot id. - */ - protected $slottags = array(); - /** * Create an instance of this class representing an empty quiz. * @@ -83,7 +70,7 @@ class structure { /** * Create an instance of this class representing the structure of a given quiz. * - * @param \mod_quiz\quiz_settings $quizobj the quiz. + * @param quiz_settings $quizobj the quiz. * @return structure */ public static function create_for_quiz($quizobj) { @@ -115,7 +102,7 @@ class structure { * Get the information about the question with this id. * * @param int $questionid The question id. - * @return \stdClass the data from the questions table, augmented with + * @return stdClass the data from the questions table, augmented with * question_category.contextid, and the quiz_slots data for the question in this quiz. */ public function get_question_by_id($questionid) { @@ -126,7 +113,7 @@ class structure { * Get the information about the question in a given slot. * * @param int $slotnumber the index of the slot in question. - * @return \stdClass the data from the questions table, augmented with + * @return stdClass the data from the questions table, augmented with * question_category.contextid, and the quiz_slots data for the question in this quiz. */ public function get_question_in_slot($slotnumber) { @@ -134,10 +121,10 @@ class structure { } /** - * Get the information about the question name in a given slot. + * Get the name of the question in a given slot. * * @param int $slotnumber the index of the slot in question. - * @return \stdClass the data from the questions table, augmented with + * @return stdClass the data from the questions table, augmented with */ public function get_question_name_in_slot($slotnumber) { return $this->questions[$this->slotsinorder[$slotnumber]->name]; @@ -271,7 +258,7 @@ class structure { return false; } - if (in_array($this->get_question_type_for_slot($slotnumber), array('random', 'missingtype'))) { + if (in_array($this->get_question_type_for_slot($slotnumber), ['random', 'missingtype'])) { return \question_engine::can_questions_finish_during_the_attempt( $this->quizobj->get_quiz()->preferredbehaviour); } @@ -366,7 +353,7 @@ class structure { /** * Get the quiz object. * - * @return \stdClass the quiz settings row from the database. + * @return stdClass the quiz settings row from the database. */ public function get_quiz() { return $this->quizobj->get_quiz(); @@ -403,7 +390,7 @@ class structure { $reportlink = quiz_attempt_summary_link_to_reports($this->get_quiz(), $this->quizobj->get_cm(), $this->quizobj->get_context()); throw new \moodle_exception('cannoteditafterattempts', 'quiz', - new \moodle_url('/mod/quiz/edit.php', array('cmid' => $this->get_cmid())), $reportlink); + new \moodle_url('/mod/quiz/edit.php', ['cmid' => $this->get_cmid()]), $reportlink); } } @@ -422,7 +409,7 @@ class structure { /** * Get quiz slots. * - * @return \stdClass[] the slots in this quiz. + * @return stdClass[] the slots in this quiz. */ public function get_slots() { return array_column($this->slotsinorder, null, 'id'); @@ -489,7 +476,7 @@ class structure { /** * Is this the first section in the quiz? * - * @param \stdClass $section the quiz_sections row. + * @param stdClass $section the quiz_sections row. * @return bool whether this is first section in the quiz. */ public function is_first_section($section) { @@ -499,7 +486,7 @@ class structure { /** * Is this the last section in the quiz? * - * @param \stdClass $section the quiz_sections row. + * @param stdClass $section the quiz_sections row. * @return bool whether this is first section in the quiz. */ public function is_last_section($section) { @@ -509,7 +496,7 @@ class structure { /** * Does this section only contain one slot? * - * @param \stdClass $section the quiz_sections row. + * @param stdClass $section the quiz_sections row. * @return bool whether this section contains only one slot. */ public function is_only_one_slot_in_section($section) { @@ -519,18 +506,17 @@ class structure { /** * Get the final slot in the quiz. * - * @return \stdClass the quiz_slots for for the final slot in the quiz. + * @return stdClass the quiz_slots for the final slot in the quiz. */ public function get_last_slot() { return end($this->slotsinorder); } /** - * Get a slot by it's id. Throws an exception if it is missing. + * Get a slot by its id. Throws an exception if it is missing. * * @param int $slotid the slot id. - * @return \stdClass the requested quiz_slots row. - * @throws \coding_exception + * @return stdClass the requested quiz_slots row. */ public function get_slot_by_id($slotid) { foreach ($this->slotsinorder as $slot) { @@ -543,10 +529,10 @@ class structure { } /** - * Get a slot by it's slot number. Throws an exception if it is missing. + * Get a slot by its slot number. Throws an exception if it is missing. * * @param int $slotnumber The slot number - * @return \stdClass + * @return stdClass * @throws \coding_exception */ public function get_slot_by_number($slotnumber) { @@ -569,7 +555,7 @@ class structure { return false; } // Get an array of firstslots. - $firstslots = array(); + $firstslots = []; foreach ($this->sections as $section) { $firstslots[] = $section->firstslot; } @@ -594,7 +580,7 @@ class structure { * @return int[] slot numbers. */ public function get_slots_in_section($sectionid) { - $slots = array(); + $slots = []; foreach ($this->slotsinorder as $slot) { if ($slot->section->id == $sectionid) { $slots[] = $slot->slot; @@ -606,7 +592,7 @@ class structure { /** * Get all the sections of the quiz. * - * @return \stdClass[] the sections in this quiz. + * @return stdClass[] the sections in this quiz. */ public function get_sections() { return $this->sections; @@ -615,7 +601,7 @@ class structure { /** * Get a particular section by id. * - * @return \stdClass the section. + * @return stdClass the section. */ public function get_section_by_id($sectionid) { return $this->sections[$sectionid]; @@ -650,7 +636,7 @@ class structure { } /** - * Get the number of decimal places for displyaing overall quiz grades or marks. + * Get the number of decimal places for displaying overall quiz grades or marks. * * @return int the number of decimal places. */ @@ -659,7 +645,7 @@ class structure { } /** - * Get the number of decimal places for displyaing question marks. + * Get the number of decimal places for displaying question marks. * * @return int the number of decimal places. */ @@ -672,7 +658,7 @@ class structure { * @return string[] array of strings. */ public function get_edit_page_warnings() { - $warnings = array(); + $warnings = []; if (quiz_has_attempts($this->quizobj->get_quizid())) { $reviewlink = quiz_attempt_summary_link_to_reports($this->quizobj->get_quiz(), @@ -693,7 +679,7 @@ class structure { $quiz = $this->quizobj->get_quiz(); // Exact open and close dates for the tool-tip. - $dates = array(); + $dates = []; if ($quiz->timeopen > 0) { if ($timenow > $quiz->timeopen) { $dates[] = get_string('quizopenedon', 'quiz', userdate($quiz->timeopen)); @@ -726,7 +712,7 @@ class structure { $currentstatus = get_string('quizisopen', 'quiz'); } - return array($currentstatus, $explanation); + return [$currentstatus, $explanation]; } /** @@ -795,10 +781,10 @@ class structure { } /** - * Get the version options to show on the Questions page for a particular question. + * Get the version options to show on the 'Questions' page for a particular question. * * @param int $slotnumber which slot to get the choices for. - * @return \stdClass[] other versions of this question. Each object has fields versionid, + * @return stdClass[] other versions of this question. Each object has fields versionid, * version and selected. Array is returned most recent version first. */ public function get_version_choices_for_slot(int $slotnumber): array { @@ -823,7 +809,7 @@ class structure { } // Make a choice for 'Always latest'. - $alwaysuselatest = new \stdClass(); + $alwaysuselatest = new stdClass(); $alwaysuselatest->versionid = 0; $alwaysuselatest->version = 0; $alwaysuselatest->versionvalue = get_string('alwayslatest', 'quiz'); @@ -836,15 +822,12 @@ class structure { /** * Move a slot from its current location to a new location. * - * After callig this method, this class will be in an invalid state, and + * After calling this method, this class will be in an invalid state, and * should be discarded if you want to manipulate the structure further. * * @param int $idmove id of slot to be moved * @param int $idmoveafter id of slot to come before slot being moved * @param int $page new page number of slot being moved - * @param bool $insection if the question is moving to a place where a new - * section starts, include it in that section. - * @return void */ public function move_slot($idmove, $idmoveafter, $page) { global $DB; @@ -871,7 +854,7 @@ class structure { } $followingslotnumber = $moveafterslotnumber + 1; - // Prevent checking against non-existance slot when already at the last slot. + // Prevent checking against non-existence slot when already at the last slot. if ($followingslotnumber == $movingslotnumber && !$this->is_last_slot_in_quiz($followingslotnumber)) { $followingslotnumber += 1; } @@ -889,7 +872,7 @@ class structure { } // Work out how things are being moved. - $slotreorder = array(); + $slotreorder = []; if ($moveafterslotnumber > $movingslotnumber) { // Moving down. $slotreorder[$movingslotnumber] = $moveafterslotnumber; @@ -948,13 +931,13 @@ class structure { // Slot has moved record new order. if ($slotreorder) { update_field_with_unique_index('quiz_slots', 'slot', $slotreorder, - array('quizid' => $this->get_quizid())); + ['quizid' => $this->get_quizid()]); } // Page has changed. Record it. if ($movingslot->page != $page) { $DB->set_field('quiz_slots', 'page', $page, - array('id' => $movingslot->id)); + ['id' => $movingslot->id]); } // Update section fist slots. @@ -969,7 +952,7 @@ class structure { AND page > 1 AND NOT EXISTS (SELECT 1 FROM {quiz_slots} WHERE quizid = ? AND page = slot.page - 1) ORDER BY page - 1 DESC - ", array($this->get_quizid(), $this->get_quizid())); + ", [$this->get_quizid(), $this->get_quizid()]); foreach ($emptypages as $emptypage) { $DB->execute(" @@ -977,7 +960,7 @@ class structure { SET page = page - 1 WHERE quizid = ? AND page > ? - ", array($this->get_quizid(), $emptypage)); + ", [$this->get_quizid(), $emptypage]); } $trans->allow_commit(); @@ -998,18 +981,18 @@ class structure { /** * Refresh page numbering of quiz slots. - * @param \stdClass[] $slots (optional) array of slot objects. - * @return \stdClass[] array of slot objects. + * @param stdClass[] $slots (optional) array of slot objects. + * @return stdClass[] array of slot objects. */ - public function refresh_page_numbers($slots = array()) { + public function refresh_page_numbers($slots = []) { global $DB; // Get slots ordered by page then slot. if (!count($slots)) { - $slots = $DB->get_records('quiz_slots', array('quizid' => $this->get_quizid()), 'slot, page'); + $slots = $DB->get_records('quiz_slots', ['quizid' => $this->get_quizid()], 'slot, page'); } - // Loop slots. Start Page number at 1 and increment as required. - $pagenumbers = array('new' => 0, 'old' => 0); + // Loop slots. Start the page number at 1 and increment as required. + $pagenumbers = ['new' => 0, 'old' => 0]; foreach ($slots as $slot) { if ($slot->page !== $pagenumbers['old']) { @@ -1028,8 +1011,8 @@ class structure { /** * Refresh page numbering of quiz slots and save to the database. - * @param \stdClass $quiz the quiz object. - * @return \stdClass[] array of slot objects. + * + * @return stdClass[] array of slot objects. */ public function refresh_page_numbers_and_update_db() { global $DB; @@ -1040,14 +1023,14 @@ class structure { // Record new page order. foreach ($slots as $slot) { $DB->set_field('quiz_slots', 'page', $slot->page, - array('id' => $slot->id)); + ['id' => $slot->id]); } return $slots; } /** - * Remove a slot from a quiz + * Remove a slot from a quiz. * * @param int $slotnumber The number of the slot to be deleted. * @throws \coding_exception @@ -1061,30 +1044,30 @@ class structure { throw new \coding_exception('You cannot remove the last slot in a section.'); } - $slot = $DB->get_record('quiz_slots', array('quizid' => $this->get_quizid(), 'slot' => $slotnumber)); + $slot = $DB->get_record('quiz_slots', ['quizid' => $this->get_quizid(), 'slot' => $slotnumber]); if (!$slot) { return; } - $maxslot = $DB->get_field_sql('SELECT MAX(slot) FROM {quiz_slots} WHERE quizid = ?', array($this->get_quizid())); + $maxslot = $DB->get_field_sql('SELECT MAX(slot) FROM {quiz_slots} WHERE quizid = ?', [$this->get_quizid()]); $trans = $DB->start_delegated_transaction(); - // Delete the reference if its a question. + // Delete the reference if it is a question. $questionreference = $DB->get_record('question_references', ['component' => 'mod_quiz', 'questionarea' => 'slot', 'itemid' => $slot->id]); if ($questionreference) { $DB->delete_records('question_references', ['id' => $questionreference->id]); } - // Delete the set reference if its a random question. + // Delete the set reference if it is a random question. $questionsetreference = $DB->get_record('question_set_references', ['component' => 'mod_quiz', 'questionarea' => 'slot', 'itemid' => $slot->id]); if ($questionsetreference) { $DB->delete_records('question_set_references', ['id' => $questionsetreference->id, 'component' => 'mod_quiz', 'questionarea' => 'slot']); } - $DB->delete_records('quiz_slots', array('id' => $slot->id)); + $DB->delete_records('quiz_slots', ['id' => $slot->id]); for ($i = $slot->slot + 1; $i <= $maxslot; $i++) { $DB->set_field('quiz_slots', 'slot', $i - 1, - array('quizid' => $this->get_quizid(), 'slot' => $i)); + ['quizid' => $this->get_quizid(), 'slot' => $i]); $this->slotsinorder[$i]->slot = $i - 1; $this->slotsinorder[$i - 1] = $this->slotsinorder[$i]; unset($this->slotsinorder[$i]); @@ -1132,11 +1115,12 @@ class structure { /** * Change the max mark for a slot. * - * Saves changes to the question grades in the quiz_slots table and any + * Save changes to the question grades in the quiz_slots table and any * corresponding question_attempts. + * * It does not update 'sumgrades' in the quiz table. * - * @param \stdClass $slot row from the quiz_slots table. + * @param stdClass $slot row from the quiz_slots table. * @param float $maxmark the new maxmark. * @return bool true if the new grade is different from the old one. */ @@ -1179,7 +1163,7 @@ class structure { */ public function update_question_dependency($slotid, $requireprevious) { global $DB; - $DB->set_field('quiz_slots', 'requireprevious', $requireprevious, array('id' => $slotid)); + $DB->set_field('quiz_slots', 'requireprevious', $requireprevious, ['id' => $slotid]); // Log slot require previous event. $event = \mod_quiz\event\slot_requireprevious_updated::create([ @@ -1221,20 +1205,20 @@ class structure { /** * Add/Remove a pagebreak. * - * Saves changes to the slot page relationship in the quiz_slots table and reorders the paging + * Save changes to the slot page relationship in the quiz_slots table and reorders the paging * for subsequent slots. * * @param int $slotid id of slot which we will add/remove the page break before. * @param int $type repaginate::LINK or repaginate::UNLINK. - * @return \stdClass[] array of slot objects. + * @return stdClass[] array of slot objects. */ public function update_page_break($slotid, $type) { global $DB; $this->check_can_be_edited(); - $quizslots = $DB->get_records('quiz_slots', array('quizid' => $this->get_quizid()), 'slot'); - $repaginate = new \mod_quiz\repaginate($this->get_quizid(), $quizslots); + $quizslots = $DB->get_records('quiz_slots', ['quizid' => $this->get_quizid()], 'slot'); + $repaginate = new repaginate($this->get_quizid(), $quizslots); $repaginate->repaginate_slots($quizslots[$slotid]->slot, $type); $slots = $this->refresh_page_numbers_and_update_db(); @@ -1272,14 +1256,14 @@ class structure { */ public function add_section_heading($pagenumber, $heading = null) { global $DB; - $section = new \stdClass(); + $section = new stdClass(); if ($heading !== null) { $section->heading = $heading; } else { $section->heading = get_string('newsectionheading', 'quiz'); } $section->quizid = $this->get_quizid(); - $slotsonpage = $DB->get_records('quiz_slots', array('quizid' => $this->get_quizid(), 'page' => $pagenumber), 'slot DESC'); + $slotsonpage = $DB->get_records('quiz_slots', ['quizid' => $this->get_quizid(), 'page' => $pagenumber], 'slot DESC'); $firstslot = end($slotsonpage); $section->firstslot = $firstslot->slot; $section->shufflequestions = 0; @@ -1308,12 +1292,12 @@ class structure { */ public function set_section_heading($id, $newheading) { global $DB; - $section = $DB->get_record('quiz_sections', array('id' => $id), '*', MUST_EXIST); + $section = $DB->get_record('quiz_sections', ['id' => $id], '*', MUST_EXIST); $section->heading = $newheading; $DB->update_record('quiz_sections', $section); // Log section title updated event. - $firstslot = $DB->get_record('quiz_slots', array('quizid' => $this->get_quizid(), 'slot' => $section->firstslot)); + $firstslot = $DB->get_record('quiz_slots', ['quizid' => $this->get_quizid(), 'slot' => $section->firstslot]); $event = \mod_quiz\event\section_title_updated::create([ 'context' => $this->quizobj->get_context(), 'objectid' => $id, @@ -1334,7 +1318,7 @@ class structure { */ public function set_section_shuffle($id, $shuffle) { global $DB; - $section = $DB->get_record('quiz_sections', array('id' => $id), '*', MUST_EXIST); + $section = $DB->get_record('quiz_sections', ['id' => $id], '*', MUST_EXIST); $section->shufflequestions = $shuffle; $DB->update_record('quiz_sections', $section); @@ -1357,14 +1341,14 @@ class structure { */ public function remove_section_heading($sectionid) { global $DB; - $section = $DB->get_record('quiz_sections', array('id' => $sectionid), '*', MUST_EXIST); + $section = $DB->get_record('quiz_sections', ['id' => $sectionid], '*', MUST_EXIST); if ($section->firstslot == 1) { throw new \coding_exception('Cannot remove the first section in a quiz.'); } - $DB->delete_records('quiz_sections', array('id' => $sectionid)); + $DB->delete_records('quiz_sections', ['id' => $sectionid]); // Log page deleted created event. - $firstslot = $DB->get_record('quiz_slots', array('quizid' => $this->get_quizid(), 'slot' => $section->firstslot)); + $firstslot = $DB->get_record('quiz_slots', ['quizid' => $this->get_quizid(), 'slot' => $section->firstslot]); $event = \mod_quiz\event\section_break_deleted::create([ 'context' => $this->quizobj->get_context(), 'objectid' => $sectionid, @@ -1400,8 +1384,8 @@ class structure { /** * Retrieve the list of slot tags for the given slot id. * - * @param int $slotid The id for the slot - * @return \stdClass[] The list of slot tag records + * @param int $slotid The id for the slot + * @return stdClass[] The list of slot tag records * @deprecated since Moodle 4.0 MDL-71573 * @todo Final deprecation on Moodle 4.4 MDL-72438 */ diff --git a/mod/quiz/classes/task/update_overdue_attempts.php b/mod/quiz/classes/task/update_overdue_attempts.php index e83c08f344e..d9683a1b5dc 100644 --- a/mod/quiz/classes/task/update_overdue_attempts.php +++ b/mod/quiz/classes/task/update_overdue_attempts.php @@ -85,14 +85,14 @@ class update_overdue_attempts extends \core\task\scheduled_task { // If we have moved on to a different quiz, fetch the new data. if (!$quiz || $attempt->quiz != $quiz->id) { - $quiz = $DB->get_record('quiz', array('id' => $attempt->quiz), '*', MUST_EXIST); + $quiz = $DB->get_record('quiz', ['id' => $attempt->quiz], '*', MUST_EXIST); $cm = get_coursemodule_from_instance('quiz', $attempt->quiz); $quizcount += 1; } // If we have moved on to a different course, fetch the new data. if (!$course || $course->id != $quiz->course) { - $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $quiz->course], '*', MUST_EXIST); } // Make a specialised version of the quiz settings, with the relevant overrides. @@ -117,7 +117,7 @@ class update_overdue_attempts extends \core\task\scheduled_task { } $attemptstoprocess->close(); - return array($count, $quizcount); + return [$count, $quizcount]; } /** @@ -150,6 +150,6 @@ class update_overdue_attempts extends \core\task\scheduled_task { AND quiza.timecheckstate <= :processto ORDER BY quiz.course, quiza.quiz", - array('processto' => $processto, 'iprocessto' => $processto)); + ['processto' => $processto, 'iprocessto' => $processto]); } } diff --git a/mod/quiz/comment.php b/mod/quiz/comment.php index 6a8ef3a355d..fbb9255d1a2 100644 --- a/mod/quiz/comment.php +++ b/mod/quiz/comment.php @@ -30,11 +30,11 @@ $attemptid = required_param('attempt', PARAM_INT); $slot = required_param('slot', PARAM_INT); // The question number in the attempt. $cmid = optional_param('cmid', null, PARAM_INT); -$PAGE->set_url('/mod/quiz/comment.php', array('attempt' => $attemptid, 'slot' => $slot)); +$PAGE->set_url('/mod/quiz/comment.php', ['attempt' => $attemptid, 'slot' => $slot]); $attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid); $attemptobj->preload_all_attempt_step_users(); -$student = $DB->get_record('user', array('id' => $attemptobj->get_userid())); +$student = $DB->get_record('user', ['id' => $attemptobj->get_userid()]); // Can only grade finished attempts. if (!$attemptobj->is_finished()) { @@ -47,37 +47,37 @@ $attemptobj->require_capability('mod/quiz:grade'); // Print the page header. $PAGE->set_pagelayout('popup'); -$PAGE->set_title(get_string('manualgradequestion', 'quiz', array( +$PAGE->set_title(get_string('manualgradequestion', 'quiz', [ 'question' => format_string($attemptobj->get_question_name($slot)), - 'quiz' => format_string($attemptobj->get_quiz_name()), 'user' => fullname($student)))); + 'quiz' => format_string($attemptobj->get_quiz_name()), 'user' => fullname($student)])); $PAGE->set_heading($attemptobj->get_course()->fullname); $output = $PAGE->get_renderer('mod_quiz'); echo $output->header(); // Prepare summary information about this question attempt. -$summarydata = array(); +$summarydata = []; // Student name. $userpicture = new user_picture($student); $userpicture->courseid = $attemptobj->get_courseid(); -$summarydata['user'] = array( +$summarydata['user'] = [ 'title' => $userpicture, - 'content' => new action_link(new moodle_url('/user/view.php', array( - 'id' => $student->id, 'course' => $attemptobj->get_courseid())), + 'content' => new action_link(new moodle_url('/user/view.php', [ + 'id' => $student->id, 'course' => $attemptobj->get_courseid()]), fullname($student, true)), -); +]; // Quiz name. -$summarydata['quizname'] = array( +$summarydata['quizname'] = [ 'title' => get_string('modulename', 'quiz'), 'content' => format_string($attemptobj->get_quiz_name()), -); +]; // Question name. -$summarydata['questionname'] = array( +$summarydata['questionname'] = [ 'title' => get_string('question', 'quiz'), 'content' => $attemptobj->get_question_name($slot), -); +]; // Process any data that was submitted. if (data_submitted() && confirm_sesskey()) { @@ -87,16 +87,16 @@ if (data_submitted() && confirm_sesskey()) { $transaction->allow_commit(); // Log this action. - $params = array( + $params = [ 'objectid' => $attemptobj->get_question_attempt($slot)->get_question_id(), 'courseid' => $attemptobj->get_courseid(), 'context' => context_module::instance($attemptobj->get_cmid()), - 'other' => array( + 'other' => [ 'quizid' => $attemptobj->get_quizid(), 'attemptid' => $attemptobj->get_attemptid(), 'slot' => $slot - ) - ); + ] + ]; $event = \mod_quiz\event\question_manually_graded::create($params); $event->trigger(); diff --git a/mod/quiz/db/events.php b/mod/quiz/db/events.php index 46f0060957a..975891c4620 100644 --- a/mod/quiz/db/events.php +++ b/mod/quiz/db/events.php @@ -26,36 +26,36 @@ defined('MOODLE_INTERNAL') || die(); -$observers = array( +$observers = [ // Handle group events, so that open quiz attempts with group overrides get updated check times. - array( + [ 'eventname' => '\core\event\course_reset_started', 'callback' => '\mod_quiz\group_observers::course_reset_started', - ), - array( + ], + [ 'eventname' => '\core\event\course_reset_ended', 'callback' => '\mod_quiz\group_observers::course_reset_ended', - ), - array( + ], + [ 'eventname' => '\core\event\group_deleted', 'callback' => '\mod_quiz\group_observers::group_deleted' - ), - array( + ], + [ 'eventname' => '\core\event\group_member_added', 'callback' => '\mod_quiz\group_observers::group_member_added', - ), - array( + ], + [ 'eventname' => '\core\event\group_member_removed', 'callback' => '\mod_quiz\group_observers::group_member_removed', - ), + ], // Handle our own \mod_quiz\event\attempt_submitted event, as a way to // send confirmation messages asynchronously. - array( + [ 'eventname' => '\mod_quiz\event\attempt_submitted', 'includefile' => '/mod/quiz/locallib.php', 'callback' => 'quiz_attempt_submitted_handler', 'internal' => false - ), -); + ], +]; diff --git a/mod/quiz/db/log.php b/mod/quiz/db/log.php index 86831d430c5..230f166f1dc 100644 --- a/mod/quiz/db/log.php +++ b/mod/quiz/db/log.php @@ -25,20 +25,20 @@ defined('MOODLE_INTERNAL') || die(); -$logs = array( - array('module'=>'quiz', 'action'=>'add', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'update', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'view', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'report', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'attempt', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'submit', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'review', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'editquestions', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'preview', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'start attempt', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'close attempt', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'continue attempt', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'edit override', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'delete override', 'mtable'=>'quiz', 'field'=>'name'), - array('module'=>'quiz', 'action'=>'view summary', 'mtable'=>'quiz', 'field'=>'name'), -); \ No newline at end of file +$logs = [ + ['module' => 'quiz', 'action' => 'add', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'update', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'view', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'report', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'attempt', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'submit', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'review', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'editquestions', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'preview', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'start attempt', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'close attempt', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'continue attempt', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'edit override', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'delete override', 'mtable' => 'quiz', 'field' => 'name'], + ['module' => 'quiz', 'action' => 'view summary', 'mtable' => 'quiz', 'field' => 'name'], +]; diff --git a/mod/quiz/db/messages.php b/mod/quiz/db/messages.php index 32136d17e79..39bede29c94 100644 --- a/mod/quiz/db/messages.php +++ b/mod/quiz/db/messages.php @@ -24,28 +24,28 @@ defined('MOODLE_INTERNAL') || die(); -$messageproviders = array( +$messageproviders = [ // Notify teacher that a student has submitted a quiz attempt. - 'submission' => array( + 'submission' => [ 'capability' => 'mod/quiz:emailnotifysubmission' - ), + ], // Confirm a student's quiz attempt. - 'confirmation' => array( + 'confirmation' => [ 'capability' => 'mod/quiz:emailconfirmsubmission', - 'defaults' => array( + 'defaults' => [ 'airnotifier' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED, - ), - ), + ], + ], // Warning to the student that their quiz attempt is now overdue, if the quiz // has a grace period. - 'attempt_overdue' => array( + 'attempt_overdue' => [ 'capability' => 'mod/quiz:emailwarnoverdue', - 'defaults' => array( + 'defaults' => [ 'airnotifier' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED, - ), - ), + ], + ], 'attempt_grading_complete' => [ 'capability' => 'mod/quiz:emailnotifyattemptgraded', @@ -53,4 +53,4 @@ $messageproviders = array( 'airnotifier' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED, ], ], -); +]; diff --git a/mod/quiz/db/services.php b/mod/quiz/db/services.php index 2babda093a1..cec474a9f18 100644 --- a/mod/quiz/db/services.php +++ b/mod/quiz/db/services.php @@ -26,171 +26,171 @@ defined('MOODLE_INTERNAL') || die; -$functions = array( +$functions = [ - 'mod_quiz_get_quizzes_by_courses' => array( + 'mod_quiz_get_quizzes_by_courses' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'get_quizzes_by_courses', 'description' => 'Returns a list of quizzes in a provided list of courses, if no list is provided all quizzes that the user can view will be returned.', 'type' => 'read', 'capabilities' => 'mod/quiz:view', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_view_quiz' => array( + 'mod_quiz_view_quiz' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'view_quiz', 'description' => 'Trigger the course module viewed event and update the module completion status.', 'type' => 'write', 'capabilities' => 'mod/quiz:view', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_get_user_attempts' => array( + 'mod_quiz_get_user_attempts' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'get_user_attempts', 'description' => 'Return a list of attempts for the given quiz and user.', 'type' => 'read', 'capabilities' => 'mod/quiz:view', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_get_user_best_grade' => array( + 'mod_quiz_get_user_best_grade' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'get_user_best_grade', 'description' => 'Get the best current grade for the given user on a quiz.', 'type' => 'read', 'capabilities' => 'mod/quiz:view', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_get_combined_review_options' => array( + 'mod_quiz_get_combined_review_options' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'get_combined_review_options', 'description' => 'Combines the review options from a number of different quiz attempts.', 'type' => 'read', 'capabilities' => 'mod/quiz:view', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_start_attempt' => array( + 'mod_quiz_start_attempt' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'start_attempt', 'description' => 'Starts a new attempt at a quiz.', 'type' => 'write', 'capabilities' => 'mod/quiz:attempt', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_get_attempt_data' => array( + 'mod_quiz_get_attempt_data' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'get_attempt_data', 'description' => 'Returns information for the given attempt page for a quiz attempt in progress.', 'type' => 'read', 'capabilities' => 'mod/quiz:attempt', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_get_attempt_summary' => array( + 'mod_quiz_get_attempt_summary' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'get_attempt_summary', 'description' => 'Returns a summary of a quiz attempt before it is submitted.', 'type' => 'read', 'capabilities' => 'mod/quiz:attempt', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_save_attempt' => array( + 'mod_quiz_save_attempt' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'save_attempt', 'description' => 'Processes save requests during the quiz. This function is intended for the quiz auto-save feature.', 'type' => 'write', 'capabilities' => 'mod/quiz:attempt', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_process_attempt' => array( + 'mod_quiz_process_attempt' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'process_attempt', 'description' => 'Process responses during an attempt at a quiz and also deals with attempts finishing.', 'type' => 'write', 'capabilities' => 'mod/quiz:attempt', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_get_attempt_review' => array( + 'mod_quiz_get_attempt_review' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'get_attempt_review', 'description' => 'Returns review information for the given finished attempt, can be used by users or teachers.', 'type' => 'read', 'capabilities' => 'mod/quiz:reviewmyattempts', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_view_attempt' => array( + 'mod_quiz_view_attempt' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'view_attempt', 'description' => 'Trigger the attempt viewed event.', 'type' => 'write', 'capabilities' => 'mod/quiz:attempt', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_view_attempt_summary' => array( + 'mod_quiz_view_attempt_summary' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'view_attempt_summary', 'description' => 'Trigger the attempt summary viewed event.', 'type' => 'write', 'capabilities' => 'mod/quiz:attempt', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_view_attempt_review' => array( + 'mod_quiz_view_attempt_review' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'view_attempt_review', 'description' => 'Trigger the attempt reviewed event.', 'type' => 'write', 'capabilities' => 'mod/quiz:reviewmyattempts', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_get_quiz_feedback_for_grade' => array( + 'mod_quiz_get_quiz_feedback_for_grade' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'get_quiz_feedback_for_grade', 'description' => 'Get the feedback text that should be show to a student who got the given grade in the given quiz.', 'type' => 'read', 'capabilities' => 'mod/quiz:view', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_get_quiz_access_information' => array( + 'mod_quiz_get_quiz_access_information' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'get_quiz_access_information', 'description' => 'Return access information for a given quiz.', 'type' => 'read', 'capabilities' => 'mod/quiz:view', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_get_attempt_access_information' => array( + 'mod_quiz_get_attempt_access_information' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'get_attempt_access_information', 'description' => 'Return access information for a given attempt in a quiz.', 'type' => 'read', 'capabilities' => 'mod/quiz:view', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], - 'mod_quiz_get_quiz_required_qtypes' => array( + 'mod_quiz_get_quiz_required_qtypes' => [ 'classname' => 'mod_quiz_external', 'methodname' => 'get_quiz_required_qtypes', 'description' => 'Return the potential question types that would be required for a given quiz.', 'type' => 'read', 'capabilities' => 'mod/quiz:view', - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], 'mod_quiz_set_question_version' => [ 'classname' => 'mod_quiz\external\submit_question_version', @@ -199,4 +199,4 @@ $functions = array( 'capabilities' => 'mod/quiz:view', 'ajax' => true, ], -); +]; diff --git a/mod/quiz/deprecatedlib.php b/mod/quiz/deprecatedlib.php index d23e90960c2..639782c1073 100644 --- a/mod/quiz/deprecatedlib.php +++ b/mod/quiz/deprecatedlib.php @@ -50,10 +50,10 @@ function quiz_completion_check_passing_grade_or_all_attempts($course, $cm, $user // Check for passing grade. require_once($CFG->libdir . '/gradelib.php'); - $item = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod', - 'itemmodule' => 'quiz', 'iteminstance' => $cm->instance, 'outcomeid' => null)); + $item = grade_item::fetch(['courseid' => $course->id, 'itemtype' => 'mod', + 'itemmodule' => 'quiz', 'iteminstance' => $cm->instance, 'outcomeid' => null]); if ($item) { - $grades = grade_grade::fetch_users_grades($item, array($userid), false); + $grades = grade_grade::fetch_users_grades($item, [$userid], false); if (!empty($grades[$userid]) && $grades[$userid]->is_passed($item)) { return true; } @@ -121,7 +121,7 @@ function quiz_get_completion_state($course, $cm, $userid, $type) { // No need to call debugging here. Deprecation debugging notice already being called in \completion_info::internal_get_state(). - $quiz = $DB->get_record('quiz', array('id' => $cm->instance), '*', MUST_EXIST); + $quiz = $DB->get_record('quiz', ['id' => $cm->instance], '*', MUST_EXIST); if (!$quiz->completionattemptsexhausted && !$cm->completionpassgrade && !$quiz->completionminattempts) { return $type; } @@ -219,7 +219,7 @@ function quiz_retrieve_tags_for_slot_ids($slotids) { * * @deprecated in 4.1 use mod_quiz\structure::has_use_capability(...) instead. * - * @param object $quiz the quiz settings. + * @param stdClass $quiz the quiz settings. * @param int $slot which question in the quiz to test. * @return bool whether the user can use this question. */ diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index 07d240aacbf..b3d19009b29 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -60,7 +60,7 @@ $PAGE->set_url($thispageurl); $PAGE->set_secondary_active_tab("mod_quiz_edit"); // Get the course object and related bits. -$course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $quiz->course], '*', MUST_EXIST); $quizobj = new quiz_settings($quiz, $cm, $course); $structure = $quizobj->get_structure(); @@ -70,7 +70,7 @@ require_capability('mod/quiz:manage', $contexts->lowest()); // Process commands ============================================================. // Get the list of question ids had their check-boxes ticked. -$selectedslots = array(); +$selectedslots = []; $params = (array) data_submitted(); foreach ($params as $key => $value) { if (preg_match('!^s([0-9]+)$!', $key, $matches)) { @@ -190,12 +190,12 @@ echo $OUTPUT->header(); // Initialise the JavaScript. $quizeditconfig = new stdClass(); -$quizeditconfig->url = $thispageurl->out(true, array('qbanktool' => '0')); -$quizeditconfig->dialoglisteners = array(); +$quizeditconfig->url = $thispageurl->out(true, ['qbanktool' => '0']); +$quizeditconfig->dialoglisteners = []; $numberoflisteners = $DB->get_field_sql(" SELECT COALESCE(MAX(page), 1) FROM {quiz_slots} - WHERE quizid = ?", array($quiz->id)); + WHERE quizid = ?", [$quiz->id]); for ($pageiter = 1; $pageiter <= $numberoflisteners; $pageiter++) { $quizeditconfig->dialoglisteners[] = 'addrandomdialoglaunch_' . $pageiter; @@ -205,7 +205,7 @@ $PAGE->requires->data_for_js('quiz_edit_config', $quizeditconfig); $PAGE->requires->js('/question/qengine.js'); // Questions wrapper start. -echo html_writer::start_tag('div', array('class' => 'mod-quiz-edit-content')); +echo html_writer::start_tag('div', ['class' => 'mod-quiz-edit-content']); echo $output->edit_page($quizobj, $structure, $contexts, $thispageurl, $pagevars); diff --git a/mod/quiz/edit_rest.php b/mod/quiz/edit_rest.php index e7fe66d1990..14583d54f71 100644 --- a/mod/quiz/edit_rest.php +++ b/mod/quiz/edit_rest.php @@ -51,12 +51,12 @@ $shuffle = optional_param('newshuffle', 0, PARAM_INT); $page = optional_param('page', '', PARAM_INT); $ids = optional_param('ids', '', PARAM_SEQUENCE); $PAGE->set_url('/mod/quiz/edit-rest.php', - array('quizid' => $quizid, 'class' => $class)); + ['quizid' => $quizid, 'class' => $class]); require_sesskey(); -$quiz = $DB->get_record('quiz', array('id' => $quizid), '*', MUST_EXIST); +$quiz = $DB->get_record('quiz', ['id' => $quizid], '*', MUST_EXIST); $cm = get_coursemodule_from_instance('quiz', $quiz->id, $quiz->course); -$course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $quiz->course], '*', MUST_EXIST); require_login($course, false, $cm); $quizobj = new quiz_settings($quiz, $cm, $course); @@ -88,17 +88,17 @@ switch($requestmethod) { switch ($field) { case 'getsectiontitle': require_capability('mod/quiz:manage', $modcontext); - $result = array('instancesection' => $section->heading); + $result = ['instancesection' => $section->heading]; break; case 'updatesectiontitle': require_capability('mod/quiz:manage', $modcontext); $structure->set_section_heading($id, $newheading); - $result = array('instancesection' => format_string($newheading)); + $result = ['instancesection' => format_string($newheading)]; break; case 'updateshufflequestions': require_capability('mod/quiz:manage', $modcontext); $structure->set_section_shuffle($id, $shuffle); - $result = array('instanceshuffle' => $section->shufflequestions); + $result = ['instanceshuffle' => $section->shufflequestions]; break; } break; @@ -116,13 +116,13 @@ switch($requestmethod) { } $structure->move_slot($id, $previousid, $page); quiz_delete_previews($quiz); - $result = array('visible' => true); + $result = ['visible' => true]; break; case 'getmaxmark': require_capability('mod/quiz:manage', $modcontext); - $slot = $DB->get_record('quiz_slots', array('id' => $id), '*', MUST_EXIST); - $result = array('instancemaxmark' => quiz_format_question_grade($quiz, $slot->maxmark)); + $slot = $DB->get_record('quiz_slots', ['id' => $id], '*', MUST_EXIST); + $result = ['instancemaxmark' => quiz_format_question_grade($quiz, $slot->maxmark)]; break; case 'updatemaxmark': @@ -136,19 +136,19 @@ switch($requestmethod) { quiz_update_all_final_grades($quiz); quiz_update_grades($quiz, 0, true); } - $result = array('instancemaxmark' => quiz_format_question_grade($quiz, $maxmark), - 'newsummarks' => quiz_format_grade($quiz, $quiz->sumgrades)); + $result = ['instancemaxmark' => quiz_format_question_grade($quiz, $maxmark), + 'newsummarks' => quiz_format_grade($quiz, $quiz->sumgrades)]; break; case 'updatepagebreak': require_capability('mod/quiz:manage', $modcontext); $slots = $structure->update_page_break($id, $value); - $json = array(); + $json = []; foreach ($slots as $slot) { - $json[$slot->slot] = array('id' => $slot->id, 'slot' => $slot->slot, - 'page' => $slot->page); + $json[$slot->slot] = ['id' => $slot->id, 'slot' => $slot->slot, + 'page' => $slot->page]; } - $result = array('slots' => $json); + $result = ['slots' => $json]; break; case 'deletemultiple': @@ -156,7 +156,7 @@ switch($requestmethod) { $ids = explode(',', $ids); foreach ($ids as $id) { - $slot = $DB->get_record('quiz_slots', array('quizid' => $quiz->id, 'id' => $id), + $slot = $DB->get_record('quiz_slots', ['quizid' => $quiz->id, 'id' => $id], '*', MUST_EXIST); if ($structure->has_use_capability($slot->slot)) { $structure->remove_slot($slot->slot); @@ -165,8 +165,8 @@ switch($requestmethod) { quiz_delete_previews($quiz); quiz_update_sumgrades($quiz); - $result = array('newsummarks' => quiz_format_grade($quiz, $quiz->sumgrades), - 'deleted' => true, 'newnumquestions' => $structure->get_question_count()); + $result = ['newsummarks' => quiz_format_grade($quiz, $quiz->sumgrades), + 'deleted' => true, 'newnumquestions' => $structure->get_question_count()]; break; case 'updatedependency': @@ -174,7 +174,7 @@ switch($requestmethod) { $slot = $structure->get_slot_by_id($id); $value = (bool) $value; $structure->update_question_dependency($slot->id, $value); - $result = array('requireprevious' => $value); + $result = ['requireprevious' => $value]; break; } break; @@ -186,12 +186,12 @@ switch($requestmethod) { case 'section': require_capability('mod/quiz:manage', $modcontext); $structure->remove_section_heading($id); - $result = array('deleted' => true); + $result = ['deleted' => true]; break; case 'resource': require_capability('mod/quiz:manage', $modcontext); - if (!$slot = $DB->get_record('quiz_slots', array('quizid' => $quiz->id, 'id' => $id))) { + if (!$slot = $DB->get_record('quiz_slots', ['quizid' => $quiz->id, 'id' => $id])) { throw new moodle_exception('AJAX commands.php: Bad slot ID '.$id); } @@ -204,8 +204,8 @@ switch($requestmethod) { $structure->remove_slot($slot->slot); quiz_delete_previews($quiz); quiz_update_sumgrades($quiz); - $result = array('newsummarks' => quiz_format_grade($quiz, $quiz->sumgrades), - 'deleted' => true, 'newnumquestions' => $structure->get_question_count()); + $result = ['newsummarks' => quiz_format_grade($quiz, $quiz->sumgrades), + 'deleted' => true, 'newnumquestions' => $structure->get_question_count()]; break; } break; diff --git a/mod/quiz/editrandom.php b/mod/quiz/editrandom.php index 258b4dd93eb..ab07bb77957 100644 --- a/mod/quiz/editrandom.php +++ b/mod/quiz/editrandom.php @@ -77,7 +77,7 @@ $mform = new mod_quiz\form\randomquestion_form(new moodle_url('/mod/quiz/editran $toform = new stdClass(); $toform->category = "{$category->id},{$category->contextid}"; $toform->includesubcategories = $filterconditions->includingsubcategories; -$toform->fromtags = array(); +$toform->fromtags = []; if (isset($filterconditions->tags)) { $currentslottags = $filterconditions->tags; foreach ($currentslottags as $slottag) { diff --git a/mod/quiz/grade.php b/mod/quiz/grade.php index c7889735261..0c531c0efb0 100644 --- a/mod/quiz/grade.php +++ b/mod/quiz/grade.php @@ -35,8 +35,8 @@ $id = required_param('id', PARAM_INT); $userid = optional_param('userid', 0, PARAM_INT); $cm = get_coursemodule_from_id('quiz', $id, 0, false, MUST_EXIST); -$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); -$quiz = $DB->get_record('quiz', array('id' => $cm->instance), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); +$quiz = $DB->get_record('quiz', ['id' => $cm->instance], '*', MUST_EXIST); require_login($course, false, $cm); $reportlist = quiz_report_list(context_module::instance($cm->id)); @@ -46,7 +46,7 @@ if (empty($reportlist) || $userid == $USER->id) { // (The looking at their own grades case is unlikely, since users who // appear in the gradebook are unlikely to be able to see quiz reports, // but it is possible.) - redirect(new moodle_url('/mod/quiz/view.php', array('id' => $cm->id))); + redirect(new moodle_url('/mod/quiz/view.php', ['id' => $cm->id])); } // Now we know the user is interested in reports. If they are interested in a @@ -91,5 +91,5 @@ if ($userid) { } // Send the user to the first report they can see. -redirect(new moodle_url('/mod/quiz/report.php', array( - 'id' => $cm->id, 'mode' => reset($reportlist)))); +redirect(new moodle_url('/mod/quiz/report.php', [ + 'id' => $cm->id, 'mode' => reset($reportlist)])); diff --git a/mod/quiz/index.php b/mod/quiz/index.php index ec7fb984ce9..b78a48bd48c 100644 --- a/mod/quiz/index.php +++ b/mod/quiz/index.php @@ -27,17 +27,17 @@ require_once("../../config.php"); require_once("locallib.php"); $id = required_param('id', PARAM_INT); -$PAGE->set_url('/mod/quiz/index.php', array('id'=>$id)); -if (!$course = $DB->get_record('course', array('id' => $id))) { +$PAGE->set_url('/mod/quiz/index.php', ['id' => $id]); +if (!$course = $DB->get_record('course', ['id' => $id])) { throw new \moodle_exception('invalidcourseid'); } $coursecontext = context_course::instance($id); require_login($course); $PAGE->set_pagelayout('incourse'); -$params = array( +$params = [ 'context' => $coursecontext -); +]; $event = \mod_quiz\event\course_module_instance_list_viewed::create($params); $event->trigger(); @@ -67,8 +67,8 @@ foreach ($quizzes as $quiz) { } // Configure table for displaying the list of instances. -$headings = array(get_string('name')); -$align = array('left'); +$headings = [get_string('name')]; +$align = ['left']; array_push($headings, get_string('quizcloses', 'quiz')); array_push($align, 'left'); @@ -87,7 +87,7 @@ if (has_capability('mod/quiz:viewreports', $coursecontext)) { array_push($align, 'left'); $showing = 'stats'; -} else if (has_any_capability(array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), +} else if (has_any_capability(['mod/quiz:reviewmyattempts', 'mod/quiz:attempt'], $coursecontext)) { array_push($headings, get_string('grade', 'quiz')); array_push($align, 'left'); @@ -102,7 +102,7 @@ if (has_capability('mod/quiz:viewreports', $coursecontext)) { FROM {quiz_grades} qg JOIN {quiz} q ON q.id = qg.quiz WHERE q.course = ? AND qg.userid = ?', - array($course->id, $USER->id)); + [$course->id, $USER->id]); } $table = new html_table(); @@ -116,7 +116,7 @@ $timeclosedates = quiz_get_user_timeclose($course->id); foreach ($quizzes as $quiz) { $cm = get_coursemodule_from_instance('quiz', $quiz->id); $context = context_module::instance($cm->id); - $data = array(); + $data = []; // Section number if necessary. $strsection = ''; diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 0cbd5902dd6..020f0346a86 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -86,7 +86,7 @@ require_once(__DIR__ . '/deprecatedlib.php'); * will create a new instance and return the id number * of the new instance. * - * @param object $quiz the data that came from the form. + * @param stdClass $quiz the data that came from the form. * @return mixed the id of the new instance on success, * false or a string error message on failure. */ @@ -105,8 +105,8 @@ function quiz_add_instance($quiz) { $quiz->id = $DB->insert_record('quiz', $quiz); // Create the first section for this quiz. - $DB->insert_record('quiz_sections', array('quizid' => $quiz->id, - 'firstslot' => 1, 'heading' => '', 'shufflequestions' => 0)); + $DB->insert_record('quiz_sections', ['quizid' => $quiz->id, + 'firstslot' => 1, 'heading' => '', 'shufflequestions' => 0]); // Do the processing required after an add or an update. quiz_after_add_or_update($quiz); @@ -119,7 +119,8 @@ function quiz_add_instance($quiz) { * (defined by the form in mod_form.php) this function * will update an existing instance with new data. * - * @param object $quiz the data that came from the form. + * @param stdClass $quiz the data that came from the form. + * @param stdClass $mform no longer used. * @return mixed true on success, false or a string error message on failure. */ function quiz_update_instance($quiz, $mform) { @@ -133,7 +134,7 @@ function quiz_update_instance($quiz, $mform) { } // Get the current value, so we can see what changed. - $oldquiz = $DB->get_record('quiz', array('id' => $quiz->instance)); + $oldquiz = $DB->get_record('quiz', ['id' => $quiz->instance]); // We need two values from the existing DB record that are not in the form, // in some of the function calls below. @@ -156,7 +157,7 @@ function quiz_update_instance($quiz, $mform) { || $oldquiz->timeclose != $quiz->timeclose || $oldquiz->graceperiod != $quiz->graceperiod; if ($quizdateschanged) { - quiz_update_open_attempts(array('quizid' => $quiz->id)); + quiz_update_open_attempts(['quizid' => $quiz->id]); } // Delete any previous preview attempts. @@ -181,21 +182,21 @@ function quiz_update_instance($quiz, $mform) { function quiz_delete_instance($id) { global $DB; - $quiz = $DB->get_record('quiz', array('id' => $id), '*', MUST_EXIST); + $quiz = $DB->get_record('quiz', ['id' => $id], '*', MUST_EXIST); quiz_delete_all_attempts($quiz); quiz_delete_all_overrides($quiz); quiz_delete_references($quiz->id); // We need to do the following deletes before we try and delete randoms, otherwise they would still be 'in use'. - $DB->delete_records('quiz_slots', array('quizid' => $quiz->id)); - $DB->delete_records('quiz_sections', array('quizid' => $quiz->id)); + $DB->delete_records('quiz_slots', ['quizid' => $quiz->id]); + $DB->delete_records('quiz_sections', ['quizid' => $quiz->id]); - $DB->delete_records('quiz_feedback', array('quizid' => $quiz->id)); + $DB->delete_records('quiz_feedback', ['quizid' => $quiz->id]); access_manager::delete_settings($quiz); - $events = $DB->get_records('event', array('modulename' => 'quiz', 'instance' => $quiz->id)); + $events = $DB->get_records('event', ['modulename' => 'quiz', 'instance' => $quiz->id]); foreach ($events as $event) { $event = calendar_event::load($event); $event->delete(); @@ -203,7 +204,7 @@ function quiz_delete_instance($id) { quiz_grade_item_delete($quiz); // We must delete the module record after we delete the grade item. - $DB->delete_records('quiz', array('id' => $quiz->id)); + $DB->delete_records('quiz', ['id' => $quiz->id]); return true; } @@ -211,7 +212,7 @@ function quiz_delete_instance($id) { /** * Deletes a quiz override from the database and clears any corresponding calendar events * - * @param object $quiz The quiz object. + * @param stdClass $quiz The quiz object. * @param int $overrideid The id of the override being deleted * @param bool $log Whether to trigger logs. * @return bool true on success @@ -224,18 +225,18 @@ function quiz_delete_override($quiz, $overrideid, $log = true) { $quiz->cmid = $cm->id; } - $override = $DB->get_record('quiz_overrides', array('id' => $overrideid), '*', MUST_EXIST); + $override = $DB->get_record('quiz_overrides', ['id' => $overrideid], '*', MUST_EXIST); // Delete the events. if (isset($override->groupid)) { // Create the search array for a group override. - $eventsearcharray = array('modulename' => 'quiz', - 'instance' => $quiz->id, 'groupid' => (int)$override->groupid); + $eventsearcharray = ['modulename' => 'quiz', + 'instance' => $quiz->id, 'groupid' => (int)$override->groupid]; $cachekey = "{$quiz->id}_g_{$override->groupid}"; } else { // Create the search array for a user override. - $eventsearcharray = array('modulename' => 'quiz', - 'instance' => $quiz->id, 'userid' => (int)$override->userid); + $eventsearcharray = ['modulename' => 'quiz', + 'instance' => $quiz->id, 'userid' => (int)$override->userid]; $cachekey = "{$quiz->id}_u_{$override->userid}"; } $events = $DB->get_records('event', $eventsearcharray); @@ -244,18 +245,18 @@ function quiz_delete_override($quiz, $overrideid, $log = true) { $eventold->delete(); } - $DB->delete_records('quiz_overrides', array('id' => $overrideid)); + $DB->delete_records('quiz_overrides', ['id' => $overrideid]); cache::make('mod_quiz', 'overrides')->delete($cachekey); if ($log) { // Set the common parameters for one of the events we will be triggering. - $params = array( + $params = [ 'objectid' => $override->id, 'context' => context_module::instance($quiz->cmid), - 'other' => array( + 'other' => [ 'quizid' => $override->quiz - ) - ); + ] + ]; // Determine which override deleted event to fire. if (!empty($override->userid)) { $params['relateduserid'] = $override->userid; @@ -276,13 +277,13 @@ function quiz_delete_override($quiz, $overrideid, $log = true) { /** * Deletes all quiz overrides from the database and clears any corresponding calendar events * - * @param object $quiz The quiz object. + * @param stdClass $quiz The quiz object. * @param bool $log Whether to trigger logs. */ function quiz_delete_all_overrides($quiz, $log = true) { global $DB; - $overrides = $DB->get_records('quiz_overrides', array('quiz' => $quiz->id), 'id'); + $overrides = $DB->get_records('quiz_overrides', ['quiz' => $quiz->id], 'id'); foreach ($overrides as $override) { quiz_delete_override($quiz, $override->id, $log); } @@ -299,15 +300,15 @@ function quiz_delete_all_overrides($quiz, $log = true) { * quiz->extrapasswords will contain an array of strings giving the remaining * passwords. * - * @param object $quiz The quiz object. + * @param stdClass $quiz The quiz object. * @param int $userid The userid. - * @return object $quiz The updated quiz object. + * @return stdClass $quiz The updated quiz object. */ function quiz_update_effective_access($quiz, $userid) { global $DB; // Check for user override. - $override = $DB->get_record('quiz_overrides', array('quiz' => $quiz->id, 'userid' => $userid)); + $override = $DB->get_record('quiz_overrides', ['quiz' => $quiz->id, 'userid' => $userid]); if (!$override) { $override = new stdClass(); @@ -330,11 +331,11 @@ function quiz_update_effective_access($quiz, $userid) { $records = $DB->get_records_sql($sql, $params); // Combine the overrides. - $opens = array(); - $closes = array(); - $limits = array(); - $attempts = array(); - $passwords = array(); + $opens = []; + $closes = []; + $limits = []; + $attempts = []; + $passwords = []; foreach ($records as $gpoverride) { if (isset($gpoverride->timeopen)) { @@ -388,7 +389,7 @@ function quiz_update_effective_access($quiz, $userid) { } // Merge with quiz defaults. - $keys = array('timeopen', 'timeclose', 'timelimit', 'attempts', 'password', 'extrapasswords'); + $keys = ['timeopen', 'timeclose', 'timelimit', 'attempts', 'password', 'extrapasswords']; foreach ($keys as $key) { if (isset($override->{$key})) { $quiz->{$key} = $override->{$key}; @@ -401,21 +402,21 @@ function quiz_update_effective_access($quiz, $userid) { /** * Delete all the attempts belonging to a quiz. * - * @param object $quiz The quiz object. + * @param stdClass $quiz The quiz object. */ function quiz_delete_all_attempts($quiz) { global $CFG, $DB; require_once($CFG->dirroot . '/mod/quiz/locallib.php'); question_engine::delete_questions_usage_by_activities(new qubaids_for_quiz($quiz->id)); - $DB->delete_records('quiz_attempts', array('quiz' => $quiz->id)); - $DB->delete_records('quiz_grades', array('quiz' => $quiz->id)); + $DB->delete_records('quiz_attempts', ['quiz' => $quiz->id]); + $DB->delete_records('quiz_grades', ['quiz' => $quiz->id]); } /** * Delete all the attempts belonging to a user in a particular quiz. * - * @param object $quiz The quiz object. - * @param object $user The user object. + * @param stdClass $quiz The quiz object. + * @param stdClass $user The user object. */ function quiz_delete_user_attempts($quiz, $user) { global $CFG, $DB; @@ -433,7 +434,7 @@ function quiz_delete_user_attempts($quiz, $user) { /** * Get the best current grade for a particular user in a quiz. * - * @param object $quiz the quiz settings. + * @param stdClass $quiz the quiz settings. * @param int $userid the id of the user. * @return float the user's current grade for this quiz, or null if this user does * not have a grade on this quiz. @@ -441,7 +442,7 @@ function quiz_delete_user_attempts($quiz, $user) { function quiz_get_best_grade($quiz, $userid) { global $DB; $grade = $DB->get_field('quiz_grades', 'grade', - array('quiz' => $quiz->id, 'userid' => $userid)); + ['quiz' => $quiz->id, 'userid' => $userid]); // Need to detect errors/no result, without catching 0 grades. if ($grade === false) { @@ -456,7 +457,7 @@ function quiz_get_best_grade($quiz, $userid) { * $quiz->grade and $quiz->sumgrades are non-zero (for example, if you want to * divide by them). * - * @param object $quiz a row from the quiz table. + * @param stdClass $quiz a row from the quiz table. * @return bool whether this is a graded quiz. */ function quiz_has_grades($quiz) { @@ -480,11 +481,11 @@ function quiz_allows_multiple_tries($quiz) { * $return->time = the time they did it * $return->info = a short text description * - * @param object $course - * @param object $user - * @param object $mod - * @param object $quiz - * @return object|null + * @param stdClass $course + * @param stdClass $user + * @param stdClass $mod + * @param stdClass $quiz + * @return stdClass|null */ function quiz_user_outline($course, $user, $mod, $quiz) { global $DB, $CFG; @@ -499,7 +500,7 @@ function quiz_user_outline($course, $user, $mod, $quiz) { $result = new stdClass(); // If the user can't see hidden grades, don't return that information. - $gitem = grade_item::fetch(array('id' => $grades->items[0]->id)); + $gitem = grade_item::fetch(['id' => $grades->items[0]->id]); if (!$gitem->hidden || has_capability('moodle/grade:viewhidden', context_course::instance($course->id))) { $result->info = get_string('gradenoun') . ': ' . $grade->str_long_grade; } else { @@ -515,10 +516,10 @@ function quiz_user_outline($course, $user, $mod, $quiz) { * Print a detailed representation of what a user has done with * a given particular instance of this module, for user activity reports. * - * @param object $course - * @param object $user - * @param object $mod - * @param object $quiz + * @param stdClass $course + * @param stdClass $user + * @param stdClass $mod + * @param stdClass $quiz * @return bool */ function quiz_user_complete($course, $user, $mod, $quiz) { @@ -530,7 +531,7 @@ function quiz_user_complete($course, $user, $mod, $quiz) { if (!empty($grades->items[0]->grades)) { $grade = reset($grades->items[0]->grades); // If the user can't see hidden grades, don't return that information. - $gitem = grade_item::fetch(array('id' => $grades->items[0]->id)); + $gitem = grade_item::fetch(['id' => $grades->items[0]->id]); if (!$gitem->hidden || has_capability('moodle/grade:viewhidden', context_course::instance($course->id))) { echo $OUTPUT->container(get_string('gradenoun').': '.$grade->str_long_grade); if ($grade->str_feedback) { @@ -545,7 +546,7 @@ function quiz_user_complete($course, $user, $mod, $quiz) { } if ($attempts = $DB->get_records('quiz_attempts', - array('userid' => $user->id, 'quiz' => $quiz->id), 'attempt')) { + ['userid' => $user->id, 'quiz' => $quiz->id], 'attempt')) { foreach ($attempts as $attempt) { echo get_string('attempt', 'quiz', $attempt->attempt) . ': '; if ($attempt->state != quiz_attempt::FINISHED) { @@ -553,7 +554,7 @@ function quiz_user_complete($course, $user, $mod, $quiz) { } else { if (!isset($gitem)) { if (!empty($grades->items[0]->grades)) { - $gitem = grade_item::fetch(array('id' => $grades->items[0]->id)); + $gitem = grade_item::fetch(['id' => $grades->items[0]->id]); } else { $gitem = new stdClass(); $gitem->hidden = true; @@ -586,7 +587,7 @@ function quiz_user_complete($course, $user, $mod, $quiz) { function quiz_get_user_attempts($quizids, $userid, $status = 'finished', $includepreviews = false) { global $DB; - $params = array(); + $params = []; switch ($status) { case 'all': $statuscondition = ''; @@ -631,7 +632,7 @@ function quiz_get_user_attempts($quizids, $userid, $status = 'finished', $includ function quiz_get_user_grades($quiz, $userid = 0) { global $CFG, $DB; - $params = array($quiz->id); + $params = [$quiz->id]; $usertest = ''; if ($userid) { $params[] = $userid; @@ -655,11 +656,11 @@ function quiz_get_user_grades($quiz, $userid = 0) { } /** - * Round a grade to to the correct number of decimal places, and format it for display. + * Round a grade to the correct number of decimal places, and format it for display. * * @param stdClass $quiz The quiz table row, only $quiz->decimalpoints is used. * @param float $grade The grade to round. - * @return float + * @return string */ function quiz_format_grade($quiz, $grade) { if (is_null($grade)) { @@ -671,7 +672,8 @@ function quiz_format_grade($quiz, $grade) { /** * Determine the correct number of decimal places required to format a grade. * - * @param object $quiz The quiz table row, only $quiz->decimalpoints is used. + * @param stdClass $quiz The quiz table row, only $quiz->decimalpoints and + * ->questiondecimalpoints are used. * @return integer */ function quiz_get_grade_format($quiz) { @@ -701,7 +703,7 @@ function quiz_format_question_grade($quiz, $grade) { * Update grades in central gradebook * * @category grade - * @param object $quiz the quiz settings. + * @param stdClass $quiz the quiz settings. * @param int $userid specific user only, 0 means all users. * @param bool $nullifnone If a single user is specified and $nullifnone is true a grade item with a null rawgrade will be inserted */ @@ -730,7 +732,7 @@ function quiz_update_grades($quiz, $userid = 0, $nullifnone = true) { * Create or update the grade item for given quiz * * @category grade - * @param object $quiz object with extra cmidnumber + * @param stdClass $quiz object with extra cmidnumber * @param mixed $grades optional array/object of grade(s); 'reset' means reset grades in gradebook * @return int 0 if ok, error code otherwise */ @@ -740,9 +742,9 @@ function quiz_grade_item_update($quiz, $grades = null) { require_once($CFG->libdir . '/gradelib.php'); if (property_exists($quiz, 'cmidnumber')) { // May not be always present. - $params = array('itemname' => $quiz->name, 'idnumber' => $quiz->cmidnumber); + $params = ['itemname' => $quiz->name, 'idnumber' => $quiz->cmidnumber]; } else { - $params = array('itemname' => $quiz->name); + $params = ['itemname' => $quiz->name]; } if ($quiz->grade > 0) { @@ -834,15 +836,15 @@ function quiz_grade_item_update($quiz, $grades = null) { * Delete grade item for given quiz * * @category grade - * @param object $quiz object - * @return object quiz + * @param stdClass $quiz object + * @return int */ function quiz_grade_item_delete($quiz) { global $CFG; require_once($CFG->libdir . '/gradelib.php'); return grade_update('mod/quiz', $quiz->course, 'mod', 'quiz', $quiz->id, 0, - null, array('deleted' => 1)); + null, ['deleted' => 1]); } /** @@ -863,7 +865,7 @@ function quiz_refresh_events($courseid = 0, $instance = null, $cm = null) { // If we have instance information then we can just update the one event instead of updating all events. if (isset($instance)) { if (!is_object($instance)) { - $instance = $DB->get_record('quiz', array('id' => $instance), '*', MUST_EXIST); + $instance = $DB->get_record('quiz', ['id' => $instance], '*', MUST_EXIST); } quiz_update_events($instance); return true; @@ -874,7 +876,7 @@ function quiz_refresh_events($courseid = 0, $instance = null, $cm = null) { return true; } } else { - if (!$quizzes = $DB->get_records('quiz', array('course' => $courseid))) { + if (!$quizzes = $DB->get_records('quiz', ['course' => $courseid])) { return true; } } @@ -898,7 +900,7 @@ function quiz_get_recent_mod_activity(&$activities, &$index, $timestart, $modinfo = get_fast_modinfo($course); $cm = $modinfo->cms[$cmid]; - $quiz = $DB->get_record('quiz', array('id' => $cm->instance)); + $quiz = $DB->get_record('quiz', ['id' => $cm->instance]); if ($userid) { $userselect = "AND u.id = :userid"; @@ -995,7 +997,7 @@ function quiz_print_recent_mod_activity($activity, $courseid, $detail, $modnames echo ''; echo '
'; - echo $OUTPUT->user_picture($activity->user, array('courseid' => $courseid)); + echo $OUTPUT->user_picture($activity->user, ['courseid' => $courseid]); echo ''; if ($detail) { @@ -1031,7 +1033,7 @@ function quiz_print_recent_mod_activity($activity, $courseid, $detail, $modnames * Pre-process the quiz options form data, making any necessary adjustments. * Called by add/update instance in this file. * - * @param object $quiz The variables set on the form. + * @param stdClass $quiz The variables set on the form. */ function quiz_process_options($quiz) { global $CFG; @@ -1137,16 +1139,16 @@ function quiz_process_options($quiz) { /** * Helper function for {@link quiz_process_options()}. - * @param object $fromform the sumbitted form date. + * @param stdClass $fromform the sumbitted form date. * @param string $field one of the review option field names. */ function quiz_review_option_form_to_db($fromform, $field) { - static $times = array( + static $times = [ 'during' => display_options::DURING, 'immediately' => display_options::IMMEDIATELY_AFTER, 'open' => display_options::LATER_WHILE_OPEN, 'closed' => display_options::AFTER_CLOSE, - ); + ]; $review = 0; foreach ($times as $whenname => $when) { @@ -1172,9 +1174,9 @@ function mod_quiz_inplace_editable(string $itemtype, int $itemid, string $newval if ($itemtype === 'slotdisplaynumber') { global $DB; $record = $DB->get_record('quiz_slots', ['id' => $itemid], '*', MUST_EXIST); - $quiz = $DB->get_record('quiz', array('id' => $record->quizid), '*', MUST_EXIST); + $quiz = $DB->get_record('quiz', ['id' => $record->quizid], '*', MUST_EXIST); $cm = get_coursemodule_from_instance('quiz', $quiz->id, $quiz->course); - $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $quiz->course], '*', MUST_EXIST); // Call validate_context for course module to check access and set current context. $context = context_module::instance($cm->id); @@ -1204,18 +1206,18 @@ function mod_quiz_inplace_editable(string $itemtype, int $itemid, string $newval * This function is called at the end of quiz_add_instance * and quiz_update_instance, to do the common processing. * - * @param object $quiz the quiz object. + * @param stdClass $quiz the quiz object. */ function quiz_after_add_or_update($quiz) { global $DB; $cmid = $quiz->coursemodule; // We need to use context now, so we need to make sure all needed info is already in db. - $DB->set_field('course_modules', 'instance', $quiz->id, array('id'=>$cmid)); + $DB->set_field('course_modules', 'instance', $quiz->id, ['id' => $cmid]); $context = context_module::instance($cmid); // Save the feedback. - $DB->delete_records('quiz_feedback', array('quizid' => $quiz->id)); + $DB->delete_records('quiz_feedback', ['quizid' => $quiz->id]); for ($i = 0; $i <= $quiz->feedbackboundarycount; $i++) { $feedback = new stdClass(); @@ -1227,10 +1229,10 @@ function quiz_after_add_or_update($quiz) { $feedback->id = $DB->insert_record('quiz_feedback', $feedback); $feedbacktext = file_save_draft_area_files((int)$quiz->feedbacktext[$i]['itemid'], $context->id, 'mod_quiz', 'feedback', $feedback->id, - array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), + ['subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0], $quiz->feedbacktext[$i]['text']); $DB->set_field('quiz_feedback', 'feedbacktext', $feedbacktext, - array('id' => $feedback->id)); + ['id' => $feedback->id]); } // Store any settings belonging to the access rules. @@ -1250,16 +1252,15 @@ function quiz_after_add_or_update($quiz) { * If $override is non-zero, then it updates only the events * associated with the specified override. * - * @uses QUIZ_MAX_EVENT_LENGTH - * @param object $quiz the quiz object. - * @param object optional $override limit to a specific override + * @param stdClass $quiz the quiz object. + * @param stdClass|null $override limit to a specific override */ function quiz_update_events($quiz, $override = null) { global $DB; // Load the old events relating to this quiz. - $conds = array('modulename'=>'quiz', - 'instance'=>$quiz->id); + $conds = ['modulename' => 'quiz', + 'instance' => $quiz->id]; if (!empty($override)) { // Only load events for this override. if (isset($override->userid)) { @@ -1273,7 +1274,7 @@ function quiz_update_events($quiz, $override = null) { // Now make a to-do list of all that needs to be updated. if (empty($override)) { // We are updating the primary settings for the quiz, so we need to add all the overrides. - $overrides = $DB->get_records('quiz_overrides', array('quiz' => $quiz->id), 'id ASC'); + $overrides = $DB->get_records('quiz_overrides', ['quiz' => $quiz->id], 'id ASC'); // It is necessary to add an empty stdClass to the beginning of the array as the $oldevents // list contains the original (non-override) event for the module. If this is not included // the logic below will end up updating the wrong row when we try to reconcile this $overrides @@ -1281,7 +1282,7 @@ function quiz_update_events($quiz, $override = null) { array_unshift($overrides, new stdClass()); } else { // Just do the one override. - $overrides = array($override); + $overrides = [$override]; } // Get group override priorities. @@ -1455,7 +1456,7 @@ function quiz_get_group_override_priorities($quizid) { * @return array */ function quiz_get_view_actions() { - return array('view', 'view all', 'report', 'review'); + return ['view', 'view all', 'report', 'review']; } /** @@ -1469,8 +1470,8 @@ function quiz_get_view_actions() { * @return array */ function quiz_get_post_actions() { - return array('attempt', 'close attempt', 'preview', 'editquestions', - 'delete attempt', 'manualgrade'); + return ['attempt', 'close attempt', 'preview', 'editquestions', + 'delete attempt', 'manualgrade']; } /** @@ -1516,9 +1517,9 @@ function quiz_reset_course_form_definition($mform) { * @return array the defaults. */ function quiz_reset_course_form_defaults($course) { - return array('reset_quiz_attempts' => 1, + return ['reset_quiz_attempts' => 1, 'reset_quiz_group_overrides' => 1, - 'reset_quiz_user_overrides' => 1); + 'reset_quiz_user_overrides' => 1]; } /** @@ -1535,7 +1536,7 @@ function quiz_reset_gradebook($courseid, $type='') { FROM {modules} m JOIN {course_modules} cm ON m.id = cm.module JOIN {quiz} q ON cm.instance = q.id - WHERE m.name = 'quiz' AND cm.course = ?", array($courseid)); + WHERE m.name = 'quiz' AND cm.course = ?", [$courseid]); foreach ($quizzes as $quiz) { quiz_grade_item_update($quiz, 'reset'); @@ -1549,7 +1550,7 @@ function quiz_reset_gradebook($courseid, $type='') { * * Also, move the quiz open and close dates, if the course start date is changing. * - * @param object $data the data submitted from the reset course. + * @param stdClass $data the data submitted from the reset course. * @return array status array */ function quiz_reset_userdata($data) { @@ -1557,32 +1558,32 @@ function quiz_reset_userdata($data) { require_once($CFG->libdir . '/questionlib.php'); $componentstr = get_string('modulenameplural', 'quiz'); - $status = array(); + $status = []; // Delete attempts. if (!empty($data->reset_quiz_attempts)) { question_engine::delete_questions_usage_by_activities(new qubaid_join( '{quiz_attempts} quiza JOIN {quiz} quiz ON quiza.quiz = quiz.id', 'quiza.uniqueid', 'quiz.course = :quizcourseid', - array('quizcourseid' => $data->courseid))); + ['quizcourseid' => $data->courseid])); $DB->delete_records_select('quiz_attempts', - 'quiz IN (SELECT id FROM {quiz} WHERE course = ?)', array($data->courseid)); - $status[] = array( + 'quiz IN (SELECT id FROM {quiz} WHERE course = ?)', [$data->courseid]); + $status[] = [ 'component' => $componentstr, 'item' => get_string('attemptsdeleted', 'quiz'), - 'error' => false); + 'error' => false]; // Remove all grades from gradebook. $DB->delete_records_select('quiz_grades', - 'quiz IN (SELECT id FROM {quiz} WHERE course = ?)', array($data->courseid)); + 'quiz IN (SELECT id FROM {quiz} WHERE course = ?)', [$data->courseid]); if (empty($data->reset_gradebook_grades)) { quiz_reset_gradebook($data->courseid); } - $status[] = array( + $status[] = [ 'component' => $componentstr, 'item' => get_string('gradesdeleted', 'quiz'), - 'error' => false); + 'error' => false]; } $purgeoverrides = false; @@ -1590,21 +1591,21 @@ function quiz_reset_userdata($data) { // Remove user overrides. if (!empty($data->reset_quiz_user_overrides)) { $DB->delete_records_select('quiz_overrides', - 'quiz IN (SELECT id FROM {quiz} WHERE course = ?) AND userid IS NOT NULL', array($data->courseid)); - $status[] = array( + 'quiz IN (SELECT id FROM {quiz} WHERE course = ?) AND userid IS NOT NULL', [$data->courseid]); + $status[] = [ 'component' => $componentstr, 'item' => get_string('useroverridesdeleted', 'quiz'), - 'error' => false); + 'error' => false]; $purgeoverrides = true; } // Remove group overrides. if (!empty($data->reset_quiz_group_overrides)) { $DB->delete_records_select('quiz_overrides', - 'quiz IN (SELECT id FROM {quiz} WHERE course = ?) AND groupid IS NOT NULL', array($data->courseid)); - $status[] = array( + 'quiz IN (SELECT id FROM {quiz} WHERE course = ?) AND groupid IS NOT NULL', [$data->courseid]); + $status[] = [ 'component' => $componentstr, 'item' => get_string('groupoverridesdeleted', 'quiz'), - 'error' => false); + 'error' => false]; $purgeoverrides = true; } @@ -1613,23 +1614,23 @@ function quiz_reset_userdata($data) { $DB->execute("UPDATE {quiz_overrides} SET timeopen = timeopen + ? WHERE quiz IN (SELECT id FROM {quiz} WHERE course = ?) - AND timeopen <> 0", array($data->timeshift, $data->courseid)); + AND timeopen <> 0", [$data->timeshift, $data->courseid]); $DB->execute("UPDATE {quiz_overrides} SET timeclose = timeclose + ? WHERE quiz IN (SELECT id FROM {quiz} WHERE course = ?) - AND timeclose <> 0", array($data->timeshift, $data->courseid)); + AND timeclose <> 0", [$data->timeshift, $data->courseid]); $purgeoverrides = true; // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset. // See MDL-9367. - shift_course_mod_dates('quiz', array('timeopen', 'timeclose'), + shift_course_mod_dates('quiz', ['timeopen', 'timeclose'], $data->timeshift, $data->courseid); - $status[] = array( + $status[] = [ 'component' => $componentstr, 'item' => get_string('openclosedatesupdated', 'quiz'), - 'error' => false); + 'error' => false]; } if ($purgeoverrides) { @@ -1643,8 +1644,8 @@ function quiz_reset_userdata($data) { * Return a textual summary of the number of attempts that have been made at a particular quiz, * returns '' if no attempts have been made yet, unless $returnzero is passed as true. * - * @param object $quiz the quiz object. Only $quiz->id is used at the moment. - * @param object $cm the cm object. Only $cm->course, $cm->groupmode and + * @param stdClass $quiz the quiz object. Only $quiz->id is used at the moment. + * @param stdClass $cm the cm object. Only $cm->course, $cm->groupmode and * $cm->groupingid fields are used at the moment. * @param bool $returnzero if false (default), when no attempts have been * made '' is returned instead of 'Attempts: 0'. @@ -1655,7 +1656,7 @@ function quiz_reset_userdata($data) { */ function quiz_num_attempt_summary($quiz, $cm, $returnzero = false, $currentgroup = 0) { global $DB, $USER; - $numattempts = $DB->count_records('quiz_attempts', array('quiz'=> $quiz->id, 'preview'=>0)); + $numattempts = $DB->count_records('quiz_attempts', ['quiz' => $quiz->id, 'preview' => 0]); if ($numattempts || $returnzero) { if (groups_get_activity_groupmode($cm)) { $a = new stdClass(); @@ -1665,7 +1666,7 @@ function quiz_num_attempt_summary($quiz, $cm, $returnzero = false, $currentgroup '{quiz_attempts} qa JOIN ' . '{groups_members} gm ON qa.userid = gm.userid ' . 'WHERE quiz = ? AND preview = 0 AND groupid = ?', - array($quiz->id, $currentgroup)); + [$quiz->id, $currentgroup]); return get_string('attemptsnumthisgroup', 'quiz', $a); } else if ($groups = groups_get_all_groups($cm->course, $USER->id, $cm->groupingid)) { list($usql, $params) = $DB->get_in_or_equal(array_keys($groups)); @@ -1673,7 +1674,7 @@ function quiz_num_attempt_summary($quiz, $cm, $returnzero = false, $currentgroup '{quiz_attempts} qa JOIN ' . '{groups_members} gm ON qa.userid = gm.userid ' . 'WHERE quiz = ? AND preview = 0 AND ' . - "groupid $usql", array_merge(array($quiz->id), $params)); + "groupid $usql", array_merge([$quiz->id], $params)); return get_string('attemptsnumyourgroups', 'quiz', $a); } } @@ -1686,10 +1687,10 @@ function quiz_num_attempt_summary($quiz, $cm, $returnzero = false, $currentgroup * Returns the same as {@link quiz_num_attempt_summary()} but wrapped in a link * to the quiz reports. * - * @param object $quiz the quiz object. Only $quiz->id is used at the moment. - * @param object $cm the cm object. Only $cm->course, $cm->groupmode and + * @param stdClass $quiz the quiz object. Only $quiz->id is used at the moment. + * @param stdClass $cm the cm object. Only $cm->course, $cm->groupmode and * $cm->groupingid fields are used at the moment. - * @param object $context the quiz context. + * @param stdClass $context the quiz context. * @param bool $returnzero if false (default), when no attempts have been made * '' is returned instead of 'Attempts: 0'. * @param int $currentgroup if there is a concept of current group where this method is being called @@ -1774,14 +1775,14 @@ function quiz_extend_settings_navigation(settings_navigation $settings, navigati if (has_capability('mod/quiz:manage', $settings->get_page()->cm->context)) { $node = navigation_node::create(get_string('questions', 'quiz'), - new moodle_url('/mod/quiz/edit.php', array('cmid' => $settings->get_page()->cm->id)), + new moodle_url('/mod/quiz/edit.php', ['cmid' => $settings->get_page()->cm->id]), navigation_node::TYPE_SETTING, null, 'mod_quiz_edit', new pix_icon('t/edit', '')); $quiznode->add_node($node, $beforekey); } if (has_capability('mod/quiz:preview', $settings->get_page()->cm->context)) { $url = new moodle_url('/mod/quiz/startattempt.php', - array('cmid' => $settings->get_page()->cm->id, 'sesskey' => sesskey())); + ['cmid' => $settings->get_page()->cm->id, 'sesskey' => sesskey()]); $node = navigation_node::create(get_string('preview', 'quiz'), $url, navigation_node::TYPE_SETTING, null, 'mod_quiz_preview', new pix_icon('i/preview', '')); @@ -1791,12 +1792,12 @@ function quiz_extend_settings_navigation(settings_navigation $settings, navigati question_extend_settings_navigation($quiznode, $settings->get_page()->cm->context)->trim_if_empty(); - if (has_any_capability(array('mod/quiz:viewreports', 'mod/quiz:grade'), $settings->get_page()->cm->context)) { + if (has_any_capability(['mod/quiz:viewreports', 'mod/quiz:grade'], $settings->get_page()->cm->context)) { require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); $reportlist = quiz_report_list($settings->get_page()->cm->context); $url = new moodle_url('/mod/quiz/report.php', - array('id' => $settings->get_page()->cm->id, 'mode' => reset($reportlist))); + ['id' => $settings->get_page()->cm->id, 'mode' => reset($reportlist)]); $reportnode = $quiznode->add_node(navigation_node::create(get_string('results', 'quiz'), $url, navigation_node::TYPE_SETTING, null, 'quiz_report', new pix_icon('i/report', ''))); @@ -1824,7 +1825,7 @@ function quiz_extend_settings_navigation(settings_navigation $settings, navigati * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - justsend the file */ -function quiz_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { +function quiz_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options= []) { global $CFG, $DB; if ($context->contextlevel != CONTEXT_MODULE) { @@ -1833,18 +1834,18 @@ function quiz_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa require_login($course, false, $cm); - if (!$quiz = $DB->get_record('quiz', array('id'=>$cm->instance))) { + if (!$quiz = $DB->get_record('quiz', ['id' => $cm->instance])) { return false; } // The 'intro' area is served by pluginfile.php. - $fileareas = array('feedback'); + $fileareas = ['feedback']; if (!in_array($filearea, $fileareas)) { return false; } $feedbackid = (int)array_shift($args); - if (!$feedback = $DB->get_record('quiz_feedback', array('id'=>$feedbackid))) { + if (!$feedback = $DB->get_record('quiz_feedback', ['id' => $feedbackid])) { return false; } @@ -1875,7 +1876,7 @@ function quiz_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa * @return bool false if file not found, does not return if found - justsend the file */ function quiz_question_pluginfile($course, $context, $component, - $filearea, $qubaid, $slot, $args, $forcedownload, array $options=array()) { + $filearea, $qubaid, $slot, $args, $forcedownload, array $options= []) { global $CFG; require_once($CFG->dirroot . '/mod/quiz/locallib.php'); @@ -1917,7 +1918,7 @@ function quiz_question_pluginfile($course, $context, $component, * @param stdClass $currentcontext Current context of block */ function quiz_page_type_list($pagetype, $parentcontext, $currentcontext) { - $module_pagetype = array( + $modulepagetype = [ 'mod-quiz-*' => get_string('page-mod-quiz-x', 'quiz'), 'mod-quiz-view' => get_string('page-mod-quiz-view', 'quiz'), 'mod-quiz-attempt' => get_string('page-mod-quiz-attempt', 'quiz'), @@ -1925,18 +1926,18 @@ function quiz_page_type_list($pagetype, $parentcontext, $currentcontext) { 'mod-quiz-review' => get_string('page-mod-quiz-review', 'quiz'), 'mod-quiz-edit' => get_string('page-mod-quiz-edit', 'quiz'), 'mod-quiz-report' => get_string('page-mod-quiz-report', 'quiz'), - ); - return $module_pagetype; + ]; + return $modulepagetype; } /** * @return the options for quiz navigation. */ function quiz_get_navigation_options() { - return array( + return [ QUIZ_NAVMETHOD_FREE => get_string('navmethod_free', 'quiz'), QUIZ_NAVMETHOD_SEQ => get_string('navmethod_seq', 'quiz') - ); + ]; } /** @@ -1948,14 +1949,14 @@ function quiz_get_navigation_options() { * @return stdClass an object with the different type of areas indicating if they were updated or not * @since Moodle 3.2 */ -function quiz_check_updates_since(cm_info $cm, $from, $filter = array()) { +function quiz_check_updates_since(cm_info $cm, $from, $filter = []) { global $DB, $USER, $CFG; require_once($CFG->dirroot . '/mod/quiz/locallib.php'); - $updates = course_check_module_updates_since($cm, $from, array(), $filter); + $updates = course_check_module_updates_since($cm, $from, [], $filter); // Check if questions were updated. - $updates->questions = (object) array('updated' => false); + $updates->questions = (object) ['updated' => false]; $quizobj = quiz_settings::create($cm->instance, $USER->id); $quizobj->preload_questions(); $quizobj->load_questions(); @@ -1973,10 +1974,10 @@ function quiz_check_updates_since(cm_info $cm, $from, $filter = array()) { } // Check for new attempts or grades. - $updates->attempts = (object) array('updated' => false); - $updates->grades = (object) array('updated' => false); + $updates->attempts = (object) ['updated' => false]; + $updates->grades = (object) ['updated' => false]; $select = 'quiz = ? AND userid = ? AND timemodified > ?'; - $params = array($cm->instance, $USER->id, $from); + $params = [$cm->instance, $USER->id, $from]; $attempts = $DB->get_records_select('quiz_attempts', $select, $params, '', 'id'); if (!empty($attempts)) { @@ -1992,7 +1993,7 @@ function quiz_check_updates_since(cm_info $cm, $from, $filter = array()) { // Now, teachers should see other students updates. if (has_capability('mod/quiz:viewreports', $cm->context)) { $select = 'quiz = ? AND timemodified > ?'; - $params = array($cm->instance, $from); + $params = [$cm->instance, $from]; if (groups_get_activity_groupmode($cm) == SEPARATEGROUPS) { $groupusers = array_keys(groups_get_activity_shared_group_members($cm)); @@ -2004,14 +2005,14 @@ function quiz_check_updates_since(cm_info $cm, $from, $filter = array()) { $params = array_merge($params, $inparams); } - $updates->userattempts = (object) array('updated' => false); + $updates->userattempts = (object) ['updated' => false]; $attempts = $DB->get_records_select('quiz_attempts', $select, $params, '', 'id'); if (!empty($attempts)) { $updates->userattempts->updated = true; $updates->userattempts->itemids = array_keys($attempts); } - $updates->usergrades = (object) array('updated' => false); + $updates->usergrades = (object) ['updated' => false]; $grades = $DB->get_records_select('quiz_grades', $select, $params, '', 'id'); if (!empty($grades)) { $updates->usergrades->updated = true; @@ -2383,7 +2384,7 @@ function mod_quiz_core_calendar_event_timestart_updated(\calendar_event $event, $DB->update_record('quiz', $quiz); if ($closedatechanged) { - quiz_update_open_attempts(array('quizid' => $quiz->id)); + quiz_update_open_attempts(['quizid' => $quiz->id]); } // Delete any previous preview attempts. @@ -2423,7 +2424,7 @@ function mod_quiz_output_fragment_quiz_question_bank($args) { question_build_edit_resources('editq', '/mod/quiz/edit.php', $params, custom_view::DEFAULT_PAGE_SIZE); // Get the course object and related bits. - $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $quiz->course], '*', MUST_EXIST); require_capability('mod/quiz:manage', $contexts->lowest()); // Create quiz question bank view. diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index cdfa2bfd23c..f18deebca6f 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -79,15 +79,15 @@ define('QUIZ_SHOWIMAGE_LARGE', 2); * user starting at the current time. The ->id field is not set. The object is * NOT written to the database. * - * @param object $quizobj the quiz object to create an attempt for. + * @param quiz_settings $quizobj the quiz object to create an attempt for. * @param int $attemptnumber the sequence number for the attempt. * @param stdClass|false $lastattempt the previous attempt by this user, if any. Only needed * if $attemptnumber > 1 and $quiz->attemptonlast is true. * @param int $timenow the time the attempt was started at. * @param bool $ispreview whether this new attempt is a preview. - * @param int $userid the id of the user attempting this quiz. + * @param int|null $userid the id of the user attempting this quiz. * - * @return object the newly created attempt object. + * @return stdClass the newly created attempt object. */ function quiz_create_attempt(quiz_settings $quizobj, $attemptnumber, $lastattempt, $timenow, $ispreview = false, $userid = null) { global $USER; @@ -99,8 +99,8 @@ function quiz_create_attempt(quiz_settings $quizobj, $attemptnumber, $lastattemp $quiz = $quizobj->get_quiz(); if ($quiz->sumgrades < 0.000005 && $quiz->grade > 0.000005) { throw new moodle_exception('cannotstartgradesmismatch', 'quiz', - new moodle_url('/mod/quiz/view.php', array('q' => $quiz->id)), - array('grade' => quiz_format_grade($quiz, $quiz->grade))); + new moodle_url('/mod/quiz/view.php', ['q' => $quiz->id]), + ['grade' => quiz_format_grade($quiz, $quiz->grade)]); } if ($attemptnumber == 1 || !$quiz->attemptonlast) { @@ -147,7 +147,7 @@ function quiz_create_attempt(quiz_settings $quizobj, $attemptnumber, $lastattemp * * @param quiz_settings $quizobj the quiz object to start an attempt for. * @param question_usage_by_activity $quba - * @param object $attempt + * @param stdClass $attempt * @param integer $attemptnumber starting from 1 * @param integer $timenow the attempt start time * @param array $questionids slot number => question id. Used for random questions, to force the choice @@ -155,10 +155,10 @@ function quiz_create_attempt(quiz_settings $quizobj, $attemptnumber, $lastattemp * @param array $forcedvariantsbyslot slot number => variant. Used for questions with variants, * to force the choice of a particular variant. Intended for testing * purposes only. - * @return object modified attempt object + * @return stdClass modified attempt object */ function quiz_start_new_attempt($quizobj, $quba, $attempt, $attemptnumber, $timenow, - $questionids = array(), $forcedvariantsbyslot = array()) { + $questionids = [], $forcedvariantsbyslot = []) { // Usages for this user's previous quiz attempts. $qubaids = new \mod_quiz\question\qubaids_for_users_attempts( @@ -171,9 +171,9 @@ function quiz_start_new_attempt($quizobj, $quba, $attempt, $attemptnumber, $time // First load all the non-random questions. $randomfound = false; $slot = 0; - $questions = array(); - $maxmark = array(); - $page = array(); + $questions = []; + $maxmark = []; + $page = []; foreach ($quizobj->get_questions() as $questiondata) { $slot += 1; $maxmark[$slot] = $questiondata->maxmark; @@ -191,7 +191,7 @@ function quiz_start_new_attempt($quizobj, $quba, $attempt, $attemptnumber, $time // Then find a question to go in place of each random question. if ($randomfound) { $slot = 0; - $usedquestionids = array(); + $usedquestionids = []; foreach ($questions as $question) { if ($question->id && isset($usedquestions[$question->id])) { $usedquestionids[$question->id] += 1; @@ -265,10 +265,10 @@ function quiz_start_new_attempt($quizobj, $quba, $attempt, $attemptnumber, $time } } - $layout = array(); + $layout = []; foreach ($sections as $section) { if ($section->shufflequestions) { - $questionsinthissection = array(); + $questionsinthissection = []; for ($slot = $section->firstslot; $slot <= $section->lastslot; $slot += 1) { $questionsinthissection[] = $slot; } @@ -306,15 +306,15 @@ function quiz_start_new_attempt($quizobj, $quba, $attempt, $attemptnumber, $time * Start a subsequent new attempt, in each attempt builds on last mode. * * @param question_usage_by_activity $quba this question usage - * @param object $attempt this attempt - * @param object $lastattempt last attempt - * @return object modified attempt object + * @param stdClass $attempt this attempt + * @param stdClass $lastattempt last attempt + * @return stdClass modified attempt object * */ function quiz_start_attempt_built_on_last($quba, $attempt, $lastattempt) { $oldquba = question_engine::load_questions_usage_by_activity($lastattempt->uniqueid); - $oldnumberstonew = array(); + $oldnumberstonew = []; foreach ($oldquba->get_attempt_iterator() as $oldslot => $oldqa) { $newslot = $quba->add_question($oldqa->get_question(false), $oldqa->get_max_mark()); @@ -324,7 +324,7 @@ function quiz_start_attempt_built_on_last($quba, $attempt, $lastattempt) { } // Update attempt layout. - $newlayout = array(); + $newlayout = []; foreach (explode(',', $lastattempt->layout) as $oldslot) { if ($oldslot != 0) { $newlayout[] = $oldnumberstonew[$oldslot]; @@ -341,8 +341,8 @@ function quiz_start_attempt_built_on_last($quba, $attempt, $lastattempt) { * * @param quiz_settings $quizobj * @param question_usage_by_activity $quba - * @param object $attempt - * @return object attempt object with uniqueid and id set. + * @param stdClass $attempt + * @return stdClass attempt object with uniqueid and id set. */ function quiz_attempt_save_started($quizobj, $quba, $attempt) { global $DB; @@ -352,17 +352,17 @@ function quiz_attempt_save_started($quizobj, $quba, $attempt) { $attempt->id = $DB->insert_record('quiz_attempts', $attempt); // Params used by the events below. - $params = array( + $params = [ 'objectid' => $attempt->id, 'relateduserid' => $attempt->userid, 'courseid' => $quizobj->get_courseid(), 'context' => $quizobj->get_context() - ); + ]; // Decide which event we are using. if ($attempt->preview) { - $params['other'] = array( + $params['other'] = [ 'quizid' => $quizobj->get_quizid() - ); + ]; $event = \mod_quiz\event\attempt_preview_started::create($params); } else { $event = \mod_quiz\event\attempt_started::create($params); @@ -399,12 +399,12 @@ function quiz_get_user_attempt_unfinished($quizid, $userid) { * Delete a quiz attempt. * @param mixed $attempt an integer attempt id or an attempt object * (row of the quiz_attempts table). - * @param object $quiz the quiz object. + * @param stdClass $quiz the quiz object. */ function quiz_delete_attempt($attempt, $quiz) { global $DB; if (is_numeric($attempt)) { - if (!$attempt = $DB->get_record('quiz_attempts', array('id' => $attempt))) { + if (!$attempt = $DB->get_record('quiz_attempts', ['id' => $attempt])) { return; } } @@ -421,18 +421,18 @@ function quiz_delete_attempt($attempt, $quiz) { } question_engine::delete_questions_usage_by_activity($attempt->uniqueid); - $DB->delete_records('quiz_attempts', array('id' => $attempt->id)); + $DB->delete_records('quiz_attempts', ['id' => $attempt->id]); // Log the deletion of the attempt if not a preview. if (!$attempt->preview) { - $params = array( + $params = [ 'objectid' => $attempt->id, 'relateduserid' => $attempt->userid, 'context' => context_module::instance($quiz->cmid), - 'other' => array( + 'other' => [ 'quizid' => $quiz->id - ) - ); + ] + ]; $event = \mod_quiz\event\attempt_deleted::create($params); $event->add_record_snapshot('quiz_attempts', $attempt); $event->trigger(); @@ -442,8 +442,8 @@ function quiz_delete_attempt($attempt, $quiz) { // If none, then delete record for this quiz, this user from quiz_grades // else recalculate best grade. $userid = $attempt->userid; - if (!$DB->record_exists('quiz_attempts', array('userid' => $userid, 'quiz' => $quiz->id))) { - $DB->delete_records('quiz_grades', array('userid' => $userid, 'quiz' => $quiz->id)); + if (!$DB->record_exists('quiz_attempts', ['userid' => $userid, 'quiz' => $quiz->id])) { + $DB->delete_records('quiz_grades', ['userid' => $userid, 'quiz' => $quiz->id]); } else { quiz_save_best_grade($quiz, $userid); } @@ -454,12 +454,12 @@ function quiz_delete_attempt($attempt, $quiz) { /** * Delete all the preview attempts at a quiz, or possibly all the attempts belonging * to one user. - * @param object $quiz the quiz object. + * @param stdClass $quiz the quiz object. * @param int $userid (optional) if given, only delete the previews belonging to this user. */ function quiz_delete_previews($quiz, $userid = null) { global $DB; - $conditions = array('quiz' => $quiz->id, 'preview' => 1); + $conditions = ['quiz' => $quiz->id, 'preview' => 1]; if (!empty($userid)) { $conditions['userid'] = $userid; } @@ -475,7 +475,7 @@ function quiz_delete_previews($quiz, $userid = null) { */ function quiz_has_attempts($quizid) { global $DB; - return $DB->record_exists('quiz_attempts', array('quiz' => $quizid, 'preview' => 0)); + return $DB->record_exists('quiz_attempts', ['quiz' => $quizid, 'preview' => 0]); } // Functions to do with quiz layout and pages ////////////////////////////////// @@ -489,8 +489,8 @@ function quiz_repaginate_questions($quizid, $slotsperpage) { global $DB; $trans = $DB->start_delegated_transaction(); - $sections = $DB->get_records('quiz_sections', array('quizid' => $quizid), 'firstslot ASC'); - $firstslots = array(); + $sections = $DB->get_records('quiz_sections', ['quizid' => $quizid], 'firstslot ASC'); + $firstslots = []; foreach ($sections as $section) { if ((int)$section->firstslot === 1) { continue; @@ -498,7 +498,7 @@ function quiz_repaginate_questions($quizid, $slotsperpage) { $firstslots[] = $section->firstslot; } - $slots = $DB->get_records('quiz_slots', array('quizid' => $quizid), + $slots = $DB->get_records('quiz_slots', ['quizid' => $quizid], 'slot'); $currentpage = 1; $slotsonthispage = 0; @@ -509,7 +509,7 @@ function quiz_repaginate_questions($quizid, $slotsperpage) { $slotsonthispage = 0; } if ($slot->page != $currentpage) { - $DB->set_field('quiz_slots', 'page', $currentpage, array('id' => $slot->id)); + $DB->set_field('quiz_slots', 'page', $currentpage, ['id' => $slot->id]); } $slotsonthispage += 1; } @@ -536,7 +536,7 @@ function quiz_repaginate_questions($quizid, $slotsperpage) { * grade for this quiz. * * @param float $rawgrade the unadjusted grade, fof example $attempt->sumgrades - * @param object $quiz the quiz object. Only the fields grade, sumgrades and decimalpoints are used. + * @param stdClass $quiz the quiz object. Only the fields grade, sumgrades and decimalpoints are used. * @param bool|string $format whether to format the results for display * or 'question' to format a question grade (different number of decimal places. * @return float|string the rescaled grade, or null/the lang string 'notyetgraded' @@ -562,7 +562,7 @@ function quiz_rescale_grade($rawgrade, $quiz, $format = true) { * Get the feedback object for this grade on this quiz. * * @param float $grade a grade on this quiz. - * @param object $quiz the quiz settings. + * @param stdClass $quiz the quiz settings. * @return false|stdClass the record object or false if there is not feedback for the given grade * @since Moodle 3.1 */ @@ -574,7 +574,7 @@ function quiz_feedback_record_for_grade($grade, $quiz) { $grade = max($grade, 0); $feedback = $DB->get_record_select('quiz_feedback', - 'quizid = ? AND mingrade <= ? AND ? < maxgrade', array($quiz->id, $grade, $grade)); + 'quizid = ? AND mingrade <= ? AND ? < maxgrade', [$quiz->id, $grade, $grade]); return $feedback; } @@ -611,17 +611,17 @@ function quiz_feedback_for_grade($grade, $quiz, $context) { } /** - * @param object $quiz the quiz database row. + * @param stdClass $quiz the quiz database row. * @return bool Whether this quiz has any non-blank feedback text. */ function quiz_has_feedback($quiz) { global $DB; - static $cache = array(); + static $cache = []; if (!array_key_exists($quiz->id, $cache)) { $cache[$quiz->id] = quiz_has_grades($quiz) && $DB->record_exists_select('quiz_feedback', "quizid = ? AND " . $DB->sql_isnotempty('quiz_feedback', 'feedbacktext', false, true), - array($quiz->id)); + [$quiz->id]); } return $cache[$quiz->id]; } @@ -633,7 +633,7 @@ function quiz_has_feedback($quiz) { * * You should call {@link quiz_delete_previews()} before you call this function. * - * @param object $quiz a quiz. + * @param stdClass $quiz a quiz. */ function quiz_update_sumgrades($quiz) { global $DB; @@ -645,8 +645,8 @@ function quiz_update_sumgrades($quiz) { WHERE quizid = {quiz}.id ), 0) WHERE id = ?'; - $DB->execute($sql, array($quiz->id)); - $quiz->sumgrades = $DB->get_field('quiz', 'sumgrades', array('id' => $quiz->id)); + $DB->execute($sql, [$quiz->id]); + $quiz->sumgrades = $DB->get_field('quiz', 'sumgrades', ['id' => $quiz->id]); if ($quiz->sumgrades < 0.000005 && quiz_has_attempts($quiz->id)) { // If the quiz has been attempted, and the sumgrades has been @@ -659,7 +659,7 @@ function quiz_update_sumgrades($quiz) { /** * Update the sumgrades field of the attempts at a quiz. * - * @param object $quiz a quiz. + * @param stdClass $quiz a quiz. */ function quiz_update_all_attempt_sumgrades($quiz) { global $DB; @@ -673,8 +673,8 @@ function quiz_update_all_attempt_sumgrades($quiz) { {$dm->sum_usage_marks_subquery('uniqueid')} ) WHERE quiz = :quizid AND state = :finishedstate"; - $DB->execute($sql, array('timenow' => $timenow, 'quizid' => $quiz->id, - 'finishedstate' => quiz_attempt::FINISHED)); + $DB->execute($sql, ['timenow' => $timenow, 'quizid' => $quiz->id, + 'finishedstate' => quiz_attempt::FINISHED]); } /** @@ -685,7 +685,7 @@ function quiz_update_all_attempt_sumgrades($quiz) { * quiz_update_grades. * * @param float $newgrade the new maximum grade for the quiz. - * @param object $quiz the quiz we are updating. Passed by reference so its + * @param stdClass $quiz the quiz we are updating. Passed by reference so its * grade field can be updated too. * @return bool indicating success or failure. */ @@ -704,7 +704,7 @@ function quiz_set_grade($newgrade, $quiz) { $transaction = $DB->start_delegated_transaction(); // Update the quiz table. - $DB->set_field('quiz', 'grade', $newgrade, array('id' => $quiz->instance)); + $DB->set_field('quiz', 'grade', $newgrade, ['id' => $quiz->instance]); if ($oldgrade < 1) { // If the old grade was zero, we cannot rescale, we have to recompute. @@ -718,7 +718,7 @@ function quiz_set_grade($newgrade, $quiz) { UPDATE {quiz_grades} SET grade = ? * grade, timemodified = ? WHERE quiz = ? - ", array($newgrade/$oldgrade, $timemodified, $quiz->id)); + ", [$newgrade / $oldgrade, $timemodified, $quiz->id]); } if ($oldgrade > 1e-7) { @@ -728,7 +728,7 @@ function quiz_set_grade($newgrade, $quiz) { UPDATE {quiz_feedback} SET mingrade = ? * mingrade, maxgrade = ? * maxgrade WHERE quizid = ? - ", array($factor, $factor, $quiz->id)); + ", [$factor, $factor, $quiz->id]); } // Update grade item and send all grades to gradebook. @@ -755,14 +755,14 @@ function quiz_set_grade($newgrade, $quiz) { /** * Save the overall grade for a user at a quiz in the quiz_grades table * - * @param object $quiz The quiz for which the best grade is to be calculated and then saved. + * @param stdClass $quiz The quiz for which the best grade is to be calculated and then saved. * @param int $userid The userid to calculate the grade for. Defaults to the current user. * @param array $attempts The attempts of this user. Useful if you are * looping through many users. Attempts can be fetched in one master query to * avoid repeated querying. * @return bool Indicates success or failure. */ -function quiz_save_best_grade($quiz, $userid = null, $attempts = array()) { +function quiz_save_best_grade($quiz, $userid = null, $attempts = []) { global $DB, $OUTPUT, $USER; if (empty($userid)) { @@ -780,10 +780,10 @@ function quiz_save_best_grade($quiz, $userid = null, $attempts = array()) { // Save the best grade in the database. if (is_null($bestgrade)) { - $DB->delete_records('quiz_grades', array('quiz' => $quiz->id, 'userid' => $userid)); + $DB->delete_records('quiz_grades', ['quiz' => $quiz->id, 'userid' => $userid]); } else if ($grade = $DB->get_record('quiz_grades', - array('quiz' => $quiz->id, 'userid' => $userid))) { + ['quiz' => $quiz->id, 'userid' => $userid])) { $grade->grade = $bestgrade; $grade->timemodified = time(); $DB->update_record('quiz_grades', $grade); @@ -803,7 +803,7 @@ function quiz_save_best_grade($quiz, $userid = null, $attempts = array()) { /** * Calculate the overall grade for a quiz given a number of attempts by a particular user. * - * @param object $quiz the quiz settings object. + * @param stdClass $quiz the quiz settings object. * @param array $attempts an array of all the user's attempts at this quiz in order. * @return float the overall grade */ @@ -851,7 +851,7 @@ function quiz_calculate_best_grade($quiz, $attempts) { * This function is equivalent to calling quiz_save_best_grade for all * users, but much more efficient. * - * @param object $quiz the quiz settings. + * @param stdClass $quiz the quiz settings. */ function quiz_update_all_final_grades($quiz) { global $DB; @@ -860,7 +860,7 @@ function quiz_update_all_final_grades($quiz) { return; } - $param = array('iquizid' => $quiz->id, 'istatefinished' => quiz_attempt::FINISHED); + $param = ['iquizid' => $quiz->id, 'istatefinished' => quiz_attempt::FINISHED]; $firstlastattemptjoin = "JOIN ( SELECT iquiza.userid, @@ -963,7 +963,7 @@ function quiz_update_all_final_grades($quiz) { $param); $timenow = time(); - $todelete = array(); + $todelete = []; foreach ($changedgrades as $changedgrade) { if (is_null($changedgrade->newgrade)) { @@ -989,7 +989,7 @@ function quiz_update_all_final_grades($quiz) { if (!empty($todelete)) { list($test, $params) = $DB->get_in_or_equal($todelete); $DB->delete_records_select('quiz_grades', 'quiz = ? AND userid ' . $test, - array_merge(array($quiz->id), $params)); + array_merge([$quiz->id], $params)); } } @@ -1075,13 +1075,13 @@ function quiz_update_open_attempts(array $conditions) { foreach ($conditions as &$value) { if (!is_array($value)) { - $value = array($value); + $value = [$value]; } } - $params = array(); - $wheres = array("quiza.state IN ('inprogress', 'overdue')"); - $iwheres = array("iquiza.state IN ('inprogress', 'overdue')"); + $params = []; + $wheres = ["quiza.state IN ('inprogress', 'overdue')"]; + $iwheres = ["iquiza.state IN ('inprogress', 'overdue')"]; if (isset($conditions['courseid'])) { list ($incond, $inparams) = $DB->get_in_or_equal($conditions['courseid'], SQL_PARAMS_NAMED, 'cid'); @@ -1218,8 +1218,8 @@ function quiz_get_attempt_usertime_sql($redundantwhereclauses = '') { * * Which attempt is the best depends on $quiz->grademethod. If the grade * method is GRADEAVERAGE then this function simply returns the last attempt. - * @return object The attempt with the best grade - * @param object $quiz The quiz for which the best grade is to be calculated + * @return stdClass The attempt with the best grade + * @param stdClass $quiz The quiz for which the best grade is to be calculated * @param array $attempts An array of all the attempts of the user at the quiz */ function quiz_calculate_best_attempt($quiz, $attempts) { @@ -1257,12 +1257,12 @@ function quiz_calculate_best_attempt($quiz, $attempts) { * from the individual attempt grades. */ function quiz_get_grading_options() { - return array( + return [ QUIZ_GRADEHIGHEST => get_string('gradehighest', 'quiz'), QUIZ_GRADEAVERAGE => get_string('gradeaverage', 'quiz'), QUIZ_ATTEMPTFIRST => get_string('attemptfirst', 'quiz'), QUIZ_ATTEMPTLAST => get_string('attemptlast', 'quiz') - ); + ]; } /** @@ -1280,11 +1280,11 @@ function quiz_get_grading_option_name($option) { * attempts. */ function quiz_get_overdue_handling_options() { - return array( + return [ 'autosubmit' => get_string('overduehandlingautosubmit', 'quiz'), 'graceperiod' => get_string('overduehandlinggraceperiod', 'quiz'), 'autoabandon' => get_string('overduehandlingautoabandon', 'quiz'), - ); + ]; } /** @@ -1292,18 +1292,18 @@ function quiz_get_overdue_handling_options() { * @return array string => lang string the options for whether to display the user's picture. */ function quiz_get_user_image_options() { - return array( + return [ QUIZ_SHOWIMAGE_NONE => get_string('shownoimage', 'quiz'), QUIZ_SHOWIMAGE_SMALL => get_string('showsmallimage', 'quiz'), QUIZ_SHOWIMAGE_LARGE => get_string('showlargeimage', 'quiz'), - ); + ]; } /** * Return an user's timeclose for all quizzes in a course, hereby taking into account group and user overrides. * * @param int $courseid the course id. - * @return object An object with of all quizids and close unixdates in this course, taking into account the most lenient + * @return stdClass An object with of all quizids and close unixdates in this course, taking into account the most lenient * overrides, if existing and 0 if no close date is set. */ function quiz_get_user_timeclose($courseid) { @@ -1315,7 +1315,7 @@ function quiz_get_user_timeclose($courseid) { FROM {quiz} quiz WHERE quiz.course = :courseid"; - $results = $DB->get_records_sql($sql, array('courseid' => $courseid)); + $results = $DB->get_records_sql($sql, ['courseid' => $courseid]); return $results; } @@ -1332,7 +1332,7 @@ function quiz_get_user_timeclose($courseid) { GROUP BY quiz.id) v JOIN {quiz} q ON q.id = v.quizid"; - $results = $DB->get_records_sql($sql, array('userid' => $USER->id, 'useringroupid' => $USER->id, 'courseid' => $courseid)); + $results = $DB->get_records_sql($sql, ['userid' => $USER->id, 'useringroupid' => $USER->id, 'courseid' => $courseid]); return $results; } @@ -1342,7 +1342,7 @@ function quiz_get_user_timeclose($courseid) { * @return array int => string. */ function quiz_questions_per_page_options() { - $pageoptions = array(); + $pageoptions = []; $pageoptions[0] = get_string('neverallononepage', 'quiz'); $pageoptions[1] = get_string('everyquestion', 'quiz'); for ($i = 2; $i <= QUIZ_MAX_QPP_OPTION; ++$i) { @@ -1374,12 +1374,11 @@ function quiz_attempt_state_name($state) { // Other quiz functions //////////////////////////////////////////////////////// /** - * @param object $quiz the quiz. + * @param stdClass $quiz the quiz. * @param int $cmid the course_module object for this quiz. - * @param object $question the question. + * @param stdClass $question the question. * @param string $returnurl url to return to after action is done. * @param int $variant which question variant to preview (optional). - * @param bool $random if question is random, true. * @return string html for a number of icons linked to action pages for a * question - preview and edit / view icons depending on user capabilities. */ @@ -1394,7 +1393,7 @@ function quiz_question_action_icons($quiz, $cmid, $question, $returnurl, $varian /** * @param int $cmid the course_module.id for this quiz. - * @param object $question the question. + * @param stdClass $question the question. * @param string $returnurl url to return to after action is done. * @param string $contentbeforeicon some HTML content to be added inside the link, before the icon. * @return the HTML for an edit icon, view icon, or nothing for a question @@ -1429,7 +1428,7 @@ function quiz_question_edit_button($cmid, $question, $returnurl, $contentafteric if ($returnurl instanceof moodle_url) { $returnurl = $returnurl->out_as_local_url(false); } - $questionparams = array('returnurl' => $returnurl, 'cmid' => $cmid, 'id' => $question->id); + $questionparams = ['returnurl' => $returnurl, 'cmid' => $cmid, 'id' => $question->id]; $questionurl = new moodle_url("$CFG->wwwroot/question/bank/editquestion/question.php", $questionparams); return '' . $OUTPUT->pix_icon($icon, $action) . $contentaftericon . @@ -1442,8 +1441,8 @@ function quiz_question_edit_button($cmid, $question, $returnurl, $contentafteric } /** - * @param object $quiz the quiz settings - * @param object $question the question + * @param stdClass $quiz the quiz settings + * @param stdClass $question the question * @param int $variant which question variant to preview (optional). * @return moodle_url to preview this question with the options from this quiz. */ @@ -1463,8 +1462,8 @@ function quiz_question_preview_url($quiz, $question, $variant = null) { } /** - * @param object $quiz the quiz settings - * @param object $question the question + * @param stdClass $quiz the quiz settings + * @param stdClass $question the question * @param bool $label if true, show the preview question label after the icon * @param int $variant which question variant to preview (optional). * @param bool $random if question is random, true. @@ -1479,8 +1478,8 @@ function quiz_question_preview_button($quiz, $question, $label = false, $variant } /** - * @param object $attempt the attempt. - * @param object $context the quiz context. + * @param stdClass $attempt the attempt. + * @param stdClass $context the quiz context. * @return int whether flags should be shown/editable to the current user for this attempt. */ function quiz_get_flag_option($attempt, $context) { @@ -1497,8 +1496,8 @@ function quiz_get_flag_option($attempt, $context) { /** * Work out what state this quiz attempt is in - in the sense used by * quiz_get_review_options, not in the sense of $attempt->state. - * @param object $quiz the quiz settings - * @param object $attempt the quiz_attempt database row. + * @param stdClass $quiz the quiz settings + * @param stdClass $attempt the quiz_attempt database row. * @return int one of the display_options::DURING, * IMMEDIATELY_AFTER, LATER_WHILE_OPEN or AFTER_CLOSE constants. */ @@ -1530,7 +1529,7 @@ function quiz_get_review_options($quiz, $attempt, $context) { $options->flags = quiz_get_flag_option($attempt, $context); if (!empty($attempt->id)) { $options->questionreviewlink = new moodle_url('/mod/quiz/reviewquestion.php', - array('attempt' => $attempt->id)); + ['attempt' => $attempt->id]); } // Show a link to the comment box only for closed attempts. @@ -1538,7 +1537,7 @@ function quiz_get_review_options($quiz, $attempt, $context) { !is_null($context) && has_capability('mod/quiz:grade', $context)) { $options->manualcomment = question_display_options::VISIBLE; $options->manualcommentlink = new moodle_url('/mod/quiz/comment.php', - array('attempt' => $attempt->id)); + ['attempt' => $attempt->id]); } if (!is_null($context) && !$attempt->preview && @@ -1569,7 +1568,7 @@ function quiz_get_review_options($quiz, $attempt, $context) { * funciton is: * list($someoptions, $alloptions) = quiz_get_combined_reviewoptions(...) * - * @param object $quiz the quiz instance. + * @param stdClass $quiz the quiz instance. * @param array $attempts an array of attempt objects. * * @return array of two options objects, one showing which options are true for @@ -1577,7 +1576,7 @@ function quiz_get_review_options($quiz, $attempt, $context) { * for all attempts. */ function quiz_get_combined_reviewoptions($quiz, $attempts) { - $fields = array('feedback', 'generalfeedback', 'rightanswer', 'overallfeedback'); + $fields = ['feedback', 'generalfeedback', 'rightanswer', 'overallfeedback']; $someoptions = new stdClass(); $alloptions = new stdClass(); foreach ($fields as $field) { @@ -1589,7 +1588,7 @@ function quiz_get_combined_reviewoptions($quiz, $attempts) { // This shouldn't happen, but we need to prevent reveal information. if (empty($attempts)) { - return array($someoptions, $someoptions); + return [$someoptions, $someoptions]; } foreach ($attempts as $attempt) { @@ -1602,7 +1601,7 @@ function quiz_get_combined_reviewoptions($quiz, $attempts) { $someoptions->marks = max($someoptions->marks, $attemptoptions->marks); $alloptions->marks = min($alloptions->marks, $attemptoptions->marks); } - return array($someoptions, $alloptions); + return [$someoptions, $alloptions]; } // Functions for sending notification messages ///////////////////////////////// @@ -1610,7 +1609,8 @@ function quiz_get_combined_reviewoptions($quiz, $attempts) { /** * Sends a confirmation message to the student confirming that the attempt was processed. * - * @param object $a lots of useful information that can be used in the message + * @param stdClass $recipient user object for the recipient. + * @param stdClass $a lots of useful information that can be used in the message * subject and body. * @param bool $studentisonline is the student currently interacting with Moodle? * @@ -1659,8 +1659,9 @@ function quiz_send_confirmation($recipient, $a, $studentisonline) { /** * Sends notification messages to the interested parties that assign the role capability * - * @param object $recipient user object of the intended recipient - * @param object $a associative array of replaceable fields for the templates + * @param stdClass $recipient user object of the intended recipient + * @param stdClass $submitter user object for the user who submitted the attempt. + * @param stdClass $a associative array of replaceable fields for the templates * * @return int|false as for {@link message_send()}. */ @@ -1706,11 +1707,11 @@ function quiz_send_notification($recipient, $submitter, $a) { /** * Send all the requried messages when a quiz attempt is submitted. * - * @param object $course the course - * @param object $quiz the quiz - * @param object $attempt this attempt just finished - * @param object $context the quiz context - * @param object $cm the coursemodule for this quiz + * @param stdClass $course the course + * @param stdClass $quiz the quiz + * @param stdClass $attempt this attempt just finished + * @param stdClass $context the quiz context + * @param stdClass $cm the coursemodule for this quiz * @param bool $studentisonline is the student currently interacting with Moodle? * * @return bool true if all necessary messages were sent successfully, else false. @@ -1723,7 +1724,7 @@ function quiz_send_notification_messages($course, $quiz, $attempt, $context, $cm throw new coding_exception('$course, $quiz, $attempt, $context and $cm must all be set.'); } - $submitter = $DB->get_record('user', array('id' => $attempt->userid), '*', MUST_EXIST); + $submitter = $DB->get_record('user', ['id' => $attempt->userid], '*', MUST_EXIST); // Check for confirmation required. $sendconfirm = false; @@ -1810,7 +1811,7 @@ function quiz_send_notification_messages($course, $quiz, $attempt, $context, $cm function quiz_send_overdue_message($attemptobj) { global $CFG, $DB; - $submitter = $DB->get_record('user', array('id' => $attemptobj->get_userid()), '*', MUST_EXIST); + $submitter = $DB->get_record('user', ['id' => $attemptobj->get_userid()], '*', MUST_EXIST); if (!$attemptobj->has_capability('mod/quiz:emailwarnoverdue', $submitter->id, false)) { return; // Message not required. @@ -1824,7 +1825,7 @@ function quiz_send_overdue_message($attemptobj) { // the email message. $quizname = format_string($attemptobj->get_quiz_name()); - $deadlines = array(); + $deadlines = []; if ($attemptobj->get_quiz()->timelimit) { $deadlines[] = $attemptobj->get_attempt()->timestart + $attemptobj->get_quiz()->timelimit; } @@ -1885,12 +1886,12 @@ function quiz_send_overdue_message($attemptobj) { * * This sends the confirmation and notification messages, if required. * - * @param object $event the event object. + * @param stdClass $event the event object. */ function quiz_attempt_submitted_handler($event) { global $DB; - $course = $DB->get_record('course', array('id' => $event->courseid)); + $course = $DB->get_record('course', ['id' => $event->courseid]); $attempt = $event->get_record_snapshot('quiz_attempts', $event->objectid); $quiz = $event->get_record_snapshot('quiz', $attempt->quiz); $cm = get_coursemodule_from_id('quiz', $event->get_context()->instanceid, $event->courseid); @@ -1916,7 +1917,7 @@ function quiz_attempt_submitted_handler($event) { * Send the notification message when a quiz attempt has been manual graded. * * @param quiz_attempt $attemptobj Some data about the quiz attempt. - * @param object $userto + * @param stdClass $userto * @return int|false As for message_send. */ function quiz_send_notify_manual_graded_message(quiz_attempt $attemptobj, object $userto): ?int { @@ -1976,7 +1977,7 @@ function quiz_process_group_deleted_in_course($courseid) { WHERE quiz.course = :courseid AND o.groupid IS NOT NULL AND grp.id IS NULL"; - $params = array('courseid' => $courseid); + $params = ['courseid' => $courseid]; $records = $DB->get_records_sql($sql, $params); if (!$records) { return; // Nothing to do. @@ -1996,26 +1997,26 @@ function quiz_process_group_deleted_in_course($courseid) { function quiz_get_js_module() { global $PAGE; - return array( + return [ 'name' => 'mod_quiz', 'fullpath' => '/mod/quiz/module.js', - 'requires' => array('base', 'dom', 'event-delegate', 'event-key', - 'core_question_engine'), - 'strings' => array( - array('cancel', 'moodle'), - array('flagged', 'question'), - array('functiondisabledbysecuremode', 'quiz'), - array('startattempt', 'quiz'), - array('timesup', 'quiz'), - ), - ); + 'requires' => ['base', 'dom', 'event-delegate', 'event-key', + 'core_question_engine'], + 'strings' => [ + ['cancel', 'moodle'], + ['flagged', 'question'], + ['functiondisabledbysecuremode', 'quiz'], + ['startattempt', 'quiz'], + ['timesup', 'quiz'], + ], + ]; } /** * Creates a textual representation of a question for display. * - * @param object $question A question object from the database questions table + * @param stdClass $question A question object from the database questions table * @param bool $showicon If true, show the question's icon with the question. False by default. * @param bool $showquestiontext If true (default), show question text after question name. * If false, show only question name. @@ -2058,7 +2059,7 @@ function quiz_question_tostring($question, $showicon = false, $showquestiontext // Question text. if ($showquestiontext) { $questiontext = question_utils::to_plain_text($question->questiontext, - $question->questiontextformat, array('noclean' => true, 'para' => false)); + $question->questiontextformat, ['noclean' => true, 'para' => false]); $questiontext = shorten_text($questiontext, 50); if ($questiontext) { $result .= ' ' . html_writer::span(s($questiontext), 'questiontext'); @@ -2075,7 +2076,7 @@ function quiz_question_tostring($question, $showicon = false, $showquestiontext */ function quiz_require_question_use($questionid) { global $DB; - $question = $DB->get_record('question', array('id' => $questionid), '*', MUST_EXIST); + $question = $DB->get_record('question', ['id' => $questionid], '*', MUST_EXIST); question_require_capability_on($question, 'use'); } @@ -2085,7 +2086,7 @@ function quiz_require_question_use($questionid) { * Adds a question to a quiz by updating $quiz as well as the * quiz and quiz_slots tables. It also adds a page break if required. * @param int $questionid The id of the question to be added - * @param object $quiz The extended quiz object as used by edit.php + * @param stdClass $quiz The extended quiz object as used by edit.php * This is updated by this function * @param int $page Which page in quiz to add the question on. If 0 (default), * add at the end @@ -2102,7 +2103,7 @@ function quiz_add_quiz_question($questionid, $quiz, $page = 0, $maxmark = null) } // Make sue the question is not of the "random" type. - $questiontype = $DB->get_field('question', 'qtype', array('id' => $questionid)); + $questiontype = $DB->get_field('question', 'qtype', ['id' => $questionid]); if ($questiontype == 'random') { throw new coding_exception( 'Adding "random" questions via quiz_add_quiz_question() is deprecated. Please use quiz_add_random_questions().' @@ -2153,7 +2154,7 @@ function quiz_add_quiz_question($questionid, $quiz, $page = 0, $maxmark = null) if ($maxmark !== null) { $slot->maxmark = $maxmark; } else { - $slot->maxmark = $DB->get_field('question', 'defaultmark', array('id' => $questionid)); + $slot->maxmark = $DB->get_field('question', 'defaultmark', ['id' => $questionid]); } if (is_int($page) && $page >= 1) { @@ -2161,7 +2162,7 @@ function quiz_add_quiz_question($questionid, $quiz, $page = 0, $maxmark = null) $lastslotbefore = 0; foreach (array_reverse($slots) as $otherslot) { if ($otherslot->page > $page) { - $DB->set_field('quiz_slots', 'slot', $otherslot->slot + 1, array('id' => $otherslot->id)); + $DB->set_field('quiz_slots', 'slot', $otherslot->slot + 1, ['id' => $otherslot->id]); } else { $lastslotbefore = $otherslot->slot; break; @@ -2333,10 +2334,10 @@ function quiz_add_random_questions($quiz, $addonpage, $categoryid, $number, */ function quiz_view($quiz, $course, $cm, $context) { - $params = array( + $params = [ 'objectid' => $quiz->id, 'context' => $context - ); + ]; $event = \mod_quiz\event\course_module_viewed::create($params); $event->add_record_snapshot('quiz', $quiz); @@ -2376,7 +2377,7 @@ function quiz_validate_new_attempt(quiz_settings $quizobj, access_manager $acces // To force the creation of a new preview, we mark the current attempt (if any) // as abandoned. It will then automatically be deleted below. $DB->set_field('quiz_attempts', 'state', quiz_attempt::ABANDONED, - array('quiz' => $quizobj->get_quizid(), 'userid' => $USER->id)); + ['quiz' => $quizobj->get_quizid(), 'userid' => $USER->id]); } // Look for an existing attempt. @@ -2428,7 +2429,7 @@ function quiz_validate_new_attempt(quiz_settings $quizobj, access_manager $acces $page = 0; } } - return array($currentattemptid, $attemptnumber, $lastattempt, $messages, $page); + return [$currentattemptid, $attemptnumber, $lastattempt, $messages, $page]; } /** @@ -2436,14 +2437,14 @@ function quiz_validate_new_attempt(quiz_settings $quizobj, access_manager $acces * * @param quiz_settings $quizobj quiz object * @param int $attemptnumber the attempt number - * @param object $lastattempt last attempt object + * @param stdClass $lastattempt last attempt object * @param bool $offlineattempt whether is an offline attempt or not * @param array $forcedrandomquestions slot number => question id. Used for random questions, * to force the choice of a particular actual question. Intended for testing purposes only. * @param array $forcedvariants slot number => variant. Used for questions with variants, * to force the choice of a particular variant. Intended for testing purposes only. * @param int $userid Specific user id to create an attempt for that user, null for current logged in user - * @return object the new attempt + * @return stdClass the new attempt * @since Moodle 3.1 */ function quiz_prepare_and_start_new_attempt(quiz_settings $quizobj, $attemptnumber, $lastattempt, @@ -2538,7 +2539,7 @@ function quiz_create_attempt_handling_errors($attemptid, $cmid = null) { } catch (moodle_exception $e) { if (!empty($cmid)) { list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'quiz'); - $continuelink = new moodle_url('/mod/quiz/view.php', array('id' => $cmid)); + $continuelink = new moodle_url('/mod/quiz/view.php', ['id' => $cmid]); $context = context_module::instance($cm->id); if (has_capability('mod/quiz:preview', $context)) { throw new moodle_exception('attempterrorcontentchange', 'quiz', $continuelink); diff --git a/mod/quiz/mod_form.php b/mod/quiz/mod_form.php index a9fec29231b..44cff553ebd 100644 --- a/mod/quiz/mod_form.php +++ b/mod/quiz/mod_form.php @@ -39,29 +39,32 @@ use mod_quiz\question\display_options; */ class mod_quiz_mod_form extends moodleform_mod { /** @var array options to be used with date_time_selector fields in the quiz. */ - public static $datefieldoptions = array('optional' => true); + public static $datefieldoptions = ['optional' => true]; + /** @var array caches the quiz overall feedback, for convenience. */ protected $_feedbacks; - protected static $reviewfields = array(); // Initialised in the constructor. + + /** @var array for convenience stores the list of types of review option. Initialised in the constructor. */ + protected static $reviewfields = []; /** @var int the max number of attempts allowed in any user or group override on this quiz. */ protected $maxattemptsanyoverride = null; public function __construct($current, $section, $cm, $course) { - self::$reviewfields = array( - 'attempt' => array('theattempt', 'quiz'), - 'correctness' => array('whethercorrect', 'question'), - 'marks' => array('marks', 'quiz'), - 'specificfeedback' => array('specificfeedback', 'question'), - 'generalfeedback' => array('generalfeedback', 'question'), - 'rightanswer' => array('rightanswer', 'question'), - 'overallfeedback' => array('reviewoverallfeedback', 'quiz'), - ); + self::$reviewfields = [ + 'attempt' => ['theattempt', 'quiz'], + 'correctness' => ['whethercorrect', 'question'], + 'marks' => ['marks', 'quiz'], + 'specificfeedback' => ['specificfeedback', 'question'], + 'generalfeedback' => ['generalfeedback', 'question'], + 'rightanswer' => ['rightanswer', 'question'], + 'overallfeedback' => ['reviewoverallfeedback', 'quiz'], + ]; parent::__construct($current, $section, $cm, $course); } protected function definition() { - global $COURSE, $CFG, $DB, $PAGE; + global $CFG, $DB, $PAGE; $quizconfig = get_config('quiz'); $mform = $this->_form; @@ -69,7 +72,7 @@ class mod_quiz_mod_form extends moodleform_mod { $mform->addElement('header', 'general', get_string('general', 'form')); // Name. - $mform->addElement('text', 'name', get_string('name'), array('size'=>'64')); + $mform->addElement('text', 'name', get_string('name'), ['size' => '64']); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { @@ -94,7 +97,7 @@ class mod_quiz_mod_form extends moodleform_mod { // Time limit. $mform->addElement('duration', 'timelimit', get_string('timelimit', 'quiz'), - array('optional' => true)); + ['optional' => true]); $mform->addHelpButton('timelimit', 'timelimit', 'quiz'); // What to do with overdue attempts. @@ -107,7 +110,7 @@ class mod_quiz_mod_form extends moodleform_mod { // Grace period time. $mform->addElement('duration', 'graceperiod', get_string('graceperiod', 'quiz'), - array('optional' => true)); + ['optional' => true]); $mform->addHelpButton('graceperiod', 'graceperiod', 'quiz'); $mform->hideIf('graceperiod', 'overduehandling', 'neq', 'graceperiod'); @@ -125,7 +128,7 @@ class mod_quiz_mod_form extends moodleform_mod { $mform->setType('grade', PARAM_FLOAT); // Number of attempts. - $attemptoptions = array('0' => get_string('unlimited')); + $attemptoptions = ['0' => get_string('unlimited')]; for ($i = 1; $i <= QUIZ_MAX_ATTEMPT_OPTION; $i++) { $attemptoptions[$i] = $i; } @@ -143,14 +146,14 @@ class mod_quiz_mod_form extends moodleform_mod { // ------------------------------------------------------------------------------- $mform->addElement('header', 'layouthdr', get_string('layout', 'quiz')); - $pagegroup = array(); + $pagegroup = []; $pagegroup[] = $mform->createElement('select', 'questionsperpage', - get_string('newpage', 'quiz'), quiz_questions_per_page_options(), array('id' => 'id_questionsperpage')); + get_string('newpage', 'quiz'), quiz_questions_per_page_options(), ['id' => 'id_questionsperpage']); $mform->setDefault('questionsperpage', $quizconfig->questionsperpage); if (!empty($this->_cm) && !quiz_has_attempts($this->_cm->instance)) { $pagegroup[] = $mform->createElement('checkbox', 'repaginatenow', '', - get_string('repaginatenow', 'quiz'), array('id' => 'id_repaginatenow')); + get_string('repaginatenow', 'quiz'), ['id' => 'id_repaginatenow']); } $mform->addGroup($pagegroup, 'questionsperpagegrp', @@ -182,7 +185,7 @@ class mod_quiz_mod_form extends moodleform_mod { $mform->addHelpButton('preferredbehaviour', 'howquestionsbehave', 'question'); // Can redo completed questions. - $redochoices = array(0 => get_string('no'), 1 => get_string('canredoquestionsyes', 'quiz')); + $redochoices = [0 => get_string('no'), 1 => get_string('canredoquestionsyes', 'quiz')]; $mform->addElement('select', 'canredoquestions', get_string('canredoquestions', 'quiz'), $redochoices); $mform->addHelpButton('canredoquestions', 'canredoquestions', 'quiz'); foreach ($behaviours as $behaviour => $notused) { @@ -238,7 +241,7 @@ class mod_quiz_mod_form extends moodleform_mod { $mform->addHelpButton('showuserpicture', 'showuserpicture', 'quiz'); // Overall decimal points. - $options = array(); + $options = []; for ($i = 0; $i <= QUIZ_MAX_DECIMAL_OPTION; $i++) { $options[$i] = $i; } @@ -247,7 +250,7 @@ class mod_quiz_mod_form extends moodleform_mod { $mform->addHelpButton('decimalpoints', 'decimalplaces', 'quiz'); // Question decimal points. - $options = array(-1 => get_string('sameasoverall', 'quiz')); + $options = [-1 => get_string('sameasoverall', 'quiz')]; for ($i = 0; $i <= QUIZ_MAX_Q_DECIMAL_OPTION; $i++) { $options[$i] = $i; } @@ -274,14 +277,14 @@ class mod_quiz_mod_form extends moodleform_mod { // Enforced time delay between quiz attempts. $mform->addElement('duration', 'delay1', get_string('delay1st2nd', 'quiz'), - array('optional' => true)); + ['optional' => true]); $mform->addHelpButton('delay1', 'delay1st2nd', 'quiz'); if ($this->get_max_attempts_for_any_override() < 2) { $mform->hideIf('delay1', 'attempts', 'eq', 1); } $mform->addElement('duration', 'delay2', get_string('delaylater', 'quiz'), - array('optional' => true)); + ['optional' => true]); $mform->addHelpButton('delay2', 'delaylater', 'quiz'); if ($this->get_max_attempts_for_any_override() < 3) { $mform->hideIf('delay2', 'attempts', 'eq', 1); @@ -313,22 +316,22 @@ class mod_quiz_mod_form extends moodleform_mod { $mform->addElement('static', 'gradeboundarystatic1', get_string('gradeboundary', 'quiz'), '100%'); - $repeatarray = array(); - $repeatedoptions = array(); + $repeatarray = []; + $repeatedoptions = []; $repeatarray[] = $mform->createElement('editor', 'feedbacktext', - get_string('feedback', 'quiz'), array('rows' => 3), array('maxfiles' => EDITOR_UNLIMITED_FILES, - 'noclean' => true, 'context' => $this->context)); + get_string('feedback', 'quiz'), ['rows' => 3], ['maxfiles' => EDITOR_UNLIMITED_FILES, + 'noclean' => true, 'context' => $this->context]); $repeatarray[] = $mform->createElement('text', 'feedbackboundaries', - get_string('gradeboundary', 'quiz'), array('size' => 10)); + get_string('gradeboundary', 'quiz'), ['size' => 10]); $repeatedoptions['feedbacktext']['type'] = PARAM_RAW; $repeatedoptions['feedbackboundaries']['type'] = PARAM_RAW; if (!empty($this->_instance)) { $this->_feedbacks = $DB->get_records('quiz_feedback', - array('quizid' => $this->_instance), 'mingrade DESC'); + ['quizid' => $this->_instance], 'mingrade DESC'); $numfeedbacks = count($this->_feedbacks); } else { - $this->_feedbacks = array(); + $this->_feedbacks = []; $numfeedbacks = $quizconfig->initialnumfeedbacks; } $numfeedbacks = max($numfeedbacks, 1); @@ -339,9 +342,9 @@ class mod_quiz_mod_form extends moodleform_mod { // Put some extra elements in before the button. $mform->insertElementBefore($mform->createElement('editor', - "feedbacktext[$nextel]", get_string('feedback', 'quiz'), array('rows' => 3), - array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, - 'context' => $this->context)), + "feedbacktext[$nextel]", get_string('feedback', 'quiz'), ['rows' => 3], + ['maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, + 'context' => $this->context]), 'boundary_add_fields'); $mform->insertElementBefore($mform->createElement('static', 'gradeboundarystatic2', get_string('gradeboundary', 'quiz'), '0%'), @@ -375,7 +378,7 @@ class mod_quiz_mod_form extends moodleform_mod { $when, $withhelp = false) { global $OUTPUT; - $group = array(); + $group = []; foreach (self::$reviewfields as $field => $string) { list($identifier, $component) = $string; @@ -602,20 +605,20 @@ class mod_quiz_mod_form extends moodleform_mod { */ public function add_completion_rules() { $mform = $this->_form; - $items = array(); + $items = []; $mform->addElement('advcheckbox', 'completionattemptsexhausted', null, get_string('completionattemptsexhausted', 'quiz'), - array('group' => 'cattempts')); + ['group' => 'cattempts']); $mform->disabledIf('completionattemptsexhausted', 'completionpassgrade', 'notchecked'); $items[] = 'completionattemptsexhausted'; - $group = array(); + $group = []; $group[] = $mform->createElement('checkbox', 'completionminattemptsenabled', '', get_string('completionminattempts', 'quiz')); - $group[] = $mform->createElement('text', 'completionminattempts', '', array('size' => 3)); + $group[] = $mform->createElement('text', 'completionminattempts', '', ['size' => 3]); $mform->setType('completionminattempts', PARAM_INT); - $mform->addGroup($group, 'completionminattemptsgroup', get_string('completionminattemptsgroup', 'quiz'), array(' '), false); + $mform->addGroup($group, 'completionminattemptsgroup', get_string('completionminattemptsgroup', 'quiz'), [' '], false); $mform->disabledIf('completionminattempts', 'completionminattemptsenabled', 'notchecked'); $items[] = 'completionminattemptsgroup'; @@ -653,7 +656,7 @@ class mod_quiz_mod_form extends moodleform_mod { SELECT MAX(CASE WHEN attempts = 0 THEN 1000 ELSE attempts END) FROM {quiz_overrides} WHERE quiz = ?", - array($this->_instance)); + [$this->_instance]); if ($this->maxattemptsanyoverride < 1) { // This happens when no override alters the number of attempts. $this->maxattemptsanyoverride = 1; diff --git a/mod/quiz/overridedelete.php b/mod/quiz/overridedelete.php index fab6698ac3d..4b68d50f3fb 100644 --- a/mod/quiz/overridedelete.php +++ b/mod/quiz/overridedelete.php @@ -31,16 +31,16 @@ require_once($CFG->dirroot.'/mod/quiz/locallib.php'); $overrideid = required_param('id', PARAM_INT); $confirm = optional_param('confirm', false, PARAM_BOOL); -if (! $override = $DB->get_record('quiz_overrides', array('id' => $overrideid))) { +if (! $override = $DB->get_record('quiz_overrides', ['id' => $overrideid])) { throw new \moodle_exception('invalidoverrideid', 'quiz'); } -if (! $quiz = $DB->get_record('quiz', array('id' => $override->quiz))) { +if (! $quiz = $DB->get_record('quiz', ['id' => $override->quiz])) { throw new \moodle_exception('invalidcoursemodule'); } if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $quiz->course)) { throw new \moodle_exception('invalidcoursemodule'); } -$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); $context = context_module::instance($cm->id); @@ -59,9 +59,9 @@ if ($override->groupid) { } } -$url = new moodle_url('/mod/quiz/overridedelete.php', array('id'=>$override->id)); -$confirmurl = new moodle_url($url, array('id'=>$override->id, 'confirm'=>1)); -$cancelurl = new moodle_url('/mod/quiz/overrides.php', array('cmid'=>$cm->id)); +$url = new moodle_url('/mod/quiz/overridedelete.php', ['id' => $override->id]); +$confirmurl = new moodle_url($url, ['id' => $override->id, 'confirm' => 1]); +$cancelurl = new moodle_url('/mod/quiz/overrides.php', ['cmid' => $cm->id]); if (!empty($override->userid)) { $cancelurl->param('mode', 'user'); diff --git a/mod/quiz/overrideedit.php b/mod/quiz/overrideedit.php index d8e419d8bdc..ef3b4082a31 100644 --- a/mod/quiz/overrideedit.php +++ b/mod/quiz/overrideedit.php @@ -36,22 +36,22 @@ $reset = optional_param('reset', false, PARAM_BOOL); $override = null; if ($overrideid) { - if (! $override = $DB->get_record('quiz_overrides', array('id' => $overrideid))) { + if (! $override = $DB->get_record('quiz_overrides', ['id' => $overrideid])) { throw new \moodle_exception('invalidoverrideid', 'quiz'); } - if (! $quiz = $DB->get_record('quiz', array('id' => $override->quiz))) { + if (! $quiz = $DB->get_record('quiz', ['id' => $override->quiz])) { throw new \moodle_exception('invalidcoursemodule'); } list($course, $cm) = get_course_and_cm_from_instance($quiz, 'quiz'); } else if ($cmid) { list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'quiz'); - $quiz = $DB->get_record('quiz', array('id' => $cm->instance), '*', MUST_EXIST); + $quiz = $DB->get_record('quiz', ['id' => $cm->instance], '*', MUST_EXIST); } else { throw new \moodle_exception('invalidcoursemodule'); } -$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); $url = new moodle_url('/mod/quiz/overrideedit.php'); if ($action) { @@ -94,7 +94,7 @@ if ($overrideid) { } // Merge quiz defaults with data. -$keys = array('timeopen', 'timeclose', 'timelimit', 'attempts', 'password'); +$keys = ['timeopen', 'timeclose', 'timelimit', 'attempts', 'password']; foreach ($keys as $key) { if (!isset($data->{$key}) || $reset) { $data->{$key} = $quiz->{$key}; @@ -112,7 +112,7 @@ if ($action === 'duplicate') { // True if group-based override. $groupmode = !empty($data->groupid) || ($action === 'addgroup' && empty($overrideid)); -$overridelisturl = new moodle_url('/mod/quiz/overrides.php', array('cmid'=>$cm->id)); +$overridelisturl = new moodle_url('/mod/quiz/overrides.php', ['cmid' => $cm->id]); if (!$groupmode) { $overridelisturl->param('mode', 'user'); } @@ -150,10 +150,10 @@ if ($mform->is_cancelled()) { } if ($userorgroupchanged) { - $conditions = array( + $conditions = [ 'quiz' => $quiz->id, - 'userid' => empty($fromform->userid)? null : $fromform->userid, - 'groupid' => empty($fromform->groupid)? null : $fromform->groupid); + 'userid' => empty($fromform->userid) ? null : $fromform->userid, + 'groupid' => empty($fromform->groupid) ? null : $fromform->groupid]; if ($oldoverride = $DB->get_record('quiz_overrides', $conditions)) { // There is an old override, so we merge any new settings on top of // the older override. @@ -169,12 +169,12 @@ if ($mform->is_cancelled()) { } // Set the common parameters for one of the events we may be triggering. - $params = array( + $params = [ 'context' => $context, - 'other' => array( + 'other' => [ 'quizid' => $quiz->id - ) - ); + ] + ]; if (!empty($override->id)) { $fromform->id = $override->id; $DB->update_record('quiz_overrides', $fromform); @@ -213,7 +213,7 @@ if ($mform->is_cancelled()) { $event->trigger(); } - quiz_update_open_attempts(array('quizid'=>$quiz->id)); + quiz_update_open_attempts(['quizid' => $quiz->id]); if ($groupmode) { // Priorities may have shifted, so we need to update all of the calendar events for group overrides. quiz_update_events($quiz); @@ -242,7 +242,7 @@ $PAGE->add_body_class('limitedwidth'); $PAGE->set_title($pagetitle); $PAGE->set_heading($course->fullname); $PAGE->activityheader->set_attrs([ - "title" => format_string($quiz->name, true, array('context' => $context)), + "title" => format_string($quiz->name, true, ['context' => $context]), "description" => "", "hidecompletion" => true ]); diff --git a/mod/quiz/repaginate.php b/mod/quiz/repaginate.php index 4ccb37da705..8df50f696be 100644 --- a/mod/quiz/repaginate.php +++ b/mod/quiz/repaginate.php @@ -39,7 +39,7 @@ if (quiz_has_attempts($quizid)) { $reportlink = quiz_attempt_summary_link_to_reports($quizobj->get_quiz(), $quizobj->get_cm(), $quizobj->get_context()); throw new \moodle_exception('cannoteditafterattempts', 'quiz', - new moodle_url('/mod/quiz/edit.php', array('cmid' => $quizobj->get_cmid())), $reportlink); + new moodle_url('/mod/quiz/edit.php', ['cmid' => $quizobj->get_cmid()]), $reportlink); } $slotnumber++; @@ -49,4 +49,4 @@ $repage->repaginate_slots($slotnumber, $repagtype); $structure = $quizobj->get_structure(); $slots = $structure->refresh_page_numbers_and_update_db(); -redirect(new moodle_url('edit.php', array('cmid' => $quizobj->get_cmid()))); +redirect(new moodle_url('edit.php', ['cmid' => $quizobj->get_cmid()])); diff --git a/mod/quiz/report.php b/mod/quiz/report.php index bb0eb8a5aee..15168bfb3cb 100644 --- a/mod/quiz/report.php +++ b/mod/quiz/report.php @@ -36,18 +36,18 @@ if ($id) { if (!$cm = get_coursemodule_from_id('quiz', $id)) { throw new \moodle_exception('invalidcoursemodule'); } - if (!$course = $DB->get_record('course', array('id' => $cm->course))) { + if (!$course = $DB->get_record('course', ['id' => $cm->course])) { throw new \moodle_exception('coursemisconf'); } - if (!$quiz = $DB->get_record('quiz', array('id' => $cm->instance))) { + if (!$quiz = $DB->get_record('quiz', ['id' => $cm->instance])) { throw new \moodle_exception('invalidcoursemodule'); } } else { - if (!$quiz = $DB->get_record('quiz', array('id' => $q))) { + if (!$quiz = $DB->get_record('quiz', ['id' => $q])) { throw new \moodle_exception('invalidquizid', 'quiz'); } - if (!$course = $DB->get_record('course', array('id' => $quiz->course))) { + if (!$course = $DB->get_record('course', ['id' => $quiz->course])) { throw new \moodle_exception('invalidcourseid'); } if (!$cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) { @@ -55,7 +55,7 @@ if ($id) { } } -$url = new moodle_url('/mod/quiz/report.php', array('id' => $cm->id)); +$url = new moodle_url('/mod/quiz/report.php', ['id' => $cm->id]); if ($mode !== '') { $url->param('mode', $mode); } @@ -99,13 +99,13 @@ $report->display($quiz, $cm, $course); echo $OUTPUT->footer(); // Log that this report was viewed. -$params = array( +$params = [ 'context' => $context, - 'other' => array( + 'other' => [ 'quizid' => $quiz->id, 'reportname' => $mode - ) -); + ] +]; $event = \mod_quiz\event\report_viewed::create($params); $event->add_record_snapshot('course', $course); $event->add_record_snapshot('quiz', $quiz); diff --git a/mod/quiz/report/grading/db/access.php b/mod/quiz/report/grading/db/access.php index 9f50665e6a2..5eabb04a949 100644 --- a/mod/quiz/report/grading/db/access.php +++ b/mod/quiz/report/grading/db/access.php @@ -24,28 +24,28 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( +$capabilities = [ // Is the user allowed to see the student's real names while grading? - 'quiz/grading:viewstudentnames' => array( + 'quiz/grading:viewstudentnames' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( + 'legacy' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ), + ], 'clonepermissionsfrom' => 'mod/quiz:viewreports' - ), + ], // Is the user allowed to see the student's identity fields while grading? // Note that the name of this capability is now out-of-date, but to preserve // backwards compatibility, the name was not changed when the functionality was updated. - 'quiz/grading:viewidnumber' => array( + 'quiz/grading:viewidnumber' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( + 'legacy' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW - ), + ], 'clonepermissionsfrom' => 'mod/quiz:viewreports' - ) -); + ] +]; diff --git a/mod/quiz/report/grading/gradingsettings_form.php b/mod/quiz/report/grading/gradingsettings_form.php index f4b8a8afe24..49189ac30f7 100644 --- a/mod/quiz/report/grading/gradingsettings_form.php +++ b/mod/quiz/report/grading/gradingsettings_form.php @@ -35,9 +35,16 @@ require_once($CFG->libdir . '/formslib.php'); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class quiz_grading_settings_form extends moodleform { + /** @var bool whether the user has asked to include automatically graded attempts. */ protected $includeauto; - protected $hidden = array(); + + /** @var array extra hidden fields to add to the form. Things like cm id. */ + protected $hidden = []; + + /** @var stdClass data about how many attempts of each type their are. */ protected $counts; + + /** @var bool Whether the user has permission to see user names. */ protected $shownames; /** @var bool $showcustomfields whether custom field values should be shown. */ @@ -71,8 +78,8 @@ class quiz_grading_settings_form extends moodleform { $mform->addElement('header', 'options', get_string('options', 'quiz_grading')); - $gradeoptions = array(); - foreach (array('needsgrading', 'manuallygraded', 'autograded', 'all') as $type) { + $gradeoptions = []; + foreach (['needsgrading', 'manuallygraded', 'autograded', 'all'] as $type) { if (empty($this->counts->$type)) { continue; } @@ -86,7 +93,7 @@ class quiz_grading_settings_form extends moodleform { $gradeoptions); $mform->addElement('text', 'pagesize', get_string('questionsperpage', 'quiz_grading'), - array('size' => 3)); + ['size' => 3]); $mform->addRule('pagesize', null, 'positiveint', null, 'client'); $mform->setType('pagesize', PARAM_INT); diff --git a/mod/quiz/report/grading/renderer.php b/mod/quiz/report/grading/renderer.php index 624c0a35f05..584dcc7ca6b 100644 --- a/mod/quiz/report/grading/renderer.php +++ b/mod/quiz/report/grading/renderer.php @@ -35,9 +35,9 @@ class quiz_grading_renderer extends plugin_renderer_base { /** * Render no question notification. * - * @param object $quiz The quiz settings. - * @param object $cm The course-module for this quiz. - * @param object $context The quiz context. + * @param stdClass $quiz The quiz settings. + * @param stdClass $cm The course-module for this quiz. + * @param stdClass $context The quiz context. * @return string The HTML for the no questions message. */ public function render_quiz_no_question_notification($quiz, $cm, $context) { @@ -99,7 +99,7 @@ class quiz_grading_renderer extends plugin_renderer_base { /** * Render grade link for question. * - * @param object $counts + * @param stdClass $counts * @param string $type Type of grade. * @param string $gradestring Lang string. * @param moodle_url $gradequestionurl Url to grade question. @@ -120,11 +120,11 @@ class quiz_grading_renderer extends plugin_renderer_base { /** * Render grading page. * - * @param object $questioninfo Information of a question. + * @param stdClass $questioninfo Information of a question. * @param moodle_url $listquestionsurl Url of the page that list all questions. * @param quiz_grading_settings_form $filterform Question filter form. - * @param object $paginginfo Pagination information. - * @param object $pagingbar Pagination bar information. + * @param stdClass $paginginfo Pagination information. + * @param stdClass $pagingbar Pagination bar information. * @param moodle_url $formaction Form submit url. * @param array $hiddeninputs List of hidden input fields. * @param string $gradequestioncontent HTML string of question content. diff --git a/mod/quiz/report/grading/report.php b/mod/quiz/report/grading/report.php index 9192a8179e5..e70ab423ef4 100644 --- a/mod/quiz/report/grading/report.php +++ b/mod/quiz/report/grading/report.php @@ -80,7 +80,7 @@ class quiz_grading_report extends report_base { $grade = optional_param('grade', null, PARAM_ALPHA); $includeauto = optional_param('includeauto', false, PARAM_BOOL); - if (!in_array($grade, array('all', 'needsgrading', 'autograded', 'manuallygraded'))) { + if (!in_array($grade, ['all', 'needsgrading', 'autograded', 'manuallygraded'])) { $grade = null; } $pagesize = optional_param('pagesize', @@ -92,7 +92,7 @@ class quiz_grading_report extends report_base { PARAM_ALPHAEXT); // Assemble the options required to reload this page. - $optparams = array('includeauto', 'page'); + $optparams = ['includeauto', 'page']; foreach ($optparams as $param) { if ($$param) { $this->viewoptions[$param] = $$param; @@ -149,10 +149,10 @@ class quiz_grading_report extends report_base { // Get the group, and the list of significant users. $this->currentgroup = $this->get_current_group($cm, $course, $this->context); if ($this->currentgroup == self::NO_GROUPS_ALLOWED) { - $this->userssql = array(); + $this->userssql = []; } else { $this->userssql = get_enrolled_sql($this->context, - array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), $this->currentgroup); + ['mod/quiz:reviewmyattempts', 'mod/quiz:attempt'], $this->currentgroup); } $hasquestions = quiz_has_questions($this->quiz->id); @@ -199,15 +199,15 @@ class quiz_grading_report extends report_base { $where = "quiza.quiz = :mangrquizid AND quiza.preview = 0 AND quiza.state = :statefinished"; - $params = array('mangrquizid' => $this->cm->instance, 'statefinished' => quiz_attempt::FINISHED); + $params = ['mangrquizid' => $this->cm->instance, 'statefinished' => quiz_attempt::FINISHED]; $usersjoin = ''; $currentgroup = groups_get_activity_group($this->cm, true); $enrolleduserscount = count_enrolled_users($this->context, - array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), $currentgroup); + ['mod/quiz:reviewmyattempts', 'mod/quiz:attempt'], $currentgroup); if ($currentgroup) { $userssql = get_enrolled_sql($this->context, - array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), $currentgroup); + ['mod/quiz:reviewmyattempts', 'mod/quiz:attempt'], $currentgroup); if ($enrolleduserscount < 1) { $where .= ' AND quiza.userid = 0'; } else { @@ -248,7 +248,7 @@ class quiz_grading_report extends report_base { WHERE quiza.uniqueid $asql AND quiza.state = ? AND quiza.quiz = ?", $params); - $attempts = array(); + $attempts = []; foreach ($attemptsbyid as $attempt) { $attempts[$attempt->uniqueid] = $attempt; } @@ -672,9 +672,9 @@ class quiz_grading_report extends report_base { /** * Initialise some parts of $PAGE and start output. * - * @param object $cm the course_module information. - * @param object $course the course settings. - * @param object $quiz the quiz settings. + * @param stdClass $cm the course_module information. + * @param stdClass $course the course settings. + * @param stdClass $quiz the quiz settings. * @param string $reportmode the report name. */ public function print_header_and_tabs($cm, $course, $quiz, $reportmode = 'overview') { diff --git a/mod/quiz/report/overview/overview_options.php b/mod/quiz/report/overview/overview_options.php index 8a3a16bd650..67d9590cbca 100644 --- a/mod/quiz/report/overview/overview_options.php +++ b/mod/quiz/report/overview/overview_options.php @@ -88,7 +88,7 @@ class quiz_overview_options extends attempts_report_options { // We only want to show the checkbox to delete attempts // if the user has permissions and if the report mode is showing attempts. $this->checkboxcolumn = has_any_capability( - array('mod/quiz:regrade', 'mod/quiz:deleteattempts'), context_module::instance($this->cm->id)) + ['mod/quiz:regrade', 'mod/quiz:deleteattempts'], context_module::instance($this->cm->id)) && ($this->attempts != attempts_report::ENROLLED_WITHOUT); } } diff --git a/mod/quiz/report/overview/overview_table.php b/mod/quiz/report/overview/overview_table.php index f1ab1da042b..5e96f27baf4 100644 --- a/mod/quiz/report/overview/overview_table.php +++ b/mod/quiz/report/overview/overview_table.php @@ -25,11 +25,12 @@ use mod_quiz\quiz_attempt; */ class quiz_overview_table extends attempts_report_table { - protected $regradedqs = array(); + /** @var array used to store information about which questoins have been regraded. */ + protected $regradedqs = []; /** * Constructor - * @param object $quiz + * @param stdClass $quiz * @param context $context * @param string $qmsubselect * @param quiz_overview_options $options @@ -109,12 +110,12 @@ class quiz_overview_table extends attempts_report_table { } else { $namekey = 'fullname'; } - $averagerow = array( + $averagerow = [ $namekey => $label, 'sumgrades' => $this->format_average($record), 'feedbacktext' => strip_tags(quiz_report_feedback_for_grade( $record->grade, $this->quiz->id, $this->context)) - ); + ]; if ($this->options->slotmarks) { $dm = new question_engine_data_mapper(); @@ -150,10 +151,10 @@ class quiz_overview_table extends attempts_report_table { * @return array the (partial) row of data. */ protected function format_average_grade_for_questions($gradeaverages) { - $row = array(); + $row = []; if (!$gradeaverages) { - $gradeaverages = array(); + $gradeaverages = []; } foreach ($this->questions as $question) { @@ -176,7 +177,7 @@ class quiz_overview_table extends attempts_report_table { /** * Format an entry in an average row. - * @param object $record with fields grade and numaveraged. + * @param stdClass $record with fields grade and numaveraged. * @param bool $question true if this is a question score, false if it is an overall score. * @return string HTML fragment for an average score (with number of things included in the average). */ @@ -193,12 +194,12 @@ class quiz_overview_table extends attempts_report_table { return $average; } else if (is_null($record->numaveraged) || $record->numaveraged == 0) { return html_writer::tag('span', html_writer::tag('span', - $average, array('class' => 'average')), array('class' => 'avgcell')); + $average, ['class' => 'average']), ['class' => 'avgcell']); } else { return html_writer::tag('span', html_writer::tag('span', - $average, array('class' => 'average')) . ' ' . html_writer::tag('span', - '(' . $record->numaveraged . ')', array('class' => 'count')), - array('class' => 'avgcell')); + $average, ['class' => 'average']) . ' ' . html_writer::tag('span', + '(' . $record->numaveraged . ')', ['class' => 'count']), + ['class' => 'avgcell']); } } @@ -251,13 +252,13 @@ class quiz_overview_table extends attempts_report_table { html_writer::empty_tag('br') . $newsumgrade; } return html_writer::link(new moodle_url('/mod/quiz/review.php', - array('attempt' => $attempt->attempt)), $grade, - array('title' => get_string('reviewattempt', 'quiz'))); + ['attempt' => $attempt->attempt]), $grade, + ['title' => get_string('reviewattempt', 'quiz')]); } /** * @param string $colname the name of the column. - * @param object $attempt the row of data - see the SQL in display() in + * @param stdClass $attempt the row of data - see the SQL in display() in * mod/quiz/report/overview/report.php to see what fields are present, * and what they are called. * @return string the contents of the cell. @@ -368,6 +369,6 @@ class quiz_overview_table extends attempts_report_table { $qubaids = $this->get_qubaids_condition(); $regradedqs = $DB->get_records_select('quiz_overview_regrades', 'questionusageid ' . $qubaids->usage_id_in(), $qubaids->usage_id_in_params()); - return quiz_report_index_by_keys($regradedqs, array('questionusageid', 'slot')); + return quiz_report_index_by_keys($regradedqs, ['questionusageid', 'slot']); } } diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 83c41a4dda6..0feea206cce 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -79,7 +79,7 @@ class quiz_overview_report extends attempts_report { $questions = quiz_report_get_significant_questions($quiz); // Prepare for downloading, if applicable. $courseshortname = format_string($course->shortname, true, - array('context' => context_course::instance($course->id))); + ['context' => context_course::instance($course->id)]); $table = new quiz_overview_table($quiz, $this->context, $this->qmsubselect, $options, $groupstudentsjoins, $studentsjoins, $questions, $options->get_url()); $filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'), @@ -157,7 +157,7 @@ class quiz_overview_report extends attempts_report { $regradealllabel = get_string('regradeall', 'quiz_overview'); } - $displayurl = new moodle_url($options->get_url(), array('sesskey' => sesskey())); + $displayurl = new moodle_url($options->get_url(), ['sesskey' => sesskey()]); echo '
'; echo '
'; echo '
'; @@ -181,8 +181,8 @@ class quiz_overview_report extends attempts_report { } // Define table columns. - $columns = array(); - $headers = array(); + $columns = []; + $headers = []; if (!$table->is_downloading() && $options->checkboxcolumn) { $columnname = 'checkbox'; @@ -242,7 +242,7 @@ class quiz_overview_report extends attempts_report { } } - if ($DB->record_exists('quiz_grades', array('quiz'=> $quiz->id))) { + if ($DB->record_exists('quiz_grades', ['quiz' => $quiz->id])) { $data = quiz_report_grade_bands($bandwidth, $bands, $quiz->id, new \core\dml\sql_join()); $chart = self::get_chart($labels, $data); $graphname = get_string('overviewreportgraph', 'quiz_overview'); @@ -256,8 +256,8 @@ class quiz_overview_report extends attempts_report { /** * Extends parent function processing any submitted actions. * - * @param object $quiz - * @param object $cm + * @param stdClass $quiz + * @param stdClass $cm * @param int $currentgroup * @param \core\dml\sql_join $groupstudentsjoins (joins, wheres, params) * @param \core\dml\sql_join $allowedjoins (joins, wheres, params) @@ -269,7 +269,7 @@ class quiz_overview_report extends attempts_report { if (empty($currentgroup) || $this->hasgroupstudents) { if (optional_param('regrade', 0, PARAM_BOOL) && confirm_sesskey()) { - if ($attemptids = optional_param_array('attemptid', array(), PARAM_INT)) { + if ($attemptids = optional_param_array('attemptid', [], PARAM_INT)) { $this->start_regrade($quiz, $cm); $this->regrade_attempts($quiz, false, $groupstudentsjoins, $attemptids); $this->finish_regrade($redirecturl); @@ -296,8 +296,8 @@ class quiz_overview_report extends attempts_report { /** * Check necessary capabilities, and start the display of the regrade progress page. - * @param object $quiz the quiz settings. - * @param object $cm the cm object for the quiz. + * @param stdClass $quiz the quiz settings. + * @param stdClass $cm the cm object for the quiz. */ protected function start_regrade($quiz, $cm) { require_capability('mod/quiz:regrade', $this->context); @@ -333,7 +333,7 @@ class quiz_overview_report extends attempts_report { * Note, $attempt is not upgraded in the database. The caller needs to do that. * However, $attempt->sumgrades is updated, if this is not a dry run. * - * @param object $attempt the quiz attempt to regrade. + * @param stdClass $attempt the quiz attempt to regrade. * @param bool $dryrun if true, do a pretend regrade, otherwise do it for real. * @param array $slots if null, regrade all questions, otherwise, just regrade * the questions with those slots. @@ -381,14 +381,14 @@ class quiz_overview_report extends attempts_report { if (!$dryrun) { question_engine::save_questions_usage_by_activity($quba); - $params = array( + $params = [ 'objectid' => $attempt->id, 'relateduserid' => $attempt->userid, 'context' => $this->context, - 'other' => array( + 'other' => [ 'quizid' => $attempt->quiz - ) - ); + ] + ]; $event = \mod_quiz\event\attempt_regraded::create($params); $event->trigger(); } @@ -452,15 +452,16 @@ class quiz_overview_report extends attempts_report { /** * Regrade attempts for this quiz, exactly which attempts are regraded is * controlled by the parameters. - * @param object $quiz the quiz settings. + * + * @param stdClass $quiz the quiz settings. * @param bool $dryrun if true, do a pretend regrade, otherwise do it for real. - * @param \core\dml\sql_join|array $groupstudentsjoins empty for all attempts, otherwise regrade attempts + * @param \core\dml\sql_join|null $groupstudentsjoins empty for all attempts, otherwise regrade attempts * for these users. * @param array $attemptids blank for all attempts, otherwise only regrade * attempts whose id is in this list. */ protected function regrade_attempts($quiz, $dryrun = false, - \core\dml\sql_join$groupstudentsjoins = null, $attemptids = array()) { + core\dml\sql_join $groupstudentsjoins = null, $attemptids = []) { global $DB; $this->unlock_session(); @@ -469,7 +470,7 @@ class quiz_overview_report extends attempts_report { FROM {quiz_attempts} quiza JOIN {user} u ON u.id = quiza.userid"; $where = "quiz = :qid AND preview = 0"; - $params = array('qid' => $quiz->id); + $params = ['qid' => $quiz->id]; if ($this->hasgroupstudents && !empty($groupstudentsjoins->joins)) { $sql .= "\n{$groupstudentsjoins->joins}"; @@ -495,7 +496,7 @@ class quiz_overview_report extends attempts_report { /** * Regrade those questions in those attempts that are marked as needing regrading * in the quiz_overview_regrades table. - * @param object $quiz the quiz settings. + * @param stdClass $quiz the quiz settings. * @param \core\dml\sql_join $groupstudentsjoins empty for all attempts, otherwise regrade attempts * for these users. */ @@ -505,7 +506,7 @@ class quiz_overview_report extends attempts_report { $join = '{quiz_overview_regrades} qqr ON qqr.questionusageid = quiza.uniqueid'; $where = "quiza.quiz = :qid AND quiza.preview = 0 AND qqr.regraded = 0"; - $params = array('qid' => $quiz->id); + $params = ['qid' => $quiz->id]; // Fetch all attempts that need regrading. if ($this->hasgroupstudents && !empty($groupstudentsjoins->joins)) { @@ -521,7 +522,7 @@ class quiz_overview_report extends attempts_report { JOIN $join WHERE $where", $params); - $attemptquestions = array(); + $attemptquestions = []; foreach ($toregrade as $row) { $attemptquestions[$row->uniqueid][] = $row->slot; } @@ -557,7 +558,7 @@ class quiz_overview_report extends attempts_report { * In addition, if $attempt->regradeonlyslots is set, then only those slots * are regraded, otherwise all slots are regraded. * - * @param object $quiz the quiz settings. + * @param stdClass $quiz the quiz settings. * @param array $attempts of data from the quiz_attempts table, with extra data as above. * @param bool $dryrun if true, do a pretend regrade, otherwise do it for real. * @param \core\dml\sql_join $groupstudentsjoins empty for all attempts, otherwise regrade attempts @@ -568,10 +569,10 @@ class quiz_overview_report extends attempts_report { $this->clear_regrade_table($quiz, $groupstudentsjoins); $progressbar = new progress_bar('quiz_overview_regrade', 500, true); - $a = array( + $a = [ 'count' => count($attempts), 'done' => 0, - ); + ]; foreach ($attempts as $attempt) { $a['done']++; $a['attemptnum'] = $attempt->attempt; @@ -605,7 +606,7 @@ class quiz_overview_report extends attempts_report { /** * Count the number of attempts in need of a regrade. * - * @param object $quiz the quiz settings. + * @param stdClass $quiz the quiz settings. * @param \core\dml\sql_join $groupstudentsjoins (joins, wheres, params) If this is given, only data relating * to these users is cleared. * @return int the number of attempts. @@ -615,7 +616,7 @@ class quiz_overview_report extends attempts_report { $userjoin = ''; $usertest = ''; - $params = array(); + $params = []; if ($this->hasgroupstudents) { $userjoin = "JOIN {user} u ON u.id = quiza.userid {$groupstudentsjoins->joins}"; @@ -654,7 +655,7 @@ class quiz_overview_report extends attempts_report { /** * Remove all information about pending/complete regrades from the database. - * @param object $quiz the quiz settings. + * @param stdClass $quiz the quiz settings. * @param \core\dml\sql_join $groupstudentsjoins (joins, wheres, params). If this is given, only data relating * to these users is cleared. */ @@ -666,7 +667,7 @@ class quiz_overview_report extends attempts_report { SELECT uniqueid FROM {quiz_attempts} quiza"; $where = "WHERE quiza.quiz = :qid"; - $params = array('qid' => $quiz->id); + $params = ['qid' => $quiz->id]; if ($this->hasgroupstudents && !empty($groupstudentsjoins->joins)) { $select .= "\nJOIN {user} u ON u.id = quiza.userid {$groupstudentsjoins->joins}"; @@ -679,11 +680,9 @@ class quiz_overview_report extends attempts_report { } /** - * Update the final grades for all attempts. This method is used following - * a regrade. - * @param object $quiz the quiz settings. - * @param array $userids only update scores for these userids. - * @param array $attemptids attemptids only update scores for these attempt ids. + * Update the final grades for all attempts. This method is used following a regrade. + * + * @param stdClass $quiz the quiz settings. */ protected function update_overall_grades($quiz) { quiz_update_all_attempt_sumgrades($quiz); @@ -698,7 +697,7 @@ class quiz_overview_report extends attempts_report { * a chart based on the maximum grade to be given on a quiz. The width of * a band is the number of grade points it encapsulates. * - * @param object $quiz The quiz object. + * @param stdClass $quiz The quiz object. * @return array Contains the number of bands, and their width. */ public static function get_bands_count_and_width($quiz) { @@ -725,7 +724,7 @@ class quiz_overview_report extends attempts_report { * * @param int $bands The number of bands. * @param int $bandwidth The band width. - * @param object $quiz The quiz object. + * @param stdClass $quiz The quiz object. * @return string[] The labels. */ public static function get_bands_labels($bands, $bandwidth, $quiz) { diff --git a/mod/quiz/report/overview/tests/helpers.php b/mod/quiz/report/overview/tests/helpers.php index 3400f44df17..8e9f7daa965 100644 --- a/mod/quiz/report/overview/tests/helpers.php +++ b/mod/quiz/report/overview/tests/helpers.php @@ -34,9 +34,9 @@ class testable_quiz_attempts_report extends attempts_report { /** * Override this function to displays the report. - * @param object $cm the course-module for this quiz. - * @param object $course the course we are in. - * @param object $quiz this quiz. + * @param stdClass $cm the course-module for this quiz. + * @param stdClass $course the course we are in. + * @param stdClass $quiz this quiz. */ public function display($cm, $course, $quiz) { @@ -45,8 +45,8 @@ class testable_quiz_attempts_report extends attempts_report { /** * Testable delete_selected_attempts function. * - * @param object $quiz - * @param object $cm + * @param stdClass $quiz + * @param stdClass $cm * @param array $attemptids * @param \core\dml\sql_join $allowedjoins */ diff --git a/mod/quiz/report/overview/tests/report_test.php b/mod/quiz/report/overview/tests/report_test.php index 1d0e583d56b..92d58c9ca93 100644 --- a/mod/quiz/report/overview/tests/report_test.php +++ b/mod/quiz/report/overview/tests/report_test.php @@ -70,9 +70,9 @@ class report_test extends \advanced_testcase { $generator = $this->getDataGenerator(); $course = $generator->create_course(); $quizgenerator = $generator->get_plugin_generator('mod_quiz'); - $quiz = $quizgenerator->create_instance(array('course' => $course->id, + $quiz = $quizgenerator->create_instance(['course' => $course->id, 'grademethod' => QUIZ_GRADEHIGHEST, 'grade' => 100.0, 'sumgrades' => 10.0, - 'attempts' => 10)); + 'attempts' => 10]); // Add one question. /** @var core_question_generator $questiongenerator */ @@ -104,18 +104,18 @@ class report_test extends \advanced_testcase { // The test data. $timestamp = 1234567890; - $attempts = array( - array($quiz, $student1, 1, 0.0, quiz_attempt::FINISHED), - array($quiz, $student1, 2, 5.0, quiz_attempt::FINISHED), - array($quiz, $student1, 3, 8.0, quiz_attempt::FINISHED), - array($quiz, $student1, 4, null, quiz_attempt::ABANDONED), - array($quiz, $student1, 5, null, quiz_attempt::IN_PROGRESS), - array($quiz, $student2, 1, null, quiz_attempt::ABANDONED), - array($quiz, $student2, 2, null, quiz_attempt::ABANDONED), - array($quiz, $student2, 3, 7.0, quiz_attempt::FINISHED), - array($quiz, $student2, 4, null, quiz_attempt::ABANDONED), - array($quiz, $student2, 5, null, quiz_attempt::ABANDONED), - ); + $attempts = [ + [$quiz, $student1, 1, 0.0, quiz_attempt::FINISHED], + [$quiz, $student1, 2, 5.0, quiz_attempt::FINISHED], + [$quiz, $student1, 3, 8.0, quiz_attempt::FINISHED], + [$quiz, $student1, 4, null, quiz_attempt::ABANDONED], + [$quiz, $student1, 5, null, quiz_attempt::IN_PROGRESS], + [$quiz, $student2, 1, null, quiz_attempt::ABANDONED], + [$quiz, $student2, 2, null, quiz_attempt::ABANDONED], + [$quiz, $student2, 3, 7.0, quiz_attempt::FINISHED], + [$quiz, $student2, 4, null, quiz_attempt::ABANDONED], + [$quiz, $student2, 5, null, quiz_attempt::ABANDONED], + ]; // Load it in to quiz attempts table. foreach ($attempts as $attemptdata) { @@ -170,22 +170,22 @@ class report_test extends \advanced_testcase { $cm = get_coursemodule_from_id('quiz', $quiz->cmid); $qmsubselect = quiz_report_qm_filter_select($quiz); $studentsjoins = get_enrolled_with_capabilities_join($context, '', - array('mod/quiz:attempt', 'mod/quiz:reviewmyattempts')); + ['mod/quiz:attempt', 'mod/quiz:reviewmyattempts']); $empty = new \core\dml\sql_join(); // Set the options. $reportoptions = new quiz_overview_options('overview', $quiz, $cm, null); $reportoptions->attempts = attempts_report::ENROLLED_ALL; $reportoptions->onlygraded = true; - $reportoptions->states = array(quiz_attempt::IN_PROGRESS, quiz_attempt::OVERDUE, quiz_attempt::FINISHED); + $reportoptions->states = [quiz_attempt::IN_PROGRESS, quiz_attempt::OVERDUE, quiz_attempt::FINISHED]; // Now do a minimal set-up of the table class. $q->slot = 1; $q->maxmark = 10; $table = new quiz_overview_table($quiz, $context, $qmsubselect, $reportoptions, - $empty, $studentsjoins, array(1 => $q), null); + $empty, $studentsjoins, [1 => $q], null); $table->download = $isdownloading; // Cannot call the is_downloading API, because it gives errors. - $table->define_columns(array('fullname')); + $table->define_columns(['fullname']); $table->sortable(true, 'uniqueid'); $table->define_baseurl(new \moodle_url('/mod/quiz/report.php')); $table->setup(); diff --git a/mod/quiz/report/reportlib.php b/mod/quiz/report/reportlib.php index 53ba5ed622b..592b41b37ad 100644 --- a/mod/quiz/report/reportlib.php +++ b/mod/quiz/report/reportlib.php @@ -45,10 +45,10 @@ use mod_quiz\question\display_options; */ function quiz_report_index_by_keys($datum, $keys, $keysunique = true) { if (!$datum) { - return array(); + return []; } $key = array_shift($keys); - $datumkeyed = array(); + $datumkeyed = []; foreach ($datum as $data) { if ($keys || !$keysunique) { $datumkeyed[$data->{$key}][]= $data; @@ -68,7 +68,7 @@ function quiz_report_unindex($datum) { if (!$datum) { return $datum; } - $datumunkeyed = array(); + $datumunkeyed = []; foreach ($datum as $value) { if (is_array($value)) { $datumunkeyed = array_merge($datumunkeyed, quiz_report_unindex($value)); @@ -85,12 +85,12 @@ function quiz_report_unindex($datum) { */ function quiz_has_questions($quizid) { global $DB; - return $DB->record_exists('quiz_slots', array('quizid' => $quizid)); + return $DB->record_exists('quiz_slots', ['quizid' => $quizid]); } /** * Get the slots of real questions (not descriptions) in this quiz, in order. - * @param object $quiz the quiz. + * @param stdClass $quiz the quiz. * @return array of slot => objects with fields * ->slot, ->id, ->qtype, ->length, ->number, ->maxmark, ->category (for random questions). */ @@ -125,7 +125,7 @@ function quiz_report_get_significant_questions($quiz) { } /** - * @param object $quiz the quiz settings. + * @param stdClass $quiz the quiz settings. * @return bool whether, for this quiz, it is possible to filter attempts to show * only those that gave the final grade. */ @@ -137,7 +137,7 @@ function quiz_report_can_filter_only_graded($quiz) { * This is a wrapper for {@link quiz_report_grade_method_sql} that takes the whole quiz object instead of just the grading method * as a param. See definition for {@link quiz_report_grade_method_sql} below. * - * @param object $quiz + * @param stdClass $quiz * @param string $quizattemptsalias sql alias for 'quiz_attempts' table * @return string sql to test if this is an attempt that will contribute towards the grade of the user */ @@ -216,7 +216,7 @@ function quiz_report_grade_bands($bandwidth, $bands, $quizid, \core\dml\sql_join } else { $userjoin = ''; $usertest = '1=1'; - $params = array(); + $params = []; } $sql = " SELECT band, COUNT(1) @@ -280,10 +280,10 @@ function quiz_report_highlighting_grading_method($quiz, $qmsubselect, $qmfilter) function quiz_report_feedback_for_grade($grade, $quizid, $context) { global $DB; - static $feedbackcache = array(); + static $feedbackcache = []; if (!isset($feedbackcache[$quizid])) { - $feedbackcache[$quizid] = $DB->get_records('quiz_feedback', array('quizid' => $quizid)); + $feedbackcache[$quizid] = $DB->get_records('quiz_feedback', ['quizid' => $quizid]); } // With CBM etc, it is possible to get -ve grades, which would then not match @@ -316,7 +316,7 @@ function quiz_report_feedback_for_grade($grade, $quizid, $context) { /** * Format a number as a percentage out of $quiz->sumgrades * @param number $rawgrade the mark to format. - * @param object $quiz the quiz settings + * @param stdClass $quiz the quiz settings * @param bool $round whether to round the results ot $quiz->decimalpoints. */ function quiz_report_scale_summarks_as_percentage($rawmark, $quiz, $round = true) { @@ -350,7 +350,7 @@ function quiz_report_list($context) { $reportdirs = core_component::get_plugin_list('quiz'); // Order the reports tab in descending order of displayorder. - $reportcaps = array(); + $reportcaps = []; foreach ($reports as $key => $report) { if (array_key_exists($report->name, $reportdirs)) { $reportcaps[$report->name] = $report->capability; @@ -363,7 +363,7 @@ function quiz_report_list($context) { $reportcaps[$reportname] = null; } } - $reportlist = array(); + $reportlist = []; foreach ($reportcaps as $name => $capability) { if (empty($capability)) { $capability = 'mod/quiz:viewreports'; @@ -390,7 +390,7 @@ function quiz_report_download_filename($report, $courseshortname, $quizname) { /** * Get the default report for the current user. - * @param object $context the quiz context. + * @param stdClass $context the quiz context. */ function quiz_report_default_report($context) { $reports = quiz_report_list($context); @@ -400,9 +400,9 @@ function quiz_report_default_report($context) { /** * Generate a message saying that this quiz has no questions, with a button to * go to the edit page, if the user has the right capability. - * @param object $quiz the quiz settings. - * @param object $cm the course_module object. - * @param object $context the quiz context. + * @param stdClass $quiz the quiz settings. + * @param stdClass $cm the course_module object. + * @param stdClass $context the quiz context. * @return string HTML to output. */ function quiz_no_questions_message($quiz, $cm, $context) { @@ -412,7 +412,7 @@ function quiz_no_questions_message($quiz, $cm, $context) { $output .= $OUTPUT->notification(get_string('noquestions', 'quiz')); if (has_capability('mod/quiz:manage', $context)) { $output .= $OUTPUT->single_button(new moodle_url('/mod/quiz/edit.php', - array('cmid' => $cm->id)), get_string('editquiz', 'quiz'), 'get'); + ['cmid' => $cm->id]), get_string('editquiz', 'quiz'), 'get'); } return $output; @@ -421,7 +421,7 @@ function quiz_no_questions_message($quiz, $cm, $context) { /** * Should the grades be displayed in this report. That depends on the quiz * display options, and whether the quiz is graded. - * @param object $quiz the quiz settings. + * @param stdClass $quiz the quiz settings. * @param context $context the quiz context. * @return bool */ diff --git a/mod/quiz/report/responses/first_or_all_responses_table.php b/mod/quiz/report/responses/first_or_all_responses_table.php index b9787cf8af3..39ec9f6ccb6 100644 --- a/mod/quiz/report/responses/first_or_all_responses_table.php +++ b/mod/quiz/report/responses/first_or_all_responses_table.php @@ -68,7 +68,7 @@ class quiz_first_or_all_responses_table extends quiz_last_responses_table { $this->questionusagesbyactivity = $dm->load_questions_usages_by_activity($qubaids); // Insert an extra field in attempt data and extra rows where necessary. - $newrawdata = array(); + $newrawdata = []; foreach ($this->rawdata as $attempt) { if (!isset($this->questionusagesbyactivity[$attempt->usageid])) { // This is a user without attempts. @@ -114,7 +114,7 @@ class quiz_first_or_all_responses_table extends quiz_last_responses_table { /** * Find the state for $slot given after this try. * - * @param object $tablerow row data + * @param stdClass $tablerow row data * @param int $slot Slot number. * @return question_state The question state after the attempt. */ @@ -137,7 +137,7 @@ class quiz_first_or_all_responses_table extends quiz_last_responses_table { /** * Get the summary of the response after the try. * - * @param object $tablerow row data + * @param stdClass $tablerow row data * @param int $slot Slot number. * @return string summary for the question after this try. */ @@ -170,7 +170,7 @@ class quiz_first_or_all_responses_table extends quiz_last_responses_table { /** * The grade for this slot after this try. * - * @param object $tablerow attempt data from db. + * @param stdClass $tablerow attempt data from db. * @param int $slot Slot number. * @return float The fraction. */ @@ -192,7 +192,7 @@ class quiz_first_or_all_responses_table extends quiz_last_responses_table { /** * Is this the last try in the question attempt? * - * @param object $tablerow attempt data from db. + * @param stdClass $tablerow attempt data from db. * @param int $slot Slot number * @param int $tryno try no * @return bool Is it the last try? @@ -204,7 +204,7 @@ class quiz_first_or_all_responses_table extends quiz_last_responses_table { /** * How many tries were attempted at this question in this slot, during this usage? * - * @param object $tablerow attempt data from db. + * @param stdClass $tablerow attempt data from db. * @param int $slot Slot number * @return int the number of tries in the question attempt for slot $slot. */ @@ -237,7 +237,7 @@ class quiz_first_or_all_responses_table extends quiz_last_responses_table { /** * Cell value function for email column. This extracts the contents for any cell in the email column from the row data. * - * @param object $tablerow Row data. + * @param stdClass $tablerow Row data. * @return string What to put in the cell for this column, for this row data. */ public function col_email($tablerow) { @@ -251,7 +251,7 @@ class quiz_first_or_all_responses_table extends quiz_last_responses_table { /** * Cell value function for sumgrades column. This extracts the contents for any cell in the sumgrades column from the row data. * - * @param object $tablerow Row data. + * @param stdClass $tablerow Row data. * @return string What to put in the cell for this column, for this row data. */ public function col_sumgrades($tablerow) { diff --git a/mod/quiz/report/responses/last_responses_table.php b/mod/quiz/report/responses/last_responses_table.php index 033de2a9311..5d2868ba1f4 100644 --- a/mod/quiz/report/responses/last_responses_table.php +++ b/mod/quiz/report/responses/last_responses_table.php @@ -27,7 +27,7 @@ class quiz_last_responses_table extends attempts_report_table { /** * Constructor - * @param object $quiz + * @param stdClass $quiz * @param context $context * @param string $qmsubselect * @param quiz_responses_options $options @@ -94,7 +94,7 @@ class quiz_last_responses_table extends attempts_report_table { /** * Column text from the extra data loaded in load_extra_data(), before html formatting etc. * - * @param object $attempt + * @param stdClass $attempt * @param int $slot * @param string $field * @return string diff --git a/mod/quiz/report/responses/report.php b/mod/quiz/report/responses/report.php index 6662e4d4328..b77a86e5c83 100644 --- a/mod/quiz/report/responses/report.php +++ b/mod/quiz/report/responses/report.php @@ -70,7 +70,7 @@ class quiz_responses_report extends attempts_report { // Prepare for downloading, if applicable. $courseshortname = format_string($course->shortname, true, - array('context' => context_course::instance($course->id))); + ['context' => context_course::instance($course->id)]); if ($options->whichtries === question_attempt::LAST_TRY) { $tableclassname = 'quiz_last_responses_table'; } else { @@ -137,8 +137,8 @@ class quiz_responses_report extends attempts_report { } // Define table columns. - $columns = array(); - $headers = array(); + $columns = []; + $headers = []; if (!$table->is_downloading() && $options->checkboxcolumn) { $columnname = 'checkbox'; diff --git a/mod/quiz/report/responses/responses_form.php b/mod/quiz/report/responses/responses_form.php index ca86d93b608..2a6391741ec 100644 --- a/mod/quiz/report/responses/responses_form.php +++ b/mod/quiz/report/responses/responses_form.php @@ -26,14 +26,14 @@ use mod_quiz\local\reports\attempts_report_options_form; class quiz_responses_settings_form extends attempts_report_options_form { protected function other_preference_fields(MoodleQuickForm $mform) { - $mform->addGroup(array( + $mform->addGroup([ $mform->createElement('advcheckbox', 'qtext', '', get_string('questiontext', 'quiz_responses')), $mform->createElement('advcheckbox', 'resp', '', get_string('response', 'quiz_responses')), $mform->createElement('advcheckbox', 'right', '', get_string('rightanswer', 'quiz_responses')), - ), 'coloptions', get_string('showthe', 'quiz_responses'), array(' '), false); + ], 'coloptions', get_string('showthe', 'quiz_responses'), [' '], false); $mform->disabledIf('qtext', 'attempts', 'eq', attempts_report::ENROLLED_WITHOUT); $mform->disabledIf('resp', 'attempts', 'eq', attempts_report::ENROLLED_WITHOUT); $mform->disabledIf('right', 'attempts', 'eq', attempts_report::ENROLLED_WITHOUT); @@ -53,10 +53,10 @@ class quiz_responses_settings_form extends attempts_report_options_form { protected function other_attempt_fields(MoodleQuickForm $mform) { parent::other_attempt_fields($mform); if (quiz_allows_multiple_tries($this->_customdata['quiz'])) { - $mform->addElement('select', 'whichtries', get_string('whichtries', 'question'), array( + $mform->addElement('select', 'whichtries', get_string('whichtries', 'question'), [ question_attempt::FIRST_TRY => get_string('firsttry', 'question'), question_attempt::LAST_TRY => get_string('lasttry', 'question'), - question_attempt::ALL_TRIES => get_string('alltries', 'question')) + question_attempt::ALL_TRIES => get_string('alltries', 'question')] ); $mform->setDefault('whichtries', question_attempt::LAST_TRY); $mform->disabledIf('whichtries', 'attempts', 'eq', attempts_report::ENROLLED_WITHOUT); diff --git a/mod/quiz/report/responses/tests/responses_from_steps_walkthrough_test.php b/mod/quiz/report/responses/tests/responses_from_steps_walkthrough_test.php index 909c706241c..07c06df8cc9 100644 --- a/mod/quiz/report/responses/tests/responses_from_steps_walkthrough_test.php +++ b/mod/quiz/report/responses/tests/responses_from_steps_walkthrough_test.php @@ -41,7 +41,10 @@ class responses_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthroug return __DIR__."/fixtures/{$setname}{$test}.csv"; } - protected $files = array('questions', 'steps', 'responses'); + /** + * @var string[] names of the files which contain the test data. + */ + protected $files = ['questions', 'steps', 'responses']; /** * Create a quiz add questions to it, walk through quiz attempts and then check results. @@ -89,7 +92,7 @@ class responses_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthroug throw new \coding_exception("There is no step no {$responses['submittedstepno']} ". "for slot $slot in quizattempt {$responses['quizattempt']}!"); } - foreach (array('responsesummary', 'fraction', 'state') as $column) { + foreach (['responsesummary', 'fraction', 'state'] as $column) { if (isset($tests[$column]) && $tests[$column] != '') { switch($column) { case 'responsesummary' : diff --git a/mod/quiz/report/statistics/classes/calculated.php b/mod/quiz/report/statistics/classes/calculated.php index 223589bb814..efba5f4d9e6 100644 --- a/mod/quiz/report/statistics/classes/calculated.php +++ b/mod/quiz/report/statistics/classes/calculated.php @@ -127,7 +127,7 @@ class calculated { public function get_formatted_quiz_info_data($course, $cm, $quiz) { // You can edit this array to control which statistics are displayed. - $todisplay = array('firstattemptscount' => 'number', + $todisplay = ['firstattemptscount' => 'number', 'allattemptscount' => 'number', 'firstattemptsavg' => 'summarks_as_percentage', 'allattemptsavg' => 'summarks_as_percentage', @@ -139,10 +139,10 @@ class calculated { 'kurtosis' => 'number_format', 'cic' => 'number_format_percent', 'errorratio' => 'number_format_percent', - 'standarderror' => 'summarks_as_percentage'); + 'standarderror' => 'summarks_as_percentage']; // General information about the quiz. - $quizinfo = array(); + $quizinfo = []; $quizinfo[get_string('quizname', 'quiz_statistics')] = format_string($quiz->name); $quizinfo[get_string('coursename', 'quiz_statistics')] = format_string($course->fullname); if ($cm->idnumber) { @@ -195,10 +195,10 @@ class calculated { /** * @var array of names of properties of this class that are cached in db record. */ - protected $fieldsindb = array('whichattempts', 'firstattemptscount', 'allattemptscount', 'firstattemptsavg', 'allattemptsavg', + protected $fieldsindb = ['whichattempts', 'firstattemptscount', 'allattemptscount', 'firstattemptsavg', 'allattemptsavg', 'lastattemptscount', 'highestattemptscount', 'lastattemptsavg', 'highestattemptsavg', 'median', 'standarddeviation', 'skewness', - 'kurtosis', 'cic', 'errorratio', 'standarderror'); + 'kurtosis', 'cic', 'errorratio', 'standarderror']; /** * Cache the stats contained in this class. diff --git a/mod/quiz/report/statistics/classes/calculator.php b/mod/quiz/report/statistics/classes/calculator.php index e6ff9567a69..514669e7087 100644 --- a/mod/quiz/report/statistics/classes/calculator.php +++ b/mod/quiz/report/statistics/classes/calculator.php @@ -135,7 +135,7 @@ class calculator { $timemodified = time() - self::TIME_TO_CACHE; $fromdb = $DB->get_record_select('quiz_statistics', 'hashcode = ? AND timemodified > ?', - array($qubaids->get_hash_code(), $timemodified)); + [$qubaids->get_hash_code(), $timemodified]); $stats = new calculated(); $stats->populate_from_record($fromdb); return $stats; @@ -152,7 +152,7 @@ class calculator { $timemodified = time() - self::TIME_TO_CACHE; return $DB->get_field_select('quiz_statistics', 'timemodified', 'hashcode = ? AND timemodified > ?', - array($qubaids->get_hash_code(), $timemodified)); + [$qubaids->get_hash_code(), $timemodified]); } /** @@ -265,7 +265,7 @@ class calculator { * @param $fromqa * @param $whereqa * @param $qaparams - * @return object with properties power2, power3, power4 + * @return stdClass with properties power2, power3, power4 */ protected function sum_of_powers_of_difference_to_mean($mean, $fromqa, $whereqa, $qaparams) { global $DB; @@ -276,7 +276,7 @@ class calculator { SUM(POWER((quiza.sumgrades - $mean), 4)) AS power4 FROM $fromqa WHERE $whereqa"; - $params = array('mean1' => $mean, 'mean2' => $mean, 'mean3' => $mean) + $qaparams; + $params = ['mean1' => $mean, 'mean2' => $mean, 'mean3' => $mean] + $qaparams; return $DB->get_record_sql($sql, $params, MUST_EXIST); } diff --git a/mod/quiz/report/statistics/db/access.php b/mod/quiz/report/statistics/db/access.php index cadcfc3aa61..53dfe46732c 100644 --- a/mod/quiz/report/statistics/db/access.php +++ b/mod/quiz/report/statistics/db/access.php @@ -24,15 +24,15 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( - 'quiz/statistics:view' => array( +$capabilities = [ + 'quiz/statistics:view' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ), + ], 'clonepermissionsfrom' => 'mod/quiz:viewreports' - ) -); + ] +]; diff --git a/mod/quiz/report/statistics/lib.php b/mod/quiz/report/statistics/lib.php index 8fe0c19da93..2ff1c7585f7 100644 --- a/mod/quiz/report/statistics/lib.php +++ b/mod/quiz/report/statistics/lib.php @@ -39,7 +39,7 @@ defined('MOODLE_INTERNAL') || die(); * @param array $options additional options affecting the file serving. */ function quiz_statistics_question_preview_pluginfile($previewcontext, $questionid, - $filecontext, $filecomponent, $filearea, $args, $forcedownload, $options = array()) { + $filecontext, $filecomponent, $filearea, $args, $forcedownload, $options = []) { global $CFG; require_once($CFG->dirroot . '/mod/quiz/locallib.php'); diff --git a/mod/quiz/report/statistics/report.php b/mod/quiz/report/statistics/report.php index 96162615bf8..ddd52a9e82c 100644 --- a/mod/quiz/report/statistics/report.php +++ b/mod/quiz/report/statistics/report.php @@ -80,7 +80,7 @@ class quiz_statistics_report extends report_base { $whichattempts = optional_param('whichattempts', $quiz->grademethod, PARAM_INT); $whichtries = optional_param('whichtries', question_attempt::LAST_TRY, PARAM_ALPHA); - $pageoptions = array(); + $pageoptions = []; $pageoptions['id'] = $cm->id; $pageoptions['mode'] = 'statistics'; @@ -88,7 +88,7 @@ class quiz_statistics_report extends report_base { $mform = new quiz_statistics_settings_form($reporturl, compact('quiz')); - $mform->set_data(array('whichattempts' => $whichattempts, 'whichtries' => $whichtries)); + $mform->set_data(['whichattempts' => $whichattempts, 'whichtries' => $whichtries]); if ($whichattempts != $quiz->grademethod) { $reporturl->param('whichattempts', $whichattempts); @@ -112,7 +112,7 @@ class quiz_statistics_report extends report_base { } else { // All users who can attempt quizzes and who are in the currently selected group. $groupstudentsjoins = get_enrolled_with_capabilities_join($this->context, '', - array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), $currentgroup); + ['mod/quiz:reviewmyattempts', 'mod/quiz:attempt'], $currentgroup); if (!empty($groupstudentsjoins->joins)) { $sql = "SELECT DISTINCT u.id FROM {user} u @@ -140,7 +140,7 @@ class quiz_statistics_report extends report_base { $report = get_string('questionstatsfilename', 'quiz_statistics'); } $courseshortname = format_string($course->shortname, true, - array('context' => context_course::instance($course->id))); + ['context' => context_course::instance($course->id)]); $filename = quiz_report_download_filename($report, $courseshortname, $quiz->name); $this->table->is_downloading($download, $filename, get_string('quizstructureanalysis', 'quiz_statistics')); @@ -234,7 +234,7 @@ class quiz_statistics_report extends report_base { $number = $questionstats->for_slot($slot)->question->number; echo $OUTPUT->heading(get_string('slotstructureanalysis', 'quiz_statistics', $number), 3); } - $this->table->define_baseurl(new moodle_url($reporturl, array('slot' => $slot))); + $this->table->define_baseurl(new moodle_url($reporturl, ['slot' => $slot])); $this->table->format_and_add_array_of_rows($questionstats->structure_analysis_for_one_slot($slot)); } else { $this->output_individual_question_data($quiz, $questionstats->for_slot($slot, $variantno)); @@ -284,7 +284,7 @@ class quiz_statistics_report extends report_base { * Display the statistical and introductory information about a question. * Only called when not downloading. * - * @param object $quiz the quiz settings. + * @param stdClass $quiz the quiz settings. * @param \core_question\statistics\questions\calculated $questionstat the question to report on. */ protected function output_individual_question_data($quiz, $questionstat) { @@ -296,29 +296,29 @@ class quiz_statistics_report extends report_base { // Set up the question info table. $questioninfotable = new html_table(); - $questioninfotable->align = array('center', 'center'); + $questioninfotable->align = ['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.' '.$datumfromtable['actions']); + $questioninfotable->data = []; + $questioninfotable->data[] = [get_string('modulename', 'quiz'), $quiz->name]; + $questioninfotable->data[] = [get_string('questionname', 'quiz_statistics'), + $questionstat->question->name.' '.$datumfromtable['actions']]; if ($questionstat->variant !== null) { - $questioninfotable->data[] = array(get_string('variant', 'quiz_statistics'), $questionstat->variant); + $questioninfotable->data[] = [get_string('variant', 'quiz_statistics'), $questionstat->variant]; } - $questioninfotable->data[] = array(get_string('questiontype', 'quiz_statistics'), + $questioninfotable->data[] = [get_string('questiontype', 'quiz_statistics'), $datumfromtable['icon'] . ' ' . question_bank::get_qtype($questionstat->question->qtype, false)->menu_name() . ' ' . - $datumfromtable['icon']); - $questioninfotable->data[] = array(get_string('positions', 'quiz_statistics'), - $questionstat->positions); + $datumfromtable['icon']]; + $questioninfotable->data[] = [get_string('positions', 'quiz_statistics'), + $questionstat->positions]; // Set up the question statistics table. $questionstatstable = new html_table(); - $questionstatstable->align = array('center', 'center'); + $questionstatstable->align = ['center', 'center']; $questionstatstable->width = '60%'; $questionstatstable->attributes['class'] = 'generaltable titlesleft'; @@ -327,7 +327,7 @@ class quiz_statistics_report extends report_base { $actions = $datumfromtable['actions']; unset($datumfromtable['actions']); unset($datumfromtable['name']); - $labels = array( + $labels = [ 's' => get_string('attempts', 'quiz_statistics'), 'facility' => get_string('facility', 'quiz_statistics'), 'sd' => get_string('standarddeviationq', 'quiz_statistics'), @@ -337,9 +337,9 @@ class quiz_statistics_report extends report_base { '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); + $questionstatstable->data[] = [$labels[$item], $value]; } // Display the various bits. @@ -353,7 +353,7 @@ class quiz_statistics_report extends report_base { /** * Output question text in a box with urls appropriate for a preview of the question. * - * @param object $question question data. + * @param stdClass $question question data. * @return string HTML of question text, ready for display. */ protected function render_question_text($question) { @@ -364,14 +364,14 @@ class quiz_statistics_report extends report_base { $this->context->id, 'quiz_statistics'); return $OUTPUT->box(format_text($text, $question->questiontextformat, - array('noclean' => true, 'para' => false, 'overflowdiv' => true)), + ['noclean' => true, 'para' => false, 'overflowdiv' => true]), 'questiontext boxaligncenter generalbox boxwidthnormal mdl-align'); } /** * Display the response analysis for a question. * - * @param object $question the question to report on. + * @param stdClass $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. @@ -491,13 +491,13 @@ class quiz_statistics_report extends report_base { protected function output_quiz_info_table($quizinfo) { $quizinfotable = new html_table(); - $quizinfotable->align = array('center', 'center'); + $quizinfotable->align = ['center', 'center']; $quizinfotable->width = '60%'; $quizinfotable->attributes['class'] = 'generaltable titlesleft'; - $quizinfotable->data = array(); + $quizinfotable->data = []; foreach ($quizinfo as $heading => $value) { - $quizinfotable->data[] = array($heading, $value); + $quizinfotable->data[] = [$heading, $value]; } return html_writer::table($quizinfotable); @@ -519,8 +519,8 @@ class quiz_statistics_report extends report_base { } // Reformat the data ready for output. - $headers = array(); - $row = array(); + $headers = []; + $row = []; foreach ($quizinfo as $heading => $value) { $headers[] = $heading; $row[] = $value; @@ -546,7 +546,7 @@ class quiz_statistics_report extends report_base { $quiz = $quizorid; if (!is_object($quiz)) { - $quiz = $DB->get_record('quiz', array('id' => $quizorid), '*', MUST_EXIST); + $quiz = $DB->get_record('quiz', ['id' => $quizorid], '*', MUST_EXIST); } // Load the rest of the required data. @@ -617,7 +617,7 @@ class quiz_statistics_report extends report_base { * Get the quiz and question statistics, either by loading the cached results, * or by recomputing them. * - * @param object $quiz the quiz settings. + * @param stdClass $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 @@ -671,7 +671,7 @@ class quiz_statistics_report extends report_base { $progress->progress(3); $progress->end_progress(); - return array($quizstats, $questionstats); + return [$quizstats, $questionstats]; } /** @@ -694,8 +694,8 @@ class quiz_statistics_report extends report_base { /** * 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 stdClass[] $questions as returned by self::load_and_initialise_questions_for_calculations + * @param stdClass[] $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. @@ -720,17 +720,17 @@ class quiz_statistics_report extends report_base { /** * Analyse responses for an array of questions or sub questions. * - * @param object[] $questions as returned by self::load_and_initialise_questions_for_calculations. + * @param stdClass[] $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. */ - protected function analyse_responses_for_questions($questions, $qubaids, $whichtries, $progress = null, $done = array()) { + protected function analyse_responses_for_questions($questions, $qubaids, $whichtries, $progress = null, $done = []) { $countquestions = count($questions); if (!$countquestions) { - return array(); + return []; } if ($progress === null) { $progress = new \core\progress\none(); @@ -760,7 +760,7 @@ class quiz_statistics_report extends report_base { 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)); + $reporturl->out_omit_querystring(), 'download', $reporturl->params() + ['everything' => 1]); } /** @@ -801,7 +801,7 @@ class quiz_statistics_report extends report_base { $a->count = $count; $recalcualteurl = new moodle_url($reporturl, - array('recalculate' => 1, 'sesskey' => sesskey())); + ['recalculate' => 1, 'sesskey' => sesskey()]); $output = ''; $output .= $OUTPUT->box_start( 'boxaligncenter generalbox boxwidthnormal mdl-align', 'cachingnotice'); @@ -821,15 +821,15 @@ class quiz_statistics_report extends report_base { */ public 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())); + $DB->delete_records('quiz_statistics', ['hashcode' => $qubaids->get_hash_code()]); + $DB->delete_records('question_statistics', ['hashcode' => $qubaids->get_hash_code()]); + $DB->delete_records('question_response_analysis', ['hashcode' => $qubaids->get_hash_code()]); } /** * Load the questions in this quiz and add some properties to the objects needed in the reports. * - * @param object $quiz the quiz. + * @param stdClass $quiz the quiz. * @return array of questions for this quiz. */ public function load_and_initialise_questions_for_calculations($quiz) { diff --git a/mod/quiz/report/statistics/statistics_form.php b/mod/quiz/report/statistics/statistics_form.php index 0ca216fa889..91882d38b52 100644 --- a/mod/quiz/report/statistics/statistics_form.php +++ b/mod/quiz/report/statistics/statistics_form.php @@ -41,7 +41,7 @@ class quiz_statistics_settings_form extends moodleform { $mform->addElement('header', 'preferencespage', get_string('reportsettings', 'quiz_statistics')); - $options = array(); + $options = []; foreach (array_keys(quiz_get_grading_options()) as $which) { $options[$which] = \quiz_statistics\calculator::using_attempts_lang_string($which); } @@ -49,10 +49,10 @@ class quiz_statistics_settings_form extends moodleform { $mform->addElement('select', 'whichattempts', get_string('calculatefrom', 'quiz_statistics'), $options); if (quiz_allows_multiple_tries($this->_customdata['quiz'])) { - $mform->addElement('select', 'whichtries', get_string('whichtries', 'quiz_statistics'), array( + $mform->addElement('select', 'whichtries', get_string('whichtries', 'quiz_statistics'), [ question_attempt::FIRST_TRY => get_string('firsttry', 'question'), question_attempt::LAST_TRY => get_string('lasttry', 'question'), - question_attempt::ALL_TRIES => get_string('alltries', 'question')) + question_attempt::ALL_TRIES => get_string('alltries', 'question')] ); $mform->setDefault('whichtries', question_attempt::LAST_TRY); } diff --git a/mod/quiz/report/statistics/statistics_question_table.php b/mod/quiz/report/statistics/statistics_question_table.php index bd899421246..99bbe470a45 100644 --- a/mod/quiz/report/statistics/statistics_question_table.php +++ b/mod/quiz/report/statistics/statistics_question_table.php @@ -40,7 +40,7 @@ require_once($CFG->libdir . '/tablelib.php'); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class quiz_statistics_question_table extends flexible_table { - /** @var object full question object for this question. */ + /** @var stdClass full question object for this question. */ protected $questiondata; /** @var int no of attempts. */ @@ -60,7 +60,7 @@ class quiz_statistics_question_table extends flexible_table { * Set up columns and column names and other table settings. * * @param moodle_url $reporturl - * @param object $questiondata + * @param stdClass $questiondata * @param integer $s number of attempts on this question. * @param \core_question\statistics\responses\analysis_for_question $responseanalysis */ @@ -73,8 +73,8 @@ class quiz_statistics_question_table extends flexible_table { $this->set_attribute('class', 'generaltable generalbox boxaligncenter quizresponseanalysis'); // Define the table columns. - $columns = array(); - $headers = array(); + $columns = []; + $headers = []; if ($responseanalysis->has_subparts()) { $columns[] = 'part'; @@ -138,7 +138,7 @@ class quiz_statistics_question_table extends flexible_table { /** * The mark fraction that this response earns. - * @param object $response containst the data to display. + * @param stdClass $response containst the data to display. * @return string contents of this table cell. */ protected function col_fraction($response) { @@ -151,7 +151,7 @@ class quiz_statistics_question_table extends flexible_table { /** * The frequency with which this response was given. - * @param object $response contains the data to display. + * @param stdClass $response contains the data to display. * @return string contents of this table cell. */ protected function col_frequency($response) { @@ -167,7 +167,7 @@ class quiz_statistics_question_table extends flexible_table { * then this is the output for this cell of the table. * * @param string $colname The name of this column. - * @param object $response The raw data for this row. + * @param stdClass $response The raw data for this row. * @return string|null The value for this cell of the table or null means use raw data. */ public function other_cols($colname, $response) { diff --git a/mod/quiz/report/statistics/statistics_table.php b/mod/quiz/report/statistics/statistics_table.php index 04538b0e9c8..f0f3e1a6174 100644 --- a/mod/quiz/report/statistics/statistics_table.php +++ b/mod/quiz/report/statistics/statistics_table.php @@ -38,7 +38,7 @@ use \core_question\statistics\questions\calculated_question_summary; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class quiz_statistics_table extends flexible_table { - /** @var object the quiz settings. */ + /** @var stdClass the quiz settings. */ protected $quiz; /** @var integer the quiz course_module id. */ @@ -55,7 +55,7 @@ class quiz_statistics_table extends flexible_table { * Set up the columns and headers and other properties of the table and then * call flexible_table::setup() method. * - * @param object $quiz the quiz settings + * @param stdClass $quiz the quiz settings * @param int $cmid the quiz course_module id * @param moodle_url $reporturl the URL to redisplay this report. * @param int $s number of attempts included in the statistics. @@ -65,8 +65,8 @@ class quiz_statistics_table extends flexible_table { $this->cmid = $cmid; // Define the table columns. - $columns = array(); - $headers = array(); + $columns = []; + $headers = []; $columns[] = 'number'; $headers[] = get_string('questionnumber', 'quiz_statistics'); @@ -140,8 +140,8 @@ class quiz_statistics_table extends flexible_table { public function wrap_html_start() { // Horrible Moodle 2.0 wide-content work-around. if (!$this->is_downloading()) { - echo html_writer::start_tag('div', array('id' => 'tablecontainer', - 'class' => 'statistics-tablecontainer')); + echo html_writer::start_tag('div', ['id' => 'tablecontainer', + 'class' => 'statistics-tablecontainer']); } } @@ -245,28 +245,28 @@ class quiz_statistics_table extends flexible_table { if (!is_null($questionstat->variant)) { if ($questionstat->subquestion) { // Variant of a sub-question. - $url = new moodle_url($baseurl, array('qid' => $questionstat->questionid, 'variant' => $questionstat->variant)); - $name = html_writer::link($url, $name, array('title' => get_string('detailedanalysisforvariant', + $url = new moodle_url($baseurl, ['qid' => $questionstat->questionid, 'variant' => $questionstat->variant]); + $name = html_writer::link($url, $name, ['title' => get_string('detailedanalysisforvariant', 'quiz_statistics', - $questionstat->variant))); + $questionstat->variant)]); } else if ($questionstat->slot) { // Variant of a question in a slot. - $url = new moodle_url($baseurl, array('slot' => $questionstat->slot, 'variant' => $questionstat->variant)); - $name = html_writer::link($url, $name, array('title' => get_string('detailedanalysisforvariant', + $url = new moodle_url($baseurl, ['slot' => $questionstat->slot, 'variant' => $questionstat->variant]); + $name = html_writer::link($url, $name, ['title' => get_string('detailedanalysisforvariant', 'quiz_statistics', - $questionstat->variant))); + $questionstat->variant)]); } } else { if ($questionstat->subquestion && !$questionstat->get_variants()) { // Sub question without variants. - $url = new moodle_url($baseurl, array('qid' => $questionstat->questionid)); - $name = html_writer::link($url, $name, array('title' => get_string('detailedanalysis', 'quiz_statistics'))); + $url = new moodle_url($baseurl, ['qid' => $questionstat->questionid]); + $name = html_writer::link($url, $name, ['title' => get_string('detailedanalysis', 'quiz_statistics')]); } else if ($baseurl->param('slot') === null && $questionstat->slot) { // Question in a slot, we are not on a page showing structural analysis of one slot, // we don't want linking on those pages. $number = $questionstat->question->number; $israndomquestion = $questionstat->question->qtype == 'random'; - $url = new moodle_url($baseurl, array('slot' => $questionstat->slot)); + $url = new moodle_url($baseurl, ['slot' => $questionstat->slot]); if ($this->is_calculated_question_summary($questionstat)) { // Only make the random question summary row name link to the slot structure @@ -278,14 +278,14 @@ class quiz_statistics_table extends flexible_table { // Question cannot be broken down into sub-questions or variants. Link will show response analysis page. $name = html_writer::link($url, $name, - array('title' => get_string('detailedanalysis', 'quiz_statistics'))); + ['title' => get_string('detailedanalysis', 'quiz_statistics')]); } } } if ($this->is_dubious_question($questionstat)) { - $name = html_writer::tag('div', $name, array('class' => 'dubious')); + $name = html_writer::tag('div', $name, ['class' => 'dubious']); } if ($this->is_calculated_question_summary($questionstat)) { @@ -417,7 +417,7 @@ class quiz_statistics_table extends flexible_table { if (!$this->is_downloading()) { $negcovar = html_writer::tag('div', $negcovar . $OUTPUT->help_icon('negcovar', 'quiz_statistics'), - array('class' => 'negcovar')); + ['class' => 'negcovar']); } return $negcovar; diff --git a/mod/quiz/report/statistics/statisticslib.php b/mod/quiz/report/statistics/statisticslib.php index fa0cf2cb5c6..c4accc2232e 100644 --- a/mod/quiz/report/statistics/statisticslib.php +++ b/mod/quiz/report/statistics/statisticslib.php @@ -43,7 +43,7 @@ function quiz_statistics_attempts_sql($quizid, \core\dml\sql_join $groupstudents $whichattempts = QUIZ_GRADEAVERAGE, $includeungraded = false) { $fromqa = "{quiz_attempts} quiza "; $whereqa = 'quiza.quiz = :quizid AND quiza.preview = 0 AND quiza.state = :quizstatefinished'; - $qaparams = array('quizid' => (int)$quizid, 'quizstatefinished' => quiz_attempt::FINISHED); + $qaparams = ['quizid' => (int)$quizid, 'quizstatefinished' => quiz_attempt::FINISHED]; if (!empty($groupstudentsjoins->joins)) { $fromqa .= "\nJOIN {user} u ON u.id = quiza.userid @@ -61,7 +61,7 @@ function quiz_statistics_attempts_sql($quizid, \core\dml\sql_join $groupstudents $whereqa .= ' AND quiza.sumgrades IS NOT NULL'; } - return array($fromqa, $whereqa, $qaparams); + return [$fromqa, $whereqa, $qaparams]; } /** diff --git a/mod/quiz/report/statistics/tests/statistics_test.php b/mod/quiz/report/statistics/tests/statistics_test.php index 0706c6d3931..ed9655fb980 100644 --- a/mod/quiz/report/statistics/tests/statistics_test.php +++ b/mod/quiz/report/statistics/tests/statistics_test.php @@ -53,7 +53,7 @@ class testable_all_calculated_for_qubaid_condition extends \core_question\statis class testable_question_statistics extends \core_question\statistics\questions\calculator { /** - * @var object[] + * @var stdClass[] */ protected $lateststeps; @@ -74,7 +74,7 @@ class testable_question_statistics extends \core_question\statistics\questions\c * - $summarks array of total marks for each usage, indexed by usage id */ protected function get_latest_steps($qubaids) { - $summarks = array(); + $summarks = []; $fakeusageid = 0; foreach ($this->lateststeps as $step) { // The same 'sumgrades' field is available in step data for every slot, we will ignore all slots but slot 1. @@ -88,7 +88,7 @@ class testable_question_statistics extends \core_question\statistics\questions\c $step->questionusageid = $fakeusageid; } - return array($this->lateststeps, $summarks); + return [$this->lateststeps, $summarks]; } protected function cache_stats($qubaids) { @@ -118,27 +118,27 @@ class statistics_test extends \basic_testcase { $this->qstats = $calculator->calculate(null); // Values expected are taken from contrib/tools/quiz_tools/stats.xls. - $facility = array(0, 0, 0, 0, null, null, null, 41.19318182, 81.36363636, + $facility = [0, 0, 0, 0, null, null, null, 41.19318182, 81.36363636, 71.36363636, 65.45454545, 65.90909091, 36.36363636, 59.09090909, 50, - 59.09090909, 63.63636364, 45.45454545, 27.27272727, 50); + 59.09090909, 63.63636364, 45.45454545, 27.27272727, 50]; $this->qstats_q_fields('facility', $facility, 100); - $sd = array(0, 0, 0, 0, null, null, null, 1912.733589, 251.2738111, + $sd = [0, 0, 0, 0, null, null, null, 1912.733589, 251.2738111, 322.6312277, 333.4199022, 337.5811591, 492.3659639, 503.2362797, - 511.7663157, 503.2362797, 492.3659639, 509.6471914, 455.8423058, 511.7663157); + 511.7663157, 503.2362797, 492.3659639, 509.6471914, 455.8423058, 511.7663157]; $this->qstats_q_fields('sd', $sd, 1000); - $effectiveweight = array(0, 0, 0, 0, 0, 0, 0, 26.58464457, 3.368456046, + $effectiveweight = [0, 0, 0, 0, 0, 0, 0, 26.58464457, 3.368456046, 3.253955259, 7.584083694, 3.79658376, 3.183278505, 4.532356904, - 7.78856243, 10.08351572, 8.381139345, 8.727645713, 7.946277111, 4.769500946); + 7.78856243, 10.08351572, 8.381139345, 8.727645713, 7.946277111, 4.769500946]; $this->qstats_q_fields('effectiveweight', $effectiveweight); - $discriminationindex = array(null, null, null, null, null, null, null, + $discriminationindex = [null, null, null, null, null, null, null, 25.88327077, 1.170256965, -4.207816809, 28.16930644, -2.513606859, -12.99017581, -8.900638238, 8.670004606, 29.63337745, 15.18945843, - 16.21079629, 15.52451404, -8.396734802); + 16.21079629, 15.52451404, -8.396734802]; $this->qstats_q_fields('discriminationindex', $discriminationindex); - $discriminativeefficiency = array(null, null, null, null, null, null, null, + $discriminativeefficiency = [null, null, null, null, null, null, null, 27.23492723, 1.382386552, -4.691171307, 31.12404354, -2.877487579, -17.5074184, -10.27568922, 10.86956522, 34.58997279, 17.4790556, - 20.14359793, 22.06477733, -10); + 20.14359793, 22.06477733, -10]; $this->qstats_q_fields('discriminativeefficiency', $discriminativeefficiency); } @@ -177,7 +177,7 @@ class statistics_test extends \basic_testcase { public function get_records_from_csv($filename) { $filecontents = file($filename, FILE_IGNORE_NEW_LINES); - $records = array(); + $records = []; // Skip the first line containing field names. $keys = $this->get_fields_from_csv(array_shift($filecontents)); while (null !== ($line = array_shift($filecontents))) { diff --git a/mod/quiz/report/statistics/tests/stats_from_steps_walkthrough_test.php b/mod/quiz/report/statistics/tests/stats_from_steps_walkthrough_test.php index b467bbfe00e..2f95f61674b 100644 --- a/mod/quiz/report/statistics/tests/stats_from_steps_walkthrough_test.php +++ b/mod/quiz/report/statistics/tests/stats_from_steps_walkthrough_test.php @@ -57,7 +57,10 @@ class stats_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthrough_fr return __DIR__."/fixtures/{$setname}{$test}.csv"; } - protected $files = array('questions', 'steps', 'results', 'qstats', 'responsecounts'); + /** + * @var string[] names of the files which contain the test data. + */ + protected $files = ['questions', 'steps', 'results', 'qstats', 'responsecounts']; /** * Create a quiz add questions to it, walk through quiz attempts and then check results. @@ -90,7 +93,7 @@ class stats_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthrough_fr protected function check_question_stats($qstats, $questionstats) { foreach ($qstats as $slotqstats) { foreach ($slotqstats as $statname => $slotqstat) { - if (!in_array($statname, array('slot', 'subqname')) && $slotqstat !== '') { + if (!in_array($statname, ['slot', 'subqname']) && $slotqstat !== '') { $this->assert_stat_equals($slotqstat, $questionstats, $slotqstats['slot'], @@ -202,19 +205,19 @@ class stats_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthrough_fr $subpartid = $possibleresponsesubpartids[$subpart - 1]; if ($modelresponse == '[NO RESPONSE]') { - return array($subpartid, null); + return [$subpartid, null]; } else if ($modelresponse == '[NO MATCH]') { - return array($subpartid, 0); + return [$subpartid, 0]; } - $modelresponses = array(); + $modelresponses = []; foreach ($possibleresponses[$subpartid] as $responseclassid => $subpartpossibleresponse) { $modelresponses[$responseclassid] = $subpartpossibleresponse->responseclass; } $this->assertContains($modelresponse, $modelresponses); $responseclassid = array_search($modelresponse, $modelresponses); - return array($subpartid, $responseclassid); + return [$subpartid, $responseclassid]; } /** @@ -225,7 +228,7 @@ class stats_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthrough_fr */ protected function check_response_counts($responsecounts, $qubaids, $questions, $whichtries) { foreach ($responsecounts as $expected) { - $defaultsforexpected = array('randq' => '', 'variant' => '1', 'subpart' => '1'); + $defaultsforexpected = ['randq' => '', 'variant' => '1', 'subpart' => '1']; foreach ($defaultsforexpected as $key => $expecteddefault) { if (!isset($expected[$key])) { $expected[$key] = $expecteddefault; @@ -248,13 +251,13 @@ class stats_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthrough_fr * @param $qubaids */ protected function check_variants_count_for_quiz_00($questions, $questionstats, $whichtries, $qubaids) { - $expectedvariantcounts = array(2 => array(1 => 6, + $expectedvariantcounts = [2 => [1 => 6, 4 => 4, 5 => 3, 6 => 4, 7 => 2, 8 => 5, - 10 => 1)); + 10 => 1]]; foreach ($questions as $slot => $question) { if (!question_bank::get_qtype($question->qtype, false)->can_analyse_responses()) { @@ -268,15 +271,15 @@ class stats_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthrough_fr // Compare contents, ignore ordering of array, using canonicalize parameter of assertEquals. $this->assertEqualsCanonicalizing(array_keys($expectedvariantcounts[$slot]), $variantsnos); } else { - $this->assertEquals(array(1), $variantsnos); + $this->assertEquals([1], $variantsnos); } - $totalspervariantno = array(); + $totalspervariantno = []; foreach ($variantsnos as $variantno) { $subpartids = $analysis->get_subpart_ids($variantno); foreach ($subpartids as $subpartid) { if (!isset($totalspervariantno[$subpartid])) { - $totalspervariantno[$subpartid] = array(); + $totalspervariantno[$subpartid] = []; } $totalspervariantno[$subpartid][$variantno] = 0; @@ -326,7 +329,7 @@ class stats_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthrough_fr * @param $quizstats */ protected function check_quiz_stats_for_quiz_00($quizstats) { - $quizstatsexpected = array( + $quizstatsexpected = [ 'median' => 4.5, 'firstattemptsavg' => 4.617333332, 'allattemptsavg' => 4.617333332, @@ -338,7 +341,7 @@ class stats_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthrough_fr 'cic' => -87.2230935542, 'errorratio' => 136.8294900795, 'standarderror' => 1.1106813066 - ); + ]; foreach ($quizstatsexpected as $statname => $statvalue) { $this->assertEqualsWithDelta($statvalue, $quizstats->$statname, abs($statvalue) * 1.5e-5, $quizstats->$statname); @@ -352,7 +355,7 @@ class stats_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthrough_fr * @param string $whichattempts * @param string $whichtries * @param \core\dml\sql_join $groupstudentsjoins - * @return array with contents 0 => $questions, 1 => $quizstats, 2=> $questionstats, 3=> $qubaids Might be needed for further + * @return array with contents 0 => $questions, 1 => $quizstats, 2 => $questionstats, 3 => $qubaids Might be needed for further * testing. */ protected function check_stats_calculations_and_response_analysis($csvdata, $whichattempts, $whichtries, @@ -381,9 +384,9 @@ class stats_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthrough_fr } if (isset($csvdata['qstats'])) { $this->check_question_stats($csvdata['qstats'], $questionstats); - return array($questions, $quizstats, $questionstats, $qubaids); + return [$questions, $quizstats, $questionstats, $qubaids]; } - return array($questions, $quizstats, $questionstats, $qubaids); + return [$questions, $quizstats, $questionstats, $qubaids]; } } diff --git a/mod/quiz/review.php b/mod/quiz/review.php index 0c907c1f421..74667e8cbe6 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -38,7 +38,7 @@ $page = optional_param('page', 0, PARAM_INT); $showall = optional_param('showall', null, PARAM_BOOL); $cmid = optional_param('cmid', null, PARAM_INT); -$url = new moodle_url('/mod/quiz/review.php', array('attempt'=>$attemptid)); +$url = new moodle_url('/mod/quiz/review.php', ['attempt' => $attemptid]); if ($page !== 0) { $url->param('page', $page); } else if ($showall) { @@ -135,58 +135,58 @@ if ($attempt->state == quiz_attempt::FINISHED) { } // Prepare summary informat about the whole attempt. -$summarydata = array(); +$summarydata = []; if (!$attemptobj->get_quiz()->showuserpicture && $attemptobj->get_userid() != $USER->id) { // If showuserpicture is true, the picture is shown elsewhere, so don't repeat it. - $student = $DB->get_record('user', array('id' => $attemptobj->get_userid())); + $student = $DB->get_record('user', ['id' => $attemptobj->get_userid()]); $userpicture = new user_picture($student); $userpicture->courseid = $attemptobj->get_courseid(); - $summarydata['user'] = array( + $summarydata['user'] = [ 'title' => $userpicture, - 'content' => new action_link(new moodle_url('/user/view.php', array( - 'id' => $student->id, 'course' => $attemptobj->get_courseid())), + 'content' => new action_link(new moodle_url('/user/view.php', [ + 'id' => $student->id, 'course' => $attemptobj->get_courseid()]), fullname($student, true)), - ); + ]; } if ($attemptobj->has_capability('mod/quiz:viewreports')) { $attemptlist = $attemptobj->links_to_other_attempts($attemptobj->review_url(null, $page, $showall)); if ($attemptlist) { - $summarydata['attemptlist'] = array( + $summarydata['attemptlist'] = [ 'title' => get_string('attempts', 'quiz'), 'content' => $attemptlist, - ); + ]; } } // Timing information. -$summarydata['startedon'] = array( +$summarydata['startedon'] = [ 'title' => get_string('startedon', 'quiz'), 'content' => userdate($attempt->timestart), -); +]; -$summarydata['state'] = array( +$summarydata['state'] = [ 'title' => get_string('attemptstate', 'quiz'), 'content' => quiz_attempt::state_name($attempt->state), -); +]; if ($attempt->state == quiz_attempt::FINISHED) { - $summarydata['completedon'] = array( + $summarydata['completedon'] = [ 'title' => get_string('completedon', 'quiz'), 'content' => userdate($attempt->timefinish), - ); - $summarydata['timetaken'] = array( + ]; + $summarydata['timetaken'] = [ 'title' => get_string('timetaken', 'quiz'), 'content' => $timetaken, - ); + ]; } if (!empty($overtime)) { - $summarydata['overdue'] = array( + $summarydata['overdue'] = [ 'title' => get_string('overdue', 'quiz'), 'content' => $overtime, - ); + ]; } // Show marks (if the user is allowed to see marks at the moment). @@ -197,10 +197,10 @@ if ($options->marks >= question_display_options::MARK_AND_MAX && quiz_has_grades // Cannot display grade. } else if (is_null($grade)) { - $summarydata['grade'] = array( + $summarydata['grade'] = [ 'title' => get_string('grade', 'quiz'), 'content' => quiz_format_grade($quiz, $grade), - ); + ]; } else { // Show raw marks only if they are different from the grade (like on the view page). @@ -208,10 +208,10 @@ if ($options->marks >= question_display_options::MARK_AND_MAX && quiz_has_grades $a = new stdClass(); $a->grade = quiz_format_grade($quiz, $attempt->sumgrades); $a->maxgrade = quiz_format_grade($quiz, $quiz->sumgrades); - $summarydata['marks'] = array( + $summarydata['marks'] = [ 'title' => get_string('marks', 'quiz'), 'content' => get_string('outofshort', 'quiz', $a), - ); + ]; } // Now the scaled grade. @@ -228,10 +228,10 @@ if ($options->marks >= question_display_options::MARK_AND_MAX && quiz_has_grades } else { $formattedgrade = get_string('outof', 'quiz', $a); } - $summarydata['grade'] = array( + $summarydata['grade'] = [ 'title' => get_string('grade', 'quiz'), 'content' => $formattedgrade, - ); + ]; } } @@ -241,10 +241,10 @@ $summarydata = array_merge($summarydata, $attemptobj->get_additional_summary_dat // Feedback if there is any, and the user is allowed to see it now. $feedback = $attemptobj->get_overall_feedback($grade); if ($options->overallfeedback && $feedback) { - $summarydata['feedback'] = array( + $summarydata['feedback'] = [ 'title' => get_string('feedback', 'quiz'), 'content' => $feedback, - ); + ]; } // Summary table end. ============================================================================== diff --git a/mod/quiz/reviewquestion.php b/mod/quiz/reviewquestion.php index 9bdb904dc00..f09a15c3a0d 100644 --- a/mod/quiz/reviewquestion.php +++ b/mod/quiz/reviewquestion.php @@ -33,7 +33,7 @@ $seq = optional_param('step', null, PARAM_INT); $cmid = optional_param('cmid', null, PARAM_INT); $baseurl = new moodle_url('/mod/quiz/reviewquestion.php', - array('attempt' => $attemptid, 'slot' => $slot)); + ['attempt' => $attemptid, 'slot' => $slot]); $currenturl = new moodle_url($baseurl); if (!is_null($seq)) { $currenturl->param('step', $seq); @@ -46,15 +46,15 @@ $attemptobj->preload_all_attempt_step_users(); // Check login. require_login($attemptobj->get_course(), false, $attemptobj->get_cm()); $attemptobj->check_review_capability(); -$student = $DB->get_record('user', array('id' => $attemptobj->get_userid())); +$student = $DB->get_record('user', ['id' => $attemptobj->get_userid()]); $accessmanager = $attemptobj->get_access_manager(time()); $options = $attemptobj->get_display_options(true); $PAGE->set_pagelayout('popup'); -$PAGE->set_title(get_string('reviewofquestion', 'quiz', array( +$PAGE->set_title(get_string('reviewofquestion', 'quiz', [ 'question' => format_string($attemptobj->get_question_name($slot)), - 'quiz' => format_string($attemptobj->get_quiz_name()), 'user' => fullname($student)))); + 'quiz' => format_string($attemptobj->get_quiz_name()), 'user' => fullname($student)])); $PAGE->set_heading($attemptobj->get_course()->fullname); $output = $PAGE->get_renderer('mod_quiz'); @@ -75,48 +75,48 @@ if ($attemptobj->is_own_attempt()) { } // Prepare summary informat about this question attempt. -$summarydata = array(); +$summarydata = []; // Student name. $userpicture = new user_picture($student); $userpicture->courseid = $attemptobj->get_courseid(); -$summarydata['user'] = array( +$summarydata['user'] = [ 'title' => $userpicture, - 'content' => new action_link(new moodle_url('/user/view.php', array( - 'id' => $student->id, 'course' => $attemptobj->get_courseid())), + 'content' => new action_link(new moodle_url('/user/view.php', [ + 'id' => $student->id, 'course' => $attemptobj->get_courseid()]), fullname($student, true)), -); +]; // Quiz name. -$summarydata['quizname'] = array( +$summarydata['quizname'] = [ 'title' => get_string('modulename', 'quiz'), 'content' => format_string($attemptobj->get_quiz_name()), -); +]; // Question name. -$summarydata['questionname'] = array( +$summarydata['questionname'] = [ 'title' => get_string('question', 'quiz'), 'content' => $attemptobj->get_question_name($slot), -); +]; // Other attempts at the quiz. if ($attemptobj->has_capability('mod/quiz:viewreports')) { $attemptlist = $attemptobj->links_to_other_attempts($baseurl); if ($attemptlist) { - $summarydata['attemptlist'] = array( + $summarydata['attemptlist'] = [ 'title' => get_string('attempts', 'quiz'), 'content' => $attemptlist, - ); + ]; } } // Timestamp of this action. $timestamp = $attemptobj->get_question_action_time($slot); if ($timestamp) { - $summarydata['timestamp'] = array( + $summarydata['timestamp'] = [ 'title' => get_string('completedon', 'quiz'), 'content' => userdate($timestamp), - ); + ]; } echo $output->review_question_page($attemptobj, $slot, $seq, diff --git a/mod/quiz/settings.php b/mod/quiz/settings.php index 8c166053ff4..94f3f080b90 100644 --- a/mod/quiz/settings.php +++ b/mod/quiz/settings.php @@ -31,7 +31,7 @@ require_once($CFG->dirroot . '/mod/quiz/lib.php'); // First get a list of quiz reports with there own settings pages. If there none, // we use a simpler overall menu structure. $reports = core_component::get_plugin_list_with_file('quiz', 'settings.php', false); -$reportsbyname = array(); +$reportsbyname = []; foreach ($reports as $report => $reportdir) { $strreportname = get_string($report . 'report', 'quiz_'.$report); $reportsbyname[$strreportname] = $report; @@ -41,7 +41,7 @@ core_collator::ksort($reportsbyname); // First get a list of quiz reports with there own settings pages. If there none, // we use a simpler overall menu structure. $rules = core_component::get_plugin_list_with_file('quizaccess', 'settings.php', false); -$rulesbyname = array(); +$rulesbyname = []; foreach ($rules as $rule => $ruledir) { $strrulename = get_string('pluginname', 'quizaccess_' . $rule); $rulesbyname[$strrulename] = $rule; @@ -75,7 +75,7 @@ if ($ADMIN->fulltree) { // What to do with overdue attempts. $setting = new \mod_quiz\admin\overdue_handling_setting('quiz/overduehandling', get_string('overduehandling', 'quiz'), get_string('overduehandling_desc', 'quiz'), - array('value' => 'autosubmit', 'adv' => false), null); + ['value' => 'autosubmit', 'adv' => false], null); $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false); $quizsettings->add($setting); @@ -93,7 +93,7 @@ if ($ADMIN->fulltree) { 60, 1)); // Number of attempts. - $options = array(get_string('unlimited')); + $options = [get_string('unlimited')]; for ($i = 1; $i <= QUIZ_MAX_ATTEMPT_OPTION; $i++) { $options[$i] = $i; } @@ -107,7 +107,7 @@ if ($ADMIN->fulltree) { // Grading method. $setting = new \mod_quiz\admin\grade_method_setting('quiz/grademethod', get_string('grademethod', 'quiz'), get_string('configgrademethod', 'quiz'), - array('value' => QUIZ_GRADEHIGHEST, 'adv' => false), null); + ['value' => QUIZ_GRADEHIGHEST, 'adv' => false], null); $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false); $quizsettings->add($setting); @@ -118,7 +118,7 @@ if ($ADMIN->fulltree) { $quizsettings->add($setting); // Questions per page. - $perpage = array(); + $perpage = []; $perpage[0] = get_string('never'); $perpage[1] = get_string('aftereachquestion', 'quiz'); for ($i = 2; $i <= QUIZ_MAX_QPP_OPTION; ++$i) { @@ -158,7 +158,7 @@ if ($ADMIN->fulltree) { $setting = new admin_setting_configselect('quiz/canredoquestions', get_string('canredoquestions', 'quiz'), get_string('canredoquestions_desc', 'quiz'), 0, - array(0 => get_string('no'), 1 => get_string('canredoquestionsyes', 'quiz'))); + [0 => get_string('no'), 1 => get_string('canredoquestionsyes', 'quiz')]); $setting->set_advanced_flag_options(admin_setting_flag::ENABLED, true); $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false); $quizsettings->add($setting); @@ -191,12 +191,12 @@ if ($ADMIN->fulltree) { // Show the user's picture. $setting = new \mod_quiz\admin\user_image_setting('quiz/showuserpicture', get_string('showuserpicture', 'quiz'), get_string('configshowuserpicture', 'quiz'), - array('value' => 0, 'adv' => false), null); + ['value' => 0, 'adv' => false], null); $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false); $quizsettings->add($setting); // Decimal places for overall grades. - $options = array(); + $options = []; for ($i = 0; $i <= QUIZ_MAX_DECIMAL_OPTION; $i++) { $options[$i] = $i; } @@ -208,7 +208,7 @@ if ($ADMIN->fulltree) { $quizsettings->add($setting); // Decimal places for question grades. - $options = array(-1 => get_string('sameasoverall', 'quiz')); + $options = [-1 => get_string('sameasoverall', 'quiz')]; for ($i = 0; $i <= QUIZ_MAX_Q_DECIMAL_OPTION; $i++) { $options[$i] = $i; } @@ -262,7 +262,7 @@ if ($ADMIN->fulltree) { // Browser security. $setting = new \mod_quiz\admin\browser_security_setting('quiz/browsersecurity', get_string('showinsecurepopup', 'quiz'), get_string('configpopup', 'quiz'), - array('value' => '-', 'adv' => true), null); + ['value' => '-', 'adv' => true], null); $setting->set_locked_flag_options(admin_setting_flag::ENABLED, false); $quizsettings->add($setting); diff --git a/mod/quiz/startattempt.php b/mod/quiz/startattempt.php index b4a132f7ccc..6ea52df6da4 100644 --- a/mod/quiz/startattempt.php +++ b/mod/quiz/startattempt.php @@ -40,7 +40,7 @@ $page = optional_param('page', -1, PARAM_INT); // Page to jump to in the attempt if (!$cm = get_coursemodule_from_id('quiz', $id)) { throw new \moodle_exception('invalidcoursemodule'); } -if (!$course = $DB->get_record('course', array('id' => $cm->course))) { +if (!$course = $DB->get_record('course', ['id' => $cm->course])) { throw new \moodle_exception("coursemisconf"); } diff --git a/mod/quiz/summary.php b/mod/quiz/summary.php index f3c22ac05df..1e530682bdd 100644 --- a/mod/quiz/summary.php +++ b/mod/quiz/summary.php @@ -31,7 +31,7 @@ require_once($CFG->dirroot . '/mod/quiz/locallib.php'); $attemptid = required_param('attempt', PARAM_INT); // The attempt to summarise. $cmid = optional_param('cmid', null, PARAM_INT); -$PAGE->set_url('/mod/quiz/summary.php', array('attempt' => $attemptid)); +$PAGE->set_url('/mod/quiz/summary.php', ['attempt' => $attemptid]); // During quiz attempts, the browser back/forwards buttons should force a reload. $PAGE->set_cacheable(false); $PAGE->set_secondary_active_tab("modulepage"); diff --git a/mod/quiz/tests/attempt_test.php b/mod/quiz/tests/attempt_test.php index 7dbf1128c84..c769db1fe28 100644 --- a/mod/quiz/tests/attempt_test.php +++ b/mod/quiz/tests/attempt_test.php @@ -289,7 +289,7 @@ class attempt_test extends \advanced_testcase { $course = $this->getDataGenerator()->create_course(); $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); $student2 = $this->getDataGenerator()->create_and_enrol($course, 'student', [], 'manual', 0, 0, ENROL_USER_SUSPENDED); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); $quizobj = quiz_settings::create($quiz->id); // Login as student. diff --git a/mod/quiz/tests/attempt_walkthrough_from_csv_test.php b/mod/quiz/tests/attempt_walkthrough_from_csv_test.php index 987195e8107..86a801d442c 100644 --- a/mod/quiz/tests/attempt_walkthrough_from_csv_test.php +++ b/mod/quiz/tests/attempt_walkthrough_from_csv_test.php @@ -35,7 +35,10 @@ require_once($CFG->dirroot . '/mod/quiz/locallib.php'); */ class attempt_walkthrough_from_csv_test extends \advanced_testcase { - protected $files = array('questions', 'steps', 'results'); + /** + * @var string[] names of the files which contain the test data. + */ + protected $files = ['questions', 'steps', 'results']; /** * @var stdClass the quiz record we create. @@ -69,18 +72,18 @@ class attempt_walkthrough_from_csv_test extends \advanced_testcase { /** @var core_question_generator $questiongenerator */ $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); - $slots = array(); - $qidsbycat = array(); + $slots = []; + $qidsbycat = []; $sumofgrades = 0; foreach ($qs as $qsrow) { $q = $this->explode_dot_separated_keys_to_make_subindexs($qsrow); - $catname = array('name' => $q['cat']); - if (!$cat = $DB->get_record('question_categories', array('name' => $q['cat']))) { + $catname = ['name' => $q['cat']]; + if (!$cat = $DB->get_record('question_categories', ['name' => $q['cat']])) { $cat = $questiongenerator->create_question_category($catname); } $q['catid'] = $cat->id; - foreach (array('which' => null, 'overrides' => array()) as $key => $default) { + foreach (['which' => null, 'overrides' => []] as $key => $default) { if (empty($q[$key])) { $q[$key] = $default; } @@ -88,7 +91,7 @@ class attempt_walkthrough_from_csv_test extends \advanced_testcase { if ($q['type'] !== 'random') { // Don't actually create random questions here. - $overrides = array('category' => $cat->id, 'defaultmark' => $q['mark']) + $q['overrides']; + $overrides = ['category' => $cat->id, 'defaultmark' => $q['mark']] + $q['overrides']; if ($q['type'] === 'truefalse') { // True/false question can never have hints, but sometimes we need to put them // in the CSV file, to keep it rectangular. @@ -98,7 +101,7 @@ class attempt_walkthrough_from_csv_test extends \advanced_testcase { $q['id'] = $question->id; if (!isset($qidsbycat[$q['cat']])) { - $qidsbycat[$q['cat']] = array(); + $qidsbycat[$q['cat']] = []; } if (!empty($q['which'])) { $name = $q['type'].'_'.$q['which']; @@ -119,14 +122,14 @@ class attempt_walkthrough_from_csv_test extends \advanced_testcase { $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); // Settings from param override defaults. - $aggregratedsettings = $quizsettings + array('course' => $SITE->id, + $aggregratedsettings = $quizsettings + ['course' => $SITE->id, 'questionsperpage' => 0, 'grade' => 100.0, - 'sumgrades' => $sumofgrades); + 'sumgrades' => $sumofgrades]; $this->quiz = $quizgenerator->create_instance($aggregratedsettings); - $this->randqids = array(); + $this->randqids = []; foreach ($slots as $slotno => $slotquestion) { if ($slotquestion['type'] !== 'random') { quiz_add_quiz_question($slotquestion['id'], $this->quiz, 0, $slotquestion['mark']); @@ -174,7 +177,7 @@ class attempt_walkthrough_from_csv_test extends \advanced_testcase { * @return array */ protected function load_csv_data_file(string $setname, string $test = ''): array { - $files = array($setname => $this->get_full_path_of_csv_file($setname, $test)); + $files = [$setname => $this->get_full_path_of_csv_file($setname, $test)]; return $this->dataset_from_files($files)->get_rows([$setname]); } @@ -185,7 +188,7 @@ class attempt_walkthrough_from_csv_test extends \advanced_testcase { * @return array the row with each part of the field name following a '.' being a separate sub array's index. */ protected function explode_dot_separated_keys_to_make_subindexs(array $row): array { - $parts = array(); + $parts = []; foreach ($row as $columnkey => $value) { $newkeys = explode('.', trim($columnkey)); $placetoputvalue =& $parts; @@ -195,7 +198,7 @@ class attempt_walkthrough_from_csv_test extends \advanced_testcase { } else { // Going deeper down. if (!isset($placetoputvalue[$newkey])) { - $placetoputvalue[$newkey] = array(); + $placetoputvalue[$newkey] = []; } $placetoputvalue =& $placetoputvalue[$newkey]; } @@ -212,15 +215,15 @@ class attempt_walkthrough_from_csv_test extends \advanced_testcase { */ public function get_data_for_walkthrough(): array { $quizzes = $this->load_csv_data_file('quizzes')['quizzes']; - $datasets = array(); + $datasets = []; foreach ($quizzes as $quizsettings) { - $dataset = array(); + $dataset = []; foreach ($this->files as $file) { if (file_exists($this->get_full_path_of_csv_file($file, $quizsettings['testnumber']))) { $dataset[$file] = $this->load_csv_data_file($file, $quizsettings['testnumber'])[$file]; } } - $datasets[] = array($quizsettings, $dataset); + $datasets[] = [$quizsettings, $dataset]; } return $datasets; } @@ -231,13 +234,13 @@ class attempt_walkthrough_from_csv_test extends \advanced_testcase { */ protected function walkthrough_attempts(array $steps): array { global $DB; - $attemptids = array(); + $attemptids = []; foreach ($steps as $steprow) { $step = $this->explode_dot_separated_keys_to_make_subindexs($steprow); // Find existing user or make a new user to do the quiz. - $username = array('firstname' => $step['firstname'], - 'lastname' => $step['lastname']); + $username = ['firstname' => $step['firstname'], + 'lastname' => $step['lastname']]; if (!$user = $DB->get_record('user', $username)) { $user = $this->getDataGenerator()->create_user($username); @@ -255,7 +258,7 @@ class attempt_walkthrough_from_csv_test extends \advanced_testcase { $attempt = quiz_create_attempt($quizobj, $attemptnumber, null, $timenow, false, $user->id); // Select variant and / or random sub question. if (!isset($step['variants'])) { - $step['variants'] = array(); + $step['variants'] = []; } if (isset($step['randqs'])) { // Replace 'names' with ids. @@ -263,7 +266,7 @@ class attempt_walkthrough_from_csv_test extends \advanced_testcase { $step['randqs'][$slotno] = $this->randqids[$slotno][$randqname]; } } else { - $step['randqs'] = array(); + $step['randqs'] = []; } quiz_start_new_attempt($quizobj, $quba, $attempt, $attemptnumber, $timenow, $step['randqs'], $step['variants']); diff --git a/mod/quiz/tests/attempt_walkthrough_test.php b/mod/quiz/tests/attempt_walkthrough_test.php index b30236c97f5..ad5794d1d3c 100644 --- a/mod/quiz/tests/attempt_walkthrough_test.php +++ b/mod/quiz/tests/attempt_walkthrough_test.php @@ -48,15 +48,15 @@ class attempt_walkthrough_test extends \advanced_testcase { // Make a quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz = $quizgenerator->create_instance(array('course'=>$SITE->id, 'questionsperpage' => 0, 'grade' => 100.0, - 'sumgrades' => 3)); + $quiz = $quizgenerator->create_instance(['course' => $SITE->id, 'questionsperpage' => 0, 'grade' => 100.0, + 'sumgrades' => 3]); // Create a couple of questions. $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); - $numq = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $saq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); + $numq = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); $matchq = $questiongenerator->create_question('match', null, ['category' => $cat->id]); // Add them to the quiz. @@ -87,8 +87,8 @@ class attempt_walkthrough_test extends \advanced_testcase { // The student has not answered any questions. $this->assertEquals(3, $attemptobj->get_number_of_unanswered_questions()); - $tosubmit = array(1 => array('answer' => 'frog'), - 2 => array('answer' => '3.14')); + $tosubmit = [1 => ['answer' => 'frog'], + 2 => ['answer' => '3.14']]; $attemptobj->process_submitted_actions($timenow, false, $tosubmit); // The student has answered two questions, and only one remaining. @@ -172,7 +172,7 @@ class attempt_walkthrough_test extends \advanced_testcase { /** @var \core_question_generator $questiongenerator */ $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); + $saq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); // Add them to the quiz. quiz_add_quiz_question($saq->id, $quiz, 0, 1); @@ -275,34 +275,34 @@ class attempt_walkthrough_test extends \advanced_testcase { // Make a quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz = $quizgenerator->create_instance(array('course' => $SITE->id, 'questionsperpage' => 2, 'grade' => 100.0, - 'sumgrades' => 4)); + $quiz = $quizgenerator->create_instance(['course' => $SITE->id, 'questionsperpage' => 2, 'grade' => 100.0, + 'sumgrades' => 4]); $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); // Add two questions to question category. $cat = $questiongenerator->create_question_category(); - $saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); - $numq = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $saq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); + $numq = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); // Add random question to the quiz. quiz_add_random_questions($quiz, 0, $cat->id, 1, false); // Make another category. $cat2 = $questiongenerator->create_question_category(); - $match = $questiongenerator->create_question('match', null, array('category' => $cat->id)); + $match = $questiongenerator->create_question('match', null, ['category' => $cat->id]); quiz_add_quiz_question($match->id, $quiz, 0); - $multichoicemulti = $questiongenerator->create_question('multichoice', 'two_of_four', array('category' => $cat->id)); + $multichoicemulti = $questiongenerator->create_question('multichoice', 'two_of_four', ['category' => $cat->id]); quiz_add_quiz_question($multichoicemulti->id, $quiz, 0); - $multichoicesingle = $questiongenerator->create_question('multichoice', 'one_of_four', array('category' => $cat->id)); + $multichoicesingle = $questiongenerator->create_question('multichoice', 'one_of_four', ['category' => $cat->id]); quiz_add_quiz_question($multichoicesingle->id, $quiz, 0); - foreach (array($saq->id => 'frog', $numq->id => '3.14') as $randomqidtoselect => $randqanswer) { + foreach ([$saq->id => 'frog', $numq->id => '3.14'] as $randomqidtoselect => $randqanswer) { // Make a new user to do the quiz each loop. $user1 = $this->getDataGenerator()->create_user(); $this->setUser($user1); @@ -316,7 +316,7 @@ class attempt_walkthrough_test extends \advanced_testcase { $timenow = time(); $attempt = quiz_create_attempt($quizobj, 1, false, $timenow); - quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow, array(1 => $randomqidtoselect)); + quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow, [1 => $randomqidtoselect]); $this->assertEquals('1,2,0,3,4,0', $attempt->layout); quiz_attempt_save_started($quizobj, $quba, $attempt); @@ -326,15 +326,15 @@ class attempt_walkthrough_test extends \advanced_testcase { $this->assertFalse($attemptobj->has_response_to_at_least_one_graded_question()); $this->assertEquals(4, $attemptobj->get_number_of_unanswered_questions()); - $tosubmit = array(); + $tosubmit = []; $selectedquestionid = $quba->get_question_attempt(1)->get_question_id(); - $tosubmit[1] = array('answer' => $randqanswer); - $tosubmit[2] = array( + $tosubmit[1] = ['answer' => $randqanswer]; + $tosubmit[2] = [ 'frog' => 'amphibian', 'cat' => 'mammal', - 'newt' => 'amphibian'); - $tosubmit[3] = array('One' => '1', 'Two' => '0', 'Three' => '1', 'Four' => '0'); // First and third choice. - $tosubmit[4] = array('answer' => 'One'); // The first choice. + 'newt' => 'amphibian']; + $tosubmit[3] = ['One' => '1', 'Two' => '0', 'Three' => '1', 'Four' => '0']; // First and third choice. + $tosubmit[4] = ['answer' => 'One']; // The first choice. $attemptobj->process_submitted_actions($timenow, false, $tosubmit); @@ -371,7 +371,7 @@ class attempt_walkthrough_test extends \advanced_testcase { public function get_correct_response_for_variants() { - return array(array(1, 9.9), array(2, 8.5), array(5, 14.2), array(10, 6.8, true)); + return [[1, 9.9], [2, 8.5], [5, 14.2], [10, 6.8, true]]; } protected $quizwithvariants = null; @@ -392,15 +392,15 @@ class attempt_walkthrough_test extends \advanced_testcase { // Make a quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $this->quizwithvariants = $quizgenerator->create_instance(array('course'=>$SITE->id, + $this->quizwithvariants = $quizgenerator->create_instance(['course' => $SITE->id, 'questionsperpage' => 0, 'grade' => 100.0, - 'sumgrades' => 1)); + 'sumgrades' => 1]); $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $calc = $questiongenerator->create_question('calculatedsimple', 'sumwithvariants', array('category' => $cat->id)); + $calc = $questiongenerator->create_question('calculatedsimple', 'sumwithvariants', ['category' => $cat->id]); quiz_add_quiz_question($calc->id, $this->quizwithvariants, 0); } @@ -418,7 +418,7 @@ class attempt_walkthrough_test extends \advanced_testcase { $attempt = quiz_create_attempt($quizobj, 1, false, $timenow); // Select variant. - quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow, array(), array(1 => $variantno)); + quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow, [], [1 => $variantno]); $this->assertEquals('1,0', $attempt->layout); quiz_attempt_save_started($quizobj, $quba, $attempt); @@ -427,7 +427,7 @@ class attempt_walkthrough_test extends \advanced_testcase { $this->assertFalse($attemptobj->has_response_to_at_least_one_graded_question()); $this->assertEquals(1, $attemptobj->get_number_of_unanswered_questions()); - $tosubmit = array(1 => array('answer' => $correctresponse)); + $tosubmit = [1 => ['answer' => $correctresponse]]; $attemptobj->process_submitted_actions($timenow, false, $tosubmit); // Finish the attempt. diff --git a/mod/quiz/tests/backup/restore_date_test.php b/mod/quiz/tests/backup/restore_date_test.php index 621ee50a3d8..76dcc08c7f6 100644 --- a/mod/quiz/tests/backup/restore_date_test.php +++ b/mod/quiz/tests/backup/restore_date_test.php @@ -44,7 +44,7 @@ class restore_date_test extends \restore_date_testcase { // Create questions. $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); + $saq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); // Add to the quiz. quiz_add_quiz_question($saq->id, $quiz); diff --git a/mod/quiz/tests/behat/behat_mod_quiz.php b/mod/quiz/tests/behat/behat_mod_quiz.php index aa402076f61..a919d49b44e 100644 --- a/mod/quiz/tests/behat/behat_mod_quiz.php +++ b/mod/quiz/tests/behat/behat_mod_quiz.php @@ -162,7 +162,7 @@ class behat_mod_quiz extends behat_question_base { */ protected function get_quiz_by_name(string $name): stdClass { global $DB; - return $DB->get_record('quiz', array('name' => $name), '*', MUST_EXIST); + return $DB->get_record('quiz', ['name' => $name], '*', MUST_EXIST); } /** @@ -209,9 +209,9 @@ class behat_mod_quiz extends behat_question_base { $firstrow = $data->getRow(0); if (!in_array('question', $firstrow) && !in_array('page', $firstrow)) { if (count($firstrow) == 2) { - $headings = array('question', 'page'); + $headings = ['question', 'page']; } else if (count($firstrow) == 3) { - $headings = array('question', 'page', 'maxmark'); + $headings = ['question', 'page', 'maxmark']; } else { throw new ExpectationException('When adding questions to a quiz, you should give 2 or three 3 things: ' . ' the question name, the page number, and optionally the maximum mark. ' . @@ -296,9 +296,9 @@ class behat_mod_quiz extends behat_question_base { // Require previous. if (array_key_exists('requireprevious', $questiondata)) { if ($questiondata['requireprevious'] === '1') { - $slot = $DB->get_field('quiz_slots', 'MAX(slot)', array('quizid' => $quiz->id)); + $slot = $DB->get_field('quiz_slots', 'MAX(slot)', ['quizid' => $quiz->id]); $DB->set_field('quiz_slots', 'requireprevious', 1, - array('quizid' => $quiz->id, 'slot' => $slot)); + ['quizid' => $quiz->id, 'slot' => $slot]); } else if ($questiondata['requireprevious'] !== '' && $questiondata['requireprevious'] !== '0') { throw new ExpectationException('Require previous for question "' . $questiondata['question'] . '" should be 0, 1 or blank.', @@ -330,7 +330,7 @@ class behat_mod_quiz extends behat_question_base { public function quiz_contains_the_following_sections($quizname, TableNode $data) { global $DB; - $quiz = $DB->get_record('quiz', array('name' => $quizname), '*', MUST_EXIST); + $quiz = $DB->get_record('quiz', ['name' => $quizname], '*', MUST_EXIST); // Add the sections. $previousfirstslot = 0; @@ -349,7 +349,7 @@ class behat_mod_quiz extends behat_question_base { } if ($rownumber == 0) { - $section = $DB->get_record('quiz_sections', array('quizid' => $quiz->id), '*', MUST_EXIST); + $section = $DB->get_record('quiz_sections', ['quizid' => $quiz->id], '*', MUST_EXIST); } else { $section = new stdClass(); $section->quizid = $quiz->id; @@ -386,7 +386,7 @@ class behat_mod_quiz extends behat_question_base { } } - if ($section->firstslot > $DB->count_records('quiz_slots', array('quizid' => $quiz->id))) { + if ($section->firstslot > $DB->count_records('quiz_slots', ['quizid' => $quiz->id])) { throw new ExpectationException('The section firstslot must be less than the total number of slots in the quiz.', $this->getSession()); } @@ -412,8 +412,8 @@ class behat_mod_quiz extends behat_question_base { ]); if ($this->running_javascript()) { - $this->execute("behat_action_menu::i_open_the_action_menu_in", array('.slots', "css_element")); - $this->execute("behat_action_menu::i_choose_in_the_open_action_menu", array($addaquestion)); + $this->execute("behat_action_menu::i_open_the_action_menu_in", ['.slots', "css_element"]); + $this->execute("behat_action_menu::i_choose_in_the_open_action_menu", [$addaquestion]); } else { $this->execute('behat_general::click_link', $addaquestion); } @@ -431,7 +431,7 @@ class behat_mod_quiz extends behat_question_base { public function i_set_the_max_mark_for_quiz_question($questionname, $newmark) { $this->execute('behat_general::click_link', $this->escape(get_string('editmaxmark', 'quiz'))); - $this->execute('behat_general::wait_until_exists', array("li input[name=maxmark]", "css_element")); + $this->execute('behat_general::wait_until_exists', ["li input[name=maxmark]", "css_element"]); $this->execute('behat_general::assert_page_contains_text', $this->escape(get_string('edittitleinstructions'))); @@ -472,7 +472,7 @@ class behat_mod_quiz extends behat_question_base { "')][./preceding-sibling::li[contains(@class, 'pagenumber')][1][contains(., 'Page " . $pagenumber . "')]]"; - $this->execute('behat_general::should_exist', array($xpath, 'xpath_element')); + $this->execute('behat_general::should_exist', [$xpath, 'xpath_element']); } /** @@ -486,7 +486,7 @@ class behat_mod_quiz extends behat_question_base { "')][./preceding-sibling::li[contains(@class, 'pagenumber')][1][contains(., 'Page " . $pagenumber . "')]]"; - $this->execute('behat_general::should_not_exist', array($xpath, 'xpath_element')); + $this->execute('behat_general::should_not_exist', [$xpath, 'xpath_element']); } /** @@ -501,7 +501,7 @@ class behat_mod_quiz extends behat_question_base { "')]/following-sibling::li" . "[contains(., '" . $this->escape($secondquestionname) . "')]"; - $this->execute('behat_general::should_exist', array($xpath, 'xpath_element')); + $this->execute('behat_general::should_exist', [$xpath, 'xpath_element']); } /** @@ -517,7 +517,7 @@ class behat_mod_quiz extends behat_question_base { } $xpath = "//li[contains(@class, 'slot') and contains(., '" . $this->escape($questionname) . "')]//span[contains(@class, 'slotnumber') and normalize-space(.) = '" . $this->escape($number) . "']"; - $this->execute('behat_general::should_exist', array($xpath, 'xpath_element')); + $this->execute('behat_general::should_exist', [$xpath, 'xpath_element']); } /** @@ -540,7 +540,7 @@ class behat_mod_quiz extends behat_question_base { public function i_click_on_the_page_break_icon_after_question($addorremoves, $questionname) { $xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname); - $this->execute("behat_general::i_click_on", array($xpath, "xpath_element")); + $this->execute("behat_general::i_click_on", [$xpath, "xpath_element"]); } /** @@ -553,7 +553,7 @@ class behat_mod_quiz extends behat_question_base { public function the_page_break_icon_after_question_should_exist($addorremoves, $questionname) { $xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname); - $this->execute('behat_general::should_exist', array($xpath, 'xpath_element')); + $this->execute('behat_general::should_exist', [$xpath, 'xpath_element']); } /** @@ -566,7 +566,7 @@ class behat_mod_quiz extends behat_question_base { public function the_page_break_icon_after_question_should_not_exist($addorremoves, $questionname) { $xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname); - $this->execute('behat_general::should_not_exist', array($xpath, 'xpath_element')); + $this->execute('behat_general::should_not_exist', [$xpath, 'xpath_element']); } /** @@ -580,7 +580,7 @@ class behat_mod_quiz extends behat_question_base { public function the_page_break_link_after_question_should_contain($addorremoves, $questionname, $paramdata) { $xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname); - $this->execute("behat_general::i_click_on", array($xpath, "xpath_element")); + $this->execute("behat_general::i_click_on", [$xpath, "xpath_element"]); } /** @@ -661,7 +661,7 @@ class behat_mod_quiz extends behat_question_base { "[contains(., '" . $this->escape($target) . "')]"; $this->execute('behat_general::i_drag_and_i_drop_it_in', - array($iconxpath, 'xpath_element', $destinationxpath, 'xpath_element') + [$iconxpath, 'xpath_element', $destinationxpath, 'xpath_element'] ); } @@ -677,10 +677,10 @@ class behat_mod_quiz extends behat_question_base { "')]"; $deletexpath = "//a[contains(@class, 'editing_delete')]"; - $this->execute("behat_general::i_click_on", array($slotxpath . $deletexpath, "xpath_element")); + $this->execute("behat_general::i_click_on", [$slotxpath . $deletexpath, "xpath_element"]); $this->execute('behat_general::i_click_on_in_the', - array('Yes', "button", "Confirm", "dialogue") + ['Yes', "button", "Confirm", "dialogue"] ); } diff --git a/mod/quiz/tests/custom_completion_test.php b/mod/quiz/tests/custom_completion_test.php index bf4c6085c5d..08b87c306c2 100644 --- a/mod/quiz/tests/custom_completion_test.php +++ b/mod/quiz/tests/custom_completion_test.php @@ -25,6 +25,7 @@ use grade_item; use mod_quiz\completion\custom_completion; use question_engine; use mod_quiz\quiz_settings; +use stdClass; defined('MOODLE_INTERNAL') || die(); @@ -462,14 +463,15 @@ class custom_completion_test extends advanced_testcase { /** * Set up moduleinfo object sample data for quiz instance. * - * @param object $cm course-module instance - * @param object $quiz quiz instance data. - * @param object $course Course related data. + * @param cm_info $cm course-module instance + * @param stdClass $quiz quiz instance data. + * @param stdClass $course Course related data. * @param int $gradepass Grade to pass and completed completion. * @param string $grademethod grade attempt method. - * @return \stdClass + * @return stdClass */ - private function prepare_module_info(object $cm, object $quiz, object $course, int $gradepass, string $grademethod): \stdClass { + private function prepare_module_info(cm_info $cm, stdClass $quiz, stdClass $course, + int $gradepass, string $grademethod): \stdClass { $grouping = $this->getDataGenerator()->create_grouping(['courseid' => $course->id]); // Module test values. $moduleinfo = new \stdClass(); diff --git a/mod/quiz/tests/event/events_test.php b/mod/quiz/tests/event/events_test.php index 3ef65c3cf30..ae5dab4d5f7 100644 --- a/mod/quiz/tests/event/events_test.php +++ b/mod/quiz/tests/event/events_test.php @@ -54,8 +54,8 @@ class events_test extends \advanced_testcase { // Make a quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz = $quizgenerator->create_instance(array('course' => $course->id, 'questionsperpage' => 0, - 'grade' => 100.0, 'sumgrades' => 2)); + $quiz = $quizgenerator->create_instance(['course' => $course->id, 'questionsperpage' => 0, + 'grade' => 100.0, 'sumgrades' => 2]); $cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id); @@ -63,8 +63,8 @@ class events_test extends \advanced_testcase { $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); - $numq = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $saq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); + $numq = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); // Add them to the quiz. quiz_add_quiz_question($saq->id, $quiz); @@ -94,7 +94,7 @@ class events_test extends \advanced_testcase { quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow); quiz_attempt_save_started($quizobj, $quba, $attempt); - return array($quizobj, $quba, $attempt); + return [$quizobj, $quba, $attempt]; } /** @@ -239,8 +239,8 @@ class events_test extends \advanced_testcase { $this->assertEquals('quiz_attempt_started', $event->get_legacy_eventname()); $this->assertEquals(\context_module::instance($quizobj->get_cmid()), $event->get_context()); // Check legacy log data. - $expected = array($quizobj->get_courseid(), 'quiz', 'attempt', 'review.php?attempt=' . $attempt->id, - $quizobj->get_quizid(), $quizobj->get_cmid()); + $expected = [$quizobj->get_courseid(), 'quiz', 'attempt', 'review.php?attempt=' . $attempt->id, + $quizobj->get_quizid(), $quizobj->get_cmid()]; $this->assertEventLegacyLogData($expected, $event); // Check legacy event data. $legacydata = new \stdClass(); @@ -369,15 +369,15 @@ class events_test extends \advanced_testcase { $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); - $params = array( + $params = [ 'courseid' => $course->id, 'context' => \context_module::instance($quiz->cmid), - 'other' => array( + 'other' => [ 'quizid' => $quiz->id - ) - ); + ] + ]; $event = \mod_quiz\event\edit_page_viewed::create($params); // Trigger and capture the event. @@ -389,7 +389,7 @@ class events_test extends \advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\mod_quiz\event\edit_page_viewed', $event); $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context()); - $expected = array($course->id, 'quiz', 'editquestions', 'view.php?id=' . $quiz->cmid, $quiz->id, $quiz->cmid); + $expected = [$course->id, 'quiz', 'editquestions', 'view.php?id=' . $quiz->cmid, $quiz->id, $quiz->cmid]; $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } @@ -409,8 +409,8 @@ class events_test extends \advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\mod_quiz\event\attempt_deleted', $event); $this->assertEquals(\context_module::instance($quizobj->get_cmid()), $event->get_context()); - $expected = array($quizobj->get_courseid(), 'quiz', 'delete attempt', 'report.php?id=' . $quizobj->get_cmid(), - $attempt->id, $quizobj->get_cmid()); + $expected = [$quizobj->get_courseid(), 'quiz', 'delete attempt', 'report.php?id=' . $quizobj->get_cmid(), + $attempt->id, $quizobj->get_cmid()]; $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } @@ -441,15 +441,15 @@ class events_test extends \advanced_testcase { $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); - $params = array( + $params = [ 'context' => $context = \context_module::instance($quiz->cmid), - 'other' => array( + 'other' => [ 'quizid' => $quiz->id, 'reportname' => 'overview' - ) - ); + ] + ]; $event = \mod_quiz\event\report_viewed::create($params); // Trigger and capture the event. @@ -461,8 +461,8 @@ class events_test extends \advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\mod_quiz\event\report_viewed', $event); $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context()); - $expected = array($course->id, 'quiz', 'report', 'report.php?id=' . $quiz->cmid . '&mode=overview', - $quiz->id, $quiz->cmid); + $expected = [$course->id, 'quiz', 'report', 'report.php?id=' . $quiz->cmid . '&mode=overview', + $quiz->id, $quiz->cmid]; $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } @@ -478,17 +478,17 @@ class events_test extends \advanced_testcase { $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); - $params = array( + $params = [ 'objectid' => 1, 'relateduserid' => 2, 'courseid' => $course->id, 'context' => \context_module::instance($quiz->cmid), - 'other' => array( + 'other' => [ 'quizid' => $quiz->id - ) - ); + ] + ]; $event = \mod_quiz\event\attempt_reviewed::create($params); // Trigger and capture the event. @@ -500,7 +500,7 @@ class events_test extends \advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\mod_quiz\event\attempt_reviewed', $event); $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context()); - $expected = array($course->id, 'quiz', 'review', 'review.php?attempt=1', $quiz->id, $quiz->cmid); + $expected = [$course->id, 'quiz', 'review', 'review.php?attempt=1', $quiz->id, $quiz->cmid]; $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } @@ -516,17 +516,17 @@ class events_test extends \advanced_testcase { $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); - $params = array( + $params = [ 'objectid' => 1, 'relateduserid' => 2, 'courseid' => $course->id, 'context' => \context_module::instance($quiz->cmid), - 'other' => array( + 'other' => [ 'quizid' => $quiz->id - ) - ); + ] + ]; $event = \mod_quiz\event\attempt_summary_viewed::create($params); // Trigger and capture the event. @@ -538,7 +538,7 @@ class events_test extends \advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\mod_quiz\event\attempt_summary_viewed', $event); $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context()); - $expected = array($course->id, 'quiz', 'view summary', 'summary.php?attempt=1', $quiz->id, $quiz->cmid); + $expected = [$course->id, 'quiz', 'view summary', 'summary.php?attempt=1', $quiz->id, $quiz->cmid]; $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } @@ -554,16 +554,16 @@ class events_test extends \advanced_testcase { $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); - $params = array( + $params = [ 'objectid' => 1, 'relateduserid' => 2, 'context' => \context_module::instance($quiz->cmid), - 'other' => array( + 'other' => [ 'quizid' => $quiz->id - ) - ); + ] + ]; $event = \mod_quiz\event\user_override_created::create($params); // Trigger and capture the event. @@ -589,16 +589,16 @@ class events_test extends \advanced_testcase { $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); - $params = array( + $params = [ 'objectid' => 1, 'context' => \context_module::instance($quiz->cmid), - 'other' => array( + 'other' => [ 'quizid' => $quiz->id, 'groupid' => 2 - ) - ); + ] + ]; $event = \mod_quiz\event\group_override_created::create($params); // Trigger and capture the event. @@ -624,16 +624,16 @@ class events_test extends \advanced_testcase { $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); - $params = array( + $params = [ 'objectid' => 1, 'relateduserid' => 2, 'context' => \context_module::instance($quiz->cmid), - 'other' => array( + 'other' => [ 'quizid' => $quiz->id - ) - ); + ] + ]; $event = \mod_quiz\event\user_override_updated::create($params); // Trigger and capture the event. @@ -645,7 +645,7 @@ class events_test extends \advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\mod_quiz\event\user_override_updated', $event); $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context()); - $expected = array($course->id, 'quiz', 'edit override', 'overrideedit.php?id=1', $quiz->id, $quiz->cmid); + $expected = [$course->id, 'quiz', 'edit override', 'overrideedit.php?id=1', $quiz->id, $quiz->cmid]; $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } @@ -661,16 +661,16 @@ class events_test extends \advanced_testcase { $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); - $params = array( + $params = [ 'objectid' => 1, 'context' => \context_module::instance($quiz->cmid), - 'other' => array( + 'other' => [ 'quizid' => $quiz->id, 'groupid' => 2 - ) - ); + ] + ]; $event = \mod_quiz\event\group_override_updated::create($params); // Trigger and capture the event. @@ -682,7 +682,7 @@ class events_test extends \advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\mod_quiz\event\group_override_updated', $event); $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context()); - $expected = array($course->id, 'quiz', 'edit override', 'overrideedit.php?id=1', $quiz->id, $quiz->cmid); + $expected = [$course->id, 'quiz', 'edit override', 'overrideedit.php?id=1', $quiz->id, $quiz->cmid]; $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } @@ -697,7 +697,7 @@ class events_test extends \advanced_testcase { $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); // Create an override. $override = new \stdClass(); @@ -714,7 +714,7 @@ class events_test extends \advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\mod_quiz\event\user_override_deleted', $event); $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context()); - $expected = array($course->id, 'quiz', 'delete override', 'overrides.php?cmid=' . $quiz->cmid, $quiz->id, $quiz->cmid); + $expected = [$course->id, 'quiz', 'delete override', 'overrides.php?cmid=' . $quiz->cmid, $quiz->id, $quiz->cmid]; $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } @@ -729,7 +729,7 @@ class events_test extends \advanced_testcase { $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); // Create an override. $override = new \stdClass(); @@ -746,7 +746,7 @@ class events_test extends \advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\mod_quiz\event\group_override_deleted', $event); $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context()); - $expected = array($course->id, 'quiz', 'delete override', 'overrides.php?cmid=' . $quiz->cmid, $quiz->id, $quiz->cmid); + $expected = [$course->id, 'quiz', 'delete override', 'overrides.php?cmid=' . $quiz->cmid, $quiz->id, $quiz->cmid]; $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } @@ -762,18 +762,18 @@ class events_test extends \advanced_testcase { $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); - $params = array( + $params = [ 'objectid' => 1, 'relateduserid' => 2, 'courseid' => $course->id, 'context' => \context_module::instance($quiz->cmid), - 'other' => array( + 'other' => [ 'quizid' => $quiz->id, 'page' => 0 - ) - ); + ] + ]; $event = \mod_quiz\event\attempt_viewed::create($params); // Trigger and capture the event. @@ -785,7 +785,7 @@ class events_test extends \advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\mod_quiz\event\attempt_viewed', $event); $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context()); - $expected = array($course->id, 'quiz', 'continue attempt', 'review.php?attempt=1', $quiz->id, $quiz->cmid); + $expected = [$course->id, 'quiz', 'continue attempt', 'review.php?attempt=1', $quiz->id, $quiz->cmid]; $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } @@ -812,8 +812,8 @@ class events_test extends \advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\mod_quiz\event\attempt_preview_started', $event); $this->assertEquals(\context_module::instance($quizobj->get_cmid()), $event->get_context()); - $expected = array($quizobj->get_courseid(), 'quiz', 'preview', 'view.php?id=' . $quizobj->get_cmid(), - $quizobj->get_quizid(), $quizobj->get_cmid()); + $expected = [$quizobj->get_courseid(), 'quiz', 'preview', 'view.php?id=' . $quizobj->get_cmid(), + $quizobj->get_quizid(), $quizobj->get_cmid()]; $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } @@ -827,16 +827,16 @@ class events_test extends \advanced_testcase { public function test_question_manually_graded() { list($quizobj, $quba, $attempt) = $this->prepare_quiz_data(); - $params = array( + $params = [ 'objectid' => 1, 'courseid' => $quizobj->get_courseid(), 'context' => \context_module::instance($quizobj->get_cmid()), - 'other' => array( + 'other' => [ 'quizid' => $quizobj->get_quizid(), 'attemptid' => 2, 'slot' => 3 - ) - ); + ] + ]; $event = \mod_quiz\event\question_manually_graded::create($params); // Trigger and capture the event. @@ -848,8 +848,8 @@ class events_test extends \advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\mod_quiz\event\question_manually_graded', $event); $this->assertEquals(\context_module::instance($quizobj->get_cmid()), $event->get_context()); - $expected = array($quizobj->get_courseid(), 'quiz', 'manualgrade', 'comment.php?attempt=2&slot=3', - $quizobj->get_quizid(), $quizobj->get_cmid()); + $expected = [$quizobj->get_courseid(), 'quiz', 'manualgrade', 'comment.php?attempt=2&slot=3', + $quizobj->get_quizid(), $quizobj->get_cmid()]; $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); } @@ -861,33 +861,33 @@ class events_test extends \advanced_testcase { * create and trigger the event and ensure the event data is returned as expected. */ public function test_attempt_regraded() { - $this->resetAfterTest(); + $this->resetAfterTest(); - $this->setAdminUser(); - $course = $this->getDataGenerator()->create_course(); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $this->setAdminUser(); + $course = $this->getDataGenerator()->create_course(); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); - $params = array( - 'objectid' => 1, - 'relateduserid' => 2, - 'courseid' => $course->id, - 'context' => \context_module::instance($quiz->cmid), - 'other' => array( - 'quizid' => $quiz->id - ) - ); - $event = \mod_quiz\event\attempt_regraded::create($params); + $params = [ + 'objectid' => 1, + 'relateduserid' => 2, + 'courseid' => $course->id, + 'context' => \context_module::instance($quiz->cmid), + 'other' => [ + 'quizid' => $quiz->id + ] + ]; + $event = \mod_quiz\event\attempt_regraded::create($params); - // Trigger and capture the event. - $sink = $this->redirectEvents(); - $event->trigger(); - $events = $sink->get_events(); - $event = reset($events); + // Trigger and capture the event. + $sink = $this->redirectEvents(); + $event->trigger(); + $events = $sink->get_events(); + $event = reset($events); - // Check that the event data is valid. - $this->assertInstanceOf('\mod_quiz\event\attempt_regraded', $event); - $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context()); - $this->assertEventContextNotUsed($event); + // Check that the event data is valid. + $this->assertInstanceOf('\mod_quiz\event\attempt_regraded', $event); + $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context()); + $this->assertEventContextNotUsed($event); } /** diff --git a/mod/quiz/tests/external/external_test.php b/mod/quiz/tests/external/external_test.php index 381894dbd6f..ce3f7859925 100644 --- a/mod/quiz/tests/external/external_test.php +++ b/mod/quiz/tests/external/external_test.php @@ -94,7 +94,7 @@ class external_test extends externallib_advanced_testcase { // Setup test data. $this->course = $this->getDataGenerator()->create_course(); - $this->quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $this->course->id)); + $this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]); $this->context = \context_module::instance($this->quiz->cmid); $this->cm = get_coursemodule_from_instance('quiz', $this->quiz->id); @@ -103,8 +103,8 @@ class external_test extends externallib_advanced_testcase { $this->teacher = self::getDataGenerator()->create_user(); // Users enrolments. - $this->studentrole = $DB->get_record('role', array('shortname' => 'student')); - $this->teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher')); + $this->studentrole = $DB->get_record('role', ['shortname' => 'student']); + $this->teacherrole = $DB->get_record('role', ['shortname' => 'editingteacher']); // Allow student to receive messages. $coursecontext = \context_course::instance($this->course->id); assign_capability('mod/quiz:emailnotifysubmission', CAP_ALLOW, $this->teacherrole->id, $coursecontext, true); @@ -128,9 +128,9 @@ class external_test extends externallib_advanced_testcase { // Create a new quiz with attempts. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $data = array('course' => $this->course->id, + $data = ['course' => $this->course->id, 'sumgrades' => 2, - 'preferredbehaviour' => $behaviour); + 'preferredbehaviour' => $behaviour]; $data = array_merge($data, $extraoptions); $quiz = $quizgenerator->create_instance($data); $context = \context_module::instance($quiz->cmid); @@ -139,22 +139,22 @@ class external_test extends externallib_advanced_testcase { $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $question = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); - $question = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); if ($includeqattachments) { - $question = $questiongenerator->create_question('essay', null, array('category' => $cat->id, 'attachments' => 1, - 'attachmentsrequired' => 1)); + $question = $questiongenerator->create_question('essay', null, ['category' => $cat->id, 'attachments' => 1, + 'attachmentsrequired' => 1]); quiz_add_quiz_question($question->id, $quiz); } $quizobj = quiz_settings::create($quiz->id, $this->student->id); // Set grade to pass. - $item = \grade_item::fetch(array('courseid' => $this->course->id, 'itemtype' => 'mod', - 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id, 'outcomeid' => null)); + $item = \grade_item::fetch(['courseid' => $this->course->id, 'itemtype' => 'mod', + 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id, 'outcomeid' => null]); $item->gradepass = 80; $item->update(); @@ -171,15 +171,15 @@ class external_test extends externallib_advanced_testcase { if ($finishattempt) { // Process some responses from the student. - $tosubmit = array(1 => array('answer' => '3.14')); + $tosubmit = [1 => ['answer' => '3.14']]; $attemptobj->process_submitted_actions(time(), false, $tosubmit); // Finish the attempt. $attemptobj->process_finish(time(), false); } - return array($quiz, $context, $quizobj, $attempt, $attemptobj, $quba); + return [$quiz, $context, $quizobj, $attempt, $attemptobj, $quba]; } else { - return array($quiz, $context, $quizobj); + return [$quiz, $context, $quizobj]; } } @@ -216,17 +216,17 @@ class external_test extends externallib_advanced_testcase { // Create what we expect to be returned when querying the two courses. // First for the student user. - $allusersfields = array('id', 'coursemodule', 'course', 'name', 'intro', 'introformat', 'introfiles', 'lang', + $allusersfields = ['id', 'coursemodule', 'course', 'name', 'intro', 'introformat', 'introfiles', 'lang', 'timeopen', 'timeclose', 'grademethod', 'section', 'visible', 'groupmode', 'groupingid', 'attempts', 'timelimit', 'grademethod', 'decimalpoints', 'questiondecimalpoints', 'sumgrades', - 'grade', 'preferredbehaviour', 'hasfeedback'); - $userswithaccessfields = array('attemptonlast', 'reviewattempt', 'reviewcorrectness', 'reviewmarks', + 'grade', 'preferredbehaviour', 'hasfeedback']; + $userswithaccessfields = ['attemptonlast', 'reviewattempt', 'reviewcorrectness', 'reviewmarks', 'reviewspecificfeedback', 'reviewgeneralfeedback', 'reviewrightanswer', 'reviewoverallfeedback', 'questionsperpage', 'navmethod', 'browsersecurity', 'delay1', 'delay2', 'showuserpicture', 'showblocks', 'completionattemptsexhausted', 'completionpass', 'autosaveperiod', 'hasquestions', - 'overduehandling', 'graceperiod', 'canredoquestions', 'allowofflineattempts'); - $managerfields = array('shuffleanswers', 'timecreated', 'timemodified', 'password', 'subnet'); + 'overduehandling', 'graceperiod', 'canredoquestions', 'allowofflineattempts']; + $managerfields = ['shuffleanswers', 'timecreated', 'timemodified', 'password', 'subnet']; // Add expected coursemodule and other data. $quiz1 = $this->quiz; @@ -261,10 +261,10 @@ class external_test extends externallib_advanced_testcase { $expected2[$field] = $quiz2->{$field}; } - $expectedquizzes = array($expected2, $expected1); + $expectedquizzes = [$expected2, $expected1]; // Call the external function passing course ids. - $result = mod_quiz_external::get_quizzes_by_courses(array($course2->id, $this->course->id)); + $result = mod_quiz_external::get_quizzes_by_courses([$course2->id, $this->course->id]); $result = external_api::clean_returnvalue($returndescription, $result); $this->assertEquals($expectedquizzes, $result['quizzes']); @@ -286,7 +286,7 @@ class external_test extends externallib_advanced_testcase { $this->assertEquals($expectedquizzes, $result['quizzes']); // Call for the second course we unenrolled the user from, expected warning. - $result = mod_quiz_external::get_quizzes_by_courses(array($course2->id)); + $result = mod_quiz_external::get_quizzes_by_courses([$course2->id]); $this->assertCount(1, $result['warnings']); $this->assertEquals('1', $result['warnings'][0]['warningcode']); $this->assertEquals($course2->id, $result['warnings'][0]['itemid']); @@ -305,7 +305,7 @@ class external_test extends externallib_advanced_testcase { // Admin also should get all the information. self::setAdminUser(); - $result = mod_quiz_external::get_quizzes_by_courses(array($this->course->id)); + $result = mod_quiz_external::get_quizzes_by_courses([$this->course->id]); $result = external_api::clean_returnvalue($returndescription, $result); $this->assertEquals($expectedquizzes, $result['quizzes']); @@ -373,7 +373,7 @@ class external_test extends externallib_advanced_testcase { // Checking that the event contains the expected values. $this->assertInstanceOf('\mod_quiz\event\course_module_viewed', $event); $this->assertEquals($this->context, $event->get_context()); - $moodlequiz = new \moodle_url('/mod/quiz/view.php', array('id' => $this->cm->id)); + $moodlequiz = new \moodle_url('/mod/quiz/view.php', ['id' => $this->cm->id]); $this->assertEquals($moodlequiz, $event->get_url()); $this->assertEventContextNotUsed($event); $this->assertNotEmpty($event->get_name()); @@ -690,22 +690,22 @@ class external_test extends externallib_advanced_testcase { // Create a new quiz with attempts. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $data = array('course' => $this->course->id, - 'sumgrades' => 1); + $data = ['course' => $this->course->id, + 'sumgrades' => 1]; $quiz = $quizgenerator->create_instance($data); // Create a couple of questions. $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $question = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); $quizobj = quiz_settings::create($quiz->id, $this->student->id); // Set grade to pass. - $item = \grade_item::fetch(array('courseid' => $this->course->id, 'itemtype' => 'mod', - 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id, 'outcomeid' => null)); + $item = \grade_item::fetch(['courseid' => $this->course->id, 'itemtype' => 'mod', + 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id, 'outcomeid' => null]); $item->gradepass = 80; $item->update(); @@ -724,23 +724,23 @@ class external_test extends externallib_advanced_testcase { $result = external_api::clean_returnvalue(mod_quiz_external::get_combined_review_options_returns(), $result); // Expected values. - $expected = array( - "someoptions" => array( - array("name" => "feedback", "value" => 1), - array("name" => "generalfeedback", "value" => 1), - array("name" => "rightanswer", "value" => 1), - array("name" => "overallfeedback", "value" => 0), - array("name" => "marks", "value" => 2), - ), - "alloptions" => array( - array("name" => "feedback", "value" => 1), - array("name" => "generalfeedback", "value" => 1), - array("name" => "rightanswer", "value" => 1), - array("name" => "overallfeedback", "value" => 0), - array("name" => "marks", "value" => 2), - ), + $expected = [ + "someoptions" => [ + ["name" => "feedback", "value" => 1], + ["name" => "generalfeedback", "value" => 1], + ["name" => "rightanswer", "value" => 1], + ["name" => "overallfeedback", "value" => 0], + ["name" => "marks", "value" => 2], + ], + "alloptions" => [ + ["name" => "feedback", "value" => 1], + ["name" => "generalfeedback", "value" => 1], + ["name" => "rightanswer", "value" => 1], + ["name" => "overallfeedback", "value" => 0], + ["name" => "marks", "value" => 2], + ], "warnings" => [], - ); + ]; $this->assertEquals($expected, $result); @@ -748,23 +748,23 @@ class external_test extends externallib_advanced_testcase { $attemptobj = quiz_attempt::create($attempt->id); $attemptobj->process_finish($timenow, false); - $expected = array( - "someoptions" => array( - array("name" => "feedback", "value" => 1), - array("name" => "generalfeedback", "value" => 1), - array("name" => "rightanswer", "value" => 1), - array("name" => "overallfeedback", "value" => 1), - array("name" => "marks", "value" => 2), - ), - "alloptions" => array( - array("name" => "feedback", "value" => 1), - array("name" => "generalfeedback", "value" => 1), - array("name" => "rightanswer", "value" => 1), - array("name" => "overallfeedback", "value" => 1), - array("name" => "marks", "value" => 2), - ), + $expected = [ + "someoptions" => [ + ["name" => "feedback", "value" => 1], + ["name" => "generalfeedback", "value" => 1], + ["name" => "rightanswer", "value" => 1], + ["name" => "overallfeedback", "value" => 1], + ["name" => "marks", "value" => 2], + ], + "alloptions" => [ + ["name" => "feedback", "value" => 1], + ["name" => "generalfeedback", "value" => 1], + ["name" => "rightanswer", "value" => 1], + ["name" => "overallfeedback", "value" => 1], + ["name" => "marks", "value" => 2], + ], "warnings" => [], - ); + ]; // We should see now the overall feedback. $result = mod_quiz_external::get_combined_review_options($quiz->id); @@ -779,23 +779,23 @@ class external_test extends externallib_advanced_testcase { quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow); quiz_attempt_save_started($quizobj, $quba, $attempt); - $expected = array( - "someoptions" => array( - array("name" => "feedback", "value" => 1), - array("name" => "generalfeedback", "value" => 1), - array("name" => "rightanswer", "value" => 1), - array("name" => "overallfeedback", "value" => 1), - array("name" => "marks", "value" => 2), - ), - "alloptions" => array( - array("name" => "feedback", "value" => 1), - array("name" => "generalfeedback", "value" => 1), - array("name" => "rightanswer", "value" => 1), - array("name" => "overallfeedback", "value" => 0), - array("name" => "marks", "value" => 2), - ), + $expected = [ + "someoptions" => [ + ["name" => "feedback", "value" => 1], + ["name" => "generalfeedback", "value" => 1], + ["name" => "rightanswer", "value" => 1], + ["name" => "overallfeedback", "value" => 1], + ["name" => "marks", "value" => 2], + ], + "alloptions" => [ + ["name" => "feedback", "value" => 1], + ["name" => "generalfeedback", "value" => 1], + ["name" => "rightanswer", "value" => 1], + ["name" => "overallfeedback", "value" => 0], + ["name" => "marks", "value" => 2], + ], "warnings" => [], - ); + ]; $result = mod_quiz_external::get_combined_review_options($quiz->id); $result = external_api::clean_returnvalue(mod_quiz_external::get_combined_review_options_returns(), $result); @@ -846,14 +846,14 @@ class external_test extends externallib_advanced_testcase { $DB->update_record('quiz', $quiz); try { - mod_quiz_external::start_attempt($quiz->id, array(array("name" => "quizpassword", "value" => 'bad'))); + mod_quiz_external::start_attempt($quiz->id, [["name" => "quizpassword", "value" => 'bad']]); $this->fail('Exception expected due to invalid passwod.'); } catch (moodle_exception $e) { $this->assertEquals(get_string('passworderror', 'quizaccess_password'), $e->errorcode); } // Now, try everything correct. - $result = mod_quiz_external::start_attempt($quiz->id, array(array("name" => "quizpassword", "value" => 'abc'))); + $result = mod_quiz_external::start_attempt($quiz->id, [["name" => "quizpassword", "value" => 'abc']]); $result = external_api::clean_returnvalue(mod_quiz_external::start_attempt_returns(), $result); $this->assertEquals(1, $result['attempt']['attempt']); @@ -865,7 +865,7 @@ class external_test extends externallib_advanced_testcase { // We are good, try to start a new attempt now. try { - mod_quiz_external::start_attempt($quiz->id, array(array("name" => "quizpassword", "value" => 'abc'))); + mod_quiz_external::start_attempt($quiz->id, [["name" => "quizpassword", "value" => 'abc']]); $this->fail('Exception expected due to attempt not finished.'); } catch (moodle_exception $e) { $this->assertEquals('attemptstillinprogress', $e->errorcode); @@ -876,7 +876,7 @@ class external_test extends externallib_advanced_testcase { // Process some responses from the student. $timenow = time(); $attemptobj = quiz_attempt::create($attemptid); - $tosubmit = array(1 => array('answer' => '3.14')); + $tosubmit = [1 => ['answer' => '3.14']]; $attemptobj->process_submitted_actions($timenow, false, $tosubmit); // Finish the attempt. @@ -885,7 +885,7 @@ class external_test extends externallib_advanced_testcase { $attemptobj->process_finish($timenow, false); // We should be able to start a new attempt. - $result = mod_quiz_external::start_attempt($quiz->id, array(array("name" => "quizpassword", "value" => 'abc'))); + $result = mod_quiz_external::start_attempt($quiz->id, [["name" => "quizpassword", "value" => 'abc']]); $result = external_api::clean_returnvalue(mod_quiz_external::start_attempt_returns(), $result); $this->assertEquals(2, $result['attempt']['attempt']); @@ -922,7 +922,7 @@ class external_test extends externallib_advanced_testcase { // Invalid attempt. try { - $params = array('attemptid' => -1, 'page' => 0); + $params = ['attemptid' => -1, 'page' => 0]; testable_mod_quiz_external::validate_attempt($params); $this->fail('Exception expected due to invalid attempt id.'); } catch (\dml_missing_record_exception $e) { @@ -930,7 +930,7 @@ class external_test extends externallib_advanced_testcase { } // Test OK case. - $params = array('attemptid' => $attempt->id, 'page' => 0); + $params = ['attemptid' => $attempt->id, 'page' => 0]; $result = testable_mod_quiz_external::validate_attempt($params); $this->assertEquals($attempt->id, $result[0]->get_attempt()->id); $this->assertEquals([], $result[1]); @@ -940,8 +940,8 @@ class external_test extends externallib_advanced_testcase { $DB->update_record('quiz', $quiz); try { - $params = array('attemptid' => $attempt->id, 'page' => 0, - 'preflightdata' => array(array("name" => "quizpassword", "value" => 'bad'))); + $params = ['attemptid' => $attempt->id, 'page' => 0, + 'preflightdata' => [["name" => "quizpassword", "value" => 'bad']]]; testable_mod_quiz_external::validate_attempt($params); $this->fail('Exception expected due to invalid passwod.'); } catch (moodle_exception $e) { @@ -1029,7 +1029,7 @@ class external_test extends externallib_advanced_testcase { list($quiz, $context, $quizobj, $attempt, $attemptobj) = $this->create_quiz_with_questions(true); // Set correctness mask so questions state can be fetched only after finishing the attempt. - $DB->set_field('quiz', 'reviewcorrectness', display_options::IMMEDIATELY_AFTER, array('id' => $quiz->id)); + $DB->set_field('quiz', 'reviewcorrectness', display_options::IMMEDIATELY_AFTER, ['id' => $quiz->id]); $quizobj = $attemptobj->get_quizobj(); $quizobj->preload_questions(); @@ -1200,7 +1200,7 @@ class external_test extends externallib_advanced_testcase { $this->assertCount(4, (array) json_decode($result['questions'][0]['settings'])); // Submit a response for the first question. - $tosubmit = array(1 => array('answer' => '3.14')); + $tosubmit = [1 => ['answer' => '3.14']]; $attemptobj->process_submitted_actions(time(), false, $tosubmit); $result = mod_quiz_external::get_attempt_summary($attempt->id); $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result); @@ -1234,12 +1234,12 @@ class external_test extends externallib_advanced_testcase { // Response for slot 1. $prefix = $quba->get_field_prefix(1); - $data = array( - array('name' => 'slots', 'value' => 1), - array('name' => $prefix . ':sequencecheck', - 'value' => $attemptobj->get_question_attempt(1)->get_sequence_check_count()), - array('name' => $prefix . 'answer', 'value' => 1), - ); + $data = [ + ['name' => 'slots', 'value' => 1], + ['name' => $prefix . ':sequencecheck', + 'value' => $attemptobj->get_question_attempt(1)->get_sequence_check_count()], + ['name' => $prefix . 'answer', 'value' => 1], + ]; $this->setUser($this->student); @@ -1269,12 +1269,12 @@ class external_test extends externallib_advanced_testcase { // Now, second slot. $prefix = $quba->get_field_prefix(2); - $data = array( - array('name' => 'slots', 'value' => 2), - array('name' => $prefix . ':sequencecheck', - 'value' => $attemptobj->get_question_attempt(1)->get_sequence_check_count()), - array('name' => $prefix . 'answer', 'value' => 1), - ); + $data = [ + ['name' => 'slots', 'value' => 2], + ['name' => $prefix . ':sequencecheck', + 'value' => $attemptobj->get_question_attempt(1)->get_sequence_check_count()], + ['name' => $prefix . 'answer', 'value' => 1], + ]; $result = mod_quiz_external::save_attempt($attempt->id, $data); $result = external_api::clean_returnvalue(mod_quiz_external::save_attempt_returns(), $result); @@ -1305,12 +1305,12 @@ class external_test extends externallib_advanced_testcase { // Response for slot 1. $prefix = $quba->get_field_prefix(1); - $data = array( - array('name' => 'slots', 'value' => 1), - array('name' => $prefix . ':sequencecheck', - 'value' => $attemptobj->get_question_attempt(1)->get_sequence_check_count()), - array('name' => $prefix . 'answer', 'value' => 1), - ); + $data = [ + ['name' => 'slots', 'value' => 1], + ['name' => $prefix . ':sequencecheck', + 'value' => $attemptobj->get_question_attempt(1)->get_sequence_check_count()], + ['name' => $prefix . 'answer', 'value' => 1], + ]; $this->setUser($this->student); @@ -1342,13 +1342,13 @@ class external_test extends externallib_advanced_testcase { // Now, second slot. $prefix = $quba->get_field_prefix(2); - $data = array( - array('name' => 'slots', 'value' => 2), - array('name' => $prefix . ':sequencecheck', - 'value' => $attemptobj->get_question_attempt(1)->get_sequence_check_count()), - array('name' => $prefix . 'answer', 'value' => 1), - array('name' => $prefix . ':flagged', 'value' => 1), - ); + $data = [ + ['name' => 'slots', 'value' => 2], + ['name' => $prefix . ':sequencecheck', + 'value' => $attemptobj->get_question_attempt(1)->get_sequence_check_count()], + ['name' => $prefix . 'answer', 'value' => 1], + ['name' => $prefix . ':flagged', 'value' => 1], + ]; $result = mod_quiz_external::process_attempt($attempt->id, $data); $result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result); @@ -1366,27 +1366,27 @@ class external_test extends externallib_advanced_testcase { // Add files in the attachment response. $draftitemid = file_get_unused_draft_itemid(); - $filerecordinline = array( + $filerecordinline = [ 'contextid' => \context_user::instance($this->student->id)->id, 'component' => 'user', 'filearea' => 'draft', 'itemid' => $draftitemid, 'filepath' => '/', 'filename' => 'faketxt.txt', - ); + ]; $fs = get_file_storage(); $fs->create_file_from_string($filerecordinline, 'fake txt contents 1.'); // Last slot. $prefix = $quba->get_field_prefix(3); - $data = array( - array('name' => 'slots', 'value' => 3), - array('name' => $prefix . ':sequencecheck', - 'value' => $attemptobj->get_question_attempt(1)->get_sequence_check_count()), - array('name' => $prefix . 'answer', 'value' => 'Some test'), - array('name' => $prefix . 'answerformat', 'value' => FORMAT_HTML), - array('name' => $prefix . 'attachments', 'value' => $draftitemid), - ); + $data = [ + ['name' => 'slots', 'value' => 3], + ['name' => $prefix . ':sequencecheck', + 'value' => $attemptobj->get_question_attempt(1)->get_sequence_check_count()], + ['name' => $prefix . 'answer', 'value' => 'Some test'], + ['name' => $prefix . 'answerformat', 'value' => FORMAT_HTML], + ['name' => $prefix . 'attachments', 'value' => $draftitemid], + ]; $result = mod_quiz_external::process_attempt($attempt->id, $data); $result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result); @@ -1411,7 +1411,7 @@ class external_test extends externallib_advanced_testcase { // Finish the attempt. $sink = $this->redirectMessages(); - $result = mod_quiz_external::process_attempt($attempt->id, array(), true); + $result = mod_quiz_external::process_attempt($attempt->id, [], true); $result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result); $this->assertEquals(quiz_attempt::FINISHED, $result['state']); $messages = $sink->get_messages(); @@ -1441,7 +1441,7 @@ class external_test extends externallib_advanced_testcase { $quiz->overduehandling = 'graceperiod'; $DB->update_record('quiz', $quiz); - $result = mod_quiz_external::process_attempt($attempt->id, array()); + $result = mod_quiz_external::process_attempt($attempt->id, []); $result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result); $this->assertEquals(quiz_attempt::OVERDUE, $result['state']); @@ -1459,7 +1459,7 @@ class external_test extends externallib_advanced_testcase { quiz_start_new_attempt($quizobj, $quba, $attempt, 2, $timenow - 10); quiz_attempt_save_started($quizobj, $quba, $attempt); - $result = mod_quiz_external::process_attempt($attempt->id, array()); + $result = mod_quiz_external::process_attempt($attempt->id, []); $result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result); $this->assertEquals(quiz_attempt::OVERDUE, $result['state']); @@ -1475,7 +1475,7 @@ class external_test extends externallib_advanced_testcase { $quiz->timeclose = $timenow - HOURSECS; $DB->update_record('quiz', $quiz); - $result = mod_quiz_external::process_attempt($attempt->id, array()); + $result = mod_quiz_external::process_attempt($attempt->id, []); $result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result); $this->assertEquals(quiz_attempt::ABANDONED, $result['state']); @@ -1494,7 +1494,7 @@ class external_test extends externallib_advanced_testcase { // Invalid attempt, invalid id. try { - $params = array('attemptid' => -1); + $params = ['attemptid' => -1]; testable_mod_quiz_external::validate_attempt_review($params); $this->fail('Exception expected due invalid id.'); } catch (\dml_missing_record_exception $e) { @@ -1503,7 +1503,7 @@ class external_test extends externallib_advanced_testcase { // Invalid attempt, not closed. try { - $params = array('attemptid' => $attempt->id); + $params = ['attemptid' => $attempt->id]; testable_mod_quiz_external::validate_attempt_review($params); $this->fail('Exception expected due not closed attempt.'); } catch (moodle_exception $e) { @@ -1513,7 +1513,7 @@ class external_test extends externallib_advanced_testcase { // Test ok case (finished attempt). list($quiz, $context, $quizobj, $attempt, $attemptobj) = $this->create_quiz_with_questions(true, true); - $params = array('attemptid' => $attempt->id); + $params = ['attemptid' => $attempt->id]; testable_mod_quiz_external::validate_attempt_review($params); // Teacher should be able to view the review of one student's attempt. @@ -1526,7 +1526,7 @@ class external_test extends externallib_advanced_testcase { $this->setUser($anotherstudent); try { - $params = array('attemptid' => $attempt->id); + $params = ['attemptid' => $attempt->id]; testable_mod_quiz_external::validate_attempt_review($params); $this->fail('Exception expected due missing permissions.'); } catch (moodle_exception $e) { @@ -1627,10 +1627,10 @@ class external_test extends externallib_advanced_testcase { $this->assertNotEmpty($event->get_name()); // Now, force the quiz with QUIZ_NAVMETHOD_SEQ (sequential) navigation method. - $DB->set_field('quiz', 'navmethod', QUIZ_NAVMETHOD_SEQ, array('id' => $quiz->id)); + $DB->set_field('quiz', 'navmethod', QUIZ_NAVMETHOD_SEQ, ['id' => $quiz->id]); // Quiz requiring preflightdata. - $DB->set_field('quiz', 'password', 'abcdef', array('id' => $quiz->id)); - $preflightdata = array(array("name" => "quizpassword", "value" => 'abcdef')); + $DB->set_field('quiz', 'password', 'abcdef', ['id' => $quiz->id]); + $preflightdata = [["name" => "quizpassword", "value" => 'abcdef']]; // See next page. $result = mod_quiz_external::view_attempt($attempt->id, 1, $preflightdata); @@ -1676,14 +1676,14 @@ class external_test extends externallib_advanced_testcase { // Checking that the event contains the expected values. $this->assertInstanceOf('\mod_quiz\event\attempt_summary_viewed', $event); $this->assertEquals($context, $event->get_context()); - $moodlequiz = new \moodle_url('/mod/quiz/summary.php', array('attempt' => $attempt->id)); + $moodlequiz = new \moodle_url('/mod/quiz/summary.php', ['attempt' => $attempt->id]); $this->assertEquals($moodlequiz, $event->get_url()); $this->assertEventContextNotUsed($event); $this->assertNotEmpty($event->get_name()); // Quiz requiring preflightdata. - $DB->set_field('quiz', 'password', 'abcdef', array('id' => $quiz->id)); - $preflightdata = array(array("name" => "quizpassword", "value" => 'abcdef')); + $DB->set_field('quiz', 'password', 'abcdef', ['id' => $quiz->id]); + $preflightdata = [["name" => "quizpassword", "value" => 'abcdef']]; $result = mod_quiz_external::view_attempt_summary($attempt->id, $preflightdata); $result = external_api::clean_returnvalue(mod_quiz_external::view_attempt_summary_returns(), $result); @@ -1717,7 +1717,7 @@ class external_test extends externallib_advanced_testcase { // Checking that the event contains the expected values. $this->assertInstanceOf('\mod_quiz\event\attempt_reviewed', $event); $this->assertEquals($context, $event->get_context()); - $moodlequiz = new \moodle_url('/mod/quiz/review.php', array('attempt' => $attempt->id)); + $moodlequiz = new \moodle_url('/mod/quiz/review.php', ['attempt' => $attempt->id]); $this->assertEquals($moodlequiz, $event->get_url()); $this->assertEventContextNotUsed($event); $this->assertNotEmpty($event->get_name()); @@ -1740,14 +1740,14 @@ class external_test extends externallib_advanced_testcase { $feedback->id = $DB->insert_record('quiz_feedback', $feedback); // Add a fake inline image to the feedback text. $filename = 'shouldbeanimage.jpg'; - $filerecordinline = array( + $filerecordinline = [ 'contextid' => $this->context->id, 'component' => 'mod_quiz', 'filearea' => 'feedback', 'itemid' => $feedback->id, 'filepath' => '/', 'filename' => $filename, - ); + ]; $fs = get_file_storage(); $fs->create_file_from_string($filerecordinline, 'image contents (not really)'); @@ -1782,7 +1782,7 @@ class external_test extends externallib_advanced_testcase { // Create a new quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $data = array('course' => $this->course->id); + $data = ['course' => $this->course->id]; $quiz = $quizgenerator->create_instance($data); $this->setUser($this->student); @@ -1791,7 +1791,7 @@ class external_test extends externallib_advanced_testcase { $result = mod_quiz_external::get_quiz_access_information($quiz->id); $result = external_api::clean_returnvalue(mod_quiz_external::get_quiz_access_information_returns(), $result); - $expected = array( + $expected = [ 'canattempt' => true, 'canmanage' => false, 'canpreview' => false, @@ -1802,7 +1802,7 @@ class external_test extends externallib_advanced_testcase { 'activerulenames' => ['quizaccess_openclosedate'], 'preventaccessreasons' => [], 'warnings' => [] - ); + ]; $this->assertEquals($expected, $result); @@ -1847,31 +1847,31 @@ class external_test extends externallib_advanced_testcase { // Create a new quiz with attempts. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $data = array('course' => $this->course->id, - 'sumgrades' => 2); + $data = ['course' => $this->course->id, + 'sumgrades' => 2]; $quiz = $quizgenerator->create_instance($data); // Create some questions. $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $question = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); - $question = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); // Add new question types in the category (for the random one). - $question = $questiongenerator->create_question('truefalse', null, array('category' => $cat->id)); - $question = $questiongenerator->create_question('essay', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('truefalse', null, ['category' => $cat->id]); + $question = $questiongenerator->create_question('essay', null, ['category' => $cat->id]); quiz_add_random_questions($quiz, 0, $cat->id, 1, false); $quizobj = quiz_settings::create($quiz->id, $this->student->id); // Set grade to pass. - $item = \grade_item::fetch(array('courseid' => $this->course->id, 'itemtype' => 'mod', - 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id, 'outcomeid' => null)); + $item = \grade_item::fetch(['courseid' => $this->course->id, 'itemtype' => 'mod', + 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id, 'outcomeid' => null]); $item->gradepass = 80; $item->update(); @@ -1881,11 +1881,11 @@ class external_test extends externallib_advanced_testcase { $result = mod_quiz_external::get_attempt_access_information($quiz->id); $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_access_information_returns(), $result); - $expected = array( + $expected = [ 'isfinished' => false, 'preventnewattemptreasons' => [], 'warnings' => [] - ); + ]; $this->assertEquals($expected, $result); @@ -1904,7 +1904,7 @@ class external_test extends externallib_advanced_testcase { // Process some responses from the student. $attemptobj = quiz_attempt::create($attempt->id); - $tosubmit = array(1 => array('answer' => '3.14')); + $tosubmit = [1 => ['answer' => '3.14']]; $attemptobj->process_submitted_actions($timenow, false, $tosubmit); // Finish the attempt. @@ -1931,23 +1931,23 @@ class external_test extends externallib_advanced_testcase { // Create a new quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $data = array('course' => $this->course->id); + $data = ['course' => $this->course->id]; $quiz = $quizgenerator->create_instance($data); // Create some questions. $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $question = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); - $question = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); - $question = $questiongenerator->create_question('truefalse', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('truefalse', null, ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); - $question = $questiongenerator->create_question('essay', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('essay', null, ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); $this->setUser($this->student); @@ -1955,10 +1955,10 @@ class external_test extends externallib_advanced_testcase { $result = mod_quiz_external::get_quiz_required_qtypes($quiz->id); $result = external_api::clean_returnvalue(mod_quiz_external::get_quiz_required_qtypes_returns(), $result); - $expected = array( + $expected = [ 'questiontypes' => ['essay', 'numerical', 'shortanswer', 'truefalse'], 'warnings' => [] - ); + ]; $this->assertEquals($expected, $result); @@ -2115,8 +2115,8 @@ class external_test extends externallib_advanced_testcase { $quizobj = quiz_settings::create($quiz->id, $this->student->id); // Set grade to pass. - $item = \grade_item::fetch(array('courseid' => $this->course->id, 'itemtype' => 'mod', - 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id, 'outcomeid' => null)); + $item = \grade_item::fetch(['courseid' => $this->course->id, 'itemtype' => 'mod', + 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id, 'outcomeid' => null]); $item->gradepass = 80; $item->update(); return $quizobj; diff --git a/mod/quiz/tests/generator/lib.php b/mod/quiz/tests/generator/lib.php index 416000b1239..9e175f958cf 100644 --- a/mod/quiz/tests/generator/lib.php +++ b/mod/quiz/tests/generator/lib.php @@ -34,7 +34,7 @@ class mod_quiz_generator extends testing_module_generator { require_once($CFG->dirroot.'/mod/quiz/locallib.php'); $record = (object)(array)$record; - $defaultquizsettings = array( + $defaultquizsettings = [ 'timeopen' => 0, 'timeclose' => 0, 'preferredbehaviour' => 'deferredfeedback', @@ -88,7 +88,7 @@ class mod_quiz_generator extends testing_module_generator { 'showuserpicture' => 0, 'showblocks' => 0, 'navmethod' => QUIZ_NAVMETHOD_FREE, - ); + ]; foreach ($defaultquizsettings as $name => $value) { if (!isset($record->{$name})) { diff --git a/mod/quiz/tests/generator_test.php b/mod/quiz/tests/generator_test.php index 6d8c0ead5e3..76435349233 100644 --- a/mod/quiz/tests/generator_test.php +++ b/mod/quiz/tests/generator_test.php @@ -38,10 +38,10 @@ class generator_test extends \advanced_testcase { $this->assertInstanceOf('mod_quiz_generator', $generator); $this->assertEquals('quiz', $generator->get_modulename()); - $generator->create_instance(array('course'=>$SITE->id)); - $generator->create_instance(array('course'=>$SITE->id)); + $generator->create_instance(['course' => $SITE->id]); + $generator->create_instance(['course' => $SITE->id]); $createtime = time(); - $quiz = $generator->create_instance(array('course' => $SITE->id, 'timecreated' => 0)); + $quiz = $generator->create_instance(['course' => $SITE->id, 'timecreated' => 0]); $this->assertEquals(3, $DB->count_records('quiz')); $cm = get_coursemodule_from_instance('quiz', $quiz->id); diff --git a/mod/quiz/tests/lib_test.php b/mod/quiz/tests/lib_test.php index a4826dd8845..b11be05e4b1 100644 --- a/mod/quiz/tests/lib_test.php +++ b/mod/quiz/tests/lib_test.php @@ -101,35 +101,35 @@ class lib_test extends \advanced_testcase { // Setup a quiz with 1 standard and 1 random question. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz = $quizgenerator->create_instance(array('course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0)); + $quiz = $quizgenerator->create_instance(['course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0]); $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $standardq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); + $standardq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); quiz_add_quiz_question($standardq->id, $quiz); quiz_add_random_questions($quiz, 0, $cat->id, 1, false); // Get the random question. - $randomq = $DB->get_record('question', array('qtype' => 'random')); + $randomq = $DB->get_record('question', ['qtype' => 'random']); quiz_delete_instance($quiz->id); // Check that the random question was deleted. if ($randomq) { - $count = $DB->count_records('question', array('id' => $randomq->id)); + $count = $DB->count_records('question', ['id' => $randomq->id]); $this->assertEquals(0, $count); } // Check that the standard question was not deleted. - $count = $DB->count_records('question', array('id' => $standardq->id)); + $count = $DB->count_records('question', ['id' => $standardq->id]); $this->assertEquals(1, $count); // Check that all the slots were removed. - $count = $DB->count_records('quiz_slots', array('quizid' => $quiz->id)); + $count = $DB->count_records('quiz_slots', ['quizid' => $quiz->id]); $this->assertEquals(0, $count); // Check that the quiz was removed. - $count = $DB->count_records('quiz', array('id' => $quiz->id)); + $count = $DB->count_records('quiz', ['id' => $quiz->id]); $this->assertEquals(0, $count); } @@ -662,8 +662,8 @@ class lib_test extends \advanced_testcase { $this->assertNull(quiz_get_group_override_priorities($quiz->id)); - $group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id)); - $group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id)); + $group1 = $this->getDataGenerator()->create_group(['courseid' => $course->id]); + $group2 = $this->getDataGenerator()->create_group(['courseid' => $course->id]); $now = 100; $override1 = (object)[ @@ -706,8 +706,8 @@ class lib_test extends \advanced_testcase { // Create a student and enrol into the course. $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); // Create a quiz. - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id, - 'timeopen' => time() - DAYSECS, 'timeclose' => time() + DAYSECS)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id, + 'timeopen' => time() - DAYSECS, 'timeclose' => time() + DAYSECS]); // Create a calendar event. $event = $this->create_action_event($course->id, $quiz->id, QUIZ_EVENT_TYPE_OPEN); @@ -737,8 +737,8 @@ class lib_test extends \advanced_testcase { // Create a student and enrol into the course. $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); // Create a quiz. - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id, - 'timeopen' => time() - DAYSECS, 'timeclose' => time() + DAYSECS)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id, + 'timeopen' => time() - DAYSECS, 'timeclose' => time() + DAYSECS]); // Create a calendar event. $event = $this->create_action_event($course->id, $quiz->id, QUIZ_EVENT_TYPE_OPEN); @@ -766,8 +766,8 @@ class lib_test extends \advanced_testcase { $course = $this->getDataGenerator()->create_course(); // Create a quiz. - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id, - 'timeclose' => time() - DAYSECS)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id, + 'timeclose' => time() - DAYSECS]); // Create a calendar event. $event = $this->create_action_event($course->id, $quiz->id, QUIZ_EVENT_TYPE_CLOSE); @@ -791,8 +791,8 @@ class lib_test extends \advanced_testcase { $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); // Create a quiz. - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id, - 'timeclose' => time() - DAYSECS)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id, + 'timeclose' => time() - DAYSECS]); // Create a calendar event. $event = $this->create_action_event($course->id, $quiz->id, QUIZ_EVENT_TYPE_CLOSE); @@ -814,8 +814,8 @@ class lib_test extends \advanced_testcase { // Create a student and enrol into the course. $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); // Create a quiz. - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id, - 'timeopen' => time() + DAYSECS)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id, + 'timeopen' => time() + DAYSECS]); // Create a calendar event. $event = $this->create_action_event($course->id, $quiz->id, QUIZ_EVENT_TYPE_CLOSE); @@ -845,8 +845,8 @@ class lib_test extends \advanced_testcase { // Create a student and enrol into the course. $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); // Create a quiz. - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id, - 'timeopen' => time() + DAYSECS)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id, + 'timeopen' => time() + DAYSECS]); // Create a calendar event. $event = $this->create_action_event($course->id, $quiz->id, QUIZ_EVENT_TYPE_CLOSE); @@ -876,13 +876,13 @@ class lib_test extends \advanced_testcase { // Create a student. $student = $this->getDataGenerator()->create_user(); - $studentrole = $DB->get_record('role', array('shortname' => 'student')); + $studentrole = $DB->get_record('role', ['shortname' => 'student']); // Enrol student. $this->assertTrue($this->getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id)); // Create a quiz. - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); // Remove the permission to attempt or review the quiz for the student role. $coursecontext = \context_course::instance($course->id); @@ -913,13 +913,13 @@ class lib_test extends \advanced_testcase { // Create a student. $student = $this->getDataGenerator()->create_user(); - $studentrole = $DB->get_record('role', array('shortname' => 'student')); + $studentrole = $DB->get_record('role', ['shortname' => 'student']); // Enrol student. $this->assertTrue($this->getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id)); // Create a quiz. - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); // Remove the permission to attempt or review the quiz for the student role. $coursecontext = \context_course::instance($course->id); @@ -948,19 +948,19 @@ class lib_test extends \advanced_testcase { // Create a student. $student = $this->getDataGenerator()->create_user(); - $studentrole = $DB->get_record('role', array('shortname' => 'student')); + $studentrole = $DB->get_record('role', ['shortname' => 'student']); // Enrol student. $this->assertTrue($this->getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id)); // Create a quiz. - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id, - 'sumgrades' => 1)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id, + 'sumgrades' => 1]); // Add a question to the quiz. $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $question = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); // Get the quiz object. @@ -1003,19 +1003,19 @@ class lib_test extends \advanced_testcase { // Create a student. $student = $this->getDataGenerator()->create_user(); - $studentrole = $DB->get_record('role', array('shortname' => 'student')); + $studentrole = $DB->get_record('role', ['shortname' => 'student']); // Enrol student. $this->assertTrue($this->getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id)); // Create a quiz. - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id, - 'sumgrades' => 1)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id, + 'sumgrades' => 1]); // Add a question to the quiz. $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $question = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); // Get the quiz object. @@ -1049,9 +1049,9 @@ class lib_test extends \advanced_testcase { $this->setAdminUser(); // Create the activity. - $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id), - array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + $course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id], + ['completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS]); // Get some additional data. $cm = get_coursemodule_from_instance('quiz', $quiz->id); @@ -1080,9 +1080,9 @@ class lib_test extends \advanced_testcase { $this->setAdminUser(); // Create the activity. - $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id), - array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS)); + $course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id], + ['completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS]); // Enrol a student in the course. $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); @@ -1188,11 +1188,11 @@ class lib_test extends \advanced_testcase { // Create an instance as a user without the calendar capabilities. $this->setUser($user); $time = time(); - $params = array( + $params = [ 'course' => $course->id, 'timeopen' => $time + 200, 'timeclose' => $time + 2000, - ); + ]; $generator->create_instance($params); } diff --git a/mod/quiz/tests/local_structure_slot_random_test.php b/mod/quiz/tests/local_structure_slot_random_test.php index 82334b4b22b..6c4c11eecac 100644 --- a/mod/quiz/tests/local_structure_slot_random_test.php +++ b/mod/quiz/tests/local_structure_slot_random_test.php @@ -39,7 +39,7 @@ class local_structure_slot_random_test extends \advanced_testcase { // Create a quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz = $quizgenerator->create_instance(array('course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0)); + $quiz = $quizgenerator->create_instance(['course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0]); // Create a question category in the system context. $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); @@ -94,7 +94,7 @@ class local_structure_slot_random_test extends \advanced_testcase { // Create a quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz = $quizgenerator->create_instance(array('course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0)); + $quiz = $quizgenerator->create_instance(['course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0]); // Create a question category in the system context. $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); @@ -131,7 +131,7 @@ class local_structure_slot_random_test extends \advanced_testcase { // Create a quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz = $quizgenerator->create_instance(array('course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0)); + $quiz = $quizgenerator->create_instance(['course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0]); // Create a question category in the system context. $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); @@ -172,7 +172,7 @@ class local_structure_slot_random_test extends \advanced_testcase { // Create a quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz = $quizgenerator->create_instance(array('course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0)); + $quiz = $quizgenerator->create_instance(['course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0]); // Create a question category in the system context. $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); @@ -191,16 +191,16 @@ class local_structure_slot_random_test extends \advanced_testcase { // Create tags. foreach ($tagnames as $tagname) { - $tagrecord = array( + $tagrecord = [ 'isstandard' => 1, 'flag' => 0, 'rawname' => $tagname, 'description' => $tagname . ' desc' - ); + ]; $tags[$tagname] = $this->getDataGenerator()->create_tag($tagrecord); } - return array($randomslot, $tags); + return [$randomslot, $tags]; } public function test_set_tags() { @@ -354,7 +354,7 @@ class local_structure_slot_random_test extends \advanced_testcase { // Create a quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz = $quizgenerator->create_instance(array('course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0)); + $quiz = $quizgenerator->create_instance(['course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0]); $quizcontext = \context_module::instance($quiz->cmid); // Create a question category in the system context. @@ -371,19 +371,19 @@ class local_structure_slot_random_test extends \advanced_testcase { $form->stamp = make_unique_id_code(); // Prepare 2 tags. - $tagrecord = array( + $tagrecord = [ 'isstandard' => 1, 'flag' => 0, 'rawname' => 'foo', 'description' => 'foo desc' - ); + ]; $footag = $this->getDataGenerator()->create_tag($tagrecord); - $tagrecord = array( + $tagrecord = [ 'isstandard' => 1, 'flag' => 0, 'rawname' => 'bar', 'description' => 'bar desc' - ); + ]; $bartag = $this->getDataGenerator()->create_tag($tagrecord); diff --git a/mod/quiz/tests/locallib_test.php b/mod/quiz/tests/locallib_test.php index b73248fc984..bc9c28a7be0 100644 --- a/mod/quiz/tests/locallib_test.php +++ b/mod/quiz/tests/locallib_test.php @@ -128,9 +128,9 @@ class locallib_test extends \advanced_testcase { $this->setAdminUser(); // Setup test data. - $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id), - array('completion' => 2, 'completionview' => 1)); + $course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id], + ['completion' => 2, 'completionview' => 1]); $context = \context_module::instance($quiz->cmid); $cm = get_coursemodule_from_instance('quiz', $quiz->id); @@ -147,7 +147,7 @@ class locallib_test extends \advanced_testcase { // Checking that the event contains the expected values. $this->assertInstanceOf('\mod_quiz\event\course_module_viewed', $event); $this->assertEquals($context, $event->get_context()); - $moodleurl = new \moodle_url('/mod/quiz/view.php', array('id' => $cm->id)); + $moodleurl = new \moodle_url('/mod/quiz/view.php', ['id' => $cm->id]); $this->assertEquals($moodleurl, $event->get_url()); $this->assertEventContextNotUsed($event); $this->assertNotEmpty($event->get_name()); @@ -281,7 +281,7 @@ class locallib_test extends \advanced_testcase { $course = $generator->create_course(); $quizgenerator = $generator->get_plugin_generator('mod_quiz'); $quiz = $quizgenerator->create_instance(['course' => $course->id]); - $group = $this->getDataGenerator()->create_group(array('courseid' => $quiz->course)); + $group = $this->getDataGenerator()->create_group(['courseid' => $quiz->course]); $groupid = $group->id; $userid = $user->id; @@ -321,10 +321,10 @@ class locallib_test extends \advanced_testcase { $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); // Both quizzes close in two hours. - $quiz1 = $quizgenerator->create_instance(array('course' => $course->id, 'timeclose' => $basetimestamp + 7200)); - $quiz2 = $quizgenerator->create_instance(array('course' => $course->id, 'timeclose' => $basetimestamp + 7200)); - $group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id)); - $group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id)); + $quiz1 = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => $basetimestamp + 7200]); + $quiz2 = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => $basetimestamp + 7200]); + $group1 = $this->getDataGenerator()->create_group(['courseid' => $course->id]); + $group2 = $this->getDataGenerator()->create_group(['courseid' => $course->id]); $student1id = $student1->id; $student2id = $student2->id; @@ -332,20 +332,20 @@ class locallib_test extends \advanced_testcase { $teacherid = $teacher->id; // Users enrolments. - $studentrole = $DB->get_record('role', array('shortname' => 'student')); - $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher')); + $studentrole = $DB->get_record('role', ['shortname' => 'student']); + $teacherrole = $DB->get_record('role', ['shortname' => 'editingteacher']); $this->getDataGenerator()->enrol_user($student1id, $course->id, $studentrole->id, 'manual'); $this->getDataGenerator()->enrol_user($student2id, $course->id, $studentrole->id, 'manual'); $this->getDataGenerator()->enrol_user($student3id, $course->id, $studentrole->id, 'manual'); $this->getDataGenerator()->enrol_user($teacherid, $course->id, $teacherrole->id, 'manual'); // Create groups. - $group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id)); - $group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id)); + $group1 = $this->getDataGenerator()->create_group(['courseid' => $course->id]); + $group2 = $this->getDataGenerator()->create_group(['courseid' => $course->id]); $group1id = $group1->id; $group2id = $group2->id; - $this->getDataGenerator()->create_group_member(array('userid' => $student1id, 'groupid' => $group1id)); - $this->getDataGenerator()->create_group_member(array('userid' => $student2id, 'groupid' => $group2id)); + $this->getDataGenerator()->create_group_member(['userid' => $student1id, 'groupid' => $group1id]); + $this->getDataGenerator()->create_group_member(['userid' => $student2id, 'groupid' => $group2id]); // Group 1 gets an group override for quiz 1 to close in three hours. $record1 = (object) [ @@ -360,7 +360,7 @@ class locallib_test extends \advanced_testcase { $this->setUser($student1id); $params = new \stdClass(); - $comparearray = array(); + $comparearray = []; $object = new \stdClass(); $object->id = $quiz1->id; $object->usertimeclose = $basetimestamp + 10800; // The overriden timeclose for quiz 1. @@ -379,7 +379,7 @@ class locallib_test extends \advanced_testcase { $this->setUser($student3id); $params = new \stdClass(); - $comparearray = array(); + $comparearray = []; $object = new \stdClass(); $object->id = $quiz1->id; $object->usertimeclose = $basetimestamp + 7200; // The original timeclose for quiz 1. @@ -406,7 +406,7 @@ class locallib_test extends \advanced_testcase { // Quiz 2 closes in two hours. $this->setUser($student2id); - $comparearray = array(); + $comparearray = []; $object = new \stdClass(); $object->id = $quiz1->id; $object->usertimeclose = $basetimestamp + 14400; // The overriden timeclose for quiz 1. @@ -425,7 +425,7 @@ class locallib_test extends \advanced_testcase { // Quiz 1 and quiz 2 close in two hours. $this->setUser($teacherid); - $comparearray = array(); + $comparearray = []; $object = new \stdClass(); $object->id = $quiz1->id; $object->usertimeclose = $basetimestamp + 7200; // The unchanged timeclose for quiz 1. @@ -473,18 +473,18 @@ class locallib_test extends \advanced_testcase { // Create tags. foreach ($alltags as $tagname) { - $tagrecord = array( + $tagrecord = [ 'isstandard' => 1, 'flag' => 0, 'rawname' => $tagname, 'description' => $tagname . ' desc' - ); + ]; $tagobjects[$tagname] = $this->getDataGenerator()->create_tag($tagrecord); } // Create a quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz = $quizgenerator->create_instance(array('course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0)); + $quiz = $quizgenerator->create_instance(['course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0]); // Create a question category in the system context. $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); @@ -492,13 +492,13 @@ class locallib_test extends \advanced_testcase { // Setup standard questions. for ($i = 0; $i < $qnum; $i++) { - $question = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); } // Setup random questions. for ($i = 0; $i < $randomqnum; $i++) { // Just create a standard question first, so there would be enough questions to pick a random question from. - $question = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); + $question = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); $tagids = []; if (!empty($questiontags[$i])) { foreach ($questiontags[$i] as $tagname) { @@ -508,7 +508,7 @@ class locallib_test extends \advanced_testcase { quiz_add_random_questions($quiz, 0, $cat->id, 1, false, $tagids); } - return array($quiz, $tagobjects); + return [$quiz, $tagobjects]; } public function test_quiz_override_summary() { @@ -631,7 +631,7 @@ class locallib_test extends \advanced_testcase { $recipient = $this->getDataGenerator()->create_user(['email' => 'student@example.com']); // Allow recipent to receive email confirm submission. - $studentrole = $DB->get_record('role', array('shortname' => 'student')); + $studentrole = $DB->get_record('role', ['shortname' => 'student']); assign_capability('mod/quiz:emailconfirmsubmission', CAP_ALLOW, $studentrole->id, \context_course::instance($course->id), true); $this->getDataGenerator()->enrol_user($recipient->id, $course->id, $studentrole->id, 'manual'); diff --git a/mod/quiz/tests/privacy/provider_test.php b/mod/quiz/tests/privacy/provider_test.php index 1f74e996d6c..ffba8269df1 100644 --- a/mod/quiz/tests/privacy/provider_test.php +++ b/mod/quiz/tests/privacy/provider_test.php @@ -239,9 +239,9 @@ class provider_test extends \core_privacy\tests\provider_testcase { $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); + $saq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); quiz_add_quiz_question($saq->id, $quiz); - $numq = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $numq = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); quiz_add_quiz_question($numq->id, $quiz); // Run as the user and make an attempt on the quiz. @@ -411,9 +411,9 @@ class provider_test extends \core_privacy\tests\provider_testcase { $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); + $saq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); quiz_add_quiz_question($saq->id, $quiz); - $numq = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $numq = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); quiz_add_quiz_question($numq->id, $quiz); return $quiz; diff --git a/mod/quiz/tests/quiz_question_bank_view_test.php b/mod/quiz/tests/quiz_question_bank_view_test.php index 7058ea33203..bcefd39deeb 100644 --- a/mod/quiz/tests/quiz_question_bank_view_test.php +++ b/mod/quiz/tests/quiz_question_bank_view_test.php @@ -43,7 +43,7 @@ class quiz_question_bank_view_test extends \advanced_testcase { // Create a course and a quiz. $course = $generator->create_course(); - $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); + $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); $context = \context_module::instance($quiz->cmid); $cm = get_coursemodule_from_instance('quiz', $quiz->id); diff --git a/mod/quiz/tests/quiz_question_helper_test_trait.php b/mod/quiz/tests/quiz_question_helper_test_trait.php index 35e027df16e..174ab2adc31 100644 --- a/mod/quiz/tests/quiz_question_helper_test_trait.php +++ b/mod/quiz/tests/quiz_question_helper_test_trait.php @@ -69,11 +69,11 @@ trait quiz_question_helper_test_trait { // Create a couple of questions. $cat = $questiongenerator->create_question_category($override); - $saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); + $saq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); // Create another version. $questiongenerator->update_question($saq); quiz_add_quiz_question($saq->id, $quiz); - $numq = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); + $numq = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); // Create two version. $questiongenerator->update_question($numq); $questiongenerator->update_question($numq); @@ -90,8 +90,8 @@ trait quiz_question_helper_test_trait { protected function add_one_random_question($questiongenerator, \stdClass $quiz, $override = []): void { // Create a random question. $cat = $questiongenerator->create_question_category($override); - $questiongenerator->create_question('truefalse', null, array('category' => $cat->id)); - $questiongenerator->create_question('essay', null, array('category' => $cat->id)); + $questiongenerator->create_question('truefalse', null, ['category' => $cat->id]); + $questiongenerator->create_question('essay', null, ['category' => $cat->id]); quiz_add_random_questions($quiz, 0, $cat->id, 1, false); } diff --git a/mod/quiz/tests/repaginate_test.php b/mod/quiz/tests/repaginate_test.php index d0a98367ff8..17fd9e3ad55 100644 --- a/mod/quiz/tests/repaginate_test.php +++ b/mod/quiz/tests/repaginate_test.php @@ -24,8 +24,6 @@ namespace mod_quiz; -use mod_quiz\quiz_settings; - defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -33,7 +31,7 @@ require_once($CFG->dirroot . '/mod/quiz/locallib.php'); require_once($CFG->dirroot . '/mod/quiz/classes/repaginate.php'); /** - * Testable subclass, giving access to the protected methods of {@link \mod_quiz\repaginate} + * Test for {@see \mod_quiz\repaginate} * @copyright 2014 The Open Univsersity * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -76,10 +74,6 @@ class repaginate_test extends \advanced_testcase { $this->repaginate = new mod_quiz_repaginate_testable(0, $this->quizslots); } - public function tearDown(): void { - $this->repaginate = null; - } - /** * Create a quiz, add five questions to the quiz * which are all on one page and return the quiz object. @@ -91,19 +85,19 @@ class repaginate_test extends \advanced_testcase { // Make a quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz = $quizgenerator->create_instance(array( - 'course' => $SITE->id, 'questionsperpage' => 0, 'grade' => 100.0, 'sumgrades' => 2)); + $quiz = $quizgenerator->create_instance([ + 'course' => $SITE->id, 'questionsperpage' => 0, 'grade' => 100.0, 'sumgrades' => 2]); $cm = get_coursemodule_from_instance('quiz', $quiz->id, $SITE->id); // Create five questions. $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $shortanswer = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id)); - $numerical = $questiongenerator->create_question('numerical', null, array('category' => $cat->id)); - $essay = $questiongenerator->create_question('essay', null, array('category' => $cat->id)); - $truefalse = $questiongenerator->create_question('truefalse', null, array('category' => $cat->id)); - $match = $questiongenerator->create_question('match', null, array('category' => $cat->id)); + $shortanswer = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]); + $numerical = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]); + $essay = $questiongenerator->create_question('essay', null, ['category' => $cat->id]); + $truefalse = $questiongenerator->create_question('truefalse', null, ['category' => $cat->id]); + $match = $questiongenerator->create_question('match', null, ['category' => $cat->id]); // Add them to the quiz. quiz_add_quiz_question($shortanswer->id, $quiz); @@ -134,7 +128,7 @@ class repaginate_test extends \advanced_testcase { */ public function test_get_this_slot() { $this->set_quiz_slots(); - $actual = array(); + $actual = []; $expected = $this->repaginate->get_slots_by_slot_number(); $this->assertEquals($expected, $actual); @@ -146,7 +140,7 @@ class repaginate_test extends \advanced_testcase { public function test_get_slots_by_slotnumber() { $this->set_quiz_slots(); - $expected = array(); + $expected = []; $actual = $this->repaginate->get_slots_by_slot_number(); $this->assertEquals($expected, $actual); @@ -160,7 +154,7 @@ class repaginate_test extends \advanced_testcase { public function test_get_slots_by_slotid() { $this->set_quiz_slots(); $actual = $this->repaginate->get_slots_by_slotid(); - $this->assertEquals(array(), $actual); + $this->assertEquals([], $actual); $slotsbyno = $this->repaginate->get_slots_by_slot_number($this->quizslots); $actual = $this->repaginate->get_slots_by_slotid($slotsbyno); @@ -171,7 +165,7 @@ class repaginate_test extends \advanced_testcase { $this->set_quiz_slots(); // Expect 2 questions per page. - $expected = array(); + $expected = []; foreach ($this->quizslots as $slot) { // Page 1 contains Slots 1 and 2. if ($slot->slot >= 1 && $slot->slot <= 2) { @@ -191,7 +185,7 @@ class repaginate_test extends \advanced_testcase { $this->assertEquals($expected, $actual); // Expect 3 questions per page. - $expected = array(); + $expected = []; foreach ($this->quizslots as $slot) { // Page 1 contains Slots 1, 2 and 3. if ($slot->slot >= 1 && $slot->slot <= 3) { @@ -207,7 +201,7 @@ class repaginate_test extends \advanced_testcase { $this->assertEquals($expected, $actual); // Expect 5 questions per page. - $expected = array(); + $expected = []; foreach ($this->quizslots as $slot) { // Page 1 contains Slots 1, 2, 3, 4 and 5. if ($slot->slot > 0 && $slot->slot < 6) { @@ -223,7 +217,7 @@ class repaginate_test extends \advanced_testcase { $this->assertEquals($expected, $actual); // Expect 10 questions per page. - $expected = array(); + $expected = []; foreach ($this->quizslots as $slot) { // Page 1 contains Slots 1 to 10. if ($slot->slot >= 1 && $slot->slot <= 10) { @@ -239,7 +233,7 @@ class repaginate_test extends \advanced_testcase { $this->assertEquals($expected, $actual); // Expect 1 questions per page. - $expected = array(); + $expected = []; $page = 1; foreach ($this->quizslots as $slot) { $slot->page = $page++; @@ -265,7 +259,7 @@ class repaginate_test extends \advanced_testcase { $this->set_quiz_slots(); $slotfrom = 1; $type = repaginate::LINK; - $expected = array(); + $expected = []; foreach ($this->quizslots as $slot) { if ($slot->slot > $slotfrom) { $slot->page = $slot->page - 1; @@ -276,7 +270,7 @@ class repaginate_test extends \advanced_testcase { $this->assertEquals($expected, $actual); $slotfrom = 2; - $newslots = array(); + $newslots = []; foreach ($this->quizslots as $s) { if ($s->slot === $slotfrom) { $s->page = $s->page - 1; @@ -285,7 +279,7 @@ class repaginate_test extends \advanced_testcase { } $type = repaginate::UNLINK; - $expected = array(); + $expected = []; foreach ($this->quizslots as $slot) { if ($slot->slot > ($slotfrom - 1)) { $slot->page = $slot->page - 1; diff --git a/mod/quiz/tests/reportlib_test.php b/mod/quiz/tests/reportlib_test.php index b5bcfb7aa82..69432ff0eb9 100644 --- a/mod/quiz/tests/reportlib_test.php +++ b/mod/quiz/tests/reportlib_test.php @@ -31,7 +31,7 @@ require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); */ class reportlib_test extends \advanced_testcase { public function test_quiz_report_index_by_keys() { - $datum = array(); + $datum = []; $object = new \stdClass(); $object->qid = 3; $object->aid = 101; @@ -39,14 +39,14 @@ class reportlib_test extends \advanced_testcase { $object->grade = 3; $datum[] = $object; - $indexed = quiz_report_index_by_keys($datum, array('aid', 'qid')); + $indexed = quiz_report_index_by_keys($datum, ['aid', 'qid']); $this->assertEquals($indexed[101][3]->qid, 3); $this->assertEquals($indexed[101][3]->aid, 101); $this->assertEquals($indexed[101][3]->response, ''); $this->assertEquals($indexed[101][3]->grade, 3); - $indexed = quiz_report_index_by_keys($datum, array('aid', 'qid'), false); + $indexed = quiz_report_index_by_keys($datum, ['aid', 'qid'], false); $this->assertEquals($indexed[101][3][0]->qid, 3); $this->assertEquals($indexed[101][3][0]->aid, 101); @@ -136,7 +136,7 @@ class reportlib_test extends \advanced_testcase { $quiz->grademethod = QUIZ_ATTEMPTFIRST; $firstattempt = $DB->get_records_sql(" SELECT * FROM {quiz_attempts} quiza WHERE userid = ? AND quiz = ? AND " - . quiz_report_qm_filter_select($quiz), array(123, 456)); + . quiz_report_qm_filter_select($quiz), [123, 456]); $this->assertEquals(1, count($firstattempt)); $firstattempt = reset($firstattempt); $this->assertEquals(1, $firstattempt->attempt); @@ -144,7 +144,7 @@ class reportlib_test extends \advanced_testcase { $quiz->grademethod = QUIZ_ATTEMPTLAST; $lastattempt = $DB->get_records_sql(" SELECT * FROM {quiz_attempts} quiza WHERE userid = ? AND quiz = ? AND " - . quiz_report_qm_filter_select($quiz), array(123, 456)); + . quiz_report_qm_filter_select($quiz), [123, 456]); $this->assertEquals(1, count($lastattempt)); $lastattempt = reset($lastattempt); $this->assertEquals(3, $lastattempt->attempt); @@ -153,7 +153,7 @@ class reportlib_test extends \advanced_testcase { $quiz->grademethod = QUIZ_GRADEHIGHEST; $bestattempt = $DB->get_records_sql(" SELECT * FROM {quiz_attempts} qa_alias WHERE userid = ? AND quiz = ? AND " - . quiz_report_qm_filter_select($quiz, 'qa_alias'), array(123, 456)); + . quiz_report_qm_filter_select($quiz, 'qa_alias'), [123, 456]); $this->assertEquals(1, count($bestattempt)); $bestattempt = reset($bestattempt); $this->assertEquals(2, $bestattempt->attempt); diff --git a/mod/quiz/tests/restore_override_test.php b/mod/quiz/tests/restore_override_test.php index 6234639c561..2773df5fdd5 100644 --- a/mod/quiz/tests/restore_override_test.php +++ b/mod/quiz/tests/restore_override_test.php @@ -41,8 +41,8 @@ class restore_override_test extends \restore_date_testcase { $quizgen = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); $quiz = $quizgen->create_instance(['course' => $course->id]); - $group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id)); - $group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id)); + $group1 = $this->getDataGenerator()->create_group(['courseid' => $course->id]); + $group2 = $this->getDataGenerator()->create_group(['courseid' => $course->id]); $now = 100; diff --git a/mod/quiz/tests/structure_test.php b/mod/quiz/tests/structure_test.php index 1e8fcc975ff..759dbba4667 100644 --- a/mod/quiz/tests/structure_test.php +++ b/mod/quiz/tests/structure_test.php @@ -40,12 +40,12 @@ class structure_test extends \advanced_testcase { // Make a quiz. $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); - $quiz = $quizgenerator->create_instance(array('course' => $course->id, 'questionsperpage' => 0, - 'grade' => 100.0, 'sumgrades' => 2, 'preferredbehaviour' => 'immediatefeedback')); + $quiz = $quizgenerator->create_instance(['course' => $course->id, 'questionsperpage' => 0, + 'grade' => 100.0, 'sumgrades' => 2, 'preferredbehaviour' => 'immediatefeedback']); $cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id); - return array($quiz, $cm, $course); + return [$quiz, $cm, $course]; } /** @@ -73,7 +73,7 @@ class structure_test extends \advanced_testcase { $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); - $headings = array(); + $headings = []; $slot = 1; $lastpage = 0; foreach ($layout as $item) { @@ -90,7 +90,7 @@ class structure_test extends \advanced_testcase { throw new \coding_exception('Page numbers wrong.'); } $q = $questiongenerator->create_question($qtype, null, - array('name' => $name, 'category' => $cat->id)); + ['name' => $name, 'category' => $cat->id]); quiz_add_quiz_question($q->id, $quiz, $page); $lastpage = $page; @@ -172,17 +172,17 @@ class structure_test extends \advanced_testcase { */ protected function parse_section_name($heading) { if (substr($heading, -1) == '*') { - return array(substr($heading, 0, -1), 1); + return [substr($heading, 0, -1), 1]; } else { - return array($heading, 0); + return [$heading, 0]; } } public function test_get_quiz_slots() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); // Are the correct slots returned? @@ -191,9 +191,9 @@ class structure_test extends \advanced_testcase { } public function test_quiz_has_one_section_by_default() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $sections = $structure->get_sections(); @@ -206,12 +206,12 @@ class structure_test extends \advanced_testcase { } public function test_get_sections() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1*', - array('TF1', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], 'Heading 2*', - array('TF2', 2, 'truefalse'), - )); + ['TF2', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $sections = $structure->get_sections(); @@ -229,12 +229,12 @@ class structure_test extends \advanced_testcase { } public function test_remove_section_heading() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1', - array('TF1', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF2', 2, 'truefalse'), - )); + ['TF2', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $sections = $structure->get_sections(); @@ -242,18 +242,18 @@ class structure_test extends \advanced_testcase { $structure->remove_section_heading($section->id); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( + $this->assert_quiz_layout([ 'Heading 1', - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - ), $structure); + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ], $structure); } public function test_cannot_remove_first_section() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1', - array('TF1', 1, 'truefalse'), - )); + ['TF1', 1, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $sections = $structure->get_sections(); @@ -264,11 +264,11 @@ class structure_test extends \advanced_testcase { } public function test_move_slot_to_the_same_place_does_nothing() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), - array('TF3', 2, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], + ['TF3', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(2)->slotid; @@ -276,19 +276,19 @@ class structure_test extends \advanced_testcase { $structure->move_slot($idtomove, $idmoveafter, '1'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), - array('TF3', 2, 'truefalse'), - ), $structure); + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], + ['TF3', 2, 'truefalse'], + ], $structure); } public function test_move_slot_end_of_one_page_to_start_of_next() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), - array('TF3', 2, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], + ['TF3', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(2)->slotid; @@ -296,18 +296,18 @@ class structure_test extends \advanced_testcase { $structure->move_slot($idtomove, $idmoveafter, '2'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - array('TF3', 2, 'truefalse'), - ), $structure); + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ['TF3', 2, 'truefalse'], + ], $structure); } public function test_move_last_slot_to_previous_page_emptying_the_last_page() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(2)->slotid; @@ -315,19 +315,19 @@ class structure_test extends \advanced_testcase { $structure->move_slot($idtomove, $idmoveafter, '1'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), - ), $structure); + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], + ], $structure); } public function test_end_of_one_section_to_start_of_next() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], 'Heading', - array('TF3', 2, 'truefalse'), - )); + ['TF3', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(2)->slotid; @@ -335,21 +335,21 @@ class structure_test extends \advanced_testcase { $structure->move_slot($idtomove, $idmoveafter, '2'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], 'Heading', - array('TF2', 2, 'truefalse'), - array('TF3', 2, 'truefalse'), - ), $structure); + ['TF2', 2, 'truefalse'], + ['TF3', 2, 'truefalse'], + ], $structure); } public function test_start_of_one_section_to_end_of_previous() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], 'Heading', - array('TF2', 2, 'truefalse'), - array('TF3', 2, 'truefalse'), - )); + ['TF2', 2, 'truefalse'], + ['TF3', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(2)->slotid; @@ -357,19 +357,19 @@ class structure_test extends \advanced_testcase { $structure->move_slot($idtomove, $idmoveafter, '1'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], 'Heading', - array('TF3', 2, 'truefalse'), - ), $structure); + ['TF3', 2, 'truefalse'], + ], $structure); } public function test_move_slot_on_same_page() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), - array('TF3', 1, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], + ['TF3', 1, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(2)->slotid; @@ -377,19 +377,19 @@ class structure_test extends \advanced_testcase { $structure->move_slot($idtomove, $idmoveafter, '1'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), - array('TF3', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), - ), $structure); + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], + ['TF3', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], + ], $structure); } public function test_move_slot_up_onto_previous_page() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - array('TF3', 2, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ['TF3', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(3)->slotid; @@ -397,19 +397,19 @@ class structure_test extends \advanced_testcase { $structure->move_slot($idtomove, $idmoveafter, '1'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), - array('TF3', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - ), $structure); + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], + ['TF3', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ], $structure); } public function test_move_slot_emptying_a_page_renumbers_pages() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - array('TF3', 3, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ['TF3', 3, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(2)->slotid; @@ -417,19 +417,19 @@ class structure_test extends \advanced_testcase { $structure->move_slot($idtomove, $idmoveafter, '3'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), - array('TF3', 2, 'truefalse'), - array('TF2', 2, 'truefalse'), - ), $structure); + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], + ['TF3', 2, 'truefalse'], + ['TF2', 2, 'truefalse'], + ], $structure); } public function test_move_slot_too_small_page_number_detected() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - array('TF3', 3, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ['TF3', 3, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(3)->slotid; @@ -439,11 +439,11 @@ class structure_test extends \advanced_testcase { } public function test_move_slot_too_large_page_number_detected() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - array('TF3', 3, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ['TF3', 3, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(1)->slotid; @@ -453,13 +453,13 @@ class structure_test extends \advanced_testcase { } public function test_move_slot_within_section() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1', - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], 'Heading 2', - array('TF3', 2, 'truefalse'), - )); + ['TF3', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(1)->slotid; @@ -467,23 +467,23 @@ class structure_test extends \advanced_testcase { $structure->move_slot($idtomove, $idmoveafter, '1'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( + $this->assert_quiz_layout([ 'Heading 1', - array('TF2', 1, 'truefalse'), - array('TF1', 1, 'truefalse'), + ['TF2', 1, 'truefalse'], + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF3', 2, 'truefalse'), - ), $structure); + ['TF3', 2, 'truefalse'], + ], $structure); } public function test_move_slot_to_new_section() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1', - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], 'Heading 2', - array('TF3', 2, 'truefalse'), - )); + ['TF3', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(2)->slotid; @@ -491,46 +491,46 @@ class structure_test extends \advanced_testcase { $structure->move_slot($idtomove, $idmoveafter, '2'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( + $this->assert_quiz_layout([ 'Heading 1', - array('TF1', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF3', 2, 'truefalse'), - array('TF2', 2, 'truefalse'), - ), $structure); + ['TF3', 2, 'truefalse'], + ['TF2', 2, 'truefalse'], + ], $structure); } public function test_move_slot_to_start() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1', - array('TF1', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF2', 2, 'truefalse'), - array('TF3', 2, 'truefalse'), - )); + ['TF2', 2, 'truefalse'], + ['TF3', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(3)->slotid; $structure->move_slot($idtomove, 0, '1'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( + $this->assert_quiz_layout([ 'Heading 1', - array('TF3', 1, 'truefalse'), - array('TF1', 1, 'truefalse'), + ['TF3', 1, 'truefalse'], + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF2', 2, 'truefalse'), - ), $structure); + ['TF2', 2, 'truefalse'], + ], $structure); } public function test_move_slot_down_to_start_of_second_section() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1', - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], 'Heading 2', - array('TF3', 2, 'truefalse'), - )); + ['TF3', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(2)->slotid; @@ -538,82 +538,82 @@ class structure_test extends \advanced_testcase { $structure->move_slot($idtomove, $idmoveafter, '2'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( + $this->assert_quiz_layout([ 'Heading 1', - array('TF1', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF2', 2, 'truefalse'), - array('TF3', 2, 'truefalse'), - ), $structure); + ['TF2', 2, 'truefalse'], + ['TF3', 2, 'truefalse'], + ], $structure); } public function test_move_first_slot_down_to_start_of_page_2() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1', - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - )); + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(1)->slotid; $structure->move_slot($idtomove, 0, '2'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( + $this->assert_quiz_layout([ 'Heading 1', - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), - ), $structure); + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], + ], $structure); } public function test_move_first_slot_to_same_place_on_page_1() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1', - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - )); + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(1)->slotid; $structure->move_slot($idtomove, 0, '1'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( + $this->assert_quiz_layout([ 'Heading 1', - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - ), $structure); + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ], $structure); } public function test_move_first_slot_to_before_page_1() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1', - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - )); + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(1)->slotid; $structure->move_slot($idtomove, 0, ''); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( + $this->assert_quiz_layout([ 'Heading 1', - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - ), $structure); + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ], $structure); } public function test_move_slot_up_to_start_of_second_section() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1', - array('TF1', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF2', 2, 'truefalse'), + ['TF2', 2, 'truefalse'], 'Heading 3', - array('TF3', 3, 'truefalse'), - array('TF4', 3, 'truefalse'), - )); + ['TF3', 3, 'truefalse'], + ['TF4', 3, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(3)->slotid; @@ -621,27 +621,27 @@ class structure_test extends \advanced_testcase { $structure->move_slot($idtomove, $idmoveafter, '2'); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( + $this->assert_quiz_layout([ 'Heading 1', - array('TF1', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF3', 2, 'truefalse'), - array('TF2', 2, 'truefalse'), + ['TF3', 2, 'truefalse'], + ['TF2', 2, 'truefalse'], 'Heading 3', - array('TF4', 3, 'truefalse'), - ), $structure); + ['TF4', 3, 'truefalse'], + ], $structure); } public function test_move_slot_does_not_violate_heading_unique_key() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1', - array('TF1', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF2', 2, 'truefalse'), + ['TF2', 2, 'truefalse'], 'Heading 3', - array('TF3', 3, 'truefalse'), - array('TF4', 3, 'truefalse'), - )); + ['TF3', 3, 'truefalse'], + ['TF4', 3, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $idtomove = $structure->get_question_in_slot(4)->slotid; @@ -649,34 +649,34 @@ class structure_test extends \advanced_testcase { $structure->move_slot($idtomove, $idmoveafter, 1); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( + $this->assert_quiz_layout([ 'Heading 1', - array('TF1', 1, 'truefalse'), - array('TF4', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], + ['TF4', 1, 'truefalse'], 'Heading 2', - array('TF2', 2, 'truefalse'), + ['TF2', 2, 'truefalse'], 'Heading 3', - array('TF3', 3, 'truefalse'), - ), $structure); + ['TF3', 3, 'truefalse'], + ], $structure); } public function test_quiz_remove_slot() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], 'Heading 2', - array('TF3', 2, 'truefalse'), - )); + ['TF3', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $structure->remove_slot(2); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF3', 2, 'truefalse'), - ), $structure); + ['TF3', 2, 'truefalse'], + ], $structure); } public function test_quiz_removing_a_random_question_deletes_the_question() { @@ -685,9 +685,9 @@ class structure_test extends \advanced_testcase { $this->resetAfterTest(true); $this->setAdminUser(); - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ]); $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); @@ -704,23 +704,23 @@ class structure_test extends \advanced_testcase { $structure->remove_slot(2); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), - ), $structure); + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], + ], $structure); $this->assertFalse($DB->record_exists('question_set_references', - array('id' => $randomq->id, 'component' => 'mod_quiz', 'questionarea' => 'slot'))); + ['id' => $randomq->id, 'component' => 'mod_quiz', 'questionarea' => 'slot'])); } /** * Unit test to make sue it is not possible to remove all slots in a section at once. */ public function test_cannot_remove_all_slots_in_a_section() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], 'Heading 2', - array('TF3', 2, 'truefalse'), - )); + ['TF3', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $structure->remove_slot(1); @@ -729,12 +729,12 @@ class structure_test extends \advanced_testcase { } public function test_cannot_remove_last_slot_in_a_section() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], 'Heading 2', - array('TF3', 2, 'truefalse'), - )); + ['TF3', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $this->expectException(\coding_exception::class); @@ -742,10 +742,10 @@ class structure_test extends \advanced_testcase { } public function test_can_remove_last_question_in_a_quiz() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1', - array('TF1', 1, 'truefalse'), - )); + ['TF1', 1, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $structure->remove_slot(1); @@ -753,131 +753,131 @@ class structure_test extends \advanced_testcase { $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); $q = $questiongenerator->create_question('truefalse', null, - array('name' => 'TF2', 'category' => $cat->id)); + ['name' => 'TF2', 'category' => $cat->id]); quiz_add_quiz_question($q->id, $quizobj->get_quiz(), 0); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( + $this->assert_quiz_layout([ 'Heading 1', - array('TF2', 1, 'truefalse'), - ), $structure); + ['TF2', 1, 'truefalse'], + ], $structure); } public function test_add_question_updates_headings() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF2', 2, 'truefalse'), - )); + ['TF2', 2, 'truefalse'], + ]); $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); $q = $questiongenerator->create_question('truefalse', null, - array('name' => 'TF3', 'category' => $cat->id)); + ['name' => 'TF3', 'category' => $cat->id]); quiz_add_quiz_question($q->id, $quizobj->get_quiz(), 1); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), - array('TF3', 1, 'truefalse'), + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], + ['TF3', 1, 'truefalse'], 'Heading 2', - array('TF2', 2, 'truefalse'), - ), $structure); + ['TF2', 2, 'truefalse'], + ], $structure); } public function test_add_question_updates_headings_even_with_one_question_sections() { - $quizobj = $this->create_test_quiz(array( + $quizobj = $this->create_test_quiz([ 'Heading 1', - array('TF1', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF2', 2, 'truefalse'), + ['TF2', 2, 'truefalse'], 'Heading 3', - array('TF3', 3, 'truefalse'), - )); + ['TF3', 3, 'truefalse'], + ]); $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); $q = $questiongenerator->create_question('truefalse', null, - array('name' => 'TF4', 'category' => $cat->id)); + ['name' => 'TF4', 'category' => $cat->id]); quiz_add_quiz_question($q->id, $quizobj->get_quiz(), 1); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( + $this->assert_quiz_layout([ 'Heading 1', - array('TF1', 1, 'truefalse'), - array('TF4', 1, 'truefalse'), + ['TF1', 1, 'truefalse'], + ['TF4', 1, 'truefalse'], 'Heading 2', - array('TF2', 2, 'truefalse'), + ['TF2', 2, 'truefalse'], 'Heading 3', - array('TF3', 3, 'truefalse'), - ), $structure); + ['TF3', 3, 'truefalse'], + ], $structure); } public function test_add_question_at_end_does_not_update_headings() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF2', 2, 'truefalse'), - )); + ['TF2', 2, 'truefalse'], + ]); $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); $q = $questiongenerator->create_question('truefalse', null, - array('name' => 'TF3', 'category' => $cat->id)); + ['name' => 'TF3', 'category' => $cat->id]); quiz_add_quiz_question($q->id, $quizobj->get_quiz(), 0); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], 'Heading 2', - array('TF2', 2, 'truefalse'), - array('TF3', 2, 'truefalse'), - ), $structure); + ['TF2', 2, 'truefalse'], + ['TF3', 2, 'truefalse'], + ], $structure); } public function test_remove_page_break() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $slotid = $structure->get_question_in_slot(2)->slotid; $slots = $structure->update_page_break($slotid, repaginate::LINK); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), - ), $structure); + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], + ], $structure); } public function test_add_page_break() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); $slotid = $structure->get_question_in_slot(2)->slotid; $slots = $structure->update_page_break($slotid, repaginate::UNLINK); $structure = structure::create_for_quiz($quizobj); - $this->assert_quiz_layout(array( - array('TF1', 1, 'truefalse'), - array('TF2', 2, 'truefalse'), - ), $structure); + $this->assert_quiz_layout([ + ['TF1', 1, 'truefalse'], + ['TF2', 2, 'truefalse'], + ], $structure); } public function test_update_question_dependency() { - $quizobj = $this->create_test_quiz(array( - array('TF1', 1, 'truefalse'), - array('TF2', 1, 'truefalse'), - )); + $quizobj = $this->create_test_quiz([ + ['TF1', 1, 'truefalse'], + ['TF2', 1, 'truefalse'], + ]); $structure = structure::create_for_quiz($quizobj); // Test adding a dependency.