GroupManager.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Muzich\CoreBundle\Managers;
  3. use Muzich\CoreBundle\Entity\Group;
  4. use Muzich\CoreBundle\Entity\User;
  5. use Doctrine\ORM\EntityManager;
  6. use Symfony\Component\DependencyInjection\Container;
  7. /**
  8. *
  9. *
  10. * @author bux
  11. */
  12. class GroupManager
  13. {
  14. protected $em;
  15. protected $group;
  16. protected $container;
  17. public function __construct(Group $group, EntityManager $em, Container $container)
  18. {
  19. $this->group = $group;
  20. $this->em = $em;
  21. $this->container = $container;
  22. // Slug stuff
  23. $evm = new \Doctrine\Common\EventManager();
  24. // ORM and ODM
  25. $sluggableListener = new \Gedmo\Sluggable\SluggableListener();
  26. $evm->addEventSubscriber($sluggableListener);
  27. // now this event manager should be passed to entity manager constructor
  28. $this->em->getEventManager()->addEventSubscriber($sluggableListener);
  29. }
  30. /**
  31. * Procédure chargé de construire le contenu tags.
  32. *
  33. * @param array $tags_ids
  34. */
  35. public function proceedTags($tags_ids)
  36. {
  37. // La procédure se charge pour le moment des tags
  38. $this->group->setTags(null);
  39. // Il faut supprimer tous les liens vers les tags
  40. foreach ($this->em->getRepository('MuzichCoreBundle:GroupsTagsFavorites')
  41. ->findBy(array(
  42. 'group' => $this->group->getId()
  43. )) as $group_tag)
  44. {
  45. $this->em->remove($group_tag);
  46. }
  47. $this->em->flush();
  48. // Pour etablir les nouveaux liens
  49. $this->group->setTagsWithIds($this->em, $tags_ids);
  50. $this->em->flush();
  51. }
  52. }