|
@@ -13,8 +13,8 @@ use Muzich\CoreBundle\Entity\Element;
|
13
|
13
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
14
|
14
|
use Muzich\CoreBundle\Form\Search\ElementSearchForm;
|
15
|
15
|
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
16
|
|
-use Muzich\CoreBundle\Util\StrictCanonicalizer;
|
17
|
16
|
use Muzich\CoreBundle\Entity\Tag;
|
|
17
|
+use Muzich\CoreBundle\Managers\TagManager;
|
18
|
18
|
|
19
|
19
|
class CoreController extends Controller
|
20
|
20
|
{
|
|
@@ -370,69 +370,14 @@ class CoreController extends Controller
|
370
|
370
|
}
|
371
|
371
|
}
|
372
|
372
|
|
373
|
|
- $canonicalizer = new StrictCanonicalizer();
|
374
|
|
- $name_canonicalized = $canonicalizer->canonicalize($name);
|
|
373
|
+ $tagManager = new TagManager();
|
|
374
|
+ $tag = $tagManager->addTag($this->getDoctrine(), $name, $this->getUser(), $arguments);
|
375
|
375
|
|
376
|
|
- // Check avant de commencer: On regarde si ce tag n'existe pas déjà en tag
|
377
|
|
- // public (en cas de gruge)
|
378
|
|
- if (($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')
|
379
|
|
- ->findOneBy(array(
|
380
|
|
- 'slug' => $name_canonicalized,
|
381
|
|
- 'tomoderate' => false
|
382
|
|
- ))))
|
383
|
|
- {
|
384
|
|
- // Si il existe déjà pas besoin de l'ajouter on retourne l'id et ne nom
|
385
|
|
- return $this->jsonResponse(array(
|
386
|
|
- 'status' => 'success',
|
387
|
|
- 'tag_id' => $tag->getId(),
|
388
|
|
- 'tag_name' => $tag->getName()
|
389
|
|
- ));
|
390
|
|
- }
|
391
|
|
-
|
392
|
|
- // Première étape, on regarde en base si quelqu'un a pas déjà ajouté ce tag
|
393
|
|
- if (($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')
|
394
|
|
- ->findOneBy(array(
|
395
|
|
- 'slug' => $name_canonicalized,
|
396
|
|
- 'tomoderate' => true
|
397
|
|
- ))))
|
398
|
|
- {
|
399
|
|
- // Si il existe déjà pas besoin de l'ajouter on retourne l'id et ne nom
|
400
|
|
- // après avoir ajouté cet utilisateurs a la liste de ceux pouvant le voir
|
401
|
|
- $privatesids = json_decode($tag->getPrivateids());
|
402
|
|
- if (!in_array($this->getUserId(), $privatesids))
|
403
|
|
- {
|
404
|
|
- $privatesids[] = (string)$this->getUserId();
|
405
|
|
- }
|
406
|
|
- $tag->setPrivateids(json_encode($privatesids));
|
407
|
|
- $tag->setArguments($tag->getArguments(). " ****" . $this->getUser()->getName()."****: " .$arguments);
|
408
|
|
-
|
409
|
|
- $this->getDoctrine()->getEntityManager()->persist($tag);
|
410
|
|
- $this->getDoctrine()->getEntityManager()->flush();
|
411
|
|
-
|
412
|
|
- return $this->jsonResponse(array(
|
413
|
|
- 'status' => 'success',
|
414
|
|
- 'tag_id' => $tag->getId(),
|
415
|
|
- 'tag_name' => $tag->getName()
|
416
|
|
- ));
|
417
|
|
- }
|
418
|
|
- else
|
419
|
|
- {
|
420
|
|
- // Sinon on l'ajoute en base
|
421
|
|
- $tag = new Tag();
|
422
|
|
- $tag->setName(ucfirst(strtolower($name)));
|
423
|
|
- $tag->setTomoderate(true);
|
424
|
|
- $tag->setPrivateids(json_encode(array((string)$this->getUserId())));
|
425
|
|
- $tag->setArguments(" ****" . $this->getUser()->getName()."****: " .$arguments);
|
426
|
|
-
|
427
|
|
- $this->getDoctrine()->getEntityManager()->persist($tag);
|
428
|
|
- $this->getDoctrine()->getEntityManager()->flush();
|
429
|
|
-
|
430
|
|
- return $this->jsonResponse(array(
|
431
|
|
- 'status' => 'success',
|
432
|
|
- 'tag_id' => $tag->getId(),
|
433
|
|
- 'tag_name' => $tag->getName()
|
434
|
|
- ));
|
435
|
|
- }
|
|
376
|
+ return $this->jsonResponse(array(
|
|
377
|
+ 'status' => 'success',
|
|
378
|
+ 'tag_id' => $tag->getId(),
|
|
379
|
+ 'tag_name' => $tag->getName()
|
|
380
|
+ ));
|
436
|
381
|
}
|
437
|
382
|
|
438
|
383
|
}
|