Display confirmation page before to delete all comments of one poll.

This commit is contained in:
Olivier PEREZ 2014-12-19 00:59:27 +01:00
parent 3829402a69
commit 94a125ca2b
3 changed files with 50 additions and 16 deletions

View File

@ -52,20 +52,6 @@ if (!$poll) {
exit;
}
// -------------------------------
// Remove all votes
// -------------------------------
if (isset($_POST['remove_all_votes'])) {
$pollService->cleanVotes($poll_id);
}
// -------------------------------
// Remove all comments
// -------------------------------
if (isset($_POST['remove_all_comments'])) {
$pollService->cleanComments($poll_id);
}
// -------------------------------
// Update poll info
// -------------------------------
@ -136,6 +122,30 @@ if (!empty($_POST['delete_comment'])) {
}
}
// -------------------------------
// Remove all votes
// -------------------------------
if (isset($_POST['remove_all_votes'])) {
$pollService->cleanVotes($poll_id);
}
// -------------------------------
// Remove all comments
// -------------------------------
if (isset($_POST['remove_all_comments'])) {
$smarty->assign('poll_id', $poll_id);
$smarty->assign('admin_poll_id', $admin_poll_id);
$smarty->assign('title', _('Poll') . ' - ' . $poll->title);
$smarty->display('confirm/delete_comment.tpl');
exit;
}
if (isset($_POST['confirm_remove_all_comments'])) {
if ($pollService->cleanComments($poll_id)) {
$message = new Message('success', _('All comments deleted.'));
} else {
$message = new Message('danger', _('Failed to delete all comments.'));
}
}
// -------------------------------
// Delete the entire poll
@ -144,6 +154,7 @@ if (!empty($_POST['delete_comment'])) {
if (isset($_POST['delete_poll'])) {
$smarty->assign('poll_id', $poll_id);
$smarty->assign('admin_poll_id', $admin_poll_id);
$smarty->assign('title', _('Poll') . ' - ' . $poll->title);
$smarty->display('confirm/delete_poll.tpl');
exit;
}

View File

@ -60,8 +60,14 @@ class PollService {
return $this->connect->insertVote($poll_id, $name, $choices);
}
/**
* Remove all votes of a poll.
*
* @param $poll_id int The ID a the poll
* @return bool|null true is action succeeded
*/
function cleanVotes($poll_id) {
$this->connect->deleteVotesByAdminPollId($poll_id);
return $this->connect->deleteVotesByAdminPollId($poll_id);
}
function addComment($poll_id, $name, $comment) {
@ -72,8 +78,14 @@ class PollService {
return $this->connect->deleteComment($poll_id, $comment_id);
}
/**
* Remove all comments of a poll.
*
* @param $poll_id int The ID a the poll
* @return bool|null true is action succeeded
*/
function cleanComments($poll_id) {
$this->connect->deleteCommentssByAdminPollId($poll_id);
return $this->connect->deleteCommentssByAdminPollId($poll_id);
}
function computeBestMoments($votes) {

View File

@ -0,0 +1,11 @@
{extends file='page.tpl'}
{block name=main}
<form action="{$admin_poll_id|poll_url:true}" method="POST">
<div class="alert alert-danger text-center">
<h2>{_("Confirm removal of all comments of the poll")}</h2>
<p><button class="btn btn-default" type="submit" name="cancel">{_("Keep comments")}</button>
<button type="submit" name="confirm_remove_all_comments" class="btn btn-danger">{_("Remove all comments!")}</button></p>
</div>
</form>
{/block}