From 1a062a2a6919c079aeb049c913e91bc286c7b651 Mon Sep 17 00:00:00 2001 From: Olivier PEREZ Date: Sun, 21 Dec 2014 00:25:00 +0100 Subject: [PATCH] admin: Add availability to delete a vote. --- adminstuds.php | 28 +++++++++++++------ app/classes/Framadate/FramaDB.php | 7 ++++- .../Framadate/Services/AdminPollService.php | 22 +++++++++++++-- tpl/part/vote_table.tpl | 7 ++++- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/adminstuds.php b/adminstuds.php index 72120d5..f468032 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 33f97b9..102ccfb 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 bf49ce9..eee80a9 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 75408dd..37829f8 100644 --- a/tpl/part/vote_table.tpl +++ b/tpl/part/vote_table.tpl @@ -5,7 +5,7 @@

{_('Votes of the poll')}

-
+ @@ -94,6 +94,11 @@ + {if $admin} + + {/if} {else}
{_('Votes of the poll')} {$poll->title}