|
3
|
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\Document; |
|
|
13 |
|
|
|
14 |
use FOS\UserBundle\Model\GroupInterface; |
|
|
15 |
use Doctrine\ODM\MongoDB\DocumentManager; |
|
|
16 |
use FOS\UserBundle\Model\GroupManager as BaseGroupManager; |
|
|
17 |
|
|
|
18 |
class GroupManager extends BaseGroupManager |
|
|
19 |
{ |
|
|
20 |
protected $dm; |
|
|
21 |
protected $class; |
|
|
22 |
protected $repository; |
|
|
23 |
|
|
|
24 |
public function __construct(DocumentManager $dm, $class) |
|
|
25 |
{ |
|
|
26 |
$this->dm = $dm; |
|
|
27 |
$this->repository = $dm->getRepository($class); |
|
|
28 |
|
|
|
29 |
$metadata = $dm->getClassMetadata($class); |
|
|
30 |
$this->class = $metadata->name; |
|
|
31 |
} |
|
|
32 |
|
|
|
33 |
/** |
|
|
34 |
* {@inheritDoc} |
|
|
35 |
*/ |
|
|
36 |
public function deleteGroup(GroupInterface $group) |
|
|
37 |
{ |
|
|
38 |
$this->dm->remove($group); |
|
|
39 |
$this->dm->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 |
*/ |
|
|
72 |
public function updateGroup(GroupInterface $group, $andFlush = true) |
|
|
73 |
{ |
|
|
74 |
$this->dm->persist($group); |
|
|
75 |
if ($andFlush) { |
|
|
76 |
$this->dm->flush(); |
|
|
77 |
} |
|
|
78 |
} |
|
|
79 |
} |