1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher Content Bundle. |
7
|
|
|
* |
8
|
|
|
* Copyright 2016 Sourcefabric z.ú. and contributors. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please see the |
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* @copyright 2016 Sourcefabric z.ú |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace SWP\Bundle\ContentBundle\Provider\ODM\PHPCR; |
18
|
|
|
|
19
|
|
|
use Jackalope\Query\SqlQuery; |
20
|
|
|
use SWP\Bundle\ContentBundle\Doctrine\ArticleRepositoryInterface; |
21
|
|
|
use SWP\Bundle\ContentBundle\Provider\ArticleProviderInterface; |
22
|
|
|
use SWP\Component\MultiTenancy\PathBuilder\TenantAwarePathBuilderInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* ArticleProvider to provide articles based on PHPCR paths. |
26
|
|
|
*/ |
27
|
|
|
class ArticleProvider implements ArticleProviderInterface |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var ArticleRepositoryInterface |
31
|
|
|
*/ |
32
|
|
|
private $articleRepository; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var TenantAwarePathBuilderInterface |
36
|
|
|
*/ |
37
|
|
|
private $pathBuilder; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $basePath; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* ArticleProvider constructor. |
46
|
|
|
* |
47
|
|
|
* @param ArticleRepositoryInterface $articleRepository |
48
|
|
|
* @param TenantAwarePathBuilderInterface $pathBuilder |
49
|
|
|
* @param string $basePath |
50
|
|
|
*/ |
51
|
|
|
public function __construct( |
52
|
|
|
ArticleRepositoryInterface $articleRepository, |
53
|
|
|
TenantAwarePathBuilderInterface $pathBuilder, |
54
|
|
|
string $basePath |
55
|
|
|
) { |
56
|
|
|
$this->articleRepository = $articleRepository; |
57
|
|
|
$this->pathBuilder = $pathBuilder; |
58
|
|
|
$this->basePath = $basePath; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function getBaseNode() |
65
|
|
|
{ |
66
|
|
|
return $this->articleRepository->findBaseNode($this->pathBuilder->build($this->basePath)); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
|
View Code Duplication |
public function getOneById($id) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
if (!filter_var($id, FILTER_VALIDATE_INT)) { |
75
|
|
|
return $this->articleRepository->findOneBySlug($id); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $this->articleRepository->findOneBy(['id' => $id]); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function getParent($id) |
85
|
|
|
{ |
86
|
|
|
return $this->articleRepository->find($this->pathBuilder->build($id)); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function getTenantArticlesQuery(string $tenantContentIdentifier, array $order) : SqlQuery |
93
|
|
|
{ |
94
|
|
|
return $this->articleRepository->getQueryForTenantArticles($tenantContentIdentifier, $order); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
|
|
public function getRouteArticlesQuery(string $routeIdentifier, array $order) : SqlQuery |
101
|
|
|
{ |
102
|
|
|
return $this->articleRepository->getQueryForRouteArticles($routeIdentifier, $order); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|