GroupManager.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\Propel;
  11. use FOS\UserBundle\Model\GroupInterface;
  12. use FOS\UserBundle\Model\GroupManager as BaseGroupManager;
  13. class GroupManager extends BaseGroupManager
  14. {
  15. protected $class;
  16. public function __construct($class)
  17. {
  18. $this->class = $class;
  19. }
  20. /**
  21. * {@inheritDoc}
  22. */
  23. public function createGroup($name)
  24. {
  25. $class = $this->class;
  26. $group = new $class();
  27. $group->setName($name);
  28. return $group;
  29. }
  30. /**
  31. * {@inheritDoc}
  32. */
  33. public function deleteGroup(GroupInterface $group)
  34. {
  35. if (!$group instanceof \Persistent) {
  36. throw new \InvalidArgumentException('This group instance is not supported by the Propel GroupManager implementation');
  37. }
  38. $group->delete();
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. public function getClass()
  44. {
  45. return $this->class;
  46. }
  47. /**
  48. * {@inheritDoc}
  49. */
  50. public function findGroupBy(array $criteria)
  51. {
  52. $query = $this->createQuery();
  53. foreach ($criteria as $field => $value) {
  54. $method = 'filterBy'.ucfirst($field);
  55. $query->$method($value);
  56. }
  57. return $query->findOne();
  58. }
  59. /**
  60. * {@inheritDoc}
  61. */
  62. public function findGroups()
  63. {
  64. return $this->createQuery()->find();
  65. }
  66. /**
  67. * {@inheritDoc}
  68. */
  69. public function updateGroup(GroupInterface $group)
  70. {
  71. if (!$group instanceof \Persistent) {
  72. throw new \InvalidArgumentException('This group instance is not supported by the Propel GroupManager implementation');
  73. }
  74. $group->save();
  75. }
  76. /**
  77. * Create the propel query class corresponding to your queryclass
  78. *
  79. * @return \ModelCriteria the queryClass
  80. */
  81. protected function createQuery()
  82. {
  83. return \PropelQuery::from($this->class);
  84. }
  85. }