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\Loader; |
16
|
|
|
|
17
|
|
|
use SWP\Bundle\ContentBundle\Loader\PaginatedLoader; |
18
|
|
|
use SWP\Component\Common\Criteria\Criteria; |
19
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Context\Context; |
20
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Factory\MetaFactory; |
21
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Loader\LoaderInterface; |
22
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Meta\Meta; |
23
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Meta\MetaCollection; |
24
|
|
|
|
25
|
|
|
class PreviewArticleMediaLoader extends PaginatedLoader implements LoaderInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var MetaFactory |
29
|
|
|
*/ |
30
|
|
|
protected $metaFactory; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var Context |
34
|
|
|
*/ |
35
|
|
|
protected $context; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* ArticleMediaLoader constructor. |
39
|
|
|
* |
40
|
|
|
* @param MetaFactory $metaFactory |
41
|
|
|
* @param Context $context |
42
|
|
|
*/ |
43
|
|
|
public function __construct(MetaFactory $metaFactory, Context $context) |
44
|
|
|
{ |
45
|
|
|
$this->metaFactory = $metaFactory; |
46
|
|
|
$this->context = $context; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function load($metaType, $withParameters = [], $withoutParameters = [], $responseType = self::SINGLE) |
53
|
|
|
{ |
54
|
|
|
if (LoaderInterface::COLLECTION === $responseType) { |
55
|
|
|
$criteria = new Criteria(); |
56
|
|
|
if (array_key_exists('article', $withParameters) && $withParameters['article'] instanceof Meta) { |
57
|
|
|
$article = $withParameters['article']->getValues(); |
58
|
|
View Code Duplication |
} elseif (isset($this->context->article) && null !== $this->context->article) { |
|
|
|
|
59
|
|
|
$article = $this->context->article->getValues(); |
60
|
|
|
} else { |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$criteria = $this->applyPaginationToCriteria($criteria, $withParameters); |
65
|
|
|
$articleMedia = $article->getMedia(); |
66
|
|
|
if (0 < count($articleMedia)) { |
67
|
|
|
$collectionCriteria = new \Doctrine\Common\Collections\Criteria( |
68
|
|
|
null, |
69
|
|
|
$criteria->get('order'), |
70
|
|
|
$criteria->get('firstResult'), |
71
|
|
|
$criteria->get('maxResults') |
72
|
|
|
); |
73
|
|
|
$count = $articleMedia->count(); |
74
|
|
|
$articleMedia = $articleMedia->matching($collectionCriteria); |
75
|
|
|
|
76
|
|
|
$metaCollection = new MetaCollection(); |
77
|
|
|
$metaCollection->setTotalItemsCount($count); |
78
|
|
|
foreach ($articleMedia as $media) { |
79
|
|
|
$metaCollection->add($this->metaFactory->create($media)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $metaCollection; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return false; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function isSupported(string $type): bool |
93
|
|
|
{ |
94
|
|
|
return in_array($type, ['articleMedia']) && $this->context->isPreviewMode(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.