1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Superdesk Web Publisher Core Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 Sourcefabric z.ú. 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 2016 Sourcefabric z.ú |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace SWP\Bundle\CoreBundle\Provider; |
16
|
|
|
|
17
|
|
|
use Doctrine\ORM\Query; |
18
|
|
|
use SWP\Component\Revision\Context\RevisionContext; |
19
|
|
|
use SWP\Bundle\TemplatesSystemBundle\Provider\ContainerProvider as BaseContentProvider; |
20
|
|
|
use SWP\Component\Common\Criteria\Criteria; |
21
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Model\ContainerInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Revisions Aware ContainerProvider. |
25
|
|
|
*/ |
26
|
|
|
class ContainerProvider extends BaseContentProvider |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var RevisionContext |
30
|
|
|
*/ |
31
|
|
|
protected $revisionContext; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function getQueryForAll(): Query |
37
|
|
|
{ |
38
|
|
|
$criteria = new Criteria(); |
39
|
|
|
$criteria->set('revision', $this->revisionContext->getCurrentRevision()); |
40
|
|
|
|
41
|
|
|
return $this->containerRepository->getQueryByCriteria($criteria, [], 'r')->getQuery(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function getOneByName(string $name) |
48
|
|
|
{ |
49
|
|
|
$qb = $this->containerRepository->getByName($name); |
50
|
|
|
$qb->andWhere('c.revision = :revision') |
51
|
|
|
->setParameter('revision', $this->revisionContext->getCurrentRevision()); |
52
|
|
|
|
53
|
|
|
return $qb->getQuery()->getOneOrNullResult(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function getOneById($uuid) |
60
|
|
|
{ |
61
|
|
|
$qb = $this->containerRepository->createQueryBuilder('c') |
62
|
|
|
->andWhere('c.revision = :revision') |
63
|
|
|
->andWhere('c.uuid = :uuid') |
64
|
|
|
->setParameters([ |
65
|
|
|
'revision' => $this->revisionContext->getCurrentRevision(), |
66
|
|
|
'uuid' => $uuid, |
67
|
|
|
]); |
68
|
|
|
|
69
|
|
|
return $qb->getQuery()->getOneOrNullResult(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
|
|
public function getContainerWidgets(ContainerInterface $container): array |
76
|
|
|
{ |
77
|
|
|
return $this->containerWidgetRepository |
78
|
|
|
->getSortedWidgets(['container' => $container]) |
79
|
|
|
->getQuery() |
80
|
|
|
->getResult(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param RevisionContext $revisionContext |
85
|
|
|
*/ |
86
|
|
|
public function setRevisionContext(RevisionContext $revisionContext) |
87
|
|
|
{ |
88
|
|
|
$this->revisionContext = $revisionContext; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|