Commit 44d6a382 authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

updated group pages so it works with groups marked as deleted

parent 558a368c
......@@ -31,7 +31,7 @@ require_once('pieforms/pieform.php');
require('group.php');
$groupid = param_integer('id');
$group = get_record('group', 'id', $groupid, 'owner', $USER->get('id'));
$group = get_record('group', 'id', $groupid, 'owner', $USER->get('id'), 'deleted', 0);
if (!$group) {
throw new AccessDeniedException(get_string('cantdeletegroup', 'group'));
......
......@@ -32,7 +32,7 @@ define('TITLE', get_string('editgroup', 'group'));
$id = param_integer('id');
$group_data = get_record('group', 'id', $id, 'owner', $USER->get('id'));
$group_data = get_record('group', 'id', $id, 'owner', $USER->get('id'), 'deleted', 0);
if (!$group_data) {
$SESSION->add_error_msg(get_string('canteditdontown'));
......
......@@ -43,22 +43,22 @@ if (empty($owned)) { // just get groups this user is a member of.
$count = get_record_sql('SELECT COUNT(distinct g.id) AS count
FROM {group} g
JOIN {group_member} gm ON gm.group = g.id
WHERE g.owner != ? AND gm.member = ?', array($userid, $userid));
WHERE g.owner != ? AND gm.member = ? AND deleted = ?', array($userid, $userid, 0));
$count = $count->count;
}
else {
$count = count_records_sql('SELECT COUNT(*) FROM {group} g WHERE g.owner = ?',
array($userid));
$count = count_records_sql('SELECT COUNT(*) FROM {group} g WHERE g.owner = ? AND deleted = ?',
array($userid, 0));
$datasql = 'SELECT g.id,g.jointype,g.name,g.owner,count(distinct gmr.group) as requestcount, COUNT(distinct v.view) AS hasviews
FROM {group} g
LEFT JOIN {group_member_request} gmr ON gmr.group = g.id
LEFT JOIN {view_access_group} v ON v.group = g.id
WHERE g.owner = ?
WHERE g.owner = ? AND g.deleted = ?
GROUP BY g.id,g.jointype,g.name,g.owner';
$data = get_records_sql_array($datasql,array($userid), $offset, $limit);
$data = get_records_sql_array($datasql,array($userid, 0), $offset, $limit);
}
if (!$data) {
......
......@@ -34,7 +34,7 @@ json_headers();
$leave = param_integer('leave');
if (!$group = get_record('group', 'id', $leave)) {
if (!$group = get_record('group', 'id', $leave, 'deleted', 0)) {
json_reply(true, get_string('invalidgroup', 'group'));
}
......
......@@ -32,7 +32,7 @@ require('group.php');
$groupid = param_integer('id');
$returnto = param_alpha('returnto', 'mygroups');
$group = get_record('group', 'id', $groupid);
$group = get_record('group', 'id', $groupid, 'deleted', 0);
if (!$group) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
}
......
......@@ -121,7 +121,9 @@ $form = pieform(array(
),
));
$count = count_records_sql('SELECT COUNT(g.*) FROM {group} g ' . $sql, $values);
$values[] = 0;
$count = count_records_sql('SELECT COUNT(g.*) FROM {group} g ' . $sql . ' WHERE g.deleted != ?', $values);
// almost the same as query used in find - common parts should probably be pulled out
// gets the groups filtered by
......@@ -148,6 +150,7 @@ $sql = 'SELECT g.id, g.name, g.description, g.owner, g.jointype, m.member1 AS me
LEFT JOIN {group_member} gm2 ON (gm2.group = g.id)
LEFT JOIN {group_member_request} gmr ON (gmr.group = g.id)' .
$sql . '
WHERE g.deleted = ?
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8
ORDER BY g.name';
......
......@@ -36,7 +36,7 @@ $action = param_variable('action');
if ($action == 'delete') {
$id = param_integer('id');
// check owner
$owner = get_field('group', 'owner', 'id', $id);
$owner = get_field('group', 'owner', 'id', $id, 'deleted', 0);
if ($owner != $USER->get('id')) {
json_reply('local', get_string('cantdeletegroupdontown', 'group'));
}
......
......@@ -32,7 +32,7 @@ require('group.php');
$groupid = param_integer('id');
$returnto = param_alpha('returnto', 'mygroups');
$group = get_record('group', 'id', $groupid);
$group = get_record('group', 'id', $groupid, 'deleted', 0);
if (!$group) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
}
......
......@@ -46,7 +46,7 @@ $data = array();
if (!$membership = user_can_access_group($id)) {
group_json_empty();
}
$group = get_record('group', 'id', $id);
$group = get_record('group', 'id', $id, 'deleted', 0);
$dbnow = db_format_timestamp(time());
......
......@@ -35,7 +35,7 @@ $id = param_integer('id');
$joincontrol = param_alpha('joincontrol', null);
$pending = param_integer('pending', 0);
if (!$group = get_record('group', 'id', $id)) {
if (!$group = get_record('group', 'id', $id, 'deleted', 0)) {
throw new GroupNotFoundException("Couldn't find group with id $id");
}
$group->ownername = display_name(get_record('usr', 'id', $group->owner));
......
......@@ -39,7 +39,7 @@ function group_user_can_leave($group, $userid=null) {
$userid = optional_userid($userid);
if (is_numeric($group)) {
if (!$group = get_record('group', 'id', $group)) {
if (!$group = get_record('group', 'id', $group, 'deleted', 0)) {
return false;
}
}
......@@ -91,8 +91,8 @@ function get_member_groups($userid=0, $offset=0, $limit=0) {
FROM {group} g
JOIN {group_member} gm ON gm.group = g.id
LEFT JOIN {view_access_group} v ON v.group = g.id
WHERE g.owner != ? AND gm.member = ?
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9', array($userid, $userid), $offset, $limit);
WHERE g.owner != ? AND gm.member = ? AND g.deleted = ?
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9', array($userid, $userid, 0), $offset, $limit);
}
......@@ -108,8 +108,8 @@ function get_owned_groups($userid=0, $jointype=null) {
$userid = optional_userid($userid);
$sql = 'SELECT g.* FROM {group} g
WHERE g.owner = ?';
$values = array($userid);
WHERE g.owner = ? AND g.deleted = ?';
$values = array($userid, 0);
if (!empty($jointype)) {
$sql .= ' AND jointype = ?';
......@@ -132,7 +132,7 @@ function get_invited_groups($userid=0) {
return get_records_sql_array('SELECT g.*, gmi.ctime, gmi.reason
FROM {group} g
JOIN {group_member_invite} gmi ON gmi.group = g.id
WHERE gmi.member = ?', array($userid));
WHERE gmi.member = ? AND g.deleted = ?', array($userid, 0));
}
/**
......@@ -149,7 +149,7 @@ function get_requested_group($userid=0) {
return get_records_sql_array('SELECT g.*, gmr.ctime, gmr.reason
FROM {group} g
JOIN {group_member_request} gmr ON gmr.group = g.id
WHERE gmr.member = ?', array($userid));
WHERE gmr.member = ? AND g.deleted = ?', array($userid, 0));
}
/**
......@@ -176,9 +176,9 @@ function get_associated_groups($userid=0) {
UNION
SELECT gm.group, 'tutor' AS type
FROM {group_member} gm WHERE gm.member = ? AND gm.tutor = 1
) AS a ON a.group = g.id";
) AS a ON a.group = g.id AND g.deleted = ?";
return get_records_sql_assoc($sql, array($userid, $userid, $userid, $userid));
return get_records_sql_assoc($sql, array($userid, $userid, $userid, $userid, 0));
}
......@@ -195,8 +195,8 @@ function get_tutor_groups($userid=0, $jointype=null) {
$sql = 'SELECT DISTINCT g.*, gm.ctime
FROM {group} g
LEFT JOIN {group_member} gm ON gm.group = g.id
WHERE (g.owner = ? OR (gm.member = ? AND gm.tutor = ?))';
$values = array($userid, $userid, 1);
WHERE (g.owner = ? OR (gm.member = ? AND gm.tutor = ?) AND g.deleted = ?)';
$values = array($userid, $userid, 1, 0);
if (!empty($jointype)) {
$sql .= ' AND g.jointype = ? ';
......@@ -239,7 +239,7 @@ function user_can_access_group($group, $user=null) {
}
if (is_int($group)) {
$group = get_record('group', 'id', $group);
$group = get_record('group', 'id', $group, 'deleted', 0);
}
if (!is_object($group)) {
......
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