@@ -18,42 +18,42 @@ |
||
18 | 18 | abstract class AbstractTool implements ToolInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @param string $templateNameAndPath |
|
23 | - * @return StandaloneView |
|
24 | - * @throws \InvalidArgumentException |
|
25 | - */ |
|
26 | - protected function initializeStandaloneView($templateNameAndPath) |
|
27 | - { |
|
28 | - |
|
29 | - $templateNameAndPath = GeneralUtility::getFileAbsFileName($templateNameAndPath); |
|
30 | - |
|
31 | - /** @var StandaloneView $view */ |
|
32 | - $view = GeneralUtility::makeInstance(StandaloneView::class); |
|
33 | - |
|
34 | - $view->setTemplatePathAndFilename($templateNameAndPath); |
|
35 | - return $view; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Returns an instance of the current Backend User. |
|
40 | - * |
|
41 | - * @return BackendUserAuthentication |
|
42 | - */ |
|
43 | - protected function getBackendUser() |
|
44 | - { |
|
45 | - return $GLOBALS['BE_USER']; |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Get the Vidi Module Loader. |
|
50 | - * |
|
51 | - * @return ModuleLoader |
|
52 | - * @throws \InvalidArgumentException |
|
53 | - */ |
|
54 | - protected function getModuleLoader() |
|
55 | - { |
|
56 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
57 | - } |
|
21 | + /** |
|
22 | + * @param string $templateNameAndPath |
|
23 | + * @return StandaloneView |
|
24 | + * @throws \InvalidArgumentException |
|
25 | + */ |
|
26 | + protected function initializeStandaloneView($templateNameAndPath) |
|
27 | + { |
|
28 | + |
|
29 | + $templateNameAndPath = GeneralUtility::getFileAbsFileName($templateNameAndPath); |
|
30 | + |
|
31 | + /** @var StandaloneView $view */ |
|
32 | + $view = GeneralUtility::makeInstance(StandaloneView::class); |
|
33 | + |
|
34 | + $view->setTemplatePathAndFilename($templateNameAndPath); |
|
35 | + return $view; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Returns an instance of the current Backend User. |
|
40 | + * |
|
41 | + * @return BackendUserAuthentication |
|
42 | + */ |
|
43 | + protected function getBackendUser() |
|
44 | + { |
|
45 | + return $GLOBALS['BE_USER']; |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Get the Vidi Module Loader. |
|
50 | + * |
|
51 | + * @return ModuleLoader |
|
52 | + * @throws \InvalidArgumentException |
|
53 | + */ |
|
54 | + protected function getModuleLoader() |
|
55 | + { |
|
56 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | } |
@@ -22,124 +22,124 @@ |
||
22 | 22 | class ContentService |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - protected $dataType; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var Content[] |
|
32 | - */ |
|
33 | - protected $objects = []; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - protected $numberOfObjects = 0; |
|
39 | - |
|
40 | - /** |
|
41 | - * Constructor |
|
42 | - * |
|
43 | - * @param string $dataType |
|
44 | - */ |
|
45 | - public function __construct($dataType = '') |
|
46 | - { |
|
47 | - if (empty($dataType)) { |
|
48 | - $dataType = $this->getModuleLoader()->getDataType(); |
|
49 | - } |
|
50 | - $this->dataType = $dataType; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Fetch the files given an object assuming |
|
55 | - * |
|
56 | - * @param Matcher $matcher |
|
57 | - * @param Order $order The order |
|
58 | - * @param int $limit |
|
59 | - * @param int $offset |
|
60 | - * @return $this |
|
61 | - */ |
|
62 | - public function findBy(Matcher $matcher, Order $order = null, $limit = null, $offset = null) |
|
63 | - { |
|
64 | - |
|
65 | - // Query the repository. |
|
66 | - $objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order, $limit, $offset); |
|
67 | - $signalResult = $this->emitAfterFindContentObjectsSignal($objects, $matcher, $order, $limit, $offset); |
|
68 | - |
|
69 | - // Reset objects variable after possible signal / slot processing. |
|
70 | - $this->objects = $signalResult->getContentObjects(); |
|
71 | - |
|
72 | - // Count number of content objects. |
|
73 | - if ($signalResult->getHasBeenProcessed()) { |
|
74 | - $this->numberOfObjects = $signalResult->getNumberOfObjects(); |
|
75 | - } else { |
|
76 | - $this->numberOfObjects = ContentRepositoryFactory::getInstance($this->dataType)->countBy($matcher); |
|
77 | - } |
|
78 | - |
|
79 | - return $this; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Signal that is called after the content objects have been found. |
|
84 | - * |
|
85 | - * @param array $contentObjects |
|
86 | - * @param Matcher $matcher |
|
87 | - * @param Order $order |
|
88 | - * @param int $limit |
|
89 | - * @param int $offset |
|
90 | - * @return AfterFindContentObjectsSignalArguments |
|
91 | - */ |
|
92 | - protected function emitAfterFindContentObjectsSignal($contentObjects, Matcher $matcher, Order $order = null, $limit = 0, $offset = 0) |
|
93 | - { |
|
94 | - |
|
95 | - /** @var AfterFindContentObjectsSignalArguments $signalArguments */ |
|
96 | - $signalArguments = GeneralUtility::makeInstance(AfterFindContentObjectsSignalArguments::class); |
|
97 | - $signalArguments->setDataType($this->dataType) |
|
98 | - ->setContentObjects($contentObjects) |
|
99 | - ->setMatcher($matcher) |
|
100 | - ->setOrder($order) |
|
101 | - ->setLimit($limit) |
|
102 | - ->setOffset($offset) |
|
103 | - ->setHasBeenProcessed(false); |
|
104 | - |
|
105 | - $signalResult = $this->getSignalSlotDispatcher()->dispatch(ContentService::class, 'afterFindContentObjects', array($signalArguments)); |
|
106 | - return $signalResult[0]; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Get the Vidi Module Loader. |
|
111 | - * |
|
112 | - * @return ModuleLoader|object |
|
113 | - */ |
|
114 | - protected function getModuleLoader() |
|
115 | - { |
|
116 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Get the SignalSlot dispatcher. |
|
121 | - * |
|
122 | - * @return Dispatcher|object |
|
123 | - */ |
|
124 | - protected function getSignalSlotDispatcher() |
|
125 | - { |
|
126 | - return GeneralUtility::makeInstance(Dispatcher::class); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @return Content[] |
|
131 | - */ |
|
132 | - public function getObjects() |
|
133 | - { |
|
134 | - return $this->objects; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @return int |
|
139 | - */ |
|
140 | - public function getNumberOfObjects() |
|
141 | - { |
|
142 | - return $this->numberOfObjects; |
|
143 | - } |
|
25 | + /** |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + protected $dataType; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var Content[] |
|
32 | + */ |
|
33 | + protected $objects = []; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + protected $numberOfObjects = 0; |
|
39 | + |
|
40 | + /** |
|
41 | + * Constructor |
|
42 | + * |
|
43 | + * @param string $dataType |
|
44 | + */ |
|
45 | + public function __construct($dataType = '') |
|
46 | + { |
|
47 | + if (empty($dataType)) { |
|
48 | + $dataType = $this->getModuleLoader()->getDataType(); |
|
49 | + } |
|
50 | + $this->dataType = $dataType; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Fetch the files given an object assuming |
|
55 | + * |
|
56 | + * @param Matcher $matcher |
|
57 | + * @param Order $order The order |
|
58 | + * @param int $limit |
|
59 | + * @param int $offset |
|
60 | + * @return $this |
|
61 | + */ |
|
62 | + public function findBy(Matcher $matcher, Order $order = null, $limit = null, $offset = null) |
|
63 | + { |
|
64 | + |
|
65 | + // Query the repository. |
|
66 | + $objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order, $limit, $offset); |
|
67 | + $signalResult = $this->emitAfterFindContentObjectsSignal($objects, $matcher, $order, $limit, $offset); |
|
68 | + |
|
69 | + // Reset objects variable after possible signal / slot processing. |
|
70 | + $this->objects = $signalResult->getContentObjects(); |
|
71 | + |
|
72 | + // Count number of content objects. |
|
73 | + if ($signalResult->getHasBeenProcessed()) { |
|
74 | + $this->numberOfObjects = $signalResult->getNumberOfObjects(); |
|
75 | + } else { |
|
76 | + $this->numberOfObjects = ContentRepositoryFactory::getInstance($this->dataType)->countBy($matcher); |
|
77 | + } |
|
78 | + |
|
79 | + return $this; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Signal that is called after the content objects have been found. |
|
84 | + * |
|
85 | + * @param array $contentObjects |
|
86 | + * @param Matcher $matcher |
|
87 | + * @param Order $order |
|
88 | + * @param int $limit |
|
89 | + * @param int $offset |
|
90 | + * @return AfterFindContentObjectsSignalArguments |
|
91 | + */ |
|
92 | + protected function emitAfterFindContentObjectsSignal($contentObjects, Matcher $matcher, Order $order = null, $limit = 0, $offset = 0) |
|
93 | + { |
|
94 | + |
|
95 | + /** @var AfterFindContentObjectsSignalArguments $signalArguments */ |
|
96 | + $signalArguments = GeneralUtility::makeInstance(AfterFindContentObjectsSignalArguments::class); |
|
97 | + $signalArguments->setDataType($this->dataType) |
|
98 | + ->setContentObjects($contentObjects) |
|
99 | + ->setMatcher($matcher) |
|
100 | + ->setOrder($order) |
|
101 | + ->setLimit($limit) |
|
102 | + ->setOffset($offset) |
|
103 | + ->setHasBeenProcessed(false); |
|
104 | + |
|
105 | + $signalResult = $this->getSignalSlotDispatcher()->dispatch(ContentService::class, 'afterFindContentObjects', array($signalArguments)); |
|
106 | + return $signalResult[0]; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Get the Vidi Module Loader. |
|
111 | + * |
|
112 | + * @return ModuleLoader|object |
|
113 | + */ |
|
114 | + protected function getModuleLoader() |
|
115 | + { |
|
116 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Get the SignalSlot dispatcher. |
|
121 | + * |
|
122 | + * @return Dispatcher|object |
|
123 | + */ |
|
124 | + protected function getSignalSlotDispatcher() |
|
125 | + { |
|
126 | + return GeneralUtility::makeInstance(Dispatcher::class); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @return Content[] |
|
131 | + */ |
|
132 | + public function getObjects() |
|
133 | + { |
|
134 | + return $this->objects; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @return int |
|
139 | + */ |
|
140 | + public function getNumberOfObjects() |
|
141 | + { |
|
142 | + return $this->numberOfObjects; |
|
143 | + } |
|
144 | 144 | |
145 | 145 | } |
@@ -25,267 +25,267 @@ |
||
25 | 25 | class MatcherObjectFactory implements SingletonInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Gets a singleton instance of this class. |
|
30 | - * |
|
31 | - * @return $this |
|
32 | - */ |
|
33 | - static public function getInstance(): self |
|
34 | - { |
|
35 | - return GeneralUtility::makeInstance(self::class); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Returns a matcher object. |
|
40 | - * |
|
41 | - * @param array $matches |
|
42 | - * @param string $dataType |
|
43 | - * @return Matcher |
|
44 | - */ |
|
45 | - public function getMatcher(array $matches = [], $dataType = ''): Matcher |
|
46 | - { |
|
47 | - if ($dataType === '') { |
|
48 | - $dataType = $this->getModuleLoader()->getDataType(); |
|
49 | - } |
|
50 | - |
|
51 | - /** @var $matcher Matcher */ |
|
52 | - $matcher = GeneralUtility::makeInstance(Matcher::class, [], $dataType); |
|
53 | - |
|
54 | - $matcher = $this->applyCriteriaFromDataTables($matcher); |
|
55 | - $matcher = $this->applyCriteriaFromMatchesArgument($matcher, $matches); |
|
56 | - |
|
57 | - if ($this->isBackendMode()) { |
|
58 | - $matcher = $this->applyCriteriaFromUrl($matcher); |
|
59 | - $matcher = $this->applyCriteriaFromTSConfig($matcher); |
|
60 | - } |
|
61 | - |
|
62 | - // Trigger signal for post processing Matcher Object. |
|
63 | - $this->emitPostProcessMatcherObjectSignal($matcher); |
|
64 | - |
|
65 | - return $matcher; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Get a possible id from the URL and apply as filter criteria. |
|
70 | - * Except if the main module belongs to the File. The id would be a combined identifier |
|
71 | - * including the storage and a mount point. |
|
72 | - * |
|
73 | - * @param Matcher $matcher |
|
74 | - * @return Matcher $matcher |
|
75 | - */ |
|
76 | - protected function applyCriteriaFromUrl(Matcher $matcher): Matcher |
|
77 | - { |
|
78 | - if (GeneralUtility::_GP('id') |
|
79 | - && !$this->getModuleLoader()->isPidIgnored() |
|
80 | - && $this->getModuleLoader()->getMainModule() !== ModuleName::FILE) { |
|
81 | - $matcher->equals('pid', GeneralUtility::_GP('id')); |
|
82 | - } |
|
83 | - |
|
84 | - return $matcher; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param Matcher $matcher |
|
89 | - * @return Matcher $matcher |
|
90 | - */ |
|
91 | - protected function applyCriteriaFromTSConfig(Matcher $matcher): Matcher |
|
92 | - { |
|
93 | - $dataType = $matcher->getDataType(); |
|
94 | - $tsConfigPath = sprintf('tx_vidi.dataType.%s.constraints', $dataType); |
|
95 | - $tsConfig = $this->getBackendUser()->getTSConfig($tsConfigPath); |
|
96 | - |
|
97 | - if (is_array($tsConfig['properties']) && !empty($tsConfig['properties'])) { |
|
98 | - |
|
99 | - foreach ($tsConfig['properties'] as $constraint) { |
|
100 | - |
|
101 | - if (preg_match('/(.+) (>=|>|<|<=|=|like) (.+)/is', $constraint, $matches) && count($matches) === 4) { |
|
102 | - |
|
103 | - $operator = $matcher->getSupportedOperators()[strtolower(trim($matches[2]))]; |
|
104 | - $operand = trim($matches[1]); |
|
105 | - $value = trim($matches[3]); |
|
106 | - |
|
107 | - $matcher->$operator($operand, $value); |
|
108 | - } elseif (preg_match('/(.+) (in) (.+)/is', $constraint, $matches) && count($matches) === 4) { |
|
109 | - |
|
110 | - $operator = $matcher->getSupportedOperators()[trim($matches[2])]; |
|
111 | - $operand = trim($matches[1]); |
|
112 | - $value = trim($matches[3]); |
|
113 | - $matcher->$operator($operand, GeneralUtility::trimExplode(',', $value, true)); |
|
114 | - } |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - return $matcher; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @param Matcher $matcher |
|
123 | - * @param array $matches |
|
124 | - * @return Matcher $matcher |
|
125 | - */ |
|
126 | - protected function applyCriteriaFromMatchesArgument(Matcher $matcher, $matches): Matcher |
|
127 | - { |
|
128 | - foreach ($matches as $fieldNameAndPath => $value) { |
|
129 | - // CSV values should be considered as "in" operator in the query, otherwise "equals". |
|
130 | - $explodedValues = GeneralUtility::trimExplode(',', $value, true); |
|
131 | - if (count($explodedValues) > 1) { |
|
132 | - $matcher->in($fieldNameAndPath, $explodedValues); |
|
133 | - } else { |
|
134 | - $matcher->equals($fieldNameAndPath, $explodedValues[0]); |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - return $matcher; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Apply criteria specific to jQuery plugin DataTable. |
|
143 | - * |
|
144 | - * @param Matcher $matcher |
|
145 | - * @return Matcher $matcher |
|
146 | - */ |
|
147 | - protected function applyCriteriaFromDataTables(Matcher $matcher): Matcher |
|
148 | - { |
|
149 | - |
|
150 | - // Special case for Grid in the BE using jQuery DataTables plugin. |
|
151 | - // Retrieve a possible search term from GP. |
|
152 | - $query = GeneralUtility::_GP('search'); |
|
153 | - if (is_array($query)) { |
|
154 | - if (!empty($query['value'])) { |
|
155 | - $query = $query['value']; |
|
156 | - } else { |
|
157 | - $query = ''; |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - if (strlen($query) > 0) { |
|
162 | - |
|
163 | - // Parse the json query coming from the Visual Search. |
|
164 | - $query = rawurldecode($query); |
|
165 | - $queryParts = json_decode($query, true); |
|
166 | - |
|
167 | - if (is_array($queryParts)) { |
|
168 | - $matcher = $this->parseQuery($queryParts, $matcher); |
|
169 | - } else { |
|
170 | - $matcher->setSearchTerm($query); |
|
171 | - } |
|
172 | - } |
|
173 | - return $matcher; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @param array $queryParts |
|
178 | - * @param Matcher $matcher |
|
179 | - * @return Matcher $matcher |
|
180 | - */ |
|
181 | - protected function parseQuery(array $queryParts, Matcher $matcher): Matcher |
|
182 | - { |
|
183 | - $dataType = $matcher->getDataType(); |
|
184 | - foreach ($queryParts as $term) { |
|
185 | - $fieldNameAndPath = key($term); |
|
186 | - |
|
187 | - $resolvedDataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType); |
|
188 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType); |
|
189 | - |
|
190 | - // Retrieve the value. |
|
191 | - $value = current($term); |
|
192 | - |
|
193 | - if (Tca::grid($resolvedDataType)->hasFacet($fieldName) && Tca::grid($resolvedDataType)->facet($fieldName)->canModifyMatcher()) { |
|
194 | - $matcher = Tca::grid($resolvedDataType)->facet($fieldName)->modifyMatcher($matcher, $value); |
|
195 | - } elseif (Tca::table($resolvedDataType)->hasField($fieldName)) { |
|
196 | - // Check whether the field exists and set it as "equal" or "like". |
|
197 | - if ($this->isOperatorEquals($fieldNameAndPath, $dataType, $value)) { |
|
198 | - $matcher->equals($fieldNameAndPath, $value); |
|
199 | - } else { |
|
200 | - $matcher->like($fieldNameAndPath, $value); |
|
201 | - } |
|
202 | - } elseif ($fieldNameAndPath === 'text') { |
|
203 | - // Special case if field is "text" which is a pseudo field in this case. |
|
204 | - // Set the search term which means Vidi will |
|
205 | - // search in various fields with operator "like". The fields come from key "searchFields" in the TCA. |
|
206 | - $matcher->setSearchTerm($value); |
|
207 | - } |
|
208 | - } |
|
209 | - return $matcher; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Tell whether the operator should be equals instead of like for a search, e.g. if the value is numerical. |
|
214 | - * |
|
215 | - * @param string $fieldName |
|
216 | - * @param string $dataType |
|
217 | - * @param string $value |
|
218 | - * @return bool |
|
219 | - */ |
|
220 | - protected function isOperatorEquals($fieldName, $dataType, $value): bool |
|
221 | - { |
|
222 | - return (Tca::table($dataType)->field($fieldName)->hasRelation() && MathUtility::canBeInterpretedAsInteger($value)) |
|
223 | - || Tca::table($dataType)->field($fieldName)->isNumerical(); |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Signal that is called for post-processing a matcher object. |
|
228 | - * |
|
229 | - * @param Matcher $matcher |
|
230 | - */ |
|
231 | - protected function emitPostProcessMatcherObjectSignal(Matcher $matcher): void |
|
232 | - { |
|
233 | - |
|
234 | - if (strlen($matcher->getDataType()) <= 0) { |
|
235 | - |
|
236 | - /** @var ModuleLoader $moduleLoader */ |
|
237 | - $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
238 | - $matcher->setDataType($moduleLoader->getDataType()); |
|
239 | - } |
|
240 | - |
|
241 | - $this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\Controller\Backend\ContentController', 'postProcessMatcherObject', array($matcher, $matcher->getDataType())); |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Get the SignalSlot dispatcher |
|
246 | - * |
|
247 | - * @return Dispatcher|object |
|
248 | - */ |
|
249 | - protected function getSignalSlotDispatcher() |
|
250 | - { |
|
251 | - return GeneralUtility::makeInstance(Dispatcher::class); |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Get the Vidi Module Loader. |
|
256 | - * |
|
257 | - * @return ModuleLoader|object |
|
258 | - */ |
|
259 | - protected function getModuleLoader() |
|
260 | - { |
|
261 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * @return FieldPathResolver|object |
|
266 | - */ |
|
267 | - protected function getFieldPathResolver() |
|
268 | - { |
|
269 | - return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Returns an instance of the current Backend User. |
|
274 | - * |
|
275 | - * @return BackendUserAuthentication |
|
276 | - */ |
|
277 | - protected function getBackendUser(): BackendUserAuthentication |
|
278 | - { |
|
279 | - return $GLOBALS['BE_USER']; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Returns whether the current mode is Backend |
|
284 | - * |
|
285 | - * @return bool |
|
286 | - */ |
|
287 | - protected function isBackendMode(): bool |
|
288 | - { |
|
289 | - return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend(); |
|
290 | - } |
|
28 | + /** |
|
29 | + * Gets a singleton instance of this class. |
|
30 | + * |
|
31 | + * @return $this |
|
32 | + */ |
|
33 | + static public function getInstance(): self |
|
34 | + { |
|
35 | + return GeneralUtility::makeInstance(self::class); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Returns a matcher object. |
|
40 | + * |
|
41 | + * @param array $matches |
|
42 | + * @param string $dataType |
|
43 | + * @return Matcher |
|
44 | + */ |
|
45 | + public function getMatcher(array $matches = [], $dataType = ''): Matcher |
|
46 | + { |
|
47 | + if ($dataType === '') { |
|
48 | + $dataType = $this->getModuleLoader()->getDataType(); |
|
49 | + } |
|
50 | + |
|
51 | + /** @var $matcher Matcher */ |
|
52 | + $matcher = GeneralUtility::makeInstance(Matcher::class, [], $dataType); |
|
53 | + |
|
54 | + $matcher = $this->applyCriteriaFromDataTables($matcher); |
|
55 | + $matcher = $this->applyCriteriaFromMatchesArgument($matcher, $matches); |
|
56 | + |
|
57 | + if ($this->isBackendMode()) { |
|
58 | + $matcher = $this->applyCriteriaFromUrl($matcher); |
|
59 | + $matcher = $this->applyCriteriaFromTSConfig($matcher); |
|
60 | + } |
|
61 | + |
|
62 | + // Trigger signal for post processing Matcher Object. |
|
63 | + $this->emitPostProcessMatcherObjectSignal($matcher); |
|
64 | + |
|
65 | + return $matcher; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Get a possible id from the URL and apply as filter criteria. |
|
70 | + * Except if the main module belongs to the File. The id would be a combined identifier |
|
71 | + * including the storage and a mount point. |
|
72 | + * |
|
73 | + * @param Matcher $matcher |
|
74 | + * @return Matcher $matcher |
|
75 | + */ |
|
76 | + protected function applyCriteriaFromUrl(Matcher $matcher): Matcher |
|
77 | + { |
|
78 | + if (GeneralUtility::_GP('id') |
|
79 | + && !$this->getModuleLoader()->isPidIgnored() |
|
80 | + && $this->getModuleLoader()->getMainModule() !== ModuleName::FILE) { |
|
81 | + $matcher->equals('pid', GeneralUtility::_GP('id')); |
|
82 | + } |
|
83 | + |
|
84 | + return $matcher; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param Matcher $matcher |
|
89 | + * @return Matcher $matcher |
|
90 | + */ |
|
91 | + protected function applyCriteriaFromTSConfig(Matcher $matcher): Matcher |
|
92 | + { |
|
93 | + $dataType = $matcher->getDataType(); |
|
94 | + $tsConfigPath = sprintf('tx_vidi.dataType.%s.constraints', $dataType); |
|
95 | + $tsConfig = $this->getBackendUser()->getTSConfig($tsConfigPath); |
|
96 | + |
|
97 | + if (is_array($tsConfig['properties']) && !empty($tsConfig['properties'])) { |
|
98 | + |
|
99 | + foreach ($tsConfig['properties'] as $constraint) { |
|
100 | + |
|
101 | + if (preg_match('/(.+) (>=|>|<|<=|=|like) (.+)/is', $constraint, $matches) && count($matches) === 4) { |
|
102 | + |
|
103 | + $operator = $matcher->getSupportedOperators()[strtolower(trim($matches[2]))]; |
|
104 | + $operand = trim($matches[1]); |
|
105 | + $value = trim($matches[3]); |
|
106 | + |
|
107 | + $matcher->$operator($operand, $value); |
|
108 | + } elseif (preg_match('/(.+) (in) (.+)/is', $constraint, $matches) && count($matches) === 4) { |
|
109 | + |
|
110 | + $operator = $matcher->getSupportedOperators()[trim($matches[2])]; |
|
111 | + $operand = trim($matches[1]); |
|
112 | + $value = trim($matches[3]); |
|
113 | + $matcher->$operator($operand, GeneralUtility::trimExplode(',', $value, true)); |
|
114 | + } |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + return $matcher; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @param Matcher $matcher |
|
123 | + * @param array $matches |
|
124 | + * @return Matcher $matcher |
|
125 | + */ |
|
126 | + protected function applyCriteriaFromMatchesArgument(Matcher $matcher, $matches): Matcher |
|
127 | + { |
|
128 | + foreach ($matches as $fieldNameAndPath => $value) { |
|
129 | + // CSV values should be considered as "in" operator in the query, otherwise "equals". |
|
130 | + $explodedValues = GeneralUtility::trimExplode(',', $value, true); |
|
131 | + if (count($explodedValues) > 1) { |
|
132 | + $matcher->in($fieldNameAndPath, $explodedValues); |
|
133 | + } else { |
|
134 | + $matcher->equals($fieldNameAndPath, $explodedValues[0]); |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + return $matcher; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Apply criteria specific to jQuery plugin DataTable. |
|
143 | + * |
|
144 | + * @param Matcher $matcher |
|
145 | + * @return Matcher $matcher |
|
146 | + */ |
|
147 | + protected function applyCriteriaFromDataTables(Matcher $matcher): Matcher |
|
148 | + { |
|
149 | + |
|
150 | + // Special case for Grid in the BE using jQuery DataTables plugin. |
|
151 | + // Retrieve a possible search term from GP. |
|
152 | + $query = GeneralUtility::_GP('search'); |
|
153 | + if (is_array($query)) { |
|
154 | + if (!empty($query['value'])) { |
|
155 | + $query = $query['value']; |
|
156 | + } else { |
|
157 | + $query = ''; |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + if (strlen($query) > 0) { |
|
162 | + |
|
163 | + // Parse the json query coming from the Visual Search. |
|
164 | + $query = rawurldecode($query); |
|
165 | + $queryParts = json_decode($query, true); |
|
166 | + |
|
167 | + if (is_array($queryParts)) { |
|
168 | + $matcher = $this->parseQuery($queryParts, $matcher); |
|
169 | + } else { |
|
170 | + $matcher->setSearchTerm($query); |
|
171 | + } |
|
172 | + } |
|
173 | + return $matcher; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @param array $queryParts |
|
178 | + * @param Matcher $matcher |
|
179 | + * @return Matcher $matcher |
|
180 | + */ |
|
181 | + protected function parseQuery(array $queryParts, Matcher $matcher): Matcher |
|
182 | + { |
|
183 | + $dataType = $matcher->getDataType(); |
|
184 | + foreach ($queryParts as $term) { |
|
185 | + $fieldNameAndPath = key($term); |
|
186 | + |
|
187 | + $resolvedDataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType); |
|
188 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType); |
|
189 | + |
|
190 | + // Retrieve the value. |
|
191 | + $value = current($term); |
|
192 | + |
|
193 | + if (Tca::grid($resolvedDataType)->hasFacet($fieldName) && Tca::grid($resolvedDataType)->facet($fieldName)->canModifyMatcher()) { |
|
194 | + $matcher = Tca::grid($resolvedDataType)->facet($fieldName)->modifyMatcher($matcher, $value); |
|
195 | + } elseif (Tca::table($resolvedDataType)->hasField($fieldName)) { |
|
196 | + // Check whether the field exists and set it as "equal" or "like". |
|
197 | + if ($this->isOperatorEquals($fieldNameAndPath, $dataType, $value)) { |
|
198 | + $matcher->equals($fieldNameAndPath, $value); |
|
199 | + } else { |
|
200 | + $matcher->like($fieldNameAndPath, $value); |
|
201 | + } |
|
202 | + } elseif ($fieldNameAndPath === 'text') { |
|
203 | + // Special case if field is "text" which is a pseudo field in this case. |
|
204 | + // Set the search term which means Vidi will |
|
205 | + // search in various fields with operator "like". The fields come from key "searchFields" in the TCA. |
|
206 | + $matcher->setSearchTerm($value); |
|
207 | + } |
|
208 | + } |
|
209 | + return $matcher; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Tell whether the operator should be equals instead of like for a search, e.g. if the value is numerical. |
|
214 | + * |
|
215 | + * @param string $fieldName |
|
216 | + * @param string $dataType |
|
217 | + * @param string $value |
|
218 | + * @return bool |
|
219 | + */ |
|
220 | + protected function isOperatorEquals($fieldName, $dataType, $value): bool |
|
221 | + { |
|
222 | + return (Tca::table($dataType)->field($fieldName)->hasRelation() && MathUtility::canBeInterpretedAsInteger($value)) |
|
223 | + || Tca::table($dataType)->field($fieldName)->isNumerical(); |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Signal that is called for post-processing a matcher object. |
|
228 | + * |
|
229 | + * @param Matcher $matcher |
|
230 | + */ |
|
231 | + protected function emitPostProcessMatcherObjectSignal(Matcher $matcher): void |
|
232 | + { |
|
233 | + |
|
234 | + if (strlen($matcher->getDataType()) <= 0) { |
|
235 | + |
|
236 | + /** @var ModuleLoader $moduleLoader */ |
|
237 | + $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
238 | + $matcher->setDataType($moduleLoader->getDataType()); |
|
239 | + } |
|
240 | + |
|
241 | + $this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\Controller\Backend\ContentController', 'postProcessMatcherObject', array($matcher, $matcher->getDataType())); |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Get the SignalSlot dispatcher |
|
246 | + * |
|
247 | + * @return Dispatcher|object |
|
248 | + */ |
|
249 | + protected function getSignalSlotDispatcher() |
|
250 | + { |
|
251 | + return GeneralUtility::makeInstance(Dispatcher::class); |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Get the Vidi Module Loader. |
|
256 | + * |
|
257 | + * @return ModuleLoader|object |
|
258 | + */ |
|
259 | + protected function getModuleLoader() |
|
260 | + { |
|
261 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * @return FieldPathResolver|object |
|
266 | + */ |
|
267 | + protected function getFieldPathResolver() |
|
268 | + { |
|
269 | + return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Returns an instance of the current Backend User. |
|
274 | + * |
|
275 | + * @return BackendUserAuthentication |
|
276 | + */ |
|
277 | + protected function getBackendUser(): BackendUserAuthentication |
|
278 | + { |
|
279 | + return $GLOBALS['BE_USER']; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Returns whether the current mode is Backend |
|
284 | + * |
|
285 | + * @return bool |
|
286 | + */ |
|
287 | + protected function isBackendMode(): bool |
|
288 | + { |
|
289 | + return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend(); |
|
290 | + } |
|
291 | 291 | } |
@@ -41,626 +41,626 @@ |
||
41 | 41 | class Query implements QueryInterface |
42 | 42 | { |
43 | 43 | |
44 | - /** |
|
45 | - * An inner join. |
|
46 | - */ |
|
47 | - const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner'; |
|
48 | - |
|
49 | - /** |
|
50 | - * A left-outer join. |
|
51 | - */ |
|
52 | - const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter'; |
|
53 | - |
|
54 | - /** |
|
55 | - * A right-outer join. |
|
56 | - */ |
|
57 | - const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter'; |
|
58 | - |
|
59 | - /** |
|
60 | - * Charset of strings in QOM |
|
61 | - */ |
|
62 | - const CHARSET = 'utf-8'; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - protected $sourceFieldName; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var string |
|
71 | - */ |
|
72 | - protected $type; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var PersistenceManagerInterface |
|
76 | - */ |
|
77 | - protected $persistenceManager; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var QueryObjectModelFactory |
|
81 | - */ |
|
82 | - protected $qomFactory; |
|
83 | - |
|
84 | - /** |
|
85 | - * @var SourceInterface |
|
86 | - */ |
|
87 | - protected $source; |
|
88 | - |
|
89 | - /** |
|
90 | - * @var ConstraintInterface |
|
91 | - */ |
|
92 | - protected $constraint; |
|
93 | - |
|
94 | - /** |
|
95 | - * @var Statement |
|
96 | - */ |
|
97 | - protected $statement; |
|
98 | - |
|
99 | - /** |
|
100 | - * @var array |
|
101 | - */ |
|
102 | - protected $orderings = []; |
|
103 | - |
|
104 | - /** |
|
105 | - * @var int |
|
106 | - */ |
|
107 | - protected $limit; |
|
108 | - |
|
109 | - /** |
|
110 | - * @var int |
|
111 | - */ |
|
112 | - protected $offset; |
|
113 | - |
|
114 | - /** |
|
115 | - * Apply DISTINCT upon property. |
|
116 | - * |
|
117 | - * @var string |
|
118 | - */ |
|
119 | - protected $distinct; |
|
120 | - |
|
121 | - /** |
|
122 | - * The query settings. |
|
123 | - * |
|
124 | - * @var Typo3QuerySettings |
|
125 | - */ |
|
126 | - public Typo3QuerySettings $typo3QuerySettings; |
|
127 | - |
|
128 | - /** |
|
129 | - * Constructs a query object working on the given class name |
|
130 | - * |
|
131 | - * @param string $type |
|
132 | - */ |
|
133 | - public function __construct($type) |
|
134 | - { |
|
135 | - $this->type = $type; |
|
136 | - $this->persistenceManager = GeneralUtility::makeInstance(PersistenceManagerInterface::class); |
|
137 | - $this->qomFactory = GeneralUtility::makeInstance(QueryObjectModelFactory::class); |
|
138 | - } |
|
139 | - |
|
140 | - public function injectTypo3QuerySettings(Typo3QuerySettings $querySettings): void |
|
141 | - { |
|
142 | - $this->typo3QuerySettings = $querySettings; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Sets the Query Settings. These Query settings must match the settings expected by |
|
147 | - * the specific Storage Backend. |
|
148 | - * |
|
149 | - * @param QuerySettingsInterface $typo3QuerySettings The Query Settings |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - public function setTypo3QuerySettings(QuerySettingsInterface $typo3QuerySettings) |
|
153 | - { |
|
154 | - $this->typo3QuerySettings = $typo3QuerySettings; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Returns the Query Settings. |
|
159 | - * |
|
160 | - * @throws \Exception |
|
161 | - * @return Typo3QuerySettings $querySettings The Query Settings |
|
162 | - * @api This method is not part of FLOW3 API |
|
163 | - */ |
|
164 | - public function getTypo3QuerySettings() |
|
165 | - { |
|
166 | - if (!$this->typo3QuerySettings instanceof QuerySettingsInterface) { |
|
167 | - throw new Exception('Tried to get the query settings without setting them before.', 1248689115); |
|
168 | - } |
|
169 | - |
|
170 | - // Apply possible settings to the query. |
|
171 | - if ($this->isBackendMode()) { |
|
172 | - /** @var BackendConfigurationManager $backendConfigurationManager */ |
|
173 | - $backendConfigurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class); |
|
174 | - $configuration = $backendConfigurationManager->getTypoScriptSetup(); |
|
175 | - $querySettings = array('respectSysLanguage'); |
|
176 | - foreach ($querySettings as $setting) { |
|
177 | - if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) { |
|
178 | - $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting]; |
|
179 | - ObjectAccess::setProperty($this->typo3QuerySettings, $setting, $value); |
|
180 | - } |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - return $this->typo3QuerySettings; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Returns the type this query cares for. |
|
189 | - * |
|
190 | - * @return string |
|
191 | - * @api |
|
192 | - */ |
|
193 | - public function getType() |
|
194 | - { |
|
195 | - return $this->type; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Sets the source to fetch the result from |
|
200 | - * |
|
201 | - * @param SourceInterface $source |
|
202 | - */ |
|
203 | - public function setSource(SourceInterface $source) |
|
204 | - { |
|
205 | - $this->source = $source; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Returns the selectorn name or an empty string, if the source is not a selector |
|
210 | - * TODO This has to be checked at another place |
|
211 | - * |
|
212 | - * @return string The selector name |
|
213 | - */ |
|
214 | - protected function getSelectorName() |
|
215 | - { |
|
216 | - if ($this->getSource() instanceof SelectorInterface) { |
|
217 | - return $this->source->getSelectorName(); |
|
218 | - } else { |
|
219 | - return ''; |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Gets the node-tuple source for this query. |
|
225 | - * |
|
226 | - * @return SourceInterface the node-tuple source; non-null |
|
227 | - */ |
|
228 | - public function getSource() |
|
229 | - { |
|
230 | - if ($this->source === null) { |
|
231 | - $this->source = $this->qomFactory->selector($this->getType()); |
|
232 | - } |
|
233 | - return $this->source; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Executes the query against the database and returns the result |
|
238 | - * |
|
239 | - * @return QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is true |
|
240 | - * @api |
|
241 | - */ |
|
242 | - public function execute($returnRawQueryResult = false) |
|
243 | - { |
|
244 | - /** @var VidiDbBackend $backend */ |
|
245 | - $backend = GeneralUtility::makeInstance(VidiDbBackend::class, $this); |
|
246 | - return $backend->fetchResult(); |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Sets the property names to order the result by. Expected like this: |
|
251 | - * array( |
|
252 | - * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
253 | - * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
254 | - * ) |
|
255 | - * where 'foo' and 'bar' are property names. |
|
256 | - * |
|
257 | - * @param array $orderings The property names to order by |
|
258 | - * @return QueryInterface |
|
259 | - * @api |
|
260 | - */ |
|
261 | - public function setOrderings(array $orderings) |
|
262 | - { |
|
263 | - $this->orderings = $orderings; |
|
264 | - return $this; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Returns the property names to order the result by. Like this: |
|
269 | - * array( |
|
270 | - * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
271 | - * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
272 | - * ) |
|
273 | - * |
|
274 | - * @return array |
|
275 | - */ |
|
276 | - public function getOrderings() |
|
277 | - { |
|
278 | - return $this->orderings; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Sets the maximum size of the result set to limit. Returns $this to allow |
|
283 | - * for chaining (fluid interface) |
|
284 | - * |
|
285 | - * @param integer $limit |
|
286 | - * @throws \InvalidArgumentException |
|
287 | - * @return QueryInterface |
|
288 | - * @api |
|
289 | - */ |
|
290 | - public function setLimit($limit) |
|
291 | - { |
|
292 | - if (!is_int($limit) || $limit < 1) { |
|
293 | - throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870); |
|
294 | - } |
|
295 | - $this->limit = $limit; |
|
296 | - return $this; |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Resets a previously set maximum size of the result set. Returns $this to allow |
|
301 | - * for chaining (fluid interface) |
|
302 | - * |
|
303 | - * @return QueryInterface |
|
304 | - * @api |
|
305 | - */ |
|
306 | - public function unsetLimit() |
|
307 | - { |
|
308 | - unset($this->limit); |
|
309 | - return $this; |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Returns the maximum size of the result set to limit. |
|
314 | - * |
|
315 | - * @return integer |
|
316 | - * @api |
|
317 | - */ |
|
318 | - public function getLimit() |
|
319 | - { |
|
320 | - return $this->limit; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Sets the start offset of the result set to offset. Returns $this to |
|
325 | - * allow for chaining (fluid interface) |
|
326 | - * |
|
327 | - * @param integer $offset |
|
328 | - * @throws \InvalidArgumentException |
|
329 | - * @return QueryInterface |
|
330 | - * @api |
|
331 | - */ |
|
332 | - public function setOffset($offset) |
|
333 | - { |
|
334 | - if (!is_int($offset) || $offset < 0) { |
|
335 | - throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872); |
|
336 | - } |
|
337 | - $this->offset = $offset; |
|
338 | - return $this; |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Returns the start offset of the result set. |
|
343 | - * |
|
344 | - * @return integer |
|
345 | - * @api |
|
346 | - */ |
|
347 | - public function getOffset() |
|
348 | - { |
|
349 | - return $this->offset; |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * The constraint used to limit the result set. Returns $this to allow |
|
354 | - * for chaining (fluid interface) |
|
355 | - * |
|
356 | - * @param ConstraintInterface $constraint |
|
357 | - * @return QueryInterface |
|
358 | - * @api |
|
359 | - */ |
|
360 | - public function matching($constraint) |
|
361 | - { |
|
362 | - $this->constraint = $constraint; |
|
363 | - return $this; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Gets the constraint for this query. |
|
368 | - * |
|
369 | - * @return ConstraintInterface the constraint, or null if none |
|
370 | - * @api |
|
371 | - */ |
|
372 | - public function getConstraint() |
|
373 | - { |
|
374 | - return $this->constraint; |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND. |
|
379 | - * It also scepts a single array of constraints to be concatenated. |
|
380 | - * |
|
381 | - * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
382 | - * @throws InvalidNumberOfConstraintsException |
|
383 | - * @return AndInterface |
|
384 | - * @api |
|
385 | - */ |
|
386 | - public function logicalAnd($constraint1) |
|
387 | - { |
|
388 | - if (is_array($constraint1)) { |
|
389 | - $resultingConstraint = array_shift($constraint1); |
|
390 | - $constraints = $constraint1; |
|
391 | - } else { |
|
392 | - $constraints = func_get_args(); |
|
393 | - $resultingConstraint = array_shift($constraints); |
|
394 | - } |
|
395 | - if ($resultingConstraint === null) { |
|
396 | - throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500); |
|
397 | - } |
|
398 | - foreach ($constraints as $constraint) { |
|
399 | - $resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint); |
|
400 | - } |
|
401 | - return $resultingConstraint; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Performs a logical disjunction of the two given constraints |
|
406 | - * |
|
407 | - * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
408 | - * @throws InvalidNumberOfConstraintsException |
|
409 | - * @return OrInterface |
|
410 | - * @api |
|
411 | - */ |
|
412 | - public function logicalOr($constraint1) |
|
413 | - { |
|
414 | - if (is_array($constraint1)) { |
|
415 | - $resultingConstraint = array_shift($constraint1); |
|
416 | - $constraints = $constraint1; |
|
417 | - } else { |
|
418 | - $constraints = func_get_args(); |
|
419 | - $resultingConstraint = array_shift($constraints); |
|
420 | - } |
|
421 | - if ($resultingConstraint === null) { |
|
422 | - throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501); |
|
423 | - } |
|
424 | - foreach ($constraints as $constraint) { |
|
425 | - $resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint); |
|
426 | - } |
|
427 | - return $resultingConstraint; |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * Performs a logical negation of the given constraint |
|
432 | - * |
|
433 | - * @param ConstraintInterface $constraint Constraint to negate |
|
434 | - * @throws \RuntimeException |
|
435 | - * @return NotInterface |
|
436 | - * @api |
|
437 | - */ |
|
438 | - public function logicalNot(ConstraintInterface $constraint) |
|
439 | - { |
|
440 | - return $this->qomFactory->not($constraint); |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Returns an equals criterion used for matching objects against a query |
|
445 | - * |
|
446 | - * @param string $propertyName The name of the property to compare against |
|
447 | - * @param mixed $operand The value to compare with |
|
448 | - * @param boolean $caseSensitive Whether the equality test should be done case-sensitive |
|
449 | - * @return ComparisonInterface |
|
450 | - * @api |
|
451 | - */ |
|
452 | - public function equals($propertyName, $operand, $caseSensitive = true) |
|
453 | - { |
|
454 | - if (is_object($operand) || $caseSensitive) { |
|
455 | - $comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand); |
|
456 | - } else { |
|
457 | - $comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), QueryInterface::OPERATOR_EQUAL_TO, mb_strtolower($operand, \TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET)); |
|
458 | - } |
|
459 | - return $comparison; |
|
460 | - } |
|
461 | - |
|
462 | - /** |
|
463 | - * Returns a like criterion used for matching objects against a query |
|
464 | - * |
|
465 | - * @param string $propertyName The name of the property to compare against |
|
466 | - * @param mixed $operand The value to compare with |
|
467 | - * @param boolean $caseSensitive Whether the matching should be done case-sensitive |
|
468 | - * @return ComparisonInterface |
|
469 | - * @api |
|
470 | - */ |
|
471 | - public function like($propertyName, $operand, $caseSensitive = true) |
|
472 | - { |
|
473 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand); |
|
474 | - } |
|
475 | - |
|
476 | - /** |
|
477 | - * Returns a "contains" criterion used for matching objects against a query. |
|
478 | - * It matches if the multivalued property contains the given operand. |
|
479 | - * |
|
480 | - * @param string $propertyName The name of the (multivalued) property to compare against |
|
481 | - * @param mixed $operand The value to compare with |
|
482 | - * @return ComparisonInterface |
|
483 | - * @api |
|
484 | - */ |
|
485 | - public function contains($propertyName, $operand) |
|
486 | - { |
|
487 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand); |
|
488 | - } |
|
489 | - |
|
490 | - /** |
|
491 | - * Returns an "in" criterion used for matching objects against a query. It |
|
492 | - * matches if the property's value is contained in the multivalued operand. |
|
493 | - * |
|
494 | - * @param string $propertyName The name of the property to compare against |
|
495 | - * @param mixed $operand The value to compare with, multivalued |
|
496 | - * @throws UnexpectedTypeException |
|
497 | - * @return ComparisonInterface |
|
498 | - * @api |
|
499 | - */ |
|
500 | - public function in($propertyName, $operand) |
|
501 | - { |
|
502 | - if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) { |
|
503 | - throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095); |
|
504 | - } |
|
505 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand); |
|
506 | - } |
|
507 | - |
|
508 | - /** |
|
509 | - * Returns a less than criterion used for matching objects against a query |
|
510 | - * |
|
511 | - * @param string $propertyName The name of the property to compare against |
|
512 | - * @param mixed $operand The value to compare with |
|
513 | - * @return ComparisonInterface |
|
514 | - * @api |
|
515 | - */ |
|
516 | - public function lessThan($propertyName, $operand) |
|
517 | - { |
|
518 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand); |
|
519 | - } |
|
520 | - |
|
521 | - /** |
|
522 | - * Returns a less or equal than criterion used for matching objects against a query |
|
523 | - * |
|
524 | - * @param string $propertyName The name of the property to compare against |
|
525 | - * @param mixed $operand The value to compare with |
|
526 | - * @return ComparisonInterface |
|
527 | - * @api |
|
528 | - */ |
|
529 | - public function lessThanOrEqual($propertyName, $operand) |
|
530 | - { |
|
531 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand); |
|
532 | - } |
|
533 | - |
|
534 | - /** |
|
535 | - * Returns a greater than criterion used for matching objects against a query |
|
536 | - * |
|
537 | - * @param string $propertyName The name of the property to compare against |
|
538 | - * @param mixed $operand The value to compare with |
|
539 | - * @return ComparisonInterface |
|
540 | - * @api |
|
541 | - */ |
|
542 | - public function greaterThan($propertyName, $operand) |
|
543 | - { |
|
544 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand); |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * Returns a greater than or equal criterion used for matching objects against a query |
|
549 | - * |
|
550 | - * @param string $propertyName The name of the property to compare against |
|
551 | - * @param mixed $operand The value to compare with |
|
552 | - * @return ComparisonInterface |
|
553 | - * @api |
|
554 | - */ |
|
555 | - public function greaterThanOrEqual($propertyName, $operand) |
|
556 | - { |
|
557 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand); |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Returns the query result count. |
|
562 | - * |
|
563 | - * @return integer The query result count |
|
564 | - * @api |
|
565 | - */ |
|
566 | - public function count() |
|
567 | - { |
|
568 | - /** @var VidiDbBackend $backend */ |
|
569 | - $backend = GeneralUtility::makeInstance(VidiDbBackend::class, $this); |
|
570 | - return $backend->countResult(); |
|
571 | - } |
|
572 | - |
|
573 | - /** |
|
574 | - * Returns an "isEmpty" criterion used for matching objects against a query. |
|
575 | - * It matches if the multivalued property contains no values or is null. |
|
576 | - * |
|
577 | - * @param string $propertyName The name of the multivalued property to compare against |
|
578 | - * @throws NotImplementedException |
|
579 | - * @throws InvalidQueryException if used on a single-valued property |
|
580 | - * @api |
|
581 | - */ |
|
582 | - public function isEmpty($propertyName) |
|
583 | - { |
|
584 | - throw new NotImplementedException(__METHOD__); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * @return string |
|
589 | - */ |
|
590 | - public function getDistinct() |
|
591 | - { |
|
592 | - return $this->distinct; |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * @param string $distinct |
|
597 | - * @return $this |
|
598 | - */ |
|
599 | - public function setDistinct($distinct) |
|
600 | - { |
|
601 | - $this->distinct = $distinct; |
|
602 | - return $this; |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage |
|
607 | - * backend (database). |
|
608 | - * |
|
609 | - * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement |
|
610 | - * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement. |
|
611 | - * @return QueryInterface |
|
612 | - */ |
|
613 | - public function statement($statement, array $parameters = array()) |
|
614 | - { |
|
615 | - $this->statement = $this->qomFactory->statement($statement, $parameters); |
|
616 | - return $this; |
|
617 | - } |
|
618 | - |
|
619 | - /** |
|
620 | - * Returns the statement of this query. |
|
621 | - * |
|
622 | - * @return Statement |
|
623 | - */ |
|
624 | - public function getStatement() |
|
625 | - { |
|
626 | - return $this->statement; |
|
627 | - } |
|
628 | - |
|
629 | - /** |
|
630 | - * Returns whether the current mode is Backend. |
|
631 | - * |
|
632 | - * @return bool |
|
633 | - */ |
|
634 | - protected function isBackendMode() |
|
635 | - { |
|
636 | - return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend(); |
|
637 | - } |
|
638 | - |
|
639 | - /** |
|
640 | - * @return string |
|
641 | - */ |
|
642 | - public function getSourceFieldName() |
|
643 | - { |
|
644 | - return $this->sourceFieldName; |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * @param string $sourceFieldName |
|
649 | - * @return $this |
|
650 | - */ |
|
651 | - public function setSourceFieldName($sourceFieldName) |
|
652 | - { |
|
653 | - $this->sourceFieldName = $sourceFieldName; |
|
654 | - return $this; |
|
655 | - } |
|
656 | - |
|
657 | - public function setQuerySettings(QuerySettingsInterface $querySettings) |
|
658 | - { |
|
659 | - $this->typo3QuerySettings = $querySettings; |
|
660 | - } |
|
661 | - |
|
662 | - public function getQuerySettings() |
|
663 | - { |
|
664 | - return $this->typo3QuerySettings; |
|
665 | - } |
|
44 | + /** |
|
45 | + * An inner join. |
|
46 | + */ |
|
47 | + const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner'; |
|
48 | + |
|
49 | + /** |
|
50 | + * A left-outer join. |
|
51 | + */ |
|
52 | + const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter'; |
|
53 | + |
|
54 | + /** |
|
55 | + * A right-outer join. |
|
56 | + */ |
|
57 | + const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter'; |
|
58 | + |
|
59 | + /** |
|
60 | + * Charset of strings in QOM |
|
61 | + */ |
|
62 | + const CHARSET = 'utf-8'; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + protected $sourceFieldName; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var string |
|
71 | + */ |
|
72 | + protected $type; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var PersistenceManagerInterface |
|
76 | + */ |
|
77 | + protected $persistenceManager; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var QueryObjectModelFactory |
|
81 | + */ |
|
82 | + protected $qomFactory; |
|
83 | + |
|
84 | + /** |
|
85 | + * @var SourceInterface |
|
86 | + */ |
|
87 | + protected $source; |
|
88 | + |
|
89 | + /** |
|
90 | + * @var ConstraintInterface |
|
91 | + */ |
|
92 | + protected $constraint; |
|
93 | + |
|
94 | + /** |
|
95 | + * @var Statement |
|
96 | + */ |
|
97 | + protected $statement; |
|
98 | + |
|
99 | + /** |
|
100 | + * @var array |
|
101 | + */ |
|
102 | + protected $orderings = []; |
|
103 | + |
|
104 | + /** |
|
105 | + * @var int |
|
106 | + */ |
|
107 | + protected $limit; |
|
108 | + |
|
109 | + /** |
|
110 | + * @var int |
|
111 | + */ |
|
112 | + protected $offset; |
|
113 | + |
|
114 | + /** |
|
115 | + * Apply DISTINCT upon property. |
|
116 | + * |
|
117 | + * @var string |
|
118 | + */ |
|
119 | + protected $distinct; |
|
120 | + |
|
121 | + /** |
|
122 | + * The query settings. |
|
123 | + * |
|
124 | + * @var Typo3QuerySettings |
|
125 | + */ |
|
126 | + public Typo3QuerySettings $typo3QuerySettings; |
|
127 | + |
|
128 | + /** |
|
129 | + * Constructs a query object working on the given class name |
|
130 | + * |
|
131 | + * @param string $type |
|
132 | + */ |
|
133 | + public function __construct($type) |
|
134 | + { |
|
135 | + $this->type = $type; |
|
136 | + $this->persistenceManager = GeneralUtility::makeInstance(PersistenceManagerInterface::class); |
|
137 | + $this->qomFactory = GeneralUtility::makeInstance(QueryObjectModelFactory::class); |
|
138 | + } |
|
139 | + |
|
140 | + public function injectTypo3QuerySettings(Typo3QuerySettings $querySettings): void |
|
141 | + { |
|
142 | + $this->typo3QuerySettings = $querySettings; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Sets the Query Settings. These Query settings must match the settings expected by |
|
147 | + * the specific Storage Backend. |
|
148 | + * |
|
149 | + * @param QuerySettingsInterface $typo3QuerySettings The Query Settings |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + public function setTypo3QuerySettings(QuerySettingsInterface $typo3QuerySettings) |
|
153 | + { |
|
154 | + $this->typo3QuerySettings = $typo3QuerySettings; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Returns the Query Settings. |
|
159 | + * |
|
160 | + * @throws \Exception |
|
161 | + * @return Typo3QuerySettings $querySettings The Query Settings |
|
162 | + * @api This method is not part of FLOW3 API |
|
163 | + */ |
|
164 | + public function getTypo3QuerySettings() |
|
165 | + { |
|
166 | + if (!$this->typo3QuerySettings instanceof QuerySettingsInterface) { |
|
167 | + throw new Exception('Tried to get the query settings without setting them before.', 1248689115); |
|
168 | + } |
|
169 | + |
|
170 | + // Apply possible settings to the query. |
|
171 | + if ($this->isBackendMode()) { |
|
172 | + /** @var BackendConfigurationManager $backendConfigurationManager */ |
|
173 | + $backendConfigurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class); |
|
174 | + $configuration = $backendConfigurationManager->getTypoScriptSetup(); |
|
175 | + $querySettings = array('respectSysLanguage'); |
|
176 | + foreach ($querySettings as $setting) { |
|
177 | + if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) { |
|
178 | + $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting]; |
|
179 | + ObjectAccess::setProperty($this->typo3QuerySettings, $setting, $value); |
|
180 | + } |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + return $this->typo3QuerySettings; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Returns the type this query cares for. |
|
189 | + * |
|
190 | + * @return string |
|
191 | + * @api |
|
192 | + */ |
|
193 | + public function getType() |
|
194 | + { |
|
195 | + return $this->type; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Sets the source to fetch the result from |
|
200 | + * |
|
201 | + * @param SourceInterface $source |
|
202 | + */ |
|
203 | + public function setSource(SourceInterface $source) |
|
204 | + { |
|
205 | + $this->source = $source; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Returns the selectorn name or an empty string, if the source is not a selector |
|
210 | + * TODO This has to be checked at another place |
|
211 | + * |
|
212 | + * @return string The selector name |
|
213 | + */ |
|
214 | + protected function getSelectorName() |
|
215 | + { |
|
216 | + if ($this->getSource() instanceof SelectorInterface) { |
|
217 | + return $this->source->getSelectorName(); |
|
218 | + } else { |
|
219 | + return ''; |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Gets the node-tuple source for this query. |
|
225 | + * |
|
226 | + * @return SourceInterface the node-tuple source; non-null |
|
227 | + */ |
|
228 | + public function getSource() |
|
229 | + { |
|
230 | + if ($this->source === null) { |
|
231 | + $this->source = $this->qomFactory->selector($this->getType()); |
|
232 | + } |
|
233 | + return $this->source; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Executes the query against the database and returns the result |
|
238 | + * |
|
239 | + * @return QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is true |
|
240 | + * @api |
|
241 | + */ |
|
242 | + public function execute($returnRawQueryResult = false) |
|
243 | + { |
|
244 | + /** @var VidiDbBackend $backend */ |
|
245 | + $backend = GeneralUtility::makeInstance(VidiDbBackend::class, $this); |
|
246 | + return $backend->fetchResult(); |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Sets the property names to order the result by. Expected like this: |
|
251 | + * array( |
|
252 | + * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
253 | + * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
254 | + * ) |
|
255 | + * where 'foo' and 'bar' are property names. |
|
256 | + * |
|
257 | + * @param array $orderings The property names to order by |
|
258 | + * @return QueryInterface |
|
259 | + * @api |
|
260 | + */ |
|
261 | + public function setOrderings(array $orderings) |
|
262 | + { |
|
263 | + $this->orderings = $orderings; |
|
264 | + return $this; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Returns the property names to order the result by. Like this: |
|
269 | + * array( |
|
270 | + * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
271 | + * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
272 | + * ) |
|
273 | + * |
|
274 | + * @return array |
|
275 | + */ |
|
276 | + public function getOrderings() |
|
277 | + { |
|
278 | + return $this->orderings; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Sets the maximum size of the result set to limit. Returns $this to allow |
|
283 | + * for chaining (fluid interface) |
|
284 | + * |
|
285 | + * @param integer $limit |
|
286 | + * @throws \InvalidArgumentException |
|
287 | + * @return QueryInterface |
|
288 | + * @api |
|
289 | + */ |
|
290 | + public function setLimit($limit) |
|
291 | + { |
|
292 | + if (!is_int($limit) || $limit < 1) { |
|
293 | + throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870); |
|
294 | + } |
|
295 | + $this->limit = $limit; |
|
296 | + return $this; |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Resets a previously set maximum size of the result set. Returns $this to allow |
|
301 | + * for chaining (fluid interface) |
|
302 | + * |
|
303 | + * @return QueryInterface |
|
304 | + * @api |
|
305 | + */ |
|
306 | + public function unsetLimit() |
|
307 | + { |
|
308 | + unset($this->limit); |
|
309 | + return $this; |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Returns the maximum size of the result set to limit. |
|
314 | + * |
|
315 | + * @return integer |
|
316 | + * @api |
|
317 | + */ |
|
318 | + public function getLimit() |
|
319 | + { |
|
320 | + return $this->limit; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Sets the start offset of the result set to offset. Returns $this to |
|
325 | + * allow for chaining (fluid interface) |
|
326 | + * |
|
327 | + * @param integer $offset |
|
328 | + * @throws \InvalidArgumentException |
|
329 | + * @return QueryInterface |
|
330 | + * @api |
|
331 | + */ |
|
332 | + public function setOffset($offset) |
|
333 | + { |
|
334 | + if (!is_int($offset) || $offset < 0) { |
|
335 | + throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872); |
|
336 | + } |
|
337 | + $this->offset = $offset; |
|
338 | + return $this; |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Returns the start offset of the result set. |
|
343 | + * |
|
344 | + * @return integer |
|
345 | + * @api |
|
346 | + */ |
|
347 | + public function getOffset() |
|
348 | + { |
|
349 | + return $this->offset; |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * The constraint used to limit the result set. Returns $this to allow |
|
354 | + * for chaining (fluid interface) |
|
355 | + * |
|
356 | + * @param ConstraintInterface $constraint |
|
357 | + * @return QueryInterface |
|
358 | + * @api |
|
359 | + */ |
|
360 | + public function matching($constraint) |
|
361 | + { |
|
362 | + $this->constraint = $constraint; |
|
363 | + return $this; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Gets the constraint for this query. |
|
368 | + * |
|
369 | + * @return ConstraintInterface the constraint, or null if none |
|
370 | + * @api |
|
371 | + */ |
|
372 | + public function getConstraint() |
|
373 | + { |
|
374 | + return $this->constraint; |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND. |
|
379 | + * It also scepts a single array of constraints to be concatenated. |
|
380 | + * |
|
381 | + * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
382 | + * @throws InvalidNumberOfConstraintsException |
|
383 | + * @return AndInterface |
|
384 | + * @api |
|
385 | + */ |
|
386 | + public function logicalAnd($constraint1) |
|
387 | + { |
|
388 | + if (is_array($constraint1)) { |
|
389 | + $resultingConstraint = array_shift($constraint1); |
|
390 | + $constraints = $constraint1; |
|
391 | + } else { |
|
392 | + $constraints = func_get_args(); |
|
393 | + $resultingConstraint = array_shift($constraints); |
|
394 | + } |
|
395 | + if ($resultingConstraint === null) { |
|
396 | + throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500); |
|
397 | + } |
|
398 | + foreach ($constraints as $constraint) { |
|
399 | + $resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint); |
|
400 | + } |
|
401 | + return $resultingConstraint; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Performs a logical disjunction of the two given constraints |
|
406 | + * |
|
407 | + * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
408 | + * @throws InvalidNumberOfConstraintsException |
|
409 | + * @return OrInterface |
|
410 | + * @api |
|
411 | + */ |
|
412 | + public function logicalOr($constraint1) |
|
413 | + { |
|
414 | + if (is_array($constraint1)) { |
|
415 | + $resultingConstraint = array_shift($constraint1); |
|
416 | + $constraints = $constraint1; |
|
417 | + } else { |
|
418 | + $constraints = func_get_args(); |
|
419 | + $resultingConstraint = array_shift($constraints); |
|
420 | + } |
|
421 | + if ($resultingConstraint === null) { |
|
422 | + throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501); |
|
423 | + } |
|
424 | + foreach ($constraints as $constraint) { |
|
425 | + $resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint); |
|
426 | + } |
|
427 | + return $resultingConstraint; |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * Performs a logical negation of the given constraint |
|
432 | + * |
|
433 | + * @param ConstraintInterface $constraint Constraint to negate |
|
434 | + * @throws \RuntimeException |
|
435 | + * @return NotInterface |
|
436 | + * @api |
|
437 | + */ |
|
438 | + public function logicalNot(ConstraintInterface $constraint) |
|
439 | + { |
|
440 | + return $this->qomFactory->not($constraint); |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Returns an equals criterion used for matching objects against a query |
|
445 | + * |
|
446 | + * @param string $propertyName The name of the property to compare against |
|
447 | + * @param mixed $operand The value to compare with |
|
448 | + * @param boolean $caseSensitive Whether the equality test should be done case-sensitive |
|
449 | + * @return ComparisonInterface |
|
450 | + * @api |
|
451 | + */ |
|
452 | + public function equals($propertyName, $operand, $caseSensitive = true) |
|
453 | + { |
|
454 | + if (is_object($operand) || $caseSensitive) { |
|
455 | + $comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand); |
|
456 | + } else { |
|
457 | + $comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), QueryInterface::OPERATOR_EQUAL_TO, mb_strtolower($operand, \TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET)); |
|
458 | + } |
|
459 | + return $comparison; |
|
460 | + } |
|
461 | + |
|
462 | + /** |
|
463 | + * Returns a like criterion used for matching objects against a query |
|
464 | + * |
|
465 | + * @param string $propertyName The name of the property to compare against |
|
466 | + * @param mixed $operand The value to compare with |
|
467 | + * @param boolean $caseSensitive Whether the matching should be done case-sensitive |
|
468 | + * @return ComparisonInterface |
|
469 | + * @api |
|
470 | + */ |
|
471 | + public function like($propertyName, $operand, $caseSensitive = true) |
|
472 | + { |
|
473 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand); |
|
474 | + } |
|
475 | + |
|
476 | + /** |
|
477 | + * Returns a "contains" criterion used for matching objects against a query. |
|
478 | + * It matches if the multivalued property contains the given operand. |
|
479 | + * |
|
480 | + * @param string $propertyName The name of the (multivalued) property to compare against |
|
481 | + * @param mixed $operand The value to compare with |
|
482 | + * @return ComparisonInterface |
|
483 | + * @api |
|
484 | + */ |
|
485 | + public function contains($propertyName, $operand) |
|
486 | + { |
|
487 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand); |
|
488 | + } |
|
489 | + |
|
490 | + /** |
|
491 | + * Returns an "in" criterion used for matching objects against a query. It |
|
492 | + * matches if the property's value is contained in the multivalued operand. |
|
493 | + * |
|
494 | + * @param string $propertyName The name of the property to compare against |
|
495 | + * @param mixed $operand The value to compare with, multivalued |
|
496 | + * @throws UnexpectedTypeException |
|
497 | + * @return ComparisonInterface |
|
498 | + * @api |
|
499 | + */ |
|
500 | + public function in($propertyName, $operand) |
|
501 | + { |
|
502 | + if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) { |
|
503 | + throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095); |
|
504 | + } |
|
505 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand); |
|
506 | + } |
|
507 | + |
|
508 | + /** |
|
509 | + * Returns a less than criterion used for matching objects against a query |
|
510 | + * |
|
511 | + * @param string $propertyName The name of the property to compare against |
|
512 | + * @param mixed $operand The value to compare with |
|
513 | + * @return ComparisonInterface |
|
514 | + * @api |
|
515 | + */ |
|
516 | + public function lessThan($propertyName, $operand) |
|
517 | + { |
|
518 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand); |
|
519 | + } |
|
520 | + |
|
521 | + /** |
|
522 | + * Returns a less or equal than criterion used for matching objects against a query |
|
523 | + * |
|
524 | + * @param string $propertyName The name of the property to compare against |
|
525 | + * @param mixed $operand The value to compare with |
|
526 | + * @return ComparisonInterface |
|
527 | + * @api |
|
528 | + */ |
|
529 | + public function lessThanOrEqual($propertyName, $operand) |
|
530 | + { |
|
531 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand); |
|
532 | + } |
|
533 | + |
|
534 | + /** |
|
535 | + * Returns a greater than criterion used for matching objects against a query |
|
536 | + * |
|
537 | + * @param string $propertyName The name of the property to compare against |
|
538 | + * @param mixed $operand The value to compare with |
|
539 | + * @return ComparisonInterface |
|
540 | + * @api |
|
541 | + */ |
|
542 | + public function greaterThan($propertyName, $operand) |
|
543 | + { |
|
544 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand); |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * Returns a greater than or equal criterion used for matching objects against a query |
|
549 | + * |
|
550 | + * @param string $propertyName The name of the property to compare against |
|
551 | + * @param mixed $operand The value to compare with |
|
552 | + * @return ComparisonInterface |
|
553 | + * @api |
|
554 | + */ |
|
555 | + public function greaterThanOrEqual($propertyName, $operand) |
|
556 | + { |
|
557 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand); |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Returns the query result count. |
|
562 | + * |
|
563 | + * @return integer The query result count |
|
564 | + * @api |
|
565 | + */ |
|
566 | + public function count() |
|
567 | + { |
|
568 | + /** @var VidiDbBackend $backend */ |
|
569 | + $backend = GeneralUtility::makeInstance(VidiDbBackend::class, $this); |
|
570 | + return $backend->countResult(); |
|
571 | + } |
|
572 | + |
|
573 | + /** |
|
574 | + * Returns an "isEmpty" criterion used for matching objects against a query. |
|
575 | + * It matches if the multivalued property contains no values or is null. |
|
576 | + * |
|
577 | + * @param string $propertyName The name of the multivalued property to compare against |
|
578 | + * @throws NotImplementedException |
|
579 | + * @throws InvalidQueryException if used on a single-valued property |
|
580 | + * @api |
|
581 | + */ |
|
582 | + public function isEmpty($propertyName) |
|
583 | + { |
|
584 | + throw new NotImplementedException(__METHOD__); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * @return string |
|
589 | + */ |
|
590 | + public function getDistinct() |
|
591 | + { |
|
592 | + return $this->distinct; |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * @param string $distinct |
|
597 | + * @return $this |
|
598 | + */ |
|
599 | + public function setDistinct($distinct) |
|
600 | + { |
|
601 | + $this->distinct = $distinct; |
|
602 | + return $this; |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage |
|
607 | + * backend (database). |
|
608 | + * |
|
609 | + * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement |
|
610 | + * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement. |
|
611 | + * @return QueryInterface |
|
612 | + */ |
|
613 | + public function statement($statement, array $parameters = array()) |
|
614 | + { |
|
615 | + $this->statement = $this->qomFactory->statement($statement, $parameters); |
|
616 | + return $this; |
|
617 | + } |
|
618 | + |
|
619 | + /** |
|
620 | + * Returns the statement of this query. |
|
621 | + * |
|
622 | + * @return Statement |
|
623 | + */ |
|
624 | + public function getStatement() |
|
625 | + { |
|
626 | + return $this->statement; |
|
627 | + } |
|
628 | + |
|
629 | + /** |
|
630 | + * Returns whether the current mode is Backend. |
|
631 | + * |
|
632 | + * @return bool |
|
633 | + */ |
|
634 | + protected function isBackendMode() |
|
635 | + { |
|
636 | + return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend(); |
|
637 | + } |
|
638 | + |
|
639 | + /** |
|
640 | + * @return string |
|
641 | + */ |
|
642 | + public function getSourceFieldName() |
|
643 | + { |
|
644 | + return $this->sourceFieldName; |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * @param string $sourceFieldName |
|
649 | + * @return $this |
|
650 | + */ |
|
651 | + public function setSourceFieldName($sourceFieldName) |
|
652 | + { |
|
653 | + $this->sourceFieldName = $sourceFieldName; |
|
654 | + return $this; |
|
655 | + } |
|
656 | + |
|
657 | + public function setQuerySettings(QuerySettingsInterface $querySettings) |
|
658 | + { |
|
659 | + $this->typo3QuerySettings = $querySettings; |
|
660 | + } |
|
661 | + |
|
662 | + public function getQuerySettings() |
|
663 | + { |
|
664 | + return $this->typo3QuerySettings; |
|
665 | + } |
|
666 | 666 | } |
@@ -174,8 +174,8 @@ |
||
174 | 174 | $configuration = $backendConfigurationManager->getTypoScriptSetup(); |
175 | 175 | $querySettings = array('respectSysLanguage'); |
176 | 176 | foreach ($querySettings as $setting) { |
177 | - if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) { |
|
178 | - $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting]; |
|
177 | + if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type.'.'][$setting])) { |
|
178 | + $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type.'.'][$setting]; |
|
179 | 179 | ObjectAccess::setProperty($this->typo3QuerySettings, $setting, $value); |
180 | 180 | } |
181 | 181 | } |
@@ -21,109 +21,109 @@ |
||
21 | 21 | class FacetSuggestionService |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Retrieve possible suggestions for a field name |
|
26 | - * |
|
27 | - * @param string $fieldNameAndPath |
|
28 | - * @return array |
|
29 | - */ |
|
30 | - public function getSuggestions($fieldNameAndPath): array |
|
31 | - { |
|
32 | - $values = []; |
|
33 | - |
|
34 | - $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath); |
|
35 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
36 | - |
|
37 | - if (Tca::grid()->facet($fieldNameAndPath)->hasSuggestions()) { |
|
38 | - $values = Tca::grid()->facet($fieldNameAndPath)->getSuggestions(); |
|
39 | - } else if (Tca::table($dataType)->hasField($fieldName)) { |
|
40 | - |
|
41 | - if (Tca::table($dataType)->field($fieldName)->hasRelation()) { |
|
42 | - |
|
43 | - // Fetch the adequate repository |
|
44 | - $foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable(); |
|
45 | - $contentRepository = ContentRepositoryFactory::getInstance($foreignTable); |
|
46 | - $table = Tca::table($foreignTable); |
|
47 | - |
|
48 | - // Initialize the matcher object. |
|
49 | - $matcher = MatcherObjectFactory::getInstance()->getMatcher([], $foreignTable); |
|
50 | - |
|
51 | - $numberOfValues = $contentRepository->countBy($matcher); |
|
52 | - if ($numberOfValues <= $this->getLimit()) { |
|
53 | - |
|
54 | - $contents = $contentRepository->findBy($matcher); |
|
55 | - |
|
56 | - foreach ($contents as $content) { |
|
57 | - $values[] = array($content->getUid() => $content[$table->getLabelField()]); |
|
58 | - } |
|
59 | - } |
|
60 | - } elseif (!Tca::table($dataType)->field($fieldName)->isTextArea()) { // We don't want suggestion if field is text area. |
|
61 | - // Fetch the adequate repository |
|
62 | - /** @var ContentRepository $contentRepository */ |
|
63 | - $contentRepository = ContentRepositoryFactory::getInstance($dataType); |
|
64 | - |
|
65 | - // Initialize some objects related to the query |
|
66 | - $matcher = MatcherObjectFactory::getInstance()->getMatcher([], $dataType); |
|
67 | - |
|
68 | - // Count the number of objects. |
|
69 | - $numberOfValues = $contentRepository->countDistinctValues($fieldName, $matcher); |
|
70 | - |
|
71 | - // Only returns suggestion if there are not too many for the browser. |
|
72 | - if ($numberOfValues <= $this->getLimit()) { |
|
73 | - |
|
74 | - // Query the repository. |
|
75 | - $contents = $contentRepository->findDistinctValues($fieldName, $matcher); |
|
76 | - |
|
77 | - foreach ($contents as $content) { |
|
78 | - |
|
79 | - $value = $content[$fieldName]; |
|
80 | - $label = $content[$fieldName]; |
|
81 | - if (Tca::table($dataType)->field($fieldName)->isSelect()) { |
|
82 | - $label = Tca::table($dataType)->field($fieldName)->getLabelForItem($value); |
|
83 | - } |
|
84 | - |
|
85 | - $values[] = $label; |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
90 | - return $values; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Return from settings the suggestion limit. |
|
95 | - * |
|
96 | - * @return int |
|
97 | - */ |
|
98 | - protected function getLimit(): int |
|
99 | - { |
|
100 | - $settings = $this->getSettings(); |
|
101 | - $suggestionLimit = (int)$settings['suggestionLimit']; |
|
102 | - if ($suggestionLimit <= 0) { |
|
103 | - $suggestionLimit = 1000; |
|
104 | - } |
|
105 | - return $suggestionLimit; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @return FieldPathResolver|object |
|
110 | - */ |
|
111 | - protected function getFieldPathResolver() |
|
112 | - { |
|
113 | - return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Returns the module settings. |
|
118 | - * |
|
119 | - * @return array |
|
120 | - */ |
|
121 | - protected function getSettings() |
|
122 | - { |
|
123 | - /** @var BackendConfigurationManager $backendConfigurationManager */ |
|
124 | - $backendConfigurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class); |
|
125 | - $configuration = $backendConfigurationManager->getTypoScriptSetup(); |
|
126 | - return $configuration['module.']['tx_vidi.']['settings.']; |
|
127 | - } |
|
24 | + /** |
|
25 | + * Retrieve possible suggestions for a field name |
|
26 | + * |
|
27 | + * @param string $fieldNameAndPath |
|
28 | + * @return array |
|
29 | + */ |
|
30 | + public function getSuggestions($fieldNameAndPath): array |
|
31 | + { |
|
32 | + $values = []; |
|
33 | + |
|
34 | + $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath); |
|
35 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
36 | + |
|
37 | + if (Tca::grid()->facet($fieldNameAndPath)->hasSuggestions()) { |
|
38 | + $values = Tca::grid()->facet($fieldNameAndPath)->getSuggestions(); |
|
39 | + } else if (Tca::table($dataType)->hasField($fieldName)) { |
|
40 | + |
|
41 | + if (Tca::table($dataType)->field($fieldName)->hasRelation()) { |
|
42 | + |
|
43 | + // Fetch the adequate repository |
|
44 | + $foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable(); |
|
45 | + $contentRepository = ContentRepositoryFactory::getInstance($foreignTable); |
|
46 | + $table = Tca::table($foreignTable); |
|
47 | + |
|
48 | + // Initialize the matcher object. |
|
49 | + $matcher = MatcherObjectFactory::getInstance()->getMatcher([], $foreignTable); |
|
50 | + |
|
51 | + $numberOfValues = $contentRepository->countBy($matcher); |
|
52 | + if ($numberOfValues <= $this->getLimit()) { |
|
53 | + |
|
54 | + $contents = $contentRepository->findBy($matcher); |
|
55 | + |
|
56 | + foreach ($contents as $content) { |
|
57 | + $values[] = array($content->getUid() => $content[$table->getLabelField()]); |
|
58 | + } |
|
59 | + } |
|
60 | + } elseif (!Tca::table($dataType)->field($fieldName)->isTextArea()) { // We don't want suggestion if field is text area. |
|
61 | + // Fetch the adequate repository |
|
62 | + /** @var ContentRepository $contentRepository */ |
|
63 | + $contentRepository = ContentRepositoryFactory::getInstance($dataType); |
|
64 | + |
|
65 | + // Initialize some objects related to the query |
|
66 | + $matcher = MatcherObjectFactory::getInstance()->getMatcher([], $dataType); |
|
67 | + |
|
68 | + // Count the number of objects. |
|
69 | + $numberOfValues = $contentRepository->countDistinctValues($fieldName, $matcher); |
|
70 | + |
|
71 | + // Only returns suggestion if there are not too many for the browser. |
|
72 | + if ($numberOfValues <= $this->getLimit()) { |
|
73 | + |
|
74 | + // Query the repository. |
|
75 | + $contents = $contentRepository->findDistinctValues($fieldName, $matcher); |
|
76 | + |
|
77 | + foreach ($contents as $content) { |
|
78 | + |
|
79 | + $value = $content[$fieldName]; |
|
80 | + $label = $content[$fieldName]; |
|
81 | + if (Tca::table($dataType)->field($fieldName)->isSelect()) { |
|
82 | + $label = Tca::table($dataType)->field($fieldName)->getLabelForItem($value); |
|
83 | + } |
|
84 | + |
|
85 | + $values[] = $label; |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | + return $values; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Return from settings the suggestion limit. |
|
95 | + * |
|
96 | + * @return int |
|
97 | + */ |
|
98 | + protected function getLimit(): int |
|
99 | + { |
|
100 | + $settings = $this->getSettings(); |
|
101 | + $suggestionLimit = (int)$settings['suggestionLimit']; |
|
102 | + if ($suggestionLimit <= 0) { |
|
103 | + $suggestionLimit = 1000; |
|
104 | + } |
|
105 | + return $suggestionLimit; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @return FieldPathResolver|object |
|
110 | + */ |
|
111 | + protected function getFieldPathResolver() |
|
112 | + { |
|
113 | + return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Returns the module settings. |
|
118 | + * |
|
119 | + * @return array |
|
120 | + */ |
|
121 | + protected function getSettings() |
|
122 | + { |
|
123 | + /** @var BackendConfigurationManager $backendConfigurationManager */ |
|
124 | + $backendConfigurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class); |
|
125 | + $configuration = $backendConfigurationManager->getTypoScriptSetup(); |
|
126 | + return $configuration['module.']['tx_vidi.']['settings.']; |
|
127 | + } |
|
128 | 128 | |
129 | 129 | } |
@@ -19,70 +19,70 @@ |
||
19 | 19 | class FindViewHelper extends AbstractContentViewHelper |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @return void |
|
24 | - * @throws Exception |
|
25 | - */ |
|
26 | - public function initializeArguments() |
|
27 | - { |
|
28 | - parent::initializeArguments(); |
|
29 | - |
|
30 | - $this->registerArgument('orderings', 'array', 'Key / value array to be used for ordering. The key corresponds to a field name. The value can be "DESC" or "ASC".', false, array()); |
|
31 | - $this->registerArgument('limit', 'int', 'Limit the number of records being fetched.', false, 0); |
|
32 | - $this->registerArgument('offset', 'int', 'Where to start the list of records.', false, 0); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Fetch and returns a list of content objects. |
|
37 | - * |
|
38 | - * @return array |
|
39 | - * @throws \BadMethodCallException |
|
40 | - */ |
|
41 | - public function render() |
|
42 | - { |
|
43 | - $selectionIdentifier = (int)$this->arguments['selection']; |
|
44 | - |
|
45 | - if ($selectionIdentifier > 0) { |
|
46 | - |
|
47 | - /** @var SelectionRepository $selectionRepository */ |
|
48 | - $selectionRepository = GeneralUtility::makeInstance(SelectionRepository::class); |
|
49 | - |
|
50 | - /** @var Selection $selection */ |
|
51 | - $selection = $selectionRepository->findByUid($selectionIdentifier); |
|
52 | - $matches = json_decode($selection->getQuery(), true); |
|
53 | - $dataType = $selection->getDataType(); |
|
54 | - } else { |
|
55 | - $dataType = $this->arguments['type']; |
|
56 | - if (!empty($this->arguments['dataType'])) { |
|
57 | - print 'Sorry to be so rude! There is something to change in the View Helper "v:find". Please replace attribute "dataType" by "type". This is a shorter syntax...'; |
|
58 | - exit(); |
|
59 | - } |
|
60 | - $matches = $this->replacesAliases($this->arguments['matches']); |
|
61 | - } |
|
62 | - |
|
63 | - $orderings = $this->replacesAliases($this->arguments['orderings']); |
|
64 | - $limit = $this->arguments['limit']; |
|
65 | - $offset = $this->arguments['offset']; |
|
66 | - $ignoreEnableFields = $this->arguments['ignoreEnableFields']; |
|
67 | - |
|
68 | - $querySignature = $this->getQuerySignature($dataType, $matches, $orderings, $limit, $offset); |
|
69 | - |
|
70 | - $resultSet = $this->getResultSetStorage()->get($querySignature); |
|
71 | - if (!$resultSet) { |
|
72 | - $matcher = $this->getMatcher($dataType, $matches); |
|
73 | - $orderings = $this->getOrder($dataType, $orderings); |
|
74 | - |
|
75 | - $this->emitPostProcessLimitSignal($dataType, $limit); |
|
76 | - $this->emitPostProcessOffsetSignal($dataType, $offset); |
|
77 | - |
|
78 | - $contentRepository = ContentRepositoryFactory::getInstance($dataType); |
|
79 | - $contentRepository->setDefaultQuerySettings($this->getDefaultQuerySettings($ignoreEnableFields)); |
|
80 | - |
|
81 | - $resultSet = $contentRepository->findBy($matcher, $orderings, $limit, $offset); |
|
82 | - $this->getResultSetStorage()->set($querySignature, $resultSet); // store the result set for performance sake. |
|
83 | - } |
|
84 | - |
|
85 | - return $resultSet; |
|
86 | - } |
|
22 | + /** |
|
23 | + * @return void |
|
24 | + * @throws Exception |
|
25 | + */ |
|
26 | + public function initializeArguments() |
|
27 | + { |
|
28 | + parent::initializeArguments(); |
|
29 | + |
|
30 | + $this->registerArgument('orderings', 'array', 'Key / value array to be used for ordering. The key corresponds to a field name. The value can be "DESC" or "ASC".', false, array()); |
|
31 | + $this->registerArgument('limit', 'int', 'Limit the number of records being fetched.', false, 0); |
|
32 | + $this->registerArgument('offset', 'int', 'Where to start the list of records.', false, 0); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Fetch and returns a list of content objects. |
|
37 | + * |
|
38 | + * @return array |
|
39 | + * @throws \BadMethodCallException |
|
40 | + */ |
|
41 | + public function render() |
|
42 | + { |
|
43 | + $selectionIdentifier = (int)$this->arguments['selection']; |
|
44 | + |
|
45 | + if ($selectionIdentifier > 0) { |
|
46 | + |
|
47 | + /** @var SelectionRepository $selectionRepository */ |
|
48 | + $selectionRepository = GeneralUtility::makeInstance(SelectionRepository::class); |
|
49 | + |
|
50 | + /** @var Selection $selection */ |
|
51 | + $selection = $selectionRepository->findByUid($selectionIdentifier); |
|
52 | + $matches = json_decode($selection->getQuery(), true); |
|
53 | + $dataType = $selection->getDataType(); |
|
54 | + } else { |
|
55 | + $dataType = $this->arguments['type']; |
|
56 | + if (!empty($this->arguments['dataType'])) { |
|
57 | + print 'Sorry to be so rude! There is something to change in the View Helper "v:find". Please replace attribute "dataType" by "type". This is a shorter syntax...'; |
|
58 | + exit(); |
|
59 | + } |
|
60 | + $matches = $this->replacesAliases($this->arguments['matches']); |
|
61 | + } |
|
62 | + |
|
63 | + $orderings = $this->replacesAliases($this->arguments['orderings']); |
|
64 | + $limit = $this->arguments['limit']; |
|
65 | + $offset = $this->arguments['offset']; |
|
66 | + $ignoreEnableFields = $this->arguments['ignoreEnableFields']; |
|
67 | + |
|
68 | + $querySignature = $this->getQuerySignature($dataType, $matches, $orderings, $limit, $offset); |
|
69 | + |
|
70 | + $resultSet = $this->getResultSetStorage()->get($querySignature); |
|
71 | + if (!$resultSet) { |
|
72 | + $matcher = $this->getMatcher($dataType, $matches); |
|
73 | + $orderings = $this->getOrder($dataType, $orderings); |
|
74 | + |
|
75 | + $this->emitPostProcessLimitSignal($dataType, $limit); |
|
76 | + $this->emitPostProcessOffsetSignal($dataType, $offset); |
|
77 | + |
|
78 | + $contentRepository = ContentRepositoryFactory::getInstance($dataType); |
|
79 | + $contentRepository->setDefaultQuerySettings($this->getDefaultQuerySettings($ignoreEnableFields)); |
|
80 | + |
|
81 | + $resultSet = $contentRepository->findBy($matcher, $orderings, $limit, $offset); |
|
82 | + $this->getResultSetStorage()->set($querySignature, $resultSet); // store the result set for performance sake. |
|
83 | + } |
|
84 | + |
|
85 | + return $resultSet; |
|
86 | + } |
|
87 | 87 | |
88 | 88 | } |
@@ -18,57 +18,57 @@ |
||
18 | 18 | */ |
19 | 19 | class ComponentsViewHelper extends AbstractViewHelper |
20 | 20 | { |
21 | - /** |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function initializeArguments() |
|
25 | - { |
|
26 | - $this->registerArgument('part', 'string', 'Template part', true); |
|
27 | - } |
|
21 | + /** |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function initializeArguments() |
|
25 | + { |
|
26 | + $this->registerArgument('part', 'string', 'Template part', true); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Escapes special characters with their escaped counterparts as needed using PHPs strip_tags() function. |
|
31 | - * |
|
32 | - * @return mixed |
|
33 | - */ |
|
34 | - public function render() |
|
35 | - { |
|
36 | - return static::renderStatic( |
|
37 | - $this->arguments, |
|
38 | - $this->buildRenderChildrenClosure(), |
|
39 | - $this->renderingContext |
|
40 | - ); |
|
41 | - } |
|
29 | + /** |
|
30 | + * Escapes special characters with their escaped counterparts as needed using PHPs strip_tags() function. |
|
31 | + * |
|
32 | + * @return mixed |
|
33 | + */ |
|
34 | + public function render() |
|
35 | + { |
|
36 | + return static::renderStatic( |
|
37 | + $this->arguments, |
|
38 | + $this->buildRenderChildrenClosure(), |
|
39 | + $this->renderingContext |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Applies strip_tags() on the specified value. |
|
45 | - * |
|
46 | - * @param array $arguments |
|
47 | - * @param \Closure $renderChildrenClosure |
|
48 | - * @param RenderingContextInterface $renderingContext |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) |
|
52 | - { |
|
53 | - /** @var ModuleLoader $moduleLoader */ |
|
54 | - $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
43 | + /** |
|
44 | + * Applies strip_tags() on the specified value. |
|
45 | + * |
|
46 | + * @param array $arguments |
|
47 | + * @param \Closure $renderChildrenClosure |
|
48 | + * @param RenderingContextInterface $renderingContext |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) |
|
52 | + { |
|
53 | + /** @var ModuleLoader $moduleLoader */ |
|
54 | + $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
55 | 55 | |
56 | - $part = $arguments['part']; |
|
56 | + $part = $arguments['part']; |
|
57 | 57 | |
58 | - $getComponents = 'get' . ucfirst($part) . 'Components'; |
|
59 | - $components = $moduleLoader->$getComponents(); |
|
58 | + $getComponents = 'get' . ucfirst($part) . 'Components'; |
|
59 | + $components = $moduleLoader->$getComponents(); |
|
60 | 60 | |
61 | - $result = ''; |
|
62 | - foreach ($components as $component) { |
|
63 | - $viewHelper = GeneralUtility::makeInstance($component); |
|
61 | + $result = ''; |
|
62 | + foreach ($components as $component) { |
|
63 | + $viewHelper = GeneralUtility::makeInstance($component); |
|
64 | 64 | |
65 | - // Get possible arguments but remove first one. |
|
66 | - $arguments = func_get_args(); |
|
67 | - array_shift($arguments); |
|
68 | - $result .= call_user_func_array(array($viewHelper, 'render'), $arguments); |
|
69 | - } |
|
65 | + // Get possible arguments but remove first one. |
|
66 | + $arguments = func_get_args(); |
|
67 | + array_shift($arguments); |
|
68 | + $result .= call_user_func_array(array($viewHelper, 'render'), $arguments); |
|
69 | + } |
|
70 | 70 | |
71 | - return $result; |
|
72 | - } |
|
71 | + return $result; |
|
72 | + } |
|
73 | 73 | |
74 | 74 | } |
@@ -55,7 +55,7 @@ |
||
55 | 55 | |
56 | 56 | $part = $arguments['part']; |
57 | 57 | |
58 | - $getComponents = 'get' . ucfirst($part) . 'Components'; |
|
58 | + $getComponents = 'get'.ucfirst($part).'Components'; |
|
59 | 59 | $components = $moduleLoader->$getComponents(); |
60 | 60 | |
61 | 61 | $result = ''; |
@@ -20,89 +20,89 @@ |
||
20 | 20 | class TcaGridAspect implements TableConfigurationPostProcessingHookInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Scans each data type of the TCA and add a Grid TCA if missing. |
|
25 | - * |
|
26 | - * @return array |
|
27 | - */ |
|
28 | - public function processData() |
|
29 | - { |
|
30 | - $configuration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('vidi'); |
|
23 | + /** |
|
24 | + * Scans each data type of the TCA and add a Grid TCA if missing. |
|
25 | + * |
|
26 | + * @return array |
|
27 | + */ |
|
28 | + public function processData() |
|
29 | + { |
|
30 | + $configuration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('vidi'); |
|
31 | 31 | |
32 | - $dataTypes = GeneralUtility::trimExplode(',', $configuration['data_types'], true); |
|
32 | + $dataTypes = GeneralUtility::trimExplode(',', $configuration['data_types'], true); |
|
33 | 33 | |
34 | - if (ExtensionManagementUtility::isLoaded('vidi_frontend')) { |
|
34 | + if (ExtensionManagementUtility::isLoaded('vidi_frontend')) { |
|
35 | 35 | |
36 | - $extendedConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('vidi_frontend'); |
|
37 | - $vidiFrontendContentTypes = GeneralUtility::trimExplode(',', $extendedConfiguration['content_types'], true); |
|
38 | - $extendedDataTypes = array_merge($dataTypes, $vidiFrontendContentTypes); |
|
39 | - $dataTypes = array_unique($extendedDataTypes); |
|
40 | - } |
|
36 | + $extendedConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('vidi_frontend'); |
|
37 | + $vidiFrontendContentTypes = GeneralUtility::trimExplode(',', $extendedConfiguration['content_types'], true); |
|
38 | + $extendedDataTypes = array_merge($dataTypes, $vidiFrontendContentTypes); |
|
39 | + $dataTypes = array_unique($extendedDataTypes); |
|
40 | + } |
|
41 | 41 | |
42 | - foreach ($dataTypes as $dataType) { |
|
43 | - $this->ensureMinimumTcaForGrid($dataType); |
|
44 | - } |
|
42 | + foreach ($dataTypes as $dataType) { |
|
43 | + $this->ensureMinimumTcaForGrid($dataType); |
|
44 | + } |
|
45 | 45 | |
46 | - return array($GLOBALS['TCA']); |
|
47 | - } |
|
46 | + return array($GLOBALS['TCA']); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param string $dataType |
|
51 | - */ |
|
52 | - protected function ensureMinimumTcaForGrid($dataType) |
|
53 | - { |
|
54 | - $labelField = $this->getLabelField($dataType); |
|
55 | - if (empty($GLOBALS['TCA'][$dataType]['grid'])) { |
|
56 | - $GLOBALS['TCA'][$dataType]['grid'] = []; |
|
57 | - } |
|
49 | + /** |
|
50 | + * @param string $dataType |
|
51 | + */ |
|
52 | + protected function ensureMinimumTcaForGrid($dataType) |
|
53 | + { |
|
54 | + $labelField = $this->getLabelField($dataType); |
|
55 | + if (empty($GLOBALS['TCA'][$dataType]['grid'])) { |
|
56 | + $GLOBALS['TCA'][$dataType]['grid'] = []; |
|
57 | + } |
|
58 | 58 | |
59 | - if (empty($GLOBALS['TCA'][$dataType]['grid']['facets'])) { |
|
60 | - $GLOBALS['TCA'][$dataType]['grid']['facets'] = [ |
|
61 | - 'uid', |
|
62 | - $labelField, |
|
63 | - ]; |
|
64 | - } |
|
59 | + if (empty($GLOBALS['TCA'][$dataType]['grid']['facets'])) { |
|
60 | + $GLOBALS['TCA'][$dataType]['grid']['facets'] = [ |
|
61 | + 'uid', |
|
62 | + $labelField, |
|
63 | + ]; |
|
64 | + } |
|
65 | 65 | |
66 | - if (empty($GLOBALS['TCA'][$dataType]['grid']['columns'])) { |
|
67 | - $GLOBALS['TCA'][$dataType]['grid']['columns'] = [ |
|
68 | - '__checkbox' => [ |
|
69 | - 'renderer' => CheckBoxRenderer::class, |
|
70 | - ], |
|
71 | - 'uid' => [ |
|
72 | - 'visible' => false, |
|
73 | - 'label' => '', |
|
74 | - 'width' => '5px', |
|
75 | - ], |
|
76 | - $labelField => [ |
|
77 | - 'editable' => true, |
|
78 | - ], |
|
79 | - '__buttons' => [ |
|
80 | - 'renderer' => ButtonGroupRenderer::class, |
|
81 | - ], |
|
82 | - ]; |
|
83 | - } |
|
84 | - } |
|
66 | + if (empty($GLOBALS['TCA'][$dataType]['grid']['columns'])) { |
|
67 | + $GLOBALS['TCA'][$dataType]['grid']['columns'] = [ |
|
68 | + '__checkbox' => [ |
|
69 | + 'renderer' => CheckBoxRenderer::class, |
|
70 | + ], |
|
71 | + 'uid' => [ |
|
72 | + 'visible' => false, |
|
73 | + 'label' => '', |
|
74 | + 'width' => '5px', |
|
75 | + ], |
|
76 | + $labelField => [ |
|
77 | + 'editable' => true, |
|
78 | + ], |
|
79 | + '__buttons' => [ |
|
80 | + 'renderer' => ButtonGroupRenderer::class, |
|
81 | + ], |
|
82 | + ]; |
|
83 | + } |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Get the label name of table name. |
|
88 | - * |
|
89 | - * @param string $dataType |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - protected function getLabelField($dataType) |
|
93 | - { |
|
94 | - return $GLOBALS['TCA'][$dataType]['ctrl']['label']; |
|
95 | - } |
|
86 | + /** |
|
87 | + * Get the label name of table name. |
|
88 | + * |
|
89 | + * @param string $dataType |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + protected function getLabelField($dataType) |
|
93 | + { |
|
94 | + return $GLOBALS['TCA'][$dataType]['ctrl']['label']; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Tell whether the table has a label field. |
|
99 | - * |
|
100 | - * @param string $dataType |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - protected function hasLabelField($dataType) |
|
104 | - { |
|
105 | - return isset($GLOBALS['TCA'][$dataType]['ctrl']['label']); |
|
106 | - } |
|
97 | + /** |
|
98 | + * Tell whether the table has a label field. |
|
99 | + * |
|
100 | + * @param string $dataType |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + protected function hasLabelField($dataType) |
|
104 | + { |
|
105 | + return isset($GLOBALS['TCA'][$dataType]['ctrl']['label']); |
|
106 | + } |
|
107 | 107 | |
108 | 108 | } |
@@ -24,134 +24,134 @@ |
||
24 | 24 | class Tca implements SingletonInterface, TcaServiceInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Fields that are considered as system. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - static protected $systemFields = array( |
|
33 | - 'uid', |
|
34 | - 'pid', |
|
35 | - 'tstamp', |
|
36 | - 'crdate', |
|
37 | - 'deleted', |
|
38 | - 'hidden', |
|
39 | - 'sys_language_uid', |
|
40 | - 'l18n_parent', |
|
41 | - 'l18n_diffsource', |
|
42 | - 't3ver_oid', |
|
43 | - 't3ver_id', |
|
44 | - 't3ver_wsid', |
|
45 | - 't3ver_label', |
|
46 | - 't3ver_state', |
|
47 | - 't3ver_stage', |
|
48 | - 't3ver_count', |
|
49 | - 't3ver_tstamp', |
|
50 | - 't3_origuid', |
|
51 | - ); |
|
52 | - |
|
53 | - /** |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - static protected $instances; |
|
57 | - |
|
58 | - /** |
|
59 | - * Returns a class instance of a corresponding TCA service. |
|
60 | - * If the class instance does not exist, create one. |
|
61 | - * |
|
62 | - * @throws NotExistingClassException |
|
63 | - * @param string $dataType |
|
64 | - * @param string $serviceType |
|
65 | - * @return TcaServiceInterface |
|
66 | - * @throws InvalidKeyInArrayException |
|
67 | - * @throws \InvalidArgumentException |
|
68 | - */ |
|
69 | - static protected function getService($dataType, $serviceType) |
|
70 | - { |
|
71 | - if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend() && empty($dataType)) { |
|
72 | - |
|
73 | - /** @var ModuleLoader $moduleLoader */ |
|
74 | - $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
75 | - $dataType = $moduleLoader->getDataType(); |
|
76 | - } |
|
77 | - |
|
78 | - if (empty(self::$instances[$dataType][$serviceType])) { |
|
79 | - $className = sprintf('Fab\Vidi\Tca\%sService', ucfirst($serviceType)); |
|
80 | - |
|
81 | - // Signal to pre-process the TCA of the given $dataType. |
|
82 | - self::emitPreProcessTcaSignal($dataType, $serviceType); |
|
83 | - |
|
84 | - $instance = GeneralUtility::makeInstance($className, $dataType, $serviceType); |
|
85 | - self::$instances[$dataType][$serviceType] = $instance; |
|
86 | - } |
|
87 | - return self::$instances[$dataType][$serviceType]; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Returns a "grid" service instance. |
|
92 | - * |
|
93 | - * @param string|Content $tableNameOrContentObject |
|
94 | - * @return GridService |
|
95 | - * @throws NotExistingClassException |
|
96 | - */ |
|
97 | - static public function grid($tableNameOrContentObject = '') |
|
98 | - { |
|
99 | - $tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject; |
|
100 | - return self::getService($tableName, self::TYPE_GRID); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Returns a "table" service instance ("ctrl" part of the TCA). |
|
105 | - * |
|
106 | - * @param string|Content $tableNameOrContentObject |
|
107 | - * @return TableService |
|
108 | - * @throws NotExistingClassException |
|
109 | - */ |
|
110 | - static public function table($tableNameOrContentObject = '') |
|
111 | - { |
|
112 | - $tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject; |
|
113 | - return self::getService($tableName, self::TYPE_TABLE); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @return array |
|
118 | - */ |
|
119 | - public static function getInstanceStorage() |
|
120 | - { |
|
121 | - return self::$instances; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @return array |
|
126 | - */ |
|
127 | - public static function getSystemFields() |
|
128 | - { |
|
129 | - return self::$systemFields; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Signal that is called after the content repository for a content type has been instantiated. |
|
134 | - * |
|
135 | - * @param string $dataType |
|
136 | - * @param string $serviceType |
|
137 | - * @throws InvalidSlotException |
|
138 | - * @throws InvalidSlotReturnException |
|
139 | - * @throws \InvalidArgumentException |
|
140 | - */ |
|
141 | - static protected function emitPreProcessTcaSignal($dataType, $serviceType) |
|
142 | - { |
|
143 | - self::getSignalSlotDispatcher()->dispatch(Tca::class, 'preProcessTca', array($dataType, $serviceType)); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Get the SignalSlot dispatcher |
|
148 | - * |
|
149 | - * @return Dispatcher |
|
150 | - * @throws \InvalidArgumentException |
|
151 | - */ |
|
152 | - static protected function getSignalSlotDispatcher() |
|
153 | - { |
|
154 | - return GeneralUtility::makeInstance(Dispatcher::class); |
|
155 | - } |
|
27 | + /** |
|
28 | + * Fields that are considered as system. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + static protected $systemFields = array( |
|
33 | + 'uid', |
|
34 | + 'pid', |
|
35 | + 'tstamp', |
|
36 | + 'crdate', |
|
37 | + 'deleted', |
|
38 | + 'hidden', |
|
39 | + 'sys_language_uid', |
|
40 | + 'l18n_parent', |
|
41 | + 'l18n_diffsource', |
|
42 | + 't3ver_oid', |
|
43 | + 't3ver_id', |
|
44 | + 't3ver_wsid', |
|
45 | + 't3ver_label', |
|
46 | + 't3ver_state', |
|
47 | + 't3ver_stage', |
|
48 | + 't3ver_count', |
|
49 | + 't3ver_tstamp', |
|
50 | + 't3_origuid', |
|
51 | + ); |
|
52 | + |
|
53 | + /** |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + static protected $instances; |
|
57 | + |
|
58 | + /** |
|
59 | + * Returns a class instance of a corresponding TCA service. |
|
60 | + * If the class instance does not exist, create one. |
|
61 | + * |
|
62 | + * @throws NotExistingClassException |
|
63 | + * @param string $dataType |
|
64 | + * @param string $serviceType |
|
65 | + * @return TcaServiceInterface |
|
66 | + * @throws InvalidKeyInArrayException |
|
67 | + * @throws \InvalidArgumentException |
|
68 | + */ |
|
69 | + static protected function getService($dataType, $serviceType) |
|
70 | + { |
|
71 | + if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend() && empty($dataType)) { |
|
72 | + |
|
73 | + /** @var ModuleLoader $moduleLoader */ |
|
74 | + $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
75 | + $dataType = $moduleLoader->getDataType(); |
|
76 | + } |
|
77 | + |
|
78 | + if (empty(self::$instances[$dataType][$serviceType])) { |
|
79 | + $className = sprintf('Fab\Vidi\Tca\%sService', ucfirst($serviceType)); |
|
80 | + |
|
81 | + // Signal to pre-process the TCA of the given $dataType. |
|
82 | + self::emitPreProcessTcaSignal($dataType, $serviceType); |
|
83 | + |
|
84 | + $instance = GeneralUtility::makeInstance($className, $dataType, $serviceType); |
|
85 | + self::$instances[$dataType][$serviceType] = $instance; |
|
86 | + } |
|
87 | + return self::$instances[$dataType][$serviceType]; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Returns a "grid" service instance. |
|
92 | + * |
|
93 | + * @param string|Content $tableNameOrContentObject |
|
94 | + * @return GridService |
|
95 | + * @throws NotExistingClassException |
|
96 | + */ |
|
97 | + static public function grid($tableNameOrContentObject = '') |
|
98 | + { |
|
99 | + $tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject; |
|
100 | + return self::getService($tableName, self::TYPE_GRID); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Returns a "table" service instance ("ctrl" part of the TCA). |
|
105 | + * |
|
106 | + * @param string|Content $tableNameOrContentObject |
|
107 | + * @return TableService |
|
108 | + * @throws NotExistingClassException |
|
109 | + */ |
|
110 | + static public function table($tableNameOrContentObject = '') |
|
111 | + { |
|
112 | + $tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject; |
|
113 | + return self::getService($tableName, self::TYPE_TABLE); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @return array |
|
118 | + */ |
|
119 | + public static function getInstanceStorage() |
|
120 | + { |
|
121 | + return self::$instances; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @return array |
|
126 | + */ |
|
127 | + public static function getSystemFields() |
|
128 | + { |
|
129 | + return self::$systemFields; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Signal that is called after the content repository for a content type has been instantiated. |
|
134 | + * |
|
135 | + * @param string $dataType |
|
136 | + * @param string $serviceType |
|
137 | + * @throws InvalidSlotException |
|
138 | + * @throws InvalidSlotReturnException |
|
139 | + * @throws \InvalidArgumentException |
|
140 | + */ |
|
141 | + static protected function emitPreProcessTcaSignal($dataType, $serviceType) |
|
142 | + { |
|
143 | + self::getSignalSlotDispatcher()->dispatch(Tca::class, 'preProcessTca', array($dataType, $serviceType)); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Get the SignalSlot dispatcher |
|
148 | + * |
|
149 | + * @return Dispatcher |
|
150 | + * @throws \InvalidArgumentException |
|
151 | + */ |
|
152 | + static protected function getSignalSlotDispatcher() |
|
153 | + { |
|
154 | + return GeneralUtility::makeInstance(Dispatcher::class); |
|
155 | + } |
|
156 | 156 | |
157 | 157 | } |