From 8d46ec6c33471676c6451311611a86054cc6c5bf Mon Sep 17 00:00:00 2001
From: Olivier PEREZ <olivier@olivierperez.fr>
Date: Sat, 20 Dec 2014 23:59:44 +0100
Subject: [PATCH] Move all admin method from PollService to AdminPollService

---
 adminstuds.php                                | 10 +++--
 .../Framadate/Services/AdminPollService.php   | 45 +++++++++++++++++++
 .../Framadate/Services/PollService.php        | 28 ------------
 3 files changed, 51 insertions(+), 32 deletions(-)
 create mode 100644 app/classes/Framadate/Services/AdminPollService.php

diff --git a/adminstuds.php b/adminstuds.php
index 84b84857..0aad6edf 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 00000000..bf49ce95
--- /dev/null
+++ b/app/classes/Framadate/Services/AdminPollService.php
@@ -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);
+    }
+
+}
+ 
\ No newline at end of file
diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php
index cf97b412..33959f00 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) {
-- 
GitLab