1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the DoyoUserBundle project. |
5
|
|
|
* |
6
|
|
|
* (c) Anthonius Munthi <[email protected]> |
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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Doyo\UserBundle\Bridge\ORM; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
17
|
|
|
use Doyo\UserBundle\Manager\GroupManager as BaseGroupManager; |
18
|
|
|
use Doyo\UserBundle\Model\GroupInterface; |
19
|
|
|
|
20
|
|
|
class GroupManager extends BaseGroupManager |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var ObjectManager |
24
|
|
|
*/ |
25
|
|
|
private $objectManager; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $class; |
31
|
|
|
|
32
|
7 |
|
public function __construct( |
33
|
|
|
ObjectManager $objectManager, |
34
|
|
|
$class |
35
|
|
|
) { |
36
|
7 |
|
$this->objectManager = $objectManager; |
37
|
7 |
|
$this->class = $class; |
38
|
|
|
} |
39
|
|
|
|
40
|
1 |
|
public function deleteGroup(GroupInterface $group) |
41
|
|
|
{ |
42
|
1 |
|
$this->objectManager->remove($group); |
43
|
1 |
|
$this->objectManager->flush(); |
44
|
|
|
} |
45
|
|
|
|
46
|
6 |
|
public function findGroupBy(array $criteria) |
47
|
|
|
{ |
48
|
6 |
|
return $this->getRepository()->findOneBy($criteria); |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
public function findGroups() |
52
|
|
|
{ |
53
|
1 |
|
return $this->getRepository()->findAll(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
8 |
|
public function getClass() |
60
|
|
|
{ |
61
|
8 |
|
if (false !== strpos($this->class, ':')) { |
62
|
1 |
|
$metadata = $this->objectManager->getClassMetadata($this->class); |
63
|
1 |
|
$this->class = $metadata->getName(); |
64
|
|
|
} |
65
|
|
|
|
66
|
8 |
|
return $this->class; |
67
|
|
|
} |
68
|
|
|
|
69
|
5 |
|
public function updateGroup(GroupInterface $group, $andFlush = true) |
70
|
|
|
{ |
71
|
5 |
|
$this->objectManager->persist($group); |
72
|
5 |
|
if ($andFlush) { |
73
|
5 |
|
$this->objectManager->flush(); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
7 |
|
public function getRepository() |
78
|
|
|
{ |
79
|
7 |
|
return $this->objectManager->getRepository($this->getClass()); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|