diff --git a/adminstuds.php b/adminstuds.php index 6da08c6..689d51b 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -56,7 +56,14 @@ if (!$poll) { // Remove all votes // ------------------------------- if (isset($_POST['remove_all_votes'])) { - $pollService->cleanVotes($admin_poll_id, $poll_id); + $pollService->cleanVotes($poll_id); +} + +// ------------------------------- +// Remove all comments +// ------------------------------- +if (isset($_POST['remove_all_comments'])) { + $pollService->cleanComments($poll_id); } // ------------------------------- diff --git a/app/classes/Framadate/FramaDB.php b/app/classes/Framadate/FramaDB.php index 2359bc1..33f97b9 100644 --- a/app/classes/Framadate/FramaDB.php +++ b/app/classes/Framadate/FramaDB.php @@ -102,18 +102,26 @@ class FramaDB return $newVote; } - function deleteVotesByAdminPollId($admin_poll_id, $poll_id) { - $prepared = $this->prepare('SELECT 1 FROM sondage WHERE admin_poll_id = ? AND poll_id = ?'); - $prepared->execute([$admin_poll_id, $poll_id]); - $count = $prepared->rowCount(); - $prepared->closeCursor(); + /** + * Delete all votes of a given poll. + * + * @param $poll_id int The ID of the given poll. + * @return bool|null true if action succeeded. + */ + function deleteVotesByAdminPollId($poll_id) { + $prepared = $this->prepare('DELETE FROM user_studs WHERE id_sondage = ?'); + return $prepared->execute([$poll_id]); + } - if ($count === 1) { - $prepared = $this->prepare('DELETE FROM user_studs WHERE id_sondage = ?'); - return $prepared->execute([$poll_id]); - } else { - return null; - } + /** + * Delete all comments of a given poll. + * + * @param $poll_id int The ID of the given poll. + * @return bool|null true if action succeeded. + */ + function deleteCommentssByAdminPollId($poll_id) { + $prepared = $this->prepare('DELETE FROM comments WHERE id_sondage = ?'); + return $prepared->execute([$poll_id]); } function updateVote($poll_id, $vote_id, $choices) { diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index 34d93e1..ca73c9c 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -60,8 +60,8 @@ class PollService { return $this->connect->insertVote($poll_id, $name, $choices); } - function cleanVotes($admin_poll_id, $poll_id) { - $this->connect->deleteVotesByAdminPollId($admin_poll_id, $poll_id); + function cleanVotes($poll_id) { + $this->connect->deleteVotesByAdminPollId($poll_id); } function addComment($poll_id, $name, $comment) { @@ -72,6 +72,10 @@ class PollService { return $this->connect->deleteComment($poll_id, $comment_id); } + function cleanComments($poll_id) { + $this->connect->deleteCommentssByAdminPollId($poll_id); + } + function computeBestMoments($votes) { $result = []; foreach ($votes as $vote) {