Add availability to delete all comments of one poll.

+ Simplify call to remove all votes of one poll
This commit is contained in:
Olivier PEREZ 2014-12-19 00:36:09 +01:00
parent 3d18c208ca
commit 07d5a336fb
3 changed files with 33 additions and 14 deletions

View File

@ -56,7 +56,14 @@ if (!$poll) {
// Remove all votes // Remove all votes
// ------------------------------- // -------------------------------
if (isset($_POST['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);
} }
// ------------------------------- // -------------------------------

View File

@ -102,18 +102,26 @@ 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 = ?'); * Delete all votes of a given poll.
$prepared->execute([$admin_poll_id, $poll_id]); *
$count = $prepared->rowCount(); * @param $poll_id int The ID of the given poll.
$prepared->closeCursor(); * @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 = ?'); * Delete all comments of a given poll.
return $prepared->execute([$poll_id]); *
} else { * @param $poll_id int The ID of the given poll.
return null; * @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) { function updateVote($poll_id, $vote_id, $choices) {

View File

@ -60,8 +60,8 @@ 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) { function cleanVotes($poll_id) {
$this->connect->deleteVotesByAdminPollId($admin_poll_id, $poll_id); $this->connect->deleteVotesByAdminPollId($poll_id);
} }
function addComment($poll_id, $name, $comment) { function addComment($poll_id, $name, $comment) {
@ -72,6 +72,10 @@ class PollService {
return $this->connect->deleteComment($poll_id, $comment_id); return $this->connect->deleteComment($poll_id, $comment_id);
} }
function cleanComments($poll_id) {
$this->connect->deleteCommentssByAdminPollId($poll_id);
}
function computeBestMoments($votes) { function computeBestMoments($votes) {
$result = []; $result = [];
foreach ($votes as $vote) { foreach ($votes as $vote) {