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

ContainerProvider::getOneByName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Template Engine Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\TemplatesSystemBundle\Provider;
16
17
use Doctrine\ORM\Query;
18
use SWP\Bundle\TemplatesSystemBundle\Repository\ContainerRepository;
19
use SWP\Bundle\TemplatesSystemBundle\Repository\ContainerWidgetRepository;
20
use SWP\Component\Common\Criteria\Criteria;
21
use SWP\Component\TemplatesSystem\Gimme\Model\ContainerInterface;
22
23
/**
24
 * Class ContainerProvider.
25
 */
26
class ContainerProvider implements ContainerProviderInterface
27
{
28
    /**
29
     * @var ContainerRepository
30
     */
31
    protected $containerRepository;
32
33
    /**
34
     * @var ContainerWidgetRepository
35
     */
36
    protected $containerWidgetRepository;
37
38
    /**
39
     * ContainerProvider constructor.
40
     *
41
     * @param ContainerRepository       $containerRepository
42
     * @param ContainerWidgetRepository $containerWidgetRepository
43
     */
44
    public function __construct(ContainerRepository $containerRepository, ContainerWidgetRepository $containerWidgetRepository)
45
    {
46
        $this->containerRepository = $containerRepository;
47
        $this->containerWidgetRepository = $containerWidgetRepository;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getQueryForAll(): Query
54
    {
55
        return $this->containerRepository->getAll();
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getOneByCriteria(Criteria $criteria)
62
    {
63
        return $this->containerRepository->getQueryByCriteria($criteria, [], 'c')->getQuery()->getOneOrNullResult();
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getOneByName(string $name)
70
    {
71
        return $this->containerRepository->getByName($name)->getQuery()->getOneOrNullResult();
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getOneById($id)
78
    {
79
        return $this->containerRepository->getById($id)->getQuery()->getOneOrNullResult();
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function getContainerWidgets(ContainerInterface $container): array
86
    {
87
        return $this->containerWidgetRepository
88
            ->getSortedWidgets(['container' => $container])
89
            ->getQuery()
90
            ->getResult();
91
    }
92
}
93