forked from FriendsOfSymfony/FOSUserBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroupManager.php
79 lines (68 loc) · 1.68 KB
/
GroupManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?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\Document;
use FOS\UserBundle\Model\GroupInterface;
use Doctrine\ODM\MongoDB\DocumentManager;
use FOS\UserBundle\Model\GroupManager as BaseGroupManager;
class GroupManager extends BaseGroupManager
{
protected $dm;
protected $class;
protected $repository;
public function __construct(DocumentManager $dm, $class)
{
$this->dm = $dm;
$this->repository = $dm->getRepository($class);
$metadata = $dm->getClassMetadata($class);
$this->class = $metadata->name;
}
/**
* {@inheritDoc}
*/
public function deleteGroup(GroupInterface $group)
{
$this->dm->remove($group);
$this->dm->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)
*/
public function updateGroup(GroupInterface $group, $andFlush = true)
{
$this->dm->persist($group);
if ($andFlush) {
$this->dm->flush();
}
}
}