|
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 TYPO3\CMS\Backend\Utility\BackendUtility; |
|
15
|
|
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
|
16
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
17
|
|
|
use TYPO3\CMS\Lang\LanguageService; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class for configuring a custom Facet item. |
|
21
|
|
|
*/ |
|
22
|
|
|
class PageFacet implements FacetInterface |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $name; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $label; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var bool |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $canModifyMatcher = false; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Constructor of a Generic Facet in Vidi. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $label |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct($label = '') |
|
46
|
|
|
{ |
|
47
|
|
|
$this->name = 'pid'; |
|
48
|
|
|
$this->label = $label; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getName() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->name; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getLabel() |
|
63
|
|
|
{ |
|
64
|
|
|
$label = ''; |
|
65
|
|
|
try { |
|
66
|
|
|
$label = LocalizationUtility::translate($this->label, ''); |
|
67
|
|
|
} catch (\InvalidArgumentException $e) { |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $label; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return array |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getSuggestions() |
|
77
|
|
|
{ |
|
78
|
|
|
$values = []; |
|
79
|
|
|
foreach ($this->getStoragePages() as $page) { |
|
80
|
|
|
$values[] = [ |
|
81
|
|
|
$page['uid'] => sprintf('%s (%s)', $page['title'], $page['uid']) |
|
82
|
|
|
]; |
|
83
|
|
|
} |
|
84
|
|
|
return $values; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return array |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function getStoragePages() |
|
91
|
|
|
{ |
|
92
|
|
|
$tableName = 'pages'; |
|
93
|
|
|
$clause = sprintf( |
|
94
|
|
|
'uid IN (SELECT DISTINCT(pid) FROM %s WHERE 1=1 %s)', |
|
95
|
|
|
$this->getModuleLoader()->getDataType(), |
|
96
|
|
|
BackendUtility::deleteClause($this->getModuleLoader()->getDataType()) |
|
97
|
|
|
); |
|
98
|
|
|
$clause .= BackendUtility::deleteClause('pages'); |
|
99
|
|
|
|
|
100
|
|
|
$pages = $this->getDatabaseConnection()->exec_SELECTgetRows('*', $tableName, $clause); |
|
101
|
|
|
|
|
102
|
|
|
return is_array($pages) |
|
103
|
|
|
? $pages |
|
104
|
|
|
: []; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Returns a pointer to the database. |
|
109
|
|
|
* |
|
110
|
|
|
* @return \TYPO3\CMS\Core\Database\DatabaseConnection |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function getDatabaseConnection() |
|
|
|
|
|
|
113
|
|
|
{ |
|
114
|
|
|
return $GLOBALS['TYPO3_DB']; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return LanguageService |
|
119
|
|
|
*/ |
|
120
|
|
View Code Duplication |
protected function getLanguageService() |
|
|
|
|
|
|
121
|
|
|
{ |
|
122
|
|
|
|
|
123
|
|
|
/** @var LanguageService $langService */ |
|
124
|
|
|
$langService = $GLOBALS['LANG']; |
|
125
|
|
|
if (!$langService) { |
|
126
|
|
|
$langService = GeneralUtility::makeInstance(LanguageService::class); |
|
127
|
|
|
$langService->init('en'); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return $langService; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return bool |
|
135
|
|
|
*/ |
|
136
|
|
|
public function hasSuggestions() |
|
137
|
|
|
{ |
|
138
|
|
|
return true; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @param string $dataType |
|
143
|
|
|
* @return $this |
|
144
|
|
|
*/ |
|
145
|
|
|
public function setDataType($dataType) |
|
146
|
|
|
{ |
|
147
|
|
|
$this->dataType = $dataType; |
|
|
|
|
|
|
148
|
|
|
return $this; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @return bool |
|
153
|
|
|
*/ |
|
154
|
|
|
public function canModifyMatcher() |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->canModifyMatcher; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param Matcher $matcher |
|
161
|
|
|
* @param $value |
|
162
|
|
|
* @return Matcher |
|
163
|
|
|
*/ |
|
164
|
|
|
public function modifyMatcher(Matcher $matcher, $value) |
|
165
|
|
|
{ |
|
166
|
|
|
return $matcher; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Get the Vidi Module Loader. |
|
171
|
|
|
* |
|
172
|
|
|
* @return ModuleLoader|object |
|
173
|
|
|
* @throws \InvalidArgumentException |
|
174
|
|
|
*/ |
|
175
|
|
|
protected function getModuleLoader() |
|
176
|
|
|
{ |
|
177
|
|
|
return GeneralUtility::makeInstance(ModuleLoader::class); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Magic method implementation for retrieving state. |
|
182
|
|
|
* |
|
183
|
|
|
* @param array $states |
|
184
|
|
|
* @return PageFacet |
|
185
|
|
|
*/ |
|
186
|
|
|
static public function __set_state($states) |
|
|
|
|
|
|
187
|
|
|
{ |
|
188
|
|
|
return new self($states['name']); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
} |
|
192
|
|
|
|