|
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\Project; |
|
16
|
|
|
|
|
17
|
|
|
use Doctrine\ORM\Query; |
|
18
|
|
|
use Doctrine\ORM\Query\Expr\Join; |
|
19
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
20
|
|
|
use Kreta\SharedKernel\Domain\Model\Identity\Slug; |
|
21
|
|
|
use Kreta\SharedKernel\Infrastructure\Persistence\Doctrine\ORM\DoctrineORMQuerySpecification; |
|
22
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\Organization; |
|
23
|
|
|
use Kreta\TaskManager\Domain\Model\Project\Project; |
|
24
|
|
|
|
|
25
|
|
|
class DoctrineORMBySlugSpecification implements DoctrineORMQuerySpecification |
|
26
|
|
|
{ |
|
27
|
|
|
private $slug; |
|
28
|
|
|
private $organizationSlug; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(Slug $slug, Slug $organizationSlug) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->slug = $slug; |
|
33
|
|
|
$this->organizationSlug = $organizationSlug; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function buildQuery(QueryBuilder $queryBuilder) : Query |
|
37
|
|
|
{ |
|
38
|
|
|
return $queryBuilder |
|
39
|
|
|
->select('p') |
|
40
|
|
|
->from(Project::class, 'p') |
|
41
|
|
|
->join(Organization::class, 'o', Join::WITH, 'p.organizationId = o.id') |
|
42
|
|
|
->where($queryBuilder->expr()->eq('p.slug.slug', ':slug')) |
|
43
|
|
|
->andWhere($queryBuilder->expr()->eq('o.slug.slug', ':organizationSlug')) |
|
44
|
|
|
->setParameter('slug', $this->slug->slug()) |
|
45
|
|
|
->setParameter('organizationSlug', $this->organizationSlug->slug()) |
|
46
|
|
|
->getQuery(); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|