Skip to content
Snippets Groups Projects
Commit 14727bd9 authored by Olivier PEREZ's avatar Olivier PEREZ
Browse files

admin: Add availability to delete all votes of a poll.

parent 1b01bcc6
No related branches found
No related tags found
No related merge requests found
...@@ -52,6 +52,13 @@ if (!$poll) { ...@@ -52,6 +52,13 @@ if (!$poll) {
exit; exit;
} }
// -------------------------------
// Remove all votes
// -------------------------------
if (isset($_POST['remove_all_votes'])) {
$pollService->cleanVotes($admin_poll_id, $poll_id);
}
// ------------------------------- // -------------------------------
// Update poll info // Update poll info
// ------------------------------- // -------------------------------
...@@ -111,6 +118,7 @@ if (isset($_POST['update_poll_info'])) { ...@@ -111,6 +118,7 @@ if (isset($_POST['update_poll_info'])) {
// ------------------------------- // -------------------------------
// Delete a comment // Delete a comment
// ------------------------------- // -------------------------------
if (!empty($_POST['delete_comment'])) { if (!empty($_POST['delete_comment'])) {
$comment_id = filter_input(INPUT_POST, 'delete_comment', FILTER_VALIDATE_INT); $comment_id = filter_input(INPUT_POST, 'delete_comment', FILTER_VALIDATE_INT);
......
...@@ -102,6 +102,20 @@ class FramaDB ...@@ -102,6 +102,20 @@ class FramaDB
return $newVote; 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();
if ($count === 1) {
$prepared = $this->prepare('DELETE FROM user_studs WHERE id_sondage = ?');
return $prepared->execute([$poll_id]);
} else {
return null;
}
}
function updateVote($poll_id, $vote_id, $choices) { function updateVote($poll_id, $vote_id, $choices) {
$prepared = $this->prepare('UPDATE user_studs SET reponses = ? WHERE id_sondage = ? AND id_users = ?'); $prepared = $this->prepare('UPDATE user_studs SET reponses = ? WHERE id_sondage = ? AND id_users = ?');
return $prepared->execute([$choices, $poll_id, $vote_id]); return $prepared->execute([$choices, $poll_id, $vote_id]);
......
...@@ -60,6 +60,10 @@ class PollService { ...@@ -60,6 +60,10 @@ class PollService {
return $this->connect->insertVote($poll_id, $name, $choices); return $this->connect->insertVote($poll_id, $name, $choices);
} }
function cleanVotes($admin_poll_id, $poll_id) {
$this->connect->deleteVotesByAdminPollId($admin_poll_id, $poll_id);
}
function addComment($poll_id, $name, $comment) { function addComment($poll_id, $name, $comment) {
return $this->connect->insertComment($poll_id, $name, $comment); return $this->connect->insertComment($poll_id, $name, $comment);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment