GroupManager.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * This file is part of the FOSUserBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace FOS\UserBundle\Doctrine;
  11. use Doctrine\Common\Persistence\ObjectManager;
  12. use FOS\UserBundle\Model\GroupInterface;
  13. use FOS\UserBundle\Model\GroupManager as BaseGroupManager;
  14. class GroupManager extends BaseGroupManager
  15. {
  16. protected $objectManager;
  17. protected $class;
  18. protected $repository;
  19. public function __construct(ObjectManager $om, $class)
  20. {
  21. $this->objectManager = $om;
  22. $this->repository = $om->getRepository($class);
  23. $metadata = $om->getClassMetadata($class);
  24. $this->class = $metadata->getName();
  25. }
  26. /**
  27. * {@inheritDoc}
  28. */
  29. public function deleteGroup(GroupInterface $group)
  30. {
  31. $this->objectManager->remove($group);
  32. $this->objectManager->flush();
  33. }
  34. /**
  35. * {@inheritDoc}
  36. */
  37. public function getClass()
  38. {
  39. return $this->class;
  40. }
  41. /**
  42. * {@inheritDoc}
  43. */
  44. public function findGroupBy(array $criteria)
  45. {
  46. return $this->repository->findOneBy($criteria);
  47. }
  48. /**
  49. * {@inheritDoc}
  50. */
  51. public function findGroups()
  52. {
  53. return $this->repository->findAll();
  54. }
  55. /**
  56. * Updates a group
  57. *
  58. * @param GroupInterface $group
  59. * @param Boolean $andFlush Whether to flush the changes (default true)
  60. */
  61. public function updateGroup(GroupInterface $group, $andFlush = true)
  62. {
  63. $this->objectManager->persist($group);
  64. if ($andFlush) {
  65. $this->objectManager->flush();
  66. }
  67. }
  68. }