Commit eac80d83 authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan

fixed so users in the moderators table who are no longer members don't show up as moderators

added relative dates
parent 68ce2190
......@@ -38,7 +38,12 @@ $post = get_record_sql(
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
LEFT JOIN {interaction_forum_moderator} m ON (m.forum = f.id AND m.user = p.poster)
LEFT JOIN (
SELECT fm.user, fm.forum
FROM {interaction_forum_moderator} fm
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.forum = f.id AND m.user = p.poster)
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)
......@@ -68,7 +73,7 @@ if (!$post->parent) {
}
define('TITLE', get_string('deletepost', 'interaction.forum') . ' - ' . $post->topicsubject);
$post->ctime = strftime(get_string('strftimerecentfull'), $post->ctime);
$post->ctime = relative_date(get_string('strftimerecentfullrelative', 'interaction.forum'), get_string('strftimerecentfull'), $post->ctime);
$breadcrumbs = array(
array(
......
......@@ -38,7 +38,12 @@ $topic = get_record_sql(
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 {interaction_forum_post} p ON (p.topic = t.id AND p.parent IS NULL)
LEFT JOIN {interaction_forum_moderator} m ON (m.user = p.poster AND m.forum = t.forum)
LEFT JOIN (
SELECT fm.user, fm.forum
FROM {interaction_forum_moderator} fm
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 = t.forum)
INNER JOIN {interaction_forum_post} p2 ON (p.poster = p2.poster AND p2.deleted != 1)
INNER JOIN {interaction_forum_topic} t2 ON (t2.deleted != 1 AND p2.topic = t2.id)
INNER JOIN {interaction_instance} f2 ON (t2.forum = f2.id AND f2.deleted != 1 AND f2.group = f.group)
......@@ -58,7 +63,7 @@ $admin = (bool)($membership & (GROUP_MEMBERSHIP_OWNER | GROUP_MEMBERSHIP_ADMIN |
$moderator = $admin || is_forum_moderator((int)$topic->forumid);
$topic->ctime = strftime(get_string('strftimerecentfull'), $topic->ctime);
$topic->ctime = relative_date(get_string('strftimerecentfullrelative', 'interaction.forum'), get_string('strftimerecentfull'), $topic->ctime);
if (!$moderator) {
throw new AccessDeniedException(get_string('cantdeletetopic', 'interaction.forum'));
......
......@@ -44,7 +44,12 @@ if ($postid == 0) { // post reply
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)
LEFT JOIN {interaction_forum_moderator} m ON (m.user = p.poster AND m.forum = f.id)
LEFT JOIN (
SELECT fm.user, fm.forum
FROM {interaction_forum_moderator} fm
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 {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)
......@@ -117,7 +122,12 @@ else { // edit post
FROM {interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t ON (p.topic = t.id AND t.deleted != 1)
INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted != 1)
LEFT JOIN {interaction_forum_moderator} m ON (m.user = p.poster AND m.forum = f.id)
LEFT JOIN (
SELECT fm.user, fm.forum
FROM {interaction_forum_moderator} fm
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 {interaction_forum_post} p2 ON (p.poster = p2.poster AND p2.deleted != 1)
WHERE p.id = ?
......@@ -175,7 +185,7 @@ else { // edit post
);
}
$parent->ctime = strftime(get_string('strftimerecentfull'), $parent->ctime);
$parent->ctime = relative_date(get_string('strftimerecentfullrelative', 'interaction.forum'), get_string('strftimerecentfull'), $parent->ctime);
// Javascript to hide the subject box if it has nothing in it, with a link you
// click to expand it.
......
......@@ -62,14 +62,19 @@ $breadcrumbs = array(
$forums = get_records_sql_array(
'SELECT f.id, f.title, f.description, m.user AS moderator, COUNT(t.*), s.forum AS subscribed
FROM {interaction_instance} f
LEFT JOIN {interaction_forum_moderator} m ON (m.forum = f.id)
LEFT JOIN (
SELECT fm.user, fm.forum
FROM {interaction_forum_moderator} fm
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.forum = f.id
LEFT JOIN {interaction_forum_topic} t ON (t.forum = f.id AND t.deleted != 1)
INNER JOIN {interaction_forum_instance_config} c ON (c.forum = f.id AND c.field = \'weight\')
LEFT JOIN {interaction_forum_subscription_forum} s ON (s.forum = f.id AND s."user" = ?)
WHERE f.group = ?
AND f.deleted != 1
GROUP BY 1, 2, 3, 4, 6, c.value
ORDER BY c.value',
ORDER BY c.value, m.user',
array($USER->get('id'), $groupid)
);
......
......@@ -120,4 +120,9 @@ $string['unsubscribefromforum'] = 'Unsubscribe from forum';
$string['unsubscribefromtopic'] = 'Unsubscribe from topic';
$string['updateselectedtopics'] = 'Update selected topics';
$string['today'] = 'Today';
$string['yesterday'] = 'Yesterday';
$string['strftimerecentrelative'] = '%%v, %%k:%%M';
$string['strftimerecentfullrelative'] = '%%v, %%l:%%M %%p';
?>
......@@ -29,7 +29,14 @@ class PluginInteractionForum extends PluginInteraction {
public static function instance_config_form($group, $instance=null) {
if (isset($instance)) {
$weight = get_field('interaction_forum_instance_config', 'value', 'field', '\'weight\'', 'forum', $instance->get('id'));
$moderators = get_column('interaction_forum_moderator', '"user"', 'forum', $instance->get('id'));
$moderators = get_column_sql(
'SELECT fm.user
FROM {interaction_forum_moderator} fm
INNER JOIN {interaction_instance} f ON f.id = fm.forum
INNER JOIN {group_member} gm ON gm.group = f.group AND fm.user = gm.member
WHERE fm.forum = ?',
array($instance->get('id'))
);
}
if ($instance === null) {
......@@ -348,6 +355,27 @@ function user_can_edit_post($poster, $posttime, $userid=null) {
return $poster == $userid && $posttime > (time() - 30 * 60);
}
function relative_date($relative, $absolute, $time1, $time2=null) {
if ($time2==null) {
$time2 = time();
}
$date = getdate($time1);
$yesterday = getdate(strtotime('-1 day', $time2));
$tomorrow = getdate(strtotime('+1 day', $time2));
$today = getdate($time2);
if ($date['year'] == $yesterday['year'] && $date['yday'] == $yesterday['yday']) {
return str_replace('%v', get_string('yesterday', 'interaction.forum'), strftime($relative, $time1));
}
else if ($date['year'] == $today['year'] && $date['yday'] == $today['yday']) {
return str_replace('%v', get_string('today', 'interaction.forum'), strftime($relative, $time1));
}
return strftime($absolute, $time1);
}
function subscribe_forum_submit(Pieform $form, $values) {
global $USER, $SESSION;
if ($values['type'] == 'subscribe') {
......
......@@ -25,6 +25,7 @@
<li>
<h4><a href="{$WWWROOT}interaction/forum/view.php?id={$forum->id|escape}">{$forum->title|escape}</a></h4>
{$forum->description}
{if $forum->moderators}
<br>
{str tag="moderatorslist" section="interaction.forum"}
{foreach from=$forum->moderators item=mod name=moderators}
......@@ -32,6 +33,7 @@
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=20&amp;id={$mod}" alt="">
{$mod|display_name|escape}</a>{if !$smarty.foreach.moderators.last}, {/if}
{/foreach}
{/if}
<div class="fr">{str tag=topics section=interaction.forum args=$forum->count}</div>
{if $admin}
<div>
......
......@@ -18,11 +18,13 @@
| <a href="{$WWWROOT}interaction/delete.php?id={$forum->id|escape}">{str tag="deleteforum" section="interaction.forum"}</a>
</div>
{/if}
<br>
{str tag="groupownerlist" section="interaction.forum"}
<a href="{$WWWROOT}user/view.php?id={$groupowner}" class="groupowner">
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=20&amp;id={$groupowner}" alt="">
{$groupowner|display_name|escape}
</a>
{if $moderators}
<br>
{str tag="moderatorslist" section="interaction.forum"}
{foreach from=$moderators item=mod name=moderators}
......@@ -30,7 +32,7 @@
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=20&amp;id={$mod}" alt="">
{$mod|display_name|escape}</a>{if !$smarty.foreach.moderators.last}, {/if}
{/foreach}
{/if}
</div>
{$forum->subscribe}
{if $stickytopics || $regulartopics}
......
......@@ -112,11 +112,21 @@ $posts = get_records_sql_array(
INNER JOIN {interaction_forum_post} p2 ON (p1.poster = p2.poster AND p2.deleted != 1)
INNER JOIN {interaction_forum_topic} t2 ON (t2.deleted != 1 AND p2.topic = t2.id)
INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted != 1 AND f.group = ?)
LEFT JOIN {interaction_forum_moderator} m oN (t.forum = m.forum AND p1.poster = m.user)
LEFT JOIN (
SELECT fm.user, fm.forum
FROM {interaction_forum_moderator} fm
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 (t.forum = m.forum AND p1.poster = m.user)
LEFT JOIN {interaction_forum_edit} e ON e.post = p1.id
LEFT JOIN {interaction_forum_post} p3 ON p3.id = e.post
LEFT JOIN {interaction_forum_topic} t3 ON t3.id = p3.topic
LEFT JOIN {interaction_forum_moderator} m2 ON t3.forum = m2.forum AND e.user = m2.user
LEFT JOIN (
SELECT fm.user, fm.forum
FROM {interaction_forum_moderator} fm
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)
) m2 ON t3.forum = m2.forum AND e.user = m2.user
WHERE p1.topic = ?
GROUP BY 1, 2, 3, 4, 5, p1.ctime, 7, 8, 10, 11, 12, e.ctime
ORDER BY p1.ctime, p1.id, e.ctime',
......@@ -129,15 +139,15 @@ $posts = get_records_sql_array(
$count = count($posts);
for ($i = 0; $i < $count; $i++) {
$posts[$i]->canedit = $posts[$i]->parent && ($moderator || user_can_edit_post($posts[$i]->poster, $posts[$i]->ctime));
$posts[$i]->ctime = strftime(get_string('strftimerecentfull'), $posts[$i]->ctime);
$posts[$i]->ctime = relative_date(get_string('strftimerecentfullrelative', 'interaction.forum'), get_string('strftimerecentfull'), $posts[$i]->ctime);
$postedits = array();
if ($posts[$i]->editor) {
$postedits[] = array('editor' => $posts[$i]->editor, 'edittime' => strftime(get_string('strftimerecentfull'), $posts[$i]->edittime), 'moderator' => $posts[$i]->editormoderator);
$postedits[] = array('editor' => $posts[$i]->editor, 'edittime' => relative_date(get_string('strftimerecentfullrelative', 'interaction.forum'), get_string('strftimerecentfull'), $posts[$i]->edittime), 'moderator' => $posts[$i]->editormoderator);
}
$temp = $i;
while (isset($posts[$i+1]) && $posts[$i+1]->id == $posts[$temp]->id) { // while the next object is the same post
$i++;
$postedits[] = array('editor' => $posts[$i]->editor, 'edittime' => strftime(get_string('strftimerecentfull'), $posts[$i]->edittime), 'moderator' => $posts[$i]->editormoderator);
$postedits[] = array('editor' => $posts[$i]->editor, 'edittime' => relative_date(get_string('strftimerecentfullrelative', 'interaction.forum'), get_string('strftimerecentfull'), $posts[$i]->edittime), 'moderator' => $posts[$i]->editormoderator);
unset($posts[$i]);
}
$posts[$temp]->edit = $postedits;
......
......@@ -64,10 +64,17 @@ $admin = (bool)($membership & (GROUP_MEMBERSHIP_OWNER | GROUP_MEMBERSHIP_ADMIN |
$moderator = $admin || is_forum_moderator($forumid);
$moderators = get_column('interaction_forum_moderator', '"user"', 'forum', $forumid);
define('TITLE', $forum->groupname . ' - ' . $forum->title);
$moderators = get_column_sql(
'SELECT m.user
FROM {interaction_forum_moderator} m
INNER JOIN {group_member} gm ON (m.user = gm.member AND gm.group = ?)
WHERE m.forum = ?
ORDER BY m.user',
array($forum->group, $forumid)
);
// updates the selected topics as subscribed/closed/sticky
if (isset($_POST['topics']) && isset($_POST['checkbox'])) {
$topics = array_keys($_POST['topics']);
......@@ -167,13 +174,19 @@ $forum->subscribe = pieform(array(
)
)
));
// gets the info about topics
// the last post is found by taking the max id of the posts in a topic with the max post time
// taking the max id is needed because multiple posts can have the same post time
$sql = 'SELECT t.id, p1.subject, p1.body, p1.poster, p1.deleted, m.user AS moderator, COUNT(p2.*), t.closed, s.topic AS subscribed, ' . db_format_tsfield('p4.ctime', 'lastposttime') . ', p4.poster AS lastposter, p4.deleted AS lastpostdeleted, m2.user AS lastpostermoderator
$sql = 'SELECT t.id, p1.subject, p1.body, p1.poster, p1.deleted, m.user AS moderator, COUNT(p2.*), t.closed, s.topic AS subscribed, ' . db_format_tsfield('p4.ctime', 'lastposttime') . ', p4.poster AS lastposter, m2.user AS lastpostermoderator
FROM interaction_forum_topic t
INNER JOIN {interaction_forum_post} p1 ON (p1.topic = t.id AND p1.parent IS NULL)
LEFT JOIN {interaction_forum_moderator} m ON (m.forum = t.forum AND p1.poster = m.user)
LEFT JOIN (
SELECT fm.user, fm.forum
FROM {interaction_forum_moderator} fm
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.forum = t.forum AND p1.poster = m.user)
INNER JOIN {interaction_forum_post} p2 ON (p2.topic = t.id AND p2.deleted != 1)
LEFT JOIN {interaction_forum_subscription_topic} s ON (s.topic = t.id AND s."user" = ?)
INNER JOIN (
......@@ -190,11 +203,16 @@ $sql = 'SELECT t.id, p1.subject, p1.body, p1.poster, p1.deleted, m.user AS moder
) p3 ON p3.topic = t.id
LEFT JOIN {interaction_forum_post} p4 ON (p4.id = p3.post)
LEFT JOIN {interaction_forum_topic} t2 ON (p4.topic = t2.id)
LEFT JOIN {interaction_forum_moderator} m2 ON (p4.poster = m2.user AND t2.forum = m2.forum)
LEFT JOIN (
SELECT fm.user, fm.forum
FROM {interaction_forum_moderator} fm
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)
) m2 ON (p4.poster = m2.user AND t2.forum = m2.forum)
WHERE t.forum = ?
AND t.sticky = ?
AND t.deleted != 1
GROUP BY 1, 2, 3, 4, 5, 6, 8, 9, p4.ctime, p4.poster, p4.deleted, p4.id, m2.user
GROUP BY 1, 2, 3, 4, 5, 6, 8, 9, p4.ctime, p4.poster, p4.id, m2.user
ORDER BY p4.ctime DESC, p4.id DESC';
$stickytopics = get_records_sql_array($sql, array($userid, $forumid, 1));
......@@ -279,9 +297,7 @@ function setup_topics(&$topics) {
$topic->body .= '...';
}
$topic->body = htmlentities($topic->body);
}
if (!$topic->lastpostdeleted) {
$topic->lastposttime = strftime(get_string('strftimerecent'), $topic->lastposttime);
$topic->lastposttime = relative_date(get_string('strftimerecentrelative', 'interaction.forum'), get_string('strftimerecent'), $topic->lastposttime);
}
}
}
......
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