diff --git a/adminstuds.php b/adminstuds.php index 72120d5c2f4b2cd0edbbedd668238ee56764c3f3..f468032f87c0de42e09e05c5b2fde58ec1a12b31 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -115,16 +115,14 @@ if (isset($_POST['update_poll_info'])) { // TODO Handle Add comment form // ------------------------------- -// Delete a comment +// Delete a votes // ------------------------------- - -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.')); +if (!empty($_POST['delete_vote'])) { + $vote_id = filter_input(INPUT_POST, 'delete_vote', FILTER_VALIDATE_INT); + if ($adminPollService->deleteVote($poll_id, $vote_id)) { + $message = new Message('success', _('Vote delete.')); } 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); } +// ------------------------------- +// 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 // ------------------------------- diff --git a/app/classes/Framadate/FramaDB.php b/app/classes/Framadate/FramaDB.php index 33f97b96a98b380c6e09745f2e5b05965f98eb59..102ccfb57c0db82a3375837b45c068b37b372c9c 100644 --- a/app/classes/Framadate/FramaDB.php +++ b/app/classes/Framadate/FramaDB.php @@ -102,6 +102,11 @@ class FramaDB 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. * @@ -119,7 +124,7 @@ class FramaDB * @param $poll_id int The ID of the given poll. * @return bool|null true if action succeeded. */ - function deleteCommentssByAdminPollId($poll_id) { + function deleteCommentsByAdminPollId($poll_id) { $prepared = $this->prepare('DELETE FROM comments WHERE id_sondage = ?'); return $prepared->execute([$poll_id]); } diff --git a/app/classes/Framadate/Services/AdminPollService.php b/app/classes/Framadate/Services/AdminPollService.php index bf49ce956e1939b2b14b3ed9eb8c0cb75e131a16..eee80a9d7ebe9f01a67c06fabd3ba38c4beb0cad 100644 --- a/app/classes/Framadate/Services/AdminPollService.php +++ b/app/classes/Framadate/Services/AdminPollService.php @@ -17,6 +17,13 @@ class AdminPollService { 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) { return $this->connect->deleteComment($poll_id, $comment_id); } @@ -28,13 +35,24 @@ class AdminPollService { * @return bool|null true is action succeeded */ 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. * - * @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 */ function cleanVotes($poll_id) { diff --git a/tpl/part/vote_table.tpl b/tpl/part/vote_table.tpl index 75408ddb116290a74acb7911ac5b12abb08d3818..37829f8624e30beb184575b5768f69bb20057c1f 100644 --- a/tpl/part/vote_table.tpl +++ b/tpl/part/vote_table.tpl @@ -5,7 +5,7 @@ <h3>{_('Votes of the poll')}</h3> <div id="tableContainer" class="tableContainer"> - <form action="{$poll_id|poll_url}" method="POST"> + <form action="" method="POST"> <table class="results"> <caption class="sr-only">{_('Votes of the poll')} {$poll->title}</caption> <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}"> <span class="glyphicon glyphicon-pencil"></span><span class="sr-only">{_('Edit')}</span> </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> {else} <td></td>