|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Kreta package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
|
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types=1); |
|
14
|
|
|
|
|
15
|
|
|
namespace Kreta\TaskManager\Infrastructure\Persistence\Doctrine\ORM\Organization; |
|
16
|
|
|
|
|
17
|
|
|
use Doctrine\ORM\EntityRepository; |
|
18
|
|
|
use Kreta\SharedKernel\Domain\Model\Identity\Slug; |
|
19
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\Organization; |
|
20
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\OrganizationId; |
|
21
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\OrganizationRepository; |
|
22
|
|
|
|
|
23
|
|
|
class DoctrineORMOrganizationRepository extends EntityRepository implements OrganizationRepository |
|
24
|
|
|
{ |
|
25
|
|
|
public function organizationOfId(OrganizationId $id) |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->find($id->id()); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function organizationOfSlug(Slug $slug) |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->findOneBy(['slug.slug' => $slug->slug()]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function query($specification) |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
return null === $specification |
|
38
|
|
|
? $this->findAll() |
|
39
|
|
|
: $specification->buildQuery($this->getEntityManager()->createQueryBuilder())->getResult(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function persist(Organization $organization) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->getEntityManager()->persist($organization); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function remove(Organization $organization) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->getEntityManager()->remove($organization); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function count($specification) : int |
|
53
|
|
|
{ |
|
54
|
|
|
if (null === $specification) { |
|
55
|
|
|
$queryBuilder = $this->createQueryBuilder('o'); |
|
56
|
|
|
|
|
57
|
|
|
return (int) $queryBuilder |
|
58
|
|
|
->select($queryBuilder->expr()->count('o.id')) |
|
59
|
|
|
->getQuery() |
|
60
|
|
|
->getSingleScalarResult(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return (int) $specification->buildCount( |
|
64
|
|
|
$this->getEntityManager()->createQueryBuilder() |
|
65
|
|
|
)->getSingleScalarResult(); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.