@@ -22,107 +22,107 @@ |
||
22 | 22 | */ |
23 | 23 | class NewButton extends AbstractComponentView |
24 | 24 | { |
25 | - /** |
|
26 | - * Renders a "new" button to be placed in the doc header. |
|
27 | - * |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function render(): string |
|
31 | - { |
|
32 | - $output = ''; |
|
25 | + /** |
|
26 | + * Renders a "new" button to be placed in the doc header. |
|
27 | + * |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function render(): string |
|
31 | + { |
|
32 | + $output = ''; |
|
33 | 33 | |
34 | - // New button only for the current data type. |
|
35 | - if ($this->getModulePidService()->isConfiguredPidValid()) { |
|
36 | - $output = $this->makeLinkButton()->setHref($this->getNewUri()) |
|
37 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:newRecordGeneral')) |
|
38 | - ->setIcon($this->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL)) |
|
39 | - ->render(); |
|
40 | - } |
|
41 | - return $output; |
|
42 | - } |
|
34 | + // New button only for the current data type. |
|
35 | + if ($this->getModulePidService()->isConfiguredPidValid()) { |
|
36 | + $output = $this->makeLinkButton()->setHref($this->getNewUri()) |
|
37 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:newRecordGeneral')) |
|
38 | + ->setIcon($this->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL)) |
|
39 | + ->render(); |
|
40 | + } |
|
41 | + return $output; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Render a create URI given a data type. |
|
46 | - * |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - protected function getUriWizardNew(): string |
|
50 | - { |
|
51 | - // Return URL in any case. |
|
52 | - $arguments['returnUrl'] = $this->getModuleLoader()->getModuleUrl(); |
|
44 | + /** |
|
45 | + * Render a create URI given a data type. |
|
46 | + * |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + protected function getUriWizardNew(): string |
|
50 | + { |
|
51 | + // Return URL in any case. |
|
52 | + $arguments['returnUrl'] = $this->getModuleLoader()->getModuleUrl(); |
|
53 | 53 | |
54 | - // Add possible id parameter |
|
55 | - if (GeneralUtility::_GP(Parameter::PID)) { |
|
56 | - $arguments['id'] = GeneralUtility::_GP(Parameter::PID); |
|
57 | - } |
|
54 | + // Add possible id parameter |
|
55 | + if (GeneralUtility::_GP(Parameter::PID)) { |
|
56 | + $arguments['id'] = GeneralUtility::_GP(Parameter::PID); |
|
57 | + } |
|
58 | 58 | |
59 | - $uri = BackendUtility::getModuleUrl( |
|
60 | - 'db_new', |
|
61 | - $arguments |
|
62 | - ); |
|
59 | + $uri = BackendUtility::getModuleUrl( |
|
60 | + 'db_new', |
|
61 | + $arguments |
|
62 | + ); |
|
63 | 63 | |
64 | - return $uri; |
|
65 | - } |
|
64 | + return $uri; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Render a create URI given a data type. |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - protected function getNewUri(): string |
|
73 | - { |
|
74 | - $uri = BackendUtility::getModuleUrl( |
|
75 | - 'record_edit', |
|
76 | - array( |
|
77 | - $this->getNewParameterName() => 'new', |
|
78 | - 'returnUrl' => $this->getModuleLoader()->getModuleUrl() |
|
79 | - ) |
|
80 | - ); |
|
81 | - return $uri; |
|
82 | - } |
|
67 | + /** |
|
68 | + * Render a create URI given a data type. |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + protected function getNewUri(): string |
|
73 | + { |
|
74 | + $uri = BackendUtility::getModuleUrl( |
|
75 | + 'record_edit', |
|
76 | + array( |
|
77 | + $this->getNewParameterName() => 'new', |
|
78 | + 'returnUrl' => $this->getModuleLoader()->getModuleUrl() |
|
79 | + ) |
|
80 | + ); |
|
81 | + return $uri; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - protected function getNewParameterName(): string |
|
88 | - { |
|
89 | - return sprintf( |
|
90 | - 'edit[%s][%s]', |
|
91 | - $this->getModuleLoader()->getDataType(), |
|
92 | - $this->getStoragePid() |
|
93 | - ); |
|
94 | - } |
|
84 | + /** |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + protected function getNewParameterName(): string |
|
88 | + { |
|
89 | + return sprintf( |
|
90 | + 'edit[%s][%s]', |
|
91 | + $this->getModuleLoader()->getDataType(), |
|
92 | + $this->getStoragePid() |
|
93 | + ); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Return the default configured pid. |
|
98 | - * |
|
99 | - * @return int |
|
100 | - */ |
|
101 | - protected function getStoragePid(): int |
|
102 | - { |
|
103 | - if (GeneralUtility::_GP(Parameter::PID)) { |
|
104 | - $pid = GeneralUtility::_GP(Parameter::PID); |
|
105 | - } elseif ((int)Tca::table()->get('rootLevel') === 1) { |
|
106 | - $pid = 0; |
|
107 | - } else { |
|
108 | - // Get configuration from User TSConfig if any |
|
109 | - $tsConfig = $this->getBackendUser()->getTSConfig()['tx_vidi.']['dataType.'][$this->getModuleLoader()->getDataType().'.']['storagePid']; |
|
110 | - $pid = $tsConfig ?? null; |
|
96 | + /** |
|
97 | + * Return the default configured pid. |
|
98 | + * |
|
99 | + * @return int |
|
100 | + */ |
|
101 | + protected function getStoragePid(): int |
|
102 | + { |
|
103 | + if (GeneralUtility::_GP(Parameter::PID)) { |
|
104 | + $pid = GeneralUtility::_GP(Parameter::PID); |
|
105 | + } elseif ((int)Tca::table()->get('rootLevel') === 1) { |
|
106 | + $pid = 0; |
|
107 | + } else { |
|
108 | + // Get configuration from User TSConfig if any |
|
109 | + $tsConfig = $this->getBackendUser()->getTSConfig()['tx_vidi.']['dataType.'][$this->getModuleLoader()->getDataType().'.']['storagePid']; |
|
110 | + $pid = $tsConfig ?? null; |
|
111 | 111 | |
112 | - // Get pid from Module Loader |
|
113 | - if (null === $pid) { |
|
114 | - $pid = $this->getModuleLoader()->getDefaultPid(); |
|
115 | - } |
|
116 | - } |
|
117 | - return (int)$pid; |
|
118 | - } |
|
112 | + // Get pid from Module Loader |
|
113 | + if (null === $pid) { |
|
114 | + $pid = $this->getModuleLoader()->getDefaultPid(); |
|
115 | + } |
|
116 | + } |
|
117 | + return (int)$pid; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return ModulePidService|object |
|
122 | - */ |
|
123 | - public function getModulePidService() |
|
124 | - { |
|
125 | - /** @var ModulePidService $modulePidService */ |
|
126 | - return GeneralUtility::makeInstance(ModulePidService::class); |
|
127 | - } |
|
120 | + /** |
|
121 | + * @return ModulePidService|object |
|
122 | + */ |
|
123 | + public function getModulePidService() |
|
124 | + { |
|
125 | + /** @var ModulePidService $modulePidService */ |
|
126 | + return GeneralUtility::makeInstance(ModulePidService::class); |
|
127 | + } |
|
128 | 128 | } |
@@ -26,252 +26,252 @@ |
||
26 | 26 | */ |
27 | 27 | class MatcherObjectFactory implements SingletonInterface |
28 | 28 | { |
29 | - /** |
|
30 | - * Gets a singleton instance of this class. |
|
31 | - * |
|
32 | - * @return $this |
|
33 | - */ |
|
34 | - public static function getInstance(): self |
|
35 | - { |
|
36 | - return GeneralUtility::makeInstance(self::class); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Returns a matcher object. |
|
41 | - * |
|
42 | - * @param array $matches |
|
43 | - * @param string $dataType |
|
44 | - * @return Matcher |
|
45 | - */ |
|
46 | - public function getMatcher(array $matches = [], $dataType = ''): Matcher |
|
47 | - { |
|
48 | - if ($dataType === '') { |
|
49 | - $dataType = $this->getModuleLoader()->getDataType(); |
|
50 | - } |
|
51 | - |
|
52 | - /** @var $matcher Matcher */ |
|
53 | - $matcher = GeneralUtility::makeInstance(Matcher::class, [], $dataType); |
|
54 | - |
|
55 | - $matcher = $this->applyCriteriaFromDataTables($matcher); |
|
56 | - $matcher = $this->applyCriteriaFromMatchesArgument($matcher, $matches); |
|
57 | - |
|
58 | - if ($this->isBackendMode()) { |
|
59 | - $matcher = $this->applyCriteriaFromUrl($matcher); |
|
60 | - $matcher = $this->applyCriteriaFromTSConfig($matcher); |
|
61 | - } |
|
62 | - |
|
63 | - // Trigger signal for post processing Matcher Object. |
|
64 | - $this->emitPostProcessMatcherObjectSignal($matcher); |
|
65 | - |
|
66 | - return $matcher; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Get a possible id from the URL and apply as filter criteria. |
|
71 | - * Except if the main module belongs to the File. The id would be a combined identifier |
|
72 | - * including the storage and a mount point. |
|
73 | - * |
|
74 | - * @param Matcher $matcher |
|
75 | - * @return Matcher $matcher |
|
76 | - */ |
|
77 | - protected function applyCriteriaFromUrl(Matcher $matcher): Matcher |
|
78 | - { |
|
79 | - if (GeneralUtility::_GP('id') |
|
80 | - && !$this->getModuleLoader()->isPidIgnored() |
|
81 | - && $this->getModuleLoader()->getMainModule() !== ModuleName::FILE) { |
|
82 | - $matcher->equals('pid', GeneralUtility::_GP('id')); |
|
83 | - } |
|
84 | - |
|
85 | - return $matcher; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @param Matcher $matcher |
|
90 | - * @return Matcher $matcher |
|
91 | - */ |
|
92 | - protected function applyCriteriaFromTSConfig(Matcher $matcher): Matcher |
|
93 | - { |
|
94 | - $tsConfig = $this->getBackendUser()->getTSConfig()['tx_vidi.']['dataType.'][$matcher->getDataType().'.']['constraints.']; |
|
95 | - |
|
96 | - if (isset($tsConfig) && is_array($tsConfig) && !empty($tsConfig)) { |
|
97 | - foreach ($tsConfig as $constraint) { |
|
98 | - if (preg_match('/(.+) (>=|>|<|<=|=|like) (.+)/is', $constraint, $matches) && count($matches) === 4) { |
|
99 | - $operator = $matcher->getSupportedOperators()[strtolower(trim($matches[2]))]; |
|
100 | - $operand = trim($matches[1]); |
|
101 | - $value = trim($matches[3]); |
|
102 | - |
|
103 | - $matcher->$operator($operand, $value); |
|
104 | - } elseif (preg_match('/(.+) (in) (.+)/is', $constraint, $matches) && count($matches) === 4) { |
|
105 | - $operator = $matcher->getSupportedOperators()[trim($matches[2])]; |
|
106 | - $operand = trim($matches[1]); |
|
107 | - $value = trim($matches[3]); |
|
108 | - $matcher->$operator($operand, GeneralUtility::trimExplode(',', $value, true)); |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - return $matcher; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @param Matcher $matcher |
|
118 | - * @param array $matches |
|
119 | - * @return Matcher $matcher |
|
120 | - */ |
|
121 | - protected function applyCriteriaFromMatchesArgument(Matcher $matcher, $matches): Matcher |
|
122 | - { |
|
123 | - foreach ($matches as $fieldNameAndPath => $value) { |
|
124 | - // CSV values should be considered as "in" operator in the query, otherwise "equals". |
|
125 | - $explodedValues = GeneralUtility::trimExplode(',', $value, true); |
|
126 | - if (count($explodedValues) > 1) { |
|
127 | - $matcher->in($fieldNameAndPath, $explodedValues); |
|
128 | - } else { |
|
129 | - $matcher->equals($fieldNameAndPath, $explodedValues[0]); |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - return $matcher; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Apply criteria specific to jQuery plugin DataTable. |
|
138 | - * |
|
139 | - * @param Matcher $matcher |
|
140 | - * @return Matcher $matcher |
|
141 | - */ |
|
142 | - protected function applyCriteriaFromDataTables(Matcher $matcher): Matcher |
|
143 | - { |
|
144 | - // Special case for Grid in the BE using jQuery DataTables plugin. |
|
145 | - // Retrieve a possible search term from GP. |
|
146 | - $query = GeneralUtility::_GP('search'); |
|
147 | - if (is_array($query)) { |
|
148 | - if (!empty($query['value'])) { |
|
149 | - $query = $query['value']; |
|
150 | - } else { |
|
151 | - $query = ''; |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - if (strlen($query) > 0) { |
|
156 | - // Parse the json query coming from the Visual Search. |
|
157 | - $query = rawurldecode($query); |
|
158 | - $queryParts = json_decode($query, true); |
|
159 | - |
|
160 | - if (is_array($queryParts)) { |
|
161 | - $matcher = $this->parseQuery($queryParts, $matcher); |
|
162 | - } else { |
|
163 | - $matcher->setSearchTerm($query); |
|
164 | - } |
|
165 | - } |
|
166 | - return $matcher; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * @param array $queryParts |
|
171 | - * @param Matcher $matcher |
|
172 | - * @return Matcher $matcher |
|
173 | - */ |
|
174 | - protected function parseQuery(array $queryParts, Matcher $matcher): Matcher |
|
175 | - { |
|
176 | - $dataType = $matcher->getDataType(); |
|
177 | - foreach ($queryParts as $term) { |
|
178 | - $fieldNameAndPath = key($term); |
|
179 | - |
|
180 | - $resolvedDataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType); |
|
181 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType); |
|
182 | - |
|
183 | - // Retrieve the value. |
|
184 | - $value = current($term); |
|
185 | - |
|
186 | - if (Tca::grid($resolvedDataType)->hasFacet($fieldName) && Tca::grid($resolvedDataType)->facet($fieldName)->canModifyMatcher()) { |
|
187 | - $matcher = Tca::grid($resolvedDataType)->facet($fieldName)->modifyMatcher($matcher, $value); |
|
188 | - } elseif (Tca::table($resolvedDataType)->hasField($fieldName)) { |
|
189 | - // Check whether the field exists and set it as "equal" or "like". |
|
190 | - if ($this->isOperatorEquals($fieldNameAndPath, $dataType, $value)) { |
|
191 | - $matcher->equals($fieldNameAndPath, $value); |
|
192 | - } else { |
|
193 | - $matcher->like($fieldNameAndPath, $value); |
|
194 | - } |
|
195 | - } elseif ($fieldNameAndPath === 'text') { |
|
196 | - // Special case if field is "text" which is a pseudo field in this case. |
|
197 | - // Set the search term which means Vidi will |
|
198 | - // search in various fields with operator "like". The fields come from key "searchFields" in the TCA. |
|
199 | - $matcher->setSearchTerm($value); |
|
200 | - } |
|
201 | - } |
|
202 | - return $matcher; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Tell whether the operator should be equals instead of like for a search, e.g. if the value is numerical. |
|
207 | - * |
|
208 | - * @param string $fieldName |
|
209 | - * @param string $dataType |
|
210 | - * @param string $value |
|
211 | - * @return bool |
|
212 | - */ |
|
213 | - protected function isOperatorEquals($fieldName, $dataType, $value): bool |
|
214 | - { |
|
215 | - return (Tca::table($dataType)->field($fieldName)->hasRelation() && MathUtility::canBeInterpretedAsInteger($value)) |
|
216 | - || Tca::table($dataType)->field($fieldName)->isNumerical(); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Signal that is called for post-processing a matcher object. |
|
221 | - * |
|
222 | - * @param Matcher $matcher |
|
223 | - */ |
|
224 | - protected function emitPostProcessMatcherObjectSignal(Matcher $matcher): void |
|
225 | - { |
|
226 | - if (strlen($matcher->getDataType()) <= 0) { |
|
227 | - /** @var ModuleLoader $moduleLoader */ |
|
228 | - $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
229 | - $matcher->setDataType($moduleLoader->getDataType()); |
|
230 | - } |
|
231 | - |
|
232 | - $this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\Controller\Backend\ContentController', 'postProcessMatcherObject', array($matcher, $matcher->getDataType())); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Get the SignalSlot dispatcher |
|
237 | - * |
|
238 | - * @return Dispatcher|object |
|
239 | - */ |
|
240 | - protected function getSignalSlotDispatcher() |
|
241 | - { |
|
242 | - return GeneralUtility::makeInstance(Dispatcher::class); |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Get the Vidi Module Loader. |
|
247 | - * |
|
248 | - * @return ModuleLoader|object |
|
249 | - */ |
|
250 | - protected function getModuleLoader() |
|
251 | - { |
|
252 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * @return FieldPathResolver|object |
|
257 | - */ |
|
258 | - protected function getFieldPathResolver() |
|
259 | - { |
|
260 | - return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Returns an instance of the current Backend User. |
|
265 | - * |
|
266 | - * @return BackendUserAuthentication |
|
267 | - */ |
|
268 | - protected function getBackendUser(): BackendUserAuthentication |
|
269 | - { |
|
270 | - return $GLOBALS['BE_USER']; |
|
271 | - } |
|
272 | - |
|
273 | - protected function isBackendMode(): bool |
|
274 | - { |
|
275 | - return Typo3Mode::isBackendMode(); |
|
276 | - } |
|
29 | + /** |
|
30 | + * Gets a singleton instance of this class. |
|
31 | + * |
|
32 | + * @return $this |
|
33 | + */ |
|
34 | + public static function getInstance(): self |
|
35 | + { |
|
36 | + return GeneralUtility::makeInstance(self::class); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Returns a matcher object. |
|
41 | + * |
|
42 | + * @param array $matches |
|
43 | + * @param string $dataType |
|
44 | + * @return Matcher |
|
45 | + */ |
|
46 | + public function getMatcher(array $matches = [], $dataType = ''): Matcher |
|
47 | + { |
|
48 | + if ($dataType === '') { |
|
49 | + $dataType = $this->getModuleLoader()->getDataType(); |
|
50 | + } |
|
51 | + |
|
52 | + /** @var $matcher Matcher */ |
|
53 | + $matcher = GeneralUtility::makeInstance(Matcher::class, [], $dataType); |
|
54 | + |
|
55 | + $matcher = $this->applyCriteriaFromDataTables($matcher); |
|
56 | + $matcher = $this->applyCriteriaFromMatchesArgument($matcher, $matches); |
|
57 | + |
|
58 | + if ($this->isBackendMode()) { |
|
59 | + $matcher = $this->applyCriteriaFromUrl($matcher); |
|
60 | + $matcher = $this->applyCriteriaFromTSConfig($matcher); |
|
61 | + } |
|
62 | + |
|
63 | + // Trigger signal for post processing Matcher Object. |
|
64 | + $this->emitPostProcessMatcherObjectSignal($matcher); |
|
65 | + |
|
66 | + return $matcher; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Get a possible id from the URL and apply as filter criteria. |
|
71 | + * Except if the main module belongs to the File. The id would be a combined identifier |
|
72 | + * including the storage and a mount point. |
|
73 | + * |
|
74 | + * @param Matcher $matcher |
|
75 | + * @return Matcher $matcher |
|
76 | + */ |
|
77 | + protected function applyCriteriaFromUrl(Matcher $matcher): Matcher |
|
78 | + { |
|
79 | + if (GeneralUtility::_GP('id') |
|
80 | + && !$this->getModuleLoader()->isPidIgnored() |
|
81 | + && $this->getModuleLoader()->getMainModule() !== ModuleName::FILE) { |
|
82 | + $matcher->equals('pid', GeneralUtility::_GP('id')); |
|
83 | + } |
|
84 | + |
|
85 | + return $matcher; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @param Matcher $matcher |
|
90 | + * @return Matcher $matcher |
|
91 | + */ |
|
92 | + protected function applyCriteriaFromTSConfig(Matcher $matcher): Matcher |
|
93 | + { |
|
94 | + $tsConfig = $this->getBackendUser()->getTSConfig()['tx_vidi.']['dataType.'][$matcher->getDataType().'.']['constraints.']; |
|
95 | + |
|
96 | + if (isset($tsConfig) && is_array($tsConfig) && !empty($tsConfig)) { |
|
97 | + foreach ($tsConfig as $constraint) { |
|
98 | + if (preg_match('/(.+) (>=|>|<|<=|=|like) (.+)/is', $constraint, $matches) && count($matches) === 4) { |
|
99 | + $operator = $matcher->getSupportedOperators()[strtolower(trim($matches[2]))]; |
|
100 | + $operand = trim($matches[1]); |
|
101 | + $value = trim($matches[3]); |
|
102 | + |
|
103 | + $matcher->$operator($operand, $value); |
|
104 | + } elseif (preg_match('/(.+) (in) (.+)/is', $constraint, $matches) && count($matches) === 4) { |
|
105 | + $operator = $matcher->getSupportedOperators()[trim($matches[2])]; |
|
106 | + $operand = trim($matches[1]); |
|
107 | + $value = trim($matches[3]); |
|
108 | + $matcher->$operator($operand, GeneralUtility::trimExplode(',', $value, true)); |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + return $matcher; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @param Matcher $matcher |
|
118 | + * @param array $matches |
|
119 | + * @return Matcher $matcher |
|
120 | + */ |
|
121 | + protected function applyCriteriaFromMatchesArgument(Matcher $matcher, $matches): Matcher |
|
122 | + { |
|
123 | + foreach ($matches as $fieldNameAndPath => $value) { |
|
124 | + // CSV values should be considered as "in" operator in the query, otherwise "equals". |
|
125 | + $explodedValues = GeneralUtility::trimExplode(',', $value, true); |
|
126 | + if (count($explodedValues) > 1) { |
|
127 | + $matcher->in($fieldNameAndPath, $explodedValues); |
|
128 | + } else { |
|
129 | + $matcher->equals($fieldNameAndPath, $explodedValues[0]); |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + return $matcher; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Apply criteria specific to jQuery plugin DataTable. |
|
138 | + * |
|
139 | + * @param Matcher $matcher |
|
140 | + * @return Matcher $matcher |
|
141 | + */ |
|
142 | + protected function applyCriteriaFromDataTables(Matcher $matcher): Matcher |
|
143 | + { |
|
144 | + // Special case for Grid in the BE using jQuery DataTables plugin. |
|
145 | + // Retrieve a possible search term from GP. |
|
146 | + $query = GeneralUtility::_GP('search'); |
|
147 | + if (is_array($query)) { |
|
148 | + if (!empty($query['value'])) { |
|
149 | + $query = $query['value']; |
|
150 | + } else { |
|
151 | + $query = ''; |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + if (strlen($query) > 0) { |
|
156 | + // Parse the json query coming from the Visual Search. |
|
157 | + $query = rawurldecode($query); |
|
158 | + $queryParts = json_decode($query, true); |
|
159 | + |
|
160 | + if (is_array($queryParts)) { |
|
161 | + $matcher = $this->parseQuery($queryParts, $matcher); |
|
162 | + } else { |
|
163 | + $matcher->setSearchTerm($query); |
|
164 | + } |
|
165 | + } |
|
166 | + return $matcher; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * @param array $queryParts |
|
171 | + * @param Matcher $matcher |
|
172 | + * @return Matcher $matcher |
|
173 | + */ |
|
174 | + protected function parseQuery(array $queryParts, Matcher $matcher): Matcher |
|
175 | + { |
|
176 | + $dataType = $matcher->getDataType(); |
|
177 | + foreach ($queryParts as $term) { |
|
178 | + $fieldNameAndPath = key($term); |
|
179 | + |
|
180 | + $resolvedDataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType); |
|
181 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType); |
|
182 | + |
|
183 | + // Retrieve the value. |
|
184 | + $value = current($term); |
|
185 | + |
|
186 | + if (Tca::grid($resolvedDataType)->hasFacet($fieldName) && Tca::grid($resolvedDataType)->facet($fieldName)->canModifyMatcher()) { |
|
187 | + $matcher = Tca::grid($resolvedDataType)->facet($fieldName)->modifyMatcher($matcher, $value); |
|
188 | + } elseif (Tca::table($resolvedDataType)->hasField($fieldName)) { |
|
189 | + // Check whether the field exists and set it as "equal" or "like". |
|
190 | + if ($this->isOperatorEquals($fieldNameAndPath, $dataType, $value)) { |
|
191 | + $matcher->equals($fieldNameAndPath, $value); |
|
192 | + } else { |
|
193 | + $matcher->like($fieldNameAndPath, $value); |
|
194 | + } |
|
195 | + } elseif ($fieldNameAndPath === 'text') { |
|
196 | + // Special case if field is "text" which is a pseudo field in this case. |
|
197 | + // Set the search term which means Vidi will |
|
198 | + // search in various fields with operator "like". The fields come from key "searchFields" in the TCA. |
|
199 | + $matcher->setSearchTerm($value); |
|
200 | + } |
|
201 | + } |
|
202 | + return $matcher; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Tell whether the operator should be equals instead of like for a search, e.g. if the value is numerical. |
|
207 | + * |
|
208 | + * @param string $fieldName |
|
209 | + * @param string $dataType |
|
210 | + * @param string $value |
|
211 | + * @return bool |
|
212 | + */ |
|
213 | + protected function isOperatorEquals($fieldName, $dataType, $value): bool |
|
214 | + { |
|
215 | + return (Tca::table($dataType)->field($fieldName)->hasRelation() && MathUtility::canBeInterpretedAsInteger($value)) |
|
216 | + || Tca::table($dataType)->field($fieldName)->isNumerical(); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Signal that is called for post-processing a matcher object. |
|
221 | + * |
|
222 | + * @param Matcher $matcher |
|
223 | + */ |
|
224 | + protected function emitPostProcessMatcherObjectSignal(Matcher $matcher): void |
|
225 | + { |
|
226 | + if (strlen($matcher->getDataType()) <= 0) { |
|
227 | + /** @var ModuleLoader $moduleLoader */ |
|
228 | + $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
229 | + $matcher->setDataType($moduleLoader->getDataType()); |
|
230 | + } |
|
231 | + |
|
232 | + $this->getSignalSlotDispatcher()->dispatch('Fab\Vidi\Controller\Backend\ContentController', 'postProcessMatcherObject', array($matcher, $matcher->getDataType())); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Get the SignalSlot dispatcher |
|
237 | + * |
|
238 | + * @return Dispatcher|object |
|
239 | + */ |
|
240 | + protected function getSignalSlotDispatcher() |
|
241 | + { |
|
242 | + return GeneralUtility::makeInstance(Dispatcher::class); |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Get the Vidi Module Loader. |
|
247 | + * |
|
248 | + * @return ModuleLoader|object |
|
249 | + */ |
|
250 | + protected function getModuleLoader() |
|
251 | + { |
|
252 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * @return FieldPathResolver|object |
|
257 | + */ |
|
258 | + protected function getFieldPathResolver() |
|
259 | + { |
|
260 | + return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Returns an instance of the current Backend User. |
|
265 | + * |
|
266 | + * @return BackendUserAuthentication |
|
267 | + */ |
|
268 | + protected function getBackendUser(): BackendUserAuthentication |
|
269 | + { |
|
270 | + return $GLOBALS['BE_USER']; |
|
271 | + } |
|
272 | + |
|
273 | + protected function isBackendMode(): bool |
|
274 | + { |
|
275 | + return Typo3Mode::isBackendMode(); |
|
276 | + } |
|
277 | 277 | } |
@@ -21,209 +21,209 @@ |
||
21 | 21 | */ |
22 | 22 | class ModulePidService |
23 | 23 | { |
24 | - /** |
|
25 | - * The data type (table) |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $dataType = ''; |
|
30 | - |
|
31 | - /** |
|
32 | - * A collection of speaking error messages why the pid is invalid. |
|
33 | - * |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $errors = []; |
|
37 | - |
|
38 | - /** |
|
39 | - * ModulePidService constructor. |
|
40 | - */ |
|
41 | - public function __construct() |
|
42 | - { |
|
43 | - $this->dataType = $this->getModuleLoader()->getDataType(); |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Returns a class instance |
|
48 | - * |
|
49 | - * @return \Fab\Vidi\Module\ModulePidService|object |
|
50 | - */ |
|
51 | - public static function getInstance() |
|
52 | - { |
|
53 | - return GeneralUtility::makeInstance(self::class); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - public function isConfiguredPidValid(): bool |
|
60 | - { |
|
61 | - $errors = $this->validateConfiguredPid(); |
|
62 | - return empty($errors); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @return array |
|
67 | - */ |
|
68 | - public function validateConfiguredPid(): array |
|
69 | - { |
|
70 | - $configuredPid = $this->getConfiguredNewRecordPid(); |
|
71 | - $this->validateRootLevel($configuredPid); |
|
72 | - $this->validatePageExist($configuredPid); |
|
73 | - $this->validateDoktype($configuredPid); |
|
74 | - return $this->errors; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Return the default configured pid. |
|
79 | - * |
|
80 | - * @return int |
|
81 | - */ |
|
82 | - public function getConfiguredNewRecordPid(): int |
|
83 | - { |
|
84 | - if (GeneralUtility::_GP(Parameter::PID)) { |
|
85 | - $configuredPid = (int)GeneralUtility::_GP(Parameter::PID); |
|
86 | - } else { |
|
87 | - // Get pid from User TSConfig if any. |
|
88 | - $result = $this->getBackendUser()->getTSConfig()['tx_vidi.']['dataType.'][$this->dataType.'.']['storagePid']; |
|
89 | - $configuredPid = isset($result) ? (int)$result : $this->getModuleLoader()->getDefaultPid(); |
|
90 | - } |
|
91 | - |
|
92 | - return $configuredPid; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Check if pid is 0 and given table is allowed on root level. |
|
97 | - * |
|
98 | - * @param int $configuredPid |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - protected function validateRootLevel(int $configuredPid): void |
|
102 | - { |
|
103 | - if ($configuredPid > 0) { |
|
104 | - return; |
|
105 | - } |
|
106 | - |
|
107 | - $isRootLevel = (bool)Tca::table()->get('rootLevel'); |
|
108 | - if (!$isRootLevel) { |
|
109 | - $this->errors[] = sprintf( |
|
110 | - 'You are not allowed to use page id "0" unless you set $GLOBALS[\'TCA\'][\'%1$s\'][\'ctrl\'][\'rootLevel\'] = 1;', |
|
111 | - $this->dataType |
|
112 | - ); |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Check if a page exists for the configured pid |
|
118 | - * |
|
119 | - * @param int $configuredPid |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - protected function validatePageExist(int $configuredPid): void |
|
123 | - { |
|
124 | - if ($configuredPid === 0) { |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - $page = $this->getPage($configuredPid); |
|
129 | - if (empty($page)) { |
|
130 | - $this->errors[] = sprintf( |
|
131 | - 'No page found for the configured page id "%s".', |
|
132 | - $configuredPid |
|
133 | - ); |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Check if configured page is a sysfolder and if it is allowed. |
|
139 | - * |
|
140 | - * @param int $configuredPid |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - protected function validateDoktype(int $configuredPid): void |
|
144 | - { |
|
145 | - if ($configuredPid === 0) { |
|
146 | - return; |
|
147 | - } |
|
148 | - |
|
149 | - $page = $this->getPage($configuredPid); |
|
150 | - if (!empty($page) |
|
151 | - && (int)$page['doktype'] !== PageRepository::DOKTYPE_SYSFOLDER |
|
152 | - && !$this->isTableAllowedOnStandardPages() |
|
153 | - && $this->getModuleLoader()->hasComponentInDocHeader(NewButton::class)) { |
|
154 | - $this->errors[] = sprintf( |
|
155 | - 'The page with the id "%s" either has to be of the type "folder" (doktype=254) or the table "%s" has to be allowed on standard pages.', |
|
156 | - $configuredPid, |
|
157 | - $this->dataType |
|
158 | - ); |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Check if given table is allowed on standard pages |
|
164 | - * |
|
165 | - * @return bool |
|
166 | - * @see \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages() |
|
167 | - */ |
|
168 | - protected function isTableAllowedOnStandardPages(): bool |
|
169 | - { |
|
170 | - $allowedTables = explode(',', $GLOBALS['PAGES_TYPES']['default']['allowedTables']); |
|
171 | - return in_array($this->dataType, $allowedTables, true); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Returns the page record of the configured pid |
|
176 | - * |
|
177 | - * @param int $configuredPid |
|
178 | - * @return array |
|
179 | - */ |
|
180 | - protected function getPage(int $configuredPid): ?array |
|
181 | - { |
|
182 | - $query = $this->getQueryBuilder('pages'); |
|
183 | - $query->getRestrictions()->removeAll(); // we are in BE context. |
|
184 | - |
|
185 | - $page = $query->select('doktype') |
|
186 | - ->from('pages') |
|
187 | - ->where( |
|
188 | - 'deleted = 0', |
|
189 | - 'uid = ' . $configuredPid |
|
190 | - ) |
|
191 | - ->execute() |
|
192 | - ->fetch(); |
|
193 | - |
|
194 | - return is_array($page) |
|
195 | - ? $page |
|
196 | - : []; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @param string $tableName |
|
201 | - * @return object|QueryBuilder |
|
202 | - */ |
|
203 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
204 | - { |
|
205 | - /** @var ConnectionPool $connectionPool */ |
|
206 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
207 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Returns an instance of the current Backend User. |
|
212 | - * |
|
213 | - * @return BackendUserAuthentication |
|
214 | - */ |
|
215 | - protected function getBackendUser() |
|
216 | - { |
|
217 | - return $GLOBALS['BE_USER']; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Get the Vidi Module Loader. |
|
222 | - * |
|
223 | - * @return ModuleLoader|object |
|
224 | - */ |
|
225 | - protected function getModuleLoader() |
|
226 | - { |
|
227 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
228 | - } |
|
24 | + /** |
|
25 | + * The data type (table) |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $dataType = ''; |
|
30 | + |
|
31 | + /** |
|
32 | + * A collection of speaking error messages why the pid is invalid. |
|
33 | + * |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $errors = []; |
|
37 | + |
|
38 | + /** |
|
39 | + * ModulePidService constructor. |
|
40 | + */ |
|
41 | + public function __construct() |
|
42 | + { |
|
43 | + $this->dataType = $this->getModuleLoader()->getDataType(); |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Returns a class instance |
|
48 | + * |
|
49 | + * @return \Fab\Vidi\Module\ModulePidService|object |
|
50 | + */ |
|
51 | + public static function getInstance() |
|
52 | + { |
|
53 | + return GeneralUtility::makeInstance(self::class); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + public function isConfiguredPidValid(): bool |
|
60 | + { |
|
61 | + $errors = $this->validateConfiguredPid(); |
|
62 | + return empty($errors); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @return array |
|
67 | + */ |
|
68 | + public function validateConfiguredPid(): array |
|
69 | + { |
|
70 | + $configuredPid = $this->getConfiguredNewRecordPid(); |
|
71 | + $this->validateRootLevel($configuredPid); |
|
72 | + $this->validatePageExist($configuredPid); |
|
73 | + $this->validateDoktype($configuredPid); |
|
74 | + return $this->errors; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Return the default configured pid. |
|
79 | + * |
|
80 | + * @return int |
|
81 | + */ |
|
82 | + public function getConfiguredNewRecordPid(): int |
|
83 | + { |
|
84 | + if (GeneralUtility::_GP(Parameter::PID)) { |
|
85 | + $configuredPid = (int)GeneralUtility::_GP(Parameter::PID); |
|
86 | + } else { |
|
87 | + // Get pid from User TSConfig if any. |
|
88 | + $result = $this->getBackendUser()->getTSConfig()['tx_vidi.']['dataType.'][$this->dataType.'.']['storagePid']; |
|
89 | + $configuredPid = isset($result) ? (int)$result : $this->getModuleLoader()->getDefaultPid(); |
|
90 | + } |
|
91 | + |
|
92 | + return $configuredPid; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Check if pid is 0 and given table is allowed on root level. |
|
97 | + * |
|
98 | + * @param int $configuredPid |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + protected function validateRootLevel(int $configuredPid): void |
|
102 | + { |
|
103 | + if ($configuredPid > 0) { |
|
104 | + return; |
|
105 | + } |
|
106 | + |
|
107 | + $isRootLevel = (bool)Tca::table()->get('rootLevel'); |
|
108 | + if (!$isRootLevel) { |
|
109 | + $this->errors[] = sprintf( |
|
110 | + 'You are not allowed to use page id "0" unless you set $GLOBALS[\'TCA\'][\'%1$s\'][\'ctrl\'][\'rootLevel\'] = 1;', |
|
111 | + $this->dataType |
|
112 | + ); |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Check if a page exists for the configured pid |
|
118 | + * |
|
119 | + * @param int $configuredPid |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + protected function validatePageExist(int $configuredPid): void |
|
123 | + { |
|
124 | + if ($configuredPid === 0) { |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + $page = $this->getPage($configuredPid); |
|
129 | + if (empty($page)) { |
|
130 | + $this->errors[] = sprintf( |
|
131 | + 'No page found for the configured page id "%s".', |
|
132 | + $configuredPid |
|
133 | + ); |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Check if configured page is a sysfolder and if it is allowed. |
|
139 | + * |
|
140 | + * @param int $configuredPid |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + protected function validateDoktype(int $configuredPid): void |
|
144 | + { |
|
145 | + if ($configuredPid === 0) { |
|
146 | + return; |
|
147 | + } |
|
148 | + |
|
149 | + $page = $this->getPage($configuredPid); |
|
150 | + if (!empty($page) |
|
151 | + && (int)$page['doktype'] !== PageRepository::DOKTYPE_SYSFOLDER |
|
152 | + && !$this->isTableAllowedOnStandardPages() |
|
153 | + && $this->getModuleLoader()->hasComponentInDocHeader(NewButton::class)) { |
|
154 | + $this->errors[] = sprintf( |
|
155 | + 'The page with the id "%s" either has to be of the type "folder" (doktype=254) or the table "%s" has to be allowed on standard pages.', |
|
156 | + $configuredPid, |
|
157 | + $this->dataType |
|
158 | + ); |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Check if given table is allowed on standard pages |
|
164 | + * |
|
165 | + * @return bool |
|
166 | + * @see \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages() |
|
167 | + */ |
|
168 | + protected function isTableAllowedOnStandardPages(): bool |
|
169 | + { |
|
170 | + $allowedTables = explode(',', $GLOBALS['PAGES_TYPES']['default']['allowedTables']); |
|
171 | + return in_array($this->dataType, $allowedTables, true); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Returns the page record of the configured pid |
|
176 | + * |
|
177 | + * @param int $configuredPid |
|
178 | + * @return array |
|
179 | + */ |
|
180 | + protected function getPage(int $configuredPid): ?array |
|
181 | + { |
|
182 | + $query = $this->getQueryBuilder('pages'); |
|
183 | + $query->getRestrictions()->removeAll(); // we are in BE context. |
|
184 | + |
|
185 | + $page = $query->select('doktype') |
|
186 | + ->from('pages') |
|
187 | + ->where( |
|
188 | + 'deleted = 0', |
|
189 | + 'uid = ' . $configuredPid |
|
190 | + ) |
|
191 | + ->execute() |
|
192 | + ->fetch(); |
|
193 | + |
|
194 | + return is_array($page) |
|
195 | + ? $page |
|
196 | + : []; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @param string $tableName |
|
201 | + * @return object|QueryBuilder |
|
202 | + */ |
|
203 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
204 | + { |
|
205 | + /** @var ConnectionPool $connectionPool */ |
|
206 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
207 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Returns an instance of the current Backend User. |
|
212 | + * |
|
213 | + * @return BackendUserAuthentication |
|
214 | + */ |
|
215 | + protected function getBackendUser() |
|
216 | + { |
|
217 | + return $GLOBALS['BE_USER']; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Get the Vidi Module Loader. |
|
222 | + * |
|
223 | + * @return ModuleLoader|object |
|
224 | + */ |
|
225 | + protected function getModuleLoader() |
|
226 | + { |
|
227 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
228 | + } |
|
229 | 229 | } |