diff --git a/adminstuds.php b/adminstuds.php index 8435200..84b8485 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -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; } diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index ca73c9c..cf97b41 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -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) { diff --git a/tpl/confirm/delete_comment.tpl b/tpl/confirm/delete_comment.tpl new file mode 100644 index 0000000..739be74 --- /dev/null +++ b/tpl/confirm/delete_comment.tpl @@ -0,0 +1,11 @@ +{extends file='page.tpl'} + +{block name=main} +
+
+

{_("Confirm removal of all comments of the poll")}

+

+

+
+
+{/block} \ No newline at end of file