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