|
@@ -9,6 +9,7 @@ use Muzich\CoreBundle\Entity\UsersTagsFavorites;
|
9
|
9
|
use Muzich\CoreBundle\Entity\GroupsTagsFavorites;
|
10
|
10
|
use Muzich\CoreBundle\Managers\TagManager;
|
11
|
11
|
use Muzich\CoreBundle\Propagator\EventElement;
|
|
12
|
+use Muzich\CoreBundle\Managers\CommentsManager;
|
12
|
13
|
|
13
|
14
|
class ModerateController extends Controller
|
14
|
15
|
{
|
|
@@ -23,10 +24,13 @@ class ModerateController extends Controller
|
23
|
24
|
->countToModerate();
|
24
|
25
|
$count_elements = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
25
|
26
|
->countToModerate();
|
|
27
|
+ $count_comments = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
28
|
+ ->countForCommentToModerate();
|
26
|
29
|
|
27
|
30
|
return array(
|
28
|
31
|
'count_tags' => $count_tags,
|
29
|
|
- 'count_elements' => $count_elements
|
|
32
|
+ 'count_elements' => $count_elements,
|
|
33
|
+ 'count_comments' => $count_comments
|
30
|
34
|
);
|
31
|
35
|
}
|
32
|
36
|
|
|
@@ -220,4 +224,136 @@ class ModerateController extends Controller
|
220
|
224
|
));
|
221
|
225
|
}
|
222
|
226
|
|
|
227
|
+ /**
|
|
228
|
+ *
|
|
229
|
+ * @Template()
|
|
230
|
+ */
|
|
231
|
+ public function commentsAction()
|
|
232
|
+ {
|
|
233
|
+ // Récupération des elements
|
|
234
|
+ $elements = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
235
|
+ ->getForCommentToModerate();
|
|
236
|
+
|
|
237
|
+ $comments = array();
|
|
238
|
+ foreach ($elements as $element)
|
|
239
|
+ {
|
|
240
|
+ $cm = new CommentsManager($element->getComments());
|
|
241
|
+ foreach ($cm->getAlertedComments() as $comment)
|
|
242
|
+ {
|
|
243
|
+ $comments[] = array(
|
|
244
|
+ 'element_id' => $element->getId(),
|
|
245
|
+ 'comment' => $comment
|
|
246
|
+ );
|
|
247
|
+ }
|
|
248
|
+
|
|
249
|
+ }
|
|
250
|
+
|
|
251
|
+ return array(
|
|
252
|
+ 'comments' => $comments
|
|
253
|
+ );
|
|
254
|
+ }
|
|
255
|
+
|
|
256
|
+ /**
|
|
257
|
+ * Considérer le commentaire signalé comme étant tout a fait acceptable
|
|
258
|
+ *
|
|
259
|
+ * Ceci induit:
|
|
260
|
+ * * Que le commentaire en question ne soit plus signalé
|
|
261
|
+ * * Que le ou les ids d'utilisateurs qui l'ont signalé comme soit "pénalisé
|
|
262
|
+ *
|
|
263
|
+ * @param int $element_id
|
|
264
|
+ * @param date $date
|
|
265
|
+ *
|
|
266
|
+ * @return Response
|
|
267
|
+ */
|
|
268
|
+ public function commentCleanAction($element_id, $date)
|
|
269
|
+ {
|
|
270
|
+ if (($response = $this->mustBeConnected(true)))
|
|
271
|
+ {
|
|
272
|
+ return $response;
|
|
273
|
+ }
|
|
274
|
+
|
|
275
|
+ if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
276
|
+ ->findOneById($element_id))
|
|
277
|
+ )
|
|
278
|
+ {
|
|
279
|
+ return $this->jsonResponse(array(
|
|
280
|
+ 'status' => 'error',
|
|
281
|
+ 'errors' => array('NotFound')
|
|
282
|
+ ));
|
|
283
|
+ }
|
|
284
|
+
|
|
285
|
+ $cm = new CommentsManager($element->getComments());
|
|
286
|
+ // On nettoie le commentaire et on récupère les ids des "signaleurs"
|
|
287
|
+ $ids = $cm->cleanAlertsOnComment($date);
|
|
288
|
+ $element->setComments($cm->get());
|
|
289
|
+ $element->setCountCommentReport($cm->countCommentAlert());
|
|
290
|
+
|
|
291
|
+ $this->getDoctrine()->getEntityManager()->persist($element);
|
|
292
|
+
|
|
293
|
+ // On récupère les user qui ont signalés ce commentaire
|
|
294
|
+ $users = $this->getDoctrine()->getEntityManager()
|
|
295
|
+ ->createQuery('
|
|
296
|
+ SELECT u FROM MuzichCoreBundle:User u
|
|
297
|
+ WHERE u.id IN (:uids)'
|
|
298
|
+ )
|
|
299
|
+ ->setParameter('uids', $ids)
|
|
300
|
+ ->getResult()
|
|
301
|
+ ;
|
|
302
|
+
|
|
303
|
+ // Pour chacun on augmente le compteur de signalements inutiles
|
|
304
|
+ foreach ($users as $user)
|
|
305
|
+ {
|
|
306
|
+ $user->addBadReport();
|
|
307
|
+ $this->getDoctrine()->getEntityManager()->persist($user);
|
|
308
|
+ }
|
|
309
|
+
|
|
310
|
+ $this->getDoctrine()->getEntityManager()->flush();
|
|
311
|
+
|
|
312
|
+ return $this->jsonResponse(array(
|
|
313
|
+ 'status' => 'success'
|
|
314
|
+ ));
|
|
315
|
+ }
|
|
316
|
+
|
|
317
|
+ /**
|
|
318
|
+ * Considérer le commentaire signalé comme étant tout a fait acceptable
|
|
319
|
+ *
|
|
320
|
+ * Ceci induit:
|
|
321
|
+ * * Que le commentaire en question ne soit plus signalé
|
|
322
|
+ * * Que le ou les ids d'utilisateurs qui l'ont signalé comme soit "pénalisé
|
|
323
|
+ *
|
|
324
|
+ * @param int $element_id
|
|
325
|
+ * @param date $date
|
|
326
|
+ *
|
|
327
|
+ * @return Response
|
|
328
|
+ */
|
|
329
|
+ public function commentRefuseAction($element_id, $date)
|
|
330
|
+ {
|
|
331
|
+ if (($response = $this->mustBeConnected(true)))
|
|
332
|
+ {
|
|
333
|
+ return $response;
|
|
334
|
+ }
|
|
335
|
+
|
|
336
|
+ if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
337
|
+ ->findOneById($element_id))
|
|
338
|
+ )
|
|
339
|
+ {
|
|
340
|
+ return $this->jsonResponse(array(
|
|
341
|
+ 'status' => 'error',
|
|
342
|
+ 'errors' => array('NotFound')
|
|
343
|
+ ));
|
|
344
|
+ }
|
|
345
|
+
|
|
346
|
+ $cm = new CommentsManager($element->getComments());
|
|
347
|
+ // On supprime le commentaire
|
|
348
|
+ $cm->deleteWithDate($date);
|
|
349
|
+ $element->setComments($cm->get());
|
|
350
|
+ $element->setCountCommentReport($cm->countCommentAlert());
|
|
351
|
+
|
|
352
|
+ $this->getDoctrine()->getEntityManager()->persist($element);
|
|
353
|
+ $this->getDoctrine()->getEntityManager()->flush();
|
|
354
|
+
|
|
355
|
+ return $this->jsonResponse(array(
|
|
356
|
+ 'status' => 'success'
|
|
357
|
+ ));
|
|
358
|
+ }
|
223
|
359
|
}
|