|
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
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @Security("has_role('ROLE_MANAGER')") |
|
24
|
|
|
* @Route("/admin") |
|
25
|
|
|
*/ |
|
26
|
|
|
class AdminCommentController extends Controller |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @Route("/comments", name="admin_comments") |
|
30
|
|
|
*/ |
|
31
|
|
View Code Duplication |
public function indexAction(Request $request) |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
$comments = $this->getDoctrine()->getRepository('AppBundle:Comment')->getDisabledComments(); |
|
34
|
|
|
$paginator = $this->get('knp_paginator'); |
|
35
|
|
|
$pagination = $paginator->paginate( |
|
36
|
|
|
$comments, |
|
37
|
|
|
$request->query->getInt('page', 1), |
|
38
|
|
|
20 |
|
39
|
|
|
); |
|
40
|
|
|
return $this->render('AppBundle::admin/comment/comments.html.twig', array('pagination' => $pagination)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @Route("/comments/all", name="admin_all_comments") |
|
45
|
|
|
*/ |
|
46
|
|
View Code Duplication |
public function allCommentsAction(Request $request) |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
|
|
$comments = $this->getDoctrine()->getRepository('AppBundle:Comment')->findAll(); |
|
49
|
|
|
$paginator = $this->get('knp_paginator'); |
|
50
|
|
|
$pagination = $paginator->paginate( |
|
51
|
|
|
$comments, |
|
52
|
|
|
$request->query->getInt('page', 1), |
|
53
|
|
|
20 |
|
54
|
|
|
); |
|
55
|
|
|
return $this->render('AppBundle::admin/comment/all_comments.html.twig', array('pagination' => $pagination)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @Route("/comments/published", name="admin_published_comments") |
|
60
|
|
|
*/ |
|
61
|
|
View Code Duplication |
public function publishedCommentsAction(Request $request) |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
$comments = $this->getDoctrine()->getRepository('AppBundle:Comment')->getEnabledComments(); |
|
64
|
|
|
$paginator = $this->get('knp_paginator'); |
|
65
|
|
|
$pagination = $paginator->paginate( |
|
66
|
|
|
$comments, |
|
67
|
|
|
$request->query->getInt('page', 1), |
|
68
|
|
|
20 |
|
69
|
|
|
); |
|
70
|
|
|
return $this->render('AppBundle:admin/comment:published_comments.html.twig', array('pagination' => $pagination)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @Route("/comment/show/{id}", name="admin_comment_show") |
|
75
|
|
|
* @ParamConverter("comment", options={"mapping": {"id": "id"}}) |
|
76
|
|
|
*/ |
|
77
|
|
|
public function showCommentAction(Request $request, Comment $comment) |
|
78
|
|
|
{ |
|
79
|
|
|
$form = $this->deleteForm($comment); |
|
80
|
|
|
return $this->render("AppBundle:admin/comment:show_comment.html.twig", array("comment" => $comment, |
|
81
|
|
|
'delete_form' => $form->createView(),)); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @Route("/comment_enable/{id}", name="admin_enable_comment") |
|
86
|
|
|
* @ParamConverter("comment", options={"mapping": {"id": "id"}}) |
|
87
|
|
|
* @Security("has_role('ROLE_ADMIN')") |
|
88
|
|
|
*/ |
|
89
|
|
|
public function enableCommentAction(Request $request, Comment $comment) |
|
90
|
|
|
{ |
|
91
|
|
|
$comment->setEnabled(true); |
|
92
|
|
|
$em = $this->getDoctrine()->getEntityManager(); |
|
|
|
|
|
|
93
|
|
|
$em->flush(); |
|
94
|
|
|
return $this->redirectToRoute('admin_comments'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @Route("/comment/delete/{id}", name="admin_comment_delete") |
|
99
|
|
|
* @Method("DELETE") |
|
100
|
|
|
* @Security("has_role('ROLE_ADMIN')") |
|
101
|
|
|
* @ParamConverter("comment", options={"mapping": {"id": "id"}}) |
|
102
|
|
|
*/ |
|
103
|
|
|
public function deleteCommentAction(Request $request, Comment $comment) |
|
104
|
|
|
{ |
|
105
|
|
|
$form = $this->deleteForm($comment); |
|
106
|
|
|
$form->handleRequest($request); |
|
107
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
108
|
|
|
$entityManager = $this->getDoctrine()->getManager(); |
|
109
|
|
|
$entityManager->remove($comment); |
|
110
|
|
|
$entityManager->flush(); |
|
111
|
|
|
} |
|
112
|
|
|
return $this->redirectToRoute('admin_comments'); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
View Code Duplication |
private function deleteForm(Comment $comment) |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
|
|
return $this->createFormBuilder() |
|
118
|
|
|
->setAction($this->generateUrl('admin_comment_delete', array('id' => $comment->getId()))) |
|
119
|
|
|
->setMethod('DELETE') |
|
120
|
|
|
->getForm() |
|
121
|
|
|
; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @Route (name="count_disables_comments") |
|
126
|
|
|
*/ |
|
127
|
11 |
|
public function countDisablesCommentsAction(Request $request) |
|
128
|
|
|
{ |
|
129
|
11 |
|
$comments = $this->getDoctrine()->getRepository('AppBundle:Comment')->getDisabledComments(); |
|
130
|
11 |
|
return $this->render("AppBundle:admin/comment:count_disables_comment.html.twig", |
|
131
|
11 |
|
array("count_disables_comments" => count($comments))); |
|
132
|
|
|
} |
|
133
|
|
|
} |
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.