|
@@ -2,8 +2,9 @@
|
2
|
2
|
|
3
|
3
|
namespace Muzich\AdminBundle\Controller;
|
4
|
4
|
|
5
|
|
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
5
|
+use Muzich\CoreBundle\lib\Controller;
|
6
|
6
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
|
7
|
+//use Muzich\CoreBundle\Util\TagLike;
|
7
|
8
|
|
8
|
9
|
class ModerateController extends Controller
|
9
|
10
|
{
|
|
@@ -29,8 +30,179 @@ class ModerateController extends Controller
|
29
|
30
|
public function tagsAction()
|
30
|
31
|
{
|
31
|
32
|
// Récupération des tags
|
32
|
|
- $tags = $this->getDoctrine()->getEntityManager('MuzichCoreBundle:Tag')
|
|
33
|
+ $tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')
|
33
|
34
|
->getToModerate();
|
|
35
|
+
|
|
36
|
+ // TODO: Ajouter a chaque tag la liste des tags ressemblant
|
|
37
|
+
|
|
38
|
+ return array(
|
|
39
|
+ 'tags' => $tags
|
|
40
|
+ );
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ public function tagAcceptAction($tag_id)
|
|
44
|
+ {
|
|
45
|
+ if ($this->getUser() == 'anon.')
|
|
46
|
+ {
|
|
47
|
+ if ($this->getRequest()->isXmlHttpRequest())
|
|
48
|
+ {
|
|
49
|
+ return $this->jsonResponse(array(
|
|
50
|
+ 'status' => 'mustbeconnected'
|
|
51
|
+ ));
|
|
52
|
+ }
|
|
53
|
+ else
|
|
54
|
+ {
|
|
55
|
+ return $this->redirect($this->generateUrl('index'));
|
|
56
|
+ }
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ if (!($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
|
|
60
|
+ 'id' => $tag_id,
|
|
61
|
+ 'tomoderate' => true
|
|
62
|
+ ))))
|
|
63
|
+ {
|
|
64
|
+ return $this->jsonResponse(array(
|
|
65
|
+ 'status' => 'error',
|
|
66
|
+ 'message' => 'NotFound'
|
|
67
|
+ ));
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ $tag->setTomoderate(false);
|
|
71
|
+ $tag->setPrivateids(null);
|
|
72
|
+ $this->getDoctrine()->getEntityManager()->persist($tag);
|
|
73
|
+ $this->getDoctrine()->getEntityManager()->flush();
|
|
74
|
+
|
|
75
|
+ return $this->jsonResponse(array(
|
|
76
|
+ 'status' => 'success'
|
|
77
|
+ ));
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ public function tagRefuseAction($tag_id)
|
|
81
|
+ {
|
|
82
|
+ if ($this->getUser() == 'anon.')
|
|
83
|
+ {
|
|
84
|
+ if ($this->getRequest()->isXmlHttpRequest())
|
|
85
|
+ {
|
|
86
|
+ return $this->jsonResponse(array(
|
|
87
|
+ 'status' => 'mustbeconnected'
|
|
88
|
+ ));
|
|
89
|
+ }
|
|
90
|
+ else
|
|
91
|
+ {
|
|
92
|
+ return $this->redirect($this->generateUrl('index'));
|
|
93
|
+ }
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ if (!($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
|
|
97
|
+ 'id' => $tag_id,
|
|
98
|
+ 'tomoderate' => true
|
|
99
|
+ ))))
|
|
100
|
+ {
|
|
101
|
+ return $this->jsonResponse(array(
|
|
102
|
+ 'status' => 'error',
|
|
103
|
+ 'message' => 'NotFound'
|
|
104
|
+ ));
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+ $this->getDoctrine()->getEntityManager()->remove($tag);
|
|
108
|
+ $this->getDoctrine()->getEntityManager()->flush();
|
|
109
|
+
|
|
110
|
+ return $this->jsonResponse(array(
|
|
111
|
+ 'status' => 'success'
|
|
112
|
+ ));
|
|
113
|
+ }
|
|
114
|
+
|
|
115
|
+ /**
|
|
116
|
+ * Cette action est plus délicate, elle consiste a remplacer le tag en question
|
|
117
|
+ * par un autre.
|
|
118
|
+ *
|
|
119
|
+ * @param int $tag_id
|
|
120
|
+ * @param int $tag_new_id
|
|
121
|
+ * @return view
|
|
122
|
+ */
|
|
123
|
+ public function tagReplaceAction($tag_id, $tag_new_id)
|
|
124
|
+ {
|
|
125
|
+ if ($this->getUser() == 'anon.')
|
|
126
|
+ {
|
|
127
|
+ if ($this->getRequest()->isXmlHttpRequest())
|
|
128
|
+ {
|
|
129
|
+ return $this->jsonResponse(array(
|
|
130
|
+ 'status' => 'mustbeconnected'
|
|
131
|
+ ));
|
|
132
|
+ }
|
|
133
|
+ else
|
|
134
|
+ {
|
|
135
|
+ return $this->redirect($this->generateUrl('index'));
|
|
136
|
+ }
|
|
137
|
+ }
|
|
138
|
+
|
|
139
|
+ $tag_array = json_decode($tag_new_id);
|
|
140
|
+ if (!array_key_exists(0, $tag_array))
|
|
141
|
+ {
|
|
142
|
+ return $this->jsonResponse(array(
|
|
143
|
+ 'status' => 'error',
|
|
144
|
+ 'message' => 'netTagError'
|
|
145
|
+ ));
|
|
146
|
+ }
|
|
147
|
+ $tag_new_id = $tag_array[0];
|
|
148
|
+
|
|
149
|
+ if (
|
|
150
|
+ !($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
|
|
151
|
+ 'id' => $tag_id,
|
|
152
|
+ 'tomoderate' => true
|
|
153
|
+ )))
|
|
154
|
+ || !($new_tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneById($tag_new_id))
|
|
155
|
+ )
|
|
156
|
+ {
|
|
157
|
+ return $this->jsonResponse(array(
|
|
158
|
+ 'status' => 'error',
|
|
159
|
+ 'message' => 'NotFound'
|
|
160
|
+ ));
|
|
161
|
+ }
|
|
162
|
+
|
|
163
|
+ /*
|
|
164
|
+ * Trois cas de figures ou sont utilisés les tags
|
|
165
|
+ * * Sur un élément
|
|
166
|
+ * * Tag favori
|
|
167
|
+ * * Tag d'un groupe
|
|
168
|
+ */
|
|
169
|
+ $em = $this->getDoctrine()->getEntityManager();
|
|
170
|
+
|
|
171
|
+ $netags = array();
|
|
172
|
+ foreach ($elements = $this->getDoctrine()->getEntityManager()->createQuery("
|
|
173
|
+ SELECT e, t FROM MuzichCoreBundle:Element e
|
|
174
|
+ JOIN e.tags t
|
|
175
|
+ WHERE t.id = :tid
|
|
176
|
+ ")
|
|
177
|
+ ->setParameter('tid', $tag_new_id)
|
|
178
|
+ ->getResult() as $element)
|
|
179
|
+ {
|
|
180
|
+
|
|
181
|
+ // TODO: a faire ...
|
|
182
|
+// foreach ($element->getTags() as $etag)
|
|
183
|
+// {
|
|
184
|
+// if ($etag->getId() != $tag->getId())
|
|
185
|
+// {
|
|
186
|
+// $netags[] = $etag;
|
|
187
|
+// }
|
|
188
|
+// }
|
|
189
|
+// $netags[] = $new_tag;
|
|
190
|
+//
|
|
191
|
+// $element->setTags(array());
|
|
192
|
+// $em->persist($element);
|
|
193
|
+// $em->flush();
|
|
194
|
+//
|
|
195
|
+// $element->setTags($netags);
|
|
196
|
+// $em->persist($element);
|
|
197
|
+// $em->flush();
|
|
198
|
+ }
|
|
199
|
+
|
|
200
|
+ $em->remove($tag);
|
|
201
|
+ $em->flush();
|
|
202
|
+
|
|
203
|
+ return $this->jsonResponse(array(
|
|
204
|
+ 'status' => 'success'
|
|
205
|
+ ));
|
34
|
206
|
}
|
35
|
207
|
|
36
|
208
|
}
|