Commit 8b11dfe3 authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan

changed first posts to be distinct from other posts

first posts cannot be editted or deleted
users can edit their topics within 30 minutes of creating them
changed layout of topic a bit
changed editting topics as moderators to only leave records if the body/subject change (ie not if just sticky/closed changes)
parent a18397f1
......@@ -62,6 +62,10 @@ if (!$moderator) {
throw new AccessDeniedException(get_string('cantdeletepost', 'interaction.forum'));
}
if (!$post->parent) {
throw new AccessDeniedException(get_string('cantdeletethispost', 'interaction.forum'));
}
define('TITLE', get_string('deletepost', 'interaction.forum') . ' - ' . $post->topicsubject);
$post->ctime = strftime(get_string('strftimerecentfull'), $post->ctime);
......
......@@ -107,7 +107,8 @@ else { // edit post
INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted != 1)
INNER JOIN {group} g ON g.id = f.group
WHERE p.id = ?
AND p.deleted != 1',
AND p.deleted != 1
AND p.parent IS NOT NULL',
array($postid)
);
......@@ -124,7 +125,7 @@ else { // edit post
$moderator = $admin || is_forum_moderator((int)$post->forum);
// no record for edits to own posts with 30 minutes
if ($post->poster == $userid && $post->ctime > (time() - 30 * 60)) {
if (user_can_edit_post($post->poster, $post->ctime)) {
$post->editrecord = false;
}
else if ($moderator) {
......
......@@ -82,7 +82,7 @@ if ($topicid == 0) { // new topic
else { // edit topic
$topic = get_record_sql(
'SELECT p.subject, p.id AS postid, p.body, p.topic AS id, t.sticky, t.closed, f.id AS forumid, f.group AS group, f.title, g.name AS groupname
'SELECT p.subject, p.id AS postid, p.body, p.poster, p.topic AS id, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.sticky, t.closed, f.id AS forumid, f.group AS group, f.title, g.name AS groupname
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 (f.id = t.forum AND f.deleted != 1)
......@@ -91,7 +91,7 @@ else { // edit topic
AND p.topic = ?',
array($topicid)
);
if (!$topic) {
throw new NotFoundException(get_string('cantfindtopic', 'interaction.forum', $topicid));
}
......@@ -104,7 +104,14 @@ else { // edit topic
$moderator = $admin || is_forum_moderator((int)$forumid);
if (!$moderator) {
// no record for edits to own posts with 30 minutes
if (user_can_edit_post($topic->poster, $topic->ctime)) {
$topic->editrecord = false;
}
else if ($moderator) {
$topic->editrecord = true;
}
else {
throw new AccessDeniedException(get_string('cantedittopic', 'interaction.forum'));
}
......@@ -182,6 +189,10 @@ $editform = array(
'post' => array(
'type' => 'hidden',
'value' => isset($topic) ? $topic->postid : false
),
'editrecord' => array(
'type' => 'hidden',
'value' => isset($topic) ? $topic->editrecord : false
)
),
);
......@@ -221,25 +232,32 @@ function addtopic_submit(Pieform $form, $values) {
}
function edittopic_submit(Pieform $form, $values) {
global $SESSION, $USER;
global $SESSION, $USER, $topic;
$topicid = param_integer('id');
db_begin();
update_record(
'interaction_forum_post',
array(
'subject' => $values['subject'],
'body' => $values['body']
),
array('id' => $values['post'])
);
insert_record(
'interaction_forum_edit',
(object)array(
'user' => $USER->get('id'),
'post' => $values['post'],
'ctime' => db_format_timestamp(time())
)
);
// check the post content actually changed
// otherwise topic could have been set as sticky/closed
$postchanged = $values['subject'] != $topic->subject || $values['body'] != $topic->body;
if ($postchanged) {
update_record(
'interaction_forum_post',
array(
'subject' => $values['subject'],
'body' => $values['body']
),
array('id' => $values['post'])
);
}
if ($values['editrecord'] && $postchanged) {
insert_record(
'interaction_forum_edit',
(object)array(
'user' => $USER->get('id'),
'post' => $values['post'],
'ctime' => db_format_timestamp(time())
)
);
}
if(isset($values['sticky'])){
update_record(
'interaction_forum_topic',
......
......@@ -34,9 +34,10 @@ $string['cantaddposttoforum'] = 'You are not allowed to post in this forum';
$string['cantaddposttotopic'] = 'You are not allowed to post in this topic';
$string['cantaddtopic'] = 'You are not allowed to add topics to this forum';
$string['cantdeletepost'] = 'You are not allowed to delete posts in this forum';
$string['cantdeletethispost'] = 'You are not allowed to delete this post';
$string['cantdeletetopic'] = 'You are not allowed to delete topics in this forum';
$string['canteditpost'] = 'You are not allowed to edit that post';
$string['cantedittopic'] = 'You are not allowed to edit topics in this forum';
$string['canteditpost'] = 'You are not allowed to edit this post';
$string['cantedittopic'] = 'You are not allowed to edit this topic';
$string['cantfindforum'] = 'Coudn\'t find forum with id %s';
$string['cantfindpost'] = 'Couldn\'t find post with id %s';
$string['cantfindtopic'] = 'Couldn\'t find topic with id %s';
......
......@@ -223,7 +223,6 @@ function is_forum_moderator($forumid, $userid=null) {
if (!is_int($forumid)) {
throw new InvalidArgumentException("non integer forum id given to is_forum_moderator: $forumid");
}
return record_exists_sql(
'SELECT fm.user
......@@ -236,6 +235,24 @@ function is_forum_moderator($forumid, $userid=null) {
);
}
/**
* Is a user allowed to edit a post
*
* @param boolean $moderator
* @param int $poster the the id of the user who created the post
* @param int $posttime the time the post was made
* @param int $userid optional id of user, defaults to logged in user
*
* @returns boolean
*/
function user_can_edit_post($poster, $posttime, $userid=null) {
if (empty($userid)) {
global $USER;
$userid = $USER->get('id');
}
return $poster == $userid && $posttime > (time() - 30 * 60);
}
/**
* For a pieform with forum, redirect and type elements.
* forum is the forum id
......
{if $post->deleted}
<h4>{str tag="deletedpost" section="interaction.forum}</h4>
{else}
{if $post->parent}
{include file="interaction:forum:simplepost.tpl" post=$post}
{else}
{include file="interaction:forum:simplepost.tpl" post=$post nosubject=true}
{/if}
{if $post->parent}
<div>
{if $moderator || !$closed}<a href="{$WWWROOT}interaction/forum/editpost.php?parent={$post->id|escape}">{str tag="reply" section=interaction.forum}</a>{/if}
{if $moderator || (!$closed && $post->canedit)} | {/if}
{if $moderator || $post->canedit}<a href="{$WWWROOT}interaction/forum/editpost.php?id={$post->id|escape}"> {str tag="edit"}</a>{/if}
{if $moderator} | <a href="{$WWWROOT}interaction/forum/deletepost.php?id={$post->id|escape}"> {str tag="delete"}</a>{/if}
</div>
{/if}
{if $post->edit}
{str tag="editstothispost" section="interaction.forum}
<ul>
......
{if $post->subject}<h4>{$post->subject|escape}</h4>{/if}
<div>
{if $post->subject && !$nosubject}<h4>{$post->subject|escape}</h4>{/if}
{$post->ctime}
<h5><a href="{$WWWROOT}user/view.php?id={$post->poster}">{$post->poster|display_name|escape}</a></h5>
<div><img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=100&amp;id={$post->poster}" alt=""></div>
<h5>{str tag="postsvariable" section=interaction.forum args=$post->count}</h5>
{$post->body}
</div>
\ No newline at end of file
......@@ -5,21 +5,25 @@
<h2>{$heading|escape}</h2>
{include file="interaction:forum:breadcrumbs.tpl" breadcrumbs=$breadcrumbs}
{if $moderator}
{if !$topic->closed}
<div class="fr">
<span class ="addicon">
<a href="{$WWWROOT}interaction/forum/editpost.php?parent={$topic->firstpost|escape}">{str tag=postreply section=interaction.forum}</a>
</span>
</div>
{/if}
{if $topic->canedit}
<div>
<a href="{$WWWROOT}interaction/forum/edittopic.php?id={$topic->id|escape}">{str tag=edittopic section=interaction.forum}</a>
{if $moderator}
| <a href="{$WWWROOT}interaction/forum/deletetopic.php?id={$topic->id|escape}">{str tag=deletetopic section=interaction.forum}</a>
{/if}
</div>
{/if}
{if !$topic->forumsubscribed}{$topic->subscribe}{/if}
{if $topic->closed}
{str tag=topicisclosed section=interaction.forum}
{/if}
<ul>
<li>
{$posts}
</li>
</ul>
{$posts}
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
......@@ -33,7 +33,7 @@ require_once('group.php');
$topicid = param_integer('id');
$topic = get_record_sql(
'SELECT p.subject, 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
'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
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
......@@ -59,6 +59,8 @@ $admin = (bool)($membership & GROUP_MEMBERSHIP_OWNER);
$moderator = $admin || is_forum_moderator((int)$topic->forumid);
$topic->canedit = $moderator || user_can_edit_post($topic->poster, $topic->ctime);
define('TITLE', $topic->forumtitle . ' - ' . $topic->subject);
$breadcrumbs = array(
......@@ -132,17 +134,8 @@ for ($i = 0; $i < $count; $i++) {
}
$posts[$temp]->edit = $postedits;
}
// works out if the logged in user can edit each post
// users can edit own posts within 30 minutes of making them
// and formats the post time
foreach ($posts as $post) {
if ($moderator ||
($post->poster == $USER->get('id') && $post->ctime > (time() - 30 * 60))) {
$post->canedit = true;
}
else {
$post->canedit = false;
}
$post->canedit = $moderator || user_can_edit_post($post->poster, $post->ctime);
$post->ctime = strftime(get_string('strftimerecentfull'), $post->ctime);
}
// builds the first post (with index 0) which has as children all the posts in the topic
......
......@@ -165,18 +165,18 @@ $forum->subscribe = pieform(array(
$sql = 'SELECT t.id, p1.subject, p1.body, p1.poster, p1.deleted, COUNT(p2.*), t.closed, s.topic AS subscribed, ' . db_format_tsfield('p4.ctime', 'lastposttime') . ', p4.poster AS lastposter, p4.deleted AS lastpostdeleted
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_post} p2 ON (p2.topic = t.id AND p2.deleted != 1)
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" = ?)
LEFT JOIN (
INNER JOIN (
SELECT MAX(p2.id) AS post, t.id AS topic
FROM {interaction_forum_topic} t
INNER JOIN (
SELECT MAX(p.ctime) AS ctime, t.id AS topic
FROM {interaction_forum_topic} t
INNER JOIN {interaction_forum_post} p ON (p.topic = t.id AND (p.deleted = 0 OR p.parent IS NULL))
INNER JOIN {interaction_forum_post} p ON (p.topic = t.id AND p.deleted = 0)
GROUP BY 2
) p1 ON t.id = p1.topic
INNER JOIN {interaction_forum_post} p2 ON (p1.topic = p2.topic AND p1.ctime = p2.ctime AND (p2.deleted = 0 OR p2.parent IS NULL))
INNER JOIN {interaction_forum_post} p2 ON (p1.topic = p2.topic AND p1.ctime = p2.ctime AND p2.deleted = 0)
GROUP BY 2
) p3 ON p3.topic = t.id
LEFT JOIN {interaction_forum_post} p4 ON (p4.id = p3.post)
......
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