admin: Add availability to delete a vote.

This commit is contained in:
Olivier PEREZ 2014-12-21 00:25:00 +01:00
parent b8d0110263
commit 1a062a2a69
4 changed files with 52 additions and 12 deletions

View File

@ -115,16 +115,14 @@ if (isset($_POST['update_poll_info'])) {
// TODO Handle Add comment form // TODO Handle Add comment form
// ------------------------------- // -------------------------------
// Delete a comment // Delete a votes
// ------------------------------- // -------------------------------
if (!empty($_POST['delete_vote'])) {
if (!empty($_POST['delete_comment'])) { $vote_id = filter_input(INPUT_POST, 'delete_vote', FILTER_VALIDATE_INT);
$comment_id = filter_input(INPUT_POST, 'delete_comment', FILTER_VALIDATE_INT); if ($adminPollService->deleteVote($poll_id, $vote_id)) {
$message = new Message('success', _('Vote delete.'));
if ($adminPollService->deleteComment($poll_id, $comment_id)) {
$message = new Message('success', _('Comment deleted.'));
} else { } else {
$message = new Message('danger', _('Failed to delete the comment.')); $message = new Message('danger', _('Failed to delete the vote.'));
} }
} }
@ -142,6 +140,20 @@ if (isset($_POST['confirm_remove_all_votes'])) {
$adminPollService->cleanVotes($poll_id); $adminPollService->cleanVotes($poll_id);
} }
// -------------------------------
// Delete a comment
// -------------------------------
if (!empty($_POST['delete_comment'])) {
$comment_id = filter_input(INPUT_POST, 'delete_comment', FILTER_VALIDATE_INT);
if ($adminPollService->deleteComment($poll_id, $comment_id)) {
$message = new Message('success', _('Comment deleted.'));
} else {
$message = new Message('danger', _('Failed to delete the comment.'));
}
}
// ------------------------------- // -------------------------------
// Remove all comments // Remove all comments
// ------------------------------- // -------------------------------

View File

@ -102,6 +102,11 @@ class FramaDB
return $newVote; return $newVote;
} }
function deleteVote($poll_id, $vote_id) {
$prepared = $this->prepare('DELETE FROM user_studs WHERE id_sondage = ? AND id_users = ?');
return $prepared->execute([$poll_id, $vote_id]);
}
/** /**
* Delete all votes of a given poll. * Delete all votes of a given poll.
* *
@ -119,7 +124,7 @@ class FramaDB
* @param $poll_id int The ID of the given poll. * @param $poll_id int The ID of the given poll.
* @return bool|null true if action succeeded. * @return bool|null true if action succeeded.
*/ */
function deleteCommentssByAdminPollId($poll_id) { function deleteCommentsByAdminPollId($poll_id) {
$prepared = $this->prepare('DELETE FROM comments WHERE id_sondage = ?'); $prepared = $this->prepare('DELETE FROM comments WHERE id_sondage = ?');
return $prepared->execute([$poll_id]); return $prepared->execute([$poll_id]);
} }

View File

@ -17,6 +17,13 @@ class AdminPollService {
return $this->connect->updatePoll($poll); return $this->connect->updatePoll($poll);
} }
/**
* Delete a comment from a poll.
*
* @param $poll_id int The ID of the poll
* @param $comment_id int The ID of the comment
* @return mixed true is action succeeded
*/
function deleteComment($poll_id, $comment_id) { function deleteComment($poll_id, $comment_id) {
return $this->connect->deleteComment($poll_id, $comment_id); return $this->connect->deleteComment($poll_id, $comment_id);
} }
@ -28,13 +35,24 @@ class AdminPollService {
* @return bool|null true is action succeeded * @return bool|null true is action succeeded
*/ */
function cleanComments($poll_id) { function cleanComments($poll_id) {
return $this->connect->deleteCommentssByAdminPollId($poll_id); return $this->connect->deleteCommentsByAdminPollId($poll_id);
}
/**
* Delete a vote from a poll.
*
* @param $poll_id int The ID of the poll
* @param $vote_id int The ID of the vote
* @return mixed true is action succeeded
*/
function deleteVote($poll_id, $vote_id) {
return $this->connect->deleteVote($poll_id, $vote_id);
} }
/** /**
* Remove all votes of a poll. * Remove all votes of a poll.
* *
* @param $poll_id int The ID a the poll * @param $poll_id int The ID of the poll
* @return bool|null true is action succeeded * @return bool|null true is action succeeded
*/ */
function cleanVotes($poll_id) { function cleanVotes($poll_id) {

View File

@ -5,7 +5,7 @@
<h3>{_('Votes of the poll')}</h3> <h3>{_('Votes of the poll')}</h3>
<div id="tableContainer" class="tableContainer"> <div id="tableContainer" class="tableContainer">
<form action="{$poll_id|poll_url}" method="POST"> <form action="" method="POST">
<table class="results"> <table class="results">
<caption class="sr-only">{_('Votes of the poll')} {$poll->title}</caption> <caption class="sr-only">{_('Votes of the poll')} {$poll->title}</caption>
<thead> <thead>
@ -94,6 +94,11 @@
<button type="submit" class="btn btn-link btn-sm" name="edit_vote" value="{$vote->id}" title="{_('Edit the line:')} {$vote->name}"> <button type="submit" class="btn btn-link btn-sm" name="edit_vote" value="{$vote->id}" title="{_('Edit the line:')} {$vote->name}">
<span class="glyphicon glyphicon-pencil"></span><span class="sr-only">{_('Edit')}</span> <span class="glyphicon glyphicon-pencil"></span><span class="sr-only">{_('Edit')}</span>
</button> </button>
{if $admin}
<button type="submit" class="btn btn-link btn-sm" name="delete_vote" value="{$vote->id}" title="{_('Remove the line:')} {$vote->name}">
<span class="glyphicon glyphicon-remove text-danger"></span><span class="sr-only">{_('Remove')}</span>
</button>
{/if}
</td> </td>
{else} {else}
<td></td> <td></td>