|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Sulu. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) MASSIVE ART WebServices GmbH |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sulu\Bundle\ArticleBundle\Teaser; |
|
13
|
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchBundle\Service\Manager; |
|
15
|
|
|
use ONGR\ElasticsearchDSL\Query\TermLevel\IdsQuery; |
|
16
|
|
|
use Sulu\Bundle\ArticleBundle\Document\ArticleViewDocument; |
|
17
|
|
|
use Sulu\Bundle\ArticleBundle\Metadata\ArticleViewDocumentIdTrait; |
|
18
|
|
|
use Sulu\Bundle\ContentBundle\Teaser\Configuration\TeaserConfiguration; |
|
19
|
|
|
use Sulu\Bundle\ContentBundle\Teaser\Provider\TeaserProviderInterface; |
|
20
|
|
|
use Sulu\Bundle\ContentBundle\Teaser\Teaser; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Enables selection of articles in teaser content-type. |
|
24
|
|
|
*/ |
|
25
|
|
|
class ArticleTeaserProvider implements TeaserProviderInterface |
|
26
|
|
|
{ |
|
27
|
|
|
use ArticleViewDocumentIdTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var Manager |
|
31
|
|
|
*/ |
|
32
|
|
|
private $searchManager; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
private $articleDocumentClass; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param Manager $searchManager |
|
41
|
|
|
* @param $articleDocumentClass |
|
42
|
|
|
*/ |
|
43
|
2 |
|
public function __construct(Manager $searchManager, $articleDocumentClass) |
|
44
|
|
|
{ |
|
45
|
2 |
|
$this->searchManager = $searchManager; |
|
46
|
2 |
|
$this->articleDocumentClass = $articleDocumentClass; |
|
47
|
2 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getConfiguration() |
|
53
|
|
|
{ |
|
54
|
|
|
return new TeaserConfiguration( |
|
55
|
|
|
'sulu_article.teaser', |
|
56
|
|
|
'teaser-selection/list@suluarticle', |
|
57
|
|
|
[ |
|
58
|
|
|
'url' => '/admin/api/articles?locale={locale}', |
|
59
|
|
|
'resultKey' => 'articles', |
|
60
|
|
|
'searchFields' => ['title', 'route_path', 'changer_full_name', 'creator_full_name', 'pages.title'], |
|
61
|
|
|
], |
|
62
|
|
|
[ |
|
|
|
|
|
|
63
|
|
|
[ |
|
64
|
|
|
'title' => 'Test 1', |
|
65
|
|
|
'cssClass' => 'authored-slide', |
|
66
|
|
|
'contentSpacing' => true, |
|
67
|
|
|
'buttons' => [ |
|
68
|
|
|
[ |
|
69
|
|
|
'type' => 'ok', |
|
70
|
|
|
'align' => 'right', |
|
71
|
|
|
], |
|
72
|
|
|
], |
|
73
|
|
|
], |
|
74
|
|
|
] |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
2 |
|
* {@inheritdoc} |
|
80
|
|
|
*/ |
|
81
|
2 |
|
public function find(array $ids, $locale) |
|
82
|
|
|
{ |
|
83
|
|
|
if (0 === count($ids)) { |
|
84
|
|
|
return []; |
|
85
|
2 |
|
} |
|
86
|
|
|
|
|
87
|
2 |
|
$articleIds = $this->getViewDocumentIds($ids, $locale); |
|
88
|
2 |
|
|
|
89
|
2 |
|
$repository = $this->searchManager->getRepository($this->articleDocumentClass); |
|
90
|
|
|
$search = $repository->createSearch(); |
|
91
|
2 |
|
$search->addQuery(new IdsQuery($articleIds)); |
|
92
|
2 |
|
|
|
93
|
2 |
|
$result = []; |
|
94
|
2 |
|
foreach ($repository->findDocuments($search) as $item) { |
|
95
|
2 |
|
$excerpt = $item->getExcerpt(); |
|
96
|
2 |
|
$result[] = new Teaser( |
|
97
|
2 |
|
$item->getUuid(), |
|
98
|
2 |
|
'article', |
|
99
|
2 |
|
$item->getLocale(), |
|
100
|
2 |
|
('' !== $excerpt->title ? $excerpt->title : $item->getTitle()), |
|
101
|
2 |
|
('' !== $excerpt->description ? $excerpt->description : $item->getTeaserDescription()), |
|
102
|
2 |
|
$excerpt->more, |
|
103
|
2 |
|
$item->getRoutePath(), |
|
104
|
|
|
count($excerpt->images) ? $excerpt->images[0]->id : $item->getTeaserMediaId(), |
|
105
|
|
|
$this->getAttributes($item) |
|
|
|
|
|
|
106
|
|
|
); |
|
107
|
2 |
|
} |
|
108
|
|
|
|
|
109
|
|
|
return $result; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Returns attributes for teaser. |
|
114
|
|
|
* |
|
115
|
|
|
* @param ArticleViewDocument $viewDocument |
|
116
|
|
|
* |
|
117
|
2 |
|
* @return array |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function getAttributes(ArticleViewDocument $viewDocument) |
|
120
|
2 |
|
{ |
|
121
|
2 |
|
return [ |
|
122
|
|
|
'structureType' => $viewDocument->getStructureType(), |
|
123
|
|
|
'type' => $viewDocument->getType(), |
|
124
|
|
|
]; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.