|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Fab\Vidi\Facet; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Fab/Vidi project under GPLv2 or later. |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please read the |
|
9
|
|
|
* LICENSE.md file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
use Fab\Vidi\Module\ModuleLoader; |
|
13
|
|
|
use Fab\Vidi\Persistence\Matcher; |
|
14
|
|
|
use Fab\Vidi\Utility\BackendUtility; |
|
15
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
16
|
|
|
use TYPO3\CMS\Core\Database\Query\QueryBuilder; |
|
17
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
18
|
|
|
use TYPO3\CMS\Lang\LanguageService; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class for configuring a custom Facet item. |
|
22
|
|
|
*/ |
|
23
|
|
|
class PageFacet implements FacetInterface |
|
24
|
|
|
{ |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $name; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $label; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $dataType; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var bool |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $canModifyMatcher = false; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Constructor of a Generic Facet in Vidi. |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $name |
|
50
|
|
|
* @param string $label |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct($name, $label = '') |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
$this->name = 'pid'; |
|
55
|
|
|
$this->label = $label; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getName(): string |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->name; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getLabel(): string |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->label; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return array |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getSuggestions(): array |
|
78
|
|
|
{ |
|
79
|
|
|
$values = []; |
|
80
|
|
|
foreach ($this->getStoragePages() as $page) { |
|
81
|
|
|
$values[] = [ |
|
82
|
|
|
$page['uid'] => sprintf('%s (%s)', $page['title'], $page['uid']) |
|
83
|
|
|
]; |
|
84
|
|
|
} |
|
85
|
|
|
return $values; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function getStoragePages(): array |
|
92
|
|
|
{ |
|
93
|
|
|
/** @var QueryBuilder $query */ |
|
94
|
|
|
$query = $this->getQueryBuilder('pages'); |
|
95
|
|
|
$query->getRestrictions()->removeAll(); |
|
96
|
|
|
return $query->select('*') |
|
97
|
|
|
->from('pages') |
|
98
|
|
|
->where( |
|
99
|
|
|
sprintf( |
|
100
|
|
|
'uid IN (SELECT DISTINCT(pid) FROM %s WHERE 1=1 %s)', |
|
101
|
|
|
$this->getModuleLoader()->getDataType(), |
|
102
|
|
|
BackendUtility::deleteClause($this->getModuleLoader()->getDataType() |
|
103
|
|
|
) |
|
104
|
|
|
), |
|
105
|
|
|
BackendUtility::deleteClause('pages', '') |
|
106
|
|
|
) |
|
107
|
|
|
->execute() |
|
108
|
|
|
->fetchAll(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param string $tableName |
|
113
|
|
|
* @return object|QueryBuilder |
|
114
|
|
|
*/ |
|
115
|
|
|
protected function getQueryBuilder($tableName): QueryBuilder |
|
116
|
|
|
{ |
|
117
|
|
|
/** @var ConnectionPool $connectionPool */ |
|
118
|
|
|
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
119
|
|
|
return $connectionPool->getQueryBuilderForTable($tableName); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Returns a pointer to the database. |
|
124
|
|
|
* |
|
125
|
|
|
* @return \Fab\Vidi\Database\DatabaseConnection |
|
126
|
|
|
*/ |
|
127
|
|
|
protected function getDatabaseConnection() |
|
128
|
|
|
{ |
|
129
|
|
|
return $GLOBALS['TYPO3_DB']; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @return LanguageService |
|
134
|
|
|
*/ |
|
135
|
|
View Code Duplication |
protected function getLanguageService(): LanguageService |
|
|
|
|
|
|
136
|
|
|
{ |
|
137
|
|
|
|
|
138
|
|
|
/** @var LanguageService $langService */ |
|
139
|
|
|
$langService = $GLOBALS['LANG']; |
|
140
|
|
|
if (!$langService) { |
|
141
|
|
|
$langService = GeneralUtility::makeInstance(LanguageService::class); |
|
142
|
|
|
$langService->init('en'); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
return $langService; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @return bool |
|
150
|
|
|
*/ |
|
151
|
|
|
public function hasSuggestions(): bool |
|
152
|
|
|
{ |
|
153
|
|
|
return true; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @param string $dataType |
|
158
|
|
|
* @return $this |
|
159
|
|
|
*/ |
|
160
|
|
|
public function setDataType($dataType): self |
|
161
|
|
|
{ |
|
162
|
|
|
$this->dataType = $dataType; |
|
163
|
|
|
return $this; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @return bool |
|
168
|
|
|
*/ |
|
169
|
|
|
public function canModifyMatcher(): bool |
|
170
|
|
|
{ |
|
171
|
|
|
return $this->canModifyMatcher; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @param Matcher $matcher |
|
176
|
|
|
* @param $value |
|
177
|
|
|
* @return Matcher |
|
178
|
|
|
*/ |
|
179
|
|
|
public function modifyMatcher(Matcher $matcher, $value): Matcher |
|
180
|
|
|
{ |
|
181
|
|
|
return $matcher; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Get the Vidi Module Loader. |
|
186
|
|
|
* |
|
187
|
|
|
* @return ModuleLoader|object |
|
188
|
|
|
* @throws \InvalidArgumentException |
|
189
|
|
|
*/ |
|
190
|
|
|
protected function getModuleLoader() |
|
191
|
|
|
{ |
|
192
|
|
|
return GeneralUtility::makeInstance(ModuleLoader::class); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
} |
|
196
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.