|
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\Markup; |
|
13
|
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchBundle\Service\Manager; |
|
15
|
|
|
use ONGR\ElasticsearchDSL\Query\TermLevel\IdsQuery; |
|
16
|
|
|
use ONGR\ElasticsearchDSL\Query\TermLevel\RangeQuery; |
|
17
|
|
|
use ONGR\ElasticsearchDSL\Search; |
|
18
|
|
|
use Sulu\Bundle\ArticleBundle\Document\ArticleViewDocumentInterface; |
|
19
|
|
|
use Sulu\Bundle\ArticleBundle\Document\Index\DocumentFactory; |
|
20
|
|
|
use Sulu\Bundle\ContentBundle\Markup\Link\LinkConfiguration; |
|
21
|
|
|
use Sulu\Bundle\ContentBundle\Markup\Link\LinkItem; |
|
22
|
|
|
use Sulu\Bundle\ContentBundle\Markup\Link\LinkProviderInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Integrates articles into link-system. |
|
26
|
|
|
*/ |
|
27
|
|
|
class ArticleLinkProvider implements LinkProviderInterface |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var Manager |
|
31
|
|
|
*/ |
|
32
|
|
|
private $manager; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var DocumentFactory |
|
36
|
|
|
*/ |
|
37
|
|
|
private $documentFactory; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
private $types; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param Manager $manager |
|
46
|
|
|
* @param DocumentFactory $documentFactory |
|
47
|
|
|
* @param array $types |
|
48
|
|
|
*/ |
|
49
|
31 |
|
public function __construct(Manager $manager, DocumentFactory $documentFactory, array $types) |
|
50
|
|
|
{ |
|
51
|
31 |
|
$this->manager = $manager; |
|
52
|
31 |
|
$this->documentFactory = $documentFactory; |
|
53
|
31 |
|
$this->types = $types; |
|
54
|
31 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getConfiguration() |
|
60
|
|
|
{ |
|
61
|
|
|
$tabs = null; |
|
62
|
|
|
if (1 < count($this->types)) { |
|
63
|
|
|
$tabs = array_map( |
|
64
|
|
|
function ($type) { |
|
65
|
|
|
return ['title' => $type['translation_key']]; |
|
66
|
|
|
}, |
|
67
|
|
|
$this->types |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return new LinkConfiguration( |
|
72
|
|
|
'sulu_article.ckeditor.link', |
|
73
|
|
|
'ckeditor/link/article@suluarticle', |
|
74
|
|
|
[], |
|
75
|
|
|
['tabs' => $tabs] |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritdoc} |
|
81
|
|
|
*/ |
|
82
|
|
|
public function preload(array $hrefs, $locale, $published = true) |
|
83
|
|
|
{ |
|
84
|
|
|
$search = new Search(); |
|
85
|
|
|
$search->addQuery(new IdsQuery($hrefs)); |
|
86
|
|
|
if ($published) { |
|
87
|
|
|
$search->addQuery(new RangeQuery('authored', ['lte' => 'now'])); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$repository = $this->manager->getRepository($this->documentFactory->getClass('article')); |
|
91
|
|
|
$documents = $repository->findDocuments($search); |
|
92
|
|
|
|
|
93
|
|
|
$result = []; |
|
94
|
|
|
/** @var ArticleViewDocumentInterface $document */ |
|
95
|
|
|
foreach ($documents as $document) { |
|
96
|
|
|
$result[] = new LinkItem( |
|
97
|
|
|
$document->getUuid(), |
|
98
|
|
|
$document->getTitle(), |
|
99
|
|
|
$document->getRoutePath(), |
|
100
|
|
|
$document->getAuthored() <= new \DateTime() |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return $result; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|