Move all admin method from PollService to AdminPollService
This commit is contained in:
parent
94a125ca2b
commit
8d46ec6c33
@ -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.'));
|
||||
|
45
app/classes/Framadate/Services/AdminPollService.php
Normal file
45
app/classes/Framadate/Services/AdminPollService.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user