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

This commit is contained in:
Olivier PEREZ 2014-12-19 00:27:30 +01:00
parent 1b01bcc6b6
commit 14727bd94c
3 changed files with 26 additions and 0 deletions

View File

@ -52,6 +52,13 @@ if (!$poll) {
exit;
}
// -------------------------------
// Remove all votes
// -------------------------------
if (isset($_POST['remove_all_votes'])) {
$pollService->cleanVotes($admin_poll_id, $poll_id);
}
// -------------------------------
// Update poll info
// -------------------------------
@ -111,6 +118,7 @@ if (isset($_POST['update_poll_info'])) {
// -------------------------------
// Delete a comment
// -------------------------------
if (!empty($_POST['delete_comment'])) {
$comment_id = filter_input(INPUT_POST, 'delete_comment', FILTER_VALIDATE_INT);

View File

@ -102,6 +102,20 @@ 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();
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) {
$prepared = $this->prepare('UPDATE user_studs SET reponses = ? WHERE id_sondage = ? AND id_users = ?');
return $prepared->execute([$choices, $poll_id, $vote_id]);

View File

@ -60,6 +60,10 @@ 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 addComment($poll_id, $name, $comment) {
return $this->connect->insertComment($poll_id, $name, $comment);
}