Commit 558a368c authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

updated interactions stuff so it works with groups marked as deleted

parent 06994961
......@@ -32,8 +32,8 @@ require_once(get_config('docroot') . 'interaction/lib.php');
$id = param_integer('id');
if (!$group = get_record('group', 'id', $id)) {
throw new GroupNotFoundException('groupnotfound', 'group', $id);
if (!$group = get_record('group', 'id', $id, 'deleted', 0)) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $id));
}
if (!$group->owner == $USER->get('id')) {
......
......@@ -36,7 +36,10 @@ require_once('group.php');
$id = param_integer('id');
$instance = interaction_instance_from_id($id);
$group = get_record('group', 'id', $instance->get('group'));
if (!$group = get_record('group', 'id', $id, 'deleted', 0)) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $id));
}
$membership = user_can_access_group((int)$group->id);
if (!(bool)($membership & (GROUP_MEMBERSHIP_OWNER | GROUP_MEMBERSHIP_ADMIN | GROUP_MEMBERSHIP_STAFF))) {
......
......@@ -50,8 +50,8 @@ else {
}
safe_require('interaction', $plugin);
if (!$group = get_record('group', 'id', $groupid)) {
throw new GroupNotFoundException('groupnotfound', 'group', $groupid);
if (!$group = get_record('group', 'id', $groupid, 'deleted', 0)) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
}
$membership = user_can_access_group((int)$groupid);
if (!(bool)($membership & (GROUP_MEMBERSHIP_OWNER | GROUP_MEMBERSHIP_ADMIN | GROUP_MEMBERSHIP_STAFF))) {
......
......@@ -39,7 +39,7 @@ $post = get_record_sql(
INNER JOIN {interaction_forum_topic} t ON (p.topic = t.id AND t.deleted != 1)
INNER JOIN {interaction_forum_post} p2 ON (p2.topic = t.id AND p2.parent IS NULL)
INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted != 1)
INNER JOIN {group} g ON g.id = f.group
INNER JOIN {group} g ON (g.id = f.group AND g.deleted = ?)
LEFT JOIN (
SELECT fm.user, fm.forum
FROM {interaction_forum_moderator} fm
......@@ -52,7 +52,7 @@ $post = get_record_sql(
WHERE p.id = ?
AND p.deleted != 1
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13',
array($postid)
array(0, $postid)
);
......
......@@ -39,7 +39,7 @@ $topic = get_record_sql(
'SELECT f."group", f.id AS forumid, f.title, g.name AS groupname, p.poster, p.subject, p.body, COUNT(p2.*), ' . db_format_tsfield('p.ctime', 'ctime') . ', t.closed, m.user AS moderator, g.owner AS groupowner
FROM {interaction_forum_topic} t
INNER JOIN {interaction_instance} f ON (f.id = t.forum AND f.deleted != 1)
INNER JOIN {group} g ON g.id = f.group
INNER JOIN {group} g ON (g.id = f.group AND g.deleted = ?)
INNER JOIN {interaction_forum_post} p ON (p.topic = t.id AND p.parent IS NULL)
LEFT JOIN (
SELECT fm.user, fm.forum
......@@ -53,7 +53,7 @@ $topic = get_record_sql(
WHERE t.id = ?
AND t.deleted != 1
GROUP BY 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12',
array($topicid)
array(0, $topicid)
);
if (!$topic) {
......
......@@ -65,14 +65,14 @@ $parent = get_record_sql(
INNER JOIN {interaction_instance} f ON (fm.forum = f.id)
INNER JOIN {group_member} gm ON (gm.group = f.group AND gm.member = fm.user)
) m ON (m.user = p.poster AND m.forum = f.id)
INNER JOIN {group} g ON g.id = f.group
INNER JOIN {group} g ON (g.id = f.group AND g.deleted = ?)
INNER JOIN {interaction_forum_post} p3 ON (p.poster = p3.poster AND p3.deleted != 1)
INNER JOIN {interaction_forum_topic} t2 ON (t2.deleted != 1 AND p3.topic = t2.id)
INNER JOIN {interaction_instance} f2 ON (t2.forum = f2.id AND f2.deleted != 1 AND f2.group = f.group)
WHERE p.id = ?
AND p.deleted != 1
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15',
array($parentid)
array(0, $parentid)
);
if (!$parent) {
......
......@@ -60,10 +60,10 @@ else { // edit topic
$forum = get_record_sql(
'SELECT f.group AS group, f.title, g.name AS groupname
FROM {interaction_instance} f
INNER JOIN {group} g ON g.id = f.group
INNER JOIN {group} g ON (g.id = f.group AND g.deleted = ?)
WHERE f.id = ?
AND f.deleted != 1',
array($forumid)
AND f.deleted != ?',
array(0, $forumid, 1)
);
if (!$forum) {
throw new NotFoundException(get_string('cantfindforum', 'interaction.forum', $forumid));
......
......@@ -34,7 +34,7 @@ require_once(get_config('docroot') . 'interaction/lib.php');
$groupid = param_integer('group');
if (!record_exists('group', 'id', $groupid)) {
if (!record_exists('group', 'id', $groupid, 'deleted', 0)) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
}
......
......@@ -215,9 +215,10 @@ class PluginInteractionForum extends PluginInteraction {
INNER JOIN {interaction_forum_topic} t ON (t.deleted != 1 AND t.id = s.topic)
INNER JOIN {interaction_forum_post} p ON (p.sent != 1 AND p.ctime < ? AND p.deleted != 1 AND p.topic = t.id)
INNER JOIN {interaction_instance} f ON (f.id = t.forum AND f.deleted != 1)
INNER JOIN {group} g ON (g.id = g.group AND g.deleted = ?)
INNER JOIN {group_member} gm ON (gm.member = s.subscriber AND gm.group = f.group)
ORDER BY type, p.id',
array(db_format_timestamp($currenttime - 30 * 60))
array(db_format_timestamp($currenttime - 30 * 60), 0)
);
// query gets a new object for every subscription
// this combines all the objects for the same post together with an array for the subscribers
......@@ -277,17 +278,10 @@ class ActivityTypeInteractionForumNewPost extends ActivityTypePlugin {
$post = get_record_sql(
'SELECT p.subject, p.poster, t.id AS topicid, p2.subject AS topicsubject, f.title AS forumtitle
FROM {interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t
ON t.id = p.topic
AND t.deleted != 1
INNER JOIN {interaction_forum_post} p2
ON p2.parent IS NULL
AND p2.topic = t.id
INNER JOIN {interaction_instance} f
ON t.forum = f.id
AND f.deleted != 1
WHERE p.id = ?
AND p.deleted != 1',
INNER JOIN {interaction_forum_topic} t ON t.id = p.topic
INNER JOIN {interaction_forum_post} p2 ON (p2.parent IS NULL AND p2.topic = t.id)
INNER JOIN {interaction_instance} f ON t.forum = f.id
WHERE p.id = ?',
array($this->postid)
);
$this->url = get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $post->topicid;
......
......@@ -38,13 +38,13 @@ $topic = get_record_sql(
'SELECT p.subject, p.poster, p.id AS firstpost, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.id, f.group, g.name AS groupname, f.id AS forumid, f.title AS forumtitle, t.closed, sf.forum AS forumsubscribed, st.topic AS topicsubscribed, g.owner
FROM {interaction_forum_topic} t
INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted != 1)
INNER JOIN {group} g ON g.id = f.group
INNER JOIN {group} g ON (g.id = f.group AND g.deleted = ?)
INNER JOIN {interaction_forum_post} p ON (p.topic = t.id AND p.parent IS NULL)
LEFT JOIN {interaction_forum_subscription_forum} sf ON (sf.forum = f.id AND sf.user = ?)
LEFT JOIN {interaction_forum_subscription_topic} st ON (st.topic = t.id AND st.user = ?)
WHERE t.id = ?
AND t.deleted != 1',
array($USER->get('id'), $USER->get('id'), $topicid)
array(0, $USER->get('id'), $USER->get('id'), $topicid)
);
if (!$topic) {
......
......@@ -43,13 +43,13 @@ $offset = (int)($offset / $topicsperpage) * $topicsperpage;
$forum = get_record_sql(
'SELECT f.title, f.description, f.id, COUNT(t.*), s.forum AS subscribed, g.id AS group, g.name AS groupname, g.owner as groupowner
FROM {interaction_instance} f
INNER JOIN {group} g ON g.id = f."group"
INNER JOIN {group} g ON (g.id = f."group" AND g.deleted = ?)
LEFT JOIN {interaction_forum_topic} t ON (t.forum = f.id AND t.deleted != 1 AND t.sticky != 1)
LEFT JOIN {interaction_forum_subscription_forum} s ON (s.forum = f.id AND s."user" = ?)
WHERE f.id = ?
AND f.deleted != 1
GROUP BY 1, 2, 3, 5, 6, 7, 8',
array($userid, $forumid)
array(0, $userid, $forumid)
);
if (!$forum) {
......
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