vendor/bundles/FOS/UserBundle/Entity/GroupManager.php
changeset 3 e54dfe4d0b2b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/bundles/FOS/UserBundle/Entity/GroupManager.php	Fri Sep 30 11:24:53 2011 +0200
@@ -0,0 +1,80 @@
+<?php
+
+/*
+ * This file is part of the FOSUserBundle package.
+ *
+ * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace FOS\UserBundle\Entity;
+
+use FOS\UserBundle\Model\GroupInterface;
+use Doctrine\ORM\EntityManager;
+use FOS\UserBundle\Model\GroupManager as BaseGroupManager;
+
+class GroupManager extends BaseGroupManager
+{
+    protected $em;
+    protected $class;
+    protected $repository;
+
+    public function __construct(EntityManager $em, $class)
+    {
+        $this->em = $em;
+        $this->repository = $em->getRepository($class);
+
+        $metadata = $em->getClassMetadata($class);
+        $this->class = $metadata->name;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function deleteGroup(GroupInterface $group)
+    {
+        $this->em->remove($group);
+        $this->em->flush();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function getClass()
+    {
+        return $this->class;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function findGroupBy(array $criteria)
+    {
+        return $this->repository->findOneBy($criteria);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function findGroups()
+    {
+        return $this->repository->findAll();
+    }
+
+    /**
+     * Updates a group
+     *
+     * @param GroupInterface $group
+     * @param Boolean $andFlush Whether to flush the changes (default true)
+     * @return void
+     */
+    public function updateGroup(GroupInterface $group, $andFlush = true)
+    {
+        $this->em->persist($group);
+        if ($andFlush) {
+            $this->em->flush();
+        }
+    }
+}