Completed
Pull Request — master (#2)
by Andrew
06:06
created

AdminCommentController::indexAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 11
loc 11
ccs 8
cts 8
cp 1
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: kate
5
 * Date: 04.03.16
6
 * Time: 22:24
7
 */
8
9
namespace AppBundle\Controller\Admin;
10
11
use AppBundle\Entity\Comment;
12
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
13
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
14
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
15
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
16
use Symfony\Component\HttpFoundation\Request;
17
use AppBundle\Utils;
18
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
19
20
21
/**
22
 * @Security("has_role('ROLE_MANAGER')")
23
 * @Route("/admin")
24
 */
25
class AdminCommentController extends Controller
26
{
27
    /**
28
     * @Route("/comments", name="admin_comments")
29
     */
30 1 View Code Duplication
    public function indexAction(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32 1
        $comments = $this->getDoctrine()->getRepository('AppBundle:Comment')->getDisabledComments();
33 1
        $paginator = $this->get('knp_paginator');
34 1
        $pagination = $paginator->paginate(
35 1
            $comments,
36 1
            $request->query->getInt('page', 1),
37
            20
38 1
        );
39 1
        return $this->render('AppBundle::admin/comment/comments.html.twig', array('pagination' => $pagination));
40
    }
41
42
    /**
43
     * @Route("/comments/all", name="admin_all_comments")
44
     */
45 1 View Code Duplication
    public function allCommentsAction(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47 1
        $comments = $this->getDoctrine()->getRepository('AppBundle:Comment')->findAll();
48 1
        $paginator = $this->get('knp_paginator');
49 1
        $pagination = $paginator->paginate(
50 1
            $comments,
51 1
            $request->query->getInt('page', 1),
52
            20
53 1
        );
54 1
        return $this->render('AppBundle::admin/comment/all_comments.html.twig', array('pagination' => $pagination));
55
    }
56
57
    /**
58
     * @Route("/comments/published", name="admin_published_comments")
59
     */
60 1 View Code Duplication
    public function publishedCommentsAction(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62 1
        $comments = $this->getDoctrine()->getRepository('AppBundle:Comment')->getEnabledComments();
63 1
        $paginator = $this->get('knp_paginator');
64 1
        $pagination = $paginator->paginate(
65 1
            $comments,
66 1
            $request->query->getInt('page', 1),
67
            20
68 1
        );
69 1
        return $this->render('AppBundle:admin/comment:published_comments.html.twig', array('pagination' => $pagination));
70
    }
71
72
    /**
73
     * @Route("/comment/show/{id}", name="admin_comment_show")
74
     * @ParamConverter("comment", options={"mapping": {"id": "id"}})
75
     */
76 1
    public function showCommentAction(Request $request, Comment $comment)
77
    {
78 1
        $form = $this->deleteForm($comment);
79 1
        return $this->render("AppBundle:admin/comment:show_comment.html.twig", array("comment" => $comment,
80 1
            'delete_form' => $form->createView(),));
81
    }
82
83
    /**
84
     * @Route("/comment_enable/{id}", name="admin_enable_comment")
85
     * @ParamConverter("comment", options={"mapping": {"id": "id"}})
86
     * @Security("has_role('ROLE_ADMIN')")
87
     */
88 1
    public function enableCommentAction(Request $request, Comment $comment)
89
    {
90 1
        $comment->setEnabled(true);
91 1
        $em = $this->getDoctrine()->getManager();
92 1
        $em->flush();
93 1
        return $this->redirectToRoute('admin_comments');
94
    }
95
96
    /**
97
     * @Route("/comment/delete/{id}", name="admin_comment_delete")
98
     * @Method("DELETE")
99
     * @Security("has_role('ROLE_ADMIN')")
100
     * @ParamConverter("comment", options={"mapping": {"id": "id"}})
101
     */
102 1
    public function deleteCommentAction(Request $request, Comment $comment)
103
    {
104
        $form = $this->deleteForm($comment);
105
        $form->handleRequest($request);
106
        if ($form->isSubmitted() && $form->isValid()) {
107 1
            $entityManager = $this->getDoctrine()->getManager();
108
            $entityManager->remove($comment);
109
            $entityManager->flush();
110 1
        }
111
        return $this->redirectToRoute('admin_comments');
112
    }
113
114 2 View Code Duplication
    private function deleteForm(Comment $comment)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
115
    {
116 1
        return $this->createFormBuilder()
117 1
            ->setAction($this->generateUrl('admin_comment_delete', array('id' => $comment->getId())))
118 2
            ->setMethod('DELETE')
119 1
            ->getForm()
120 1
            ;
121
    }
122
123
    /**
124
     * @Route (name="count_disables_comments")
125
     */
126 15
    public function countDisablesCommentsAction(Request $request)
127
    {
128 15
        $comments = $this->getDoctrine()->getRepository('AppBundle:Comment')->getDisabledComments();
129 15
        return $this->render("AppBundle:admin/comment:count_disables_comment.html.twig",
130 15
            array("count_disables_comments" => count($comments)));
131
    }
132
}