|
@@ -0,0 +1,126 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace Muzich\AdminBundle\Controller\Moderate_user;
|
|
4
|
+
|
|
5
|
+use Muzich\CoreBundle\lib\Controller as BaseController;
|
|
6
|
+use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
7
|
+use Symfony\Component\HttpFoundation\Response;
|
|
8
|
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
9
|
+
|
|
10
|
+class EditController extends BaseController
|
|
11
|
+{
|
|
12
|
+
|
|
13
|
+ protected function getUserContext($user_id)
|
|
14
|
+ {
|
|
15
|
+ $user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
|
|
16
|
+ ->findOneById($user_id)->getSingleResult();
|
|
17
|
+
|
|
18
|
+ if (!$user) {
|
|
19
|
+ throw new NotFoundHttpException("The Muzich\CoreBundle\Entity\User with id $user_id can't be found");
|
|
20
|
+ }
|
|
21
|
+ return $user;
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+ public function disableAndDeleteAllHisElementsAction($pk)
|
|
25
|
+ {
|
|
26
|
+ $user = $this->getUserContext($pk);
|
|
27
|
+ $user->setEnabled(false);
|
|
28
|
+ $this->persist($user);
|
|
29
|
+ foreach ($user->getElements() as $element)
|
|
30
|
+ {
|
|
31
|
+ $this->remove($element);
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ try
|
|
35
|
+ {
|
|
36
|
+ $this->flush();
|
|
37
|
+ $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
|
|
38
|
+ }
|
|
39
|
+ catch (\Exception $e)
|
|
40
|
+ {
|
|
41
|
+ throw $e;
|
|
42
|
+ $this->get('session')->setFlash('error', $this->get('translator')->trans("object.edit.error", array(), 'Admingenerator') );
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Admin_user_show", array(
|
|
46
|
+ 'pk' => $pk
|
|
47
|
+ )));
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ public function acceptAction($element_id, $date)
|
|
51
|
+ {
|
|
52
|
+ $element = $this->getElementContext($element_id);
|
|
53
|
+ $cm = new CommentsManager($element->getComments());
|
|
54
|
+ // On nettoie le commentaire et on récupère les ids des "signaleurs"
|
|
55
|
+ $ids = $cm->cleanAlertsOnComment($date);
|
|
56
|
+ $element->setComments($cm->get());
|
|
57
|
+ $element->setCountCommentReport($cm->countCommentAlert());
|
|
58
|
+
|
|
59
|
+ $this->getDoctrine()->getEntityManager()->persist($element);
|
|
60
|
+
|
|
61
|
+ // On récupère les user qui ont signalés ce commentaire
|
|
62
|
+ $users = $this->getDoctrine()->getEntityManager()
|
|
63
|
+ ->createQuery('
|
|
64
|
+ SELECT u FROM MuzichCoreBundle:User u
|
|
65
|
+ WHERE u.id IN (:uids)'
|
|
66
|
+ )
|
|
67
|
+ ->setParameter('uids', $ids)
|
|
68
|
+ ->getResult()
|
|
69
|
+ ;
|
|
70
|
+
|
|
71
|
+ // Pour chacun on augmente le compteur de signalements inutiles
|
|
72
|
+ foreach ($users as $user)
|
|
73
|
+ {
|
|
74
|
+ $user->addBadReport();
|
|
75
|
+ $this->getDoctrine()->getEntityManager()->persist($user);
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ $this->getDoctrine()->getEntityManager()->flush();
|
|
79
|
+
|
|
80
|
+ if (!$this->getRequest()->isXmlHttpRequest())
|
|
81
|
+ {
|
|
82
|
+ $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
|
|
83
|
+ return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Moderate_comment_list" ));
|
|
84
|
+ }
|
|
85
|
+ return $this->getJsonEmptyResponse();
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ protected function getJsonEmptyResponse()
|
|
89
|
+ {
|
|
90
|
+ $response = new Response(json_encode(array()));
|
|
91
|
+ $response->headers->set('Content-Type', 'application/json; charset=utf-8');
|
|
92
|
+ return $response;
|
|
93
|
+ }
|
|
94
|
+
|
|
95
|
+ public function refuseAction($element_id, $date)
|
|
96
|
+ {
|
|
97
|
+ $element = $this->getElementContext($element_id);
|
|
98
|
+ $cm = new CommentsManager($element->getComments());
|
|
99
|
+ $comment = $cm->get($cm->getIndexWithDate($date));
|
|
100
|
+ // On supprime le commentaire
|
|
101
|
+ $cm->deleteWithDate($date);
|
|
102
|
+ $element->setComments($cm->get());
|
|
103
|
+ $element->setCountCommentReport($cm->countCommentAlert());
|
|
104
|
+
|
|
105
|
+ // On récupère l'auteur du commentaire pour lui incrémenté son compteur
|
|
106
|
+ // de contenu modéré
|
|
107
|
+ $user = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:User')
|
|
108
|
+ ->findOneBy(array(
|
|
109
|
+ 'id' => $comment['u']['i']
|
|
110
|
+ ));
|
|
111
|
+
|
|
112
|
+ $user->addModeratedCommentCount();
|
|
113
|
+
|
|
114
|
+ $this->getDoctrine()->getEntityManager()->persist($user);
|
|
115
|
+ $this->getDoctrine()->getEntityManager()->persist($element);
|
|
116
|
+ $this->getDoctrine()->getEntityManager()->flush();
|
|
117
|
+
|
|
118
|
+ if (!$this->getRequest()->isXmlHttpRequest())
|
|
119
|
+ {
|
|
120
|
+ $this->get('session')->setFlash('success', $this->get('translator')->trans("object.edit.success", array(), 'Admingenerator') );
|
|
121
|
+ return new RedirectResponse($this->generateUrl("Muzich_AdminBundle_Moderate_comment_list" ));
|
|
122
|
+ }
|
|
123
|
+ return $this->getJsonEmptyResponse();
|
|
124
|
+ }
|
|
125
|
+
|
|
126
|
+}
|