Added clauses to exclude deleted users from the queries
This commit is contained in:
parent
5bd10de529
commit
3ba4d4d4c5
|
@ -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
|
$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";
|
ORDER BY u.lastname, u.firstname";
|
||||||
$rs = $DB->get_recordset_sql($sql, ['studyplan_id' => $studyplanid]);
|
$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 {cohort_members} cm ON u.id = cm.userid
|
||||||
LEFT JOIN {local_treestudyplan_cohort} tc ON cm.cohortid = tc.cohort_id
|
LEFT JOIN {local_treestudyplan_cohort} tc ON cm.cohortid = tc.cohort_id
|
||||||
LEFT JOIN {local_treestudyplan_user} tu ON u.id = tu.user_id
|
LEFT JOIN {local_treestudyplan_user} tu ON u.id = tu.user_id
|
||||||
WHERE tc.studyplan_id = :studyplanid
|
WHERE ( tc.studyplan_id = :studyplanid
|
||||||
OR tu.studyplan_id = :studyplanidtoo
|
OR tu.studyplan_id = :studyplanidtoo )
|
||||||
|
AND u.deleted != 1
|
||||||
ORDER BY u.lastname, u.firstname";
|
ORDER BY u.lastname, u.firstname";
|
||||||
$rs = $DB->get_recordset_sql($sql, ["studyplanid" => $studyplan->id(), "studyplanidtoo" => $studyplan->id()]);
|
$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
|
$sql = "SELECT DISTINCT u.id, u.username, u.firstname, u.lastname, u.idnumber, u.email
|
||||||
FROM {user} u
|
FROM {user} u
|
||||||
LEFT JOIN {cohort_members} cm ON u.id = cm.userid
|
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";
|
ORDER BY u.lastname, u.firstname";
|
||||||
$rs = $DB->get_recordset_sql($sql, ["cohortid" => $c->id]);
|
$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());
|
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
|
$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";
|
ORDER BY u.lastname, u.firstname";
|
||||||
$rs = $DB->get_recordset_sql($sql, ['studyplan_id' => $studyplanid]);
|
$rs = $DB->get_recordset_sql($sql, ['studyplan_id' => $studyplanid]);
|
||||||
|
|
||||||
|
|
|
@ -671,12 +671,14 @@ class studyplan {
|
||||||
$sql = "SELECT s.id FROM {local_treestudyplan} s
|
$sql = "SELECT s.id FROM {local_treestudyplan} s
|
||||||
INNER JOIN {local_treestudyplan_cohort} j ON j.studyplan_id = s.id
|
INNER JOIN {local_treestudyplan_cohort} j ON j.studyplan_id = s.id
|
||||||
INNER JOIN {cohort_members} cm ON j.cohort_id = cm.cohortid
|
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]);
|
$cohortplanids = $DB->get_fieldset_sql($sql, ['userid' => $userid]);
|
||||||
|
|
||||||
$sql = "SELECT s.id FROM {local_treestudyplan} s
|
$sql = "SELECT s.id FROM {local_treestudyplan} s
|
||||||
INNER JOIN {local_treestudyplan_user} j ON j.studyplan_id = s.id
|
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]);
|
$userplanids = $DB->get_fieldset_sql($sql, ['userid' => $userid]);
|
||||||
|
|
||||||
$plans = [];
|
$plans = [];
|
||||||
|
@ -703,12 +705,14 @@ class studyplan {
|
||||||
$sql = "SELECT COUNT(s.id) FROM {local_treestudyplan} s
|
$sql = "SELECT COUNT(s.id) FROM {local_treestudyplan} s
|
||||||
INNER JOIN {local_treestudyplan_cohort} j ON j.studyplan_id = s.id
|
INNER JOIN {local_treestudyplan_cohort} j ON j.studyplan_id = s.id
|
||||||
INNER JOIN {cohort_members} cm ON j.cohort_id = cm.cohortid
|
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]);
|
$count += $DB->count_records_sql($sql, ['userid' => $userid]);
|
||||||
|
|
||||||
$sql = "SELECT COUNT(s.id) FROM {local_treestudyplan} s
|
$sql = "SELECT COUNT(s.id) FROM {local_treestudyplan} s
|
||||||
INNER JOIN {local_treestudyplan_user} j ON j.studyplan_id = s.id
|
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]);
|
$count += $DB->count_records_sql($sql, ['userid' => $userid]);
|
||||||
|
|
||||||
return ($count > 0);
|
return ($count > 0);
|
||||||
|
@ -743,7 +747,8 @@ class studyplan {
|
||||||
$uids = [];
|
$uids = [];
|
||||||
// First get directly linked userids.
|
// First get directly linked userids.
|
||||||
$sql = "SELECT j.user_id FROM {local_treestudyplan_user} j
|
$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]);
|
$ulist = $DB->get_fieldset_sql($sql, ['planid' => $this->id]);
|
||||||
|
|
||||||
$uids = array_merge($uids, $ulist);
|
$uids = array_merge($uids, $ulist);
|
||||||
|
@ -754,7 +759,8 @@ class studyplan {
|
||||||
// Next het users linked though cohort.
|
// Next het users linked though cohort.
|
||||||
$sql = "SELECT cm.userid FROM {local_treestudyplan_cohort} j
|
$sql = "SELECT cm.userid FROM {local_treestudyplan_cohort} j
|
||||||
INNER JOIN {cohort_members} cm ON j.cohort_id = cm.cohortid
|
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]);
|
$ulist = $DB->get_fieldset_sql($sql, ['planid' => $this->id]);
|
||||||
|
|
||||||
$uids = array_merge($uids, $ulist);
|
$uids = array_merge($uids, $ulist);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user