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
// -------------------------------
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;
}
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) {

View File

@ -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) {