From 3ba4d4d4c57a343a6a72393099eff31992edbb31 Mon Sep 17 00:00:00 2001 From: PMKuipers Date: Wed, 22 May 2024 23:18:05 +0200 Subject: [PATCH] Added clauses to exclude deleted users from the queries --- classes/associationservice.php | 11 ++++++----- classes/studyplan.php | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/classes/associationservice.php b/classes/associationservice.php index 5a41422..4790aa8 100644 --- a/classes/associationservice.php +++ b/classes/associationservice.php @@ -480,7 +480,7 @@ class associationservice extends \external_api { } $sql = "SELECT DISTINCT u.* FROM {user} u INNER JOIN {local_treestudyplan_user} j ON j.user_id = u.id - WHERE j.studyplan_id = :studyplan_id + WHERE j.studyplan_id = :studyplan_id AND u.deleted != 1 ORDER BY u.lastname, u.firstname"; $rs = $DB->get_recordset_sql($sql, ['studyplan_id' => $studyplanid]); @@ -573,8 +573,9 @@ class associationservice extends \external_api { LEFT JOIN {cohort_members} cm ON u.id = cm.userid LEFT JOIN {local_treestudyplan_cohort} tc ON cm.cohortid = tc.cohort_id LEFT JOIN {local_treestudyplan_user} tu ON u.id = tu.user_id - WHERE tc.studyplan_id = :studyplanid - OR tu.studyplan_id = :studyplanidtoo + WHERE ( tc.studyplan_id = :studyplanid + OR tu.studyplan_id = :studyplanidtoo ) + AND u.deleted != 1 ORDER BY u.lastname, u.firstname"; $rs = $DB->get_recordset_sql($sql, ["studyplanid" => $studyplan->id(), "studyplanidtoo" => $studyplan->id()]); @@ -638,7 +639,7 @@ class associationservice extends \external_api { $sql = "SELECT DISTINCT u.id, u.username, u.firstname, u.lastname, u.idnumber, u.email FROM {user} u LEFT JOIN {cohort_members} cm ON u.id = cm.userid - WHERE cm.cohortid = :cohortid + WHERE cm.cohortid = :cohortid AND u.deleted != 1 ORDER BY u.lastname, u.firstname"; $rs = $DB->get_recordset_sql($sql, ["cohortid" => $c->id]); @@ -895,7 +896,7 @@ class associationservice extends \external_api { webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context()); $sql = "SELECT DISTINCT u.* FROM {user} u INNER JOIN {local_treestudyplan_coach} j ON j.user_id = u.id - WHERE j.studyplan_id = :studyplan_id + WHERE j.studyplan_id = :studyplan_id AND u.deleted != 1 ORDER BY u.lastname, u.firstname"; $rs = $DB->get_recordset_sql($sql, ['studyplan_id' => $studyplanid]); diff --git a/classes/studyplan.php b/classes/studyplan.php index 08ccbac..437342a 100644 --- a/classes/studyplan.php +++ b/classes/studyplan.php @@ -671,12 +671,14 @@ class studyplan { $sql = "SELECT s.id FROM {local_treestudyplan} s INNER JOIN {local_treestudyplan_cohort} j ON j.studyplan_id = s.id INNER JOIN {cohort_members} cm ON j.cohort_id = cm.cohortid - WHERE cm.userid = :userid"; + INNER JOIN {user} u ON cm.userid = user.id + WHERE cm.userid = :userid AND u.deleted != 1"; $cohortplanids = $DB->get_fieldset_sql($sql, ['userid' => $userid]); $sql = "SELECT s.id FROM {local_treestudyplan} s INNER JOIN {local_treestudyplan_user} j ON j.studyplan_id = s.id - WHERE j.user_id = :userid"; + INNER JOIN {user} u ON j.user_id = u.id + WHERE j.user_id = :userid AND u.deleted != 1"; $userplanids = $DB->get_fieldset_sql($sql, ['userid' => $userid]); $plans = []; @@ -703,12 +705,14 @@ class studyplan { $sql = "SELECT COUNT(s.id) FROM {local_treestudyplan} s INNER JOIN {local_treestudyplan_cohort} j ON j.studyplan_id = s.id INNER JOIN {cohort_members} cm ON j.cohort_id = cm.cohortid - WHERE cm.userid = :userid"; + INNER JOIN {user} u ON cm.userid = user.id + WHERE cm.userid = :userid AND u.deleted != 1"; $count += $DB->count_records_sql($sql, ['userid' => $userid]); $sql = "SELECT COUNT(s.id) FROM {local_treestudyplan} s INNER JOIN {local_treestudyplan_user} j ON j.studyplan_id = s.id - WHERE j.user_id = :userid"; + INNER JOIN {user} u ON j.user_id = u.id + WHERE j.user_id = :userid AND u.deleted != 1"; $count += $DB->count_records_sql($sql, ['userid' => $userid]); return ($count > 0); @@ -743,7 +747,8 @@ class studyplan { $uids = []; // First get directly linked userids. $sql = "SELECT j.user_id FROM {local_treestudyplan_user} j - WHERE j.studyplan_id = :planid"; + INNER JOIN {user} u ON j.user_id = u.id + WHERE j.studyplan_id = :planid AND u.deleted != 1"; $ulist = $DB->get_fieldset_sql($sql, ['planid' => $this->id]); $uids = array_merge($uids, $ulist); @@ -754,7 +759,8 @@ class studyplan { // Next het users linked though cohort. $sql = "SELECT cm.userid FROM {local_treestudyplan_cohort} j INNER JOIN {cohort_members} cm ON j.cohort_id = cm.cohortid - WHERE j.studyplan_id = :planid"; + INNER JOIN {user} u ON cm.userid = user.id + WHERE j.studyplan_id = :planid AND u.deleted != 1"; $ulist = $DB->get_fieldset_sql($sql, ['planid' => $this->id]); $uids = array_merge($uids, $ulist);