Commit 5d96cc8e authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Comment deletion


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent b2a13c34
......@@ -34,6 +34,10 @@ $string['comments'] = 'comments';
$string['attachfile'] = "Attach file";
$string['Attachments'] = "Attachments";
$string['commentremoved'] = 'Comment removed';
$string['commentremovedbyauthor'] = 'Comment removed by the author';
$string['commentremovedbyowner'] = 'Comment removed by the owner';
$string['commentremovedbyadmin'] = 'Comment removed by an administrator';
$string['feedback'] = 'Feedback';
$string['feedbackattachdirname'] = 'commentattachments';
$string['feedbackattachdirdesc'] = 'Files attached to comments on your portfolio';
......
......@@ -233,6 +233,13 @@ class ArtefactTypeComment extends ArtefactType {
}
public static function build_html(&$data) {
global $USER;
$candelete = $data->canedit || $USER->get('admin');
$deletedmessage = array(
'author' => get_string('commentremovedbyauthor', 'artefact.comment'),
'owner' => get_string('commentremovedbyowner', 'artefact.comment'),
'admin' => get_string('commentremovedbyadmin', 'artefact.comment'),
);
$authors = array();
foreach ($data->data as &$item) {
$item->date = format_date(strtotime($item->ctime), 'strftimedatetime');
......@@ -257,6 +264,13 @@ class ArtefactTypeComment extends ArtefactType {
$item->pubmessage = get_string('thisfeedbackispublic', 'artefact.comment');
$item->makeprivateform = pieform(self::make_private_form($item->id));
}
if ($item->deletedby) {
$item->deleted = 1;
$item->deletedmessage = $deletedmessage[$item->deletedby];
}
else if ($candelete || ($item->author && $item->author == $USER->get('id'))) {
$item->deleteform = pieform(self::delete_comment_form($item->id));
}
if ($item->author) {
if (isset($authors[$item->author])) {
$item->author = $authors[$item->author];
......@@ -373,6 +387,23 @@ class ArtefactTypeComment extends ArtefactType {
),
);
}
public static function delete_comment_form($id) {
return array(
'name' => 'delete_comment',
'renderer' => 'oneline',
'class' => 'makeprivate',
'elements' => array(
'comment' => array('type' => 'hidden', 'value' => $id),
'submit' => array(
'type' => 'submit',
'class' => 'delete',
'name' => 'delete_comment_submit',
'value' => get_string('delete'),
),
),
);
}
}
function make_private_submit(Pieform $form, $values) {
......@@ -388,6 +419,32 @@ function make_private_submit(Pieform $form, $values) {
redirect(get_config('wwwroot') . 'view/view.php?id=' . $viewid);
}
function delete_comment_submit(Pieform $form, $values) {
global $SESSION, $USER, $view;
$comment = new ArtefactTypeComment((int) $values['comment']);
if ($USER->get('id') == $comment->get('author')) {
$deletedby = 'author';
}
else if ($USER->can_edit_view($view)) {
$deletedby = 'owner';
}
else if ($USER->get('admin')) {
$deletedby = 'admin';
}
$comment->set('deletedby', $deletedby);
$comment->commit();
$SESSION->add_ok_msg(get_string('commentremoved', 'artefact.comment'));
$viewid = $view->get('id');
if ($artefact = $comment->get('onartefact')) {
redirect(get_config('wwwroot') . 'view/artefact.php?view=' . $viewid . '&artefact=' . $artefact);
}
redirect(get_config('wwwroot') . 'view/view.php?id=' . $viewid);
}
function add_feedback_form_validate(Pieform $form, $values) {
global $USER, $view;
if (!$USER->is_logged_in()) {
......
{foreach from=$data item=item}
<tr class="{cycle name=rows values='r0,r1'}">
<td>
{$item->description|clean_html}
{if $item->attachmessage}<div>{$item->attachmessage}</div>{/if}
{if $item->deleted}
<span class="details">[{str tag=commentremoved section=artefact.comment}]</span>
{else}
{$item->description|clean_html}
{if $item->attachmessage}<div>{$item->attachmessage}</div>{/if}
{/if}
<div class="details">
{if $item->deleteform}<div class="fr">{$item->deleteform}</div>{/if}
{if $item->author}
<div class="icon"><a href="{$WWWROOT}user/view.php?id={$item->author->id|escape}">
<img src="{profile_icon_url user=$item->author maxheight=20 maxwidth=20}" valign="middle" alt="{$item->author|display_name}">
......@@ -12,15 +17,19 @@
{else}
{$item->authorname|escape}
{/if}
| {$item->date|escape}
{if $item->pubmessage}
| {$item->pubmessage|escape}{if $item->makeprivateform}{$item->makeprivateform}{/if}
{if $item->deleted}
| {$item->deletedmessage|escape}
{else}
| {$item->date|escape}
{if $item->pubmessage}
| {$item->pubmessage|escape}{if $item->makeprivateform}{$item->makeprivateform}{/if}
{/if}
{strip}
{foreach $item->attachments item=a name=attachments}
{if $.foreach.attachments.first} | {str tag=Attachments section=artefact.comment}:{else},{/if} <a href="{$WWWROOT}artefact/file/download.php?file={$a->attachid}">{$a->attachtitle|escape}</a> ({$a->attachsize|escape})
{/foreach}
{/strip}
{/if}
{strip}
{foreach $item->attachments item=a name=attachments}
{if $.foreach.attachments.first} | {str tag=Attachments section=artefact.comment}:{else},{/if} <a href="{$WWWROOT}artefact/file/download.php?file={$a->attachid}">{$a->attachtitle|escape}</a> ({$a->attachsize|escape})
{/foreach}
{/strip}
</div>
</td>
</tr>
......
......@@ -78,6 +78,9 @@ $view = new View($viewid);
if (param_variable('make_private_submit', null)) {
pieform(ArtefactTypeComment::make_private_form(param_integer('comment')));
}
else if (param_variable('delete_comment_submit', null)) {
pieform(ArtefactTypeComment::delete_comment_form(param_integer('comment')));
}
$owner = $view->get('owner');
$viewtype = $view->get('type');
......
Supports Markdown
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