Commit 0e2f1c39 authored by Richard Mansfield's avatar Richard Mansfield

Update queries using view_access_group,view_access_usr,view_access_token

Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent c3c9f247
......@@ -47,7 +47,7 @@ define('TITLE', get_string('deletespecifiedgroup', 'group', $group->name));
$views = count_records_sql(
'SELECT COUNT(*)
FROM {view_access_group} a
FROM {view_access} a
WHERE a.group = ?',
array($groupid)
);
......
......@@ -48,16 +48,6 @@ if (!group_user_can_leave($group)) {
$goto = get_config('wwwroot') . 'group/' . $returnto . '.php' . ($returnto == 'view' ? ('?id=' . $groupid) : '');
$views = count_records_sql(
'SELECT COUNT(*)
FROM {view} v
INNER JOIN {view_access_group} a
ON a.group = ?
AND a.view = v.id
WHERE v.owner = ?',
array($groupid, $USER->get('id'))
);
$form = pieform(array(
'name' => 'leavegroup',
'renderer' => 'div',
......@@ -79,7 +69,7 @@ $form = pieform(array(
$smarty = smarty();
$smarty->assign('subheading', get_string('leavespecifiedgroup', 'group', $group->name));
$smarty->assign('form', $form);
$smarty->assign('message', $views ? get_string('groupconfirmleavehasviews', 'group') : get_string('groupconfirmleave', 'group'));
$smarty->assign('message', get_string('groupconfirmleave', 'group');
$smarty->assign('group', $group);
$smarty->display('group/leave.tpl');
......
......@@ -231,20 +231,20 @@ function activity_get_viewaccess_users($view, $owner, $type) {
FROM {usr_friend} f
JOIN {view} v ON (v.owner = f.usr1 OR v.owner = f.usr2)
JOIN {view_access} vu ON vu.view = v.id
WHERE (usr1 = ? OR usr2 = ?) AND vu.accesstype = ? AND v.id = ?
WHERE (usr1 = ? OR usr2 = ?) AND vu.accesstype = 'friends' AND v.id = ?
UNION SELECT usr AS userid
FROM {view_access_usr} u
FROM {view_access} u
WHERE u.view = ?
UNION SELECT m.member
FROM {group_member} m
JOIN {view_access_group} vg ON vg.group = m.group
JOIN {view_access} vg ON vg.group = m.group
JOIN {group} g ON (g.id = vg.group AND g.deleted = 0)
WHERE vg.view = ? AND (vg.role IS NULL OR vg.role = m.role)
) AS userlist
JOIN {usr} u ON u.id = userlist.userid
LEFT JOIN {usr_activity_preference} p ON p.usr = u.id AND p.activity = ?
LEFT JOIN {usr_account_preference} ap ON ap.usr = u.id AND ap.field = 'lang'";
$values = array($owner, $owner, $owner, 'friends', $view, $view, $view, $type->id);
$values = array($owner, $owner, $owner, $view, $view, $view, $type->id);
if (!$u = get_records_sql_assoc($sql, $values)) {
$u = array();
}
......
......@@ -428,8 +428,6 @@ function group_user_can_leave($group, $userid=null) {
/**
* Removes a user from a group.
*
* Also removes view access given by the user to the group
*
* @param int $groupid ID of group
* @param int $userid ID of user to remove
*/
......@@ -438,19 +436,7 @@ function group_remove_user($groupid, $userid=null, $force=false) {
if (!$force && !group_user_can_leave($groupid, $userid)) {
throw new AccessDeniedException(get_string('usercantleavegroup', 'group'));
}
db_begin();
delete_records('group_member', 'group', $groupid, 'member', $userid);
delete_records_sql(
'DELETE FROM {view_access_group}
WHERE "group" = ?
AND "view" IN (
SELECT v.id
FROM {view} v
WHERE v.owner = ?
)',
array($groupid, $userid)
);
db_commit();
require_once(get_config('docroot') . 'interaction/lib.php');
$interactions = get_column('interaction_instance', 'id', 'group', $groupid);
......
......@@ -1641,12 +1641,12 @@ function can_view_view($view_id, $user_id=null, $usertoken=null, $mnettoken=null
WHERE "view" = ?
UNION
SELECT \'user\' AS type, 2 AS typeorder, ' . db_format_tsfield('startdate') . ', ' . db_format_tsfield('stopdate') . '
FROM {view_access_usr}
FROM {view_access}
WHERE "view" = ? AND usr = ?
UNION
SELECT \'group\' AS type, 3 AS typeorder, ' . db_format_tsfield('startdate') . ', ' . db_format_tsfield('stopdate') . '
FROM
{view_access_group} vg
{view_access} vg
INNER JOIN {group} g ON (vg.group = g.id AND g.deleted = 0)
INNER JOIN {group_member} m ON (g.id = m.group AND (vg.role IS NULL OR vg.role = m.role))
WHERE vg.view = ? AND m.member = ?
......@@ -1680,7 +1680,7 @@ function get_view_from_token($token, $visible=true) {
}
return get_field_sql('
SELECT "view"
FROM {view_access_token}
FROM {view_access}
WHERE token = ? AND visible = ?
AND (startdate IS NULL OR startdate < current_timestamp)
AND (stopdate IS NULL OR stopdate > current_timestamp)
......@@ -1788,7 +1788,7 @@ function get_views($users, $userlooking=null, $limit=5, $type=null) {
' . db_format_tsfield('ctime') . '
FROM
{view} v
INNER JOIN {view_access_usr} a ON v.id=a.view AND a.usr=?
INNER JOIN {view_access} a ON v.id=a.view AND a.usr=?
WHERE
v.owner IN (' . join(',',array_map('db_quote', array_keys($users))) . ')
AND ( v.startdate IS NULL OR v.startdate < ? )
......@@ -1816,7 +1816,7 @@ function get_views($users, $userlooking=null, $limit=5, $type=null) {
' . db_format_tsfield('v.ctime','ctime') . '
FROM
{view} v
INNER JOIN {view_access_group} a ON v.id=a.view
INNER JOIN {view_access} a ON v.id=a.view
INNER JOIN {group_member} m ON m.group=a.group AND m.member=?
INNER JOIN {group} g ON (g.id = a.group AND g.deleted = ?)
WHERE
......
......@@ -1057,7 +1057,7 @@ function delete_user($userid) {
delete_records('usr_institution_request', 'usr', $userid);
delete_records('usr_password_request', 'usr', $userid);
delete_records('usr_watchlist_view', 'usr', $userid);
delete_records('view_access_usr', 'usr', $userid);
delete_records('view_access', 'usr', $userid);
// Remove the user's views & artefacts
$viewids = get_column('view', 'id', 'owner', $userid);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment