|
@@ -161,7 +161,7 @@ class CoreController extends Controller
|
161
|
161
|
throw $this->createNotFoundException('Cette ressource n\'est pas accessible');
|
162
|
162
|
}
|
163
|
163
|
|
164
|
|
- $user = $this->getUser();
|
|
164
|
+ $user = $this->getUser(true, array('join' => array('groups_owned_groups_tags')));
|
165
|
165
|
$em = $this->getDoctrine()->getEntityManager();
|
166
|
166
|
|
167
|
167
|
/*
|
|
@@ -235,14 +235,11 @@ class CoreController extends Controller
|
235
|
235
|
'no_group_name' => true
|
236
|
236
|
))->getContent();
|
237
|
237
|
}
|
238
|
|
-
|
239
|
|
-
|
240
|
|
-
|
241
|
|
-
|
242
|
238
|
|
243
|
239
|
return $this->jsonResponse(array(
|
244
|
240
|
'status' => 'success',
|
245
|
|
- 'html' => $html
|
|
241
|
+ 'html' => $html,
|
|
242
|
+ 'groups' => (!$group)?$this->isAddedElementCanBeInGroup($element):array()
|
246
|
243
|
));
|
247
|
244
|
}
|
248
|
245
|
else
|
|
@@ -333,6 +330,40 @@ class CoreController extends Controller
|
333
|
330
|
|
334
|
331
|
}
|
335
|
332
|
|
|
333
|
+ /**
|
|
334
|
+ * Cette méthode vérifie si l'élément qui vient d'être envoyé pourrais être
|
|
335
|
+ * associé a un groupe de l'utilisateur.
|
|
336
|
+ *
|
|
337
|
+ * @param Element $element
|
|
338
|
+ * @return array
|
|
339
|
+ */
|
|
340
|
+ protected function isAddedElementCanBeInGroup(Element $element)
|
|
341
|
+ {
|
|
342
|
+ $element_tags = $element->getTags();
|
|
343
|
+ $groups = array();
|
|
344
|
+ foreach ($this->getUser()->getGroupsOwned() as $group)
|
|
345
|
+ {
|
|
346
|
+ foreach ($element_tags as $element_tag)
|
|
347
|
+ {
|
|
348
|
+ if ($group->hasThisTag($element_tag->getId()))
|
|
349
|
+ {
|
|
350
|
+ $groups[] = array(
|
|
351
|
+ 'name' => $group->getName(),
|
|
352
|
+ 'id' => $group->getId(),
|
|
353
|
+ 'url' => $this->generateUrl('ajax_set_element_group', array(
|
|
354
|
+ 'token' => $this->getUser()->getPersonalHash(),
|
|
355
|
+ 'element_id' => $element->getId(),
|
|
356
|
+ 'group_id' => $group->getId()
|
|
357
|
+ ))
|
|
358
|
+ );
|
|
359
|
+ }
|
|
360
|
+
|
|
361
|
+ }
|
|
362
|
+ }
|
|
363
|
+
|
|
364
|
+ return $groups;
|
|
365
|
+ }
|
|
366
|
+
|
336
|
367
|
public function filterClearAction()
|
337
|
368
|
{
|
338
|
369
|
$es = $this->getElementSearcher();
|
|
@@ -431,4 +462,50 @@ class CoreController extends Controller
|
431
|
462
|
));
|
432
|
463
|
}
|
433
|
464
|
|
|
465
|
+ public function setElementGroupAction($element_id, $group_id, $token)
|
|
466
|
+ {
|
|
467
|
+ if (($response = $this->mustBeConnected(true)))
|
|
468
|
+ {
|
|
469
|
+ return $response;
|
|
470
|
+ }
|
|
471
|
+
|
|
472
|
+ if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
473
|
+ ->findOneById($element_id))
|
|
474
|
+ || !($group = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
|
|
475
|
+ ->findOneById($group_id))
|
|
476
|
+ || $this->getUser()->getPersonalHash() != $token)
|
|
477
|
+ {
|
|
478
|
+ return $this->jsonResponse(array(
|
|
479
|
+ 'status' => 'error',
|
|
480
|
+ 'errors' => array('NotFound')
|
|
481
|
+ ));
|
|
482
|
+ }
|
|
483
|
+
|
|
484
|
+ if ($element->getOwner()->getId() != $this->getUserId()
|
|
485
|
+ || $group->getOwner()->getId() != $this->getUserId()
|
|
486
|
+ )
|
|
487
|
+ {
|
|
488
|
+ return $this->jsonResponse(array(
|
|
489
|
+ 'status' => 'error',
|
|
490
|
+ 'errors' => array('NotAllowed')
|
|
491
|
+ ));
|
|
492
|
+ }
|
|
493
|
+
|
|
494
|
+ // a partir d'ici on a tout ce qu'il faut
|
|
495
|
+ $element->setGroup($group);
|
|
496
|
+ $this->getDoctrine()->getEntityManager()->persist($element);
|
|
497
|
+ $this->getDoctrine()->getEntityManager()->flush();
|
|
498
|
+
|
|
499
|
+ // On récupère le nouveau dom de l'élément
|
|
500
|
+ $html = $this->render('MuzichCoreBundle:SearchElement:element.html.twig', array(
|
|
501
|
+ 'element' => $element
|
|
502
|
+ ))->getContent();
|
|
503
|
+
|
|
504
|
+ return $this->jsonResponse(array(
|
|
505
|
+ 'status' => 'success',
|
|
506
|
+ 'html' => $html,
|
|
507
|
+ 'dom_id' => 'element_'.$element->getId()
|
|
508
|
+ ));
|
|
509
|
+ }
|
|
510
|
+
|
434
|
511
|
}
|