Completed
Push — master ( 3d485f...407dff )
by Paweł
66:49
created

RevisionAwareContainerRepository::getIds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2016 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2016 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\Repository;
18
19
use Doctrine\ORM\QueryBuilder;
20
use SWP\Bundle\TemplatesSystemBundle\Repository\ContainerRepository;
21
use SWP\Component\Common\Criteria\Criteria;
22
use SWP\Component\Revision\Model\RevisionInterface;
23
24
class RevisionAwareContainerRepository extends ContainerRepository implements RevisionAwareContainerRepositoryInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function getIds(RevisionInterface $revision): QueryBuilder
30
    {
31
        return $this->createQueryBuilder('c')
32
            ->select('c.uuid')
33
            ->where('c.revision = :revision')
34
            ->setParameter('revision', $revision);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getContainerWithoutProvidedIds(array $ids, RevisionInterface $revision): QueryBuilder
41
    {
42
        $criteria = new Criteria();
43
        $criteria->set('revision', $revision->getPrevious());
44
        $qb = $this->getQueryByCriteria($criteria, [], 'c');
45
        if (count($ids) > 0) {
46
            $qb->andWhere('c.uuid NOT IN (:ids)')->setParameter('ids', $ids);
47
        }
48
49
        return $qb;
50
    }
51
}
52