|
@@ -7,6 +7,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
7
|
7
|
//use Muzich\CoreBundle\Util\TagLike;
|
8
|
8
|
use Muzich\CoreBundle\Entity\UsersTagsFavorites;
|
9
|
9
|
use Muzich\CoreBundle\Entity\GroupsTagsFavorites;
|
|
10
|
+use Muzich\CoreBundle\Managers\TagManager;
|
10
|
11
|
|
11
|
12
|
class ModerateController extends Controller
|
12
|
13
|
{
|
|
@@ -58,10 +59,8 @@ class ModerateController extends Controller
|
58
|
59
|
}
|
59
|
60
|
}
|
60
|
61
|
|
61
|
|
- if (!($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
|
62
|
|
- 'id' => $tag_id,
|
63
|
|
- 'tomoderate' => true
|
64
|
|
- ))))
|
|
62
|
+ $tagManager = new TagManager();
|
|
63
|
+ if (!$tagManager->moderateTag($this->getDoctrine(), $tag_id, true))
|
65
|
64
|
{
|
66
|
65
|
return $this->jsonResponse(array(
|
67
|
66
|
'status' => 'error',
|
|
@@ -69,11 +68,6 @@ class ModerateController extends Controller
|
69
|
68
|
));
|
70
|
69
|
}
|
71
|
70
|
|
72
|
|
- $tag->setTomoderate(false);
|
73
|
|
- $tag->setPrivateids(null);
|
74
|
|
- $this->getDoctrine()->getEntityManager()->persist($tag);
|
75
|
|
- $this->getDoctrine()->getEntityManager()->flush();
|
76
|
|
-
|
77
|
71
|
return $this->jsonResponse(array(
|
78
|
72
|
'status' => 'success'
|
79
|
73
|
));
|
|
@@ -95,10 +89,8 @@ class ModerateController extends Controller
|
95
|
89
|
}
|
96
|
90
|
}
|
97
|
91
|
|
98
|
|
- if (!($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
|
99
|
|
- 'id' => $tag_id,
|
100
|
|
- 'tomoderate' => true
|
101
|
|
- ))))
|
|
92
|
+ $tagManager = new TagManager();
|
|
93
|
+ if (!$tagManager->moderateTag($this->getDoctrine(), $tag_id, false))
|
102
|
94
|
{
|
103
|
95
|
return $this->jsonResponse(array(
|
104
|
96
|
'status' => 'error',
|
|
@@ -106,9 +98,6 @@ class ModerateController extends Controller
|
106
|
98
|
));
|
107
|
99
|
}
|
108
|
100
|
|
109
|
|
- $this->getDoctrine()->getEntityManager()->remove($tag);
|
110
|
|
- $this->getDoctrine()->getEntityManager()->flush();
|
111
|
|
-
|
112
|
101
|
return $this->jsonResponse(array(
|
113
|
102
|
'status' => 'success'
|
114
|
103
|
));
|
|
@@ -148,13 +137,8 @@ class ModerateController extends Controller
|
148
|
137
|
}
|
149
|
138
|
$tag_new_id = $tag_array[0];
|
150
|
139
|
|
151
|
|
- if (
|
152
|
|
- !($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneBy(array(
|
153
|
|
- 'id' => $tag_id,
|
154
|
|
- 'tomoderate' => true
|
155
|
|
- )))
|
156
|
|
- || !($new_tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneById($tag_new_id))
|
157
|
|
- )
|
|
140
|
+ $tagManager = new TagManager();
|
|
141
|
+ if (!$tagManager->moderateTag($this->getDoctrine(), $tag_id, false, $tag_new_id))
|
158
|
142
|
{
|
159
|
143
|
return $this->jsonResponse(array(
|
160
|
144
|
'status' => 'error',
|
|
@@ -162,90 +146,10 @@ class ModerateController extends Controller
|
162
|
146
|
));
|
163
|
147
|
}
|
164
|
148
|
|
165
|
|
- /*
|
166
|
|
- * Trois cas de figures ou sont utilisés les tags
|
167
|
|
- * * Sur un élément
|
168
|
|
- * * Tag favori
|
169
|
|
- * * Tag d'un groupe
|
170
|
|
- */
|
171
|
|
- $em = $this->getDoctrine()->getEntityManager();
|
172
|
|
-
|
173
|
|
- // Sur un élément
|
174
|
|
- foreach ($elements = $this->getDoctrine()->getEntityManager()->createQuery("
|
175
|
|
- SELECT e, t FROM MuzichCoreBundle:Element e
|
176
|
|
- JOIN e.tags t
|
177
|
|
- WHERE t.id = :tid
|
178
|
|
- ")
|
179
|
|
- ->setParameter('tid', $tag_id)
|
180
|
|
- ->getResult() as $element)
|
181
|
|
- {
|
182
|
|
- // Pour chaque elements lié a ce tag
|
183
|
|
- // On ajoute un lien vers le nouveau tag si il n'en n'a pas déjà
|
184
|
|
- if (!$element->hasTag($new_tag))
|
185
|
|
- {
|
186
|
|
- $element->addTag($new_tag);
|
187
|
|
- $em->persist($element);
|
188
|
|
- }
|
189
|
|
- }
|
190
|
|
-
|
191
|
|
- // Tag favoris
|
192
|
|
- foreach ($favorites = $this->getDoctrine()->getEntityManager()->createQuery("
|
193
|
|
- SELECT f FROM MuzichCoreBundle:UsersTagsFavorites f
|
194
|
|
- WHERE f.tag = :tid
|
195
|
|
- ")
|
196
|
|
- ->setParameter('tid', $tag_id)
|
197
|
|
- ->getResult() as $fav)
|
198
|
|
- {
|
199
|
|
- // Pour chaque favoris utilisant ce tag on regarde si l'utilisateur
|
200
|
|
- // n'a pas déjà le nouveau tag en favoris.
|
201
|
|
- if (!$this->getDoctrine()->getEntityManager()->createQuery("
|
202
|
|
- SELECT COUNT(f.id) FROM MuzichCoreBundle:UsersTagsFavorites f
|
203
|
|
- WHERE f.tag = :tid AND f.user = :uid
|
204
|
|
- ")
|
205
|
|
- ->setParameters(array('tid' => $tag_new_id, 'uid' => $fav->getUser()->getId()))
|
206
|
|
- ->getSingleScalarResult())
|
207
|
|
- {
|
208
|
|
- $new_fav = new UsersTagsFavorites();
|
209
|
|
- $new_fav->setTag($new_tag);
|
210
|
|
- $new_fav->setUser($fav->getUser());
|
211
|
|
- $new_fav->setPosition($fav->getPosition());
|
212
|
|
- $em->persist($new_fav);
|
213
|
|
- }
|
214
|
|
- $em->remove($fav);
|
215
|
|
- }
|
216
|
|
-
|
217
|
|
- // groupe
|
218
|
|
- foreach ($this->getDoctrine()->getEntityManager()->createQuery("
|
219
|
|
- SELECT f FROM MuzichCoreBundle:GroupsTagsFavorites f
|
220
|
|
- WHERE f.tag = :tid
|
221
|
|
- ")
|
222
|
|
- ->setParameter('tid', $tag_id)
|
223
|
|
- ->getResult() as $fav)
|
224
|
|
- {
|
225
|
|
- // Pour chaque favoris utilisant ce tag on regarde si le groupe
|
226
|
|
- // n'a pas déjà le nouveau tag en favoris.
|
227
|
|
- if (!$this->getDoctrine()->getEntityManager()->createQuery("
|
228
|
|
- SELECT COUNT(f.id) FROM MuzichCoreBundle:GroupsTagsFavorites f
|
229
|
|
- WHERE f.tag = :tid AND f.group = :gid
|
230
|
|
- ")
|
231
|
|
- ->setParameters(array('tid' => $tag_new_id, 'gid' => $fav->getGroup()->getId()))
|
232
|
|
- ->getSingleScalarResult())
|
233
|
|
- {
|
234
|
|
- $new_fav = new GroupsTagsFavorites();
|
235
|
|
- $new_fav->setTag($new_tag);
|
236
|
|
- $new_fav->setGroup($fav->getGroup());
|
237
|
|
- $new_fav->setPosition($fav->getPosition());
|
238
|
|
- $em->persist($new_fav);
|
239
|
|
- }
|
240
|
|
- $em->remove($fav);
|
241
|
|
- }
|
242
|
|
-
|
243
|
|
- $em->remove($tag);
|
244
|
|
- $em->flush();
|
245
|
|
-
|
246
|
149
|
return $this->jsonResponse(array(
|
247
|
150
|
'status' => 'success'
|
248
|
151
|
));
|
|
152
|
+
|
249
|
153
|
}
|
250
|
154
|
|
251
|
155
|
}
|