diff --git a/adminstuds.php b/adminstuds.php index 84b8485..0aad6ed 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -17,6 +17,7 @@ * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) */ use Framadate\Services\PollService; +use Framadate\Services\AdminPollService; use Framadate\Services\InputService; use Framadate\Message; use Framadate\Utils; @@ -35,6 +36,7 @@ $editingVoteId = 0; /*----------*/ $pollService = new PollService($connect); +$adminPollService = new AdminPollService($connect); $inputService = new InputService(); /* PAGE */ @@ -101,7 +103,7 @@ if (isset($_POST['update_poll_info'])) { } // Update poll in database - if ($updated && $pollService->updatePoll($poll)) { + if ($updated && $adminPollService->updatePoll($poll)) { $message = new Message('success', _('Poll saved.')); } else { $message = new Message('danger', _('Failed to save poll.')); @@ -115,7 +117,7 @@ if (isset($_POST['update_poll_info'])) { if (!empty($_POST['delete_comment'])) { $comment_id = filter_input(INPUT_POST, 'delete_comment', FILTER_VALIDATE_INT); - if ($pollService->deleteComment($poll_id, $comment_id)) { + if ($adminPollService->deleteComment($poll_id, $comment_id)) { $message = new Message('success', _('Comment deleted.')); } else { $message = new Message('danger', _('Failed to delete the comment.')); @@ -126,7 +128,7 @@ if (!empty($_POST['delete_comment'])) { // Remove all votes // ------------------------------- if (isset($_POST['remove_all_votes'])) { - $pollService->cleanVotes($poll_id); + $adminPollService->cleanVotes($poll_id); } // ------------------------------- @@ -140,7 +142,7 @@ if (isset($_POST['remove_all_comments'])) { exit; } if (isset($_POST['confirm_remove_all_comments'])) { - if ($pollService->cleanComments($poll_id)) { + if ($adminPollService->cleanComments($poll_id)) { $message = new Message('success', _('All comments deleted.')); } else { $message = new Message('danger', _('Failed to delete all comments.')); diff --git a/app/classes/Framadate/Services/AdminPollService.php b/app/classes/Framadate/Services/AdminPollService.php new file mode 100644 index 0000000..bf49ce9 --- /dev/null +++ b/app/classes/Framadate/Services/AdminPollService.php @@ -0,0 +1,45 @@ +connect = $connect; + } + + function updatePoll($poll) { + return $this->connect->updatePoll($poll); + } + + function deleteComment($poll_id, $comment_id) { + 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) { + return $this->connect->deleteCommentssByAdminPollId($poll_id); + } + + /** + * 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) { + return $this->connect->deleteVotesByAdminPollId($poll_id); + } + +} + \ No newline at end of file diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index cf97b41..33959f0 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -34,10 +34,6 @@ class PollService { return null; } - function updatePoll($poll) { - return $this->connect->updatePoll($poll); - } - function allCommentsByPollId($poll_id) { return $this->connect->allCommentsByPollId($poll_id); } @@ -60,34 +56,10 @@ 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) { - return $this->connect->deleteVotesByAdminPollId($poll_id); - } - function addComment($poll_id, $name, $comment) { return $this->connect->insertComment($poll_id, $name, $comment); } - function deleteComment($poll_id, $comment_id) { - 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) { - return $this->connect->deleteCommentssByAdminPollId($poll_id); - } - function computeBestMoments($votes) { $result = []; foreach ($votes as $vote) {