This commit is contained in:
Jun Pataleta
2023-01-24 23:19:43 +08:00
136 changed files with 2421 additions and 2421 deletions
@@ -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) {
+2 -2
View File
@@ -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'));
+1 -1
View File
@@ -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) {
@@ -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'];
}
/**
@@ -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'];
}
/**
@@ -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'];
}
/**
@@ -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'];
}
/**
@@ -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'];
}
/**
@@ -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'];
}
/**
+1 -1
View File
@@ -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(
+106 -106
View File
@@ -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
)
),
);
]
],
];
+2 -2
View File
@@ -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);
}
}
+4 -4
View File
@@ -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');
@@ -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(
@@ -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;
+4 -4
View File
@@ -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')];
}
}
+6 -6
View File
@@ -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');
}
+2 -2
View File
@@ -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.
+21 -21
View File
@@ -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 <overrides> 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');
@@ -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);
@@ -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]);
}
}
}
+4 -4
View File
@@ -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) {
@@ -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'];
}
/**
@@ -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'];
}
/**
+1 -1
View File
@@ -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)) {
+5 -5
View File
@@ -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;
}
@@ -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;
}
+6 -6
View File
@@ -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;
}
@@ -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;
}
+4 -4
View File
@@ -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;
}
+6 -6
View File
@@ -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;
}
+6 -6
View File
@@ -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;
}
+5 -5
View File
@@ -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;
}
@@ -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;
}
+5 -5
View File
@@ -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;
}
@@ -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'];
}
}
+5 -5
View File
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
+6 -6
View File
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
File diff suppressed because it is too large Load Diff
+6 -6
View File
@@ -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;
}
@@ -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') {
@@ -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');
}
+3 -3
View File
@@ -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]);
}
}
+5 -5
View File
@@ -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
*/
@@ -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.
@@ -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;
@@ -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.
@@ -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;
+125 -125
View File
@@ -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';
@@ -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);
}
}
@@ -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) {
+4 -4
View File
@@ -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) {
+1 -1
View File
@@ -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. */
+1 -1
View File
@@ -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();
}
@@ -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');
@@ -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';
+6 -6
View File
@@ -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;
+22 -23
View File
@@ -14,15 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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) {
+80 -96
View File
@@ -14,17 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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
*/
@@ -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]);
}
}
+17 -17
View File
@@ -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();
+14 -14
View File
@@ -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
),
);
],
];
+17 -17
View File
@@ -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'),
);
$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'],
];
+12 -12
View File
@@ -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,
],
],
);
];
+56 -56
View File
@@ -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,
],
);
];
+5 -5
View File
@@ -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.
*/
+6 -6
View File
@@ -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);
+23 -23
View File
@@ -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;
+1 -1
View File
@@ -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) {
+5 -5
View File
@@ -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)]));
+9 -9
View File
@@ -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 = '';
+149 -148
View File
@@ -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 '<table border="0" cellpadding="3" cellspacing="0" class="forum-recent">';
echo '<tr><td class="userpicture" valign="top">';
echo $OUTPUT->user_picture($activity->user, array('courseid' => $courseid));
echo $OUTPUT->user_picture($activity->user, ['courseid' => $courseid]);
echo '</td><td>';
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.
+142 -141
View File
@@ -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 '<a title="' . $action . '" href="' . $questionurl->out() . '" class="questioneditbutton">' .
$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);
+44 -41
View File
@@ -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;
+6 -6
View File
@@ -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');
+15 -15
View File
@@ -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
]);
+2 -2
View File
@@ -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()]));
+9 -9
View File
@@ -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);
+10 -10
View File
@@ -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'
)
);
]
];
@@ -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);
+7 -7
View File
@@ -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.
+11 -11
View File
@@ -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') {
@@ -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);
}
}
+16 -15
View File
@@ -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']);
}
}
+35 -36
View File
@@ -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 '<div class="mdl-align">';
echo '<form action="'.$displayurl->out_omit_querystring().'">';
echo '<div>';
@@ -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) {
+5 -5
View File
@@ -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
*/
+18 -18
View File
@@ -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();
+19 -19
View File
@@ -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
*/
@@ -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) {
@@ -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
+3 -3
View File
@@ -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';
+4 -4
View File
@@ -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);
@@ -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' :

Some files were not shown because too many files have changed in this diff Show More