Passed
Push — master ( 3ec415...9f2f47 )
by Daniel
16:25
created

AbstractPageDataRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 41
ccs 0
cts 25
cp 0
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A findByComponent() 0 31 1
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[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 Silverback\ApiComponentsBundle\Repository\Core;
15
16
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
17
use Doctrine\ORM\Query\Expr\Join;
18
use Doctrine\Persistence\ManagerRegistry;
19
use Silverback\ApiComponentsBundle\Entity\Core\AbstractComponent;
20
use Silverback\ApiComponentsBundle\Entity\Core\AbstractPageData;
21
22
/**
23
 * @author Daniel West <[email protected]>
24
 *
25
 * @method AbstractPageData|null find($id, $lockMode = null, $lockVersion = null)
26
 * @method AbstractPageData|null findOneBy(array $criteria, array $orderBy = null)
27
 * @method AbstractPageData[]    findAll()
28
 * @method AbstractPageData[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
29
 */
30
class AbstractPageDataRepository extends ServiceEntityRepository
31
{
32
    public function __construct(ManagerRegistry $registry)
33
    {
34
        parent::__construct($registry, AbstractPageData::class);
35
    }
36
37
    /**
38
     * @return AbstractPageData[]
39
     */
40
    public function findByComponent(AbstractComponent $component): array
41
    {
42
        $queryBuilder = $this->createQueryBuilder('pageData');
43
        $queryBuilder
44
            ->leftJoin(
45
                'pageData.page',
46
                'pageData_page',
47
                Join::WITH,
48
                $queryBuilder->expr()->eq('pageData_page', 'pageData.page')
49
            )
50
            ->leftJoin(
51
                'pageData_page.componentCollections',
52
                'page_data_cc'
53
            )
54
            ->leftJoin(
55
                'page_data_cc.componentPositions',
56
                'page_data_pos'
57
            )
58
            ->leftJoin(
59
                'page_data_pos.component',
60
                'page_data_component',
61
                Join::WITH,
62
                $queryBuilder->expr()->eq('page_data_pos.component', 'page_data_component')
63
            )
64
65
            ->andWhere(
66
                $queryBuilder->expr()->eq('page_data_component', ':component')
67
            )
68
            ->setParameter('component', $component);
69
70
        return $queryBuilder->getQuery()->getResult();
71
    }
72
}
73