Skip to content

Commit

Permalink
Minor M4.4 compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
davosmith committed Apr 4, 2024
1 parent 5b4acf4 commit e275af3
Show file tree
Hide file tree
Showing 28 changed files with 369 additions and 359 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
matrix:
include:
- php: '8.2'
moodle-branch: 'master'
moodle-branch: 'main'
database: 'pgsql'
- php: '8.2'
moodle-branch: 'MOODLE_403_STABLE'
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
Expand Down
1 change: 1 addition & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The teacher can, at a later date, go back through the results and, for each ques
Changes:
--------

2024-04-04 - 3.4.4.1 - Minor M4.4 compatibility fixes
2023-10-02 - 3.4.4.0 - update GitHub actions ready for 4.3 release
2023-04-14 - 3.4.3.0 - Minor M4.2 compatibility fixes (remove legacy log functions in events)
2022-11-19 - 3.4.2.0 - Minor M4.1 compatibility fixes, fix layout in M4.0+
Expand Down
40 changes: 20 additions & 20 deletions backup/moodle2/backup_realtimequiz_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,29 @@ protected function define_structure() {

// Define each element separated.

$realtimequiz = new backup_nested_element('realtimequiz', array('id'), array(
'name', 'intro', 'introformat', 'timecreated', 'timemodified', 'questiontime'
));
$realtimequiz = new backup_nested_element('realtimequiz', ['id'], [
'name', 'intro', 'introformat', 'timecreated', 'timemodified', 'questiontime',
]);

$sessions = new backup_nested_element('sessions');
$session = new backup_nested_element('session', array('id'), array(
'name', 'timestamp'
));
$session = new backup_nested_element('session', ['id'], [
'name', 'timestamp',
]);

$questions = new backup_nested_element('questions');
$question = new backup_nested_element('question', array('id'), array(
'questionnum', 'questiontext', 'questiontextformat', 'questiontime'
));
$question = new backup_nested_element('question', ['id'], [
'questionnum', 'questiontext', 'questiontextformat', 'questiontime',
]);

$answers = new backup_nested_element('answers');
$answer = new backup_nested_element('answer', array('id'), array(
'answertext', 'correct'
));
$answer = new backup_nested_element('answer', ['id'], [
'answertext', 'correct',
]);

$submissions = new backup_nested_element('submissions');
$submission = new backup_nested_element('submission', array('id'), array(
'sessionid', 'userid', 'answerid'
));
$submission = new backup_nested_element('submission', ['id'], [
'sessionid', 'userid', 'answerid',
]);

// Build the tree.
if ($userinfo) {
Expand All @@ -88,13 +88,13 @@ protected function define_structure() {

// Define sources.

$realtimequiz->set_source_table('realtimequiz', array('id' => backup::VAR_ACTIVITYID));
$question->set_source_table('realtimequiz_question', array('quizid' => backup::VAR_PARENTID));
$answer->set_source_table('realtimequiz_answer', array('questionid' => backup::VAR_PARENTID));
$realtimequiz->set_source_table('realtimequiz', ['id' => backup::VAR_ACTIVITYID]);
$question->set_source_table('realtimequiz_question', ['quizid' => backup::VAR_PARENTID]);
$answer->set_source_table('realtimequiz_answer', ['questionid' => backup::VAR_PARENTID]);

if ($userinfo) {
$session->set_source_table('realtimequiz_session', array('quizid' => backup::VAR_PARENTID));
$submission->set_source_table('realtimequiz_submitted', array('questionid' => backup::VAR_PARENTID));
$session->set_source_table('realtimequiz_session', ['quizid' => backup::VAR_PARENTID]);
$submission->set_source_table('realtimequiz_submitted', ['questionid' => backup::VAR_PARENTID]);
}

// Define id annotations.
Expand Down
12 changes: 6 additions & 6 deletions backup/moodle2/restore_realtimequiz_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ protected function define_my_steps() {
* processed by the link decoder
*/
public static function define_decode_contents() {
$contents = array();
$contents = [];

$contents[] = new restore_decode_content('realtimequiz', array('intro'));
$contents[] = new restore_decode_content('realtimequiz_question', array('questiontext'));
$contents[] = new restore_decode_content('realtimequiz', ['intro']);
$contents[] = new restore_decode_content('realtimequiz_question', ['questiontext']);

return $contents;
}
Expand All @@ -64,7 +64,7 @@ public static function define_decode_contents() {
* to the activity to be executed by the link decoder
*/
public static function define_decode_rules() {
$rules = array();
$rules = [];

// List of realtimequizs in course.
$rules[] = new restore_decode_rule('REALTIMEQUIZINDEX', '/mod/realtimequiz/index.php?id=$1', 'course');
Expand All @@ -82,7 +82,7 @@ public static function define_decode_rules() {
* @return restore_log_rule[]
*/
public static function define_restore_log_rules() {
$rules = array();
$rules = [];

return $rules;
}
Expand All @@ -99,7 +99,7 @@ public static function define_restore_log_rules() {
* @return restore_log_rule[]
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules = [];

return $rules;
}
Expand Down
2 changes: 1 addition & 1 deletion backup/moodle2/restore_realtimequiz_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class restore_realtimequiz_activity_structure_step extends restore_activity_stru
*/
protected function define_structure() {

$paths = array();
$paths = [];
$userinfo = $this->get_setting_value('userinfo');

$paths[] = new restore_path_element('realtimequiz', '/activity/realtimequiz');
Expand Down
6 changes: 3 additions & 3 deletions classes/event/edit_page_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function get_name() {
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the edit page for the realtime quiz with " .
return "The user with id '$this->userid' viewed the edit page for the realtime quiz with ".
"course module id '$this->contextinstanceid'.";
}

Expand All @@ -73,14 +73,14 @@ public function get_description() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/realtimequiz/edit.php', array('id' => $this->contextinstanceid));
return new \moodle_url('/mod/realtimequiz/edit.php', ['id' => $this->contextinstanceid]);
}

/**
* Custom validation.
*
* @throws \coding_exception
* @return void
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
Expand Down
6 changes: 3 additions & 3 deletions classes/event/responses_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function get_name() {
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the responses for the realtime quiz with " .
return "The user with id '$this->userid' viewed the responses for the realtime quiz with ".
"course module id '$this->contextinstanceid'.";
}

Expand All @@ -75,14 +75,14 @@ public function get_description() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/realtimequiz/responses.php', array('id' => $this->contextinstanceid));
return new \moodle_url('/mod/realtimequiz/responses.php', ['id' => $this->contextinstanceid]);
}

/**
* Custom validation.
*
* @throws \coding_exception
* @return void
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
Expand Down
20 changes: 10 additions & 10 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
* @package mod_realtimequiz
*/
class provider implements \core_privacy\local\metadata\provider,
\core_privacy\local\request\plugin\provider,
\core_privacy\local\request\core_userlist_provider {
\core_privacy\local\request\plugin\provider,
\core_privacy\local\request\core_userlist_provider {

/**
* Get details of user data stored by this plugin
* @param collection $collection
* @return collection
*/
public static function get_metadata(collection $collection) : collection {
public static function get_metadata(collection $collection): collection {
$collection->add_database_table(
'realtimequiz_submitted',
[
Expand Down Expand Up @@ -82,7 +82,7 @@ private static function get_modid() {
* @return contextlist
* @throws \dml_exception
*/
public static function get_contexts_for_userid(int $userid) : contextlist {
public static function get_contexts_for_userid(int $userid): contextlist {
$contextlist = new contextlist();
$modid = self::get_modid();
if (!$modid) {
Expand Down Expand Up @@ -125,7 +125,7 @@ public static function export_user_data(approved_contextlist $contextlist) {
}

$user = $contextlist->get_user();
list($contextsql, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);
[$contextsql, $contextparams] = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);

$sql = "SELECT cm.id AS cmid,
sess.name AS sessionname,
Expand Down Expand Up @@ -239,7 +239,7 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
}
$questionids = $DB->get_fieldset_select('realtimequiz_question', 'id', 'quizid = ?', [$cm->instance]);
if ($questionids) {
list($qsql, $params) = $DB->get_in_or_equal($questionids, SQL_PARAMS_NAMED);
[$qsql, $params] = $DB->get_in_or_equal($questionids, SQL_PARAMS_NAMED);
$params['userid'] = $userid;
$DB->delete_records_select('realtimequiz_submitted', "questionid $qsql AND userid = :userid", $params);
}
Expand All @@ -249,7 +249,7 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
/**
* Get the list of users who have data within a context.
*
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*/
public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();
Expand All @@ -263,7 +263,7 @@ public static function get_users_in_context(userlist $userlist) {
$params = [
'modid' => $modid,
'contextlevel' => CONTEXT_MODULE,
'contextid' => $context->id,
'contextid' => $context->id,
];

// Quiz responses.
Expand All @@ -283,7 +283,7 @@ public static function get_users_in_context(userlist $userlist) {
/**
* Delete multiple users within a single context.
*
* @param approved_userlist $userlist The approved context and user information to delete information for.
* @param approved_userlist $userlist The approved context and user information to delete information for.
*/
public static function delete_data_for_users(approved_userlist $userlist) {
global $DB;
Expand All @@ -298,7 +298,7 @@ public static function delete_data_for_users(approved_userlist $userlist) {

// Prepare SQL to gather all completed IDs.
$userids = $userlist->get_userids();
list($insql, $inparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
[$insql, $inparams] = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);

// Delete quiz responses.
$DB->delete_records_select(
Expand Down
54 changes: 27 additions & 27 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,66 +24,66 @@

defined('MOODLE_INTERNAL') || die();

$capabilities = array(
$capabilities = [

// Can start a quiz and move on to the next question
// NB: must have 'attempt' as well to be able to see the questions.
'mod/realtimequiz:control' => array(
'mod/realtimequiz:control' => [

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
'legacy' => [
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
'manager' => CAP_ALLOW,
],
],

// Can try to answer the quiz.
'mod/realtimequiz:attempt' => array(
'mod/realtimequiz:attempt' => [

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
'legacy' => [
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
'manager' => CAP_ALLOW,
],
],

// Can see who gave what answer.
'mod/realtimequiz:seeresponses' => array(
'mod/realtimequiz:seeresponses' => [

'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
'legacy' => [
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
'manager' => CAP_ALLOW,
],
],

// Can add / delete / update questions.
'mod/realtimequiz:editquestions' => array(
'mod/realtimequiz:editquestions' => [

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
'legacy' => [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
'manager' => CAP_ALLOW,
],
],

// Can add an instance of this module to a course.
'mod/realtimequiz:addinstance' => array(
'mod/realtimequiz:addinstance' => [
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'legacy' => [
'editingteacher' => CAP_ALLOW,
'coursecreator' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
)
);
'manager' => CAP_ALLOW,
],
],
];

Loading

0 comments on commit e275af3

Please sign in to comment.