Skip to content
Snippets Groups Projects
Commit 8d46ec6c authored by Olivier PEREZ's avatar Olivier PEREZ
Browse files

Move all admin method from PollService to AdminPollService

parent 94a125ca
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/ */
use Framadate\Services\PollService; use Framadate\Services\PollService;
use Framadate\Services\AdminPollService;
use Framadate\Services\InputService; use Framadate\Services\InputService;
use Framadate\Message; use Framadate\Message;
use Framadate\Utils; use Framadate\Utils;
...@@ -35,6 +36,7 @@ $editingVoteId = 0; ...@@ -35,6 +36,7 @@ $editingVoteId = 0;
/*----------*/ /*----------*/
$pollService = new PollService($connect); $pollService = new PollService($connect);
$adminPollService = new AdminPollService($connect);
$inputService = new InputService(); $inputService = new InputService();
/* PAGE */ /* PAGE */
...@@ -101,7 +103,7 @@ if (isset($_POST['update_poll_info'])) { ...@@ -101,7 +103,7 @@ if (isset($_POST['update_poll_info'])) {
} }
// Update poll in database // Update poll in database
if ($updated && $pollService->updatePoll($poll)) { if ($updated && $adminPollService->updatePoll($poll)) {
$message = new Message('success', _('Poll saved.')); $message = new Message('success', _('Poll saved.'));
} else { } else {
$message = new Message('danger', _('Failed to save poll.')); $message = new Message('danger', _('Failed to save poll.'));
...@@ -115,7 +117,7 @@ if (isset($_POST['update_poll_info'])) { ...@@ -115,7 +117,7 @@ if (isset($_POST['update_poll_info'])) {
if (!empty($_POST['delete_comment'])) { if (!empty($_POST['delete_comment'])) {
$comment_id = filter_input(INPUT_POST, 'delete_comment', FILTER_VALIDATE_INT); $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.')); $message = new Message('success', _('Comment deleted.'));
} else { } else {
$message = new Message('danger', _('Failed to delete the comment.')); $message = new Message('danger', _('Failed to delete the comment.'));
...@@ -126,7 +128,7 @@ if (!empty($_POST['delete_comment'])) { ...@@ -126,7 +128,7 @@ if (!empty($_POST['delete_comment'])) {
// Remove all votes // Remove all votes
// ------------------------------- // -------------------------------
if (isset($_POST['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'])) { ...@@ -140,7 +142,7 @@ if (isset($_POST['remove_all_comments'])) {
exit; exit;
} }
if (isset($_POST['confirm_remove_all_comments'])) { if (isset($_POST['confirm_remove_all_comments'])) {
if ($pollService->cleanComments($poll_id)) { if ($adminPollService->cleanComments($poll_id)) {
$message = new Message('success', _('All comments deleted.')); $message = new Message('success', _('All comments deleted.'));
} else { } else {
$message = new Message('danger', _('Failed to delete all comments.')); $message = new Message('danger', _('Failed to delete all comments.'));
......
<?php
namespace Framadate\Services;
/**
* Class AdminPollService
* @package Framadate\Services
*/
class AdminPollService {
private $connect;
function __construct($connect) {
$this->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
...@@ -34,10 +34,6 @@ class PollService { ...@@ -34,10 +34,6 @@ class PollService {
return null; return null;
} }
function updatePoll($poll) {
return $this->connect->updatePoll($poll);
}
function allCommentsByPollId($poll_id) { function allCommentsByPollId($poll_id) {
return $this->connect->allCommentsByPollId($poll_id); return $this->connect->allCommentsByPollId($poll_id);
} }
...@@ -60,34 +56,10 @@ class PollService { ...@@ -60,34 +56,10 @@ class PollService {
return $this->connect->insertVote($poll_id, $name, $choices); 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) { function addComment($poll_id, $name, $comment) {
return $this->connect->insertComment($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) { function computeBestMoments($votes) {
$result = []; $result = [];
foreach ($votes as $vote) { foreach ($votes as $vote) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment