admin: Add availability to delete comments one by one.

This commit is contained in:
Olivier PEREZ 2014-12-19 00:13:21 +01:00
parent 178208380f
commit 1b01bcc6b6
4 changed files with 59 additions and 32 deletions

View File

@ -55,6 +55,7 @@ if (!$poll) {
// -------------------------------
// Update poll info
// -------------------------------
if (isset($_POST['update_poll_info'])) {
$updated = false;
$field = $inputService->filterAllowedValues($_POST['update_poll_info'], ['title', 'admin_mail', 'comment', 'rules']);
@ -107,6 +108,19 @@ if (isset($_POST['update_poll_info'])) {
}
}
// -------------------------------
// Delete a comment
// -------------------------------
if (!empty($_POST['delete_comment'])) {
$comment_id = filter_input(INPUT_POST, 'delete_comment', FILTER_VALIDATE_INT);
if ($pollService->deleteComment($poll_id, $comment_id)) {
$message = new Message('success', _('Comment deleted.'));
} else {
$message = new Message('danger', _('Failed to delete the comment.'));
}
}
// Retrieve data
$slots = $pollService->allSlotsByPollId($poll_id);
$votes = $pollService->allUserVotesByPollId($poll_id);

View File

@ -112,4 +112,9 @@ class FramaDB
return $prepared->execute([$poll_id, $name, $comment]);
}
function deleteComment($poll_id, $comment_id) {
$prepared = $this->prepare('DELETE FROM comments WHERE id_sondage = ? AND id_comment = ?');
return $prepared->execute([$poll_id, $comment_id]);
}
}

View File

@ -64,6 +64,10 @@ class PollService {
return $this->connect->insertComment($poll_id, $name, $comment);
}
function deleteComment($poll_id, $comment_id) {
return $this->connect->deleteComment($poll_id, $comment_id);
}
function computeBestMoments($votes) {
$result = [];
foreach ($votes as $vote) {

View File

@ -1,36 +1,40 @@
<hr role="presentation" id="comments"/>
<form action="#comments" method="POST">
{* Comment list *}
{* Comment list *}
{if $comments|count > 0}
{foreach $comments as $comment}
<div class="comment">
<b>{$comment->usercomment}</b>&nbsp;
<span class="comment">{nl2br($comment->comment)}</span>
{if $comments|count > 0}
<h3>{_("Comments of polled people")}</h3>
{foreach $comments as $comment}
<div class="comment">
{if $admin}
<button type="submit" name="delete_comment" value="{$comment->id_comment}" class="btn btn-link" title="{_('Remove the comment')}"><span class="glyphicon glyphicon-remove text-danger"></span><span class="sr-only">{_('Remove')}</span></button>
{/if}
<b>{$comment->usercomment}</b>&nbsp;
<span class="comment">{nl2br($comment->comment)}</span>
</div>
{/foreach}
{/if}
{* Add comment form *}
{if $active}
<div class="hidden-print alert alert-info">
<div class="col-md-6 col-md-offset-3">
<fieldset id="add-comment"><legend>{_("Add a comment to the poll")}</legend>
<div class="form-group">
<label for="name" class="control-label">{_("Your name")}</label>
<input type="text" name="name" id="name" class="form-control" />
</div>
<div class="form-group">
<label for="comment" class="control-label">{_("Your comment")}</label>
<textarea name="comment" id="comment" class="form-control" rows="2" cols="40"></textarea>
</div>
<div class="pull-right">
<input type="submit" name="add_comment" value="{_("Send the comment")}" class="btn btn-success">
</div>
</fieldset>
</div>
<div class="clearfix"></div>
</div>
{/foreach}
{/if}
{* Add comment form *}
{if $active}
<div class="hidden-print alert alert-info">
<form action="{$poll_id|poll_url}#comments" method="POST">
<div class="col-md-6 col-md-offset-3">
<fieldset id="add-comment"><legend>{_("Add a comment to the poll")}</legend>
<div class="form-group">
<label for="name" class="control-label">{_("Your name")}</label>
<input type="text" name="name" id="name" class="form-control" />
</div>
<div class="form-group">
<label for="comment" class="control-label">{_("Your comment")}</label>
<textarea name="comment" id="comment" class="form-control" rows="2" cols="40"></textarea>
</div>
<div class="pull-right">
<input type="submit" name="add_comment" value="{_("Send the comment")}" class="btn btn-success">
</div>
</fieldset>
</div>
<div class="clearfix"></div>
</form>
</div>
{/if}
{/if}
</form>