Skip to content

Commit

Permalink
Fix intendation #74 (second step)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbadusch committed Mar 12, 2024
1 parent 545a171 commit 39c06a7
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 87 deletions.
24 changes: 12 additions & 12 deletions classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -1226,12 +1226,12 @@ public static function get_pushtokens(int $userid) {
'activeuserid' => $activeuserid,
];
$sql = "SELECT *
FROM {mooduell_games}
WHERE (playeraid = ' . :userid . '
OR playerbid =' . :userid . ')
AND (playeraid = ' . :activeuserid . '
OR playerbid =' . :activeuserid . ')
AND status != 3";
FROM {mooduell_games}
WHERE (playeraid = ' . :userid . '
OR playerbid =' . :userid . ')
AND (playeraid = ' . :activeuserid . '
OR playerbid =' . :activeuserid . ')
AND status != 3";
$data = $DB->get_records_sql($sql, $paramsarray);

if (!$data || count($data) == 0) {
Expand Down Expand Up @@ -1303,12 +1303,12 @@ public static function set_pushtokens(int $userid, string $identifier, string $m
'activeuserid' => $activeuserid,
];
$sql = "SELECT *
FROM {mooduell_games}
WHERE (playeraid = ' . :userid . '
OR playerbid =' . :userid . ')
AND (playeraid = ' . :activeuserid . '
OR playerbid =' . :activeuserid . ')
AND status != 3";
FROM {mooduell_games}
WHERE (playeraid = ' . :userid . '
OR playerbid =' . :userid . ')
AND (playeraid = ' . :activeuserid . '
OR playerbid =' . :activeuserid . ')
AND status != 3";
$data = $DB->get_records_sql($sql, $paramsarray);

if (!$data || count($data) == 0) {
Expand Down
22 changes: 10 additions & 12 deletions classes/game_control.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ public static function get_user_stats(int $userid, $mooduellid = null) {
// Get all the games where player was either Player A or Player B AND game is finished.
$params = ['userid' => $userid];
$sql = "SELECT *
FROM {mooduell_games}
WHERE (playeraid = ' . :userid . '
OR playerbid =' . :userid . ')";
FROM {mooduell_games}
WHERE (playeraid = ' . :userid . '
OR playerbid =' . :userid . ')";
$data = $DB->get_records_sql($sql, $params);

$wongames = 0;
Expand Down Expand Up @@ -527,17 +527,15 @@ public function get_questions() {

if ($CFG->version >= 2022041900) {
$sql = "SELECT q.*, qc.contextid, qc.name AS categoryname, qbe.questioncategoryid AS category
FROM {question} q
JOIN {question_versions} qv ON q.id=qv.questionid
JOIN {question_bank_entries} qbe ON qbe.id=qv.questionbankentryid
JOIN {question_categories} qc ON qbe.questioncategoryid=qc.id
WHERE q.id $inorequal";
FROM {question} q
JOIN {question_versions} qv ON q.id=qv.questionid
JOIN {question_bank_entries} qbe ON qbe.id=qv.questionbankentryid
JOIN {question_categories} qc ON qbe.questioncategoryid=qc.id
WHERE q.id $inorequal";
} else {
$sql = "SELECT *
FROM {question} q
WHERE q.id $inorequal";
FROM {question} q
WHERE q.id $inorequal";
}
if (!$questionsdata = $DB->get_records_sql($sql, $params)) {
throw new moodle_exception('wrongnumberofquestions2', 'mooduell', null, null,
Expand Down
13 changes: 6 additions & 7 deletions classes/manage_tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ public static function generate_tokens_for_all_instance_users(int $cmid) {
// Currently, ALL users enrolled in the course to which a MooDuell instance has been added, will be selected.
$sql =
'SELECT DISTINCT ue.userid
FROM {user_enrolments} ue
LEFT JOIN {enrol} e
ON e.id = ue.enrolid
WHERE e.courseid IN (
SELECT cm.course
FROM {course_modules} cm
WHERE cm.id = :cmid
FROM {user_enrolments} ue
LEFT JOIN {enrol} e ON e.id = ue.enrolid
WHERE e.courseid IN (
SELECT cm.course
FROM {course_modules} cm
WHERE cm.id = :cmid
)';

if ($records = $DB->get_records_sql($sql, ['cmid' => $cmid])) {
Expand Down
133 changes: 78 additions & 55 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,14 @@ public static function get_contexts_for_userid(int $userid): contextlist {
// Look up all mooduell games of a specific user.
$sql = "SELECT c.id
FROM {context} c
INNER JOIN {course_modules} cm ON cm.id = c.instanceid AND c.contextlevel = :contextlevel
INNER JOIN {modules} m ON m.id = cm.module AND m.name = :modname
INNER JOIN {mooduell} md ON md.id = cm.instance
INNER JOIN {mooduell_games} mdg ON mdg.mooduellid = md.id
WHERE mdg.playeraid = :userida OR mdg.playerbid = :useridb";
INNER JOIN {course_modules} cm ON cm.id = c.instanceid
AND c.contextlevel = :contextlevel
INNER JOIN {modules} m ON m.id = cm.module
AND m.name = :modname
INNER JOIN {mooduell} md ON md.id = cm.instance
INNER JOIN {mooduell_games} mdg ON mdg.mooduellid = md.id
WHERE mdg.playeraid = :userida
OR mdg.playerbid = :useridb";

$params = [
'modname' => 'mooduell',
Expand All @@ -157,10 +160,12 @@ public static function get_contexts_for_userid(int $userid): contextlist {
// Look up all mooduell highscores of a specific user.
$sql = "SELECT c.id
FROM {context} c
INNER JOIN {course_modules} cm ON cm.id = c.instanceid AND c.contextlevel = :contextlevel
INNER JOIN {modules} m ON m.id = cm.module AND m.name = :modname
INNER JOIN {mooduell} md ON md.id = cm.instance
INNER JOIN {mooduell_highscores} mdh ON mdh.mooduellid = md.id
INNER JOIN {course_modules} cm ON cm.id = c.instanceid
AND c.contextlevel = :contextlevel
INNER JOIN {modules} m ON m.id = cm.module
AND m.name = :modname
INNER JOIN {mooduell} md ON md.id = cm.instance
INNER JOIN {mooduell_highscores} mdh ON mdh.mooduellid = md.id
WHERE mdh.userid = :userid";

$params = [
Expand Down Expand Up @@ -234,16 +239,16 @@ public static function delete_data_for_all_users_in_context(\context $context) {

// To delete the pushtokens, we must first find out all users (game players).
$getallplayerssql = 'SELECT DISTINCT userid
FROM (
SELECT playeraid AS userid
FROM {mooduell_games}
WHERE mooduellid = :cminstance
UNION
SELECT playerbid AS userid
FROM {mooduell_games}
WHERE mooduellid = :cminstance
) s
ORDER BY userid ASC
FROM (
SELECT playeraid AS userid
FROM {mooduell_games}
WHERE mooduellid = :cminstance
UNION
SELECT playerbid AS userid
FROM {mooduell_games}
WHERE mooduellid = :cminstance
) s
ORDER BY userid ASC
';

$records = $DB->get_records_sql($getallplayerssql, ['cminstance' => $cm->instance]);
Expand Down Expand Up @@ -279,8 +284,10 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
}

// Before deleting mooduell_games we have to delete the associated mooduell_questions data.
$where = 'gameid in (SELECT id FROM {mooduell_games} WHERE mooduellid = :mooduellid AND ' .
'(playeraid = :playeraid OR playerbid = :playerbid))';
$where = 'gameid in (SELECT id
FROM {mooduell_games}
WHERE mooduellid = :mooduellid
AND ' . '(playeraid = :playeraid OR playerbid = :playerbid))';
$DB->delete_records_select('mooduell_questions', $where, [
'mooduellid' => $instanceid,
'playeraid' => $userid,
Expand Down Expand Up @@ -311,7 +318,8 @@ public static function get_users_in_context(userlist $userlist) {
// Add all games where user is playera.
$sql = "SELECT mdg.playeraid
FROM {course_modules} cm
JOIN {modules} m ON m.id = cm.module AND m.name = :modname
JOIN {modules} m ON m.id = cm.module
AND m.name = :modname
JOIN {mooduell} md ON md.id = cm.instance
JOIN {mooduell_games} mdg ON mdg.mooduellid = md.id
WHERE cm.id = :cmid";
Expand All @@ -326,7 +334,8 @@ public static function get_users_in_context(userlist $userlist) {
// Add all games where user is playerb.
$sql = "SELECT mdg.playerbid
FROM {course_modules} cm
JOIN {modules} m ON m.id = cm.module AND m.name = :modname
JOIN {modules} m ON m.id = cm.module
AND m.name = :modname
JOIN {mooduell} md ON md.id = cm.instance
JOIN {mooduell_games} mdg ON mdg.mooduellid = md.id
WHERE cm.id = :cmid";
Expand Down Expand Up @@ -388,13 +397,17 @@ protected static function export_all_mooduells(approved_contextlist $contextlist
list($contextsql, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);

$sql = "SELECT mdg.*, cm.id AS cmid, md.name AS mooduellname, u.firstname, u.lastname
FROM {course_modules} cm
JOIN {modules} m ON cm.module = m.id AND m.name = :modname
JOIN {context} c ON cm.id = c.instanceid AND c.contextlevel = :contextlevel
JOIN {mooduell} md ON cm.instance = md.id
JOIN {mooduell_games} mdg ON mdg.mooduellid = md.id AND mdg.playeraid = :userida OR mdg.playerbid = :useridb
LEFT JOIN {user} u ON u.id = :userid
WHERE c.id {$contextsql}";
FROM {course_modules} cm
JOIN {modules} m ON cm.module = m.id
AND m.name = :modname
JOIN {context} c ON cm.id = c.instanceid
AND c.contextlevel = :contextlevel
JOIN {mooduell} md ON cm.instance = md.id
JOIN {mooduell_games} mdg ON mdg.mooduellid = md.id
AND mdg.playeraid = :userida
OR mdg.playerbid = :useridb
LEFT JOIN {user} u ON u.id = :userid
WHERE c.id {$contextsql}";

$params = [
'modname' => 'mooduell',
Expand Down Expand Up @@ -484,13 +497,16 @@ protected static function export_all_highscores(approved_contextlist $contextlis
list($contextsql, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);

$sql = "SELECT mdh.*, cm.id AS cmid, u.firstname, u.lastname, md.name AS mooduellname
FROM {course_modules} cm
JOIN {modules} m ON cm.module = m.id AND m.name = :modname
JOIN {context} c ON cm.id = c.instanceid AND c.contextlevel = :contextlevel
JOIN {mooduell} md ON cm.instance = md.id
JOIN {mooduell_highscores} mdh ON mdh.mooduellid = md.id AND mdh.userid = :userid
LEFT JOIN {user} u ON u.id = :userid2
WHERE c.id {$contextsql}";
FROM {course_modules} cm
JOIN {modules} m ON cm.module = m.id
AND m.name = :modname
JOIN {context} c ON cm.id = c.instanceid
AND c.contextlevel = :contextlevel
JOIN {mooduell} md ON cm.instance = md.id
JOIN {mooduell_highscores} mdh ON mdh.mooduellid = md.id
AND mdh.userid = :userid
LEFT JOIN {user} u ON u.id = :userid2
WHERE c.id {$contextsql}";

$params = [
'modname' => 'mooduell',
Expand Down Expand Up @@ -544,13 +560,15 @@ protected static function export_all_pushtokens(approved_contextlist $contextlis
list($contextsql, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);

$sql = "SELECT mdp.*, cm.id AS cmid, u.firstname, u.lastname
FROM {course_modules} cm
JOIN {modules} m ON cm.module = m.id AND m.name = :modname
JOIN {context} c ON cm.id = c.instanceid AND c.contextlevel = :contextlevel
JOIN {mooduell} md ON cm.instance = md.id
JOIN {mooduell_pushtokens} mdp ON mdp.userid = :userid
LEFT JOIN {user} u ON u.id = :userid2
WHERE c.id {$contextsql}";
FROM {course_modules} cm
JOIN {modules} m ON cm.module = m.id
AND m.name = :modname
JOIN {context} c ON cm.id = c.instanceid
AND c.contextlevel = :contextlevel
JOIN {mooduell} md ON cm.instance = md.id
JOIN {mooduell_pushtokens} mdp ON mdp.userid = :userid
LEFT JOIN {user} u ON u.id = :userid2
WHERE c.id {$contextsql}";

$params = [
'modname' => 'mooduell',
Expand Down Expand Up @@ -594,17 +612,22 @@ protected static function export_all_questiondata(approved_contextlist $contextl
list($contextsql, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);

$sql = "SELECT mdq.*, cm.id AS cmid, q.questiontext, md.name as mooduellname
FROM {course_modules} cm
JOIN {modules} m ON cm.module = m.id AND m.name = :modname
JOIN {context} c ON cm.id = c.instanceid AND c.contextlevel = :contextlevel
JOIN {mooduell} md ON cm.instance = md.id
JOIN (SELECT mq.*, mg.playeraid, mg.playerbid
FROM {mooduell_questions} mq
JOIN {mooduell_games} mg
ON mq.mooduellid = mg.mooduellid AND mq.gameid = mg.id) mdq
ON mdq.mooduellid = md.id AND (mdq.playeraid = :playeraid OR mdq.playerbid = :playerbid)
LEFT JOIN {question} q ON q.id = mdq.questionid
WHERE c.id {$contextsql}";
FROM {course_modules} cm
JOIN {modules} m ON cm.module = m.id
AND m.name = :modname
JOIN {context} c ON cm.id = c.instanceid
AND c.contextlevel = :contextlevel
JOIN {mooduell} md ON cm.instance = md.id
JOIN (SELECT mq.*, mg.playeraid, mg.playerbid
FROM {mooduell_questions} mq
JOIN {mooduell_games} mg
ON mq.mooduellid = mg.mooduellid
AND mq.gameid = mg.id) mdq
ON mdq.mooduellid = md.id
AND (mdq.playeraid = :playeraid
OR mdq.playerbid = :playerbid)
LEFT JOIN {question} q ON q.id = mdq.questionid
WHERE c.id {$contextsql}";

$params = [
'modname' => 'mooduell',
Expand Down
4 changes: 3 additions & 1 deletion classes/question_control.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ public function return_answers($listofanswers = null): array {

// For drag and drop with text (ddwtos) questions, the order is important.
// So use ORDER BY in an SQL statement instead of get_records.
$sql = "SELECT * FROM {question_answers} WHERE question = :questionid ORDER BY id ASC";
$sql = "SELECT *
FROM {question_answers}
WHERE question = :questionid ORDER BY id ASC";
$params = [
'questionid' => $this->questionid,
];
Expand Down

0 comments on commit 39c06a7

Please sign in to comment.